source: tags/Mars-V0.9.2/mhcalib/MHCalibrationTestTimeCam.cc

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