ATLAS Offline Software
TruthToTrack.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #define TRUTHTOTRACK_IMP
7 
8 #include <cmath>
9 #include <memory>
10 
11 #include "AtlasHepMC/GenParticle.h"
12 #include "AtlasHepMC/GenVertex.h"
15 
17 #include "xAODTruth/TruthVertex.h"
18 
20 
21 
22 //================================================================
23 Trk::TruthToTrack::TruthToTrack(const std::string& type, const std::string& name, const IInterface* parent)
25  , m_extrapolator("Trk::Extrapolator/AtlasExtrapolator")
26 {
27  declareInterface<ITruthToTrack>(this);
28  declareProperty("Extrapolator", m_extrapolator);
29 }
30 
31 //================================================================
33  ATH_CHECK( m_extrapolator.retrieve() );
34  return StatusCode::SUCCESS;
35 }
36 
37 
38 
39 //================================================================
41  Trk::TrackParameters *result = nullptr;
42 
43  if(part && part->production_vertex()) {
44  HepMC::FourVector tv = part->production_vertex()->position();
45  Amg::Vector3D hv(tv.x(),tv.y(),tv.z());
46  const Amg::Vector3D& globalPos = hv;
47 
48  const HepMC::FourVector& fv = part->momentum();
49  Amg::Vector3D hv2(fv.px(),fv.py(),fv.pz());
50  const Amg::Vector3D& globalMom = hv2;
51 
52  const int id = part->pdg_id();
53  if (id) {
54  const double charge = MC::charge(id);
55  Amg::Translation3D tmpTransl(hv);
56  Amg::Transform3D tmpTransf = tmpTransl * Amg::RotationMatrix3D::Identity();
57  const Trk::PlaneSurface surface(tmpTransf);
58  result = new Trk::AtaPlane(globalPos, globalMom, charge, surface);
59  }
60  else {
61  ATH_MSG_WARNING("Could not get particle data for particle ID="<<id);
62  }
63  }
64 
65  return result;
66 }
67 
68 
69 //================================================================
71  Trk::TrackParameters *result = nullptr;
72 
73  if(part && part->hasProdVtx()) {
74  Amg::Vector3D hv(part->prodVtx()->x(),part->prodVtx()->y(),part->prodVtx()->z());
75  const Amg::Vector3D& globalPos = hv;
76 
77  Amg::Vector3D hv2(part->p4().Px(),part->p4().Py(),part->p4().Pz());
78  const Amg::Vector3D& globalMom = hv2;
79 
80  const int id = part->pdg_id();
81  if (id) {
82  const double charge = MC::charge(id);
83  Amg::Translation3D tmpTransl(hv);
84  Amg::Transform3D tmpTransf = tmpTransl * Amg::RotationMatrix3D::Identity();
85  const Trk::PlaneSurface surface(tmpTransf);
86  result = new Trk::AtaPlane(globalPos, globalMom, charge, surface);
87  }
88  else {
89  ATH_MSG_WARNING("Could not get particle data for particle ID="<<id);
90  }
91  }
92 
93  return result;
94 }
95 
96 
97 
98 //================================================================
100  const Trk::TrackParameters* generatedTrackPerigee = nullptr;
101 
102  if(part && part->production_vertex() && m_extrapolator) {
103 
104  std::unique_ptr<const Trk::TrackParameters> productionVertexTrackParams( makeProdVertexParameters(part) );
105  if(productionVertexTrackParams) {
106 
107  // Extrapolate the TrackParameters object to the perigee. Direct extrapolation,
108  // no material effects.
109  generatedTrackPerigee = m_extrapolator->extrapolateDirectly(
110  Gaudi::Hive::currentContext(),
111  *productionVertexTrackParams,
114  false,
115  Trk::nonInteracting ).release();
116  }
117  }
118 
119  return generatedTrackPerigee;
120 }
121 
122 
123 
124 //================================================================
126  const Trk::TrackParameters* generatedTrackPerigee = nullptr;
127 
128  if(part && part->hasProdVtx() && m_extrapolator) {
129 
130  std::unique_ptr<const Trk::TrackParameters> productionVertexTrackParams( makeProdVertexParameters(part) );
131  if(productionVertexTrackParams) {
132 
133  // Extrapolate the TrackParameters object to the perigee. Direct extrapolation,
134  // no material effects.
135  generatedTrackPerigee = m_extrapolator->extrapolateDirectly(
136  Gaudi::Hive::currentContext(),
137  *productionVertexTrackParams,
140  false,
141  Trk::nonInteracting ).release();
142  }
143  }
144 
145  return generatedTrackPerigee;
146 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
Trk::anyDirection
@ anyDirection
Definition: PropDirection.h:22
Trk::TruthToTrack::TruthToTrack
TruthToTrack(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TruthToTrack.cxx:23
get_generator_info.result
result
Definition: get_generator_info.py:21
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
GenVertex.h
IExtrapolator.h
GenParticle.h
Trk::TruthToTrack::makeProdVertexParameters
virtual const Trk::TrackParameters * makeProdVertexParameters(HepMC::ConstGenParticlePtr part) const
This function produces a Trk::TrackParameters object corresponding to the HepMC::GenParticle at the p...
Definition: TruthToTrack.cxx:40
SimpleVector.h
Trk::TruthToTrack::makePerigeeParameters
virtual const Trk::TrackParameters * makePerigeeParameters(HepMC::ConstGenParticlePtr part) const
This function extrapolates track to the perigee, and returns perigee parameters.
Definition: TruthToTrack.cxx:99
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::ParametersBase
Definition: ParametersBase.h:55
TruthVertex.h
Trk::TruthToTrack::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: TruthToTrack.h:52
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trk::nonInteracting
@ nonInteracting
Definition: ParticleHypothesis.h:25
charge
double charge(const T &p)
Definition: AtlasPID.h:756
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::PlaneSurface
Definition: PlaneSurface.h:64
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Trk::AtaPlane
ParametersT< TrackParametersDim, Charged, PlaneSurface > AtaPlane
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:34
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
Trk::TruthToTrack::initialize
virtual StatusCode initialize()
Definition: TruthToTrack.cxx:32
TruthToTrack.h
AthAlgTool
Definition: AthAlgTool.h:26
TruthParticle.h
HepMCHelpers.h