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

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