ATLAS Offline Software
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 
16 InDet::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
58  if (prd->type(Trk::PrepRawDataType::PixelCluster)) {
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
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 
165 {
166  return findConnectedTracks (m_maps, track);
167 }
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 
211 std::vector< const Trk::PrepRawData* >
213 {
214  return getPrdsOnTrack (m_maps, track);
215 }
216 
217 
218 std::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
259  if (meas->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
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 
276 {
277  return onTracks (m_maps, prd);
278 }
279 
282  const Trk::PrepRawData& prd) const
283 {
284  return maps.m_prepRawDataTrackMap.equal_range(&prd);
285 }
286 
288 {
291 }
292 
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:275
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:287
TrkDetElementBase.h
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:86
InDet::InDetPRD_AssociationToolGangedPixels::m_addTRToutliers
BooleanProperty m_addTRToutliers
add TRT outliers in the addTrack method to avoid splits due to rejected extensions
Definition: InDetPRD_AssociationToolGangedPixels.h:113
InDet::InDetPRD_AssociationToolGangedPixels::~InDetPRD_AssociationToolGangedPixels
virtual ~InDetPRD_AssociationToolGangedPixels()
skel.it
it
Definition: skel.GENtoEVGEN.py:396
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:212
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:29
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
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
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:794
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:34
InDet::InDetPRD_AssociationToolGangedPixels::initialize
virtual StatusCode initialize() override
Definition: InDetPRD_AssociationToolGangedPixels.cxx:23
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
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:164
Trk::IPRD_AssociationTool::Maps
The mutable state of the tool.
Definition: IPRD_AssociationTool.h:56
SiliconTech::pixel
@ pixel
Trk::IPRD_AssociationTool::Maps::m_trackPrepRawDataMap
IPRD_AssociationTool::TrackPrepRawDataMap m_trackPrepRawDataMap
Definition: IPRD_AssociationTool.h:60