source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationPix.cc@ 5372

Last change on this file since 5372 was 5137, checked in by gaug, 20 years ago
*** empty log message ***
File size: 6.6 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Markus Gaug 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MHCalibrationPix
28//
29// A base class for events which are believed to follow a Gaussian distribution
30// with time, e.g. calibration events, observables containing white noise, ...
31//
32// MHCalibrationPix derives from MHGausEvents, thus all features of
33// MHGausEvents can be used by a class deriving from MHCalibrationPix
34//
35// See also: MHGausEvents
36//
37//////////////////////////////////////////////////////////////////////////////
38#include "MHCalibrationPix.h"
39
40#include <TH1.h>
41#include <TF1.h>
42#include <TGraph.h>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47ClassImp(MHCalibrationPix);
48
49using namespace std;
50
51const Float_t MHCalibrationPix::fgBlackoutLimit = 5.;
52const Float_t MHCalibrationPix::fgPickupLimit = 5.;
53// --------------------------------------------------------------------------
54//
55// Default Constructor.
56// Sets:
57// - the default number for fPickupLimit (fgPickupLimit)
58// - the default number for fBlackoutLimit (fgBlackoutLimit)
59//
60// Initializes:
61// - all variables to 0.
62//
63MHCalibrationPix::MHCalibrationPix(const char *name, const char *title)
64{
65
66 fName = name ? name : "MHCalibrationPix";
67 fTitle = title ? title : "Calibration histogram events";
68
69 Clear();
70
71 SetBlackoutLimit();
72 SetPickupLimit();
73}
74
75// --------------------------------------------------------------------------
76//
77// Default Clear(), can be overloaded.
78//
79// Sets:
80// - all other pointers to NULL
81// - all variables to 0., except fPixId to -1
82// - all flags to kFALSE
83//
84// - all pointers
85//
86void MHCalibrationPix::Clear(Option_t *o)
87{
88
89 MHGausEvents::Clear();
90 fSaturated = 0;
91}
92
93// -----------------------------------------------------------------------------
94//
95// Bypasses the Gauss fit by taking mean and RMS from the histogram
96//
97// Errors are determined in the following way:
98// MeanErr = RMS / Sqrt(entries)
99// SigmaErr = RMS / (2.*Sqrt(entries) )
100//
101void MHCalibrationPix::BypassFit()
102{
103
104 const Stat_t entries = fHGausHist.GetEntries();
105
106 if (entries <= 0.)
107 {
108 *fLog << warn << GetDescriptor()
109 << ": Cannot bypass fit. Number of entries smaller or equal 0 in pixel: " << GetName() << endl;
110 return;
111 }
112
113 fMean = fHGausHist.GetMean();
114 fMeanErr = fHGausHist.GetRMS() / TMath::Sqrt(entries);
115 fSigma = fHGausHist.GetRMS() ;
116 fSigmaErr = fHGausHist.GetRMS() / TMath::Sqrt(entries) / 2.;
117}
118
119// -------------------------------------------------------------------------------
120//
121// Return the number of "blackout" events, which are events with values higher
122// than fBlackoutLimit sigmas from the mean
123//
124//
125const Double_t MHCalibrationPix::GetBlackout() const
126{
127
128 if ((fMean == 0.) && (fSigma == 0.))
129 return -1.;
130
131 const Int_t first = fHGausHist.GetXaxis()->GetFirst();
132 const Int_t last = fHGausHist.GetXaxis()->FindBin(fMean-fBlackoutLimit*fSigma);
133
134 if (first >= last)
135 return 0.;
136
137 return fHGausHist.Integral(first, last, "width");
138}
139
140
141// -------------------------------------------------------------------------------
142//
143// Return the number of "pickup" events, which are events with values higher
144// than fPickupLimit sigmas from the mean
145//
146//
147const Double_t MHCalibrationPix::GetPickup() const
148{
149
150 if ((fMean == 0.) && (fSigma == 0.))
151 return -1.;
152
153 const Int_t first = fHGausHist.GetXaxis()->FindBin(fMean+fPickupLimit*fSigma);
154 const Int_t last = fHGausHist.GetXaxis()->GetLast();
155
156 if (first >= last)
157 return 0.;
158
159 return fHGausHist.Integral(first, last, "width");
160}
161
162
163// --------------------------------------------------------------------------
164//
165// Re-normalize the results, has to be overloaded
166//
167void MHCalibrationPix::Renorm()
168{
169}
170
171// -----------------------------------------------------------------------------
172//
173// If flag IsGausFitOK() is set (histogram already successfully fitted),
174// returns kTRUE
175//
176// If both fMean and fSigma are still zero, call FitGaus()
177//
178// Repeats the Gauss fit in a smaller range, defined by:
179//
180// min = GetMean() - fBlackoutLimit * GetSigma();
181// max = GetMean() + fPickupLimit * GetSigma();
182//
183// The fit results are retrieved and stored in class-own variables.
184//
185// A flag IsGausFitOK() is set according to whether the fit probability
186// is smaller or bigger than fProbLimit, whether the NDF is bigger than
187// fNDFLimit and whether results are NaNs.
188//
189Bool_t MHCalibrationPix::RepeatFit(const Option_t *option)
190{
191
192 if (IsGausFitOK())
193 return kTRUE;
194
195 if ((fMean == 0.) && (fSigma == 0.))
196 return FitGaus();
197
198 //
199 // Get new fitting ranges
200 //
201 Axis_t rmin = fMean - fBlackoutLimit * fSigma;
202 Axis_t rmax = fMean + fPickupLimit * fSigma;
203
204 Axis_t hmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst());
205 Axis_t hmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast()) ;
206
207 fFGausFit->SetRange(hmin < rmin ? rmin : hmin , hmax > rmax ? rmax : hmax);
208
209 fHGausHist.Fit(fFGausFit,option);
210
211 fMean = fFGausFit->GetParameter(1);
212 fSigma = fFGausFit->GetParameter(2);
213 fMeanErr = fFGausFit->GetParError(1) ;
214 fSigmaErr = fFGausFit->GetParError(2) ;
215 fProb = fFGausFit->GetProb() ;
216
217 //
218 // The fit result is accepted under condition:
219 // 1) The results are not nan's
220 // 2) The NDF is not smaller than fNDFLimit (default: fgNDFLimit)
221 // 3) The Probability is greater than fProbLimit (default: fgProbLimit)
222 //
223 if ( TMath::IsNaN ( fMean )
224 || TMath::IsNaN ( fMeanErr )
225 || TMath::IsNaN ( fProb )
226 || TMath::IsNaN ( fSigma )
227 || TMath::IsNaN ( fSigmaErr )
228 || fFGausFit->GetNDF() < fNDFLimit
229 || fProb < fProbLimit )
230 return kFALSE;
231
232 SetGausFitOK(kTRUE);
233 return kTRUE;
234
235}
236
Note: See TracBrowser for help on using the repository browser.