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

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