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