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

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