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

Last change on this file since 5489 was 5478, 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// As an additional feature to MHGausEvents, this class offers to skip the fitting
36// to set mean, sigma and its errors directly from the histograms with the function
37// BypassFit()
38//
39// See also: MHGausEvents
40//
41//////////////////////////////////////////////////////////////////////////////
42#include "MHCalibrationPix.h"
43
44#include <TH1.h>
45#include <TF1.h>
46#include <TGraph.h>
47
48#include "MLog.h"
49#include "MLogManip.h"
50
51ClassImp(MHCalibrationPix);
52
53using namespace std;
54
55const Float_t MHCalibrationPix::fgBlackoutLimit = 5.;
56const Float_t MHCalibrationPix::fgPickupLimit = 5.;
57// --------------------------------------------------------------------------
58//
59// Default Constructor.
60// Sets:
61// - the default number for fPickupLimit (fgPickupLimit)
62// - the default number for fBlackoutLimit (fgBlackoutLimit)
63//
64// Initializes:
65// - all variables to 0.
66//
67MHCalibrationPix::MHCalibrationPix(const char *name, const char *title)
68{
69
70 fName = name ? name : "MHCalibrationPix";
71 fTitle = title ? title : "Calibration histogram events";
72
73 Clear();
74
75 SetBlackoutLimit();
76 SetPickupLimit();
77}
78
79// --------------------------------------------------------------------------
80//
81// Default Clear(), can be overloaded.
82//
83// Sets:
84// - all other pointers to NULL
85// - all variables to 0., except fPixId to -1
86// - all flags to kFALSE
87//
88// - all pointers
89//
90void MHCalibrationPix::Clear(Option_t *o)
91{
92
93 MHGausEvents::Clear();
94 fSaturated = 0;
95}
96
97// -----------------------------------------------------------------------------
98//
99// Bypasses the Gauss fit by taking mean and RMS from the histogram
100//
101// Errors are determined in the following way:
102// MeanErr = RMS / Sqrt(entries)
103// SigmaErr = RMS / (2.*Sqrt(entries) )
104//
105void MHCalibrationPix::BypassFit()
106{
107
108 const Stat_t entries = fHGausHist.GetEntries();
109
110 if (entries <= 0.)
111 {
112 *fLog << warn << GetDescriptor()
113 << ": Cannot bypass fit. Number of entries smaller or equal 0 in pixel: " << GetName() << endl;
114 return;
115 }
116
117 fMean = fHGausHist.GetMean();
118 fMeanErr = fHGausHist.GetRMS() / TMath::Sqrt(entries);
119 fSigma = fHGausHist.GetRMS() ;
120 fSigmaErr = fHGausHist.GetRMS() / TMath::Sqrt(entries) / 2.;
121}
122
123// -------------------------------------------------------------------------------
124//
125// Return the number of "blackout" events, which are events with values higher
126// than fBlackoutLimit sigmas from the mean
127//
128//
129const Double_t MHCalibrationPix::GetBlackout() const
130{
131
132 if ((fMean == 0.) && (fSigma == 0.))
133 return -1.;
134
135 const Int_t first = fHGausHist.GetXaxis()->GetFirst();
136 const Int_t last = fHGausHist.GetXaxis()->FindBin(fMean-fBlackoutLimit*fSigma);
137
138 if (first >= last)
139 return 0.;
140
141 return fHGausHist.Integral(first, last, "width");
142}
143
144
145// -------------------------------------------------------------------------------
146//
147// Return the number of "pickup" events, which are events with values higher
148// than fPickupLimit sigmas from the mean
149//
150//
151const Double_t MHCalibrationPix::GetPickup() const
152{
153
154 if ((fMean == 0.) && (fSigma == 0.))
155 return -1.;
156
157 const Int_t first = fHGausHist.GetXaxis()->FindBin(fMean+fPickupLimit*fSigma);
158 const Int_t last = fHGausHist.GetXaxis()->GetLast();
159
160 if (first >= last)
161 return 0.;
162
163 return fHGausHist.Integral(first, last, "width");
164}
165
166// -----------------------------------------------------------------------------
167//
168// If flag IsGausFitOK() is set (histogram already successfully fitted),
169// returns kTRUE
170//
171// If both fMean and fSigma are still zero, call FitGaus()
172//
173// Repeats the Gauss fit in a smaller range, defined by:
174//
175// min = GetMean() - fBlackoutLimit * GetSigma();
176// max = GetMean() + fPickupLimit * GetSigma();
177//
178// The fit results are retrieved and stored in class-own variables.
179//
180// A flag IsGausFitOK() is set according to whether the fit probability
181// is smaller or bigger than fProbLimit, whether the NDF is bigger than
182// fNDFLimit and whether results are NaNs.
183//
184Bool_t MHCalibrationPix::RepeatFit(const Option_t *option)
185{
186
187 if (IsGausFitOK())
188 return kTRUE;
189
190 if ((fMean == 0.) && (fSigma == 0.))
191 return FitGaus();
192
193 //
194 // Get new fitting ranges
195 //
196 Axis_t rmin = fMean - fBlackoutLimit * fSigma;
197 Axis_t rmax = fMean + fPickupLimit * fSigma;
198
199 Axis_t hmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst());
200 Axis_t hmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast()) ;
201
202 fFGausFit->SetRange(hmin < rmin ? rmin : hmin , hmax > rmax ? rmax : hmax);
203
204 fHGausHist.Fit(fFGausFit,option);
205
206 fMean = fFGausFit->GetParameter(1);
207 fSigma = fFGausFit->GetParameter(2);
208 fMeanErr = fFGausFit->GetParError(1) ;
209 fSigmaErr = fFGausFit->GetParError(2) ;
210 fProb = fFGausFit->GetProb() ;
211
212 //
213 // The fit result is accepted under condition:
214 // 1) The results are not nan's
215 // 2) The NDF is not smaller than fNDFLimit (default: fgNDFLimit)
216 // 3) The Probability is greater than fProbLimit (default: fgProbLimit)
217 //
218 if ( TMath::IsNaN ( fMean )
219 || TMath::IsNaN ( fMeanErr )
220 || TMath::IsNaN ( fProb )
221 || TMath::IsNaN ( fSigma )
222 || TMath::IsNaN ( fSigmaErr )
223 || fFGausFit->GetNDF() < fNDFLimit
224 || fProb < fProbLimit )
225 return kFALSE;
226
227 SetGausFitOK(kTRUE);
228 return kTRUE;
229
230}
231
Note: See TracBrowser for help on using the repository browser.