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

Last change on this file since 8296 was 6253, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 10.0 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// return kTRUE the lo gains exist for the actual pixel, else return kFALSE
74//
75Bool_t MRawEvtPixelIter::HasLoGain() const
76{
77 // We have no lo-gain at all
78 if (!fLoGainId)
79 return kFALSE;
80
81 // This is to make the first call of this function in Next()
82 // work properly! NEVER call this function before Next()
83 if (fNumLoGainEntry==0)
84 return kTRUE;
85
86 if (fNumLoGainEntry>fData->fLoGainPixId->GetSize())
87 return kFALSE;
88
89 Bool_t rc = *fHiGainId!=*fLoGainId;
90
91 if (rc)
92 return kFALSE;
93
94 return kTRUE;
95}
96
97// --------------------------------------------------------------------------
98//
99// It steps to the next pixel. If there is no next pixel NULL is returned.
100// If a next pixel where found, a pointer to the primary given (constructor)
101// data structur is returned.
102//
103MRawEvtData *MRawEvtPixelIter::Next()
104{
105 //
106 // if we are already at the last entry there is no 'next' entry anymore
107 //
108 if (fNumHiGainEntry==fData->fHiGainPixId->GetSize())
109 return NULL;
110
111 //
112 // if we are already at the last entry there is no 'next' entry anymore
113 //
114 if (HasLoGain())
115 {
116 //
117 // if higainpixid and logainpixid of the actual pixel are
118 // identical then we have to move the pointer to the next
119 // entry in the lo gains
120 //
121 fNumLoGainEntry++;
122 fLoGainId++;
123 fLoGainPos += fNumLoGainSamples;
124 }
125
126 //
127 // here we have to move the pointer to the next entry in the hi gains
128 //
129 fNumHiGainEntry++;
130 fHiGainId++;
131 fHiGainPos += fNumHiGainSamples;
132
133 //
134 // return a pointer to the 'source' class if we succeed
135 //
136 return fData;
137}
138
139// --------------------------------------------------------------------------
140//
141// Reset the iteration. Jump to the first pixel.
142//
143void MRawEvtPixelIter::Reset()
144{
145 //
146 // set counter to zero
147 //
148 fNumLoGainEntry = 0;
149 fNumHiGainEntry = 0;
150
151 //
152 // set pointer to first entry of arrays
153 //
154 fHiGainId = fData->fHiGainPixId->GetArray()-1;
155 fLoGainId = fData->fLoGainPixId->GetArray();
156 fHiGainPos = fData->fHiGainFadcSamples->GetArray()-fNumHiGainSamples;
157 fLoGainPos = fData->fLoGainFadcSamples->GetArray()-fNumLoGainSamples;
158 fABFlags = fData->fABFlags->GetSize()==0 ? 0 : fData->fABFlags->GetArray();
159
160 //
161 // In case fLoGainPixId.GetSize()=0 some root versions seems to
162 // initialize the array with NULL. This makes both cases work.
163 //
164 if (fLoGainId)
165 fLoGainId -= 1;
166}
167
168// --------------------------------------------------------------------------
169//
170// Calls the draw-function of the actual pixel (see MRawEvtData::Draw)
171//
172void MRawEvtPixelIter::Draw(Option_t *t)
173{
174 fData->Draw(Form("%s%d", t, *fHiGainId));
175}
176
177// --------------------------------------------------------------------------
178//
179// returns the sum of all hi gain fadc samples of the actual pixel
180//
181ULong_t MRawEvtPixelIter::GetSumHiGainSamples() const
182{
183 //
184 // return the sum of the hi gain samples of the present pixel
185 //
186 Byte_t *ptr = fHiGainPos;
187 const Byte_t *end = fHiGainPos + fNumHiGainSamples;
188
189 ULong_t sum=0;
190
191 do sum += *ptr++;
192 while (ptr != end);
193
194 return sum;
195}
196
197// --------------------------------------------------------------------------
198//
199// returns the sum of squares of all hi gain fadc sample of the actual pixel
200//
201ULong_t MRawEvtPixelIter::GetSumSqrHiGainSamples() const
202{
203 //
204 // return the sum of the squares of the hi gain samples of the present pixel
205 //
206 Byte_t *ptr = fHiGainPos;
207 const Byte_t *end = fHiGainPos + fNumHiGainSamples;
208
209 ULong_t sum=0;
210
211 do sum += (*ptr)*(*ptr);
212 while (++ptr != end);
213
214 return sum;
215}
216
217// --------------------------------------------------------------------------
218//
219// Returns the variance (sigma^2) of the HiGainSamples
220//
221Float_t MRawEvtPixelIter::GetVarHiGainSamples() const
222{
223 Byte_t *ptr = fHiGainPos;
224 const Byte_t *end = fHiGainPos + fNumHiGainSamples;
225
226 ULong_t sum=0;
227 ULong_t sqsum=0;
228
229 do {
230 sum += *ptr;
231 sqsum += (*ptr)*(*ptr);
232 } while (++ptr != end);
233
234 return (sqsum-(Float_t)sum*sum/fNumHiGainSamples)/(fNumHiGainSamples-1);
235}
236
237// --------------------------------------------------------------------------
238//
239// Returns the index of the FADC slice the maximum signal in. If the highest
240// slices have the same value the last one is returned.
241//
242Byte_t MRawEvtPixelIter::GetIdxMaxHiGainSample() const
243{
244 Byte_t *ptr = fHiGainPos+1;
245 Byte_t *max = fHiGainPos;
246 const Byte_t *end = fHiGainPos + fNumHiGainSamples;
247
248 do if (*ptr>*max) max = ptr;
249 while (++ptr != end);
250
251 return max-fHiGainPos;
252}
253
254// --------------------------------------------------------------------------
255//
256// Returns the index of the FADC slice the maximum signal in. If no lo-gains
257// are available -1 is returned. If the highest slices have the same value the
258// last one is returned.
259//
260Short_t MRawEvtPixelIter::GetIdxMaxLoGainSample(const Byte_t lofirst) const
261{
262 if (!HasLoGain())
263 return -1; // means: not found
264
265 Byte_t *ptr = fLoGainPos+lofirst+1;
266 Byte_t *max = fLoGainPos+lofirst;
267 const Byte_t *end = fLoGainPos + fNumLoGainSamples;
268
269 do if (*ptr>*max) max = ptr;
270 while (++ptr != end);
271
272 return max-fLoGainPos;
273}
274
275// --------------------------------------------------------------------------
276//
277// Returns the index of the maximum FADC slice from high gain at first. If
278// high gain is saturated it returns the low gain one.
279// If no lo-gains are existing and the hi-gains have saturating values
280// a negative value (-1) is returned.
281//
282Short_t MRawEvtPixelIter::GetIdxMaxHiLoGainSample() const
283{
284 Byte_t max = 0;
285 Char_t maxi = 0;
286
287 for (int i=fNumHiGainSamples-1; i>=0; i--)
288 if (fHiGainPos[i]>max)
289 {
290 max = fHiGainPos[i];
291 maxi = i;
292 }
293
294 return max<0xff ? maxi : GetIdxMaxLoGainSample();
295}
296
297// --------------------------------------------------------------------------
298//
299// Returns the maximum signal of all sliced in the hi gain samples
300//
301Byte_t MRawEvtPixelIter::GetMaxHiGainSample() const
302{
303 Byte_t max = 0;
304
305 for (int i=0; i<fNumHiGainSamples; i++)
306 if (fHiGainPos[i]>max)
307 max = fHiGainPos[i];
308
309 return max;
310}
311
312// --------------------------------------------------------------------------
313//
314// Returns the maximum signal of all sliced in the hi gain samples
315//
316Byte_t MRawEvtPixelIter::GetMaxLoGainSample() const
317{
318 Byte_t max = 0;
319
320 for (int i=fNumLoGainSamples-1; i>=0; i--)
321 if (fLoGainPos[i]>max)
322 max = fLoGainPos[i];
323
324 return max;
325}
326
327// --------------------------------------------------------------------------
328//
329// returns the sum of all lo gain fadc samples of the actual pixel.
330// if no lo gain information is available 0 is returned.
331//
332ULong_t MRawEvtPixelIter::GetSumLoGainSamples() const
333{
334 //
335 // return the sum of the lo gain samples of the present pixel
336 //
337 if (!HasLoGain())
338 return 0;
339
340 Byte_t *ptr = fLoGainPos;
341 const Byte_t *end = fLoGainPos + fNumLoGainSamples;
342
343 ULong_t sum=0;
344
345 do sum += *ptr++;
346 while (ptr != end);
347
348 return sum;
349}
350
351// --------------------------------------------------------------------------
352//
353// returns the sum of squares of all hi gain fadc sample of the actual pixel
354//
355ULong_t MRawEvtPixelIter::GetSumSqrLoGainSamples() const
356{
357 //
358 // return the sum of the lo gain samples squares of the present pixel
359 //
360 if (!HasLoGain())
361 return 0;
362
363 Byte_t *ptr = fLoGainPos;
364 const Byte_t *end = fLoGainPos + fNumLoGainSamples;
365
366 ULong_t sum=0;
367
368 do sum += (*ptr)*(*ptr);
369 while (++ptr != end);
370
371 return sum;
372}
Note: See TracBrowser for help on using the repository browser.