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 "MSignalCam.h"
|
---|
97 | #include "MSignalPix.h"
|
---|
98 |
|
---|
99 | #include "MGeomCam.h"
|
---|
100 | #include "MGeomPix.h"
|
---|
101 |
|
---|
102 | #include "MBadPixelsCam.h"
|
---|
103 | #include "MBadPixelsPix.h"
|
---|
104 |
|
---|
105 | #include <TOrdCollection.h>
|
---|
106 |
|
---|
107 | ClassImp(MHCalibrationTestTimeCam);
|
---|
108 |
|
---|
109 | using namespace std;
|
---|
110 |
|
---|
111 | const Int_t MHCalibrationTestTimeCam::fgNbins = 300;
|
---|
112 | const Axis_t MHCalibrationTestTimeCam::fgFirst = -0.025;
|
---|
113 | const Axis_t MHCalibrationTestTimeCam::fgLast = 14.975;
|
---|
114 | const Float_t MHCalibrationTestTimeCam::fgProbLimit = 0.00000001;
|
---|
115 | const TString MHCalibrationTestTimeCam::gsHistName = "TestTime";
|
---|
116 | const TString MHCalibrationTestTimeCam::gsHistTitle = "Calibrated Calibration Arrival Times";
|
---|
117 | const TString MHCalibrationTestTimeCam::gsHistXTitle = "Arrival Time [FADC slices]";
|
---|
118 | const TString MHCalibrationTestTimeCam::gsHistYTitle = "Nr. events";
|
---|
119 |
|
---|
120 | // --------------------------------------------------------------------------
|
---|
121 | //
|
---|
122 | // Default Constructor.
|
---|
123 | //
|
---|
124 | // Sets:
|
---|
125 | // - fNbins to fgNbins
|
---|
126 | // - fFirst to fgFirst
|
---|
127 | // - fLast to fgLast
|
---|
128 | //
|
---|
129 | // - fHistName to gsHistName
|
---|
130 | // - fHistTitle to gsHistTitle
|
---|
131 | // - fHistXTitle to gsHistXTitle
|
---|
132 | // - fHistYTitle to gsHistYTitle
|
---|
133 | //
|
---|
134 | MHCalibrationTestTimeCam::MHCalibrationTestTimeCam(const char *name, const char *title)
|
---|
135 | {
|
---|
136 |
|
---|
137 | fName = name ? name : "MHCalibrationTestTimeCam";
|
---|
138 | fTitle = title ? title : "Histogram class for testing the calibration of arrival times";
|
---|
139 |
|
---|
140 | SetBinning(fgNbins, fgFirst, 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 | const Int_t npixels = fGeom->GetNumPixels();
|
---|
171 | const Int_t nsectors = fGeom->GetNumSectors();
|
---|
172 | const Int_t nareas = fGeom->GetNumAreas();
|
---|
173 |
|
---|
174 | InitHiGainArrays(npixels,nareas,nsectors);
|
---|
175 | InitLoGainArrays(npixels,nareas,nsectors);
|
---|
176 |
|
---|
177 | return kTRUE;
|
---|
178 | }
|
---|
179 |
|
---|
180 |
|
---|
181 | // -------------------------------------------------------------------------------
|
---|
182 | //
|
---|
183 | // Retrieves pointer to MArrivalTime:
|
---|
184 | //
|
---|
185 | // Retrieves from MGeomCam:
|
---|
186 | // - number of pixels
|
---|
187 | // - number of pixel areas
|
---|
188 | // - number of sectors
|
---|
189 | //
|
---|
190 | // Fills HiGain histograms (MHGausEvents::FillHistAndArray())
|
---|
191 | // with:
|
---|
192 | // - MArrivalTime::GetArrivalTime(pixid) - MArrivalTime::GetArrivalTime(1);
|
---|
193 | // (i.e. the time difference between pixel i and pixel 1 (hardware number: 2) )
|
---|
194 | //
|
---|
195 | Bool_t MHCalibrationTestTimeCam::FillHists(const MParContainer *par, const Stat_t w)
|
---|
196 | {
|
---|
197 |
|
---|
198 | MSignalCam *calibration = (MSignalCam*)par;
|
---|
199 | if (!calibration)
|
---|
200 | {
|
---|
201 | gLog << err << "No argument in MHCalibrationRelTimeCam::Fill... abort." << endl;
|
---|
202 | return kFALSE;
|
---|
203 | }
|
---|
204 |
|
---|
205 | const Int_t npixels = fGeom->GetNumPixels();
|
---|
206 | const Int_t nareas = fGeom->GetNumAreas();
|
---|
207 | const Int_t nsectors = fGeom->GetNumSectors();
|
---|
208 |
|
---|
209 | TArrayF sumareahi (nareas);
|
---|
210 | TArrayF sumsectorhi(nsectors);
|
---|
211 | TArrayI numareahi (nareas);
|
---|
212 | TArrayI numsectorhi(nsectors);
|
---|
213 |
|
---|
214 | for (Int_t i=0; i<npixels; i++)
|
---|
215 | {
|
---|
216 |
|
---|
217 | MHCalibrationPix &histhi = (*this)[i];
|
---|
218 |
|
---|
219 | if (histhi.IsExcluded())
|
---|
220 | continue;
|
---|
221 |
|
---|
222 | const Float_t time = (*calibration)[i].GetArrivalTime();
|
---|
223 | const Int_t aidx = (*fGeom)[i].GetAidx();
|
---|
224 | const Int_t sector = (*fGeom)[i].GetSector();
|
---|
225 |
|
---|
226 | histhi.FillHistAndArray(time) ;
|
---|
227 | sumareahi [aidx] += time;
|
---|
228 | numareahi [aidx] ++;
|
---|
229 | sumsectorhi[sector] += time;
|
---|
230 | numsectorhi[sector] ++;
|
---|
231 | }
|
---|
232 |
|
---|
233 | for (Int_t j=0; j<nareas; j++)
|
---|
234 | {
|
---|
235 | MHCalibrationPix &histhi = GetAverageHiGainArea(j);
|
---|
236 | histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
|
---|
237 |
|
---|
238 | }
|
---|
239 |
|
---|
240 | for (Int_t j=0; j<nsectors; j++)
|
---|
241 | {
|
---|
242 | MHCalibrationPix &histhi = GetAverageHiGainSector(j);
|
---|
243 | histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
|
---|
244 |
|
---|
245 | }
|
---|
246 |
|
---|
247 | return kTRUE;
|
---|
248 | }
|
---|
249 |
|
---|
250 | // --------------------------------------------------------------------------
|
---|
251 | //
|
---|
252 | //
|
---|
253 | Bool_t MHCalibrationTestTimeCam::FinalizeHists()
|
---|
254 | {
|
---|
255 |
|
---|
256 | for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
|
---|
257 | {
|
---|
258 |
|
---|
259 | MHCalibrationPix &hist = (*this)[i];
|
---|
260 |
|
---|
261 | if (hist.IsExcluded())
|
---|
262 | continue;
|
---|
263 |
|
---|
264 | if (hist.IsEmpty())
|
---|
265 | continue;
|
---|
266 |
|
---|
267 | if (!hist.FitGaus())
|
---|
268 | if (!hist.RepeatFit())
|
---|
269 | {
|
---|
270 | hist.BypassFit();
|
---|
271 | }
|
---|
272 |
|
---|
273 | hist.CreateFourierSpectrum();
|
---|
274 |
|
---|
275 | }
|
---|
276 |
|
---|
277 | for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
|
---|
278 | {
|
---|
279 |
|
---|
280 | MHCalibrationPix &hist = GetAverageHiGainArea(j);
|
---|
281 | if (hist.IsEmpty())
|
---|
282 | continue;
|
---|
283 |
|
---|
284 | if (!hist.FitGaus())
|
---|
285 | if (!hist.RepeatFit())
|
---|
286 | {
|
---|
287 | hist.BypassFit();
|
---|
288 | }
|
---|
289 |
|
---|
290 | hist.CreateFourierSpectrum();
|
---|
291 |
|
---|
292 |
|
---|
293 | }
|
---|
294 |
|
---|
295 | for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
|
---|
296 | {
|
---|
297 |
|
---|
298 | MHCalibrationPix &hist = GetAverageHiGainSector(j);
|
---|
299 | if (hist.IsEmpty())
|
---|
300 | continue;
|
---|
301 |
|
---|
302 | if (!hist.FitGaus())
|
---|
303 | if (!hist.RepeatFit())
|
---|
304 | {
|
---|
305 | hist.BypassFit();
|
---|
306 | }
|
---|
307 | hist.CreateFourierSpectrum();
|
---|
308 |
|
---|
309 |
|
---|
310 | }
|
---|
311 |
|
---|
312 | return kTRUE;
|
---|
313 | }
|
---|
314 |
|
---|
315 | // --------------------------------------------------------------------------
|
---|
316 | //
|
---|
317 | void MHCalibrationTestTimeCam::FinalizeBadPixels()
|
---|
318 | {
|
---|
319 |
|
---|
320 | }
|
---|
321 |
|
---|
322 | // --------------------------------------------------------------------------
|
---|
323 | //
|
---|
324 | // The types are as follows:
|
---|
325 | //
|
---|
326 | // Fitted values:
|
---|
327 | // ==============
|
---|
328 | //
|
---|
329 | // 0: Fitted Mean Time Calibration (MHGausEvents::GetMean())
|
---|
330 | // 1: Error Mean Time Calibration (MHGausEvents::GetMeanErr())
|
---|
331 | // 2: Sigma fitted Time Calibration (MHGausEvents::GetSigma())
|
---|
332 | // 3: Error Sigma Time Calibration (MHGausEvents::GetSigmaErr())
|
---|
333 | //
|
---|
334 | // Useful variables derived from the fit results:
|
---|
335 | // =============================================
|
---|
336 | //
|
---|
337 | // 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
|
---|
338 | //
|
---|
339 | // Localized defects:
|
---|
340 | // ==================
|
---|
341 | //
|
---|
342 | // 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
|
---|
343 | // 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
|
---|
344 | //
|
---|
345 | Bool_t MHCalibrationTestTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
---|
346 | {
|
---|
347 |
|
---|
348 | if (fHiGainArray->GetSize() <= idx)
|
---|
349 | return kFALSE;
|
---|
350 |
|
---|
351 | const MHCalibrationPix &pix = (*this)[idx];
|
---|
352 |
|
---|
353 | if (pix.IsExcluded())
|
---|
354 | return kFALSE;
|
---|
355 |
|
---|
356 | switch (type)
|
---|
357 | {
|
---|
358 | case 0:
|
---|
359 | val = pix.GetMean();
|
---|
360 | break;
|
---|
361 | case 1:
|
---|
362 | val = pix.GetMeanErr();
|
---|
363 | break;
|
---|
364 | case 2:
|
---|
365 | val = pix.GetSigma();
|
---|
366 | break;
|
---|
367 | case 3:
|
---|
368 | val = pix.GetSigmaErr();
|
---|
369 | break;
|
---|
370 | case 4:
|
---|
371 | val = pix.GetProb();
|
---|
372 | break;
|
---|
373 | case 5:
|
---|
374 | if (!pix.IsGausFitOK())
|
---|
375 | val = 1.;
|
---|
376 | break;
|
---|
377 | case 6:
|
---|
378 | if (!pix.IsFourierSpectrumOK())
|
---|
379 | val = 1.;
|
---|
380 | break;
|
---|
381 | default:
|
---|
382 | return kFALSE;
|
---|
383 | }
|
---|
384 | return kTRUE;
|
---|
385 | }
|
---|
386 |
|
---|
387 | // --------------------------------------------------------------------------
|
---|
388 | //
|
---|
389 | // Calls MHCalibrationPix::DrawClone() for pixel idx
|
---|
390 | //
|
---|
391 | void MHCalibrationTestTimeCam::DrawPixelContent(Int_t idx) const
|
---|
392 | {
|
---|
393 | (*this)[idx].DrawClone();
|
---|
394 | }
|
---|
395 |
|
---|
396 |
|
---|
397 | //------------------------------------------------------------
|
---|
398 | //
|
---|
399 | // For all averaged areas, the fitted sigma is multiplied with the square root of
|
---|
400 | // the number involved pixels
|
---|
401 | //
|
---|
402 | void MHCalibrationTestTimeCam::CalcAverageSigma()
|
---|
403 | {
|
---|
404 |
|
---|
405 | for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
|
---|
406 | {
|
---|
407 |
|
---|
408 | MHCalibrationPix &hist = GetAverageHiGainArea(j);
|
---|
409 |
|
---|
410 | const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
|
---|
411 | fAverageAreaSigma[j] = hist.GetSigma () * numsqr;
|
---|
412 | fAverageAreaSigmaVar[j] = hist.GetSigmaErr () * hist.GetSigmaErr() * numsqr;
|
---|
413 |
|
---|
414 | fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / hist.GetMean();
|
---|
415 | fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
|
---|
416 | fAverageAreaRelSigmaVar[j] += hist.GetMeanErr()*hist.GetMeanErr()/hist.GetMean()/hist.GetMean();
|
---|
417 | fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
|
---|
418 | }
|
---|
419 | }
|
---|