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

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