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 | : fEventFrequency(0), 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 | // --------------------------------------------------------------------------
|
---|
79 | //
|
---|
80 | // Default Clear(), can be overloaded.
|
---|
81 | //
|
---|
82 | // Sets:
|
---|
83 | // - all other pointers to NULL
|
---|
84 | // - all variables to 0., except fPixId to -1 and keep fEventFrequency
|
---|
85 | // - all flags to kFALSE
|
---|
86 | //
|
---|
87 | // Deletes (if not NULL):
|
---|
88 | // - all pointers
|
---|
89 | //
|
---|
90 | void MHCalibrationPix::Clear(Option_t *o)
|
---|
91 | {
|
---|
92 |
|
---|
93 | MHGausEvents::Clear();
|
---|
94 | fSaturated = 0;
|
---|
95 | }
|
---|
96 |
|
---|
97 | // --------------------------------------------------------------------------
|
---|
98 | //
|
---|
99 | // Use the MHGausEvents::Clone function and clone additionally the rest of the
|
---|
100 | // data members.
|
---|
101 | //
|
---|
102 | TObject *MHCalibrationPix::Clone(const char *name) const
|
---|
103 | {
|
---|
104 |
|
---|
105 | MHCalibrationPix &pix = (MHCalibrationPix&)*MHGausEvents::Clone(name);
|
---|
106 |
|
---|
107 | //
|
---|
108 | // Copy data members
|
---|
109 | //
|
---|
110 | pix.fEventFrequency = fEventFrequency;
|
---|
111 | pix.fBlackoutLimit = fBlackoutLimit;
|
---|
112 | pix.fSaturated = fSaturated;
|
---|
113 | pix.fPickupLimit = fPickupLimit;
|
---|
114 | pix.fPixId = fPixId;
|
---|
115 |
|
---|
116 | return &pix;
|
---|
117 | }
|
---|
118 |
|
---|
119 | // -----------------------------------------------------------------------------
|
---|
120 | //
|
---|
121 | // Bypasses the Gauss fit by taking mean and RMS from the histogram
|
---|
122 | //
|
---|
123 | // Errors are determined in the following way:
|
---|
124 | // MeanErr = RMS / Sqrt(entries)
|
---|
125 | // SigmaErr = RMS / (2.*Sqrt(entries) )
|
---|
126 | //
|
---|
127 | void MHCalibrationPix::BypassFit()
|
---|
128 | {
|
---|
129 |
|
---|
130 | const Stat_t entries = fHGausHist.GetEntries();
|
---|
131 |
|
---|
132 | if (entries <= 0.)
|
---|
133 | {
|
---|
134 | *fLog << warn << GetDescriptor()
|
---|
135 | << ": Cannot bypass fit. Number of entries smaller or equal 0 in pixel: " << fPixId << endl;
|
---|
136 | return;
|
---|
137 | }
|
---|
138 |
|
---|
139 | fMean = fHGausHist.GetMean();
|
---|
140 | fMeanErr = fHGausHist.GetRMS() / TMath::Sqrt(entries);
|
---|
141 | fSigma = fHGausHist.GetRMS() ;
|
---|
142 | fSigmaErr = fHGausHist.GetRMS() / TMath::Sqrt(entries) / 2.;
|
---|
143 | }
|
---|
144 |
|
---|
145 | // --------------------------------------------------------------------------
|
---|
146 | //
|
---|
147 | // - Set fPixId to id
|
---|
148 | //
|
---|
149 | // Add id to names and titles of:
|
---|
150 | // - fHGausHist
|
---|
151 | //
|
---|
152 | void MHCalibrationPix::ChangeHistId(const Int_t id)
|
---|
153 | {
|
---|
154 |
|
---|
155 | fPixId = id;
|
---|
156 |
|
---|
157 | fHGausHist.SetName( Form("%s%d", fHGausHist.GetName(), id));
|
---|
158 | fHGausHist.SetTitle( Form("%s%d", fHGausHist.GetTitle(), id));
|
---|
159 |
|
---|
160 | fName = Form("%s%d", fName.Data(), id);
|
---|
161 | fTitle = Form("%s%d", fTitle.Data(), id);
|
---|
162 |
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | // -----------------------------------------------------------------------------
|
---|
167 | //
|
---|
168 | // Create the x-axis for the event graph
|
---|
169 | //
|
---|
170 | Float_t *MHCalibrationPix::CreateEventXaxis(Int_t n)
|
---|
171 | {
|
---|
172 |
|
---|
173 | Float_t *xaxis = new Float_t[n];
|
---|
174 |
|
---|
175 | if (fEventFrequency)
|
---|
176 | for (Int_t i=0;i<n;i++)
|
---|
177 | xaxis[i] = (Float_t)i/fEventFrequency;
|
---|
178 | else
|
---|
179 | for (Int_t i=0;i<n;i++)
|
---|
180 | xaxis[i] = (Float_t)i;
|
---|
181 |
|
---|
182 | return xaxis;
|
---|
183 |
|
---|
184 | }
|
---|
185 |
|
---|
186 | // -----------------------------------------------------------------------------
|
---|
187 | //
|
---|
188 | // Create the x-axis for the event graph
|
---|
189 | //
|
---|
190 | Float_t *MHCalibrationPix::CreatePSDXaxis(Int_t n)
|
---|
191 | {
|
---|
192 |
|
---|
193 | Float_t *xaxis = new Float_t[n];
|
---|
194 |
|
---|
195 | if (fEventFrequency)
|
---|
196 | for (Int_t i=0;i<n;i++)
|
---|
197 | xaxis[i] = 0.5*(Float_t)i*fEventFrequency/n;
|
---|
198 | else
|
---|
199 | for (Int_t i=0;i<n;i++)
|
---|
200 | xaxis[i] = 0.5*(Float_t)i/n;
|
---|
201 |
|
---|
202 | return xaxis;
|
---|
203 |
|
---|
204 | }
|
---|
205 |
|
---|
206 | // ----------------------------------------------------------------------------------
|
---|
207 | //
|
---|
208 | // Create a graph to display the array fEvents
|
---|
209 | // If the variable fEventFrequency is set, the x-axis is transformed into real time.
|
---|
210 | //
|
---|
211 | void MHCalibrationPix::CreateGraphEvents()
|
---|
212 | {
|
---|
213 |
|
---|
214 | MHGausEvents::CreateGraphEvents();
|
---|
215 | fGraphEvents->GetXaxis()->SetTitle((fEventFrequency) ? "Time [s]" : "Event Nr.");
|
---|
216 | }
|
---|
217 |
|
---|
218 | // ----------------------------------------------------------------------------------
|
---|
219 | //
|
---|
220 | // Create a graph to display the array fPowerSpectrum
|
---|
221 | // If the variable fEventFrequency is set, the x-axis is transformed into real frequency.
|
---|
222 | //
|
---|
223 | void MHCalibrationPix::CreateGraphPowerSpectrum()
|
---|
224 | {
|
---|
225 |
|
---|
226 | MHGausEvents::CreateGraphPowerSpectrum();
|
---|
227 |
|
---|
228 | fGraphPowerSpectrum->GetXaxis()->SetTitle((fEventFrequency) ? "Frequency [Hz]" : "Frequency");
|
---|
229 | }
|
---|
230 |
|
---|
231 | // -------------------------------------------------------------------------------
|
---|
232 | //
|
---|
233 | // Return the number of "blackout" events, which are events with values higher
|
---|
234 | // than fBlackoutLimit sigmas from the mean
|
---|
235 | //
|
---|
236 | //
|
---|
237 | const Double_t MHCalibrationPix::GetBlackout() const
|
---|
238 | {
|
---|
239 |
|
---|
240 | if ((fMean == 0.) && (fSigma == 0.))
|
---|
241 | return -1.;
|
---|
242 |
|
---|
243 | const Int_t first = fHGausHist.GetXaxis()->GetFirst();
|
---|
244 | const Int_t last = fHGausHist.GetXaxis()->FindBin(fMean-fBlackoutLimit*fSigma);
|
---|
245 |
|
---|
246 | if (first >= last)
|
---|
247 | return 0.;
|
---|
248 |
|
---|
249 | return fHGausHist.Integral(first, last, "width");
|
---|
250 | }
|
---|
251 |
|
---|
252 |
|
---|
253 | // -------------------------------------------------------------------------------
|
---|
254 | //
|
---|
255 | // Return the number of "pickup" events, which are events with values higher
|
---|
256 | // than fPickupLimit sigmas from the mean
|
---|
257 | //
|
---|
258 | //
|
---|
259 | const Double_t MHCalibrationPix::GetPickup() const
|
---|
260 | {
|
---|
261 |
|
---|
262 | if ((fMean == 0.) && (fSigma == 0.))
|
---|
263 | return -1.;
|
---|
264 |
|
---|
265 | const Int_t first = fHGausHist.GetXaxis()->FindBin(fMean+fPickupLimit*fSigma);
|
---|
266 | const Int_t last = fHGausHist.GetXaxis()->GetLast();
|
---|
267 |
|
---|
268 | if (first >= last)
|
---|
269 | return 0.;
|
---|
270 |
|
---|
271 | return fHGausHist.Integral(first, last, "width");
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 | // --------------------------------------------------------------------------
|
---|
276 | //
|
---|
277 | // Re-normalize the results, has to be overloaded
|
---|
278 | //
|
---|
279 | void MHCalibrationPix::Renorm()
|
---|
280 | {
|
---|
281 | }
|
---|
282 |
|
---|
283 | // -----------------------------------------------------------------------------
|
---|
284 | //
|
---|
285 | // If flag IsGausFitOK() is set (histogram already successfully fitted),
|
---|
286 | // returns kTRUE
|
---|
287 | //
|
---|
288 | // If both fMean and fSigma are still zero, call FitGaus()
|
---|
289 | //
|
---|
290 | // Repeats the Gauss fit in a smaller range, defined by:
|
---|
291 | //
|
---|
292 | // min = GetMean() - fBlackoutLimit * GetSigma();
|
---|
293 | // max = GetMean() + fPickupLimit * GetSigma();
|
---|
294 | //
|
---|
295 | // The fit results are retrieved and stored in class-own variables.
|
---|
296 | //
|
---|
297 | // A flag IsGausFitOK() is set according to whether the fit probability
|
---|
298 | // is smaller or bigger than fProbLimit, whether the NDF is bigger than
|
---|
299 | // fNDFLimit and whether results are NaNs.
|
---|
300 | //
|
---|
301 | Bool_t MHCalibrationPix::RepeatFit(const Option_t *option)
|
---|
302 | {
|
---|
303 |
|
---|
304 | if (IsGausFitOK())
|
---|
305 | return kTRUE;
|
---|
306 |
|
---|
307 | if ((fMean == 0.) && (fSigma == 0.))
|
---|
308 | return FitGaus();
|
---|
309 |
|
---|
310 | //
|
---|
311 | // Get new fitting ranges
|
---|
312 | //
|
---|
313 | Axis_t rmin = fMean - fBlackoutLimit * fSigma;
|
---|
314 | Axis_t rmax = fMean + fPickupLimit * fSigma;
|
---|
315 |
|
---|
316 | Axis_t hmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst());
|
---|
317 | Axis_t hmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast()) ;
|
---|
318 |
|
---|
319 | fFGausFit->SetRange(hmin < rmin ? rmin : hmin , hmax > rmax ? rmax : hmax);
|
---|
320 |
|
---|
321 | fHGausHist.Fit(fFGausFit,option);
|
---|
322 |
|
---|
323 | fMean = fFGausFit->GetParameter(1);
|
---|
324 | fSigma = fFGausFit->GetParameter(2);
|
---|
325 | fMeanErr = fFGausFit->GetParError(1) ;
|
---|
326 | fSigmaErr = fFGausFit->GetParError(2) ;
|
---|
327 | fProb = fFGausFit->GetProb() ;
|
---|
328 |
|
---|
329 | //
|
---|
330 | // The fit result is accepted under condition:
|
---|
331 | // 1) The results are not nan's
|
---|
332 | // 2) The NDF is not smaller than fNDFLimit (default: fgNDFLimit)
|
---|
333 | // 3) The Probability is greater than fProbLimit (default: fgProbLimit)
|
---|
334 | //
|
---|
335 | if ( TMath::IsNaN ( fMean )
|
---|
336 | || TMath::IsNaN ( fMeanErr )
|
---|
337 | || TMath::IsNaN ( fProb )
|
---|
338 | || TMath::IsNaN ( fSigma )
|
---|
339 | || TMath::IsNaN ( fSigmaErr )
|
---|
340 | || fFGausFit->GetNDF() < fNDFLimit
|
---|
341 | || fProb < fProbLimit )
|
---|
342 | return kFALSE;
|
---|
343 |
|
---|
344 | SetGausFitOK(kTRUE);
|
---|
345 | return kTRUE;
|
---|
346 |
|
---|
347 | }
|
---|
348 |
|
---|