ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
Trk::PRD_AssociationTool Class Referencefinal

Concrete Implementation of the IPRD_AssociationTool interface. More...

#include <PRD_AssociationTool.h>

Inheritance diagram for Trk::PRD_AssociationTool:
Collaboration diagram for Trk::PRD_AssociationTool:

Public Member Functions

 PRD_AssociationTool (const std::string &, const std::string &, const IInterface *)
 
virtual ~PRD_AssociationTool ()=default
 
virtual StatusCode initialize () override
 
virtual StatusCode addPRDs (const Track &track) override
 add the PRDs from this track to the store More...
 
virtual StatusCode addPRDs (Maps &maps, const Track &track) const override
 add the PRDs from this track to maps. More...
 
virtual StatusCode removePRDs (Maps &maps, const Track &track) const override
 remove the PRDs from this track from maps More...
 
virtual StatusCode removePRDs (const Track &track) override
 remove the PRDs from this track from the store More...
 
virtual bool isUsed (const Maps &maps, const PrepRawData &prd) const override final
 does this PRD belong to at least one track in maps? More...
 
virtual bool isUsed (const PrepRawData &prd) const override final
 does this PRD belong to at least one track? More...
 
virtual bool isShared (const Maps &maps, const PrepRawData &prd) const override final
 does this PRD belong to more than one track in maps? More...
 
virtual bool isShared (const PrepRawData &prd) const override final
 does this PRD belong to more than one track? More...
 
virtual std::vector< const PrepRawData * > getPrdsOnTrack (const Track &track) const override
 returns a vector of PRDs belonging to the passed track. More...
 
virtual std::vector< const PrepRawData * > getPrdsOnTrack (const Maps &maps, const Track &track) const override
 
virtual IPRD_AssociationTool::TrackSet findConnectedTracks (const Track &track) const override
 returns set of tracks which share PRD with this one More...
 
virtual IPRD_AssociationTool::TrackSet findConnectedTracks (const Maps &maps, const Track &track) const override
 
virtual IPRD_AssociationTool::PrepRawDataTrackMapRange onTracks (const PrepRawData &prd) const override
 get the Tracks associated with this Trk::PrepRawData. More...
 
virtual IPRD_AssociationTool::PrepRawDataTrackMapRange onTracks (const Maps &maps, const PrepRawData &prd) const override
 
virtual void reset () override
 resets the tool - should be called before using tool (and maybe afterwards to free up memory) More...
 

Private Attributes

Maps m_maps
 
SG::ReadHandleKey< Trk::PRDtoTrackMapm_prdToTrackMap {this,"PRDtoTrackMap",""}
 
ServiceHandle< Muon::IMuonIdHelperSvcm_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}
 

Detailed Description

Concrete Implementation of the IPRD_AssociationTool interface.

Definition at line 24 of file PRD_AssociationTool.h.

Constructor & Destructor Documentation

◆ PRD_AssociationTool()

Trk::PRD_AssociationTool::PRD_AssociationTool ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Definition at line 16 of file PRD_AssociationTool.cxx.

19  :
20  base_class(t,n,p)
21 {
22 }

◆ ~PRD_AssociationTool()

virtual Trk::PRD_AssociationTool::~PRD_AssociationTool ( )
virtualdefault

Member Function Documentation

◆ addPRDs() [1/2]

StatusCode Trk::PRD_AssociationTool::addPRDs ( const Track track)
overridevirtual

add the PRDs from this track to the store

Parameters
trackall PRDs from 'track' will be added to PRD_AssociationTool's internal store.

Definition at line 33 of file PRD_AssociationTool.cxx.

34 {
35  if (!m_prdToTrackMap.key().empty()) throw std::runtime_error("Cannot modify(addPRDs) the PRDtoTrackMap that was read from storegate!");
36  return addPRDs (m_maps, track);
37 }

◆ addPRDs() [2/2]

StatusCode Trk::PRD_AssociationTool::addPRDs ( Maps &  maps,
const Track track 
) const
overridevirtual

add the PRDs from this track to maps.

Parameters
trackall PRDs from 'track' will be added to PRD_AssociationTool's internal store.

Definition at line 39 of file PRD_AssociationTool.cxx.

