source: trunk/MagicSoft/Mars/mcalib/MHCalibrationRelTimeCam.cc@ 3636

Last change on this file since 3636 was 3636, checked in by gaug, 20 years ago
*** empty log message ***
File size: 15.0 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// MHCalibrationRelTimeCam //
27// //
28// Fills the extracted relative arrival times of MArrivalTimeCam into
29// the MHGausEvents-classes MHCalibrationRelTimePix for every:
30//
31// - pixel, stored in the TObjArray's MHCalibrationCam::fHiGainArray
32//
33// - average pixel per area index (e.g. inner and outer for the MAGIC camera),
34// stored in the TObjArray's MHCalibrationCam::fAverageHiGainAreas
35//
36// - average pixel per camera sector (e.g. sectors 1-6 for the MAGIC camera),
37// stored in the TObjArray's MHCalibrationCam::fAverageHiGainSectors
38//
39// Every time is filled into a histogram and an array, in order to perform
40// a Fourier analysis (see MHGausEvents). The signals are moreover averaged on an
41// event-by-event basis and written into the corresponding average pixels.
42//
43// The histograms are fitted to a Gaussian, mean and sigma with its errors
44// and the fit probability are extracted. If none of these values are NaN's and
45// if the probability is bigger than fProbLimit (default: 0.5%), the fit is valid.
46// Otherwise, the fit is repeated within ranges of the previous mean +- 5 sigma.
47// In case this does not make the fit valid, the histogram means and RMS's are
48// taken directly and the following flags are set:
49// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kRelTimeNotFitted ) and
50// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
51//
52// Outliers of more than MHCalibrationChargePix::fPickupLimit (default: 5) sigmas
53// from the mean are counted as PickUp events (stored in MHCalibrationRelTimePix::fPickup)
54//
55// The class also fills arrays with the signal vs. event number, creates a fourier
56// spectrum and investigates if the projected fourier components follow an exponential
57// distribution. In case that the probability of the exponential fit is less than
58// fProbLimit (default: 0.5%), the following flags are set:
59// - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kRelTimeOscillating ) and
60// - MBadPixelsPix::SetUnsuitable( MBadPixelsPix::kUnreliableRun )
61//
62// This same procedure is performed for the average pixels.
63//
64// The following results are written into MCalibrationRelTimeCam:
65//
66// - MCalibrationPix::SetMean()
67// - MCalibrationPix::SetMeanErr()
68// - MCalibrationPix::SetSigma()
69// - MCalibrationPix::SetSigmaErr()
70// - MCalibrationPix::SetProb()
71// - MCalibrationPix::SetNumPickup()
72//
73// For all averaged areas, the fitted sigma is multiplied with the square root of
74// the number involved pixels in order to be able to compare it to the average of
75// sigmas in the camera.
76//
77/////////////////////////////////////////////////////////////////////////////
78#include "MHCalibrationRelTimeCam.h"
79#include "MHCalibrationRelTimePix.h"
80
81#include "MLog.h"
82#include "MLogManip.h"
83
84#include "MParList.h"
85
86#include "MCalibrationRelTimeCam.h"
87#include "MCalibrationPix.h"
88
89#include "MArrivalTimeCam.h"
90#include "MArrivalTimePix.h"
91
92#include "MGeomCam.h"
93#include "MGeomPix.h"
94
95#include "MBadPixelsCam.h"
96#include "MBadPixelsPix.h"
97
98ClassImp(MHCalibrationRelTimeCam);
99
100using namespace std;
101// --------------------------------------------------------------------------
102//
103// Default Constructor.
104//
105MHCalibrationRelTimeCam::MHCalibrationRelTimeCam(const char *name, const char *title)
106{
107
108 fName = name ? name : "MHCalibrationRelTimeCam";
109 fTitle = title ? title : "Histogram class for the relative time calibration of the camera";
110
111}
112
113// --------------------------------------------------------------------------
114//
115// Gets or creates the pointers to:
116// - MCalibrationRelTimeCam
117//
118// Searches pointer to:
119// - MArrivalTimeCam
120//
121// Initializes, if empty to MArrivalTimeCam::GetSize() for:
122// - MHCalibrationCam::fHiGainArray, MHCalibrationCam::fLoGainArray
123//
124// Initializes, if empty to MGeomCam::GetNumAreas() for:
125// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
126//
127// Initializes, if empty to MGeomCam::GetNumSectors() for:
128// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
129//
130// Calls InitializeHists() for every entry in:
131// - MHCalibrationCam::fHiGainArray
132// - MHCalibrationCam::fAverageHiGainAreas
133// - MHCalibrationCam::fAverageHiGainSectors
134//
135// Sets Titles and Names for the Histograms
136// - MHCalibrationCam::fAverageHiGainAreas
137// - MHCalibrationCam::fAverageHiGainSectors
138//
139// Sets number of bins to MHCalibrationCam::fAverageNbins for:
140// - MHCalibrationCam::fAverageHiGainAreas, MHCalibrationCam::fAverageLoGainAreas
141// - MHCalibrationCam::fAverageHiGainSectors, MHCalibrationCam::fAverageLoGainSectors
142//
143Bool_t MHCalibrationRelTimeCam::ReInitHists(MParList *pList)
144{
145
146 fCam = (MCalibrationCam*)pList->FindCreateObj("MCalibrationRelTimeCam");
147 if (!fCam)
148 return kFALSE;
149
150 MArrivalTimeCam *signal = (MArrivalTimeCam*)pList->FindObject("MArrivalTimeCam");
151 if (!signal)
152 {
153 *fLog << err << "MArrivalTimeCam not found... abort." << endl;
154 return kFALSE;
155 }
156
157 const Int_t npixels = fGeom->GetNumPixels();
158 const Int_t nsectors = fGeom->GetNumSectors();
159 const Int_t nareas = fGeom->GetNumAreas();
160
161 if (fHiGainArray->GetEntries()==0)
162 {
163 fHiGainArray->Expand(npixels);
164 for (Int_t i=0; i<npixels; i++)
165 {
166 (*fHiGainArray)[i] = new MHCalibrationRelTimePix;
167 InitHists((*this)[i],(*fBadPixels)[i],i);
168 }
169 }
170
171 if (fLoGainArray->GetEntries()==0)
172 {
173 fLoGainArray->Expand(npixels);
174 for (Int_t i=0; i<npixels; i++)
175 {
176 (*fLoGainArray)[i] = new MHCalibrationRelTimePix;
177 InitHists((*this)(i),(*fBadPixels)[i],i);
178 }
179 }
180
181 if (fAverageHiGainAreas->GetEntries()==0)
182 {
183 fAverageHiGainAreas->Expand(nareas);
184
185 for (Int_t j=0; j<nareas; j++)
186 {
187 (*fAverageHiGainAreas)[j] =
188 new MHCalibrationRelTimePix("AverageHiGainArea",
189 "Average Relative Arrival Times area idx ");
190
191 InitHists(GetAverageHiGainArea(j),fCam->GetAverageBadArea(j),j);
192
193 GetAverageHiGainArea(j).GetHGausHist()->SetTitle("Relative Arrival Times average Area Idx ");
194 GetAverageHiGainArea(j).SetNbins(fAverageNbins);
195 }
196 }
197
198 if (fAverageLoGainAreas->GetEntries()==0)
199 {
200 fAverageLoGainAreas->Expand(nareas);
201
202 for (Int_t j=0; j<nareas; j++)
203 {
204 (*fAverageLoGainAreas)[j] =
205 new MHCalibrationRelTimePix("AverageLoGainArea",
206 "Relative Arrival Times average Area idx ");
207
208 InitHists(GetAverageLoGainArea(j),fCam->GetAverageBadArea(j),j);
209
210 GetAverageLoGainArea(j).GetHGausHist()->SetTitle("Relative Arrival Times average Area Idx ");
211 GetAverageLoGainArea(j).SetNbins(fAverageNbins);
212 }
213 }
214
215 if (fAverageHiGainSectors->GetEntries()==0)
216 {
217 fAverageHiGainSectors->Expand(nsectors);
218
219 for (Int_t j=0; j<nsectors; j++)
220 {
221 (*fAverageHiGainSectors)[j] =
222 new MHCalibrationRelTimePix("AverageHiGainSector",
223 "Relative Arrival Times average sector ");
224
225 GetAverageHiGainSector(j).GetHGausHist()->SetTitle("Relative Arrival Times average Sector ");
226 GetAverageHiGainSector(j).SetNbins(fAverageNbins);
227 }
228 }
229
230 if (fAverageLoGainSectors->GetEntries()==0)
231 {
232 fAverageLoGainSectors->Expand(nsectors);
233
234 for (Int_t j=0; j<nsectors; j++)
235 {
236 (*fAverageLoGainSectors)[j] =
237 new MHCalibrationRelTimePix("AverageLoGainSector",
238 "Relative Arrival Times average sector ");
239
240 InitHists(GetAverageLoGainSector(j),fCam->GetAverageBadSector(j),j);
241
242 GetAverageLoGainSector(j).GetHGausHist()->SetTitle("Relative Arrival Times average Sector ");
243 GetAverageLoGainSector(j).SetNbins(fAverageNbins);
244 }
245 }
246
247 return kTRUE;
248}
249
250
251//--------------------------------------------------------------------------------
252//
253// Retrieves pointer to MArrivalTimeCam:
254//
255// Retrieves from MGeomCam:
256// - number of pixels
257// - number of pixel areas
258// - number of sectors
259//
260// Fill RelTimes histograms (MHGausEvents::FillHistAndArray()) with:
261// - MArrivalTimePix::GetArrivalTime(pixid) - MArrivalTimePix::GetArrivalTime(1);
262// (i.e. the time difference between pixel i and pixel 1 (hardware number: 2)
263//
264Bool_t MHCalibrationRelTimeCam::FillHists(const MParContainer *par, const Stat_t w)
265{
266
267 MArrivalTimeCam *arrtime = (MArrivalTimeCam*)par;
268 if (!arrtime)
269 {
270 gLog << err << "No argument in MArrivalTime::Fill... abort." << endl;
271 return kFALSE;
272 }
273
274 const Int_t npixels = fGeom->GetNumPixels();
275 const Int_t nareas = fGeom->GetNumAreas();
276 const Int_t nsectors = fGeom->GetNumSectors();
277
278 Float_t sumareahi [nareas], sumarealo [nareas];
279 Float_t sumsectorhi[nsectors], sumsectorlo[nsectors];
280 Int_t numareahi [nareas], numarealo [nareas];
281 Int_t numsectorhi[nsectors], numsectorlo[nsectors];
282
283 for (UInt_t j=0; j<nareas; j++)
284 {
285 sumareahi[j] = sumarealo[j] = 0.;
286 numareahi[j] = numarealo[j] = 0;
287 }
288
289 for (UInt_t j=0; j<nsectors; j++)
290 {
291 sumsectorhi[j] = sumsectorlo[j] = 0.;
292 numsectorhi[j] = numsectorlo[j] = 0;
293 }
294
295 const MArrivalTimePix &refpix = (*arrtime)[1];
296 const Float_t reftime = refpix.IsLoGainUsed()
297 ? refpix.GetArrivalTimeLoGain() : refpix.GetArrivalTimeHiGain();
298
299 for (Int_t i=0; i<npixels; i++)
300 {
301
302 MHGausEvents &histhi = (*this)[i];
303 MHGausEvents &histlo = (*this)(i);
304
305 if (histhi.IsExcluded())
306 continue;
307
308 const MArrivalTimePix &pix = (*arrtime)[i];
309 const Float_t time = pix.IsLoGainUsed()
310 ? pix.GetArrivalTimeLoGain() : pix.GetArrivalTimeHiGain();
311 const Float_t reltime = time - reftime;
312
313 const Int_t aidx = (*fGeom)[i].GetAidx();
314 const Int_t sector = (*fGeom)[i].GetSector();
315
316 if (pix.IsLoGainUsed())
317 {
318 histlo.FillHistAndArray(reltime);
319 sumarealo [aidx] += reltime;
320 numarealo [aidx] ++;
321 sumsectorlo[sector] += reltime;
322 numsectorlo[sector] ++;
323 }
324 else
325 {
326 histhi.FillHistAndArray(reltime) ;
327 sumareahi [aidx] += reltime;
328 numareahi [aidx] ++;
329 sumsectorhi[sector] += reltime;
330 numsectorhi[sector] ++;
331 }
332 }
333
334 for (UInt_t j=0; j<nareas; j++)
335 {
336 MHGausEvents &histhi = GetAverageHiGainArea(j);
337 histhi.FillHistAndArray(numareahi[j] == 0 ? 0. : sumareahi[j]/numareahi[j]);
338
339 MHGausEvents &histlo = GetAverageLoGainArea(j);
340 histlo.FillHistAndArray(numarealo[j] == 0 ? 0. : sumarealo[j]/numarealo[j]);
341 }
342
343 for (UInt_t j=0; j<nsectors; j++)
344 {
345 MHGausEvents &histhi = GetAverageHiGainSector(j);
346 histhi.FillHistAndArray(numsectorhi[j] == 0 ? 0. : sumsectorhi[j]/numsectorhi[j]);
347
348 MHGausEvents &histlo = GetAverageLoGainSector(j);
349 histlo.FillHistAndArray(numsectorlo[j] == 0 ? 0. : sumsectorlo[j]/numsectorlo[j]);
350 }
351
352 return kTRUE;
353}
354
355// --------------------------------------------------------------------------
356//
357// Calls:
358// - MHCalibrationCam::FitHiGainArrays() with flags:
359// MBadPixelsPix::kRelTimeNotFitted and MBadPixelsPix::kRelTimeOscillating
360// - MHCalibrationCam::FitLoGainArrays() with flags:
361// MBadPixelsPix::kRelTimeNotFitted and MBadPixelsPix::kRelTimeOscillating
362//
363Bool_t MHCalibrationRelTimeCam::FinalizeHists()
364{
365
366 FitHiGainArrays((MCalibrationCam&)(*fCam),*fBadPixels,
367 MBadPixelsPix::kRelTimeNotFitted,
368 MBadPixelsPix::kRelTimeOscillating);
369
370 FitLoGainArrays((MCalibrationCam&)(*fCam),*fBadPixels,
371 MBadPixelsPix::kRelTimeNotFitted,
372 MBadPixelsPix::kRelTimeOscillating);
373
374 return kTRUE;
375}
376
377// --------------------------------------------------------------------------
378//
379// Sets all pixels to MBadPixelsPix::kUnreliableRun, if following flags are set:
380// - MBadPixelsPix::kRelTimeNotFitted
381// - MBadPixelsPix::kRelTimeOscillating
382//
383void MHCalibrationRelTimeCam::FinalizeBadPixels()
384{
385
386 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
387 {
388
389 MBadPixelsPix &bad = (*fBadPixels)[i];
390
391 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeNotFitted ))
392 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
393
394 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeOscillating))
395 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
396
397 }
398}
399
400// --------------------------------------------------------------------------
401//
402// The types are as follows:
403//
404// Fitted values:
405// ==============
406//
407// 0: Fitted Mean Relative Arrival Time
408// 1: Error of fitted Mean Relative Arrival Time
409// 2: Sigma of fitted Relative Arrival Time
410// 3: Error of Sigma of fitted Relative Arrival Time
411//
412//
413// Useful variables derived from the fit results:
414// =============================================
415//
416// 4: Returned probability of Gauss fit to RelTime distribution
417//
418// Localized defects:
419// ==================
420//
421// 5: Gaus fit not OK
422// 6: Fourier spectrum not OK
423//
424Bool_t MHCalibrationRelTimeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
425{
426
427 if (fHiGainArray->GetSize() <= idx)
428 return kFALSE;
429
430 MHCalibrationRelTimePix &hist = (MHCalibrationRelTimePix&)(*this)[idx];
431
432 switch (type)
433 {
434 case 0:
435 val = hist.GetMean();
436 break;
437 case 1:
438 val = hist.GetMeanErr();
439 break;
440 case 2:
441 val = hist.GetSigma();
442 break;
443 case 3:
444 val = hist.GetSigmaErr();
445 break;
446 case 4:
447 val = hist.GetProb();
448 break;
449 case 5:
450 if (!hist.IsGausFitOK())
451 val = 1.;
452 break;
453 case 6:
454 if (!hist.IsFourierSpectrumOK())
455 val = 1.;
456 break;
457 default:
458 return kFALSE;
459 }
460 return kTRUE;
461}
462
463void MHCalibrationRelTimeCam::DrawPixelContent(Int_t idx) const
464{
465 const MHCalibrationRelTimePix &hist = (MHCalibrationRelTimePix&)(*this)[idx];
466 hist.DrawClone();
467}
Note: See TracBrowser for help on using the repository browser.