| 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 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2008
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MRawEvtData
|
|---|
| 28 | //
|
|---|
| 29 | // Storage container to store the raw FADC values.
|
|---|
| 30 | //
|
|---|
| 31 | // MArrayS fHiGainPixId
|
|---|
| 32 | // ---------------------
|
|---|
| 33 | // Array of Pixel Numbers for their high voltage channel in the order the
|
|---|
| 34 | // FADC values are stored in fHiGainFadcSamples
|
|---|
| 35 | //
|
|---|
| 36 | // MArrayB fHiGainFadcSaples
|
|---|
| 37 | // -------------------------
|
|---|
| 38 | // FADC samples (hi gain) of all pixels
|
|---|
| 39 | //
|
|---|
| 40 | // MArrayS fLoGainPixId
|
|---|
| 41 | // --------------------
|
|---|
| 42 | // see fHiGainPixId
|
|---|
| 43 | //
|
|---|
| 44 | // MArrayB fLoGainFadcSamples
|
|---|
| 45 | // --------------------------
|
|---|
| 46 | // see fHiGainFadcSaples
|
|---|
| 47 | //
|
|---|
| 48 | //
|
|---|
| 49 | // Version 8
|
|---|
| 50 | // ------------------
|
|---|
| 51 | // + MArrayS *fStartCell
|
|---|
| 52 | // + Bool_t fIsSigned
|
|---|
| 53 | //
|
|---|
| 54 | // Version 7
|
|---|
| 55 | // ------------------
|
|---|
| 56 | // + UShort_t fNumBytesPerSample;
|
|---|
| 57 | //
|
|---|
| 58 | // Version 6
|
|---|
| 59 | // ------------------
|
|---|
| 60 | // - The data can now be stoe in a single array keeping he full
|
|---|
| 61 | // compatibility
|
|---|
| 62 | //
|
|---|
| 63 | // Version 5 (0.8.5):
|
|---|
| 64 | // ------------------
|
|---|
| 65 | // - Changed type of ABFlags from TArrayC to MArrayB
|
|---|
| 66 | //
|
|---|
| 67 | // Version 4 (0.8.4):
|
|---|
| 68 | // ------------------
|
|---|
| 69 | // - Changed derivement from MCamEvent to MParContainer and MCamEvent
|
|---|
| 70 | //
|
|---|
| 71 | // Version 3 (0.8.4):
|
|---|
| 72 | // ------------------
|
|---|
| 73 | // - Added fABFlags
|
|---|
| 74 | //
|
|---|
| 75 | // Version 2:
|
|---|
| 76 | // ----------
|
|---|
| 77 | // - Derives from MCamEvent now
|
|---|
| 78 | //
|
|---|
| 79 | // Version 1:
|
|---|
| 80 | // ----------
|
|---|
| 81 | // - First implementation
|
|---|
| 82 | //
|
|---|
| 83 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 84 | #include "MRawEvtData.h"
|
|---|
| 85 |
|
|---|
| 86 | #include <fstream>
|
|---|
| 87 |
|
|---|
| 88 | #include <TH1.h>
|
|---|
| 89 | #include <TGraph.h>
|
|---|
| 90 | #include <TArrayC.h>
|
|---|
| 91 | #include <TVirtualPad.h>
|
|---|
| 92 |
|
|---|
| 93 | #include "MLog.h"
|
|---|
| 94 | #include "MLogManip.h"
|
|---|
| 95 |
|
|---|
| 96 | #include "MArrayS.h"
|
|---|
| 97 | #include "MArrayB.h"
|
|---|
| 98 | #include "MArrayI.h"
|
|---|
| 99 | #include "MGeomCam.h"
|
|---|
| 100 |
|
|---|
| 101 | #include "MRawCrateArray.h"
|
|---|
| 102 | #include "MRawCrateData.h"
|
|---|
| 103 |
|
|---|
| 104 | #include "MRawRunHeader.h"
|
|---|
| 105 | #include "MRawEvtPixelIter.h"
|
|---|
| 106 |
|
|---|
| 107 | ClassImp(MRawEvtData);
|
|---|
| 108 |
|
|---|
| 109 | using namespace std;
|
|---|
| 110 |
|
|---|
| 111 | // --------------------------------------------------------------------------
|
|---|
| 112 | //
|
|---|
| 113 | // Default constructor. It initializes all arrays with zero size.
|
|---|
| 114 | //
|
|---|
| 115 | MRawEvtData::MRawEvtData(const char *name, const char *title)
|
|---|
| 116 | : fRunHeader(0), fTriggerType(0), fNumBytesPerSample(1), fIsSigned(false)
|
|---|
| 117 | {
|
|---|
| 118 | fName = name ? name : "MRawEvtData";
|
|---|
| 119 | fTitle = title ? title : "Raw Event Data Information";
|
|---|
| 120 |
|
|---|
| 121 | InitArrays();
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | // --------------------------------------------------------------------------
|
|---|
| 125 | //
|
|---|
| 126 | // Destructor. Deletes all the arrays.
|
|---|
| 127 | //
|
|---|
| 128 | MRawEvtData::~MRawEvtData()
|
|---|
| 129 | {
|
|---|
| 130 | DeleteArrays();
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | // --------------------------------------------------------------------------
|
|---|
| 134 | //
|
|---|
| 135 | // reset all arrays
|
|---|
| 136 | //
|
|---|
| 137 | void MRawEvtData::Clear(Option_t *)
|
|---|
| 138 | {
|
|---|
| 139 | /*
|
|---|
| 140 | FIXME:
|
|---|
| 141 | Is Reset (set all entries to zero) what you want to do
|
|---|
| 142 | or Set(0) (delete the array)
|
|---|
| 143 | */
|
|---|
| 144 | fHiGainPixId->Reset();
|
|---|
| 145 | fLoGainPixId->Reset();
|
|---|
| 146 | fHiGainFadcSamples->Reset();
|
|---|
| 147 | fLoGainFadcSamples->Reset();
|
|---|
| 148 | fABFlags->Reset();
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | // --------------------------------------------------------------------------
|
|---|
| 152 | //
|
|---|
| 153 | // return the number of hi gain samples per pixel
|
|---|
| 154 | //
|
|---|
| 155 | UShort_t MRawEvtData::GetNumHiGainSamples() const
|
|---|
| 156 | {
|
|---|
| 157 | // If value<0 we are reading old MC files which don't have the
|
|---|
| 158 | // value set so far. So we use the old methid to determin the
|
|---|
| 159 | // numbers and calculate them from the length of the arrays.
|
|---|
| 160 | return fHiGainPixId->GetSize() ? fHiGainFadcSamples->GetSize()/(fHiGainPixId->GetSize()*fNumBytesPerSample) : 0;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | // --------------------------------------------------------------------------
|
|---|
| 164 | //
|
|---|
| 165 | // return the number of lo gain samples per pixel
|
|---|
| 166 | //
|
|---|
| 167 | UShort_t MRawEvtData::GetNumLoGainSamples() const
|
|---|
| 168 | {
|
|---|
| 169 | // If value<0 we are reading old MC files which don't have the
|
|---|
| 170 | // value set so far. So we use the old methid to determin the
|
|---|
| 171 | // numbers and calculate them from the length of the arrays.
|
|---|
| 172 | return fLoGainPixId->GetSize() ? fLoGainFadcSamples->GetSize()/(fLoGainPixId->GetSize()*fNumBytesPerSample) : 0;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | // --------------------------------------------------------------------------
|
|---|
| 176 | //
|
|---|
| 177 | // return the number of stored pixel
|
|---|
| 178 | //
|
|---|
| 179 | UShort_t MRawEvtData::GetNumPixels() const
|
|---|
| 180 | {
|
|---|
| 181 | return fHiGainPixId ? fHiGainPixId->GetSize() : 0;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | // --------------------------------------------------------------------------
|
|---|
| 185 | //
|
|---|
| 186 | // Print out the onformation to *fLog.
|
|---|
| 187 | // Options:
|
|---|
| 188 | // "hex" Prints the time slices hexadecimal (default)
|
|---|
| 189 | // "dec" Prints the time slices decimal
|
|---|
| 190 | //
|
|---|
| 191 | void MRawEvtData::Print(Option_t *opt) const
|
|---|
| 192 | {
|
|---|
| 193 | //
|
|---|
| 194 | // print fadc inforation to screen
|
|---|
| 195 | // Possible Options:
|
|---|
| 196 | // - DEC: Print values decimal instead of hexadecimal (default)
|
|---|
| 197 | //
|
|---|
| 198 | const UShort_t nHiSamp = GetNumHiGainSamples();
|
|---|
| 199 | const UShort_t nLoSamp = GetNumLoGainSamples();
|
|---|
| 200 |
|
|---|
| 201 | const UShort_t bps = GetNumBytesPerSample();
|
|---|
| 202 |
|
|---|
| 203 | fLog->unsetf(ios::showbase);
|
|---|
| 204 |
|
|---|
| 205 | *fLog << dec << all;
|
|---|
| 206 | *fLog << GetDescriptor() << ": " << endl;
|
|---|
| 207 | *fLog << GetNumPixels() << " Pixels with " << (Int_t)nHiSamp << "/" << (Int_t)nLoSamp << " samples" << endl;
|
|---|
| 208 |
|
|---|
| 209 | TString str(opt);
|
|---|
| 210 | Int_t manip = str.Contains("dec", TString::kIgnoreCase);
|
|---|
| 211 |
|
|---|
| 212 | MRawEvtPixelIter pixel(const_cast<MRawEvtData*>(this));
|
|---|
| 213 | Int_t i = 0;
|
|---|
| 214 | while (pixel.Next())
|
|---|
| 215 | {
|
|---|
| 216 | const UShort_t idx = pixel.GetPixelId();
|
|---|
| 217 |
|
|---|
| 218 | *fLog << endl << dec << setfill(' ');
|
|---|
| 219 | *fLog << " " << setw(3) << i++ << " - " << setw(3) << idx << " ";
|
|---|
| 220 |
|
|---|
| 221 | if (pixel.IsABFlagValid())
|
|---|
| 222 | *fLog << "<" << (pixel.HasABFlag()?"B":"A") << "> ";
|
|---|
| 223 |
|
|---|
| 224 | *fLog << (manip?dec:hex) << setfill(manip?' ':'0');
|
|---|
| 225 |
|
|---|
| 226 | const Byte_t *hi = (Byte_t*)pixel.GetHiGainSamples();
|
|---|
| 227 | const Byte_t *lo = (Byte_t*)pixel.GetLoGainSamples();
|
|---|
| 228 |
|
|---|
| 229 | for (int j=0; j<nHiSamp*bps; j++)
|
|---|
| 230 | {
|
|---|
| 231 | *fLog << setw(manip?3:2);
|
|---|
| 232 | *fLog << (hi[j]&0xff);
|
|---|
| 233 | if (manip)
|
|---|
| 234 | *fLog << ' ';
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | for (int j=0; j<nLoSamp*bps; j++)
|
|---|
| 238 | {
|
|---|
| 239 | *fLog << setw(manip?3:2);
|
|---|
| 240 | *fLog << ((UShort_t)lo[j]&0xff);
|
|---|
| 241 | if (manip)
|
|---|
| 242 | *fLog << ' ';
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 | *fLog << dec << endl;
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | // --------------------------------------------------------------------------
|
|---|
| 249 | //
|
|---|
| 250 | // Draw a pixel. A Histogram or Graph is created and it's draw function is
|
|---|
| 251 | // called.
|
|---|
| 252 | // Options:
|
|---|
| 253 | // "GRAPH" A graph is drawn
|
|---|
| 254 | // "HIST" A histogram is drawn
|
|---|
| 255 | // <index> The pixel with the given index is drawn
|
|---|
| 256 | //
|
|---|
| 257 | void MRawEvtData::Draw(Option_t *opt)
|
|---|
| 258 | {
|
|---|
| 259 | if (GetNumPixels()==0)
|
|---|
| 260 | {
|
|---|
| 261 | *fLog << warn << "Sorry, no pixel to draw!" << endl;
|
|---|
| 262 | return;
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | TString str(opt);
|
|---|
| 266 | str.ToLower();
|
|---|
| 267 |
|
|---|
| 268 | UInt_t id = 0;
|
|---|
| 269 |
|
|---|
| 270 | if (str.BeginsWith("graph"))
|
|---|
| 271 | sscanf(str.Data()+5, "%d", &id);
|
|---|
| 272 | if (str.BeginsWith("hist"))
|
|---|
| 273 | sscanf(str.Data()+4, "%d", &id);
|
|---|
| 274 |
|
|---|
| 275 | MRawEvtPixelIter pix(this);
|
|---|
| 276 | if (!pix.Jump(id))
|
|---|
| 277 | {
|
|---|
| 278 | *fLog << warn << dec << "Pixel Idx #" << id << " doesn't exist!" << endl;
|
|---|
| 279 | return;
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | const void *higains = pix.GetHiGainSamples();
|
|---|
| 283 | const void *logains = pix.GetLoGainSamples();
|
|---|
| 284 |
|
|---|
| 285 | const Int_t nh = GetNumHiGainSamples();
|
|---|
| 286 | const Int_t nl = GetNumLoGainSamples();
|
|---|
| 287 |
|
|---|
| 288 | TString name = "Pixel Idx.";
|
|---|
| 289 | name += pix.GetPixelId();
|
|---|
| 290 |
|
|---|
| 291 | fIsSigned = kTRUE;
|
|---|
| 292 |
|
|---|
| 293 | Bool_t same = str.Contains("same");
|
|---|
| 294 |
|
|---|
| 295 | cout << "MIN/MAX=" << fNumBytesPerSample << " " << GetMin() << " " << GetMax() << endl;
|
|---|
| 296 |
|
|---|
| 297 | if (str.BeginsWith("graph"))
|
|---|
| 298 | {
|
|---|
| 299 | *fLog << inf << "Drawing Graph: Pixel Idx #" << dec << pix.GetPixelId();
|
|---|
| 300 | *fLog << " of " << (int)GetNumPixels() << "Pixels" << endl;
|
|---|
| 301 |
|
|---|
| 302 | TGraph *graphhi = new TGraph;
|
|---|
| 303 |
|
|---|
| 304 | for (int i=0; i<nh; i++)
|
|---|
| 305 | graphhi->SetPoint(graphhi->GetN(), i, GetSample(higains, i));
|
|---|
| 306 | for (int i=0; i<nl; i++)
|
|---|
| 307 | graphhi->SetPoint(graphhi->GetN(), i+nh, GetSample(logains, i));
|
|---|
| 308 |
|
|---|
| 309 | graphhi->SetMaximum(GetMax()+0.5);
|
|---|
| 310 | graphhi->SetMinimum(GetMin());
|
|---|
| 311 |
|
|---|
| 312 | graphhi->SetBit(kCanDelete);
|
|---|
| 313 | graphhi->Draw(same ? "C*" : "AC*");
|
|---|
| 314 |
|
|---|
| 315 | TH1F *histhi = graphhi->GetHistogram();
|
|---|
| 316 | histhi->SetMinimum(GetMin());
|
|---|
| 317 | histhi->SetMaximum(GetMax()+0.5);
|
|---|
| 318 |
|
|---|
| 319 | histhi->SetXTitle("Time/FADC Slices");
|
|---|
| 320 | histhi->SetYTitle("Signal/FADC Units");
|
|---|
| 321 |
|
|---|
| 322 | return;
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | if (str.BeginsWith("hist"))
|
|---|
| 326 | {
|
|---|
| 327 | // FIXME: Add Legend
|
|---|
| 328 | *fLog << inf << "Drawing Histogram of Pixel with Idx #" << dec << pix.GetPixelId() << " to " << gPad << endl;
|
|---|
| 329 |
|
|---|
| 330 | TH1F *histh = new TH1F(name, "FADC Samples", nh+nl, -0.5, nh+nl-.5);
|
|---|
| 331 | histh->SetMinimum(GetMin());
|
|---|
| 332 | histh->SetMaximum(GetMax()+0.5);
|
|---|
| 333 | histh->SetXTitle("Time [FADC Slices]");
|
|---|
| 334 | histh->SetYTitle("Signal [FADC Units]");
|
|---|
| 335 | histh->SetDirectory(NULL);
|
|---|
| 336 | for (int i=0; i<nh; i++)
|
|---|
| 337 | histh->Fill(i, GetSample(higains, i));
|
|---|
| 338 | for (int i=0; i<nl; i++)
|
|---|
| 339 | histh->Fill(i+nl, GetSample(logains, i));
|
|---|
| 340 | histh->SetBit(kCanDelete);
|
|---|
| 341 | histh->Draw(same ? "same" : "");
|
|---|
| 342 |
|
|---|
| 343 | return;
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | *fLog << warn << dbginf << "WARNING - You must specify either 'GRAPH' or 'HIST'" << endl;
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | // --------------------------------------------------------------------------
|
|---|
| 350 | //
|
|---|
| 351 | // Deletes all the arrays
|
|---|
| 352 | // The flag is for future usage.
|
|---|
| 353 | //
|
|---|
| 354 | void MRawEvtData::InitArrays(UShort_t numconnected, UShort_t maxid)
|
|---|
| 355 | {
|
|---|
| 356 | // fRunHeader should not be set only in the constructor!
|
|---|
| 357 | const Int_t numhi = fRunHeader ? fRunHeader->GetNumSamplesHiGain() : 0;
|
|---|
| 358 | const Int_t numlo = fRunHeader ? fRunHeader->GetNumSamplesLoGain() : 0;
|
|---|
| 359 |
|
|---|
| 360 | fNumBytesPerSample = fRunHeader ? fRunHeader->GetNumBytesPerSample() : 1;
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 | if (fRunHeader == 0)
|
|---|
| 364 | {
|
|---|
| 365 | fTriggerType = 0x0000;
|
|---|
| 366 | }
|
|---|
| 367 | else
|
|---|
| 368 | {
|
|---|
| 369 | switch(fRunHeader->GetRunType())
|
|---|
| 370 | {
|
|---|
| 371 | case MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTData:
|
|---|
| 372 | fTriggerType = 0x0004; break;
|
|---|
| 373 | case MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTPedestal:
|
|---|
| 374 | fTriggerType = 0x0400; break;
|
|---|
| 375 | case MRawRunHeader::kRTMonteCarlo|MRawRunHeader::kRTCalibration:
|
|---|
| 376 | fTriggerType = 0x0164; break;
|
|---|
| 377 | default:
|
|---|
| 378 | fTriggerType = 0x0000; break;
|
|---|
| 379 | }
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | fHiGainPixId = new MArrayS(numconnected);
|
|---|
| 383 | fLoGainPixId = new MArrayS(0);
|
|---|
| 384 | fHiGainFadcSamples = new MArrayB(numconnected*(numhi+numlo)*fNumBytesPerSample);
|
|---|
| 385 | fLoGainFadcSamples = new MArrayB(0);
|
|---|
| 386 |
|
|---|
| 387 | fABFlags = new MArrayB(maxid==0 ? 0 : maxid/8+1);
|
|---|
| 388 | fStartCells = new MArrayS(0);
|
|---|
| 389 |
|
|---|
| 390 | fConnectedPixels = 0;
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | void MRawEvtData::InitStartCells()
|
|---|
| 394 | {
|
|---|
| 395 | delete fStartCells;
|
|---|
| 396 | fStartCells = new MArrayS(fHiGainPixId->GetSize());
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | // --------------------------------------------------------------------------
|
|---|
| 400 | //
|
|---|
| 401 | // Deletes all the arrays
|
|---|
| 402 | //
|
|---|
| 403 | void MRawEvtData::DeleteArrays()
|
|---|
| 404 | {
|
|---|
| 405 | delete fHiGainPixId;
|
|---|
| 406 | delete fLoGainPixId;
|
|---|
| 407 | delete fHiGainFadcSamples;
|
|---|
| 408 | delete fLoGainFadcSamples;
|
|---|
| 409 | delete fABFlags;
|
|---|
| 410 | delete fStartCells;
|
|---|
| 411 | }
|
|---|
| 412 |
|
|---|
| 413 | // --------------------------------------------------------------------------
|
|---|
| 414 | //
|
|---|
| 415 | // Deletes all arrays describing the pixel Id and Samples in pixels.
|
|---|
| 416 | // The flag is for future usage.
|
|---|
| 417 | //
|
|---|
| 418 | void MRawEvtData::ResetPixels(UShort_t numconnected, UShort_t maxid)
|
|---|
| 419 | {
|
|---|
| 420 | //const int npix = fRunHeader->GetNumCrates()*fRunHeader->GetNumPixInCrate();
|
|---|
| 421 | if (fHiGainPixId && fHiGainPixId->GetSize()==numconnected && (UShort_t)fABFlags->GetSize()==(maxid/8+1))
|
|---|
| 422 | {
|
|---|
| 423 | fConnectedPixels = 0;
|
|---|
| 424 | return;
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | DeleteArrays();
|
|---|
| 428 | InitArrays(numconnected, maxid);
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | void MRawEvtData::ResetPixels()
|
|---|
| 432 | {
|
|---|
| 433 | if (!fRunHeader)
|
|---|
| 434 | return;
|
|---|
| 435 |
|
|---|
| 436 | // FIXME: Better give NumNormalPixels if numconnected==0 ?
|
|---|
| 437 |
|
|---|
| 438 | ResetPixels(fRunHeader->GetNumNormalPixels(), fRunHeader->GetNumNormalPixels()-1);
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | // --------------------------------------------------------------------------
|
|---|
| 442 | //
|
|---|
| 443 | // This is to fill the data of one pixel to the MRawEvtHeader Class.
|
|---|
| 444 | // The parameters are the pixelnumber and the FADC_SLICES values of ADCs
|
|---|
| 445 | //
|
|---|
| 446 | void MRawEvtData::AddPixel(UShort_t nOfPixel, const TArrayC &data)
|
|---|
| 447 | {
|
|---|
| 448 | const Int_t n = fRunHeader->GetNumSamples();
|
|---|
| 449 | if (data.GetSize()!=n)
|
|---|
| 450 | {
|
|---|
| 451 | *fLog << err << "RawEvtData::AddPixel: Error, number of samples in ";
|
|---|
| 452 | *fLog << "TArrayC " << data.GetSize() << " doesn't match current number " << n << endl;
|
|---|
| 453 | return;
|
|---|
| 454 | }
|
|---|
| 455 |
|
|---|
| 456 | //
|
|---|
| 457 | // enhance pixel array by one
|
|---|
| 458 | //
|
|---|
| 459 | fHiGainPixId->Set(fHiGainPixId->GetSize()+1);
|
|---|
| 460 |
|
|---|
| 461 | //
|
|---|
| 462 | // add the number of the new pixel to the array as last entry
|
|---|
| 463 | //
|
|---|
| 464 | fHiGainPixId->AddAt(nOfPixel, fHiGainPixId->GetSize()-1);
|
|---|
| 465 |
|
|---|
| 466 | //
|
|---|
| 467 | // enhance the array by the number of new samples
|
|---|
| 468 | //
|
|---|
| 469 | fHiGainFadcSamples->Set(fHiGainFadcSamples->GetSize()+n);
|
|---|
| 470 |
|
|---|
| 471 | //
|
|---|
| 472 | // add the new slices as last entries to array
|
|---|
| 473 | //
|
|---|
| 474 | fHiGainFadcSamples->AddAt((Byte_t*)data.GetArray(), fHiGainFadcSamples->GetSize()-n, n);
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 | // --------------------------------------------------------------------------
|
|---|
| 478 | //
|
|---|
| 479 | // Add the contents of the MArrayI to the fHiGainFadcSamples
|
|---|
| 480 | // One Integer is added to one sample in the array.
|
|---|
| 481 | //
|
|---|
| 482 | void MRawEvtData::Set(const MArrayI &data)
|
|---|
| 483 | {
|
|---|
| 484 | fConnectedPixels = fHiGainPixId->GetSize();
|
|---|
| 485 |
|
|---|
| 486 | UInt_t n = fConnectedPixels*fRunHeader->GetNumSamplesHiGain();
|
|---|
| 487 | if (n!=data.GetSize())
|
|---|
| 488 | {
|
|---|
| 489 | *fLog << err << "MRawEvtData::Set: Size mismatch." << endl;
|
|---|
| 490 | *fLog << " fConnectedPixels=" << fConnectedPixels << endl;
|
|---|
| 491 | *fLog << " NumHiGainSamples=" << fRunHeader->GetNumSamplesHiGain() << endl;
|
|---|
| 492 | *fLog << " data.GetSize()=" << data.GetSize() << endl;
|
|---|
| 493 | return;
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | Byte_t *dest = fHiGainFadcSamples->GetArray();
|
|---|
| 497 |
|
|---|
| 498 | UInt_t *src = reinterpret_cast<UInt_t*>(data.GetArray());
|
|---|
| 499 | UInt_t *end = reinterpret_cast<UInt_t*>(data.GetArray()) + n;
|
|---|
| 500 |
|
|---|
| 501 | switch (fNumBytesPerSample)
|
|---|
| 502 | {
|
|---|
| 503 | case 1:
|
|---|
| 504 | {
|
|---|
| 505 | Byte_t *ptr = reinterpret_cast<Byte_t*>(dest);
|
|---|
| 506 | while (src<end)
|
|---|
| 507 | *ptr++ = Byte_t(*src++);
|
|---|
| 508 | }
|
|---|
| 509 | return;
|
|---|
| 510 |
|
|---|
| 511 | case 2:
|
|---|
| 512 | {
|
|---|
| 513 | UShort_t *ptr = reinterpret_cast<UShort_t*>(dest);
|
|---|
| 514 | while (src<end)
|
|---|
| 515 | *ptr++ = UShort_t(*src++);
|
|---|
| 516 | }
|
|---|
| 517 | return;
|
|---|
| 518 |
|
|---|
| 519 | case 4:
|
|---|
| 520 | memcpy(dest, data.GetArray(), n*4);
|
|---|
| 521 | return;
|
|---|
| 522 | }
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | // --------------------------------------------------------------------------
|
|---|
| 526 | //
|
|---|
| 527 | // Set indices according to the given array. The array must have the same
|
|---|
| 528 | // size as fHiGainPixId
|
|---|
| 529 | //
|
|---|
| 530 | void MRawEvtData::SetIndices(const MArrayS &idx)
|
|---|
| 531 | {
|
|---|
| 532 | if (idx.GetSize()!=fHiGainPixId->GetSize())
|
|---|
| 533 | return;
|
|---|
| 534 |
|
|---|
| 535 | for (UInt_t i=0; i<fHiGainPixId->GetSize(); i++)
|
|---|
| 536 | (*fHiGainPixId)[i] = idx[i]-1;
|
|---|
| 537 | }
|
|---|
| 538 |
|
|---|
| 539 | // --------------------------------------------------------------------------
|
|---|
| 540 | //
|
|---|
| 541 | // Set indices according to the length of the array fHiGainPixId
|
|---|
| 542 | // from 0 to n-1
|
|---|
| 543 | //
|
|---|
| 544 | void MRawEvtData::SetIndices()
|
|---|
| 545 | {
|
|---|
| 546 | for (UInt_t i=0; i<fHiGainPixId->GetSize(); i++)
|
|---|
| 547 | (*fHiGainPixId)[i] = i;
|
|---|
| 548 | }
|
|---|
| 549 |
|
|---|
| 550 | Byte_t *MRawEvtData::GetSamples() const { return fHiGainFadcSamples->GetArray(); }
|
|---|
| 551 | UShort_t *MRawEvtData::GetStartCells() const { return fStartCells->GetArray(); }
|
|---|
| 552 | UShort_t *MRawEvtData::GetPixelIds() const { return fHiGainPixId->GetArray(); }
|
|---|
| 553 | Bool_t MRawEvtData::HasStartCells() const { return fStartCells->GetSize()==fHiGainPixId->GetSize(); }
|
|---|
| 554 |
|
|---|
| 555 | /*
|
|---|
| 556 | void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
|
|---|
| 557 | {
|
|---|
| 558 | MArrayS *arrpix = lflag ? fLoGainPixId : fHiGainPixId;
|
|---|
| 559 | MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
|
|---|
| 560 |
|
|---|
| 561 | //
|
|---|
| 562 | // check whether we got the right number of new samples
|
|---|
| 563 | // if there are no samples already stored: this is the new number of samples
|
|---|
| 564 | //
|
|---|
| 565 | const UShort_t ns = data->GetSize();
|
|---|
| 566 | const UShort_t nSamp = lflag ? GetNumLoGainSamples() : GetNumHiGainSamples();
|
|---|
| 567 | if (nSamp && ns!=nSamp)
|
|---|
| 568 | {
|
|---|
| 569 | *fLog << err << "RawEvtData::AddPixel: Error, number of samples in ";
|
|---|
| 570 | *fLog << "TArrayC " << ns << " doesn't match current number " << nSamp << endl;
|
|---|
| 571 | return;
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | //
|
|---|
| 575 | // enhance pixel array by one
|
|---|
| 576 | //
|
|---|
| 577 | arrpix->Set(arrpix->GetSize()+1);
|
|---|
| 578 |
|
|---|
| 579 | //
|
|---|
| 580 | // add the number of the new pixel to the array as last entry
|
|---|
| 581 | //
|
|---|
| 582 | arrpix->AddAt(nOfPixel, arrpix->GetSize()-1);
|
|---|
| 583 |
|
|---|
| 584 | //
|
|---|
| 585 | // enhance the array by the number of new samples
|
|---|
| 586 | //
|
|---|
| 587 | arrsam->Set(arrsam->GetSize()+ns);
|
|---|
| 588 |
|
|---|
| 589 | //
|
|---|
| 590 | // add the new slices as last entries to array
|
|---|
| 591 | //
|
|---|
| 592 | arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
|
|---|
| 593 | }
|
|---|
| 594 | */
|
|---|
| 595 |
|
|---|
| 596 | void MRawEvtData::ReadPixel(istream &fin, Int_t npix)
|
|---|
| 597 | {
|
|---|
| 598 | // number of samples
|
|---|
| 599 | const UInt_t ns = fRunHeader->GetNumSamples();
|
|---|
| 600 |
|
|---|
| 601 | // bytes per sample
|
|---|
| 602 | const Int_t bps = fRunHeader->GetNumBytesPerSample();
|
|---|
| 603 |
|
|---|
| 604 | // Number of bytes
|
|---|
| 605 | const Int_t nb = ns*bps;
|
|---|
| 606 |
|
|---|
| 607 | // position in higain array
|
|---|
| 608 | Byte_t *pos = fHiGainFadcSamples->GetArray() + fConnectedPixels*nb;
|
|---|
| 609 |
|
|---|
| 610 | // Set pixel index
|
|---|
| 611 | fHiGainPixId->AddAt(npix, fConnectedPixels++);
|
|---|
| 612 |
|
|---|
| 613 | // Read data for one pixel
|
|---|
| 614 | fin.read((char*)pos, nb);
|
|---|
| 615 | }
|
|---|
| 616 |
|
|---|
| 617 | void MRawEvtData::SetABFlag(Int_t npix, Bool_t ab)
|
|---|
| 618 | {
|
|---|
| 619 | if (ab)
|
|---|
| 620 | SETBIT((*fABFlags)[npix/8], npix%8);
|
|---|
| 621 | else
|
|---|
| 622 | CLRBIT((*fABFlags)[npix/8], npix%8);
|
|---|
| 623 | }
|
|---|
| 624 |
|
|---|
| 625 | // --------------------------------------------------------------------------
|
|---|
| 626 | //
|
|---|
| 627 | // Fills members with information from a magic binary file.
|
|---|
| 628 | // WARNING: you have to use Init() before you can do this
|
|---|
| 629 | //
|
|---|
| 630 | /*
|
|---|
| 631 | void MRawEvtData::ReadEvt(istream &fin, Int_t posinarray)
|
|---|
| 632 | {
|
|---|
| 633 |
|
|---|
| 634 | const UShort_t npic = fRunHeader->GetNumPixInCrate();
|
|---|
| 635 |
|
|---|
| 636 | const UShort_t npos = npic*posinarray;
|
|---|
| 637 |
|
|---|
| 638 | //const Byte_t ab = fCrateArray->GetEntry(posinarray)->GetABFlags();
|
|---|
| 639 |
|
|---|
| 640 | for (int i=npos; i<npic+npos; i++)
|
|---|
| 641 | {
|
|---|
| 642 | // calc the spiral hardware pixel number
|
|---|
| 643 | const UShort_t ipos = i;
|
|---|
| 644 |
|
|---|
| 645 | // Get Hardware Id
|
|---|
| 646 | const Short_t hwid = fRunHeader->GetPixAssignment(ipos);
|
|---|
| 647 |
|
|---|
| 648 | // Check whether the pixel is connected or not
|
|---|
| 649 | if (hwid==0)
|
|---|
| 650 | {
|
|---|
| 651 | const UShort_t n = fRunHeader->GetNumSamplesLoGain()+fRunHeader->GetNumSamplesHiGain();
|
|---|
| 652 | fin.seekg(n, ios::cur);
|
|---|
| 653 | return;
|
|---|
| 654 | }
|
|---|
| 655 |
|
|---|
| 656 | // -1 converts the hardware pixel Id into the software pixel index
|
|---|
| 657 | const Int_t npix = (Int_t)hwid-1;
|
|---|
| 658 |
|
|---|
| 659 | const Byte_t ab = fCrateArray->GetEntry(posinarray)->GetABFlags();
|
|---|
| 660 | AddPixel(fin, npix, TESTBIT(ab, i-npos));
|
|---|
| 661 | }
|
|---|
| 662 | }
|
|---|
| 663 | */
|
|---|
| 664 |
|
|---|
| 665 | // --------------------------------------------------------------------------
|
|---|
| 666 | //
|
|---|
| 667 | // Return the size in bytes of one event data block
|
|---|
| 668 | //
|
|---|
| 669 | Int_t MRawEvtData::GetNumBytes() const
|
|---|
| 670 | {
|
|---|
| 671 | const UShort_t nlo = fRunHeader->GetNumSamplesLoGain();
|
|---|
| 672 | const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
|
|---|
| 673 | const UShort_t npic = fRunHeader->GetNumPixInCrate();
|
|---|
| 674 | const UShort_t nbps = fRunHeader->GetNumBytesPerSample();
|
|---|
| 675 |
|
|---|
| 676 | return (nhi+nlo)*npic*nbps;
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | // --------------------------------------------------------------------------
|
|---|
| 680 | //
|
|---|
| 681 | // Make sure, that you skip the whole event. This function only skips a part
|
|---|
| 682 | // of the event - see MRawRead::SkipEvent
|
|---|
| 683 | //
|
|---|
| 684 | void MRawEvtData::SkipEvt(istream &fin)
|
|---|
| 685 | {
|
|---|
| 686 | fin.seekg(GetNumBytes(), ios::cur);
|
|---|
| 687 | }
|
|---|
| 688 |
|
|---|
| 689 | Bool_t MRawEvtData::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
|---|
| 690 | {
|
|---|
| 691 | *fLog << warn << "WARNING - The use of MRawEvtData::GetPixelContent is deprecated!" << endl;
|
|---|
| 692 |
|
|---|
| 693 | /*
|
|---|
| 694 | MRawEvtPixelIter Next(const_cast<MRawEvtData*>(this));
|
|---|
| 695 | if (!Next.Jump(idx))
|
|---|
| 696 | return kFALSE;
|
|---|
| 697 |
|
|---|
| 698 | switch (type)
|
|---|
| 699 | {
|
|---|
| 700 | case 0:
|
|---|
| 701 | val = Next.GetSumHiGainSamples()-(float)GetNumHiGainSamples()*fHiGainFadcSamples->GetArray()[0];
|
|---|
| 702 | val*= cam.GetPixRatio(idx);
|
|---|
| 703 | break;
|
|---|
| 704 | case 1:
|
|---|
| 705 | val = Next.GetMaxHiGainSample();
|
|---|
| 706 | break;
|
|---|
| 707 | case 2:
|
|---|
| 708 | val = Next.GetMaxLoGainSample();
|
|---|
| 709 | break;
|
|---|
| 710 | case 3:
|
|---|
| 711 | val = Next.GetIdxMaxHiGainSample();
|
|---|
| 712 | break;
|
|---|
| 713 | case 4:
|
|---|
| 714 | val = Next.GetIdxMaxLoGainSample();
|
|---|
| 715 | break;
|
|---|
| 716 | case 5:
|
|---|
| 717 | val = Next.GetIdxMaxHiLoGainSample();
|
|---|
| 718 | return val >= 0;
|
|---|
| 719 | }
|
|---|
| 720 | */
|
|---|
| 721 | return kTRUE;
|
|---|
| 722 | }
|
|---|
| 723 |
|
|---|
| 724 | void MRawEvtData::Copy(TObject &named)
|
|---|
| 725 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,04,01)
|
|---|
| 726 | const
|
|---|
| 727 | #endif
|
|---|
| 728 | {
|
|---|
| 729 | MRawEvtData &evt = (MRawEvtData &)named;
|
|---|
| 730 |
|
|---|
| 731 | *evt.fHiGainPixId = *fHiGainPixId;
|
|---|
| 732 | *evt.fLoGainPixId = *fLoGainPixId;
|
|---|
| 733 |
|
|---|
| 734 | *evt.fHiGainFadcSamples = *fHiGainFadcSamples;
|
|---|
| 735 | *evt.fLoGainFadcSamples = *fLoGainFadcSamples;
|
|---|
| 736 |
|
|---|
| 737 | *evt.fABFlags = *fABFlags;
|
|---|
| 738 |
|
|---|
| 739 | evt.fConnectedPixels = fConnectedPixels;
|
|---|
| 740 |
|
|---|
| 741 | evt.fNumBytesPerSample = fNumBytesPerSample;
|
|---|
| 742 | }
|
|---|