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

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