ATLAS Offline Software
InDetPRDtoTrackMapToolGangedPixels.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include "TrkTrack/Track.h"
12 #include "Identifier/Identifier.h"
15 
16 #include <memory>
17 
18 #include <vector>
20  const std::string& n,
21  const IInterface* p)
22  : base_class(t,n,p)
23 { }
24 
26 = default;
27 
29 {
30  bool has_ambi_map = m_pixelClusterAmbiguitiesMapName.initialize(!m_pixelClusterAmbiguitiesMapName.key().empty()).isSuccess();
31  if (!has_ambi_map && !m_pixelClusterAmbiguitiesMapName.key().empty()) {
32  ATH_MSG_WARNING("Could not retrieve "<< m_pixelClusterAmbiguitiesMapName.key() << " this is ok if pixel is off");
33  // @TODO introduce more robust method e.g. dummy tool if pixel is off ?
34  }
35 
36  return StatusCode::SUCCESS;
37 }
38 
40 {
41  return StatusCode::SUCCESS;
42 }
43 
44 std::unique_ptr<Trk::PRDtoTrackMap> InDet::InDetPRDtoTrackMapToolGangedPixels::createPRDtoTrackMap() const {
45  std::unique_ptr<PRDtoTrackMap> prd_to_track_map( new PRDtoTrackMap(m_pixelClusterAmbiguitiesMapName ) );
46 
48  << ", number of entries for this event:"
49  << (prd_to_track_map->m_gangedAmbis.isValid() ? prd_to_track_map->m_gangedAmbis->size() : -1) );
50  return std::unique_ptr<Trk::PRDtoTrackMap>(prd_to_track_map.release());
51 }
52 
53 std::unique_ptr<Trk::PRDtoTrackMap> InDet::InDetPRDtoTrackMapToolGangedPixels::reduceToStorableMap(std::unique_ptr<Trk::PRDtoTrackMap> &&obj_in) const {
54  if (obj_in->getType()!=typeid(Trk::PRDtoTrackMap)) {
55  return std::move(obj_in);
56  }
57  if (obj_in->getType()!=typeid(InDet::InDetPRDtoTrackMapToolGangedPixels)) {
58  ATH_MSG_FATAL( "Type mismap between tool and map. Expecting " << typeid(InDet::InDetPRDtoTrackMapToolGangedPixels).name()
59  << " but got " << obj_in->getType().name()
60  << " . The tool can only handle a map created by the same tool. ");
61  }
62  Trk::PRDtoTrackMap *the_obj=static_cast<PRDtoTrackMap *>(obj_in.get());
63  return std::make_unique<Trk::PRDtoTrackMap>(std::move(*the_obj));
64 }
65 
66 
68 {
69  if (virt_prd_to_track_map.getType() != typeid(InDetPRDtoTrackMapToolGangedPixels::PRDtoTrackMap)) {
70  ATH_MSG_FATAL( "Type mismap between tool and map. Expecting " << typeid(InDetPRDtoTrackMapToolGangedPixels).name()
71  << " but got " << virt_prd_to_track_map.getType().name()
72  << " . The tool can only handle a map created by the same tool. ");
73  throw std::logic_error("Type mismap between tool and map");
74  }
75  assert( dynamic_cast<InDetPRDtoTrackMapToolGangedPixels::PRDtoTrackMap *>(&virt_prd_to_track_map) != nullptr );
76 }
77 
78 
80 {
81  ensureType(virt_prd_to_track_map);
82  PRDtoTrackMap &prd_to_track_map = static_cast<PRDtoTrackMap&>(virt_prd_to_track_map);
83  // test caching
84  Trk::PRDtoTrackMap::TrackPrepRawDataMap::const_iterator itvec = prd_to_track_map.m_trackPrepRawDataMap.find(&track);
85  if (itvec!=prd_to_track_map.m_trackPrepRawDataMap.end())
86  {
87  ATH_MSG_ERROR("track already found in cache, should not happen");
88  return StatusCode::FAILURE;
89  }
90  // get all prds on 'track'
91  std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack(prd_to_track_map, track );
92  // loop over PRD
93  for (const Trk::PrepRawData* prd : prds) {
94  prd_to_track_map.m_prepRawDataTrackMap.insert(std::make_pair(prd, &track) );
95  // test ganged ambiguity
96  if (prd->type(Trk::PrepRawDataType::PixelCluster)) {
97  const PixelCluster* pixel = static_cast<const PixelCluster*> (prd);
98  if (pixel->gangedPixel()) {
99  ATH_MSG_DEBUG( "Found ganged pixel, search for mirror" );
100  std::pair<PixelGangedClusterAmbiguities::const_iterator,
101  PixelGangedClusterAmbiguities::const_iterator> ambi = prd_to_track_map.m_gangedAmbis->equal_range(pixel);
102  for (; ambi.first != ambi.second ; ++(ambi.first) ) {
103  // add ambiguity as used by this track as well
104  if (msgLvl(MSG::DEBUG)) msg() << "Found mirror pixel, add mirror to association map" << endmsg;
105  prd_to_track_map.m_prepRawDataTrackMap.insert(std::make_pair(ambi.first->second, &track) );
106  }
107  }
108  }
109  }
110 
111  // cache this using m_trackPrepRawDataMap
112  prd_to_track_map.m_trackPrepRawDataMap.insert( std::make_pair(&track, prds) );
113 
114  ATH_MSG_DEBUG("Added PRDs from Track at ("<<&track<<") - map now has size: \t"
115  <<prd_to_track_map.m_prepRawDataTrackMap.size() );
116  return StatusCode::SUCCESS;
117 }
118 
119 
122  const Trk::Track& track ) const
123 {
124  ensureType(virt_prd_to_track_map);
125  PRDtoTrackMap &prd_to_track_map = static_cast<PRDtoTrackMap&>(virt_prd_to_track_map);
126 
127  TrackSet connectedTracks;
128 
129  std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack(virt_prd_to_track_map, track);
130  for (const Trk::PrepRawData* prd : prds) {
132  // add them into the list
133  for ( ; range.first!=range.second; ++(range.first) )
134  connectedTracks.insert((range.first)->second);
135 
136  // test ganged ambiguity
137 
138  if (prd->type(Trk::PrepRawDataType::PixelCluster)) {
139  const PixelCluster* pixel = static_cast<const PixelCluster*> (prd);
140  if (pixel->gangedPixel()) {
141  std::pair<PixelGangedClusterAmbiguities::const_iterator,
142  PixelGangedClusterAmbiguities::const_iterator> ambi = prd_to_track_map.m_gangedAmbis->equal_range(pixel);
143  for (; ambi.first != ambi.second ; ++(ambi.first) ) {
144  range = prd_to_track_map.onTracks( *(ambi.first->second) );
145  // add them into the list
146  for ( ; range.first!=range.second; ++(range.first) )
147  connectedTracks.insert((range.first)->second);
148  }
149  }
150  }
151  }
152 
153  // don't forget to remove the input track
154  connectedTracks.erase(&track);
155 
156  ATH_MSG_VERBOSE("Added in connected tracks for track "<<&track
157  << "\tsize of list is "<<connectedTracks.size());
158 
159  return connectedTracks;
160 }
161 
162 
163 std::vector< const Trk::PrepRawData* >
165  const Trk::Track& track) const
166 {
167  ensureType(virt_prd_to_track_map);
168  PRDtoTrackMap &prd_to_track_map = static_cast<PRDtoTrackMap&>(virt_prd_to_track_map);
169  using PRDs_t = std::vector<const Trk::PrepRawData *>;
170 
171  // test caching
172  Trk::PRDtoTrackMap::TrackPrepRawDataMap::const_iterator itvec = prd_to_track_map.m_trackPrepRawDataMap.find(&track);
173  if (itvec!=prd_to_track_map.m_trackPrepRawDataMap.end())
174  {
175  ATH_MSG_VERBOSE("found track in cache, return cached PRD vector for track");
176  return itvec->second;
177  }
178 
179  if (track.measurementsOnTrack()==nullptr) {
180  ATH_MSG_WARNING("Track has no RoTs");
181  return {}; // return vector optimization
182  }
183 
184  // FIXME can I do this without copying the vector?
185  /* transform(
186  track.measurementsOnTrack()->begin(),
187  track.measurementsOnTrack()->end() ,
188  back_inserter(vec),
189  bind2nd(CreatePRD_VectorFromTrack(), &track) );*/
190 
191  // output vector
192  PRDs_t vec;
193  // size it
194  vec.reserve(track.measurementsOnTrack()->size());
195 
196  // get the PRDs for the measurements on track
197  DataVector<const Trk::MeasurementBase>::const_iterator it = track.measurementsOnTrack()->begin();
198  DataVector<const Trk::MeasurementBase>::const_iterator itEnd = track.measurementsOnTrack()->end();
199  for (;it!=itEnd;++it)
200  {
201  const auto *const meas{*it};
202  if (meas->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
203  const Trk::RIO_OnTrack* rot = static_cast<const Trk::RIO_OnTrack*>(meas);
204  if(rot->prepRawData()) vec.push_back(rot->prepRawData());
205  }
206  }
207  ATH_MSG_DEBUG(" Getting "<<vec.size()<<" PRDs from track at:"<<&track);
208  // new mode, we add the outliers in the TRT
209  if (m_addTRToutliers) {
210  // get the PRDs for the measurements on track
211  for (const Trk::MeasurementBase* meas : *track.outliersOnTrack()){
212  // get the ROT, make sure it is not a pseudo measurement
213  if (meas->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
214  const Trk::RIO_OnTrack* rot = static_cast<const Trk::RIO_OnTrack*>(meas);
215  // check if outlier is TRT ?
217  // add to the list, it is TRT
218  if(rot->prepRawData()) vec.push_back(rot->prepRawData());
219  }
220  }
221  }
222  ATH_MSG_DEBUG(" Getting "<<vec.size()<<" PRDs including TRT outlier from track at:"<<&track);
223  }
224 
225  return vec;
226 }
227 
229 {
230  if (!key.key().empty()) {
232  }
233 }
234 
PRDtoTrackMap.h
InDet::InDetPRDtoTrackMapToolGangedPixels::getPrdsOnTrack
virtual std::vector< const Trk::PrepRawData * > getPrdsOnTrack(Trk::PRDtoTrackMap &virt_prd_to_track_map, const Trk::Track &track) const override
returns a vector of PRDs belonging to the passed track.
Definition: InDetPRDtoTrackMapToolGangedPixels.cxx:164
TrkDetElementBase.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
InDet::InDetPRDtoTrackMapToolGangedPixels::createPRDtoTrackMap
virtual std::unique_ptr< Trk::PRDtoTrackMap > createPRDtoTrackMap() const override
Definition: InDetPRDtoTrackMapToolGangedPixels.cxx:44
InDet::InDetPRDtoTrackMapToolGangedPixels::reduceToStorableMap
virtual std::unique_ptr< Trk::PRDtoTrackMap > reduceToStorableMap(std::unique_ptr< Trk::PRDtoTrackMap > &&obj_in) const override
Definition: InDetPRDtoTrackMapToolGangedPixels.cxx:53
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
Trk::PRDtoTrackMap::onTracks
PrepRawDataTrackMapRange onTracks(const PrepRawData &prd)
get the Tracks associated with this PrepRawData.
PixelCluster.h
Trk::PRDtoTrackMap
Definition: PRDtoTrackMap.h:17
InDet::InDetPRDtoTrackMapToolGangedPixels::InDetPRDtoTrackMapToolGangedPixels
InDetPRDtoTrackMapToolGangedPixels(const std::string &, const std::string &, const IInterface *)
Definition: InDetPRDtoTrackMapToolGangedPixels.cxx:19
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.
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
Trk::PRDtoTrackMap::PRDtoTrackMap
PRDtoTrackMap()=default
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
InDet::InDetPRDtoTrackMapToolGangedPixels::PRDtoTrackMap
Definition: InDetPRDtoTrackMapToolGangedPixels.h:65
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
SG::ReadHandleKey< PixelGangedClusterAmbiguities >
InDet::InDetPRDtoTrackMapToolGangedPixels::findConnectedTracks
virtual Trk::IPRDtoTrackMapTool::TrackSet findConnectedTracks(Trk::PRDtoTrackMap &virt_prd_to_track_map, const Trk::Track &track) const override
returns set of tracks which share PRD with this one
Definition: InDetPRDtoTrackMapToolGangedPixels.cxx:121
Track.h
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
Trk::IPRDtoTrackMapTool::TrackSet
std::set< const Track * > TrackSet
Definition: IPRDtoTrackMapTool.h:42
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
InDet::InDetPRDtoTrackMapToolGangedPixels::PRDtoTrackMap::m_gangedAmbis
SG::ReadHandle< PixelGangedClusterAmbiguities > m_gangedAmbis
Definition: InDetPRDtoTrackMapToolGangedPixels.h:73
InDet::InDetPRDtoTrackMapToolGangedPixels::m_addTRToutliers
BooleanProperty m_addTRToutliers
add TRT outliers in the addTrack method to avoid splits due to rejected extensions
Definition: InDetPRDtoTrackMapToolGangedPixels.h:62
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Trk::PRDtoTrackMap::m_trackPrepRawDataMap
TrackPrepRawDataMap m_trackPrepRawDataMap
holds the PRDs associated with each Track (i.e.
Definition: PRDtoTrackMap.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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::InDetPRDtoTrackMapToolGangedPixels::initialize
virtual StatusCode initialize() override
Definition: InDetPRDtoTrackMapToolGangedPixels.cxx:28
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Trk::PRDtoTrackMap::getType
virtual const std::type_info & getType() const
InDet::InDetPRDtoTrackMapToolGangedPixels
Concrete Implementation of the IPRD_AssociationTool interface.
Definition: InDetPRDtoTrackMapToolGangedPixels.h:21
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::RIO_OnTrackType::TRT_DriftCircle
@ TRT_DriftCircle
Definition: RIO_OnTrack.h:59
Trk::PrepRawData
Definition: PrepRawData.h:62
Trk::MeasurementBase
Definition: MeasurementBase.h:58
InDet::InDetPRDtoTrackMapToolGangedPixels::addPRDs
virtual StatusCode addPRDs(Trk::PRDtoTrackMap &virt_prd_to_track_map, const Trk::Track &track) const override
add the PRDs from this track to the store
Definition: InDetPRDtoTrackMapToolGangedPixels.cxx:79
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RIO_OnTrack.h
InDet::InDetPRDtoTrackMapToolGangedPixels::ensureType
void ensureType(Trk::PRDtoTrackMap &virt_prd_to_track_map) const
Definition: InDetPRDtoTrackMapToolGangedPixels.cxx:67
Trk::PrepRawDataType::PixelCluster
@ PixelCluster
InDet::InDetPRDtoTrackMapToolGangedPixels::finalize
virtual StatusCode finalize() override
Definition: InDetPRDtoTrackMapToolGangedPixels.cxx:39
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::PRDtoTrackMap::m_prepRawDataTrackMap
PrepRawDataTrackMap m_prepRawDataTrackMap
holds the tracks associated with each PRD (i.e.
Definition: PRDtoTrackMap.h:82
Trk::MeasurementBaseType::RIO_OnTrack
@ RIO_OnTrack
Definition: MeasurementBase.h:49
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
InDet::InDetPRDtoTrackMapToolGangedPixels::~InDetPRDtoTrackMapToolGangedPixels
virtual ~InDetPRDtoTrackMapToolGangedPixels()
InDetPRDtoTrackMapToolGangedPixels.h
InDet::InDetPRDtoTrackMapToolGangedPixels::m_pixelClusterAmbiguitiesMapName
SG::ReadHandleKey< PixelGangedClusterAmbiguities > m_pixelClusterAmbiguitiesMapName
Definition: InDetPRDtoTrackMapToolGangedPixels.h:59
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
PixelClusterOnTrack.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
SiliconTech::pixel
@ pixel
Trk::PRDtoTrackMap::ConstPrepRawDataTrackMapRange
std::pair< PrepRawDataTrackMap::const_iterator, PrepRawDataTrackMap::const_iterator > ConstPrepRawDataTrackMapRange
Definition: PRDtoTrackMap.h:44
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37