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 SetNamePedestalCam() and/or SetNamePedPhotCam() you
|
---|
69 | // can control the name of the 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.SetNamePedestalCam("MPedestalFromLoGain");
|
---|
79 | // cal2.SetNamePedPhotCam("MPedPhotFromLoGain")
|
---|
80 | // cal2.SetPedestalFlag(MCalibrateData::kEvent);
|
---|
81 | //
|
---|
82 | //
|
---|
83 | // Input Containers:
|
---|
84 | // [MPedestalCam]
|
---|
85 | // [MExtractedSignalCam]
|
---|
86 | // [MCalibrationChargeCam]
|
---|
87 | // [MCalibrationQECam]
|
---|
88 | // MBadPixelsCam
|
---|
89 | //
|
---|
90 | // Output Containers:
|
---|
91 | // [MPedPhotCam]
|
---|
92 | // [MCerPhotEvt]
|
---|
93 | //
|
---|
94 | // See also: MJCalibration, MJPedestal, MJExtractSignal, MJExtractCalibTest
|
---|
95 | //
|
---|
96 | //////////////////////////////////////////////////////////////////////////////
|
---|
97 | #include "MCalibrateData.h"
|
---|
98 |
|
---|
99 | #include <fstream>
|
---|
100 |
|
---|
101 | #include <TEnv.h>
|
---|
102 |
|
---|
103 | #include "MLog.h"
|
---|
104 | #include "MLogManip.h"
|
---|
105 |
|
---|
106 | #include "MParList.h"
|
---|
107 | #include "MH.h"
|
---|
108 |
|
---|
109 | #include "MGeomCam.h"
|
---|
110 |
|
---|
111 | #include "MPedestalCam.h"
|
---|
112 | #include "MPedestalPix.h"
|
---|
113 |
|
---|
114 | #include "MCalibrationChargeCam.h"
|
---|
115 | #include "MCalibrationChargePix.h"
|
---|
116 |
|
---|
117 | #include "MCalibrationQECam.h"
|
---|
118 | #include "MCalibrationQEPix.h"
|
---|
119 |
|
---|
120 | #include "MExtractedSignalCam.h"
|
---|
121 | #include "MExtractedSignalPix.h"
|
---|
122 |
|
---|
123 | #include "MPedPhotCam.h"
|
---|
124 | #include "MPedPhotPix.h"
|
---|
125 |
|
---|
126 | #include "MBadPixelsCam.h"
|
---|
127 | #include "MBadPixelsPix.h"
|
---|
128 |
|
---|
129 | #include "MCerPhotEvt.h"
|
---|
130 |
|
---|
131 | ClassImp(MCalibrateData);
|
---|
132 |
|
---|
133 | using namespace std;
|
---|
134 |
|
---|
135 | const TString MCalibrateData::fgNamePedestalCam = "MPedestalCam";
|
---|
136 | const TString MCalibrateData::fgNamePedPhotCam = "MPedPhotCam";
|
---|
137 |
|
---|
138 | // --------------------------------------------------------------------------
|
---|
139 | //
|
---|
140 | // Default constructor.
|
---|
141 | //
|
---|
142 | // Sets all pointers to NULL
|
---|
143 | //
|
---|
144 | // Initializes:
|
---|
145 | // - fCalibrationMode to kDefault
|
---|
146 | // - fPedestalFlag to kNo
|
---|
147 | // - fNamePedADCRunContainer to "MPedestalCam"
|
---|
148 | // - fNamePedPhotRunContainer to "MPedPhotCam"
|
---|
149 | //
|
---|
150 | MCalibrateData::MCalibrateData(CalibrationMode_t calmode,const char *name, const char *title)
|
---|
151 | : fGeomCam(NULL), fPedestalMean(NULL), fPedestalRms(NULL),
|
---|
152 | fBadPixels(NULL), fCalibrations(NULL), fQEs(NULL), fSignals(NULL),
|
---|
153 | fPedPhot(NULL), fCerPhotEvt(NULL), fPedestalFlag(kNo)
|
---|
154 | {
|
---|
155 |
|
---|
156 | fName = name ? name : "MCalibrateData";
|
---|
157 | fTitle = title ? title : "Task to calculate the number of photons in one event";
|
---|
158 |
|
---|
159 | SetCalibrationMode(calmode);
|
---|
160 |
|
---|
161 | SetNamePedestalCam();
|
---|
162 | SetNamePedPhotCam();
|
---|
163 | }
|
---|
164 |
|
---|
165 | // --------------------------------------------------------------------------
|
---|
166 | //
|
---|
167 | // The PreProcess searches for the following input containers:
|
---|
168 | //
|
---|
169 | // - MGeomCam
|
---|
170 | // - MPedestalCam
|
---|
171 | // - MCalibrationChargeCam
|
---|
172 | // - MCalibrationQECam
|
---|
173 | // - MExtractedSignalCam
|
---|
174 | // - MBadPixelsCam
|
---|
175 | //
|
---|
176 | // The following output containers are also searched and created if
|
---|
177 | // they were not found:
|
---|
178 | //
|
---|
179 | // - MPedPhotCam
|
---|
180 | // - MCerPhotEvt
|
---|
181 | //
|
---|
182 | Int_t MCalibrateData::PreProcess(MParList *pList)
|
---|
183 | {
|
---|
184 | // input containers
|
---|
185 |
|
---|
186 | fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
|
---|
187 | if (!fBadPixels)
|
---|
188 | {
|
---|
189 | *fLog << err << AddSerialNumber("MBadPixelsCam") << " not found ... aborting" << endl;
|
---|
190 | return kFALSE;
|
---|
191 | }
|
---|
192 |
|
---|
193 | fSignals = 0;
|
---|
194 | fCerPhotEvt = 0;
|
---|
195 | if (fCalibrationMode>kSkip)
|
---|
196 | {
|
---|
197 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
---|
198 | if (!fSignals)
|
---|
199 | {
|
---|
200 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
---|
201 | return kFALSE;
|
---|
202 | }
|
---|
203 |
|
---|
204 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
---|
205 | if (!fCerPhotEvt)
|
---|
206 | return kFALSE;
|
---|
207 | }
|
---|
208 |
|
---|
209 | fCalibrations = 0;
|
---|
210 | fQEs = 0;
|
---|
211 | if (fCalibrationMode>kNone)
|
---|
212 | {
|
---|
213 | fCalibrations = (MCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
---|
214 | if (!fCalibrations)
|
---|
215 | {
|
---|
216 | *fLog << err << AddSerialNumber("MCalibrationChargeCam") << " not found ... aborting." << endl;
|
---|
217 | return kFALSE;
|
---|
218 | }
|
---|
219 |
|
---|
220 | fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
|
---|
221 | if (!fQEs)
|
---|
222 | {
|
---|
223 | *fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
|
---|
224 | return kFALSE;
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | //fPedestalMean = 0;
|
---|
229 | //fPedestalRms = 0;
|
---|
230 | fPedPhot = 0;
|
---|
231 | if (fPedestalFlag)
|
---|
232 | {
|
---|
233 | if (!fPedestalMean)
|
---|
234 | {
|
---|
235 | fPedestalMean = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
|
---|
236 | if (!fPedestalMean)
|
---|
237 | {
|
---|
238 | *fLog << err << AddSerialNumber(fNamePedestalCam) << " [MPedestalCam] not found ... aborting" << endl;
|
---|
239 | return kFALSE;
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 | if (!fPedestalRms)
|
---|
244 | {
|
---|
245 | fPedestalRms = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
|
---|
246 | if (!fPedestalRms)
|
---|
247 | {
|
---|
248 | *fLog << err << AddSerialNumber(fNamePedestalCam) << " [MPedestalCam] not found ... aborting" << endl;
|
---|
249 | return kFALSE;
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 | fPedPhot = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam", AddSerialNumber(fNamePedPhotCam));
|
---|
254 | if (!fPedPhot)
|
---|
255 | return kFALSE;
|
---|
256 | }
|
---|
257 |
|
---|
258 | return kTRUE;
|
---|
259 | }
|
---|
260 |
|
---|
261 | // --------------------------------------------------------------------------
|
---|
262 | //
|
---|
263 | // The ReInit searches for the following input containers:
|
---|
264 | //
|
---|
265 | // - MGeomCam
|
---|
266 | //
|
---|
267 | // Check for validity of the selected calibration method, switch to a
|
---|
268 | // different one in case of need
|
---|
269 | //
|
---|
270 | // Fill the MPedPhotCam container using the information from MPedestalCam,
|
---|
271 | // MExtractedSignalCam and MCalibrationCam
|
---|
272 | //
|
---|
273 | Bool_t MCalibrateData::ReInit(MParList *pList)
|
---|
274 | {
|
---|
275 | fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
276 | if (!fGeomCam)
|
---|
277 | {
|
---|
278 | *fLog << err << "No MGeomCam found... aborting." << endl;
|
---|
279 | return kFALSE;
|
---|
280 | }
|
---|
281 |
|
---|
282 | // Sizes might have changed
|
---|
283 | if (fPedestalFlag && (Int_t)fPedestalMean->GetSize() != fSignals->GetSize())
|
---|
284 | {
|
---|
285 | *fLog << err << "Size mismatch of MPedestalCam for Mean and MCalibrationCam... abort." << endl;
|
---|
286 | return kFALSE;
|
---|
287 | }
|
---|
288 |
|
---|
289 | if (fPedestalFlag && (Int_t)fPedestalRms->GetSize() != fSignals->GetSize())
|
---|
290 | {
|
---|
291 | *fLog << err << "Size mismatch of MPedestalCam for RMS and MCalibrationCam... abort." << endl;
|
---|
292 | return kFALSE;
|
---|
293 | }
|
---|
294 |
|
---|
295 | if(fCalibrationMode == kBlindPixel && !fQEs->IsBlindPixelMethodValid())
|
---|
296 | {
|
---|
297 | *fLog << warn << "Blind pixel calibration method not valid, switching to F-factor method" << endl;
|
---|
298 | fCalibrationMode = kFfactor;
|
---|
299 | }
|
---|
300 |
|
---|
301 | if(fCalibrationMode == kPinDiode && !fQEs->IsPINDiodeMethodValid())
|
---|
302 | {
|
---|
303 | *fLog << warn << "PIN diode calibration method not valid, switching to F-factor method" << endl;
|
---|
304 | fCalibrationMode = kFfactor;
|
---|
305 | }
|
---|
306 |
|
---|
307 | if(fCalibrationMode == kCombined && !fQEs->IsCombinedMethodValid())
|
---|
308 | {
|
---|
309 | *fLog << warn << "Combined calibration method not valid, switching to F-factor method" << endl;
|
---|
310 | fCalibrationMode = kFfactor;
|
---|
311 | }
|
---|
312 |
|
---|
313 | //
|
---|
314 | // output information or warnings:
|
---|
315 | //
|
---|
316 | switch(fCalibrationMode)
|
---|
317 | {
|
---|
318 | case kBlindPixel:
|
---|
319 | break;
|
---|
320 | case kFfactor:
|
---|
321 | break;
|
---|
322 | case kPinDiode:
|
---|
323 | *fLog << err << "PIN Diode Calibration mode not yet available!" << endl;
|
---|
324 | return kFALSE;
|
---|
325 | break;
|
---|
326 | case kCombined:
|
---|
327 | *fLog << err << "Combined Calibration mode not yet available!" << endl;
|
---|
328 | return kFALSE;
|
---|
329 | break;
|
---|
330 | case kFlatCharge:
|
---|
331 | *fLog << warn << "WARNING - Flat-fielding charges - only for muon calibration!" << endl;
|
---|
332 | break;
|
---|
333 | case kDummy:
|
---|
334 | *fLog << warn << "WARNING - Dummy calibration, no calibration applied!" << endl;
|
---|
335 | break;
|
---|
336 | case kNone:
|
---|
337 | *fLog << warn << "WARNING - No calibration applied!" << endl;
|
---|
338 | break;
|
---|
339 | default:
|
---|
340 | *fLog << warn << "WARNING - Calibration mode value (" << fCalibrationMode << ") not known" << endl;
|
---|
341 | return kFALSE;
|
---|
342 | }
|
---|
343 |
|
---|
344 | if (TestPedestalFlag(kRun))
|
---|
345 | Calibrate(kFALSE, kTRUE);
|
---|
346 |
|
---|
347 | return kTRUE;
|
---|
348 | }
|
---|
349 |
|
---|
350 | // --------------------------------------------------------------------------
|
---|
351 | //
|
---|
352 | // Get conversion factor and its error from MCalibrationCam
|
---|
353 | //
|
---|
354 | Bool_t MCalibrateData::GetConversionFactor(UInt_t pixidx, Float_t &hiloconv, Float_t &hiloconverr,
|
---|
355 | Float_t &calibConv, Float_t &calibConvVar,
|
---|
356 | Float_t &calibFFactor) const
|
---|
357 | {
|
---|
358 | //
|
---|
359 | // For the moment, we use only a dummy zenith for the calibration:
|
---|
360 | //
|
---|
361 | const Float_t zenith = -1.;
|
---|
362 |
|
---|
363 | hiloconv = 1.;
|
---|
364 | hiloconverr = 0.;
|
---|
365 | calibConv = 1.;
|
---|
366 | calibConvVar = 0.;
|
---|
367 | calibFFactor = 0.;
|
---|
368 |
|
---|
369 | Float_t calibQE = 1.;
|
---|
370 | Float_t calibQEVar = 0.;
|
---|
371 |
|
---|
372 | if(fCalibrationMode!=kNone)
|
---|
373 | {
|
---|
374 | MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCalibrations)[pixidx];
|
---|
375 |
|
---|
376 | hiloconv = pix.GetConversionHiLo ();
|
---|
377 | hiloconverr= pix.GetConversionHiLoErr();
|
---|
378 |
|
---|
379 | if ((*fBadPixels)[pixidx].IsUnsuitable())
|
---|
380 | return kFALSE;
|
---|
381 |
|
---|
382 | calibConv = pix.GetMeanConvFADC2Phe();
|
---|
383 | calibConvVar = pix.GetMeanConvFADC2PheVar();
|
---|
384 | calibFFactor = pix.GetMeanFFactorFADC2Phot();
|
---|
385 |
|
---|
386 | MCalibrationQEPix &qe = (MCalibrationQEPix&) (*fQEs)[pixidx];
|
---|
387 |
|
---|
388 | switch(fCalibrationMode)
|
---|
389 | {
|
---|
390 | case kFlatCharge:
|
---|
391 | {
|
---|
392 | MCalibrationChargePix &avpix = (MCalibrationChargePix&)fCalibrations->GetAverageArea(0);
|
---|
393 | calibConv = avpix.GetMean() / (pix.GetMean() * fGeomCam->GetPixRatio(pixidx));
|
---|
394 | calibConvVar = (avpix.GetMeanRelVar() + pix.GetMeanRelVar()) * calibConv * calibConv;
|
---|
395 | if (pix.IsFFactorMethodValid())
|
---|
396 | {
|
---|
397 | const Float_t convmin1 = qe.GetQECascadesFFactor(zenith)/pix.GetMeanConvFADC2Phe();
|
---|
398 | if (convmin1 > 0)
|
---|
399 | calibFFactor *= TMath::Sqrt(convmin1);
|
---|
400 | else
|
---|
401 | calibFFactor = -1.;
|
---|
402 | }
|
---|
403 | }
|
---|
404 | break;
|
---|
405 |
|
---|
406 | case kBlindPixel:
|
---|
407 | if (!qe.IsBlindPixelMethodValid())
|
---|
408 | return kFALSE;
|
---|
409 | calibQE = qe.GetQECascadesBlindPixel ( zenith );
|
---|
410 | calibQEVar = qe.GetQECascadesBlindPixelVar( zenith );
|
---|
411 | break;
|
---|
412 |
|
---|
413 | case kPinDiode:
|
---|
414 | if (!qe.IsPINDiodeMethodValid())
|
---|
415 | return kFALSE;
|
---|
416 | calibQE = qe.GetQECascadesPINDiode ( zenith );
|
---|
417 | calibQEVar = qe.GetQECascadesPINDiodeVar( zenith );
|
---|
418 | break;
|
---|
419 |
|
---|
420 | case kFfactor:
|
---|
421 | if (!pix.IsFFactorMethodValid())
|
---|
422 | return kFALSE;
|
---|
423 | calibQE = qe.GetQECascadesFFactor ( zenith );
|
---|
424 | calibQEVar = qe.GetQECascadesFFactorVar( zenith );
|
---|
425 | break;
|
---|
426 |
|
---|
427 | case kCombined:
|
---|
428 | if (!qe.IsCombinedMethodValid())
|
---|
429 | return kFALSE;
|
---|
430 | calibQE = qe.GetQECascadesCombined ( zenith );
|
---|
431 | calibQEVar = qe.GetQECascadesCombinedVar( zenith );
|
---|
432 | break;
|
---|
433 |
|
---|
434 | case kDummy:
|
---|
435 | hiloconv = 1.;
|
---|
436 | hiloconverr = 0.;
|
---|
437 | break;
|
---|
438 | } /* switch calibration mode */
|
---|
439 | } /* if(fCalibrationMode!=kNone) */
|
---|
440 | else
|
---|
441 | {
|
---|
442 | calibConv = 1./fGeomCam->GetPixRatio(pixidx);
|
---|
443 | }
|
---|
444 |
|
---|
445 | calibConv /= calibQE;
|
---|
446 |
|
---|
447 | if (calibConv != 0. && calibQE != 0.)
|
---|
448 | {
|
---|
449 | // Now doing:
|
---|
450 | // calibConvVar = calibConvVar/(calibConv*calibConv) + calibQEVar/(calibQE*calibQE);
|
---|
451 | // calibConvVar *= (calibConv*calibConv);
|
---|
452 | calibConvVar += calibQEVar*(calibConv*calibConv)/(calibQE*calibQE);
|
---|
453 | }
|
---|
454 |
|
---|
455 | return kTRUE;
|
---|
456 | }
|
---|
457 |
|
---|
458 | Int_t MCalibrateData::Calibrate(Bool_t data, Bool_t pedestal) const
|
---|
459 | {
|
---|
460 | if (!data && !pedestal)
|
---|
461 | return kTRUE;
|
---|
462 |
|
---|
463 | const UInt_t npix = fSignals->GetSize();
|
---|
464 | const Float_t slices = fSignals->GetNumUsedHiGainFADCSlices();
|
---|
465 | const Float_t sqrtslices = TMath::Sqrt(slices);
|
---|
466 |
|
---|
467 | Float_t hiloconv;
|
---|
468 | Float_t hiloconverr;
|
---|
469 | Float_t calibConv;
|
---|
470 | Float_t calibConvErr;
|
---|
471 | Float_t calibFFactor;
|
---|
472 |
|
---|
473 | UInt_t skip = 0;
|
---|
474 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
---|
475 | {
|
---|
476 | if (!GetConversionFactor(pixidx, hiloconv, hiloconverr,
|
---|
477 | calibConv, calibConvErr, calibFFactor))
|
---|
478 | {
|
---|
479 | skip++;
|
---|
480 | continue;
|
---|
481 | }
|
---|
482 |
|
---|
483 | if (data)
|
---|
484 | {
|
---|
485 | const MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
---|
486 |
|
---|
487 | Float_t signal = 0;
|
---|
488 | Float_t signalErr = 0.;
|
---|
489 |
|
---|
490 | if (sig.IsLoGainUsed())
|
---|
491 | {
|
---|
492 | signal = sig.GetExtractedSignalLoGain()*hiloconv;
|
---|
493 | signalErr = signal*hiloconverr;
|
---|
494 | }
|
---|
495 | else
|
---|
496 | {
|
---|
497 | if (sig.GetExtractedSignalHiGain() <= 9999.)
|
---|
498 | signal = sig.GetExtractedSignalHiGain();
|
---|
499 | }
|
---|
500 |
|
---|
501 | const Float_t nphot = signal*calibConv;
|
---|
502 | const Float_t nphotErr = calibFFactor*TMath::Sqrt(TMath::Abs(nphot));
|
---|
503 |
|
---|
504 | //
|
---|
505 | // The following part is the commented first version of the error calculation
|
---|
506 | // Contact Markus Gaug for questions (or wait for the next documentation update...)
|
---|
507 | //
|
---|
508 | /*
|
---|
509 | nphotErr = signal > 0 ? signalErr*signalErr / (signal * signal) : 0.
|
---|
510 | + calibConv > 0 ? calibConvVar / (calibConv * calibConv ) : 0.;
|
---|
511 | nphotErr = TMath::Sqrt(nphotErr) * nphot;
|
---|
512 | */
|
---|
513 |
|
---|
514 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
---|
515 |
|
---|
516 | if (sig.GetNumHiGainSaturated() > 0)
|
---|
517 | cpix->SetPixelHGSaturated();
|
---|
518 |
|
---|
519 | if (sig.GetNumLoGainSaturated() > 0)
|
---|
520 | cpix->SetPixelSaturated();
|
---|
521 | }
|
---|
522 |
|
---|
523 | if (pedestal)
|
---|
524 | {
|
---|
525 | // pedestals/(used FADC slices) in [ADC] counts
|
---|
526 | const Float_t pedes = (*fPedestalMean)[pixidx].GetPedestal() * slices;
|
---|
527 | const Float_t pedrms = (*fPedestalRms)[pixidx].GetPedestalRms() * sqrtslices;
|
---|
528 |
|
---|
529 | //
|
---|
530 | // pedestals/(used FADC slices) in [number of photons]
|
---|
531 | //
|
---|
532 | const Float_t pedphot = pedes * calibConv;
|
---|
533 | const Float_t pedphotrms = pedrms * calibConv;
|
---|
534 |
|
---|
535 | (*fPedPhot)[pixidx].Set(pedphot, pedphotrms);
|
---|
536 | }
|
---|
537 | }
|
---|
538 |
|
---|
539 | if (skip>npix*0.9)
|
---|
540 | {
|
---|
541 | *fLog << warn << "WARNING - GetConversionFactor has skipped more than 90% of the pixels... skip." << endl;
|
---|
542 | return kCONTINUE;
|
---|
543 | }
|
---|
544 |
|
---|
545 | if (pedestal)
|
---|
546 | fPedPhot->SetReadyToSave();
|
---|
547 |
|
---|
548 | if (data)
|
---|
549 | {
|
---|
550 | fCerPhotEvt->FixSize();
|
---|
551 | fCerPhotEvt->SetReadyToSave();
|
---|
552 | }
|
---|
553 | return kTRUE;
|
---|
554 | }
|
---|
555 |
|
---|
556 | // --------------------------------------------------------------------------
|
---|
557 | //
|
---|
558 | // Apply the calibration factors to the extracted signal according to the
|
---|
559 | // selected calibration method
|
---|
560 | //
|
---|
561 | Int_t MCalibrateData::Process()
|
---|
562 | {
|
---|
563 | /*
|
---|
564 | if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
|
---|
565 | {
|
---|
566 | // FIXME: MExtractedSignal must be of variable size -
|
---|
567 | // like MCerPhotEvt - because we must be able
|
---|
568 | // to reduce size by zero supression
|
---|
569 | // For the moment this check could be done in ReInit...
|
---|
570 | *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
|
---|
571 | return kFALSE;
|
---|
572 | }
|
---|
573 | */
|
---|
574 |
|
---|
575 | return Calibrate(fCalibrationMode!=kSkip, TestPedestalFlag(kEvent));
|
---|
576 | }
|
---|
577 |
|
---|
578 | // --------------------------------------------------------------------------
|
---|
579 | //
|
---|
580 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
581 | // to a macro. In the original root implementation it is used to write
|
---|
582 | // gui elements to a macro-file.
|
---|
583 | //
|
---|
584 | void MCalibrateData::StreamPrimitive(ofstream &out) const
|
---|
585 | {
|
---|
586 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
587 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
588 |
|
---|
589 | if (TestPedestalFlag(kEvent))
|
---|
590 | out << " " << GetUniqueName() << ".EnablePedestalType(MCalibrateData::kEvent)" << endl;
|
---|
591 | if (TestPedestalFlag(kRun))
|
---|
592 | out << " " << GetUniqueName() << ".EnablePedestalType(MCalibrateData::kRun)" << endl;
|
---|
593 |
|
---|
594 | if (fCalibrationMode != kDefault)
|
---|
595 | {
|
---|
596 | out << " " << GetUniqueName() << ".SetCalibrationMode(MCalibrateData::";
|
---|
597 | switch (fCalibrationMode)
|
---|
598 | {
|
---|
599 | case kSkip: out << "kSkip"; break;
|
---|
600 | case kNone: out << "kNone"; break;
|
---|
601 | case kFlatCharge: out << "kFlatCharge"; break;
|
---|
602 | case kBlindPixel: out << "kBlindPixel"; break;
|
---|
603 | case kFfactor: out << "kFfactor"; break;
|
---|
604 | case kPinDiode: out << "kPinDiode"; break;
|
---|
605 | case kCombined: out << "kCombined"; break;
|
---|
606 | case kDummy: out << "kDummy"; break;
|
---|
607 | default: out << (int)fCalibrationMode; break;
|
---|
608 | }
|
---|
609 | out << ")" << endl;
|
---|
610 | }
|
---|
611 |
|
---|
612 | if (fNamePedestalCam != fgNamePedestalCam)
|
---|
613 | {
|
---|
614 | out << " " << GetUniqueName() << ".SetNamePedestalCam(";
|
---|
615 | out << fNamePedestalCam << ");" << endl;
|
---|
616 | }
|
---|
617 |
|
---|
618 | if (fNamePedPhotCam != fgNamePedPhotCam)
|
---|
619 | {
|
---|
620 | out << " " << GetUniqueName() << ".SetNamePedPhotCam(";
|
---|
621 | out << fNamePedPhotCam << ");" << endl;
|
---|
622 | }
|
---|
623 | }
|
---|
624 |
|
---|
625 | // --------------------------------------------------------------------------
|
---|
626 | //
|
---|
627 | // Read the setup from a TEnv, eg:
|
---|
628 | // MJPedestal.MCalibrateDate.PedestalFlag: no,run,event
|
---|
629 | // MJPedestal.MCalibrateDate.CalibrationMode: skip,none,flatcharge,blindpixel,ffactor,pindiode,combined,dummy,default
|
---|
630 | //
|
---|
631 | Int_t MCalibrateData::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
632 | {
|
---|
633 | Bool_t rc = kFALSE;
|
---|
634 | if (IsEnvDefined(env, prefix, "PedestalFlag", print))
|
---|
635 | {
|
---|
636 | rc = kTRUE;
|
---|
637 | TString s = GetEnvValue(env, prefix, "PedestalFlag", "");
|
---|
638 | s.ToLower();
|
---|
639 | if (s.BeginsWith("no"))
|
---|
640 | SetPedestalFlag(kNo);
|
---|
641 | if (s.BeginsWith("run"))
|
---|
642 | SetPedestalFlag(kRun);
|
---|
643 | if (s.BeginsWith("event"))
|
---|
644 | SetPedestalFlag(kEvent);
|
---|
645 | }
|
---|
646 |
|
---|
647 | if (IsEnvDefined(env, prefix, "CalibrationMode", print))
|
---|
648 | {
|
---|
649 | rc = kTRUE;
|
---|
650 | TString s = GetEnvValue(env, prefix, "CalibrationMode", "");
|
---|
651 | s.ToLower();
|
---|
652 | if (s.BeginsWith("skip"))
|
---|
653 | SetCalibrationMode(kSkip);
|
---|
654 | if (s.BeginsWith("none"))
|
---|
655 | SetCalibrationMode(kNone);
|
---|
656 | if (s.BeginsWith("flatcharge"))
|
---|
657 | SetCalibrationMode(kFlatCharge);
|
---|
658 | if (s.BeginsWith("blindpixel"))
|
---|
659 | SetCalibrationMode(kBlindPixel);
|
---|
660 | if (s.BeginsWith("ffactor"))
|
---|
661 | SetCalibrationMode(kFfactor);
|
---|
662 | if (s.BeginsWith("pindiode"))
|
---|
663 | SetCalibrationMode(kPinDiode);
|
---|
664 | if (s.BeginsWith("combined"))
|
---|
665 | SetCalibrationMode(kCombined);
|
---|
666 | if (s.BeginsWith("dummy"))
|
---|
667 | SetCalibrationMode(kDummy);
|
---|
668 | if (s.BeginsWith("default"))
|
---|
669 | SetCalibrationMode();
|
---|
670 | }
|
---|
671 |
|
---|
672 | return rc;
|
---|
673 | }
|
---|