ATLAS Offline Software
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 
10 #include "AtlasHepMC/GenParticle.h"
11 #include "AtlasHepMC/GenVertex.h"
12 
14 #include "xAODTruth/TruthVertex.h"
15 
20 
21 
22 //================================================================
23 Trk::TruthTrackRecordToTrack::TruthTrackRecordToTrack(const std::string& type, const std::string& name,
24  const IInterface* 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 
49  Trk::TrackParameters *result = nullptr;
50  Amg::Vector3D prodVertexVector;
51  prodVertexVector.setZero();
52  Amg::Vector3D globalPos;
53  Amg::Vector3D globalMom;
54  int id=0;
55 
56  SG::ReadHandle<TrackRecordCollection> trackRecordCollection(m_reccollkey);
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 
116  SG::ReadHandle<TrackRecordCollection> trackRecordCollection(m_reccollkey);
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 //================================================================
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
Trk::anyDirection
@ anyDirection
Definition: PropDirection.h:22
Trk::TruthTrackRecordToTrack::TruthTrackRecordToTrack
TruthTrackRecordToTrack(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TruthTrackRecordToTrack.cxx:23
get_generator_info.result
result
Definition: get_generator_info.py:21
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
GenVertex.h
Trk::TruthTrackRecordToTrack::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: TruthTrackRecordToTrack.cxx:45
Trk::TruthTrackRecordToTrack::initialize
virtual StatusCode initialize()
Definition: TruthTrackRecordToTrack.cxx:35
IExtrapolator.h
HepMC::is_same_particle
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
Definition: MagicNumbers.h:354
GenParticle.h
AtlasHitsVector::empty
bool empty() const
Definition: AtlasHitsVector.h:129
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TruthVertex.h
TrackRecord.h
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
Trk::TruthTrackRecordToTrack::m_reccollkey
SG::ReadHandleKey< TrackRecordCollection > m_reccollkey
Definition: TruthTrackRecordToTrack.h:66
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MagicNumbers.h
Trk::nonInteracting
@ nonInteracting
Definition: ParticleHypothesis.h:25
charge
double charge(const T &p)
Definition: AtlasPID.h:538
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::TruthTrackRecordToTrack::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: TruthTrackRecordToTrack.h:65
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::PlaneSurface
Definition: PlaneSurface.h:64
Trk::TruthTrackRecordToTrack::makePerigeeParameters
virtual const Trk::TrackParameters * makePerigeeParameters(HepMC::ConstGenParticlePtr part) const
This function extrapolates track to the perigee, and returns perigee parameters.
Definition: TruthTrackRecordToTrack.cxx:161
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
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
AthAlgTool
Definition: AthAlgTool.h:26
TruthParticle.h
TruthTrackRecordToTrack.h
HepMCHelpers.h