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

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