GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TBGSubtraction.cxx
Go to the documentation of this file.
1#include "TROOT.h"
2#include "TBGSubtraction.h"
3#include "TGNumberEntry.h"
4#include "TInterpreter.h"
5#include "TString.h"
6#include "GCanvas.h"
7
8#include "TGauss.h"
9#include "TRWPeak.h"
10#include "TABPeak.h"
11#include "TAB3Peak.h"
12
13TBGSubtraction::TBGSubtraction(TH2* mat, const char* gate_axis, int maxBinning)
14 : TGMainFrame(nullptr, 10, 10, kHorizontalFrame), fMatrix(mat),
15 fPeakFitter(new TPeakFitter()), fMaxBinning(maxBinning)
16{
17 TString tmp_gate_word(gate_axis);
18 tmp_gate_word.ToUpper();
19 if(tmp_gate_word.EqualTo("X")) {
20 fGateAxis = 0;
21 } else {
22 fGateAxis = 1;
23 }
24
25 if(fGateAxis == 0) {
26 fProjection = fMatrix->ProjectionY();
27 } else {
28 fProjection = fMatrix->ProjectionX();
29 }
30
31 // fTree = 0;
32 if(!gClient) {
33 return;
34 }
35 gInterpreter->SaveContext();
36 // First we build the interface based on how it looks
38 // Now we initialize pieces of the interface to create the initial projections etc.
41 fCurrentFile = TFile::CurrentFile();
42}
43
45{
46 /// Connect Canvases to recognize that they have been zoomed
47 /// This function includes setting the slider, and drawing the gate markers.
48 fProjectionCanvas->GetCanvas()->Connect("RangeChanged()", "TBGSubtraction", this, "DoProjectionCanvasZoomed()");
49
50 fGateCanvas->GetCanvas()->Connect("RangeChanged()", "TBGSubtraction", this, "DoGateCanvasZoomed()");
51
52 // Connect Status Info to canvases
53 fProjectionCanvas->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "TBGSubtraction", this,
54 "ProjectionStatusInfo(Int_t,Int_t,Int_t,TObject*)");
55 fGateCanvas->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "TBGSubtraction", this,
56 "GateStatusInfo(Int_t,Int_t,Int_t,TObject*)");
57
58 // Connect the sliding of sliders
59 // I'm storing the "true" information in the entry boxes. This is what we refer back to for
60 // the actual value of the sliders, etc.
61 // However, there are two number entries, so we will send out two signals per change. We want to connect the gating to
62 // the slider instead.
63
64 fGateSlider->Connect("PositionChanged()", "TBGSubtraction", this, "DoSlider()");
65
66 fBGSlider1->Connect("PositionChanged()", "TBGSubtraction", this, "DoSlider()");
67 fBGSlider2->Connect("PositionChanged()", "TBGSubtraction", this, "DoSlider()");
68
69 fPeakSlider->Connect("PointerPositionChanged()", "TBGSubtraction", this, "DoSlider()");
70 fPeakSlider->Connect("PositionChanged()", "TBGSubtraction", this, "DoSlider()");
71
72 fBinningSlider->Connect("PositionChanged(Int_t)", "TBGSubtraction", this, "DoSlider()");
73
74 // Connect the clicking of buttons
75 fPeakFitButton->Connect("Clicked()", "TBGSubtraction", this, "DoPeakFit()");
76
77 fBGCheckButton1->Connect("Clicked()", "TBGSubtraction", this, "UpdateBackground()");
78 fBGCheckButton2->Connect("Clicked()", "TBGSubtraction", this, "UpdateBackground()");
79
80 fWrite2FileButton->Connect("Clicked()", "TBGSubtraction", this, "WriteHistograms()");
81
82 // Connect the axis combo box
83 fAxisCombo->Connect("Selected(Int_t,Int_t)", "TBGSubtraction", this, "AxisComboSelected()");
84 fPeakCombo->Connect("Selected(Int_t,Int_t)", "TBGSubtraction", this, "PeakComboSelected()");
85
86 // Connect the Gate entries so that if you type a value in they do the proper things
87 // Everyhting that is updated sets the value of these entries, which trickles down and fixes everything else
88 fGateEntryLow->Connect("ValueSet(Long_t)", "TBGSubtraction", this, "DoEntry(Long_t)");
89 fGateEntryHigh->Connect("ValueSet(Long_t)", "TBGSubtraction", this, "DoEntry(Long_t)");
90 fBGEntryLow1->Connect("ValueSet(Long_t)", "TBGSubtraction", this, "DoEntry(Long_t)");
91 fBGEntryHigh1->Connect("ValueSet(Long_t)", "TBGSubtraction", this, "DoEntry(Long_t)");
92 fBGEntryLow2->Connect("ValueSet(Long_t)", "TBGSubtraction", this, "DoEntry(Long_t)");
93 fBGEntryHigh2->Connect("ValueSet(Long_t)", "TBGSubtraction", this, "DoEntry(Long_t)");
94 fBGEntryHigh2->Connect("ValueSet(Long_t)", "TBGSubtraction", this, "UpdateProjectionSliders()");
95
96 // Connect the bg paramater entry to do the proper thing
97 fBGParamEntry->Connect("ValueSet(Long_t)", "TBGSubtraction", this, "UpdateBackground()");
98
99 // We want to connect the fit peak, and write histogram buttons with the update check box.
100 // We don't want someone writing a histo, or fitting a peak when the gate isn't as expected.
101 fAutoUpdateCheckButton->Connect("Clicked()", "TBGSubtraction", this, "SetStatusFromUpdateCheckButton()");
102}
103
105{
106 /// Disconnect Canvases to recognize that they have been zoomed
107 /// This function includes setting the slider, and drawing the gate markers.
108 fProjectionCanvas->GetCanvas()->Disconnect("RangeChanged()", this, "DoProjectionCanvasZoomed()");
109
110 fGateCanvas->GetCanvas()->Disconnect("RangeChanged()", this, "DoGateCanvasZoomed()");
111
112 // Disconnect Status Info to canvases
113 fProjectionCanvas->GetCanvas()->Disconnect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", this,
114 "ProjectionStatusInfo(Int_t,Int_t,Int_t,TObject*)");
115 fGateCanvas->GetCanvas()->Disconnect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", this,
116 "GateStatusInfo(Int_t,Int_t,Int_t,TObject*)");
117
118 // Disconnect the sliding of sliders
119 // I'm storing the "true" information in the entry boxes. This is what we refer back to for
120 // the actual value of the sliders, etc.
121 // However, there are two number entries, so we will send out two signals per change. We want to connect the gating to
122 // the slider instead.
123
124 fGateSlider->Disconnect("PositionChanged()", this, "DoSlider()");
125
126 fBGSlider1->Disconnect("PositionChanged()", this, "DoSlider()");
127 fBGSlider2->Disconnect("PositionChanged()", this, "DoSlider()");
128
129 fPeakSlider->Disconnect("PointerPositionChanged()", this, "DoSlider()");
130 fPeakSlider->Disconnect("PositionChanged()", this, "DoSlider()");
131
132 fBinningSlider->Disconnect("PositionChanged(Int_t)", this, "DoSlider()");
133
134 // Disconnect the clicking of buttons
135 fPeakFitButton->Disconnect("Clicked()", this, "DoPeakFit()");
136
137 fBGCheckButton1->Disconnect("Clicked()", this, "UpdateBackground()");
138 fBGCheckButton2->Disconnect("Clicked()", this, "UpdateBackground()");
139
140 fWrite2FileButton->Disconnect("Clicked()", this, "WriteHistograms()");
141
142 // Disconnect the axis combo box
143 fAxisCombo->Disconnect("Selected(Int_t,Int_t)", this, "AxisComboSelected()");
144 fPeakCombo->Disconnect("Selected(Int_t,Int_t)", this, "PeakComboSelected()");
145
146 // Disconnect the Gate entries so that if you type a value in they do the proper things
147 // Everyhting that is updated sets the value of these entries, which trickles down and fixes everything else
148 fGateEntryLow->Disconnect("ValueSet(Long_t)", this, "DoEntry(Long_t)");
149 fGateEntryHigh->Disconnect("ValueSet(Long_t)", this, "DoEntry(Long_t)");
150 fBGEntryLow1->Disconnect("ValueSet(Long_t)", this, "DoEntry(Long_t)");
151 fBGEntryHigh1->Disconnect("ValueSet(Long_t)", this, "DoEntry(Long_t)");
152 fBGEntryLow2->Disconnect("ValueSet(Long_t)", this, "DoEntry(Long_t)");
153 fBGEntryHigh2->Disconnect("ValueSet(Long_t)", this, "DoEntry(Long_t)");
154 fBGEntryHigh2->Disconnect("ValueSet(Long_t)", this, "UpdateProjectionSliders()");
155
156 // Disconnect the bg paramater entry to do the proper thing
157 fBGParamEntry->Disconnect("ValueSet(Long_t)", this, "UpdateBackground()");
158
159 // We want to connect the fit peak, and write histogram buttons with the update check box.
160 // We don't want someone writing a histo, or fitting a peak when the gate isn't as expected.
161 fAutoUpdateCheckButton->Disconnect("Clicked()", this, "SetStatusFromUpdateCheckButton()");
162}
163
165{
166 Double_t def_gate_low = 0.3;
167 Double_t def_gate_high = 0.4;
168 Double_t def_bg_low = 0.7;
169 Double_t def_bg_high = 0.8;
170 Double_t def_peak_low = 0.4;
171 Double_t def_peak_high = 0.5; // ratios of bar width
172
173 // Lets Project out the matrix
174
175 // Set Up entry and sliders for doing gating.
176 Double_t xmin = 0.;
177 Double_t ymin = 0.;
178 Double_t xmax = 0.;
179 Double_t ymax = 0.;
180 fProjectionCanvas->GetCanvas()->GetRange(xmin, ymin, xmax, ymax);
181 Double_t x_width = xmax - xmin;
182
183 fGateEntryLow->SetNumber(xmin + def_gate_low * x_width);
184 fGateEntryHigh->SetNumber(xmax - (1.0 - def_gate_high) * x_width);
185 fGateEntryLow->SetLimitValues(xmin, xmax);
186 fGateEntryHigh->SetLimitValues(xmin, xmax);
187
188 fBGEntryLow1->SetNumber(xmin + def_bg_low * x_width);
189 fBGEntryHigh1->SetNumber(xmax - (1.0 - def_bg_high) * x_width);
190 fBGEntryLow1->SetLimitValues(xmin, xmax);
191 fBGEntryHigh1->SetLimitValues(xmin, xmax);
192
193 fBGEntryLow2->SetNumber(xmin + def_bg_low * x_width);
194 fBGEntryHigh2->SetNumber(xmax - (1.0 - def_bg_high) * x_width);
195 fBGEntryLow2->SetLimitValues(xmin, xmax);
196 fBGEntryHigh2->SetLimitValues(xmin, xmax);
197
200 DoAllGates();
202
203 // Set up peak fitting bars
204 if(fSubtractedBinHist != nullptr) { fSubtractedBinHist->GetXaxis()->UnZoom(); }
205 fGateCanvas->GetCanvas()->GetRange(xmin, ymin, xmax, ymax);
206 x_width = xmax - xmin;
207
208 fPeakLowValue = xmin + def_peak_low * x_width;
209 fPeakHighValue = xmax - (1.0 - def_peak_high) * x_width;
210 fPeakValue = xmin + (def_peak_low + 0.05) * x_width;
211
212 fPeakLowLimit = xmin;
213 fPeakHighLimit = xmax;
214
218}
219
221{
222 // Set up axis combo box for selecting x or y axis
223 // This has to happen at the start to create the projection
224 fAxisCombo->Resize(150, 20);
225 fAxisCombo->AddEntry("x", 0);
226 fAxisCombo->AddEntry("y", 1);
227 fAxisCombo->SetEnabled();
228 fAxisCombo->Select(fGateAxis);
230
231 fPeakCombo->Resize(150, 20);
232 fPeakCombo->AddEntry("TGauss", 0);
233 fPeakCombo->AddEntry("TRWPeak", 1);
234 fPeakCombo->AddEntry("TABPeak", 2);
235 fPeakCombo->AddEntry("TAB3Peak", 3);
236 fPeakCombo->SetEnabled();
237 fPeakCombo->Select(0);
239
243
245}
246
248{
249 // Create a main frame
250 fProjectionFrame = new TGVerticalFrame(this, 400, 400);
251 // Create canvas widget
252 fProjectionCanvas = new TRootEmbeddedCanvas("ProjectionCanvas", fProjectionFrame, 200, 200);
253 // Create a horizontal frame widget with buttons
254
255 fGateEntryFrame = new TGHorizontalFrame(fProjectionFrame, 400, 400);
256
257 Double_t xmin = 0.;
258 Double_t ymin = 0.;
259 Double_t xmax = 0.;
260 Double_t ymax = 0.;
261 fProjectionCanvas->GetCanvas()->GetRange(xmin, ymin, xmax, ymax);
262
263 // We are going to start the limits off at a specific ratio of the frame
264 fGateEntryLow = new TGNumberEntry(fGateEntryFrame, 0, 3, kGateLowEntry, TGNumberFormat::kNESReal,
265 TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, xmin, xmax);
266
268 new TGNumberEntry(fGateEntryFrame, 0, 3, kGateHighEntry, TGNumberFormat::kNESReal,
269 TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, xmin, xmax);
270
271 fGateSlider = new TGDoubleHSlider(fProjectionFrame, 100, kDoubleScaleBoth, kGateSlider, kHorizontalFrame);
272
273 fBGEntryFrame1 = new TGHorizontalFrame(fProjectionFrame, 200, 200);
274 fBGEntryLow1 = new TGNumberEntry(fBGEntryFrame1, 0, 3, kBGLowEntry1, TGNumberFormat::kNESReal,
275 TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, xmin, xmax);
276
277 fBGEntryHigh1 = new TGNumberEntry(fBGEntryFrame1, 0, 3, kBGHighEntry1, TGNumberFormat::kNESReal,
278 TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, xmin, xmax);
279
280 fBGEntryFrame2 = new TGHorizontalFrame(fProjectionFrame, 200, 200);
281 fBGEntryLow2 = new TGNumberEntry(fBGEntryFrame2, 0, 3, kBGLowEntry2, TGNumberFormat::kNESReal,
282 TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, xmin, xmax);
283
284 fBGEntryHigh2 = new TGNumberEntry(fBGEntryFrame2, 0, 3, kBGHighEntry2, TGNumberFormat::kNESReal,
285 TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, xmin, xmax);
286
287 fBGSlider1 = new TGDoubleHSlider(fProjectionFrame, 100, kDoubleScaleBoth, kBGSlider1, kHorizontalFrame);
288 fBGSlider2 = new TGDoubleHSlider(fProjectionFrame, 100, kDoubleScaleBoth, kBGSlider2, kHorizontalFrame);
289
290 fGateFrame = new TGVerticalFrame(this, 200, 200);
291 fGateCanvas = new TRootEmbeddedCanvas("GateCanvas", fGateFrame, 200, 200);
292 auto* canvas = fGateCanvas->GetCanvas();
293 // according to clang-tidy the second and third arguments should be Int_t, but the Getters return UInt_t?
294 // might not be true for all root versions though?
295 auto* gcanvas = new GCanvas(canvas->GetName(), canvas->GetWindowWidth(), canvas->GetWindowHeight(), canvas->GetCanvasID());
296 fGateCanvas->AdoptCanvas(gcanvas);
297
298 // Status Bars
299 std::array<Int_t, 2> parts = {20, 50};
300 fProjectionStatus = new TGStatusBar(fProjectionFrame, 50, 10, kHorizontalFrame);
301 fProjectionStatus->SetParts(parts.data(), parts.size());
302
303 fPeakSlider = new TGTripleHSlider(fGateFrame, 100, kDoubleScaleBoth, kPeakSlider, kHorizontalFrame);
304
305 fBinningFrame = new TGHorizontalFrame(fGateFrame, 200, 200);
306 fBinningLabel = new TGLabel(fBinningFrame, Form("Binning (1 - %d): ", fMaxBinning));
307 fBinningSlider = new TGHSlider(fBinningFrame, 100, kSlider2, kBinningSlider, kHorizontalFrame);
308
309 fPeakFitFrame = new TGHorizontalFrame(fGateFrame, 200, 200);
310 fPeakFitButton = new TGTextButton(fPeakFitFrame, "&Fit Peak");
311
312 fBGParamFrame = new TGHorizontalFrame(fGateFrame, 200, 200);
313 fBGParamLabel = new TGLabel(fBGParamFrame, "Background:");
314 fBGParamEntry = new TGNumberEntry(fBGParamFrame, 20, 4, kBGParamEntry, TGNumberFormat::kNESInteger, // style
315 TGNumberFormat::kNEANonNegative, // input value filter
316 TGNumberFormat::kNELLimitMin, // specify limits
317 1, 1.); // limit values
318
319 fAxisCombo = new TGComboBox(fBGParamFrame, kComboAxisEntry);
320
321 fPeakCombo = new TGComboBox(fBGParamFrame, kComboPeakEntry);
322
323 fBGCheckButton1 = new TGCheckButton(fBGParamFrame, "BG 1", kBGCheckButton1);
324 fBGCheckButton1->SetState(kButtonDown);
325
326 fBGCheckButton2 = new TGCheckButton(fBGParamFrame, "BG 2", kBGCheckButton2);
327 fBGCheckButton2->SetState(kButtonUp);
328
329 fDescriptionFrame = new TGHorizontalFrame(fGateFrame, 200, 200);
330 fAutoUpdateCheckButton = new TGCheckButton(fDescriptionFrame, "Auto Update", kAutoUpdateCheckButton);
331 fAutoUpdateCheckButton->SetState(kButtonDown);
332 fHistogramDescription = new TGTextEntry(fDescriptionFrame, "gated #gamma-#gamma", kHistogramDescriptionEntry);
333
334 fButtonFrame = new TGHorizontalFrame(fGateFrame, 200, 200);
335 fWrite2FileName = new TGTextEntry(fButtonFrame, "default.root", kWrite2FileNameEntry);
336 fWrite2FileButton = new TGTextButton(fButtonFrame, "&Write Histograms");
337
338 fBly = new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 1, 1, 3, 1);
339 fLayoutCanvases = new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX | kLHintsExpandY, 1, 1, 3, 4);
340 fLayoutParam = new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 1, 1, 3, 20);
341
342 fBly1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX | kLHintsExpandY, 20, 10, 15, 0);
343
344 // Build smaller horizontal frames
345 fBGParamFrame->AddFrame(fAxisCombo, fBly);
346 fBGParamFrame->AddFrame(fPeakCombo, fBly);
349 fBGParamFrame->AddFrame(fBGParamLabel, fBly);
350 fBGParamFrame->AddFrame(fBGParamEntry, fBly);
351
354
356
357 fBinningFrame->AddFrame(fBinningLabel, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsCenterY, 1, 3, 3, 1));
359
360 fBGEntryFrame1->AddFrame(fBGEntryLow1, fBly);
362
363 fBGEntryFrame2->AddFrame(fBGEntryLow2, fBly);
365
368
371
372 // Build left and right frames
376 fProjectionFrame->AddFrame(fBGSlider1, fBly);
377 fProjectionFrame->AddFrame(fBGSlider2, fBly);
381
383 fGateFrame->AddFrame(fPeakSlider, fBly);
384 fGateFrame->AddFrame(fPeakFitFrame, fBly);
385 fGateFrame->AddFrame(fBinningFrame, fBly);
389
390 AddFrame(fProjectionFrame, fBly1);
391 AddFrame(fGateFrame, fBly1);
392
393 // Set a name to the main frame
394 SetWindowName("Gater and Subtractor");
395
396 // Map all subwindows of main frame
397 MapSubwindows();
398
399 // Initialize the layout algorithm
400 Resize(GetDefaultSize());
401
402 // Map main frame
403 MapWindow();
404}
405
407{
408 Disconnect();
409 // Clean up used widgets: frames, buttons, layout hints
410 Cleanup();
411 delete fLowBGMarker1;
412 delete fHighBGMarker1;
413 delete fLowBGMarker2;
414 delete fHighBGMarker2;
415 delete fLowGateMarker;
416 delete fHighGateMarker;
417 delete fHighPeakMarker;
418 delete fLowPeakMarker;
419 delete fPeakMarker;
420}
421
423{
424 // Draws function graphics in randomly chosen interval
425 TCanvas* fCanvas = fProjectionCanvas->GetCanvas();
426 fCanvas->cd();
427 fProjection->Draw("hist");
429 if((fAutoUpdateCheckButton != nullptr) && fAutoUpdateCheckButton->IsDown()) {
431 }
432 if(((fBGCheckButton1 != nullptr) && fBGCheckButton1->IsDown()) || ((fBGCheckButton2 != nullptr) && fBGCheckButton2->IsDown())) {
433 fProjection->ShowBackground(static_cast<Int_t>(fBGParamEntry->GetNumberEntry()->GetIntNumber()));
434 }
435 fCanvas->Update();
436 fGateCanvas->GetCanvas()->cd();
437}
438
440{
441 if(fPeak == nullptr) {
442 std::cerr << "Something went wrong and the peak is a nullptr?" << std::endl;
443 return;
444 }
448 fGateCanvas->GetCanvas()->cd();
450 DrawPeak();
451 fGateCanvas->GetCanvas()->Update();
452}
453
455{
456 if(fPeak != nullptr) { fPeak->Draw("same"); }
457}
458
460{
461 if((fBGCheckButton1 != nullptr) && fBGCheckButton1->IsDown()) {
462 fBGParamEntry->SetState(true);
463 } else {
464 fBGParamEntry->SetState(false);
465 }
466}
467
469{
470 fGateSlider->SetPosition(fGateEntryLow->GetNumber(), fGateEntryHigh->GetNumber());
471 fGateSlider->SetRange(fGateEntryLow->GetNumMin(), fGateEntryHigh->GetNumMax());
472}
473
475{
476 fBGSlider1->SetPosition(fBGEntryLow1->GetNumber(), fBGEntryHigh1->GetNumber());
477 fBGSlider1->SetRange(fBGEntryLow1->GetNumMin(), fBGEntryHigh1->GetNumMax());
478}
479
481{
482 fBGSlider2->SetPosition(fBGEntryLow2->GetNumber(), fBGEntryHigh2->GetNumber());
483 fBGSlider2->SetRange(fBGEntryLow2->GetNumMin(), fBGEntryHigh2->GetNumMax());
484}
485
487{
488 // Something has happened, so we have to let the sliders know about it
489 // This is as simple as checking the status of the "main" entry boxes
493}
494
496{
497 // Something has happened, so we have to let the sliders know about it
498 // This is as simple as checking the status of the "main" entry boxes
499 // The range has to be set first so that the other slider pieces don't get confused.
502 fPeakSlider->SetPointerPosition(fPeakValue);
503}
504
506{
507 // for now this is hard coded from 1 to 10, might want to change the upper limit somehow?
508 fBinningSlider->SetRange(1, fMaxBinning);
509 fBinningSlider->SetPosition(1);
510}
511
513{
514 // Handle slider widgets.
515 Int_t index = 0;
516 auto* frm = reinterpret_cast<TGFrame*>(gTQSender);
517 if(frm->IsA()->InheritsFrom(TGSlider::Class())) {
518 auto* slider = static_cast<TGSlider*>(frm);
519 index = slider->WidgetId();
520 } else {
521 auto* slider = static_cast<TGDoubleSlider*>(frm);
522 index = slider->WidgetId();
523 }
524
525 switch(index) {
526 case kGateSlider:
527 fGateEntryLow->SetNumber(fGateSlider->GetMinPosition());
528 fGateEntryHigh->SetNumber(fGateSlider->GetMaxPosition());
530 if((fAutoUpdateCheckButton != nullptr) && fAutoUpdateCheckButton->IsDown()) {
533 }
534 break;
535 case kBGSlider1:
536 fBGEntryLow1->SetNumber(fBGSlider1->GetMinPosition());
537 fBGEntryHigh1->SetNumber(fBGSlider1->GetMaxPosition());
539 if((fAutoUpdateCheckButton != nullptr) && fAutoUpdateCheckButton->IsDown()) {
540 MakeBGHisto1();
542 }
543 break;
544 case kBGSlider2:
545 fBGEntryLow2->SetNumber(fBGSlider2->GetMinPosition());
546 fBGEntryHigh2->SetNumber(fBGSlider2->GetMaxPosition());
548 if((fAutoUpdateCheckButton != nullptr) && fAutoUpdateCheckButton->IsDown()) {
549 MakeBGHisto2();
551 }
552 break;
553 case kPeakSlider:
554 fPeakLowValue = fPeakSlider->GetMinPosition();
555 fPeakHighValue = fPeakSlider->GetMaxPosition();
556 fPeakValue = fPeakSlider->GetPointerPosition();
558 break;
559 case kBinningSlider:
561 break;
562 };
563}
564
566{
567 static int old_selection = -1;
568 fGateAxis = fAxisCombo->GetSelected();
569
570 if(old_selection != fGateAxis) {
571 old_selection = fGateAxis;
572 delete fProjection;
573 if(fGateAxis == 0) {
574 std::cout << "Selecting the x axis" << std::endl;
575 fProjection = fMatrix->ProjectionY();
576 } else {
577 std::cout << "Selecting the y axis" << std::endl;
578 fProjection = fMatrix->ProjectionX();
579 }
580
581 fProjectionCanvas->GetCanvas()->cd();
582 fProjection->Draw("HIST");
584 fProjectionCanvas->GetCanvas()->Update();
585 }
586}
587
589{
590 static int oldPeakId = -1;
591 int peakId = fPeakCombo->GetSelected();
592
593 if(oldPeakId != peakId) {
594 oldPeakId = peakId;
595 if(fPeak != nullptr) { fPeakFitter->RemovePeak(fPeak); }
596 switch(peakId) {
597 case kGauss:
598 std::cout << "Selecting gaussian peak" << std::endl;
599 fPeak = static_cast<TSinglePeak*>(TGauss::Class()->New());
600 std::cout << "fPeak = " << fPeak << std::endl;
601 break;
602 case kRWPeak:
603 std::cout << "Selecting radware peak" << std::endl;
604 fPeak = static_cast<TSinglePeak*>(TRWPeak::Class()->New());
605 break;
606 case kABPeak:
607 std::cout << "Selecting two hit addback peak" << std::endl;
608 fPeak = static_cast<TSinglePeak*>(TABPeak::Class()->New());
609 break;
610 case kAB3Peak:
611 std::cout << "Selecting three hit addback peak" << std::endl;
612 fPeak = static_cast<TSinglePeak*>(TAB3Peak::Class()->New());
613 break;
614 default:
615 std::cerr << "Unknown peak id " << peakId << ", only know kGauss (" << kGauss << "), kRWPeak (" << kRWPeak << "), kABPeak (" << kABPeak << "), and kAB3Peak (" << kAB3Peak << ")" << std::endl;
616 break;
617 }
620 }
621}
622
624{
625 if(fLowPeakMarker == nullptr) {
626 fLowPeakMarker = new GMarker();
627 }
628 if(fHighPeakMarker == nullptr) {
629 fHighPeakMarker = new GMarker();
630 }
631 if(fPeakMarker == nullptr) {
632 fPeakMarker = new GMarker();
633 }
634 if(fSubtractedBinHist != nullptr) {
638
645
646 double low_peak_bin_edge = fSubtractedBinHist->GetXaxis()->GetBinLowEdge(fLowPeakMarker->GetBinX());
647 double high_peak_bin_edge = fSubtractedBinHist->GetXaxis()->GetBinLowEdge(fHighPeakMarker->GetBinX());
648 double peak_bin_edge = fSubtractedBinHist->GetXaxis()->GetBinLowEdge(fPeakMarker->GetBinX());
649
650 fLowPeakMarker->SetLineX(low_peak_bin_edge, low_peak_bin_edge, fSubtractedBinHist->GetMinimum(), fSubtractedBinHist->GetMaximum());
651 fLowPeakMarker->SetColor(kMagenta);
652
653 fHighPeakMarker->SetLineX(high_peak_bin_edge, high_peak_bin_edge, fSubtractedBinHist->GetMinimum(), fSubtractedBinHist->GetMaximum());
654 fHighPeakMarker->SetColor(kMagenta);
655
656 fPeakMarker->SetLineX(peak_bin_edge, peak_bin_edge, fSubtractedBinHist->GetMinimum(), fSubtractedBinHist->GetMaximum());
657 fPeakMarker->SetColor(kMagenta);
658 fPeakMarker->SetStyle(kDashed);
659
660 fGateCanvas->GetCanvas()->cd();
663 fPeakMarker->Draw();
664 fGateCanvas->GetCanvas()->Update();
665 }
666}
667
668void TBGSubtraction::DrawBGMarkers(TGCheckButton*& check_button, GMarker*& low_marker, GMarker*& high_marker, TGNumberEntry*& low_entry, TGNumberEntry*& high_entry, Color_t color)
669{
670 // Only Draw the BG Markers if BG is applied.
671 if((check_button != nullptr) && check_button->IsDown()) {
672 if(low_marker == nullptr) {
673 low_marker = new GMarker();
674 low_marker->SetHist(fProjection);
675 }
676 if(high_marker == nullptr) {
677 high_marker = new GMarker();
678 high_marker->SetHist(fProjection);
679 }
680 low_marker->SetLocalX(low_entry->GetNumber());
681 high_marker->SetLocalX(high_entry->GetNumber());
682 low_marker->SetBinX(fProjection->GetXaxis()->FindBin(low_marker->GetLocalX()));
683 high_marker->SetBinX(fProjection->GetXaxis()->FindBin(high_marker->GetLocalX()));
684 double low_bg_bin_edge = fProjection->GetXaxis()->GetBinLowEdge(low_marker->GetBinX());
685 double high_bg_bin_edge = fProjection->GetXaxis()->GetBinLowEdge(high_marker->GetBinX());
686
687 low_marker->SetLineX(low_bg_bin_edge, low_bg_bin_edge, fProjection->GetMinimum(), fProjection->GetMaximum());
688 low_marker->SetColor(color);
689
690 high_marker->SetLineX(high_bg_bin_edge, high_bg_bin_edge, fProjection->GetMinimum(), fProjection->GetMaximum());
691 high_marker->SetColor(color);
692
693 fProjectionCanvas->GetCanvas()->cd();
694 low_marker->Draw();
695 high_marker->Draw();
696 fProjectionCanvas->GetCanvas()->Update();
697 }
698}
699
704
709
716
718{
719 if(fLowGateMarker == nullptr) {
720 fLowGateMarker = new GMarker();
722 }
723 if(fHighGateMarker == nullptr) {
724 fHighGateMarker = new GMarker();
726 }
727
730 fLowGateMarker->SetBinX(fProjection->GetXaxis()->FindBin(fLowGateMarker->GetLocalX()));
732
733 double low_gate_bin_edge = fProjection->GetXaxis()->GetBinLowEdge(fLowGateMarker->GetBinX());
734 double high_gate_bin_edge = fProjection->GetXaxis()->GetBinLowEdge(fHighGateMarker->GetBinX());
735
736 fLowGateMarker->SetLineX(low_gate_bin_edge, low_gate_bin_edge, fProjection->GetMinimum(), fProjection->GetMaximum());
737 fLowGateMarker->SetColor(kGreen);
738
739 fHighGateMarker->SetLineX(high_gate_bin_edge, high_gate_bin_edge, fProjection->GetMinimum(), fProjection->GetMaximum());
740 fHighGateMarker->SetColor(kGreen);
741
742 fProjectionCanvas->GetCanvas()->cd();
745
746 fProjectionCanvas->GetCanvas()->Update();
747}
748
750{
751 auto* entry = reinterpret_cast<TGNumberEntry*>(gTQSender);
752 int index = entry->WidgetId();
753
754 // When we do an entry, update the corresponding slider...this then performs the gating.
755 switch(index) {
756 case kGateLowEntry:
757 if(fGateEntryLow->GetNumber() > fGateEntryHigh->GetNumber()) {
758 fGateEntryLow->SetNumber(fGateEntryHigh->GetNumber());
760 fGateSlider->PositionChanged();
761 }
762 break;
763 case kGateHighEntry:
764 if(fGateEntryHigh->GetNumber() < fGateEntryLow->GetNumber()) {
765 fGateEntryHigh->SetNumber(fGateEntryLow->GetNumber());
767 }
768 break;
769 case kBGLowEntry1:
770 if(fBGEntryLow1->GetNumber() > fBGEntryHigh1->GetNumber()) {
771 fBGEntryLow1->SetNumber(fBGEntryHigh1->GetNumber());
773 }
774 break;
775 case kBGHighEntry1:
776 if(fBGEntryHigh1->GetNumber() < fBGEntryLow1->GetNumber()) {
777 fBGEntryHigh1->SetNumber(fBGEntryLow1->GetNumber());
779 }
780 break;
781 case kBGLowEntry2:
782 if(fBGEntryLow2->GetNumber() > fBGEntryHigh2->GetNumber()) {
783 fBGEntryLow2->SetNumber(fBGEntryHigh2->GetNumber());
785 }
786 break;
787 case kBGHighEntry2:
788 if(fBGEntryHigh2->GetNumber() < fBGEntryLow2->GetNumber()) {
789 fBGEntryHigh2->SetNumber(fBGEntryLow2->GetNumber());
791 }
792 break;
793 };
794}
795
797{
798 // If we zoom in on this canvas, we need to update the sliders and Number boxes appropriately.
799 Double_t xmin = 0.;
800 Double_t ymin = 0.;
801 Double_t xmax = 0.;
802 Double_t ymax = 0.;
803 fGateCanvas->GetCanvas()->GetRange(xmin, ymin, xmax, ymax);
804 // The first thing we need to do is set new limits on the number entries
805 // Start by getting the old limits, this should be the same as the old histo range
806 Double_t old_limit_min = fPeakLowLimit;
807 Double_t old_limit_max = fPeakHighLimit;
808
809 // Get the old value
810 Double_t old_lower_peak_val = fPeakLowValue;
811 Double_t old_upper_peak_val = fPeakHighValue;
812 Double_t old_peak_val = fPeakValue;
813 // Now maintain the ratio of the position
814 Double_t rel_lower_peak_val = (old_lower_peak_val - old_limit_min) / (old_limit_max - old_limit_min);
815 Double_t rel_upper_peak_val = (old_upper_peak_val - old_limit_min) / (old_limit_max - old_limit_min);
816 Double_t rel_peak_val = (old_peak_val - old_limit_min) / (old_limit_max - old_limit_min);
817 // set the new positions
818 fPeakLowValue = xmin + rel_lower_peak_val * (xmax - xmin);
819 fPeakHighValue = xmin + rel_upper_peak_val * (xmax - xmin);
820 fPeakValue = xmin + rel_peak_val * (xmax - xmin);
821 // Set the new limits
822 fPeakLowLimit = xmin;
823 fPeakHighLimit = xmax;
824
827}
828
830{
831 // If we zoom in on this canvas, we need to update the sliders and Number boxes appropriately.
832 Double_t xmin = 0.;
833 Double_t ymin = 0.;
834 Double_t xmax = 0.;
835 Double_t ymax = 0.;
836 fProjectionCanvas->GetCanvas()->GetRange(xmin, ymin, xmax, ymax);
837 // The first thing we need to do is set new limits on the number entries
838 // Start by getting the old limits, this should be the same as the old histo range
839 Double_t old_limit_min = fGateEntryLow->GetNumMin();
840 Double_t old_limit_max = fGateEntryLow->GetNumMax();
841
842 // Get the old value
843 Double_t old_lower_gate_val = fGateEntryLow->GetNumber();
844 Double_t old_upper_gate_val = fGateEntryHigh->GetNumber();
845 Double_t old_lower_bg1_val = fBGEntryLow1->GetNumber();
846 Double_t old_upper_bg1_val = fBGEntryHigh1->GetNumber();
847 Double_t old_lower_bg2_val = fBGEntryLow2->GetNumber();
848 Double_t old_upper_bg2_val = fBGEntryHigh2->GetNumber();
849 // Now maintain the ratio of the position
850 Double_t rel_lower_gate_val = (old_lower_gate_val - old_limit_min) / (old_limit_max - old_limit_min);
851 Double_t rel_upper_gate_val = (old_upper_gate_val - old_limit_min) / (old_limit_max - old_limit_min);
852 Double_t rel_lower_bg1_val = (old_lower_bg1_val - old_limit_min) / (old_limit_max - old_limit_min);
853 Double_t rel_upper_bg1_val = (old_upper_bg1_val - old_limit_min) / (old_limit_max - old_limit_min);
854 Double_t rel_lower_bg2_val = (old_lower_bg2_val - old_limit_min) / (old_limit_max - old_limit_min);
855 Double_t rel_upper_bg2_val = (old_upper_bg2_val - old_limit_min) / (old_limit_max - old_limit_min);
856 // set the new positions
857 fGateEntryLow->SetNumber(xmin + rel_lower_gate_val * (xmax - xmin));
858 fGateEntryHigh->SetNumber(xmin + rel_upper_gate_val * (xmax - xmin));
859 fBGEntryLow1->SetNumber(xmin + rel_lower_bg1_val * (xmax - xmin));
860 fBGEntryHigh1->SetNumber(xmin + rel_upper_bg1_val * (xmax - xmin));
861 fBGEntryLow2->SetNumber(xmin + rel_lower_bg2_val * (xmax - xmin));
862 fBGEntryHigh2->SetNumber(xmin + rel_upper_bg2_val * (xmax - xmin));
863 // Set the new limits
864 fGateEntryLow->SetLimitValues(xmin, xmax);
865 fGateEntryHigh->SetLimitValues(xmin, xmax);
866 fBGEntryLow1->SetLimitValues(xmin, xmax);
867 fBGEntryHigh1->SetLimitValues(xmin, xmax);
868 fBGEntryLow2->SetLimitValues(xmin, xmax);
869 fBGEntryHigh2->SetLimitValues(xmin, xmax);
870
873
874 if((fAutoUpdateCheckButton != nullptr) && fAutoUpdateCheckButton->IsDown()) {
875 DoAllGates(); // Figure out how to make this happen on histo zooms and not scaling canvas
876 }
877 // DoGateProjection();
878}
879
886
888{
889 delete fGateHist;
890
891 const char* proj_name = Form("gate_%d_%d", static_cast<Int_t>(fGateEntryLow->GetNumber()),
892 static_cast<Int_t>(fGateEntryHigh->GetNumber()));
893
894 fGateAxis = fAxisCombo->GetSelected();
895
896 if(fGateAxis == 0) {
897 fGateHist = fMatrix->ProjectionX(proj_name, fMatrix->GetYaxis()->FindBin(fGateSlider->GetMinPosition()),
898 fMatrix->GetYaxis()->FindBin(fGateSlider->GetMaxPosition()));
899 } else {
900 fGateHist = fMatrix->ProjectionY(proj_name, fMatrix->GetXaxis()->FindBin(fGateSlider->GetMinPosition()),
901 fMatrix->GetXaxis()->FindBin(fGateSlider->GetMaxPosition()));
902 }
903 fGateHist->Sumw2();
904}
905
907{
908 Double_t xmin = 0.;
909 Double_t ymin = 0.;
910 Double_t xmax = 0.;
911 Double_t ymax = 0.;
912 fProjectionCanvas->GetCanvas()->GetRange(xmin, ymin, xmax, ymax);
913
914 delete fBGHist1;
915
916 const char* bg_name1 =
917 Form("bg1_%d_%d", static_cast<Int_t>(fBGEntryLow1->GetNumber()), static_cast<Int_t>(fBGEntryHigh1->GetNumber()));
918
919 if(fGateAxis == 0) {
920 fBGHist1 = fMatrix->ProjectionX(bg_name1, fMatrix->GetYaxis()->FindBin(fBGSlider1->GetMinPosition()),
921 fMatrix->GetYaxis()->FindBin(fBGSlider1->GetMaxPosition()));
922 } else {
923 fBGHist1 = fMatrix->ProjectionY(bg_name1, fMatrix->GetXaxis()->FindBin(fBGSlider1->GetMinPosition()),
924 fMatrix->GetXaxis()->FindBin(fBGSlider1->GetMaxPosition()));
925 }
926
927 fBGHist1->Sumw2();
928}
929
931{
932 delete fBGHist2;
933
934 const char* bg_name2 =
935 Form("bg2_%d_%d", static_cast<Int_t>(fBGEntryLow2->GetNumber()), static_cast<Int_t>(fBGEntryHigh2->GetNumber()));
936
937 if(fGateAxis == 0) {
938 fBGHist2 = fMatrix->ProjectionX(bg_name2, fMatrix->GetYaxis()->FindBin(fBGSlider2->GetMinPosition()),
939 fMatrix->GetYaxis()->FindBin(fBGSlider2->GetMaxPosition()));
940 } else {
941 fBGHist2 = fMatrix->ProjectionY(bg_name2, fMatrix->GetXaxis()->FindBin(fBGSlider2->GetMinPosition()),
942 fMatrix->GetXaxis()->FindBin(fBGSlider2->GetMaxPosition()));
943 }
944
945 fBGHist2->Sumw2();
946}
947
949{
950 TH1* bg_hist = nullptr;
951 Double_t under_peak_bg = 0.0;
952 // Make sure one of the two buttons are checked
953 if(((fBGCheckButton1 != nullptr) && fBGCheckButton1->IsDown()) || ((fBGCheckButton2 != nullptr) && fBGCheckButton2->IsDown())) {
954 bg_hist = fProjection->ShowBackground(static_cast<Int_t>(fBGParamEntry->GetNumberEntry()->GetIntNumber()));
955 under_peak_bg = bg_hist->Integral(bg_hist->FindBin(fGateSlider->GetMinPosition()),
956 bg_hist->FindBin(fGateSlider->GetMaxPosition()));
957 }
958
959 // Add the two background regions together;
960 Double_t bg_region = 0.0;
961 if((fBGCheckButton1 != nullptr) && fBGCheckButton1->IsDown()) {
962 bg_region += fProjection->Integral(fProjection->FindBin(fBGSlider1->GetMinPosition()),
963 fProjection->FindBin(fBGSlider1->GetMaxPosition()));
964 }
965 if((fBGCheckButton2 != nullptr) && fBGCheckButton2->IsDown()) {
966 bg_region += fProjection->Integral(fProjection->FindBin(fBGSlider2->GetMinPosition()),
967 fProjection->FindBin(fBGSlider2->GetMaxPosition()));
968 }
969 Double_t ratio = 0;
970
971 if(bg_region != 0) {
972 ratio = under_peak_bg / bg_region;
973 }
974
975 Int_t first_bin = -1;
976 Int_t last_bin = -1;
977 if(fSubtractedBinHist != nullptr) {
978 // Get old axis range
979 first_bin = fSubtractedBinHist->GetXaxis()->GetFirst();
980 last_bin = fSubtractedBinHist->GetXaxis()->GetLast();
981 delete fSubtractedBinHist;
982 delete fSubtractedHist;
983 }
984 // create new subtracted hist
985 const char* sub_name = Form("%s_%s", fGateHist->GetName(), fBGHist1->GetName()); // TO DO: Come up with better naming
986 fSubtractedHist = static_cast<TH1*>(fGateHist->Clone(sub_name));
987 if((fBGCheckButton1 != nullptr) && fBGCheckButton1->IsDown()) {
988 fSubtractedHist->Add(fBGHist1, -ratio);
989 }
990 if((fBGCheckButton2 != nullptr) && fBGCheckButton2->IsDown()) {
991 fSubtractedHist->Add(fBGHist2, -ratio);
992 }
993 fSubtractedBinHist = static_cast<TH1*>(fSubtractedHist->Clone(Form("%s_bin", sub_name)));
994 fGateCanvas->GetCanvas()->cd();
995 if(fSubtractedBinHist != nullptr) {
996 fSubtractedBinHist->GetXaxis()->SetRange(first_bin, last_bin);
997 fSubtractedBinHist->Draw("hist");
998 }
1000 fGateCanvas->GetCanvas()->Update();
1001}
1002
1003// void TBGSubtraction::DoProjection()
1004//{
1005// if(fGateHist != nullptr) {
1006// delete fGateHist;
1007// }
1008//
1009// const char* proj_name = Form("gate_%d_%d", static_cast<Int_t>(fGateEntryLow->GetNumber()),
1010// static_cast<Int_t>(fGateEntryHigh->GetNumber()));
1011//
1012// fGateAxis = fAxisCombo->GetSelected();
1013//
1014// if(fGateAxis == 0) {
1015// fGateHist = fMatrix->ProjectionX(proj_name, fMatrix->GetYaxis()->FindBin(fGateSlider->GetMinPosition()),
1016// fMatrix->GetYaxis()->FindBin(fGateSlider->GetMaxPosition()));
1017// } else {
1018// fGateHist = fMatrix->ProjectionY(proj_name, fMatrix->GetXaxis()->FindBin(fGateSlider->GetMinPosition()),
1019// fMatrix->GetXaxis()->FindBin(fGateSlider->GetMaxPosition()));
1020// }
1021// fGateHist->Sumw2();
1022//
1023// if(fBGHist1 != nullptr) {
1024// delete fBGHist1;
1025// }
1026// if(fBGHist2 != nullptr) {
1027// delete fBGHist2;
1028// }
1029// const char* bg_name1 =
1030// Form("bg1_%d_%d", static_cast<Int_t>(fBGEntryLow1->GetNumber()), static_cast<Int_t>(fBGEntryHigh1->GetNumber()));
1031// const char* bg_name2 =
1032// Form("bg2_%d_%d", static_cast<Int_t>(fBGEntryLow2->GetNumber()), static_cast<Int_t>(fBGEntryHigh2->GetNumber()));
1033//
1034// if(fGateAxis == 0) {
1035// fBGHist1 = fMatrix->ProjectionX(bg_name1, fMatrix->GetYaxis()->FindBin(fBGSlider1->GetMinPosition()),
1036// fMatrix->GetYaxis()->FindBin(fBGSlider1->GetMaxPosition()));
1037// fBGHist2 = fMatrix->ProjectionX(bg_name1, fMatrix->GetYaxis()->FindBin(fBGSlider2->GetMinPosition()),
1038// fMatrix->GetYaxis()->FindBin(fBGSlider2->GetMaxPosition()));
1039// } else {
1040// fBGHist1 = fMatrix->ProjectionY(bg_name1, fMatrix->GetXaxis()->FindBin(fBGSlider1->GetMinPosition()),
1041// fMatrix->GetXaxis()->FindBin(fBGSlider1->GetMaxPosition()));
1042// fBGHist2 = fMatrix->ProjectionY(bg_name2, fMatrix->GetXaxis()->FindBin(fBGSlider2->GetMinPosition()),
1043// fMatrix->GetXaxis()->FindBin(fBGSlider2->GetMaxPosition()));
1044// }
1045//
1046// fBGHist1->Sumw2();
1047// fBGHist2->Sumw2();
1048// TH1* bg_hist = nullptr;
1049// Double_t under_peak_bg = 0.0;
1050// //Make sure one of the two buttons are checked
1051// if(((fBGCheckButton1 != nullptr) && fBGCheckButton1->IsDown()) || ((fBGCheckButton2 != nullptr) && fBGCheckButton2->IsDown())) {
1052// bg_hist = fProjection->ShowBackground(fBGParamEntry->GetNumberEntry()->GetIntNumber());
1053// under_peak_bg = bg_hist->Integral(bg_hist->FindBin(fGateSlider->GetMinPosition()),
1054// bg_hist->FindBin(fGateSlider->GetMaxPosition()));
1055// }
1056//
1057// //Add the two background regions together;
1058// Double_t bg_region = 0.0;
1059// if((fBGCheckButton1 != nullptr) && fBGCheckButton1->IsDown()){
1060// bg_region += fProjection->Integral(fProjection->FindBin(fBGSlider1->GetMinPosition()),
1061// fProjection->FindBin(fBGSlider1->GetMaxPosition()));
1062// }
1063// if((fBGCheckButton2 != nullptr) && fBGCheckButton2->IsDown()){
1064// bg_region += fProjection->Integral(fProjection->FindBin(fBGSlider2->GetMinPosition()),
1065// fProjection->FindBin(fBGSlider2->GetMaxPosition()));
1066// }
1067// Double_t ratio = 0;
1068//
1069// if(bg_region != 0) {
1070// ratio = under_peak_bg / bg_region;
1071// }
1072//
1073// Int_t first_bin = -1, last_bin = -1;
1074// if(fSubtractedHist != nullptr) {
1075// // Get old axis range
1076// first_bin = fSubtractedHist->GetXaxis()->GetFirst();
1077// last_bin = fSubtractedHist->GetXaxis()->GetLast();
1078// delete fSubtractedHist;
1079// }
1080// const char* sub_name = Form("%s_%s", fGateHist->GetName(), fBGHist1->GetName()); //TO DO: Come up with better naming
1081//
1082// fSubtractedHist = static_cast<TH1*>(fGateHist->Clone(sub_name));
1083// if((fBGCheckButton1 != nullptr) && fBGCheckButton1->IsDown()) {
1084// fSubtractedHist->Add(fBGHist1, -ratio);
1085// }
1086// if((fBGCheckButton2 != nullptr) && fBGCheckButton2->IsDown()) {
1087// fSubtractedHist->Add(fBGHist2, -ratio);
1088// }
1089//
1090// fGateCanvas->GetCanvas()->cd();
1091// if(fSubtractedHist != nullptr) {
1092// fSubtractedHist->GetXaxis()->SetRange(first_bin, last_bin);
1093// fSubtractedHist->Draw("hist");
1094// }
1095// DrawPeakMarkers();
1096// fGateCanvas->GetCanvas()->Update();
1097// }
1098
1100{
1101 if(fSubtractedBinHist != nullptr) {
1102 auto* canvas = new TCanvas;
1103 canvas->cd();
1104 fSubtractedBinHist->DrawCopy();
1105 canvas->Update();
1106 }
1107}
1108
1110{
1111 // Find if there is a file name
1112 const char* file_name = fWrite2FileName->GetText();
1113
1114 if(file_name == nullptr) {
1115 std::cout << "Please enter a file name" << std::endl;
1116 return;
1117 }
1118
1119 TFile f(file_name, "Update");
1120 std::cout << "Writing " << fHistogramDescription->GetText() << " histograms to " << f.GetName() << std::endl;
1121 if(fSubtractedHist != nullptr) {
1122 if(fHistogramDescription->GetText() != nullptr) {
1123 fSubtractedHist->SetTitle(fHistogramDescription->GetText());
1124 }
1125 fSubtractedHist->Write();
1126 }
1127
1128 if(fBGHist1 != nullptr) {
1129 if(fHistogramDescription->GetText() != nullptr) {
1130 fBGHist1->SetTitle(Form("%s Background 1", fHistogramDescription->GetText()));
1131 }
1132
1133 fBGHist1->Write();
1134 }
1135
1136 if(fBGHist2 != nullptr) {
1137 if(fHistogramDescription->GetText() != nullptr) {
1138 fBGHist2->SetTitle(Form("%s Background 2", fHistogramDescription->GetText()));
1139 }
1140
1141 fBGHist2->Write();
1142 }
1143
1144 if(fGateHist != nullptr) {
1145 if(fHistogramDescription->GetText() != nullptr) {
1146 fGateHist->SetTitle(Form("%s Gate only", fHistogramDescription->GetText()));
1147 }
1148
1149 fGateHist->Write();
1150 }
1151}
1152
1153void TBGSubtraction::GateStatusInfo(Int_t event, Int_t px, Int_t py, TObject* selected)
1154{
1155 fGateCanvas->GetCanvas()->cd();
1156 StatusInfo(event, px, py, selected);
1157}
1158
1159void TBGSubtraction::ProjectionStatusInfo(Int_t event, Int_t px, Int_t py, TObject* selected)
1160{
1161 fProjectionCanvas->GetCanvas()->cd();
1162 StatusInfo(event, px, py, selected);
1163}
1164
1165void TBGSubtraction::StatusInfo(Int_t, Int_t px, Int_t py, TObject* selected)
1166{
1167 fProjectionStatus->SetText(selected->GetName(), 0);
1168 fProjectionStatus->SetText(selected->GetObjectInfo(px, py), 1);
1169}
1170
1172{
1173 // Here we want to check the status of the update checkbox, and then do the following:
1174 if((fAutoUpdateCheckButton == nullptr) || !fAutoUpdateCheckButton->IsDown()) {
1175 // 1. the checkbox has been turned off, this means we want to disable anything that can
1176 // mess with the user.
1177 fPeakFitButton->SetEnabled(false);
1178 fWrite2FileButton->SetEnabled(false);
1179 } else {
1180 // 2. the checkbox has been turned on, this means we want to enable features as well as take all
1181 // of the current gates
1182 fPeakFitButton->SetEnabled(true);
1183 fWrite2FileButton->SetEnabled(true);
1184 DoAllGates();
1186 }
1187}
1188
1190{
1191 // first get the min. and max. of the old histogram and calculate where
1192 // they are in percent of the unzoomed range
1193 double minimumRatio = 0.;
1194 double maximumRatio = 1.;
1195 if(fSubtractedBinHist != nullptr) {
1196 double oldMinimum = fSubtractedBinHist->GetMinimum();
1197 double oldMaximum = fSubtractedBinHist->GetMaximum();
1198 fSubtractedBinHist->GetYaxis()->UnZoom();
1199 double unZoomedMinimum = fSubtractedBinHist->GetMinimum();
1200 double unZoomedMaximum = fSubtractedBinHist->GetMaximum();
1201 minimumRatio = (oldMinimum - unZoomedMinimum) / (unZoomedMaximum - unZoomedMinimum);
1202 maximumRatio = (oldMaximum - unZoomedMinimum) / (unZoomedMaximum - unZoomedMinimum);
1203 delete fSubtractedBinHist;
1204 }
1205 fSubtractedBinHist = fSubtractedHist->Rebin(fBinningSlider->GetPosition(), Form("%s_bin", fSubtractedHist->GetName()));
1206 fSubtractedBinHist->SetDirectory(nullptr);
1207 fGateCanvas->GetCanvas()->cd();
1208 fSubtractedBinHist->GetXaxis()->SetRangeUser(fGateCanvas->GetCanvas()->GetUxmin(), fGateCanvas->GetCanvas()->GetUxmax());
1209 // we only need (and want) to set the range of the y-axis if it was zoomed in
1210 if(minimumRatio != 0. || maximumRatio != 1.) {
1211 double unZoomedMinimum = fSubtractedBinHist->GetMinimum();
1212 double unZoomedMaximum = fSubtractedBinHist->GetMaximum();
1213 fSubtractedBinHist->GetYaxis()->SetRangeUser(unZoomedMinimum + minimumRatio * (unZoomedMaximum - unZoomedMinimum),
1214 unZoomedMinimum + maximumRatio * (unZoomedMaximum - unZoomedMinimum));
1215 }
1216 fSubtractedBinHist->Draw("hist");
1218 fGateCanvas->GetCanvas()->Update();
1219}
TH2D * mat
Definition UserFillObj.h:12
void SetLocalX(const double &val)
Definition GCanvas.h:113
int GetBinX() const
Definition GCanvas.h:140
void Draw(Option_t *opt="") override
Definition GCanvas.h:37
void SetStyle(Style_t style)
Definition GCanvas.h:68
void SetBinX(const int &val)
Definition GCanvas.h:127
void SetHist(const TH1 *val)
Definition GCanvas.h:151
void SetLineX(double x1, double x2, double y1, double y2)
Definition GCanvas.h:89
double GetLocalX() const
Definition GCanvas.h:130
void SetColor(Color_t color)
Definition GCanvas.h:58
TSinglePeak * fPeak
the peak to be fit (will be a class that inherits from TSinglePeak)
TGNumberEntry * fBGEntryHigh1
TPeakFitter * fPeakFitter
the peak fitter that fPeak is added to
TGNumberEntry * fGateEntryLow
TRootEmbeddedCanvas * fProjectionCanvas
TGHorizontalFrame * fButtonFrame
TGComboBox * fPeakCombo
Double_t fPeakLowLimit
lower limit for peak slider range
TGVerticalFrame * fProjectionFrame
void DoProjectionCanvasZoomed()
TGHSlider * fBinningSlider
TGDoubleHSlider * fBGSlider2
GMarker * fLowBGMarker2
TGCheckButton * fBGCheckButton1
TGNumberEntry * fBGEntryHigh2
TGTextEntry * fWrite2FileName
GMarker * fPeakMarker
void UpdateProjectionSliders()
TGTextButton * fWrite2FileButton
TGCheckButton * fAutoUpdateCheckButton
GMarker * fHighGateMarker
void StatusInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
TGNumberEntry * fBGEntryLow2
void SetStatusFromUpdateCheckButton()
TGHorizontalFrame * fPeakFitFrame
TBGSubtraction(TH2 *mat, const char *gate_axis="x", int maxBinning=20)
TGDoubleHSlider * fBGSlider1
TGLayoutHints * fBly
TGHorizontalFrame * fBGEntryFrame1
TGHorizontalFrame * fDescriptionFrame
TGHorizontalFrame * fBinningFrame
TGStatusBar * fProjectionStatus
TGHorizontalFrame * fBGParamFrame
void DrawBGMarkers(TGCheckButton *&check_button, GMarker *&low_marker, GMarker *&high_marker, TGNumberEntry *&low_entry, TGNumberEntry *&high_entry, Color_t color=kBlue)
Int_t fMaxBinning
maximum binning possible with binning slider (hard-coded, for now?)
TGTextEntry * fHistogramDescription
TGTextButton * fPeakFitButton
TGLabel * fBinningLabel
Double_t fPeakHighLimit
upper limit for peak slider range
GMarker * fHighBGMarker2
TGDoubleHSlider * fGateSlider
TGComboBox * fAxisCombo
TGLayoutHints * fLayoutCanvases
TGLayoutHints * fLayoutParam
TGNumberEntry * fBGParamEntry
GMarker * fLowPeakMarker
void ProjectionStatusInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
TGNumberEntry * fBGEntryLow1
GMarker * fHighPeakMarker
GMarker * fHighBGMarker1
GMarker * fLowGateMarker
TGCheckButton * fBGCheckButton2
GMarker * fLowBGMarker1
Double_t fPeakValue
centroid for fit
TRootEmbeddedCanvas * fGateCanvas
Double_t fPeakHighValue
high range for fit
void DoEntry(Long_t)
TGLabel * fBGParamLabel
TGTripleHSlider * fPeakSlider
TGHorizontalFrame * fGateEntryFrame
void GateStatusInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
Double_t fPeakLowValue
low range for fit
TGNumberEntry * fGateEntryHigh
TGLayoutHints * fBly1
void DoSlider(Int_t pos=0)
TGVerticalFrame * fGateFrame
TGHorizontalFrame * fBGEntryFrame2
void RemovePeak(TSinglePeak *peak)
Definition TPeakFitter.h:47
void SetRange(const Double_t &low, const Double_t &high)
void ResetInitFlag()
Definition TPeakFitter.h:72
void AddPeak(TSinglePeak *peak)
Definition TPeakFitter.h:42
TFitResultPtr Fit(TH1 *fit_hist, Option_t *opt="")
void Draw(Option_t *opt="") override
virtual void Centroid(const Double_t &centroid)=0