source: trunk/MagicSoft/Mars/mcalib/MHCalibrationTestTimeCam.cc@ 4921

Last change on this file since 4921 was 4904, checked in by gaug, 20 years ago
*** empty log message ***
File size: 14.0 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// MHCalibrationTestTimeCam
27//
28// Fills the calibrated signal from an MArrivalTime into
29// MHCalibrationTestTimePix 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 "MHCalibrationTestTimeCam.h"
85#include "MHCalibrationTestTimePix.h"
86
87#include "MHCalibrationPix.h"
88
89#include "MLog.h"
90#include "MLogManip.h"
91
92#include "MParList.h"
93
94#include "MCalibrationCam.h"
95#include "MCalibrationPix.h"
96
97#include "MArrivalTime.h"
98
99#include "MGeomCam.h"
100#include "MGeomPix.h"
101
102#include "MBadPixelsCam.h"
103#include "MBadPixelsPix.h"
104
105ClassImp(MHCalibrationTestTimeCam);
106
107using namespace std;
108// --------------------------------------------------------------------------
109//
110// Default Constructor.
111//
112MHCalibrationTestTimeCam::MHCalibrationTestTimeCam(const char *name, const char *title)
113{
114
115 fName = name ? name : "MHCalibrationTestTimeCam";
116 fTitle = title ? title : "Histogram class for testing the calibration of arrival times";
117
118 SetAverageNbins(5000);
119}
120
121// --------------------------------------------------------------------------
122//
123// Gets or creates the pointers to:
124//
125// Searches pointer to:
126// - MArrivalTime
127//
128// Initializes, if empty to MGeomCam::GetNumAreas() for:
129// - MHCalibrationCam::fAverageHiGainAreas
130//
131// Initializes, if empty to MGeomCam::GetNumSectors() for:
132// - MHCalibrationCam::fAverageHiGainSectors
133//
134// Calls MHCalibrationCam::InitHists() for every entry in:
135// - MHCalibrationCam::fHiGainArray
136// - MHCalibrationCam::fAverageHiGainAreas
137// - MHCalibrationCam::fAverageHiGainSectors
138//
139// Sets Titles and Names for the Histograms
140// - MHCalibrationCam::fAverageHiGainAreas
141// - MHCalibrationCam::fAverageHiGainSectors
142//
143// Sets number of bins to MHCalibrationCam::fAverageNbins for:
144// - MHCalibrationCam::fAverageHiGainAreas
145// - MHCalibrationCam::fAverageHiGainSectors
146//
147Bool_t MHCalibrationTestTimeCam::ReInitHists(MParList *pList)
148{
149
150 MArrivalTime *signal = (MArrivalTime*)pList->FindObject("MArrivalTime");
151 if (!signal)
152 {
153 *fLog << err << "MArrivalTime not found... abort." << endl;
154 return kFALSE;
155 }
156
157 const Int_t npixels = fGeom->GetNumPixels();
158 const Int_t nsectors = fGeom->GetNumSectors();
159 const Int_t nareas = fGeom->GetNumAreas();
160
161 if (fHiGainArray->GetEntries()==0)
162 {
163 fHiGainArray->Expand(npixels);
164 for (Int_t i=0; i<npixels; i++)
165 {
166 (*fHiGainArray)[i] = new MHCalibrationTestTimePix("Calibrated Events Time",
167 "TestTime Calibration Pixel");
168 InitHists((*this)[i],(*fBadPixels)[i],i);
169 }
170 }
171
172 if (fAverageHiGainAreas->GetEntries()==0)
173 {
174 fAverageHiGainAreas->Expand(nareas);
175
176 for (Int_t j=0; j<nareas; j++)
177 {
178 (*fAverageHiGainAreas)[j] =
179 new MHCalibrationTestTimePix("MHCalibrationTestTimeAverageArea",
180 "Average TestTime Calibrations Area Idx ");
181
182 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("TestTime Calibrations Area Idx ");
183 GetAverageHiGainArea(j).SetNbins(fAverageNbins);
184 GetAverageHiGainArea(j).InitBins();
185 GetAverageHiGainArea(j).ChangeHistId(j);
186 GetAverageHiGainArea(j).SetEventFrequency(fPulserFrequency);
187
188 TH1F *h = GetAverageHiGainArea(j).GetHGausHist();
189 h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
190
191
192 }
193 }
194
195
196 if (fAverageHiGainSectors->GetEntries()==0)
197 {
198 fAverageHiGainSectors->Expand(nsectors);
199
200 for (Int_t j=0; j<nsectors; j++)
201 {
202 (*fAverageHiGainSectors)[j] =
203 new MHCalibrationTestTimePix("MHCalibrationTestTimeAverageSector",
204 "Average TestTime Calibrations Sector ");
205
206 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("TestTime Calibrations Sector ");
207 GetAverageHiGainSector(j).SetNbins(fAverageNbins);
208 GetAverageHiGainSector(j).InitBins();
209 GetAverageHiGainSector(j).ChangeHistId(j);
210 GetAverageHiGainSector(j).SetEventFrequency(fPulserFrequency);
211 TH1F *h = GetAverageHiGainSector(j).GetHGausHist();
212 h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
213
214
215 }
216 }
217
218 fLoGain = kFALSE;
219
220 return kTRUE;
221}
222
223
224// -------------------------------------------------------------------------------
225//
226// Retrieves pointer to MArrivalTime:
227//
228// Retrieves from MGeomCam:
229// - number of pixels
230// - number of pixel areas
231// - number of sectors
232//
233// Fills HiGain histograms (MHGausEvents::FillHistAndArray())
234// with:
235// - MArrivalTime::GetArrivalTime(pixid) - MArrivalTime::GetArrivalTime(1);
236// (i.e. the time difference between pixel i and pixel 1 (hardware number: 2) )
237//
238Bool_t MHCalibrationTestTimeCam::FillHists(const MParContainer *par, const Stat_t w)
239{
240
241 MArrivalTime *calibration = (MArrivalTime*)par;
242 if (!calibration)
243 {
244 gLog << err << "No argument in MHCalibrationRelTimeCam::Fill... abort." << endl;
245 return kFALSE;
246 }
247
248 const Int_t npixels = fGeom->GetNumPixels();
249 const Int_t nareas = fGeom->GetNumAreas();
250 const Int_t nsectors = fGeom->GetNumSectors();
251
252 TArrayF sumareahi (nareas);
253 TArrayF sumsectorhi(nsectors);
254 TArrayI numareahi (nareas);
255 TArrayI numsectorhi(nsectors);
256
257 for (Int_t i=0; i<npixels; i++)
258 {
259
260 MHCalibrationPix &histhi = (*this)[i];
261
262 if (histhi.IsExcluded())
263 continue;
264
265 const Float_t time = (*calibration)[i];
266 const Int_t aidx = (*fGeom)[i].GetAidx();
267 const Int_t sector = (*fGeom)[i].GetSector();
268
269 histhi.FillHistAndArray(time) ;
270 sumareahi [aidx] += time;
271 numareahi [aidx] ++;
272 sumsectorhi[sector] += time;
273 numsectorhi[sector] ++;
274 }
275
276 for (Int_t j=0; j<nareas; j++)
277 {
278 MHCalibrationPix &histhi = GetAverageHiGainArea(j);
279 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
280
281 }
282
283 for (Int_t j=0; j<nsectors; j++)
284 {
285 MHCalibrationPix &histhi = GetAverageHiGainSector(j);
286 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
287
288 }
289
290 return kTRUE;
291}
292
293// --------------------------------------------------------------------------
294//
295//
296Bool_t MHCalibrationTestTimeCam::FinalizeHists()
297{
298
299 for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
300 {
301
302 MHCalibrationPix &hist = (*this)[i];
303
304 if (hist.IsExcluded())
305 continue;
306
307 if (hist.IsEmpty())
308 continue;
309
310 if (!hist.FitGaus())
311 if (!hist.RepeatFit())
312 {
313 hist.BypassFit();
314 }
315
316 hist.CreateFourierSpectrum();
317
318 }
319
320 for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
321 {
322
323 MHCalibrationPix &hist = GetAverageHiGainArea(j);
324 if (hist.IsEmpty())
325 continue;
326
327 if (!hist.FitGaus())
328 if (!hist.RepeatFit())
329 {
330 hist.BypassFit();
331 }
332
333 hist.CreateFourierSpectrum();
334
335
336 }
337
338 for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
339 {
340
341 MHCalibrationPix &hist = GetAverageHiGainSector(j);
342 if (hist.IsEmpty())
343 continue;
344
345 if (!hist.FitGaus())
346 if (!hist.RepeatFit())
347 {
348 hist.BypassFit();
349 }
350 hist.CreateFourierSpectrum();
351
352
353 }
354
355 return kTRUE;
356}
357
358// --------------------------------------------------------------------------
359//
360void MHCalibrationTestTimeCam::FinalizeBadPixels()
361{
362
363}
364
365// --------------------------------------------------------------------------
366//
367// The types are as follows:
368//
369// Fitted values:
370// ==============
371//
372// 0: Fitted Mean Time Calibration (MHGausEvents::GetMean())
373// 1: Error Mean Time Calibration (MHGausEvents::GetMeanErr())
374// 2: Sigma fitted Time Calibration (MHGausEvents::GetSigma())
375// 3: Error Sigma Time Calibration (MHGausEvents::GetSigmaErr())
376//
377// Useful variables derived from the fit results:
378// =============================================
379//
380// 4: Returned probability of Gauss fit (calls: MHGausEvents::GetProb())
381//
382// Localized defects:
383// ==================
384//
385// 5: Gaus fit not OK (calls: MHGausEvents::IsGausFitOK())
386// 6: Fourier spectrum not OK (calls: MHGausEvents::IsFourierSpectrumOK())
387//
388Bool_t MHCalibrationTestTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
389{
390
391 if (fHiGainArray->GetSize() <= idx)
392 return kFALSE;
393
394 const MHCalibrationPix &pix = (*this)[idx];
395
396 if (pix.IsExcluded())
397 return kFALSE;
398
399 switch (type)
400 {
401 case 0:
402 val = pix.GetMean();
403 break;
404 case 1:
405 val = pix.GetMeanErr();
406 break;
407 case 2:
408 val = pix.GetSigma();
409 break;
410 case 3:
411 val = pix.GetSigmaErr();
412 break;
413 case 4:
414 val = pix.GetProb();
415 break;
416 case 5:
417 if (!pix.IsGausFitOK())
418 val = 1.;
419 break;
420 case 6:
421 if (!pix.IsFourierSpectrumOK())
422 val = 1.;
423 break;
424 default:
425 return kFALSE;
426 }
427 return kTRUE;
428}
429
430// --------------------------------------------------------------------------
431//
432// Calls MHCalibrationPix::DrawClone() for pixel idx
433//
434void MHCalibrationTestTimeCam::DrawPixelContent(Int_t idx) const
435{
436 (*this)[idx].DrawClone();
437}
438
439
440//------------------------------------------------------------
441//
442// For all averaged areas, the fitted sigma is multiplied with the square root of
443// the number involved pixels
444//
445void MHCalibrationTestTimeCam::CalcAverageSigma()
446{
447
448 for (UInt_t j=0; j<fGeom->GetNumAreas(); j++)
449 {
450
451 MHCalibrationPix &hist = GetAverageHiGainArea(j);
452
453 const Float_t numsqr = TMath::Sqrt((Float_t)fAverageAreaNum[j]);
454 fAverageAreaSigma[j] = hist.GetSigma () * numsqr;
455 fAverageAreaSigmaVar[j] = hist.GetSigmaErr () * hist.GetSigmaErr() * numsqr;
456
457 fAverageAreaRelSigma [j] = fAverageAreaSigma[j] / hist.GetMean();
458 fAverageAreaRelSigmaVar[j] = fAverageAreaSigmaVar[j] / (fAverageAreaSigma[j]*fAverageAreaSigma[j]);
459 fAverageAreaRelSigmaVar[j] += hist.GetMeanErr()*hist.GetMeanErr()/hist.GetMean()/hist.GetMean();
460 fAverageAreaRelSigmaVar[j] *= fAverageAreaRelSigma[j];
461 }
462}
Note: See TracBrowser for help on using the repository browser.