ATLAS Offline Software
InDetPRD_AssociationToolGangedPixels.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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 
17  const std::string& n,
18  const IInterface* p ) :
19  base_class(t,n,p)
20 {
21  declareProperty( "PixelClusterAmbiguitiesMapName", m_pixelClusterAmbiguitiesMapName = "PixelClusterAmbiguitiesMap" );
22  declareProperty( "addTRToutliers", m_addTRToutliers = false);
23 }
24 
26 = default;
27 
29 {
31  return StatusCode::SUCCESS;
32 }
33 
35 {
36  return StatusCode::SUCCESS;
37 }
38 
40 {
41  return addPRDs (m_maps, track);
42 }
43 
45  const Trk::Track& track ) const
46 {
47  // test caching
48  TrackPrepRawDataMap::const_iterator itvec = maps.m_trackPrepRawDataMap.find(&track);
49  if (itvec!=maps.m_trackPrepRawDataMap.end())
50  {
51  ATH_MSG_ERROR("track already found in cache, should not happen");
52  return StatusCode::FAILURE;
53  }
54  // get all prds on 'track'
55  std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack( maps, track );
56 
58 
59  // loop over PRD
60  for (const Trk::PrepRawData* prd : prds) {
61  maps.m_prepRawDataTrackMap.emplace(prd, &track);
62  // test ganged ambiguity
63  if (prd->type(Trk::PrepRawDataType::PixelCluster)) {
64  const PixelCluster* pixel = static_cast<const PixelCluster*> (prd);
65  if (pixel->gangedPixel()) {
66  ATH_MSG_DEBUG( "Found ganged pixel, search for mirror" );
67  std::pair<PixelGangedClusterAmbiguities::const_iterator,
68  PixelGangedClusterAmbiguities::const_iterator> ambi = gangedAmbis->equal_range(pixel);
69  for (; ambi.first != ambi.second ; ++(ambi.first) ) {
70  // add ambiguity as used by this track as well
71  ATH_MSG_DEBUG( "Found mirror pixel, add mirror to association map" );
72  maps.m_prepRawDataTrackMap.emplace(ambi.first->second, &track);
73  }
74  }
75  }
76  }
77 
78  // cache this using maps.m_trackPrepRawDataMap
79  maps.m_trackPrepRawDataMap.emplace(&track, prds);
80 
81  ATH_MSG_DEBUG("Added PRDs from Track at ("<<&track<<") - map now has size: \t"
82  <<maps.m_prepRawDataTrackMap.size());
83  return StatusCode::SUCCESS;
84 }
85 
87 {
88  return removePRDs (m_maps, track);
89 }
90 
92  const Trk::Track& track ) const
93 {
94  // This is NOT pretty code!
95  // At the moment I'm brute-forcing, but maybe I need a second map, containing <Track*, iterator>
96  // The problem is that I think filling such a map is also time-consuming.
97  // Since removes happen much less frequently than add, then the slow bit should be here.
98  // EJWM
99 
100  // save for debugging purposes
101  int oldSize = maps.m_prepRawDataTrackMap.size();//used in debug output at end.
102 
103  // test caching
105  if (itvec==maps.m_trackPrepRawDataMap.end())
106  {
107  ATH_MSG_ERROR("Track not found in cache, this should not happen");
108  return StatusCode::FAILURE;
109  }
110 
112 
113  // get all prds on 'track'
114  std::vector< const Trk::PrepRawData* > prds = itvec->second;
115  for (const Trk::PrepRawData* prd : prds)
116  {
117  // now get all map elements (i.e. Tracks) that contain this PRD
119  range = maps.m_prepRawDataTrackMap.equal_range(prd);
120  // get iterators for range
121  ConstPRD_MapIt mapIt = range.first;
122  ConstPRD_MapIt mapItEnd = range.second;
123  // simple for loop instead of fancier remove_if above
124  for ( ;mapIt!=mapItEnd; ++mapIt) {
125  if ( mapIt->second==&track ) {
126  maps.m_prepRawDataTrackMap.erase( mapIt );
127  break;//should only ever be one Track
128  }
129  }
130 
131  // test ganged ambiguity
132 
133  if (prd->type(Trk::PrepRawDataType::PixelCluster)) {
134  const PixelCluster* pixel = static_cast<const PixelCluster*> (prd);
135  if (pixel->gangedPixel()) {
136  std::pair<PixelGangedClusterAmbiguities::const_iterator,
137  PixelGangedClusterAmbiguities::const_iterator> ambi = gangedAmbis->equal_range(pixel);
138  for (; ambi.first != ambi.second ; ++(ambi.first) ) {
139  // add ambiguity as used by this track as well
140  ATH_MSG_DEBUG("Found ganged pixel, remove also mirror from association map");
141 
142  range = maps.m_prepRawDataTrackMap.equal_range(ambi.first->second);
143  // get iterators for range
144  mapIt = range.first;
145  mapItEnd = range.second;
146  // simple for loop instead of fancier remove_if above
147  for ( ;mapIt!=mapItEnd; ++mapIt) {
148  if ( mapIt->second==&track ) {
149  maps.m_prepRawDataTrackMap.erase( mapIt );
150  break;//should only ever be one Track
151  }
152  }
153  }
154  }
155  }
156 
157  }
158 
159  // remove cached PRD vector
160  maps.m_trackPrepRawDataMap.erase( itvec );
161 
162  ATH_MSG_DEBUG("Removed PRDs from track ("
163  <<&track<<") \t- map has changed size from \t"
164  <<oldSize <<" \tto "<<maps.m_prepRawDataTrackMap.size());
165  return StatusCode::SUCCESS;
166 }
167 
170 {
171  return findConnectedTracks (m_maps, track);
172 }
173 
176  const Trk::Track& track ) const
177 {
178  TrackSet connectedTracks;
179 
181 
182  std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack(maps, track);
183  for (const Trk::PrepRawData* prd : prds) {
185  // add them into the list
186  for ( ; range.first!=range.second; ++(range.first) )
187  connectedTracks.insert((range.first)->second);
188 
189  // test ganged ambiguity
190 
191  if (prd->type(Trk::PrepRawDataType::PixelCluster)) {
192  const PixelCluster* pixel = static_cast<const PixelCluster*> (prd);
193  if (pixel->gangedPixel()) {
194  std::pair<PixelGangedClusterAmbiguities::const_iterator,
195  PixelGangedClusterAmbiguities::const_iterator> ambi = gangedAmbis->equal_range(pixel);
196  for (; ambi.first != ambi.second ; ++(ambi.first) ) {
197  range = onTracks( maps, *(ambi.first->second) );
198  // add them into the list
199  for ( ; range.first!=range.second; ++(range.first) )
200  connectedTracks.insert((range.first)->second);
201  }
202  }
203  }
204  }
205 
206  // don't forget to remove the input track
207  connectedTracks.erase(&track);
208 
209  ATH_MSG_VERBOSE("Added in connected tracks for track "<<&track
210  << "\tsize of list is "<<connectedTracks.size());
211 
212  return connectedTracks;
213 }
214 
215 
216 std::vector< const Trk::PrepRawData* >
218 {
219  return getPrdsOnTrack (m_maps, track);
220 }
221 
222 
223 std::vector< const Trk::PrepRawData* >
225  const Trk::Track& track) const
226 {
227  using PRDs_t = std::vector<const Trk::PrepRawData *>;
228 
229  // test caching
230  TrackPrepRawDataMap::const_iterator itvec = maps.m_trackPrepRawDataMap.find(&track);
231  if (itvec!=maps.m_trackPrepRawDataMap.end())
232  {
233  ATH_MSG_VERBOSE("found track in cache, return cached PRD vector for track");
234  return itvec->second;
235  }
236 
237  if (track.measurementsOnTrack()==nullptr) {
238  ATH_MSG_WARNING("Track has no RoTs");
239  return {}; // return vector optimization
240  }
241 
242 
243  // output vector
244  PRDs_t vec;
245  // size it
246  vec.reserve(track.measurementsOnTrack()->size());
247 
248  // get the PRDs for the measuremenst on track
249  DataVector<const Trk::MeasurementBase>::const_iterator it = track.measurementsOnTrack()->begin();
250  DataVector<const Trk::MeasurementBase>::const_iterator itEnd = track.measurementsOnTrack()->end();
251  for (;it!=itEnd;++it){
252  const auto *const pThisMeasurement(*it);
253  if (pThisMeasurement->type(Trk::MeasurementBaseType::RIO_OnTrack)){
254  const Trk::RIO_OnTrack* rot = static_cast<const Trk::RIO_OnTrack*>(pThisMeasurement);
255  vec.push_back(rot->prepRawData());
256  }
257  }
258  ATH_MSG_DEBUG(" Getting "<<vec.size()<<" PRDs from track at:"<<&track);
259  // new mode, we add the outliers in the TRT
260  if (m_addTRToutliers) {
261  // get the PRDs for the measuremenst on track
262  for (const Trk::MeasurementBase* meas : *track.outliersOnTrack()){
263  // get the ROT, make sure it is not a pseudo measurment
264  if (meas->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
265  const Trk::RIO_OnTrack* rot = static_cast<const Trk::RIO_OnTrack*>(meas);
266  // check if outlier is TRT ?
268  // add to the list, it is TRT
269  vec.push_back(rot->prepRawData());
270  }
271  }
272  }
273  ATH_MSG_DEBUG(" Getting "<<vec.size()<<" PRDs including TRT outlier from track at:"<<&track);
274  }
275 
276  return vec;
277 }
278 
281 {
282  return onTracks (m_maps, prd);
283 }
284 
287  const Trk::PrepRawData& prd) const
288 {
289  return maps.m_prepRawDataTrackMap.equal_range(&prd);
290 }
291 
293 {
296 }
297 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
InDet::InDetPRD_AssociationToolGangedPixels::onTracks
virtual Trk::IPRD_AssociationTool::PrepRawDataTrackMapRange onTracks(const Trk::PrepRawData &prd) const override
get the Tracks associated with this Trk::PrepRawData.
Definition: InDetPRD_AssociationToolGangedPixels.cxx:280
InDet::InDetPRD_AssociationToolGangedPixels::reset
virtual void reset() override
resets the tool - should be called before using tool (and maybe afterwards to free up memory)
Definition: InDetPRD_AssociationToolGangedPixels.cxx:292
TrkDetElementBase.h
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
PixelCluster.h
SG::ReadHandle< PixelGangedClusterAmbiguities >
InDet::InDetPRD_AssociationToolGangedPixels::removePRDs
virtual StatusCode removePRDs(Maps &maps, const Trk::Track &track) const override
remove the PRDs from this track from maps
Definition: InDetPRD_AssociationToolGangedPixels.cxx:91
InDet::InDetPRD_AssociationToolGangedPixels::~InDetPRD_AssociationToolGangedPixels
virtual ~InDetPRD_AssociationToolGangedPixels()
skel.it
it
Definition: skel.GENtoEVGEN.py:423
CP::TrackSet
std::set< TrackPtr > TrackSet
Definition: PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/Defs.h:72
Trk::RIO_OnTrack::rioType
virtual bool rioType(RIO_OnTrackType::Type type) const =0
Method checking the Rio On Track type.
InDet::InDetPRD_AssociationToolGangedPixels::getPrdsOnTrack
virtual std::vector< const Trk::PrepRawData * > getPrdsOnTrack(const Trk::Track &track) const override
returns a vector of PRDs belonging to the passed track.
Definition: InDetPRD_AssociationToolGangedPixels.cxx:217
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
InDet::InDetPRD_AssociationToolGangedPixels::finalize
virtual StatusCode finalize() override
Definition: InDetPRD_AssociationToolGangedPixels.cxx:34
Track.h
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
InDetPRD_AssociationToolGangedPixels.h
Trk::IPRD_AssociationTool::Maps::m_prepRawDataTrackMap
IPRD_AssociationTool::PrepRawDataTrackMap m_prepRawDataTrackMap
Definition: IPRD_AssociationTool.h:58
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
InDet::InDetPRD_AssociationToolGangedPixels::InDetPRD_AssociationToolGangedPixels
InDetPRD_AssociationToolGangedPixels(const std::string &, const std::string &, const IInterface *)
Definition: InDetPRD_AssociationToolGangedPixels.cxx:16
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
InDet::InDetPRD_AssociationToolGangedPixels::m_maps
Maps m_maps
Definition: InDetPRD_AssociationToolGangedPixels.h:108
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
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TRT_DriftCircleOnTrack.h
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Trk::RIO_OnTrackType::TRT_DriftCircle
@ TRT_DriftCircle
Definition: RIO_OnTrack.h:59
Trk::PrepRawData
Definition: PrepRawData.h:62
Trk::MeasurementBase
Definition: MeasurementBase.h:58
RIO_OnTrack.h
Trk::PrepRawDataType::PixelCluster
@ PixelCluster
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
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
Trk::IPRD_AssociationTool::TrackSet
std::set< const Track * > TrackSet
Definition: IPRD_AssociationTool.h:52
InDet::InDetPRD_AssociationToolGangedPixels::addPRDs
virtual StatusCode addPRDs(const Trk::Track &track) override
add the PRDs from this track to the store
Definition: InDetPRD_AssociationToolGangedPixels.cxx:39
InDet::InDetPRD_AssociationToolGangedPixels::initialize
virtual StatusCode initialize() override
Definition: InDetPRD_AssociationToolGangedPixels.cxx:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
InDet::InDetPRD_AssociationToolGangedPixels::m_pixelClusterAmbiguitiesMapName
SG::ReadHandleKey< PixelGangedClusterAmbiguities > m_pixelClusterAmbiguitiesMapName
Definition: InDetPRD_AssociationToolGangedPixels.h:110
InDet::InDetPRD_AssociationToolGangedPixels::findConnectedTracks
virtual Trk::IPRD_AssociationTool::TrackSet findConnectedTracks(const Trk::Track &track) const override
returns set of tracks which share PRD with this one
Definition: InDetPRD_AssociationToolGangedPixels.cxx:169
Trk::IPRD_AssociationTool::Maps
The mutable state of the tool.
Definition: IPRD_AssociationTool.h:56
SiliconTech::pixel
@ pixel
InDet::InDetPRD_AssociationToolGangedPixels::m_addTRToutliers
bool m_addTRToutliers
add TRT outliers in the addTrack method to avoid splits due to rejected extensions
Definition: InDetPRD_AssociationToolGangedPixels.h:113
Trk::IPRD_AssociationTool::Maps::m_trackPrepRawDataMap
IPRD_AssociationTool::TrackPrepRawDataMap m_trackPrepRawDataMap
Definition: IPRD_AssociationTool.h:60