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