ATLAS Offline Software
Loading...
Searching...
No Matches
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
virtual StatusCode addPRDs (Maps &maps, const Track &track) const override
 add the PRDs from this track to maps.
virtual StatusCode removePRDs (Maps &maps, const Track &track) const override
 remove the PRDs from this track from maps
virtual StatusCode removePRDs (const Track &track) override
 remove the PRDs from this track from the store
virtual bool isUsed (const Maps &maps, const PrepRawData &prd) const override final
 does this PRD belong to at least one track in maps?
virtual bool isUsed (const PrepRawData &prd) const override final
 does this PRD belong to at least one track?
virtual bool isShared (const Maps &maps, const PrepRawData &prd) const override final
 does this PRD belong to more than one track in maps?
virtual bool isShared (const PrepRawData &prd) const override final
 does this PRD belong to more than one track?
virtual std::vector< const PrepRawData * > getPrdsOnTrack (const Track &track) const override
 returns a vector of PRDs belonging to the passed track.
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
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.
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)

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}
SG::ReadHandleKey< Trk::PRDtoTrackMap > m_prdToTrackMap
virtual StatusCode addPRDs(const Track &track) override
add the PRDs from this track to the store

◆ 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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
virtual std::vector< const PrepRawData * > getPrdsOnTrack(const Track &track) const override
returns a vector of PRDs belonging to the passed track.

◆ 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}
#define ATH_MSG_VERBOSE(x)
std::pair< ConstPRD_MapIt, ConstPRD_MapIt > PrepRawDataTrackMapRange
the first element is the beginning iterator of the range, the second is the end
virtual IPRD_AssociationTool::PrepRawDataTrackMapRange onTracks(const PrepRawData &prd) const override
get the Tracks associated with this Trk::PrepRawData.

◆ 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}
virtual IPRD_AssociationTool::TrackSet findConnectedTracks(const Track &track) const override
returns set of tracks which share PRD with this one

◆ 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}
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
Identifier identify() const
return the identifier -extends MeasurementBase
virtual unsigned int numberOfContainedROTs() const =0
Number of RIO_OnTracks to be contained by this CompetingRIOsOnTrack.
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
Identifier identify() const
return the identifier -extends MeasurementBase

◆ 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{
26 StatusCode sc = AlgTool::initialize();
27 if (sc.isFailure()) return sc;
28 ATH_CHECK( m_prdToTrackMap.initialize( !m_prdToTrackMap.key().empty() ) );
29 ATH_CHECK( m_idHelperSvc.retrieve());
30 return StatusCode::SUCCESS;
31}
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t sc
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ 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{
137 if (!m_prdToTrackMap.key().empty()) {return SG::ReadHandle<Trk::PRDtoTrackMap>(m_prdToTrackMap)->isShared(prd);}
138 return isShared (m_maps, prd);
139}
virtual bool isShared(const Maps &maps, const PrepRawData &prd) const override final
does this PRD belong to more than one track in maps?

◆ 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{
125 if (!m_prdToTrackMap.key().empty()) {return SG::ReadHandle<Trk::PRDtoTrackMap>(m_prdToTrackMap)->isUsed(prd);}
126 return isUsed (m_maps, prd);
127}
virtual bool isUsed(const Maps &maps, const PrepRawData &prd) const override final
does this PRD belong to at least one track in maps?

◆ 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{
217 if (!m_prdToTrackMap.key().empty()) {return SG::ReadHandle<Trk::PRDtoTrackMap>(m_prdToTrackMap)->onTracks(prd);}
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}
virtual StatusCode removePRDs(Maps &maps, const Track &track) const override
remove the PRDs from this track from maps

◆ 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.

114{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};

◆ 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.

112{this,"PRDtoTrackMap",""};

The documentation for this class was generated from the following files: