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): Markus Gaug 02/2004 <mailto:markus@ifae.es>
|
---|
21 | !
|
---|
22 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
23 | !
|
---|
24 | !
|
---|
25 | \* ======================================================================== */
|
---|
26 |
|
---|
27 | //////////////////////////////////////////////////////////////////////////////
|
---|
28 | //
|
---|
29 | // MCalibrate
|
---|
30 | //
|
---|
31 | // This task takes the integrated charge from MExtractedSignal and apply
|
---|
32 | // the calibration constants from MCalibraitionCam to convert the summed FADC
|
---|
33 | // slices to photons. The number of photons obtained is stored in MCerPhotEvt.
|
---|
34 | //
|
---|
35 | // Selection of different calibration methods is possible through the
|
---|
36 | // SetCalibrationMode member function
|
---|
37 | //
|
---|
38 | // The calibration modes which exclude non-valid pixels are the following:
|
---|
39 | //
|
---|
40 | // kFfactor: calibrates using the F-Factor method
|
---|
41 | // kBlindpixel: calibrates using the BlindPixel method
|
---|
42 | // kBlindpixel: calibrates using the BlindPixel method
|
---|
43 | // kDummy: calibrates with fixed conversion factors of 1 and errors of 0.
|
---|
44 | //
|
---|
45 | // The calibration modes which include all pixels regardless of their validity is:
|
---|
46 | //
|
---|
47 | // kNone: calibrates with fixed conversion factors of 1 and errors of 0.
|
---|
48 | //
|
---|
49 | // Use the kDummy and kNone methods ONLY FOR DEBUGGING!
|
---|
50 | //
|
---|
51 | // Input Containers:
|
---|
52 | // MExtractedSingal
|
---|
53 | // MCalibrationChargeCam
|
---|
54 | //
|
---|
55 | // Output Containers:
|
---|
56 | // MCerPhotEvt
|
---|
57 | //
|
---|
58 | //////////////////////////////////////////////////////////////////////////////
|
---|
59 | #include "MCalibrate.h"
|
---|
60 |
|
---|
61 | #include "MLog.h"
|
---|
62 | #include "MLogManip.h"
|
---|
63 |
|
---|
64 | #include "MParList.h"
|
---|
65 | #include "MH.h"
|
---|
66 |
|
---|
67 | #include "MGeomCam.h"
|
---|
68 |
|
---|
69 | #include "MCalibrationChargeCam.h"
|
---|
70 | #include "MCalibrationChargePix.h"
|
---|
71 |
|
---|
72 | #include "MCalibrationQECam.h"
|
---|
73 | #include "MCalibrationQEPix.h"
|
---|
74 |
|
---|
75 | #include "MExtractedSignalCam.h"
|
---|
76 | #include "MExtractedSignalPix.h"
|
---|
77 |
|
---|
78 | #include "MBadPixelsCam.h"
|
---|
79 | #include "MBadPixelsPix.h"
|
---|
80 |
|
---|
81 | #include "MCerPhotEvt.h"
|
---|
82 |
|
---|
83 | ClassImp(MCalibrate);
|
---|
84 |
|
---|
85 | using namespace std;
|
---|
86 | // --------------------------------------------------------------------------
|
---|
87 | //
|
---|
88 | // Default constructor.
|
---|
89 | //
|
---|
90 | MCalibrate::MCalibrate(CalibrationMode_t calmode,const char *name, const char *title)
|
---|
91 | : fGeomCam(NULL), fCalibrations(NULL), fQEs(NULL), fBadPixels(NULL), fSignals(NULL),
|
---|
92 | fCerPhotEvt(NULL), fCalibrationMode(calmode)
|
---|
93 | {
|
---|
94 | fName = name ? name : "MCalibrate";
|
---|
95 | fTitle = title ? title : "Task to calculate the number of photons in one event";
|
---|
96 | }
|
---|
97 |
|
---|
98 | // --------------------------------------------------------------------------
|
---|
99 | //
|
---|
100 | // The PreProcess searches for the following input containers:
|
---|
101 | // - MGeomCam
|
---|
102 | // - MCalibrationChargeCam
|
---|
103 | // - MExtractedSignalCam
|
---|
104 | // - MBadPixelsCam
|
---|
105 | //
|
---|
106 | // The following output containers are also searched and created if
|
---|
107 | // they were not found:
|
---|
108 | //
|
---|
109 | // - MCerPhotEvt
|
---|
110 | //
|
---|
111 | Int_t MCalibrate::PreProcess(MParList *pList)
|
---|
112 | {
|
---|
113 |
|
---|
114 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
---|
115 |
|
---|
116 | if (!fSignals)
|
---|
117 | {
|
---|
118 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
---|
119 | return kFALSE;
|
---|
120 | }
|
---|
121 |
|
---|
122 | fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
|
---|
123 | if (!fBadPixels)
|
---|
124 | *fLog << warn << AddSerialNumber("MBadPixelsCam") << " not found ... no action" << endl;
|
---|
125 |
|
---|
126 | if(fCalibrationMode>kNone)
|
---|
127 | {
|
---|
128 |
|
---|
129 | fCalibrations = (MCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
---|
130 | if (!fCalibrations)
|
---|
131 | {
|
---|
132 | *fLog << err << AddSerialNumber("MCalibrationChargeCam") << " not found ... aborting." << endl;
|
---|
133 | return kFALSE;
|
---|
134 | }
|
---|
135 |
|
---|
136 | fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
|
---|
137 | if (!fQEs)
|
---|
138 | {
|
---|
139 | *fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
|
---|
140 | return kFALSE;
|
---|
141 | }
|
---|
142 |
|
---|
143 | }
|
---|
144 |
|
---|
145 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
---|
146 | if (!fCerPhotEvt)
|
---|
147 | return kFALSE;
|
---|
148 |
|
---|
149 | return kTRUE;
|
---|
150 | }
|
---|
151 |
|
---|
152 | // --------------------------------------------------------------------------
|
---|
153 | //
|
---|
154 | // Check for validity of the selected calibration method, switch to a
|
---|
155 | // different one in case of need
|
---|
156 | //
|
---|
157 | Bool_t MCalibrate::ReInit(MParList *pList)
|
---|
158 | {
|
---|
159 |
|
---|
160 | if(fCalibrationMode == kBlindPixel && !fQEs->IsBlindPixelMethodValid())
|
---|
161 | {
|
---|
162 | *fLog << warn << GetDescriptor()
|
---|
163 | << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
|
---|
164 | fCalibrationMode = kFfactor;
|
---|
165 | }
|
---|
166 |
|
---|
167 | if(fCalibrationMode == kPinDiode && !fQEs->IsPINDiodeMethodValid())
|
---|
168 | {
|
---|
169 | *fLog << warn << GetDescriptor()
|
---|
170 | << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
|
---|
171 | fCalibrationMode = kFfactor;
|
---|
172 | }
|
---|
173 |
|
---|
174 | if(fCalibrationMode == kCombined && !fQEs->IsCombinedMethodValid())
|
---|
175 | {
|
---|
176 | *fLog << warn << GetDescriptor()
|
---|
177 | << "Warning: Combined calibration method not valid, switching to F-factor method" << endl;
|
---|
178 | fCalibrationMode = kFfactor;
|
---|
179 | }
|
---|
180 |
|
---|
181 | switch(fCalibrationMode)
|
---|
182 | {
|
---|
183 | case kBlindPixel:
|
---|
184 | break;
|
---|
185 | case kFfactor:
|
---|
186 | break;
|
---|
187 | case kPinDiode:
|
---|
188 | *fLog << err << GetDescriptor()
|
---|
189 | << ": PIN Diode Calibration mode not yet available " << endl;
|
---|
190 | return kFALSE;
|
---|
191 | break;
|
---|
192 | case kCombined:
|
---|
193 | *fLog << err << GetDescriptor()
|
---|
194 | << ": Combined Calibration mode not yet available " << endl;
|
---|
195 | return kFALSE;
|
---|
196 | break;
|
---|
197 | case kDummy:
|
---|
198 | *fLog << warn << GetDescriptor()
|
---|
199 | << ": WARNING: Dummy calibration, no calibration applied!!" << endl;
|
---|
200 | break;
|
---|
201 | case kNone:
|
---|
202 | *fLog << warn << GetDescriptor()
|
---|
203 | << ": WARNING: No calibration applied!!" << endl;
|
---|
204 | break;
|
---|
205 | default:
|
---|
206 | *fLog << warn << GetDescriptor()
|
---|
207 | << ": WARNING: Calibration mode value ("
|
---|
208 | <<fCalibrationMode<<") not known" << endl;
|
---|
209 | return kFALSE;
|
---|
210 | }
|
---|
211 |
|
---|
212 | return kTRUE;
|
---|
213 | }
|
---|
214 | // --------------------------------------------------------------------------
|
---|
215 | //
|
---|
216 | // Apply the calibration factors to the extracted signal according to the
|
---|
217 | // selected calibration method
|
---|
218 | //
|
---|
219 | Int_t MCalibrate::Process()
|
---|
220 | {
|
---|
221 |
|
---|
222 | //
|
---|
223 | // For the moment, we use only a dummy zenith for the calibration:
|
---|
224 | //
|
---|
225 | const Float_t zenith = 0;
|
---|
226 |
|
---|
227 | /*
|
---|
228 | if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
|
---|
229 | {
|
---|
230 | // FIXME: MExtractedSignal must be of variable size -
|
---|
231 | // like MCerPhotEvt - because we must be able
|
---|
232 | // to reduce size by zero supression
|
---|
233 | // For the moment this check could be done in ReInit...
|
---|
234 | *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
|
---|
235 | return kFALSE;
|
---|
236 | }
|
---|
237 | */
|
---|
238 |
|
---|
239 | UInt_t npix = fSignals->GetSize();
|
---|
240 |
|
---|
241 | Float_t hiloconv = 0.;
|
---|
242 | Float_t hiloconverr = 0.;
|
---|
243 | Float_t calibConv = 0.;
|
---|
244 | Float_t calibConvVar = 0.;
|
---|
245 | Float_t calibFFactor = 0.;
|
---|
246 | Float_t calibQE = 0.;
|
---|
247 | Float_t calibQEVar = 0.;
|
---|
248 |
|
---|
249 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
---|
250 | {
|
---|
251 |
|
---|
252 | if(fCalibrationMode!=kNone)
|
---|
253 | {
|
---|
254 |
|
---|
255 |
|
---|
256 | MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCalibrations)[pixidx];
|
---|
257 | MCalibrationQEPix &qe = (MCalibrationQEPix&) (*fQEs )[pixidx];
|
---|
258 | MBadPixelsPix &bad = (*fBadPixels)[pixidx];
|
---|
259 |
|
---|
260 | if (fBadPixels)
|
---|
261 | if (!bad.IsCalibrationResultOK())
|
---|
262 | continue;
|
---|
263 |
|
---|
264 | calibConv = pix.GetMeanConvFADC2Phe();
|
---|
265 | calibConvVar = pix.GetMeanConvFADC2PheVar();
|
---|
266 | calibFFactor = pix.GetMeanFFactorFADC2Phot();
|
---|
267 |
|
---|
268 | switch(fCalibrationMode)
|
---|
269 | {
|
---|
270 | case kBlindPixel:
|
---|
271 | if (qe.IsBlindPixelMethodValid())
|
---|
272 | {
|
---|
273 | calibQE = qe.GetQECascadesBlindPixel ( zenith );
|
---|
274 | calibQEVar = qe.GetQECascadesBlindPixelVar( zenith );
|
---|
275 | }
|
---|
276 | else
|
---|
277 | continue;
|
---|
278 | break;
|
---|
279 | case kPinDiode:
|
---|
280 | if (qe.IsPINDiodeMethodValid())
|
---|
281 | {
|
---|
282 | calibQE = qe.GetQECascadesPINDiode ( zenith );
|
---|
283 | calibQEVar = qe.GetQECascadesPINDiodeVar( zenith );
|
---|
284 | }
|
---|
285 | else
|
---|
286 | continue;
|
---|
287 | break;
|
---|
288 | case kFfactor:
|
---|
289 | if (pix.IsFFactorMethodValid())
|
---|
290 | {
|
---|
291 | calibQE = qe.GetQECascadesFFactor ( zenith );
|
---|
292 | calibQEVar = qe.GetQECascadesFFactorVar( zenith );
|
---|
293 | }
|
---|
294 | else
|
---|
295 | continue;
|
---|
296 | break;
|
---|
297 | case kCombined:
|
---|
298 | if (qe.IsCombinedMethodValid())
|
---|
299 | {
|
---|
300 | calibQE = qe.GetQECascadesCombined ( zenith );
|
---|
301 | calibQEVar = qe.GetQECascadesCombinedVar( zenith );
|
---|
302 | }
|
---|
303 | else
|
---|
304 | continue;
|
---|
305 | break;
|
---|
306 | case kDummy:
|
---|
307 | hiloconv = 1.;
|
---|
308 | hiloconverr = 0.;
|
---|
309 | calibQE = 1.;
|
---|
310 | calibQEVar = 0.;
|
---|
311 | break;
|
---|
312 |
|
---|
313 | } /* switch calibration mode */
|
---|
314 |
|
---|
315 | hiloconv = pix.GetConversionHiLo ();
|
---|
316 | hiloconverr= pix.GetConversionHiLoErr();
|
---|
317 |
|
---|
318 | } /* if(fCalibrationMode!=kNone) */
|
---|
319 | else
|
---|
320 | {
|
---|
321 | hiloconv = 1.;
|
---|
322 | hiloconverr = 0.;
|
---|
323 | calibConv = 1.;
|
---|
324 | calibConvVar = 0.;
|
---|
325 | calibFFactor = 0.;
|
---|
326 | calibQE = 1.;
|
---|
327 | calibQEVar = 0.;
|
---|
328 | }
|
---|
329 | MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
---|
330 |
|
---|
331 | Float_t signal;
|
---|
332 | Float_t signalErr = 0.;
|
---|
333 | Float_t nphot,nphotErr;
|
---|
334 |
|
---|
335 | if (sig.IsLoGainUsed())
|
---|
336 | {
|
---|
337 | signal = sig.GetExtractedSignalLoGain()*hiloconv;
|
---|
338 | signalErr = signal*hiloconverr;
|
---|
339 | }
|
---|
340 | else
|
---|
341 | {
|
---|
342 | if (sig.GetExtractedSignalHiGain() > 9999.)
|
---|
343 | {
|
---|
344 | signal = 0.;
|
---|
345 | signalErr = 0.;
|
---|
346 | }
|
---|
347 | else
|
---|
348 | signal = sig.GetExtractedSignalHiGain();
|
---|
349 | }
|
---|
350 |
|
---|
351 | nphot = signal*calibConv/calibQE;
|
---|
352 | nphotErr = calibFFactor*TMath::Sqrt(nphot);
|
---|
353 |
|
---|
354 | //
|
---|
355 | // The following part is the outcommented first version of the error calculation
|
---|
356 | // Contact Markus Gaug for questions (or wait for the next documentation update...)
|
---|
357 | //
|
---|
358 | /*
|
---|
359 | nphotErr = signal > 0 ? signalErr*signalErr / (signal * signal) : 0.
|
---|
360 | + calibConv > 0 ? calibConvVar / (calibConv * calibConv ) : 0.
|
---|
361 | + calibQE > 0 ? calibQEVar / (calibQE * calibQE ) : 0.;
|
---|
362 | nphotErr = TMath::Sqrt(nphotErr) * nphot;
|
---|
363 | */
|
---|
364 |
|
---|
365 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
---|
366 |
|
---|
367 | if (sig.GetNumLoGainSaturated() > 0)
|
---|
368 | cpix->SetPixelSaturated();
|
---|
369 |
|
---|
370 | if (sig.GetNumHiGainSaturated() > 0)
|
---|
371 | cpix->SetPixelHGSaturated();
|
---|
372 |
|
---|
373 |
|
---|
374 | } /* for (UInt_t pixidx=0; pixidx<npix; pixidx++) */
|
---|
375 |
|
---|
376 | fCerPhotEvt->FixSize();
|
---|
377 | fCerPhotEvt->SetReadyToSave();
|
---|
378 |
|
---|
379 | return kTRUE;
|
---|
380 | }
|
---|