source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestCam.cc@ 5480

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