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

Last change on this file since 4127 was 4127, checked in by gaug, 20 years ago
*** empty log message ***
File size: 14.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::fgRelTimeResolutionLimit = 0.5;
75// --------------------------------------------------------------------------
76//
77// Default constructor.
78//
79// Sets all pointers to NULL
80//
81// Initializes:
82// - fRelTimeResolutionLimit to fgRelTimeResolutionimit
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 SetRelTimeResolutionLimit();
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 ",fRelTimeResolutionLimit," FADC slices 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 fRelTimeResolutionLimit FADC slices
257// 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 Int_t useunreliable[nareas];
272
273 memset(lowlim ,0, nareas * sizeof(Float_t));
274 memset(upplim ,0, nareas * sizeof(Float_t));
275 memset(areasum ,0, nareas * sizeof(Float_t));
276 // memset(areasum2 ,0, nareas * sizeof(Float_t));
277 memset(numareavalid ,0, nareas * sizeof(Int_t ));
278 memset(useunreliable ,0, nareas * sizeof(Int_t ));
279
280 //
281 // Apero loop: Count number of unreliable pixels:
282 //
283 for (UInt_t i=0; i<npixels; i++)
284 {
285 MBadPixelsPix &bad = (*fBadPixels)[i];
286 const Int_t aidx = (*fGeom)[i].GetAidx();
287
288 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
289 continue;
290
291 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
292 continue;
293
294 numareavalid[aidx] ++;
295 }
296
297 for (UInt_t aidx=0; aidx<nareas; aidx++)
298 if (numareavalid[aidx] < 100)
299 useunreliable[aidx] = 1;
300
301 memset(numareavalid ,0, nareas * sizeof(Int_t ));
302 //
303 // First loop: Get mean time resolution the RMS
304 // The loop is only to recognize later pixels with very deviating numbers
305 //
306 for (UInt_t i=0; i<npixels; i++)
307 {
308
309 MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[i];
310 MBadPixelsPix &bad = (*fBadPixels)[i];
311
312 if (pix.IsExcluded())
313 continue;
314
315 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
316 continue;
317
318 const Int_t aidx = (*fGeom)[i].GetAidx();
319
320 if (!useunreliable[aidx])
321 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
322 continue;
323
324 const Float_t res = pix.GetTimePrecision();
325
326 areasum [aidx] += res;
327 // areasum2 [aidx] += res*res;
328 numareavalid[aidx] ++;
329 }
330
331
332 for (UInt_t aidx=0; aidx<nareas; aidx++)
333 {
334 if (numareavalid[aidx] < 20)
335 {
336 *fLog << warn << GetDescriptor() << ": Less than 20 pixels with valid time resolution found "
337 << "in area index: " << aidx << endl;
338 continue;
339 }
340
341 // Calculate the rms out of sum2:
342 /*
343 areasum2[aidx] = (areasum2[aidx] - areasum[aidx]*areasum[aidx]/numareavalid[aidx]);
344 areasum2[aidx] /= (numareavalid[aidx]-1.);
345 */
346 areasum [aidx] /= numareavalid[aidx];
347 lowlim [aidx] = 0.;
348 upplim [aidx] = areasum [aidx] + fRelTimeResolutionLimit;
349
350 *fLog << endl;
351 *fLog << inf << GetDescriptor() << ": Limits for acceptance of time resolution: ["
352 << Form("%4.2f%s%4.2f",lowlim[aidx],",",upplim[aidx]) << "] in area index " << aidx;
353 }
354 *fLog << endl;
355
356
357 for (UInt_t i=0; i<npixels; i++)
358 {
359
360 MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[i];
361 MBadPixelsPix &bad = (*fBadPixels)[i];
362
363 if (pix.IsExcluded())
364 continue;
365
366 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
367 continue;
368
369 const Float_t res = pix.GetTimePrecision();
370 const Int_t aidx = (*fGeom)[i].GetAidx();
371
372 if ( res < lowlim[aidx] || res > upplim[aidx] )
373 {
374 *fLog << warn << GetDescriptor() << ": Deviating time resolution: "
375 << Form("%4.2f",res) << " out of accepted limits: ["
376 << Form("%4.2f%s%4.2f",lowlim[aidx],",",upplim[aidx]) << "] in pixel " << i << endl;
377 bad.SetUncalibrated( MBadPixelsPix::kDeviatingTimeResolution);
378 pix.SetExcluded();
379 }
380 }
381}
382
383
384// -----------------------------------------------------------------------------------
385//
386// Sets pixel to MBadPixelsPix::kUnsuitableRun, if one of the following flags is set:
387// - MBadPixelsPix::kRelTimeIsPedestal
388// - MBadPixelsPix::kRelTimeErrNotValid
389// - MBadPixelsPix::kRelTimeRelErrNotValid
390//
391// - Call MCalibrationPix::SetExcluded() for the bad pixels
392//
393void MCalibrationRelTimeCalc::FinalizeBadPixels()
394{
395
396 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
397 {
398
399 MBadPixelsPix &bad = (*fBadPixels)[i];
400 MCalibrationPix &pix = (*fCam)[i];
401
402 if (bad.IsUncalibrated( MBadPixelsPix::kDeviatingTimeResolution))
403 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
404
405 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeNotFitted))
406 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
407
408 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeOscillating))
409 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
410
411 if (bad.IsUnsuitable( MBadPixelsPix::kUnsuitableRun ))
412 pix.SetExcluded();
413
414 }
415}
416
417
418// -----------------------------------------------------------------------------------------------
419//
420// - Print out statistics about BadPixels of type UnsuitableType_t
421// - store numbers of bad pixels of each type in fCam
422//
423void MCalibrationRelTimeCalc::FinalizeUnsuitablePixels()
424{
425
426 *fLog << inf << endl;
427 *fLog << GetDescriptor() << ": Rel. Times Calibration status:" << endl;
428 *fLog << dec << setfill(' ');
429
430 const Int_t nareas = fGeom->GetNumAreas();
431
432 Int_t counts[nareas];
433 memset(counts,0,nareas*sizeof(Int_t));
434
435 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
436 {
437 MBadPixelsPix &bad = (*fBadPixels)[i];
438 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
439 {
440 const Int_t aidx = (*fGeom)[i].GetAidx();
441 counts[aidx]++;
442 }
443 }
444
445 for (Int_t aidx=0; aidx<nareas; aidx++)
446 fCam->SetNumUnsuitable(counts[aidx], aidx);
447
448 if (fGeom->InheritsFrom("MGeomCamMagic"))
449 *fLog << " " << setw(7) << "Uncalibrated Pixels: "
450 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
451
452 memset(counts,0,nareas*sizeof(Int_t));
453
454 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
455 {
456 MBadPixelsPix &bad = (*fBadPixels)[i];
457 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
458 {
459 const Int_t aidx = (*fGeom)[i].GetAidx();
460 counts[aidx]++;
461 }
462 }
463
464 for (Int_t aidx=0; aidx<nareas; aidx++)
465 fCam->SetNumUnreliable(counts[aidx], aidx);
466
467 *fLog << " " << setw(7) << "Unreliable Pixels: "
468 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
469
470}
471
472// -----------------------------------------------------------------------------------------------
473//
474// Print out statistics about BadPixels of type UncalibratedType_t
475//
476void MCalibrationRelTimeCalc::PrintUncalibrated(MBadPixelsPix::UncalibratedType_t typ, const char *text) const
477{
478
479 UInt_t countinner = 0;
480 UInt_t countouter = 0;
481 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
482 {
483 MBadPixelsPix &bad = (*fBadPixels)[i];
484 if (bad.IsUncalibrated(typ))
485 {
486 if (fGeom->GetPixRatio(i) == 1.)
487 countinner++;
488 else
489 countouter++;
490 }
491 }
492
493 *fLog << " " << setw(7) << text
494 << Form("%s%3i%s%3i","Inner: ",countinner," Outer: ",countouter) << endl;
495}
496
Note: See TracBrowser for help on using the repository browser.