source: trunk/MagicSoft/Mars/manalysis/MMcCalibrationCalc.cc@ 2827

Last change on this file since 2827 was 2827, checked in by moralejo, 21 years ago
*** empty log message ***
File size: 7.5 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// and in the conversion factor between photons and ADC counts in
32// MCalibrationCam.
33// Then we create and fill also the MPedPhotCam object containing the pedestal
34// 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 "MMcCalibrationCalc.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(MMcCalibrationCalc);
64
65using namespace std;
66
67MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
68{
69 fName = name ? name : "MMcCalibrationCalc";
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 MMcCalibrationCalc::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 MMcCalibrationCalc::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 MMcCalibrationCalc::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 MMcCalibrationCalc::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 return kTRUE;
194}
195
196
197// --------------------------------------------------------------------------
198//
199// Fill the MCalibrationCam and MCerPhotPed objects
200//
201Int_t MMcCalibrationCalc::Process()
202{
203 const int num = fCalCam->GetSize();
204
205 for (int i=0; i<num; i++)
206 {
207 MCalibrationPix &calpix = (*fCalCam)[i];
208 MExtractedSignalPix &sigpix = (*fSignalCam)[i];
209
210 //
211 // ped mean and rms per pixel, in ADC counts, according to signal
212 // calculation (hi or low gain and number of integrated slices):
213 //
214 const Float_t pedestmean = sigpix.IsLoGainUsed()?
215 fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
216 fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
217
218 //
219 // In some cases, depending on the camera simulation parameters, one can have
220 // very little or no noise in the FADC. In the case the rms of pedestal is zero,
221 // the pixel will be cleaned out later in the image cleaning. To avoid this problem,
222 // we set a default value of 0.01 ADC counts for the RMS per slice:
223 //
224
225
226 const Float_t pedestrms = sigpix.IsLoGainUsed()?
227 sqrt((Double_t)(fSignalCam->GetNumUsedLoGainFADCSlices())) *
228 (fHeaderFadc->GetPedestalRmsLow(i)>0.? fHeaderFadc->GetPedestalRmsLow(i): 0.01)
229 :
230 sqrt((Double_t)(fSignalCam->GetNumUsedHiGainFADCSlices())) *
231 (fHeaderFadc->GetPedestalRmsHigh(i)>0.? fHeaderFadc->GetPedestalRmsHigh(i) : 0.01);
232
233 calpix.SetPedestal(pedestmean, pedestrms);
234 calpix.SetBlindPixelMethodValid();
235 calpix.SetFitValid();
236
237 calpix.SetConversionHiLo(fConversionHiLo);
238 calpix.SetConversionHiLoError(0.); // FIXME ?
239
240 //
241 // Write conversion factor ADC to photons (different for inner
242 // and outer pixels).
243 //
244
245 Float_t adc2phot = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
246 fADC2PhOuter : fADC2PhInner;
247
248 calpix.SetConversionBlindPixelMethod(adc2phot, 0., 0.);
249
250 //
251 // Write mean pedestal and pedestal rms per pixel
252 // in number of photons:
253 //
254 MPedPhotPix &pedpix = (*fPedPhotCam)[i];
255
256 if (sigpix.IsLoGainUsed())
257 pedpix.Set(adc2phot*fConversionHiLo*pedestmean,
258 adc2phot*fConversionHiLo*pedestrms);
259 else
260 pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
261
262 }
263
264 return kTRUE;
265}
Note: See TracBrowser for help on using the repository browser.