ATLAS Offline Software
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):
12 #include "TrackCollectionCnvTool.h"
13 
14 namespace 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);
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);
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);
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 
152  const TrackCollection& container,
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" );
165 
166  return StatusCode::SUCCESS;
167  }
168 
169 } // namespace xAODMaker
170 
xAOD::numSharedOrSplit
@ numSharedOrSplit
Definition: TrackingPrimitives.h:521
xAOD::hasIBLHit
@ hasIBLHit
Definition: TrackingPrimitives.h:527
xAOD::numWeightedShared
@ numWeightedShared
Definition: TrackingPrimitives.h:541
xAOD::numUnused
@ numUnused
Definition: TrackingPrimitives.h:535
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAOD::isPatternTrack
@ isPatternTrack
Definition: TrackingPrimitives.h:524
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
xAOD::averageSplit2
@ averageSplit2
Definition: TrackingPrimitives.h:540
xAOD::hasSharedIBLHit
@ hasSharedIBLHit
Definition: TrackingPrimitives.h:528
xAODMaker::TrackCollectionCnvTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition: TrackCollectionCnvTool.cxx:28
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::numSplitSharedPixel
@ numSplitSharedPixel
Definition: TrackingPrimitives.h:519
xAODMaker::TrackCollectionCnvTool::convert
virtual StatusCode convert(const TrackCollection *aod, xAOD::TrackParticleContainer *xaod, const xAOD::Vertex *vtx=nullptr) const override
Function that fills an existing xAOD::TrackParticleContainer.
Definition: TrackCollectionCnvTool.cxx:36
xAOD::numPseudo
@ numPseudo
Definition: TrackingPrimitives.h:538
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD::firstPixIsShared
@ firstPixIsShared
Definition: TrackingPrimitives.h:530
xAODMaker
Definition: StoreGateSvc.h:72
xAODMaker::TrackCollectionCnvTool::setParticleCreatorTool
virtual StatusCode setParticleCreatorTool(ToolHandle< Trk::ITrackParticleCreatorTool > *tool) override
allow other algorithms to pass the tool in order to preserve initialisation
Definition: TrackCollectionCnvTool.cxx:161
xAOD::hasSharedPixel
@ hasSharedPixel
Definition: TrackingPrimitives.h:529
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
ObservedTrackMap
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
Definition: ObservedTrackMap.h:50
xAOD::numSCTDeadSensor
@ numSCTDeadSensor
Definition: TrackingPrimitives.h:532
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
xAODMaker::TrackCollectionCnvTool::convertAndAugment
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.
Definition: TrackCollectionCnvTool.cxx:63
xAODMaker::TrackCollectionCnvTool::m_particleCreator
ToolHandle< Trk::ITrackParticleCreatorTool > m_particleCreator
Definition: TrackCollectionCnvTool.h:50
xAOD::totalSiHits
@ totalSiHits
Definition: TrackingPrimitives.h:525
xAOD::numPixelHits
@ numPixelHits
Definition: TrackingPrimitives.h:533
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
TrackCollection.h
xAOD::numSharedOrSplitPixels
@ numSharedOrSplitPixels
Definition: TrackingPrimitives.h:522
xAOD::numSCTHits
@ numSCTHits
Definition: TrackingPrimitives.h:534
TrackCollectionCnvTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::rejectStep
@ rejectStep
Definition: TrackingPrimitives.h:514
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::numSCT_Unused
@ numSCT_Unused
Definition: TrackingPrimitives.h:537
DataVector< Trk::Track >
xAOD::inROI
@ inROI
Definition: TrackingPrimitives.h:526
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
xAOD::averageSplit1
@ averageSplit1
Definition: TrackingPrimitives.h:539
xAOD::score
@ score
Definition: TrackingPrimitives.h:513
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TrackParticle.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
DECORATE2
#define DECORATE2(NAME, SEL, TYPE)
xAOD::parentId
@ parentId
Definition: TrackingPrimitives.h:516
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::rejectReason
@ rejectReason
Definition: TrackingPrimitives.h:515
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DECORATE
#define DECORATE(NAME, TYPE)
xAOD::numPixelHoles
@ numPixelHoles
Definition: TrackingPrimitives.h:517
xAODMaker::TrackCollectionCnvTool::createParticle
xAOD::TrackParticle * createParticle(xAOD::TrackParticleContainer &xaod, const TrackCollection &container, const Trk::Track &tp, const xAOD::Vertex *vtx) const
Definition: TrackCollectionCnvTool.cxx:151
xAOD::numTRT_Unused
@ numTRT_Unused
Definition: TrackingPrimitives.h:536
xAOD::numSCTHoles
@ numSCTHoles
Definition: TrackingPrimitives.h:518
xAOD::numSplitSharedSCT
@ numSplitSharedSCT
Definition: TrackingPrimitives.h:520
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAODMaker::TrackCollectionCnvTool::TrackCollectionCnvTool
TrackCollectionCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
Definition: TrackCollectionCnvTool.cxx:16
AthAlgTool
Definition: AthAlgTool.h:26
xAOD::numShared
@ numShared
Definition: TrackingPrimitives.h:523
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrackParticleContainer.h
xAOD::numPixelDeadSensor
@ numPixelDeadSensor
Definition: TrackingPrimitives.h:531
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.