ATLAS Offline Software
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 
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 
133 void readTree(AccumulateMap & map, TTree *tree, size_t nLayers, size_t nCoords);
134 
135 
144 std::vector<std::pair<std::vector<module_t>, FPGATrackSimMatrixAccumulator>> readTree(TTree *tree, size_t nLayers, size_t nCoords);
145 
146 
156 template<typename Iter>
157 void 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
178 void fillTree(AccumulateMap & map, TTree *tree, int nLayers, int nCoords);
179 
180 
181 
182 #endif
FPGATrackSimMatrixWriter::fill
size_t fill(std::vector< module_t > modules, FPGATrackSimMatrixAccumulator &acc)
Definition: FPGATrackSimMatrixIO.cxx:175
FPGATrackSimMatrixReader::FPGATrackSimMatrixReader
FPGATrackSimMatrixReader(TTree *tree, size_t nLayers, size_t nCoords)
Definition: FPGATrackSimMatrixIO.cxx:15
FPGATrackSimMatrixReader::m_bins_eta
std::vector< short > m_bins_eta
Definition: FPGATrackSimMatrixIO.h:72
FPGATrackSimMatrixWriter::m_nCoords2
int m_nCoords2
Definition: FPGATrackSimMatrixIO.h:102
FPGATrackSimMatrixWriter
Definition: FPGATrackSimMatrixIO.h:87
FPGATrackSimMatrixWriter::m_pz0
std::vector< short > * m_pz0
Definition: FPGATrackSimMatrixIO.h:115
tree
TChain * tree
Definition: tile_monitor.h:30
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
FPGATrackSimMatrixReader::m_tree
TTree * m_tree
Definition: FPGATrackSimMatrixIO.h:60
FPGATrackSimMatrixReader::getEntry
size_t getEntry() const
Definition: FPGATrackSimMatrixIO.h:48
FPGATrackSimMatrixReader::m_pz0
std::vector< short > * m_pz0
Definition: FPGATrackSimMatrixIO.h:78
FPGATrackSimMatrixReader::m_pphi
std::vector< short > * m_pphi
Definition: FPGATrackSimMatrixIO.h:76
FPGATrackSimMatrixReader::~FPGATrackSimMatrixReader
~FPGATrackSimMatrixReader()
Definition: FPGATrackSimMatrixIO.h:45
FPGATrackSimMatrixReader::setEntry
void setEntry(size_t entry)
Definition: FPGATrackSimMatrixIO.h:47
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
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
FPGATrackSimMatrixReader::m_bins_z0
std::vector< short > m_bins_z0
Definition: FPGATrackSimMatrixIO.h:71
FPGATrackSimMatrixReader::m_modules
std::vector< module_t > m_modules
Definition: FPGATrackSimMatrixIO.h:65
FPGATrackSimMatrixWriter::FPGATrackSimMatrixWriter
FPGATrackSimMatrixWriter(TTree *tree, int nLayers, int nCoords)
Definition: FPGATrackSimMatrixIO.cxx:125
fillTree
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).
Definition: FPGATrackSimMatrixIO.h:157
lumiFormat.i
int i
Definition: lumiFormat.py:85
FPGATrackSimMatrixWriter::m_pQoP
std::vector< short > * m_pQoP
Definition: FPGATrackSimMatrixIO.h:112
FPGATrackSimMatrixReader::getAccumulator
FPGATrackSimMatrixAccumulator & getAccumulator()
Definition: FPGATrackSimMatrixIO.h:56
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
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
FPGATrackSimMatrixAccumulator.h
Helper struct for accumulating sector information for matrix generation.
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
FPGATrackSimMatrixReader::m_bins_phi
std::vector< short > m_bins_phi
Definition: FPGATrackSimMatrixIO.h:69
FPGATrackSimMatrixReader::getModules
std::vector< module_t > & getModules()
Definition: FPGATrackSimMatrixIO.h:55
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
a
TList * a
Definition: liststreamerinfos.cxx:10
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
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
example.writer
writer
show summary of content
Definition: example.py:36
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
FPGATrackSimTypes.h
FPGATrackSimMatrixWriter::m_peta
std::vector< short > * m_peta
Definition: FPGATrackSimMatrixIO.h:116
FPGATrackSimMatrixWriter::m_nLayers
int m_nLayers
Definition: FPGATrackSimMatrixIO.h:100