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

Last change on this file since 3949 was 3949, checked in by gaug, 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) : 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->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 gLog << count << endl;
249
250 return max-fLoGainPos;
251}
252
253// --------------------------------------------------------------------------
254//
255// Returns the index of the maximum FADC slice from high gain at first. If
256// high gain is saturated it returns the low gain one.
257// If no lo-gains are existing and the hi-gains have saturating values
258// a negative value (-1) is returned.
259//
260Short_t MRawEvtPixelIter::GetIdxMaxHiLoGainSample() const
261{
262 Byte_t max = 0;
263 Char_t maxi = 0;
264
265 for (int i=fNumHiGainSamples-1; i>=0; i--)
266 if (fHiGainPos[i]>max)
267 {
268 max = fHiGainPos[i];
269 maxi = i;
270 }
271
272 return max<0xff ? maxi : GetIdxMaxLoGainSample();
273}
274
275// --------------------------------------------------------------------------
276//
277// Returns the maximum signal of all sliced in the hi gain samples
278//
279Byte_t MRawEvtPixelIter::GetMaxHiGainSample() const
280{
281 Byte_t max = 0;
282
283 for (int i=0; i<fNumHiGainSamples; i++)
284 if (fHiGainPos[i]>max)
285 max = fHiGainPos[i];
286
287 return max;
288}
289
290// --------------------------------------------------------------------------
291//
292// Returns the maximum signal of all sliced in the hi gain samples
293//
294Byte_t MRawEvtPixelIter::GetMaxLoGainSample() const
295{
296
297 Byte_t max = 0;
298
299 for (int i=fNumLoGainSamples-1; i>=0; i--)
300 if (fLoGainPos[i]>max)
301 max = fLoGainPos[i];
302
303 return max;
304}
305
306// --------------------------------------------------------------------------
307//
308// returns the sum of all lo gain fadc samples of the actual pixel.
309// if no lo gain information is available 0 is returned.
310//
311ULong_t MRawEvtPixelIter::GetSumLoGainSamples() const
312{
313 //
314 // return the sum of the lo gain samples of the present pixel
315 //
316 if (!HasLoGain())
317 return 0;
318
319 Byte_t *ptr = fLoGainPos;
320 const Byte_t *end = ptr + fNumLoGainSamples;
321
322 ULong_t sum=0;
323
324 do sum += *ptr++;
325 while (ptr != end);
326
327 return sum;
328}
329
330// --------------------------------------------------------------------------
331//
332// returns the sum of squares of all hi gain fadc sample of the actual pixel
333//
334ULong_t MRawEvtPixelIter::GetSumSqrLoGainSamples() const
335{
336 //
337 // return the sum of the lo gain samples squares of the present pixel
338 //
339 if (!HasLoGain())
340 return 0;
341
342 Byte_t *ptr = fLoGainPos;
343 const Byte_t *end = ptr + fNumLoGainSamples;
344
345 ULong_t sum=0;
346
347 do sum += (*ptr)*(*ptr);
348 while (++ptr != end);
349
350 return sum;
351}
Note: See TracBrowser for help on using the repository browser.