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

Last change on this file since 2961 was 2961, checked in by moralejo, 21 years ago
*** empty log message ***
File size: 9.0 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 "MCalibrationPix.h"
56#include "MCalibrationCam.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
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 //
111 // If it is no MC file skip this function...
112 //
113 if (!CheckRunType(pList))
114 return kTRUE;
115
116
117 fCalCam = (MCalibrationCam*) pList->FindObject(AddSerialNumber("MCalibrationCam"));
118 if ( !fCalCam )
119 {
120 *fLog << inf << dbginf << AddSerialNumber("MCalibrationCam") << " does not exist... Creating." << endl;
121
122 fCalCam = (MCalibrationCam*) pList->FindCreateObj(AddSerialNumber("MCalibrationCam"));
123 if ( !fCalCam )
124 {
125 *fLog << err << dbginf << "Cannot create " << AddSerialNumber("MCalibrationCam") << "... aborting." << endl;
126 return kFALSE;
127 }
128 }
129 else
130 {
131 fFillCalibrationCam = kFALSE;
132 *fLog << inf << AddSerialNumber("MCalibrationCam") << " already exists... " << endl;
133 }
134
135 fPedPhotCam = (MPedPhotCam*) pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
136 if ( ! fPedPhotCam)
137 {
138 *fLog << err << dbginf << "Cannot create " << AddSerialNumber("MPedPhotCam") << "... aborting." << endl;
139 return kFALSE;
140 }
141
142 fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
143 if ( ! fSignalCam)
144 {
145 *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MExtractedSignalCam") << "... aborting." << endl;
146 return kFALSE;
147 }
148
149 return kTRUE;
150
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 return kTRUE;
166
167 //
168 // Now check the existence of all necessary containers.
169 //
170
171 fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
172 if ( ! fGeom )
173 {
174 *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MGeomCam") << "... aborting." << endl;
175 return kFALSE;
176 }
177
178 fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
179 if (!fHeaderFadc)
180 {
181 *fLog << err << dbginf << AddSerialNumber("MMcFadcHeader") << " 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 fAmplitudeOuter = fHeaderFadc->GetAmplitudOuter();
192 fConversionHiLo = fHeaderFadc->GetLow2HighGain();
193 }
194 else // Check that following files have all the same FADC parameters
195 {
196 if ( fabs(fHeaderFadc->GetAmplitud()-fAmplitude) > 1.e-6 ||
197 fabs(fHeaderFadc->GetAmplitudOuter()-fAmplitudeOuter) > 1.e-6 ||
198 fabs(fConversionHiLo-fHeaderFadc->GetLow2HighGain()) > 1.e-6 )
199 {
200 *fLog << err << endl << endl << dbginf << "Parameters of MMcFadcHeader are not the same for all the read files. Aborting..." << endl << endl;
201 return kFALSE;
202 }
203 }
204
205 //
206 // If MCalibrationCam already existed in the parameter list before
207 // MMcCalibrationUpdate::PreProcess was executed (from a
208 // previous calibration loop) we must not fill it, hence nothing
209 // else has to be done in ReInit:
210 //
211 if ( !fFillCalibrationCam )
212 return kTRUE;
213
214 //
215 // Set the ADC to photons conversion factor for outer pixels:
216 //
217 fADC2PhOuter = fADC2PhInner * (fAmplitude / fAmplitudeOuter);
218
219 const int num = fCalCam->GetSize();
220
221 fCalCam->SetBlindPixelMethodValid(kTRUE);
222
223 for (int i=0; i<num; i++)
224 {
225 MCalibrationPix &calpix = (*fCalCam)[i];
226
227 calpix.SetBlindPixelMethodValid();
228 calpix.SetFitValid();
229
230 calpix.SetConversionHiLo(fConversionHiLo);
231 calpix.SetConversionHiLoError(0.); // FIXME ?
232
233 //
234 // Write conversion factor ADC to photons (different for inner
235 // and outer pixels).
236 //
237
238 Float_t adc2phot = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
239 fADC2PhOuter : fADC2PhInner;
240
241 calpix.SetConversionBlindPixelMethod(adc2phot, 0., 0.);
242 }
243
244
245 return kTRUE;
246}
247
248
249// --------------------------------------------------------------------------
250//
251// Fill the MCerPhotPed object
252//
253Int_t MMcCalibrationUpdate::Process()
254{
255 const int num = fCalCam->GetSize();
256
257 for (int i=0; i<num; i++)
258 {
259 MExtractedSignalPix &sigpix = (*fSignalCam)[i];
260
261 //
262 // ped mean and rms per pixel, in ADC counts, according to signal
263 // calculation (hi or low gain and number of integrated slices):
264 //
265 const Float_t pedestmean = sigpix.IsLoGainUsed()?
266 fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
267 fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
268
269 //
270 // In some cases, depending on the camera simulation parameters, one can
271 // have very little or no noise in the FADC. In the case the rms of
272 // pedestal is zero, the pixel will be cleaned out later in the image
273 // cleaning. To avoid this problem,we set a default value of 0.01 ADC
274 // counts for the RMS per slice:
275 //
276
277 const Float_t pedestrms = sigpix.IsLoGainUsed()?
278 sqrt((Double_t)(fSignalCam->GetNumUsedLoGainFADCSlices())) *
279 (fHeaderFadc->GetPedestalRmsLow(i)>0.? fHeaderFadc->GetPedestalRmsLow(i): 0.01)
280 :
281 sqrt((Double_t)(fSignalCam->GetNumUsedHiGainFADCSlices())) *
282 (fHeaderFadc->GetPedestalRmsHigh(i)>0.? fHeaderFadc->GetPedestalRmsHigh(i) : 0.01);
283
284 //
285 // Write mean pedestal and pedestal rms per pixel
286 // in number of photons:
287 //
288 MPedPhotPix &pedpix = (*fPedPhotCam)[i];
289
290 MCalibrationPix &calpix = (*fCalCam)[i];
291 Float_t adc2phot = calpix.GetMeanConversionBlindPixelMethod();
292 Float_t hi2lo = calpix.GetConversionHiLo();
293
294 if (sigpix.IsLoGainUsed())
295 pedpix.Set(adc2phot*hi2lo*pedestmean,
296 adc2phot*hi2lo*pedestrms);
297 else
298 pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
299
300 }
301
302 return kTRUE;
303}
Note: See TracBrowser for help on using the repository browser.