- Timestamp:
- 09/24/10 15:35:55 (14 years ago)
- Location:
- trunk/Mars
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/Changelog
r9940 r9941 18 18 19 19 -*-*- END OF LINE -*-*- 20 21 2010/09/24 Thomas Bretz 22 23 * mcorsika/MCorsikaEvtHeader.cc: 24 - store impact parameters persistent for further use (because in 25 eventio format the header is not repeated this is needed) 26 27 * mcorsika/MCorsikaFormat.[h,cc]: 28 - adapted to be able to read all telescopes and all reused shower 29 events in eventio 30 - a lot of cosmetics 31 - many more comments 32 - PRELIMINARY 33 34 * mcorsika/MCorsikaRead.[h,cc]: 35 - implemented variable for selection of the telescope in eventio format 36 - implemented eventio format (PRELIMINARY) 37 38 * msim/MPhotonData.[h,cc], msim/MPhotonEvent.[h,cc]: 39 - implemented function to calculate mean event time 40 - implemented function to simulate the wavelength (lambda^-2) 41 - implemented function to shift all photons by a certain xy 42 - adapted ReadCorsikaEvt to changes in MCorsikaFormat 43 44 20 45 21 46 2010/09/24 Daniela Dorner -
trunk/Mars/mcorsika/MCorsikaEvtHeader.cc
r9937 r9941 160 160 // f[96] // Number of reuse of event [max=20] 161 161 162 memcpy(fTempX, f +97, 20*sizeof(Float_t)); 163 memcpy(fTempY, f+117, 20*sizeof(Float_t)); 164 162 165 // FIXME: Check fNumReuse<20 163 fX = f[117 + fNumReuse];164 fY = -f[ 97 + fNumReuse];166 // fX = f[117 + fNumReuse]; 167 // fY = -f[ 97 + fNumReuse]; 165 168 166 169 fWeightedNumPhotons = 0; -
trunk/Mars/mcorsika/MCorsikaEvtHeader.h
r9937 r9941 40 40 Float_t fWeightedNumPhotons; // weighted number of photons arriving at observation level 41 41 42 Float_t fTempX[20]; //! Temporary storage for impact parameter 43 Float_t fTempY[20]; //! Temporary storage for impact parameter 44 42 45 public: 43 46 MCorsikaEvtHeader(const char *name=NULL, const char *title=NULL); … … 67 70 void ResetNumReuse() { fNumReuse=(UInt_t)-1; } 68 71 72 void InitXY() { fX=fTempY[fNumReuse]; fY=-fTempX[fNumReuse]; } 73 69 74 Int_t ReadEvt(MCorsikaFormat *informat); // read in event header block 70 75 Int_t ReadEvtEnd(MCorsikaFormat *informat); // read in event end block -
trunk/Mars/mcorsika/MCorsikaFormat.cc
r9938 r9941 198 198 // returns kFALSE; 199 199 // 200 Bool_t MCorsikaFormatRaw::GetNextEvent(Float_t ** buffer, Bool_t & readError)200 Int_t MCorsikaFormatRaw::GetNextEvent(Float_t **buffer, UInt_t) 201 201 { 202 202 static Float_t data[273]; … … 204 204 205 205 if (next == data + 273) 206 206 { 207 207 // read next block of events 208 208 if (!ReadData(273, data)) 209 { 210 readError = kTRUE; 211 return kFALSE; 212 } 209 return kERROR; 213 210 214 211 if (!memcmp(data, "EVTE", 4)) 215 212 { 216 213 // we found the end of list of events 217 214 UnreadLastData(); 218 215 return kFALSE; 219 216 } 220 217 221 218 next = data; 222 219 } 223 220 224 221 *buffer = next; … … 226 223 227 224 return kTRUE; 228 229 225 } 230 226 … … 259 255 260 256 if (fIn->eof()) 261 { 262 gLog << err << "ERROR - Missing identifier: " << id << 263 " type: " << type << endl; 257 { 258 gLog << err << "MCorsikaFormatEventIO::SeekNextBlock: ERROR - unexpected end-of-file." << endl; 264 259 return kFALSE; 265 266 267 unsigned short fileType = blockHeader[1] & 0xFFFF;268 if (type == fileType)260 } 261 262 const unsigned short objType = blockHeader[1] & 0xFFFF; 263 if (type == objType) 269 264 break; 270 265 271 if (type == 1202 && fileType == 1210)272 // we are looking for a event header, but found a runEnd.273 // This will happen at the end of a run. We stop here looking for274 // the next event header266 // we are looking for a event header, but found a runEnd. 267 // This will happen at the end of a run. We stop here looking for 268 // the next event header 269 if (type == 1202 && objType == 1210) 275 270 return kFALSE; 276 271 277 272 // a unknown block, we jump to the next one 278 //gLog << "unknown: " << id << " type: " << fileType << " sub-blocks: " << (blockHeader[3]>>29);279 //gLog << " length: " << (blockHeader[3] & 0x3fffffff) << " pos: " << fIn->tellg() << endl;280 273 const int length = blockHeader[3] & 0x3fffffff; 281 282 fIn->seekg(length - 2 * (Int_t)(sizeof(int)), ios::cur); 274 275 fIn->seekg(length - 2 * (Int_t)(sizeof(int)), ios::cur); 283 276 } 284 277 … … 307 300 308 301 // is the RUNE block at the very end of the file? 309 std::streampos currentPos = fIn->tellg();302 const streampos currentPos = fIn->tellg(); 310 303 311 304 fIn->seekg(-32, ios::end); … … 332 325 UnreadLastHeader(); 333 326 fRunePos = fIn->tellg(); 327 334 328 return kTRUE; 335 329 } … … 342 336 // returns kFALSE; 343 337 // 344 Bool_t MCorsikaFormatEventIO::GetNextEvent(Float_t ** buffer, 345 Bool_t & readError) 346 { 347 348 static Float_t * data = NULL; 349 static Float_t * next; 350 static Int_t topLevelLength = 0; 351 static Int_t eventLength = 0; 352 353 354 while (eventLength == 0) 355 { 338 Int_t MCorsikaFormatEventIO::GetNextEvent(Float_t **buffer, UInt_t telescope) 339 { 340 static Float_t *data = NULL; 341 static Int_t lengthEvent = -1; 342 static Int_t lengthPhotonData = 0; 343 344 while (lengthPhotonData == 0) 345 { 356 346 delete [] data; 357 347 data = NULL; 358 348 359 if (topLevelLength == 0) 360 { 361 if (!NextTopLevelBlock(topLevelLength, readError)) 362 return kFALSE; 363 } 364 365 if (!NextEventBlock(eventLength, readError)) 366 return kFALSE; 367 topLevelLength -= eventLength + 3 * sizeof(int); 368 369 // read next block of events 370 data = new Float_t [eventLength / sizeof(Float_t)]; 371 if (!ReadData(eventLength / sizeof(Float_t), data, 0)) 372 { 349 // If we are at the end of the event signal this and 350 // start next time with a new event 351 if (lengthEvent==0) 352 { 353 lengthEvent=-1; 354 return kFALSE; // Signal to start with a new event (process task list first) 355 } 356 357 // Look for the next top level block (an "event", object type 1204) 358 // A top level block contains the data of a full array simulation 359 // (a single re-usage of the shower) 360 if (lengthEvent<0) 361 { 362 // The length of the block is stored and we use it to determine 363 // when the next top level block is expected 364 const Int_t rc = NextEventObject(lengthEvent); 365 if (rc!=kTRUE) 366 return rc; 367 } 368 369 // Look for the next event photon bunch (object type 1205) 370 const Int_t tel = NextPhotonObject(lengthPhotonData); 371 if (tel<0) 372 return kERROR; 373 374 // Decrease the distance to the next "event" by the current photon bunches 375 lengthEvent -= lengthPhotonData + 3 * sizeof(int); 376 377 // If the telescope is not the one we want to read skip the photon data 378 if (UInt_t(tel)!=telescope) 379 { 380 fPrevPos = fIn->tellg(); 381 fIn->seekg(lengthPhotonData, ios::cur); 382 lengthPhotonData=0; 383 continue; 384 } 385 386 const UInt_t cnt = lengthPhotonData / sizeof(Float_t); 387 388 // Read next object (photon bunch) 389 data = new Float_t[cnt]; 390 if (!ReadData(cnt, data, 0)) 391 { 373 392 delete [] data; 374 393 data = NULL; 375 readError = kTRUE; 376 return kFALSE; 377 } 378 next = data + 3; 379 eventLength -= 3 * sizeof(Float_t); 380 } 381 382 eventLength -= 8 * sizeof(Float_t); 383 *buffer = next; 384 next += 8; 385 394 return kERROR; 395 } 396 397 // The object containing the photon bunches starts with: 398 // Array[short], Telescope[Short], NumPhotons[Real], NumBunches[Long] 399 // eventLength contains now the number of bytes with photon data not yet evaluated 400 lengthPhotonData -= 3 * sizeof(Float_t); 401 } 402 403 // The photon data itself is 8 floats long. When we return we expect this to be 404 // evaluated already when the function is called the next time. 405 lengthPhotonData -= 8 * sizeof(Float_t); 406 407 // Return the pointer to the start of the current photon data 408 *buffer = data + 3; 386 409 387 410 return kTRUE; … … 394 417 // EventEnd block (1209). In this case kFALSE is returned 395 418 // 396 Bool_t MCorsikaFormatEventIO::NextTopLevelBlock(Int_t & length, 397 Bool_t & readError) const 398 { 399 Int_t blockHeader[4]; 400 419 Int_t MCorsikaFormatEventIO::NextEventObject(Int_t &length) const 420 { 401 421 while (1) 402 422 { … … 405 425 // - identification field 406 426 // - length 427 428 UInt_t blockHeader[4]; 407 429 fIn->read((char*)blockHeader, 4 * sizeof(Int_t)); 408 430 409 431 if (fIn->eof()) 410 { 411 gLog << err << "ERROR - Missing identifier: 1204 or 1209" << endl; 412 readError = kTRUE; 413 return kFALSE; 414 } 415 432 { 433 gLog << err << "MCorsikaFormatEventIO::NextEventObject: ERROR - Unexpected end-of-file." << endl; 434 return kERROR; 435 } 436 437 // For speed reasons we skip the check of the synchronization marker 438 439 // Decode the object type 440 const unsigned short objType = blockHeader[1] & 0xFFFF; 441 442 // Decode length of block 416 443 length = blockHeader[3] & 0x3fffffff; 417 const unsigned short fileType = blockHeader[1] & 0xFFFF; 418 if (fileType == 1204) 444 445 // Check if we found the next array (reuse / impact parameter) 446 // blockHeader[2] == array number (reuse) 447 if (objType==1204) 419 448 return kTRUE; 420 449 421 if (fileType == 1209) 422 { 423 // we found an eventEnd block, reset file pointer 424 fIn->seekg( -4 * (Int_t)(sizeof(Int_t)), ios::cur); 425 length = 0; 426 return kFALSE; 427 } 428 450 // we found an eventEnd block, reset file pointer 451 if (objType==1209) 452 break; 429 453 430 454 // a unknown block, we jump to the next one 431 fIn->seekg(length, ios::cur); 432 } 433 434 return kTRUE; 435 } 436 437 // -------------------------------------------------------------------------- 438 // 439 Bool_t MCorsikaFormatEventIO::NextEventBlock(Int_t & length, 440 Bool_t & readError) const 441 { 442 Int_t blockHeader[3]; 455 fIn->seekg(length, ios::cur); 456 } 457 458 fIn->seekg( -4 * (Int_t)(sizeof(Int_t)), ios::cur); 459 length = 0; 460 461 return kFALSE; 462 } 463 464 // -------------------------------------------------------------------------- 465 // 466 Int_t MCorsikaFormatEventIO::NextPhotonObject(Int_t &length) const 467 { 468 UInt_t blockHeader[3]; 443 469 444 470 // we read - synchronisation marker … … 446 472 // - identification field 447 473 // - length 448 fIn->read((char*)blockHeader, 3 * sizeof( Int_t));474 fIn->read((char*)blockHeader, 3 * sizeof(UInt_t)); 449 475 450 476 if (fIn->eof()) 451 { 452 gLog << err << "ERROR - Missing identifier: 1205" << endl; 453 readError = kTRUE; 454 return kFALSE; 455 } 456 457 const unsigned short fileType = blockHeader[0] & 0xFFFF; 458 if (fileType != 1205) 459 { 460 gLog << err << "ERROR - Unexpected type: " << fileType << "expected 1205" << endl; 461 readError = kTRUE; 462 return kFALSE; 463 } 477 { 478 gLog << err << "MCorsikaFormatEventIO::NextPhotonObject: ERROR - Unexpected end-of-file.." << endl; 479 return -1; 480 } 481 482 const unsigned short objType = blockHeader[0] & 0xFFFF; 483 if (objType != 1205) 484 { 485 gLog << err << "MCorsikaFormatEventIO::NextPhotonObject: ERROR - Unexpected EventIO object type " << objType << " (expected 1205)." << endl; 486 return -1; 487 } 464 488 465 489 const unsigned short version = (blockHeader[0] >> 20) & 0x0FFF; 466 490 if (version != 0) 467 { 468 gLog << err << "ERROR - Unexpected version: " << version << "expected: 0" << endl; 469 readError = kTRUE; 470 return kFALSE; 471 } 491 { 492 gLog << err << "MCorsikaFormatEventIO::NextPhotonObject: ERROR - Unexpected EventIO object version " << version << " (expected 0 for object type 1205)." << endl; 493 return -1; 494 } 472 495 473 496 length = blockHeader[2] & 0x3fffffff; 474 497 475 return kTRUE;476 477 } 498 // blockHeader[1] == 1000 x array number (reuse) + telescope number 499 return blockHeader[1] % 1000; 500 } -
trunk/Mars/mcorsika/MCorsikaFormat.h
r9938 r9941 2 2 #define MARS_MDataFormat 3 3 4 #ifndef MARS_MAGIC 5 #include "MAGIC.h" 6 #endif 4 7 5 8 #ifndef ROOT_Rtypes … … 35 38 virtual void ResetPos() const; 36 39 37 virtual Bool_t GetNextEvent(Float_t ** buffer, Bool_t & readError) = 0;40 virtual Int_t GetNextEvent(Float_t **buffer, UInt_t tel=0) = 0; 38 41 virtual Bool_t IsEventioFormat() const = 0; 39 42 … … 59 62 Bool_t SeekEvtEnd(); 60 63 61 Bool_t GetNextEvent(Float_t ** buffer, Bool_t & readError);64 Int_t GetNextEvent(Float_t **buffer, UInt_t); 62 65 Bool_t IsEventioFormat() const {return kFALSE;} 63 66 }; … … 67 70 { 68 71 private: 69 72 std::streampos fRunePos; // file position of the RUNE block 70 73 71 74 public: 72 MCorsikaFormatEventIO(std::istream *in)75 MCorsikaFormatEventIO(std::istream *in) 73 76 : MCorsikaFormat(in) {fRunePos = std::streampos(0);} 74 77 75 Bool_t SeekNextBlock(const char *id, unsigned short type) const;76 void UnreadLastHeader() const;78 Bool_t SeekNextBlock(const char *id, unsigned short type) const; 79 void UnreadLastHeader() const; 77 80 78 Bool_t SeekEvtEnd();81 Bool_t SeekEvtEnd(); 79 82 80 Bool_t GetNextEvent(Float_t ** buffer, Bool_t & readError);81 Bool_t IsEventioFormat() const {return kTRUE;}83 Int_t GetNextEvent(Float_t **buffer, UInt_t tel); 84 Bool_t IsEventioFormat() const { return kTRUE; } 82 85 83 86 private: 84 Bool_t NextTopLevelBlock(Int_t & length, Bool_t & readError) const; 85 Bool_t NextEventBlock(Int_t & length, Bool_t & readError) const; 86 87 Int_t NextEventObject(Int_t &length) const; 88 Int_t NextPhotonObject(Int_t &length) const; 87 89 }; 88 90 -
trunk/Mars/mcorsika/MCorsikaRead.cc
r9937 r9941 96 96 // 97 97 MCorsikaRead::MCorsikaRead(const char *fname, const char *name, const char *title) 98 : fRunHeader(0), fEvtHeader(0), fEvent(0), /*fEvtData(0),*/fForceMode(kFALSE),98 : fRunHeader(0), fEvtHeader(0), fEvent(0), fTelescopeIdx(0), fForceMode(kFALSE), 99 99 fFileNames(0), fNumFile(0), fNumEvents(0), fNumTotalEvents(0), 100 100 fIn(0), fInFormat(0), fParList(0) … … 212 212 213 213 const char *expname = gSystem->ExpandPathName(name); 214 fInFormat = CorsikaFormatFactory(fLog,expname);214 fInFormat = MCorsikaFormat::CorsikaFormatFactory(expname); 215 215 delete [] expname; 216 216 … … 401 401 fInFormat->StorePos(); 402 402 fEvtHeader->ResetNumReuse(); 403 404 if (fInFormat->IsEventioFormat()) 405 { 406 // Read the event header 407 const Int_t rc1 = fEvtHeader->ReadEvt(fInFormat); 408 if (rc1!=kTRUE) 409 return rc1; 410 } 411 403 412 } 404 413 else 405 fInFormat->ResetPos(); 414 { 415 if (!fInFormat->IsEventioFormat()) 416 fInFormat->ResetPos(); 417 } 418 419 if (!fInFormat->IsEventioFormat()) 420 { 421 // Read the event header 422 const Int_t rc1 = fEvtHeader->ReadEvt(fInFormat); 423 if (rc1!=kTRUE) 424 return rc1; 425 426 } 406 427 407 428 fEvtHeader->IncNumReuse(); 408 409 // Read the event header 410 const Int_t rc1 = fEvtHeader->ReadEvt(fInFormat); 411 if (rc1!=kTRUE) 412 return rc1; 413 414 // Check if reusage number should be reset and increase it 415 // Note, that the trick here is that after reset it is set to -1 429 fEvtHeader->InitXY(); 430 431 // In the case of corsika raw data (MMCS only) we have too loop over one event 432 // several times to read all impact parameters (reusage of events) 433 // In case of the eventio format we have to decide, the data of which telescope 434 // we want to extract 435 const Int_t id = fInFormat->IsEventioFormat() ? fTelescopeIdx : fEvtHeader->GetNumReuse()+1; 416 436 417 437 // Read the photons corresponding to the i-th core location 418 const Int_t rc2 = fEvent->ReadCorsikaEvt(fInFormat, fEvtHeader->GetNumReuse()+1); 438 // EventIO: Number of telescope 439 // Raw: Number of re-use 440 const Int_t rc2 = fEvent->ReadCorsikaEvt(fInFormat, id); 419 441 if (rc2!=kTRUE) 420 442 return rc2; 443 444 //---- 445 if (fInFormat->IsEventioFormat()) 446 { 447 fEvent->AddXY(fEvtHeader->GetX(), fEvtHeader->GetY()); 448 fEvent->SimWavelength(fRunHeader->GetWavelengthMin(), fRunHeader->GetWavelengthMax()); 449 return kTRUE; 450 } 451 //---- 452 421 453 422 454 // read event end -
trunk/Mars/mcorsika/MCorsikaRead.h
r9937 r9941 22 22 MPhotonEvent *fEvent; //! event information 23 23 24 UInt_t fTelescopeIdx; // Index of telescope to be extracted 24 25 Bool_t fForceMode; // Force mode skipping defect RUNE 25 26 … … 52 53 ~MCorsikaRead(); 53 54 54 //static Byte_t IsFileValid(const char *name);55 56 //void SetInterleave(UInt_t i) { fInterleave = i; }57 55 void SetForceMode(Bool_t b=kTRUE) { fForceMode=b; } 56 void SetTelescopeIdx(UInt_t idx=0) { fTelescopeIdx = idx; } 58 57 59 58 TString GetFullFileName() const; -
trunk/Mars/msim/MPhotonData.cc
r9937 r9941 47 47 48 48 #include <TMath.h> 49 #include <TRandom.h> 49 50 50 51 #include "MLog.h" … … 171 172 // -------------------------------------------------------------------------- 172 173 // 174 // Set the wavelength to a random lambda^-2 distributed value 175 // between wmin and wmax. 176 // 177 void MPhotonData::SimWavelength(Float_t wmin, Float_t wmax) 178 { 179 const Double_t w = gRandom->Uniform(wmin, wmax); 180 181 fWavelength = TMath::Nint(wmin*wmax / w); 182 } 183 184 185 // -------------------------------------------------------------------------- 186 // 173 187 // Set the data member according to the 8 floats read from a reflector-file. 174 188 // This function MUST reset all data-members, no matter whether these are … … 255 269 Int_t MPhotonData::FillEventIO(Float_t f[8]) 256 270 { 257 if (TMath::Nint(f[6])!=1) 258 { 259 gLog << err << "ERROR - Bunch sizes != 1 are not supported." << endl; 260 return kFALSE; 261 } 271 // photons in this bunch 272 const UInt_t n = TMath::Nint(f[6]); 273 if (n==0) 274 return 0; 275 276 f[6] = n-1; 262 277 263 278 fPosX = f[1]; // xpos relative to telescope [cm] … … 267 282 fTime = f[4]; // a relative arival time [ns] 268 283 fProductionHeight = f[5]; // altitude of emission [cm] 269 // fNumPhotons = TMath::Nint(f[6]); // photons in this bunch270 284 fWavelength = TMath::Nint(f[7]); // so far always zeor = unspec. [nm] 271 285 … … 275 289 fWeight = 1; 276 290 277 return kTRUE; 278 } 291 return n; 292 } 293 279 294 /* 280 295 // -------------------------------------------------------------------------- -
trunk/Mars/msim/MPhotonData.h
r9937 r9941 101 101 void SetTime(Double_t t) { fTime = t; } 102 102 103 void SimWavelength(Float_t wmin, Float_t wmax); 104 103 105 void Copy(TObject &obj) const; 104 106 -
trunk/Mars/msim/MPhotonEvent.h
r9937 r9941 39 39 Double_t GetMeanX() const; 40 40 Double_t GetMeanY() const; 41 Double_t GetMeanT() const; 41 42 42 43 TClonesArray &GetArray() { return fData; } … … 54 55 Int_t Shrink(Int_t n); 55 56 void Resize(Int_t n); 57 58 void AddXY(Double_t x, Double_t y); 59 void SimWavelength(Float_t wmin, Float_t wmax); 56 60 57 61 // I/O
Note:
See TracChangeset
for help on using the changeset viewer.