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

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