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

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