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

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