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

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