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