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

Last change on this file since 8148 was 8020, checked in by tbretz, 18 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
97void MHCalibrationPix::Reset()
98{
99
100 MHGausEvents::Reset();
101 fSaturated = 0;
102}
103
104
105// -----------------------------------------------------------------------------
106//
107// Bypasses the Gauss fit by taking mean and RMS from the histogram
108//
109// Errors are determined in the following way:
110// MeanErr = RMS / Sqrt(entries)
111// SigmaErr = RMS / (2.*Sqrt(entries) )
112//
113void MHCalibrationPix::BypassFit()
114{
115
116 const Stat_t entries = fHGausHist.GetEntries();
117
118 if (entries <= 0.)
119 {
120 *fLog << warn << GetDescriptor()
121 << ": Cannot bypass fit. Number of entries smaller or equal 0 in pixel: " << GetName() << endl;
122 return;
123 }
124
125 fMean = fHGausHist.GetMean();
126 fMeanErr = fHGausHist.GetRMS() / TMath::Sqrt(entries);
127 fSigma = fHGausHist.GetRMS() ;
128 fSigmaErr = fHGausHist.GetRMS() / TMath::Sqrt(entries) / 2.;
129}
130
131// -------------------------------------------------------------------------------
132//
133// Return the number of "blackout" events, which are events with values higher
134// than fBlackoutLimit sigmas from the mean
135//
136//
137const Double_t MHCalibrationPix::GetBlackout() const
138{
139
140 if ((fMean == 0.) && (fSigma == 0.))
141 return -1.;
142
143 const Int_t first = fHGausHist.GetXaxis()->GetFirst();
144 const Int_t last = fHGausHist.GetXaxis()->FindBin(fMean-fBlackoutLimit*fSigma);
145
146 if (first >= last)
147 return 0.;
148
149 return fHGausHist.Integral(first, last);
150}
151
152
153// -------------------------------------------------------------------------------
154//
155// Return the number of "pickup" events, which are events with values higher
156// than fPickupLimit sigmas from the mean
157//
158//
159const Double_t MHCalibrationPix::GetPickup() const
160{
161 if (!IsValid())
162 return -1.;
163
164 const Int_t first = fHGausHist.GetXaxis()->FindBin(fMean+fPickupLimit*fSigma);
165 const Int_t last = fHGausHist.GetXaxis()->GetLast();
166
167 if (first >= last)
168 return 0.;
169
170 return fHGausHist.Integral(first, last);
171}
172
173// -----------------------------------------------------------------------------
174//
175// If flag IsGausFitOK() is set (histogram already successfully fitted),
176// returns kTRUE
177//
178// If both fMean and fSigma are still zero, call FitGaus()
179//
180// Repeats the Gauss fit in a smaller range, defined by:
181//
182// min = GetMean() - fBlackoutLimit * GetSigma();
183// max = GetMean() + fPickupLimit * GetSigma();
184//
185// The fit results are retrieved and stored in class-own variables.
186//
187// A flag IsGausFitOK() is set according to whether the fit probability
188// is smaller or bigger than fProbLimit, whether the NDF is bigger than
189// fNDFLimit and whether results are NaNs.
190//
191Bool_t MHCalibrationPix::RepeatFit(const Option_t *option)
192{
193
194 if (IsGausFitOK())
195 return kTRUE;
196
197 if (!IsValid())
198 return FitGaus();
199
200 //
201 // Get new fitting ranges
202 //
203 Axis_t rmin = GetMean() - fBlackoutLimit * GetSigma();
204 Axis_t rmax = GetMean() + fPickupLimit * GetSigma();
205
206 Axis_t hmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst());
207 Axis_t hmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast()) ;
208
209 fFGausFit->SetRange(hmin < rmin ? rmin : hmin , hmax > rmax ? rmax : hmax);
210
211 fHGausHist.Fit(fFGausFit,option);
212
213 fMean = fFGausFit->GetParameter(1);
214 fSigma = fFGausFit->GetParameter(2);
215 fMeanErr = fFGausFit->GetParError(1) ;
216 fSigmaErr = fFGausFit->GetParError(2) ;
217 fProb = fFGausFit->GetProb() ;
218
219 //
220 // The fit result is accepted under condition:
221 // 1) The results are not nan's
222 // 2) The NDF is not smaller than fNDFLimit (default: fgNDFLimit)
223 // 3) The Probability is greater than fProbLimit (default: fgProbLimit)
224 //
225 if ( !TMath::Finite( fMean )
226 || !TMath::Finite( fMeanErr )
227 || !TMath::Finite( fProb )
228 || !TMath::Finite( fSigma )
229 || !TMath::Finite( fSigmaErr )
230 || fFGausFit->GetNDF() < GetNDFLimit()
231 || fProb < GetProbLimit() )
232 return kFALSE;
233
234 SetGausFitOK(kTRUE);
235 return kTRUE;
236
237}
238
Note: See TracBrowser for help on using the repository browser.