source: trunk/MagicSoft/Mars/mhcalib/MHGausEvents.h@ 8802

Last change on this file since 8802 was 8339, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 9.1 KB
Line 
1#ifndef MARS_MHGausEvents
2#define MARS_MHGausEvents
3
4#ifndef ROOT_TH1
5#include <TH1.h>
6#endif
7
8#ifndef ROOF_TF1
9#include <TF1.h>
10#endif
11
12#ifndef MARS_MH
13#include "MH.h"
14#endif
15
16#ifndef MARS_MArrayF
17#include "MArrayF.h"
18#endif
19
20class TVirtualPad;
21class TGraph;
22class TH1F;
23class TH1I;
24class TF1;
25
26class MHGausEvents : public MH
27{
28private:
29
30 const static Int_t fgNDFLimit; //! Default for fNDFLimit (now set to: 2)
31 const static Float_t fgProbLimit; //! Default for fProbLimit (now set to: 0.001)
32 const static Int_t fgPowerProbabilityBins; //! Default for fPowerProbabilityBins (now set to: 20)
33
34private:
35
36 Int_t fBinsAfterStripping; // Bins for the Gauss Histogram after stripping off the zeros at both ends
37 UInt_t fCurrentSize; // Current size of the array fEvents
38 Float_t fEventFrequency; // Event frequency in Hertz (to be set)
39 Byte_t fFlags; // Bit field for the fit result bits
40 Int_t fPowerProbabilityBins; // Bins for the projected power spectrum
41
42 TH1I *fHPowerProbability; //! Fourier transform of fEvents projected on y-axis
43 MArrayF *fPowerSpectrum; //! Fourier transform of fEvents
44
45 enum { kGausFitOK,
46 kExpFitOK,
47 kFourierSpectrumOK,
48 kExcluded }; // Bits for information about fit results
49
50 MArrayF fEvents; // Array which holds the entries of GausHist
51 TF1 *fFExpFit; // Exponential fit for FHPowerProbability
52 TGraph *fGraphEvents; //! TGraph to display the event array
53 TGraph *fGraphPowerSpectrum; //! TGraph to display the power spectrum array
54 Axis_t fFirst; // Lower histogram edge for fHGausHist (used by InitBins())
55 Axis_t fLast; // Upper histogram edge for fHGausHist (used by InitBins())
56 Int_t fNbins; // Number histogram bins for fHGausHist (used by InitBins())
57 Int_t fNDFLimit; // NDF limit for judgement if fit is OK
58 Float_t fProbLimit; // Probability limit for judgement if fit is OK
59
60protected:
61 TF1 *fFGausFit; // Gauss fit for fHGausHist
62 TH1F fHGausHist; // Histogram to hold the Gaussian distribution
63
64 Double_t fMean; // Mean of the Gauss fit
65 Double_t fMeanErr; // Error of the mean of the Gauss fit
66 Double_t fSigma; // Sigma of the Gauss fit
67 Double_t fSigmaErr; // Error of the sigma of the Gauss fit
68 Double_t fProb; // Probability of the Gauss fit
69
70 // Setters
71 void SetBinsAfterStripping ( const Int_t nbins=0 ) { fBinsAfterStripping =nbins; }
72 void SetPowerProbabilityBins ( const Int_t nbins=fgPowerProbabilityBins ) { fPowerProbabilityBins=nbins; }
73
74public:
75
76 MHGausEvents(const char* name=NULL, const char* title=NULL);
77 ~MHGausEvents();
78
79 void Clear(Option_t *o="");
80 void Reset();
81
82 void CreateFourierSpectrum();
83 void CreateGraphEvents();
84 void CreateGraphPowerSpectrum();
85
86 // Draws
87 void Draw ( Option_t *option="" ); // *MENU*
88 void DrawEvents ( Option_t *option="" ); // *MENU*
89 void DrawPowerSpectrum ( Option_t *option="" ); // *MENU*
90 void DrawPowerProjection( Option_t *option="" ); // *MENU*
91
92 // Fill
93 void FillArray ( const Float_t f );
94 Bool_t FillHist ( const Float_t f );
95 Bool_t FillHistAndArray ( const Float_t f );
96
97 // Fits
98 Bool_t FitGaus ( Option_t *option="RQ0",
99 const Double_t xmin=0.,
100 const Double_t xmax=0.); // *MENU*
101
102 // Inits
103 virtual void InitBins();
104
105 // Getters
106 const Double_t GetChiSquare() const { return ( fFGausFit ? fFGausFit->GetChisquare() : 0.); }
107 const Double_t GetExpChiSquare() const { return ( fFExpFit ? fFExpFit->GetChisquare() : 0.); }
108 const Int_t GetExpNdf() const { return ( fFExpFit ? fFExpFit->GetNDF() : 0 ); }
109 const Double_t GetExpProb() const { return ( fFExpFit ? fFExpFit->GetProb() : 0.); }
110 MArrayF *GetEvents() { return &fEvents; }
111 const MArrayF *GetEvents() const { return &fEvents; }
112 const Float_t GetEventFrequency () const { return fEventFrequency; }
113 TF1 *GetFExpFit() { return fFExpFit; }
114 const TF1 *GetFExpFit() const { return fFExpFit; }
115 TF1 *GetFGausFit() { return fFGausFit; }
116 const TF1 *GetFGausFit() const { return fFGausFit; }
117 TGraph *GetGraphEvents() { return fGraphEvents; }
118 const Double_t GetFirst() const { return fFirst; }
119 const Double_t GetLast () const { return fLast ; }
120 const TGraph *GetGraphEvents() const { return fGraphEvents; }
121 TGraph *GetGraphPowerSpectrum() { return fGraphPowerSpectrum; }
122 const TGraph *GetGraphPowerSpectrum() const { return fGraphPowerSpectrum; }
123 TH1F *GetHGausHist() { return &fHGausHist; }
124 const TH1F *GetHGausHist() const { return &fHGausHist; }
125 TH1I *GetHPowerProbability() { return fHPowerProbability; }
126 const TH1I *GetHPowerProbability() const { return fHPowerProbability; }
127 const Double_t GetHistRms() const { return fHGausHist.GetRMS(); }
128 const Double_t GetMean() const { return fMean; }
129 const Double_t GetMeanErr() const { return fMeanErr; }
130 const Int_t GetNdf() const { return ( fFGausFit ? fFGausFit->GetNDF() : 0); }
131 const Int_t GetNbins() const { return fNbins; }
132 const Double_t GetOffset() const { return ( fFExpFit ? fFExpFit->GetParameter(0) : 0.); }
133 MArrayF *GetPowerSpectrum() { return fPowerSpectrum; }
134 const MArrayF *GetPowerSpectrum() const { return fPowerSpectrum; }
135 const Double_t GetProb() const { return fProb; }
136 const Double_t GetSigma() const { return fSigma; }
137 const Double_t GetSigmaErr() const { return fSigmaErr; }
138 const Double_t GetSlope() const { return ( fFExpFit ? fFExpFit->GetParameter(1) : 0.); }
139 const Int_t GetNDFLimit() const { return fNDFLimit; }
140 const Float_t GetProbLimit() const { return fProbLimit; }
141
142 const Bool_t IsValid() const { return fMean!=0 || fSigma!=0; }
143 const Bool_t IsExcluded() const { return TESTBIT(fFlags,kExcluded); }
144 const Bool_t IsExpFitOK() const { return TESTBIT(fFlags,kExpFitOK); }
145 const Bool_t IsEmpty() const { return !(fHGausHist.GetEntries()); }
146 const Bool_t IsFourierSpectrumOK() const { return TESTBIT(fFlags,kFourierSpectrumOK); }
147 const Bool_t IsGausFitOK() const { return TESTBIT(fFlags,kGausFitOK); }
148 const Bool_t IsOnlyOverflow() const { return fHGausHist.GetEntries()>0 && fHGausHist.GetEntries() == fHGausHist.GetBinContent(fNbins+1); }
149 const Bool_t IsOnlyUnderflow() const { return fHGausHist.GetEntries()>0 && fHGausHist.GetEntries() == fHGausHist.GetBinContent(0); }
150
151 // Prints
152 void Print(const Option_t *o="") const; // *MENU*
153
154 // Setters
155 void SetEventFrequency ( const Float_t f ) { fEventFrequency = f; }
156 void SetExcluded ( const Bool_t b=kTRUE ) { b ? SETBIT(fFlags,kExcluded) : CLRBIT(fFlags,kExcluded); }
157 void SetExpFitOK ( const Bool_t b=kTRUE ) { b ? SETBIT(fFlags,kExpFitOK) : CLRBIT(fFlags,kExpFitOK); }
158 void SetFourierSpectrumOK( const Bool_t b=kTRUE ) { b ? SETBIT(fFlags,kFourierSpectrumOK) : CLRBIT(fFlags,kFourierSpectrumOK); }
159 void SetGausFitOK ( const Bool_t b=kTRUE ) { b ? SETBIT(fFlags,kGausFitOK) : CLRBIT(fFlags,kGausFitOK);}
160 void SetMean ( const Double_t d ) { fMean = d; }
161 void SetMeanErr ( const Double_t d ) { fMeanErr = d; }
162 void SetNDFLimit ( const Int_t lim=fgNDFLimit ) { fNDFLimit = lim; }
163 void SetProb ( const Double_t d ) { fProb = d; }
164 void SetProbLimit ( const Float_t lim=fgProbLimit ) { fProbLimit = lim; }
165 void SetSigma ( const Double_t d ) { fSigma = d; }
166 void SetSigmaErr ( const Double_t d ) { fSigmaErr = d; }
167
168 void SetBinning(Int_t i, Axis_t lo, Axis_t up) { fNbins=i; fFirst=lo; fLast=up; }
169
170 // Simulates
171 void SimulateGausEvents(const Float_t mean, const Float_t sigma, const Int_t nevts=4096); // *MENU*
172
173 ClassDef(MHGausEvents, 4) // Base class for events with Gaussian distributed values
174};
175
176#endif
Note: See TracBrowser for help on using the repository browser.