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): Javier Lopez 12/2003 <mailto:jlopez@ifae.es>
|
---|
19 | ! Author(s): Javier Rico 01/2004 <mailto:jrico@ifae.es>
|
---|
20 | ! Author(s): Wolfgang Wittek 02/2004 <mailto:wittek@mppmu.mpg.de>
|
---|
21 | ! Author(s): Markus Gaug 04/2004 <mailto:markus@ifae.es>
|
---|
22 | ! Author(s): Hendrik Bartko 08/2004 <mailto:hbartko@mppmu.mpg.de>
|
---|
23 | ! Author(s): Thomas Bretz 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
24 | !
|
---|
25 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
26 | !
|
---|
27 | !
|
---|
28 | \* ======================================================================== */
|
---|
29 |
|
---|
30 | ///////////////////////////////////////////////////////////////////////////////////
|
---|
31 | //
|
---|
32 | // MCalibrateData
|
---|
33 | //
|
---|
34 | // This task takes the integrated charge from MExtractedSignal and applies
|
---|
35 | // the calibration constants from MCalibrationCam to convert the summed FADC
|
---|
36 | // slices into photons. The number of photons obtained is stored in MCerPhotEvt.
|
---|
37 | // Optionally, the calibration of pedestals from an MPedestalCam container into
|
---|
38 | // an MPedPhotCam container can be chosen with the member functions
|
---|
39 | // SetPedestalType(). Default is 'kRun', i.e. calibration of pedestals from a
|
---|
40 | // dedicated pedestal run.
|
---|
41 | // In case, the chosen pedestal type is kRun or kEvent, in ReInit() the MPedPhotCam
|
---|
42 | // container is filled using the information from MPedestalCam, MExtractedSignalCam,
|
---|
43 | // MCalibrationChargeCam and MCalibrationQECam
|
---|
44 | //
|
---|
45 | // Selection of different calibration methods is allowed through the
|
---|
46 | // SetCalibrationMode() member function (default: kFfactor)
|
---|
47 | //
|
---|
48 | // The calibration modes which exclude non-valid pixels are the following:
|
---|
49 | //
|
---|
50 | // kFfactor: calibrates using the F-Factor method
|
---|
51 | // kBlindpixel: calibrates using the BlindPixel method
|
---|
52 | // kBlindpixel: calibrates using the BlindPixel method
|
---|
53 | // kFlatCharge: perform a charge flat-flatfielding. Outer pixels are area-corrected.
|
---|
54 | // kDummy: calibrates with fixed conversion factors of 1 and errors of 0.
|
---|
55 | //
|
---|
56 | // The calibration modes which include all pixels regardless of their validity is:
|
---|
57 | //
|
---|
58 | // kNone: calibrates with fixed conversion factors of 1 and errors of 0.
|
---|
59 | //
|
---|
60 | // Use the kDummy and kNone methods ONLY FOR DEBUGGING!
|
---|
61 | //
|
---|
62 | //
|
---|
63 | // This class can calibrate data and/or pedestals. To switch off calibration of data
|
---|
64 | // set the Calibration Mode to kSkip. To switch on pedestal calibration call either
|
---|
65 | // SetPedestalFlag(MCalibrateData::kRun) (calibration is done once in ReInit)
|
---|
66 | // SetPedestalFlag(MCalibrateData::kEvent) (calibration is done for each event)
|
---|
67 | //
|
---|
68 | // By calling AddPedestal() you can control the name of the
|
---|
69 | // MPedestalCam and/or MPedPhotCam container which is used.
|
---|
70 | //
|
---|
71 | // Assume you want to calibrate "MPedestalCam" once and "MPedestalFromLoGain" [MPedestalCam]
|
---|
72 | // event-by-event, so:
|
---|
73 | // MCalibrateData cal1;
|
---|
74 | // cal1.SetCalibrationMode(MCalibrateData::kSkip);
|
---|
75 | // cal1.SetPedestalFlag(MCalibrateData::kRun);
|
---|
76 | // MCalibrateData cal2;
|
---|
77 | // cal2.SetCalibrationMode(MCalibrateData::kSkip);
|
---|
78 | // cal2.AddPedestal("FromLoGain");
|
---|
79 | // cal2.SetPedestalFlag(MCalibrateData::kEvent);
|
---|
80 | //
|
---|
81 | //
|
---|
82 | // Input Containers:
|
---|
83 | // [MPedestalCam]
|
---|
84 | // [MExtractedSignalCam]
|
---|
85 | // [MCalibrationChargeCam]
|
---|
86 | // [MCalibrationQECam]
|
---|
87 | // MBadPixelsCam
|
---|
88 | //
|
---|
89 | // Output Containers:
|
---|
90 | // [MPedPhotCam]
|
---|
91 | // [MCerPhotEvt]
|
---|
92 | //
|
---|
93 | // See also: MJCalibration, MJPedestal, MJExtractSignal, MJExtractCalibTest
|
---|
94 | //
|
---|
95 | //////////////////////////////////////////////////////////////////////////////
|
---|
96 | #include "MCalibrateData.h"
|
---|
97 |
|
---|
98 | #include <fstream>
|
---|
99 |
|
---|
100 | #include <TEnv.h>
|
---|
101 |
|
---|
102 | #include "MLog.h"
|
---|
103 | #include "MLogManip.h"
|
---|
104 |
|
---|
105 | #include "MParList.h"
|
---|
106 | #include "MH.h"
|
---|
107 |
|
---|
108 | #include "MGeomCam.h"
|
---|
109 |
|
---|
110 | #include "MPedestalCam.h"
|
---|
111 | #include "MPedestalPix.h"
|
---|
112 |
|
---|
113 | #include "MCalibrationChargeCam.h"
|
---|
114 | #include "MCalibrationChargePix.h"
|
---|
115 |
|
---|
116 | #include "MCalibrationQECam.h"
|
---|
117 | #include "MCalibrationQEPix.h"
|
---|
118 |
|
---|
119 | #include "MCalibConstCam.h"
|
---|
120 | #include "MCalibConstPix.h"
|
---|
121 |
|
---|
122 | #include "MExtractedSignalCam.h"
|
---|
123 | #include "MExtractedSignalPix.h"
|
---|
124 |
|
---|
125 | #include "MPedPhotCam.h"
|
---|
126 | #include "MPedPhotPix.h"
|
---|
127 |
|
---|
128 | #include "MBadPixelsCam.h"
|
---|
129 | #include "MBadPixelsPix.h"
|
---|
130 |
|
---|
131 | #include "MCerPhotEvt.h"
|
---|
132 |
|
---|
133 | ClassImp(MCalibrateData);
|
---|
134 |
|
---|
135 | using namespace std;
|
---|
136 |
|
---|
137 | const Float_t MCalibrateData::fgCalibConvMinLimit = 0.01;
|
---|
138 | const Float_t MCalibrateData::fgCalibConvMaxLimit = 5.;
|
---|
139 | // --------------------------------------------------------------------------
|
---|
140 | //
|
---|
141 | // Default constructor.
|
---|
142 | //
|
---|
143 | // Sets all pointers to NULL
|
---|
144 | //
|
---|
145 | // Initializes:
|
---|
146 | // - fCalibrationMode to kDefault
|
---|
147 | // - fPedestalFlag to kNo
|
---|
148 | //
|
---|
149 | MCalibrateData::MCalibrateData(CalibrationMode_t calmode,const char *name, const char *title)
|
---|
150 | : fGeomCam(NULL), fBadPixels(NULL), fCalibrations(NULL),
|
---|
151 | fQEs(NULL), fSignals(NULL), fCerPhotEvt(NULL), fCalibConstCam(NULL),
|
---|
152 | fPedestalFlag(kNo), fSignalType(kPhot), fRenormFactor(1.)
|
---|
153 | {
|
---|
154 |
|
---|
155 | fName = name ? name : "MCalibrateData";
|
---|
156 | fTitle = title ? title : "Task to calculate the number of photons in one event";
|
---|
157 |
|
---|
158 | SetCalibrationMode(calmode);
|
---|
159 |
|
---|
160 | SetCalibConvMinLimit();
|
---|
161 | SetCalibConvMaxLimit();
|
---|
162 |
|
---|
163 | fNamesPedestal.SetOwner();
|
---|
164 | }
|
---|
165 |
|
---|
166 | void MCalibrateData::AddPedestal(const char *name)
|
---|
167 | {
|
---|
168 | TString ped(name);
|
---|
169 | TString pho(name);
|
---|
170 | ped.Prepend("MPedestal");
|
---|
171 | pho.Prepend("MPedPhot");
|
---|
172 |
|
---|
173 | fNamesPedestal.Add(new TNamed(ped, pho));
|
---|
174 | }
|
---|
175 |
|
---|
176 | void MCalibrateData::AddPedestal(const char *pedestal, const char *pedphot)
|
---|
177 | {
|
---|
178 | fNamesPedestal.Add(new TNamed(pedestal, pedphot));
|
---|
179 | }
|
---|
180 |
|
---|
181 | // --------------------------------------------------------------------------
|
---|
182 | //
|
---|
183 | // The PreProcess searches for the following input containers:
|
---|
184 | //
|
---|
185 | // - MGeomCam
|
---|
186 | // - MPedestalCam
|
---|
187 | // - MCalibrationChargeCam
|
---|
188 | // - MCalibrationQECam
|
---|
189 | // - MExtractedSignalCam
|
---|
190 | // - MBadPixelsCam
|
---|
191 | //
|
---|
192 | // The following output containers are also searched and created if
|
---|
193 | // they were not found:
|
---|
194 | //
|
---|
195 | // - MPedPhotCam
|
---|
196 | // - MCerPhotEvt
|
---|
197 | //
|
---|
198 | Int_t MCalibrateData::PreProcess(MParList *pList)
|
---|
199 | {
|
---|
200 | // input containers
|
---|
201 |
|
---|
202 | fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
|
---|
203 | if (!fBadPixels)
|
---|
204 | {
|
---|
205 | *fLog << err << AddSerialNumber("MBadPixelsCam") << " not found ... aborting" << endl;
|
---|
206 | return kFALSE;
|
---|
207 | }
|
---|
208 |
|
---|
209 | fSignals = 0;
|
---|
210 | fCerPhotEvt = 0;
|
---|
211 | if (fCalibrationMode>kSkip)
|
---|
212 | {
|
---|
213 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
---|
214 | if (!fSignals)
|
---|
215 | {
|
---|
216 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
---|
217 | return kFALSE;
|
---|
218 | }
|
---|
219 |
|
---|
220 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
---|
221 | if (!fCerPhotEvt)
|
---|
222 | return kFALSE;
|
---|
223 |
|
---|
224 | fCalibConstCam = (MCalibConstCam*)pList->FindCreateObj(AddSerialNumber("MCalibConstCam"));
|
---|
225 | if (!fCalibConstCam)
|
---|
226 | return kFALSE;
|
---|
227 | }
|
---|
228 |
|
---|
229 | fCalibrations = 0;
|
---|
230 | fQEs = 0;
|
---|
231 | if (fCalibrationMode>kNone)
|
---|
232 | {
|
---|
233 | fCalibrations = (MCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
---|
234 | if (!fCalibrations)
|
---|
235 | {
|
---|
236 | *fLog << err << AddSerialNumber("MCalibrationChargeCam") << " not found ... aborting." << endl;
|
---|
237 | return kFALSE;
|
---|
238 | }
|
---|
239 |
|
---|
240 | fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
|
---|
241 | if (!fQEs)
|
---|
242 | {
|
---|
243 | *fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
|
---|
244 | return kFALSE;
|
---|
245 | }
|
---|
246 |
|
---|
247 | }
|
---|
248 |
|
---|
249 | if (fNamesPedestal.GetSize()>0 && fPedestalFlag==kNo)
|
---|
250 | {
|
---|
251 | *fLog << warn << "Pedestal list contains entries, but mode is set to kNo... setting to kEvent." << endl;
|
---|
252 | fPedestalFlag = kEvent;
|
---|
253 | }
|
---|
254 |
|
---|
255 | if (fPedestalFlag)
|
---|
256 | {
|
---|
257 | if (fNamesPedestal.GetSize()==0)
|
---|
258 | {
|
---|
259 | *fLog << inf << "No container names specified... using default: MPedestalCam and MPedPhotCam." << endl;
|
---|
260 | AddPedestal();
|
---|
261 | }
|
---|
262 |
|
---|
263 | fPedestalCams.Clear();
|
---|
264 | fPedPhotCams.Clear();
|
---|
265 |
|
---|
266 | TIter Next(&fNamesPedestal);
|
---|
267 | TObject *o=0;
|
---|
268 | while ((o=Next()))
|
---|
269 | {
|
---|
270 | TObject *pedcam = pList->FindObject(AddSerialNumber(o->GetName()), "MPedestalCam");
|
---|
271 | if (!pedcam)
|
---|
272 | {
|
---|
273 | *fLog << err << AddSerialNumber(o->GetName()) << " [MPedestalCam] not found ... aborting" << endl;
|
---|
274 | return kFALSE;
|
---|
275 | }
|
---|
276 | TObject *pedphot = pList->FindCreateObj("MPedPhotCam", AddSerialNumber(o->GetTitle()));
|
---|
277 | if (!pedphot)
|
---|
278 | return kFALSE;
|
---|
279 |
|
---|
280 | fPedestalCams.Add(pedcam);
|
---|
281 | fPedPhotCams.Add(pedphot);
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | switch (fSignalType)
|
---|
286 | {
|
---|
287 | case kPhe:
|
---|
288 | fRenormFactor = MCalibrationQEPix::gkDefaultAverageQE;
|
---|
289 | break;
|
---|
290 | case kPhot:
|
---|
291 | fRenormFactor = 1.;
|
---|
292 | break;
|
---|
293 | }
|
---|
294 |
|
---|
295 | fCalibConsts.Reset();
|
---|
296 | fCalibFFactors.Reset();
|
---|
297 | fHiLoConv.Reset();
|
---|
298 | fHiLoConvErr.Reset();
|
---|
299 |
|
---|
300 | return kTRUE;
|
---|
301 | }
|
---|
302 |
|
---|
303 | // --------------------------------------------------------------------------
|
---|
304 | //
|
---|
305 | // The ReInit searches for the following input containers:
|
---|
306 | //
|
---|
307 | // - MGeomCam
|
---|
308 | //
|
---|
309 | // Check for validity of the selected calibration method, switch to a
|
---|
310 | // different one in case of need
|
---|
311 | //
|
---|
312 | // Fill the MPedPhotCam container using the information from MPedestalCam,
|
---|
313 | // MExtractedSignalCam and MCalibrationCam
|
---|
314 | //
|
---|
315 | Bool_t MCalibrateData::ReInit(MParList *pList)
|
---|
316 | {
|
---|
317 | fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
318 | if (!fGeomCam)
|
---|
319 | {
|
---|
320 | *fLog << err << "No MGeomCam found... aborting." << endl;
|
---|
321 | return kFALSE;
|
---|
322 | }
|
---|
323 |
|
---|
324 | // Sizes might have changed
|
---|
325 | if (fPedestalFlag)
|
---|
326 | {
|
---|
327 | TIter Next(&fPedestalCams);
|
---|
328 | MPedestalCam *cam=0;
|
---|
329 | while ((cam=(MPedestalCam*)Next()))
|
---|
330 | if ((Int_t)cam->GetSize() != fSignals->GetSize())
|
---|
331 | {
|
---|
332 | *fLog << err << "Size mismatch of " << cam->GetDescriptor() << " and MCalibrationCam... abort." << endl;
|
---|
333 | return kFALSE;
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | if(fCalibrationMode == kBlindPixel && !fQEs->IsBlindPixelMethodValid())
|
---|
338 | {
|
---|
339 | *fLog << warn << "Blind pixel calibration method not valid, switching to F-factor method" << endl;
|
---|
340 | fCalibrationMode = kFfactor;
|
---|
341 | }
|
---|
342 |
|
---|
343 | if(fCalibrationMode == kPinDiode && !fQEs->IsPINDiodeMethodValid())
|
---|
344 | {
|
---|
345 | *fLog << warn << "PIN diode calibration method not valid, switching to F-factor method" << endl;
|
---|
346 | fCalibrationMode = kFfactor;
|
---|
347 | }
|
---|
348 |
|
---|
349 | if(fCalibrationMode == kCombined && !fQEs->IsCombinedMethodValid())
|
---|
350 | {
|
---|
351 | *fLog << warn << "Combined calibration method not valid, switching to F-factor method" << endl;
|
---|
352 | fCalibrationMode = kFfactor;
|
---|
353 | }
|
---|
354 |
|
---|
355 | //
|
---|
356 | // output information or warnings:
|
---|
357 | //
|
---|
358 | switch(fCalibrationMode)
|
---|
359 | {
|
---|
360 | case kBlindPixel:
|
---|
361 | break;
|
---|
362 | case kFfactor:
|
---|
363 | break;
|
---|
364 | case kPinDiode:
|
---|
365 | *fLog << err << "PIN Diode Calibration mode not yet available!" << endl;
|
---|
366 | return kFALSE;
|
---|
367 | break;
|
---|
368 | case kCombined:
|
---|
369 | *fLog << err << "Combined Calibration mode not yet available!" << endl;
|
---|
370 | return kFALSE;
|
---|
371 | break;
|
---|
372 | case kFlatCharge:
|
---|
373 | *fLog << warn << "WARNING - Flat-fielding charges - only for muon calibration!" << endl;
|
---|
374 | break;
|
---|
375 | case kDummy:
|
---|
376 | *fLog << warn << "WARNING - Dummy calibration, no calibration applied!" << endl;
|
---|
377 | break;
|
---|
378 | case kNone:
|
---|
379 | *fLog << warn << "WARNING - No calibration applied!" << endl;
|
---|
380 | break;
|
---|
381 | default:
|
---|
382 | *fLog << warn << "WARNING - Calibration mode value (" << fCalibrationMode << ") not known" << endl;
|
---|
383 | return kFALSE;
|
---|
384 | }
|
---|
385 |
|
---|
386 | //
|
---|
387 | // output information or warnings:
|
---|
388 | //
|
---|
389 | switch(fSignalType)
|
---|
390 | {
|
---|
391 | case kPhe:
|
---|
392 | *fLog << warn << "WARNING - Renormalization to photo-electrons applied!" << endl;
|
---|
393 | break;
|
---|
394 | case kPhot:
|
---|
395 | break;
|
---|
396 | }
|
---|
397 |
|
---|
398 | const Int_t npixels = fGeomCam->GetNumPixels();
|
---|
399 |
|
---|
400 | if (fCalibrationMode > kNone)
|
---|
401 | {
|
---|
402 |
|
---|
403 | if (fCalibrations->GetSize() != npixels)
|
---|
404 | {
|
---|
405 | *fLog << err << GetDescriptor()
|
---|
406 | << ": Size mismatch between MGeomCam and MCalibrationChargeCam ... abort!" << endl;
|
---|
407 | return kFALSE;
|
---|
408 | }
|
---|
409 |
|
---|
410 | if (fBadPixels->GetSize() != npixels)
|
---|
411 | {
|
---|
412 | *fLog << err << GetDescriptor()
|
---|
413 | << ": Size mismatch between MGeomCam and MBadPixelsCam ... abort!" << endl;
|
---|
414 | return kFALSE;
|
---|
415 | }
|
---|
416 |
|
---|
417 | if (fBadPixels->GetSize() != npixels)
|
---|
418 | {
|
---|
419 | *fLog << err << GetDescriptor()
|
---|
420 | << ": Size mismatch between MGeomCam and MBadPixelsCam ... abort!" << endl;
|
---|
421 | return kFALSE;
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | fCalibConsts .Set(npixels);
|
---|
426 | fCalibFFactors.Set(npixels);
|
---|
427 | fHiLoConv .Set(npixels);
|
---|
428 | fHiLoConvErr .Set(npixels);
|
---|
429 |
|
---|
430 | if (!UpdateConversionFactors())
|
---|
431 | return kFALSE;
|
---|
432 |
|
---|
433 | if (TestPedestalFlag(kRun))
|
---|
434 | Calibrate(kFALSE, kTRUE);
|
---|
435 |
|
---|
436 | return kTRUE;
|
---|
437 | }
|
---|
438 |
|
---|
439 | // --------------------------------------------------------------------------
|
---|
440 | //
|
---|
441 | // Update the conversion factors and F-Factors from MCalibrationCams into
|
---|
442 | // the arrays. Later, the here pre-calcualted conversion factors get simply
|
---|
443 | // copied from memory.
|
---|
444 | //
|
---|
445 | // This function can be called from outside in case that the MCalibrationCams
|
---|
446 | // have been updated...
|
---|
447 | //
|
---|
448 | Bool_t MCalibrateData::UpdateConversionFactors( const MCalibrationChargeCam *updatecam)
|
---|
449 | {
|
---|
450 |
|
---|
451 | *fLog << inf << GetDescriptor()
|
---|
452 | << ": Updating Conversion Factors... " << endl;
|
---|
453 |
|
---|
454 | fCalibConsts.Reset();
|
---|
455 | fCalibFFactors.Reset();
|
---|
456 | fHiLoConv.Reset();
|
---|
457 | fHiLoConvErr.Reset();
|
---|
458 |
|
---|
459 | //
|
---|
460 | // For the moment, we use only a dummy zenith for the calibration:
|
---|
461 | //
|
---|
462 | const Float_t zenith = -1.;
|
---|
463 |
|
---|
464 | UInt_t skip = 0;
|
---|
465 |
|
---|
466 | for (UInt_t pixidx=0; pixidx<fGeomCam->GetNumPixels(); pixidx++)
|
---|
467 | {
|
---|
468 |
|
---|
469 | Float_t hiloconv = 1.;
|
---|
470 | Float_t hiloconverr = 0.;
|
---|
471 | Float_t calibConv = 1.;
|
---|
472 | Float_t calibConvVar = 0.;
|
---|
473 | Float_t calibFFactor = 0.;
|
---|
474 |
|
---|
475 | Float_t calibQE = 1.;
|
---|
476 | Float_t calibQEVar = 0.;
|
---|
477 |
|
---|
478 | Float_t calibUpdate = 1.;
|
---|
479 |
|
---|
480 | MCalibConstPix &cpix = (*fCalibConstCam)[pixidx];
|
---|
481 |
|
---|
482 | if(fCalibrationMode!=kNone)
|
---|
483 | {
|
---|
484 | if ((*fBadPixels)[pixidx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
|
---|
485 | {
|
---|
486 | skip++;
|
---|
487 | calibConv = -1.;
|
---|
488 | continue;
|
---|
489 | }
|
---|
490 |
|
---|
491 | MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCalibrations)[pixidx];
|
---|
492 | MCalibrationChargePix &avpix = (MCalibrationChargePix&)fCalibrations->GetAverageArea(0);
|
---|
493 |
|
---|
494 | hiloconv = pix.GetConversionHiLo ();
|
---|
495 | hiloconverr= pix.GetConversionHiLoErr();
|
---|
496 |
|
---|
497 | calibConv = pix.GetMeanConvFADC2Phe();
|
---|
498 | calibConvVar = pix.GetMeanConvFADC2PheVar();
|
---|
499 | calibFFactor = pix.GetMeanFFactorFADC2Phot();
|
---|
500 |
|
---|
501 | MCalibrationQEPix &qe = (MCalibrationQEPix&) (*fQEs)[pixidx];
|
---|
502 |
|
---|
503 | if (updatecam)
|
---|
504 | {
|
---|
505 | MCalibrationChargePix &upix = (MCalibrationChargePix&)(*updatecam)[pixidx];
|
---|
506 | //
|
---|
507 | // Correct for the possible change in amplification of the individual pixels chain
|
---|
508 | //
|
---|
509 | const Float_t pixmean = upix.GetConvertedMean();
|
---|
510 | calibUpdate = (pixmean == 0.) ? 1. : pix.GetConvertedMean() / pixmean;
|
---|
511 | //
|
---|
512 | // Correct for global shifts in light emission
|
---|
513 | //
|
---|
514 | MCalibrationChargePix &ugpix = (MCalibrationChargePix&)updatecam->GetAverageArea(0);
|
---|
515 |
|
---|
516 | const Float_t globmean = avpix.GetConvertedMean();
|
---|
517 | calibUpdate = (globmean == 0.) ? 1. : ugpix.GetConvertedMean() / globmean;
|
---|
518 |
|
---|
519 | MBadPixelsPix &ubad = (MBadPixelsPix&) updatecam->GetAverageBadArea(0);
|
---|
520 | if (ubad.IsUncalibrated(MBadPixelsPix::kChargeIsPedestal))
|
---|
521 | {
|
---|
522 | *fLog << warn << GetDescriptor() << "Probably calibration pulses have been lost!!!!" << endl;
|
---|
523 | *fLog << warn << "Will not update calib. factors any more!!!!" << endl;
|
---|
524 | calibUpdate = 1.;
|
---|
525 | }
|
---|
526 | }
|
---|
527 |
|
---|
528 | switch(fCalibrationMode)
|
---|
529 | {
|
---|
530 | case kFlatCharge:
|
---|
531 | {
|
---|
532 | calibConv = avpix.GetConvertedMean()
|
---|
533 | / (pix.GetConvertedMean() * fGeomCam->GetPixRatio(pixidx));
|
---|
534 | calibConvVar = (avpix.GetMeanRelVar() + pix.GetMeanRelVar()) * calibConv * calibConv;
|
---|
535 | if (pix.IsFFactorMethodValid())
|
---|
536 | {
|
---|
537 | const Float_t convmin1 = qe.GetQECascadesFFactor(zenith)/pix.GetMeanConvFADC2Phe();
|
---|
538 | if (convmin1 > 0)
|
---|
539 | calibFFactor *= TMath::Sqrt(convmin1);
|
---|
540 | else
|
---|
541 | calibFFactor = -1.;
|
---|
542 | }
|
---|
543 | break;
|
---|
544 | }
|
---|
545 | case kBlindPixel:
|
---|
546 | if (!qe.IsBlindPixelMethodValid())
|
---|
547 | {
|
---|
548 | skip++;
|
---|
549 | continue;
|
---|
550 | }
|
---|
551 | calibQE = qe.GetQECascadesBlindPixel ( zenith );
|
---|
552 | calibQEVar = qe.GetQECascadesBlindPixelVar( zenith );
|
---|
553 | break;
|
---|
554 |
|
---|
555 | case kPinDiode:
|
---|
556 | if (!qe.IsPINDiodeMethodValid())
|
---|
557 | {
|
---|
558 | skip++;
|
---|
559 | continue;
|
---|
560 | }
|
---|
561 | calibQE = qe.GetQECascadesPINDiode ( zenith );
|
---|
562 | calibQEVar = qe.GetQECascadesPINDiodeVar( zenith );
|
---|
563 | break;
|
---|
564 |
|
---|
565 | case kFfactor:
|
---|
566 | if (!pix.IsFFactorMethodValid())
|
---|
567 | {
|
---|
568 | skip++;
|
---|
569 | continue;
|
---|
570 | }
|
---|
571 | calibQE = qe.GetQECascadesFFactor ( zenith );
|
---|
572 | calibQEVar = qe.GetQECascadesFFactorVar( zenith );
|
---|
573 | break;
|
---|
574 |
|
---|
575 | case kCombined:
|
---|
576 | if (!qe.IsCombinedMethodValid())
|
---|
577 | {
|
---|
578 | skip++;
|
---|
579 | continue;
|
---|
580 | }
|
---|
581 | calibQE = qe.GetQECascadesCombined ( zenith );
|
---|
582 | calibQEVar = qe.GetQECascadesCombinedVar( zenith );
|
---|
583 | break;
|
---|
584 |
|
---|
585 | case kDummy:
|
---|
586 | hiloconv = 1.;
|
---|
587 | hiloconverr = 0.;
|
---|
588 | calibUpdate = 1.;
|
---|
589 | break;
|
---|
590 | } /* switch calibration mode */
|
---|
591 | } /* if(fCalibrationMode!=kNone) */
|
---|
592 | else
|
---|
593 | {
|
---|
594 | calibConv = 1./fGeomCam->GetPixRatio(pixidx);
|
---|
595 | }
|
---|
596 |
|
---|
597 | calibConv /= calibQE;
|
---|
598 |
|
---|
599 | if (calibConv != 0. && calibQE != 0.)
|
---|
600 | {
|
---|
601 | // Now doing:
|
---|
602 | calibConvVar = calibConvVar/(calibConv*calibConv) + calibQEVar/(calibQE*calibQE);
|
---|
603 | calibConvVar *= (calibConv*calibConv);
|
---|
604 | // The above two lines had been commented by TB and replaced by the following line
|
---|
605 | // (without notice to me!) but it is simply wrong!
|
---|
606 | // calibConvVar += calibQEVar*(calibConv*calibConv)/(calibQE*calibQE);
|
---|
607 | }
|
---|
608 |
|
---|
609 | calibConv *= fRenormFactor * calibUpdate;
|
---|
610 | calibFFactor *= TMath::Sqrt(fRenormFactor);
|
---|
611 |
|
---|
612 | fHiLoConv [pixidx] = hiloconv;
|
---|
613 | fHiLoConvErr [pixidx] = hiloconverr;
|
---|
614 | fCalibConsts [pixidx] = calibConv;
|
---|
615 | fCalibFFactors[pixidx] = calibFFactor;
|
---|
616 |
|
---|
617 | if (calibConv < fCalibConvMinLimit || calibConv > fCalibConvMaxLimit)
|
---|
618 | {
|
---|
619 | (*fBadPixels)[pixidx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
|
---|
620 | calibConv = -1.;
|
---|
621 | calibFFactor = -1.;
|
---|
622 | }
|
---|
623 | cpix.SetCalibConst(calibConv);
|
---|
624 | cpix.SetCalibFFactor(calibFFactor);
|
---|
625 |
|
---|
626 | } /* for (Int_t pixidx=0; pixidx<fGeomCam->GetNumPixels(); pixidx++) */
|
---|
627 |
|
---|
628 | if (skip>fGeomCam->GetNumPixels()*0.9)
|
---|
629 | {
|
---|
630 | *fLog << warn << GetDescriptor()
|
---|
631 | << ": WARNING - GetConversionFactor has skipped more than 90% of the pixels... abort." << endl;
|
---|
632 | return kFALSE;
|
---|
633 | }
|
---|
634 |
|
---|
635 |
|
---|
636 |
|
---|
637 | // Print();
|
---|
638 |
|
---|
639 | return kTRUE;
|
---|
640 | }
|
---|
641 |
|
---|
642 |
|
---|
643 | // --------------------------------------------------------------------------
|
---|
644 | //
|
---|
645 | // Apply the conversion factors and F-Factors from the arrays to the data.
|
---|
646 | //
|
---|
647 | // The flags 'data' and 'pedestal' decide whether the signal and/or the pedetals
|
---|
648 | // shall be calibrated, respectively.
|
---|
649 | //
|
---|
650 | Int_t MCalibrateData::Calibrate(Bool_t data, Bool_t pedestal) const
|
---|
651 | {
|
---|
652 | if (!data && !pedestal)
|
---|
653 | return kTRUE;
|
---|
654 |
|
---|
655 | const UInt_t npix = fSignals->GetSize();
|
---|
656 | const Float_t slices = fSignals->GetNumUsedHiGainFADCSlices();
|
---|
657 | const Float_t sqrtslices = TMath::Sqrt(slices);
|
---|
658 |
|
---|
659 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
---|
660 | {
|
---|
661 |
|
---|
662 | if (data)
|
---|
663 | {
|
---|
664 | const MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
---|
665 |
|
---|
666 | Float_t signal = 0.;
|
---|
667 | Float_t signalErr = 0.;
|
---|
668 |
|
---|
669 | if (sig.IsLoGainUsed())
|
---|
670 | {
|
---|
671 | if (fHiLoConv[pixidx] < 0.5)
|
---|
672 | {
|
---|
673 | signal = sig.GetExtractedSignalHiGain()*1.5;
|
---|
674 | signalErr = sig.GetExtractedSignalHiGain()*0.5;
|
---|
675 | }
|
---|
676 | else
|
---|
677 | {
|
---|
678 | const Float_t siglo = sig.GetExtractedSignalLoGain();
|
---|
679 |
|
---|
680 | if (siglo > 0.1) // low-gain signal has been extracted successfully
|
---|
681 | {
|
---|
682 | signal = siglo*fHiLoConv [pixidx];
|
---|
683 | signalErr = siglo*fHiLoConvErr[pixidx];
|
---|
684 | }
|
---|
685 | else // low-gain signal has not been extracted successfully, get a rough estimate from the high-gain
|
---|
686 | {
|
---|
687 | signal = sig.GetExtractedSignalHiGain()*1.5;
|
---|
688 | signalErr = sig.GetExtractedSignalHiGain()*0.5;
|
---|
689 | }
|
---|
690 | }
|
---|
691 | }
|
---|
692 | else
|
---|
693 | {
|
---|
694 | if (sig.GetExtractedSignalHiGain() <= 9999.)
|
---|
695 | signal = sig.GetExtractedSignalHiGain();
|
---|
696 | }
|
---|
697 |
|
---|
698 | const Float_t nphot = signal * fCalibConsts [pixidx];
|
---|
699 | const Float_t nphotErr = TMath::Sqrt(TMath::Abs(nphot)) * fCalibFFactors[pixidx];
|
---|
700 |
|
---|
701 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
---|
702 |
|
---|
703 | if (sig.GetNumHiGainSaturated() > 0)
|
---|
704 | cpix->SetPixelHGSaturated();
|
---|
705 |
|
---|
706 | if (sig.GetNumLoGainSaturated() > 0)
|
---|
707 | cpix->SetPixelSaturated();
|
---|
708 | } /* if (data) */
|
---|
709 |
|
---|
710 |
|
---|
711 | if (pedestal)
|
---|
712 | {
|
---|
713 | TIter NextPed(&fPedestalCams);
|
---|
714 | TIter NextPhot(&fPedPhotCams);
|
---|
715 |
|
---|
716 | MPedestalCam *pedestal = 0;
|
---|
717 | MPedPhotCam *pedphot = 0;
|
---|
718 |
|
---|
719 | const Float_t pedmeancalib = slices *fCalibConsts[pixidx];
|
---|
720 | const Float_t pedrmscalib = sqrtslices*fCalibConsts[pixidx];
|
---|
721 |
|
---|
722 | while ((pedestal=(MPedestalCam*)NextPed()) &&
|
---|
723 | (pedphot =(MPedPhotCam*)NextPhot()))
|
---|
724 | {
|
---|
725 | // pedestals/(used FADC slices) in [number of photons]
|
---|
726 | const Float_t mean = (*pedestal)[pixidx].GetPedestal() *pedmeancalib;
|
---|
727 | const Float_t rms = (*pedestal)[pixidx].GetPedestalRms()*pedrmscalib;
|
---|
728 |
|
---|
729 | (*pedphot)[pixidx].Set(mean, rms);
|
---|
730 | pedphot->SetReadyToSave();
|
---|
731 | }
|
---|
732 | } /* if (pedestal) */
|
---|
733 | }
|
---|
734 |
|
---|
735 | if (data)
|
---|
736 | {
|
---|
737 | fCerPhotEvt->FixSize();
|
---|
738 | fCerPhotEvt->SetReadyToSave();
|
---|
739 | }
|
---|
740 | return kTRUE;
|
---|
741 | }
|
---|
742 |
|
---|
743 | // --------------------------------------------------------------------------
|
---|
744 | //
|
---|
745 | // Apply the calibration factors to the extracted signal according to the
|
---|
746 | // selected calibration method
|
---|
747 | //
|
---|
748 | Int_t MCalibrateData::Process()
|
---|
749 | {
|
---|
750 | return Calibrate(fCalibrationMode!=kSkip, TestPedestalFlag(kEvent));
|
---|
751 | }
|
---|
752 |
|
---|
753 | // --------------------------------------------------------------------------
|
---|
754 | //
|
---|
755 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
756 | // to a macro. In the original root implementation it is used to write
|
---|
757 | // gui elements to a macro-file.
|
---|
758 | //
|
---|
759 | void MCalibrateData::StreamPrimitive(ofstream &out) const
|
---|
760 | {
|
---|
761 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
762 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
763 |
|
---|
764 | if (TestPedestalFlag(kEvent))
|
---|
765 | out << " " << GetUniqueName() << ".EnablePedestalType(MCalibrateData::kEvent)" << endl;
|
---|
766 | if (TestPedestalFlag(kRun))
|
---|
767 | out << " " << GetUniqueName() << ".EnablePedestalType(MCalibrateData::kRun)" << endl;
|
---|
768 |
|
---|
769 | if (fCalibrationMode != kDefault)
|
---|
770 | {
|
---|
771 | out << " " << GetUniqueName() << ".SetCalibrationMode(MCalibrateData::";
|
---|
772 | switch (fCalibrationMode)
|
---|
773 | {
|
---|
774 | case kSkip: out << "kSkip"; break;
|
---|
775 | case kNone: out << "kNone"; break;
|
---|
776 | case kFlatCharge: out << "kFlatCharge"; break;
|
---|
777 | case kBlindPixel: out << "kBlindPixel"; break;
|
---|
778 | case kFfactor: out << "kFfactor"; break;
|
---|
779 | case kPinDiode: out << "kPinDiode"; break;
|
---|
780 | case kCombined: out << "kCombined"; break;
|
---|
781 | case kDummy: out << "kDummy"; break;
|
---|
782 | default: out << (int)fCalibrationMode; break;
|
---|
783 | }
|
---|
784 | out << ")" << endl;
|
---|
785 | }
|
---|
786 |
|
---|
787 | TIter Next(&fNamesPedestal);
|
---|
788 | TObject *o=0;
|
---|
789 | while ((o=Next()))
|
---|
790 | {
|
---|
791 | out << " " << GetUniqueName() << ".AddPedestal(\"";
|
---|
792 | out << o->GetName() << "\", \"" << o->GetTitle() << "\");" << endl;
|
---|
793 | }
|
---|
794 | }
|
---|
795 |
|
---|
796 | // --------------------------------------------------------------------------
|
---|
797 | //
|
---|
798 | // Read the setup from a TEnv, eg:
|
---|
799 | // MJPedestal.MCalibrateDate.PedestalFlag: no,run,event
|
---|
800 | // MJPedestal.MCalibrateDate.CalibrationMode: skip,none,flatcharge,blindpixel,ffactor,pindiode,combined,dummy,default
|
---|
801 | //
|
---|
802 | Int_t MCalibrateData::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
803 | {
|
---|
804 | Bool_t rc = kFALSE;
|
---|
805 | if (IsEnvDefined(env, prefix, "PedestalFlag", print))
|
---|
806 | {
|
---|
807 | rc = kTRUE;
|
---|
808 | TString s = GetEnvValue(env, prefix, "PedestalFlag", "");
|
---|
809 | s.ToLower();
|
---|
810 | if (s.BeginsWith("no"))
|
---|
811 | SetPedestalFlag(kNo);
|
---|
812 | if (s.BeginsWith("run"))
|
---|
813 | SetPedestalFlag(kRun);
|
---|
814 | if (s.BeginsWith("event"))
|
---|
815 | SetPedestalFlag(kEvent);
|
---|
816 | }
|
---|
817 |
|
---|
818 | if (IsEnvDefined(env, prefix, "CalibrationMode", print))
|
---|
819 | {
|
---|
820 | rc = kTRUE;
|
---|
821 | TString s = GetEnvValue(env, prefix, "CalibrationMode", "");
|
---|
822 | s.ToLower();
|
---|
823 | if (s.BeginsWith("skip"))
|
---|
824 | SetCalibrationMode(kSkip);
|
---|
825 | if (s.BeginsWith("none"))
|
---|
826 | SetCalibrationMode(kNone);
|
---|
827 | if (s.BeginsWith("flatcharge"))
|
---|
828 | SetCalibrationMode(kFlatCharge);
|
---|
829 | if (s.BeginsWith("blindpixel"))
|
---|
830 | SetCalibrationMode(kBlindPixel);
|
---|
831 | if (s.BeginsWith("ffactor"))
|
---|
832 | SetCalibrationMode(kFfactor);
|
---|
833 | if (s.BeginsWith("pindiode"))
|
---|
834 | SetCalibrationMode(kPinDiode);
|
---|
835 | if (s.BeginsWith("combined"))
|
---|
836 | SetCalibrationMode(kCombined);
|
---|
837 | if (s.BeginsWith("dummy"))
|
---|
838 | SetCalibrationMode(kDummy);
|
---|
839 | if (s.BeginsWith("default"))
|
---|
840 | SetCalibrationMode();
|
---|
841 | }
|
---|
842 |
|
---|
843 | if (IsEnvDefined(env, prefix, "SignalType", print))
|
---|
844 | {
|
---|
845 | rc = kTRUE;
|
---|
846 | TString s = GetEnvValue(env, prefix, "SignalType", "");
|
---|
847 | s.ToLower();
|
---|
848 | if (s.BeginsWith("phot"))
|
---|
849 | SetSignalType(kPhot);
|
---|
850 | if (s.BeginsWith("phe"))
|
---|
851 | SetSignalType(kPhe);
|
---|
852 | if (s.BeginsWith("default"))
|
---|
853 | SetSignalType();
|
---|
854 | }
|
---|
855 |
|
---|
856 | if (IsEnvDefined(env, prefix, "CalibConvMinLimit", print))
|
---|
857 | {
|
---|
858 | fCalibConvMinLimit = GetEnvValue(env, prefix, "CalibConvMinLimit", fCalibConvMinLimit);
|
---|
859 | rc = kTRUE;
|
---|
860 | }
|
---|
861 |
|
---|
862 | if (IsEnvDefined(env, prefix, "CalibConvMaxLimit", print))
|
---|
863 | {
|
---|
864 | fCalibConvMaxLimit = GetEnvValue(env, prefix, "CalibConvMaxLimit", fCalibConvMaxLimit);
|
---|
865 | rc = kTRUE;
|
---|
866 | }
|
---|
867 |
|
---|
868 | return rc;
|
---|
869 | }
|
---|
870 |
|
---|
871 | void MCalibrateData::Print(Option_t *o) const
|
---|
872 | {
|
---|
873 |
|
---|
874 | *fLog << all << GetDescriptor() << ":" << endl;
|
---|
875 |
|
---|
876 | for (UInt_t pixidx=0; pixidx<fGeomCam->GetNumPixels(); pixidx++)
|
---|
877 | {
|
---|
878 | *fLog << all
|
---|
879 | << Form("%s%3i","Pixel: ",pixidx)
|
---|
880 | << Form("%s%4.2f"," CalibConst: ",fCalibConsts[pixidx])
|
---|
881 | << Form("%s%4.2f"," F-Factor: ",fCalibFFactors[pixidx])
|
---|
882 | << Form("%s%4.2f"," HiLoConv: ",fHiLoConv[pixidx])
|
---|
883 | << endl;
|
---|
884 | }
|
---|
885 | }
|
---|
886 |
|
---|