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

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