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

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