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 "GaudiKernel/IPartPropSvc.h"
12 
13 #include "AtlasHepMC/GenParticle.h"
14 #include "AtlasHepMC/GenVertex.h"
16 
18 #include "xAODTruth/TruthVertex.h"
19 
20 
21 #include "HepPDT/ParticleDataTable.hh"
22 
24 
25 
26 //================================================================
27 Trk::TruthToTrack::TruthToTrack(const std::string& type, const std::string& name, const IInterface* parent)
29  , m_particleDataTable(nullptr)
30  , m_extrapolator("Trk::Extrapolator/AtlasExtrapolator")
31 {
32  declareInterface<ITruthToTrack>(this);
33  declareProperty("Extrapolator", m_extrapolator);
34 }
35 
36 //================================================================
38  // get the Particle Properties Service
39  IPartPropSvc* partPropSvc = nullptr;
40  StatusCode sc = service("PartPropSvc", partPropSvc, true);
41  if (sc.isFailure()) {
42  ATH_MSG_ERROR("Could not initialize Particle Properties Service");
43  return StatusCode::FAILURE;
44  }
45  m_particleDataTable = partPropSvc->PDT();
46 
47  if ( m_extrapolator.retrieve().isFailure() ) {
48  ATH_MSG_FATAL("Failed to retrieve tool " << m_extrapolator);
49  return StatusCode::FAILURE;
50  }
51 
52  return StatusCode::SUCCESS;
53 }
54 
55 
56 
57 //================================================================
59  Trk::TrackParameters *result = nullptr;
60 
61  if(part && part->production_vertex() && m_particleDataTable) {
62  HepMC::FourVector tv = part->production_vertex()->position();
63  Amg::Vector3D hv(tv.x(),tv.y(),tv.z());
64  const Amg::Vector3D& globalPos = hv;
65 
66  const HepMC::FourVector& fv = part->momentum();
67  Amg::Vector3D hv2(fv.px(),fv.py(),fv.pz());
68  const Amg::Vector3D& globalMom = hv2;
69 
70  int id = part->pdg_id();
71  // the table seems to lack antiparticles, thus the use of abs()
72  const HepPDT::ParticleData* pd = m_particleDataTable->particle(std::abs(id));
73 
74  if(pd) {
75  // pd could point to an antiparticle. recover the sign:
76  double charge = (id>0) ? pd->charge() : -pd->charge();
77  Amg::Translation3D tmpTransl(hv);
78  Amg::Transform3D tmpTransf = tmpTransl * Amg::RotationMatrix3D::Identity();
79  const Trk::PlaneSurface surface(tmpTransf);
80  result = new Trk::AtaPlane(globalPos, globalMom, charge, surface);
81  }
82  else {
83  ATH_MSG_WARNING("Could not get particle data for particle ID="<<id);
84  }
85  }
86 
87  return result;
88 }
89 
90 
91 //================================================================
93  Trk::TrackParameters *result = nullptr;
94 
95  if(part && part->hasProdVtx() && m_particleDataTable) {
96  Amg::Vector3D hv(part->prodVtx()->x(),part->prodVtx()->y(),part->prodVtx()->z());
97  const Amg::Vector3D& globalPos = hv;
98 
99  Amg::Vector3D hv2(part->p4().Px(),part->p4().Py(),part->p4().Pz());
100  const Amg::Vector3D& globalMom = hv2;
101 
102  int id = part->pdgId();
103  // the table seems to lack antiparticles, thus the use of abs()
104  const HepPDT::ParticleData* pd = m_particleDataTable->particle(std::abs(id));
105 
106  if(pd) {
107  // pd could point to an antiparticle. recover the sign:
108  double charge = (id>0) ? pd->charge() : -pd->charge();
109  Amg::Translation3D tmpTransl(hv);
110  Amg::Transform3D tmpTransf = tmpTransl * Amg::RotationMatrix3D::Identity();
111  const Trk::PlaneSurface surface(tmpTransf);
112  result = new Trk::AtaPlane(globalPos, globalMom, charge, surface);
113  }
114  else {
115  ATH_MSG_WARNING("Could not get particle data for particle ID="<<id);
116  }
117  }
118 
119  return result;
120 }
121 
122 
123 
124 //================================================================
126  const Trk::TrackParameters* generatedTrackPerigee = nullptr;
127 
128  if(part && part->production_vertex() && m_particleDataTable && 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 }
147 
148 
149 
150 //================================================================
152  const Trk::TrackParameters* generatedTrackPerigee = nullptr;
153 
154  if(part && part->hasProdVtx() && m_particleDataTable && m_extrapolator) {
155 
156  std::unique_ptr<const Trk::TrackParameters> productionVertexTrackParams( makeProdVertexParameters(part) );
157  if(productionVertexTrackParams) {
158 
159  // Extrapolate the TrackParameters object to the perigee. Direct extrapolation,
160  // no material effects.
161  generatedTrackPerigee = m_extrapolator->extrapolateDirectly(
162  Gaudi::Hive::currentContext(),
163  *productionVertexTrackParams,
166  false,
167  Trk::nonInteracting ).release();
168  }
169  }
170 
171  return generatedTrackPerigee;
172 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
Trk::anyDirection
@ anyDirection
Definition: PropDirection.h:22
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Trk::TruthToTrack::TruthToTrack
TruthToTrack(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TruthToTrack.cxx:27
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
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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:58
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:125
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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:41
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Trk::ParametersBase
Definition: ParametersBase.h:55
TruthVertex.h
Trk::TruthToTrack::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: TruthToTrack.h:55
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Trk::nonInteracting
@ nonInteracting
Definition: ParticleHypothesis.h:25
charge
double charge(const T &p)
Definition: AtlasPID.h:494
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::AtaPlane
ParametersT< 5, Charged, PlaneSurface > AtaPlane
Definition: Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:30
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
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
Trk::TruthToTrack::initialize
virtual StatusCode initialize()
Definition: TruthToTrack.cxx:37
TruthToTrack.h
AthAlgTool
Definition: AthAlgTool.h:26
TruthParticle.h