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 | // MHCalibrationTestTimeCam
|
---|
27 | //
|
---|
28 | // Fills the calibrated signal from an MArrivalTime into
|
---|
29 | // MHCalibrationTestTimePix for every:
|
---|
30 | //
|
---|
31 | // - Pixel, stored in the TObjArray's MHCalibrationCam::fHiGainArray
|
---|
32 | // or MHCalibrationCam::fHiGainArray, respectively.
|
---|
33 | //
|
---|
34 | // - Average pixel per AREA index (e.g. inner and outer for the MAGIC camera),
|
---|
35 | // stored in the TObjArray's MHCalibrationCam::fAverageHiGainAreas and
|
---|
36 | // MHCalibrationCam::fAverageHiGainAreas
|
---|
37 | //
|
---|
38 | // - Average pixel per camera SECTOR (e.g. sectors 1-6 for the MAGIC camera),
|
---|
39 | // stored in the TObjArray's MHCalibrationCam::fAverageHiGainSectors
|
---|
40 | // and MHCalibrationCam::fAverageHiGainSectors
|
---|
41 | //
|
---|
42 | // The signals are filled into a histogram and an array, in order to perform
|
---|
43 | // a Fourier analysis (see MHGausEvents). The signals are moreover averaged on an
|
---|
44 | // event-by-event basis and written into the corresponding average pixels.
|
---|
45 | //
|
---|
46 | // The histograms are fitted to a Gaussian, mean and sigma with its errors
|
---|
47 | // and the fit probability are extracted. If none of these values are NaN's and
|
---|
48 | // if the probability is bigger than MHGausEvents::fProbLimit (default: 0.5%),
|
---|
49 | // the fit is declared valid.
|
---|
50 | // Otherwise, the fit is repeated within ranges of the previous mean
|
---|
51 | // +- MHCalibrationPix::fPickupLimit (default: 5) sigma (see MHCalibrationPix::RepeatFit())
|
---|
52 | // In case this does not make the fit valid, the histogram means and RMS's are
|
---|
53 | // taken directly (see MHCalibrationPix::BypassFit()) and the following flags are set:
|
---|
54 | // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainNotFitted ) and
|
---|
55 | // - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
|
---|
56 | //
|
---|
57 | // Outliers of more than MHCalibrationPix::fPickupLimit (default: 5) sigmas
|
---|
58 | // from the mean are counted as Pickup events (stored in MHCalibrationPix::fPickup)
|
---|
59 | //
|
---|
60 | // The class also fills arrays with the signal vs. event number, creates a fourier
|
---|
61 | // spectrum (see MHGausEvents::CreateFourierSpectrum()) and investigates if the
|
---|
62 | // projected fourier components follow an exponential distribution.
|
---|
63 | // In case that the probability of the exponential fit is less than
|
---|
64 | // MHGausEvents::fProbLimit (default: 0.5%), the following flags are set:
|
---|
65 | // - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainOscillating ) and
|
---|
66 | // - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
|
---|
67 | //
|
---|
68 | // This same procedure is performed for the average pixels.
|
---|
69 | //
|
---|
70 | // The following results are written into an MCalibrationCam:
|
---|
71 | //
|
---|
72 | // - MCalibrationPix::SetMean()
|
---|
73 | // - MCalibrationPix::SetMeanErr()
|
---|
74 | // - MCalibrationPix::SetSigma()
|
---|
75 | // - MCalibrationPix::SetSigmaErr()
|
---|
76 | // - MCalibrationPix::SetProb()
|
---|
77 | // - MCalibrationPix::SetNumPickup()
|
---|
78 | //
|
---|
79 | // For all averaged areas, the fitted sigma is multiplied with the square root of
|
---|
80 | // the number involved pixels in order to be able to compare it to the average of
|
---|
81 | // sigmas in the camera.
|
---|
82 | //
|
---|
83 | /////////////////////////////////////////////////////////////////////////////
|
---|
84 | #include "MHCalibrationTestTimeCam.h"
|
---|
85 |
|
---|
86 | #include "MHCalibrationPix.h"
|
---|
87 |
|
---|
88 | #include "MLog.h"
|
---|
89 | #include "MLogManip.h"
|
---|
90 |
|
---|
91 | #include "MParList.h"
|
---|
92 |
|
---|
93 | #include "MCalibrationCam.h"
|
---|
94 | #include "MCalibrationPix.h"
|
---|
95 |
|
---|
96 | #include "MArrivalTime.h"
|
---|
97 |
|
---|
98 | #include "MGeomCam.h"
|
---|
99 | #include "MGeomPix.h"
|
---|
100 |
|
---|
101 | #include "MBadPixelsCam.h"
|
---|
102 | #include "MBadPixelsPix.h"
|
---|
103 |
|
---|
104 | #include <TOrdCollection.h>
|
---|
105 |
|
---|
106 | ClassImp(MHCalibrationTestTimeCam);
|
---|
107 |
|
---|
108 | using namespace std;
|
---|
109 |
|
---|
110 | const Int_t MHCalibrationTestTimeCam::fgNbins = 600;
|
---|
111 | const Axis_t MHCalibrationTestTimeCam::fgFirst = -0.5;
|
---|
112 | const Axis_t MHCalibrationTestTimeCam::fgLast = 14.5;
|
---|
113 | const Float_t MHCalibrationTestTimeCam::fgProbLimit = 0.00000001;
|
---|
114 | const TString MHCalibrationTestTimeCam::gsHistName = "TestTime";
|
---|
115 | const TString MHCalibrationTestTimeCam::gsHistTitle = "Calibrated Calibration Arrival Times";
|
---|
116 | const TString MHCalibrationTestTimeCam::gsHistXTitle = "Arrival Time [FADC slices]";
|
---|
117 | const TString MHCalibrationTestTimeCam::gsHistYTitle = "Nr. events";
|
---|
118 | // --------------------------------------------------------------------------
|
---|
119 | //
|
---|
120 | // Default Constructor.
|
---|
121 | //
|
---|
122 | // Sets:
|
---|
123 | // - fNbins to fgNbins
|
---|
124 | // - fFirst to fgFirst
|
---|
125 | // - fLast to fgLast
|
---|
126 | //
|
---|
127 | // - fHistName to gsHistName
|
---|
128 | // - fHistTitle to gsHistTitle
|
---|
129 | // - fHistXTitle to gsHistXTitle
|
---|
130 | // - fHistYTitle to gsHistYTitle
|
---|
131 | //
|
---|
132 | MHCalibrationTestTimeCam::MHCalibrationTestTimeCam(const char *name, const char *title)
|
---|
133 | {
|
---|
134 |
|
---|
135 | fName = name ? name : "MHCalibrationTestTimeCam";
|
---|
136 | fTitle = title ? title : "Histogram class for testing the calibration of arrival times";
|
---|
137 |
|
---|
138 | SetNbins(fgNbins);
|
---|
139 | SetFirst(fgFirst);
|
---|
140 | SetLast (fgLast );
|
---|
141 |
|
---|
142 | SetProbLimit(fgProbLimit);
|
---|
143 |
|
---|
144 | SetHistName (gsHistName .Data());
|
---|
145 | SetHistTitle (gsHistTitle .Data());
|
---|
146 | SetHistXTitle(gsHistXTitle.Data());
|
---|
147 | SetHistYTitle(gsHistYTitle.Data());
|
---|
148 |
|
---|
149 | SetLoGain(kFALSE);
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 | // --------------------------------------------------------------------------
|
---|
154 | //
|
---|
155 | // Searches pointer to:
|
---|
156 | // - MArrivalTime
|
---|
157 | //
|
---|
158 | // Calls:
|
---|
159 | // - MHCalibrationCam::InitHiGainArrays()
|
---|
160 | //
|
---|
161 | // Sets:
|
---|
162 | // - SetLoGain(kFALSE);
|
---|
163 | //
|
---|
164 | Bool_t MHCalibrationTestTimeCam::ReInitHists(MParList *pList)
|
---|
165 | {
|
---|
166 |
|
---|
167 | if (!InitCams(pList,""))
|
---|
168 | return kFALSE;
|
---|
169 |
|
---|
170 | MArrivalTime *signal = (MArrivalTime*)pList->FindObject("MArrivalTime");
|
---|
171 | if (!signal)
|
---|
172 | {
|
---|
173 | *fLog << err << "MArrivalTime not found... abort." << endl;
|
---|
174 | return kFALSE;
|
---|
175 | }
|
---|
176 |
|
---|
177 | const Int_t npixels = fGeom->GetNumPixels();
|
---|
178 | const Int_t nsectors = fGeom->GetNumSectors();
|
---|
179 | const Int_t nareas = fGeom->GetNumAreas();
|
---|
180 |
|
---|
181 | InitHiGainArrays(npixels,nareas,nsectors);
|
---|
182 | InitLoGainArrays(npixels,nareas,nsectors);
|
---|
183 |
|
---|
184 | return kTRUE;
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | // -------------------------------------------------------------------------------
|
---|
189 | //
|
---|
190 | // Retrieves pointer to MArrivalTime:
|
---|
191 | //
|
---|
192 | // Retrieves from MGeomCam:
|
---|
193 | // - number of pixels
|
---|
194 | // - number of pixel areas
|
---|
195 | // - number of sectors
|
---|
196 | //
|
---|
197 | // Fills HiGain histograms (MHGausEvents::FillHistAndArray())
|
---|
198 | // with:
|
---|
199 | // - MArrivalTime::GetArrivalTime(pixid) - MArrivalTime::GetArrivalTime(1);
|
---|
200 | // (i.e. the time difference between pixel i and pixel 1 (hardware number: 2) )
|
---|
201 | //
|
---|
202 | Bool_t MHCalibrationTestTimeCam::FillHists(const MParContainer *par, const Stat_t w)
|
---|
203 | {
|
---|
204 |
|
---|
205 | MArrivalTime *calibration = (MArrivalTime*)par;
|
---|
206 | if (!calibration)
|
---|
207 | {
|
---|
208 | gLog << err << "No argument in MHCalibrationRelTimeCam::Fill... abort." << endl;
|
---|
209 | return kFALSE;
|
---|
210 | }
|
---|
211 |
|
---|
212 | const Int_t npixels = fGeom->GetNumPixels();
|
---|
213 | const Int_t nareas = fGeom->GetNumAreas();
|
---|
214 | const Int_t nsectors = fGeom->GetNumSectors();
|
---|
215 |
|
---|
216 | TArrayF sumareahi (nareas);
|
---|
217 | TArrayF sumsectorhi(nsectors);
|
---|
218 | TArrayI numareahi (nareas);
|
---|
219 | TArrayI numsectorhi(nsectors);
|
---|
220 |
|
---|
221 | for (Int_t i=0; i<npixels; i++)
|
---|
222 | {
|
---|
223 |
|
---|
224 | MHCalibrationPix &histhi = (*this)[i];
|
---|
225 |
|
---|
226 | if (histhi.IsExcluded())
|
---|
227 | continue;
|
---|
228 |
|
---|
229 | const Float_t time = (*calibration)[i];
|
---|
230 | const Int_t aidx = (*fGeom)[i].GetAidx();
|
---|
231 | const Int_t sector = (*fGeom)[i].GetSector();
|
---|
232 |
|
---|
233 | histhi.FillHistAndArray(time) ;
|
---|
234 | sumareahi [aidx] += time;
|
---|
235 | numareahi [aidx] ++;
|
---|
236 | sumsectorhi[sector] += time;
|
---|
237 | numsectorhi[sector] ++;
|
---|
238 | }
|
---|
239 |
|
---|
240 | for (Int_t j=0; j<nareas; j++)
|
---|
241 | {
|
---|
242 | MHCalibrationPix &histhi = GetAverageHiGainArea(j);
|
---|
243 | histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
|
---|
244 |
|
---|
245 | }
|
---|
246 |
|
---|
247 | for (Int_t j=0; j<nsectors; j++)
|
---|
248 | {
|
---|
249 | MHCalibrationPix &histhi = GetAverageHiGainSector(j);
|
---|
250 | histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
|
---|
251 |
|
---|
252 | }
|
---|
253 |
|
---|
254 | return kTRUE;
|
---|
255 | }
|
---|
256 |
|
---|
257 | // --------------------------------------------------------------------------
|
---|
258 | //
|
---|
259 | //
|
---|
260 | Bool_t MHCalibrationTestTimeCam::FinalizeHists()
|
---|
261 | {
|
---|
262 |
|
---|
263 | for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
|
---|
264 | {
|
---|
265 |
|
---|
266 | MHCalibrationPix &hist = (*this)[i];
|
---|
267 |
|
---|
268 | if (hist.IsExcluded())
|
---|
269 | continue;
|
---|
270 |
|
---|
271 | if (hist.IsEmpty())
|
---|
272 | continue;
|
---|
273 |
|
---|
274 | if (!hist.FitGaus())
|
---|
275 | if (!hist.RepeatFit())
|
---|
276 | {
|
---|
277 | hist.BypassFit();
|
---|
278 | }
|
---|
279 |
|
---|
280 | hist.CreateFourierSpectrum();
|
---|
281 |
|
---|
282 | }
|
---|
283 |
|
---|
284 | for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
|
---|
285 | {
|
---|
286 |
|
---|
287 | MHCalibrationPix &hist = GetAverageHiGainArea(j);
|
---|
288 | if (hist.IsEmpty())
|
---|
289 | continue;
|
---|
290 |
|
---|
291 | if (!hist.FitGaus())
|
---|
292 | if (!hist.RepeatFit())
|
---|
293 | {
|
---|
294 | hist.BypassFit();
|
---|
295 | }
|
---|
296 |
|
---|
297 | hist.CreateFourierSpectrum();
|
---|
298 |
|
---|
299 |
|
---|
300 | }
|
---|
301 |
|
---|
302 | for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
|
---|
303 | {
|
---|
304 |
|
---|
305 | MHCalibrationPix &hist = GetAverageHiGainSector(j);
|
---|
306 | if (hist.IsEmpty())
|
---|
307 | continue;
|
---|
308 |
|
---|
309 | if (!hist.FitGaus())
|
---|
310 | if (!hist.RepeatFit())
|
---|
311 | {
|
---|
312 | hist.BypassFit();
|
---|
313 | }
|
---|
314 | hist.CreateFourierSpectrum();
|
---|
315 |
|
---|
316 |
|
---|
317 | }
|
---|
318 |
|
---|
319 | return kTRUE;
|
---|
320 | }
|
---|
321 |
|
---|
322 | // --------------------------------------------------------------------------
|
---|
323 | //
|
---|
324 | void MHCalibrationTestTimeCam::FinalizeBadPixels()
|
---|
325 | {
|
---|
326 |
|
---|
327 | }
|
---|
328 |
|
---|
329 | // --------------------------------------------------------------------------
|
---|
330 | //
|
---|
331 | // The types are as follows:
|
---|
332 | //
|
---|
333 | // Fitted values:
|
---|
334 | // ==============
|
---|
335 | //
|
---|
336 | // 0: Fitted Mean Time Calibration (MHGausEvents::GetMean())
|
---|
337 | // 1: Error Mean Time Calibration (MHGausEvents::GetMeanErr())
|
---|
338 | // 2: Sigma fitted Time Calibration (MHGausEvents::GetSigma())
|
---|
339 | // 3: Error Sigma Time Calibration (MHGausEvents::GetSigmaErr())
|
---|
340 | //
|
---|
341 | // Useful variables derived from the fit results:
|
---|
342 | // =============================================
|
---|
343 | //
|
---|
344 | // 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
|
---|
345 | //
|
---|
346 | // Localized defects:
|
---|
347 | // ==================
|
---|
348 | //
|
---|
349 | // 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
|
---|
350 | // 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
|
---|
351 | //
|
---|
352 | Bool_t MHCalibrationTestTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
---|
353 | {
|
---|
354 |
|
---|
355 | if (fHiGainArray->GetSize() <= idx)
|
---|
356 | return kFALSE;
|
---|
357 |
|
---|
358 | const MHCalibrationPix &pix = (*this)[idx];
|
---|
359 |
|
---|
360 | if (pix.IsExcluded())
|
---|
361 | return kFALSE;
|
---|
362 |
|
---|
363 | switch (type)
|
---|
364 | {
|
---|
365 | case 0:
|
---|
366 | val = pix.GetMean();
|
---|
367 | break;
|
---|
368 | case 1:
|
---|
369 | val = pix.GetMeanErr();
|
---|
370 | break;
|
---|
371 | case 2:
|
---|
372 | val = pix.GetSigma();
|
---|
373 | break;
|
---|
374 | case 3:
|
---|
375 | val = pix.GetSigmaErr();
|
---|
376 | break;
|
---|
377 | case 4:
|
---|
378 | val = pix.GetProb();
|
---|
379 | break;
|
---|
380 | case 5:
|
---|
381 | if (!pix.IsGausFitOK())
|
---|
382 | val = 1.;
|
---|
383 | break;
|
---|
384 | case 6:
|
---|
385 | if (!pix.IsFourierSpectrumOK())
|
---|
386 | val = 1.;
|
---|
387 | break;
|
---|
388 | default:
|
---|
389 | return kFALSE;
|
---|
390 | }
|
---|
391 | return kTRUE;
|
---|
392 | }
|
---|
393 |
|
---|
394 | // --------------------------------------------------------------------------
|
---|
395 | //
|
---|
396 | // Calls MHCalibrationPix::DrawClone() for pixel idx
|
---|
397 | //
|
---|
398 | void MHCalibrationTestTimeCam::DrawPixelContent(Int_t idx) const
|
---|
399 | {
|
---|
400 | (*this)[idx].DrawClone();
|
---|
401 | }
|
---|
402 |
|
---|
403 |
|
---|
404 | //------------------------------------------------------------
|
---|
405 | //
|
---|
406 | // For all averaged areas, the fitted sigma is multiplied with the square root of
|
---|
407 | // the number involved pixels
|
---|
408 | //
|
---|
409 | void MHCalibrationTestTimeCam::CalcAverageSigma()
|
---|
410 | {
|
---|
411 |
|
---|
412 | for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
|
---|
413 | {
|
---|
414 |
|
---|
415 | MHCalibrationPix &hist = GetAverageHiGainArea(j);
|
---|
416 |
|
---|
417 | const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
|
---|
418 | fAverageAreaSigma[j] = hist.GetSigma () * numsqr;
|
---|
419 | fAverageAreaSigmaVar[j] = hist.GetSigmaErr () * hist.GetSigmaErr() * numsqr;
|
---|
420 |
|
---|
421 | fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / hist.GetMean();
|
---|
422 | fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
|
---|
423 | fAverageAreaRelSigmaVar[j] += hist.GetMeanErr()*hist.GetMeanErr()/hist.GetMean()/hist.GetMean();
|
---|
424 | fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
|
---|
425 | }
|
---|
426 | }
|
---|