source: trunk/Mars/mhcalib/MHCalibrationTestCam.cc@ 19870

Last change on this file since 19870 was 8489, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 14.2 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 MSignalCam 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 "MSignalCam.h"
97#include "MSignalPix.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 = -1.;
113const Axis_t MHCalibrationTestCam::fgLast = 1999.;
114const Float_t MHCalibrationTestCam::fgProbLimit = 0.00000001;
115const TString MHCalibrationTestCam::gsHistName = "Test";
116const TString MHCalibrationTestCam::gsHistTitle = "Calibrated Calibration Signals";
117const TString MHCalibrationTestCam::gsHistXTitle = "Nr. Photons";
118const TString MHCalibrationTestCam::gsHistYTitle = "Nr. events";
119// --------------------------------------------------------------------------
120//
121// Default Constructor.
122//
123// Sets:
124// - fNbins to fgNbins
125// - fFirst to fgFirst
126// - fLast to fgLast
127//
128// - fHistName to gsHistName
129// - fHistTitle to gsHistTitle
130// - fHistXTitle to gsHistXTitle
131// - fHistYTitle to gsHistYTitle
132//
133MHCalibrationTestCam::MHCalibrationTestCam(const char *name, const char *title)
134{
135
136 fName = name ? name : "MHCalibrationTestCam";
137 fTitle = title ? title : "Histogram class for testing the calibration";
138
139 SetBinning(fgNbins, fgFirst, fgLast);
140
141 SetProbLimit(fgProbLimit);
142
143 SetHistName (gsHistName .Data());
144 SetHistTitle (gsHistTitle .Data());
145 SetHistXTitle(gsHistXTitle.Data());
146 SetHistYTitle(gsHistYTitle.Data());
147
148 SetLoGain(kFALSE);
149
150}
151
152// --------------------------------------------------------------------------
153//
154// Searches pointer to:
155// - MSignalCam
156//
157// Calls:
158// - MHCalibrationCam::InitHiGainArrays()
159//
160// Sets:
161// - SetLoGain(kFALSE);
162// - fMeanMeanPhotPerArea to nareas
163// - fRmsMeanPhotPerArea to nareas
164// - fMeanSigmaPhotPerArea to nareas
165// - fRmsSigmaPhotPerArea to nareas
166//
167Bool_t MHCalibrationTestCam::ReInitHists(MParList *pList)
168{
169
170 if (!InitCams(pList,"Test"))
171 return kFALSE;
172
173
174 MSignalCam *signal = (MSignalCam*)pList->FindObject("MSignalCam");
175 if (!signal)
176 {
177 *fLog << err << "MSignalCam not found... abort." << endl;
178 return kFALSE;
179 }
180
181
182 const Int_t npixels = fGeom->GetNumPixels();
183 const Int_t nsectors = fGeom->GetNumSectors();
184 const Int_t nareas = fGeom->GetNumAreas();
185
186 InitHiGainArrays(npixels,nareas,nsectors);
187 InitLoGainArrays(npixels,nareas,nsectors);
188
189 fMeanMeanPhotPerArea.Set(nareas);
190 fRmsMeanPhotPerArea .Set(nareas);
191 fMeanSigmaPhotPerArea.Set(nareas);
192 fRmsSigmaPhotPerArea.Set(nareas);
193
194 return kTRUE;
195}
196
197// -------------------------------------------------------------------------------
198//
199// Retrieves pointer to MSignalCam:
200//
201// Retrieves from MGeomCam:
202// - number of pixels
203// - number of pixel areas
204// - number of sectors
205//
206// Fills HiGain histograms (MHGausEvents::FillHistAndArray())
207// with:
208// - MSignalPix::GetNumPhotons(pixid);
209//
210Bool_t MHCalibrationTestCam::FillHists(const MParContainer *par, const Stat_t w)
211{
212
213 MSignalCam *calibration = (MSignalCam*)par;
214 if (!calibration)
215 {
216 gLog << err << "No argument in MHCalibrationTestCam::Fill... abort." << endl;
217 return kFALSE;
218 }
219
220 const Int_t npixels = fGeom->GetNumPixels();
221 const Int_t nareas = fGeom->GetNumAreas();
222 const Int_t nsectors = fGeom->GetNumSectors();
223
224 TArrayF sumareahi (nareas);
225 TArrayF sumsectorhi(nsectors);
226 TArrayI numareahi (nareas);
227 TArrayI numsectorhi(nsectors);
228
229 for (Int_t i=0; i<npixels; i++)
230 {
231
232 const MSignalPix &pix = (*calibration)[i];
233
234 const Float_t signal = pix.GetNumPhotons();
235 if (signal < 0.0001)
236 continue;
237
238 const Int_t aidx = (*fGeom)[i].GetAidx();
239 const Int_t sector = (*fGeom)[i].GetSector();
240
241 (*this)[i].FillHistAndArray(signal);
242
243 sumareahi [aidx] += signal;
244 numareahi [aidx] ++;
245 sumsectorhi[sector] += signal;
246 numsectorhi[sector] ++;
247 }
248
249 for (Int_t j=0; j<nareas; j++)
250 {
251 MHCalibrationPix &histhi = GetAverageHiGainArea(j);
252 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
253 }
254
255 for (Int_t j=0; j<nsectors; j++)
256 {
257 MHCalibrationPix &histhi = GetAverageHiGainSector(j);
258 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
259
260 }
261
262 return kTRUE;
263}
264
265// --------------------------------------------------------------------------
266//
267// Calls:
268// - MHCalibrationCam::FitHiGainArrays() with flags:
269// MBadPixelsPix::kTestNotFitted and MBadPixelsPix::kTestOscillating
270//
271Bool_t MHCalibrationTestCam::FinalizeHists()
272{
273
274 *fLog << endl;
275
276 TArrayI numaidx;
277 numaidx.Set(fGeom->GetNumAreas());
278
279 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
280 {
281
282 MHCalibrationPix &hist = (*this)[i];
283
284 if (hist.IsEmpty())
285 continue;
286
287 if (!hist.FitGaus())
288 if (!hist.RepeatFit())
289 hist.BypassFit();
290
291 hist.CreateFourierSpectrum();
292
293 const Float_t area = (*fGeom)[i].GetA();
294 const Int_t aidx = (*fGeom)[i].GetAidx();
295
296 fMeanMeanPhotPerArea[aidx] += hist.GetMean() / area;
297 fRmsMeanPhotPerArea [aidx] += hist.GetMean() / area * hist.GetMean() / area;
298 fMeanSigmaPhotPerArea[aidx] += hist.GetSigma()/ area;
299 fRmsSigmaPhotPerArea [aidx] += hist.GetSigma()/ area * hist.GetSigma() / area;
300 numaidx[aidx]++;
301 }
302
303
304 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
305 {
306
307 MHCalibrationPix &hist = GetAverageHiGainArea(j);
308 if (hist.IsEmpty())
309 continue;
310
311 if (!hist.FitGaus())
312 if (!hist.RepeatFit())
313 hist.BypassFit();
314
315 hist.CreateFourierSpectrum();
316
317 fRmsMeanPhotPerArea [j] -= fMeanMeanPhotPerArea [j]*fMeanMeanPhotPerArea [j]/numaidx[j];
318 fRmsSigmaPhotPerArea[j] -= fMeanSigmaPhotPerArea[j]*fMeanSigmaPhotPerArea[j]/numaidx[j];
319
320 fMeanMeanPhotPerArea [j] /= numaidx[j];
321 fMeanSigmaPhotPerArea[j] /= numaidx[j];
322 fRmsMeanPhotPerArea [j] /= numaidx[j]-1.;
323 fRmsSigmaPhotPerArea [j] /= numaidx[j]-1.;
324
325 if (fRmsMeanPhotPerArea [j] > 0.)
326 fRmsMeanPhotPerArea [j] = TMath::Sqrt(fRmsMeanPhotPerArea [j]);
327 if (fRmsSigmaPhotPerArea [j] > 0.)
328 fRmsSigmaPhotPerArea [j] = TMath::Sqrt(fRmsSigmaPhotPerArea [j]);
329 }
330
331 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
332 {
333
334 MHCalibrationPix &hist = GetAverageHiGainSector(j);
335 if (hist.IsEmpty())
336 continue;
337
338 if (!hist.FitGaus())
339 if (!hist.RepeatFit())
340 hist.BypassFit();
341
342 hist.CreateFourierSpectrum();
343 }
344
345 return kTRUE;
346}
347
348
349// --------------------------------------------------------------------------
350//
351// The types are as follows:
352//
353// Fitted values:
354// ==============
355//
356// 0: Fitted Mean Test Calibration (MHGausEvents::GetMean())
357// 1: Error Mean Test Calibration (MHGausEvents::GetMeanErr())
358// 2: Sigma fitted Test Calibration (MHGausEvents::GetSigma())
359// 3: Error Sigma Test Calibration (MHGausEvents::GetSigmaErr())
360//
361// Useful variables derived from the fit results:
362// =============================================
363//
364// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
365//
366// Localized defects:
367// ==================
368//
369// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
370// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
371//
372// Converted values:
373// =================
374//
375// 7: Fitted Mean Test Calibration (MHGausEvents::GetMean()) by MGeomPix::GetA()
376// 8: Fitted Mean Error Calibration (MHGausEvents::GetMeanErr()) by MGeomPix::GetA()
377// 9: Fitted Sigma Test Calibration (MHGausEvents::GetSigma()) by MGeomPix::GetA()
378// 10: Fitted Sigma Error Calibration (MHGausEvents::GetSigmaErr()) by MGeomPix::GetA()
379//
380Bool_t MHCalibrationTestCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
381{
382
383 if (fHiGainArray->GetSize() <= idx)
384 return kFALSE;
385
386 const MHCalibrationPix &pix = (*this)[idx];
387
388 if (pix.IsEmpty())
389 return kFALSE;
390
391 switch (type)
392 {
393 case 0:
394 val = pix.GetMean();
395 break;
396 case 1:
397 val = pix.GetMeanErr();
398 break;
399 case 2:
400 val = pix.GetSigma();
401 break;
402 case 3:
403 val = pix.GetSigmaErr();
404 break;
405 case 4:
406 val = pix.GetProb();
407 break;
408 case 5:
409 if (!pix.IsGausFitOK())
410 val = 1.;
411 break;
412 case 6:
413 if (!pix.IsFourierSpectrumOK())
414 val = 1.;
415 break;
416 case 7:
417 val = pix.GetMean()/cam[idx].GetA();
418 break;
419 case 8:
420 val = pix.GetMeanErr()/cam[idx].GetA();
421 break;
422 case 9:
423 val = pix.GetSigma()/cam[idx].GetA();
424 break;
425 case 10:
426 val = pix.GetSigmaErr()/cam[idx].GetA();
427 break;
428 default:
429 return kFALSE;
430 }
431 return kTRUE;
432}
433
434// --------------------------------------------------------------------------
435//
436// Calls MHCalibrationPix::DrawClone() for pixel idx
437//
438void MHCalibrationTestCam::DrawPixelContent(Int_t idx) const
439{
440 (*this)[idx].DrawClone();
441}
442
443
444//------------------------------------------------------------
445//
446// For all averaged areas, the fitted sigma is multiplied with the square root of
447// the number involved pixels
448//
449void MHCalibrationTestCam::CalcAverageSigma()
450{
451
452 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
453 {
454
455 MHCalibrationPix &hist = GetAverageHiGainArea(j);
456
457 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
458 fAverageAreaSigma[j] = hist.GetSigma () * numsqr;
459 fAverageAreaSigmaVar[j] = hist.GetSigmaErr () * hist.GetSigmaErr() * numsqr;
460
461 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / hist.GetMean();
462 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
463 fAverageAreaRelSigmaVar[j] += hist.GetMeanErr()*hist.GetMeanErr()/hist.GetMean()/hist.GetMean();
464 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
465 }
466}
Note: See TracBrowser for help on using the repository browser.