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

Last change on this file since 4439 was 3982, checked in by gaug, 21 years ago
*** empty log message ***
File size: 15.8 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 Float_t sumareahi [nareas];
300 Float_t sumsectorhi[nsectors];
301 Int_t numareahi [nareas];
302 Int_t numsectorhi[nsectors];
303
304 memset(sumareahi, 0, nareas * sizeof(Float_t));
305 memset(sumsectorhi, 0, nsectors*sizeof(Float_t));
306 memset(numareahi, 0, nareas * sizeof(Int_t));
307 memset(numsectorhi, 0, nsectors*sizeof(Int_t));
308
309 for (Int_t i=0; i<npixels; i++)
310 {
311
312 MHGausEvents &histhi = (*this)[i];
313
314 if (histhi.IsExcluded())
315 continue;
316
317 const Float_t time = (*calibration)[i];
318 const Int_t aidx = (*fGeom)[i].GetAidx();
319 const Int_t sector = (*fGeom)[i].GetSector();
320
321 histhi.FillHistAndArray(time) ;
322 sumareahi [aidx] += time;
323 numareahi [aidx] ++;
324 sumsectorhi[sector] += time;
325 numsectorhi[sector] ++;
326 }
327
328 for (Int_t j=0; j<nareas; j++)
329 {
330 MHGausEvents &histhi = GetAverageHiGainArea(j);
331 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
332
333 }
334
335 for (Int_t j=0; j<nsectors; j++)
336 {
337 MHGausEvents &histhi = GetAverageHiGainSector(j);
338 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
339
340 }
341
342 return kTRUE;
343}
344
345// --------------------------------------------------------------------------
346//
347//
348Bool_t MHCalibrationTestTimeCam::FinalizeHists()
349{
350
351 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
352 {
353
354 MHGausEvents &hist = (*this)[i];
355
356 if (hist.IsExcluded())
357 continue;
358
359 if (hist.IsEmpty())
360 continue;
361
362 if (!hist.FitGaus())
363 if (!hist.RepeatFit())
364 {
365 hist.BypassFit();
366 }
367
368 hist.CreateFourierSpectrum();
369
370 }
371
372 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
373 {
374
375 MHGausEvents &hist = GetAverageHiGainArea(j);
376 if (hist.IsEmpty())
377 continue;
378
379 if (!hist.FitGaus())
380 if (!hist.RepeatFit())
381 {
382 hist.BypassFit();
383 }
384
385 hist.CreateFourierSpectrum();
386
387
388 }
389
390 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
391 {
392
393 MHGausEvents &hist = GetAverageHiGainSector(j);
394 if (hist.IsEmpty())
395 continue;
396
397 if (!hist.FitGaus())
398 if (!hist.RepeatFit())
399 {
400 hist.BypassFit();
401 }
402 hist.CreateFourierSpectrum();
403
404
405 }
406
407 return kTRUE;
408}
409
410// --------------------------------------------------------------------------
411//
412void MHCalibrationTestTimeCam::FinalizeBadPixels()
413{
414
415}
416
417// --------------------------------------------------------------------------
418//
419// The types are as follows:
420//
421// Fitted values:
422// ==============
423//
424// 0: Fitted Mean Time Calibration (MHGausEvents::GetMean())
425// 1: Error Mean Time Calibration (MHGausEvents::GetMeanErr())
426// 2: Sigma fitted Time Calibration (MHGausEvents::GetSigma())
427// 3: Error Sigma Time Calibration (MHGausEvents::GetSigmaErr())
428//
429// Useful variables derived from the fit results:
430// =============================================
431//
432// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
433//
434// Localized defects:
435// ==================
436//
437// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
438// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
439//
440Bool_t MHCalibrationTestTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
441{
442
443 if (fHiGainArray->GetSize() <= idx)
444 return kFALSE;
445
446 const MHGausEvents &pix = (*this)[idx];
447
448 if (pix.IsExcluded())
449 return kFALSE;
450
451 switch (type)
452 {
453 case 0:
454 val = pix.GetMean();
455 break;
456 case 1:
457 val = pix.GetMeanErr();
458 break;
459 case 2:
460 val = pix.GetSigma();
461 break;
462 case 3:
463 val = pix.GetSigmaErr();
464 break;
465 case 4:
466 val = pix.GetProb();
467 break;
468 case 5:
469 if (!pix.IsGausFitOK())
470 val = 1.;
471 break;
472 case 6:
473 if (!pix.IsFourierSpectrumOK())
474 val = 1.;
475 break;
476 default:
477 return kFALSE;
478 }
479 return kTRUE;
480}
481
482// --------------------------------------------------------------------------
483//
484// Calls MHGausEvents::DrawClone() for pixel idx
485//
486void MHCalibrationTestTimeCam::DrawPixelContent(Int_t idx) const
487{
488 (*this)[idx].DrawClone();
489}
490
491
492//------------------------------------------------------------
493//
494// For all averaged areas, the fitted sigma is multiplied with the square root of
495// the number involved pixels
496//
497void MHCalibrationTestTimeCam::CalcAverageSigma()
498{
499
500 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
501 {
502
503 MHGausEvents &hist = GetAverageHiGainArea(j);
504
505 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
506 fAverageAreaSigma[j] = hist.GetSigma () * numsqr;
507 fAverageAreaSigmaVar[j] = hist.GetSigmaErr () * hist.GetSigmaErr() * numsqr;
508
509 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / hist.GetMean();
510 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
511 fAverageAreaRelSigmaVar[j] += hist.GetMeanErr()*hist.GetMeanErr()/hist.GetMean()/hist.GetMean();
512 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
513 }
514}
Note: See TracBrowser for help on using the repository browser.