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

Last change on this file since 1835 was 1548, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 6.7 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 sum of all lo gain fadc samples of the actual pixel.
192// if no lo gain information is available 0 is returned.
193//
194ULong_t MRawEvtPixelIter::GetSumLoGainSamples() const
195{
196 //
197 // return the sum of the lo gain samples of the present pixel
198 //
199 if (!HasLoGain())
200 return 0;
201
202 Byte_t *ptr = fLoGainPos;
203 const Byte_t *end = ptr + fNumLoGainSamples;
204
205 ULong_t sum=0;
206
207 do sum += *ptr++;
208 while (ptr != end);
209
210 return sum;
211}
212
213// --------------------------------------------------------------------------
214//
215// returns the sum of squares of all hi gain fadc sample of the actual pixel
216//
217ULong_t MRawEvtPixelIter::GetSumSqrLoGainSamples() const
218{
219 //
220 // return the sum of the lo gain samples squares of the present pixel
221 //
222 if (!HasLoGain())
223 return 0;
224
225 Byte_t *ptr = fLoGainPos;
226 const Byte_t *end = ptr + fNumLoGainSamples;
227
228 ULong_t sum=0;
229
230 do sum += (*ptr)*(*ptr);
231 while (++ptr != end);
232
233 return sum;
234}
Note: See TracBrowser for help on using the repository browser.