ATLAS Offline Software
Loading...
Searching...
No Matches
GbtsSeedingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <memory>
6#if defined(FLATTEN) && defined(__GNUC__)
7// Avoid warning in dbg build
8#pragma GCC optimize "-fno-var-tracking-assignments"
9#endif
10
11#include "src/GbtsSeedingTool.h"
13
14
15namespace ActsTrk {
16
18 const std::string& name,
19 const IInterface* parent)
20 : base_class(type, name, parent)
21 {}
22
24
25
26 ATH_CHECK(m_layerNumberTool.retrieve());
27 ATH_MSG_DEBUG("Initializing " << name() << "...");
28
29 // Make the logger And Propagate to ACTS routines
30 m_logger = makeActsAthenaLogger(this, "Acts");
31
34
35 // layer geometry creation
36 const std::vector<TrigInDetSiLayer>* pVL = m_layerNumberTool->layerGeometry();
37
38 m_layerGeometry.clear();
39 m_layerGeometry.reserve(pVL->size());
40
41 //convert from trigindetsilayer to acts::experimental::trigindetsilayer
42
43 for (const TrigInDetSiLayer& s : *pVL) {
44 m_layerGeometry.emplace_back(s.m_subdet, s.m_type, s.m_refCoord, s.m_minBound, s.m_maxBound);
45 }
46
47 //fill which has id for each module belongs to what layer
48 m_sct_h2l = m_layerNumberTool->sctLayers();
49 m_pix_h2l = m_layerNumberTool->pixelLayers();
50 m_are_pixels.resize(m_layerNumberTool->maxNumberOfUniqueLayers(), true);
51 for(const auto& l : *m_sct_h2l) m_are_pixels[l] = false;
52
53 //parse connection
54
55 m_connector = std::make_unique<Acts::Experimental::GbtsConnector>(m_cfg.connectorInputFile, m_cfg.lrtMode);
56
57 // option that allows for adding custom eta binning (default is at 0.2)
58 if (m_cfg.etaBinOverride != 0.0f) {
59
60 m_connector->etaBin = m_cfg.etaBinOverride;
61 }
62
63 //create geoemtry object that holds allowed pairing of allowed eta regions in each layer
64 m_gbtsGeo = std::make_unique<Acts::Experimental::GbtsGeometry>( m_layerGeometry, m_connector);
65
66 m_finder = std::make_unique<Acts::Experimental::SeedFinderGbts>(m_cfg, std::move(m_gbtsGeo), m_layerGeometry, logger().cloneWithSuffix("gbtsFinder"));
67
68 return StatusCode::SUCCESS;
69}
70
71 //create seeds
74 const EventContext& ctx,
75 const std::vector<const xAOD::SpacePointContainer*>& spacePointCollections,
76 const Eigen::Vector3f& beamSpotPos, float bFieldInZ,
77 ActsTrk::SeedContainer& seedContainer) const
78 {
79 //to avoid compile issues with unused veriables
80 (void) ctx;
81 (void) bFieldInZ;
82 //define new custom spacepoint container
83 Acts::SpacePointContainer2 coreSpacePoints(
84 Acts::SpacePointColumns::CopyFromIndex |
85 Acts::SpacePointColumns::SourceLinks |
86 Acts::SpacePointColumns::X |
87 Acts::SpacePointColumns::Y |
88 Acts::SpacePointColumns::Z |
89 Acts::SpacePointColumns::R |
90 Acts::SpacePointColumns::Phi
91 );
92
93 //add new column for layer ID and clusterwidth
94 auto layerColumn = coreSpacePoints.createColumn<std::uint32_t>("LayerID");
95 auto clusterWidthColumn = coreSpacePoints.createColumn<float>("Cluster_Width");
96 auto localPositionColumn = coreSpacePoints.createColumn<float>("LocalPositionY");
97
98
99 std::vector<const xAOD::SpacePoint*> tmpSpacePoints;
100 std::size_t totalSpacePoints = 0;
101
102 //add spacepoint pointers to singel container, this makes indexing them easier
103 for (const xAOD::SpacePointContainer* spacePoints : spacePointCollections) {
104 for (const xAOD::SpacePoint* sp : *spacePoints) {
105
106 tmpSpacePoints.emplace_back(sp);
107 }
108 totalSpacePoints += spacePoints->size();
109 }
110
111 coreSpacePoints.reserve(totalSpacePoints);
112
113 //add spacepoints to new container
114 for(std::size_t idx = 0; idx < tmpSpacePoints.size(); ++idx){
115
116 //obtain module hash for spacepoint
117 const xAOD::SpacePoint* sp = tmpSpacePoints[idx];
118 const std::vector<xAOD::DetectorIDHashType>& elementlist = sp->elementIdList() ;
119
120 bool isPixel(elementlist.size() == 1);
121 if(isPixel == false) continue; //as currently strip hits are not used for seeding
122
123 short layer = (isPixel ? m_pix_h2l : m_sct_h2l)->operator[](static_cast<int>(elementlist[0]));
124 //obtain coordinates
125
126 auto newSp = coreSpacePoints.createSpacePoint();
127 newSp.copyFromIndex() = idx;
128
129 //apply beamspot corrections if needed
130 if(m_cfg.beamSpotCorrection){
131
132 float new_x = static_cast<float>(sp->x() - beamSpotPos[0]);
133 float new_y = static_cast<float>(sp->y() - beamSpotPos[1]);
134 newSp.x() = new_x;
135 newSp.y() = new_y;
136 newSp.z() = static_cast<float>(sp->z());
137 newSp.r() = std::hypot(new_x, new_y);
138 newSp.phi() = std::atan2(new_y, new_x);
139
140 }else{
141 float new_x = static_cast<float>(sp->x());
142 float new_y = static_cast<float>(sp->y());
143 newSp.x() = static_cast<float>(sp->x());
144 newSp.y() = static_cast<float>(sp->y());
145 newSp.z() = static_cast<float>(sp->z());
146 newSp.r() = std::hypot(new_x, new_y);
147 newSp.phi() = std::atan2(sp->y(), sp->x());
148 }
149
150 newSp.extra(layerColumn) = layer;
151
152 if(m_cfg.useMl){
153
154 assert(dynamic_cast<const xAOD::PixelCluster*>(sp->measurements().front())!=nullptr);
155 const xAOD::PixelCluster* pCL = static_cast<const xAOD::PixelCluster*>(sp->measurements().front());
156 newSp.extra(clusterWidthColumn) = pCL->widthInEta();
157 newSp.extra(localPositionColumn) = pCL->localPosition<2>().y();
158
159 }else{
160 newSp.extra(clusterWidthColumn) = 0;
161 newSp.extra(localPositionColumn) = 0;
162
163 }
164 }
165 ATH_MSG_VERBOSE("Spacepoints successfully added to new container");
166
167 //collect all spacepoint containers objects so they can be passed into the seedfinder
168 auto sPContainerComponents = std::make_tuple(std::move(coreSpacePoints), layerColumn.asConst(), clusterWidthColumn.asConst(), localPositionColumn.asConst());
169
170 //compute seeds
171 int max_layers = m_are_pixels.size();
172 Acts::Experimental::RoiDescriptor internalRoi(0, -4.5, 4.5, 0, -std::numbers::pi, std::numbers::pi, 0, -150.0,150.0); //(eta,etaMinus,etaPlus,phi,phiMinus,Phiplus,z,zMinus,zPlus)
173 Acts::SeedContainer2 seeds = m_finder->createSeeds(internalRoi, sPContainerComponents, max_layers);
174
175 //add seeds to the output container
176 seedContainer.reserve(seedContainer.size() + seeds.size(), 7.0f);
177 for (Acts::MutableSeedProxy2 seed : seeds) {
178 seedContainer.push_back(
179 Acts::ConstSeedProxy2(seed),
180 [&](const Acts::SpacePointIndex2 spIndex) {
181 return tmpSpacePoints[spIndex];
182 });
183 }
184
185 ATH_MSG_VERBOSE("Number of seeds created is " << seedContainer.size());
186 return StatusCode::SUCCESS;
187 }
188
189
190 //this is called in initialise
191 //adds all veriables that may have been changed in the gaudi properties defined in headerfile
192 //TO DO: ADD NEW VERIABLES, DELETE OLD ONES AND CHANGE CURRENT ONES TO NEW VALUES
193 StatusCode
195 {
196
197 m_cfg.lrtMode = m_LRTmode;
198 m_cfg.useMl = m_useML;
199 m_cfg.matchBeforeCreate = m_matchBeforeCreate;
200 m_cfg.useOldTunings = m_useOldTunings;
201 m_cfg.etaBinOverride = m_etaBinOverride;
202 m_cfg.beamSpotCorrection = m_BeamSpotCorrection;
203 m_cfg.sigmaMS = m_sigmaMS;
204 m_cfg.radLen = m_radLen;
205 m_cfg.sigmaX = m_sigma_x;
206 m_cfg.sigmaY = m_sigma_y;
207 m_cfg.weightX = m_weight_x;
208 m_cfg.weightY = m_weight_y;
209 m_cfg.maxDChi2X = m_maxDChi2_x;
210 m_cfg.maxDChi2Y = m_maxDChi2_y;
211 m_cfg.addHit = m_add_hit;
212 m_cfg.minPt = m_minPt;
213 m_cfg.phiSliceWidth = m_phiSliceWidth ;
214 m_cfg.nMaxPhiSlice = m_nMaxPhiSlice;
215 m_cfg.connectorInputFile = m_connectorInputFile;
216 m_cfg.lutInputFile = m_lutFile;
217 m_cfg.useEtaBinning = m_useEtaBinning;
218 m_cfg.doubletFilterRZ = m_doubletFilterRZ ;
219 m_cfg.minDeltaRadius = m_minDeltaRadius;
220 m_cfg.nMaxEdges = m_nMaxEdges;
221 m_cfg.tauRatioCut = m_tau_ratio_cut;
222 m_cfg.tauRatioPrecut = m_tau_ratio_precut;
223 m_cfg.ptCoeff = m_ptCoeff;
224 m_cfg.maxCurvature = m_max_curvature;
225 m_cfg.maxZ0 = m_max_z0;
226 m_cfg.edgeMaskMinEta = m_edge_mask_min_eta;
227 m_cfg.hitShareThreshold = m_hit_share_threshold;
228 m_cfg.maxEndcapClusterWidth = m_max_endcap_clusterwidth;
229
230 return StatusCode::SUCCESS;
231 }
232 //called in initialise, used to make sure all config settings look sensible
233 void GbtsSeedingTool::printGbtsConfig(const Acts::Experimental::GbtsConfig& cfg) {
234 ATH_MSG_DEBUG("===== GbtsConfig =====");
235 ATH_MSG_DEBUG( "beamSpotCorrection: " << cfg.beamSpotCorrection << " (default: false)");
236 ATH_MSG_DEBUG( "connectorInputFile: " << cfg.connectorInputFile << " (default: empty string)");
237 ATH_MSG_DEBUG( "lutInputFile: " << cfg.lutInputFile << " (default: empty string)");
238 ATH_MSG_DEBUG( "lrtMode: " << cfg.lrtMode << " (default: false)");
239 ATH_MSG_DEBUG( "useMl: " << cfg.useMl << " (default: false)");
240 ATH_MSG_DEBUG( "matchBeforeCreate: " << cfg.matchBeforeCreate << " (default: false)");
241 ATH_MSG_DEBUG( "useOldTunings: " << cfg.useOldTunings << " (default: false)");
242 ATH_MSG_DEBUG( "tauRatioPrecut: " << cfg.tauRatioPrecut << " (default: 0.009f)");
243 ATH_MSG_DEBUG( "tauRatioCut: " << cfg.tauRatioCut << " (default: 0.007)");
244 ATH_MSG_DEBUG( "etaBinOverride: " << cfg.etaBinOverride << " (default: 0.0)");
245 ATH_MSG_DEBUG( "nMaxPhiSlice: " << cfg.nMaxPhiSlice << " (default: 53)");
246 ATH_MSG_DEBUG( "minPt: " << cfg.minPt << " (default: 1000. MeV)");
247 ATH_MSG_DEBUG( "phiSliceWidth: " << cfg.phiSliceWidth << " (default: null)");
248 ATH_MSG_DEBUG( "ptCoeff: " << cfg.ptCoeff << " (default: 0.29955)");
249 ATH_MSG_DEBUG( "useEtaBinning: " << cfg.useEtaBinning << " (default: true)");
250 ATH_MSG_DEBUG( "doubletFilterRZ: " << cfg.doubletFilterRZ << " (default: true)");
251 ATH_MSG_DEBUG( "nMaxEdges: " << cfg.nMaxEdges << " (default: 2000000)");
252 ATH_MSG_DEBUG( "minDeltaRadius: " << cfg.minDeltaRadius << " (default: 2.0)");
253 ATH_MSG_DEBUG( "sigmaMS: " << cfg.sigmaMS << " (default: 0.016)");
254 ATH_MSG_DEBUG( "radLen: " << cfg.radLen << " (default: 0.025)");
255 ATH_MSG_DEBUG( "sigmaX: " << cfg.sigmaX << " (default: 0.08)");
256 ATH_MSG_DEBUG( "sigmaY: " << cfg.sigmaY << " (default: 0.25)");
257 ATH_MSG_DEBUG( "weightX: " << cfg.weightX << " (default: 0.5)");
258 ATH_MSG_DEBUG( "weightY: " << cfg.weightY << " (default: 0.5)");
259 ATH_MSG_DEBUG( "maxDChi2X: " << cfg.maxDChi2X << " (default: 5.0)");
260 ATH_MSG_DEBUG( "maxDChi2Y: " << cfg.maxDChi2Y << " (default: 6.0)");
261 ATH_MSG_DEBUG( "addHit: " << cfg.addHit << " (default: 14.0)");
262 ATH_MSG_DEBUG( "maxCurvature: " << cfg.maxCurvature << " (default: 1e-3f)");
263 ATH_MSG_DEBUG( "maxZ0: " << cfg.maxZ0 << " (default: 170.0)");
264 ATH_MSG_DEBUG( "edgeMaskMinEta: " << cfg.edgeMaskMinEta << " (default: 1.5)");
265 ATH_MSG_DEBUG( "hitShareThreshold: " << cfg.hitShareThreshold << " (default: 0.49)");
266 ATH_MSG_DEBUG( "maxEndcapClusterWidth: " << cfg.maxEndcapClusterWidth << " (default: 0.35)");
267
268}
269
270} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t sp
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
#define y
Gaudi::Property< float > m_tau_ratio_cut
std::unique_ptr< Acts::Experimental::GbtsConnector > m_connector
Gaudi::Property< bool > m_doubletFilterRZ
Gaudi::Property< float > m_sigma_x
Gaudi::Property< int > m_nMaxEdges
Gaudi::Property< float > m_add_hit
Gaudi::Property< float > m_maxDChi2_x
Gaudi::Property< float > m_max_z0
Gaudi::Property< float > m_minPt
Gaudi::Property< bool > m_BeamSpotCorrection
Gaudi::Property< double > m_ptCoeff
std::vector< bool > m_are_pixels
Gaudi::Property< float > m_sigmaMS
virtual StatusCode initialize() override
const std::vector< short > * m_sct_h2l
Gaudi::Property< float > m_hit_share_threshold
Gaudi::Property< bool > m_LRTmode
Gaudi::Property< float > m_max_curvature
std::unique_ptr< const Acts::Logger > m_logger
logging instance
std::unique_ptr< Acts::Experimental::SeedFinderGbts > m_finder
Gaudi::Property< float > m_nMaxPhiSlice
Gaudi::Property< bool > m_useOldTunings
Gaudi::Property< float > m_sigma_y
const Acts::Logger & logger() const
Private access to the logger.
Gaudi::Property< float > m_max_endcap_clusterwidth
Gaudi::Property< std::string > m_connectorInputFile
std::vector< Acts::Experimental::TrigInDetSiLayer > m_layerGeometry
const std::vector< short > * m_pix_h2l
Gaudi::Property< float > m_weight_x
Gaudi::Property< bool > m_useML
Gaudi::Property< float > m_minDeltaRadius
Gaudi::Property< float > m_weight_y
void printGbtsConfig(const Acts::Experimental::GbtsConfig &cfg)
Gaudi::Property< float > m_tau_ratio_precut
Gaudi::Property< bool > m_useEtaBinning
Gaudi::Property< bool > m_matchBeforeCreate
Gaudi::Property< float > m_phiSliceWidth
std::unique_ptr< Acts::Experimental::GbtsGeometry > m_gbtsGeo
ToolHandle< ITrigL2LayerNumberTool > m_layerNumberTool
Acts::Experimental::GbtsConfig m_cfg
Gaudi::Property< float > m_etaBinOverride
Gaudi::Property< float > m_maxDChi2_y
Gaudi::Property< std::string > m_lutFile
Gaudi::Property< float > m_edge_mask_min_eta
GbtsSeedingTool(const std::string &type, const std::string &name, const IInterface *parent)
StatusCode createSeeds2(const EventContext &ctx, const std::vector< const xAOD::SpacePointContainer * > &spacePointCollections, const Eigen::Vector3f &beamSpotPos, float bFieldInZ, ActsTrk::SeedContainer &seedContainer) const override
Gaudi::Property< float > m_radLen
float widthInEta() const
Returns the width of the cluster in phi (x) and eta (y) directions, respectively.
ConstVectorMap< N > localPosition() const
Returns the local position of the measurement.
#define ATH_FLATTEN
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
SpacePointContainer_v1 SpacePointContainer
Define the version of the space point container.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
Seed push_back(SpacePointRange spacePoints, float quality, float vertexZ)
void reserve(std::size_t size, float averageSpacePoints=3) noexcept
std::size_t size() const noexcept