source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationTimeTestCam.cc@ 4940

Last change on this file since 4940 was 4929, checked in by gaug, 20 years ago
*** empty log message ***
File size: 15.9 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// MHCalibrationTimeTestCam
27//
28// Fills the calibrated signal from an MArrivalTime into
29// MHCalibrationTimeTestPix 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// +- MHGausEvents::fPickupLimit (default: 5) sigma (see MHGausEvents::RepeatFit())
52// In case this does not make the fit valid, the histogram means and RMS's are
53// taken directly (see MHGausEvents::BypassFit()) and the following flags are set:
54// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainNotFitted ) and
55// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
56//
57// Outliers of more than MHGausEvents::fPickupLimit (default: 5) sigmas
58// from the mean are counted as Pickup events (stored in MHGausEvents::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 "MHCalibrationTimeTestCam.h"
85#include "MHCalibrationTimeTestPix.h"
86
87#include "MLog.h"
88#include "MLogManip.h"
89
90#include "MParList.h"
91
92#include "MCalibrationCam.h"
93#include "MCalibrationPix.h"
94
95#include "MArrivalTime.h"
96
97#include "MGeomCam.h"
98#include "MGeomPix.h"
99
100#include "MBadPixelsCam.h"
101#include "MBadPixelsPix.h"
102
103ClassImp(MHCalibrationTimeTestCam);
104
105using namespace std;
106// --------------------------------------------------------------------------
107//
108// Default Constructor.
109//
110MHCalibrationTimeTestCam::MHCalibrationTimeTestCam(const char *name, const char *title)
111{
112
113 fName = name ? name : "MHCalibrationTimeTestCam";
114 fTitle = title ? title : "Histogram class for testing the calibration of arrival times";
115
116}
117
118// --------------------------------------------------------------------------
119//
120// Gets or creates the pointers to:
121//
122// Searches pointer to:
123// - MArrivalTime
124//
125// Initializes, if empty to MGeomCam::GetNumAreas() for:
126// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
127//
128// Initializes, if empty to MGeomCam::GetNumSectors() for:
129// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
130//
131// Calls MHCalibrationCam::InitHists() for every entry in:
132// - MHCalibrationCam::fHiGainArray
133// - MHCalibrationCam::fAverageHiGainAreas
134// - MHCalibrationCam::fAverageHiGainSectors
135//
136// Sets Titles and Names for the Histograms
137// - MHCalibrationCam::fAverageHiGainAreas
138// - MHCalibrationCam::fAverageHiGainSectors
139//
140// Sets number of bins to MHCalibrationCam::fAverageNbins for:
141// - MHCalibrationCam::fAverageHiGainAreas
142// - MHCalibrationCam::fAverageHiGainSectors
143//
144Bool_t MHCalibrationTimeTestCam::ReInitHists(MParList *pList)
145{
146
147 MArrivalTime *signal = (MArrivalTime*)pList->FindObject("MArrivalTime");
148 if (!signal)
149 {
150 *fLog << err << "MArrivalTime not found... abort." << endl;
151 return kFALSE;
152 }
153
154 const Int_t npixels = fGeom->GetNumPixels();
155 const Int_t nsectors = fGeom->GetNumSectors();
156 const Int_t nareas = fGeom->GetNumAreas();
157
158 if (fHiGainArray->GetEntries()==0)
159 {
160 fHiGainArray->Expand(npixels);
161 for (Int_t i=0; i<npixels; i++)
162 {
163 (*fHiGainArray)[i] = new MHCalibrationTimeTestPix("Calibrated Events Time",
164 "TimeTest Calibration Pixel");
165 InitHists((*this)[i],(*fBadPixels)[i],i);
166 }
167 }
168
169 if (fLoGainArray->GetEntries()==0)
170 {
171 fLoGainArray->Expand(npixels);
172 for (Int_t i=0; i<npixels; i++)
173 {
174 (*fLoGainArray)[i] = new MHCalibrationTimeTestPix("Calibrated Events Time",
175 "TimeTest Calibration Pixel");
176 InitHists((*this)(i),(*fBadPixels)[i],i);
177 }
178 }
179
180
181 if (fAverageHiGainAreas->GetEntries()==0)
182 {
183 fAverageHiGainAreas->Expand(nareas);
184
185 for (Int_t j=0; j<nareas; j++)
186 {
187 (*fAverageHiGainAreas)[j] =
188 new MHCalibrationTimeTestPix("MHCalibrationTimeTestAverageArea",
189 "Average TimeTest Calibrations Area Idx ");
190
191 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("TimeTest Calibrations Area Idx ");
192 GetAverageHiGainArea(j).SetNbins(fAverageNbins);
193 GetAverageHiGainArea(j).InitBins();
194 GetAverageHiGainArea(j).ChangeHistId(j);
195 GetAverageHiGainArea(j).SetEventFrequency(fPulserFrequency);
196
197 }
198 }
199
200 if (fAverageLoGainAreas->GetEntries()==0)
201 {
202 fAverageLoGainAreas->Expand(nareas);
203
204 for (Int_t j=0; j<nareas; j++)
205 {
206 (*fAverageLoGainAreas)[j] =
207 new MHCalibrationTimeTestPix("MHCalibrationTimeTestAverageArea",
208 "Average TimeTest Calibrations Area Idx ");
209
210 GetAverageLoGainArea(j).GetHGausHist()->SetTitle("TimeTest Calibrations Area Idx ");
211 GetAverageLoGainArea(j).SetNbins(fAverageNbins);
212 GetAverageLoGainArea(j).InitBins();
213 GetAverageLoGainArea(j).ChangeHistId(j);
214 GetAverageLoGainArea(j).SetEventFrequency(fPulserFrequency);
215
216 }
217 }
218
219
220 if (fAverageHiGainSectors->GetEntries()==0)
221 {
222 fAverageHiGainSectors->Expand(nsectors);
223
224 for (Int_t j=0; j<nsectors; j++)
225 {
226 (*fAverageHiGainSectors)[j] =
227 new MHCalibrationTimeTestPix("MHCalibrationTimeTestAverageSector",
228 "Average TimeTest Calibrations Sector ");
229
230 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("TimeTest Calibrations Sector ");
231 GetAverageHiGainSector(j).SetNbins(fAverageNbins);
232 GetAverageHiGainSector(j).InitBins();
233 GetAverageHiGainSector(j).ChangeHistId(j);
234 GetAverageHiGainSector(j).SetEventFrequency(fPulserFrequency);
235 }
236 }
237
238
239 if (fAverageLoGainSectors->GetEntries()==0)
240 {
241 fAverageLoGainSectors->Expand(nsectors);
242
243 for (Int_t j=0; j<nsectors; j++)
244 {
245 (*fAverageLoGainSectors)[j] =
246 new MHCalibrationTimeTestPix("MHCalibrationTimeTestAverageSector",
247 "Average TimeTest Calibrations Sector ");
248
249 GetAverageLoGainSector(j).GetHGausHist()->SetTitle("TimeTest Calibrations Sector ");
250 GetAverageLoGainSector(j).SetNbins(fAverageNbins);
251 GetAverageLoGainSector(j).InitBins();
252 GetAverageLoGainSector(j).ChangeHistId(j);
253 GetAverageLoGainSector(j).SetEventFrequency(fPulserFrequency);
254 }
255 }
256
257
258 return kTRUE;
259}
260
261
262// -------------------------------------------------------------------------------
263//
264// Retrieves pointer to MArrivalTime:
265//
266// Retrieves from MGeomCam:
267// - number of pixels
268// - number of pixel areas
269// - number of sectors
270//
271// Fills HiGain or LoGain histograms (MHGausEvents::FillHistAndArray()), respectively
272// depending on MCerPhotPix::IsLoGainUsed(), with:
273// - MCerPhotPix::GetArrivalTime(pixid) - MCerPhotPix::GetArrivalTime(1);
274// (i.e. the time difference between pixel i and pixel 1 (hardware number: 2) )
275//
276Bool_t MHCalibrationTimeTestCam::FillHists(const MParContainer *par, const Stat_t w)
277{
278
279 MArrivalTime *calibration = (MArrivalTime*)par;
280 if (!calibration)
281 {
282 gLog << err << "No argument in MHCalibrationRelTimeCam::Fill... abort." << endl;
283 return kFALSE;
284 }
285
286 const Int_t npixels = fGeom->GetNumPixels();
287 const Int_t nareas = fGeom->GetNumAreas();
288 const Int_t nsectors = fGeom->GetNumSectors();
289
290 Float_t sumareahi [nareas];
291 Float_t sumsectorhi[nsectors];
292 Int_t numareahi [nareas];
293 Int_t numsectorhi[nsectors];
294
295 memset(sumareahi, 0, nareas * sizeof(Float_t));
296 memset(sumsectorhi, 0, nsectors*sizeof(Float_t));
297
298 for (Int_t i=0; i<npixels; i++)
299 {
300
301 MHGausEvents &histhi = (*this)[i];
302
303 if (histhi.IsExcluded())
304 continue;
305
306 const Float_t time = (*calibration)[i];
307 const Int_t aidx = (*fGeom)[i].GetAidx();
308 const Int_t sector = (*fGeom)[i].GetSector();
309
310 histhi.FillHistAndArray(time) ;
311 sumareahi [aidx] += time;
312 numareahi [aidx] ++;
313 sumsectorhi[sector] += time;
314 numsectorhi[sector] ++;
315 }
316
317 for (Int_t j=0; j<nareas; j++)
318 {
319 MHGausEvents &histhi = GetAverageHiGainArea(j);
320 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
321
322 }
323
324 for (Int_t j=0; j<nsectors; j++)
325 {
326 MHGausEvents &histhi = GetAverageHiGainSector(j);
327 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
328
329 }
330
331 return kTRUE;
332}
333
334// --------------------------------------------------------------------------
335//
336// Calls:
337// - MHCalibrationCam::FitHiGainArrays() with flags:
338// MBadPixelsPix::kTimeTestNotFitted and MBadPixelsPix::kTimeTestOscillating
339// - MHCalibrationCam::FitLoGainArrays() with flags:
340// MBadPixelsPix::kTimeTestNotFitted and MBadPixelsPix::kTimeTestOscillating
341//
342Bool_t MHCalibrationTimeTestCam::FinalizeHists()
343{
344
345 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
346 {
347
348 MHGausEvents &hist = (*this)[i];
349
350 if (hist.IsExcluded())
351 continue;
352
353 if (hist.IsEmpty())
354 continue;
355
356 if (!hist.FitGaus())
357 if (!hist.RepeatFit())
358 {
359 hist.BypassFit();
360 }
361
362 hist.CreateFourierSpectrum();
363
364 }
365
366 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
367 {
368
369 MHGausEvents &hist = GetAverageHiGainArea(j);
370 if (hist.IsEmpty())
371 continue;
372
373 if (!hist.FitGaus())
374 if (!hist.RepeatFit())
375 {
376 hist.BypassFit();
377 }
378
379 hist.CreateFourierSpectrum();
380
381
382 }
383
384 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
385 {
386
387 MHGausEvents &hist = GetAverageHiGainSector(j);
388 if (hist.IsEmpty())
389 continue;
390
391 if (!hist.FitGaus())
392 if (!hist.RepeatFit())
393 {
394 hist.BypassFit();
395 }
396 hist.CreateFourierSpectrum();
397
398
399 }
400
401 return kTRUE;
402}
403
404// --------------------------------------------------------------------------
405//
406// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
407// - MBadPixelsPix::kTimeTestNotFitted
408// - MBadPixelsPix::kTimeTestOscillating
409//
410void MHCalibrationTimeTestCam::FinalizeBadPixels()
411{
412
413}
414
415// --------------------------------------------------------------------------
416//
417// The types are as follows:
418//
419// Fitted values:
420// ==============
421//
422// 0: Fitted Mean Time Calibration (MHGausEvents::GetMean())
423// 1: Error Mean Time Calibration (MHGausEvents::GetMeanErr())
424// 2: Sigma fitted Time Calibration (MHGausEvents::GetSigma())
425// 3: Error Sigma Time Calibration (MHGausEvents::GetSigmaErr())
426//
427// Useful variables derived from the fit results:
428// =============================================
429//
430// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
431//
432// Localized defects:
433// ==================
434//
435// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
436// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
437//
438Bool_t MHCalibrationTimeTestCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
439{
440
441 if (fHiGainArray->GetSize() <= idx)
442 return kFALSE;
443
444 const MHGausEvents &pix = (*this)[idx];
445
446 if (pix.IsExcluded())
447 return kFALSE;
448
449 switch (type)
450 {
451 case 0:
452 val = pix.GetMean();
453 break;
454 case 1:
455 val = pix.GetMeanErr();
456 break;
457 case 2:
458 val = pix.GetSigma();
459 break;
460 case 3:
461 val = pix.GetSigmaErr();
462 break;
463 case 4:
464 val = pix.GetProb();
465 break;
466 case 5:
467 if (!pix.IsGausFitOK())
468 val = 1.;
469 break;
470 case 6:
471 if (!pix.IsFourierSpectrumOK())
472 val = 1.;
473 break;
474 default:
475 return kFALSE;
476 }
477 return kTRUE;
478}
479
480// --------------------------------------------------------------------------
481//
482// Calls MHGausEvents::DrawClone() for pixel idx
483//
484void MHCalibrationTimeTestCam::DrawPixelContent(Int_t idx) const
485{
486 (*this)[idx].DrawClone();
487}
488
489
490//------------------------------------------------------------
491//
492// For all averaged areas, the fitted sigma is multiplied with the square root of
493// the number involved pixels
494//
495void MHCalibrationTimeTestCam::CalcAverageSigma()
496{
497
498 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
499 {
500
501 MHGausEvents &hist = GetAverageHiGainArea(j);
502
503 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
504 fAverageAreaSigma[j] = hist.GetSigma () * numsqr;
505 fAverageAreaSigmaVar[j] = hist.GetSigmaErr () * hist.GetSigmaErr() * numsqr;
506
507 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / hist.GetMean();
508 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
509 fAverageAreaRelSigmaVar[j] += hist.GetMeanErr()*hist.GetMeanErr()/hist.GetMean()/hist.GetMean();
510 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
511 }
512}
Note: See TracBrowser for help on using the repository browser.