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

Last change on this file since 8405 was 8339, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 14.3 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 MHCalibrationPix &histhi = (*this)[i];
233
234 const MSignalPix *pix = calibration->GetPixById(i);
235 if (!pix)
236 continue;
237
238 const Float_t signal = pix->GetNumPhotons();
239
240 if (signal < 0.0001)
241 continue;
242
243 const Int_t aidx = (*fGeom)[i].GetAidx();
244 const Int_t sector = (*fGeom)[i].GetSector();
245
246 histhi.FillHistAndArray(signal) ;
247
248 sumareahi [aidx] += signal;
249 numareahi [aidx] ++;
250 sumsectorhi[sector] += signal;
251 numsectorhi[sector] ++;
252 }
253
254 for (Int_t j=0; j<nareas; j++)
255 {
256 MHCalibrationPix &histhi = GetAverageHiGainArea(j);
257 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
258 }
259
260 for (Int_t j=0; j<nsectors; j++)
261 {
262 MHCalibrationPix &histhi = GetAverageHiGainSector(j);
263 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
264
265 }
266
267 return kTRUE;
268}
269
270// --------------------------------------------------------------------------
271//
272// Calls:
273// - MHCalibrationCam::FitHiGainArrays() with flags:
274// MBadPixelsPix::kTestNotFitted and MBadPixelsPix::kTestOscillating
275//
276Bool_t MHCalibrationTestCam::FinalizeHists()
277{
278
279 *fLog << endl;
280
281 TArrayI numaidx;
282 numaidx.Set(fGeom->GetNumAreas());
283
284 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
285 {
286
287 MHCalibrationPix &hist = (*this)[i];
288
289 if (hist.IsEmpty())
290 continue;
291
292 if (!hist.FitGaus())
293 if (!hist.RepeatFit())
294 hist.BypassFit();
295
296 hist.CreateFourierSpectrum();
297
298 const Float_t area = (*fGeom)[i].GetA();
299 const Int_t aidx = (*fGeom)[i].GetAidx();
300
301 fMeanMeanPhotPerArea[aidx] += hist.GetMean() / area;
302 fRmsMeanPhotPerArea [aidx] += hist.GetMean() / area * hist.GetMean() / area;
303 fMeanSigmaPhotPerArea[aidx] += hist.GetSigma()/ area;
304 fRmsSigmaPhotPerArea [aidx] += hist.GetSigma()/ area * hist.GetSigma() / area;
305 numaidx[aidx]++;
306 }
307
308
309 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
310 {
311
312 MHCalibrationPix &hist = GetAverageHiGainArea(j);
313 if (hist.IsEmpty())
314 continue;
315
316 if (!hist.FitGaus())
317 if (!hist.RepeatFit())
318 hist.BypassFit();
319
320 hist.CreateFourierSpectrum();
321
322 fRmsMeanPhotPerArea [j] -= fMeanMeanPhotPerArea [j]*fMeanMeanPhotPerArea [j]/numaidx[j];
323 fRmsSigmaPhotPerArea[j] -= fMeanSigmaPhotPerArea[j]*fMeanSigmaPhotPerArea[j]/numaidx[j];
324
325 fMeanMeanPhotPerArea [j] /= numaidx[j];
326 fMeanSigmaPhotPerArea[j] /= numaidx[j];
327 fRmsMeanPhotPerArea [j] /= numaidx[j]-1.;
328 fRmsSigmaPhotPerArea [j] /= numaidx[j]-1.;
329
330 if (fRmsMeanPhotPerArea [j] > 0.)
331 fRmsMeanPhotPerArea [j] = TMath::Sqrt(fRmsMeanPhotPerArea [j]);
332 if (fRmsSigmaPhotPerArea [j] > 0.)
333 fRmsSigmaPhotPerArea [j] = TMath::Sqrt(fRmsSigmaPhotPerArea [j]);
334 }
335
336 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
337 {
338
339 MHCalibrationPix &hist = GetAverageHiGainSector(j);
340 if (hist.IsEmpty())
341 continue;
342
343 if (!hist.FitGaus())
344 if (!hist.RepeatFit())
345 hist.BypassFit();
346
347 hist.CreateFourierSpectrum();
348 }
349
350 return kTRUE;
351}
352
353
354// --------------------------------------------------------------------------
355//
356// The types are as follows:
357//
358// Fitted values:
359// ==============
360//
361// 0: Fitted Mean Test Calibration (MHGausEvents::GetMean())
362// 1: Error Mean Test Calibration (MHGausEvents::GetMeanErr())
363// 2: Sigma fitted Test Calibration (MHGausEvents::GetSigma())
364// 3: Error Sigma Test Calibration (MHGausEvents::GetSigmaErr())
365//
366// Useful variables derived from the fit results:
367// =============================================
368//
369// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
370//
371// Localized defects:
372// ==================
373//
374// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
375// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
376//
377// Converted values:
378// =================
379//
380// 7: Fitted Mean Test Calibration (MHGausEvents::GetMean()) by MGeomPix::GetA()
381// 8: Fitted Mean Error Calibration (MHGausEvents::GetMeanErr()) by MGeomPix::GetA()
382// 9: Fitted Sigma Test Calibration (MHGausEvents::GetSigma()) by MGeomPix::GetA()
383// 10: Fitted Sigma Error Calibration (MHGausEvents::GetSigmaErr()) by MGeomPix::GetA()
384//
385Bool_t MHCalibrationTestCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
386{
387
388 if (fHiGainArray->GetSize() <= idx)
389 return kFALSE;
390
391 const MHCalibrationPix &pix = (*this)[idx];
392
393 if (pix.IsEmpty())
394 return kFALSE;
395
396 switch (type)
397 {
398 case 0:
399 val = pix.GetMean();
400 break;
401 case 1:
402 val = pix.GetMeanErr();
403 break;
404 case 2:
405 val = pix.GetSigma();
406 break;
407 case 3:
408 val = pix.GetSigmaErr();
409 break;
410 case 4:
411 val = pix.GetProb();
412 break;
413 case 5:
414 if (!pix.IsGausFitOK())
415 val = 1.;
416 break;
417 case 6:
418 if (!pix.IsFourierSpectrumOK())
419 val = 1.;
420 break;
421 case 7:
422 val = pix.GetMean()/cam[idx].GetA();
423 break;
424 case 8:
425 val = pix.GetMeanErr()/cam[idx].GetA();
426 break;
427 case 9:
428 val = pix.GetSigma()/cam[idx].GetA();
429 break;
430 case 10:
431 val = pix.GetSigmaErr()/cam[idx].GetA();
432 break;
433 default:
434 return kFALSE;
435 }
436 return kTRUE;
437}
438
439// --------------------------------------------------------------------------
440//
441// Calls MHCalibrationPix::DrawClone() for pixel idx
442//
443void MHCalibrationTestCam::DrawPixelContent(Int_t idx) const
444{
445 (*this)[idx].DrawClone();
446}
447
448
449//------------------------------------------------------------
450//
451// For all averaged areas, the fitted sigma is multiplied with the square root of
452// the number involved pixels
453//
454void MHCalibrationTestCam::CalcAverageSigma()
455{
456
457 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
458 {
459
460 MHCalibrationPix &hist = GetAverageHiGainArea(j);
461
462 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
463 fAverageAreaSigma[j] = hist.GetSigma () * numsqr;
464 fAverageAreaSigmaVar[j] = hist.GetSigmaErr () * hist.GetSigmaErr() * numsqr;
465
466 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / hist.GetMean();
467 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
468 fAverageAreaRelSigmaVar[j] += hist.GetMeanErr()*hist.GetMeanErr()/hist.GetMean()/hist.GetMean();
469 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
470 }
471}
Note: See TracBrowser for help on using the repository browser.