ATLAS Offline Software
Loading...
Searching...
No Matches
TrackCollectionCnvTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// EDM include(s):
6// $Id$
10
11// Local include(s):
13
14namespace xAODMaker {
15
17 const std::string& name,
18 const IInterface* parent )
19 : AthAlgTool( type, name, parent ),
20 m_particleCreator("Trk::TrackParticleCreatorTool/TrackParticleCreatorTool")
21 {
22
23 // Declare the interface(s) provided by the tool:
24 declareInterface< ITrackCollectionCnvTool >( this );
25 declareProperty("TrackParticleCreator", m_particleCreator, "creator of xAOD::TrackParticles");
26 }
27
29 // Greet the user:
30 ATH_MSG_INFO( "Initializing TrackCollectionCnvTool with " << m_particleCreator.name() );
31 ATH_CHECK( m_particleCreator.retrieve() );
32
33 return StatusCode::SUCCESS;
34 }
35
37 xAOD::TrackParticleContainer* xaod, const xAOD::Vertex* vtx ) const {
38
39 ATH_MSG_DEBUG( "Sizes of containers before conversion: aod, xaod: " << aod->size() << ", " << xaod->size() );
40
43
44 for( ;itr!=end;++itr ) {
45 // Create the xAOD object:
46 if (!(*itr)) {
47 ATH_MSG_WARNING("Empty element in container!");
48 continue;
49 }
50 xAOD::TrackParticle* particle = createParticle(*xaod, *aod, **itr, vtx);
51
52 if (!particle) {
53 ATH_MSG_WARNING("Failed to create a TrackParticle");
54 continue;
55 }
56 }
57
58 ATH_MSG_DEBUG( "Sizes of containers after conversion: aod, xaod: " << aod->size() << ", " << xaod->size() );
59
60 return StatusCode::SUCCESS;
61 }
62
64 xAOD::TrackParticleContainer* xaod, const ObservedTrackMap* trk_map, const xAOD::Vertex* vtx ) const {
65
66 ATH_MSG_DEBUG( "convertAndAugment: Sizes of containers before conversion: aod, xaod: " << aod->size() << ", " << xaod->size() );
67 ATH_MSG_DEBUG( "convertAndAugment: Size of track map: " << trk_map->size() );
68
71 ObservedTrackMap::const_iterator itrMap = trk_map->begin();
72
73 // Check size of track collection matches size of observed tracks map
74 if(aod->size() != trk_map->size()){
75 ATH_MSG_ERROR("convertAndAugment: Number of tracks different in collection to convert vs. observed tracks map: "<<aod->size()<<" vs. "<<trk_map->size());
76 return StatusCode::FAILURE;
77 }
78
79 for( ;itr!=end;++itr ) {
80 // Create the xAOD object:
81 if (!(*itr)) {
82 ATH_MSG_WARNING("convertAndAugment: Empty element in container!");
83 continue;
84 }
85 xAOD::TrackParticle* particle = createParticle(*xaod, *aod, **itr, vtx);
86 if(!particle){
87 ATH_MSG_WARNING("convertAndAugment: Failed to create a TrackParticle");
88 ++itrMap;
89 continue;
90 }
91 // Augment xAOD object with information from track map
92 static const SG::Decorator<long int> IdDec ("Id");
93 IdDec (*particle) = (*itrMap).first;
94
95#define DECORATE2(NAME, SEL, TYPE) \
96 static const SG::Decorator<TYPE> NAME##Dec (#NAME); \
97 NAME##Dec(*particle) = std::get<xAOD::ObserverToolIndex::SEL>((*itrMap).second)
98#define DECORATE(NAME, TYPE) DECORATE2(NAME, NAME, TYPE)
99 DECORATE(score, double);
100 DECORATE(rejectStep, int);
101 DECORATE(rejectReason, int);
102 DECORATE(parentId, long int);
103 DECORATE(numPixelHoles, int);
104 DECORATE(numSCTHoles, int);
105 DECORATE(numSplitSharedPixel, int);
106 DECORATE(numSplitSharedSCT, int);
107 DECORATE(numSharedOrSplit, int);
108 DECORATE(numSharedOrSplitPixels, int);
109 DECORATE(numShared, int);
110 DECORATE(isPatternTrack, int);
111 DECORATE(totalSiHits, int);
112 DECORATE(inROI, int);
113 DECORATE2(thishasblayer, hasIBLHit, int);
114 DECORATE2(hassharedblayer, hasSharedIBLHit, int);
115 DECORATE2(hassharedpixel, hasSharedPixel, int);
116 DECORATE2(firstisshared, firstPixIsShared, int);
117 DECORATE(numPixelDeadSensor, int);
118 DECORATE(numSCTDeadSensor, int);
119 DECORATE(numPixelHits, int);
120 DECORATE(numSCTHits, int);
121 DECORATE(numUnused, int);
122 DECORATE(numTRT_Unused, int);
123 DECORATE(numSCT_Unused, int);
124 DECORATE(numPseudo, int);
125 DECORATE(averageSplit1, int);
126 DECORATE(averageSplit2, int);
127 DECORATE(numWeightedShared, int);
128#undef DECORATE
129#undef DECORATE2
130
131 const std::vector<xAOD::RejectionStep>& v_rejectStep =
132 std::get<xAOD::ObserverToolIndex::rejectStep_full>((*itrMap).second);
133 const std::vector<xAOD::RejectionReason>& v_rejectReason =
134 std::get<xAOD::ObserverToolIndex::rejectReason_full>((*itrMap).second);
135 static const SG::Decorator<std::vector<int> > rejectStep_fullDec ("rejectStep_full");
136 static const SG::Decorator<std::vector<int> > rejectReason_fullDec ("rejectReason_full");
137 rejectStep_fullDec(*particle).assign (v_rejectStep.begin(), v_rejectStep.end());
138 rejectReason_fullDec(*particle).assign (v_rejectReason.begin(), v_rejectReason.end());
139 ATH_MSG_DEBUG("convertAndAugment: Augmenting TrackParticle with id "
140 << IdDec(*particle) << " and rejectReason "
141 << rejectReasonDec(*particle)
142 << " (has chi2 = " << particle->chiSquared() << ")");
143 ++itrMap;
144 }
146 "convertAndAugment: Sizes of containers after conversion: aod, xaod: "
147 << aod->size() << ", " << xaod->size());
148 return StatusCode::SUCCESS;
149 }
150
153 const Trk::Track& tp,
154 const xAOD::Vertex* vtx) const {
155 // create the xAOD::TrackParticle, the pointer is added to the container in the function
156 ElementLink<TrackCollection> trackLink( &tp, container );
157 return m_particleCreator->createParticle( trackLink, &xaod , vtx);
158 //no! return m_particleCreator->createParticle( tp, &xaod );
159 }
160
161 StatusCode TrackCollectionCnvTool::setParticleCreatorTool(ToolHandle<Trk::ITrackParticleCreatorTool> *tool)
162 {
163 ATH_MSG_DEBUG( "In setParticleCreatorTool" );
164 m_particleCreator = *tool;
165
166 return StatusCode::SUCCESS;
167 }
168
169} // namespace xAODMaker
170
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::map< int, std::tuple< Trk::Track *, double, xAOD::RejectionStep, xAOD::RejectionReason, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, float, float, int, std::vector< xAOD::RejectionStep >, std::vector< xAOD::RejectionReason > > > ObservedTrackMap
#define DECORATE(NAME, TYPE)
#define DECORATE2(NAME, SEL, TYPE)
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
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)
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Helper class to provide type-safe access to aux data.
Definition Decorator.h:59
virtual StatusCode setParticleCreatorTool(ToolHandle< Trk::ITrackParticleCreatorTool > *tool) override
allow other algorithms to pass the tool in order to preserve initialisation
TrackCollectionCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
virtual StatusCode initialize() override
Function initialising the tool.
virtual StatusCode convert(const TrackCollection *aod, xAOD::TrackParticleContainer *xaod, const xAOD::Vertex *vtx=nullptr) const override
Function that fills an existing xAOD::TrackParticleContainer.
virtual StatusCode convertAndAugment(const TrackCollection *aod, xAOD::TrackParticleContainer *xaod, const ObservedTrackMap *trk_map, const xAOD::Vertex *vtx=nullptr) const override
Function that fills an existing xAOD::TrackParticleContainer and augments track particles.
xAOD::TrackParticle * createParticle(xAOD::TrackParticleContainer &xaod, const TrackCollection &container, const Trk::Track &tp, const xAOD::Vertex *vtx) const
ToolHandle< Trk::ITrackParticleCreatorTool > m_particleCreator
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".