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

Last change on this file since 3938 was 3938, checked in by gaug, 20 years ago
*** empty log message ***
File size: 13.2 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 = 15.;
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 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
295 continue;
296
297 const Float_t res = pix.GetTimePrecision();
298 const Int_t aidx = (*fGeom)[i].GetAidx();
299
300 areasum [aidx] += res;
301 areasum2 [aidx] += res*res;
302 numareavalid[aidx] ++;
303 }
304
305
306 for (UInt_t aidx=0; aidx<nareas; aidx++)
307 {
308 if (numareavalid[aidx] == 0)
309 {
310 *fLog << warn << GetDescriptor() << ": No pixels with valid time resolution found "
311 << "in area index: " << aidx << endl;
312 continue;
313 }
314
315 *fLog << err << areasum2[aidx] << " " << areasum[aidx] << " " << numareavalid[aidx] << endl;
316
317 // Calculate the rms out of sum2:
318 areasum2[aidx] = (areasum2[aidx] - areasum[aidx]*areasum[aidx]/numareavalid[aidx]);
319 areasum2[aidx] /= (numareavalid[aidx]-1.);
320 areasum [aidx] /= numareavalid[aidx];
321 lowlim [aidx] = areasum [aidx] - fRelTimeRelErrLimit*areasum2[aidx];
322 upplim [aidx] = areasum [aidx] + fRelTimeRelErrLimit*areasum2[aidx];
323 }
324
325
326
327 for (UInt_t i=0; i<npixels; i++)
328 {
329
330 MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[i];
331 MBadPixelsPix &bad = (*fBadPixels)[i];
332
333 if (pix.IsExcluded())
334 continue;
335
336 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
337 continue;
338
339 const Float_t res = pix.GetTimePrecision();
340 const Int_t aidx = (*fGeom)[i].GetAidx();
341
342 if ( res < lowlim[aidx] || res > upplim[aidx] )
343 {
344 *fLog << warn << GetDescriptor() << ": Deviating time resolution: "
345 << Form("%4.2f",res) << " out of accepted limits: ["
346 << Form("%4.2f%s%4.2f",lowlim[aidx],",",upplim[aidx]) << "] in pixel " << i << endl;
347 bad.SetUncalibrated( MBadPixelsPix::kDeviatingTimeResolution);
348 pix.SetExcluded();
349 }
350 }
351}
352
353
354// -----------------------------------------------------------------------------------
355//
356// Sets pixel to MBadPixelsPix::kUnsuitableRun, if one of the following flags is set:
357// - MBadPixelsPix::kRelTimeIsPedestal
358// - MBadPixelsPix::kRelTimeErrNotValid
359// - MBadPixelsPix::kRelTimeRelErrNotValid
360//
361// - Call MCalibrationPix::SetExcluded() for the bad pixels
362//
363void MCalibrationRelTimeCalc::FinalizeBadPixels()
364{
365
366 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
367 {
368
369 MBadPixelsPix &bad = (*fBadPixels)[i];
370 MCalibrationPix &pix = (*fCam)[i];
371
372 if (bad.IsUncalibrated( MBadPixelsPix::kDeviatingTimeResolution))
373 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
374
375 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeNotFitted))
376 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
377
378 if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeOscillating))
379 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
380
381 if (bad.IsUnsuitable( MBadPixelsPix::kUnsuitableRun ))
382 pix.SetExcluded();
383
384 }
385}
386
387
388// -----------------------------------------------------------------------------------------------
389//
390// - Print out statistics about BadPixels of type UnsuitableType_t
391// - store numbers of bad pixels of each type in fCam
392//
393void MCalibrationRelTimeCalc::FinalizeUnsuitablePixels()
394{
395
396 *fLog << inf << endl;
397 *fLog << GetDescriptor() << ": Rel. Times Calibration status:" << endl;
398 *fLog << dec << setfill(' ');
399
400 const Int_t nareas = fGeom->GetNumAreas();
401
402 Int_t counts[nareas];
403 memset(counts,0,nareas*sizeof(Int_t));
404
405 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
406 {
407 MBadPixelsPix &bad = (*fBadPixels)[i];
408 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
409 {
410 const Int_t aidx = (*fGeom)[i].GetAidx();
411 counts[aidx]++;
412 }
413 }
414
415 for (Int_t aidx=0; aidx<nareas; aidx++)
416 fCam->SetNumUnsuitable(counts[aidx], aidx);
417
418 if (fGeom->InheritsFrom("MGeomCamMagic"))
419 *fLog << " " << setw(7) << "Uncalibrated Pixels: "
420 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
421
422 memset(counts,0,nareas*sizeof(Int_t));
423
424 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
425 {
426 MBadPixelsPix &bad = (*fBadPixels)[i];
427 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
428 {
429 const Int_t aidx = (*fGeom)[i].GetAidx();
430 counts[aidx]++;
431 }
432 }
433
434 for (Int_t aidx=0; aidx<nareas; aidx++)
435 fCam->SetNumUnreliable(counts[aidx], aidx);
436
437 *fLog << " " << setw(7) << "Unreliable Pixels: "
438 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
439
440}
441
442// -----------------------------------------------------------------------------------------------
443//
444// Print out statistics about BadPixels of type UncalibratedType_t
445//
446void MCalibrationRelTimeCalc::PrintUncalibrated(MBadPixelsPix::UncalibratedType_t typ, const char *text) const
447{
448
449 UInt_t countinner = 0;
450 UInt_t countouter = 0;
451 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
452 {
453 MBadPixelsPix &bad = (*fBadPixels)[i];
454 if (bad.IsUncalibrated(typ))
455 {
456 if (fGeom->GetPixRatio(i) == 1.)
457 countinner++;
458 else
459 countouter++;
460 }
461 }
462
463 *fLog << " " << setw(7) << text
464 << Form("%s%3i%s%3i","Inner: ",countinner," Outer: ",countouter) << endl;
465}
466
Note: See TracBrowser for help on using the repository browser.