source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestTimeCam.cc@ 6147

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