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 "MCalibrationChargeCam.h"
|
---|
63 | #include "MCalibrationChargePix.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 | // - MCalibrationChargeCam
|
---|
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 |
|
---|
110 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
---|
111 | if (!fSignals)
|
---|
112 | {
|
---|
113 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
---|
114 | return kFALSE;
|
---|
115 | }
|
---|
116 |
|
---|
117 | if (fCalibrationMode>kNone)
|
---|
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 | fPedPhot = (MPedPhotCam*)pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
|
---|
128 | if (!fPedPhot)
|
---|
129 | return kFALSE;
|
---|
130 |
|
---|
131 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
---|
132 | if (!fCerPhotEvt)
|
---|
133 | return kFALSE;
|
---|
134 |
|
---|
135 | return kTRUE;
|
---|
136 | }
|
---|
137 |
|
---|
138 | // --------------------------------------------------------------------------
|
---|
139 | //
|
---|
140 | // Check for validity of the selected calibration method, switch to a
|
---|
141 | // different one in case of need
|
---|
142 | //
|
---|
143 | // fill the MPedPhotCam container using the information from MPedestalCam,
|
---|
144 | // MExtractedSignalCam and MCalibrationCam
|
---|
145 | //
|
---|
146 | //
|
---|
147 | Bool_t MCalibrateData::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 | //---------------------------------------------
|
---|
163 | // fill MPedPhot container using the informations from
|
---|
164 | // MPedestalCam, MExtractedSignalCam and MCalibrationCam
|
---|
165 |
|
---|
166 | fNumUsedHiGainFADCSlices = fSignals->GetNumUsedHiGainFADCSlices();
|
---|
167 |
|
---|
168 | // is pixid equal to pixidx ?
|
---|
169 | if ( (Int_t)(fPedestal->GetSize()) != fSignals->GetSize())
|
---|
170 | {
|
---|
171 | *fLog << err << "MCalibrateData::ReInit(); sizes of MPedestalCam and MCalibrationCam are different"
|
---|
172 | << endl;
|
---|
173 | }
|
---|
174 |
|
---|
175 | *fLog << all << "MCalibrateData::ReInit(); fill MPedPhotCam container"
|
---|
176 | << endl;
|
---|
177 | *fLog << all << " fNumUsedHiGainADCSlices = "
|
---|
178 | << fNumUsedHiGainFADCSlices << endl;
|
---|
179 | *fLog << all << " pixid, calibrationConversionFactor, ped, pedRMS, pedphot, pedphotRMS :"
|
---|
180 | << endl;
|
---|
181 | for (Int_t pixid=0; pixid<fPedestal->GetSize(); pixid++)
|
---|
182 | {
|
---|
183 | const MPedestalPix &ped = (*fPedestal)[pixid];
|
---|
184 |
|
---|
185 | // pedestals/(used FADC slices) in [ADC] counts
|
---|
186 | Float_t pedes = ped.GetPedestal() * fNumUsedHiGainFADCSlices;
|
---|
187 | Float_t pedrms = ped.GetPedestalRms() * sqrt(fNumUsedHiGainFADCSlices);
|
---|
188 |
|
---|
189 | //----------------------------------
|
---|
190 | // get photon/ADC conversion factor
|
---|
191 |
|
---|
192 | Float_t hiloconv;
|
---|
193 | Float_t hiloconverr;
|
---|
194 | Float_t calibrationConversionFactor;
|
---|
195 | Float_t calibrationConversionFactorErr;
|
---|
196 |
|
---|
197 | if ( !GetConversionFactor(pixid, hiloconv, hiloconverr,
|
---|
198 | calibrationConversionFactor, calibrationConversionFactorErr ))
|
---|
199 | continue;
|
---|
200 |
|
---|
201 | //----------------------------------
|
---|
202 |
|
---|
203 | // pedestals/(used FADC slices) in [number of photons]
|
---|
204 | Float_t pedphot = pedes * calibrationConversionFactor;
|
---|
205 | Float_t pedphotrms = pedrms * calibrationConversionFactor;
|
---|
206 |
|
---|
207 | (*fPedPhot)[pixid].Set(pedphot, pedphotrms);
|
---|
208 |
|
---|
209 | *fLog << all << pixid << ", " << calibrationConversionFactor << ", "
|
---|
210 | << ped.GetPedestal() << ", " << ped.GetPedestalRms() << ", "
|
---|
211 | << pedphot << ", " << pedphotrms << endl;
|
---|
212 | }
|
---|
213 |
|
---|
214 | //---------------------------------------------
|
---|
215 |
|
---|
216 | fPedPhot->SetReadyToSave();
|
---|
217 |
|
---|
218 | return kTRUE;
|
---|
219 | }
|
---|
220 |
|
---|
221 | // --------------------------------------------------------------------------
|
---|
222 | //
|
---|
223 | // Get conversion factor and its error from MCalibrationCam
|
---|
224 | //
|
---|
225 | //
|
---|
226 | Bool_t MCalibrateData::GetConversionFactor(UInt_t pixidx,
|
---|
227 | Float_t &hiloconv, Float_t &hiloconverr,
|
---|
228 | Float_t &calibrationConversionFactor, Float_t &calibrationConversionFactorErr)
|
---|
229 | {
|
---|
230 | hiloconv = 1.;
|
---|
231 | hiloconverr = 0.;
|
---|
232 | calibrationConversionFactor = 1.;
|
---|
233 | calibrationConversionFactorErr = 0.;
|
---|
234 |
|
---|
235 | if(fCalibrationMode!=kNone)
|
---|
236 | {
|
---|
237 | MCalibrationChargePix &pix = (*fCalibrations)[pixidx];
|
---|
238 |
|
---|
239 | if (!pix.IsChargeValid())
|
---|
240 | return kFALSE;
|
---|
241 |
|
---|
242 | hiloconv = pix.GetConversionHiLo();
|
---|
243 | hiloconverr= pix.GetConversionHiLoErr();
|
---|
244 |
|
---|
245 | switch(fCalibrationMode)
|
---|
246 | {
|
---|
247 | case kBlindPixel:
|
---|
248 | calibrationConversionFactor = pix.GetMeanConversionBlindPixelMethod();
|
---|
249 | calibrationConversionFactorErr = pix.GetConversionBlindPixelMethodErr();
|
---|
250 | break;
|
---|
251 | case kFfactor:
|
---|
252 | calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
|
---|
253 | calibrationConversionFactorErr = pix.GetConversionFFactorMethodErr();
|
---|
254 | break;
|
---|
255 | default:
|
---|
256 | *fLog << warn << "MCalibrateData::GetConversionFactor; Warning: Calibration mode value ("<<fCalibrationMode<<") not known" << endl;
|
---|
257 | break;
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | return kTRUE;
|
---|
262 | }
|
---|
263 |
|
---|
264 | // --------------------------------------------------------------------------
|
---|
265 | //
|
---|
266 | // Apply the calibration factors to the extracted signal according to the
|
---|
267 | // selected calibration method
|
---|
268 | //
|
---|
269 | Int_t MCalibrateData::Process()
|
---|
270 | {
|
---|
271 | /*
|
---|
272 | if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
|
---|
273 | {
|
---|
274 | // FIXME: MExtractedSignal must be of variable size -
|
---|
275 | // like MCerPhotEvt - because we must be able
|
---|
276 | // to reduce size by zero supression
|
---|
277 | // For the moment this check could be done in ReInit...
|
---|
278 | *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
|
---|
279 | return kFALSE;
|
---|
280 | }
|
---|
281 | */
|
---|
282 |
|
---|
283 | UInt_t npix = fSignals->GetSize();
|
---|
284 |
|
---|
285 | Float_t hiloconv;
|
---|
286 | Float_t hiloconverr;
|
---|
287 | Float_t calibrationConversionFactor;
|
---|
288 | Float_t calibrationConversionFactorErr;
|
---|
289 |
|
---|
290 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
---|
291 | {
|
---|
292 | if ( !GetConversionFactor(pixidx, hiloconv, hiloconverr,
|
---|
293 | calibrationConversionFactor, calibrationConversionFactorErr) )
|
---|
294 | continue;
|
---|
295 |
|
---|
296 | MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
---|
297 |
|
---|
298 | Float_t signal;
|
---|
299 | Float_t signalErr = 0.;
|
---|
300 | Float_t nphot,nphotErr;
|
---|
301 |
|
---|
302 | if (sig.IsLoGainUsed())
|
---|
303 | {
|
---|
304 | signal = sig.GetExtractedSignalLoGain()*hiloconv;
|
---|
305 | signalErr = signal*hiloconverr;
|
---|
306 | }
|
---|
307 | else
|
---|
308 | {
|
---|
309 | if (sig.GetExtractedSignalHiGain() > 9999.)
|
---|
310 | {
|
---|
311 | signal = 0.;
|
---|
312 | signalErr = 0.;
|
---|
313 | }
|
---|
314 | else
|
---|
315 | signal = sig.GetExtractedSignalHiGain();
|
---|
316 | }
|
---|
317 |
|
---|
318 | nphot = signal*calibrationConversionFactor;
|
---|
319 | nphotErr = signal*calibrationConversionFactorErr
|
---|
320 | *signal*calibrationConversionFactorErr
|
---|
321 | +signalErr*calibrationConversionFactor
|
---|
322 | *signalErr*calibrationConversionFactor;
|
---|
323 |
|
---|
324 | nphotErr = TMath::Sqrt(nphotErr);
|
---|
325 |
|
---|
326 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
---|
327 |
|
---|
328 | if (sig.GetNumLoGainSaturated() > 0)
|
---|
329 | cpix->SetPixelSaturated();
|
---|
330 | }
|
---|
331 |
|
---|
332 | fCerPhotEvt->FixSize();
|
---|
333 | fCerPhotEvt->SetReadyToSave();
|
---|
334 |
|
---|
335 | return kTRUE;
|
---|
336 | }
|
---|