19 #include "GaudiKernel/ISvcLocator.h"
22 #include "Acts/Definitions/Algebra.hpp"
23 #include "Acts/Definitions/TrackParametrization.hpp"
24 #include "Acts/EventData/ParticleHypothesis.hpp"
25 #include "Acts/Geometry/GeometryContext.hpp"
26 #include "Acts/Propagator/detail/SteppingLogger.hpp"
27 #include "Acts/Surfaces/CylinderSurface.hpp"
28 #include "Acts/Surfaces/DiscSurface.hpp"
29 #include "Acts/Surfaces/PerigeeSurface.hpp"
30 #include "Acts/Surfaces/Surface.hpp"
31 #include "Acts/Utilities/Helpers.hpp"
32 #include "Acts/Utilities/Logger.hpp"
37 #include "CLHEP/Random/RandomEngine.h"
38 #include "CLHEP/Random/Randomize.h"
46 using xclock = std::chrono::steady_clock;
58 for (
const auto& surfaceTriple : m_atlasReferenceSurfaceTriples) {
59 for (
const auto* surface : surfaceTriple) {
74 ATH_CHECK( m_extrapolationTool.retrieve() );
75 ATH_CHECK( m_atlasExtrapolator.retrieve() );
76 ATH_CHECK( m_trackingGeometryTool.retrieve() );
80 if (m_referenceSurfaceRadius.size() == m_referenceSurfaceHalflength.size()) {
82 m_referenceSurfaces = m_referenceSurfaceRadius.size();
84 for (
unsigned int surface = 0; surface < m_referenceSurfaces; surface++) {
86 double radius = m_referenceSurfaceRadius[surface];
87 double halfZ = m_referenceSurfaceHalflength[surface];
90 std::vector< const Trk::Surface*> trkSurfaceTriplet;
95 m_atlasReferenceSurfaceTriples.push_back(trkSurfaceTriplet);
98 std::vector<std::shared_ptr<const Acts::Surface>> actsSurfaceTriplet;
100 Acts::Transform3 posTransf(Acts::Transform3::Identity()*Acts::Translation3(Acts::Vector3(0.,0., halfZ)));
101 Acts::Transform3 cTransf(Acts::Transform3::Identity()*Acts::Translation3(Acts::Vector3(0.,0., 0.)));
102 Acts::Transform3 negTransf(Acts::Transform3::Identity()*Acts::Translation3(Acts::Vector3(0.,0.,-halfZ)));
104 auto posSurface = Acts::Surface::makeShared<Acts::DiscSurface> (posTransf , 0.,
radius);
105 auto cSurface = Acts::Surface::makeShared<Acts::CylinderSurface>( cTransf ,
radius, halfZ);
106 auto negSurface = Acts::Surface::makeShared<Acts::DiscSurface> (negTransf , 0.,
radius);
108 actsSurfaceTriplet.push_back(posSurface);
109 actsSurfaceTriplet.push_back(cSurface );
110 actsSurfaceTriplet.push_back(negSurface);
112 m_actsReferenceSurfaceTriples.push_back(actsSurfaceTriplet);
114 m_referenceSurfaceNegativeBoundary.push_back(atan2(
radius,-halfZ));
115 m_referenceSurfacePositiveBoundary.push_back(atan2(
radius, halfZ));
118 ATH_MSG_WARNING(
"Not compatible size of ReferenceSurfaceRadius and ReferenceSurfaceHalfZ!! Returning FAILURE!");
119 return StatusCode::FAILURE;
122 ATH_CHECK( m_atlasPropResultWriterSvc.retrieve() );
123 ATH_CHECK( m_actsPropResultWriterSvc.retrieve() );
125 m_randomEngine = m_rndmSvc->getEngine (
this,
"ExtrapolatorComparisonTest");
127 return StatusCode::SUCCESS;
135 return StatusCode::SUCCESS;
142 float milliseconds_to_seconds = 1000.;
145 CLHEP::HepRandomEngine* engine = m_randomEngine->getEngine(ctx);
147 std::vector<perigeeParameters>
parameters = {};
148 for (
int ext = 0;
ext<m_eventsPerExecute;
ext++) {
150 double d0 = CLHEP::RandGauss::shoot(engine) * m_sigmaD0;
151 double z0 = CLHEP::RandGauss::shoot(engine) * m_sigmaZ0;
152 double phi = m_minPhi + (m_maxPhi-m_minPhi)* CLHEP::RandFlat::shoot(engine);
153 double eta = m_minEta + CLHEP::RandFlat::shoot(engine)*(m_maxEta-m_minEta);
154 double pt = m_minPt + CLHEP::RandFlat::shoot(engine)*(m_maxPt-m_minPt);
155 double charge = (CLHEP::RandFlat::shoot(engine) > 0.5 ) ? -1. : 1.;
163 Acts::Vector3
momentum(perigee.m_pt *
std::cos(perigee.m_phi), perigee.m_pt *
std::sin(perigee.m_phi), perigee.m_pt * std::sinh(perigee.m_eta));
170 for (
unsigned int surface = 0; surface < m_atlasReferenceSurfaceTriples.size(); surface++) {
173 double negRef = m_referenceSurfaceNegativeBoundary.at(surface);
174 double posRef = m_referenceSurfacePositiveBoundary.at(surface);
177 int refSurface =
theta < posRef ? 2 : 1;
178 refSurface =
theta > negRef ? 0 : 1;
180 const Trk::Surface* destinationSurface = m_atlasReferenceSurfaceTriples.at(surface).at(refSurface);
182 ATH_MSG_VERBOSE(
"Starting extrapolation " << n_extraps <<
" from : " << *atlPerigee <<
" to : " << *destinationSurface);
186 m_atlasExtrapolator->extrapolate(
194 float ms_fwd = std::chrono::duration_cast<std::chrono::milliseconds>(end_fwd-start_fwd).count();
196 if (destParameters) {
199 ATH_MSG_VERBOSE(
" [ intersection ] parameters: " << destParameters->parameters() );
200 ATH_MSG_VERBOSE(
" [ intersection ] cov matrix: " << destParameters->covariance() );
205 m_atlasExtrapolator->extrapolate(
213 float ms_bkw = std::chrono::duration_cast<std::chrono::milliseconds>(end_bkw-start_bkw).count();
217 ATH_MSG_VERBOSE(
" [extrapolation to perigee] input: " << atlPerigee->parameters() );
218 ATH_MSG_VERBOSE(
" [extrapolation to perigee] output: " << finalperigee->parameters() );
219 ATH_MSG_VERBOSE(
" [extrapolation to perigee] cov matrix: " << finalperigee->covariance() );
221 }
else if (!finalperigee) {
222 ATH_MSG_DEBUG(
" ATLAS Extrapolation to perigee failed for input parameters: " << destParameters->parameters());
225 m_atlasPropResultWriterSvc->write<
Trk::TrackParameters>(atlPerigee, destParameters, ms_fwd, finalperigee, ms_bkw);
227 }
else if (!destParameters) {
231 delete destParameters;
236 auto secs = std::chrono::duration_cast<std::chrono::milliseconds>(
end-
start).count() / milliseconds_to_seconds;
237 double secs_per_ex = secs / n_extraps;
239 ATH_MSG_INFO(
"ATLAS : Time for " << n_extraps <<
" iterations: " << secs <<
"s (" << secs_per_ex <<
"s per extrapolation)");
244 Acts::Vector3
momentum(perigee.m_pt *
std::cos(perigee.m_phi), perigee.m_pt *
std::sin(perigee.m_phi), perigee.m_pt * std::sinh(perigee.m_eta));
248 std::shared_ptr<Acts::PerigeeSurface> actsPerigeeSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3(0, 0, 0));
250 Acts::BoundVector
pars;
253 std::optional<Acts::BoundSquareMatrix>
cov = std::nullopt;
260 for (
unsigned int surface = 0; surface < m_actsReferenceSurfaceTriples.size(); surface++) {
263 double negRef = m_referenceSurfaceNegativeBoundary.at(surface);
264 double posRef = m_referenceSurfacePositiveBoundary.at(surface);
267 int refSurface =
theta < posRef ? 2 : 1;
268 refSurface =
theta > negRef ? 0 : 1;
270 auto destinationSurface = m_actsReferenceSurfaceTriples.at(surface).at(refSurface);
272 ATH_MSG_VERBOSE(
"Starting extrapolation " << n_extraps <<
" from : " <<
pars <<
" to : " << destinationSurface);
275 auto destParameters = m_extrapolationTool->propagate(ctx, *startParameters, *destinationSurface, Acts::Direction::Forward());
277 float ms_fwd = std::chrono::duration_cast<std::chrono::milliseconds>(end_fwd-start_fwd).count();
279 if (destParameters) {
281 ATH_MSG_VERBOSE(
" [ intersection ] with surface at (x,y,z) = " << destParameters->position(anygctx).x() <<
", " << destParameters->position(anygctx).y() <<
", " << destParameters->position(anygctx).z() );
282 ATH_MSG_VERBOSE(
" [ intersection ] parameters: " << destParameters->parameters() );
283 ATH_MSG_VERBOSE(
" [ intersection ] cov matrix: " << *destParameters->covariance() );
287 auto finalperigee = m_extrapolationTool->propagate(ctx, *destParameters, startParameters->referenceSurface(), Acts::Direction::Backward());
289 float ms_bkw = std::chrono::duration_cast<std::chrono::milliseconds>(end_bkw-start_bkw).count();
293 ATH_MSG_VERBOSE(
" [extrapolation to perigee] input: " << startParameters->parameters() );
294 ATH_MSG_VERBOSE(
" [extrapolation to perigee] output: " << finalperigee->parameters() );
295 ATH_MSG_VERBOSE(
" [extrapolation to perigee] cov matrix: " << *finalperigee->covariance() );
297 }
else if (!finalperigee) {
298 ATH_MSG_DEBUG(
" ACTS Extrapolation to perigee failed for input parameters: " << destParameters->parameters());
306 m_actsPropResultWriterSvc->write<
ActsTrackWrapper>(startWrapper, destWrapper, ms_fwd, finalWrapper, ms_bkw);
311 }
else if (!destParameters) {
318 delete startParameters;
322 secs = std::chrono::duration_cast<std::chrono::milliseconds>(
end-
start).count() / milliseconds_to_seconds;
323 secs_per_ex = secs / n_extraps;
325 ATH_MSG_INFO(
"ACTS : Time for " << n_extraps <<
" iterations: " << secs <<
"s (" << secs_per_ex <<
"s per extrapolation)");
327 return StatusCode::SUCCESS;