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

Last change on this file since 9180 was 8571, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 4.9 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 fNumBytesHiGain = dat->GetNumHiGainSamples()*dat->GetNumBytesPerSample();
66 fNumBytesLoGain = dat->GetNumLoGainSamples()*dat->GetNumBytesPerSample();
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//
77MRawEvtData *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 // For old MC data which stores hi- and lo-gain in two arrays
87 // we have to use the old algorithm
88 //
89 if (fData->fLoGainPixId->GetSize())
90 {
91 fNumHiGainEntry++;
92 fHiGainId++;
93 fHiGainPos += fNumBytesHiGain;
94
95 fNumLoGainEntry++;
96 fLoGainId++;
97 fLoGainPos += fNumBytesLoGain;
98 }
99 else
100 {
101 fNumLoGainEntry = ++fNumHiGainEntry;
102 fLoGainId = ++fHiGainId;
103
104 fHiGainPos += fNumBytesHiGain+fNumBytesLoGain;
105 fLoGainPos = fHiGainPos + fNumBytesHiGain;
106 }
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//
118void 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 fABFlags = fData->fABFlags->GetSize()==0 ? 0 : fData->fABFlags->GetArray();
131
132 //
133 // For old MC data which stores hi- and lo-gain in two arrays
134 // we have to use the old algorithm
135 //
136 if (fData->fLoGainPixId->GetSize())
137 {
138 fLoGainId = fData->fLoGainPixId->GetArray();
139 fHiGainPos = fData->fHiGainFadcSamples->GetArray()-fNumBytesHiGain;
140 fLoGainPos = fData->fLoGainFadcSamples->GetArray()-fNumBytesLoGain;
141 }
142 else
143 {
144 fLoGainId = fHiGainId;
145 fLoGainPos = fHiGainPos+fNumBytesHiGain;
146 fHiGainPos = fData->fHiGainFadcSamples->GetArray()-(fNumBytesHiGain+fNumBytesLoGain);
147 }
148
149 //
150 // In case fLoGainPixId.GetSize()=0 some root versions seems to
151 // initialize the array with NULL. This makes both cases work.
152 //
153 if (fLoGainId)
154 fLoGainId -= 1;
155}
156
157// --------------------------------------------------------------------------
158//
159// Calls the draw-function of the actual pixel (see MRawEvtData::Draw)
160//
161void MRawEvtPixelIter::Draw(Option_t *t)
162{
163 fData->Draw(Form("%s%d", t, *fHiGainId));
164}
Note: See TracBrowser for help on using the repository browser.