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

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