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

Last change on this file since 3982 was 3982, checked in by gaug, 21 years ago
*** empty log message ***
File size: 13.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 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 = 10.;
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 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 areasum2[aidx] = (areasum2[aidx] - areasum[aidx]*areasum[aidx]/numareavalid[aidx]);
343 areasum2[aidx] /= (numareavalid[aidx]-1.);
344 areasum [aidx] /= numareavalid[aidx];
345 lowlim [aidx] = 0.;
346 upplim [aidx] = areasum [aidx] + fRelTimeRelErrLimit*areasum2[aidx];
347
348 *fLog << endl;
349 *fLog << inf << GetDescriptor() << ": Limits for acceptance of time resolution: ["
350 << Form("%4.2f%s%4.2f",lowlim[aidx],",",upplim[aidx]) << "] in area index " << aidx;
351 }
352 *fLog << endl;
353
354
355 for (UInt_t i=0; i<npixels; i++)
356 {
357
358 MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[i];
359 MBadPixelsPix &bad = (*fBadPixels)[i];
360
361 if (pix.IsExcluded())
362 continue;
363
364 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
365 continue;
366
367 const Float_t res = pix.GetTimePrecision();
368 const Int_t aidx = (*fGeom)[i].GetAidx();
369
370 if ( res < lowlim[aidx] || res > upplim[aidx] )
371 {
372 *fLog << warn << GetDescriptor() << ": Deviating time resolution: "
373 << Form("%4.2f",res) << " out of accepted limits: ["
374 << Form("%4.2f%s%4.2f",lowlim[aidx],",",upplim[aidx]) << "] in pixel " << i << endl;
375 bad.SetUncalibrated( MBadPixelsPix::kDeviatingTimeResolution);
376 pix.SetExcluded();
377 }
378 }
379}
380
381
382// -----------------------------------------------------------------------------------
383//
384// Sets pixel to MBadPixelsPix::kUnsuitableRun, if one of the following flags is set:
385// - MBadPixelsPix::kRelTimeIsPedestal
386// - MBadPixelsPix::kRelTimeErrNotValid
387// - MBadPixelsPix::kRelTimeRelErrNotValid
388//
389// - Call MCalibrationPix::SetExcluded() for the bad pixels
390//
391void MCalibrationRelTimeCalc::FinalizeBadPixels()
392{
393
394 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
395 {
396
397 MBadPixelsPix &bad = (*fBadPixels)[i];
398 MCalibrationPix &pix = (*fCam)[i];
399
400 if (bad.IsUncalibrated( MBadPixelsPix::kDeviatingTimeResolution))
401 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
402
403 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeNotFitted))
404 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
405
406 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeOscillating))
407 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
408
409 if (bad.IsUnsuitable( MBadPixelsPix::kUnsuitableRun ))
410 pix.SetExcluded();
411
412 }
413}
414
415
416// -----------------------------------------------------------------------------------------------
417//
418// - Print out statistics about BadPixels of type UnsuitableType_t
419// - store numbers of bad pixels of each type in fCam
420//
421void MCalibrationRelTimeCalc::FinalizeUnsuitablePixels()
422{
423
424 *fLog << inf << endl;
425 *fLog << GetDescriptor() << ": Rel. Times Calibration status:" << endl;
426 *fLog << dec << setfill(' ');
427
428 const Int_t nareas = fGeom->GetNumAreas();
429
430 Int_t counts[nareas];
431 memset(counts,0,nareas*sizeof(Int_t));
432
433 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
434 {
435 MBadPixelsPix &bad = (*fBadPixels)[i];
436 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
437 {
438 const Int_t aidx = (*fGeom)[i].GetAidx();
439 counts[aidx]++;
440 }
441 }
442
443 for (Int_t aidx=0; aidx<nareas; aidx++)
444 fCam->SetNumUnsuitable(counts[aidx], aidx);
445
446 if (fGeom->InheritsFrom("MGeomCamMagic"))
447 *fLog << " " << setw(7) << "Uncalibrated Pixels: "
448 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
449
450 memset(counts,0,nareas*sizeof(Int_t));
451
452 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
453 {
454 MBadPixelsPix &bad = (*fBadPixels)[i];
455 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
456 {
457 const Int_t aidx = (*fGeom)[i].GetAidx();
458 counts[aidx]++;
459 }
460 }
461
462 for (Int_t aidx=0; aidx<nareas; aidx++)
463 fCam->SetNumUnreliable(counts[aidx], aidx);
464
465 *fLog << " " << setw(7) << "Unreliable Pixels: "
466 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
467
468}
469
470// -----------------------------------------------------------------------------------------------
471//
472// Print out statistics about BadPixels of type UncalibratedType_t
473//
474void MCalibrationRelTimeCalc::PrintUncalibrated(MBadPixelsPix::UncalibratedType_t typ, const char *text) const
475{
476
477 UInt_t countinner = 0;
478 UInt_t countouter = 0;
479 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
480 {
481 MBadPixelsPix &bad = (*fBadPixels)[i];
482 if (bad.IsUncalibrated(typ))
483 {
484 if (fGeom->GetPixRatio(i) == 1.)
485 countinner++;
486 else
487 countouter++;
488 }
489 }
490
491 *fLog << " " << setw(7) << text
492 << Form("%s%3i%s%3i","Inner: ",countinner," Outer: ",countouter) << endl;
493}
494
Note: See TracBrowser for help on using the repository browser.