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

Last change on this file since 2179 was 2178, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.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-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
189Float_t MRawEvtPixelIter::GetVarHiGainSamples() const
190{
191 Byte_t *ptr = fHiGainPos;
192 const Byte_t *end = ptr + fNumHiGainSamples;
193
194 ULong_t sum=0;
195 ULong_t sqsum=0;
196
197 do {
198 sum += *ptr;
199 sqsum += (*ptr)*(*ptr);
200 } while (++ptr != end);
201
202 return (sqsum-(Float_t)sum*sum/fNumHiGainSamples)/(fNumHiGainSamples-1);
203}
204
205// --------------------------------------------------------------------------
206//
207// returns the sum of all lo gain fadc samples of the actual pixel.
208// if no lo gain information is available 0 is returned.
209//
210ULong_t MRawEvtPixelIter::GetSumLoGainSamples() const
211{
212 //
213 // return the sum of the lo gain samples of the present pixel
214 //
215 if (!HasLoGain())
216 return 0;
217
218 Byte_t *ptr = fLoGainPos;
219 const Byte_t *end = ptr + fNumLoGainSamples;
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::GetSumSqrLoGainSamples() const
234{
235 //
236 // return the sum of the lo gain samples squares of the present pixel
237 //
238 if (!HasLoGain())
239 return 0;
240
241 Byte_t *ptr = fLoGainPos;
242 const Byte_t *end = ptr + fNumLoGainSamples;
243
244 ULong_t sum=0;
245
246 do sum += (*ptr)*(*ptr);
247 while (++ptr != end);
248
249 return sum;
250}
Note: See TracBrowser for help on using the repository browser.