23 #include <TMathBase.h>
31 if (
m_cfg.fileList.empty()) {
32 throw std::invalid_argument{
"No input files given"};
35 m_inputChain =
new TChain(
m_cfg.treeName.c_str());
38 for (
const auto& inputFile :
m_cfg.fileList) {
40 m_inputChain->Add(inputFile.c_str());
41 ACTS_DEBUG(
"Adding File " << inputFile <<
" to tree '" <<
m_cfg.treeName
46 size_t nentries = m_inputChain->GetEntries();
49 (
TTree::kMatch == m_inputChain->SetBranchAddress(
"event_id", &m_eventId));
51 m_inputChain->SetBranchAddress(
"v_x", &m_v_x);
52 m_inputChain->SetBranchAddress(
"v_y", &m_v_y);
53 m_inputChain->SetBranchAddress(
"v_z", &m_v_z);
54 m_inputChain->SetBranchAddress(
"v_px", &m_v_px);
55 m_inputChain->SetBranchAddress(
"v_py", &m_v_py);
56 m_inputChain->SetBranchAddress(
"v_pz", &m_v_pz);
57 m_inputChain->SetBranchAddress(
"v_phi", &m_v_phi);
58 m_inputChain->SetBranchAddress(
"v_eta", &m_v_eta);
59 m_inputChain->SetBranchAddress(
"t_X0", &m_tX0);
60 m_inputChain->SetBranchAddress(
"t_L0", &m_tL0);
61 m_inputChain->SetBranchAddress(
"mat_x", &m_step_x);
62 m_inputChain->SetBranchAddress(
"mat_y", &m_step_y);
63 m_inputChain->SetBranchAddress(
"mat_z", &m_step_z);
64 m_inputChain->SetBranchAddress(
"mat_dx", &m_step_dx);
65 m_inputChain->SetBranchAddress(
"mat_dy", &m_step_dy);
66 m_inputChain->SetBranchAddress(
"mat_dz", &m_step_dz);
67 m_inputChain->SetBranchAddress(
"mat_step_length", &m_step_length);
68 m_inputChain->SetBranchAddress(
"mat_X0", &m_step_X0);
69 m_inputChain->SetBranchAddress(
"mat_L0", &m_step_L0);
70 m_inputChain->SetBranchAddress(
"mat_A", &m_step_A);
71 m_inputChain->SetBranchAddress(
"mat_Z", &m_step_Z);
72 m_inputChain->SetBranchAddress(
"mat_rho", &m_step_rho);
73 if (
m_cfg.readCachedSurfaceInformation) {
74 m_inputChain->SetBranchAddress(
"sur_id", &m_sur_id);
75 m_inputChain->SetBranchAddress(
"sur_x", &m_sur_x);
76 m_inputChain->SetBranchAddress(
"sur_y", &m_sur_y);
77 m_inputChain->SetBranchAddress(
"sur_z", &m_sur_z);
78 m_inputChain->SetBranchAddress(
"sur_pathCorrection", &m_sur_pathCorrection);
81 m_events = eventIdPresent
82 ?
static_cast<size_t>(m_inputChain->GetMaximum(
"event_id") + 1)
84 m_batchSize = nentries / m_events;
86 << nentries <<
" entries for " << m_events
87 <<
" events this corresponds to a batch size of: " << m_batchSize);
88 std::cout <<
"The full chain has " << nentries <<
" entries for " << m_events
89 <<
" events this corresponds to a batch size of: " << m_batchSize
93 if (not
m_cfg.orderedEvents) {
94 if (not eventIdPresent) {
95 throw std::invalid_argument{
96 "'event_id' branch is missing in your tree. This is not compatible "
97 "with unordered events."};
99 m_entryNumbers.resize(nentries);
100 m_inputChain->Draw(
"event_id",
"",
"goff");
102 TMath::Sort(m_inputChain->GetEntries(), m_inputChain->GetV1(),
103 m_entryNumbers.data(),
false);
105 m_outputMaterialTracks.initialize(
m_cfg.collection);
117 delete m_step_length;
128 delete m_sur_pathCorrection;
132 return "RootMaterialTrackReader";
135 std::pair<size_t, size_t>
137 return {0
u, m_events};
142 ACTS_DEBUG(
"Trying to read recorded material from tracks.");
144 if (m_inputChain !=
nullptr && context.
eventNumber < m_events) {
146 std::lock_guard<std::mutex> lock(m_read_mutex);
150 std::unordered_map<size_t, Acts::RecordedMaterialTrack> mtrackCollection;
153 for (
size_t ib = 0;
ib < m_batchSize; ++
ib) {
156 if (not
m_cfg.orderedEvents and
entry < m_entryNumbers.size()) {
160 <<
" with stored entry: " <<
entry);
161 m_inputChain->GetEntry(
entry);
166 rmTrack.first.second =
Acts::Vector3(m_v_px, m_v_py, m_v_pz);
169 ACTS_VERBOSE(
"Track momentum:" << rmTrack.first.second);
172 size_t msteps = m_step_length->size();
173 ACTS_VERBOSE(
"Reading " << msteps <<
" material steps.");
174 rmTrack.second.materialInteractions.reserve(msteps);
175 rmTrack.second.materialInX0 = 0.;
176 rmTrack.second.materialInL0 = 0.;
178 for (
size_t is = 0; is < msteps; ++is) {
180 ACTS_VERBOSE(
"[" << is + 1 <<
"/" << msteps <<
"] STEP INFORMATION: ");
182 double s = (*m_step_length)[is];
188 double mX0 = (*m_step_X0)[is];
189 double mL0 = (*m_step_L0)[is];
191 rmTrack.second.materialInX0 += s / mX0;
192 rmTrack.second.materialInL0 += s / mL0;
196 Acts::Vector3((*m_step_x)[is], (*m_step_y)[is], (*m_step_z)[is]);
197 ACTS_VERBOSE(
"POSITION : " << (*m_step_x)[is] <<
", " << (*m_step_y)[is]
198 <<
", " << (*m_step_z)[is]);
200 Acts::Vector3((*m_step_dx)[is], (*m_step_dy)[is], (*m_step_dz)[is]);
202 << (*m_step_dy)[is] <<
", "
203 << (*m_step_dz)[is]);
206 (*m_step_Z)[is], (*m_step_rho)[is]),
209 << (*m_step_A)[is] <<
", " << (*m_step_Z)[is]
210 <<
", " << (*m_step_rho)[is]);
213 if (
m_cfg.readCachedSurfaceInformation) {
219 Acts::Vector3((*m_sur_x)[is], (*m_sur_y)[is], (*m_sur_z)[is]);
225 rmTrack.second.materialInteractions.push_back(
std::move(mInteraction));
230 m_outputMaterialTracks(context,
std::move(mtrackCollection));