LDMX Software
ParticleReader Struct Reference

Struct used for reading particles written out by the TrackFinderPerformanceWriter. More...

#include <TreeReader.h>

Public Member Functions

 ParticleReader (TTree *tree_, bool sortEvents)
 
std::vector< ParticleInfogetParticles (const std::uint32_t &eventNumber) const
 
- Public Member Functions inherited from TreeReader
 TreeReader (TTree *tree_)
 
void getEntry (unsigned int i) const
 

Public Attributes

ULong64_t eventId = 0
 
ULong64_t particleId = 0
 
Int_t particleType = 0
 
float vx = 0
 
float vy = 0
 
float vz = 0
 
float vt = 0
 
float px = 0
 
float py = 0
 
float pz = 0
 
float m = 0
 
float q = 0
 
UShort_t nHits = 0
 
UShort_t nTracks = 0
 
UShort_t nTracksMajority = 0
 
- Public Attributes inherited from TreeReader
TTree * tree = nullptr
 

Additional Inherited Members

- Protected Attributes inherited from TreeReader
std::vector< long long > entryNumbers = {}
 The entry numbers for accessing events in increased order (there could be multiple entries corresponding to one event number)
 

Detailed Description

Struct used for reading particles written out by the TrackFinderPerformanceWriter.

Definition at line 405 of file TreeReader.h.

Constructor & Destructor Documentation

◆ ParticleReader()

ParticleReader::ParticleReader ( TTree * tree_,
bool sortEvents )
inline

Definition at line 410 of file TreeReader.h.

410 : TreeReader(tree_) {
411 tree->SetBranchAddress("event_id", &eventId);
412 tree->SetBranchAddress("particle_id", &particleId);
413 tree->SetBranchAddress("particle_type", &particleType);
414 tree->SetBranchAddress("vx", &vx);
415 tree->SetBranchAddress("vy", &vy);
416 tree->SetBranchAddress("vz", &vz);
417 tree->SetBranchAddress("vt", &vt);
418 tree->SetBranchAddress("px", &px);
419 tree->SetBranchAddress("py", &py);
420 tree->SetBranchAddress("pz", &pz);
421 tree->SetBranchAddress("m", &m);
422 tree->SetBranchAddress("q", &q);
423 tree->SetBranchAddress("nhits", &nHits);
424 tree->SetBranchAddress("ntracks", &nTracks);
425 tree->SetBranchAddress("ntracks_majority", &nTracksMajority);
426
427 // It's not necessary if you just need to read one file, but please do it to
428 // synchronize events if multiple root files are read
429 if (sortEvents) {
430 entryNumbers.resize(tree->GetEntries());
431 tree->Draw("event_id", "", "goff");
432 // Sort to get the entry numbers of the ordered events
433 TMath::Sort(tree->GetEntries(), tree->GetV1(), entryNumbers.data(),
434 false);
435 }
436 }
Helper for reading tree.
Definition TreeReader.h:37
std::vector< long long > entryNumbers
The entry numbers for accessing events in increased order (there could be multiple entries correspond...
Definition TreeReader.h:56

Member Function Documentation

◆ getParticles()

std::vector< ParticleInfo > ParticleReader::getParticles ( const std::uint32_t & eventNumber) const
inline

Definition at line 439 of file TreeReader.h.

439 {
440 // Find the start entry and the batch size for this event
441 std::string eventNumberStr = std::to_string(eventNumber);
442 std::string findStartEntry = "event_id<" + eventNumberStr;
443 std::string findParticlesSize = "event_id==" + eventNumberStr;
444 std::size_t startEntry = tree->GetEntries(findStartEntry.c_str());
445 std::size_t nParticles = tree->GetEntries(findParticlesSize.c_str());
446 if (nParticles == 0) {
447 throw std::invalid_argument(
448 "No particles found. Please check the input file.");
449 }
450 std::vector<ParticleInfo> particles;
451 particles.reserve(nParticles);
452 for (unsigned int i = 0; i < nParticles; ++i) {
453 getEntry(startEntry + i);
454 auto pt = std::hypot(px, py);
455 auto p = std::hypot(pt, pz);
456 auto eta = std::atanh(pz / p * 1.);
457 particles.push_back({particleId, eta, p, pt, nHits});
458 }
459 return particles;
460 }

Member Data Documentation

◆ eventId

ULong64_t ParticleReader::eventId = 0

Definition at line 463 of file TreeReader.h.

◆ m

float ParticleReader::m = 0

Definition at line 469 of file TreeReader.h.

◆ nHits

UShort_t ParticleReader::nHits = 0

Definition at line 471 of file TreeReader.h.

◆ nTracks

UShort_t ParticleReader::nTracks = 0

Definition at line 472 of file TreeReader.h.

◆ nTracksMajority

UShort_t ParticleReader::nTracksMajority = 0

Definition at line 473 of file TreeReader.h.

◆ particleId

ULong64_t ParticleReader::particleId = 0

Definition at line 464 of file TreeReader.h.

◆ particleType

Int_t ParticleReader::particleType = 0

Definition at line 465 of file TreeReader.h.

◆ px

float ParticleReader::px = 0

Definition at line 468 of file TreeReader.h.

◆ py

float ParticleReader::py = 0

Definition at line 468 of file TreeReader.h.

◆ pz

float ParticleReader::pz = 0

Definition at line 468 of file TreeReader.h.

◆ q

float ParticleReader::q = 0

Definition at line 470 of file TreeReader.h.

◆ vt

float ParticleReader::vt = 0

Definition at line 467 of file TreeReader.h.

◆ vx

float ParticleReader::vx = 0

Definition at line 466 of file TreeReader.h.

◆ vy

float ParticleReader::vy = 0

Definition at line 466 of file TreeReader.h.

◆ vz

float ParticleReader::vz = 0

Definition at line 466 of file TreeReader.h.


The documentation for this struct was generated from the following file: