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