source: trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc@ 3831

Last change on this file since 3831 was 3831, checked in by moralejo, 20 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): 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 photons and ADC counts is
33// set to 1 to allow the analysis to proceed.
34//
35// Then it creates and fills also the MPedPhotCam object containing the pedestal
36// mean and rms in units of photons.
37//
38// Input Containers:
39// MMcFadcHeader
40// MRawRunHeader
41// [MCalibrationChargeCam] (if it existed previously)
42// [MCalibrationQECam] (if it existed previously)
43//
44// Output Containers:
45// MPedPhotCam
46// [MCalibrationChargeCam] (if it did not exist previously)
47// [MCalibrationQECam] (if it did not exist previously)
48//
49/////////////////////////////////////////////////////////////////////////////
50#include "MMcCalibrationUpdate.h"
51
52#include "MParList.h"
53
54#include "MLog.h"
55#include "MLogManip.h"
56
57#include "MCalibrationChargePix.h"
58#include "MCalibrationChargeCam.h"
59
60#include "MCalibrationQEPix.h"
61#include "MCalibrationQECam.h"
62
63#include "MExtractedSignalCam.h"
64#include "MExtractedSignalPix.h"
65#include "MGeomCam.h"
66#include "MPedPhotCam.h"
67#include "MPedPhotPix.h"
68
69#include "MRawRunHeader.h"
70#include "MMcRunHeader.hxx"
71#include "MMcFadcHeader.hxx"
72
73ClassImp(MMcCalibrationUpdate);
74
75using namespace std;
76
77MMcCalibrationUpdate::MMcCalibrationUpdate(const char *name, const char *title)
78{
79 fName = name ? name : "MMcCalibrationUpdate";
80 fTitle = title ? title : "Write MC pedestals and conversion factors into MCalibration Container";
81
82 //
83 // As default we set 1 photon = 1 ADC count.
84 // (this will make Size to be in ADC counts if no previous calibration has been made)
85 // Hence:
86 //
87 fADC2PhElInner = MCalibrationQEPix::gkDefaultAverageQE;
88 fADC2PhElOuter = MCalibrationQEPix::gkDefaultAverageQE;
89
90 fAmplitude = -1.;
91 fAmplitudeOuter = -1.;
92 fConversionHiLo = -1.;
93
94 fFillCalibrationCam = kTRUE;
95 fOuterPixelsGainScaling = kTRUE;
96}
97
98// --------------------------------------------------------------------------
99//
100// Check for the run type. Return kTRUE if it is a MC run or if there
101// is no MC run header (old camera files) kFALSE in case of a different
102// run type
103//
104Bool_t MMcCalibrationUpdate::CheckRunType(MParList *pList) const
105{
106 const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
107 if (!run)
108 {
109 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
110 return kTRUE;
111 }
112
113 return run->IsMonteCarloRun();
114}
115
116// --------------------------------------------------------------------------
117//
118// Make sure, that there is an MCalibrationCam Object in the Parameter List.
119//
120Int_t MMcCalibrationUpdate::PreProcess(MParList *pList)
121{
122 fCalCam = (MCalibrationChargeCam*) pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
123 fQECam = (MCalibrationQECam*) pList->FindObject(AddSerialNumber("MCalibrationQECam"));
124
125 if (!fCalCam || !fQECam)
126 {
127 fCalCam = (MCalibrationChargeCam*) pList->FindCreateObj(AddSerialNumber("MCalibrationChargeCam"));
128 fQECam = (MCalibrationQECam*) pList->FindCreateObj(AddSerialNumber("MCalibrationQECam"));
129 if (!fCalCam || !fQECam)
130 return kFALSE;
131 }
132 else
133 {
134 fFillCalibrationCam = kFALSE;
135 *fLog << inf << AddSerialNumber("MCalibrationChargeCam") << " and " <<
136 AddSerialNumber("MCalibrationQECam") << " already exist... " << endl;
137 }
138
139 fPedPhotCam = (MPedPhotCam*) pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
140 if (!fPedPhotCam)
141 return kFALSE;
142
143 fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
144 if (!fSignalCam)
145 {
146 *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found... aborting." << endl;
147 return kFALSE;
148 }
149
150 return kTRUE;
151}
152
153// --------------------------------------------------------------------------
154//
155// Check for the runtype.
156// Search for MGeomCam and MMcFadcHeader.
157// Fill the MCalibrationCam object.
158//
159Bool_t MMcCalibrationUpdate::ReInit(MParList *pList)
160{
161 //
162 // If it is no MC file skip this function...
163 //
164 if (!CheckRunType(pList))
165 {
166 *fLog << inf << "This is no MC file... skipping." << endl;
167 return kTRUE;
168 }
169
170 //
171 // Now check the existence of all necessary containers.
172 //
173 fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
174 if (!fGeom)
175 {
176 *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
177 return kFALSE;
178 }
179
180 fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
181 if (!fHeaderFadc)
182 {
183 *fLog << err << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
184 return kFALSE;
185 }
186
187 MMcRunHeader* mcrunh = (MMcRunHeader*) pList->FindObject("MMcRunHeader");
188
189 //
190 // Initialize Fadc simulation parameters:
191 //
192 if (fAmplitude < 0)
193 {
194 fAmplitude = fHeaderFadc->GetAmplitud();
195 if (mcrunh->GetCamVersion() > 60)
196 {
197 fAmplitudeOuter = fHeaderFadc->GetAmplitudOuter();
198 fConversionHiLo = fHeaderFadc->GetLow2HighGain();
199 }
200 else // old MC files, camera < v0.7
201 {
202 fAmplitudeOuter = fAmplitude;
203 fConversionHiLo = 10; // dummy value
204 }
205
206 }
207 else // Check that following files have all the same FADC parameters
208 {
209 if ( fabs(fHeaderFadc->GetAmplitud()-fAmplitude) > 1.e-6 )
210 {
211 *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
212 return kFALSE;
213 }
214
215 if (mcrunh->GetCamVersion() > 60) // old MC files, camera < v0.7
216 {
217 if( fabs(fHeaderFadc->GetAmplitudOuter()-fAmplitudeOuter) > 1.e-6 ||
218 fabs(fConversionHiLo-fHeaderFadc->GetLow2HighGain()) > 1.e-6 )
219 {
220 *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
221 return kFALSE;
222 }
223 }
224 }
225
226
227
228 //
229 // If MCalibrationCam already existed in the parameter list before
230 // MMcCalibrationUpdate::PreProcess was executed (from a
231 // previous calibration loop) we must not fill it, hence nothing
232 // else has to be done in ReInit:
233 //
234 if (!fFillCalibrationCam)
235 return kTRUE;
236
237 //
238 // Set the ADC to photons conversion factor for outer pixels.
239 // One can choose not to apply the known (in MC) gain factor between
240 // inner and outer pixels, (fOuterPixelsGainScaling = kFALSE),
241 // which may be useful for display purposes.
242 //
243
244 if (fOuterPixelsGainScaling)
245 fADC2PhElOuter = fADC2PhElInner * (fAmplitude / fAmplitudeOuter);
246 else
247 fADC2PhElOuter = fADC2PhElInner;
248
249
250 const int num = fCalCam->GetSize();
251
252 fCalCam->SetFFactorMethodValid ( kTRUE );
253 fQECam->SetFFactorMethodValid ( kTRUE );
254 fQECam->SetBlindPixelMethodValid ( kTRUE );
255 fQECam->SetCombinedMethodValid ( kTRUE );
256 fQECam->SetPINDiodeMethodValid ( kTRUE );
257
258 for (int i=0; i<num; i++)
259 {
260 MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
261
262 calpix.SetFFactorMethodValid();
263
264 calpix.SetConversionHiLo(fConversionHiLo);
265 calpix.SetConversionHiLoErr(0.); // FIXME ?
266
267 //
268 // Write conversion factor ADC to photo-electrons (different for inner
269 // and outer pixels).
270 //
271 Float_t adc2photel = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
272 fADC2PhElOuter : fADC2PhElInner;
273
274 calpix.SetMeanConvFADC2Phe(adc2photel);
275 calpix.SetMeanConvFADC2PheVar(0.);
276 calpix.SetMeanFFactorFADC2Phot(0.);
277
278 }
279
280
281 return kTRUE;
282}
283
284
285// --------------------------------------------------------------------------
286//
287// Fill the MCerPhotPed object
288//
289Int_t MMcCalibrationUpdate::Process()
290{
291 const int num = fCalCam->GetSize();
292
293 for (int i=0; i<num; i++)
294 {
295 MExtractedSignalPix &sigpix = (*fSignalCam)[i];
296
297 //
298 // ped mean and rms per pixel, in ADC counts, according to signal
299 // calculation (hi or low gain and number of integrated slices):
300 //
301 const Float_t pedestmean = sigpix.IsLoGainUsed()?
302 fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
303 fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
304
305 //
306 // In some cases, depending on the camera simulation parameters, one can
307 // have very little or no noise in the FADC. In the case the rms of
308 // pedestal is zero, the pixel will be cleaned out later in the image
309 // cleaning. To avoid this problem,we set a default value of 0.01 ADC
310 // counts for the RMS per slice:
311 //
312 const Double_t used = (Double_t)(sigpix.IsLoGainUsed() ?
313 fSignalCam->GetNumUsedLoGainFADCSlices() :
314 fSignalCam->GetNumUsedHiGainFADCSlices());
315
316 const Float_t rms0 = sigpix.IsLoGainUsed() ?
317 fHeaderFadc->GetPedestalRmsLow(i) :
318 fHeaderFadc->GetPedestalRmsHigh(i);
319
320 const Float_t pedestrms = TMath::Sqrt(used) * (rms0>0 ? rms0 : 0.01);
321
322 //
323 // Write mean pedestal and pedestal rms per pixel
324 // in number of photons:
325 //
326 MPedPhotPix &pedpix = (*fPedPhotCam)[i];
327
328 MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
329 MCalibrationQEPix &qepix = (MCalibrationQEPix&)(*fQECam)[i];
330
331 qepix.SetAvNormFFactor(1.);
332 // This factor should convert the default average QE to average QE for a spectrum
333 // like that of Cherenkov light. See the documentration of MCalibrationQEPix.
334
335 Float_t qe = qepix.GetAverageQE();
336 Float_t adc2phot = calpix.GetMeanConvFADC2Phe() / qe;
337 Float_t hi2lo = calpix.GetConversionHiLo();
338
339 if (sigpix.IsLoGainUsed())
340 pedpix.Set(adc2phot*hi2lo*pedestmean, adc2phot*hi2lo*pedestrms);
341 else
342 pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
343
344 }
345
346 return kTRUE;
347}
Note: See TracBrowser for help on using the repository browser.