ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimMappingSvc.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
6
7FPGATrackSimMappingSvc::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
148 if (m_GNNmap_moduleMap != nullptr) {
149 return m_GNNmap_moduleMap->getNNMap();
150 }
151 else{
152 return "";
153 }
154}
155
157{
158 std::string line;
159
160 getline(fileIn, line);
161 std::istringstream sline(line);
162 std::string geoKeyCheck;
163 sline >> geoKeyCheck;
164 m_numberOfPmaps = 1;
165 while (getline(fileIn,line)){
166 std::istringstream sline(line);
167 std::string geoKeyCandidate;
168 sline >> geoKeyCandidate;
169 if(geoKeyCheck.compare(geoKeyCandidate)==0){
171 }
172 }
173 return m_numberOfPmaps;
174}
176{
178
179 if (m_mappingType.value() == "FILE")
180 {
181 const std::string & filepath = PathResolverFindCalibFile(m_pmap_path.value());
182 std::ifstream fin(filepath);
183 if (!fin.is_open())
184 {
185 ATH_MSG_DEBUG("Couldn't open " << filepath);
186 throw ("FPGATrackSimPlaneMap Couldn't open " + filepath);
187 }
188
189 countPmapSize(fin);
190 fin.close();
191 fin.open(filepath);
192 ATH_MSG_DEBUG("Creating the 1st stage plane map");
193 for (size_t i = 0; i<m_numberOfPmaps; i++)
194 {
195 m_pmap_vector_1st.emplace_back(std::make_unique<FPGATrackSimPlaneMap>(fin, m_regionID, 1, m_layerOverrides));
196 }
197
198 fin.close();
199 fin.open(filepath);
200 ATH_MSG_DEBUG("Creating the 2nd stage plane map");
201 for (size_t i = 0; i<m_numberOfPmaps; i++)
202 {
203 m_pmap_vector_2nd.emplace_back(std::make_unique<FPGATrackSimPlaneMap>(fin, m_regionID, 2, m_layerOverrides));
204 }
205 fin.close();
206
207 ATH_MSG_DEBUG("Creating the 1st stage region map: " << PathResolverFindCalibFile(m_rmap_path.value()));
208 m_rmap_1st = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_1st, PathResolverFindCalibFile(m_rmap_path.value()), !(m_loadRegionMap.value())));
209
210 ATH_MSG_DEBUG("Creating the 2nd stage region map: " << PathResolverFindCalibFile(m_rmap_path.value()));
211 m_rmap_2nd = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_2nd, PathResolverFindCalibFile(m_rmap_path.value()), !(m_loadRegionMap.value())));
212
213 ATH_MSG_DEBUG("Creating the sub-region map: " << PathResolverFindCalibFile(m_subrmap_path.value()));
214 m_subrmap = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_1st, PathResolverFindCalibFile(m_subrmap_path.value()), !(m_loadRegionMap.value())));
215
216 ATH_MSG_DEBUG("Creating the 2nd stage sub-region map:" << PathResolverFindCalibFile(m_subrmap_path.value()));
217 m_subrmap_2nd = std::unique_ptr<FPGATrackSimRegionMap>(new FPGATrackSimRegionMap(m_pmap_vector_2nd, PathResolverFindCalibFile(m_subrmap_path.value()), !(m_loadRegionMap.value())));
218
219 ATH_MSG_DEBUG("Setting the Modules LUT for Region Maps");
220 ATH_MSG_DEBUG("Loading the Module LUT from " << PathResolverFindCalibFile(m_modulelut_path.value()));
221 m_rmap_1st->loadModuleIDLUT(PathResolverFindCalibFile(m_modulelut_path.value()));
222 m_rmap_2nd->loadModuleIDLUT(PathResolverFindCalibFile(m_modulelut_path.value()));
223
224 if (m_loadRadii) {
225 ATH_MSG_DEBUG("Setting the average radius per logical layer for Region and Subregion Maps");
226 ATH_MSG_DEBUG("Loading Radii from " << PathResolverFindCalibFile(m_radii_path.value()));
227 m_rmap_1st->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()), 0, m_pmap_vector_1st.at(0)->getNLogiLayers());
228 m_rmap_2nd->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()), 0, m_pmap_vector_1st.at(0)->getNLogiLayers());
229 m_rmap_2nd->loadRadiiFile(PathResolverFindCalibFile(m_radii2nd_path.value()), m_pmap_vector_1st.at(0)->getNLogiLayers(), m_pmap_vector_2nd.at(0)->getNLogiLayers());
230
231 m_subrmap->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()), 0, m_pmap_vector_1st.at(0)->getNLogiLayers());
232 m_subrmap_2nd->loadRadiiFile(PathResolverFindCalibFile(m_radii_path.value()), 0, m_pmap_vector_1st.at(0)->getNLogiLayers());
233 m_subrmap_2nd->loadRadiiFile(PathResolverFindCalibFile(m_radii2nd_path.value()), m_pmap_vector_1st.at(0)->getNLogiLayers(), m_pmap_vector_2nd.at(0)->getNLogiLayers());
234 }
235
236 ATH_MSG_DEBUG("Creating NN weighting map");
237 ATH_MSG_INFO("MappingSVc using " << m_NNmap_path_fake.value() << " for fake track estimation");
238 ATH_MSG_INFO("MappingSVc using " << m_NNmap_path_param.value() << " for track parameter estimation");
239 ATH_MSG_INFO("MappingSVc using " << m_NNmap2nd_path_fake.value() << " for 2nd stage fake track estimation");
240 ATH_MSG_INFO("MappingSVc using " << m_NNmap2nd_path_param.value() << " for 2nd stage track parameter estimation");
241 ATH_MSG_INFO("MappingSVc using " << m_NNmap_path_extension_vol.value() << " for track extension");
242 ATH_MSG_INFO("MappingSVc using " << m_NNmap_path_extension_hit.value() << " for track extension");
243
244 if ( ! m_NNmap_path_extension_vol.empty() ) {
245 std::string model_path = m_NNmap_path_extension_vol.value() + "_" + std::to_string(m_regionID) + "_cyl_condor.onnx";
246 m_NNmap_extension_vol = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
247 } else {
248 m_NNmap_extension_vol = nullptr;
249 }
250
251 if ( ! m_NNmap_path_extension_hit.empty() ) {
252 std::string model_path = m_NNmap_path_extension_hit.value() + "_" + std::to_string(m_regionID) + "_cyl_condor.onnx";
253 m_NNmap_extension_hit = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
254 } else {
255 m_NNmap_extension_hit = nullptr;
256
257 }
258
259 if ( ! m_NNmap_path_fake.empty() ) {
260 std::string model_path = m_NNmap_path_fake.value() + "_" + std::to_string(m_regionID) + "_condor.onnx";
261 m_NNmap_fake = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
262 } else {
263 m_NNmap_fake = nullptr;
264 }
265
266 if ( ! m_NNmap2nd_path_fake.empty() ) {
267 std::string model_path = m_NNmap2nd_path_fake.value() + "_" + std::to_string(m_regionID) + "_condor.onnx";
268 m_NNmap2nd_fake = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
269 } else {
270 m_NNmap2nd_fake = nullptr;
271 }
272
273 if (m_doGNNTrack) { // For GNN algorithms to use second stage models in first stage
274 if ( ! m_NNmap_path_param.empty() ) {
275 std::string model_path = m_NNmap_path_param.value() + "_" + std::to_string(m_regionID) + "_condor.onnx";
276 m_NNmap_param = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
277 } else {
278 m_NNmap_param = nullptr;
279 }
280 }
281 else { // For GenScan/InsideOut algorithms to use first stage models
282 if ( ! m_NNmap_path_param.empty() ) {
283 std::string model_path;
284 if(m_regionID <= 354) model_path = m_NNmap_path_param.value() + "_34_354.onnx";
285 else if (m_regionID <= 738) model_path = m_NNmap_path_param.value() + "_418_738.onnx";
286 else model_path = m_NNmap_path_param.value() + "_802_1250.onnx";
287 m_NNmap_param = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
288 } else {
289 m_NNmap_param = nullptr;
290 }
291 }
292
293 if ( ! m_NNmap2nd_path_param.empty() ) {
294 std::string model_path = m_NNmap2nd_path_param.value() + "_" + std::to_string(m_regionID) + "_condor.onnx";
295 m_NNmap_param = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
296 } else {
297 m_NNmap_param = nullptr;
298 }
299
300 if ( ! m_GNNmap_path_moduleMap.empty() ) {
301 std::string model_path = m_GNNmap_path_moduleMap.value()+ "_" + std::to_string(m_regionID) + ".root";
302 m_GNNmap_moduleMap = std::make_unique<FPGATrackSimNNMap>(PathResolverFindCalibFile(model_path));
303 } else {
304 m_GNNmap_moduleMap = nullptr;
305 }
306 }
308 return StatusCode::SUCCESS;
309}
310
311
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
static Double_t a
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
std::vector< std::unique_ptr< FPGATrackSimPlaneMap > > m_pmap_vector_1st
Gaudi::Property< bool > m_loadRegionMap
std::unique_ptr< FPGATrackSimNNMap > m_NNmap2nd_param
virtual std::string getExtensionNNVolMapString() const override
Gaudi::Property< std::string > m_NNmap_path_fake
std::unique_ptr< FPGATrackSimNNMap > m_GNNmap_moduleMap
Gaudi::Property< bool > m_loadRadii
Gaudi::Property< std::string > m_NNmap2nd_path_param
virtual std::string getFakeNNMap2ndString() const override
Gaudi::Property< std::string > m_rmap_path
Gaudi::Property< std::string > m_radii_path
std::unique_ptr< FPGATrackSimRegionMap > m_subrmap
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_fake
Gaudi::Property< std::string > m_NNmap2nd_path_fake
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_param
Gaudi::Property< std::string > m_modulelut_path
virtual std::string getParamNNMapString() const override
Gaudi::Property< std::string > m_mappingType
virtual std::string getGNNModuleMapString() const override
virtual StatusCode initialize() override
Gaudi::Property< std::string > m_subrmap_path
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_extension_hit
std::unique_ptr< FPGATrackSimRegionMap > m_rmap_2nd
virtual std::string getParamNNMap2ndString() const override
std::unique_ptr< FPGATrackSimRegionMap > m_subrmap_2nd
Gaudi::Property< std::string > m_GNNmap_path_moduleMap
FPGATrackSimMappingSvc(const std::string &name, ISvcLocator *svc)
Gaudi::Property< std::string > m_NNmap_path_extension_vol
Gaudi::Property< std::string > m_NNmap_path_param
int countPmapSize(std::ifstream &fileIn)
Gaudi::Property< std::string > m_pmap_path
std::unique_ptr< FPGATrackSimRegionMap > m_rmap_1st
Gaudi::Property< std::string > m_NNmap_path_extension_hit
Gaudi::Property< std::vector< int > > m_layerOverrides
Gaudi::Property< bool > m_doGNNTrack
virtual std::string getFakeNNMapString() const override
std::unique_ptr< FPGATrackSimNNMap > m_NNmap_extension_vol
std::vector< std::unique_ptr< FPGATrackSimPlaneMap > > m_pmap_vector_2nd
Gaudi::Property< unsigned int > m_regionID
virtual std::string getExtensionNNHitMapString() const override
Gaudi::Property< std::string > m_radii2nd_path
std::unique_ptr< FPGATrackSimNNMap > m_NNmap2nd_fake