ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RootVertexAndTracksReader.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RootVertexAndTracksReader.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
12 #include <TChain.h>
13 #include <TFile.h>
14 #include <iostream>
15 
18 
21  : m_cfg(std::move(cfg)),
22  m_events(0),
23  m_inputChain(nullptr),
24  m_logger(Acts::getDefaultLogger("RootVertexAndTracksReader", lvl)) {
25  m_inputChain = new TChain(m_cfg.treeName.c_str());
26 
27  m_inputChain->SetBranchAddress("event_nr", &m_eventNr);
28  m_inputChain->SetBranchAddress("vx", &m_ptrVx);
29  m_inputChain->SetBranchAddress("vy", &m_ptrVy);
30  m_inputChain->SetBranchAddress("vz", &m_ptrVz);
31 
32  m_inputChain->SetBranchAddress("d0", &m_ptrD0);
33  m_inputChain->SetBranchAddress("z0", &m_ptrZ0);
34  m_inputChain->SetBranchAddress("phi", &m_ptrPhi);
35  m_inputChain->SetBranchAddress("theta", &m_ptrTheta);
36  m_inputChain->SetBranchAddress("qp", &m_ptrQP);
37  m_inputChain->SetBranchAddress("time", &m_ptrTime);
38  m_inputChain->SetBranchAddress("vtxID", &m_ptrVtxID);
39  m_inputChain->SetBranchAddress("trkCov", &m_ptrTrkCov);
40 
41  // loop over the input files
42  for (auto inputFile : m_cfg.fileList) {
43  // add file to the input chain
44  m_inputChain->Add(inputFile.c_str());
45  ACTS_DEBUG("Adding File " << inputFile << " to tree '" << m_cfg.treeName
46  << "'.");
47  }
48 
49  m_events = m_inputChain->GetEntries();
50  ACTS_DEBUG("The full chain has " << m_events << " entries.");
51 }
52 
54  delete m_ptrVx;
55  delete m_ptrVy;
56  delete m_ptrVz;
57  delete m_ptrD0;
58  delete m_ptrZ0;
59  delete m_ptrPhi;
60  delete m_ptrTheta;
61  delete m_ptrQP;
62  delete m_ptrTime;
63  delete m_ptrVtxID;
64  delete m_ptrTrkCov;
65 }
66 
68  return "RootVertexAndTracksReader";
69 }
70 
72  const {
73  return {0u, m_events};
74 }
75 
78  ACTS_DEBUG("Trying to read vertex and tracks.");
79 
80  if (m_inputChain && context.eventNumber < m_events) {
81  // Lock the mutex
82  std::lock_guard<std::mutex> lock(m_read_mutex);
83 
84  // The collection to be written
85  std::vector<FW::VertexAndTracks> mCollection;
86 
87  for (size_t ib = 0; ib < m_cfg.batchSize; ++ib) {
88  // Read the correct entry: batch size * event_number + ib
89  m_inputChain->GetEntry(m_cfg.batchSize * context.eventNumber + ib);
90  ACTS_VERBOSE("Reading entry: " << m_cfg.batchSize * context.eventNumber +
91  ib);
92 
93  // Loop over all vertices
94  for (size_t idx = 0; idx < m_ptrVx->size(); ++idx) {
95  FW::VertexAndTracks vtxAndTracks;
96  vtxAndTracks.vertex.position4[0] = (*m_ptrVx)[idx];
97  vtxAndTracks.vertex.position4[1] = (*m_ptrVy)[idx];
98  vtxAndTracks.vertex.position4[2] = (*m_ptrVz)[idx];
99  vtxAndTracks.vertex.position4[3] = 0;
100 
101  std::vector<Acts::BoundParameters> tracks;
102  // Loop over all tracks in current event
103  for (size_t trkId = 0; trkId < m_ptrD0->size(); ++trkId) {
104  // Take only tracks that belong to current vertex
105  if (static_cast<size_t>((*m_ptrVtxID)[trkId]) == idx) {
106  // Get track parameter
107  Acts::BoundVector newTrackParams;
108  newTrackParams << (*m_ptrD0)[trkId], (*m_ptrZ0)[trkId],
109  (*m_ptrPhi)[trkId], (*m_ptrTheta)[trkId], (*m_ptrQP)[trkId],
110  (*m_ptrTime)[trkId];
111 
112  // Get track covariance vector
113  std::vector<double> trkCovVec = (*m_ptrTrkCov)[trkId];
114 
115  // Construct track covariance
116  Acts::BoundSymMatrix covMat =
117  Eigen::Map<Acts::BoundSymMatrix>(trkCovVec.data());
118 
119  // Create track parameters and add to track list
120  std::shared_ptr<Acts::PerigeeSurface> perigeeSurface =
121  Acts::Surface::makeShared<Acts::PerigeeSurface>(
122  Acts::Vector3D(0., 0., 0.));
123  tracks.push_back(
124  Acts::BoundParameters(context.geoContext, std::move(covMat),
125  newTrackParams, perigeeSurface));
126  }
127  } // End loop over all tracks
128  // Set tracks
129  vtxAndTracks.tracks = tracks;
130  // Add to collection
131  mCollection.push_back(std::move(vtxAndTracks));
132  }
133  }
134 
135  // Write to the collection to the EventStore
136  context.eventStore.add(m_cfg.outputCollection, std::move(mCollection));
137  }
138  // Return success flag
140 }