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 |
|
---|
47 | ClassImp(MHCalibrationPix);
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | const Float_t MHCalibrationPix::fgBlackoutLimit = 5.;
|
---|
52 | const 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 | //
|
---|
63 | MHCalibrationPix::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 | //
|
---|
87 | void MHCalibrationPix::Clear(Option_t *o)
|
---|
88 | {
|
---|
89 |
|
---|
90 | MHGausEvents::Clear();
|
---|
91 | fSaturated = 0;
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | #if 0
|
---|
96 | // --------------------------------------------------------------------------
|
---|
97 | //
|
---|
98 | // ATTENTION: This nasty Clone function is necessary since the ROOT cloning
|
---|
99 | // lead to crashes on SOME machines (unfortunately not mine...).
|
---|
100 | // This function is a workaround in order to achieve the correct
|
---|
101 | // DrawClone() behaviour.
|
---|
102 | //
|
---|
103 | TObject *MHCalibrationPix::Clone(const char *name) const
|
---|
104 | {
|
---|
105 |
|
---|
106 | MHCalibrationPix &pix = *new MHCalibrationPix(name ? name : fName.Data(),fTitle.Data());
|
---|
107 |
|
---|
108 | //
|
---|
109 | // Copy MHGausEvents data members
|
---|
110 | //
|
---|
111 | pix.fBinsAfterStripping = fBinsAfterStripping;
|
---|
112 | pix.fCurrentSize = fCurrentSize;
|
---|
113 | pix.fFlags = fFlags;
|
---|
114 | pix.fPowerProbabilityBins = fPowerProbabilityBins;
|
---|
115 |
|
---|
116 | if (fHPowerProbability)
|
---|
117 | pix.fHPowerProbability=(TH1I*)fHPowerProbability->Clone();
|
---|
118 |
|
---|
119 | if (fPowerSpectrum)
|
---|
120 | pix.fPowerSpectrum = new TArrayF(*fPowerSpectrum);
|
---|
121 |
|
---|
122 | pix.fEvents = fEvents;
|
---|
123 |
|
---|
124 | if (fFGausFit)
|
---|
125 | pix.fFGausFit=(TF1*)fFGausFit->Clone();
|
---|
126 | if (fFExpFit)
|
---|
127 | pix.fFExpFit=(TF1*)fFExpFit->Clone();
|
---|
128 |
|
---|
129 | pix.fFirst = fFirst;
|
---|
130 |
|
---|
131 | if (fGraphEvents)
|
---|
132 | pix.fGraphEvents=(TGraph*)fGraphEvents->Clone();
|
---|
133 | if (fGraphPowerSpectrum)
|
---|
134 | pix.fGraphPowerSpectrum=(TGraph*)fGraphPowerSpectrum->Clone();
|
---|
135 |
|
---|
136 | pix.fHGausHist = fHGausHist;
|
---|
137 |
|
---|
138 | pix.fLast = fLast;
|
---|
139 | pix.fMean = fMean;
|
---|
140 | pix.fMeanErr = fMeanErr;
|
---|
141 | pix.fNbins = fNbins;
|
---|
142 | pix.fNDFLimit = fNDFLimit;
|
---|
143 | pix.fSigma = fSigma;
|
---|
144 | pix.fSigmaErr = fSigmaErr;
|
---|
145 | pix.fProb = fProb;
|
---|
146 | pix.fProbLimit = fProbLimit;
|
---|
147 |
|
---|
148 | //
|
---|
149 | // Copy data members
|
---|
150 | //
|
---|
151 | pix.fBlackoutLimit = fBlackoutLimit;
|
---|
152 | pix.fSaturated = fSaturated;
|
---|
153 | pix.fPickupLimit = fPickupLimit;
|
---|
154 | pix.fPixId = fPixId;
|
---|
155 |
|
---|
156 | return &pix;
|
---|
157 | }
|
---|
158 | #endif
|
---|
159 |
|
---|
160 | // -----------------------------------------------------------------------------
|
---|
161 | //
|
---|
162 | // Bypasses the Gauss fit by taking mean and RMS from the histogram
|
---|
163 | //
|
---|
164 | // Errors are determined in the following way:
|
---|
165 | // MeanErr = RMS / Sqrt(entries)
|
---|
166 | // SigmaErr = RMS / (2.*Sqrt(entries) )
|
---|
167 | //
|
---|
168 | void MHCalibrationPix::BypassFit()
|
---|
169 | {
|
---|
170 |
|
---|
171 | const Stat_t entries = fHGausHist.GetEntries();
|
---|
172 |
|
---|
173 | if (entries <= 0.)
|
---|
174 | {
|
---|
175 | *fLog << warn << GetDescriptor()
|
---|
176 | << ": Cannot bypass fit. Number of entries smaller or equal 0 in pixel: " << fPixId << endl;
|
---|
177 | return;
|
---|
178 | }
|
---|
179 |
|
---|
180 | fMean = fHGausHist.GetMean();
|
---|
181 | fMeanErr = fHGausHist.GetRMS() / TMath::Sqrt(entries);
|
---|
182 | fSigma = fHGausHist.GetRMS() ;
|
---|
183 | fSigmaErr = fHGausHist.GetRMS() / TMath::Sqrt(entries) / 2.;
|
---|
184 | }
|
---|
185 |
|
---|
186 | // --------------------------------------------------------------------------
|
---|
187 | //
|
---|
188 | // - Set fPixId to id
|
---|
189 | //
|
---|
190 | // Add id to names and titles of:
|
---|
191 | // - fHGausHist
|
---|
192 | //
|
---|
193 | void MHCalibrationPix::ChangeHistId(const Int_t id)
|
---|
194 | {
|
---|
195 |
|
---|
196 | fPixId = id;
|
---|
197 |
|
---|
198 | fHGausHist.SetName( Form("%s%d", fHGausHist.GetName(), id));
|
---|
199 | fHGausHist.SetTitle( Form("%s%d", fHGausHist.GetTitle(), id));
|
---|
200 |
|
---|
201 | fName = Form("%s%d", fName.Data(), id);
|
---|
202 | fTitle = Form("%s%d", fTitle.Data(), id);
|
---|
203 |
|
---|
204 | }
|
---|
205 |
|
---|
206 | // -------------------------------------------------------------------------------
|
---|
207 | //
|
---|
208 | // Return the number of "blackout" events, which are events with values higher
|
---|
209 | // than fBlackoutLimit sigmas from the mean
|
---|
210 | //
|
---|
211 | //
|
---|
212 | const Double_t MHCalibrationPix::GetBlackout() const
|
---|
213 | {
|
---|
214 |
|
---|
215 | if ((fMean == 0.) && (fSigma == 0.))
|
---|
216 | return -1.;
|
---|
217 |
|
---|
218 | const Int_t first = fHGausHist.GetXaxis()->GetFirst();
|
---|
219 | const Int_t last = fHGausHist.GetXaxis()->FindBin(fMean-fBlackoutLimit*fSigma);
|
---|
220 |
|
---|
221 | if (first >= last)
|
---|
222 | return 0.;
|
---|
223 |
|
---|
224 | return fHGausHist.Integral(first, last, "width");
|
---|
225 | }
|
---|
226 |
|
---|
227 |
|
---|
228 | // -------------------------------------------------------------------------------
|
---|
229 | //
|
---|
230 | // Return the number of "pickup" events, which are events with values higher
|
---|
231 | // than fPickupLimit sigmas from the mean
|
---|
232 | //
|
---|
233 | //
|
---|
234 | const Double_t MHCalibrationPix::GetPickup() const
|
---|
235 | {
|
---|
236 |
|
---|
237 | if ((fMean == 0.) && (fSigma == 0.))
|
---|
238 | return -1.;
|
---|
239 |
|
---|
240 | const Int_t first = fHGausHist.GetXaxis()->FindBin(fMean+fPickupLimit*fSigma);
|
---|
241 | const Int_t last = fHGausHist.GetXaxis()->GetLast();
|
---|
242 |
|
---|
243 | if (first >= last)
|
---|
244 | return 0.;
|
---|
245 |
|
---|
246 | return fHGausHist.Integral(first, last, "width");
|
---|
247 | }
|
---|
248 |
|
---|
249 |
|
---|
250 | // --------------------------------------------------------------------------
|
---|
251 | //
|
---|
252 | // Re-normalize the results, has to be overloaded
|
---|
253 | //
|
---|
254 | void MHCalibrationPix::Renorm()
|
---|
255 | {
|
---|
256 | }
|
---|
257 |
|
---|
258 | // -----------------------------------------------------------------------------
|
---|
259 | //
|
---|
260 | // If flag IsGausFitOK() is set (histogram already successfully fitted),
|
---|
261 | // returns kTRUE
|
---|
262 | //
|
---|
263 | // If both fMean and fSigma are still zero, call FitGaus()
|
---|
264 | //
|
---|
265 | // Repeats the Gauss fit in a smaller range, defined by:
|
---|
266 | //
|
---|
267 | // min = GetMean() - fBlackoutLimit * GetSigma();
|
---|
268 | // max = GetMean() + fPickupLimit * GetSigma();
|
---|
269 | //
|
---|
270 | // The fit results are retrieved and stored in class-own variables.
|
---|
271 | //
|
---|
272 | // A flag IsGausFitOK() is set according to whether the fit probability
|
---|
273 | // is smaller or bigger than fProbLimit, whether the NDF is bigger than
|
---|
274 | // fNDFLimit and whether results are NaNs.
|
---|
275 | //
|
---|
276 | Bool_t MHCalibrationPix::RepeatFit(const Option_t *option)
|
---|
277 | {
|
---|
278 |
|
---|
279 | if (IsGausFitOK())
|
---|
280 | return kTRUE;
|
---|
281 |
|
---|
282 | if ((fMean == 0.) && (fSigma == 0.))
|
---|
283 | return FitGaus();
|
---|
284 |
|
---|
285 | //
|
---|
286 | // Get new fitting ranges
|
---|
287 | //
|
---|
288 | Axis_t rmin = fMean - fBlackoutLimit * fSigma;
|
---|
289 | Axis_t rmax = fMean + fPickupLimit * fSigma;
|
---|
290 |
|
---|
291 | Axis_t hmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst());
|
---|
292 | Axis_t hmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast()) ;
|
---|
293 |
|
---|
294 | fFGausFit->SetRange(hmin < rmin ? rmin : hmin , hmax > rmax ? rmax : hmax);
|
---|
295 |
|
---|
296 | fHGausHist.Fit(fFGausFit,option);
|
---|
297 |
|
---|
298 | fMean = fFGausFit->GetParameter(1);
|
---|
299 | fSigma = fFGausFit->GetParameter(2);
|
---|
300 | fMeanErr = fFGausFit->GetParError(1) ;
|
---|
301 | fSigmaErr = fFGausFit->GetParError(2) ;
|
---|
302 | fProb = fFGausFit->GetProb() ;
|
---|
303 |
|
---|
304 | //
|
---|
305 | // The fit result is accepted under condition:
|
---|
306 | // 1) The results are not nan's
|
---|
307 | // 2) The NDF is not smaller than fNDFLimit (default: fgNDFLimit)
|
---|
308 | // 3) The Probability is greater than fProbLimit (default: fgProbLimit)
|
---|
309 | //
|
---|
310 | if ( TMath::IsNaN ( fMean )
|
---|
311 | || TMath::IsNaN ( fMeanErr )
|
---|
312 | || TMath::IsNaN ( fProb )
|
---|
313 | || TMath::IsNaN ( fSigma )
|
---|
314 | || TMath::IsNaN ( fSigmaErr )
|
---|
315 | || fFGausFit->GetNDF() < fNDFLimit
|
---|
316 | || fProb < fProbLimit )
|
---|
317 | return kFALSE;
|
---|
318 |
|
---|
319 | SetGausFitOK(kTRUE);
|
---|
320 | return kTRUE;
|
---|
321 |
|
---|
322 | }
|
---|
323 |
|
---|