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

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