ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimMatrixIO.h
Go to the documentation of this file.
1// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
3#ifndef FPGATrackSimMATRIXREADER_H
4#define FPGATrackSimMATRIXREADER_H
5
14
17
18#include <vector>
19
20#include "TTree.h"
21
22
24// Reader
26
27
28/*
29 * Use nextEntry() or readEntry() to read the entry in the tree,
30 * then use getModules() or getAccumulator() to get a reference to the data.
31 *
32 * Example:
33 * FPGATrackSimMatrixReader reader(tree, nLayers, nCoords);
34 * while (reader.nextEntry())
35 * {
36 * std::vector<module_t> & modules = reader.getModules();
37 * FPGATrackSimMatrixAccumulator & acc = reader.getAccumulator();
38 * }
39 */
41{
42 public:
43
44 FPGATrackSimMatrixReader(TTree *tree, size_t nLayers, size_t nCoords);
45 ~FPGATrackSimMatrixReader() { m_tree->ResetBranchAddresses(); }
46
47 void setEntry(size_t entry) { m_entry = entry; }
48 size_t getEntry() const { return m_entry - 1; } // last read entry number
49
50 // Read the next entry. Returns true on success.
51 bool nextEntry();
52 // Read a specific entry.
53 void readEntry(size_t entry);
54
55 std::vector<module_t> & getModules() { return m_modules; }
57
58 private:
59
60 TTree* m_tree;
61
62 size_t m_entry;
63 size_t m_nEntries;
64
65 std::vector<module_t> m_modules;
67
68 std::vector<short> m_bins_QoP;
69 std::vector<short> m_bins_phi;
70 std::vector<short> m_bins_d0;
71 std::vector<short> m_bins_z0;
72 std::vector<short> m_bins_eta;
73
74 // These point to the variables above because ROOT expects a vector**.
75 std::vector<short>* m_pQoP;
76 std::vector<short>* m_pphi;
77 std::vector<short>* m_pd0;
78 std::vector<short>* m_pz0;
79 std::vector<short>* m_peta;
80};
81
83// Writer
85
87{
88 public:
89
90 FPGATrackSimMatrixWriter(TTree *tree, int nLayers, int nCoords);
91
92 // Returns entry filled
93 size_t fill(std::vector<module_t> modules, FPGATrackSimMatrixAccumulator & acc); // copying, necessary since root writing is not const but map keys are
94
95 private:
96
97 TTree* m_tree;
98
99 size_t m_nEntries;
103 float m_coverage = 0.0F;
104
105 std::vector<short> m_bins_QoP;
106 std::vector<short> m_bins_phi;
107 std::vector<short> m_bins_d0;
108 std::vector<short> m_bins_z0;
109 std::vector<short> m_bins_eta;
110
111 // These point to the variables above because ROOT expects a vector**.
112 std::vector<short>* m_pQoP;
113 std::vector<short>* m_pphi;
114 std::vector<short>* m_pd0;
115 std::vector<short>* m_pz0;
116 std::vector<short>* m_peta;
117};
118
119
121// Utility functions
123
133void readTree(AccumulateMap & map, TTree *tree, size_t nLayers, size_t nCoords);
134
135
144std::vector<std::pair<std::vector<module_t>, FPGATrackSimMatrixAccumulator>> readTree(TTree *tree, size_t nLayers, size_t nCoords);
145
146
156template<typename Iter>
157void fillTree(Iter begin, Iter end, TTree *tree, int nLayers, int nCoords)
158{
159 // Sort sectors by decreasing coverage
160 std::vector<Iter> sorted_sectors;
161 sorted_sectors.reserve(std::distance(begin, end));
162 for (Iter i = begin; i != end; i++) sorted_sectors.push_back(i);
163
164 std::sort(sorted_sectors.begin(), sorted_sectors.end(), [](Iter const & a, Iter const & b)
165 { return a->second.track_bins.size() > b->second.track_bins.size(); }
166 );
167
168 // Create the writer
169 FPGATrackSimMatrixWriter writer(tree, nLayers, nCoords);
170
171 // Fill the tree
172 for (Iter & sector_info : sorted_sectors)
173 writer.fill(sector_info->first, sector_info->second);
174}
175
176
177// Specialization to AccumulateMap
178void fillTree(AccumulateMap & map, TTree *tree, int nLayers, int nCoords);
179
180
181
182#endif
Helper struct for accumulating sector information for matrix generation.
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(Iter begin, Iter end, TTree *tree, int nLayers, int nCoords)
Writes the contents of an AccumulateMap into the supplied tree (one entry per sector).
static Double_t a
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< module_t > & getModules()
FPGATrackSimMatrixAccumulator & getAccumulator()
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.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TChain * tree