40 {
41  // test caching
42  TrackPrepRawDataMap::const_iterator itvec = maps.m_trackPrepRawDataMap.find(&track);
43  if (itvec!=maps.m_trackPrepRawDataMap.end())
44  {
45  ATH_MSG_ERROR ("track already found in cache, should not happen");
46  return StatusCode::FAILURE;
47  }
48  // get all prds on 'track'
49  std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack( maps, track );
50  for (const Trk::PrepRawData* prd : prds) {
51  maps.m_prepRawDataTrackMap.emplace(prd, &track);
52  }
53 
54  // cache this using m_trackPrepRawDataMap
55  maps.m_trackPrepRawDataMap.emplace(&track, prds);
56 
57  ATH_MSG_DEBUG ("Added PRDs from Track at ("<<&track<<") - map now has size: \t"<<
58  maps.m_prepRawDataTrackMap.size());
59  return StatusCode::SUCCESS;
60 }

◆ findConnectedTracks() [1/2]

Trk::IPRD_AssociationTool::TrackSet Trk::PRD_AssociationTool::findConnectedTracks ( const Maps &  maps,
const Track track 
) const
overridevirtual

Definition at line 127 of file PRD_AssociationTool.cxx.

129 {
130  TrackSet connectedTracks;
131 
132  std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack(maps, track);
133  for (const Trk::PrepRawData* prd : prds)
134  {
136 
137  // TODO use remove_copy_if instead.
138  for ( ; range.first!=range.second; ++(range.first) )
139  {
140  const Track* conTrack = (range.first)->second;
141  // don't copy this track!
142  if (conTrack!=&track) {
143  // this does actually not allow for double entries
144  connectedTracks.insert(conTrack);
145  ATH_MSG_VERBOSE ("Track "<<&track<<" \tshares PRD "<<prd<<" \twith track:"<<conTrack);
146  }
147  }
148  ATH_MSG_VERBOSE ("Added in connected tracks for PRD:"<<prd<<
149  "\tsize of list now:"<<connectedTracks.size());
150  }
151 
152  return connectedTracks;
153 }

◆ findConnectedTracks() [2/2]

Trk::IPRD_AssociationTool::TrackSet Trk::PRD_AssociationTool::findConnectedTracks ( const Track track) const
overridevirtual

returns set of tracks which share PRD with this one

Parameters
trackthis Track must be known to this tool.
Returns
a set of tracks which share PRD/hits with the passed 'track'

Definition at line 120 of file PRD_AssociationTool.cxx.

121 {
122  if (!m_prdToTrackMap.key().empty()) throw std::runtime_error("findConnectedTracks not supported when using a PRDtoTrackMap from storegate.");
123  return findConnectedTracks (m_maps, track);
124 }

◆ getPrdsOnTrack() [1/2]

std::vector< const Trk::PrepRawData * > Trk::PRD_AssociationTool::getPrdsOnTrack ( const Maps &  maps,
const Track track 
) const
overridevirtual

Definition at line 165 of file PRD_AssociationTool.cxx.

167 {
168  using PRDs_t = std::vector<const PrepRawData *>;
169 
170  // test caching
171  TrackPrepRawDataMap::const_iterator itvec = maps.m_trackPrepRawDataMap.find(&track);
172  if (itvec!=maps.m_trackPrepRawDataMap.end())
173  {
174  ATH_MSG_VERBOSE ("found track in cache, return cached PRD vector for track");
175  return itvec->second;
176  }
177 
178  if (track.measurementsOnTrack()==nullptr) {
179  ATH_MSG_WARNING ("Track has no RoTs");
180  return {};
181  }
182 
183  PRDs_t vec;
184  vec.reserve(track.measurementsOnTrack()->size());
185  for (const MeasurementBase* meas : *track.measurementsOnTrack())
186  {
187  const RIO_OnTrack* rot = dynamic_cast<const RIO_OnTrack*>(meas);
188  if (rot){
189  if(m_idHelperSvc->isMuon(rot->identify())){
190  //only use precision hits for muon track overlap
191  if(!m_idHelperSvc->isMdt(rot->identify()) && (!m_idHelperSvc->isCsc(rot->identify()) || m_idHelperSvc->measuresPhi(rot->identify()))) continue;
192  }
193  vec.push_back(rot->prepRawData());
194  }
195  else{
196  const Trk::CompetingRIOsOnTrack* competingROT = dynamic_cast <const Trk::CompetingRIOsOnTrack*> (meas);
197  if(competingROT){
198  const unsigned int numROTs = competingROT->numberOfContainedROTs();
199  for( unsigned int i=0;i<numROTs;++i ){
200  const Trk::RIO_OnTrack* rot = &competingROT->rioOnTrack(i);
201  if( !rot || !rot->prepRawData() || !m_idHelperSvc->isMuon(rot->identify()) ) continue;
202  //only use precision hits for muon track overlap
203  if(!m_idHelperSvc->isMdt(rot->identify()) && (!m_idHelperSvc->isCsc(rot->identify()) || m_idHelperSvc->measuresPhi(rot->identify()))) continue;
204  vec.push_back(rot->prepRawData());
205  }
206  }
207  }
208  }
209  ATH_MSG_DEBUG (" Getting "<<vec.size()<<" PRDs from track at:"<<&track);
210 
211  return vec;
212 }

