source: branches/Corsika7405Compatibility/mhflux/MAlphaFitter.h@ 18752

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