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

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