◆ getPrdsOnTrack() [2/2]

std::vector< const Trk::PrepRawData * > Trk::PRD_AssociationTool::getPrdsOnTrack ( const Track track) const
overridevirtual

returns a vector of PRDs belonging to the passed track.

It's basically for the convenience of users and is created purely from the passed track.

i.e. there is no caching if you do it multiple times on the same track, you're being inefficient!!

Parameters
trackthis Track will be iterated through and all PrepRawData added to a vector
Returns
vector of PrepRawData* belonging to 'track'. The PrepRawData should NOT be deleted
  • they belong to the Track (and thus the event).

Definition at line 157 of file PRD_AssociationTool.cxx.

158 {
159  if (!m_prdToTrackMap.key().empty()) throw std::runtime_error("getPrdsOnTrack not supported when using a PRDtoTrackMap from storegate.");
160  return getPrdsOnTrack (m_maps, track);
161 }

◆ initialize()

StatusCode Trk::PRD_AssociationTool::initialize ( )
overridevirtual

Definition at line 24 of file PRD_AssociationTool.cxx.

25 {
27  if (sc.isFailure()) return sc;
29  ATH_CHECK( m_idHelperSvc.retrieve());
30  return StatusCode::SUCCESS;
31 }

◆ isShared() [1/2]

bool Trk::PRD_AssociationTool::isShared ( const Maps &  maps,
const PrepRawData prd 
) const
inlinefinaloverridevirtual

does this PRD belong to more than one track in maps?

