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

Last change on this file since 2744 was 2731, checked in by moralejo, 21 years ago
*** empty log message ***
File size: 7.1 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 fADC2PhOuter = x *
104 fHeaderFadc->GetAmplitud() / fHeaderFadc->GetAmplitudOuter();
105
106 return;
107}
108
109// --------------------------------------------------------------------------
110//
111// Make sure, that there is an MCalibrationCam Object in the Parameter List.
112//
113Int_t MMcCalibrationCalc::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 if ( ! pList->FindCreateObj(AddSerialNumber("MCalibrationCam")))
122 {
123 *fLog << err << dbginf << "Cannot create MCalibrationCam... aborting." << endl;
124 return kFALSE;
125 }
126
127 if ( ! pList->FindCreateObj(AddSerialNumber("MPedPhotCam")))
128 {
129 *fLog << err << dbginf << "Cannot create MPedPhotCam... aborting." << endl;
130 return kFALSE;
131 }
132
133 fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
134 if ( ! fGeom )
135 {
136 *fLog << err << dbginf << "Cannot find MGeomCam... aborting." << endl;
137 return kFALSE;
138 }
139
140 fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
141 if ( ! fSignalCam)
142 {
143 *fLog << err << dbginf << "Cannot find MExtractedSignalCam... 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. This has
166 // to be done only if this is a MC file.
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 fCalCam = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationCam"));
177
178 if (!fCalCam)
179 {
180 *fLog << err << dbginf << "Could not create MCalibrationCam... aborting. " << endl;
181 return kFALSE;
182 }
183
184 fPedPhotCam = (MPedPhotCam*)pList->FindObject(AddSerialNumber("MPedPhotCam"));
185
186 if (!fPedPhotCam)
187 {
188 *fLog << err << dbginf << "Could not create MPedPhotCam... aborting. " << endl;
189 return kFALSE;
190 }
191
192 fPedPhotCam->InitSize(fGeom->GetNumPixels());
193
194 return kTRUE;
195}
196
197
198// --------------------------------------------------------------------------
199//
200// Fill the MCalibrationCam and MCerPhotPed objects
201//
202Int_t MMcCalibrationCalc::Process()
203{
204 const int num = fCalCam->GetSize();
205
206 for (int i=0; i<num; i++)
207 {
208 MCalibrationPix &calpix = (*fCalCam)[i];
209 MExtractedSignalPix &sigpix = (*fSignalCam)[i];
210
211 //
212 // ped mean and rms per pixel, in ADC counts, according to signal
213 // calculation (hi or low gain and number of integrated slices):
214 //
215 const Float_t pedestmean = sigpix.IsLoGainUsed()?
216 fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
217 fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
218
219 const Float_t pedestrms = sigpix.IsLoGainUsed()?
220 sqrt((Double_t)(fSignalCam->GetNumUsedLoGainFADCSlices())) * fHeaderFadc->GetPedestalRmsLow(i) :
221 sqrt((Double_t)(fSignalCam->GetNumUsedHiGainFADCSlices())) * fHeaderFadc->GetPedestalRmsHigh(i);
222
223 calpix.SetPedestal(pedestmean, pedestrms);
224 calpix.SetBlindPixelMethodValid();
225 calpix.SetConversionHiLo(fConversionHiLo);
226 calpix.SetConversionHiLoError(0.); // FIXME ?
227
228 //
229 // Write conversion factor ADC to photons (different for inner
230 // and outer pixels).
231 //
232
233 Float_t adc2phot = (fGeom->GetPixRatio(i) > fGeom->GetPixRatio(0))?
234 fADC2PhOuter : fADC2PhInner;
235
236 calpix.SetConversionBlindPixelMethod(adc2phot, 0., 0.);
237
238 //
239 // Write mean pedestal and pedestal rms per pixel
240 // in number of photons:
241 //
242 MPedPhotPix &pedpix = (*fPedPhotCam)[i];
243
244 if (sigpix.IsLoGainUsed())
245 pedpix.Set(adc2phot*fConversionHiLo*pedestmean,
246 adc2phot*fConversionHiLo*pedestrms);
247 else
248 pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
249
250 }
251
252 return kTRUE;
253}
Note: See TracBrowser for help on using the repository browser.