source: trunk/MagicSoft/Mars/mcalib/MHCalibrationTestTimeCam.cc@ 4858

Last change on this file since 4858 was 4808, checked in by gaug, 20 years ago
*** empty log message ***
File size: 15.6 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// MHCalibrationTestTimeCam
27//
28// Fills the calibrated signal from an MArrivalTime into
29// MHCalibrationTestTimePix for every:
30//
31// - Pixel, stored in the TObjArray's MHCalibrationCam::fHiGainArray
32// or MHCalibrationCam::fHiGainArray, respectively.
33//
34// - Average pixel per AREA index (e.g. inner and outer for the MAGIC camera),
35// stored in the TObjArray's MHCalibrationCam::fAverageHiGainAreas and
36// MHCalibrationCam::fAverageHiGainAreas
37//
38// - Average pixel per camera SECTOR (e.g. sectors 1-6 for the MAGIC camera),
39// stored in the TObjArray's MHCalibrationCam::fAverageHiGainSectors
40// and MHCalibrationCam::fAverageHiGainSectors
41//
42// The signals are filled into a histogram and an array, in order to perform
43// a Fourier analysis (see MHGausEvents). The signals are moreover averaged on an
44// event-by-event basis and written into the corresponding average pixels.
45//
46// The histograms are fitted to a Gaussian, mean and sigma with its errors
47// and the fit probability are extracted. If none of these values are NaN's and
48// if the probability is bigger than MHGausEvents::fProbLimit (default: 0.5%),
49// the fit is declared valid.
50// Otherwise, the fit is repeated within ranges of the previous mean
51// +- MHGausEvents::fPickupLimit (default: 5) sigma (see MHGausEvents::RepeatFit())
52// In case this does not make the fit valid, the histogram means and RMS's are
53// taken directly (see MHGausEvents::BypassFit()) and the following flags are set:
54// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainNotFitted ) and
55// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
56//
57// Outliers of more than MHGausEvents::fPickupLimit (default: 5) sigmas
58// from the mean are counted as Pickup events (stored in MHGausEvents::fPickup)
59//
60// The class also fills arrays with the signal vs. event number, creates a fourier
61// spectrum (see MHGausEvents::CreateFourierSpectrum()) and investigates if the
62// projected fourier components follow an exponential distribution.
63// In case that the probability of the exponential fit is less than
64// MHGausEvents::fProbLimit (default: 0.5%), the following flags are set:
65// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainOscillating ) and
66// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
67//
68// This same procedure is performed for the average pixels.
69//
70// The following results are written into an MCalibrationCam:
71//
72// - MCalibrationPix::SetMean()
73// - MCalibrationPix::SetMeanErr()
74// - MCalibrationPix::SetSigma()
75// - MCalibrationPix::SetSigmaErr()
76// - MCalibrationPix::SetProb()
77// - MCalibrationPix::SetNumPickup()
78//
79// For all averaged areas, the fitted sigma is multiplied with the square root of
80// the number involved pixels in order to be able to compare it to the average of
81// sigmas in the camera.
82//
83/////////////////////////////////////////////////////////////////////////////
84#include "MHCalibrationTestTimeCam.h"
85#include "MHCalibrationTestTimePix.h"
86
87#include "MLog.h"
88#include "MLogManip.h"
89
90#include "MParList.h"
91
92#include "MCalibrationCam.h"
93#include "MCalibrationPix.h"
94
95#include "MArrivalTime.h"
96
97#include "MGeomCam.h"
98#include "MGeomPix.h"
99
100#include "MBadPixelsCam.h"
101#include "MBadPixelsPix.h"
102
103ClassImp(MHCalibrationTestTimeCam);
104
105using namespace std;
106// --------------------------------------------------------------------------
107//
108// Default Constructor.
109//
110MHCalibrationTestTimeCam::MHCalibrationTestTimeCam(const char *name, const char *title)
111{
112
113 fName = name ? name : "MHCalibrationTestTimeCam";
114 fTitle = title ? title : "Histogram class for testing the calibration of arrival times";
115
116 SetAverageNbins(5000);
117}
118
119// --------------------------------------------------------------------------
120//
121// Gets or creates the pointers to:
122//
123// Searches pointer to:
124// - MArrivalTime
125//
126// Initializes, if empty to MGeomCam::GetNumAreas() for:
127// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
128//
129// Initializes, if empty to MGeomCam::GetNumSectors() for:
130// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
131//
132// Calls MHCalibrationCam::InitHists() for every entry in:
133// - MHCalibrationCam::fHiGainArray
134// - MHCalibrationCam::fAverageHiGainAreas
135// - MHCalibrationCam::fAverageHiGainSectors
136//
137// Sets Titles and Names for the Histograms
138// - MHCalibrationCam::fAverageHiGainAreas
139// - MHCalibrationCam::fAverageHiGainSectors
140//
141// Sets number of bins to MHCalibrationCam::fAverageNbins for:
142// - MHCalibrationCam::fAverageHiGainAreas
143// - MHCalibrationCam::fAverageHiGainSectors
144//
145Bool_t MHCalibrationTestTimeCam::ReInitHists(MParList *pList)
146{
147
148 MArrivalTime *signal = (MArrivalTime*)pList->FindObject("MArrivalTime");
149 if (!signal)
150 {
151 *fLog << err << "MArrivalTime not found... abort." << endl;
152 return kFALSE;
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 if (fHiGainArray->GetEntries()==0)
160 {
161 fHiGainArray->Expand(npixels);
162 for (Int_t i=0; i<npixels; i++)
163 {
164 (*fHiGainArray)[i] = new MHCalibrationTestTimePix("Calibrated Events Time",
165 "TestTime Calibration Pixel");
166 InitHists((*this)[i],(*fBadPixels)[i],i);
167 }
168 }
169
170 if (fLoGainArray->GetEntries()==0)
171 {
172 fLoGainArray->Expand(npixels);
173 for (Int_t i=0; i<npixels; i++)
174 {
175 (*fLoGainArray)[i] = new MHCalibrationTestTimePix("Calibrated Events Time",
176 "TestTime Calibration Pixel");
177 InitHists((*this)(i),(*fBadPixels)[i],i);
178 }
179 }
180
181
182 if (fAverageHiGainAreas->GetEntries()==0)
183 {
184 fAverageHiGainAreas->Expand(nareas);
185
186 for (Int_t j=0; j<nareas; j++)
187 {
188 (*fAverageHiGainAreas)[j] =
189 new MHCalibrationTestTimePix("MHCalibrationTestTimeAverageArea",
190 "Average TestTime Calibrations Area Idx ");
191
192 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("TestTime Calibrations Area Idx ");
193 GetAverageHiGainArea(j).SetNbins(fAverageNbins);
194 GetAverageHiGainArea(j).InitBins();
195 GetAverageHiGainArea(j).ChangeHistId(j);
196 GetAverageHiGainArea(j).SetEventFrequency(fPulserFrequency);
197
198 TH1F *h = GetAverageHiGainArea(j).GetHGausHist();
199 h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
200
201
202 }
203 }
204
205 if (fAverageLoGainAreas->GetEntries()==0)
206 {
207 fAverageLoGainAreas->Expand(nareas);
208
209 for (Int_t j=0; j<nareas; j++)
210 {
211 (*fAverageLoGainAreas)[j] =
212 new MHCalibrationTestTimePix("MHCalibrationTestTimeAverageArea",
213 "Average TestTime Calibrations Area Idx ");
214
215 GetAverageLoGainArea(j).GetHGausHist()->SetTitle("TestTime Calibrations Area Idx ");
216 GetAverageLoGainArea(j).SetNbins(fAverageNbins);
217 GetAverageLoGainArea(j).InitBins();
218 GetAverageLoGainArea(j).ChangeHistId(j);
219 GetAverageLoGainArea(j).SetEventFrequency(fPulserFrequency);
220
221 }
222 }
223
224
225 if (fAverageHiGainSectors->GetEntries()==0)
226 {
227 fAverageHiGainSectors->Expand(nsectors);
228
229 for (Int_t j=0; j<nsectors; j++)
230 {
231 (*fAverageHiGainSectors)[j] =
232 new MHCalibrationTestTimePix("MHCalibrationTestTimeAverageSector",
233 "Average TestTime Calibrations Sector ");
234
235 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("TestTime Calibrations Sector ");
236 GetAverageHiGainSector(j).SetNbins(fAverageNbins);
237 GetAverageHiGainSector(j).InitBins();
238 GetAverageHiGainSector(j).ChangeHistId(j);
239 GetAverageHiGainSector(j).SetEventFrequency(fPulserFrequency);
240 TH1F *h = GetAverageHiGainSector(j).GetHGausHist();
241 h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
242
243
244 }
245 }
246
247
248 if (fAverageLoGainSectors->GetEntries()==0)
249 {
250 fAverageLoGainSectors->Expand(nsectors);
251
252 for (Int_t j=0; j<nsectors; j++)
253 {
254 (*fAverageLoGainSectors)[j] =
255 new MHCalibrationTestTimePix("MHCalibrationTestTimeAverageSector",
256 "Average TestTime Calibrations Sector ");
257
258 GetAverageLoGainSector(j).GetHGausHist()->SetTitle("TestTime Calibrations Sector ");
259 GetAverageLoGainSector(j).SetNbins(fAverageNbins);
260 GetAverageLoGainSector(j).InitBins();
261 GetAverageLoGainSector(j).ChangeHistId(j);
262 GetAverageLoGainSector(j).SetEventFrequency(fPulserFrequency);
263 }
264 }
265
266
267 return kTRUE;
268}
269
270
271// -------------------------------------------------------------------------------
272//
273// Retrieves pointer to MArrivalTime:
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 MCerPhotPix::IsLoGainUsed(), with:
282// - MCerPhotPix::GetArrivalTime(pixid) - MCerPhotPix::GetArrivalTime(1);
283// (i.e. the time difference between pixel i and pixel 1 (hardware number: 2) )
284//
285Bool_t MHCalibrationTestTimeCam::FillHists(const MParContainer *par, const Stat_t w)
286{
287
288 MArrivalTime *calibration = (MArrivalTime*)par;
289 if (!calibration)
290 {
291 gLog << err << "No argument in MHCalibrationRelTimeCam::Fill... abort." << endl;
292 return kFALSE;
293 }
294
295 const Int_t npixels = fGeom->GetNumPixels();
296 const Int_t nareas = fGeom->GetNumAreas();
297 const Int_t nsectors = fGeom->GetNumSectors();
298
299 TArrayF sumareahi (nareas);
300 TArrayF sumsectorhi(nsectors);
301 TArrayI numareahi (nareas);
302 TArrayI numsectorhi(nsectors);
303
304 for (Int_t i=0; i<npixels; i++)
305 {
306
307 MHGausEvents &histhi = (*this)[i];
308
309 if (histhi.IsExcluded())
310 continue;
311
312 const Float_t time = (*calibration)[i];
313 const Int_t aidx = (*fGeom)[i].GetAidx();
314 const Int_t sector = (*fGeom)[i].GetSector();
315
316 histhi.FillHistAndArray(time) ;
317 sumareahi [aidx] += time;
318 numareahi [aidx] ++;
319 sumsectorhi[sector] += time;
320 numsectorhi[sector] ++;
321 }
322
323 for (Int_t j=0; j<nareas; j++)
324 {
325 MHGausEvents &histhi = GetAverageHiGainArea(j);
326 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
327
328 }
329
330 for (Int_t j=0; j<nsectors; j++)
331 {
332 MHGausEvents &histhi = GetAverageHiGainSector(j);
333 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
334
335 }
336
337 return kTRUE;
338}
339
340// --------------------------------------------------------------------------
341//
342//
343Bool_t MHCalibrationTestTimeCam::FinalizeHists()
344{
345
346 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
347 {
348
349 MHGausEvents &hist = (*this)[i];
350
351 if (hist.IsExcluded())
352 continue;
353
354 if (hist.IsEmpty())
355 continue;
356
357 if (!hist.FitGaus())
358 if (!hist.RepeatFit())
359 {
360 hist.BypassFit();
361 }
362
363 hist.CreateFourierSpectrum();
364
365 }
366
367 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
368 {
369
370 MHGausEvents &hist = GetAverageHiGainArea(j);
371 if (hist.IsEmpty())
372 continue;
373
374 if (!hist.FitGaus())
375 if (!hist.RepeatFit())
376 {
377 hist.BypassFit();
378 }
379
380 hist.CreateFourierSpectrum();
381
382
383 }
384
385 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
386 {
387
388 MHGausEvents &hist = GetAverageHiGainSector(j);
389 if (hist.IsEmpty())
390 continue;
391
392 if (!hist.FitGaus())
393 if (!hist.RepeatFit())
394 {
395 hist.BypassFit();
396 }
397 hist.CreateFourierSpectrum();
398
399
400 }
401
402 return kTRUE;
403}
404
405// --------------------------------------------------------------------------
406//
407void MHCalibrationTestTimeCam::FinalizeBadPixels()
408{
409
410}
411
412// --------------------------------------------------------------------------
413//
414// The types are as follows:
415//
416// Fitted values:
417// ==============
418//
419// 0: Fitted Mean Time Calibration (MHGausEvents::GetMean())
420// 1: Error Mean Time Calibration (MHGausEvents::GetMeanErr())
421// 2: Sigma fitted Time Calibration (MHGausEvents::GetSigma())
422// 3: Error Sigma Time Calibration (MHGausEvents::GetSigmaErr())
423//
424// Useful variables derived from the fit results:
425// =============================================
426//
427// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
428//
429// Localized defects:
430// ==================
431//
432// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
433// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
434//
435Bool_t MHCalibrationTestTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
436{
437
438 if (fHiGainArray->GetSize() <= idx)
439 return kFALSE;
440
441 const MHGausEvents &pix = (*this)[idx];
442
443 if (pix.IsExcluded())
444 return kFALSE;
445
446 switch (type)
447 {
448 case 0:
449 val = pix.GetMean();
450 break;
451 case 1:
452 val = pix.GetMeanErr();
453 break;
454 case 2:
455 val = pix.GetSigma();
456 break;
457 case 3:
458 val = pix.GetSigmaErr();
459 break;
460 case 4:
461 val = pix.GetProb();
462 break;
463 case 5:
464 if (!pix.IsGausFitOK())
465 val = 1.;
466 break;
467 case 6:
468 if (!pix.IsFourierSpectrumOK())
469 val = 1.;
470 break;
471 default:
472 return kFALSE;
473 }
474 return kTRUE;
475}
476
477// --------------------------------------------------------------------------
478//
479// Calls MHGausEvents::DrawClone() for pixel idx
480//
481void MHCalibrationTestTimeCam::DrawPixelContent(Int_t idx) const
482{
483 (*this)[idx].DrawClone();
484}
485
486
487//------------------------------------------------------------
488//
489// For all averaged areas, the fitted sigma is multiplied with the square root of
490// the number involved pixels
491//
492void MHCalibrationTestTimeCam::CalcAverageSigma()
493{
494
495 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
496 {
497
498 MHGausEvents &hist = GetAverageHiGainArea(j);
499
500 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
501 fAverageAreaSigma[j] = hist.GetSigma () * numsqr;
502 fAverageAreaSigmaVar[j] = hist.GetSigmaErr () * hist.GetSigmaErr() * numsqr;
503
504 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / hist.GetMean();
505 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
506 fAverageAreaRelSigmaVar[j] += hist.GetMeanErr()*hist.GetMeanErr()/hist.GetMean()/hist.GetMean();
507 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
508 }
509}
Note: See TracBrowser for help on using the repository browser.