source: trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc@ 3952

Last change on this file since 3952 was 3952, checked in by gaug, 20 years ago
*** empty log message ***
File size: 13.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 04/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MCalibrationRelTimeCalc
28//
29// Task to finalize the relative time calibration obtained
30// from the fit results to the summed FADC slice distributions delivered by
31// MCalibrationRelTimeCam, calculated and filled by MHCalibrationRelTimeCam,
32//
33// PreProcess(): Initialize pointers to MCalibrationRelTimeCam,
34//
35// ReInit(): Initializes pointer to MBadPixelsCam
36//
37// Process(): Nothing to be done, histograms getting filled by MHCalibrationChargeCam
38//
39// PostProcess(): - FinalizeRelTimes()
40// - FinalizeBadPixels()
41//
42// Input Containers:
43// MCalibrationRelTimeCam
44// MBadPixelsCam
45// MGeomCam
46//
47// Output Containers:
48// MCalibrationRelTimeCam
49// MBadPixelsCam
50//
51//
52//////////////////////////////////////////////////////////////////////////////
53#include "MCalibrationRelTimeCalc.h"
54
55#include "MLog.h"
56#include "MLogManip.h"
57
58#include "MParList.h"
59
60#include "MGeomCam.h"
61#include "MGeomPix.h"
62
63#include "MCalibrationRelTimeCam.h"
64#include "MCalibrationRelTimePix.h"
65
66#include "MBadPixelsCam.h"
67#include "MBadPixelsPix.h"
68
69
70ClassImp(MCalibrationRelTimeCalc);
71
72using namespace std;
73
74const Float_t MCalibrationRelTimeCalc::fgRelTimeRelErrLimit = 7.5;
75// --------------------------------------------------------------------------
76//
77// Default constructor.
78//
79// Sets all pointers to NULL
80//
81// Initializes:
82// - fRelTimeRelErrLimit to fgRelTimeRelErrimit
83//
84// Calls:
85// - Clear()
86//
87MCalibrationRelTimeCalc::MCalibrationRelTimeCalc(const char *name, const char *title)
88 : fBadPixels(NULL), fCam(NULL), fGeom(NULL)
89{
90
91 fName = name ? name : "MCalibrationRelTimeCalc";
92 fTitle = title ? title : "Task to finalize the relative time calibration";
93
94 SetRelTimeRelErrLimit();
95
96 Clear();
97
98}
99
100// --------------------------------------------------------------------------
101//
102// Sets:
103// - all flags to kFALSE
104//
105void MCalibrationRelTimeCalc::Clear(const Option_t *o)
106{
107 SkipHiLoGainCalibration( kFALSE );
108}
109
110
111// -----------------------------------------------------------------------------------
112//
113// The following containers are searched and created if they were not found:
114//
115// - MBadPixelsCam
116//
117Int_t MCalibrationRelTimeCalc::PreProcess(MParList *pList)
118{
119
120
121 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj("MBadPixelsCam");
122 if (!fBadPixels)
123 {
124 *fLog << err << "Could not find or create MBadPixelsCam ... aborting." << endl;
125 return kFALSE;
126 }
127
128
129
130 return kTRUE;
131}
132
133
134// --------------------------------------------------------------------------
135//
136// Search for the following input containers and abort if not existing:
137// - MGeomCam
138// - MCalibrationRelTimeCam
139//
140// It defines the PixId of every pixel in:
141//
142// - MCalibrationRelTimeCam
143//
144// It sets all pixels in excluded which have the flag fBadBixelsPix::IsBad() set in:
145//
146// - MCalibrationRelTimePix
147//
148Bool_t MCalibrationRelTimeCalc::ReInit(MParList *pList )
149{
150
151 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
152 if (!fGeom)
153 {
154 *fLog << err << "No MGeomCam found... aborting." << endl;
155 return kFALSE;
156 }
157
158 fCam = (MCalibrationRelTimeCam*)pList->FindObject("MCalibrationRelTimeCam");
159 if (!fCam)
160 {
161 *fLog << err << "Cannot find MCalibrationRelTimeCam... aborting" << endl;
162 *fLog << err << "Maybe you forget to call an MFillH for the MHCalibrationRelTimeCam before..." << endl;
163 return kFALSE;
164 }
165
166
167 UInt_t npixels = fGeom->GetNumPixels();
168
169 for (UInt_t i=0; i<npixels; i++)
170 {
171
172 MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam) [i];
173 MBadPixelsPix &bad = (*fBadPixels)[i];
174
175 pix.SetPixId(i);
176
177 if (bad.IsBad())
178 {
179 pix.SetExcluded();
180 continue;
181 }
182
183 }
184
185 return kTRUE;
186}
187
188// ----------------------------------------------------------------------------------
189//
190// Nothing to be done in Process, but have a look at MHCalibrationRelTimeCam, instead
191//
192Int_t MCalibrationRelTimeCalc::Process()
193{
194 return kTRUE;
195}
196
197// -----------------------------------------------------------------------
198//
199// Return if number of executions is null.
200//
201// First loop over pixels, average areas and sectors, call:
202// - FinalizeRelTimes()
203// for every entry. Count number of valid pixels in loop and return kFALSE
204// if there are none (the "Michele check").
205//
206// Call FinalizeBadPixels()
207//
208// Call MParContainer::SetReadyToSave() for fCam
209//
210// Print out some statistics
211//
212Int_t MCalibrationRelTimeCalc::PostProcess()
213{
214
215 if (GetNumExecutions()==0)
216 return kFALSE;
217
218 //
219 // First loop over pixels, call FinalizePedestals and FinalizeRelTimes
220 //
221 FinalizeRelTimes();
222
223 //
224 // Finalize Bad Pixels
225 //
226 FinalizeBadPixels();
227
228 //
229 // Finalize calibration statistics
230 //
231 FinalizeUnsuitablePixels();
232
233 fCam ->SetReadyToSave();
234 fBadPixels->SetReadyToSave();
235
236 *fLog << inf << endl;
237 *fLog << GetDescriptor() << ": Errors statistics:" << endl;
238
239 PrintUncalibrated(MBadPixelsPix::kDeviatingTimeResolution,
240 Form("%s%2.1f%s","Time resolution less than ",fRelTimeRelErrLimit," sigma from Mean: "));
241 PrintUncalibrated(MBadPixelsPix::kRelTimeOscillating,
242 "Pixels with changing Rel. Times over time: ");
243 PrintUncalibrated(MBadPixelsPix::kRelTimeNotFitted,
244 "Pixels with unsuccesful Gauss fit to the times: ");
245 return kTRUE;
246}
247
248
249// ----------------------------------------------------------------------------------------------------
250//
251//
252// First loop: Calculate a mean and mean RMS of time resolution per area index
253// Include only pixels which are not MBadPixelsPix::kUnsuitableRun or
254// MBadPixelsPix::kUnreliableRun (see FinalizeBadPixels())
255//
256// Second loop: Exclude those deviating by more than fRelTimeRelErrLimit mean
257// sigmas from the mean (obtained in first loop). Set
258// MBadPixelsPix::kDeviatingTimeResolution if excluded.
259//
260void MCalibrationRelTimeCalc::FinalizeRelTimes()
261{
262
263 const UInt_t npixels = fGeom->GetNumPixels();
264 const UInt_t nareas = fGeom->GetNumAreas();
265
266 Float_t lowlim [nareas];
267 Float_t upplim [nareas];
268 Float_t areasum [nareas];
269 Float_t areasum2 [nareas];
270 Int_t numareavalid[nareas];
271
272 memset(lowlim ,0, nareas * sizeof(Float_t));
273 memset(upplim ,0, nareas * sizeof(Float_t));
274 memset(areasum ,0, nareas * sizeof(Float_t));
275 memset(areasum2 ,0, nareas * sizeof(Float_t));
276 memset(numareavalid ,0, nareas * sizeof(Int_t ));
277
278 //
279 // First loop: Get mean time resolution the RMS
280 // The loop is only to recognize later pixels with very deviating numbers
281 //
282 for (UInt_t i=0; i<npixels; i++)
283 {
284
285 MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[i];
286 MBadPixelsPix &bad = (*fBadPixels)[i];
287
288 if (pix.IsExcluded())
289 continue;
290
291 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
292 continue;
293
294 const Float_t res = pix.GetTimePrecision();
295 const Int_t aidx = (*fGeom)[i].GetAidx();
296
297 areasum [aidx] += res;
298 areasum2 [aidx] += res*res;
299 numareavalid[aidx] ++;
300 }
301
302
303 for (UInt_t aidx=0; aidx<nareas; aidx++)
304 {
305 if (numareavalid[aidx] < 20)
306 {
307 *fLog << warn << GetDescriptor() << ": Less than 20 pixels with valid time resolution found "
308 << "in area index: " << aidx << endl;
309 continue;
310 }
311
312 // Calculate the rms out of sum2:
313 areasum2[aidx] = (areasum2[aidx] - areasum[aidx]*areasum[aidx]/numareavalid[aidx]);
314 areasum2[aidx] /= (numareavalid[aidx]-1.);
315 areasum [aidx] /= numareavalid[aidx];
316 lowlim [aidx] = areasum [aidx] - fRelTimeRelErrLimit*areasum2[aidx];
317 upplim [aidx] = areasum [aidx] + fRelTimeRelErrLimit*areasum2[aidx];
318 }
319
320
321
322 for (UInt_t i=0; i<npixels; i++)
323 {
324
325 MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[i];
326 MBadPixelsPix &bad = (*fBadPixels)[i];
327
328 if (pix.IsExcluded())
329 continue;
330
331 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
332 continue;
333
334 const Float_t res = pix.GetTimePrecision();
335 const Int_t aidx = (*fGeom)[i].GetAidx();
336
337 if ( res < lowlim[aidx] || res > upplim[aidx] )
338 {
339 *fLog << warn << GetDescriptor() << ": Deviating time resolution: "
340 << Form("%4.2f",res) << " out of accepted limits: ["
341 << Form("%4.2f%s%4.2f",lowlim[aidx],",",upplim[aidx]) << "] in pixel " << i << endl;
342 bad.SetUncalibrated( MBadPixelsPix::kDeviatingTimeResolution);
343 pix.SetExcluded();
344 }
345 }
346}
347
348
349// -----------------------------------------------------------------------------------
350//
351// Sets pixel to MBadPixelsPix::kUnsuitableRun, if one of the following flags is set:
352// - MBadPixelsPix::kRelTimeIsPedestal
353// - MBadPixelsPix::kRelTimeErrNotValid
354// - MBadPixelsPix::kRelTimeRelErrNotValid
355//
356// - Call MCalibrationPix::SetExcluded() for the bad pixels
357//
358void MCalibrationRelTimeCalc::FinalizeBadPixels()
359{
360
361 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
362 {
363
364 MBadPixelsPix &bad = (*fBadPixels)[i];
365 MCalibrationPix &pix = (*fCam)[i];
366
367 if (bad.IsUncalibrated( MBadPixelsPix::kDeviatingTimeResolution))
368 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
369
370 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeNotFitted))
371 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
372
373 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeOscillating))
374 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
375
376 if (bad.IsUnsuitable( MBadPixelsPix::kUnsuitableRun ))
377 pix.SetExcluded();
378
379 }
380}
381
382
383// -----------------------------------------------------------------------------------------------
384//
385// - Print out statistics about BadPixels of type UnsuitableType_t
386// - store numbers of bad pixels of each type in fCam
387//
388void MCalibrationRelTimeCalc::FinalizeUnsuitablePixels()
389{
390
391 *fLog << inf << endl;
392 *fLog << GetDescriptor() << ": Rel. Times Calibration status:" << endl;
393 *fLog << dec << setfill(' ');
394
395 const Int_t nareas = fGeom->GetNumAreas();
396
397 Int_t counts[nareas];
398 memset(counts,0,nareas*sizeof(Int_t));
399
400 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
401 {
402 MBadPixelsPix &bad = (*fBadPixels)[i];
403 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
404 {
405 const Int_t aidx = (*fGeom)[i].GetAidx();
406 counts[aidx]++;
407 }
408 }
409
410 for (Int_t aidx=0; aidx<nareas; aidx++)
411 fCam->SetNumUnsuitable(counts[aidx], aidx);
412
413 if (fGeom->InheritsFrom("MGeomCamMagic"))
414 *fLog << " " << setw(7) << "Uncalibrated Pixels: "
415 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
416
417 memset(counts,0,nareas*sizeof(Int_t));
418
419 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
420 {
421 MBadPixelsPix &bad = (*fBadPixels)[i];
422 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
423 {
424 const Int_t aidx = (*fGeom)[i].GetAidx();
425 counts[aidx]++;
426 }
427 }
428
429 for (Int_t aidx=0; aidx<nareas; aidx++)
430 fCam->SetNumUnreliable(counts[aidx], aidx);
431
432 *fLog << " " << setw(7) << "Unreliable Pixels: "
433 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
434
435}
436
437// -----------------------------------------------------------------------------------------------
438//
439// Print out statistics about BadPixels of type UncalibratedType_t
440//
441void MCalibrationRelTimeCalc::PrintUncalibrated(MBadPixelsPix::UncalibratedType_t typ, const char *text) const
442{
443
444 UInt_t countinner = 0;
445 UInt_t countouter = 0;
446 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
447 {
448 MBadPixelsPix &bad = (*fBadPixels)[i];
449 if (bad.IsUncalibrated(typ))
450 {
451 if (fGeom->GetPixRatio(i) == 1.)
452 countinner++;
453 else
454 countouter++;
455 }
456 }
457
458 *fLog << " " << setw(7) << text
459 << Form("%s%3i%s%3i","Inner: ",countinner," Outer: ",countouter) << endl;
460}
461
Note: See TracBrowser for help on using the repository browser.