ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimMatrixIO.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
8
10
12// Reader
14
15FPGATrackSimMatrixReader::FPGATrackSimMatrixReader(TTree *tree, size_t nLayers, size_t nCoords) :
16 m_tree(tree),
17 m_entry(0),
19 m_modules(nLayers),
20 m_acc(nLayers, nCoords),
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
92void 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
108std::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
126 m_tree(tree),
127 m_nEntries(0),
128 m_nLayers(nLayers),
129 m_nCoords(nCoords),
130 m_nCoords2(nCoords * nCoords),
136{
137 // Dummy variables for typing (the branch address will be set for each sector)
138 int anInt;
139 double aDouble;
140 float aFloat;
141
142 m_tree->Branch("ndim", &m_nCoords, "ndim/I");
143 m_tree->Branch("ndim2", &m_nCoords2, "ndim2/I");
144 m_tree->Branch("nplanes", &m_nLayers, "nplanes/I");
145
146 m_tree->Branch("sectorID", &anInt, "sectorID[nplanes]/I");
147 m_tree->Branch("hashID", &anInt, "hashID[nplanes]/I");
148
149 m_tree->Branch("tmpC", &aDouble, "tmpC/D");
150 m_tree->Branch("tmpD", &aDouble, "tmpD/D");
151 m_tree->Branch("tmpPhi", &aDouble, "tmpPhi/D");
152 m_tree->Branch("tmpCoto", &aDouble, "tmpCoto/D");
153 m_tree->Branch("tmpZ", &aDouble, "tmpZ/D");
154
155 m_tree->Branch("Vec", &aFloat, "Vec[ndim]/F");
156 m_tree->Branch("VecG", &aFloat, "VecG[ndim]/F");
157 m_tree->Branch("tmpxC", &aDouble, "tmpxC[ndim]/D");
158 m_tree->Branch("tmpxGC", &aDouble, "tmpxGC[ndim]/D");
159 m_tree->Branch("tmpxD", &aDouble, "tmpxD[ndim]/D");
160 m_tree->Branch("tmpxPhi", &aDouble, "tmpxPhi[ndim]/D");
161 m_tree->Branch("tmpxCoto", &aDouble, "tmpxCoto[ndim]/D");
162 m_tree->Branch("tmpxGCoto", &aDouble, "tmpxGCoto[ndim]/D");
163 m_tree->Branch("tmpxZ", &aDouble, "tmpxZ[ndim]/D");
164 m_tree->Branch("tmpcovx", &aDouble, "tmpcovx[ndim2]/D");
165 m_tree->Branch("tmpcovxG", &aDouble, "tmpcovxG[ndim2]/D");
166
167 m_tree->Branch("nhit", &m_coverage, "nhit/F");
168 m_tree->Branch("tmpintc", &m_pQoP);
169 m_tree->Branch("tmpintphi", &m_pphi);
170 m_tree->Branch("tmpintd0", &m_pd0);
171 m_tree->Branch("tmpintz0", &m_pz0);
172 m_tree->Branch("tmpinteta", &m_peta);
173}
174
175size_t FPGATrackSimMatrixWriter::fill(std::vector<module_t> modules, FPGATrackSimMatrixAccumulator & acc)
176{
177
178 m_tree->SetBranchAddress("sectorID", acc.FTK_modules.data());
179 m_tree->SetBranchAddress("hashID", modules.data());
180
181 m_tree->SetBranchAddress("tmpC", &acc.pars.qOverPt);
182 m_tree->SetBranchAddress("tmpD", &acc.pars.d0);
183 m_tree->SetBranchAddress("tmpPhi", &acc.pars.phi);
184 m_tree->SetBranchAddress("tmpCoto", &acc.pars.eta);
185 m_tree->SetBranchAddress("tmpZ", &acc.pars.z0);
186
187 m_tree->SetBranchAddress("Vec", acc.hit_coords.data());
188 m_tree->SetBranchAddress("VecG", acc.hit_coordsG.data());
189 m_tree->SetBranchAddress("tmpxC", acc.hit_x_QoP.data());
190 m_tree->SetBranchAddress("tmpxGC", acc.hit_xG_HIP.data());
191 m_tree->SetBranchAddress("tmpxD", acc.hit_x_d0.data());
192 m_tree->SetBranchAddress("tmpxPhi", acc.hit_x_phi.data());
193 m_tree->SetBranchAddress("tmpxCoto", acc.hit_x_eta.data());
194 m_tree->SetBranchAddress("tmpxGCoto", acc.hit_xG_eta.data());
195 m_tree->SetBranchAddress("tmpxZ", acc.hit_x_z0.data());
196 m_tree->SetBranchAddress("tmpcovx", acc.covariance.data());
197 m_tree->SetBranchAddress("tmpcovxG", acc.covarianceG.data());
198
199 m_bins_QoP.clear();
200 m_bins_phi.clear();
201 m_bins_z0.clear();
202 m_bins_d0.clear();
203 m_bins_eta.clear();
204 for (FPGATrackSimTrackParsI const & pars : acc.track_bins)
205 {
206 m_bins_QoP.push_back(pars.qOverPt);
207 m_bins_phi.push_back(pars.phi);
208 m_bins_d0.push_back(pars.d0);
209 m_bins_z0.push_back(pars.z0);
210 m_bins_eta.push_back(pars.eta);
211 }
212 m_coverage = static_cast<float>(acc.track_bins.size());
213 m_tree->Fill();
214 return m_nEntries++;
215}
216
217
226void fillTree(AccumulateMap & map, TTree *tree, int nLayers, int nCoords)
227{
228 fillTree(map.begin(), map.end(), tree, nLayers, nCoords);
229}
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
std::unordered_map< std::vector< module_t >, FPGATrackSimMatrixAccumulator, container_hash< std::vector< module_t > > > AccumulateMap
void readTree(AccumulateMap &map, TTree *tree, size_t nLayers, size_t nCoords)
Reads a matrix tree, accumulating its entries into a map.
void fillTree(AccumulateMap &map, TTree *tree, int nLayers, int nCoords)
Writes the contents of an AccumulateMap into the supplied tree (one entry per sector).
Classes to read/write matrix files event by event.
static const std::vector< std::string > bins
TGraphErrors * GetEntries(TH2F *histo)
FPGATrackSimMatrixAccumulator m_acc
std::vector< short > * m_pz0
std::vector< module_t > m_modules
FPGATrackSimMatrixReader(TTree *tree, size_t nLayers, size_t nCoords)
std::vector< short > m_bins_QoP
std::vector< short > m_bins_phi
std::vector< short > * m_pphi
std::vector< short > m_bins_eta
std::vector< short > m_bins_z0
std::vector< short > * m_peta
std::vector< short > m_bins_d0
std::vector< short > * m_pQoP
std::vector< short > * m_pd0
std::vector< short > m_bins_d0
std::vector< short > m_bins_eta
std::vector< short > m_bins_z0
std::vector< short > * m_peta
std::vector< short > m_bins_phi
FPGATrackSimMatrixWriter(TTree *tree, int nLayers, int nCoords)
std::vector< short > * m_pz0
std::vector< short > m_bins_QoP
std::vector< short > * m_pd0
std::vector< short > * m_pphi
std::vector< short > * m_pQoP
size_t fill(std::vector< module_t > modules, FPGATrackSimMatrixAccumulator &acc)
STL class.
TChain * tree