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 | !
|
---|
24 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
25 | !
|
---|
26 | !
|
---|
27 | \* ======================================================================== */
|
---|
28 |
|
---|
29 | ///////////////////////////////////////////////////////////////////////////////////
|
---|
30 | //
|
---|
31 | // MCalibrateData
|
---|
32 | //
|
---|
33 | // This task takes the integrated charge from MExtractedSignal and applies
|
---|
34 | // the calibration constants from MCalibrationCam to convert the summed FADC
|
---|
35 | // slices into photons. The number of photons obtained is stored in MCerPhotEvt.
|
---|
36 | // Optionally, the calibration of pedestals from an MPedestalCam container into
|
---|
37 | // an MPedPhotCam container can be chosen with the member functions
|
---|
38 | // SetPedestalType(). Default is 'kRun', i.e. calibration of pedestals from a
|
---|
39 | // dedicated pedestal run.
|
---|
40 | // In case, the chosen pedestal type is kRun or kEvent, in ReInit() the MPedPhotCam
|
---|
41 | // container is filled using the information from MPedestalCam, MExtractedSignalCam,
|
---|
42 | // MCalibrationChargeCam and MCalibrationQECam
|
---|
43 | //
|
---|
44 | // Selection of different calibration methods is allowed through the
|
---|
45 | // SetCalibrationMode() member function (default: kFfactor)
|
---|
46 | //
|
---|
47 | // The calibration modes which exclude non-valid pixels are the following:
|
---|
48 | //
|
---|
49 | // kFfactor: calibrates using the F-Factor method
|
---|
50 | // kBlindpixel: calibrates using the BlindPixel method
|
---|
51 | // kBlindpixel: calibrates using the BlindPixel method
|
---|
52 | // kFlatCharge: perform a charge flat-flatfielding. Outer pixels are area-corrected.
|
---|
53 | // kDummy: calibrates with fixed conversion factors of 1 and errors of 0.
|
---|
54 | //
|
---|
55 | // The calibration modes which include all pixels regardless of their validity is:
|
---|
56 | //
|
---|
57 | // kNone: calibrates with fixed conversion factors of 1 and errors of 0.
|
---|
58 | //
|
---|
59 | // Use the kDummy and kNone methods ONLY FOR DEBUGGING!
|
---|
60 | //
|
---|
61 | // Input Containers:
|
---|
62 | // MPedestalCam
|
---|
63 | // MExtractedSignalCam
|
---|
64 | // MCalibrationChargeCam
|
---|
65 | // MCalibrationQECam
|
---|
66 | //
|
---|
67 | // Output Containers:
|
---|
68 | // MPedPhotCam
|
---|
69 | // MCerPhotEvt
|
---|
70 | //
|
---|
71 | // See also: MJCalibration, MJPedestal, MJExtractSignal, MJExtractCalibTest
|
---|
72 | //
|
---|
73 | //////////////////////////////////////////////////////////////////////////////
|
---|
74 | #include "MCalibrateData.h"
|
---|
75 |
|
---|
76 | #include <fstream>
|
---|
77 |
|
---|
78 | #include "MLog.h"
|
---|
79 | #include "MLogManip.h"
|
---|
80 |
|
---|
81 | #include "MParList.h"
|
---|
82 | #include "MH.h"
|
---|
83 |
|
---|
84 | #include "MGeomCam.h"
|
---|
85 |
|
---|
86 | #include "MPedestalCam.h"
|
---|
87 | #include "MPedestalPix.h"
|
---|
88 |
|
---|
89 | #include "MCalibrationChargeCam.h"
|
---|
90 | #include "MCalibrationChargePix.h"
|
---|
91 |
|
---|
92 | #include "MCalibrationQECam.h"
|
---|
93 | #include "MCalibrationQEPix.h"
|
---|
94 |
|
---|
95 | #include "MExtractedSignalCam.h"
|
---|
96 | #include "MExtractedSignalPix.h"
|
---|
97 |
|
---|
98 | #include "MPedPhotCam.h"
|
---|
99 | #include "MPedPhotPix.h"
|
---|
100 |
|
---|
101 | #include "MBadPixelsCam.h"
|
---|
102 | #include "MBadPixelsPix.h"
|
---|
103 |
|
---|
104 | #include "MCerPhotEvt.h"
|
---|
105 |
|
---|
106 | ClassImp(MCalibrateData);
|
---|
107 |
|
---|
108 | using namespace std;
|
---|
109 |
|
---|
110 | const TString MCalibrateData::fgNamePedADCRunContainer = "MPedestalCam" ;
|
---|
111 | const TString MCalibrateData::fgNamePedADCEventContainer = "MPedestalCamFromData";
|
---|
112 | const TString MCalibrateData::fgNamePedPhotRunContainer = "MPedPhotCam" ;
|
---|
113 | const TString MCalibrateData::fgNamePedPhotEventContainer = "MPedPhotCamFromData" ;
|
---|
114 | // --------------------------------------------------------------------------
|
---|
115 | //
|
---|
116 | // Default constructor.
|
---|
117 | //
|
---|
118 | // Sets all pointers to NULL
|
---|
119 | //
|
---|
120 | // Initializes:
|
---|
121 | // - fCalibrationMode to kDefault
|
---|
122 | // - fPedestalFlag to kRun
|
---|
123 | // - fNamePedADCRunContainer to "MPedestalCam"
|
---|
124 | // - fNamePedADCEventContainer to "MPedestalCamFromData"
|
---|
125 | // - fNamePedPhotRunContainer to "MPedPhotCam"
|
---|
126 | // - fNamePedPhotEventContainer to "MPedPhotCamFromData"
|
---|
127 | //
|
---|
128 | MCalibrateData::MCalibrateData(CalibrationMode_t calmode,const char *name, const char *title)
|
---|
129 | : fGeomCam(NULL), fPedestal(NULL), fPedestalFromData(NULL),
|
---|
130 | fBadPixels(NULL), fCalibrations(NULL), fQEs(NULL), fSignals(NULL),
|
---|
131 | fPedPhot(NULL), fPedPhotFromData(NULL), fCerPhotEvt(NULL)
|
---|
132 | {
|
---|
133 |
|
---|
134 | fName = name ? name : "MCalibrateData";
|
---|
135 | fTitle = title ? title : "Task to calculate the number of photons in one event";
|
---|
136 |
|
---|
137 | SetCalibrationMode();
|
---|
138 | SetPedestalType();
|
---|
139 |
|
---|
140 | SetNamePedADCRunContainer ();
|
---|
141 | SetNamePedADCEventContainer ();
|
---|
142 | SetNamePedPhotRunContainer ();
|
---|
143 | SetNamePedPhotEventContainer();
|
---|
144 |
|
---|
145 | }
|
---|
146 |
|
---|
147 | // --------------------------------------------------------------------------
|
---|
148 | //
|
---|
149 | // The PreProcess searches for the following input containers:
|
---|
150 | //
|
---|
151 | // - MGeomCam
|
---|
152 | // - MPedestalCam
|
---|
153 | // - MCalibrationChargeCam
|
---|
154 | // - MCalibrationQECam
|
---|
155 | // - MExtractedSignalCam
|
---|
156 | // - MBadPixelsCam
|
---|
157 | //
|
---|
158 | // The following output containers are also searched and created if
|
---|
159 | // they were not found:
|
---|
160 | //
|
---|
161 | // - MPedPhotCam
|
---|
162 | // - MCerPhotEvt
|
---|
163 | //
|
---|
164 | Int_t MCalibrateData::PreProcess(MParList *pList)
|
---|
165 | {
|
---|
166 |
|
---|
167 | // input containers
|
---|
168 |
|
---|
169 | if (TestFlag(kRun))
|
---|
170 | {
|
---|
171 | fPedestal = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedADCRunContainer), "MPedestalCam");
|
---|
172 | if (!fPedestal)
|
---|
173 | {
|
---|
174 | *fLog << err << "container 'MPedestalCam'"
|
---|
175 | << " not found ... aborting" << endl;
|
---|
176 | return kFALSE;
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 |
|
---|
181 | if (TestFlag(kEvent))
|
---|
182 | {
|
---|
183 | fPedestalFromData = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedADCEventContainer), "MPedestalCam");
|
---|
184 | if (!fPedestalFromData)
|
---|
185 | {
|
---|
186 | *fLog << err << "container 'MPedestalCamFromData'"
|
---|
187 | << " not found ... aborting" << endl;
|
---|
188 | return kFALSE;
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
---|
194 | if (!fSignals)
|
---|
195 | {
|
---|
196 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
---|
197 | return kFALSE;
|
---|
198 | }
|
---|
199 |
|
---|
200 | fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
|
---|
201 | if (!fBadPixels)
|
---|
202 | {
|
---|
203 | *fLog << err << AddSerialNumber("MBadPixelsCam") << " not found ... aborting" << endl;
|
---|
204 | return kFALSE;
|
---|
205 | }
|
---|
206 |
|
---|
207 | if (fCalibrationMode>kNone)
|
---|
208 | {
|
---|
209 | fCalibrations = (MCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
---|
210 | if (!fCalibrations)
|
---|
211 | {
|
---|
212 | *fLog << err << AddSerialNumber("MCalibrationChargeCam") << " not found ... aborting." << endl;
|
---|
213 | return kFALSE;
|
---|
214 | }
|
---|
215 |
|
---|
216 | fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
|
---|
217 | if (!fQEs)
|
---|
218 | {
|
---|
219 | *fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
|
---|
220 | return kFALSE;
|
---|
221 | }
|
---|
222 | }
|
---|
223 |
|
---|
224 | // output containers
|
---|
225 |
|
---|
226 | if (TestFlag(kRun))
|
---|
227 | {
|
---|
228 | fPedPhot = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam", AddSerialNumber(fNamePedPhotRunContainer));
|
---|
229 | if (!fPedPhot)
|
---|
230 | return kFALSE;
|
---|
231 |
|
---|
232 | }
|
---|
233 |
|
---|
234 |
|
---|
235 | if (TestFlag(kEvent))
|
---|
236 | {
|
---|
237 | fPedPhotFromData = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam", AddSerialNumber(fNamePedPhotEventContainer));
|
---|
238 | if (!fPedPhotFromData)
|
---|
239 | return kFALSE;
|
---|
240 |
|
---|
241 | }
|
---|
242 |
|
---|
243 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
---|
244 | if (!fCerPhotEvt)
|
---|
245 | return kFALSE;
|
---|
246 |
|
---|
247 | return kTRUE;
|
---|
248 | }
|
---|
249 |
|
---|
250 | // --------------------------------------------------------------------------
|
---|
251 | //
|
---|
252 | // The ReInit searches for the following input containers:
|
---|
253 | //
|
---|
254 | // - MGeomCam
|
---|
255 | //
|
---|
256 | // Check for validity of the selected calibration method, switch to a
|
---|
257 | // different one in case of need
|
---|
258 | //
|
---|
259 | // Fill the MPedPhotCam container using the information from MPedestalCam,
|
---|
260 | // MExtractedSignalCam and MCalibrationCam
|
---|
261 | //
|
---|
262 | Bool_t MCalibrateData::ReInit(MParList *pList)
|
---|
263 | {
|
---|
264 |
|
---|
265 | fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
266 | if (!fGeomCam)
|
---|
267 | {
|
---|
268 | *fLog << err << "No MGeomCam found... aborting." << endl;
|
---|
269 | return kFALSE;
|
---|
270 | }
|
---|
271 |
|
---|
272 | if(fCalibrationMode == kBlindPixel && !fQEs->IsBlindPixelMethodValid())
|
---|
273 | {
|
---|
274 | *fLog << warn << GetDescriptor()
|
---|
275 | << ": Blind pixel calibration method not valid, switching to default F-factor method" << endl;
|
---|
276 | fCalibrationMode = kFfactor;
|
---|
277 | }
|
---|
278 |
|
---|
279 | if(fCalibrationMode == kPinDiode && !fQEs->IsPINDiodeMethodValid())
|
---|
280 | {
|
---|
281 | *fLog << warn << GetDescriptor()
|
---|
282 | << ": PIN diode calibration method not valid, switching to default F-factor method" << endl;
|
---|
283 | fCalibrationMode = kFfactor;
|
---|
284 | }
|
---|
285 |
|
---|
286 | if(fCalibrationMode == kCombined && !fQEs->IsCombinedMethodValid())
|
---|
287 | {
|
---|
288 | *fLog << warn << GetDescriptor()
|
---|
289 | << ": Combined calibration method not valid, switching to default F-factor method" << endl;
|
---|
290 | fCalibrationMode = kFfactor;
|
---|
291 | }
|
---|
292 |
|
---|
293 | //
|
---|
294 | // output information or warnings:
|
---|
295 | //
|
---|
296 | switch(fCalibrationMode)
|
---|
297 | {
|
---|
298 | case kBlindPixel:
|
---|
299 | break;
|
---|
300 | case kFfactor:
|
---|
301 | break;
|
---|
302 | case kPinDiode:
|
---|
303 | *fLog << err << GetDescriptor()
|
---|
304 | << ": PIN Diode Calibration mode not yet available " << endl;
|
---|
305 | return kFALSE;
|
---|
306 | break;
|
---|
307 | case kCombined:
|
---|
308 | *fLog << err << GetDescriptor()
|
---|
309 | << ": Combined Calibration mode not yet available " << endl;
|
---|
310 | return kFALSE;
|
---|
311 | break;
|
---|
312 | case kFlatCharge:
|
---|
313 | *fLog << warn << GetDescriptor()
|
---|
314 | << ": WARNING: Flat-fielding charges - only for muon calibration! " << endl;
|
---|
315 | break;
|
---|
316 | case kDummy:
|
---|
317 | *fLog << warn << GetDescriptor()
|
---|
318 | << ": WARNING: Dummy calibration, no calibration applied!!" << endl;
|
---|
319 | break;
|
---|
320 | case kNone:
|
---|
321 | *fLog << warn << GetDescriptor()
|
---|
322 | << ": WARNING: No calibration applied!!" << endl;
|
---|
323 | break;
|
---|
324 | default:
|
---|
325 | *fLog << warn << GetDescriptor()
|
---|
326 | << ": WARNING: Calibration mode value ("
|
---|
327 | << fCalibrationMode << ") not known" << endl;
|
---|
328 | return kFALSE;
|
---|
329 | }
|
---|
330 |
|
---|
331 | if (TestFlag(kRun))
|
---|
332 | if (!CalibratePedestal(fPedestal,fPedPhot))
|
---|
333 | return kFALSE;
|
---|
334 |
|
---|
335 |
|
---|
336 | return kTRUE;
|
---|
337 | }
|
---|
338 |
|
---|
339 |
|
---|
340 |
|
---|
341 | // --------------------------------------------------------------------------
|
---|
342 | //
|
---|
343 | // Calibrate the Pedestal values
|
---|
344 | //
|
---|
345 | Bool_t MCalibrateData::CalibratePedestal(MPedestalCam *pedADCCam, MPedPhotCam *pedPhotCam)
|
---|
346 | {
|
---|
347 |
|
---|
348 | //
|
---|
349 | // Fill MPedPhot container using the informations from
|
---|
350 | // MPedestalCam, MExtractedSignalCam and MCalibrationCam
|
---|
351 | //
|
---|
352 | const Float_t slices = fSignals->GetNumUsedHiGainFADCSlices();
|
---|
353 |
|
---|
354 | // is pixid equal to pixidx ?
|
---|
355 | if ( (Int_t)(pedADCCam->GetSize()) != fSignals->GetSize())
|
---|
356 | {
|
---|
357 | *fLog << err << "MCalibrateData::ReInit(); sizes of MPedestalCam and MCalibrationCam are different"
|
---|
358 | << endl;
|
---|
359 | }
|
---|
360 |
|
---|
361 |
|
---|
362 | for (Int_t pixid=0; pixid<pedADCCam->GetSize(); pixid++)
|
---|
363 | {
|
---|
364 |
|
---|
365 | const MPedestalPix &ped = (*pedADCCam)[pixid];
|
---|
366 |
|
---|
367 | // pedestals/(used FADC slices) in [ADC] counts
|
---|
368 | Float_t pedes = ped.GetPedestal() * slices;
|
---|
369 | Float_t pedrms = ped.GetPedestalRms() * TMath::Sqrt(slices);
|
---|
370 |
|
---|
371 | //
|
---|
372 | // get phe/ADC conversion factor
|
---|
373 | //
|
---|
374 | Float_t hiloconv;
|
---|
375 | Float_t hiloconverr;
|
---|
376 | Float_t calibConv;
|
---|
377 | Float_t calibConvVar;
|
---|
378 | Float_t calibFFactor;
|
---|
379 |
|
---|
380 | if ( !GetConversionFactor(pixid, hiloconv, hiloconverr,
|
---|
381 | calibConv, calibConvVar, calibFFactor ))
|
---|
382 | continue;
|
---|
383 |
|
---|
384 | //
|
---|
385 | // pedestals/(used FADC slices) in [number of photons]
|
---|
386 | //
|
---|
387 | Float_t pedphot = pedes * calibConv;
|
---|
388 | Float_t pedphotrms = pedrms * calibConv;
|
---|
389 |
|
---|
390 | (*pedPhotCam)[pixid].Set(pedphot, pedphotrms);
|
---|
391 |
|
---|
392 | }
|
---|
393 |
|
---|
394 | pedPhotCam->SetReadyToSave();
|
---|
395 |
|
---|
396 | return kTRUE;
|
---|
397 | }
|
---|
398 |
|
---|
399 | // --------------------------------------------------------------------------
|
---|
400 | //
|
---|
401 | // Get conversion factor and its error from MCalibrationCam
|
---|
402 | //
|
---|
403 | Bool_t MCalibrateData::GetConversionFactor(UInt_t pixidx,
|
---|
404 | Float_t &hiloconv, Float_t &hiloconverr,
|
---|
405 | Float_t &calibConv, Float_t &calibConvVar, Float_t &calibFFactor)
|
---|
406 | {
|
---|
407 |
|
---|
408 | //
|
---|
409 | // For the moment, we use only a dummy zenith for the calibration:
|
---|
410 | //
|
---|
411 | const Float_t zenith = -1.;
|
---|
412 |
|
---|
413 | hiloconv = 1.;
|
---|
414 | hiloconverr = 0.;
|
---|
415 | calibConv = 1.;
|
---|
416 | calibConvVar = 0.;
|
---|
417 | calibFFactor = 0.;
|
---|
418 | Float_t calibQE = 1.;
|
---|
419 | Float_t calibQEVar = 0.;
|
---|
420 | Float_t avMean = 1.;
|
---|
421 | Float_t avMeanRelVar = 0.;
|
---|
422 |
|
---|
423 | if (fCalibrationMode == kFlatCharge)
|
---|
424 | {
|
---|
425 | MCalibrationChargePix &avpix = (MCalibrationChargePix&)fCalibrations->GetAverageArea(0);
|
---|
426 | avMean = avpix.GetMean();
|
---|
427 | avMeanRelVar = avpix.GetMeanRelVar();
|
---|
428 | }
|
---|
429 |
|
---|
430 |
|
---|
431 | if(fCalibrationMode!=kNone)
|
---|
432 | {
|
---|
433 |
|
---|
434 | MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCalibrations)[pixidx];
|
---|
435 |
|
---|
436 | hiloconv = pix.GetConversionHiLo ();
|
---|
437 | hiloconverr= pix.GetConversionHiLoErr();
|
---|
438 |
|
---|
439 | if (fBadPixels)
|
---|
440 | {
|
---|
441 | MBadPixelsPix &bad = (*fBadPixels)[pixidx];
|
---|
442 | if (bad.IsUnsuitable())
|
---|
443 | return kFALSE;
|
---|
444 | }
|
---|
445 |
|
---|
446 | calibConv = pix.GetMeanConvFADC2Phe();
|
---|
447 | calibConvVar = pix.GetMeanConvFADC2PheVar();
|
---|
448 | calibFFactor = pix.GetMeanFFactorFADC2Phot();
|
---|
449 |
|
---|
450 | MCalibrationQEPix &qe = (MCalibrationQEPix&) (*fQEs)[pixidx];
|
---|
451 |
|
---|
452 | switch(fCalibrationMode)
|
---|
453 | {
|
---|
454 | case kFlatCharge:
|
---|
455 | calibConv = avMean / pix.GetMean() / fGeomCam->GetPixRatio(pixidx) ;
|
---|
456 | calibConvVar = (avMeanRelVar + pix.GetMeanRelVar()) * calibConv * calibConv;
|
---|
457 | if (pix.IsFFactorMethodValid())
|
---|
458 | {
|
---|
459 | const Float_t convmin1 = qe.GetQECascadesFFactor(zenith)/pix.GetMeanConvFADC2Phe();
|
---|
460 | if (convmin1 > 0)
|
---|
461 | calibFFactor *= TMath::Sqrt(convmin1);
|
---|
462 | else
|
---|
463 | calibFFactor = -1.;
|
---|
464 | }
|
---|
465 | break;
|
---|
466 | case kBlindPixel:
|
---|
467 | if (qe.IsBlindPixelMethodValid())
|
---|
468 | {
|
---|
469 | calibQE = qe.GetQECascadesBlindPixel ( zenith );
|
---|
470 | calibQEVar = qe.GetQECascadesBlindPixelVar( zenith );
|
---|
471 | }
|
---|
472 | else
|
---|
473 | return kFALSE;
|
---|
474 | break;
|
---|
475 | case kPinDiode:
|
---|
476 | if (qe.IsPINDiodeMethodValid())
|
---|
477 | {
|
---|
478 | calibQE = qe.GetQECascadesPINDiode ( zenith );
|
---|
479 | calibQEVar = qe.GetQECascadesPINDiodeVar( zenith );
|
---|
480 | }
|
---|
481 | else
|
---|
482 | return kFALSE;
|
---|
483 | break;
|
---|
484 | case kFfactor:
|
---|
485 | if (pix.IsFFactorMethodValid())
|
---|
486 | {
|
---|
487 | calibQE = qe.GetQECascadesFFactor ( zenith );
|
---|
488 | calibQEVar = qe.GetQECascadesFFactorVar( zenith );
|
---|
489 | }
|
---|
490 | else
|
---|
491 | return kFALSE;
|
---|
492 | break;
|
---|
493 | case kCombined:
|
---|
494 | if (qe.IsCombinedMethodValid())
|
---|
495 | {
|
---|
496 | calibQE = qe.GetQECascadesCombined ( zenith );
|
---|
497 | calibQEVar = qe.GetQECascadesCombinedVar( zenith );
|
---|
498 | }
|
---|
499 | else
|
---|
500 | return kFALSE;
|
---|
501 | break;
|
---|
502 | case kDummy:
|
---|
503 | hiloconv = 1.;
|
---|
504 | hiloconverr = 0.;
|
---|
505 | break;
|
---|
506 |
|
---|
507 | } /* switch calibration mode */
|
---|
508 | } /* if(fCalibrationMode!=kNone) */
|
---|
509 | else
|
---|
510 | {
|
---|
511 | calibConv = 1./fGeomCam->GetPixRatio(pixidx);
|
---|
512 | }
|
---|
513 |
|
---|
514 | calibConv /= calibQE;
|
---|
515 |
|
---|
516 | if (calibConv != 0. && calibQE != 0.)
|
---|
517 | {
|
---|
518 | calibConvVar = calibConvVar/calibConv/calibConv + calibQEVar/calibQE/calibQE;
|
---|
519 | calibConvVar *= calibConv*calibConv;
|
---|
520 | }
|
---|
521 |
|
---|
522 | return kTRUE;
|
---|
523 | }
|
---|
524 |
|
---|
525 |
|
---|
526 | // --------------------------------------------------------------------------
|
---|
527 | //
|
---|
528 | // Apply the calibration factors to the extracted signal according to the
|
---|
529 | // selected calibration method
|
---|
530 | //
|
---|
531 | Int_t MCalibrateData::Process()
|
---|
532 | {
|
---|
533 |
|
---|
534 | /*
|
---|
535 | if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
|
---|
536 | {
|
---|
537 | // FIXME: MExtractedSignal must be of variable size -
|
---|
538 | // like MCerPhotEvt - because we must be able
|
---|
539 | // to reduce size by zero supression
|
---|
540 | // For the moment this check could be done in ReInit...
|
---|
541 | *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
|
---|
542 | return kFALSE;
|
---|
543 | }
|
---|
544 | */
|
---|
545 |
|
---|
546 | UInt_t npix = fSignals->GetSize();
|
---|
547 |
|
---|
548 | Float_t hiloconv;
|
---|
549 | Float_t hiloconverr;
|
---|
550 | Float_t calibrationConversionFactor;
|
---|
551 | Float_t calibrationConversionFactorErr;
|
---|
552 | Float_t calibFFactor;
|
---|
553 |
|
---|
554 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
---|
555 | {
|
---|
556 | if ( !GetConversionFactor(pixidx, hiloconv, hiloconverr,
|
---|
557 | calibrationConversionFactor, calibrationConversionFactorErr, calibFFactor) )
|
---|
558 | continue;
|
---|
559 |
|
---|
560 | MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
---|
561 |
|
---|
562 | Float_t signal;
|
---|
563 | Float_t signalErr = 0.;
|
---|
564 | Float_t nphot,nphotErr;
|
---|
565 |
|
---|
566 | if (sig.IsLoGainUsed())
|
---|
567 | {
|
---|
568 | signal = sig.GetExtractedSignalLoGain()*hiloconv;
|
---|
569 | signalErr = signal*hiloconverr;
|
---|
570 | }
|
---|
571 | else
|
---|
572 | {
|
---|
573 | if (sig.GetExtractedSignalHiGain() > 9999.)
|
---|
574 | {
|
---|
575 | signal = 0.;
|
---|
576 | signalErr = 0.;
|
---|
577 | }
|
---|
578 | else
|
---|
579 | signal = sig.GetExtractedSignalHiGain();
|
---|
580 | }
|
---|
581 |
|
---|
582 | nphot = signal*calibrationConversionFactor;
|
---|
583 | nphotErr = calibFFactor*TMath::Sqrt(TMath::Abs(nphot));
|
---|
584 | //
|
---|
585 | // The following part is the commented first version of the error calculation
|
---|
586 | // Contact Markus Gaug for questions (or wait for the next documentation update...)
|
---|
587 | //
|
---|
588 | /*
|
---|
589 | nphotErr = signal > 0 ? signalErr*signalErr / (signal * signal) : 0.
|
---|
590 | + calibConv > 0 ? calibConvVar / (calibConv * calibConv ) : 0.;
|
---|
591 | nphotErr = TMath::Sqrt(nphotErr) * nphot;
|
---|
592 | */
|
---|
593 |
|
---|
594 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
---|
595 |
|
---|
596 | if (sig.GetNumHiGainSaturated() > 0)
|
---|
597 | cpix->SetPixelHGSaturated();
|
---|
598 |
|
---|
599 | if (sig.GetNumLoGainSaturated() > 0)
|
---|
600 | cpix->SetPixelSaturated();
|
---|
601 | }
|
---|
602 |
|
---|
603 | fCerPhotEvt->FixSize();
|
---|
604 | fCerPhotEvt->SetReadyToSave();
|
---|
605 |
|
---|
606 | if(TestFlag(kEvent))
|
---|
607 | if (!CalibratePedestal(fPedestalFromData,fPedPhotFromData))
|
---|
608 | return kFALSE;
|
---|
609 |
|
---|
610 | /*
|
---|
611 | //
|
---|
612 | // fill MPedPhot(FromData) container using the informations from
|
---|
613 | // MPedestalCam, MExtractedSignalCam and MCalibrationCam
|
---|
614 | //
|
---|
615 | fNumUsedHiGainFADCSlices = fSignals->GetNumUsedHiGainFADCSlices();
|
---|
616 |
|
---|
617 | // is pixid equal to pixidx ?
|
---|
618 | if ( (Int_t)(fPedestal->GetSize()) != fSignals->GetSize())
|
---|
619 | {
|
---|
620 | *fLog << err << "MCalibrateData::ReInit(); sizes of MPedestalCam and MCalibrationCam are different"
|
---|
621 | << endl;
|
---|
622 | }
|
---|
623 | */
|
---|
624 |
|
---|
625 | /*
|
---|
626 | *fLog << all << "MCalibrateData::ReInit(); fill MPedPhotCam container"
|
---|
627 | << endl;
|
---|
628 | *fLog << all << " fNumUsedHiGainADCSlices = "
|
---|
629 | << fNumUsedHiGainFADCSlices << endl;
|
---|
630 | *fLog << all << " pixid, calibrationConversionFactor, ped, pedRMS, pedphot, pedphotRMS :"
|
---|
631 | << endl;
|
---|
632 | */ /*
|
---|
633 | for (Int_t pixid=0; pixid<fPedestalFromData->GetSize(); pixid++)
|
---|
634 | {
|
---|
635 | const MPedestalPix &ped = (*fPedestalFromData)[pixid];
|
---|
636 |
|
---|
637 | // pedestals/(used FADC slices) in [ADC] counts
|
---|
638 | Float_t pedes = ped.GetPedestal() * fNumUsedHiGainFADCSlices;
|
---|
639 | Float_t pedrms = ped.GetPedestalRms() * sqrt(fNumUsedHiGainFADCSlices);
|
---|
640 |
|
---|
641 | //----------------------------------
|
---|
642 | // get phe/ADC conversion factor
|
---|
643 |
|
---|
644 | Float_t hiloconv;
|
---|
645 | Float_t hiloconverr;
|
---|
646 | Float_t calibConv;
|
---|
647 | Float_t calibFFactor;
|
---|
648 |
|
---|
649 | if ( !GetConversionFactor(pixid, hiloconv, hiloconverr,
|
---|
650 | calibConv, calibFFactor ))
|
---|
651 | continue;
|
---|
652 |
|
---|
653 | //----------------------------------
|
---|
654 |
|
---|
655 | // pedestals/(used FADC slices) in [number of photons]
|
---|
656 | Float_t pedphot = pedes * calibConv;
|
---|
657 | Float_t pedphotrms = pedrms * calibConv;
|
---|
658 |
|
---|
659 | (*fPedPhotFromData)[pixid].Set(pedphot, pedphotrms);
|
---|
660 |
|
---|
661 | // *fLog << all << pixid << ", " << calibConv << ", "
|
---|
662 | // << ped.GetPedestal() << ", " << ped.GetPedestalRms() << ", "
|
---|
663 | // << pedphot << ", " << pedphotrms << endl;
|
---|
664 | }
|
---|
665 |
|
---|
666 | //---------------------------------------------
|
---|
667 |
|
---|
668 | fPedPhotFromData->SetReadyToSave();
|
---|
669 |
|
---|
670 | }
|
---|
671 | */
|
---|
672 |
|
---|
673 | return kTRUE;
|
---|
674 | }
|
---|
675 |
|
---|
676 | // --------------------------------------------------------------------------
|
---|
677 | //
|
---|
678 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
679 | // to a macro. In the original root implementation it is used to write
|
---|
680 | // gui elements to a macro-file.
|
---|
681 | //
|
---|
682 | void MCalibrateData::StreamPrimitive(ofstream &out) const
|
---|
683 | {
|
---|
684 |
|
---|
685 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
686 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
687 |
|
---|
688 | if (TestFlag(kEvent))
|
---|
689 | out << " " << GetUniqueName() << ".EnablePedestalType(kEvent)" << endl;
|
---|
690 | if (TestFlag(kRun))
|
---|
691 | out << " " << GetUniqueName() << ".EnablePedestalType(kRun)" << endl;
|
---|
692 |
|
---|
693 | if (fCalibrationMode != kDefault)
|
---|
694 | out << " " << GetUniqueName() << ".SetCalibrationMode(fCalibrationMode)" << endl;
|
---|
695 |
|
---|
696 | if (fNamePedADCRunContainer != fgNamePedADCRunContainer)
|
---|
697 | {
|
---|
698 | out << " " << GetUniqueName() << ".SetNamePedADCRunContainer(";
|
---|
699 | out << fNamePedADCRunContainer.Data() << ");" << endl;
|
---|
700 | }
|
---|
701 |
|
---|
702 | if (fNamePedADCEventContainer != fgNamePedADCEventContainer)
|
---|
703 | {
|
---|
704 | out << " " << GetUniqueName() << ".SetNamePedADCEventContainer(";
|
---|
705 | out << fNamePedADCEventContainer.Data() << ");" << endl;
|
---|
706 | }
|
---|
707 |
|
---|
708 |
|
---|
709 | if (fNamePedPhotRunContainer != fgNamePedPhotRunContainer)
|
---|
710 | {
|
---|
711 | out << " " << GetUniqueName() << ".SetNamePedPhotRunContainer(";
|
---|
712 | out << fNamePedPhotRunContainer.Data() << ");" << endl;
|
---|
713 | }
|
---|
714 |
|
---|
715 |
|
---|
716 | if (fNamePedPhotEventContainer != fNamePedPhotEventContainer)
|
---|
717 | {
|
---|
718 | out << " " << GetUniqueName() << ".SetNamePedPhotEventContainer(";
|
---|
719 | out << fNamePedPhotEventContainer.Data() << ");" << endl;
|
---|
720 | }
|
---|
721 |
|
---|
722 | }
|
---|
723 |
|
---|
724 |
|
---|