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

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