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

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