source: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h@ 7110

Last change on this file since 7110 was 7066, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 6.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
12#ifndef ROOT_TF1
13#include <TF1.h>
14#endif
15
16class TH1D;
17class TH3D;
18
19class MAlphaFitter : public MParContainer
20{
21public:
22 enum ScaleMode_t {
23 kNone, // No scaling
24 kEntries, // scale by the number of entries in on and off
25 kIntegral, // scale by the integral in on and off
26 kOffRegion, // scale by the integral between fScaleMin, fScaleMax in on and off
27 kBackground, // scale by the integral between fBgMin, fBgMax in on and off
28 kLeastSquare, // not yet implemented
29 kUserScale // scale by fixed factor set by SetScaleUser
30 };
31 enum Strategy_t {
32 kSignificance,
33 kSignificanceChi2,
34 kSignificanceLogExcess,
35 kSignificanceExcess,
36 kExcess
37 };
38private:
39 Float_t fSigInt;
40 Float_t fSigMax;
41 Float_t fBgMin;
42 Float_t fBgMax;
43 Float_t fScaleMin;
44 Float_t fScaleMax;
45 Int_t fPolynomOrder;
46
47 Double_t fSignificance;
48 Double_t fEventsExcess;
49 Double_t fEventsSignal;
50 Double_t fEventsBackground; // fScaleFactor already applied
51
52 Double_t fChiSqSignal;
53 Double_t fChiSqBg;
54 Double_t fIntegralMax;
55 Double_t fScaleFactor; // Scale factor for off-data
56
57 TArrayD fCoefficients;
58
59 TF1 *fFunc;
60
61 ScaleMode_t fScaleMode;
62 Double_t fScaleUser;
63
64 Strategy_t fStrategy;
65
66public:
67 // Implementing the function yourself is only about 5% faster
68 MAlphaFitter(const char *name=0, const char *title=0) : fSigInt(15), fSigMax(75), fBgMin(45), fBgMax(85), fScaleMin(40), fScaleMax(80), fPolynomOrder(2), fCoefficients(3+fPolynomOrder+1), fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90)), fScaleMode(kOffRegion), fScaleUser(1), fStrategy(kSignificance)
69 {
70 fName = name ? name : "MAlphaFitter";
71 fTitle = title ? title : "Fit alpha";
72
73 gROOT->GetListOfFunctions()->Remove(fFunc);
74 fFunc->SetName("Dummy");
75
76 Clear();
77 }
78
79 MAlphaFitter(const MAlphaFitter &f) : fFunc(0)
80 {
81 f.Copy(*this);
82 }
83 ~MAlphaFitter()
84 {
85 delete fFunc;
86 }
87
88 void Clear(Option_t *o="");
89 void Print(Option_t *o="") const; //*MENU*
90 void Copy(TObject &o) const;
91 /*
92 TObject *Clone(const char *name) const
93 {
94 return new MAlphaFitter(*this);
95 }
96 */
97
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) { if (s==fPolynomOrder) return; fPolynomOrder = s; delete fFunc; fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", s));
108 gROOT->GetListOfFunctions()->Remove(fFunc);
109 fFunc->SetName("Dummy");
110 fCoefficients.Set(3+s+1); fCoefficients.Reset(); }
111
112 Double_t GetSignalIntegralMax() const { return fSigInt; }
113
114 Double_t GetEventsExcess() const { return fEventsExcess; }
115 Double_t GetEventsSignal() const { return fEventsSignal; }
116 Double_t GetEventsBackground() const { return fEventsBackground; }
117
118 Double_t GetSignificance() const { return fSignificance; }
119 Double_t GetChiSqSignal() const { return fChiSqSignal; }
120 Double_t GetChiSqBg() const { return fChiSqBg; }
121 Double_t GetScaleFactor() const { return fScaleFactor; }
122 Double_t GetMinimizationValue() const;
123
124 Double_t GetGausSigma() const { return fCoefficients[2]; }
125 Double_t GetGausMu() const { return fCoefficients[1]; }
126 Double_t GetGausA() const { return fCoefficients[0]; }
127 Double_t GetCoefficient(Int_t i) const { return fCoefficients[i]; }
128 const TArrayD &GetCoefficients() const { return fCoefficients; }
129
130 void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const;
131
132 Bool_t Fit(TH1D &h, Bool_t paint=kFALSE);
133 Bool_t Fit(const TH1D &on, const TH1D &off, Double_t alpha, Bool_t paint=kFALSE);
134 Bool_t Fit(TH1D &on, TH1D *off, Double_t alpha, Bool_t paint=kFALSE)
135 {
136 return off ? Fit(on, *off, alpha, paint) : Fit(on, paint);
137 }
138 Bool_t Fit(TH1D &on, TH1D *off, Bool_t paint=kFALSE)
139 {
140 return off ? Fit(on, *off, 1, paint) : Fit(on, paint);
141 }
142 Bool_t ScaleAndFit(TH1D &on, TH1D *off, Bool_t paint=kFALSE)
143 {
144 const Double_t alpha = off ? Scale(*off, on) : 1;
145 return off ? Fit(on, *off, alpha, paint) : Fit(on, paint);
146 }
147
148 Bool_t FitAlpha(const TH3D &h, Bool_t paint=kFALSE);
149 Bool_t FitEnergy(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
150 Bool_t FitTheta(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
151
152 Bool_t FitAlpha(const TH3D &on, const TH3D &off, Bool_t paint=kFALSE);
153 Bool_t FitEnergy(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
154 Bool_t FitTheta(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
155
156 Bool_t FitAlpha(const TH3D &on, const TH3D *off, Bool_t paint=kFALSE)
157 {
158 return off ? FitAlpha(on, *off, paint) : FitAlpha(on, paint);
159 }
160 Bool_t FitEnergy(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
161 {
162 return off ? FitEnergy(on, *off, bin, paint) : FitEnergy(on, bin, paint);
163 }
164 Bool_t FitTheta(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
165 {
166 return off ? FitTheta(on, *off, bin, paint) : FitTheta(on, bin, paint);
167 }
168
169 Double_t Scale(TH1D &off, const TH1D &on) const;
170
171 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
172
173 ClassDef(MAlphaFitter, 1)
174};
175
176#endif
Note: See TracBrowser for help on using the repository browser.