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

Last change on this file since 4858 was 4815, checked in by gaug, 20 years ago
*** empty log message ***
File size: 18.6 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
109#include "MArrayI.h"
110#include "MArrayD.h"
111
112ClassImp(MHCalibrationRelTimeCam);
113
114using namespace std;
115
116const Float_t MHCalibrationRelTimeCam::fgNumHiGainSaturationLimit = 0.25;
117const UInt_t MHCalibrationRelTimeCam::fgReferencePixel = 1;
118// --------------------------------------------------------------------------
119//
120// Default Constructor.
121//
122// Sets:
123// - fReferencePixel to fgReferencePixel
124//
125MHCalibrationRelTimeCam::MHCalibrationRelTimeCam(const char *name, const char *title)
126{
127
128 fName = name ? name : "MHCalibrationRelTimeCam";
129 fTitle = title ? title : "Histogram class for the relative time calibration of the camera";
130
131 SetNumHiGainSaturationLimit(fgNumHiGainSaturationLimit);
132 SetReferencePixel();
133}
134
135// --------------------------------------------------------------------------
136//
137// Gets or creates the pointers to:
138// - MCalibrationRelTimeCam
139//
140// Searches pointer to:
141// - MArrivalTimeCam
142//
143// Initializes, if empty to MGeomCam::GetNumPixels():
144// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
145//
146// Initializes, if empty to MGeomCam::GetNumAreas() for:
147// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
148//
149// Initializes, if empty to MGeomCam::GetNumSectors() for:
150// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
151//
152// Calls MHCalibrationCam::InitHists() for every entry in:
153// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
154// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
155// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
156//
157// Sets Titles and Names for the Histograms
158// - MHCalibrationCam::fAverageHiGainAreas
159// - MHCalibrationCam::fAverageHiGainSectors
160//
161// Sets number of bins to MHCalibrationCam::fAverageNbins for:
162// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
163// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
164//
165Bool_t MHCalibrationRelTimeCam::ReInitHists(MParList *pList)
166{
167
168
169 fCam = (MCalibrationCam*)pList->FindObject("MCalibrationRelTimeCam");
170 if (!fCam)
171 {
172 fCam = (MCalibrationCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationRelTimeCam"));
173 if (!fCam)
174 {
175 gLog << err << "Cannot find nor create MCalibrationRelTimeCam ... abort." << endl;
176 return kFALSE;
177 }
178 else
179 fCam->Init(*fGeom);
180 }
181
182
183 MArrivalTimeCam *signal = (MArrivalTimeCam*)pList->FindObject("MArrivalTimeCam");
184 if (!signal)
185 {
186 *fLog << err << "MArrivalTimeCam not found... abort." << endl;
187 return kFALSE;
188 }
189
190 const Int_t npixels = fGeom->GetNumPixels();
191 const Int_t nsectors = fGeom->GetNumSectors();
192 const Int_t nareas = fGeom->GetNumAreas();
193
194 if (fHiGainArray->GetEntries()==0)
195 {
196 fHiGainArray->Expand(npixels);
197 for (Int_t i=0; i<npixels; i++)
198 {
199 (*fHiGainArray)[i] = new MHCalibrationRelTimePix("MHCalibrationRelTimePixHiGain",
200 "Rel. Arr. Time Hi-Gain Pixel ");
201 InitHists((*this)[i],(*fBadPixels)[i],i);
202 }
203 }
204
205 if (fLoGainArray->GetEntries()==0)
206 {
207 fLoGainArray->Expand(npixels);
208 for (Int_t i=0; i<npixels; i++)
209 {
210 (*fLoGainArray)[i] = new MHCalibrationRelTimePix("MHCalibrationRelTimePixLoGain",
211 "Rel. Arr. Time Lo-Gain Pixel ");
212 InitHists((*this)(i),(*fBadPixels)[i],i);
213 }
214 }
215
216
217 if (fAverageHiGainAreas->GetEntries()==0)
218 {
219 fAverageHiGainAreas->Expand(nareas);
220
221 for (Int_t j=0; j<nareas; j++)
222 {
223 (*fAverageHiGainAreas)[j] =
224 new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageAreaHiGain",
225 "Average Rel. Arr. Times Hi-Gain Area Idx ");
226
227 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("Rel. Arr. Times HiGain Area Idx ");
228 GetAverageHiGainArea(j).SetNbins(fAverageNbins);
229
230 InitHists(GetAverageHiGainArea(j),fCam->GetAverageBadArea(j),j);
231 }
232 }
233
234 if (fAverageLoGainAreas->GetEntries()==0)
235 {
236 fAverageLoGainAreas->Expand(nareas);
237
238 for (Int_t j=0; j<nareas; j++)
239 {
240 (*fAverageLoGainAreas)[j] =
241 new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageAreaLoGain",
242 "Average Rel. Arr. Times Lo-Gain Area Idx ");
243
244 GetAverageLoGainArea(j).GetHGausHist()->SetTitle("Rel. Arr. Times LoGain Area Idx ");
245 GetAverageLoGainArea(j).SetNbins(fAverageNbins);
246
247 InitHists(GetAverageLoGainArea(j),fCam->GetAverageBadArea(j),j);
248 }
249 }
250
251 if (fAverageHiGainSectors->GetEntries()==0)
252 {
253 fAverageHiGainSectors->Expand(nsectors);
254
255 for (Int_t j=0; j<nsectors; j++)
256 {
257 (*fAverageHiGainSectors)[j] =
258 new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageSectorHiGain",
259 "Average Rel. Arr. Times Hi-Gain Sector ");
260
261 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("Rel. Arr. Times HiGain Sector ");
262 GetAverageHiGainSector(j).SetNbins(fAverageNbins);
263
264 InitHists(GetAverageHiGainSector(j),fCam->GetAverageBadSector(j),j);
265 }
266 }
267
268 if (fAverageLoGainSectors->GetEntries()==0)
269 {
270 fAverageLoGainSectors->Expand(nsectors);
271
272 for (Int_t j=0; j<nsectors; j++)
273 {
274 (*fAverageLoGainSectors)[j] =
275 new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageSectorLoGain",
276 "Average Rel. Arr. Times Lo-Gain Sector ");
277
278 GetAverageLoGainSector(j).GetHGausHist()->SetTitle("Rel. Arr. Times LoGain Sector ");
279 GetAverageLoGainSector(j).SetNbins(fAverageNbins);
280
281 InitHists(GetAverageLoGainSector(j),fCam->GetAverageBadSector(j),j);
282
283 }
284 }
285
286 fSumareahi .Set(nareas);
287 fSumarealo .Set(nareas);
288 fSumsectorhi.Set(nsectors);
289 fSumsectorlo.Set(nsectors);
290 fNumareahi .Set(nareas);
291 fNumarealo .Set(nareas);
292 fNumsectorhi.Set(nsectors);
293 fNumsectorlo.Set(nsectors);
294
295 return kTRUE;
296}
297
298
299// -------------------------------------------------------------------------------
300//
301// Retrieves pointer to MArrivalTimeCam:
302//
303// Retrieves from MGeomCam:
304// - number of pixels
305// - number of pixel areas
306// - number of sectors
307//
308// Fills HiGain or LoGain histograms (MHGausEvents::FillHistAndArray()), respectively
309// depending on MArrivalTimePix::IsLoGainUsed(), with:
310// - MArrivalTimePix::GetArrivalTime(pixid) - MArrivalTimePix::GetArrivalTime(1);
311// (i.e. the time difference between pixel i and pixel 1 (hardware number: 2) )
312//
313Bool_t MHCalibrationRelTimeCam::FillHists(const MParContainer *par, const Stat_t w)
314{
315
316 MArrivalTimeCam *arrtime = (MArrivalTimeCam*)par;
317 if (!arrtime)
318 {
319 gLog << err << "No argument in MArrivalTime::Fill... abort." << endl;
320 return kFALSE;
321 }
322
323 const Int_t npixels = fGeom->GetNumPixels();
324 const Int_t nareas = fGeom->GetNumAreas();
325 const Int_t nsectors = fGeom->GetNumSectors();
326
327 fSumareahi .Reset();
328 fSumarealo .Reset();
329 fSumsectorhi.Reset();
330 fSumsectorlo.Reset();
331 fNumareahi .Reset();
332 fNumarealo .Reset();
333 fNumsectorhi.Reset();
334 fNumsectorlo.Reset();
335
336 const MArrivalTimePix &refpix = (*arrtime)[fReferencePixel];
337 const Float_t reftime = refpix.IsLoGainUsed()
338 ? refpix.GetArrivalTimeLoGain() : refpix.GetArrivalTimeHiGain();
339
340 for (Int_t i=0; i<npixels; i++)
341 {
342
343 MHGausEvents &histhi = (*this)[i];
344 MHGausEvents &histlo = (*this)(i);
345
346 if (histhi.IsExcluded())
347 continue;
348
349 const MArrivalTimePix &pix = (*arrtime)[i];
350 const Int_t aidx = (*fGeom)[i].GetAidx();
351 const Int_t sector = (*fGeom)[i].GetSector();
352
353 if (pix.IsLoGainUsed())
354 {
355 const Float_t reltime = pix.GetArrivalTimeLoGain() - reftime;
356 histhi.SetSaturated(1);
357 histlo.FillHistAndArray(reltime);
358 fSumarealo [aidx] += reltime;
359 fNumarealo [aidx] ++;
360 fSumsectorlo[sector] += reltime;
361 fNumsectorlo[sector] ++;
362 }
363 else
364 {
365 const Float_t reltime = pix.GetArrivalTimeHiGain() - reftime;
366 histhi.FillHistAndArray(reltime) ;
367 fSumareahi [aidx] += reltime;
368 fNumareahi [aidx] ++;
369 fSumsectorhi[sector] += reltime;
370 fNumsectorhi[sector] ++;
371 }
372 }
373
374 for (Int_t j=0; j<nareas; j++)
375 {
376 MHGausEvents &histhi = GetAverageHiGainArea(j);
377 histhi.FillHistAndArray(fNumareahi[j] == 0 ? 0. : fSumareahi[j]/fNumareahi[j]);
378
379 MHGausEvents &histlo = GetAverageLoGainArea(j);
380 histlo.FillHistAndArray(fNumarealo[j] == 0 ? 0. : fSumarealo[j]/fNumarealo[j]);
381 }
382
383 for (Int_t j=0; j<nsectors; j++)
384 {
385 MHGausEvents &histhi = GetAverageHiGainSector(j);
386 histhi.FillHistAndArray(fNumsectorhi[j] == 0 ? 0. : fSumsectorhi[j]/fNumsectorhi[j]);
387
388 MHGausEvents &histlo = GetAverageLoGainSector(j);
389 histlo.FillHistAndArray(fNumsectorlo[j] == 0 ? 0. : fSumsectorlo[j]/fNumsectorlo[j]);
390 }
391
392 return kTRUE;
393}
394
395// --------------------------------------------------------------------------
396//
397// Calls:
398// - MHCalibrationCam::FitHiGainArrays() with flags:
399// MBadPixelsPix::kRelTimeNotFitted and MBadPixelsPix::kRelTimeOscillating
400// - MHCalibrationCam::FitLoGainArrays() with flags:
401// MBadPixelsPix::kRelTimeNotFitted and MBadPixelsPix::kRelTimeOscillating
402//
403Bool_t MHCalibrationRelTimeCam::FinalizeHists()
404{
405
406 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
407 {
408
409 MHCalibrationRelTimePix &histhi = (MHCalibrationRelTimePix&)(*this)[i];
410
411 if (histhi.IsExcluded())
412 continue;
413
414 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
415 {
416 (*fCam)[i].SetHiGainSaturation();
417 histhi.SetExcluded();
418 }
419 else
420 (*this)(i).SetExcluded();
421
422 }
423
424
425 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
426 {
427
428 MHCalibrationRelTimePix &histhi = (MHCalibrationRelTimePix&)GetAverageHiGainArea(j);
429
430 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
431 {
432 fCam->GetAverageArea(j).SetHiGainSaturation();
433 histhi.SetExcluded();
434 }
435 else
436 GetAverageLoGainArea(j).SetExcluded();
437
438 }
439
440
441 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
442 {
443
444 MHCalibrationRelTimePix &histhi = (MHCalibrationRelTimePix&)GetAverageHiGainSector(j);
445
446 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
447 {
448 fCam->GetAverageSector(j).SetHiGainSaturation();
449 histhi.SetExcluded();
450 }
451 else
452 GetAverageHiGainSector(j).SetExcluded();
453 }
454
455
456 FitHiGainArrays((*fCam),*fBadPixels,
457 MBadPixelsPix::kRelTimeNotFitted,
458 MBadPixelsPix::kRelTimeOscillating);
459
460 FitLoGainArrays((*fCam),*fBadPixels,
461 MBadPixelsPix::kRelTimeNotFitted,
462 MBadPixelsPix::kRelTimeOscillating);
463
464 return kTRUE;
465}
466
467// --------------------------------------------------------------------------
468//
469// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
470// - MBadPixelsPix::kRelTimeNotFitted
471// - MBadPixelsPix::kRelTimeOscillating
472//
473void MHCalibrationRelTimeCam::FinalizeBadPixels()
474{
475
476 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
477 {
478
479 MBadPixelsPix &bad = (*fBadPixels)[i];
480
481 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeNotFitted ))
482 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
483
484 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeOscillating))
485 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
486
487 }
488}
489
490// --------------------------------------------------------------------------
491//
492// The types are as follows:
493//
494// Fitted values:
495// ==============
496//
497// 0: Fitted Mean Relative Arrival Time in ns (MHGausEvents::GetMean()*MHCalibrationRelTimePix::GetFADCSliceWidth())
498// 1: Error Mean Relative Arrival Time in ns (MHGausEvents::GetMeanErr()*MHCalibrationRelTimePix::GetFADCSliceWidth())
499// 2: Sigma fitted Relative Arrival Time in ns (MHGausEvents::GetSigma()*MHCalibrationRelTimePix::GetFADCSliceWidth())
500// 3: Error Sigma Relative Arrival Time in ns (MHGausEvents::GetSigmaErr()*MHCalibrationRelTimePix::GetFADCSliceWidth())
501//
502// Useful variables derived from the fit results:
503// =============================================
504//
505// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
506//
507// Localized defects:
508// ==================
509//
510// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
511// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
512//
513Bool_t MHCalibrationRelTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
514{
515
516 if (fHiGainArray->GetSize() <= idx)
517 return kFALSE;
518
519 const MHCalibrationRelTimePix &pix = (MHCalibrationRelTimePix&)(*this)[idx];
520 const Float_t fadc2ns = pix.GetFADCSliceWidth();
521
522 switch (type)
523 {
524 case 0:
525 val = pix.GetMean()*fadc2ns;
526 break;
527 case 1:
528 val = pix.GetMeanErr()*fadc2ns;
529 break;
530 case 2:
531 val = pix.GetSigma()*fadc2ns;
532 break;
533 case 3:
534 val = pix.GetSigmaErr()*fadc2ns;
535 break;
536 case 4:
537 val = pix.GetProb();
538 break;
539 case 5:
540 if (!pix.IsGausFitOK())
541 val = 1.;
542 break;
543 case 6:
544 if (!pix.IsFourierSpectrumOK())
545 val = 1.;
546 break;
547 default:
548 return kFALSE;
549 }
550 return kTRUE;
551}
552
553// --------------------------------------------------------------------------
554//
555// Calls MHGausEvents::DrawClone() for pixel idx
556//
557void MHCalibrationRelTimeCam::DrawPixelContent(Int_t idx) const
558{
559 (*this)[idx].DrawClone();
560}
Note: See TracBrowser for help on using the repository browser.