ATLAS Offline Software
SCTExtensionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "TrkTrack/Track.h"
11 
12 
13 
14 
16 SCTExtensionAlg::SCTExtensionAlg(const std::string& name, ISvcLocator* pSvcLocator) :
17  AthReentrantAlgorithm(name, pSvcLocator)
18 {
19  // Properties go here
20 }
21 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
23 
24  ATH_MSG_INFO ("initialize()");
25 
28 
29  return StatusCode::SUCCESS;
30 }
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
32 StatusCode SCTExtensionAlg::execute(const EventContext& ctx) const {
33 
35  if (not tracklets.isValid())
36  {
37  ATH_MSG_FATAL("Could not retrieve " << m_pixelTracklets.key());
38  return StatusCode::FAILURE;
39  }
40 
42  if (not trks.isValid())
43  {
44  ATH_MSG_FATAL("Could not retrieve " << m_tracks.key());
45  return StatusCode::FAILURE;
46  }
47 
49 
50  int n_tracks=0;
51  int n_tracklets=0;
52 
53  static const SG::Decorator< ElementLink< xAOD:: TrackParticleContainer > > MatchedTrackLinkDec("MatchedTrackLink");
54  static const SG::Decorator< int > MatchedTrackSharedHitsDec("MatchedTrackSharedHits");
55 
56  for (mytracklet = tracklets->begin(); mytracklet != tracklets->end(); ++mytracklet) // Loop over tracklets
57  {
58  n_tracklets++;
59  int nSharedHits=0;
60  const xAOD::TrackParticle* trackletParticle = *mytracklet;
61  const Trk::Track* tracklet = trackletParticle->track();
62  if(!tracklet)
63  return StatusCode::FAILURE;
64 
65  std::vector<const InDet::PixelCluster*> tracklet_pixelClusters;
66 
67  const DataVector<const Trk::MeasurementBase>* tracklet_measurements = tracklet->measurementsOnTrack();
68  for ( auto tracklet_measurement : *tracklet_measurements )
69  {
70  // find out if it is a pixel hit
71  const InDet::PixelClusterOnTrack* pixelClusterOnTracklet = dynamic_cast<const InDet::PixelClusterOnTrack*>(tracklet_measurement);
72  if( pixelClusterOnTracklet )
73  {
74  //Go back to the original pixel cluster
75  const InDet::PixelCluster* tracklet_pixelCluster = dynamic_cast<const InDet::PixelCluster*>( pixelClusterOnTracklet->prepRawData() );
76 
77  if( tracklet_pixelCluster )
78  {
79  // This is the pixel cluster that you would like to check if it contained in the other tracklet.
80  // to avoid doing this loop multiple time then would store these is a vector
81  tracklet_pixelClusters.push_back(tracklet_pixelCluster);
82  }
83  } // End: tracklet_PixelCluster
84  } // End: tracklet_Measurements
85 
87  for (mytrack = trks->begin(); mytrack != trks->end(); ++mytrack) // Loop over tracks for each tracklet
88  {
89  n_tracks++;
90  const xAOD::TrackParticle* trackParticle = *mytrack;
91  const Trk::Track* track = trackParticle->track();
92  if(!track)
93  return StatusCode::FAILURE;
94 
95  std::vector<const InDet::PixelCluster*> pixelClusters;
96 
97  const DataVector<const Trk::MeasurementBase>* measurements = track->measurementsOnTrack();
98  for ( auto measurement : *measurements )
99  {
100  // find out if it is a pixel hit
101  const InDet::PixelClusterOnTrack* pixelClusterOnTrack = dynamic_cast<const InDet::PixelClusterOnTrack*>(measurement);
102  if( pixelClusterOnTrack )
103  {
104  //Go back to the original pixel cluster
105  const InDet::PixelCluster* pixelCluster = dynamic_cast<const InDet::PixelCluster*>( pixelClusterOnTrack->prepRawData() );
106 
107  if( pixelCluster )
108  {
109  // This is the pixel cluster that you would like to check if it contained in the other track.
110  // to avoid doing this loop multiple time then would store these is a vector
111  pixelClusters.push_back(pixelCluster);
112  }
113  } // End: PixelCluster
114  } // End: Measurements
115 
116  int n_corr=0;
117  for (unsigned int i = 0; i < pixelClusters.size(); i++)
118  {
119  if ( std::find(tracklet_pixelClusters.begin(),tracklet_pixelClusters.end(),pixelClusters[i]) != tracklet_pixelClusters.end() )
120  n_corr++;
121  }
122  if (n_corr>0)
123  {
124  nSharedHits=n_corr;
125  ElementLink< xAOD:: TrackParticleContainer > eLink( *trks, trackParticle->index());
126  eLink.toPersistent();
127  MatchedTrackLinkDec(*trackletParticle) = eLink;
128 
129  break; //??? how many n_corr?
130 
131  }
132  } // End: Loop over tracks for each tracklet
133 
134  MatchedTrackSharedHitsDec(*trackletParticle) = nSharedHits;
135 
136 
137 
138  } // End: Loop over tracklets
139 
140  if (n_tracks==0 || n_tracklets==0) ATH_MSG_INFO("=========>>>>>>>>n_tracklets=" << n_tracklets << " =========>>>>>>>>n_tracks="<< n_tracks);
141 
142 
143  ATH_MSG_DEBUG ("Your new package and algorithm are successfully executing");
144 
145  return StatusCode::SUCCESS;
146 }
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
149 
150  ATH_MSG_INFO ("finalize()");
151 
152  return StatusCode::SUCCESS;
153 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
MeasurementBase.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
PixelCluster.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SCTExtensionAlg::SCTExtensionAlg
SCTExtensionAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SCTExtensionAlg.cxx:16
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SCTExtensionAlg::finalize
virtual StatusCode finalize() override
Definition: SCTExtensionAlg.cxx:148
SCTExtensionAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: SCTExtensionAlg.cxx:32
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Track.h
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
DataVector< const Trk::MeasurementBase >
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SCTExtensionAlg.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SCTExtensionAlg::initialize
virtual StatusCode initialize() override
Definition: SCTExtensionAlg.cxx:22
SCTExtensionAlg::m_pixelTracklets
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_pixelTracklets
Definition: SCTExtensionAlg.h:19
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Trk::Track::measurementsOnTrack
const DataVector< const MeasurementBase > * measurementsOnTrack() const
return a pointer to a vector of MeasurementBase (NOT including any that come from outliers).
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:178
Trk::pixelCluster
@ pixelCluster
Definition: MeasurementType.h:22
InDet::PixelClusterOnTrack::prepRawData
virtual const PixelCluster * prepRawData() const override final
returns the PrepRawData - is a SiCluster in this scope
Definition: PixelClusterOnTrack.h:179
SCTExtensionAlg::m_tracks
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracks
Definition: SCTExtensionAlg.h:20
InDet::PixelClusterOnTrack
Definition: PixelClusterOnTrack.h:51
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAOD::TrackParticle_v1::track
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
Definition: TrackParticle_v1.cxx:805
PixelClusterOnTrack.h
Decorator.h
Helper class to provide type-safe access to aux data.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.