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

Last change on this file since 4814 was 4813, checked in by gaug, 22 years ago
*** empty log message ***
File size: 18.5 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 fSumareahi .Set(nareas);
284 fSumarealo .Set(nareas);
285 fSumsectorhi.Set(nsectors);
286 fSumsectorlo.Set(nsectors);
287 fNumareahi .Set(nareas);
288 fNumarealo .Set(nareas);
289 fNumsectorhi.Set(nsectors);
290 fNumsectorlo.Set(nsectors);
291
292 return kTRUE;
293}
294
295
296// -------------------------------------------------------------------------------
297//
298// Retrieves pointer to MArrivalTimeCam:
299//
300// Retrieves from MGeomCam:
301// - number of pixels
302// - number of pixel areas
303// - number of sectors
304//
305// Fills HiGain or LoGain histograms (MHGausEvents::FillHistAndArray()), respectively
306// depending on MArrivalTimePix::IsLoGainUsed(), with:
307// - MArrivalTimePix::GetArrivalTime(pixid) - MArrivalTimePix::GetArrivalTime(1);
308// (i.e. the time difference between pixel i and pixel 1 (hardware number: 2) )
309//
310Bool_t MHCalibrationRelTimeCam::FillHists(const MParContainer *par, const Stat_t w)
311{
312
313 MArrivalTimeCam *arrtime = (MArrivalTimeCam*)par;
314 if (!arrtime)
315 {
316 gLog << err << "No argument in MArrivalTime::Fill... abort." << endl;
317 return kFALSE;
318 }
319
320 const Int_t npixels = fGeom->GetNumPixels();
321 const Int_t nareas = fGeom->GetNumAreas();
322 const Int_t nsectors = fGeom->GetNumSectors();
323
324 fSumareahi .Reset();
325 fSumarealo .Reset();
326 fSumsectorhi.Reset();
327 fSumsectorlo.Reset();
328 fNumareahi .Reset();
329 fNumarealo .Reset();
330 fNumsectorhi.Reset();
331 fNumsectorlo.Reset();
332
333 const MArrivalTimePix &refpix = (*arrtime)[fReferencePixel];
334 const Float_t reftime = refpix.IsLoGainUsed()
335 ? refpix.GetArrivalTimeLoGain() : refpix.GetArrivalTimeHiGain();
336
337 for (Int_t i=0; i<npixels; i++)
338 {
339
340 MHGausEvents &histhi = (*this)[i];
341 MHGausEvents &histlo = (*this)(i);
342
343 if (histhi.IsExcluded())
344 continue;
345
346 const MArrivalTimePix &pix = (*arrtime)[i];
347 const Int_t aidx = (*fGeom)[i].GetAidx();
348 const Int_t sector = (*fGeom)[i].GetSector();
349
350 if (pix.IsLoGainUsed())
351 {
352 const Float_t reltime = pix.GetArrivalTimeLoGain() - reftime;
353 histhi.SetSaturated(1);
354 histlo.FillHistAndArray(reltime);
355 fSumarealo [aidx] += reltime;
356 fNumarealo [aidx] ++;
357 fSumsectorlo[sector] += reltime;
358 fNumsectorlo[sector] ++;
359 }
360 else
361 {
362 const Float_t reltime = pix.GetArrivalTimeHiGain() - reftime;
363 histhi.FillHistAndArray(reltime) ;
364 fSumareahi [aidx] += reltime;
365 fNumareahi [aidx] ++;
366 fSumsectorhi[sector] += reltime;
367 fNumsectorhi[sector] ++;
368 }
369 }
370
371 for (Int_t j=0; j<nareas; j++)
372 {
373 MHGausEvents &histhi = GetAverageHiGainArea(j);
374 histhi.FillHistAndArray(fNumareahi[j] == 0 ? 0. : fSumareahi[j]/fNumareahi[j]);
375
376 MHGausEvents &histlo = GetAverageLoGainArea(j);
377 histlo.FillHistAndArray(fNumarealo[j] == 0 ? 0. : fSumarealo[j]/fNumarealo[j]);
378 }
379
380 for (Int_t j=0; j<nsectors; j++)
381 {
382 MHGausEvents &histhi = GetAverageHiGainSector(j);
383 histhi.FillHistAndArray(fNumsectorhi[j] == 0 ? 0. : fSumsectorhi[j]/fNumsectorhi[j]);
384
385 MHGausEvents &histlo = GetAverageLoGainSector(j);
386 histlo.FillHistAndArray(fNumsectorlo[j] == 0 ? 0. : fSumsectorlo[j]/fNumsectorlo[j]);
387 }
388
389 return kTRUE;
390}
391
392// --------------------------------------------------------------------------
393//
394// Calls:
395// - MHCalibrationCam::FitHiGainArrays() with flags:
396// MBadPixelsPix::kRelTimeNotFitted and MBadPixelsPix::kRelTimeOscillating
397// - MHCalibrationCam::FitLoGainArrays() with flags:
398// MBadPixelsPix::kRelTimeNotFitted and MBadPixelsPix::kRelTimeOscillating
399//
400Bool_t MHCalibrationRelTimeCam::FinalizeHists()
401{
402
403 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
404 {
405
406 MHCalibrationRelTimePix &histhi = (MHCalibrationRelTimePix&)(*this)[i];
407
408 if (histhi.IsExcluded())
409 continue;
410
411 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
412 {
413 (*fCam)[i].SetHiGainSaturation();
414 histhi.SetExcluded();
415 }
416 else
417 (*this)(i).SetExcluded();
418
419 }
420
421
422 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
423 {
424
425 MHCalibrationRelTimePix &histhi = (MHCalibrationRelTimePix&)GetAverageHiGainArea(j);
426
427 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
428 {
429 fCam->GetAverageArea(j).SetHiGainSaturation();
430 histhi.SetExcluded();
431 }
432 else
433 GetAverageLoGainArea(j).SetExcluded();
434
435 }
436
437
438 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
439 {
440
441 MHCalibrationRelTimePix &histhi = (MHCalibrationRelTimePix&)GetAverageHiGainSector(j);
442
443 if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
444 {
445 fCam->GetAverageSector(j).SetHiGainSaturation();
446 histhi.SetExcluded();
447 }
448 else
449 GetAverageHiGainSector(j).SetExcluded();
450 }
451
452
453 FitHiGainArrays((*fCam),*fBadPixels,
454 MBadPixelsPix::kRelTimeNotFitted,
455 MBadPixelsPix::kRelTimeOscillating);
456
457 FitLoGainArrays((*fCam),*fBadPixels,
458 MBadPixelsPix::kRelTimeNotFitted,
459 MBadPixelsPix::kRelTimeOscillating);
460
461 return kTRUE;
462}
463
464// --------------------------------------------------------------------------
465//
466// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
467// - MBadPixelsPix::kRelTimeNotFitted
468// - MBadPixelsPix::kRelTimeOscillating
469//
470void MHCalibrationRelTimeCam::FinalizeBadPixels()
471{
472
473 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
474 {
475
476 MBadPixelsPix &bad = (*fBadPixels)[i];
477
478 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeNotFitted ))
479 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
480
481 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeOscillating))
482 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
483
484 }
485}
486
487// --------------------------------------------------------------------------
488//
489// The types are as follows:
490//
491// Fitted values:
492// ==============
493//
494// 0: Fitted Mean Relative Arrival Time in ns (MHGausEvents::GetMean()*MHCalibrationRelTimePix::GetFADCSliceWidth())
495// 1: Error Mean Relative Arrival Time in ns (MHGausEvents::GetMeanErr()*MHCalibrationRelTimePix::GetFADCSliceWidth())
496// 2: Sigma fitted Relative Arrival Time in ns (MHGausEvents::GetSigma()*MHCalibrationRelTimePix::GetFADCSliceWidth())
497// 3: Error Sigma Relative Arrival Time in ns (MHGausEvents::GetSigmaErr()*MHCalibrationRelTimePix::GetFADCSliceWidth())
498//
499// Useful variables derived from the fit results:
500// =============================================
501//
502// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
503//
504// Localized defects:
505// ==================
506//
507// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
508// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
509//
510Bool_t MHCalibrationRelTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
511{
512
513 if (fHiGainArray->GetSize() <= idx)
514 return kFALSE;
515
516 const MHCalibrationRelTimePix &pix = (MHCalibrationRelTimePix&)(*this)[idx];
517 const Float_t fadc2ns = pix.GetFADCSliceWidth();
518
519 switch (type)
520 {
521 case 0:
522 val = pix.GetMean()*fadc2ns;
523 break;
524 case 1:
525 val = pix.GetMeanErr()*fadc2ns;
526 break;
527 case 2:
528 val = pix.GetSigma()*fadc2ns;
529 break;
530 case 3:
531 val = pix.GetSigmaErr()*fadc2ns;
532 break;
533 case 4:
534 val = pix.GetProb();
535 break;
536 case 5:
537 if (!pix.IsGausFitOK())
538 val = 1.;
539 break;
540 case 6:
541 if (!pix.IsFourierSpectrumOK())
542 val = 1.;
543 break;
544 default:
545 return kFALSE;
546 }
547 return kTRUE;
548}
549
550// --------------------------------------------------------------------------
551//
552// Calls MHGausEvents::DrawClone() for pixel idx
553//
554void MHCalibrationRelTimeCam::DrawPixelContent(Int_t idx) const
555{
556 (*this)[idx].DrawClone();
557}
Note: See TracBrowser for help on using the repository browser.