ATLAS Offline Software
FPGATrackSimMatrixIO.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
9 #include "FPGATrackSimMatrixIO.h"
10 
12 // Reader
14 
15 FPGATrackSimMatrixReader::FPGATrackSimMatrixReader(TTree *tree, size_t nLayers, size_t nCoords) :
16  m_tree(tree),
17  m_entry(0),
18  m_nEntries(tree->GetEntries()),
19  m_modules(nLayers),
20  m_acc(nLayers, nCoords),
21  m_pQoP(&m_bins_QoP),
22  m_pphi(&m_bins_phi),
23  m_pd0(&m_bins_d0),
24  m_pz0(&m_bins_z0),
25  m_peta(&m_bins_eta)
26 {
27  tree->SetBranchAddress("sectorID", m_acc.FTK_modules.data());
28  tree->SetBranchAddress("hashID", m_modules.data());
29 
30  tree->SetBranchAddress("tmpC", &m_acc.pars.qOverPt);
31  tree->SetBranchAddress("tmpD", &m_acc.pars.d0);
32  tree->SetBranchAddress("tmpPhi", &m_acc.pars.phi);
33  tree->SetBranchAddress("tmpCoto", &m_acc.pars.eta);
34  tree->SetBranchAddress("tmpZ", &m_acc.pars.z0);
35 
36  tree->SetBranchAddress("Vec", m_acc.hit_coords.data());
37  tree->SetBranchAddress("VecG", m_acc.hit_coordsG.data());
38  tree->SetBranchAddress("tmpxC", m_acc.hit_x_QoP.data());
39  tree->SetBranchAddress("tmpxGC", m_acc.hit_xG_HIP.data());
40  tree->SetBranchAddress("tmpxD", m_acc.hit_x_d0.data());
41  tree->SetBranchAddress("tmpxPhi", m_acc.hit_x_phi.data());
42  tree->SetBranchAddress("tmpxCoto", m_acc.hit_x_eta.data());
43  tree->SetBranchAddress("tmpxGCoto", m_acc.hit_xG_eta.data());
44  tree->SetBranchAddress("tmpxZ", m_acc.hit_x_z0.data());
45  tree->SetBranchAddress("tmpcovx", m_acc.covariance.data());
46  tree->SetBranchAddress("tmpcovxG", m_acc.covarianceG.data());
47 
48  tree->SetBranchAddress("tmpintc", &m_pQoP);
49  tree->SetBranchAddress("tmpintphi", &m_pphi);
50  tree->SetBranchAddress("tmpintd0", &m_pd0);
51  tree->SetBranchAddress("tmpintz0", &m_pz0);
52  tree->SetBranchAddress("tmpinteta", &m_peta);
53 }
54 
55 
57 {
58  m_tree->GetEntry(entry);
59 
60  m_acc.track_bins.clear();
61  for (size_t j = 0; j < m_bins_QoP.size(); j++)
62  {
64  bins.qOverPt = m_bins_QoP[j];
65  bins.phi = m_bins_phi[j];
66  bins.d0 = m_bins_d0[j];
67  bins.z0 = m_bins_z0[j];
68  bins.eta = m_bins_eta[j];
69  m_acc.track_bins.push_back(bins);
70  }
71 }
72 
74 {
75  if (m_entry >= m_nEntries) return false;
76 
78  m_entry++;
79  return true;
80 }
81 
82 
92 void readTree(AccumulateMap & map, TTree *tree, size_t nLayers, size_t nCoords)
93 {
94  FPGATrackSimMatrixReader reader(tree, nLayers, nCoords);
95  while (reader.nextEntry())
96  accumulate(map, reader.getModules(), reader.getAccumulator());
97 }
98 
99 
108 std::vector<std::pair<std::vector<module_t>, FPGATrackSimMatrixAccumulator>> readTree(TTree *tree, size_t nLayers, size_t nCoords)
109 {
110  std::vector<std::pair<std::vector<module_t>, FPGATrackSimMatrixAccumulator>> matrices;
111 
112  FPGATrackSimMatrixReader reader(tree, nLayers, nCoords);
113  while (reader.nextEntry())
114  matrices.push_back({ reader.getModules(), reader.getAccumulator() });
115 
116  return matrices;
117 }
118 
119 
121 // Writer
123 
124 
125 FPGATrackSimMatrixWriter::FPGATrackSimMatrixWriter(TTree *tree, int nLayers, int nCoords) :
126  m_tree(tree),
127  m_nEntries(0),
128  m_nLayers(nLayers),
129  m_nCoords(nCoords),
130  m_nCoords2(nCoords * nCoords),
131  m_pQoP(&m_bins_QoP),
132  m_pphi(&m_bins_phi),
133  m_pd0(&m_bins_d0),
134  m_pz0(&m_bins_z0),
135  m_peta(&m_bins_eta)
136 {
137  // Dummy variables for typing (the branch address will be set for each sector)
138  int anInt;
139  double aDouble;
140 
141  m_tree->Branch("ndim", &m_nCoords, "ndim/I");
142  m_tree->Branch("ndim2", &m_nCoords2, "ndim2/I");
143  m_tree->Branch("nplanes", &m_nLayers, "nplanes/I");
144 
145  m_tree->Branch("sectorID", &anInt, "sectorID[nplanes]/I");
146  m_tree->Branch("hashID", &anInt, "hashID[nplanes]/I");
147 
148  m_tree->Branch("tmpC", &aDouble, "tmpC/D");
149  m_tree->Branch("tmpD", &aDouble, "tmpD/D");
150  m_tree->Branch("tmpPhi", &aDouble, "tmpPhi/D");
151  m_tree->Branch("tmpCoto", &aDouble, "tmpCoto/D");
152  m_tree->Branch("tmpZ", &aDouble, "tmpZ/D");
153 
154  m_tree->Branch("Vec", &aDouble, "Vec[ndim]/D");
155  m_tree->Branch("VecG", &aDouble, "VecG[ndim]/D");
156  m_tree->Branch("tmpxC", &aDouble, "tmpxC[ndim]/D");
157  m_tree->Branch("tmpxGC", &aDouble, "tmpxGC[ndim]/D");
158  m_tree->Branch("tmpxD", &aDouble, "tmpxD[ndim]/D");
159  m_tree->Branch("tmpxPhi", &aDouble, "tmpxPhi[ndim]/D");
160  m_tree->Branch("tmpxCoto", &aDouble, "tmpxCoto[ndim]/D");
161  m_tree->Branch("tmpxGCoto", &aDouble, "tmpxGCoto[ndim]/D");
162  m_tree->Branch("tmpxZ", &aDouble, "tmpxZ[ndim]/D");
163  m_tree->Branch("tmpcovx", &aDouble, "tmpcovx[ndim2]/D");
164  m_tree->Branch("tmpcovxG", &aDouble, "tmpcovxG[ndim2]/D");
165 
166  m_tree->Branch("nhit", &m_coverage, "nhit/F");
167  m_tree->Branch("tmpintc", &m_pQoP);
168  m_tree->Branch("tmpintphi", &m_pphi);
169  m_tree->Branch("tmpintd0", &m_pd0);
170  m_tree->Branch("tmpintz0", &m_pz0);
171  m_tree->Branch("tmpinteta", &m_peta);
172 }
173 
174 size_t FPGATrackSimMatrixWriter::fill(std::vector<module_t> modules, FPGATrackSimMatrixAccumulator & acc)
175 {
176 
177  m_tree->SetBranchAddress("sectorID", acc.FTK_modules.data());
178  m_tree->SetBranchAddress("hashID", modules.data());
179 
180  m_tree->SetBranchAddress("tmpC", &acc.pars.qOverPt);
181  m_tree->SetBranchAddress("tmpD", &acc.pars.d0);
182  m_tree->SetBranchAddress("tmpPhi", &acc.pars.phi);
183  m_tree->SetBranchAddress("tmpCoto", &acc.pars.eta);
184  m_tree->SetBranchAddress("tmpZ", &acc.pars.z0);
185 
186  m_tree->SetBranchAddress("Vec", acc.hit_coords.data());
187  m_tree->SetBranchAddress("VecG", acc.hit_coordsG.data());
188  m_tree->SetBranchAddress("tmpxC", acc.hit_x_QoP.data());
189  m_tree->SetBranchAddress("tmpxGC", acc.hit_xG_HIP.data());
190  m_tree->SetBranchAddress("tmpxD", acc.hit_x_d0.data());
191  m_tree->SetBranchAddress("tmpxPhi", acc.hit_x_phi.data());
192  m_tree->SetBranchAddress("tmpxCoto", acc.hit_x_eta.data());
193  m_tree->SetBranchAddress("tmpxGCoto", acc.hit_xG_eta.data());
194  m_tree->SetBranchAddress("tmpxZ", acc.hit_x_z0.data());
195  m_tree->SetBranchAddress("tmpcovx", acc.covariance.data());
196  m_tree->SetBranchAddress("tmpcovxG", acc.covarianceG.data());
197 
198  m_bins_QoP.clear();
199  m_bins_phi.clear();
200  m_bins_z0.clear();
201  m_bins_d0.clear();
202  m_bins_eta.clear();
203  for (FPGATrackSimTrackParsI const & pars : acc.track_bins)
204  {
205  m_bins_QoP.push_back(pars.qOverPt);
206  m_bins_phi.push_back(pars.phi);
207  m_bins_d0.push_back(pars.d0);
208  m_bins_z0.push_back(pars.z0);
209  m_bins_eta.push_back(pars.eta);
210  }
211  m_coverage = static_cast<float>(acc.track_bins.size());
212  m_tree->Fill();
213  return m_nEntries++;
214 }
215 
216 
225 void fillTree(AccumulateMap & map, TTree *tree, int nLayers, int nCoords)
226 {
227  fillTree(map.begin(), map.end(), tree, nLayers, nCoords);
228 }
FPGATrackSimMatrixAccumulator::hit_x_QoP
std::vector< double > hit_x_QoP
Definition: FPGATrackSimMatrixAccumulator.h:77
FPGATrackSimMatrixWriter::fill
size_t fill(std::vector< module_t > modules, FPGATrackSimMatrixAccumulator &acc)
Definition: FPGATrackSimMatrixIO.cxx:174
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
readTree
void readTree(AccumulateMap &map, TTree *tree, size_t nLayers, size_t nCoords)
Reads a matrix tree, accumulating its entries into a map.
Definition: FPGATrackSimMatrixIO.cxx:92
FPGATrackSimMatrixAccumulator::hit_x_phi
std::vector< double > hit_x_phi
Definition: FPGATrackSimMatrixAccumulator.h:83
FPGATrackSimMatrixReader::FPGATrackSimMatrixReader
FPGATrackSimMatrixReader(TTree *tree, size_t nLayers, size_t nCoords)
Definition: FPGATrackSimMatrixIO.cxx:15
FPGATrackSimTrackPars::phi
double phi
Definition: FPGATrackSimTrackPars.h:24
FPGATrackSimMatrixReader::m_bins_eta
std::vector< short > m_bins_eta
Definition: FPGATrackSimMatrixIO.h:72
FPGATrackSimMatrixWriter::m_nCoords2
int m_nCoords2
Definition: FPGATrackSimMatrixIO.h:102
python.App.bins
bins
Definition: App.py:410
FPGATrackSimTrackPars::qOverPt
double qOverPt
Definition: FPGATrackSimTrackPars.h:25
FPGATrackSimMatrixAccumulator::covarianceG
std::vector< double > covarianceG
Definition: FPGATrackSimMatrixAccumulator.h:85
FPGATrackSimMatrixWriter::m_pz0
std::vector< short > * m_pz0
Definition: FPGATrackSimMatrixIO.h:115
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
tree
TChain * tree
Definition: tile_monitor.h:30
FPGATrackSimTrackPars::d0
double d0
Definition: FPGATrackSimTrackPars.h:26
FPGATrackSimMatrixReader::m_tree
TTree * m_tree
Definition: FPGATrackSimMatrixIO.h:60
FPGATrackSimMatrixReader::m_pz0
std::vector< short > * m_pz0
Definition: FPGATrackSimMatrixIO.h:78
FPGATrackSimMatrixReader::m_pphi
std::vector< short > * m_pphi
Definition: FPGATrackSimMatrixIO.h:76
FPGATrackSimMatrixAccumulator::hit_x_d0
std::vector< double > hit_x_d0
Definition: FPGATrackSimMatrixAccumulator.h:79
FPGATrackSimMatrixAccumulator::track_bins
std::vector< FPGATrackSimTrackParsI > track_bins
Definition: FPGATrackSimMatrixAccumulator.h:91
FPGATrackSimMatrixAccumulator::hit_coordsG
std::vector< double > hit_coordsG
Definition: FPGATrackSimMatrixAccumulator.h:76
FPGATrackSimTrackPars::eta
double eta
Definition: FPGATrackSimTrackPars.h:28
FPGATrackSimMatrixWriter::m_bins_eta
std::vector< short > m_bins_eta
Definition: FPGATrackSimMatrixIO.h:109
FPGATrackSimMatrixWriter::m_pd0
std::vector< short > * m_pd0
Definition: FPGATrackSimMatrixIO.h:114
FPGATrackSimMatrixWriter::m_bins_phi
std::vector< short > m_bins_phi
Definition: FPGATrackSimMatrixIO.h:106
FPGATrackSimMatrixReader::m_bins_z0
std::vector< short > m_bins_z0
Definition: FPGATrackSimMatrixIO.h:71
fillTree
void fillTree(AccumulateMap &map, TTree *tree, int nLayers, int nCoords)
Writes the contents of an AccumulateMap into the supplied tree (one entry per sector).
Definition: FPGATrackSimMatrixIO.cxx:225
FPGATrackSimMatrixAccumulator::hit_x_eta
std::vector< double > hit_x_eta
Definition: FPGATrackSimMatrixAccumulator.h:81
FPGATrackSimMatrixAccumulator::hit_xG_HIP
std::vector< double > hit_xG_HIP
Definition: FPGATrackSimMatrixAccumulator.h:78
FPGATrackSimMatrixReader::m_modules
std::vector< module_t > m_modules
Definition: FPGATrackSimMatrixIO.h:65
FPGATrackSimMatrixIO.h
Classes to read/write matrix files event by event.
FPGATrackSimMatrixAccumulator::hit_coords
std::vector< double > hit_coords
Definition: FPGATrackSimMatrixAccumulator.h:75
FPGATrackSimMatrixAccumulator::covariance
std::vector< double > covariance
Definition: FPGATrackSimMatrixAccumulator.h:84
FPGATrackSimMatrixWriter::FPGATrackSimMatrixWriter
FPGATrackSimMatrixWriter(TTree *tree, int nLayers, int nCoords)
Definition: FPGATrackSimMatrixIO.cxx:125
FPGATrackSimMatrixWriter::m_pQoP
std::vector< short > * m_pQoP
Definition: FPGATrackSimMatrixIO.h:112
FPGATrackSimMatrixReader::m_acc
FPGATrackSimMatrixAccumulator m_acc
Definition: FPGATrackSimMatrixIO.h:66
FPGATrackSimMatrixAccumulator
Definition: FPGATrackSimMatrixAccumulator.h:36
FPGATrackSimMatrixReader::m_bins_d0
std::vector< short > m_bins_d0
Definition: FPGATrackSimMatrixIO.h:70
FPGATrackSimMatrixReader::m_pd0
std::vector< short > * m_pd0
Definition: FPGATrackSimMatrixIO.h:77
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
FPGATrackSimMatrixWriter::m_pphi
std::vector< short > * m_pphi
Definition: FPGATrackSimMatrixIO.h:113
FPGATrackSimMatrixReader::m_bins_QoP
std::vector< short > m_bins_QoP
Definition: FPGATrackSimMatrixIO.h:68
FPGATrackSimMatrixReader
Definition: FPGATrackSimMatrixIO.h:41
FPGATrackSimMatrixReader::m_entry
size_t m_entry
Definition: FPGATrackSimMatrixIO.h:62
FPGATrackSimMatrixWriter::m_bins_z0
std::vector< short > m_bins_z0
Definition: FPGATrackSimMatrixIO.h:108
FPGATrackSimMatrixWriter::m_nCoords
int m_nCoords
Definition: FPGATrackSimMatrixIO.h:101
FPGATrackSimMatrixAccumulator::hit_x_z0
std::vector< double > hit_x_z0
Definition: FPGATrackSimMatrixAccumulator.h:80
FPGATrackSimMatrixAccumulator::FTK_modules
std::vector< module_t > FTK_modules
Definition: FPGATrackSimMatrixAccumulator.h:56
FPGATrackSimMatrixAccumulator::hit_xG_eta
std::vector< double > hit_xG_eta
Definition: FPGATrackSimMatrixAccumulator.h:82
FPGATrackSimMatrixReader::nextEntry
bool nextEntry()
Definition: FPGATrackSimMatrixIO.cxx:73
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
FPGATrackSimMatrixWriter::m_coverage
float m_coverage
Definition: FPGATrackSimMatrixIO.h:103
FPGATrackSimMatrixWriter::m_nEntries
size_t m_nEntries
Definition: FPGATrackSimMatrixIO.h:99
FPGATrackSimMatrixReader::m_bins_phi
std::vector< short > m_bins_phi
Definition: FPGATrackSimMatrixIO.h:69
FPGATrackSimMatrixAccumulator::pars
FPGATrackSimTrackPars pars
Definition: FPGATrackSimMatrixAccumulator.h:70
FPGATrackSimMatrixReader::readEntry
void readEntry(size_t entry)
Definition: FPGATrackSimMatrixIO.cxx:56
FPGATrackSimMatrixWriter::m_bins_d0
std::vector< short > m_bins_d0
Definition: FPGATrackSimMatrixIO.h:107
FPGATrackSimTrackPars::z0
double z0
Definition: FPGATrackSimTrackPars.h:27
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
FPGATrackSimMatrixReader::m_peta
std::vector< short > * m_peta
Definition: FPGATrackSimMatrixIO.h:79
FPGATrackSimMatrixReader::m_nEntries
size_t m_nEntries
Definition: FPGATrackSimMatrixIO.h:63
FPGATrackSimMatrixReader::m_pQoP
std::vector< short > * m_pQoP
Definition: FPGATrackSimMatrixIO.h:75
FPGATrackSimMatrixWriter::m_tree
TTree * m_tree
Definition: FPGATrackSimMatrixIO.h:97
AccumulateMap
std::unordered_map< std::vector< module_t >, FPGATrackSimMatrixAccumulator, container_hash< std::vector< module_t > > > AccumulateMap
Definition: FPGATrackSimMatrixAccumulator.h:108
FPGATrackSimMatrixWriter::m_bins_QoP
std::vector< short > m_bins_QoP
Definition: FPGATrackSimMatrixIO.h:105
collisions.reader
reader
read the goodrunslist xml file(s)
Definition: collisions.py:22
FPGATrackSimTrackParsI
Definition: FPGATrackSimTrackPars.h:56
FPGATrackSimMatrixWriter::m_peta
std::vector< short > * m_peta
Definition: FPGATrackSimMatrixIO.h:116
FPGATrackSimMatrixWriter::m_nLayers
int m_nLayers
Definition: FPGATrackSimMatrixIO.h:100