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

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