17#include "GaudiKernel/ThreadLocalContext.h"
31#include "CLHEP/Units/PhysicalConstants.h"
100 return m_d->surfaces;
106 double dx(p2.x()-p1.x()), dy(p2.y()-p1.y()), dz(p2.z()-p1.z());
108 theclass->message(
"movePoint1ToZPlaneAndPoint2 Error: Points have same z!!");
111 double s( (
z-p1.z())/dz );
126 double p1r(p1.perp());
127 double dr(p2.perp()-p1r);
129 theclass->message(
"movePoint1ToInfiniteCylinderAndPoint2 Error: Points have same r!!");
132 double s((
r-p1r)/dr);
135 p1[0]= p1.x()*t + p2.x()*s;
137 p1[1]= p1.y()*t + p2.y()*s;
138 p1[2]= p1.z()*t + p2.z()*s;
161 message(
"makePointsNeutral called with null track pointer");
164 const unsigned npars = track->trackParameters()->size();
166 message(
"makePointsNeutral Error: No TrackParameters on track!");
170 return m_d->makePointsNeutral_SinglePar(points,track);
172 points.reserve(track->trackParameters()->size());
177 bool problems(
false);
178 for (; tsos_iter != tsos_end; ++tsos_iter) {
179 if (!
m_d->tracksanity->isSafe(*tsos_iter)) {
186 if (!
m_d->tracksanity->isSafe(trackParam)) {
190 points.push_back(trackParam->
position());
193 messageDebug(
"makePointsNeutral WARNING: Track had one or more track parameters which is unsafe to use in job.");
194 if (points.size()<2) {
195 messageDebug(
"makePointsNeutral ERROR: Track did not have at least two safe parameters.");
210 theclass->messageVerbose(
"makePointsNeutral_SinglePar start");
214 theclass->messageDebug(
"makePointsNeutral_SinglePar called with unsafe track parameter");
224 b =
a +999*CLHEP::m*u;
237 theclass->messageVerbose(
"makePointsNeutral_SinglePar (single track parameter) end");
246 messageVerbose(
"makePointsCharged start with hypo="+
str(hypo)+
", useMEOT="+
str(useMEOT)+
", volume=" +
str(volume));
254 message(
"makePointsCharged ERROR: Null extrapolator tool provided!");
258 message(
"makePointsCharged ERROR: Called with null track pointer");
261 const unsigned npars = track->trackParameters()->size();
263 message(
"makePointsCharged ERROR: No TrackParameters on track!");
267 return m_d->makePointsCharged_SinglePar(points,track,extrapolator,hypo);
269 points.reserve(npars);
270 const EventContext& ctx = Gaudi::Hive::currentContext();
276 bool problems(
false);
277 for (; tsos_iter != tsos_end; ++tsos_iter) {
278 if (!
m_d->tracksanity->isSafe(*tsos_iter))
280 if ((*tsos_iter)->measurementOnTrack()==
nullptr && ( (*tsos_iter)->materialEffectsOnTrack()&&!useMEOT ) )
282 trackParam = (*tsos_iter)->trackParameters();
283 if (!
m_d->tracksanity->isSafe(trackParam))
287 prevpar = trackParam;
288 points.push_back(prevpar->
position());
291 if (!
m_d->addPointsBetweenParameters_Charged(points,track,prevpar,trackParam,extrapolator,hypo))
293 points.push_back(trackParam->
position());
294 prevpar = trackParam;
298 messageDebug(
"WARNING: Problems encountered adding point(s) between track parameters");
301 if (volume && prevpar && !
m_d->outsideIDVolume(prevpar->
position())) {
305 std::size_t intersections = 0;
306 bool extended =
false;
307 QStringList surfaceErrors;
308 for (std::size_t i = 0; i < surfaces.size(); ++i) {
310 const auto target = extrapolator->
extrapolate(ctx, *prevpar, *surfaces[i],
317 const auto pointCount = points.size();
318 const bool sampled =
m_d->addPointsBetweenParameters_Charged(
319 points, track, prevpar, target.get(), extrapolator, hypo);
320 if (sampled && points.size() > pointCount)
322 }
catch (
const std::runtime_error&
error) {
323 surfaceErrors << QStringLiteral(
"surface %1: %2").arg(i + 1).arg(
error.what());
328 const QString warning = QStringLiteral(
"WARNING: The extrapolator could not extend a track to the selected destination.");
329 message(warning + QStringLiteral(
" See the terminal for details."));
334 <<
" | Start (x, y, z) [mm]: " << prevpar->
position().transpose()
335 <<
" | Particle hypothesis: " << hypo
336 <<
" | Target intersections: " << intersections <<
'/' << surfaces.size() <<
". ";
337 if (surfaces.empty())
338 details <<
"The target volume has no boundary surfaces.";
339 else if (intersections == 0)
340 details <<
"No boundary surface could be reached along the track momentum.";
342 details <<
"An intersection was found, but no extension segment was sampled successfully.";
343 if (!surfaceErrors.empty())
344 details <<
" Extrapolator exceptions: " << surfaceErrors.join(QStringLiteral(
"; ")).toStdString();
345 std::cerr <<
details.str() << std::endl;
360 if (!trk||!prevpars||!extrapolator)
376 newpars = extrapolator->
extrapolate(Gaudi::Hive::currentContext(),
380 }
catch (
const std::runtime_error& e) {
381 theclass->message(
"Failure trying to use extrapolator for track (Exception thrown: " + QString(e.what())+
")");
385 theclass->message(
"Failure trying to use extrapolator for track");
389 theclass->message(
"Failure trying to use extrapolator for track");
396 return m_d->showExtrapSurfaces;
405 theclass->messageVerbose(
"makePointsCharged_SinglePar start");
408 theclass->message(
"makePointsCharged_SinglePar ERROR: Null extrapolator tool provided!");
413 theclass->messageDebug(
"makePointsCharged_SinglePar called with unsafe track parameter");
418 points.push_back(p0);
422 const double maxdistadded = 2*CLHEP::m;
427 while (distadded<maxdistadded) {
435 theclass->messageDebug(
"makePointsCharged_SinglePar ERROR: Failed to use extrapolator for next point");
436 if (points.size()<2) {
457 theclass->messageVerbose(
"makePointsCharged_SinglePar end");
468 if (distbetween<0.001) {
469 theclass->messageVerbose(
"TrackPropagationHelper::Imp::addPointsBetweenParameters_Charged: parameters on top of each other. Skip, but no error.");
478 double olddistsq(1.0e99);
480 const double maxdistadded = std::max(2*CLHEP::m,(par1->
position()-p2).mag()*1.5);
489 theclass->messageVerbose(
"TrackPropagationHelper::Imp::addPointsBetweenParameters_Charged: Extrapolation failed.");
493 if (distsq>olddistsq) {
498 theclass->messageVerbose(
"TrackPropagationHelper::Imp::addPointsBetweenParameters_Charged: distq("+
str(distsq)+
")>olddistsq ("+
str(olddistsq)+
") so overshot?");
506 points.push_back(newpars->
position());
514 return (distadded<maxdistadded);
DataModel_detail::const_iterator< DataVector > const_iterator
const Trk::TrackParameters * extrapolateToNewPar(Trk::IExtrapolator *extrapolator, const Trk::Track *trk, const Trk::TrackParameters *prevpars, Trk::ParticleHypothesis hypo, const double &dist)
std::vector< Trk::PlaneSurface > surfaces
For debugging.
bool addPointsBetweenParameters_Charged(std::vector< Amg::Vector3D > &points, const Trk::Track *, const Trk::TrackParameters *par1, const Trk::TrackParameters *par2, Trk::IExtrapolator *extrapolator, Trk::ParticleHypothesis hypo)
bool makePointsCharged_SinglePar(std::vector< Amg::Vector3D > &points, const Trk::Track *, Trk::IExtrapolator *extrapolator, Trk::ParticleHypothesis hypo)
TrackPropagationHelper * theclass
void movePoint1ToZPlaneAndPoint2(Amg::Vector3D &p1, const Amg::Vector3D &p2, const double &z) const
bool outsideIDVolume(const Amg::Vector3D &p) const
Imp(TrackPropagationHelper *tc)
std::unique_ptr< VP1TrackSanity > tracksanity
bool makePointsNeutral_SinglePar(std::vector< Amg::Vector3D > &points, const Trk::Track *)
const double fallback_flydist
static double maxPointDistSq(const Amg::Vector3D &)
void movePoint1ToInfiniteCylinderAndPoint2(Amg::Vector3D &p1, const Amg::Vector3D &p2, const double &r) const
bool makePointsCharged(std::vector< Amg::Vector3D > &points, const Trk::Track *, Trk::IExtrapolator *extrapolator, Trk::ParticleHypothesis hypo=Trk::nonInteracting, bool useMEOT=false, const Trk::Volume *volume=0)
TrackPropagationHelper(IVP1System *sys)
bool makePointsNeutral(std::vector< Amg::Vector3D > &points, const Trk::Track *)
std::vector< Trk::PlaneSurface > & getExtrapolationSurfaces() const
bool showExtrapolationSurfaces() const
~TrackPropagationHelper()
simple class that constructs the curvilinear vectors curvU and curvV from a given momentum direction ...
const Amg::Vector3D & curvU() const
Access methods.
const Amg::Vector3D & curvT() const
const Amg::Vector3D & curvV() const
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
Class for a planaer rectangular or trapezoidal surface in the ATLAS detector.
Pure Absract Base Class for Volume bounds.
virtual std::vector< std::unique_ptr< Trk::Surface > > decomposeToSurfaces(const Amg::Transform3D &transform)=0
Method to decompose the Bounds into Surfaces, the Volume can turn them into BoundarySurfaces.
Base class for all volumes inside the tracking realm, it defines the interface for inherited Volume c...
const Amg::Transform3D & transform() const
Return methods for geometry transform.
const VolumeBounds & volumeBounds() const
returns the volumeBounds()
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const
void message(const QString &) const
IVP1System * systemBase() const
void messageDebug(const QString &) const
static const char * prefix_msg()
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.
ParametersBase< TrackParametersDim, Charged > TrackParameters