source: trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc@ 3033

Last change on this file since 3033 was 2942, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.8 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 7/2002 <mailto:moralejo@pd.infn.it>
19! Author(s): Thomas Bretz 2002 <mailto:tbretz@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2002-2003
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MCerPhotCalc
29//
30// This is a task which calculates the number of photons from the FADC
31// time slices. It weights the each slice according to the numbers in
32// the array fWeight (default: all slices added up with weight 1).
33//
34// The weights are rescaled, such that sum(weigths)=num slices
35//
36// Input Containers:
37// MRawEvtData
38// MPedestalCam
39// [MRawRunHeader]
40//
41// Output Containers:
42// MCerPhotEvt
43//
44//////////////////////////////////////////////////////////////////////////////
45#include "MCerPhotCalc.h"
46
47#include "MParList.h"
48
49#include "MLog.h"
50#include "MLogManip.h"
51
52#include "MGeomCam.h"
53#include "MMcRunHeader.hxx"
54
55#include "MRawRunHeader.h"
56#include "MRawEvtData.h" // MRawEvtData::GetNumPixels
57#include "MCerPhotEvt.h"
58#include "MPedestalPix.h"
59#include "MPedestalCam.h"
60#include "MRawEvtPixelIter.h"
61
62ClassImp(MCerPhotCalc);
63
64using namespace std;
65
66// --------------------------------------------------------------------------
67//
68// Default constructor.
69//
70MCerPhotCalc::MCerPhotCalc(const char *name, const char *title)
71{
72 fName = name ? name : "MCerPhotCalc";
73 fTitle = title ? title : "Calculate pixel signal from FADC data";
74
75 AddToBranchList("MRawEvtData.fHiGainPixId");
76 AddToBranchList("MRawEvtData.fLoGainPixId");
77 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
78 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
79
80 SetDefaultWeights();
81}
82
83// --------------------------------------------------------------------------
84//
85// The PreProcess searches for the following input containers:
86// - MRawRunHeader
87// - MRawEvtData
88// - MPedestalCam
89//
90// The following output containers are also searched and created if
91// they were not found:
92// - MCerPhotEvt
93//
94Int_t MCerPhotCalc::PreProcess(MParList *pList)
95{
96 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
97 if (!fRunHeader)
98 {
99 *fLog << err << "MRawRunHeader not found... aborting." << endl;
100 return kFALSE;
101 }
102
103 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
104 if (!fRawEvt)
105 {
106 *fLog << err << "MRawEvtData not found... aborting." << endl;
107 return kFALSE;
108 }
109
110 fPedestals = (MPedestalCam*)pList->FindCreateObj(AddSerialNumber("MPedestalCam"));
111 if (!fPedestals)
112 {
113 *fLog << err << "MPedestalCam not found... aborting." << endl;
114 return kFALSE;
115 }
116
117 fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
118 if (!fCerPhotEvt)
119 return kFALSE;
120
121 // Calculate sum and quadratic sum of weights:
122 fSumWeights = 0;
123 fSumQuadWeights = 0;
124 for (Int_t i=0; i<fWeight.GetSize(); i++)
125 {
126 fSumWeights += fWeight[i];
127 fSumQuadWeights += fWeight[i]*fWeight[i];
128 }
129
130 fSumQuadWeights = sqrt(fSumQuadWeights);
131
132 return kTRUE;
133}
134
135// --------------------------------------------------------------------------
136//
137// Check for the run type and camera version.
138// If the file is a MC file and the used camera version is <= 40
139// we enable a fix for truncated pedestal means in this version.
140//
141Bool_t MCerPhotCalc::ReInit(MParList *pList)
142{
143 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
144 if (!runheader)
145 {
146 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
147 return kTRUE;
148 }
149
150 if (fRunHeader->GetNumSamplesHiGain() != fWeight.GetSize())
151 {
152 *fLog << dbginf << "Number of FADC slices (" << fRunHeader->GetNumSamplesHiGain() <<") is different from assumed one (" << fWeight.GetSize() << ")... aborting." << endl;
153 return kFALSE;
154 }
155
156 Bool_t fIsMcFile = runheader->GetRunType() == kRTMonteCarlo;
157 if (!fIsMcFile)
158 return kTRUE;
159
160 MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
161 if (!mcrunheader)
162 {
163 *fLog << warn << dbginf << "Warning - cannot check for camera version, MC run header not found." << endl;
164 return kTRUE;
165 }
166
167 fEnableFix = kFALSE;
168
169 if (mcrunheader->GetCamVersion() <= 40)
170 fEnableFix = kTRUE;
171
172 ScalePedestals();
173
174 return kTRUE;
175}
176
177void MCerPhotCalc::ScalePedestals()
178{
179 const Int_t n = fPedestals->GetSize();
180
181 for (int idx=0; idx<n; idx++)
182 {
183 MPedestalPix &ped = (*fPedestals)[idx];
184
185 // This converts the pedestal info contained in ped from the pedestal
186 // of each FADC slice to the pedesal of the pixel signal (depends on
187 // how many FADC slices are added up).
188
189 const Double_t offset = fEnableFix ? ped.GetPedestal()-0.5 : ped.GetPedestal();
190
191 ped.Set(offset*fSumWeights, ped.GetPedestalRms()*fSumQuadWeights);
192 }
193
194 fPedestals->SetReadyToSave();
195}
196
197// --------------------------------------------------------------------------
198//
199// Calculate the integral of the FADC time slices and store them as a new
200// pixel in the MCerPhotEvt container.
201//
202Int_t MCerPhotCalc::Process()
203{
204 //fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
205
206// if (fIsMcFile)
207// ScalePedestals();
208
209 const Int_t n = fWeight.GetSize();
210
211 MRawEvtPixelIter pixel(fRawEvt);
212
213 Int_t saturatedpixels = 0;
214
215 while (pixel.Next())
216 {
217 const UInt_t idx = pixel.GetPixelId();
218
219 MPedestalPix &ped = (*fPedestals)[idx];
220
221 //
222 // Calculate pixel signal unless it has all FADC slices empty:
223 //
224 Byte_t *ptr = pixel.GetHiGainSamples();
225
226 Int_t i;
227 Double_t nphot = 0;
228 for (i=0; i<n; i++)
229 {
230 if (ptr[i]==0xff)
231 break;
232 nphot += ptr[i]*fWeight[i];
233 }
234
235 Bool_t saturatedlg = kFALSE;
236
237 if (i<n)
238 {
239 nphot = 0;
240
241 ptr = pixel.GetLoGainSamples();
242 if (ptr==NULL)
243 {
244 *fLog << warn << "WARNING - Pixel #" << idx << " saturated but has no lo gains... skipping!" << endl;
245 return kCONTINUE;
246 }
247
248 for (i=0; i<n; i++)
249 {
250 if (ptr[i]==0xff)
251 saturatedlg = kTRUE;
252
253 nphot += ptr[i]*fWeight[i];
254 }
255
256 nphot -= ped.GetPedestal();
257 nphot *= 10;
258 }
259 else
260 nphot -= ped.GetPedestal();
261
262 fCerPhotEvt->AddPixel(idx, nphot, 0);
263
264 if (saturatedlg)
265 saturatedpixels++;
266 }
267
268 if (saturatedpixels>0)
269 *fLog << warn << "WARNING: " << saturatedpixels << " pixel(s) had saturating low gains..." << endl;
270
271 fCerPhotEvt->FixSize();
272 fCerPhotEvt->SetReadyToSave();
273
274 return kTRUE;
275}
276
277// --------------------------------------------------------------------------
278//
279// Set default values for the number of slices and weights:
280//
281void MCerPhotCalc::SetDefaultWeights()
282{
283 const Float_t dummy[15] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
284 fWeight.Set(15, dummy);
285}
Note: See TracBrowser for help on using the repository browser.