source: tags/Mars-V2.0/manalysis/MMcCalibrationUpdate.cc

Last change on this file was 8354, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 15.2 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): Abelardo Moralejo, 12/2003 <mailto:moralejo@pd.infn.it>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MMcCalibrationUpdate
28//
29// This task looks for the information about FADC pedestals in
30// MMcFadcHeader and translates it to the pedestal mean and rms (in adc counts).
31// If not already existing in the parameter list, an MCalibrationCam object
32// is created, with the conversion factor between ADC counts and photons or
33// photoelectrons (depending on fSignalType) is set to 1 to allow the analysis
34// to proceed.
35//
36// Then it creates and fills also the MPedPhotCam object containing the pedestal
37// mean and rms in units of photons or photoelectrons.
38//
39// Input Containers:
40// MMcFadcHeader
41// MRawRunHeader
42// [MCalibrationChargeCam] (if it existed previously)
43// [MCalibrationQECam] (if it existed previously)
44//
45// Output Containers:
46// MPedPhotCam
47// [MCalibrationChargeCam] (if it did not exist previously)
48// [MCalibrationQECam] (if it did not exist previously)
49//
50/////////////////////////////////////////////////////////////////////////////
51#include "MMcCalibrationUpdate.h"
52
53#include "MParList.h"
54
55#include "MLog.h"
56#include "MLogManip.h"
57
58#include "MCalibrationChargePix.h"
59#include "MCalibrationChargeCam.h"
60
61#include "MCalibrationQEPix.h"
62#include "MCalibrationQECam.h"
63
64#include "MExtractedSignalCam.h"
65#include "MExtractedSignalPix.h"
66#include "MGeomCam.h"
67#include "MPedPhotCam.h"
68#include "MPedPhotPix.h"
69
70#include "MRawRunHeader.h"
71#include "MMcRunHeader.hxx"
72#include "MMcFadcHeader.hxx"
73#include "MMcConfigRunHeader.h"
74#include "MCalibrateData.h"
75
76ClassImp(MMcCalibrationUpdate);
77
78using namespace std;
79
80MMcCalibrationUpdate::MMcCalibrationUpdate(const char *name, const char *title)
81 : fFillCalibrationCam(kTRUE), fOuterPixelsGainScaling(kTRUE), fAmplitude(-1.),
82 fAmplitudeOuter(-1.), fConversionHiLo(-1.), fUserLow2HiGainFactor(-1.),
83 fSignalType(MCalibrateData::kPhe)
84{
85 fName = name ? name : "MMcCalibrationUpdate";
86 fTitle = title ? title : "Write MC pedestals and conversion factors into MCalibration Container";
87}
88
89// --------------------------------------------------------------------------
90//
91// Check for the run type. Return kTRUE if it is a MC run or if there
92// is no MC run header (old camera files) kFALSE in case of a different
93// run type
94//
95Bool_t MMcCalibrationUpdate::CheckRunType(MParList *pList) const
96{
97 const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
98 if (!run)
99 {
100 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
101 return kTRUE;
102 }
103
104 return run->IsMonteCarloRun();
105}
106
107// --------------------------------------------------------------------------
108//
109// Make sure, that there is an MCalibrationCam Object in the Parameter List.
110//
111Int_t MMcCalibrationUpdate::PreProcess(MParList *pList)
112{
113 fCalCam = (MCalibrationChargeCam*) pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
114 fQECam = (MCalibrationQECam*) pList->FindObject(AddSerialNumber("MCalibrationQECam"));
115
116 if (!fCalCam || !fQECam)
117 {
118 fCalCam = (MCalibrationChargeCam*) pList->FindCreateObj(AddSerialNumber("MCalibrationChargeCam"));
119 fQECam = (MCalibrationQECam*) pList->FindCreateObj(AddSerialNumber("MCalibrationQECam"));
120 if (!fCalCam || !fQECam)
121 return kFALSE;
122 }
123 else
124 {
125 fFillCalibrationCam = kFALSE;
126 *fLog << inf << AddSerialNumber("MCalibrationChargeCam") << " and " <<
127 AddSerialNumber("MCalibrationQECam") << " already exist... " << endl;
128 }
129
130 fPedPhotCam = (MPedPhotCam*) pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
131 if (!fPedPhotCam)
132 return kFALSE;
133
134 fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
135 if (!fSignalCam)
136 {
137 *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found... aborting." << endl;
138 return kFALSE;
139 }
140
141 return kTRUE;
142}
143
144// --------------------------------------------------------------------------
145//
146// Check for the runtype.
147// Search for MGeomCam and MMcFadcHeader.
148// Fill the MCalibrationCam object.
149//
150Bool_t MMcCalibrationUpdate::ReInit(MParList *pList)
151{
152 //
153 // If it is no MC file skip this function...
154 //
155 fGeom = 0;
156 if (!CheckRunType(pList))
157 {
158 *fLog << inf << "This is no MC file... skipping." << endl;
159 return kTRUE;
160 }
161
162 //
163 // Now check the existence of all necessary containers.
164 //
165 fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
166 if (!fGeom)
167 {
168 *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
169 return kFALSE;
170 }
171
172 fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
173 if (!fHeaderFadc)
174 {
175 *fLog << err << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
176 return kFALSE;
177 }
178
179 MMcRunHeader* mcrunh = (MMcRunHeader*) pList->FindObject(AddSerialNumber("MMcRunHeader"));
180 if (!mcrunh)
181 {
182 *fLog << err << AddSerialNumber("MMcRunHeader") << " not found... aborting." << endl;
183 return kFALSE;
184 }
185
186 //
187 // Initialize Fadc simulation parameters:
188 //
189 if (fAmplitude < 0)
190 {
191 fAmplitude = fHeaderFadc->GetAmplitud();
192 if (mcrunh->GetCamVersion() > 60)
193 {
194 fAmplitudeOuter = fHeaderFadc->GetAmplitudOuter();
195
196 fHeaderLow2HiGainFactor = fHeaderFadc->GetLow2HighGain();
197
198 // The high to low gain ratio is stored in MMcFadcHeader.Low2HighGain.
199 // However, this is just the ratio of total pulse integrals. Since the
200 // shape of the low gain pulse is different from that of the high gain,
201 // the factor to be applied to signals extracted from low gain depends
202 // on the type of signal extractor (for instance if we extract the pulse
203 // height, the factor is larger than Low2HighGain, because the low gain
204 // pulse shape is wider and hence lower than the high gain pulse. So the
205 // user can set manually the value of the factor to be applied. If such
206 // value has not been set by the user, then we takes as default Low2HighGain.
207
208 if (fUserLow2HiGainFactor < 0.)
209 fConversionHiLo = fHeaderLow2HiGainFactor;
210 else
211 fConversionHiLo = fUserLow2HiGainFactor;
212
213 }
214 else // old MC files, camera < v0.7
215 {
216 fAmplitudeOuter = fAmplitude;
217 fConversionHiLo = 10; // dummy value
218 }
219
220 }
221 else // Check that the following files have all the same FADC parameters as the first
222 {
223 if ( fabs(fHeaderFadc->GetAmplitud()-fAmplitude) > 1.e-6 )
224 {
225 *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
226 return kFALSE;
227 }
228
229 if (mcrunh->GetCamVersion() > 60) // files from camera 0.7 or newer
230 {
231 if( fabs(fHeaderFadc->GetAmplitudOuter()-fAmplitudeOuter) > 1.e-6 ||
232 fabs(fHeaderLow2HiGainFactor-fHeaderFadc->GetLow2HighGain()) > 1.e-6 )
233 {
234 *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
235 return kFALSE;
236 }
237 }
238 }
239
240 //
241 // If MCalibrationChargeCam and MCalibrationQECam already existed
242 // in the parameter list before MMcCalibrationUpdate::PreProcess was
243 // executed (from a previous calibration loop) we must not fill them,
244 // hence nothing else has to be done in ReInit:
245 //
246 if (!fFillCalibrationCam)
247 return kTRUE;
248
249 // Now check the light collection for inner and outer pixels to
250 // calculate the ratio between the two. FIXME! Light collection
251 // depends on the incidence angle of the light w.r.t. the camera
252 // plane. For the moment we take the ratio for light impinging
253 // perpendicular to the camera plane.
254 //
255 // As it happens with most containers, we look for AddSerialNumber("MMcConfigRunHeader")
256 // because in the stereo option the camera simulation writes one such header
257 // per telescope.
258 //
259 MMcConfigRunHeader* mcconfig = (MMcConfigRunHeader*) pList->FindObject(AddSerialNumber("MMcConfigRunHeader"));
260 if (!mcconfig)
261 {
262 *fLog << err << AddSerialNumber("MMcConfigRunHeader") <<
263 " not found... aborting." << endl;
264 return kFALSE;
265 }
266 TArrayF innerlightcoll = mcconfig->GetLightCollectionFactor();
267 TArrayF outerlightcoll = mcconfig->GetLightCollectionFactorOuter();
268
269 // In principle outer pixels seem to have a different average light
270 // collection efficiency than outer ones. We set here the factor between
271 // the two.
272
273 fOuterPixelsLightCollection = outerlightcoll[90] / innerlightcoll[90];
274 // (at angle = 90 deg)
275
276 // Set now the default conversion from ADC counts to photoelectrons
277 // (in case no previous calibration existed in the parameter list).
278 //
279 // As default we want to have SIZE in ADC counts, or rather, in "inner pixel
280 // equivalent ADC counts".
281 //
282 // To achieve this:
283 // - In the case fSignalType==kPhot: we set the ADC to photoelectron conversion
284 // equal to the QE, which will later make the ADC to photon conversion factor
285 // (= ADC2PhotEl/QE) to be = 1,
286 //
287 // - In the case fSignalType==kPhe: we set the ADC to photoelectron conversion
288 // equal to 1, since this will be applied directly to the signals...
289
290 if (fSignalType == MCalibrateData::kPhot)
291 fADC2PhElInner = MCalibrationQEPix::gkDefaultAverageQE;
292 else
293 fADC2PhElInner = 1.;
294
295 //
296 // Set the default ADC to "photoelectrons" conversion factor for outer
297 // pixels. One can choose not to apply the known (in MC) gain factor
298 // between inner and outer pixels, (in case fOuterPixelsGainScaling = kFALSE),
299 // which may be useful for display purposes.
300 // If on the contrary we apply the factor, we must take into account the
301 // different gains photoelectrons->ADC counts, given in MC by fAmplitude
302 // and fAmplitudeOuter. This "default" calibration is such that a shower
303 // completely contained in the inner part would have Size in ADC counts,
304 // whereas one partially in the outer part would have Size in "equivalent
305 // inner ADC counts" : the "same" shower (light density distribution) would
306 // have the same Size no matter where in the camera it lies. For this we have
307 // also to set later (see below) the right QE for outer pixels, which may
308 // be different from that of inner pixels.
309 //
310
311 if (fOuterPixelsGainScaling)
312 fADC2PhElOuter = fADC2PhElInner
313 * (fAmplitude / fAmplitudeOuter);
314 else
315 fADC2PhElOuter = fADC2PhElInner;
316
317
318 Int_t num = fCalCam->GetSize();
319
320 fCalCam->SetFFactorMethodValid ( kTRUE );
321 fQECam->SetFFactorMethodValid ( kTRUE );
322 fQECam->SetBlindPixelMethodValid ( kTRUE );
323 fQECam->SetCombinedMethodValid ( kTRUE );
324 fQECam->SetPINDiodeMethodValid ( kTRUE );
325
326 for (Int_t i=0; i<num; i++)
327 {
328 MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
329
330 calpix.SetFFactorMethodValid();
331
332 calpix.SetConversionHiLo(fConversionHiLo);
333 calpix.SetConversionHiLoErr(0.); // FIXME ?
334
335 //
336 // Write conversion factor ADC to photo-electrons (different for inner
337 // and outer pixels).
338 //
339 Float_t adc2photel = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
340 fADC2PhElOuter : fADC2PhElInner;
341
342
343 calpix.SetMeanConvFADC2Phe(adc2photel);
344 calpix.SetMeanConvFADC2PheVar(0.);
345 calpix.SetMeanFFactorFADC2Phot(0.); // Not used for now.
346
347 }
348
349 //
350 // Now set the average QE for each type of pixels. Correct outer pixels
351 // for different light collection efficiency.
352 //
353 num = fQECam->GetSize();
354 for (Int_t i=0; i<num; i++)
355 {
356 MCalibrationQEPix &qepix = (MCalibrationQEPix&)(*fQECam)[i];
357
358 Float_t avqe = MCalibrationQEPix::gkDefaultAverageQE;
359
360 if (fOuterPixelsGainScaling)
361 if (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))
362 avqe = MCalibrationQEPix::gkDefaultAverageQE*fOuterPixelsLightCollection;
363
364 qepix.SetAvNormFFactor(1.);
365 // This factor should convert the default average QE to average QE
366 // for a spectrum like that of Cherenkov light. See the documentation
367 // of MCalibrationQEPix. Here it is 1 because we calibrate using
368 // Cherenkov light.
369
370 qepix.SetAverageQE(avqe);
371 }
372
373 return kTRUE;
374}
375
376
377// --------------------------------------------------------------------------
378//
379// Fill the MCerPhotPed object
380//
381// This has to be done on an event by event basis because the (calibrated)
382// pedestal fluctuations depend on whether, for each pixel, we are using
383// the high gain or the low gain branch.
384//
385Int_t MMcCalibrationUpdate::Process()
386{
387 // This is the case it is no MC file...
388 if (!fGeom)
389 return kTRUE;
390
391 const Int_t num = fCalCam->GetSize();
392
393 for (Int_t i=0; i<num; i++)
394 {
395 MExtractedSignalPix &sigpix = (*fSignalCam)[i];
396
397 const Bool_t uselo = sigpix.IsHiGainSaturated();
398
399 //
400 // ped mean and rms per pixel, in ADC counts, according to signal
401 // calculation (hi or low gain and number of integrated slices):
402 //
403 const Float_t pedestmean = uselo ?
404 fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
405 fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
406
407 //
408 // In some cases, depending on the camera simulation parameters, one can
409 // have very little or no noise in the FADC. In the case the rms of
410 // pedestal is zero, the pixel will be cleaned out later in the image
411 // cleaning. To avoid this problem,we set a default value of 0.01 ADC
412 // counts for the RMS per slice:
413 //
414 const Double_t used = uselo ?
415 fSignalCam->GetNumUsedLoGainFADCSlices() :
416 fSignalCam->GetNumUsedHiGainFADCSlices();
417
418 const Float_t rms0 = uselo ?
419 fHeaderFadc->GetPedestalRmsLow(i) :
420 fHeaderFadc->GetPedestalRmsHigh(i);
421
422 const Float_t pedestrms = TMath::Sqrt(used) * (rms0>0 ? rms0 : 0.01);
423
424 //
425 // Write mean pedestal and pedestal rms per pixel
426 // in number of photons:
427 //
428 const MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
429 const MCalibrationQEPix &qepix = (MCalibrationQEPix&)(*fQECam)[i];
430
431 const Float_t conv = fSignalType == MCalibrateData::kPhot ?
432 calpix.GetMeanConvFADC2Phe() / qepix.GetAverageQE() :
433 calpix.GetMeanConvFADC2Phe();
434
435 const Float_t hi2lo = uselo ? calpix.GetConversionHiLo() : 1;
436
437 (*fPedPhotCam)[i].Set(conv*hi2lo*pedestmean, conv*hi2lo*pedestrms);
438
439 }
440
441 return kTRUE;
442}
443
Note: See TracBrowser for help on using the repository browser.