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

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