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

Last change on this file since 3492 was 3480, checked in by gaug, 21 years ago
*** empty log message ***
File size: 10.0 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 "MExtractedSignalCam.h"
73#include "MExtractedSignalPix.h"
74
75#include "MBadPixelsCam.h"
76#include "MBadPixelsPix.h"
77
78#include "MCerPhotEvt.h"
79
80ClassImp(MCalibrate);
81
82using namespace std;
83// --------------------------------------------------------------------------
84//
85// Default constructor.
86//
87MCalibrate::MCalibrate(CalibrationMode_t calmode,const char *name, const char *title)
88 : fGeomCam(NULL), fCalibrations(NULL), fBadPixels(NULL), fSignals(NULL),
89 fCerPhotEvt(NULL), fCalibrationMode(calmode)
90{
91 fName = name ? name : "MCalibrate";
92 fTitle = title ? title : "Task to calculate the number of photons in one event";
93}
94
95// --------------------------------------------------------------------------
96//
97// The PreProcess searches for the following input containers:
98// - MGeomCam
99// - MCalibrationChargeCam
100// - MExtractedSignalCam
101// - MBadPixelsCam
102//
103// The following output containers are also searched and created if
104// they were not found:
105//
106// - MCerPhotEvt
107//
108Int_t MCalibrate::PreProcess(MParList *pList)
109{
110
111 fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
112
113 if (!fSignals)
114 {
115 *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
116 return kFALSE;
117 }
118
119 fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
120 if (!fBadPixels)
121 *fLog << warn << AddSerialNumber("MBadPixelsCam") << " not found ... no action" << endl;
122
123 if(fCalibrationMode>kNone)
124 {
125
126 fCalibrations = (MCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
127 if (!fCalibrations)
128 {
129 *fLog << err << AddSerialNumber("MCalibrationChargeCam") << " not found ... aborting." << endl;
130 return kFALSE;
131 }
132
133 }
134
135 fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
136 if (!fCerPhotEvt)
137 return kFALSE;
138
139 return kTRUE;
140}
141
142// --------------------------------------------------------------------------
143//
144// Check for validity of the selected calibration method, switch to a
145// different one in case of need
146//
147Bool_t MCalibrate::ReInit(MParList *pList)
148{
149
150 if(fCalibrationMode == kBlindPixel && !fCalibrations->IsBlindPixelMethodValid())
151 {
152 *fLog << warn << GetDescriptor() << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
153 fCalibrationMode = kFfactor;
154 }
155
156 if(fCalibrationMode == kPinDiode && !fCalibrations->IsPINDiodeMethodValid())
157 {
158 *fLog << warn << GetDescriptor() << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
159 fCalibrationMode = kFfactor;
160 }
161
162 switch(fCalibrationMode)
163 {
164 case kBlindPixel:
165 break;
166 case kFfactor:
167 break;
168 case kPinDiode:
169 *fLog << err << GetDescriptor()
170 << ": PIN Diode Calibration mode not yet available " << endl;
171 return kFALSE;
172 break;
173 case kCombined:
174 *fLog << err << GetDescriptor()
175 << ": Combined Calibration mode not yet available " << endl;
176 return kFALSE;
177 break;
178 case kDummy:
179 *fLog << warn << GetDescriptor()
180 << ": WARNING: Dummy calibration, no calibration applied!!" << endl;
181 break;
182 case kNone:
183 *fLog << warn << GetDescriptor()
184 << ": WARNING: No calibration applied!!" << endl;
185 break;
186 default:
187 *fLog << warn << GetDescriptor()
188 << ": WARNING: Calibration mode value ("
189 <<fCalibrationMode<<") not known" << endl;
190 return kFALSE;
191 }
192
193 return kTRUE;
194}
195// --------------------------------------------------------------------------
196//
197// Apply the calibration factors to the extracted signal according to the
198// selected calibration method
199//
200Int_t MCalibrate::Process()
201{
202 /*
203 if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
204 {
205 // FIXME: MExtractedSignal must be of variable size -
206 // like MCerPhotEvt - because we must be able
207 // to reduce size by zero supression
208 // For the moment this check could be done in ReInit...
209 *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
210 return kFALSE;
211 }
212 */
213
214 UInt_t npix = fSignals->GetSize();
215
216 Float_t hiloconv = 0.;
217 Float_t hiloconverr = 0.;
218 Float_t calibrationConversionFactor = 0.;
219 Float_t calibrationConversionFactorErr = 0.;
220
221 for (UInt_t pixidx=0; pixidx<npix; pixidx++)
222 {
223
224 if(fCalibrationMode!=kNone)
225 {
226
227
228 MCalibrationChargePix &pix = (*fCalibrations)[pixidx];
229 MBadPixelsPix &bad = (*fBadPixels)[pixidx];
230
231 if (fBadPixels)
232 if (!bad.IsCalibrationResultOK())
233 continue;
234
235 switch(fCalibrationMode)
236 {
237 case kBlindPixel:
238 if (pix.IsBlindPixelMethodValid())
239 {
240 calibrationConversionFactor = pix.GetMeanConversionBlindPixelMethod();
241 calibrationConversionFactorErr = pix.GetConversionBlindPixelMethodErr();
242 }
243 else
244 continue;
245 break;
246 case kPinDiode:
247 if (pix.IsPINDiodeMethodValid())
248 {
249 calibrationConversionFactor = pix.GetMeanConversionPINDiodeMethod();
250 calibrationConversionFactorErr = pix.GetConversionPINDiodeMethodErr();
251 }
252 else
253 continue;
254 break;
255 case kFfactor:
256 if (pix.IsFFactorMethodValid())
257 {
258 calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
259 calibrationConversionFactorErr = pix.GetConversionFFactorMethodErr();
260 }
261 else
262 continue;
263 break;
264 case kCombined:
265 if (pix.IsCombinedMethodValid())
266 {
267 calibrationConversionFactor = pix.GetMeanConversionCombinedMethod();
268 calibrationConversionFactorErr = pix.GetConversionCombinedMethodErr();
269 }
270 else
271 continue;
272 break;
273 case kDummy:
274 hiloconv = 1.;
275 hiloconverr = 0.;
276 calibrationConversionFactor = 1.;
277 calibrationConversionFactorErr = 0.;
278 break;
279
280 } /* switch calibration mode */
281
282 hiloconv = pix.GetConversionHiLo();
283 hiloconverr= pix.GetConversionHiLoErr();
284
285 } /* if(fCalibrationMode!=kNone) */
286 else
287 {
288 hiloconv = 1.;
289 hiloconverr = 0.;
290 calibrationConversionFactor = 1.;
291 calibrationConversionFactorErr = 0.;
292 }
293 MExtractedSignalPix &sig = (*fSignals)[pixidx];
294
295 Float_t signal;
296 Float_t signalErr = 0.;
297 Float_t nphot,nphotErr;
298
299 if (sig.IsLoGainUsed())
300 {
301 signal = sig.GetExtractedSignalLoGain()*hiloconv;
302 signalErr = signal*hiloconverr;
303 }
304 else
305 {
306 if (sig.GetExtractedSignalHiGain() > 9999.)
307 {
308 signal = 0.;
309 signalErr = 0.;
310 }
311 else
312 signal = sig.GetExtractedSignalHiGain();
313 }
314
315 nphot = signal*calibrationConversionFactor;
316 nphotErr = signal*calibrationConversionFactorErr
317 *signal*calibrationConversionFactorErr
318 + signalErr*calibrationConversionFactor
319 *signalErr*calibrationConversionFactor;
320
321 nphotErr = TMath::Sqrt(nphotErr);
322
323 MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
324
325 if (sig.GetNumLoGainSaturated() > 0)
326 cpix->SetPixelSaturated();
327
328 if (sig.GetNumHiGainSaturated() > 0)
329 cpix->SetPixelHGSaturated();
330
331
332 } /* for (UInt_t pixidx=0; pixidx<npix; pixidx++) */
333
334 fCerPhotEvt->FixSize();
335 fCerPhotEvt->SetReadyToSave();
336
337 return kTRUE;
338}
Note: See TracBrowser for help on using the repository browser.