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

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