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

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