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

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