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 ìnformation 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 |
|
---|
76 | ClassImp(MMcCalibrationUpdate);
|
---|
77 |
|
---|
78 | using namespace std;
|
---|
79 |
|
---|
80 | MMcCalibrationUpdate::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 | //
|
---|
95 | Bool_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 | //
|
---|
111 | Int_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 | //
|
---|
150 | Bool_t MMcCalibrationUpdate::ReInit(MParList *pList)
|
---|
151 | {
|
---|
152 | //
|
---|
153 | // If it is no MC file skip this function...
|
---|
154 | //
|
---|
155 | if (!CheckRunType(pList))
|
---|
156 | {
|
---|
157 | *fLog << inf << "This is no MC file... skipping." << endl;
|
---|
158 | return kTRUE;
|
---|
159 | }
|
---|
160 |
|
---|
161 | //
|
---|
162 | // Now check the existence of all necessary containers.
|
---|
163 | //
|
---|
164 | fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
165 | if (!fGeom)
|
---|
166 | {
|
---|
167 | *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
|
---|
168 | return kFALSE;
|
---|
169 | }
|
---|
170 |
|
---|
171 | fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
|
---|
172 | if (!fHeaderFadc)
|
---|
173 | {
|
---|
174 | *fLog << err << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
|
---|
175 | return kFALSE;
|
---|
176 | }
|
---|
177 |
|
---|
178 | MMcRunHeader* mcrunh = (MMcRunHeader*) pList->FindObject(AddSerialNumber("MMcRunHeader"));
|
---|
179 | if (!mcrunh)
|
---|
180 | {
|
---|
181 | *fLog << err << AddSerialNumber("MMcRunHeader") << " not found... aborting." << endl;
|
---|
182 | return kFALSE;
|
---|
183 | }
|
---|
184 |
|
---|
185 | //
|
---|
186 | // Initialize Fadc simulation parameters:
|
---|
187 | //
|
---|
188 | if (fAmplitude < 0)
|
---|
189 | {
|
---|
190 | fAmplitude = fHeaderFadc->GetAmplitud();
|
---|
191 | if (mcrunh->GetCamVersion() > 60)
|
---|
192 | {
|
---|
193 | fAmplitudeOuter = fHeaderFadc->GetAmplitudOuter();
|
---|
194 |
|
---|
195 | fHeaderLow2HiGainFactor = fHeaderFadc->GetLow2HighGain();
|
---|
196 |
|
---|
197 | // The high to low gain ratio is stored in MMcFadcHeader.Low2HighGain.
|
---|
198 | // However, this is just the ratio of total pulse integrals. Since the
|
---|
199 | // shape of the low gain pulse is different from that of the high gain,
|
---|
200 | // the factor to be applied to signals extracted from low gain depends
|
---|
201 | // on the type of signal extractor (for instance if we extract the pulse
|
---|
202 | // height, the factor is larger than Low2HighGain, because the low gain
|
---|
203 | // pulse shape is wider and hence lower than the high gain pulse. So the
|
---|
204 | // user can set manually the value of the factor to be applied. If such
|
---|
205 | // value has not been set by the user, then we takes as default Low2HighGain.
|
---|
206 |
|
---|
207 | if (fUserLow2HiGainFactor < 0.)
|
---|
208 | fConversionHiLo = fHeaderLow2HiGainFactor;
|
---|
209 | else
|
---|
210 | fConversionHiLo = fUserLow2HiGainFactor;
|
---|
211 |
|
---|
212 | }
|
---|
213 | else // old MC files, camera < v0.7
|
---|
214 | {
|
---|
215 | fAmplitudeOuter = fAmplitude;
|
---|
216 | fConversionHiLo = 10; // dummy value
|
---|
217 | }
|
---|
218 |
|
---|
219 | }
|
---|
220 | else // Check that the following files have all the same FADC parameters as the first
|
---|
221 | {
|
---|
222 | if ( fabs(fHeaderFadc->GetAmplitud()-fAmplitude) > 1.e-6 )
|
---|
223 | {
|
---|
224 | *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
|
---|
225 | return kFALSE;
|
---|
226 | }
|
---|
227 |
|
---|
228 | if (mcrunh->GetCamVersion() > 60) // files from camera 0.7 or newer
|
---|
229 | {
|
---|
230 | if( fabs(fHeaderFadc->GetAmplitudOuter()-fAmplitudeOuter) > 1.e-6 ||
|
---|
231 | fabs(fHeaderLow2HiGainFactor-fHeaderFadc->GetLow2HighGain()) > 1.e-6 )
|
---|
232 | {
|
---|
233 | *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
|
---|
234 | return kFALSE;
|
---|
235 | }
|
---|
236 | }
|
---|
237 | }
|
---|
238 |
|
---|
239 | //
|
---|
240 | // If MCalibrationChargeCam and MCalibrationQECam already existed
|
---|
241 | // in the parameter list before MMcCalibrationUpdate::PreProcess was
|
---|
242 | // executed (from a previous calibration loop) we must not fill them,
|
---|
243 | // hence nothing else has to be done in ReInit:
|
---|
244 | //
|
---|
245 | if (!fFillCalibrationCam)
|
---|
246 | return kTRUE;
|
---|
247 |
|
---|
248 | // Now check the light collection for inner and outer pixels to
|
---|
249 | // calculate the ratio between the two. FIXME! Light collection
|
---|
250 | // depends on the incidence angle of the light w.r.t. the camera
|
---|
251 | // plane. For the moment we take the ratio for light impinging
|
---|
252 | // perpendicular to the camera plane.
|
---|
253 | //
|
---|
254 | // As it happens with most containers, we look for AddSerialNumber("MMcConfigRunHeader")
|
---|
255 | // because in the stereo option the camera simulation writes one such header
|
---|
256 | // per telescope.
|
---|
257 | //
|
---|
258 | MMcConfigRunHeader* mcconfig = (MMcConfigRunHeader*) pList->FindObject(AddSerialNumber("MMcConfigRunHeader"));
|
---|
259 | if (!mcconfig)
|
---|
260 | {
|
---|
261 | *fLog << err << AddSerialNumber("MMcConfigRunHeader") <<
|
---|
262 | " not found... aborting." << endl;
|
---|
263 | return kFALSE;
|
---|
264 | }
|
---|
265 | TArrayF innerlightcoll = mcconfig->GetLightCollectionFactor();
|
---|
266 | TArrayF outerlightcoll = mcconfig->GetLightCollectionFactorOuter();
|
---|
267 |
|
---|
268 | // In principle outer pixels seem to have a different average light
|
---|
269 | // collection efficiency than outer ones. We set here the factor between
|
---|
270 | // the two.
|
---|
271 |
|
---|
272 | fOuterPixelsLightCollection = outerlightcoll[90] / innerlightcoll[90];
|
---|
273 | // (at angle = 90 deg)
|
---|
274 |
|
---|
275 | // Set now the default conversion from ADC counts to photoelectrons
|
---|
276 | // (in case no previous calibration existed in the parameter list).
|
---|
277 | //
|
---|
278 | // As default we want to have SIZE in ADC counts, or rather, in "inner pixel
|
---|
279 | // equivalent ADC counts".
|
---|
280 | //
|
---|
281 | // To achieve this:
|
---|
282 | // - In the case fSignalType==kPhot: we set the ADC to photoelectron conversion
|
---|
283 | // equal to the QE, which will later make the ADC to photon conversion factor
|
---|
284 | // (= ADC2PhotEl/QE) to be = 1,
|
---|
285 | //
|
---|
286 | // - In the case fSignalType==kPhe: we set the ADC to photoelectron conversion
|
---|
287 | // equal to 1, since this will be applied directly to the signals...
|
---|
288 |
|
---|
289 | if (fSignalType == MCalibrateData::kPhot)
|
---|
290 | fADC2PhElInner = MCalibrationQEPix::gkDefaultAverageQE;
|
---|
291 | else
|
---|
292 | fADC2PhElInner = 1.;
|
---|
293 |
|
---|
294 | //
|
---|
295 | // Set the default ADC to "photoelectrons" conversion factor for outer
|
---|
296 | // pixels. One can choose not to apply the known (in MC) gain factor
|
---|
297 | // between inner and outer pixels, (in case fOuterPixelsGainScaling = kFALSE),
|
---|
298 | // which may be useful for display purposes.
|
---|
299 | // If on the contrary we apply the factor, we must take into account the
|
---|
300 | // different gains photoelectrons->ADC counts, given in MC by fAmplitude
|
---|
301 | // and fAmplitudeOuter. This "default" calibration is such that a shower
|
---|
302 | // completely contained in the inner part would have Size in ADC counts,
|
---|
303 | // whereas one partially in the outer part would have Size in "equivalent
|
---|
304 | // inner ADC counts" : the "same" shower (light density distribution) would
|
---|
305 | // have the same Size no matter where in the camera it lies. For this we have
|
---|
306 | // also to set later (see below) the right QE for outer pixels, which may
|
---|
307 | // be different from that of inner pixels.
|
---|
308 | //
|
---|
309 |
|
---|
310 | if (fOuterPixelsGainScaling)
|
---|
311 | fADC2PhElOuter = fADC2PhElInner
|
---|
312 | * (fAmplitude / fAmplitudeOuter);
|
---|
313 | else
|
---|
314 | fADC2PhElOuter = fADC2PhElInner;
|
---|
315 |
|
---|
316 |
|
---|
317 | Int_t num = fCalCam->GetSize();
|
---|
318 |
|
---|
319 | fCalCam->SetFFactorMethodValid ( kTRUE );
|
---|
320 | fQECam->SetFFactorMethodValid ( kTRUE );
|
---|
321 | fQECam->SetBlindPixelMethodValid ( kTRUE );
|
---|
322 | fQECam->SetCombinedMethodValid ( kTRUE );
|
---|
323 | fQECam->SetPINDiodeMethodValid ( kTRUE );
|
---|
324 |
|
---|
325 | for (Int_t i=0; i<num; i++)
|
---|
326 | {
|
---|
327 | MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
|
---|
328 |
|
---|
329 | calpix.SetFFactorMethodValid();
|
---|
330 |
|
---|
331 | calpix.SetConversionHiLo(fConversionHiLo);
|
---|
332 | calpix.SetConversionHiLoErr(0.); // FIXME ?
|
---|
333 |
|
---|
334 | //
|
---|
335 | // Write conversion factor ADC to photo-electrons (different for inner
|
---|
336 | // and outer pixels).
|
---|
337 | //
|
---|
338 | Float_t adc2photel = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
|
---|
339 | fADC2PhElOuter : fADC2PhElInner;
|
---|
340 |
|
---|
341 |
|
---|
342 | calpix.SetMeanConvFADC2Phe(adc2photel);
|
---|
343 | calpix.SetMeanConvFADC2PheVar(0.);
|
---|
344 | calpix.SetMeanFFactorFADC2Phot(0.); // Not used for now.
|
---|
345 |
|
---|
346 | }
|
---|
347 |
|
---|
348 | //
|
---|
349 | // Now set the average QE for each type of pixels. Correct outer pixels
|
---|
350 | // for different light collection efficiency.
|
---|
351 | //
|
---|
352 | num = fQECam->GetSize();
|
---|
353 | for (Int_t i=0; i<num; i++)
|
---|
354 | {
|
---|
355 | MCalibrationQEPix &qepix = (MCalibrationQEPix&)(*fQECam)[i];
|
---|
356 |
|
---|
357 | Float_t avqe = MCalibrationQEPix::gkDefaultAverageQE;
|
---|
358 |
|
---|
359 | if (fOuterPixelsGainScaling)
|
---|
360 | if (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))
|
---|
361 | avqe = MCalibrationQEPix::gkDefaultAverageQE*fOuterPixelsLightCollection;
|
---|
362 |
|
---|
363 | qepix.SetAvNormFFactor(1.);
|
---|
364 | // This factor should convert the default average QE to average QE
|
---|
365 | // for a spectrum like that of Cherenkov light. See the documentation
|
---|
366 | // of MCalibrationQEPix. Here it is 1 because we calibrate using
|
---|
367 | // Cherenkov light.
|
---|
368 |
|
---|
369 | qepix.SetAverageQE(avqe);
|
---|
370 | }
|
---|
371 |
|
---|
372 | return kTRUE;
|
---|
373 | }
|
---|
374 |
|
---|
375 |
|
---|
376 | // --------------------------------------------------------------------------
|
---|
377 | //
|
---|
378 | // Fill the MCerPhotPed object
|
---|
379 | //
|
---|
380 | // This has to be done on an event by event basis because the (calibrated)
|
---|
381 | // pedestal fluctuations depend on whether, for each pixel, we are using
|
---|
382 | // the high gain or the low gain branch.
|
---|
383 | //
|
---|
384 | Int_t MMcCalibrationUpdate::Process()
|
---|
385 | {
|
---|
386 | const Int_t num = fCalCam->GetSize();
|
---|
387 |
|
---|
388 | for (Int_t i=0; i<num; i++)
|
---|
389 | {
|
---|
390 | MExtractedSignalPix &sigpix = (*fSignalCam)[i];
|
---|
391 |
|
---|
392 | const Bool_t uselo = sigpix.IsHiGainSaturated();
|
---|
393 |
|
---|
394 | //
|
---|
395 | // ped mean and rms per pixel, in ADC counts, according to signal
|
---|
396 | // calculation (hi or low gain and number of integrated slices):
|
---|
397 | //
|
---|
398 | const Float_t pedestmean = uselo ?
|
---|
399 | fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
|
---|
400 | fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
|
---|
401 |
|
---|
402 | //
|
---|
403 | // In some cases, depending on the camera simulation parameters, one can
|
---|
404 | // have very little or no noise in the FADC. In the case the rms of
|
---|
405 | // pedestal is zero, the pixel will be cleaned out later in the image
|
---|
406 | // cleaning. To avoid this problem,we set a default value of 0.01 ADC
|
---|
407 | // counts for the RMS per slice:
|
---|
408 | //
|
---|
409 | const Double_t used = uselo ?
|
---|
410 | fSignalCam->GetNumUsedLoGainFADCSlices() :
|
---|
411 | fSignalCam->GetNumUsedHiGainFADCSlices();
|
---|
412 |
|
---|
413 | const Float_t rms0 = uselo ?
|
---|
414 | fHeaderFadc->GetPedestalRmsLow(i) :
|
---|
415 | fHeaderFadc->GetPedestalRmsHigh(i);
|
---|
416 |
|
---|
417 | const Float_t pedestrms = TMath::Sqrt(used) * (rms0>0 ? rms0 : 0.01);
|
---|
418 |
|
---|
419 | //
|
---|
420 | // Write mean pedestal and pedestal rms per pixel
|
---|
421 | // in number of photons:
|
---|
422 | //
|
---|
423 | const MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
|
---|
424 | const MCalibrationQEPix &qepix = (MCalibrationQEPix&)(*fQECam)[i];
|
---|
425 |
|
---|
426 | const Float_t conv = fSignalType == MCalibrateData::kPhot ?
|
---|
427 | calpix.GetMeanConvFADC2Phe() / qepix.GetAverageQE() :
|
---|
428 | calpix.GetMeanConvFADC2Phe();
|
---|
429 |
|
---|
430 | const Float_t hi2lo = uselo ? calpix.GetConversionHiLo() : 1;
|
---|
431 |
|
---|
432 | (*fPedPhotCam)[i].Set(conv*hi2lo*pedestmean, conv*hi2lo*pedestrms);
|
---|
433 |
|
---|
434 | }
|
---|
435 |
|
---|
436 | return kTRUE;
|
---|
437 | }
|
---|
438 |
|
---|