ATLAS Offline Software
TruthGuidedProtoTrackCreatorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
7 #include "Acts/Surfaces/PerigeeSurface.hpp"
8 #include "TruthUtils/AtlasPID.h"
9 
10 
12  const std::string& name,
13  const IInterface* parent)
14  : base_class(type,name,parent)
15 {}
16 
18 {
19  ATH_CHECK( m_prdMultiTruthCollectionNames.initialize() );
20  return StatusCode::SUCCESS;
21 }
22 
26  std::vector<ActsTrk::ProtoTrack> & foundProtoTracks ) const {
27 
28  // Read the PRD information
29  std::vector<const PRD_MultiTruthCollection*> prdMultiTruthCollections;
30  prdMultiTruthCollections.reserve(m_prdMultiTruthCollectionNames.size());
31  // load the PRD collections from SG
32  for(const auto& pmtCollNameIter:m_prdMultiTruthCollectionNames)
33  {
34  // try to retrieve the PRD multi truth collection
35  SG::ReadHandle<PRD_MultiTruthCollection> curColl (pmtCollNameIter, ctx);
36  if (!curColl.isValid())
37  {
38  ATH_MSG_WARNING("Could not retrieve " << pmtCollNameIter << ". Ignoring ... ");
39  }
40  else
41  {
42  ATH_MSG_INFO("Added " << pmtCollNameIter << " to collection list for truth track creation.");
43  prdMultiTruthCollections.push_back(curColl.cptr());
44  }
45  }
46 
47  // create the map for the ine
48  std::map<Identifier, HepMC::ConstGenParticlePtr> identToHepMCMap;
49  for (auto & PRD_truthCollec: prdMultiTruthCollections )
50  {
51  // loop over the map and get the identifier, GenParticle relation
52  PRD_MultiTruthCollection::const_iterator prdMtCIter = PRD_truthCollec->begin();
53  PRD_MultiTruthCollection::const_iterator prdMtCIterE = PRD_truthCollec->end();
54  for ( ; prdMtCIter != prdMtCIterE; ++ prdMtCIter ){
55 
56  // check if entry exists and if
57 #ifdef HEPMC3
58  HepMC::ConstGenParticlePtr curGenP = (*prdMtCIter).second.scptr();
59 #else
60 //AV Looks like an implicit conversion
61  HepMC::ConstGenParticlePtr curGenP = (*prdMtCIter).second;
62 #endif
63  Identifier curIdentifier = (*prdMtCIter).first;
64 
65  // Min pT cut
66  if ( curGenP->momentum().perp() < 500. ) continue;
67 
68 
69 
70  identToHepMCMap[curIdentifier] = curGenP;
71  }
72  }
73 
74  // Now loop over the pixel and strip container and make collectiong
75  std::map<HepMC::ConstGenParticlePtr, std::vector<ActsTrk::ATLASUncalibSourceLink>> trackCollections;
76 
77  for(const auto cluster: pixelContainer)
78  {
79  // Get the idetifier list for the RDOs
80  auto identifierList = cluster->rdoList();
81 
82  // Loop and push back the cluster in the corresponding trith particle
83  for(auto& id: identifierList)
84  {
85  // Found a match, so push it into the track collection
86  if(identToHepMCMap.find(id) != identToHepMCMap.end())
87  {
88  auto truthParticle = identToHepMCMap.at(id);
89  trackCollections[truthParticle].emplace_back(makeATLASUncalibSourceLink(&pixelContainer, cluster, ctx));
90  }
91  }
92  }
93 
94  for(const auto cluster: stripContainer)
95  {
96  // Get the idetifier list for the RDOs
97  auto identifierList = cluster->rdoList();
98 
99  // Loop and push back the cluster in the corresponding trith particle
100  for(auto& id: identifierList)
101  {
102  // Found a match, so push it into the track collection
103  if(identToHepMCMap.find(id) != identToHepMCMap.end())
104  {
105  auto truthParticle = identToHepMCMap.at(id);
106  trackCollections[truthParticle].emplace_back(makeATLASUncalibSourceLink(&stripContainer, cluster, ctx));
107  }
108  }
109  }
110 
111  for(const auto& var: trackCollections)
112  {
113  // Skip if we find less than 3 clusters per truth track
114  if(var.second.size() < 3) continue;
115 
116  // Make the intput perigee
117  auto inputPerigee = makeDummyParams(var.first);
118  ATH_MSG_INFO("Found " << var.second.size() << " clusters for truth partcle "<<var.first);
119  foundProtoTracks.push_back({var.second,std::move(inputPerigee)});
120  }
121 
122  // and add to the list (will only make one prototrack per event for now)
123 
124  return StatusCode::SUCCESS;
125 }
126 
127 
128 std::unique_ptr<Acts::BoundTrackParameters>
130 
131  using namespace Acts::UnitLiterals;
132  std::shared_ptr<const Acts::Surface> actsSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(
133  Acts::Vector3(0., 0., 0.));
134  Acts::BoundVector params;
135 
136 
137  // No, this is not a physically correct parameter estimate!
138  // We just want a placeholder to point in roughly the expected direction...
139  // A real track finder would do something more reasonable here.
140  params << 0., 0.,
141  truthParticle->momentum().phi(), truthParticle->momentum().theta(),
142  static_cast<float>(::charge(truthParticle)) / (truthParticle->momentum().e()), 0.;
143 
144 
145  // Covariance - let's be honest and say we have no clue ;-)
146  Acts::BoundSquareMatrix cov = Acts::BoundSquareMatrix::Identity();
147  cov *= 100000;
148 
149  // some ACTS paperwork
150  Trk::ParticleHypothesis hypothesis = Trk::pion;
152  Acts::PdgParticle absPdg = Acts::makeAbsolutePdgParticle(Acts::ePionPlus);
153  Acts::ParticleHypothesis actsHypothesis{
154  absPdg, mass, Acts::AnyCharge{static_cast<float>(::charge(truthParticle))}};
155 
156  return std::make_unique<Acts::BoundTrackParameters>(actsSurface, params,
157  cov, actsHypothesis);
158 
159 }
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
ActsTrk::TruthGuidedProtoTrackCreatorTool::findProtoTracks
virtual StatusCode findProtoTracks(const EventContext &ctx, const xAOD::PixelClusterContainer &pixelContainer, const xAOD::StripClusterContainer &stripContainer, std::vector< ActsTrk::ProtoTrack > &foundProtoTracks) const override final
EF-style pattern recognition to create prototracks.
Definition: TruthGuidedProtoTrackCreatorTool.cxx:23
ActsTrk::TruthGuidedProtoTrackCreatorTool::makeDummyParams
std::unique_ptr< Acts::BoundTrackParameters > makeDummyParams(const HepMC::ConstGenParticlePtr &truthParticle) const
creates a random, dummy set of parameters Warning: This is not a real parameter estimate.
Definition: TruthGuidedProtoTrackCreatorTool.cxx:129
DataPrepToActsConfig.stripContainer
stripContainer
Definition: DataPrepToActsConfig.py:10
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:25
ActsTrk::makeATLASUncalibSourceLink
ATLASUncalibSourceLink makeATLASUncalibSourceLink(const xAOD::UncalibratedMeasurementContainer *container, std::size_t index, [[maybe_unused]] const EventContext &ctx)
Definition: ATLASSourceLink.h:30
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::pion
@ pion
Definition: ParticleHypothesis.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ActsTrk::TruthGuidedProtoTrackCreatorTool::TruthGuidedProtoTrackCreatorTool
TruthGuidedProtoTrackCreatorTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TruthGuidedProtoTrackCreatorTool.cxx:11
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ParticleHypothesis.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ActsTrk::TruthGuidedProtoTrackCreatorTool::initialize
virtual StatusCode initialize() override
Definition: TruthGuidedProtoTrackCreatorTool.cxx:17
Trk::ParticleMasses::mass
constexpr double mass[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:53
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
charge
double charge(const T &p)
Definition: AtlasPID.h:756
xAOD::ParticleHypothesis
ParticleHypothesis
Definition: TrackingPrimitives.h:192
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TruthGuidedProtoTrackCreatorTool.h
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
DataPrepToActsConfig.pixelContainer
pixelContainer
Definition: DataPrepToActsConfig.py:9
AtlasPID.h
Identifier
Definition: IdentifierFieldParser.cxx:14