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

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