ATLAS Offline Software
Loading...
Searching...
No Matches
InDetPRD_AssociationToolGangedPixels.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "TrkTrack/Track.h"
11#include "Identifier/Identifier.h"
13
14#include <vector>
15
16InDet::InDetPRD_AssociationToolGangedPixels::InDetPRD_AssociationToolGangedPixels(const std::string& t, const std::string& n, const IInterface* p ) :
17 base_class(t,n,p)
18{ }
19
21= default;
22
24{
26 return StatusCode::SUCCESS;
27}
28
30{
31 return StatusCode::SUCCESS;
32}
33
35{
36 return addPRDs (m_maps, track);
37}
38
40 const Trk::Track& track ) const
41{
42 // test caching
43 TrackPrepRawDataMap::const_iterator itvec = maps.m_trackPrepRawDataMap.find(&track);
44 if (itvec!=maps.m_trackPrepRawDataMap.end())
45 {
46 ATH_MSG_ERROR("track already found in cache, should not happen");
47 return StatusCode::FAILURE;
48 }
49 // get all prds on 'track'
50 std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack( maps, track );
51
53
54 // loop over PRD
55 for (const Trk::PrepRawData* prd : prds) {
56 maps.m_prepRawDataTrackMap.emplace(prd, &track);
57 // test ganged ambiguity
59 const PixelCluster* pixel = static_cast<const PixelCluster*> (prd);
60 if (pixel->gangedPixel()) {
61 ATH_MSG_DEBUG( "Found ganged pixel, search for mirror" );
62 std::pair<PixelGangedClusterAmbiguities::const_iterator,
63 PixelGangedClusterAmbiguities::const_iterator> ambi = gangedAmbis->equal_range(pixel);
64 for (; ambi.first != ambi.second ; ++(ambi.first) ) {
65 // add ambiguity as used by this track as well
66 ATH_MSG_DEBUG( "Found mirror pixel, add mirror to association map" );
67 maps.m_prepRawDataTrackMap.emplace(ambi.first->second, &track);
68 }
69 }
70 }
71 }
72
73 // cache this using maps.m_trackPrepRawDataMap
74 maps.m_trackPrepRawDataMap.emplace(&track, prds);
75
76 ATH_MSG_DEBUG("Added PRDs from Track at ("<<&track<<") - map now has size: \t"
77 <<maps.m_prepRawDataTrackMap.size());
78 return StatusCode::SUCCESS;
79}
80
82{
83 return removePRDs (m_maps, track);
84}
85
87 const Trk::Track& track ) const
88{
89 // This is NOT pretty code!
90 // At the moment I'm brute-forcing, but maybe I need a second map, containing <Track*, iterator>
91 // The problem is that I think filling such a map is also time-consuming.
92 // Since removes happen much less frequently than add, then the slow bit should be here.
93 // EJWM
94
95 // save for debugging purposes
96 int oldSize = maps.m_prepRawDataTrackMap.size();//used in debug output at end.
97
98 // test caching
99 TrackPrepRawDataMap::iterator itvec = maps.m_trackPrepRawDataMap.find(&track);
100 if (itvec==maps.m_trackPrepRawDataMap.end())
101 {
102 ATH_MSG_ERROR("Track not found in cache, this should not happen");
103 return StatusCode::FAILURE;
104 }
105
107
108 // get all prds on 'track'
109 std::vector< const Trk::PrepRawData* > prds = itvec->second;
110 for (const Trk::PrepRawData* prd : prds)
111 {
112 // now get all map elements (i.e. Tracks) that contain this PRD
114 range = maps.m_prepRawDataTrackMap.equal_range(prd);
115 // get iterators for range
116 ConstPRD_MapIt mapIt = range.first;
117 ConstPRD_MapIt mapItEnd = range.second;
118 // simple for loop instead of fancier remove_if above
119 for ( ;mapIt!=mapItEnd; ++mapIt) {
120 if ( mapIt->second==&track ) {
121 maps.m_prepRawDataTrackMap.erase( mapIt );
122 break;//should only ever be one Track
123 }
124 }
125
126 // test ganged ambiguity
127
128 if (prd->type(Trk::PrepRawDataType::PixelCluster)) {
129 const PixelCluster* pixel = static_cast<const PixelCluster*> (prd);
130 if (pixel->gangedPixel()) {
131 std::pair<PixelGangedClusterAmbiguities::const_iterator,
132 PixelGangedClusterAmbiguities::const_iterator> ambi = gangedAmbis->equal_range(pixel);
133 for (; ambi.first != ambi.second ; ++(ambi.first) ) {
134 // add ambiguity as used by this track as well
135 ATH_MSG_DEBUG("Found ganged pixel, remove also mirror from association map");
136
137 range = maps.m_prepRawDataTrackMap.equal_range(ambi.first->second);
138 // get iterators for range
139 mapIt = range.first;
140 mapItEnd = range.second;
141 // simple for loop instead of fancier remove_if above
142 for ( ;mapIt!=mapItEnd; ++mapIt) {
143 if ( mapIt->second==&track ) {
144 maps.m_prepRawDataTrackMap.erase( mapIt );
145 break;//should only ever be one Track
146 }
147 }
148 }
149 }
150 }
151
152 }
153
154 // remove cached PRD vector
155 maps.m_trackPrepRawDataMap.erase( itvec );
156
157 ATH_MSG_DEBUG("Removed PRDs from track ("
158 <<&track<<") \t- map has changed size from \t"
159 <<oldSize <<" \tto "<<maps.m_prepRawDataTrackMap.size());
160 return StatusCode::SUCCESS;
161}
162
168
171 const Trk::Track& track ) const
172{
173 TrackSet connectedTracks;
174
176
177 std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack(maps, track);
178 for (const Trk::PrepRawData* prd : prds) {
180 // add them into the list
181 for ( ; range.first!=range.second; ++(range.first) )
182 connectedTracks.insert((range.first)->second);
183
184 // test ganged ambiguity
185
186 if (prd->type(Trk::PrepRawDataType::PixelCluster)) {
187 const PixelCluster* pixel = static_cast<const PixelCluster*> (prd);
188 if (pixel->gangedPixel()) {
189 std::pair<PixelGangedClusterAmbiguities::const_iterator,
190 PixelGangedClusterAmbiguities::const_iterator> ambi = gangedAmbis->equal_range(pixel);
191 for (; ambi.first != ambi.second ; ++(ambi.first) ) {
192 range = onTracks( maps, *(ambi.first->second) );
193 // add them into the list
194 for ( ; range.first!=range.second; ++(range.first) )
195 connectedTracks.insert((range.first)->second);
196 }
197 }
198 }
199 }
200
201 // don't forget to remove the input track
202 connectedTracks.erase(&track);
203
204 ATH_MSG_VERBOSE("Added in connected tracks for track "<<&track
205 << "\tsize of list is "<<connectedTracks.size());
206
207 return connectedTracks;
208}
209
210
211std::vector< const Trk::PrepRawData* >
216
217
218std::vector< const Trk::PrepRawData* >
220 const Trk::Track& track) const
221{
222 using PRDs_t = std::vector<const Trk::PrepRawData *>;
223
224 // test caching
225 TrackPrepRawDataMap::const_iterator itvec = maps.m_trackPrepRawDataMap.find(&track);
226 if (itvec!=maps.m_trackPrepRawDataMap.end())
227 {
228 ATH_MSG_VERBOSE("found track in cache, return cached PRD vector for track");
229 return itvec->second;
230 }
231
232 if (track.measurementsOnTrack()==nullptr) {
233 ATH_MSG_WARNING("Track has no RoTs");
234 return {}; // return vector optimization
235 }
236
237
238 // output vector
239 PRDs_t vec;
240 // size it
241 vec.reserve(track.measurementsOnTrack()->size());
242
243 // get the PRDs for the measuremenst on track
244 DataVector<const Trk::MeasurementBase>::const_iterator it = track.measurementsOnTrack()->begin();
245 DataVector<const Trk::MeasurementBase>::const_iterator itEnd = track.measurementsOnTrack()->end();
246 for (;it!=itEnd;++it){
247 const auto *const pThisMeasurement(*it);
248 if (pThisMeasurement->type(Trk::MeasurementBaseType::RIO_OnTrack)){
249 const Trk::RIO_OnTrack* rot = static_cast<const Trk::RIO_OnTrack*>(pThisMeasurement);
250 vec.push_back(rot->prepRawData());
251 }
252 }
253 ATH_MSG_DEBUG(" Getting "<<vec.size()<<" PRDs from track at:"<<&track);
254 // new mode, we add the outliers in the TRT
255 if (m_addTRToutliers) {
256 // get the PRDs for the measuremenst on track
257 for (const Trk::MeasurementBase* meas : *track.outliersOnTrack()){
258 // get the ROT, make sure it is not a pseudo measurment
260 const Trk::RIO_OnTrack* rot = static_cast<const Trk::RIO_OnTrack*>(meas);
261 // check if outlier is TRT ?
263 // add to the list, it is TRT
264 vec.push_back(rot->prepRawData());
265 }
266 }
267 }
268 ATH_MSG_DEBUG(" Getting "<<vec.size()<<" PRDs including TRT outlier from track at:"<<&track);
269 }
270
271 return vec;
272}
273
279
282 const Trk::PrepRawData& prd) const
283{
284 return maps.m_prepRawDataTrackMap.equal_range(&prd);
285}
286
288{
289 m_maps.m_prepRawDataTrackMap.clear();
290 m_maps.m_trackPrepRawDataMap.clear();
291}
292
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
std::vector< size_t > vec
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
InDetPRD_AssociationToolGangedPixels(const std::string &, const std::string &, const IInterface *)
virtual std::vector< const Trk::PrepRawData * > getPrdsOnTrack(const Trk::Track &track) const override
returns a vector of PRDs belonging to the passed track.
virtual Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange onTracks(const Trk::PrepRawData &prd) const override
get the Tracks associated with this Trk::PrepRawData.
virtual void reset() override
resets the tool - should be called before using tool (and maybe afterwards to free up memory)
SG::ReadHandleKey< PixelGangedClusterAmbiguities > m_pixelClusterAmbiguitiesMapName
BooleanProperty m_addTRToutliers
add TRT outliers in the addTrack method to avoid splits due to rejected extensions
virtual Trk::IPRD_AssociationTool::TrackSet findConnectedTracks(const Trk::Track &track) const override
returns set of tracks which share PRD with this one
virtual StatusCode addPRDs(const Trk::Track &track) override
add the PRDs from this track to the store
virtual StatusCode removePRDs(Maps &maps, const Trk::Track &track) const override
remove the PRDs from this track from maps
std::set< const Track * > TrackSet
std::pair< ConstPRD_MapIt, ConstPRD_MapIt > PrepRawDataTrackMapRange
the first element is the beginning iterator of the range, the second is the end
This class is the pure abstract base class for all fittable tracking measurements.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
virtual bool rioType(RIO_OnTrackType::Type type) const =0
Method checking the Rio On Track type.
IPRD_AssociationTool::TrackPrepRawDataMap m_trackPrepRawDataMap
IPRD_AssociationTool::PrepRawDataTrackMap m_prepRawDataTrackMap