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 <TArrayC.h>
|
---|
53 |
|
---|
54 | #include "MRawEvtData.h"
|
---|
55 |
|
---|
56 | #include "MArrayS.h"
|
---|
57 | #include "MArrayB.h"
|
---|
58 |
|
---|
59 | ClassImp(MRawEvtPixelIter);
|
---|
60 |
|
---|
61 | using namespace std;
|
---|
62 |
|
---|
63 | MRawEvtPixelIter::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 | //
|
---|
77 | MRawEvtData *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 | //
|
---|
118 | void 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 | //
|
---|
147 | void 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 | //
|
---|
156 | ULong_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 | //
|
---|
176 | ULong_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 | //
|
---|
196 | Float_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 | //
|
---|
217 | Byte_t MRawEvtPixelIter::GetIdxMaxHiGainSample() const
|
---|
218 | {
|
---|
219 | Byte_t max = 0;
|
---|
220 | Byte_t maxi = 0;
|
---|
221 |
|
---|
222 | for (int i=0; i<fNumHiGainSamples; i++)
|
---|
223 | if (fHiGainPos[i]>max)
|
---|
224 | {
|
---|
225 | max = fHiGainPos[i];
|
---|
226 | maxi = i;
|
---|
227 | }
|
---|
228 |
|
---|
229 | return maxi;
|
---|
230 | }
|
---|
231 |
|
---|
232 | // --------------------------------------------------------------------------
|
---|
233 | //
|
---|
234 | // Returns the index of the FADC slice the maximum signal in. If no lo-gains
|
---|
235 | // are available -1 is returned. If the highest slices have the same value the
|
---|
236 | // last one is returned.
|
---|
237 | //
|
---|
238 | Short_t MRawEvtPixelIter::GetIdxMaxLoGainSample() const
|
---|
239 | {
|
---|
240 | if (!HasLoGain())
|
---|
241 | return -1; // means: not found
|
---|
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 index of the maximum FADC slice from high gain at first. If
|
---|
259 | // high gain is saturated it returns the low gain one.
|
---|
260 | // If no lo-gains are existing and the hi-gains have saturating values
|
---|
261 | // a negative value (-1) is returned.
|
---|
262 | //
|
---|
263 | Short_t MRawEvtPixelIter::GetIdxMaxHiLoGainSample() const
|
---|
264 | {
|
---|
265 | Byte_t max = 0;
|
---|
266 | Char_t maxi = 0;
|
---|
267 |
|
---|
268 | for (int i=fNumHiGainSamples-1; i>=0; i--)
|
---|
269 | if (fHiGainPos[i]>max)
|
---|
270 | {
|
---|
271 | max = fHiGainPos[i];
|
---|
272 | maxi = i;
|
---|
273 | }
|
---|
274 |
|
---|
275 | return max<0xff ? maxi : GetIdxMaxLoGainSample();
|
---|
276 | }
|
---|
277 |
|
---|
278 | // --------------------------------------------------------------------------
|
---|
279 | //
|
---|
280 | // Returns the maximum signal of all sliced in the hi gain samples
|
---|
281 | //
|
---|
282 | Byte_t MRawEvtPixelIter::GetMaxHiGainSample() const
|
---|
283 | {
|
---|
284 | Byte_t max = 0;
|
---|
285 |
|
---|
286 | for (int i=0; i<fNumHiGainSamples; i++)
|
---|
287 | if (fHiGainPos[i]>max)
|
---|
288 | max = fHiGainPos[i];
|
---|
289 |
|
---|
290 | return max;
|
---|
291 | }
|
---|
292 |
|
---|
293 | // --------------------------------------------------------------------------
|
---|
294 | //
|
---|
295 | // Returns the maximum signal of all sliced in the hi gain samples
|
---|
296 | //
|
---|
297 | Byte_t MRawEvtPixelIter::GetMaxLoGainSample() const
|
---|
298 | {
|
---|
299 | Byte_t max = 0;
|
---|
300 |
|
---|
301 | for (int i=fNumLoGainSamples-1; i>=0; i--)
|
---|
302 | if (fLoGainPos[i]>max)
|
---|
303 | max = fLoGainPos[i];
|
---|
304 |
|
---|
305 | return max;
|
---|
306 | }
|
---|
307 |
|
---|
308 | // --------------------------------------------------------------------------
|
---|
309 | //
|
---|
310 | // returns the sum of all lo gain fadc samples of the actual pixel.
|
---|
311 | // if no lo gain information is available 0 is returned.
|
---|
312 | //
|
---|
313 | ULong_t MRawEvtPixelIter::GetSumLoGainSamples() const
|
---|
314 | {
|
---|
315 | //
|
---|
316 | // return the sum of the lo gain samples of the present pixel
|
---|
317 | //
|
---|
318 | if (!HasLoGain())
|
---|
319 | return 0;
|
---|
320 |
|
---|
321 | Byte_t *ptr = fLoGainPos;
|
---|
322 | const Byte_t *end = ptr + fNumLoGainSamples;
|
---|
323 |
|
---|
324 | ULong_t sum=0;
|
---|
325 |
|
---|
326 | do sum += *ptr++;
|
---|
327 | while (ptr != end);
|
---|
328 |
|
---|
329 | return sum;
|
---|
330 | }
|
---|
331 |
|
---|
332 | // --------------------------------------------------------------------------
|
---|
333 | //
|
---|
334 | // returns the sum of squares of all hi gain fadc sample of the actual pixel
|
---|
335 | //
|
---|
336 | ULong_t MRawEvtPixelIter::GetSumSqrLoGainSamples() const
|
---|
337 | {
|
---|
338 | //
|
---|
339 | // return the sum of the lo gain samples squares of the present pixel
|
---|
340 | //
|
---|
341 | if (!HasLoGain())
|
---|
342 | return 0;
|
---|
343 |
|
---|
344 | Byte_t *ptr = fLoGainPos;
|
---|
345 | const Byte_t *end = ptr + fNumLoGainSamples;
|
---|
346 |
|
---|
347 | ULong_t sum=0;
|
---|
348 |
|
---|
349 | do sum += (*ptr)*(*ptr);
|
---|
350 | while (++ptr != end);
|
---|
351 |
|
---|
352 | return sum;
|
---|
353 | }
|
---|