ATLAS Offline Software
TrackHitAssignementAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // TrackHitAssignement includes
7 
8 
9 TrackHitAssignementAlg::TrackHitAssignementAlg( const std::string& name, ISvcLocator* pSvcLocator ) : AthReentrantAlgorithm( name, pSvcLocator ){
10 }
11 
12 
14 
15 
17  ATH_MSG_INFO ("Initializing " << name() << "...");
19  ATH_CHECK(m_JetPixelCluster.initialize());
20  ATH_CHECK(m_JetSCTCluster.initialize());
21  ATH_CHECK(m_TrackCollection.initialize());
22  ATH_CHECK(m_JetPixelClusterHits.initialize());
23  ATH_CHECK(m_JetSCTClusterHits.initialize());
26 
27  return StatusCode::SUCCESS;
28 }
29 
30 StatusCode TrackHitAssignementAlg::execute(const EventContext& context) const {
31  ATH_MSG_DEBUG ("Executing " << name() << "...");
32  //Read needed Containers to decorate
33  //and check if valid
37 
42 
43  if(!JetPixelCluster.isValid()){
44  ATH_MSG_ERROR ("Couldn't find Pixel");
45  return StatusCode::FAILURE;
46  }
47  if(!JetSCTCluster.isValid()){
48  ATH_MSG_ERROR ("Couldn't find SCT");
49  return StatusCode::FAILURE;
50  }
51  if(!tracks.isValid()){
52  ATH_MSG_ERROR ("Couldn't find tracks");
53  return StatusCode::FAILURE;
54  }
55 
56  std::multimap<uint64_t, const xAOD::TrackParticle*> track_hits;
57 
58  //go from tracks to hits and save the hits used for reconstruction in a map
59  for(const auto trk:*tracks){
60  auto trkTrk_link = trk->trackLink();
61  if (trkTrk_link.isValid()){
62  auto trkTrk = *trkTrk_link;
63  auto states = trkTrk->trackStateOnSurfaces();
64  for(const auto state:*states){
65  if (!state->type(Trk::TrackStateOnSurface::Measurement)){
66  continue;
67  }
68  auto hitOnTrack = state->measurementOnTrack();
69  if(hitOnTrack->type(Trk::MeasurementBaseType::RIO_OnTrack)){
70  const Trk::RIO_OnTrack* hit = dynamic_cast <const Trk::RIO_OnTrack*>( hitOnTrack ) ;
71  const Trk::PrepRawData* prd = hit->prepRawData() ;
72  Identifier ident_hit = prd->identify();
73  track_hits.emplace(ident_hit.get_compact(), trk);
74  }
75  }
76  }
77  }
78 
79 
80  // run through SCT/Pixel Clusters and check if hit is in map
81  // if yes, add also ElementLink
83 
84  for(const xAOD::TrackMeasurementValidation* hit: *JetSCTCluster){
85  std::pair<MMAPIterator, MMAPIterator> result = track_hits.equal_range(hit->identifier());
86  int count = std::distance(result.first, result.second);
87  std::vector<ElementLink<xAOD::TrackParticleContainer>> vec_ElemLink_SCT;
88  if(count == 0){
89  JetSCTClusterHits(*hit)=0;
90  }
91  else{
92  JetSCTClusterHits(*hit)=1;
93  for (MMAPIterator it = result.first; it != result.second; ++it){
94  vec_ElemLink_SCT.push_back(ElementLink<xAOD::TrackParticleContainer> ((it->second),*tracks, context));
95  }
96  }
97  JetSCTClusterTrackAssocs(*hit)=vec_ElemLink_SCT;
98  }
99 
100  for(const xAOD::TrackMeasurementValidation* hit: *JetPixelCluster){
101  std::pair<MMAPIterator, MMAPIterator> result = track_hits.equal_range(hit->identifier());
102  int count = std::distance(result.first, result.second);
103  std::vector<ElementLink<xAOD::TrackParticleContainer>> vec_ElemLink_pix;
104  if(count == 0){
105  JetPixelClusterHits(*hit)=0;
106  }
107  else{
108  JetPixelClusterHits(*hit)=1;
109  for (MMAPIterator it = result.first; it != result.second; ++it){
110  vec_ElemLink_pix.push_back(ElementLink<xAOD::TrackParticleContainer> ((it->second),*tracks, context));
111  }
112  }
113  JetPixelClusterTrackAssocs(*hit)=vec_ElemLink_pix;
114  }
115  return StatusCode::SUCCESS;
116 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TrackHitAssignementAlg::m_tracks
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracks
Definition: TrackHitAssignementAlg.h:35
get_generator_info.result
result
Definition: get_generator_info.py:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Identifier::get_compact
value_type get_compact() const
Get the compact id.
TrackHitAssignementAlg::m_JetSCTClusterHits
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_JetSCTClusterHits
Definition: TrackHitAssignementAlg.h:42
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
TrackHitAssignementAlg::m_JetPixelClusterTrackAssocs
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_JetPixelClusterTrackAssocs
Definition: TrackHitAssignementAlg.h:43
TrackHitAssignementAlg::initialize
virtual StatusCode initialize() override
Definition: TrackHitAssignementAlg.cxx:16
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
TrackHitAssignementAlg::m_JetPixelCluster
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_JetPixelCluster
Definition: TrackHitAssignementAlg.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAOD::TrackMeasurementValidation_v1
Class describing a TrackMeasurementValidation.
Definition: TrackMeasurementValidation_v1.h:27
TrackHitAssignementAlg::m_JetPixelClusterHits
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_JetPixelClusterHits
Definition: TrackHitAssignementAlg.h:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackHitAssignementAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrackHitAssignementAlg.cxx:30
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
urldecode::states
states
Definition: urldecode.h:39
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
TrackHitAssignementAlg::TrackHitAssignementAlg
TrackHitAssignementAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackHitAssignementAlg.cxx:9
TrackHitAssignementAlg.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrackHitAssignementAlg::m_TrackCollection
SG::ReadHandleKey< TrackCollection > m_TrackCollection
Definition: TrackHitAssignementAlg.h:36
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Trk::PrepRawData
Definition: PrepRawData.h:62
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trk::RIO_OnTrack::prepRawData
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
Trk::MeasurementBaseType::RIO_OnTrack
@ RIO_OnTrack
Definition: MeasurementBase.h:49
TrackHitAssignementAlg::m_JetSCTClusterTrackAssocs
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_JetSCTClusterTrackAssocs
Definition: TrackHitAssignementAlg.h:44
TrackHitAssignementAlg::~TrackHitAssignementAlg
virtual ~TrackHitAssignementAlg()
Definition: TrackHitAssignementAlg.cxx:13
TrackHitAssignementAlg::m_JetSCTCluster
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_JetSCTCluster
Definition: TrackHitAssignementAlg.h:39
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
Identifier
Definition: IdentifierFieldParser.cxx:14