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

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