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