GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
Gate.hh
Go to the documentation of this file.
1#ifndef GAMR_TOOLKIT_GATE_HH
2#define GAMR_TOOLKIT_GATE_HH
3
4#include <algorithm>
5#include <map>
6#include <sstream>
7#include <string>
8#include <iostream>
9
10/* ROOT */
11#include <Rtypes.h>
12#include <TBrowser.h>
13#include <TCanvas.h>
14#include <TH1.h>
15#include <TH2.h>
16#include <TNamed.h>
17
18namespace GamR {
23
26 namespace TK {
27
28
32 class Gate : public TNamed, public TAttLine, public TAttFill {
33 private:
34 double Low;
35 double High;
36
37 public:
39 {
40 SetLineColor(8);
41 SetFillStyle(3003);
42 SetFillColor(8);
43 };
44 Gate(const char *name);
45 Gate(const char *name, const char *title);
46 Gate(const char *name, TVirtualPad *canvas, Option_t *opt="");
47 Gate(const char *name, const char *title, TVirtualPad *canvas, Option_t *opt="");
48 Gate(TVirtualPad *canvas, Option_t *opt="");
49 Gate(double l, double h) : Gate()
50 {
51 Low = l;
52 High = h;
53 Valid();
54 };
55 ~Gate() { };
56
57 int SetGate(); // *MENU*
58 int SetGate(TVirtualPad *canvas, Option_t *opt="");
59 void SetGate(double l, double h)
60 {
61 Low = l;
62 High = h;
63 Valid();
64 };
65 void SetLow(double l) { Low = l; Valid(); }; // *MENU* *ARGS={l=>Low}
66 void SetLow(std::string l) { std::stringstream(l) >> Low; Valid();};
67 void SetHigh(double h) { High = h; Valid();}; // *MENU* *ARGS={h=>High}
68 void SetHigh(std::string h) { std::stringstream(h) >> High; Valid();};
69 void SetScale(double s) { double cent = (Low + High)/2.; double width = GetWidth(); Low = cent - s*width/2.; High = cent + s*width/2.; }
70 double GetLow() const { return Low; };
71 double GetHigh() const { return High; };
72 double GetWidth() const { return High - Low; };
73 int GetBinLow(TH1 *hist) const { return hist->FindBin(Low); }
74 int GetBinHigh(TH1 *hist) const { return hist->FindBin(High); }
75 int GetBinWidth(TH1 *hist) const { return hist->FindBin(High) - hist->FindBin(Low) + 1; };
76 double GetTrueWidth(TH1 *hist) const { return hist->GetBinLowEdge(GetBinHigh(hist)+1) - hist->GetBinLowEdge(GetBinLow(hist)); }
77
78 double GetIntegral(TH1 *hist) const;
79 double GetIntegral(TH1 *hist, Gate background) const;
80 double GetIntegral(TH1 *hist, Gate backLow, Gate backHigh) const;
81 double GetIntegral(TH1 *hist, std::vector<Gate> background) const;
82 double GetIntegralError(TH1 *hist) const;
83 double GetIntegralError(TH1 *hist, Gate background) const;
84 double GetIntegralError(TH1 *hist, std::vector<Gate> background) const;
85 double GetCounts(TH1 *hist) const;
86 double GetCounts(TH1 *hist, Gate background) const;
87 double GetCounts(TH1 *hist, std::vector<Gate> background) const;
88 double GetCountsError(TH1 *hist) const;
89 double GetCountsError(TH1 *hist, Gate background) const;
90 double GetCountsError(TH1 *hist, std::vector<Gate> background) const;
91 void Browse(TBrowser *b);
92 Bool_t Pass(double x)
93 {
94 return ((x >= Low) && (x <= High));
95 }
96 Bool_t Pass(double x) const
97 {
98 return ((x >= Low) && (x <= High));
99 }
100 template <size_t Meas, class TDetector>
101 Bool_t PassDetector(TDetector det, Bool_t calibrated = kTRUE, Int_t id = -1);
102 TH1D *ApplyX(TH2 *hist) const; // don't know if there's a way to return the same
103 TH1D *ApplyX(TH2 *hist, const char *name) const; // kind of histogram as passed?
104 TH1D *ApplyY(TH2 *hist) const;
105 TH1D *ApplyY(TH2 *hist, const char *name) const;
106 void Norm(TH1 *hist, TH1 *ref);
107 void NormBackSub(TH1 *hist, TH1 *ref, Gate background);
108 void Paint(Option_t *option = "same");
109 Int_t DistancetoPrimitive(Int_t px, Int_t py);
110 void ExecuteEvent(Int_t event, Int_t px, Int_t py);
111 Bool_t IsFolder() const { return kTRUE; };
112 void ls(Option_t *option = "") const;
113
114 Bool_t Valid() {
115 if (this->Low > this->High) {
116 std::cout << "Warning! Gate low edge is higher than high edge" << std::endl;
117 }
118 return false;
119 }
120
122 ClassDef(Gate, 2);
123 // version 1: no inheritance from TAttLine or TAttFill, not drawing
125 };
126
127 std::ostream &operator<<(std::ostream &os, Gate const &g);
128
135 class GateMap : public TNamed {
136 private:
137 std::map<std::string, Gate > fMap;
138
139 public:
141 GateMap(const char *name) : TNamed(name, name){};
142 GateMap(const char *name, const char *title) : TNamed(name, title){};
143 Gate &operator[](std::string key) { return fMap[key]; };
144 Bool_t IsFolder() const { return kTRUE; };
145 void Browse(TBrowser *b);
146 void ls(Option_t *option = "") const;
147 Bool_t PassAny(double x) const
148 {
149 return std::any_of(fMap.cbegin(), fMap.cend(),
150 [&x](const std::pair<std::string, Gate> &g) { return g.second.Pass(x); });
151 }
152
154 ClassDef(GateMap, 1)
156 };
157 } // namespace TK
158 /* @} */
159} // namespace GamR
160
161#endif
void ls()
void os(std::vector< int > indexes, TCanvas *canvas, Option_t *option)
void py(TVirtualPad *canvas)
void px(TVirtualPad *canvas)
double GetCountsError(TH1 *hist) const
Definition Gate.cc:596
void Paint(Option_t *option="same")
Definition Gate.cc:721
Bool_t PassAny(double x) const
Definition Gate.hh:147
double GetLow() const
Definition Gate.hh:70
int GetBinWidth(TH1 *hist) const
Definition Gate.hh:75
void SetHigh(double h)
Definition Gate.hh:67
void Browse(TBrowser *b)
Definition Gate.cc:714
TH1D * ApplyY(TH2 *hist) const
Definition Gate.cc:168
void SetGate(double l, double h)
Definition Gate.hh:59
Bool_t IsFolder() const
Definition Gate.hh:111
void SetLow(double l)
Definition Gate.hh:65
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
TH1D * ApplyX(TH2 *hist) const
Definition Gate.cc:218
Bool_t Pass(double x) const
Definition Gate.hh:96
void SetLow(std::string l)
Definition Gate.hh:66
int SetGate()
Definition Gate.cc:76
Bool_t Pass(double x)
Definition Gate.hh:92
double GetTrueWidth(TH1 *hist) const
Definition Gate.hh:76
Gate & operator[](std::string key)
Definition Gate.hh:143
Gate(double l, double h)
Definition Gate.hh:49
double GetWidth() const
Definition Gate.hh:72
void NormBackSub(TH1 *hist, TH1 *ref, Gate background)
Definition Gate.cc:691
void SetHigh(std::string h)
Definition Gate.hh:68
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
Bool_t IsFolder() const
Definition Gate.hh:144
GateMap(const char *name, const char *title)
Definition Gate.hh:142
Bool_t PassDetector(TDetector det, Bool_t calibrated=kTRUE, Int_t id=-1)
GateMap(const char *name)
Definition Gate.hh:141
std::ostream & operator<<(std::ostream &os, Gate const &g)
Definition Gate.cc:869
void SetScale(double s)
Definition Gate.hh:69
Definition Gain.cc:19