ATLAS Offline Software
Loading...
Searching...
No Matches
ActsTrk::TruthTrackBuilderTool Class Referencefinal

#include <TruthTrackBuilderTool.h>

Inheritance diagram for ActsTrk::TruthTrackBuilderTool:
Collaboration diagram for ActsTrk::TruthTrackBuilderTool:

Classes

struct  TruthHit

Public Types

using Vector3 = Eigen::Vector3f
using TruthHits = std::vector<TruthHit>
using TruthTracks = std::unordered_map<const xAOD::TruthParticle*, TruthHits>

Public Member Functions

 TruthTrackBuilderTool (const std::string &type, const std::string &name, const IInterface *parent)
StatusCode initialize () override
StatusCode buildTruthTracks (const EventContext &ctx, TruthTracks &truthTracks) const
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvc > StoreGateSvc_t

Private Member Functions

template<typename ClusterContainer>
void addClusterToTruthTracks (const ClusterContainer &clusters, const MeasurementToTruthParticleAssociation &truthAssociations, TruthTracks &truthTracks) const
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

SG::ReadHandleKey< xAOD::PixelClusterContainer > m_pixelClustersKey
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_pixelTruthAssociationKey
SG::ReadHandleKey< xAOD::StripClusterContainer > m_stripClustersKey
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_stripTruthAssociationKey
Gaudi::Property< bool > m_usePixelClusters
Gaudi::Property< bool > m_useStripClusters
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default).
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default).
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 19 of file TruthTrackBuilderTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

◆ TruthHits

Definition at line 31 of file TruthTrackBuilderTool.h.

◆ TruthTracks

◆ Vector3

using ActsTrk::TruthTrackBuilderTool::Vector3 = Eigen::Vector3f

Definition at line 23 of file TruthTrackBuilderTool.h.

Constructor & Destructor Documentation

◆ TruthTrackBuilderTool()

ActsTrk::TruthTrackBuilderTool::TruthTrackBuilderTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Definition at line 11 of file TruthTrackBuilderTool.cxx.

14 : AthAlgTool(type, name, parent) {}
AthAlgTool()
Default constructor:

Member Function Documentation

◆ addClusterToTruthTracks()

template<typename ClusterContainer>
void ActsTrk::TruthTrackBuilderTool::addClusterToTruthTracks ( const ClusterContainer & clusters,
const MeasurementToTruthParticleAssociation & truthAssociations,
TruthTracks & truthTracks ) const
private

Definition at line 28 of file TruthTrackBuilderTool.cxx.

31 {
32
33 for (const auto* cluster : clusters) {
34
35 const auto& matchedTruthParticles = truthAssociations.at(cluster->index());
36
37 // if no truth particles for cluster, skip
38 if (matchedTruthParticles.empty()) {
39 ATH_MSG_WARNING("empty truth particle vector for cluster, skipping");
40 continue;
41 }
42
43 // only taking leading order truth particle
44 // (most likely to be the correct truth match as it has largest depsoit in
45 // cluster)
46 const xAOD::TruthParticle* truthParticle = matchedTruthParticles.front();
47
48 // obtain global position of cluster before upcasting (makes sorting easier)
49 const auto& globalPosition = cluster->globalPosition();
50 TruthHit hit{cluster, globalPosition};
51
52 truthTracks[truthParticle].push_back(hit);
53 }
54}
#define ATH_MSG_WARNING(x,...)
bool hit(const Container &ids, int pdgId)
TruthParticle_v1 TruthParticle
Typedef to implementation.

◆ buildTruthTracks()

StatusCode ActsTrk::TruthTrackBuilderTool::buildTruthTracks ( const EventContext & ctx,
TruthTracks & truthTracks ) const

Definition at line 56 of file TruthTrackBuilderTool.cxx.

