19 #include "GaudiKernel/SystemOfUnits.h"
20 #include "GaudiKernel/ISvcLocator.h"
23 #include "Acts/Definitions/Algebra.hpp"
24 #include "Acts/Definitions/TrackParametrization.hpp"
25 #include "Acts/EventData/ParticleHypothesis.hpp"
26 #include "Acts/Geometry/GeometryContext.hpp"
27 #include "Acts/Propagator/detail/SteppingLogger.hpp"
28 #include "Acts/Surfaces/CylinderSurface.hpp"
29 #include "Acts/Surfaces/DiscSurface.hpp"
30 #include "Acts/Surfaces/PerigeeSurface.hpp"
31 #include "Acts/Surfaces/Surface.hpp"
32 #include "Acts/Utilities/Helpers.hpp"
33 #include "Acts/Utilities/Logger.hpp"
38 #include "CLHEP/Random/RandomEngine.h"
39 #include "CLHEP/Random/Randomize.h"
47 using xclock = std::chrono::steady_clock;
63 m_referenceSurfaces(0),
64 m_eventsPerExecute(1),
65 m_atlasPropResultWriterSvc(
"ATLASPropResultRootWriterSvc",
name),
66 m_actsPropResultWriterSvc(
"ACTSPropResultRootWriterSvc",
name),
67 m_rndmSvc(
"AthRNGSvc",
name)
92 std::vector< std::vector< const Trk::Surface* > >::const_iterator atlasSurfaceTripleIter = m_atlasReferenceSurfaceTriples.begin();
93 std::vector< std::vector< const Trk::Surface* > >::const_iterator atlasSurfaceTripleIterEnd = m_atlasReferenceSurfaceTriples.end();
94 for ( ; atlasSurfaceTripleIter != atlasSurfaceTripleIterEnd; ++atlasSurfaceTripleIter) {
95 std::vector<const Trk::Surface*>::const_iterator surfIter = (*atlasSurfaceTripleIter).begin();
96 std::vector<const Trk::Surface*>::const_iterator surfIterEnd = (*atlasSurfaceTripleIter).end();
97 for ( ; surfIter != surfIterEnd;
delete (*surfIter), ++surfIter);
110 ATH_CHECK( m_extrapolationTool.retrieve() );
111 ATH_CHECK( m_atlasExtrapolator.retrieve() );
115 if (m_referenceSurfaceRadius.size() == m_referenceSurfaceHalflength.size()) {
117 m_referenceSurfaces = m_referenceSurfaceRadius.size();
119 for (
unsigned int surface = 0; surface < m_referenceSurfaces; surface++) {
121 double radius = m_referenceSurfaceRadius.at(surface);
122 double halfZ = m_referenceSurfaceHalflength.at(surface);
125 std::vector< const Trk::Surface*> trkSurfaceTriplet;
130 m_atlasReferenceSurfaceTriples.push_back(trkSurfaceTriplet);
133 std::vector<std::shared_ptr<const Acts::Surface>> actsSurfaceTriplet;
135 Acts::Transform3 posTransf(Acts::Transform3::Identity()*Acts::Translation3(Acts::Vector3(0.,0., halfZ)));
136 Acts::Transform3 cTransf(Acts::Transform3::Identity()*Acts::Translation3(Acts::Vector3(0.,0., 0.)));
137 Acts::Transform3 negTransf(Acts::Transform3::Identity()*Acts::Translation3(Acts::Vector3(0.,0.,-halfZ)));
139 auto posSurface = Acts::Surface::makeShared<Acts::DiscSurface> (posTransf , 0.,
radius);
140 auto cSurface = Acts::Surface::makeShared<Acts::CylinderSurface>( cTransf ,
radius, halfZ);
141 auto negSurface = Acts::Surface::makeShared<Acts::DiscSurface> (negTransf , 0.,
radius);
143 actsSurfaceTriplet.push_back(posSurface);
144 actsSurfaceTriplet.push_back(cSurface );
145 actsSurfaceTriplet.push_back(negSurface);
147 m_actsReferenceSurfaceTriples.push_back(actsSurfaceTriplet);
149 m_referenceSurfaceNegativeBoundary.push_back(atan2(
radius,-halfZ));
150 m_referenceSurfacePositiveBoundary.push_back(atan2(
radius, halfZ));
153 ATH_MSG_WARNING(
"Not compatible size of ReferenceSurfaceRadius and ReferenceSurfaceHalfZ!! Returning FAILURE!");
154 return StatusCode::FAILURE;
157 ATH_CHECK( m_atlasPropResultWriterSvc.retrieve() );
158 ATH_CHECK( m_actsPropResultWriterSvc.retrieve() );
160 m_randomEngine = m_rndmSvc->getEngine (
this,
"ExtrapolatorComparisonTest");
162 return StatusCode::SUCCESS;
170 return StatusCode::SUCCESS;
177 float milliseconds_to_seconds = 1000.;
180 CLHEP::HepRandomEngine* engine = m_randomEngine->getEngine(ctx);
182 std::vector<perigeeParameters>
parameters = {};
183 for (
int ext = 0;
ext<m_eventsPerExecute;
ext++) {
185 double d0 = CLHEP::RandGauss::shoot(engine) * m_sigmaD0;
186 double z0 = CLHEP::RandGauss::shoot(engine) * m_sigmaZ0;
187 double phi = m_minPhi + (m_maxPhi-m_minPhi)* CLHEP::RandFlat::shoot(engine);
188 double eta = m_minEta + CLHEP::RandFlat::shoot(engine)*(m_maxEta-m_minEta);
189 double pt = m_minPt + CLHEP::RandFlat::shoot(engine)*(m_maxPt-m_minPt);
190 double charge = (CLHEP::RandFlat::shoot(engine) > 0.5 ) ? -1. : 1.;
198 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));
205 for (
unsigned int surface = 0; surface < m_atlasReferenceSurfaceTriples.size(); surface++) {
208 double negRef = m_referenceSurfaceNegativeBoundary.at(surface);
209 double posRef = m_referenceSurfacePositiveBoundary.at(surface);
212 int refSurface =
theta < posRef ? 2 : 1;
213 refSurface =
theta > negRef ? 0 : 1;
215 const Trk::Surface* destinationSurface = m_atlasReferenceSurfaceTriples.at(surface).at(refSurface);
217 ATH_MSG_VERBOSE(
"Starting extrapolation " << n_extraps <<
" from : " << *atlPerigee <<
" to : " << *destinationSurface);
221 m_atlasExtrapolator->extrapolate(
229 float ms_fwd = std::chrono::duration_cast<std::chrono::milliseconds>(end_fwd-start_fwd).count();
231 if (destParameters) {
234 ATH_MSG_VERBOSE(
" [ intersection ] parameters: " << destParameters->parameters() );
235 ATH_MSG_VERBOSE(
" [ intersection ] cov matrix: " << destParameters->covariance() );
240 m_atlasExtrapolator->extrapolate(
248 float ms_bkw = std::chrono::duration_cast<std::chrono::milliseconds>(end_bkw-start_bkw).count();
252 ATH_MSG_VERBOSE(
" [extrapolation to perigee] input: " << atlPerigee->parameters() );
253 ATH_MSG_VERBOSE(
" [extrapolation to perigee] output: " << finalperigee->parameters() );
254 ATH_MSG_VERBOSE(
" [extrapolation to perigee] cov matrix: " << finalperigee->covariance() );
256 }
else if (!finalperigee) {
257 ATH_MSG_DEBUG(
" ATLAS Extrapolation to perigee failed for input parameters: " << destParameters->parameters());
260 m_atlasPropResultWriterSvc->write<
Trk::TrackParameters>(atlPerigee, destParameters, ms_fwd, finalperigee, ms_bkw);
262 }
else if (!destParameters) {
266 delete destParameters;
271 auto secs = std::chrono::duration_cast<std::chrono::milliseconds>(
end-
start).count() / milliseconds_to_seconds;
272 double secs_per_ex = secs / n_extraps;
274 ATH_MSG_INFO(
"ATLAS : Time for " << n_extraps <<
" iterations: " << secs <<
"s (" << secs_per_ex <<
"s per extrapolation)");
279 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));
283 std::shared_ptr<Acts::PerigeeSurface> actsPerigeeSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3(0, 0, 0));
285 Acts::BoundVector
pars;
288 std::optional<Acts::BoundSquareMatrix>
cov = std::nullopt;
291 ActsGeometryContext gctx = m_extrapolationTool->trackingGeometryTool()->getNominalGeometryContext();
295 for (
unsigned int surface = 0; surface < m_actsReferenceSurfaceTriples.size(); surface++) {
298 double negRef = m_referenceSurfaceNegativeBoundary.at(surface);
299 double posRef = m_referenceSurfacePositiveBoundary.at(surface);
302 int refSurface =
theta < posRef ? 2 : 1;
303 refSurface =
theta > negRef ? 0 : 1;
305 auto destinationSurface = m_actsReferenceSurfaceTriples.at(surface).at(refSurface);
307 ATH_MSG_VERBOSE(
"Starting extrapolation " << n_extraps <<
" from : " <<
pars <<
" to : " << destinationSurface);
310 auto destParameters = m_extrapolationTool->propagate(ctx, *startParameters, *destinationSurface, Acts::Direction::Forward);
312 float ms_fwd = std::chrono::duration_cast<std::chrono::milliseconds>(end_fwd-start_fwd).count();
314 if (destParameters) {
316 ATH_MSG_VERBOSE(
" [ intersection ] with surface at (x,y,z) = " << destParameters->position(anygctx).x() <<
", " << destParameters->position(anygctx).y() <<
", " << destParameters->position(anygctx).z() );
317 ATH_MSG_VERBOSE(
" [ intersection ] parameters: " << destParameters->parameters() );
318 ATH_MSG_VERBOSE(
" [ intersection ] cov matrix: " << *destParameters->covariance() );
322 auto finalperigee = m_extrapolationTool->propagate(ctx, *destParameters, startParameters->referenceSurface(), Acts::Direction::Backward);
324 float ms_bkw = std::chrono::duration_cast<std::chrono::milliseconds>(end_bkw-start_bkw).count();
328 ATH_MSG_VERBOSE(
" [extrapolation to perigee] input: " << startParameters->parameters() );
329 ATH_MSG_VERBOSE(
" [extrapolation to perigee] output: " << finalperigee->parameters() );
330 ATH_MSG_VERBOSE(
" [extrapolation to perigee] cov matrix: " << *finalperigee->covariance() );
332 }
else if (!finalperigee) {
333 ATH_MSG_DEBUG(
" ACTS Extrapolation to perigee failed for input parameters: " << destParameters->parameters());
341 m_actsPropResultWriterSvc->write<
ActsTrackWrapper>(startWrapper, destWrapper, ms_fwd, finalWrapper, ms_bkw);
346 }
else if (!destParameters) {
353 delete startParameters;
357 secs = std::chrono::duration_cast<std::chrono::milliseconds>(
end-
start).count() / milliseconds_to_seconds;
358 secs_per_ex = secs / n_extraps;
360 ATH_MSG_INFO(
"ACTS : Time for " << n_extraps <<
" iterations: " << secs <<
"s (" << secs_per_ex <<
"s per extrapolation)");
362 return StatusCode::SUCCESS;