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

Last change on this file since 6169 was 5941, checked in by mazin, 20 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 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 SetLoGain(kFALSE);
148
149}
150
151// --------------------------------------------------------------------------
152//
153// Searches pointer to:
154// - MCerPhotEvt
155//
156// Calls:
157// - MHCalibrationCam::InitHiGainArrays()
158//
159// Sets:
160// - SetLoGain(kFALSE);
161// - fMeanMeanPhotPerArea to nareas
162// - fRmsMeanPhotPerArea to nareas
163// - fMeanSigmaPhotPerArea to nareas
164// - fRmsSigmaPhotPerArea to nareas
165//
166Bool_t MHCalibrationTestCam::ReInitHists(MParList *pList)
167{
168
169 if (!InitCams(pList,"Test"))
170 return kFALSE;
171
172
173 MCerPhotEvt *signal = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
174 if (!signal)
175 {
176 *fLog << err << "MCerPhotEvt not found... abort." << endl;
177 return kFALSE;
178 }
179
180
181 const Int_t npixels = fGeom->GetNumPixels();
182 const Int_t nsectors = fGeom->GetNumSectors();
183 const Int_t nareas = fGeom->GetNumAreas();
184
185 InitHiGainArrays(npixels,nareas,nsectors);
186 InitLoGainArrays(npixels,nareas,nsectors);
187
188 fMeanMeanPhotPerArea.Set(nareas);
189 fRmsMeanPhotPerArea .Set(nareas);
190 fMeanSigmaPhotPerArea.Set(nareas);
191 fRmsSigmaPhotPerArea.Set(nareas);
192
193 return kTRUE;
194}
195
196// -------------------------------------------------------------------------------
197//
198// Retrieves pointer to MCerPhotEvt:
199//
200// Retrieves from MGeomCam:
201// - number of pixels
202// - number of pixel areas
203// - number of sectors
204//
205// Fills HiGain histograms (MHGausEvents::FillHistAndArray())
206// with:
207// - MCerPhotPix::GetNumPhotons(pixid);
208//
209Bool_t MHCalibrationTestCam::FillHists(const MParContainer *par, const Stat_t w)
210{
211
212 MCerPhotEvt *calibration = (MCerPhotEvt*)par;
213 if (!calibration)
214 {
215 gLog << err << "No argument in MHCalibrationTestCam::Fill... abort." << endl;
216 return kFALSE;
217 }
218
219 const Int_t npixels = fGeom->GetNumPixels();
220 const Int_t nareas = fGeom->GetNumAreas();
221 const Int_t nsectors = fGeom->GetNumSectors();
222
223 TArrayF sumareahi (nareas);
224 TArrayF sumsectorhi(nsectors);
225 TArrayI numareahi (nareas);
226 TArrayI numsectorhi(nsectors);
227
228 for (Int_t i=0; i<npixels; i++)
229 {
230
231 MHCalibrationPix &histhi = (*this)[i];
232
233 const MCerPhotPix *pix = calibration->GetPixById(i);
234 if (!pix)
235 continue;
236
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.