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

Last change on this file since 5115 was 5098, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.0 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 : fPixId(-1)
65{
66
67 fName = name ? name : "MHCalibrationPix";
68 fTitle = title ? title : "Calibration histogram events";
69
70 Clear();
71
72 SetBlackoutLimit();
73 SetPickupLimit();
74}
75
76// --------------------------------------------------------------------------
77//
78// Default Clear(), can be overloaded.
79//
80// Sets:
81// - all other pointers to NULL
82// - all variables to 0., except fPixId to -1
83// - all flags to kFALSE
84//
85// - all pointers
86//
87void MHCalibrationPix::Clear(Option_t *o)
88{
89
90 MHGausEvents::Clear();
91 fSaturated = 0;
92}
93
94// -----------------------------------------------------------------------------
95//
96// Bypasses the Gauss fit by taking mean and RMS from the histogram
97//
98// Errors are determined in the following way:
99// MeanErr = RMS / Sqrt(entries)
100// SigmaErr = RMS / (2.*Sqrt(entries) )
101//
102void MHCalibrationPix::BypassFit()
103{
104
105 const Stat_t entries = fHGausHist.GetEntries();
106
107 if (entries <= 0.)
108 {
109 *fLog << warn << GetDescriptor()
110 << ": Cannot bypass fit. Number of entries smaller or equal 0 in pixel: " << fPixId << endl;
111 return;
112 }
113
114 fMean = fHGausHist.GetMean();
115 fMeanErr = fHGausHist.GetRMS() / TMath::Sqrt(entries);
116 fSigma = fHGausHist.GetRMS() ;
117 fSigmaErr = fHGausHist.GetRMS() / TMath::Sqrt(entries) / 2.;
118}
119
120// --------------------------------------------------------------------------
121//
122// - Set fPixId to id
123//
124// Add id to names and titles of:
125// - fHGausHist
126//
127void MHCalibrationPix::ChangeHistId(const Int_t id)
128{
129
130 fPixId = id;
131
132 fHGausHist.SetName( Form("%s%d", fHGausHist.GetName(), id));
133 fHGausHist.SetTitle( Form("%s%d", fHGausHist.GetTitle(), id));
134
135 fName = Form("%s%d", fName.Data(), id);
136 fTitle = Form("%s%d", fTitle.Data(), id);
137
138}
139
140// -------------------------------------------------------------------------------
141//
142// Return the number of "blackout" events, which are events with values higher
143// than fBlackoutLimit sigmas from the mean
144//
145//
146const Double_t MHCalibrationPix::GetBlackout() const
147{
148
149 if ((fMean == 0.) && (fSigma == 0.))
150 return -1.;
151
152 const Int_t first = fHGausHist.GetXaxis()->GetFirst();
153 const Int_t last = fHGausHist.GetXaxis()->FindBin(fMean-fBlackoutLimit*fSigma);
154
155 if (first >= last)
156 return 0.;
157
158 return fHGausHist.Integral(first, last, "width");
159}
160
161
162// -------------------------------------------------------------------------------
163//
164// Return the number of "pickup" events, which are events with values higher
165// than fPickupLimit sigmas from the mean
166//
167//
168const Double_t MHCalibrationPix::GetPickup() const
169{
170
171 if ((fMean == 0.) && (fSigma == 0.))
172 return -1.;
173
174 const Int_t first = fHGausHist.GetXaxis()->FindBin(fMean+fPickupLimit*fSigma);
175 const Int_t last = fHGausHist.GetXaxis()->GetLast();
176
177 if (first >= last)
178 return 0.;
179
180 return fHGausHist.Integral(first, last, "width");
181}
182
183
184// --------------------------------------------------------------------------
185//
186// Re-normalize the results, has to be overloaded
187//
188void MHCalibrationPix::Renorm()
189{
190}
191
192// -----------------------------------------------------------------------------
193//
194// If flag IsGausFitOK() is set (histogram already successfully fitted),
195// returns kTRUE
196//
197// If both fMean and fSigma are still zero, call FitGaus()
198//
199// Repeats the Gauss fit in a smaller range, defined by:
200//
201// min = GetMean() - fBlackoutLimit * GetSigma();
202// max = GetMean() + fPickupLimit * GetSigma();
203//
204// The fit results are retrieved and stored in class-own variables.
205//
206// A flag IsGausFitOK() is set according to whether the fit probability
207// is smaller or bigger than fProbLimit, whether the NDF is bigger than
208// fNDFLimit and whether results are NaNs.
209//
210Bool_t MHCalibrationPix::RepeatFit(const Option_t *option)
211{
212
213 if (IsGausFitOK())
214 return kTRUE;
215
216 if ((fMean == 0.) && (fSigma == 0.))
217 return FitGaus();
218
219 //
220 // Get new fitting ranges
221 //
222 Axis_t rmin = fMean - fBlackoutLimit * fSigma;
223 Axis_t rmax = fMean + fPickupLimit * fSigma;
224
225 Axis_t hmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst());
226 Axis_t hmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast()) ;
227
228 fFGausFit->SetRange(hmin < rmin ? rmin : hmin , hmax > rmax ? rmax : hmax);
229
230 fHGausHist.Fit(fFGausFit,option);
231
232 fMean = fFGausFit->GetParameter(1);
233 fSigma = fFGausFit->GetParameter(2);
234 fMeanErr = fFGausFit->GetParError(1) ;
235 fSigmaErr = fFGausFit->GetParError(2) ;
236 fProb = fFGausFit->GetProb() ;
237
238 //
239 // The fit result is accepted under condition:
240 // 1) The results are not nan's
241 // 2) The NDF is not smaller than fNDFLimit (default: fgNDFLimit)
242 // 3) The Probability is greater than fProbLimit (default: fgProbLimit)
243 //
244 if ( TMath::IsNaN ( fMean )
245 || TMath::IsNaN ( fMeanErr )
246 || TMath::IsNaN ( fProb )
247 || TMath::IsNaN ( fSigma )
248 || TMath::IsNaN ( fSigmaErr )
249 || fFGausFit->GetNDF() < fNDFLimit
250 || fProb < fProbLimit )
251 return kFALSE;
252
253 SetGausFitOK(kTRUE);
254 return kTRUE;
255
256}
257
Note: See TracBrowser for help on using the repository browser.