source: trunk/MagicSoft/Mars/mcalib/MHCalibrationTestCam.cc@ 3933

Last change on this file since 3933 was 3855, checked in by gaug, 21 years ago
*** empty log message ***
File size: 16.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// MHCalibrationTestCam
27//
28// Fills the calibrated signal from an MCerPhotEvt into
29// MHCalibrationTestPix 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 "MHCalibrationTestCam.h"
85#include "MHCalibrationTestPix.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 "MCerPhotEvt.h"
96#include "MCerPhotPix.h"
97
98#include "MGeomCam.h"
99#include "MGeomPix.h"
100
101#include "MBadPixelsCam.h"
102#include "MBadPixelsPix.h"
103
104ClassImp(MHCalibrationTestCam);
105
106using namespace std;
107// --------------------------------------------------------------------------
108//
109// Default Constructor.
110//
111MHCalibrationTestCam::MHCalibrationTestCam(const char *name, const char *title)
112{
113
114 fName = name ? name : "MHCalibrationTestCam";
115 fTitle = title ? title : "Histogram class for testing the calibration";
116
117}
118
119// --------------------------------------------------------------------------
120//
121// Gets or creates the pointers to:
122// - MCalibrationTestCam
123//
124// Searches pointer to:
125// - MCerPhotEvt
126//
127// Initializes, if empty to MGeomCam::GetNumAreas() for:
128// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
129//
130// Initializes, if empty to MGeomCam::GetNumSectors() for:
131// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
132//
133// Calls MHCalibrationCam::InitHists() for every entry in:
134// - MHCalibrationCam::fHiGainArray
135// - MHCalibrationCam::fAverageHiGainAreas
136// - MHCalibrationCam::fAverageHiGainSectors
137//
138// Sets Titles and Names for the Histograms
139// - MHCalibrationCam::fAverageHiGainAreas
140// - MHCalibrationCam::fAverageHiGainSectors
141//
142// Sets number of bins to MHCalibrationCam::fAverageNbins for:
143// - MHCalibrationCam::fAverageHiGainAreas
144// - MHCalibrationCam::fAverageHiGainSectors
145//
146Bool_t MHCalibrationTestCam::ReInitHists(MParList *pList)
147{
148
149 MCerPhotEvt *signal = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
150 if (!signal)
151 {
152 *fLog << err << "MCerPhotEvt not found... abort." << endl;
153 return kFALSE;
154 }
155
156 const Int_t npixels = fGeom->GetNumPixels();
157 const Int_t nsectors = fGeom->GetNumSectors();
158 const Int_t nareas = fGeom->GetNumAreas();
159
160 if (fHiGainArray->GetEntries()==0)
161 {
162 fHiGainArray->Expand(npixels);
163 for (Int_t i=0; i<npixels; i++)
164 {
165 (*fHiGainArray)[i] = new MHCalibrationTestPix("Calibrated Events",
166 "Test Calibration Pixel");
167 if (!(*fBadPixels)[i].IsOK())
168 (*this)[i].SetExcluded();
169
170 (*this)[i].InitBins();
171 (*this)[i].ChangeHistId(i);
172 (*this)[i].SetEventFrequency(fPulserFrequency);
173 }
174 }
175
176 if (fLoGainArray->GetEntries()==0)
177 {
178 fLoGainArray->Expand(npixels);
179 for (Int_t i=0; i<npixels; i++)
180 {
181 (*fLoGainArray)[i] = new MHCalibrationTestPix("Calibrated Events",
182 "Test Calibration Pixel");
183 if (!(*fBadPixels)[i].IsOK())
184 (*this)[i].SetExcluded();
185
186 (*this)[i].InitBins();
187 (*this)[i].ChangeHistId(i);
188 (*this)[i].SetEventFrequency(fPulserFrequency);
189 }
190 }
191
192
193 if (fAverageHiGainAreas->GetEntries()==0)
194 {
195 fAverageHiGainAreas->Expand(nareas);
196
197 for (Int_t j=0; j<nareas; j++)
198 {
199 (*fAverageHiGainAreas)[j] =
200 new MHCalibrationTestPix("MHCalibrationTestAverageArea",
201 "Average Test Calibrations Area Idx ");
202
203 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("Test Calibrations Area Idx ");
204 GetAverageHiGainArea(j).SetNbins(fAverageNbins);
205 GetAverageHiGainArea(j).InitBins();
206 GetAverageHiGainArea(j).ChangeHistId(j);
207 GetAverageHiGainArea(j).SetEventFrequency(fPulserFrequency);
208
209 }
210 }
211
212 if (fAverageLoGainAreas->GetEntries()==0)
213 {
214 fAverageLoGainAreas->Expand(nareas);
215
216 for (Int_t j=0; j<nareas; j++)
217 {
218 (*fAverageLoGainAreas)[j] =
219 new MHCalibrationTestPix("MHCalibrationTestAverageArea",
220 "Average Test Calibrations Area Idx ");
221
222 GetAverageLoGainArea(j).GetHGausHist()->SetTitle("Test Calibrations Area Idx ");
223 GetAverageLoGainArea(j).SetNbins(fAverageNbins);
224 GetAverageLoGainArea(j).InitBins();
225 GetAverageLoGainArea(j).ChangeHistId(j);
226 GetAverageLoGainArea(j).SetEventFrequency(fPulserFrequency);
227
228 }
229 }
230
231
232 if (fAverageHiGainSectors->GetEntries()==0)
233 {
234 fAverageHiGainSectors->Expand(nsectors);
235
236 for (Int_t j=0; j<nsectors; j++)
237 {
238 (*fAverageHiGainSectors)[j] =
239 new MHCalibrationTestPix("MHCalibrationTestAverageSector",
240 "Average Test Calibrations Sector ");
241
242 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("Test Calibrations Sector ");
243 GetAverageHiGainSector(j).SetNbins(fAverageNbins);
244 GetAverageHiGainSector(j).InitBins();
245 GetAverageHiGainSector(j).ChangeHistId(j);
246 GetAverageHiGainSector(j).SetEventFrequency(fPulserFrequency);
247 }
248 }
249
250
251 if (fAverageLoGainSectors->GetEntries()==0)
252 {
253 fAverageLoGainSectors->Expand(nsectors);
254
255 for (Int_t j=0; j<nsectors; j++)
256 {
257 (*fAverageLoGainSectors)[j] =
258 new MHCalibrationTestPix("MHCalibrationTestAverageSector",
259 "Average Test Calibrations Sector ");
260
261 GetAverageLoGainSector(j).GetHGausHist()->SetTitle("Test Calibrations Sector ");
262 GetAverageLoGainSector(j).SetNbins(fAverageNbins);
263 GetAverageLoGainSector(j).InitBins();
264 GetAverageLoGainSector(j).ChangeHistId(j);
265 GetAverageLoGainSector(j).SetEventFrequency(fPulserFrequency);
266 }
267 }
268
269
270 return kTRUE;
271}
272
273
274// -------------------------------------------------------------------------------
275//
276// Retrieves pointer to MCerPhotEvt:
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 MCerPhotPix::IsLoGainUsed(), with:
285// - MCerPhotPix::GetArrivalTime(pixid) - MCerPhotPix::GetArrivalTime(1);
286// (i.e. the time difference between pixel i and pixel 1 (hardware number: 2) )
287//
288Bool_t MHCalibrationTestCam::FillHists(const MParContainer *par, const Stat_t w)
289{
290
291 MCerPhotEvt *calibration = (MCerPhotEvt*)par;
292 if (!calibration)
293 {
294 gLog << err << "No argument in MHCalibrationRelTimeCam::Fill... abort." << endl;
295 return kFALSE;
296 }
297
298 const Int_t npixels = fGeom->GetNumPixels();
299 const Int_t nareas = fGeom->GetNumAreas();
300 const Int_t nsectors = fGeom->GetNumSectors();
301
302 Float_t sumareahi [nareas];
303 Float_t sumsectorhi[nsectors];
304 Int_t numareahi [nareas];
305 Int_t numsectorhi[nsectors];
306
307 memset(sumareahi, 0, nareas * sizeof(Float_t));
308 memset(sumsectorhi, 0, nsectors*sizeof(Float_t));
309
310 for (Int_t i=0; i<npixels; i++)
311 {
312
313 MHGausEvents &histhi = (*this)[i];
314
315 if (histhi.IsExcluded())
316 continue;
317
318 const MCerPhotPix *pix = calibration->GetPixById(i);
319 if (!pix)
320 continue;
321
322 const Float_t signal = pix->GetNumPhotons();
323
324 const Int_t aidx = (*fGeom)[i].GetAidx();
325 const Int_t sector = (*fGeom)[i].GetSector();
326
327 histhi.FillHistAndArray(signal) ;
328 sumareahi [aidx] += signal;
329 numareahi [aidx] ++;
330 sumsectorhi[sector] += signal;
331 numsectorhi[sector] ++;
332 }
333
334 for (Int_t j=0; j<nareas; j++)
335 {
336 MHGausEvents &histhi = GetAverageHiGainArea(j);
337 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
338
339 }
340
341 for (Int_t j=0; j<nsectors; j++)
342 {
343 MHGausEvents &histhi = GetAverageHiGainSector(j);
344 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
345
346 }
347
348 return kTRUE;
349}
350
351// --------------------------------------------------------------------------
352//
353// Calls:
354// - MHCalibrationCam::FitHiGainArrays() with flags:
355// MBadPixelsPix::kTestNotFitted and MBadPixelsPix::kTestOscillating
356// - MHCalibrationCam::FitLoGainArrays() with flags:
357// MBadPixelsPix::kTestNotFitted and MBadPixelsPix::kTestOscillating
358//
359Bool_t MHCalibrationTestCam::FinalizeHists()
360{
361
362 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
363 {
364
365 MHGausEvents &hist = (*this)[i];
366
367 if (hist.IsExcluded())
368 continue;
369
370 if (hist.IsEmpty())
371 continue;
372
373 if (!hist.FitGaus())
374 if (!hist.RepeatFit())
375 {
376 hist.BypassFit();
377 }
378
379 hist.CreateFourierSpectrum();
380
381 }
382
383 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
384 {
385
386 MHGausEvents &hist = GetAverageHiGainArea(j);
387 if (hist.IsEmpty())
388 continue;
389
390 if (!hist.FitGaus())
391 if (!hist.RepeatFit())
392 {
393 hist.BypassFit();
394 }
395
396 hist.CreateFourierSpectrum();
397
398
399 }
400
401 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
402 {
403
404 MHGausEvents &hist = GetAverageHiGainSector(j);
405 if (hist.IsEmpty())
406 continue;
407
408 if (!hist.FitGaus())
409 if (!hist.RepeatFit())
410 {
411 hist.BypassFit();
412 }
413 hist.CreateFourierSpectrum();
414
415
416 }
417
418 return kTRUE;
419}
420
421// --------------------------------------------------------------------------
422//
423// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
424// - MBadPixelsPix::kTestNotFitted
425// - MBadPixelsPix::kTestOscillating
426//
427void MHCalibrationTestCam::FinalizeBadPixels()
428{
429
430}
431
432// --------------------------------------------------------------------------
433//
434// The types are as follows:
435//
436// Fitted values:
437// ==============
438//
439// 0: Fitted Mean Test Calibration (MHGausEvents::GetMean())
440// 1: Error Mean Test Calibration (MHGausEvents::GetMeanErr())
441// 2: Sigma fitted Test Calibration (MHGausEvents::GetSigma())
442// 3: Error Sigma Test Calibration (MHGausEvents::GetSigmaErr())
443//
444// Useful variables derived from the fit results:
445// =============================================
446//
447// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
448//
449// Localized defects:
450// ==================
451//
452// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
453// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
454//
455// Converted values:
456// =================
457//
458// 7: Fitted Mean Test Calibration (MHGausEvents::GetMean()) by MGeomPix::GetA()
459// 8: Fitted Mean Error Calibration (MHGausEvents::GetSigma()) by MGeomPix::GetA()
460// 9: Fitted Sigma Test Calibration (MHGausEvents::GetMean()) by MGeomPix::GetA()
461// 8: Fitted Sigma Error Calibration (MHGausEvents::GetSigma()) by MGeomPix::GetA()
462//
463Bool_t MHCalibrationTestCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
464{
465
466 if (fHiGainArray->GetSize() <= idx)
467 return kFALSE;
468
469 const MHGausEvents &pix = (*this)[idx];
470
471 if (pix.IsExcluded())
472 return kFALSE;
473
474 switch (type)
475 {
476 case 0:
477 val = pix.GetMean();
478 break;
479 case 1:
480 val = pix.GetMeanErr();
481 break;
482 case 2:
483 val = pix.GetSigma();
484 break;
485 case 3:
486 val = pix.GetSigmaErr();
487 break;
488 case 4:
489 val = pix.GetProb();
490 break;
491 case 5:
492 if (!pix.IsGausFitOK())
493 val = 1.;
494 break;
495 case 6:
496 if (!pix.IsFourierSpectrumOK())
497 val = 1.;
498 break;
499 case 7:
500 val = pix.GetMean()/cam[idx].GetA();
501 break;
502 case 8:
503 val = pix.GetMeanErr()/cam[idx].GetA();
504 break;
505 case 9:
506 val = pix.GetSigma()/cam[idx].GetA();
507 break;
508 case 10:
509 val = pix.GetSigmaErr()/cam[idx].GetA();
510 break;
511 default:
512 return kFALSE;
513 }
514 return kTRUE;
515}
516
517// --------------------------------------------------------------------------
518//
519// Calls MHGausEvents::DrawClone() for pixel idx
520//
521void MHCalibrationTestCam::DrawPixelContent(Int_t idx) const
522{
523 (*this)[idx].DrawClone();
524}
525
526
527//------------------------------------------------------------
528//
529// For all averaged areas, the fitted sigma is multiplied with the square root of
530// the number involved pixels
531//
532void MHCalibrationTestCam::CalcAverageSigma()
533{
534
535 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
536 {
537
538 MHGausEvents &hist = GetAverageHiGainArea(j);
539
540 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
541 fAverageAreaSigma[j] = hist.GetSigma () * numsqr;
542 fAverageAreaSigmaVar[j] = hist.GetSigmaErr () * hist.GetSigmaErr() * numsqr;
543
544 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / hist.GetMean();
545 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
546 fAverageAreaRelSigmaVar[j] += hist.GetMeanErr()*hist.GetMeanErr()/hist.GetMean()/hist.GetMean();
547 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
548 }
549}
Note: See TracBrowser for help on using the repository browser.