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