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

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