source: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc@ 4966

Last change on this file since 4966 was 4643, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 9.4 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): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Markus Gaus 10/2002 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26///////////////////////////////////////////////////////////////////////////////
27//
28// MRawEvtPixelIter
29//
30// class to iterate over all pixels of one event.
31// The calling is similar to a root iterator:
32//
33// MRawEvtData *evtdata; // must be filled with data from somewhere
34// MRawEvtPixelIter pixel(evtdata); // evtdata: ptr to event you want to iterate
35//
36// while (pixel.Next())
37// {
38// // here you can access the actual time slices by using
39// // pixel.GetPixelId();
40// // pixel.GetHiGainFadcSamples()[i]; // i is the number of the slice
41// // pixel.HasLoGain(); // check if pixel has
42// // pixel.GetLoGainFadcSamples()[i]; // i is the number of the slice
43//
44// // WARNING: Don't acces more time slices than available.
45// // Get the numbers by calling: evtdata->GetNum[Lo,Hi]GainSamples()
46// // This number is constant for one event
47// }
48//
49///////////////////////////////////////////////////////////////////////////////
50#include "MRawEvtPixelIter.h"
51
52#include <TArrayC.h>
53
54#include "MRawEvtData.h"
55
56#include "MArrayS.h"
57#include "MArrayB.h"
58
59ClassImp(MRawEvtPixelIter);
60
61using namespace std;
62
63MRawEvtPixelIter::MRawEvtPixelIter(MRawEvtData *dat) : fABFlags(0), fData(dat)
64{
65 fNumHiGainSamples = dat->GetNumHiGainSamples();
66 fNumLoGainSamples = dat->GetNumLoGainSamples();
67
68 Reset();
69}
70
71// --------------------------------------------------------------------------
72//
73// It steps to the next pixel. If there is no next pixel NULL is returned.
74// If a next pixel where found, a pointer to the primary given (constructor)
75// data structur is returned.
76//
77MRawEvtData *MRawEvtPixelIter::Next()
78{
79 //
80 // if we are already at the last entry there is no 'next' entry anymore
81 //
82 if (fNumHiGainEntry==fData->fHiGainPixId->GetSize())
83 return NULL;
84
85 //
86 // if we are already at the last entry there is no 'next' entry anymore
87 //
88 if (fNumLoGainEntry != fData->fLoGainPixId->GetSize())
89 if (HasLoGain())
90 {
91 //
92 // if higainpixid and logainpixid of the actual pixel are
93 // identical then we have to move the pointer to the next
94 // entry in the lo gains
95 //
96 fNumLoGainEntry++;
97 fLoGainId++;
98 fLoGainPos += fNumLoGainSamples;
99 }
100
101 //
102 // here we have to move the pointer to the next entry in the hi gains
103 //
104 fNumHiGainEntry++;
105 fHiGainId++;
106 fHiGainPos += fNumHiGainSamples;
107
108 //
109 // return a pointer to the 'source' class if we succeed
110 //
111 return fData;
112}
113
114// --------------------------------------------------------------------------
115//
116// Reset the iteration. Jump to the first pixel.
117//
118void MRawEvtPixelIter::Reset()
119{
120 //
121 // set counter to zero
122 //
123 fNumLoGainEntry = 0;
124 fNumHiGainEntry = 0;
125
126 //
127 // set pointer to first entry of arrays
128 //
129 fHiGainId = fData->fHiGainPixId->GetArray()-1;
130 fLoGainId = fData->fLoGainPixId->GetArray();
131 fHiGainPos = fData->fHiGainFadcSamples->GetArray()-fNumHiGainSamples;
132 fLoGainPos = fData->fLoGainFadcSamples->GetArray()-fNumLoGainSamples;
133 fABFlags = fData->fABFlags->GetSize()==0 ? 0 : fData->fABFlags->GetArray();
134
135 //
136 // In case fLoGainPixId.GetSize()=0 some root versions seems to
137 // initialize the array with NULL. This makes both cases work.
138 //
139 if (fLoGainId)
140 fLoGainId -= 1;
141}
142
143// --------------------------------------------------------------------------
144//
145// Calls the draw-function of the actual pixel (see MRawEvtData::Draw)
146//
147void MRawEvtPixelIter::Draw(Option_t *t)
148{
149 fData->Draw(Form("%s%d", t, *fHiGainId));
150}
151
152// --------------------------------------------------------------------------
153//
154// returns the sum of all hi gain fadc samples of the actual pixel
155//
156ULong_t MRawEvtPixelIter::GetSumHiGainSamples() const
157{
158 //
159 // return the sum of the hi gain samples of the present pixel
160 //
161 Byte_t *ptr = fHiGainPos;
162 const Byte_t *end = ptr + fNumHiGainSamples;
163
164 ULong_t sum=0;
165
166 do sum += *ptr++;
167 while (ptr != end);
168
169 return sum;
170}
171
172// --------------------------------------------------------------------------
173//
174// returns the sum of squares of all hi gain fadc sample of the actual pixel
175//
176ULong_t MRawEvtPixelIter::GetSumSqrHiGainSamples() const
177{
178 //
179 // return the sum of the squares of the hi gain samples of the present pixel
180 //
181 Byte_t *ptr = fHiGainPos;
182 const Byte_t *end = ptr + fNumHiGainSamples;
183
184 ULong_t sum=0;
185
186 do sum += (*ptr)*(*ptr);
187 while (++ptr != end);
188
189 return sum;
190}
191
192// --------------------------------------------------------------------------
193//
194// Returns the variance (sigma^2) of the HiGainSamples
195//
196Float_t MRawEvtPixelIter::GetVarHiGainSamples() const
197{
198 Byte_t *ptr = fHiGainPos;
199 const Byte_t *end = ptr + fNumHiGainSamples;
200
201 ULong_t sum=0;
202 ULong_t sqsum=0;
203
204 do {
205 sum += *ptr;
206 sqsum += (*ptr)*(*ptr);
207 } while (++ptr != end);
208
209 return (sqsum-(Float_t)sum*sum/fNumHiGainSamples)/(fNumHiGainSamples-1);
210}
211
212// --------------------------------------------------------------------------
213//
214// Returns the index of the FADC slice the maximum signal in. If the highest
215// slices have the same value the last one is returned.
216//
217Byte_t MRawEvtPixelIter::GetIdxMaxHiGainSample() const
218{
219 Byte_t *ptr = fHiGainPos+1;
220 Byte_t *max = fHiGainPos;
221 const Byte_t *end = ptr + fNumHiGainSamples;
222
223 do if (*ptr>*max) max = ptr;
224 while (++ptr != end);
225
226 return max-fHiGainPos;
227}
228
229// --------------------------------------------------------------------------
230//
231// Returns the index of the FADC slice the maximum signal in. If no lo-gains
232// are available -1 is returned. If the highest slices have the same value the
233// last one is returned.
234//
235Short_t MRawEvtPixelIter::GetIdxMaxLoGainSample(const Byte_t lofirst) const
236{
237
238 if (!HasLoGain())
239 return -1; // means: not found
240
241 Byte_t *ptr = fLoGainPos+lofirst+1;
242 Byte_t *max = fLoGainPos+lofirst;
243 const Byte_t *end = fLoGainPos + fNumLoGainSamples;
244
245 do if (*ptr>*max) max = ptr;
246 while (++ptr != end);
247
248 return max-fLoGainPos;
249}
250
251// --------------------------------------------------------------------------
252//
253// Returns the index of the maximum FADC slice from high gain at first. If
254// high gain is saturated it returns the low gain one.
255// If no lo-gains are existing and the hi-gains have saturating values
256// a negative value (-1) is returned.
257//
258Short_t MRawEvtPixelIter::GetIdxMaxHiLoGainSample() const
259{
260 Byte_t max = 0;
261 Char_t maxi = 0;
262
263 for (int i=fNumHiGainSamples-1; i>=0; i--)
264 if (fHiGainPos[i]>max)
265 {
266 max = fHiGainPos[i];
267 maxi = i;
268 }
269
270 return max<0xff ? maxi : GetIdxMaxLoGainSample();
271}
272
273// --------------------------------------------------------------------------
274//
275// Returns the maximum signal of all sliced in the hi gain samples
276//
277Byte_t MRawEvtPixelIter::GetMaxHiGainSample() const
278{
279 Byte_t max = 0;
280
281 for (int i=0; i<fNumHiGainSamples; i++)
282 if (fHiGainPos[i]>max)
283 max = fHiGainPos[i];
284
285 return max;
286}
287
288// --------------------------------------------------------------------------
289//
290// Returns the maximum signal of all sliced in the hi gain samples
291//
292Byte_t MRawEvtPixelIter::GetMaxLoGainSample() const
293{
294
295 Byte_t max = 0;
296
297 for (int i=fNumLoGainSamples-1; i>=0; i--)
298 if (fLoGainPos[i]>max)
299 max = fLoGainPos[i];
300
301 return max;
302}
303
304// --------------------------------------------------------------------------
305//
306// returns the sum of all lo gain fadc samples of the actual pixel.
307// if no lo gain information is available 0 is returned.
308//
309ULong_t MRawEvtPixelIter::GetSumLoGainSamples() const
310{
311 //
312 // return the sum of the lo gain samples of the present pixel
313 //
314 if (!HasLoGain())
315 return 0;
316
317 Byte_t *ptr = fLoGainPos;
318 const Byte_t *end = ptr + fNumLoGainSamples;
319
320 ULong_t sum=0;
321
322 do sum += *ptr++;
323 while (ptr != end);
324
325 return sum;
326}
327
328// --------------------------------------------------------------------------
329//
330// returns the sum of squares of all hi gain fadc sample of the actual pixel
331//
332ULong_t MRawEvtPixelIter::GetSumSqrLoGainSamples() const
333{
334 //
335 // return the sum of the lo gain samples squares of the present pixel
336 //
337 if (!HasLoGain())
338 return 0;
339
340 Byte_t *ptr = fLoGainPos;
341 const Byte_t *end = ptr + fNumLoGainSamples;
342
343 ULong_t sum=0;
344
345 do sum += (*ptr)*(*ptr);
346 while (++ptr != end);
347
348 return sum;
349}
Note: See TracBrowser for help on using the repository browser.