1 | #ifndef MARS_MAlphaFitter
|
---|
2 | #define MARS_MAlphaFitter
|
---|
3 |
|
---|
4 | #ifndef MARS_MParContainer
|
---|
5 | #include "MParContainer.h"
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #ifndef ROOT_TArrayD
|
---|
9 | #include <TArrayD.h>
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | class TF1;
|
---|
13 | class TH1D;
|
---|
14 | class TH3D;
|
---|
15 |
|
---|
16 | class MAlphaFitter : public MParContainer
|
---|
17 | {
|
---|
18 | public:
|
---|
19 | #pragma GCC diagnostic push
|
---|
20 | #pragma GCC diagnostic ignored "-Wshadow"
|
---|
21 | enum ScaleMode_t {
|
---|
22 | kNone, // No scaling
|
---|
23 | kEntries, // scale by the number of entries in on and off
|
---|
24 | kIntegral, // scale by the integral in on and off
|
---|
25 | kOffRegion, // scale by the integral between fScaleMin, fScaleMax in on and off
|
---|
26 | kBackground, // scale by the integral between fBgMin, fBgMax in on and off
|
---|
27 | kLeastSquare, // not yet implemented
|
---|
28 | kUserScale // scale by fixed factor set by SetScaleUser
|
---|
29 | };
|
---|
30 | #pragma GCC diagnostic pop
|
---|
31 | enum Strategy_t {
|
---|
32 | kSignificance,
|
---|
33 | kSignificanceChi2,
|
---|
34 | kSignificanceLogExcess,
|
---|
35 | kSignificanceSqrtExcess,
|
---|
36 | kSignificanceExcess,
|
---|
37 | kExcess,
|
---|
38 | kGaussSigma,
|
---|
39 | kWeakSource,
|
---|
40 | kWeakSourceLogExcess
|
---|
41 | };
|
---|
42 | enum SignalFunc_t {
|
---|
43 | kGauss, kThetaSq
|
---|
44 | };
|
---|
45 |
|
---|
46 | private:
|
---|
47 | // Fitting Setup
|
---|
48 | Float_t fSigInt; // minimum of range to fit the signal
|
---|
49 | Float_t fSigMax; // maximum of range to fit the signal
|
---|
50 | Float_t fBgMin; // minimum of range to fit the background
|
---|
51 | Float_t fBgMax; // minimum of range to fit the background
|
---|
52 | Float_t fScaleMin; // minimum of range to determin the scale factor of the background
|
---|
53 | Float_t fScaleMax; // maximum of range to determin the scale factor of the background
|
---|
54 | Int_t fPolynomOrder; // order of polyom to be fitted to the background
|
---|
55 | Bool_t fFitBackground; // Backround fit: yes/no
|
---|
56 | SignalFunc_t fSignalFunc; // Type of signal function
|
---|
57 | // Result
|
---|
58 | Double_t fSignificance; // significance of an unknown signal (Li/Ma 17)
|
---|
59 | Double_t fErrorExcess; // Simple error propagation
|
---|
60 | Double_t fEventsExcess; // calculated number of excess events (signal-bg)
|
---|
61 | Double_t fEventsSignal; // calculated number of signal events
|
---|
62 | Double_t fEventsBackground; // calculated number of bg events (fScaleFactor already applied)
|
---|
63 |
|
---|
64 | Double_t fChiSqSignal; // Reduced (chi^2/NDF) chisq of signal fit
|
---|
65 | Double_t fChiSqBg; // Reduced (chi^2/NDF) chisq of bg fit
|
---|
66 | Double_t fIntegralMax; // Calculated bin border to which it was integrated
|
---|
67 | Double_t fScaleFactor; // Scale factor determined for off-data
|
---|
68 |
|
---|
69 | TArrayD fCoefficients; // Fit result
|
---|
70 | TArrayD fErrors; // Fit errors
|
---|
71 |
|
---|
72 | // Function
|
---|
73 | TF1 *fFunc; // fit function (gauss + polynom)
|
---|
74 |
|
---|
75 | // Scaling setup
|
---|
76 | ScaleMode_t fScaleMode; // scaling mode
|
---|
77 | Double_t fScaleUser; // user scale factor
|
---|
78 |
|
---|
79 | // Minimization strategy
|
---|
80 | Strategy_t fStrategy; // How to calc minimization value
|
---|
81 |
|
---|
82 | Double_t DoOffFit(const TH1D &hon, const TH1D &hof, Bool_t paint);
|
---|
83 | Bool_t FitOff(TH1D &h, Int_t paint);
|
---|
84 | void FitResult(const TH1D &h);
|
---|
85 |
|
---|
86 | public:
|
---|
87 | // Implementing the function yourself is only about 5% faster
|
---|
88 | MAlphaFitter(const char *name=0, const char *title=0);
|
---|
89 | MAlphaFitter(const MAlphaFitter &f) : MParContainer(f), fFunc(0)
|
---|
90 | {
|
---|
91 | f.Copy(*this);
|
---|
92 | }
|
---|
93 | ~MAlphaFitter();
|
---|
94 |
|
---|
95 | // TObject
|
---|
96 | void Clear(Option_t *o="");
|
---|
97 | void Print(Option_t *o="") const; //*MENU*
|
---|
98 | void Copy(TObject &o) const;
|
---|
99 |
|
---|
100 | // Setter
|
---|
101 | void SetScaleUser(Float_t scale) { fScaleUser = scale; fScaleMode=kUserScale; }
|
---|
102 | void SetScaleMode(ScaleMode_t mode) { fScaleMode = mode; }
|
---|
103 | void SetMinimizationStrategy(Strategy_t mode) { fStrategy = mode; }
|
---|
104 | void SetSignalIntegralMax(Float_t s) { fSigInt = s; }
|
---|
105 | void SetSignalFitMax(Float_t s) { fSigMax = s; }
|
---|
106 | void SetBackgroundFitMin(Float_t s) { fBgMin = s; }
|
---|
107 | void SetBackgroundFitMax(Float_t s) { fBgMax = s; }
|
---|
108 | void SetScaleMin(Float_t s) { fScaleMin = s; }
|
---|
109 | void SetScaleMax(Float_t s) { fScaleMax = s; }
|
---|
110 | void SetPolynomOrder(Int_t s)
|
---|
111 | {
|
---|
112 | if (s==fPolynomOrder)
|
---|
113 | return;
|
---|
114 |
|
---|
115 | fPolynomOrder = s;
|
---|
116 |
|
---|
117 | SetSignalFunction(fSignalFunc);
|
---|
118 | }
|
---|
119 | void SetSignalFunction(SignalFunc_t func);
|
---|
120 |
|
---|
121 | void EnableBackgroundFit(Bool_t b=kTRUE) { fFitBackground=b; }
|
---|
122 |
|
---|
123 | void FixScale()
|
---|
124 | {
|
---|
125 | fScaleMode = kUserScale;
|
---|
126 | fScaleUser = fScaleFactor;
|
---|
127 | }
|
---|
128 |
|
---|
129 | // Getter
|
---|
130 | Double_t GetSignalIntegralMax() const { return fSigInt; }
|
---|
131 |
|
---|
132 | Double_t GetEventsExcess() const { return fEventsExcess; }
|
---|
133 | Double_t GetEventsSignal() const { return fEventsSignal; }
|
---|
134 | Double_t GetEventsBackground() const { return fEventsBackground; }
|
---|
135 |
|
---|
136 | Double_t GetSignificance() const { return fSignificance; }
|
---|
137 | Double_t GetErrorExcess() const { return fErrorExcess; }
|
---|
138 | Double_t GetChiSqSignal() const { return fChiSqSignal; }
|
---|
139 | Double_t GetChiSqBg() const { return fChiSqBg; }
|
---|
140 | Double_t GetScaleFactor() const { return fScaleFactor; }
|
---|
141 | Double_t GetMinimizationValue() const;
|
---|
142 |
|
---|
143 | ScaleMode_t GetScaleMode() const { return fScaleMode; }
|
---|
144 |
|
---|
145 | Double_t GetGausSigma() const { return fCoefficients[2]; }
|
---|
146 | Double_t GetGausMu() const { return fCoefficients[1]; }
|
---|
147 | Double_t GetGausA() const { return fCoefficients[0]; }
|
---|
148 | Double_t GetCoefficient(Int_t i) const { return fCoefficients[i]; }
|
---|
149 | const TArrayD &GetCoefficients() const { return fCoefficients; }
|
---|
150 | const TArrayD &GetErrors() const { return fErrors; }
|
---|
151 | Double_t Eval(Double_t d) const;
|
---|
152 |
|
---|
153 | Double_t CalcUpperLimit() const;
|
---|
154 |
|
---|
155 | // Interface to fit
|
---|
156 | Bool_t Fit(TH1D &h, Bool_t paint=kFALSE);
|
---|
157 | Bool_t Fit(const TH1D &on, const TH1D &off, Double_t alpha, Bool_t paint=kFALSE);
|
---|
158 | Bool_t Fit(TH1D &on, TH1D *off, Double_t alpha, Bool_t paint=kFALSE)
|
---|
159 | {
|
---|
160 | return off ? Fit(on, *off, alpha, paint) : Fit(on, paint);
|
---|
161 | }
|
---|
162 | Bool_t Fit(TH1D &on, TH1D *off, Bool_t paint=kFALSE)
|
---|
163 | {
|
---|
164 | return off ? Fit(on, *off, 1, paint) : Fit(on, paint);
|
---|
165 | }
|
---|
166 | Bool_t ScaleAndFit(TH1D &on, TH1D *off, Bool_t paint=kFALSE)
|
---|
167 | {
|
---|
168 | const Double_t alpha = off ? Scale(*off, on) : 1;
|
---|
169 | return off ? Fit(on, *off, alpha, paint) : Fit(on, paint);
|
---|
170 | }
|
---|
171 |
|
---|
172 | Bool_t FitAlpha(const TH3D &h, Bool_t paint=kFALSE);
|
---|
173 | Bool_t FitEnergy(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
|
---|
174 | Bool_t FitTheta(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
|
---|
175 | //Bool_t FitTime(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
|
---|
176 |
|
---|
177 | Bool_t FitAlpha(const TH3D &on, const TH3D &off, Bool_t paint=kFALSE);
|
---|
178 | Bool_t FitEnergy(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
|
---|
179 | Bool_t FitTheta(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
|
---|
180 | //Bool_t FitTime(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
|
---|
181 |
|
---|
182 | Bool_t FitAlpha(const TH3D &on, const TH3D *off, Bool_t paint=kFALSE)
|
---|
183 | {
|
---|
184 | return off ? FitAlpha(on, *off, paint) : FitAlpha(on, paint);
|
---|
185 | }
|
---|
186 | Bool_t FitEnergy(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
|
---|
187 | {
|
---|
188 | return off ? FitEnergy(on, *off, bin, paint) : FitEnergy(on, bin, paint);
|
---|
189 | }
|
---|
190 | Bool_t FitTheta(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
|
---|
191 | {
|
---|
192 | return off ? FitTheta(on, *off, bin, paint) : FitTheta(on, bin, paint);
|
---|
193 | }/*
|
---|
194 | Bool_t FitTime(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
|
---|
195 | {
|
---|
196 | return off ? FitTime(on, *off, bin, paint) : FitTime(on, bin, paint);
|
---|
197 | }*/
|
---|
198 |
|
---|
199 | Double_t Scale(TH1D &off, const TH1D &on) const;
|
---|
200 |
|
---|
201 | Bool_t ApplyScaling(const TH3D &hon, TH3D &hof, UInt_t bin) const;
|
---|
202 | Bool_t ApplyScaling(const TH3D &hon, TH3D &hof) const;
|
---|
203 |
|
---|
204 | // Interface to result
|
---|
205 | void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035, Bool_t draw=kFALSE) const;
|
---|
206 | void DrawResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const { PaintResult(x, y, size, kTRUE); }
|
---|
207 |
|
---|
208 | // MTask
|
---|
209 | Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
|
---|
210 |
|
---|
211 | ClassDef(MAlphaFitter, 4)
|
---|
212 | };
|
---|
213 |
|
---|
214 | #endif
|
---|