57 {
58
59 // obtain truth map and clusters
60 // for every cluster, obtain its truth particle and add to map
61 // This can be optional for both pixel and strip clusters
63 SG::ReadHandle<xAOD::PixelClusterContainer> pixelClusters{
65
66 SG::ReadHandle<MeasurementToTruthParticleAssociation>
67 pixelTruthAssociations{m_pixelTruthAssociationKey, ctx};
68
69 if (!pixelClusters.isValid()) {
70
72 "Could not read pixel clusters: " << m_pixelClustersKey.key());
73 return StatusCode::FAILURE;
74 }
75
76 if (!pixelTruthAssociations.isValid()) {
77
78 ATH_MSG_ERROR("Could not read pixel truth associations: "
80 return StatusCode::FAILURE;
81 }
82
83 addClusterToTruthTracks(*pixelClusters, *pixelTruthAssociations,
84 truthTracks);
85 }
86
88
89 SG::ReadHandle<xAOD::StripClusterContainer> stripClusters{
91
92 SG::ReadHandle<MeasurementToTruthParticleAssociation>
93 stripTruthAssociations{m_stripTruthAssociationKey, ctx};
94
95 if (!stripClusters.isValid()) {
96
98 "Could not read strip clusters: " << m_stripClustersKey.key());
99 return StatusCode::FAILURE;
100 }
101
102 if (!stripTruthAssociations.isValid()) {
103
104 ATH_MSG_ERROR("Could not read strip truth associations: "
106 return StatusCode::FAILURE;
107 }
108
109 addClusterToTruthTracks(*stripClusters, *stripTruthAssociations,
110 truthTracks);
111 }
112
113 // reorder clusters for each associated truth particle
114 // This is done by ordering by distance away from truth particle production
115 // vertex (assuming small bending)
116 for (auto it = truthTracks.begin(); it != truthTracks.end();) {
117
118 auto& [truthParticle, truthClusters] = *it;
119
120 if (truthParticle == nullptr || !truthParticle->hasProdVtx()) {
121
123 "Truth particle does not have a production vertex, erasing");
124 it = truthTracks.erase(it);
125 continue;
126 }
127
128 const xAOD::TruthVertex* vertex = truthParticle->prodVtx();
129 const Vector3 vertexPosition{vertex->x(), vertex->y(), vertex->z()};
130 std::sort(truthClusters.begin(), truthClusters.end(),
131 [&vertexPosition](const TruthHit& firstCluster,
132 const TruthHit& secondCluster) {
133 const Vector3 firstClusterDis =
134 firstCluster.globalPosition - vertexPosition;
135 const Vector3 secondClusterDis =
136 secondCluster.globalPosition - vertexPosition;
137
138 const float firstClusterNorm = firstClusterDis.squaredNorm();
139 const float secondClusterNorm = secondClusterDis.squaredNorm();
140
141 return firstClusterNorm < secondClusterNorm;
142 });
143
144 ++it;
145 }
146
147 return StatusCode::SUCCESS;
148}
#define ATH_MSG_ERROR(x,...)
SG::ReadHandleKey< xAOD::StripClusterContainer > m_stripClustersKey
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_pixelClustersKey
Gaudi::Property< bool > m_useStripClusters
Gaudi::Property< bool > m_usePixelClusters
void addClusterToTruthTracks(const ClusterContainer &clusters, const MeasurementToTruthParticleAssociation &truthAssociations, TruthTracks &truthTracks) const
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_pixelTruthAssociationKey
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_stripTruthAssociationKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ initialize()

StatusCode ActsTrk::TruthTrackBuilderTool::initialize ( )
override

Definition at line 16 of file TruthTrackBuilderTool.cxx.

16 {
17
18 // initialize all the conatiners needed
19 ATH_CHECK(m_pixelClustersKey.initialize());
21 ATH_CHECK(m_stripClustersKey.initialize());
23
24 return StatusCode::SUCCESS;
25}
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, and AthCheckedComponent<::AthAlgTool >.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default).

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default).

Definition at line 390 of file AthCommonDataStore.h.

◆ m_pixelClustersKey

SG::ReadHandleKey<xAOD::PixelClusterContainer> ActsTrk::TruthTrackBuilderTool::m_pixelClustersKey
private
Initial value:
{
this, "PixelClusters", "ITkPixelClusters",
"Input reconstructed pixel clusters"}

Definition at line 47 of file TruthTrackBuilderTool.h.

47 {
48 this, "PixelClusters", "ITkPixelClusters",
49 "Input reconstructed pixel clusters"};

◆ m_pixelTruthAssociationKey

SG::ReadHandleKey<MeasurementToTruthParticleAssociation> ActsTrk::TruthTrackBuilderTool::m_pixelTruthAssociationKey
private
Initial value:
{
this, "PixelClustersToTruthAssociationMap",
"ITkPixelClustersToTruthParticles",
"Pixel cluster-to-truth-particle associations"}

Definition at line 51 of file TruthTrackBuilderTool.h.

51 {
52 this, "PixelClustersToTruthAssociationMap",
53 "ITkPixelClustersToTruthParticles",
54 "Pixel cluster-to-truth-particle associations"};

◆ m_stripClustersKey

SG::ReadHandleKey<xAOD::StripClusterContainer> ActsTrk::TruthTrackBuilderTool::m_stripClustersKey
private
Initial value:
{
this, "StripClusters", "ITkStripClusters",
"Input reconstructed strip clusters"}

Definition at line 56 of file TruthTrackBuilderTool.h.

56 {
57 this, "StripClusters", "ITkStripClusters",
58 "Input reconstructed strip clusters"};

◆ m_stripTruthAssociationKey

SG::ReadHandleKey<MeasurementToTruthParticleAssociation> ActsTrk::TruthTrackBuilderTool::m_stripTruthAssociationKey
private
Initial value:
{
this, "StripClustersToTruthAssociationMap",
"ITkStripClustersToTruthParticles",
"Strip cluster-to-truth-particle associations"}

Definition at line 60 of file TruthTrackBuilderTool.h.

60 {
61 this, "StripClustersToTruthAssociationMap",
62 "ITkStripClustersToTruthParticles",
63 "Strip cluster-to-truth-particle associations"};

◆ m_usePixelClusters

Gaudi::Property<bool> ActsTrk::TruthTrackBuilderTool::m_usePixelClusters
private
Initial value:
{this, "usePixelClusters", true,
"option for using pixel clusters"}

Definition at line 66 of file TruthTrackBuilderTool.h.

66 {this, "usePixelClusters", true,
67 "option for using pixel clusters"};

◆ m_useStripClusters

Gaudi::Property<bool> ActsTrk::TruthTrackBuilderTool::m_useStripClusters
private
Initial value:
{this, "useStripClusters", true,
"option for using strip clusters"}

Definition at line 68 of file TruthTrackBuilderTool.h.

68 {this, "useStripClusters", true,
69 "option for using strip clusters"};

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: