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 |
|
---|
16 | class TH1D;
|
---|
17 | class TH3D;
|
---|
18 |
|
---|
19 | class MAlphaFitter : public MParContainer
|
---|
20 | {
|
---|
21 | public:
|
---|
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 | };
|
---|
37 | private:
|
---|
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 |
|
---|
65 | public:
|
---|
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;
|
---|
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 GetEventsExcess() const { return fEventsExcess; }
|
---|
112 | Double_t GetEventsSignal() const { return fEventsSignal; }
|
---|
113 | Double_t GetEventsBackground() const { return fEventsBackground; }
|
---|
114 |
|
---|
115 | Double_t GetSignificance() const { return fSignificance; }
|
---|
116 | Double_t GetChiSqSignal() const { return fChiSqSignal; }
|
---|
117 | Double_t GetChiSqBg() const { return fChiSqBg; }
|
---|
118 | Double_t GetScaleFactor() const { return fScaleFactor; }
|
---|
119 | Double_t GetMinimizationValue() const;
|
---|
120 |
|
---|
121 | Double_t GetGausSigma() const { return fCoefficients[2]; }
|
---|
122 | Double_t GetGausMu() const { return fCoefficients[1]; }
|
---|
123 | Double_t GetGausA() const { return fCoefficients[0]; }
|
---|
124 | Double_t GetCoefficient(Int_t i) const { return fCoefficients[i]; }
|
---|
125 | const TArrayD &GetCoefficients() const { return fCoefficients; }
|
---|
126 |
|
---|
127 | void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const;
|
---|
128 |
|
---|
129 | Bool_t Fit(TH1D &h, Bool_t paint=kFALSE);
|
---|
130 | Bool_t Fit(const TH1D &on, const TH1D &off, Double_t alpha, Bool_t paint=kFALSE);
|
---|
131 | Bool_t Fit(TH1D &on, TH1D *off, Double_t alpha, Bool_t paint=kFALSE)
|
---|
132 | {
|
---|
133 | return off ? Fit(on, *off, alpha, paint) : Fit(on, paint);
|
---|
134 | }
|
---|
135 | Bool_t Fit(TH1D &on, TH1D *off, Bool_t paint=kFALSE)
|
---|
136 | {
|
---|
137 | return off ? Fit(on, *off, 1, paint) : Fit(on, paint);
|
---|
138 | }
|
---|
139 | Bool_t ScaleAndFit(TH1D &on, TH1D *off, Bool_t paint=kFALSE)
|
---|
140 | {
|
---|
141 | const Double_t alpha = off ? Scale(*off, on) : 1;
|
---|
142 | return off ? Fit(on, *off, alpha, paint) : Fit(on, paint);
|
---|
143 | }
|
---|
144 |
|
---|
145 | Bool_t FitAlpha(const TH3D &h, Bool_t paint=kFALSE);
|
---|
146 | Bool_t FitEnergy(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
|
---|
147 | Bool_t FitTheta(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE);
|
---|
148 |
|
---|
149 | Bool_t FitAlpha(const TH3D &on, const TH3D &off, Bool_t paint=kFALSE);
|
---|
150 | Bool_t FitEnergy(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
|
---|
151 | Bool_t FitTheta(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE);
|
---|
152 |
|
---|
153 | Bool_t FitAlpha(const TH3D &on, const TH3D *off, Bool_t paint=kFALSE)
|
---|
154 | {
|
---|
155 | return off ? FitAlpha(on, *off, paint) : FitAlpha(on, paint);
|
---|
156 | }
|
---|
157 | Bool_t FitEnergy(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
|
---|
158 | {
|
---|
159 | return off ? FitEnergy(on, *off, bin, paint) : FitEnergy(on, bin, paint);
|
---|
160 | }
|
---|
161 | Bool_t FitTheta(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE)
|
---|
162 | {
|
---|
163 | return off ? FitTheta(on, *off, bin, paint) : FitTheta(on, bin, paint);
|
---|
164 | }
|
---|
165 |
|
---|
166 | Double_t Scale(TH1D &off, const TH1D &on) const;
|
---|
167 |
|
---|
168 | Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
|
---|
169 |
|
---|
170 | ClassDef(MAlphaFitter, 1)
|
---|
171 | };
|
---|
172 |
|
---|
173 | #endif
|
---|