GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
Gate.cc
Go to the documentation of this file.
1
10
11/* STD */
12#include <iostream>
13
14/* ROOT */
15#include <Buttons.h>
16#include <TAttFill.h>
17#include <TAttLine.h>
18#include <TCanvas.h>
19#include <TLine.h>
20#include <TMarker.h>
21#include <TNamed.h>
22#include <TParameter.h>
23#include <TROOT.h>
24#include <TMath.h>
25#include <TVirtualX.h>
26#include <TQObject.h>
27
28/* GAMMA */
29#include <utils/Utilities.hh>
30#include "Gate.hh"
31
32/* apparently we have to do this explicitly for every type */
34// ClassImp(GamR::TK::Gate<Double_t>) ClassImp(GamR::TK::Gate<Float_t>)
35// ClassImp(GamR::TK::Gate<Int_t>)
36
37// ClassImp(GamR::TK::GateMap<Double_t>)
38// ClassImp(GamR::TK::GateMap<Float_t>)
39// ClassImp(GamR::TK::GateMap<Int_t>)
41
42// This was supposed to work according to the root documentation!
43// AND ALSO THE CODE /usr/include/root/Rtypes.h
44// templateClassImp(GamR::TK::Gate);
45
46namespace GamR {
47 namespace TK {
48 Gate::Gate(const char *name) : TNamed(name, name)
49 {
50 SetLineColor(8); SetFillStyle(3003); SetFillColor(8);
51 }
52
53 Gate::Gate(const char *name, const char *title) : TNamed(name, title)
54 {
55 SetLineColor(8); SetFillStyle(3003); SetFillColor(8);
56 }
57
58 Gate::Gate(const char *name, TVirtualPad *canvas, Option_t *opt) : TNamed(name, name)
59 {
60 SetLineColor(8); SetFillStyle(3003); SetFillColor(8);
61 this->SetGate(canvas, opt);
62 }
63
64 Gate::Gate(const char *name, const char *title, TVirtualPad *canvas, Option_t *opt) : TNamed(name, title)
65 {
66 SetLineColor(8); SetFillStyle(3003); SetFillColor(8);
67 this->SetGate(canvas, opt);
68 }
69
70 Gate::Gate(TVirtualPad *canvas, Option_t *opt)
71 {
72 SetLineColor(8); SetFillStyle(3003); SetFillColor(8);
73 this->SetGate(canvas, opt);
74 }
75
77 {
78 return this->SetGate(gPad->GetCanvas());
79 }
80
86 int Gate::SetGate(TVirtualPad *canvas, Option_t *opt)
87 {
88 TString sOpt(opt);
89 sOpt.ToLower();
90
91 canvas->SetCrosshair();
92
93 canvas->Update();
94
96 std::vector<std::string> messages = {"Click for lower bound of region, press any key to exit...", "Click for upper bound of region, press any key to exit..."};
97
98 int retval = click.GetClicks(canvas, 2, messages);
99
100 if (retval > 0) { // quit prematurely
101 std::cout << "gating cancelled" << std::endl;
102 canvas->SetCrosshair(0);
103 return retval;
104 }
105
106 double lowX = click.xs[0];
107 double lowY = click.ys[0];
108 double highX = click.xs[1];
109 double highY = click.ys[1];
110
111 canvas->SetCrosshair(0);
112 // set gate values
113 if (sOpt.Contains("x")) {
114 this->Low = lowX;
115 this->High = highX;
116 }
117 else if (sOpt.Contains("y")) {
118 this->Low = lowY;
119 this->High = highY;
120 }
121 else {
122 if ((highX - lowX) / (canvas->GetUxmax() - canvas->GetUxmin()) >=
123 (highY - lowY) / (canvas->GetUymax() - canvas->GetUymin())) {
124 this->Low = lowX;
125 this->High = highX;
126 } else {
127 this->Low = lowY;
128 this->High = highY;
129 }
130 }
131 Valid();
132 std::cout << *this << std::endl;
133 return retval;
134
135 }
136
148 template <size_t Meas, class TDetector>
149 Bool_t PassDetector(TDetector det, Bool_t calibrated, Int_t id)
150 {
151 if (id >= 0 && id != det.ID) {
152 return kFALSE;
153 } else if (calibrated) {
154 return Pass(det.template GetCal<Meas>());
155 } else {
156 return Pass(det.template Get<Meas>());
157 }
158 }
159
168 TH1D *Gate::ApplyY(TH2 *hist) const
169 {
170 TH1D *hOut;
171 TString name;
172 name.Form("%s_gx", hist->GetName());
173 double xmax = -1;
174 double xmin = -1;
175 if (gPad) {
176 xmax = gPad->GetUxmax();
177 xmin = gPad->GetUxmin();
178 }
179 hist->GetXaxis()->UnZoom();
180 hOut = hist->ProjectionX(name.Data(), hist->GetYaxis()->FindBin(this->Low), hist->GetYaxis()->FindBin(this->High));
181 if (gPad)
182 hist->GetXaxis()->SetRangeUser(xmin, xmax);
183 return hOut;
184 }
185
194 TH1D *Gate::ApplyY(TH2 *hist, const char *name) const
195 {
196 TH1D *hOut;
197 double xmax = -1;
198 double xmin = -1;
199 if (gPad) {
200 xmax = gPad->GetUxmax();
201 xmin = gPad->GetUxmin();
202 }
203 hist->GetXaxis()->UnZoom();
204 hOut = hist->ProjectionX(name, hist->GetYaxis()->FindBin(this->Low), hist->GetYaxis()->FindBin(this->High));
205 if (gPad)
206 hist->GetXaxis()->SetRangeUser(xmin, xmax);
207 return hOut;
208 }
209
218 TH1D *Gate::ApplyX(TH2 *hist) const
219 {
220 TH1D *hOut;
221 TString name;
222 name.Form("%s_gy", hist->GetName());
223 double ymax = -1;
224 double ymin = -1;
225 if (gPad) {
226 ymax = gPad->GetUymax();
227 ymin = gPad->GetUymin();
228 }
229 hist->GetYaxis()->UnZoom();
230 hOut = hist->ProjectionY(name.Data(), hist->GetXaxis()->FindBin(this->Low), hist->GetXaxis()->FindBin(this->High));
231 if (gPad)
232 hist->GetYaxis()->SetRangeUser(ymin, ymax);
233 return hOut;
234 }
235
244 TH1D *Gate::ApplyX(TH2 *hist, const char *name) const
245 {
246 TH1D *hOut;
247 double ymin = -1;
248 double ymax = -1;
249 if (gPad) {
250 ymax = gPad->GetUymax();
251 ymin = gPad->GetUymin();
252 }
253 hist->GetYaxis()->UnZoom();
254 hOut = hist->ProjectionY(name, hist->GetXaxis()->FindBin(this->Low), hist->GetXaxis()->FindBin(this->High));
255 if (gPad)
256 hist->GetYaxis()->SetRangeUser(ymin, ymax);
257 return hOut;
258 }
259
266 double Gate::GetIntegral(TH1 *hist) const
267 {
268 int iLowBin = hist->FindBin(this->Low);
269 int iHighBin = hist->FindBin(this->High);
270
271 double integral = 0;
272
273 for (int i = iLowBin; i <= iHighBin; i++) {
274 integral = integral + hist->GetBinContent(i) * hist->GetBinWidth(i);
275 }
276
277 return integral;
278 }
279
280 double Gate::GetIntegral(TH1 *hist, std::vector<Gate> back) const
281 {
282 int nData = 0;
283 double sumX = 0;
284 double sumY = 0;
285 double sumX2 = 0;
286 double sumXY = 0;
287 double sumY2 = 0;
288
289 int startGate = GetBinLow(hist);
290 int stopGate = GetBinHigh(hist);
291
292 for (auto &backgate : back) {
293 int startback = backgate.GetBinLow(hist);
294 int stopback = backgate.GetBinHigh(hist);
295 for (int i=startback; i<=stopback; ++i) {
296 nData++;
297 sumX += hist->GetBinCenter(i);
298 sumX2 += hist->GetBinCenter(i)*hist->GetBinCenter(i);
299 sumXY += hist->GetBinCenter(i)*hist->GetBinContent(i);
300 sumY += hist->GetBinContent(i);
301 sumY2 += hist->GetBinContent(i)*hist->GetBinContent(i);
302 }
303 }
304
305 double slope = (nData*sumXY - sumX*sumY)/(nData*sumX2-sumX*sumX);
306
307 double constant = (sumY*sumX2 - sumX*sumXY)/(nData*sumX2 - sumX*sumX);
308
309 double sumBackground = 0;
310 sumX = 0;
311 sumY = 0;
312 sumX2 = 0;
313 sumY2 = 0;
314 sumXY = 0;
315 for ( int i=startGate; i<= stopGate; ++i) {
316 double background = constant + slope*hist->GetBinCenter(i);
317 sumBackground += background;
318 double Y = hist->GetBinContent(i) - background;
319 sumY += Y;
320 sumXY += hist->GetBinCenter(i)*Y;
321 }
322
323 double posX = sumXY/sumY;
324 double area = (double)sumY;
325 double dArea = std::sqrt(area + 2*sumBackground);
326
327 return area;
328 }
329
337 double Gate::GetIntegral(TH1 *hist, Gate background) const
338 {
339 double peak = 0;
340 double back = 0;
341 peak = GetIntegral(hist);
342 back = background.GetIntegral(hist);
343 return peak - back*(double)GetBinWidth(hist)/(double)background.GetBinWidth(hist);
344 }
345
346 double Gate::GetIntegral(TH1 *hist, Gate backLow, Gate backHigh) const
347 {
348 int nData = 0;
349 double sumX = 0;
350 double sumY = 0;
351 double sumX2 = 0;
352 double sumXY = 0;
353 double sumY2 = 0;
354
355 int startLow = backLow.GetBinLow(hist);
356 int stopLow = backLow.GetBinHigh(hist);
357 int startHigh = backHigh.GetBinLow(hist);
358 int stopHigh = backHigh.GetBinHigh(hist);
359
360 int startGate = GetBinLow(hist);
361 int stopGate = GetBinHigh(hist);
362
363 for (int i=startLow; i<=stopLow; ++i) {
364 nData++;
365 sumX += hist->GetBinCenter(i);
366 sumX2 += hist->GetBinCenter(i)*hist->GetBinCenter(i);
367 sumXY += hist->GetBinCenter(i)*hist->GetBinContent(i);
368 sumY += hist->GetBinContent(i);
369 sumY2 += hist->GetBinContent(i)*hist->GetBinContent(i);
370 }
371 for (int i=startHigh; i<=stopHigh; ++i) {
372 nData++;
373 sumX += hist->GetBinCenter(i);
374 sumX2 += hist->GetBinCenter(i)*hist->GetBinCenter(i);
375 sumXY += hist->GetBinCenter(i)*hist->GetBinContent(i);
376 sumY += hist->GetBinContent(i);
377 sumY2 += hist->GetBinContent(i)*hist->GetBinContent(i);
378 }
379 double slope = (nData*sumXY - sumX*sumY)/(nData*sumX2-sumX*sumX);
380 double constant = (sumY*sumX2 - sumX*sumXY)/(nData*sumX2 - sumX*sumX);
381
382 double sumBackground = 0;
383 sumX = 0;
384 sumY = 0;
385 sumX2 = 0;
386 sumY2 = 0;
387 sumXY = 0;
388 for ( int i=startGate; i<= stopGate; ++i) {
389 double background = constant + slope*hist->GetBinCenter(i);
390 sumBackground += background;
391 double Y = hist->GetBinContent(i) - background;
392 sumY += Y;
393 sumXY += hist->GetBinCenter(i)*Y;
394 }
395
396 double posX = sumXY/sumY;
397 double area = (double)sumY;
398 double dArea = std::sqrt(area + 2*sumBackground);
399
400 //std::cout << "centroid: " << posX << std::endl;
401 return area;
402 }
403
411 double Gate::GetIntegralError(TH1 *hist) const
412 {
413 int iLowBin = hist->FindBin(this->Low);
414 int iHighBin = hist->FindBin(this->High);
415
416 double integralerror = 0;
417
418 for (int i = iLowBin; i <= iHighBin; i++) {
419 integralerror = integralerror + pow(hist->GetBinError(i) * hist->GetBinWidth(i), 2);
420 }
421
422 return sqrt(integralerror);
423 }
424
425 double Gate::GetIntegralError(TH1 *hist, Gate background) const
426 {
427 double peak = 0;
428 double back = 0;
429 peak = GetIntegralError(hist);
430 back = background.GetIntegralError(hist);
431 return sqrt(pow(peak,2) + pow(back*(double)GetBinWidth(hist)/(double)background.GetBinWidth(hist), 2));
432 }
433
434 double Gate::GetIntegralError(TH1 *hist, std::vector<Gate> back) const
435 {
436 int nData = 0;
437 double sumX = 0;
438 double sumY = 0;
439 double sumX2 = 0;
440 double sumXY = 0;
441 double sumY2 = 0;
442
443 int startGate = GetBinLow(hist);
444 int stopGate = GetBinHigh(hist);
445
446 double backwidth = 0;
447
448 for (auto &backgate : back) {
449 backwidth += (backgate.GetHigh()-backgate.GetLow());
450 int startback = backgate.GetBinLow(hist);
451 int stopback = backgate.GetBinHigh(hist);
452 for (int i=startback; i<=stopback; ++i) {
453 nData++;
454 sumX += hist->GetBinCenter(i);
455 sumX2 += hist->GetBinCenter(i)*hist->GetBinCenter(i);
456 sumXY += hist->GetBinCenter(i)*hist->GetBinContent(i);
457 sumY += hist->GetBinContent(i);
458 sumY2 += hist->GetBinContent(i)*hist->GetBinContent(i);
459 }
460 }
461
462 double slope = (nData*sumXY - sumX*sumY)/(nData*sumX2-sumX*sumX);
463 double constant = (sumY*sumX2 - sumX*sumXY)/(nData*sumX2 - sumX*sumX);
464
465 double sumBackground = 0;
466 sumX = 0;
467 sumY = 0;
468 sumX2 = 0;
469 sumY2 = 0;
470 sumXY = 0;
471 double peakwidth = (this->GetHigh() - this->GetLow());
472 for ( int i=startGate; i<= stopGate; ++i) {
473 double background = constant + slope*hist->GetBinCenter(i);
474 sumBackground += background;
475 double Y = hist->GetBinContent(i) - background;
476 sumY += Y;
477 sumXY += hist->GetBinCenter(i)*Y;
478 }
479
480 double posX = sumXY/sumY;
481 double area = (double)sumY;
482 double dArea = std::sqrt(area + std::pow(peakwidth/backwidth,2)*sumBackground);
483
484 //std::cout << "centroid: " << posX << std::endl;
485 return dArea;
486 }
487
488
495 double Gate::GetCounts(TH1 *hist) const
496 {
497 int iLowBin = hist->FindBin(this->Low);
498 int iHighBin = hist->FindBin(this->High);
499
500 double integral = 0;
501
502 for (int i = iLowBin; i <= iHighBin; i++) {
503 integral = integral + hist->GetBinContent(i);
504 }
505
506 return integral;
507 }
508
516 double Gate::GetCounts(TH1 *hist, Gate background) const
517 {
518 double peak = 0;
519 double back = 0;
520 peak = GetCounts(hist);
521 back = background.GetCounts(hist);
522 return peak - back*(double)GetBinWidth(hist)/(double)background.GetBinWidth(hist);
523 }
524
525 double Gate::GetCounts(TH1 *hist, std::vector<Gate> background) const
526 {
527 double peak = 0;
528 double back = 0;
529 peak = GetCounts(hist);
530 double back_width = 0;
531 for (auto &backgate : background) {
532 back += backgate.GetCounts(hist);
533 back_width += backgate.GetBinWidth(hist);
534 }
535 //std::cout << "peak: " << peak << " back: " << back << " scale: " << (double)GetBinWidth(hist)/back_width << std::endl;
536 return peak - back*(double)GetBinWidth(hist)/back_width;
537
538 /*
539 int nData = 0;
540 double sumX = 0;
541 double sumY = 0;
542 double sumX2 = 0;
543 double sumXY = 0;
544 double sumY2 = 0;
545
546 int startGate = GetBinLow(hist);
547 int stopGate = GetBinHigh(hist);
548
549 for (auto &backgate : background) {
550 int startback = backgate.GetBinLow(hist);
551 int stopback = backgate.GetBinHigh(hist);
552 for (int i=startback; i<=stopback; ++i) {
553 nData++;
554 sumX += double(i);
555 sumX2 += double(i)*double(i);
556 sumXY += double(i)*hist->GetBinContent(i);
557 sumY += hist->GetBinContent(i);
558 sumY2 += hist->GetBinContent(i)*hist->GetBinContent(i);
559 }
560 }
561
562
563 double slope = (nData*sumXY - sumX*sumY)/(nData*sumX2-sumX*sumX);
564 double constant = (sumY*sumX2 - sumX*sumXY)/(nData*sumX2 - sumX*sumX);
565
566 double sumBackground = 0;
567 sumX = 0;
568 sumY = 0;
569 sumX2 = 0;
570 sumY2 = 0;
571 sumXY = 0;
572 for ( int i=startGate; i<= stopGate; ++i) {
573 double background = constant + slope*double(i);
574 sumBackground += background;
575 double Y = hist->GetBinContent(i) - background;
576 sumY += Y;
577 sumXY += double(i)*Y;
578 }
579
580 double posX = sumXY/sumY;
581 double counts = (double)sumY;
582 double dCounts = std::sqrt(counts + 2*sumBackground);
583
584 //std::cout << "centroid: " << posX << std::endl;
585 return counts;
586 */
587 }
588
596 double Gate::GetCountsError(TH1 *hist) const
597 {
598 int iLowBin = hist->FindBin(this->Low);
599 int iHighBin = hist->FindBin(this->High);
600
601 double integralerror = 0;
602
603 for (int i = iLowBin; i <= iHighBin; i++) {
604 integralerror = integralerror + pow(hist->GetBinError(i), 2);
605 }
606
607 return sqrt(integralerror);
608 }
609
610 double Gate::GetCountsError(TH1 *hist, Gate background) const
611 {
612 double peak = 0;
613 double back = 0;
614 peak = GetCountsError(hist);
615 back = background.GetCountsError(hist);
616 return sqrt(pow(peak,2) + pow(back*(double)GetBinWidth(hist)/(double)background.GetBinWidth(hist), 2));
617 }
618
619 double Gate::GetCountsError(TH1 *hist, std::vector<Gate> background) const
620 {
621 double peak = 0;
622 double back = 0;
623 peak = GetCountsError(hist);
624 double back_width = 0;
625 for (auto &backgate : background) {
626 back += backgate.GetCountsError(hist);
627 back_width += backgate.GetBinWidth(hist);
628 }
629 //std::cout << "peak err: " << peak << " back err: " << back << " scale: " << (double)GetBinWidth(hist)/back_width << std::endl;
630 return sqrt(pow(peak, 2) + pow(back*(double)GetBinWidth(hist)/back_width, 2));
631
632 /*
633 int nData = 0;
634 double sumX = 0;
635 double sumY = 0;
636 double sumX2 = 0;
637 double sumXY = 0;
638 double sumY2 = 0;
639
640 int startGate = GetBinLow(hist);
641 int stopGate = GetBinHigh(hist);
642
643 int peakWidth = 0;
644 peakWidth = stopGate-startGate+1;
645 int backWidth = 0;
646 for (auto &backgate : background) {
647 int startback = backgate.GetBinLow(hist);
648 int stopback = backgate.GetBinHigh(hist);
649 backWidth += stopback - startback + 1;
650 for (int i=startback; i<=stopback; ++i) {
651 nData++;
652 sumX += double(i);
653 sumX2 += double(i)*double(i);
654 sumXY += double(i)*hist->GetBinContent(i);
655 sumY += hist->GetBinContent(i);
656 sumY2 += hist->GetBinContent(i)*hist->GetBinContent(i);
657 }
658 }
659
660
661 double slope = (nData*sumXY - sumX*sumY)/(nData*sumX2-sumX*sumX);
662 double constant = (sumY*sumX2 - sumX*sumXY)/(nData*sumX2 - sumX*sumX);
663
664 double sumBackground = 0;
665 sumX = 0;
666 sumY = 0;
667 sumX2 = 0;
668 sumY2 = 0;
669 sumXY = 0;
670 for ( int i=startGate; i<= stopGate; ++i) {
671 double background = constant + slope*double(i);
672 sumBackground += background;
673 double Y = hist->GetBinContent(i) - background;
674 sumY += Y;
675 sumXY += double(i)*Y;
676 }
677
678 double posX = sumXY/sumY;
679 double counts = (double)sumY;
680 double dCounts = std::sqrt(counts + std::pow(double(peakWidth)/double(backWidth),2)*sumBackground);
681
682 return dCounts;
683 */
684 }
685
686 void Gate::Norm(TH1 *hist, TH1 *ref) {
687 double scale = GetIntegral(ref)/GetIntegral(hist);
688 hist->Scale(scale);
689 }
690
691 void Gate::NormBackSub(TH1 *hist, TH1 *ref, Gate background) {
692 /*
693 //this is very dumb: subtracts constant background from all histograms and then rescales
694 double back_level = background.GetIntegral(hist)/(double)background.GetBinWidth(hist);
695 std::cout << "hist = " << hist->GetName() << std::endl;
696 std::cout << back_level << std::endl;
697 for (int i=0; i<hist->GetNbinsX(); ++i) {
698 hist->SetBinContent(i, hist->GetBinContent(i) - back_level);
699 }
700 double back_ref = background.GetIntegral(ref)/(double)background.GetBinWidth(hist);
701 std::cout << back_ref << std::endl;
702 for (int i=0; i<ref->GetNbinsX(); ++i) {
703 ref->SetBinContent(i, ref->GetBinContent(i) - back_ref);
704 }
705 std::cout << GetIntegral(hist) << " " << GetIntegral(ref) << std::endl;
706 double scale = GetIntegral(ref)/GetIntegral(hist);
707 hist->Scale(scale);
708 */
709
710 double scale = GetIntegral(ref, background)/GetIntegral(hist, background);
711 hist->Scale(scale);
712 }
713
714 void Gate::Browse(TBrowser *b)
715 {
716 (void)b;
717 Draw();
718 ls();
719 }
720
721 void Gate::Paint(Option_t *option /*="same"*/)
722 {
723 TAttLine::Modify();
724 TAttFill::Modify();
725
726 //check if there's a histogram
727 TH1D *hist = GamR::Utils::GetHist1D(gPad->GetCanvas());
728 double x1[2];
729 double y1[2];
730 double x2[2];
731 double y2[2];
732
733 x1[0] = this->Low;
734 x1[1] = this->Low;
735
736 int logy = gPad->GetLogy();
737
738 y1[0] = gPad->GetUymin();
739 if (!hist) {
740 y1[1] = gPad->GetUymax();
741 }
742 else {
743 y1[1] = hist->GetBinContent(hist->FindBin(this->Low));
744 if (logy) {
745 if (y1[1] > 0) y1[1] = TMath::Log10(y1[1]);
746 }
747 y1[1] = std::min(gPad->GetUymax(), y1[1]);
748 }
749
750 x2[0] = this->High;
751 x2[1] = this->High;
752
753
754 y2[0] = gPad->GetUymin();
755 if (!hist) {
756 y2[1] = gPad->GetUymax();
757 }
758 else {
759 y2[1] = hist->GetBinContent(hist->FindBin(this->High));
760 if (logy) {
761 if (y2[1] > 0) y2[1] = TMath::Log10(y2[1]);
762 }
763 y2[1] = std::min(gPad->GetUymax(), y2[1]);
764 }
765
766 if (gPad->GetUxmin() <= x1[0] && x1[0] <= gPad->GetUxmax()) {
767 if (y1[1] > y1[0]) {
768 gPad->PaintPolyLine(2, &x1[0], &y1[0], option);
769 }
770 }
771 if (gPad->GetUxmin() <= x2[0] && x2[0] <= gPad->GetUxmax()) {
772 if (y2[1] > y2[0]) {
773 gPad->PaintPolyLine(2, &x2[0], &y2[0], option);
774 }
775 }
776
777 if (!hist) {
778 gPad->PaintBox(x1[0], y1[0], x2[1], y2[1], option);
779 }
780 else {
781 for (int i=hist->FindBin(this->Low); i<=hist->FindBin(this->High); ++i) {
782 if (hist->GetBinCenter(i) < gPad->GetUxmin() || hist->GetBinCenter(i) > gPad->GetUxmax()) { continue; }
783 x1[0] = std::max(this->Low, hist->GetBinLowEdge(i));
784 x1[1] = x1[0];
785
786 x2[0] = std::min(this->High, hist->GetBinLowEdge(i+1));
787 x2[1] = x2[0];
788
789 y1[1] = hist->GetBinContent(i);
790 y2[1] = hist->GetBinContent(i);
791
792 if (logy) {
793 if (y1[1] > 0) y1[1] = TMath::Log10(y1[1]);
794 if (y2[1] > 0) y2[1] = TMath::Log10(y2[1]);
795 }
796
797 y1[1] = std::min(gPad->GetUymax(), y1[1]);
798 y2[1] = std::min(gPad->GetUymax(), y2[1]);
799
800 if (y1[1] <= y1[0] || y2[1] <= y2[0]) { continue; }
801
802 gPad->PaintBox(x1[0], y1[0], x2[1], y2[1], option);
803 }
804 }
805
806 }
807
808 Int_t Gate::DistancetoPrimitive(Int_t px, Int_t py)
809 {
810 (void)py;
811 double lowDist = std::abs(gPad->XtoPixel(this->Low) - px);
812 double highDist = std::abs(gPad->XtoPixel(this->High) - px);
813 return fmin(lowDist, highDist);
814 }
815
816 void Gate::ExecuteEvent(Int_t event, Int_t px, Int_t py)
817 {
818 (void)py;
819 if (!gPad)
820 return;
821 int kMaxDiff = 20;
822
823 if (!gPad->IsEditable())
824 return;
825
826 switch (event) {
827 case kMouseMotion:
828 if (fmin(std::abs(px - gPad->XtoPixel(this->Low)), std::abs(px - gPad->XtoPixel(this->High))) < kMaxDiff) {
829 gPad->SetCursor(kPointer);
830 return;
831 }
832 break;
833 }
834 }
835
836 void Gate::ls(Option_t *option /*=""*/) const
837 {
838 (void)option;
839 printf("Name Low High\n");
840 printf("%-20s%-12.2f%-12.2f\n", GetName(), (double)GetLow(), (double)GetHigh());
841 }
842
843 void GateMap::Browse(TBrowser *b)
844 {
845 TObject *obj;
846
847 ls();
848
849 if (b) {
850 for (auto i = fMap.begin(); i != fMap.end(); ++i) {
851 (i->second).SetName((i->first).c_str());
852 obj = (TObject *)(&(i->second));
853 b->Add(obj);
854 }
855 } else {
856 TObject::Browse(b);
857 }
858 }
859
860 void GateMap::ls(Option_t *option /*=""*/) const
861 {
862 (void)option;
863 printf("Key Low High\n");
864 for (auto i = fMap.begin(); i != fMap.end(); ++i) {
865 printf("%-20s%-12.2f%-12.2f\n", (i->first).c_str(), (double)(i->second).GetLow(), (double)(i->second).GetHigh());
866 }
867 }
868
869 std::ostream &operator<<(std::ostream &os, Gate const &g)
870 {
871 os << "Low: " << g.GetLow() << " High: " << g.GetHigh();
872 return os;
873 }
874
875 } /* namespace TK */
876} /* namespace GamR */
void ls()
void os(std::vector< int > indexes, TCanvas *canvas, Option_t *option)
void py(TVirtualPad *canvas)
void px(TVirtualPad *canvas)
std::vector< double > xs
Definition Utilities.hh:38
std::vector< double > ys
Definition Utilities.hh:39
int GetClicks(TVirtualPad *canvas, int n, std::vector< std::string > &messages, int draw=0, int print=0)
Definition Utilities.cc:127
double GetCountsError(TH1 *hist) const
Definition Gate.cc:596
void Paint(Option_t *option="same")
Definition Gate.cc:721
double GetLow() const
Definition Gate.hh:70
int GetBinWidth(TH1 *hist) const
Definition Gate.hh:75
void Browse(TBrowser *b)
Definition Gate.cc:714
TH1D * ApplyY(TH2 *hist) const
Definition Gate.cc:168
void ls(Option_t *option="") const
Definition Gate.cc:860
double GetCounts(TH1 *hist) const
Definition Gate.cc:495
int GetBinLow(TH1 *hist) const
Definition Gate.hh:73
void Browse(TBrowser *b)
Definition Gate.cc:843
void ls(Option_t *option="") const
Definition Gate.cc:836
TH1D * ApplyX(TH2 *hist) const
Definition Gate.cc:218
int SetGate()
Definition Gate.cc:76
void NormBackSub(TH1 *hist, TH1 *ref, Gate background)
Definition Gate.cc:691
double GetIntegralError(TH1 *hist) const
Definition Gate.cc:411
void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition Gate.cc:816
double GetIntegral(TH1 *hist) const
Definition Gate.cc:266
void Norm(TH1 *hist, TH1 *ref)
Definition Gate.cc:686
int GetBinHigh(TH1 *hist) const
Definition Gate.hh:74
double GetHigh() const
Definition Gate.hh:71
Int_t DistancetoPrimitive(Int_t px, Int_t py)
Definition Gate.cc:808
Bool_t Valid()
Definition Gate.hh:114
std::ostream & operator<<(std::ostream &os, Gate const &g)
Definition Gate.cc:869
Bool_t PassDetector(TDetector det, Bool_t calibrated, Int_t id)
Definition Gate.cc:149
TH1D * GetHist1D(TVirtualPad *canvas)
Definition Utilities.cc:182
Definition Gain.cc:19