source: trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc@ 4241

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