ATLAS Offline Software
Loading...
Searching...
No Matches
TruthTrackRecordToTrack.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <cmath>
8#include <memory>
9
12
15
20
21
22//================================================================
23Trk::TruthTrackRecordToTrack::TruthTrackRecordToTrack(const std::string& type, const std::string& name,
24 const IInterface* parent)
25 : AthAlgTool(type,name,parent),
26 m_extrapolator("Trk::Extrapolator/AtlasExtrapolator")
27{
28 declareInterface<ITruthToTrack>(this);
29
30 declareProperty("Extrapolator", m_extrapolator);
31 declareProperty("TrackRecordKey",m_reccollkey="CosmicPerigee");
32}
33
34//================================================================
36
37 ATH_CHECK ( m_extrapolator.retrieve() );
38
39 ATH_CHECK( m_reccollkey.initialize() );
40
41 return StatusCode::SUCCESS;
42}
43
44//================================================================
46
47 if (part == nullptr) return nullptr;
48
50 Amg::Vector3D prodVertexVector;
51 prodVertexVector.setZero();
52 Amg::Vector3D globalPos;
53 Amg::Vector3D globalMom;
54 int id=0;
55
57
58 if (trackRecordCollection.isValid()) {
59 ATH_MSG_ERROR ("Could not get track record!");
60 return nullptr;
61 }
62 ATH_MSG_DEBUG("reading from track record, size=" << trackRecordCollection->size());
63
64 if (trackRecordCollection->empty()) ATH_MSG_WARNING ("action required but TrackRecordCollection size is 0");
65
66 for (const auto & trackRecord : *trackRecordCollection) {
67
68 if ( !HepMC::is_same_particle(trackRecord,part) ) continue;
69
70 id = trackRecord.GetPDGCode();
71
72 CLHEP::Hep3Vector tv = trackRecord.GetPosition();
73 prodVertexVector = Amg::Vector3D(tv.x(),tv.y(),tv.z());
74 globalPos = prodVertexVector;
75
76 Amg::Vector3D hv2(trackRecord.GetMomentum().x(), trackRecord.GetMomentum().y(),
77 trackRecord.GetMomentum().z());
78 globalMom = hv2;
79
80 ATH_MSG_DEBUG("Found particle " << part << ", momentum " << hv2 << " production " << globalPos);
81
82
83 } // loop over G4 records
84
85 if (id) {
86 const double charge = MC::charge(id);
87
88 Amg::Translation3D prodSurfaceCentre( prodVertexVector.x(),
89 prodVertexVector.y(),
90 prodVertexVector.z() );
91
92 Amg::Transform3D tmpTransf = prodSurfaceCentre * Amg::RotationMatrix3D::Identity();
93
94 Trk::PlaneSurface planeSurface(tmpTransf, 5., 5. );
95 result = new Trk::AtaPlane(globalPos, globalMom, charge, planeSurface);
96 } else {
97 ATH_MSG_WARNING ("Could not get particle data for particle ID="<<id);
98 }
99 return result;
100}
101
102
103
104//================================================================
106
107 if (part == nullptr) return nullptr;
108
110 Amg::Vector3D prodVertexVector(0., 0., 0.);
111 Amg::Vector3D globalPos(0., 0., 0.);
112 Amg::Vector3D globalMom(0., 0., 0.);
113 int id=0;
114 double charge = 0.0;
115
117
118 if (trackRecordCollection.isValid()) {
119 ATH_MSG_ERROR ("Could not get track record!");
120 return nullptr;
121 }
122
123 ATH_MSG_DEBUG("reading from track record, size=" << trackRecordCollection->size());
124
125 if (trackRecordCollection->empty()) ATH_MSG_WARNING ("action required but TrackRecordCollection size is 0");
126
127 for (const auto & trackRecord : *trackRecordCollection) {
128 if ( HepMC::is_same_particle(trackRecord,part) ) {
129 id = trackRecord.GetPDGCode();
130 if (!id) continue;
131 CLHEP::Hep3Vector tv = trackRecord.GetPosition();
132 prodVertexVector = Amg::Vector3D(tv.x(),tv.y(),tv.z());
133 globalPos = prodVertexVector;
134 Amg::Vector3D hv2(trackRecord.GetMomentum().x(), trackRecord.GetMomentum().y(), trackRecord.GetMomentum().z());
135 globalMom = hv2;
136 ATH_MSG_DEBUG("found particle " << part << ", momentum " << hv2 << " production " << globalPos);
137 }
138 } // loop over G4 records
139
140 if (id) {
141 charge = MC::charge(id);
142
143 Amg::Translation3D prodSurfaceCentre( prodVertexVector.x(),
144 prodVertexVector.y(),
145 prodVertexVector.z() );
146
147 Amg::Transform3D tmpTransf = prodSurfaceCentre * Amg::RotationMatrix3D::Identity();
148
149 Trk::PlaneSurface planeSurface(tmpTransf, 5., 5. );
150 result = new Trk::AtaPlane(globalPos, globalMom, charge, planeSurface);
151
152 } else {
153 ATH_MSG_WARNING ("Could not get particle data for particle ID="<<id);
154 }
155 return result;
156}
157
158
159
160//================================================================
162 const Trk::TrackParameters* generatedTrackPerigee = nullptr;
163
164 if(part && part->production_vertex() && m_extrapolator) {
165
166 MsgStream log(msgSvc(), name());
167
168 std::unique_ptr<const Trk::TrackParameters> productionVertexTrackParams( makeProdVertexParameters(part) );
169 if(productionVertexTrackParams) {
170
171 // Extrapolate the TrackParameters object to the perigee. Direct extrapolation,
172 // no material effects.
173 generatedTrackPerigee =
174 m_extrapolator->extrapolateDirectly(Gaudi::Hive::currentContext(),
175 *productionVertexTrackParams,
178 false,
179 Trk::nonInteracting).release();
180 }
181 }
182
183 return generatedTrackPerigee;
184}
185
186//================================================================
188 const Trk::TrackParameters* generatedTrackPerigee = nullptr;
189
190 if(part && part->hasProdVtx() && m_extrapolator) {
191
192 MsgStream log(msgSvc(), name());
193
194 std::unique_ptr<const Trk::TrackParameters> productionVertexTrackParams( makeProdVertexParameters(part) );
195 if(productionVertexTrackParams) {
196
197 // Extrapolate the TrackParameters object to the perigee. Direct extrapolation,
198 // no material effects.
199 generatedTrackPerigee =
200 m_extrapolator->extrapolateDirectly(Gaudi::Hive::currentContext(),
201 *productionVertexTrackParams,
204 false,
205 Trk::nonInteracting).release();
206 }
207 }
208
209 return generatedTrackPerigee;
210}
211//================================================================
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
ATLAS-specific HepMC functions.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Class describing the Line to which the Perigee refers to.
Class for a planaer rectangular or trapezoidal surface in the ATLAS detector.
ToolHandle< Trk::IExtrapolator > m_extrapolator
SG::ReadHandleKey< TrackRecordCollection > m_reccollkey
TruthTrackRecordToTrack(const std::string &type, const std::string &name, const IInterface *parent)
virtual const Trk::TrackParameters * makeProdVertexParameters(HepMC::ConstGenParticlePtr part) const
This function produces a Trk::TrackParameters object corresponding to the HepMC::GenParticle at the p...
virtual const Trk::TrackParameters * makePerigeeParameters(HepMC::ConstGenParticlePtr part) const
This function extrapolates track to the perigee, and returns perigee parameters.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
double charge(const T &p)
@ anyDirection
ParametersBase< TrackParametersDim, Charged > TrackParameters
ParametersT< TrackParametersDim, Charged, PlaneSurface > AtaPlane
TruthParticle_v1 TruthParticle
Typedef to implementation.