source: branches/AddingGoogleTestEnvironment/mraw/MRawEvtPixelIter.cc@ 18294

Last change on this file since 18294 was 11488, checked in by tbretz, 13 years ago
Added iterator to start cell.
File size: 5.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) :
64 fABFlags(0), fStartCell(0), fData(dat)
65{
66 fNumBytesHiGain = dat->GetNumHiGainSamples()*dat->GetNumBytesPerSample();
67 fNumBytesLoGain = dat->GetNumLoGainSamples()*dat->GetNumBytesPerSample();
68
69 Reset();
70}
71
72// --------------------------------------------------------------------------
73//
74// It steps to the next pixel. If there is no next pixel NULL is returned.
75// If a next pixel where found, a pointer to the primary given (constructor)
76// data structur is returned.
77//
78MRawEvtData *MRawEvtPixelIter::Next()
79{
80 //
81 // if we are already at the last entry there is no 'next' entry anymore
82 //
83 if (fNumHiGainEntry==fData->fHiGainPixId->GetSize())
84 return NULL;
85
86 //
87 // For old MC data which stores hi- and lo-gain in two arrays
88 // we have to use the old algorithm
89 //
90 if (fData->fLoGainPixId->GetSize())
91 {
92 fNumHiGainEntry++;
93 fHiGainId++;
94 fHiGainPos += fNumBytesHiGain;
95
96 fNumLoGainEntry++;
97 fLoGainId++;
98 fLoGainPos += fNumBytesLoGain;
99 }
100 else
101 {
102 fNumLoGainEntry = ++fNumHiGainEntry;
103 fLoGainId = ++fHiGainId;
104
105 fHiGainPos += fNumBytesHiGain+fNumBytesLoGain;
106 fLoGainPos = fHiGainPos + fNumBytesHiGain;
107
108 fStartCell++;
109 }
110
111
112 //
113 // return a pointer to the 'source' class if we succeed
114 //
115 return fData;
116}
117
118// --------------------------------------------------------------------------
119//
120// Reset the iteration. Jump to the first pixel.
121//
122void MRawEvtPixelIter::Reset()
123{
124 //
125 // set counter to zero
126 //
127 fNumLoGainEntry = 0;
128 fNumHiGainEntry = 0;
129
130 //
131 // set pointer to first entry of arrays
132 //
133 fHiGainId = fData->fHiGainPixId->GetArray()-1;
134 fABFlags = fData->fABFlags->GetSize()==0 ? 0 : fData->fABFlags->GetArray();
135
136 //
137 // For old MC data which stores hi- and lo-gain in two arrays
138 // we have to use the old algorithm
139 //
140 if (fData->fLoGainPixId->GetSize())
141 {
142 fLoGainId = fData->fLoGainPixId->GetArray();
143 fHiGainPos = fData->fHiGainFadcSamples->GetArray()-fNumBytesHiGain;
144 fLoGainPos = fData->fLoGainFadcSamples->GetArray()-fNumBytesLoGain;
145 }
146 else
147 {
148 fLoGainId = fHiGainId;
149 fLoGainPos = fHiGainPos+fNumBytesHiGain;
150 fHiGainPos = fData->fHiGainFadcSamples->GetArray()-(fNumBytesHiGain+fNumBytesLoGain);
151 }
152
153 fStartCell = fData->fStartCells->GetSize() ? fData->GetStartCells()-1 : 0;
154
155 //
156 // In case fLoGainPixId.GetSize()=0 some root versions seems to
157 // initialize the array with NULL. This makes both cases work.
158 //
159 if (fLoGainId)
160 fLoGainId -= 1;
161}
162
163// --------------------------------------------------------------------------
164//
165// Calls the draw-function of the actual pixel (see MRawEvtData::Draw)
166//
167void MRawEvtPixelIter::Draw(Option_t *t)
168{
169 fData->Draw(Form("%s%d", t, *fHiGainId));
170}
Note: See TracBrowser for help on using the repository browser.