| 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 |
|
|---|
| 59 | ClassImp(MRawEvtPixelIter);
|
|---|
| 60 |
|
|---|
| 61 | using namespace std;
|
|---|
| 62 |
|
|---|
| 63 | MRawEvtPixelIter::MRawEvtPixelIter(MRawEvtData *dat) : fABFlags(0), 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 | // 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 += fNumHiGainSamples;
|
|---|
| 94 |
|
|---|
| 95 | fNumLoGainEntry++;
|
|---|
| 96 | fLoGainId++;
|
|---|
| 97 | fLoGainPos += fNumLoGainSamples;
|
|---|
| 98 | }
|
|---|
| 99 | else
|
|---|
| 100 | {
|
|---|
| 101 | fNumLoGainEntry = ++fNumHiGainEntry;
|
|---|
| 102 | fLoGainId = ++fHiGainId;
|
|---|
| 103 |
|
|---|
| 104 | fHiGainPos += fNumHiGainSamples+fNumLoGainSamples;
|
|---|
| 105 | fLoGainPos = fHiGainPos + fNumHiGainSamples;
|
|---|
| 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 | //
|
|---|
| 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 | 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()-fNumHiGainSamples;
|
|---|
| 140 | fLoGainPos = fData->fLoGainFadcSamples->GetArray()-fNumLoGainSamples;
|
|---|
| 141 | }
|
|---|
| 142 | else
|
|---|
| 143 | {
|
|---|
| 144 | fLoGainId = fHiGainId;
|
|---|
| 145 | fLoGainPos = fHiGainPos+fNumHiGainSamples;
|
|---|
| 146 | fHiGainPos = fData->fHiGainFadcSamples->GetArray()-(fNumHiGainSamples+fNumLoGainSamples);
|
|---|
| 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 | //
|
|---|
| 161 | void MRawEvtPixelIter::Draw(Option_t *t)
|
|---|
| 162 | {
|
|---|
| 163 | fData->Draw(Form("%s%d", t, *fHiGainId));
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | /*
|
|---|
| 167 | // --------------------------------------------------------------------------
|
|---|
| 168 | //
|
|---|
| 169 | // Returns the index of the FADC slice the maximum signal in. If the highest
|
|---|
| 170 | // slices have the same value the first one is returned.
|
|---|
| 171 | //
|
|---|
| 172 | Byte_t MRawEvtPixelIter::GetIdxMaxHiGainSample(const Byte_t hifirst, const Byte_t hilast) const
|
|---|
| 173 | {
|
|---|
| 174 | const Int_t l = hilast>fNumHiGainSamples ? fNumHiGainSamples : hilast+1;
|
|---|
| 175 |
|
|---|
| 176 | Byte_t *beg = fHiGainPos+hifirst;
|
|---|
| 177 |
|
|---|
| 178 | Byte_t *ptr = beg+1;
|
|---|
| 179 | Byte_t *max = beg;
|
|---|
| 180 | const Byte_t *end = fHiGainPos + l;
|
|---|
| 181 |
|
|---|
| 182 | do if (*ptr>*max) max = ptr;
|
|---|
| 183 | while (++ptr != end);
|
|---|
| 184 |
|
|---|
| 185 | return max-fHiGainPos;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | // --------------------------------------------------------------------------
|
|---|
| 189 | //
|
|---|
| 190 | // Returns the index of the FADC slice the maximum signal in. If no lo-gains
|
|---|
| 191 | // are available -1 is returned. If the highest slices have the same value
|
|---|
| 192 | // the first one is returned.
|
|---|
| 193 | //
|
|---|
| 194 | Short_t MRawEvtPixelIter::GetIdxMaxLoGainSample(const Byte_t lofirst, const Byte_t lolast) const
|
|---|
| 195 | {
|
|---|
| 196 | if (!HasLoGain())
|
|---|
| 197 | return -1; // means: not found
|
|---|
| 198 |
|
|---|
| 199 | const Int_t l = lolast>fNumLoGainSamples ? fNumLoGainSamples : lolast+1;
|
|---|
| 200 |
|
|---|
| 201 | Byte_t *beg = fLoGainPos+lofirst;
|
|---|
| 202 |
|
|---|
| 203 | Byte_t *ptr = beg+1;
|
|---|
| 204 | Byte_t *max = beg;
|
|---|
| 205 | const Byte_t *end = fLoGainPos + l;
|
|---|
| 206 |
|
|---|
| 207 | do if (*ptr>*max) max = ptr;
|
|---|
| 208 | while (++ptr != end);
|
|---|
| 209 |
|
|---|
| 210 | return max-fLoGainPos;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | // --------------------------------------------------------------------------
|
|---|
| 214 | //
|
|---|
| 215 | // Returns the maximum signal of all sliced in the hi gain samples
|
|---|
| 216 | //
|
|---|
| 217 | Byte_t MRawEvtPixelIter::GetMaxHiGainSample(const Byte_t hifirst, const Byte_t hilast) const
|
|---|
| 218 | {
|
|---|
| 219 | Byte_t max = 0;
|
|---|
| 220 |
|
|---|
| 221 | const Int_t f = hifirst;
|
|---|
| 222 | const Int_t l = hilast>fNumHiGainSamples ? fNumHiGainSamples : hilast+1;
|
|---|
| 223 |
|
|---|
| 224 | for (int i=f; i<l; i++)
|
|---|
| 225 | if (fHiGainPos[i]>max)
|
|---|
| 226 | max = fHiGainPos[i];
|
|---|
| 227 |
|
|---|
| 228 | return max;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | // --------------------------------------------------------------------------
|
|---|
| 232 | //
|
|---|
| 233 | // returns the sum of all hi gain fadc samples of the actual pixel
|
|---|
| 234 | //
|
|---|
| 235 | ULong_t MRawEvtPixelIter::GetSumHiGainSamples() const
|
|---|
| 236 | {
|
|---|
| 237 | //
|
|---|
| 238 | // return the sum of the hi gain samples of the present pixel
|
|---|
| 239 | //
|
|---|
| 240 | Byte_t *ptr = fHiGainPos;
|
|---|
| 241 | const Byte_t *end = fHiGainPos + fNumHiGainSamples;
|
|---|
| 242 |
|
|---|
| 243 | ULong_t sum=0;
|
|---|
| 244 |
|
|---|
| 245 | do sum += *ptr++;
|
|---|
| 246 | while (ptr != end);
|
|---|
| 247 |
|
|---|
| 248 | return sum;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | // --------------------------------------------------------------------------
|
|---|
| 252 | //
|
|---|
| 253 | // returns the sum of squares of all hi gain fadc sample of the actual pixel
|
|---|
| 254 | //
|
|---|
| 255 | ULong_t MRawEvtPixelIter::GetSumSqrHiGainSamples() const
|
|---|
| 256 | {
|
|---|
| 257 | //
|
|---|
| 258 | // return the sum of the squares of the hi gain samples of the present pixel
|
|---|
| 259 | //
|
|---|
| 260 | Byte_t *ptr = fHiGainPos;
|
|---|
| 261 | const Byte_t *end = fHiGainPos + fNumHiGainSamples;
|
|---|
| 262 |
|
|---|
| 263 | ULong_t sum=0;
|
|---|
| 264 |
|
|---|
| 265 | do sum += (*ptr)*(*ptr);
|
|---|
| 266 | while (++ptr != end);
|
|---|
| 267 |
|
|---|
| 268 | return sum;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | // --------------------------------------------------------------------------
|
|---|
| 272 | //
|
|---|
| 273 | // Returns the variance (sigma^2) of the HiGainSamples
|
|---|
| 274 | //
|
|---|
| 275 | Float_t MRawEvtPixelIter::GetVarHiGainSamples() const
|
|---|
| 276 | {
|
|---|
| 277 | Byte_t *ptr = fHiGainPos;
|
|---|
| 278 | const Byte_t *end = fHiGainPos + fNumHiGainSamples;
|
|---|
| 279 |
|
|---|
| 280 | ULong_t sum=0;
|
|---|
| 281 | ULong_t sqsum=0;
|
|---|
| 282 |
|
|---|
| 283 | do {
|
|---|
| 284 | sum += *ptr;
|
|---|
| 285 | sqsum += (*ptr)*(*ptr);
|
|---|
| 286 | } while (++ptr != end);
|
|---|
| 287 |
|
|---|
| 288 | return (sqsum-(Float_t)sum*sum/fNumHiGainSamples)/(fNumHiGainSamples-1);
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | // --------------------------------------------------------------------------
|
|---|
| 292 | //
|
|---|
| 293 | // Returns the index of the maximum FADC slice from high gain at first. If
|
|---|
| 294 | // high gain is saturated it returns the low gain one.
|
|---|
| 295 | // If no lo-gains are existing and the hi-gains have saturating values
|
|---|
| 296 | // a negative value (-1) is returned.
|
|---|
| 297 | //
|
|---|
| 298 | Short_t MRawEvtPixelIter::GetIdxMaxHiLoGainSample() const
|
|---|
| 299 | {
|
|---|
| 300 | Byte_t max = 0;
|
|---|
| 301 | Char_t maxi = 0;
|
|---|
| 302 |
|
|---|
| 303 | for (int i=fNumHiGainSamples-1; i>=0; i--)
|
|---|
| 304 | if (fHiGainPos[i]>max)
|
|---|
| 305 | {
|
|---|
| 306 | max = fHiGainPos[i];
|
|---|
| 307 | maxi = i;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | return max<0xff ? maxi : GetIdxMaxLoGainSample();
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | // --------------------------------------------------------------------------
|
|---|
| 314 | //
|
|---|
| 315 | // Returns the maximum signal of all sliced in the hi gain samples
|
|---|
| 316 | //
|
|---|
| 317 | Byte_t MRawEvtPixelIter::GetMaxLoGainSample() const
|
|---|
| 318 | {
|
|---|
| 319 | Byte_t max = 0;
|
|---|
| 320 |
|
|---|
| 321 | for (int i=fNumLoGainSamples-1; i>=0; i--)
|
|---|
| 322 | if (fLoGainPos[i]>max)
|
|---|
| 323 | max = fLoGainPos[i];
|
|---|
| 324 |
|
|---|
| 325 | return max;
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | // --------------------------------------------------------------------------
|
|---|
| 329 | //
|
|---|
| 330 | // returns the sum of all lo gain fadc samples of the actual pixel.
|
|---|
| 331 | // if no lo gain information is available 0 is returned.
|
|---|
| 332 | //
|
|---|
| 333 | ULong_t MRawEvtPixelIter::GetSumLoGainSamples() const
|
|---|
| 334 | {
|
|---|
| 335 | //
|
|---|
| 336 | // return the sum of the lo gain samples of the present pixel
|
|---|
| 337 | //
|
|---|
| 338 | if (!HasLoGain())
|
|---|
| 339 | return 0;
|
|---|
| 340 |
|
|---|
| 341 | Byte_t *ptr = fLoGainPos;
|
|---|
| 342 | const Byte_t *end = fLoGainPos + fNumLoGainSamples;
|
|---|
| 343 |
|
|---|
| 344 | ULong_t sum=0;
|
|---|
| 345 |
|
|---|
| 346 | do sum += *ptr++;
|
|---|
| 347 | while (ptr != end);
|
|---|
| 348 |
|
|---|
| 349 | return sum;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | // --------------------------------------------------------------------------
|
|---|
| 353 | //
|
|---|
| 354 | // returns the sum of squares of all hi gain fadc sample of the actual pixel
|
|---|
| 355 | //
|
|---|
| 356 | ULong_t MRawEvtPixelIter::GetSumSqrLoGainSamples() const
|
|---|
| 357 | {
|
|---|
| 358 | //
|
|---|
| 359 | // return the sum of the lo gain samples squares of the present pixel
|
|---|
| 360 | //
|
|---|
| 361 | if (!HasLoGain())
|
|---|
| 362 | return 0;
|
|---|
| 363 |
|
|---|
| 364 | Byte_t *ptr = fLoGainPos;
|
|---|
| 365 | const Byte_t *end = fLoGainPos + fNumLoGainSamples;
|
|---|
| 366 |
|
|---|
| 367 | ULong_t sum=0;
|
|---|
| 368 |
|
|---|
| 369 | do sum += (*ptr)*(*ptr);
|
|---|
| 370 | while (++ptr != end);
|
|---|
| 371 |
|
|---|
| 372 | return sum;
|
|---|
| 373 | }
|
|---|
| 374 | */
|
|---|