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

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