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): Wolfgang Wittek 02/2004 <mailto:wittek@mppmu.mpg.de>
|
---|
21 | !
|
---|
22 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
23 | !
|
---|
24 | !
|
---|
25 | \* ======================================================================== */
|
---|
26 |
|
---|
27 | //////////////////////////////////////////////////////////////////////////////
|
---|
28 | //
|
---|
29 | // MCalibrateData
|
---|
30 | //
|
---|
31 | // This task takes the integrated charge from MExtractedSignal and apply
|
---|
32 | // the calibration constants from MCalibraitionCam to the charge. Then
|
---|
33 | // stores number of photons obtained in MCerPhotEvt. Selection of different
|
---|
34 | // calibration methods is allowed through SetCalibrationMode member function
|
---|
35 | //
|
---|
36 | // in ReInit the MPedPhotCam container is filled using the information from
|
---|
37 | // MPedestalCam, MExtractedSignalCam and MCalibrationCam
|
---|
38 | //
|
---|
39 | // Input Containers:
|
---|
40 | // MPedestalCam
|
---|
41 | // MExtractedSingalCam
|
---|
42 | // MCalibrationCam
|
---|
43 | //
|
---|
44 | // Output Containers:
|
---|
45 | // MPedPhotCam
|
---|
46 | // MCerPhotEvt
|
---|
47 | //
|
---|
48 | //////////////////////////////////////////////////////////////////////////////
|
---|
49 | #include "MCalibrateData.h"
|
---|
50 |
|
---|
51 | #include "MLog.h"
|
---|
52 | #include "MLogManip.h"
|
---|
53 |
|
---|
54 | #include "MParList.h"
|
---|
55 | #include "MH.h"
|
---|
56 |
|
---|
57 | #include "MGeomCam.h"
|
---|
58 |
|
---|
59 | #include "MPedestalCam.h"
|
---|
60 | #include "MPedestalPix.h"
|
---|
61 |
|
---|
62 | #include "MCalibrationCam.h"
|
---|
63 | #include "MCalibrationPix.h"
|
---|
64 |
|
---|
65 | #include "MExtractedSignalCam.h"
|
---|
66 | #include "MExtractedSignalPix.h"
|
---|
67 |
|
---|
68 | #include "MPedPhotCam.h"
|
---|
69 | #include "MPedPhotPix.h"
|
---|
70 |
|
---|
71 | #include "MCerPhotEvt.h"
|
---|
72 |
|
---|
73 | ClassImp(MCalibrateData);
|
---|
74 |
|
---|
75 | using namespace std;
|
---|
76 | // --------------------------------------------------------------------------
|
---|
77 | //
|
---|
78 | // Default constructor.
|
---|
79 | //
|
---|
80 | MCalibrateData::MCalibrateData(CalibrationMode_t calmode,const char *name, const char *title) : fCalibrationMode(calmode)
|
---|
81 | {
|
---|
82 | fName = name ? name : "MCalibrateData";
|
---|
83 | fTitle = title ? title : "Task to calculate the number of photons in one event";
|
---|
84 | }
|
---|
85 |
|
---|
86 | // --------------------------------------------------------------------------
|
---|
87 | //
|
---|
88 | // The PreProcess searches for the following input containers:
|
---|
89 | // - MGeomCam
|
---|
90 | // - MPedestalCam
|
---|
91 | // - MCalibrationCam
|
---|
92 | // - MExtractedSignalCam
|
---|
93 | //
|
---|
94 | // The following output containers are also searched and created if
|
---|
95 | // they were not found:
|
---|
96 | //
|
---|
97 | // - MPedPhotCam
|
---|
98 | // - MCerPhotEvt
|
---|
99 | //
|
---|
100 | Int_t MCalibrateData::PreProcess(MParList *pList)
|
---|
101 | {
|
---|
102 | fPedestal = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
---|
103 | if (!fPedestal)
|
---|
104 | {
|
---|
105 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found ... aborting" << endl;
|
---|
106 | return kFALSE;
|
---|
107 | }
|
---|
108 |
|
---|
109 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
---|
110 | if (!fSignals)
|
---|
111 | {
|
---|
112 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
---|
113 | return kFALSE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | if(fCalibrationMode>kNone)
|
---|
117 | {
|
---|
118 | fCalibrations = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationCam"));
|
---|
119 | if (!fCalibrations)
|
---|
120 | {
|
---|
121 | *fLog << err << AddSerialNumber("MCalibrationCam") << " not found ... aborting." << endl;
|
---|
122 | return kFALSE;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | fPedPhot = (MPedPhotCam*)pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
|
---|
127 | if (!fPedPhot)
|
---|
128 | return kFALSE;
|
---|
129 |
|
---|
130 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
---|
131 | if (!fCerPhotEvt)
|
---|
132 | return kFALSE;
|
---|
133 |
|
---|
134 | return kTRUE;
|
---|
135 | }
|
---|
136 |
|
---|
137 | // --------------------------------------------------------------------------
|
---|
138 | //
|
---|
139 | // Check for validity of the selected calibration method, switch to a
|
---|
140 | // different one in case of need
|
---|
141 | //
|
---|
142 | // fill the MPedPhotCam container using the information from MPedestalCam,
|
---|
143 | // MExtractedSignalCam and MCalibrationCam
|
---|
144 | //
|
---|
145 | //
|
---|
146 | Bool_t MCalibrateData::ReInit(MParList *pList)
|
---|
147 | {
|
---|
148 |
|
---|
149 | if(fCalibrationMode == kBlindPixel && !fCalibrations->IsBlindPixelMethodValid())
|
---|
150 | {
|
---|
151 | *fLog << warn << GetDescriptor() << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
|
---|
152 | fCalibrationMode = kFfactor;
|
---|
153 | }
|
---|
154 |
|
---|
155 | if(fCalibrationMode == kPinDiode && !fCalibrations->IsPINDiodeMethodValid())
|
---|
156 | {
|
---|
157 | *fLog << warn << GetDescriptor() << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
|
---|
158 | fCalibrationMode = kFfactor;
|
---|
159 | }
|
---|
160 |
|
---|
161 | //---------------------------------------------
|
---|
162 | // fill MPedPhot container using the informations from
|
---|
163 | // MPedestalCam, MExtractedSignalCam and MCalibrationCam
|
---|
164 |
|
---|
165 | fNumUsedHiGainFADCSlices = fSignals->GetNumUsedHiGainFADCSlices();
|
---|
166 |
|
---|
167 | // is pixid equal to pixidx ?
|
---|
168 | if (fPedestal->GetSize() != fSignals->GetSize())
|
---|
169 | {
|
---|
170 | *fLog << err << "MCalibrateData::ReInit(); sizes of MPedestalCam and MCalibrationCam are different"
|
---|
171 | << endl;
|
---|
172 | }
|
---|
173 |
|
---|
174 | *fLog << all << "MCalibrateData::ReInit(); fill MPedPhotCam container"
|
---|
175 | << endl;
|
---|
176 | *fLog << all << " fNumUsedHiGainADCSlices = "
|
---|
177 | << fNumUsedHiGainFADCSlices << endl;
|
---|
178 | *fLog << all << " pixid, calibrationConversionFactor, ped, pedRMS, pedphot, pedphotRMS :"
|
---|
179 | << endl;
|
---|
180 | for (Int_t pixid=0; pixid<fPedestal->GetSize(); pixid++)
|
---|
181 | {
|
---|
182 | const MPedestalPix &ped = (*fPedestal)[pixid];
|
---|
183 |
|
---|
184 | // pedestals/(used FADC slices) in [ADC] counts
|
---|
185 | Float_t pedes = ped.GetPedestal() * fNumUsedHiGainFADCSlices;
|
---|
186 | Float_t pedrms = ped.GetPedestalRms() * sqrt(fNumUsedHiGainFADCSlices);
|
---|
187 |
|
---|
188 | //----------------------------------
|
---|
189 | // get photon/ADC conversion factor
|
---|
190 |
|
---|
191 | Float_t hiloconv;
|
---|
192 | Float_t hiloconverr;
|
---|
193 | Float_t calibrationConversionFactor;
|
---|
194 | Float_t calibrationConversionFactorErr;
|
---|
195 |
|
---|
196 | if ( !GetConversionFactor(pixid, hiloconv, hiloconverr,
|
---|
197 | calibrationConversionFactor, calibrationConversionFactorErr ))
|
---|
198 | continue;
|
---|
199 |
|
---|
200 | //----------------------------------
|
---|
201 |
|
---|
202 | // pedestals/(used FADC slices) in [number of photons]
|
---|
203 | Float_t pedphot = pedes * calibrationConversionFactor;
|
---|
204 | Float_t pedphotrms = pedrms * calibrationConversionFactor;
|
---|
205 |
|
---|
206 | (*fPedPhot)[pixid].Set(pedphot, pedphotrms);
|
---|
207 |
|
---|
208 | *fLog << all << pixid << ", " << calibrationConversionFactor << ", "
|
---|
209 | << ped.GetPedestal() << ", " << ped.GetPedestalRms() << ", "
|
---|
210 | << pedphot << ", " << pedphotrms << endl;
|
---|
211 | }
|
---|
212 |
|
---|
213 | //---------------------------------------------
|
---|
214 |
|
---|
215 | fPedPhot->SetReadyToSave();
|
---|
216 |
|
---|
217 | return kTRUE;
|
---|
218 | }
|
---|
219 |
|
---|
220 | // --------------------------------------------------------------------------
|
---|
221 | //
|
---|
222 | // Get conversion factor and its error from MCalibrationCam
|
---|
223 | //
|
---|
224 | //
|
---|
225 | Bool_t MCalibrateData::GetConversionFactor(UInt_t pixidx,
|
---|
226 | Float_t &hiloconv, Float_t &hiloconverr,
|
---|
227 | Float_t &calibrationConversionFactor, Float_t &calibrationConversionFactorErr)
|
---|
228 | {
|
---|
229 | hiloconv = 1.;
|
---|
230 | hiloconverr = 0.;
|
---|
231 | calibrationConversionFactor = 1.;
|
---|
232 | calibrationConversionFactorErr = 0.;
|
---|
233 |
|
---|
234 | if(fCalibrationMode!=kNone)
|
---|
235 | {
|
---|
236 | MCalibrationPix &pix = (*fCalibrations)[pixidx];
|
---|
237 |
|
---|
238 | if (!pix.IsChargeValid())
|
---|
239 | return kFALSE;
|
---|
240 |
|
---|
241 | hiloconv = pix.GetConversionHiLo();
|
---|
242 | hiloconverr= pix.GetConversionHiLoErr();
|
---|
243 |
|
---|
244 | switch(fCalibrationMode)
|
---|
245 | {
|
---|
246 | case kBlindPixel:
|
---|
247 | calibrationConversionFactor = pix.GetMeanConversionBlindPixelMethod();
|
---|
248 | calibrationConversionFactorErr = pix.GetConversionBlindPixelMethodErr();
|
---|
249 | break;
|
---|
250 | case kFfactor:
|
---|
251 | calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
|
---|
252 | calibrationConversionFactorErr = pix.GetConversionFFactorMethodErr();
|
---|
253 | break;
|
---|
254 | default:
|
---|
255 | *fLog << warn << "MCalibrateData::GetConversionFactor; Warning: Calibration mode value ("<<fCalibrationMode<<") not known" << endl;
|
---|
256 | break;
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | return kTRUE;
|
---|
261 | }
|
---|
262 |
|
---|
263 | // --------------------------------------------------------------------------
|
---|
264 | //
|
---|
265 | // Apply the calibration factors to the extracted signal according to the
|
---|
266 | // selected calibration method
|
---|
267 | //
|
---|
268 | Int_t MCalibrateData::Process()
|
---|
269 | {
|
---|
270 | /*
|
---|
271 | if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
|
---|
272 | {
|
---|
273 | // FIXME: MExtractedSignal must be of variable size -
|
---|
274 | // like MCerPhotEvt - because we must be able
|
---|
275 | // to reduce size by zero supression
|
---|
276 | // For the moment this check could be done in ReInit...
|
---|
277 | *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
|
---|
278 | return kFALSE;
|
---|
279 | }
|
---|
280 | */
|
---|
281 |
|
---|
282 | UInt_t npix = fSignals->GetSize();
|
---|
283 |
|
---|
284 | Float_t hiloconv;
|
---|
285 | Float_t hiloconverr;
|
---|
286 | Float_t calibrationConversionFactor;
|
---|
287 | Float_t calibrationConversionFactorErr;
|
---|
288 |
|
---|
289 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
---|
290 | {
|
---|
291 | if ( !GetConversionFactor(pixidx, hiloconv, hiloconverr,
|
---|
292 | calibrationConversionFactor, calibrationConversionFactorErr) )
|
---|
293 | continue;
|
---|
294 |
|
---|
295 | MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
---|
296 |
|
---|
297 | Float_t signal;
|
---|
298 | Float_t signalErr = 0.;
|
---|
299 | Float_t nphot,nphotErr;
|
---|
300 |
|
---|
301 | if (sig.IsLoGainUsed())
|
---|
302 | {
|
---|
303 | signal = sig.GetExtractedSignalLoGain()*hiloconv;
|
---|
304 | signalErr = signal*hiloconverr;
|
---|
305 | }
|
---|
306 | else
|
---|
307 | {
|
---|
308 | if (sig.GetExtractedSignalHiGain() > 9999.)
|
---|
309 | {
|
---|
310 | signal = 0.;
|
---|
311 | signalErr = 0.;
|
---|
312 | }
|
---|
313 | else
|
---|
314 | signal = sig.GetExtractedSignalHiGain();
|
---|
315 | }
|
---|
316 |
|
---|
317 | nphot = signal*calibrationConversionFactor;
|
---|
318 | nphotErr = signal*calibrationConversionFactorErr
|
---|
319 | *signal*calibrationConversionFactorErr
|
---|
320 | +signalErr*calibrationConversionFactor
|
---|
321 | *signalErr*calibrationConversionFactor;
|
---|
322 |
|
---|
323 | nphotErr = TMath::Sqrt(nphotErr);
|
---|
324 |
|
---|
325 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
---|
326 |
|
---|
327 | if (sig.GetNumLoGainSaturated() > 0)
|
---|
328 | cpix->SetPixelSaturated();
|
---|
329 | }
|
---|
330 |
|
---|
331 | fCerPhotEvt->FixSize();
|
---|
332 | fCerPhotEvt->SetReadyToSave();
|
---|
333 |
|
---|
334 | return kTRUE;
|
---|
335 | }
|
---|