ATLAS Offline Software
FPGATrackSimPlaneMap.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 #ifndef FPGATrackSimPLANEMAP_H
4 #define FPGATrackSimPLANEMAP_H
5 
30 
31 
32 #include <vector>
33 #include <string>
34 #include <stdexcept>
35 #include <fstream>
36 #include <memory>
37 
38 
40 {
41  int layer = -1; // logical layer, -1 if unused
42  uint32_t section = 0; // arbitrary enumeration (identifier) if there are multiple detector elements in the same logical layer
43 };
44 
45 
46 /* Max index of modules along phi and eta is specified.
47  * Attention: on SCT layers the modules with eta index 0 is missing so the actual number of modules is neta-1.
48  * ^ ^ ^
49  * Is this still true???
50  */
51 struct LayerInfo
52 {
55  int physLayer = -1; // physical layer number (see this file's header)
56  int physDisk = -1; //
57  int stereo = -1; // strip layer side
58 };
59 
60 
62 {
63  public:
65  // Constructor/Destructor
67  // See doc on m_layerOverrides for info on argument layerOverrides
68  FPGATrackSimPlaneMap(std::ifstream& fin, unsigned region, unsigned stage,
69  std::vector<int> layerOverrides = std::vector<int>());
71  // Sizing
73 
74  uint32_t getNDetLayers() const { return m_nDetLayers; }
76  uint32_t getNCoords() const { return m_nCoords; }
77  uint32_t getNSections(size_t logiLayer) const { return m_layerInfo[logiLayer].size(); }
78  uint32_t getDim(size_t logiLayer) const { return m_dimension[logiLayer]; }
79  SiliconTech getDetType(size_t logiLayer) const { return m_dimension[logiLayer] == 2 ? SiliconTech::pixel : SiliconTech::strip; }
80 
82  // Layer <-> Coordinates
84 
85  /* Coordinates in tracks / matrices are flattened into a single array.
86  * Each layer, in order, gets 1 (strip) or 2 (pixel) entries.
87  * This entry gives the offset for the first coordinate for a given layer.
88  * The coordinates for a pixel hit are e.g.
89  * x = coords[getCoordOffset(layer)];
90  * y = coords[getCoordOffset(layer) + 1]
91  */
92  uint32_t getCoordOffset(size_t logiLayer) const { return m_coordOffset[logiLayer]; }
93 
94  /* This does the inverse search of the above function getCoordOffset.
95  * Given the coordinate index/offset, this function returns the logical layer
96  * that coordinate belongs to.
97  */
99 
101  // Info about a logical layer
103 
105 
106  bool isSCT(int pl) const { return m_dimension[pl] == 1; }
107  bool isPixel(int pl) const { return m_dimension[pl] == 2; }
109 
110  std::string layerName(uint32_t layer, uint32_t section) const;
111 
113  // Getting the logical layer
115 
116  // Main function. Wrapper/shortcuts below.
118  {
119  if ( static_cast<size_t>(siTech) < m_map.size() ) {
120  if ( static_cast<size_t>(zone) < m_map.at(static_cast<size_t>(siTech)).size() ) {
121  if ( physLayer < m_map.at(static_cast<size_t>(siTech)).at(static_cast<size_t>(zone)).size() ) {
122  return m_map[static_cast<size_t>(siTech)][static_cast<size_t>(zone)][physLayer];
123  }
124  }
125  }
126  return m_inValidLayerSection;
127  }
128 
129  const LayerSection & getLayerSection(LayerInfo const & mi) const
130  { return getLayerSection(mi.siTech, mi.zone, mi.physLayer); }
131 
132  int getLayer(SiliconTech siTech, DetectorZone zone, uint32_t physLayer) const
133  { return getLayerSection(siTech, zone, physLayer).layer; }
134 
135  unsigned getSection(SiliconTech siTech, DetectorZone zone, uint32_t physLayer) const
136  { return getLayerSection(siTech, zone, physLayer).section; }
137 
138 
140  // Mapping Hits
142  void doRemap(FPGATrackSimHit & hit) const;
143  void map(FPGATrackSimHit & hit) const ;
144 
145  private:
146 
147  uint32_t m_nLogiLayers = 0; // number of logical layers
148  uint32_t m_nDetLayers = 0; // number of physical detector layers used (I think this is different than physical layers, i.e. the index into getMap());
149  uint32_t m_nCoords = 0; // total number of coordinates in a pattern == accumulate(m_dimension)
150 
151  std::vector<uint32_t> m_dimension; // Index by (logiLayer). Dimension of layer (1 for strip, 2 for pixels). Assumes same across logical layer.
152  std::vector<uint32_t> m_coordOffset; // Index by (logiLayer).
153  // Coordinates for a track i.e. are flattened into a single array. Each layer, in order, gets 1 (strip) or 2 (pixel) entries.
154  // This entry gives the offset for the first coordinate for a given layer.
155  // The coordinates for a pixel hit are e.g. x = coords[m_coordOffset(layer)], y = coords[m_coordOffset(layer) + 1]
156  std::vector<uint32_t> m_coordLayer; // Index by (coordinate #)
157  // Inverse of above map. Given the coordinate index, returns the logical layer of the coordinate.
158 
159  std::vector<std::vector<std::vector<LayerSection>>> m_map; // index by (SCT/PIXEL, BARREL/posENDCAP/negENDCAP, physLayer)
160  // Maps detector layers to logical layer and section numbers
161  std::vector<std::vector<LayerInfo>> m_layerInfo; // index by (logiLayer, section)
162  // Get info about a logical layer section
163 
164  std::vector<int> m_layerOverrides; // Overrides the selection of logical layers
165  // If not empty, each entry declares a detector layer to use as a logical layer
166  // Specify a detector layer with { SilictonTech * 1000 + DetectorZone * 100 + PhysicalLayer }
167 
168  std::vector<uint32_t> m_diskIndex; // index of disks in the pixel endcap, indexed by ITK layer_disk
169 
170  // Module relabel object for remapping pixel endcap hits.
171  std::unique_ptr<FPGATrackSimModuleRelabel> m_moduleRelabel{};
172 
173  // this is used when the getLayerSection needs to return a reference to an invalid LayerSection
175 
177  // Helper Functions
178  void allocateMap(std::ifstream & fin, uint32_t stage);
179  void seek(std::ifstream & fin, unsigned region);
180  void readLayers(std::ifstream & fin, uint32_t stage);
181  int getOverrideLayer(SiliconTech si, DetectorZone dz, int physLayer);
182 };
183 
184 
185 
186 #endif // FPGATrackSimPLANEMAP_H
FPGATrackSimPlaneMap::m_nCoords
uint32_t m_nCoords
Definition: FPGATrackSimPlaneMap.h:149
FPGATrackSimPlaneMap::m_inValidLayerSection
const LayerSection m_inValidLayerSection
Definition: FPGATrackSimPlaneMap.h:174
FPGATrackSimPlaneMap::getNSections
uint32_t getNSections(size_t logiLayer) const
Definition: FPGATrackSimPlaneMap.h:77
FPGATrackSimPlaneMap::getNLogiLayers
uint32_t getNLogiLayers() const
Definition: FPGATrackSimPlaneMap.h:75
SiliconTech::strip
@ strip
python.FPGATrackSimAnalysisConfig.stage
stage
Definition: FPGATrackSimAnalysisConfig.py:558
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
FPGATrackSimPlaneMap::getLayerSection
const LayerSection & getLayerSection(LayerInfo const &mi) const
Definition: FPGATrackSimPlaneMap.h:129
FPGATrackSimPlaneMap::getLayer
int getLayer(SiliconTech siTech, DetectorZone zone, uint32_t physLayer) const
Definition: FPGATrackSimPlaneMap.h:132
LayerInfo::stereo
int stereo
Definition: FPGATrackSimPlaneMap.h:57
FPGATrackSimPlaneMap::m_nDetLayers
uint32_t m_nDetLayers
Definition: FPGATrackSimPlaneMap.h:148
FPGATrackSimPlaneMap::getNCoords
uint32_t getNCoords() const
Definition: FPGATrackSimPlaneMap.h:76
FPGATrackSimPlaneMap::isEC
bool isEC(uint32_t layer, uint32_t section) const
Definition: FPGATrackSimPlaneMap.h:108
FPGATrackSimPlaneMap::readLayers
void readLayers(std::ifstream &fin, uint32_t stage)
Definition: FPGATrackSimPlaneMap.cxx:150
FPGATrackSimPlaneMap::m_map
std::vector< std::vector< std::vector< LayerSection > > > m_map
Definition: FPGATrackSimPlaneMap.h:159
FPGATrackSimPlaneMap::getLayerSection
const LayerSection & getLayerSection(SiliconTech siTech, DetectorZone zone, uint32_t physLayer) const
Definition: FPGATrackSimPlaneMap.h:117
FPGATrackSimPlaneMap::getCoordLayer
uint32_t getCoordLayer(uint32_t coord) const
Definition: FPGATrackSimPlaneMap.h:98
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
FPGATrackSimPlaneMap::getDim
uint32_t getDim(size_t logiLayer) const
Definition: FPGATrackSimPlaneMap.h:78
LayerInfo::physDisk
int physDisk
Definition: FPGATrackSimPlaneMap.h:56
FPGATrackSimPlaneMap::getCoordOffset
uint32_t getCoordOffset(size_t logiLayer) const
Definition: FPGATrackSimPlaneMap.h:92
FPGATrackSimPlaneMap::isPixel
bool isPixel(int pl) const
Definition: FPGATrackSimPlaneMap.h:107
FPGATrackSimPlaneMap::m_layerOverrides
std::vector< int > m_layerOverrides
Definition: FPGATrackSimPlaneMap.h:164
FPGATrackSimPlaneMap::map
void map(FPGATrackSimHit &hit) const
Definition: FPGATrackSimPlaneMap.cxx:234
SiliconTech
SiliconTech
Definition: FPGATrackSimTypes.h:25
FPGATrackSimPlaneMap::getSection
unsigned getSection(SiliconTech siTech, DetectorZone zone, uint32_t physLayer) const
Definition: FPGATrackSimPlaneMap.h:135
FPGATrackSimPlaneMap::seek
void seek(std::ifstream &fin, unsigned region)
Definition: FPGATrackSimPlaneMap.cxx:130
FPGATrackSimPlaneMap::m_coordOffset
std::vector< uint32_t > m_coordOffset
Definition: FPGATrackSimPlaneMap.h:152
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
FPGATrackSimPlaneMap::getDetType
SiliconTech getDetType(size_t logiLayer) const
Definition: FPGATrackSimPlaneMap.h:79
FPGATrackSimModuleRelabel.h
FPGATrackSimPlaneMap::getLayerInfo
const LayerInfo & getLayerInfo(uint32_t layer, uint32_t section) const
Definition: FPGATrackSimPlaneMap.h:104
LayerSection
Definition: FPGATrackSimPlaneMap.h:40
FPGATrackSimPlaneMap
Definition: FPGATrackSimPlaneMap.h:62
python.draw_obj.zone
def zone(nx, ny)
Definition: draw_obj.py:288
FPGATrackSimPlaneMap::m_nLogiLayers
uint32_t m_nLogiLayers
Definition: FPGATrackSimPlaneMap.h:147
LayerInfo
Definition: FPGATrackSimPlaneMap.h:52
FPGATrackSimHit.h
: FPGATrackSim-specific class to represent an hit in the detector.
LayerSection::section
uint32_t section
Definition: FPGATrackSimPlaneMap.h:42
FPGATrackSimPlaneMap::isSCT
bool isSCT(int pl) const
Definition: FPGATrackSimPlaneMap.h:106
FPGATrackSimPlaneMap::m_moduleRelabel
std::unique_ptr< FPGATrackSimModuleRelabel > m_moduleRelabel
Definition: FPGATrackSimPlaneMap.h:171
FPGATrackSimPlaneMap::allocateMap
void allocateMap(std::ifstream &fin, uint32_t stage)
Definition: FPGATrackSimPlaneMap.cxx:53
JetVoronoiDiagramHelpers::coord
double coord
Definition: JetVoronoiDiagramHelpers.h:45
LayerInfo::zone
DetectorZone zone
Definition: FPGATrackSimPlaneMap.h:54
FPGATrackSimPlaneMap::layerName
std::string layerName(uint32_t layer, uint32_t section) const
Definition: FPGATrackSimPlaneMap.cxx:267
FPGATrackSimPlaneMap::FPGATrackSimPlaneMap
FPGATrackSimPlaneMap(std::ifstream &fin, unsigned region, unsigned stage, std::vector< int > layerOverrides=std::vector< int >())
Definition: FPGATrackSimPlaneMap.cxx:26
DetectorZone
DetectorZone
Definition: FPGATrackSimTypes.h:28
FPGATrackSimPlaneMap::getOverrideLayer
int getOverrideLayer(SiliconTech si, DetectorZone dz, int physLayer)
Definition: FPGATrackSimPlaneMap.cxx:259
LayerSection::layer
int layer
Definition: FPGATrackSimPlaneMap.h:41
LayerInfo::siTech
SiliconTech siTech
Definition: FPGATrackSimPlaneMap.h:53
FPGATrackSimPlaneMap::m_dimension
std::vector< uint32_t > m_dimension
Definition: FPGATrackSimPlaneMap.h:151
DetectorZone::barrel
@ barrel
FPGATrackSimPlaneMap::getNDetLayers
uint32_t getNDetLayers() const
Definition: FPGATrackSimPlaneMap.h:74
compute_lumi.fin
fin
Definition: compute_lumi.py:19
FPGATrackSimPlaneMap::m_layerInfo
std::vector< std::vector< LayerInfo > > m_layerInfo
Definition: FPGATrackSimPlaneMap.h:161
section
void section(const std::string &sec)
Definition: TestTriggerMenuAccess.cxx:22
LayerInfo::physLayer
int physLayer
Definition: FPGATrackSimPlaneMap.h:55
FPGATrackSimPlaneMap::m_diskIndex
std::vector< uint32_t > m_diskIndex
Definition: FPGATrackSimPlaneMap.h:168
FPGATrackSimPlaneMap::doRemap
void doRemap(FPGATrackSimHit &hit) const
Definition: FPGATrackSimPlaneMap.cxx:227
SiliconTech::undefined
@ undefined
SiliconTech::pixel
@ pixel
FPGATrackSimPlaneMap::m_coordLayer
std::vector< uint32_t > m_coordLayer
Definition: FPGATrackSimPlaneMap.h:156
DetectorZone::undefined
@ undefined