Parameters
prdthe PrepRawData in question
Returns
true if 'prd' exists on more than one track (of course PRD_AssociationTool can only give information about tracks it knows about i.e. that were added to maps with addPRDs()

Definition at line 129 of file PRD_AssociationTool.h.

131 {
132  return (maps.m_prepRawDataTrackMap.count(&prd)>1);
133 }

◆ isShared() [2/2]

bool Trk::PRD_AssociationTool::isShared ( const PrepRawData prd) const
inlinefinaloverridevirtual

does this PRD belong to more than one track?

Parameters
prdthe PrepRawData in question
Returns
true if 'prd' exists on more than one track (of course PRD_AssociationTool can only give information about tracks it knows about i.e. that were added with addPRDs()

Definition at line 135 of file PRD_AssociationTool.h.

136 {
138  return isShared (m_maps, prd);
139 }

◆ isUsed() [1/2]

bool Trk::PRD_AssociationTool::isUsed ( const Maps &  maps,
const PrepRawData prd 
) const
inlinefinaloverridevirtual

does this PRD belong to at least one track in maps?

Parameters
prdthe PrepRawData in question
Returns
true if 'prd' exists in at least one track (of course PRD_AssociationTool can only give information about tracks it knows about i.e. that were added to maps with addPRDs()

Definition at line 117 of file PRD_AssociationTool.h.

119 {
120  return (maps.m_prepRawDataTrackMap.count(&prd)>0);
121 }

◆ isUsed() [2/2]

bool Trk::PRD_AssociationTool::isUsed ( const PrepRawData prd) const
inlinefinaloverridevirtual

does this PRD belong to at least one track?

Parameters
prdthe PrepRawData in question
Returns
true if 'prd' exists in at least one track (of course PRD_AssociationTool can only give information about tracks it knows about i.e. that were added with addPRDs()

Definition at line 123 of file PRD_AssociationTool.h.

124 {
126  return isUsed (m_maps, prd);
127 }

◆ onTracks() [1/2]

Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange Trk::PRD_AssociationTool::onTracks ( const Maps &  maps,
const PrepRawData prd 
) const
overridevirtual

Definition at line 222 of file PRD_AssociationTool.cxx.

223 {
224 // std::pair<IPRD_AssociationTool::PRD_MapIt, IPRD_AssociationTool::PRD_MapIt> range =
225  return maps.m_prepRawDataTrackMap.equal_range(&prd);
226 }

◆ onTracks() [2/2]

Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange Trk::PRD_AssociationTool::onTracks ( const PrepRawData prd) const
overridevirtual

get the Tracks associated with this Trk::PrepRawData.

IMPORTANT: Please use the typedefs IPRD_AssociationTool::PrepRawDataRange and IPRD_AssociationTool::ConstPRD_MapIt (defined in the interface) to access the tracks, as the way the data is stored internally may change.

Definition at line 215 of file PRD_AssociationTool.cxx.

216 {
218  return onTracks (m_maps, prd);
219 }

◆ removePRDs() [1/2]

StatusCode Trk::PRD_AssociationTool::removePRDs ( const Track track)
overridevirtual

remove the PRDs from this track from the store

Parameters
trackall PRDs from 'track' will be removed from the PRD_AssociationTool's internal store.

Definition at line 62 of file PRD_AssociationTool.cxx.

63 {
64  if (!m_prdToTrackMap.key().empty()) throw std::runtime_error("Cannot modify(removePRDs) the PRDtoTrackMap that was read from storegate!");
65  return removePRDs (m_maps, track);
66 }

◆ removePRDs() [2/2]

StatusCode Trk::PRD_AssociationTool::removePRDs ( Maps &  maps,
const Track track 
) const
overridevirtual

remove the PRDs from this track from maps

Parameters
trackall PRDs from 'track' will be removed from maps

Definition at line 68 of file PRD_AssociationTool.cxx.

70 {
71  // This is NOT pretty code!
72  // At the moment I'm brute-forcing, but maybe I need a second map, containing <Track*, iterator>
73  // The problem is that I think filling such a map is also time-consuming.
74  // Since removes happen much less frequently than add, then the slow bit should be here.
75  // EJWM
76 
77  // save for debugging purposes
78  int oldSize = maps.m_prepRawDataTrackMap.size();//used in debug output at end.
79 
80  // test caching
81  TrackPrepRawDataMap::iterator itvec = maps.m_trackPrepRawDataMap.find(&track);
82  if (itvec==maps.m_trackPrepRawDataMap.end())
83  {
84  ATH_MSG_ERROR ("Track not found in cache, this should not happen");
85  return StatusCode::FAILURE;
86  }
87 
88  // get all prds on 'track'
89  std::vector< const Trk::PrepRawData* > prds = itvec->second;
90  for (const Trk::PrepRawData* prd : prds)
91  {
92  // now get all map elements (i.e. Tracks) that contain this PRD
94  range = maps.m_prepRawDataTrackMap.equal_range(prd);
95 
96  // get iterators for range
97  ConstPRD_MapIt mapIt = range.first;
98  ConstPRD_MapIt mapItEnd = range.second;
99 
100  // simple for loop instead of fancier remove_if above
101  for ( ;mapIt!=mapItEnd; ++mapIt)
102  {
103  if ( mapIt->second==&track )
104  {
105  maps.m_prepRawDataTrackMap.erase( mapIt );
106  break;//should only ever be one Track
107  }
108  }
109  }
110 
111  // remove cached PRD vector
112  maps.m_trackPrepRawDataMap.erase( itvec );
113 
114  ATH_MSG_DEBUG ("Removed PRDs from track (" <<&track<<") \t- map has changed "<<
115  "size from \t"<<oldSize <<" \tto "<<maps.m_prepRawDataTrackMap.size());
116  return StatusCode::SUCCESS;
117 }

◆ reset()

void Trk::PRD_AssociationTool::reset ( )
overridevirtual

resets the tool - should be called before using tool (and maybe afterwards to free up memory)

Definition at line 228 of file PRD_AssociationTool.cxx.

229 {
230  if (!m_prdToTrackMap.key().empty()) throw std::runtime_error("cannot reset PRDtoTrack map when it is taken from storegate.");
231  m_maps.m_prepRawDataTrackMap.clear();
232  m_maps.m_trackPrepRawDataMap.clear();
233 }

Member Data Documentation

◆ m_idHelperSvc

ServiceHandle<Muon::IMuonIdHelperSvc> Trk::PRD_AssociationTool::m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}
private

Definition at line 114 of file PRD_AssociationTool.h.

◆ m_maps

Maps Trk::PRD_AssociationTool::m_maps
private

Definition at line 111 of file PRD_AssociationTool.h.

◆ m_prdToTrackMap

SG::ReadHandleKey<Trk::PRDtoTrackMap> Trk::PRD_AssociationTool::m_prdToTrackMap {this,"PRDtoTrackMap",""}
private

Definition at line 112 of file PRD_AssociationTool.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
Trk::PRD_AssociationTool::onTracks
virtual IPRD_AssociationTool::PrepRawDataTrackMapRange onTracks(const PrepRawData &prd) const override
get the Tracks associated with this Trk::PrepRawData.
Definition: PRD_AssociationTool.cxx:215
Trk::PRD_AssociationTool::m_prdToTrackMap
SG::ReadHandleKey< Trk::PRDtoTrackMap > m_prdToTrackMap
Definition: PRD_AssociationTool.h:112
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Trk::PRDtoTrackMap::onTracks
PrepRawDataTrackMapRange onTracks(const PrepRawData &prd)
get the Tracks associated with this PrepRawData.
SG::ReadHandle< Trk::PRDtoTrackMap >
Trk::PRD_AssociationTool::isUsed
virtual bool isUsed(const Maps &maps, const PrepRawData &prd) const override final
does this PRD belong to at least one track in maps?
Definition: PRD_AssociationTool.h:117
initialize
void initialize()
Definition: run_EoverP.cxx:894
Trk::PRD_AssociationTool::getPrdsOnTrack
virtual std::vector< const PrepRawData * > getPrdsOnTrack(const Track &track) const override
returns a vector of PRDs belonging to the passed track.
Definition: PRD_AssociationTool.cxx:157
CP::TrackSet
std::set< TrackPtr > TrackSet
Definition: PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/Defs.h:72
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Trk::PRD_AssociationTool::isShared
virtual bool isShared(const Maps &maps, const PrepRawData &prd) const override final
does this PRD belong to more than one track in maps?
Definition: PRD_AssociationTool.h:129
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
Trk::PRD_AssociationTool::m_maps
Maps m_maps
Definition: PRD_AssociationTool.h:111
Trk::CompetingRIOsOnTrack::rioOnTrack
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::CompetingRIOsOnTrack::numberOfContainedROTs
virtual unsigned int numberOfContainedROTs() const =0
Number of RIO_OnTracks to be contained by this CompetingRIOsOnTrack.
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
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
Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange
std::pair< ConstPRD_MapIt, ConstPRD_MapIt > PrepRawDataTrackMapRange
the first element is the beginning iterator of the range, the second is the end
Definition: IPRD_AssociationTool.h:48
Trk::CompetingRIOsOnTrack
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
Definition: CompetingRIOsOnTrack.h:64
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Trk::PRD_AssociationTool::addPRDs
virtual StatusCode addPRDs(const Track &track) override
add the PRDs from this track to the store
Definition: PRD_AssociationTool.cxx:33
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::PRD_AssociationTool::findConnectedTracks
virtual IPRD_AssociationTool::TrackSet findConnectedTracks(const Track &track) const override
returns set of tracks which share PRD with this one
Definition: PRD_AssociationTool.cxx:120
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::PRDtoTrackMap::isUsed
bool isUsed(const PrepRawData &prd) const
does this PRD belong to at least one track?
Trk::PRD_AssociationTool::removePRDs
virtual StatusCode removePRDs(Maps &maps, const Track &track) const override
remove the PRDs from this track from maps
Definition: PRD_AssociationTool.cxx:68
Trk::PrepRawData
Definition: PrepRawData.h:62
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
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::RIO_OnTrack::identify
virtual Identifier identify() const final
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:155
Track
Definition: TriggerChamberClusterOnTrackCreator.h:21
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Trk::PRD_AssociationTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: PRD_AssociationTool.h:114
Trk::PRDtoTrackMap::isShared
bool isShared(const PrepRawData &prd) const
does this PRD belong to more than one track?