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

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