ATLAS Offline Software
SCTExtensionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "TrkTrack/Track.h"
10 
11 
12 
13 
15 SCTExtensionAlg::SCTExtensionAlg(const std::string& name, ISvcLocator* pSvcLocator) :
16  AthReentrantAlgorithm(name, pSvcLocator)
17 {
18  // Properties go here
19 }
20 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
22 
23  ATH_MSG_INFO ("initialize()");
24 
27 
28  return StatusCode::SUCCESS;
29 }
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
31 StatusCode SCTExtensionAlg::execute(const EventContext& ctx) const {
32 
34  if (not tracklets.isValid())
35  {
36  ATH_MSG_FATAL("Could not retrieve " << m_pixelTracklets.key());
37  return StatusCode::FAILURE;
38  }
39 
41  if (not trks.isValid())
42  {
43  ATH_MSG_FATAL("Could not retrieve " << m_tracks.key());
44  return StatusCode::FAILURE;
45  }
46 
48 
49  int n_tracks=0;
50  int n_tracklets=0;
51 
52  for (mytracklet = tracklets->begin(); mytracklet != tracklets->end(); ++mytracklet) // Loop over tracklets
53  {
54  n_tracklets++;
55  int nSharedHits=0;
56  const xAOD::TrackParticle* trackletParticle = *mytracklet;
57  const Trk::Track* tracklet = trackletParticle->track();
58  if(!tracklet)
59  return StatusCode::FAILURE;
60 
61  std::vector<const InDet::PixelCluster*> tracklet_pixelClusters;
62 
63  const DataVector<const Trk::MeasurementBase>* tracklet_measurements = tracklet->measurementsOnTrack();
64  for ( auto tracklet_measurement : *tracklet_measurements )
65  {
66  // find out if it is a pixel hit
67  const InDet::PixelClusterOnTrack* pixelClusterOnTracklet = dynamic_cast<const InDet::PixelClusterOnTrack*>(tracklet_measurement);
68  if( pixelClusterOnTracklet )
69  {
70  //Go back to the original pixel cluster
71  const InDet::PixelCluster* tracklet_pixelCluster = dynamic_cast<const InDet::PixelCluster*>( pixelClusterOnTracklet->prepRawData() );
72 
73  if( tracklet_pixelCluster )
74  {
75  // This is the pixel cluster that you would like to check if it contained in the other tracklet.
76  // to avoid doing this loop multiple time then would store these is a vector
77  tracklet_pixelClusters.push_back(tracklet_pixelCluster);
78  }
79  } // End: tracklet_PixelCluster
80  } // End: tracklet_Measurements
81 
83  for (mytrack = trks->begin(); mytrack != trks->end(); ++mytrack) // Loop over tracks for each tracklet
84  {
85  n_tracks++;
86  const xAOD::TrackParticle* trackParticle = *mytrack;
87  const Trk::Track* track = trackParticle->track();
88  if(!track)
89  return StatusCode::FAILURE;
90 
91  std::vector<const InDet::PixelCluster*> pixelClusters;
92 
93  const DataVector<const Trk::MeasurementBase>* measurements = track->measurementsOnTrack();
94  for ( auto measurement : *measurements )
95  {
96  // find out if it is a pixel hit
97  const InDet::PixelClusterOnTrack* pixelClusterOnTrack = dynamic_cast<const InDet::PixelClusterOnTrack*>(measurement);
98  if( pixelClusterOnTrack )
99  {
100  //Go back to the original pixel cluster
101  const InDet::PixelCluster* pixelCluster = dynamic_cast<const InDet::PixelCluster*>( pixelClusterOnTrack->prepRawData() );
102 
103  if( pixelCluster )
104  {
105  // This is the pixel cluster that you would like to check if it contained in the other track.
106  // to avoid doing this loop multiple time then would store these is a vector
107  pixelClusters.push_back(pixelCluster);
108  }
109  } // End: PixelCluster
110  } // End: Measurements
111 
112  int n_corr=0;
113  for (unsigned int i = 0; i < pixelClusters.size(); i++)
114  {
115  if ( std::find(tracklet_pixelClusters.begin(),tracklet_pixelClusters.end(),pixelClusters[i]) != tracklet_pixelClusters.end() )
116  n_corr++;
117  }
118  if (n_corr>0)
119  {
120  nSharedHits=n_corr;
121  ElementLink< xAOD:: TrackParticleContainer > eLink( *trks, trackParticle->index());
122  eLink.toPersistent();
123  trackletParticle->auxdecor< ElementLink< xAOD:: TrackParticleContainer > >("MatchedTrackLink") = eLink;
124 
125  break; //??? how many n_corr?
126 
127  }
128  } // End: Loop over tracks for each tracklet
129 
130  trackletParticle->auxdecor<int>("MatchedTrackSharedHits") = nSharedHits;
131 
132 
133 
134  } // End: Loop over tracklets
135 
136  if (n_tracks==0 || n_tracklets==0) ATH_MSG_INFO("=========>>>>>>>>n_tracklets=" << n_tracklets << " =========>>>>>>>>n_tracks="<< n_tracks);
137 
138 
139  ATH_MSG_DEBUG ("Your new package and algorithm are successfully executing");
140 
141  return StatusCode::SUCCESS;
142 }
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
145 
146  ATH_MSG_INFO ("finalize()");
147 
148  return StatusCode::SUCCESS;
149 }
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:15
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:144
SG::AuxElement::auxdecor
Decorator< T, ALLOC >::reference_type auxdecor(const std::string &name) const
Fetch an aux decoration, as a non-const reference.
SCTExtensionAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: SCTExtensionAlg.cxx:31
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Track.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:195
SCTExtensionAlg::initialize
virtual StatusCode initialize() override
Definition: SCTExtensionAlg.cxx:21
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
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.