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

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