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

Last change on this file since 4200 was 3374, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.7 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 if (!runheader->IsMonteCarloRun())
157 return kTRUE;
158
159 MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
160 if (!mcrunheader)
161 {
162 *fLog << warn << dbginf << "Warning - cannot check for camera version, MC run header not found." << endl;
163 return kTRUE;
164 }
165
166 fEnableFix = kFALSE;
167
168 if (mcrunheader->GetCamVersion() <= 40)
169 fEnableFix = kTRUE;
170
171 ScalePedestals();
172
173 return kTRUE;
174}
175
176void MCerPhotCalc::ScalePedestals()
177{
178 const Int_t n = fPedestals->GetSize();
179
180 for (int idx=0; idx<n; idx++)
181 {
182 MPedestalPix &ped = (*fPedestals)[idx];
183
184 // This converts the pedestal info contained in ped from the pedestal
185 // of each FADC slice to the pedesal of the pixel signal (depends on
186 // how many FADC slices are added up).
187
188 const Double_t offset = fEnableFix ? ped.GetPedestal()-0.5 : ped.GetPedestal();
189
190 ped.Set(offset*fSumWeights, ped.GetPedestalRms()*fSumQuadWeights);
191 }
192
193 fPedestals->SetReadyToSave();
194}
195
196// --------------------------------------------------------------------------
197//
198// Calculate the integral of the FADC time slices and store them as a new
199// pixel in the MCerPhotEvt container.
200//
201Int_t MCerPhotCalc::Process()
202{
203 //fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
204
205// if (fIsMcFile)
206// ScalePedestals();
207
208 const Int_t n = fWeight.GetSize();
209
210 MRawEvtPixelIter pixel(fRawEvt);
211
212 Int_t saturatedpixels = 0;
213
214 while (pixel.Next())
215 {
216 const UInt_t idx = pixel.GetPixelId();
217
218 MPedestalPix &ped = (*fPedestals)[idx];
219
220 //
221 // Calculate pixel signal unless it has all FADC slices empty:
222 //
223 Byte_t *ptr = pixel.GetHiGainSamples();
224
225 Int_t i;
226 Double_t nphot = 0;
227 for (i=0; i<n; i++)
228 {
229 if (ptr[i]==0xff)
230 break;
231 nphot += ptr[i]*fWeight[i];
232 }
233
234 Bool_t saturatedlg = kFALSE;
235
236 if (i<n)
237 {
238 nphot = 0;
239
240 ptr = pixel.GetLoGainSamples();
241 if (ptr==NULL)
242 {
243 *fLog << warn << "WARNING - Pixel #" << idx << " saturated but has no lo gains... skipping!" << endl;
244 return kCONTINUE;
245 }
246
247 for (i=0; i<n; i++)
248 {
249 if (ptr[i]==0xff)
250 saturatedlg = kTRUE;
251
252 nphot += ptr[i]*fWeight[i];
253 }
254
255 nphot -= ped.GetPedestal();
256 nphot *= 10;
257 }
258 else
259 nphot -= ped.GetPedestal();
260
261 fCerPhotEvt->AddPixel(idx, nphot, 0);
262
263 if (saturatedlg)
264 saturatedpixels++;
265 }
266
267 if (saturatedpixels>0)
268 *fLog << warn << "WARNING: " << saturatedpixels << " pixel(s) had saturating low gains..." << endl;
269
270 fCerPhotEvt->FixSize();
271 fCerPhotEvt->SetReadyToSave();
272
273 return kTRUE;
274}
275
276// --------------------------------------------------------------------------
277//
278// Set default values for the number of slices and weights:
279//
280void MCerPhotCalc::SetDefaultWeights()
281{
282 const Float_t dummy[15] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
283 fWeight.Set(15, dummy);
284}
Note: See TracBrowser for help on using the repository browser.