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

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