ATLAS Offline Software
FPGATrackSimPlaneMap.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 
15 #include <numeric>
16 #include <sstream>
17 #include <utility>
18 
19 using namespace asg::msgUserCode;
20 using namespace std;
21 
23 // Constructor/Desctructor
25 
26 FPGATrackSimPlaneMap::FPGATrackSimPlaneMap(std::ifstream& fin, unsigned region, unsigned stage, std::vector<int> layerOverrides) :
27  m_map(static_cast<int>(SiliconTech::nTechs),
28  vector<vector<LayerSection>>(static_cast<int>(DetectorZone::nZones))
29  ),
30  m_layerOverrides(std::move(layerOverrides))
31 {
32  // Reads the header of the file to resize all the vector members
34 
35  // Seek to the correct region
36  seek(fin, region);
37 
38  // Reads the rest of the file to populate all the member vectors
40 
41  // Postprocessing on coordinate indices
42  for (uint32_t l = 0; l < m_nLogiLayers; l++)
43  {
46  for (uint32_t i = 0; i < m_dimension[l]; i++)
47  m_coordLayer.push_back(l);
48  }
49 
50  ANA_MSG_DEBUG("Using " << m_nLogiLayers << " logical layers and " << m_nCoords << " coordinates");
51 }
52 // Reads the header of the file to resize all the vector members
54 {
55  // Initialize read variables
56  vector<int> layerCounts((int)SiliconTech::nTechs * static_cast<int>(DetectorZone::nZones)); // pixel_barrel, pixel_EC, SCT_barrel, SCT_EC
57  std::string line, silicon, detReg, layerKey, geoKey;
58  bool ok = true;
59  // Read Geometry Version
60  ok = ok && getline(fin, line);
61  while (line.empty() || line[0] == '!')
62  {
63  ok = ok && getline(fin, line);
64  }
66  istringstream sline(line);
67  ok = ok && (sline >> geoKey);
69 
70  ANA_MSG_DEBUG("Allocating map for geometry " << geoKey <<" diskIndex size="<<m_diskIndex.size());
71  m_moduleRelabel = std::make_unique<FPGATrackSimModuleRelabel>(geoKey, false);
72 
73 
74 
75  // Read number of logical layers
76  if (stage == 1)
77  {
78  ok = ok && getline(fin, line);
80  istringstream sline(line);
81  ok = ok && (sline >> m_nLogiLayers >> layerKey);
82  ok = ok && (layerKey == "logical_s1");
83  ok = ok && getline(fin, line); // skip the 2nd stage line
84  }
85  else if (stage == 2)
86  {
87  ok = ok && getline(fin, line); // skip the 1st stage line
88  ok = ok && getline(fin, line);
90  istringstream sline(line);
91  ok = ok && (sline >> m_nLogiLayers >> layerKey);
92  ok = ok && (layerKey == "logical_s2");
93  }
94  else ANA_MSG_ERROR("Bad stage " << stage << ". Stage should be 1 or 2");
95 
96  if (!m_layerOverrides.empty()) m_nLogiLayers = m_layerOverrides.size();
97 
98  // Read number of physical layers
99  int nHeaderLines = 6;
100  for (int i = 0; i < nHeaderLines; i++)
101  {
102  if (!ok) break;
103  ok = ok && getline(fin, line);
105 
106  istringstream sline(line);
107  ok = ok && (sline >> layerCounts[i] >> silicon >> detReg);
108 
109  ok = ok && ( (i < (nHeaderLines/2) && silicon == "pixel") || (i >= (nHeaderLines/2) && silicon == "SCT") );
110  ok = ok && ( (i % (nHeaderLines/2) == 0 && detReg == "barrel") || (i % (nHeaderLines/2) != 0 && (detReg == "endcap+" || detReg == "endcap-")) );
111  }
112 
113  if (!ok) ANA_MSG_FATAL("Error reading layer counts");
114  m_nDetLayers = std::accumulate(layerCounts.begin(), layerCounts.end(), 0);
115 
116  // Resize objects
117  m_map[(int)SiliconTech::pixel][(int)DetectorZone::barrel].resize(layerCounts[0]);
118  m_map[(int)SiliconTech::pixel][(int)DetectorZone::posEndcap].resize(layerCounts[1]);
119  m_map[(int)SiliconTech::pixel][(int)DetectorZone::negEndcap].resize(layerCounts[2]);
120  m_map[(int)SiliconTech::strip][(int)DetectorZone::barrel].resize(layerCounts[3]);
121  m_map[(int)SiliconTech::strip][(int)DetectorZone::posEndcap].resize(layerCounts[4]);
122  m_map[(int)SiliconTech::strip][(int)DetectorZone::negEndcap].resize(layerCounts[5]);
123 
124  m_dimension.resize(m_nLogiLayers);
125  m_layerInfo.resize(m_nLogiLayers);
127 }
128 
129 // Seeks to the selected region
130 void FPGATrackSimPlaneMap::seek(ifstream & fin, unsigned region)
131 {
132  std::string line, key;
133  unsigned region_read = -1;
134 
135  while (getline(fin, line))
136  {
137  if (line.empty() || line[0] == '!') continue;
139  istringstream sline(line);
140 
141  bool ok = static_cast<bool>(sline >> key >> region_read);
142  if (ok && key == "region" && region_read == region) break;
143  }
144 
145  ANA_MSG_DEBUG("seek() ended at:" << line);
146 }
147 
148 
149 // Reads the rest of the file to populate all the member vectors
151 {
152  // Initialize read variables
153  int BEC{}, physLayer{}, physDisk{}, logiLayer{}, logiLayer1{}, logiLayer2{}, stereo{}, nDim{};
154  string line, silicon, planeKey1, planeKey2, stereoKey;
155  bool ok = true;
156 
157  uint32_t linesRead = 0;
158 
159  // Each line is a detector layer
160  while (getline(fin, line))
161  {
162  if (line.empty() || line[0] == '!') continue;
164  istringstream sline(line);
165 
166  ok = ok && (sline >> silicon >> BEC >> physDisk >> physLayer);
167 
168  // Detector
170  if (BEC == 0) zone = DetectorZone::barrel;
171  else if (BEC == 1) zone = DetectorZone::posEndcap;
172  else if (BEC == 2) zone = DetectorZone::negEndcap;
173  else ANA_MSG_FATAL("Bad Detector zone" << BEC);
174 
175  // Case on silicon type
176  int sil = 0;
178  if (silicon == "pixel")
179  {
180  sil = static_cast<int>(SiliconTech::pixel);
181  nDim = 2;
182  stereo = -1;
183  ok = ok && (sline >> planeKey1 >> logiLayer1 >> planeKey2 >> logiLayer2);
184  ok = ok && (planeKey1 == "plane1" && planeKey2 == "plane2");
185  }
186  else if (silicon == "SCT")
187  {
188  sil = static_cast<int>(SiliconTech::strip);
189  siTech = SiliconTech::strip;
190 
191  nDim = 1;
192  ok = ok && (sline >> stereoKey >> stereo >> planeKey1 >> logiLayer1 >> planeKey2 >> logiLayer2);
193  ok = ok && (planeKey1 == "plane1" && planeKey2 == "plane2" && stereoKey == "stereo");
194  }
195  else ANA_MSG_FATAL("Bad silicon type " << silicon);
196 
197 
198  if (!ok) break;
199 
200  // Logical layer
201  if (!m_layerOverrides.empty()) logiLayer = getOverrideLayer(siTech, zone, physLayer);
202  else if (stage == 1) logiLayer = logiLayer1;
203  else if (stage == 2) logiLayer = logiLayer2;
204 
205  // Check number of layers
206  linesRead++;
207  if (logiLayer >= (int)m_nLogiLayers) ANA_MSG_FATAL("Logical layer " << logiLayer << " exceeds expected number " << m_nLogiLayers);
208 
209  // Store to map
210  m_map.at(sil).at(BEC).at(physLayer).layer = logiLayer;
211  if (logiLayer >= 0)
212  {
213  m_dimension[logiLayer] = nDim;
214  m_map[sil][BEC][physLayer].section = m_layerInfo[logiLayer].size(); // i.e. index into m_layerInfo[logiLayer] entry below
215  m_layerInfo[logiLayer].push_back({ siTech, zone, physLayer, physDisk, stereo});
216  }
217  if (m_nDetLayers == linesRead) break;
218  }
219 
220  if (!ok) ANA_MSG_FATAL("Error reading file");
221 }
222 
223 
225 // Interface Functions
228 {
229  if (!hit.isRemapped()) {
230  m_moduleRelabel->remap(hit);
231  }
232 }
233 
235 {
236  // re-assign layers in the pixel endcap to be each individual disk
237  // technically this returns a success/fail but I'm not sure we need it?
238  // This should only happen if the hit is not already mapped.
239  const LayerSection &pinfo = getLayerSection(hit.getDetType(), hit.getDetectorZone(), hit.getPhysLayer());
240  hit.setSection(pinfo.section);
241  hit.setLayer(pinfo.layer);
242  if (!hit.isMapped()) // failsafe if for some reason someone calls this on a clustered hit again, or something
244 
245  // Special case if this is a spacepoint (now possible because slicing engine happens after SP formation).
246  if (hit.getHitType() == HitType::spacepoint) {
248  hit.setPairedSection(pinfo_sp.section);
249  hit.setPairedLayer(pinfo_sp.layer);
250  }
251 }
252 
253 
255 // Helper Functions
257 
258 // Gets the logical layer number based on the override list
259 int FPGATrackSimPlaneMap::getOverrideLayer(SiliconTech si, DetectorZone dz, int physLayer) // TODO does dz need edit for negEndcap?
260 {
261  int code = static_cast<int>(si) * 1000 + static_cast<int>(dz) * 100 + physLayer;
262  for (unsigned i = 0; i < m_layerOverrides.size(); i++)
263  if (code == m_layerOverrides[i]) return i;
264  return -1;
265 }
266 
268 {
269  std::string out;
270  out += (isPixel(layer) ? "PIX" : "SCT");
271  out += (isEC(layer, section) ? "_EC_" : "_B_");
272  out += std::to_string(getLayerInfo(layer, section).physLayer);
273  return out;
274 }
FPGATrackSimPlaneMap::m_nCoords
uint32_t m_nCoords
Definition: FPGATrackSimPlaneMap.h:149
FPGATrackSimHit::setSection
void setSection(unsigned v)
Definition: FPGATrackSimHit.h:93
Remappings::diskIndices
std::vector< uint32_t > diskIndices(const std::string &geoKey)
for a given geo tag return disk indices remappings the format is this: 'GeometryVersion':'ATLAS-P2-RU...
Definition: Remappings.cxx:16
checkFileSG.line
line
Definition: checkFileSG.py:75
LArNewCalib_Delay_OFC_Cali.BEC
BEC
Definition: LArNewCalib_Delay_OFC_Cali.py:119
SiliconTech::strip
@ strip
FPGATrackSimHit::getPhysLayer
unsigned getPhysLayer() const
Definition: FPGATrackSimHit.cxx:69
python.FPGATrackSimAnalysisConfig.stage
stage
Definition: FPGATrackSimAnalysisConfig.py:559
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
FPGATrackSimPlaneMap.h
Maps physical layers to logical layers.
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
DetectorZone::posEndcap
@ posEndcap
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
FPGATrackSimHit::getPairedDetType
SiliconTech getPairedDetType() const
Definition: FPGATrackSimHit.h:127
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
FPGATrackSimPlaneMap::m_nDetLayers
uint32_t m_nDetLayers
Definition: FPGATrackSimPlaneMap.h:148
DetectorZone::nZones
@ nZones
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
HitType::spacepoint
@ spacepoint
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
FPGATrackSimHit
Definition: FPGATrackSimHit.h:41
FPGATrackSimHit::isRemapped
bool isRemapped() const
Definition: FPGATrackSimHit.cxx:20
FPGATrackSimPlaneMap::isPixel
bool isPixel(int pl) const
Definition: FPGATrackSimPlaneMap.h:107
histSizes.code
code
Definition: histSizes.py:129
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
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
MessageCheck.h
macros for messaging and checking status codes
SiliconTech::nTechs
@ nTechs
FPGATrackSimPlaneMap::getLayerInfo
const LayerInfo & getLayerInfo(uint32_t layer, uint32_t section) const
Definition: FPGATrackSimPlaneMap.h:104
FPGATrackSimHit::getPairedPhysLayer
unsigned getPairedPhysLayer() const
Definition: FPGATrackSimHit.h:125
LayerSection
Definition: FPGATrackSimPlaneMap.h:40
ANA_MSG_FATAL
#define ANA_MSG_FATAL(xmsg)
Macro printing fatal messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:296
FPGATrackSimHit::setPairedSection
void setPairedSection(unsigned v)
Definition: FPGATrackSimHit.h:131
FPGATrackSimHit::getDetectorZone
DetectorZone getDetectorZone() const
Definition: FPGATrackSimHit.h:59
Remappings.h
python.draw_obj.zone
def zone(nx, ny)
Definition: draw_obj.py:288
ANA_MSG_VERBOSE
#define ANA_MSG_VERBOSE(xmsg)
Macro printing verbose messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:286
FPGATrackSimPlaneMap::m_nLogiLayers
uint32_t m_nLogiLayers
Definition: FPGATrackSimPlaneMap.h:147
FPGATrackSimHit::setPairedLayer
void setPairedLayer(unsigned v)
Definition: FPGATrackSimHit.h:130
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
LayerSection::section
uint32_t section
Definition: FPGATrackSimPlaneMap.h:42
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
FPGATrackSimHit::getPairedDetZone
DetectorZone getPairedDetZone() const
Definition: FPGATrackSimHit.h:126
HitType::mapped
@ mapped
DetectorZone::negEndcap
@ negEndcap
FPGATrackSimHit::isMapped
bool isMapped() const
Definition: FPGATrackSimHit.cxx:13
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
FPGATrackSimHit::setLayer
void setLayer(unsigned v)
Definition: FPGATrackSimHit.h:92
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
FPGATrackSimPlaneMap::m_dimension
std::vector< uint32_t > m_dimension
Definition: FPGATrackSimPlaneMap.h:151
FPGATrackSimHit::getDetType
SiliconTech getDetType() const
Definition: FPGATrackSimHit.h:58
DetectorZone::barrel
@ barrel
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
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::pixel
@ pixel
FPGATrackSimPlaneMap::m_coordLayer
std::vector< uint32_t > m_coordLayer
Definition: FPGATrackSimPlaneMap.h:156
FPGATrackSimHit::getHitType
HitType getHitType() const
Definition: FPGATrackSimHit.h:57
FPGATrackSimHit::setHitType
void setHitType(HitType type)
Definition: FPGATrackSimHit.h:54
DetectorZone::undefined
@ undefined
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288