source: trunk/MagicSoft/Mars/mcalib/MHCalibrationRelTimeCam.cc@ 4740

Last change on this file since 4740 was 4128, checked in by gaug, 21 years ago
*** empty log message ***
File size: 18.7 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// MHCalibrationRelTimeCam
27//
28// Fills the extracted relative arrival times of MArrivalTimeCam into
29// the MHGausEvents-classes MHCalibrationRelTimePix for every:
30//
31// - Pixel, stored in the TObjArray's MHCalibrationCam::fHiGainArray
32// or MHCalibrationCam::fHiGainArray, respectively, depending if
33// MArrivalTimePix::IsLoGainUsed() is set.
34//
35// - Average pixel per AREA index (e.g. inner and outer for the MAGIC camera),
36// stored in the TObjArray's MHCalibrationCam::fAverageHiGainAreas and
37// MHCalibrationCam::fAverageHiGainAreas
38//
39// - Average pixel per camera SECTOR (e.g. sectors 1-6 for the MAGIC camera),
40// stored in the TObjArray's MHCalibrationCam::fAverageHiGainSectors
41// and MHCalibrationCam::fAverageHiGainSectors
42//
43// Every relative time is calculated as the difference between the individual
44// pixel arrival time and the one of pixel 1 (hardware number: 2).
45// The relative times are filled into a histogram and an array, in order to perform
46// a Fourier analysis (see MHGausEvents). The signals are moreover averaged on an
47// event-by-event basis and written into the corresponding average pixels.
48//
49// The histograms are fitted to a Gaussian, mean and sigma with its errors
50// and the fit probability are extracted. If none of these values are NaN's and
51// if the probability is bigger than MHGausEvents::fProbLimit (default: 0.5%),
52// the fit is declared valid.
53// Otherwise, the fit is repeated within ranges of the previous mean
54// +- MHGausEvents::fPickupLimit (default: 5) sigma (see MHGausEvents::RepeatFit())
55// In case this does not make the fit valid, the histogram means and RMS's are
56// taken directly (see MHGausEvents::BypassFit()) and the following flags are set:
57// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kRelTimeNotFitted ) and
58// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
59//
60// Outliers of more than MHGausEvents::fPickupLimit (default: 5) sigmas
61// from the mean are counted as Pickup events (stored in MHGausEvents::fPickup)
62//
63// The class also fills arrays with the signal vs. event number, creates a fourier
64// spectrum (see MHGausEvents::CreateFourierSpectrum()) and investigates if the
65// projected fourier components follow an exponential distribution.
66// In case that the probability of the exponential fit is less than
67// MHGausEvents::fProbLimit (default: 0.5%), the following flags are set:
68// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kRelTimeOscillating ) and
69// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
70//
71// This same procedure is performed for the average pixels.
72//
73// The following results are written into MCalibrationRelTimeCam:
74//
75// - MCalibrationPix::SetMean()
76// - MCalibrationPix::SetMeanErr()
77// - MCalibrationPix::SetSigma()
78// - MCalibrationPix::SetSigmaErr()
79// - MCalibrationPix::SetProb()
80// - MCalibrationPix::SetNumPickup()
81//
82// For all averaged areas, the fitted sigma is multiplied with the square root of
83// the number involved pixels in order to be able to compare it to the average of
84// sigmas in the camera.
85//
86/////////////////////////////////////////////////////////////////////////////
87#include "MHCalibrationRelTimeCam.h"
88#include "MHCalibrationRelTimePix.h"
89
90#include "MLog.h"
91#include "MLogManip.h"
92
93#include "MParList.h"
94
95#include "MCalibrationRelTimeCam.h"
96#include "MCalibrationPix.h"
97
98#include "MArrivalTimeCam.h"
99#include "MArrivalTimePix.h"
100
101#include "MGeomCam.h"
102#include "MGeomPix.h"
103
104#include "MBadPixelsCam.h"
105#include "MBadPixelsPix.h"
106
107#include "MHGausEvents.h"
108
109ClassImp(MHCalibrationRelTimeCam);
110
111using namespace std;
112
113const Float_t MHCalibrationRelTimeCam::fgNumHiGainSaturationLimit = 0.25;
114const UInt_t MHCalibrationRelTimeCam::fgReferencePixel = 1;
115// --------------------------------------------------------------------------
116//
117// Default Constructor.
118//
119// Sets:
120// - fReferencePixel to fgReferencePixel
121//
122MHCalibrationRelTimeCam::MHCalibrationRelTimeCam(const char *name, const char *title)
123{
124
125 fName = name ? name : "MHCalibrationRelTimeCam";
126 fTitle = title ? title : "Histogram class for the relative time calibration of the camera";
127
128 SetNumHiGainSaturationLimit(fgNumHiGainSaturationLimit);
129 SetReferencePixel();
130}
131
132// --------------------------------------------------------------------------
133//
134// Gets or creates the pointers to:
135// - MCalibrationRelTimeCam
136//
137// Searches pointer to:
138// - MArrivalTimeCam
139//
140// Initializes, if empty to MGeomCam::GetNumPixels():
141// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
142//
143// Initializes, if empty to MGeomCam::GetNumAreas() for:
144// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
145//
146// Initializes, if empty to MGeomCam::GetNumSectors() for:
147// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
148//
149// Calls MHCalibrationCam::InitHists() for every entry in:
150// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
151// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
152// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
153//
154// Sets Titles and Names for the Histograms
155// - MHCalibrationCam::fAverageHiGainAreas
156// - MHCalibrationCam::fAverageHiGainSectors
157//
158// Sets number of bins to MHCalibrationCam::fAverageNbins for:
159// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
160// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
161//
162Bool_t MHCalibrationRelTimeCam::ReInitHists(MParList *pList)
163{
164
165
166 fCam = (MCalibrationCam*)pList->FindObject("MCalibrationRelTimeCam");
167 if (!fCam)
168 {
169 fCam = (MCalibrationCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationRelTimeCam"));
170 if (!fCam)
171 {
172 gLog << err << "Cannot find nor create MCalibrationRelTimeCam ... abort." << endl;
173 return kFALSE;
174 }
175 else
176 fCam->Init(*fGeom);
177 }
178
179
180 MArrivalTimeCam *signal = (MArrivalTimeCam*)pList->FindObject("MArrivalTimeCam");
181 if (!signal)
182 {
183 *fLog << err << "MArrivalTimeCam not found... abort." << endl;
184 return kFALSE;
185 }
186
187 const Int_t npixels = fGeom->GetNumPixels();
188 const Int_t nsectors = fGeom->GetNumSectors();
189 const Int_t nareas = fGeom->GetNumAreas();
190
191 if (fHiGainArray->GetEntries()==0)
192 {
193 fHiGainArray->Expand(npixels);
194 for (Int_t i=0; i<npixels; i++)
195 {
196 (*fHiGainArray)[i] = new MHCalibrationRelTimePix("MHCalibrationRelTimePixHiGain",
197 "Rel. Arr. Time Hi-Gain Pixel ");
198 InitHists((*this)[i],(*fBadPixels)[i],i);
199 }
200 }
201
202 if (fLoGainArray->GetEntries()==0)
203 {
204 fLoGainArray->Expand(npixels);
205 for (Int_t i=0; i<npixels; i++)
206 {
207 (*fLoGainArray)[i] = new MHCalibrationRelTimePix("MHCalibrationRelTimePixLoGain",
208 "Rel. Arr. Time Lo-Gain Pixel ");
209 InitHists((*this)(i),(*fBadPixels)[i],i);
210 }
211 }
212
213
214 if (fAverageHiGainAreas->GetEntries()==0)
215 {
216 fAverageHiGainAreas->Expand(nareas);
217
218 for (Int_t j=0; j<nareas; j++)
219 {
220 (*fAverageHiGainAreas)[j] =
221 new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageAreaHiGain",
222 "Average Rel. Arr. Times Hi-Gain Area Idx ");
223
224 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("Rel. Arr. Times HiGain Area Idx ");
225 GetAverageHiGainArea(j).SetNbins(fAverageNbins);
226
227 InitHists(GetAverageHiGainArea(j),fCam->GetAverageBadArea(j),j);
228 }
229 }
230
231 if (fAverageLoGainAreas->GetEntries()==0)
232 {
233 fAverageLoGainAreas->Expand(nareas);
234
235 for (Int_t j=0; j<nareas; j++)
236 {
237 (*fAverageLoGainAreas)[j] =
238 new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageAreaLoGain",
239 "Average Rel. Arr. Times Lo-Gain Area Idx ");
240
241 GetAverageLoGainArea(j).GetHGausHist()->SetTitle("Rel. Arr. Times LoGain Area Idx ");
242 GetAverageLoGainArea(j).SetNbins(fAverageNbins);
243
244 InitHists(GetAverageLoGainArea(j),fCam->GetAverageBadArea(j),j);
245 }
246 }
247
248 if (fAverageHiGainSectors->GetEntries()==0)
249 {
250 fAverageHiGainSectors->Expand(nsectors);
251
252 for (Int_t j=0; j<nsectors; j++)
253 {
254 (*fAverageHiGainSectors)[j] =
255 new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageSectorHiGain",
256 "Average Rel. Arr. Times Hi-Gain Sector ");
257
258 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("Rel. Arr. Times HiGain Sector ");
259 GetAverageHiGainSector(j).SetNbins(fAverageNbins);
260
261 InitHists(GetAverageHiGainSector(j),fCam->GetAverageBadSector(j),j);
262 }
263 }
264
265 if (fAverageLoGainSectors->GetEntries()==0)
266 {
267 fAverageLoGainSectors->Expand(nsectors);
268
269 for (Int_t j=0; j<nsectors; j++)
270 {
271 (*fAverageLoGainSectors)[j] =
272 new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageSectorLoGain",
273 "Average Rel. Arr. Times Lo-Gain Sector ");
274
275 GetAverageLoGainSector(j).GetHGausHist()->SetTitle("Rel. Arr. Times LoGain Sector ");
276 GetAverageLoGainSector(j).SetNbins(fAverageNbins);
277
278 InitHists(GetAverageLoGainSector(j),fCam->GetAverageBadSector(j),j);
279
280 }
281 }
282
283 return kTRUE;
284}
285
286
287// -------------------------------------------------------------------------------
288//
289// Retrieves pointer to MArrivalTimeCam:
290//
291// Retrieves from MGeomCam:
292// - number of pixels
293// - number of pixel areas
294// - number of sectors
295//
296// Fills HiGain or LoGain histograms (MHGausEvents::FillHistAndArray()), respectively
297// depending on MArrivalTimePix::IsLoGainUsed(), with:
298// - MArrivalTimePix::GetArrivalTime(pixid) - MArrivalTimePix::GetArrivalTime(1);
299// (i.e. the time difference between pixel i and pixel 1 (hardware number: 2) )
300//
301Bool_t MHCalibrationRelTimeCam::FillHists(const MParContainer *par, const Stat_t w)
302{
303
304 MArrivalTimeCam *arrtime = (MArrivalTimeCam*)par;
305 if (!arrtime)
306 {
307 gLog << err << "No argument in MArrivalTime::Fill... abort." << endl;
308 return kFALSE;
309 }
310
311 const Int_t npixels = fGeom->GetNumPixels();
312 const Int_t nareas = fGeom->GetNumAreas();
313 const Int_t nsectors = fGeom->GetNumSectors();
314
315 Float_t sumareahi [nareas], sumarealo [nareas];
316 Float_t sumsectorhi[nsectors], sumsectorlo[nsectors];
317 Int_t numareahi [nareas], numarealo [nareas];
318 Int_t numsectorhi[nsectors], numsectorlo[nsectors];
319
320 memset(sumareahi, 0, nareas * sizeof(Float_t));
321 memset(sumarealo, 0, nareas * sizeof(Float_t));
322 memset(sumsectorhi, 0, nsectors*sizeof(Float_t));
323 memset(sumsectorlo, 0, nsectors*sizeof(Float_t));
324 memset(numareahi, 0, nareas * sizeof(Float_t));
325 memset(numarealo, 0, nareas * sizeof(Float_t));
326 memset(numsectorhi, 0, nsectors*sizeof(Float_t));
327 memset(numsectorlo, 0, nsectors*sizeof(Float_t));
328
329 const MArrivalTimePix &refpix = (*arrtime)[fReferencePixel];
330 const Float_t reftime = refpix.IsLoGainUsed()
331 ? refpix.GetArrivalTimeLoGain() : refpix.GetArrivalTimeHiGain();
332
333 for (Int_t i=0; i<npixels; i++)
334 {
335
336 MHGausEvents &histhi = (*this)[i];
337 MHGausEvents &histlo = (*this)(i);
338
339 if (histhi.IsExcluded())
340 continue;
341
342 const MArrivalTimePix &pix = (*arrtime)[i];
343 const Int_t aidx = (*fGeom)[i].GetAidx();
344 const Int_t sector = (*fGeom)[i].GetSector();
345
346 if (pix.IsLoGainUsed())
347 {
348 const Float_t reltime = pix.GetArrivalTimeLoGain() - reftime;
349 histhi.SetSaturated(1);
350 histlo.FillHistAndArray(reltime);
351 sumarealo [aidx] += reltime;
352 numarealo [aidx] ++;
353 sumsectorlo[sector] += reltime;
354 numsectorlo[sector] ++;
355 }
356 else
357 {
358 const Float_t reltime = pix.GetArrivalTimeHiGain() - reftime;
359 histhi.FillHistAndArray(reltime) ;
360 sumareahi [aidx] += reltime;
361 numareahi [aidx] ++;
362 sumsectorhi[sector] += reltime;
363 numsectorhi[sector] ++;
364 }
365 }
366
367 for (Int_t j=0; j<nareas; j++)
368 {
369 MHGausEvents &histhi = GetAverageHiGainArea(j);
370 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
371
372 MHGausEvents &histlo = GetAverageLoGainArea(j);
373 histlo.FillHistAndArray(numarealo[j] == 0 ? 0. : sumarealo[j]/numarealo[j]);
374 }
375
376 for (Int_t j=0; j<nsectors; j++)
377 {
378 MHGausEvents &histhi = GetAverageHiGainSector(j);
379 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
380
381 MHGausEvents &histlo = GetAverageLoGainSector(j);
382 histlo.FillHistAndArray(numsectorlo[j] == 0 ? 0. : sumsectorlo[j]/numsectorlo[j]);
383 }
384
385 return kTRUE;
386}
387
388// --------------------------------------------------------------------------
389//
390// Calls:
391// - MHCalibrationCam::FitHiGainArrays() with flags:
392// MBadPixelsPix::kRelTimeNotFitted and MBadPixelsPix::kRelTimeOscillating
393// - MHCalibrationCam::FitLoGainArrays() with flags:
394// MBadPixelsPix::kRelTimeNotFitted and MBadPixelsPix::kRelTimeOscillating
395//
396Bool_t MHCalibrationRelTimeCam::FinalizeHists()
397{
398
399 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
400 {
401
402 MHCalibrationRelTimePix &histhi = (MHCalibrationRelTimePix&)(*this)[i];
403
404 if (histhi.IsExcluded())
405 continue;
406
407 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
408 {
409 (*fCam)[i].SetHiGainSaturation();
410 histhi.SetExcluded();
411 }
412 else
413 (*this)(i).SetExcluded();
414
415 }
416
417
418 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
419 {
420
421 MHCalibrationRelTimePix &histhi = (MHCalibrationRelTimePix&)GetAverageHiGainArea(j);
422
423 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
424 {
425 fCam->GetAverageArea(j).SetHiGainSaturation();
426 histhi.SetExcluded();
427 }
428 else
429 GetAverageLoGainArea(j).SetExcluded();
430
431 }
432
433
434 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
435 {
436
437 MHCalibrationRelTimePix &histhi = (MHCalibrationRelTimePix&)GetAverageHiGainSector(j);
438
439 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
440 {
441 fCam->GetAverageSector(j).SetHiGainSaturation();
442 histhi.SetExcluded();
443 }
444 else
445 GetAverageHiGainSector(j).SetExcluded();
446 }
447
448
449 FitHiGainArrays((*fCam),*fBadPixels,
450 MBadPixelsPix::kRelTimeNotFitted,
451 MBadPixelsPix::kRelTimeOscillating);
452
453 FitLoGainArrays((*fCam),*fBadPixels,
454 MBadPixelsPix::kRelTimeNotFitted,
455 MBadPixelsPix::kRelTimeOscillating);
456
457 return kTRUE;
458}
459
460// --------------------------------------------------------------------------
461//
462// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
463// - MBadPixelsPix::kRelTimeNotFitted
464// - MBadPixelsPix::kRelTimeOscillating
465//
466void MHCalibrationRelTimeCam::FinalizeBadPixels()
467{
468
469 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
470 {
471
472 MBadPixelsPix &bad = (*fBadPixels)[i];
473
474 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeNotFitted ))
475 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
476
477 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeOscillating))
478 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
479
480 }
481}
482
483// --------------------------------------------------------------------------
484//
485// The types are as follows:
486//
487// Fitted values:
488// ==============
489//
490// 0: Fitted Mean Relative Arrival Time in ns (MHGausEvents::GetMean()*MHCalibrationRelTimePix::GetFADCSliceWidth())
491// 1: Error Mean Relative Arrival Time in ns (MHGausEvents::GetMeanErr()*MHCalibrationRelTimePix::GetFADCSliceWidth())
492// 2: Sigma fitted Relative Arrival Time in ns (MHGausEvents::GetSigma()*MHCalibrationRelTimePix::GetFADCSliceWidth())
493// 3: Error Sigma Relative Arrival Time in ns (MHGausEvents::GetSigmaErr()*MHCalibrationRelTimePix::GetFADCSliceWidth())
494//
495// Useful variables derived from the fit results:
496// =============================================
497//
498// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
499//
500// Localized defects:
501// ==================
502//
503// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
504// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
505//
506Bool_t MHCalibrationRelTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
507{
508
509 if (fHiGainArray->GetSize() <= idx)
510 return kFALSE;
511
512 const MHCalibrationRelTimePix &pix = (MHCalibrationRelTimePix&)(*this)[idx];
513 const Float_t fadc2ns = pix.GetFADCSliceWidth();
514
515 switch (type)
516 {
517 case 0:
518 val = pix.GetMean()*fadc2ns;
519 break;
520 case 1:
521 val = pix.GetMeanErr()*fadc2ns;
522 break;
523 case 2:
524 val = pix.GetSigma()*fadc2ns;
525 break;
526 case 3:
527 val = pix.GetSigmaErr()*fadc2ns;
528 break;
529 case 4:
530 val = pix.GetProb();
531 break;
532 case 5:
533 if (!pix.IsGausFitOK())
534 val = 1.;
535 break;
536 case 6:
537 if (!pix.IsFourierSpectrumOK())
538 val = 1.;
539 break;
540 default:
541 return kFALSE;
542 }
543 return kTRUE;
544}
545
546// --------------------------------------------------------------------------
547//
548// Calls MHGausEvents::DrawClone() for pixel idx
549//
550void MHCalibrationRelTimeCam::DrawPixelContent(Int_t idx) const
551{
552 (*this)[idx].DrawClone();
553}
Note: See TracBrowser for help on using the repository browser.