ATLAS Offline Software
FPGATrackSimMappingSvc.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
6 
7 FPGATrackSimMappingSvc::FPGATrackSimMappingSvc(const std::string& name, ISvcLocator*svc) :
8  base_class(name, svc)
9 {
10 }
11 
12 
14 {
15  if (m_pmap_path.value().empty())
16  ATH_MSG_FATAL("Main plane map definition missing");
17  else if (m_rmap_path.value().empty())
18  ATH_MSG_FATAL("Missing region map path");
19  else if (m_modulelut_path.value().empty())
20  ATH_MSG_FATAL("Module LUT file is missing");
21  else
22  return StatusCode::SUCCESS;
23 
24  return StatusCode::FAILURE;
25 }
26 
27 
29 {
30  if (m_pmap_vector_1st.empty())
31  {
32  ATH_MSG_FATAL("Error using 1st stage plane map no elements of vector made: " << m_pmap_vector_1st);
33  return StatusCode::FAILURE;
34  }
35  if (!m_numberOfPmaps){
36  ATH_MSG_FATAL("Error with declared number of plane maps: " << m_pmap_path);
37  return StatusCode::FAILURE;
38  }
39  if (m_numberOfPmaps != (m_pmap_vector_1st.size())){
40  ATH_MSG_FATAL("Error using number of declared plane maps does not equal number of loaded plane maps: " << m_pmap_path<<"=/="<<m_pmap_vector_1st.size());
41  return StatusCode::FAILURE;
42  }
43  for (size_t a = 0 ; a < m_pmap_vector_1st.size() ;a++)
44  {
45  if(!m_pmap_vector_1st.at(a)){
46  ATH_MSG_FATAL("Error using 1st stage plane map for slice: " << a <<" of "<< m_pmap_vector_1st.size());
47  return StatusCode::FAILURE;
48  }
49  }
50  if (m_pmap_vector_2nd.empty())
51  {
52  ATH_MSG_FATAL("Error using 2nd stage plane map no elements of vector made: " << m_pmap_vector_2nd);
53  return StatusCode::FAILURE;
54  }
55  if (!m_numberOfPmaps){
56  ATH_MSG_FATAL("Error with declared number of plane maps: " << m_pmap_path);
57  return StatusCode::FAILURE;
58  }
59  if (m_numberOfPmaps != (m_pmap_vector_2nd.size())){
60  ATH_MSG_FATAL("Error using number of declared plane maps does not equal number of loaded plane maps: " << m_pmap_path<<"=/="<<m_pmap_vector_2nd.size());
61  return StatusCode::FAILURE;
62  }
63  for (size_t a = 0 ; a < m_pmap_vector_2nd.size() ;a++)
64  {
65  if(!m_pmap_vector_2nd.at(a)){
66  ATH_MSG_FATAL("Error using 1st stage plane map for slice: " << a <<" of "<< m_pmap_vector_2nd.size());
67  return StatusCode::FAILURE;
68  }
69  }
70  if (!m_rmap_1st){
71  ATH_MSG_FATAL("Error creating region map for 1st stage from: " << m_rmap_path);
72  return StatusCode::FAILURE;
73  }
74  if (!m_rmap_2nd){
75  ATH_MSG_FATAL("Error creating region map for 2nd stage from: " << m_rmap_path);
76  return StatusCode::FAILURE;
77  }
78  if (!m_subrmap){
79  ATH_MSG_FATAL("Error creating sub-region map from: " << m_subrmap_path);
80  return StatusCode::FAILURE;
81  }
82  if (!m_subrmap_2nd){
83  ATH_MSG_FATAL("Error creating second stage sub-region map from: " << m_subrmap_path);
84  return StatusCode::FAILURE;
85  }
86  return StatusCode::SUCCESS;
87 }
88 
89 
91  if (m_NNmap_fake != nullptr) {
92  return m_NNmap_fake->getNNMap();
93  }
94  else{
95  return "";
96  }
97 }
98 
99 
101  if (m_NNmap2nd_fake != nullptr) {
102  return m_NNmap2nd_fake->getNNMap();
103  }
104  else{
105  return "";
106  }
107 }
108 
109 
111  if (m_NNmap_extension_vol != nullptr) {
112  return m_NNmap_extension_vol->getNNMap();
113  }
114  else{
115  return "";
116  }
117 }
118 
120  if (m_NNmap_extension_hit != nullptr) {
121  return m_NNmap_extension_hit->getNNMap();
122  }
123  else{
124  return "";
125  }
126 }
127 
128 
130  if (m_NNmap_param != nullptr) {
131  return m_NNmap_param->getNNMap();
132  }
133  else{
134  return "";
135  }
136 }
137 
139  if (m_NNmap2nd_param != nullptr) {
140  return m_NNmap2nd_param->getNNMap();
141  }
142  else{
143  return "";
144  }
145 }
146 
147 
148 
149 int FPGATrackSimMappingSvc::countPmapSize(std::ifstream& fileIn)
150 {
151  std::string line;
152 
153  getline(fileIn, line);
154  std::istringstream sline(line);
155  std::string geoKeyCheck;
156  sline >> geoKeyCheck;
157  m_numberOfPmaps = 1;
158  while (getline(fileIn,line)){
159  std::istringstream sline(line);
160  std::string geoKeyCandidate;
161  sline >> geoKeyCandidate;
162  if(geoKeyCheck.compare(geoKeyCandidate)==0){
163  m_numberOfPmaps++;
164  }
165  }
166  return m_numberOfPmaps;
167 }
169 {
171 
172  if (m_mappingType.value() == "FILE")
173  {
174  const std::string & filepath = PathResolverFindCalibFile(m_pmap_path.value());
175  std::ifstream fin(filepath);
176  if (!fin.is_open())
177  {
178  ATH_MSG_DEBUG("Couldn't open " << filepath);
179  throw ("FPGATrackSimPlaneMap Couldn't open " + filepath);
180  }
181 
183  fin.close();
184  fin.open(filepath);
185  ATH_MSG_DEBUG("Creating the 1st stage plane map");
186  for (size_t i = 0; i<m_numberOfPmaps; i++)
187  {
188  m_pmap_vector_1st.emplace_back(std::make_unique<FPGATrackSimPlaneMap>(fin, m_regionID, 1, m_layerOverrides));
189  }
190 
191  fin.close();
192  fin.open(filepath);
193  ATH_MSG_DEBUG("Creating the 2nd stage plane map");
194  for (size_t i = 0; i<m_numberOfPmaps; i++)
195  {
196  m_pmap_vector_2nd.emplace_back(std::make_unique<FPGATrackSimPlaneMap>(fin, m_regionID, 2, m_layerOverrides));
197  }
198  fin.close();
199 
200  ATH_MSG_DEBUG("Creating the 1st stage region map: " << PathResolverFindCalibFile(m_rmap_path.value()));
201  m_rmap_1st = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_1st, PathResolverFindCalibFile(m_rmap_path.value())));
202 
203  ATH_MSG_DEBUG("Creating the 2nd stage region map: " << PathResolverFindCalibFile(m_rmap_path.value()));
204  m_rmap_2nd = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_2nd, PathResolverFindCalibFile(m_rmap_path.value())));
205 
206  ATH_MSG_DEBUG("Creating the sub-region map: " << PathResolverFindCalibFile(m_subrmap_path.value()));
207  m_subrmap = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_1st, PathResolverFindCalibFile(m_subrmap_path.value())));
208 
209  ATH_MSG_DEBUG("Creating the 2nd stage sub-region map:" << PathResolverFindCalibFile(m_subrmap_path.value()));
210  m_subrmap_2nd = std::make_unique<FPGATrackSimRegionMap>(m_pmap_vector_2nd, PathResolverFindCalibFile(m_subrmap_path.value()));
211 
212  ATH_MSG_DEBUG("Setting the Modules LUT for Region Maps");
213  ATH_MSG_DEBUG("Loading the Module LUT from " << PathResolverFindCalibFile(m_modulelut_path.value()));
214  m_rmap_1st->loadModuleIDLUT(PathResolverFindCalibFile(m_modulelut_path.value()));
215  m_rmap_2nd->loadModuleIDLUT(PathResolverFindCalibFile(m_modulelut_path.value()));
216 
217  if (m_loadRadii) {
218  ATH_MSG_DEBUG("Setting the average radius per logical layer for Region and Subregion Maps");
219  ATH_MSG_DEBUG("Loading Radii from " << PathResolverFindCalibFile(m_radii_path.value()));
220  m_rmap_1st->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()), 0, m_pmap_vector_1st.at(0)->getNLogiLayers());
221  m_rmap_2nd->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()), 0, m_pmap_vector_1st.at(0)->getNLogiLayers());
222  m_rmap_2nd->loadRadiiFile(PathResolverFindCalibFile(m_radii2nd_path.value()), m_pmap_vector_1st.at(0)->getNLogiLayers(), m_pmap_vector_2nd.at(0)->getNLogiLayers());
223 
224  m_subrmap->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()), 0, m_pmap_vector_1st.at(0)->getNLogiLayers());
225  m_subrmap_2nd->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()), 0, m_pmap_vector_1st.at(0)->getNLogiLayers());
226  m_subrmap_2nd->loadRadiiFile(PathResolverFindCalibFile(m_radii2nd_path.value()), m_pmap_vector_1st.at(0)->getNLogiLayers(), m_pmap_vector_2nd.at(0)->getNLogiLayers());
227  }
228 
229  ATH_MSG_DEBUG("Creating NN weighting map");
230  ATH_MSG_INFO("MappingSVc using " << m_NNmap_path_fake.value() << " for fake track estimation");
231  ATH_MSG_INFO("MappingSVc using " << m_NNmap_path_param.value() << " for track parameter estimation");
232  ATH_MSG_INFO("MappingSVc using " << m_NNmap2nd_path_fake.value() << " for 2nd stage fake track estimation");
233  ATH_MSG_INFO("MappingSVc using " << m_NNmap2nd_path_param.value() << " for 2nd stage track parameter estimation");
234  ATH_MSG_INFO("MappingSVc using " << m_NNmap_path_extension_vol.value() << " for track extension");
235  ATH_MSG_INFO("MappingSVc using " << m_NNmap_path_extension_hit.value() << " for track extension");
236 
237 
238 
239  if ( ! m_NNmap_path_extension_vol.empty() ) {
240  std::string model_path = m_NNmap_path_extension_vol.value() + "_" + std::to_string(m_regionID) + "_cyl_condor.onnx";
241  m_NNmap_extension_vol = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
242  } else {
243  m_NNmap_extension_vol = nullptr;
244  }
245 
246  if ( ! m_NNmap_path_extension_hit.empty() ) {
247  std::string model_path = m_NNmap_path_extension_hit.value() + "_" + std::to_string(m_regionID) + "_cyl_condor.onnx";
248  m_NNmap_extension_hit = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
249  } else {
250  m_NNmap_extension_hit = nullptr;
251 
252  }
253 
254  if ( ! m_NNmap_path_fake.empty() ) {
255  std::string model_path = m_NNmap_path_fake.value() + "_" + std::to_string(m_regionID) + "_condor.onnx";
256  m_NNmap_fake = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
257  } else {
258  m_NNmap_fake = nullptr;
259  }
260 
261  if ( ! m_NNmap2nd_path_fake.empty() ) {
262  std::string model_path = m_NNmap2nd_path_fake.value() + "_" + std::to_string(m_regionID) + "_condor.onnx";
263  m_NNmap2nd_fake = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
264  } else {
265  m_NNmap2nd_fake = nullptr;
266  }
267 
268  if ( ! m_NNmap_path_param.empty() ) {
269  std::string model_path;
270  if(m_regionID <= 354) model_path = m_NNmap_path_param.value() + "_34_354.onnx";
271  else if (m_regionID <= 738) model_path = m_NNmap_path_param.value() + "_418_738.onnx";
272  else model_path = m_NNmap_path_param.value() + "_802_1250.onnx";
273  m_NNmap_param = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
274  }
275 
276  if ( ! m_NNmap2nd_path_param.empty() ) {
277  std::string model_path = m_NNmap2nd_path_param.value() + "_" + std::to_string(m_regionID) + "_condor.onnx";
278  m_NNmap2nd_param = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
279  }
280  }
282  return StatusCode::SUCCESS;
283 }
284 
285 
FPGATrackSimMappingSvc::m_NNmap_path_fake
Gaudi::Property< std::string > m_NNmap_path_fake
Definition: FPGATrackSimMappingSvc.h:51
FPGATrackSimMappingSvc::m_rmap_2nd
std::unique_ptr< FPGATrackSimRegionMap > m_rmap_2nd
Definition: FPGATrackSimMappingSvc.h:69
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
FPGATrackSimMappingSvc::FPGATrackSimMappingSvc
FPGATrackSimMappingSvc(const std::string &name, ISvcLocator *svc)
Definition: FPGATrackSimMappingSvc.cxx:7
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FPGATrackSimMappingSvc::m_NNmap_path_extension_hit
Gaudi::Property< std::string > m_NNmap_path_extension_hit
Definition: FPGATrackSimMappingSvc.h:54
FPGATrackSimMappingSvc::m_NNmap_fake
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_fake
Definition: FPGATrackSimMappingSvc.h:72
FPGATrackSimMappingSvc::m_numberOfPmaps
size_t m_numberOfPmaps
Definition: FPGATrackSimMappingSvc.h:79
FPGATrackSimMappingSvc::m_radii_path
Gaudi::Property< std::string > m_radii_path
Definition: FPGATrackSimMappingSvc.h:57
FPGATrackSimMappingSvc::checkAllocs
StatusCode checkAllocs()
Definition: FPGATrackSimMappingSvc.cxx:28
FPGATrackSimMappingSvc::m_rmap_1st
std::unique_ptr< FPGATrackSimRegionMap > m_rmap_1st
Definition: FPGATrackSimMappingSvc.h:68
dq_defect_bulk_create_defects.line
line
Definition: dq_defect_bulk_create_defects.py:27
FPGATrackSimMappingSvc::getFakeNNMap2ndString
virtual std::string getFakeNNMap2ndString() const override
Definition: FPGATrackSimMappingSvc.cxx:100
FPGATrackSimMappingSvc::m_NNmap2nd_path_fake
Gaudi::Property< std::string > m_NNmap2nd_path_fake
Definition: FPGATrackSimMappingSvc.h:52
FPGATrackSimMappingSvc::m_NNmap_path_extension_vol
Gaudi::Property< std::string > m_NNmap_path_extension_vol
Definition: FPGATrackSimMappingSvc.h:53
FPGATrackSimMappingSvc::getParamNNMapString
virtual std::string getParamNNMapString() const override
Definition: FPGATrackSimMappingSvc.cxx:129
FPGATrackSimMappingSvc::m_layerOverrides
Gaudi::Property< std::vector< int > > m_layerOverrides
Definition: FPGATrackSimMappingSvc.h:59
FPGATrackSimMappingSvc::m_subrmap_2nd
std::unique_ptr< FPGATrackSimRegionMap > m_subrmap_2nd
Definition: FPGATrackSimMappingSvc.h:71
FPGATrackSimMappingSvc::m_NNmap2nd_param
std::unique_ptr< FPGATrackSimNNMap > m_NNmap2nd_param
Definition: FPGATrackSimMappingSvc.h:75
FPGATrackSimMappingSvc::getFakeNNMapString
virtual std::string getFakeNNMapString() const override
Definition: FPGATrackSimMappingSvc.cxx:90
lumiFormat.i
int i
Definition: lumiFormat.py:85
FPGATrackSimMappingSvc::m_pmap_path
Gaudi::Property< std::string > m_pmap_path
Definition: FPGATrackSimMappingSvc.h:49
FPGATrackSimMappingSvc::m_NNmap_extension_hit
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_extension_hit
Definition: FPGATrackSimMappingSvc.h:77
FPGATrackSimMappingSvc::m_modulelut_path
Gaudi::Property< std::string > m_modulelut_path
Definition: FPGATrackSimMappingSvc.h:50
FPGATrackSimMappingSvc::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimMappingSvc.cxx:168
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FPGATrackSimMappingSvc::getExtensionNNHitMapString
virtual std::string getExtensionNNHitMapString() const override
Definition: FPGATrackSimMappingSvc.cxx:119
FPGATrackSimMappingSvc::m_NNmap_path_param
Gaudi::Property< std::string > m_NNmap_path_param
Definition: FPGATrackSimMappingSvc.h:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FPGATrackSimMappingSvc::m_NNmap2nd_fake
std::unique_ptr< FPGATrackSimNNMap > m_NNmap2nd_fake
Definition: FPGATrackSimMappingSvc.h:74
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
FPGATrackSimMappingSvc::m_pmap_vector_1st
std::vector< std::unique_ptr< FPGATrackSimPlaneMap > > m_pmap_vector_1st
Definition: FPGATrackSimMappingSvc.h:64
PathResolver.h
FPGATrackSimMappingSvc::m_rmap_path
Gaudi::Property< std::string > m_rmap_path
Definition: FPGATrackSimMappingSvc.h:47
FPGATrackSimMappingSvc::m_regionID
Gaudi::Property< unsigned int > m_regionID
Definition: FPGATrackSimMappingSvc.h:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
FPGATrackSimMappingSvc::getExtensionNNVolMapString
virtual std::string getExtensionNNVolMapString() const override
Definition: FPGATrackSimMappingSvc.cxx:110
FPGATrackSimMappingSvc::m_pmap_vector_2nd
std::vector< std::unique_ptr< FPGATrackSimPlaneMap > > m_pmap_vector_2nd
Definition: FPGATrackSimMappingSvc.h:65
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:283
FPGATrackSimMappingSvc::m_mappingType
Gaudi::Property< std::string > m_mappingType
Definition: FPGATrackSimMappingSvc.h:46
FPGATrackSimMappingSvc::m_subrmap_path
Gaudi::Property< std::string > m_subrmap_path
Definition: FPGATrackSimMappingSvc.h:48
a
TList * a
Definition: liststreamerinfos.cxx:10
FPGATrackSimMappingSvc::m_NNmap_extension_vol
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_extension_vol
Definition: FPGATrackSimMappingSvc.h:76
IFPGATrackSimEventSelectionSvc.h
FPGATrackSimMappingSvc::m_subrmap
std::unique_ptr< FPGATrackSimRegionMap > m_subrmap
Definition: FPGATrackSimMappingSvc.h:70
FPGATrackSimMappingSvc::m_NNmap2nd_path_param
Gaudi::Property< std::string > m_NNmap2nd_path_param
Definition: FPGATrackSimMappingSvc.h:56
FPGATrackSimMappingSvc::checkInputs
StatusCode checkInputs()
Definition: FPGATrackSimMappingSvc.cxx:13
FPGATrackSimMappingSvc::m_radii2nd_path
Gaudi::Property< std::string > m_radii2nd_path
Definition: FPGATrackSimMappingSvc.h:58
compute_lumi.fin
fin
Definition: compute_lumi.py:19
FPGATrackSimRegionMap
Definition: FPGATrackSimRegionMap.h:62
FPGATrackSimMappingSvc::m_loadRadii
Gaudi::Property< bool > m_loadRadii
Definition: FPGATrackSimMappingSvc.h:60
FPGATrackSimMappingSvc.h
FPGATrackSimMappingSvc::m_NNmap_param
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_param
Definition: FPGATrackSimMappingSvc.h:73
FPGATrackSimMappingSvc::getParamNNMap2ndString
virtual std::string getParamNNMap2ndString() const override
Definition: FPGATrackSimMappingSvc.cxx:138
FPGATrackSimMappingSvc::countPmapSize
int countPmapSize(std::ifstream &fileIn)
Definition: FPGATrackSimMappingSvc.cxx:149