source: trunk/MagicSoft/Mars/mcalib/MCalibrate.cc@ 3786

Last change on this file since 3786 was 3751, checked in by gaug, 21 years ago
*** empty log message ***
File size: 11.3 KB
Line 
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
83ClassImp(MCalibrate);
84
85using namespace std;
86// --------------------------------------------------------------------------
87//
88// Default constructor.
89//
90MCalibrate::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//
111Int_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//
157Bool_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//
219Int_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 = 1.;
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
259 if (fBadPixels)
260 {
261 MBadPixelsPix &bad = (*fBadPixels)[pixidx];
262 if (!bad.IsCalibrationResultOK())
263 continue;
264 }
265
266 calibConv = pix.GetMeanConvFADC2Phe();
267 calibConvVar = pix.GetMeanConvFADC2PheVar();
268 calibFFactor = pix.GetMeanFFactorFADC2Phot();
269
270 switch(fCalibrationMode)
271 {
272 case kBlindPixel:
273 if (qe.IsBlindPixelMethodValid())
274 {
275 calibQE = qe.GetQECascadesBlindPixel ( zenith );
276 calibQEVar = qe.GetQECascadesBlindPixelVar( zenith );
277 }
278 else
279 continue;
280 break;
281 case kPinDiode:
282 if (qe.IsPINDiodeMethodValid())
283 {
284 calibQE = qe.GetQECascadesPINDiode ( zenith );
285 calibQEVar = qe.GetQECascadesPINDiodeVar( zenith );
286 }
287 else
288 continue;
289 break;
290 case kFfactor:
291 if (pix.IsFFactorMethodValid())
292 {
293 calibQE = qe.GetQECascadesFFactor ( zenith );
294 calibQEVar = qe.GetQECascadesFFactorVar( zenith );
295 }
296 else
297 continue;
298 break;
299 case kCombined:
300 if (qe.IsCombinedMethodValid())
301 {
302 calibQE = qe.GetQECascadesCombined ( zenith );
303 calibQEVar = qe.GetQECascadesCombinedVar( zenith );
304 }
305 else
306 continue;
307 break;
308 case kDummy:
309 hiloconv = 1.;
310 hiloconverr = 0.;
311 calibQE = 1.;
312 calibQEVar = 0.;
313 break;
314
315 } /* switch calibration mode */
316
317 hiloconv = pix.GetConversionHiLo ();
318 hiloconverr= pix.GetConversionHiLoErr();
319
320 } /* if(fCalibrationMode!=kNone) */
321 else
322 {
323 hiloconv = 1.;
324 hiloconverr = 0.;
325 calibConv = 1.;
326 calibConvVar = 0.;
327 calibFFactor = 0.;
328 calibQE = 1.;
329 calibQEVar = 0.;
330 }
331 MExtractedSignalPix &sig = (*fSignals)[pixidx];
332
333 Float_t signal;
334 Float_t signalErr = 0.;
335 Float_t nphot,nphotErr;
336
337 if (sig.IsLoGainUsed())
338 {
339 signal = sig.GetExtractedSignalLoGain()*hiloconv;
340 signalErr = signal*hiloconverr;
341 }
342 else
343 {
344 if (sig.GetExtractedSignalHiGain() > 9999.)
345 {
346 signal = 0.;
347 signalErr = 0.;
348 }
349 else
350 signal = sig.GetExtractedSignalHiGain();
351 }
352
353 nphot = signal*calibConv/calibQE;
354 nphotErr = calibFFactor*TMath::Sqrt(nphot);
355
356 //
357 // The following part is the outcommented first version of the error calculation
358 // Contact Markus Gaug for questions (or wait for the next documentation update...)
359 //
360 /*
361 nphotErr = signal > 0 ? signalErr*signalErr / (signal * signal) : 0.
362 + calibConv > 0 ? calibConvVar / (calibConv * calibConv ) : 0.
363 + calibQE > 0 ? calibQEVar / (calibQE * calibQE ) : 0.;
364 nphotErr = TMath::Sqrt(nphotErr) * nphot;
365 */
366
367 MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
368
369 if (sig.GetNumLoGainSaturated() > 0)
370 cpix->SetPixelSaturated();
371
372 if (sig.GetNumHiGainSaturated() > 0)
373 cpix->SetPixelHGSaturated();
374
375
376 } /* for (UInt_t pixidx=0; pixidx<npix; pixidx++) */
377
378 fCerPhotEvt->FixSize();
379 fCerPhotEvt->SetReadyToSave();
380
381 return kTRUE;
382}
Note: See TracBrowser for help on using the repository browser.