ATLAS Offline Software
PRDtoTrackMapTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "TrkTrack/Track.h"
11 
12 #include <cassert>
13 #include <vector>
14 #include "ext/functional"
15 
17  const std::string& n,
18  const IInterface* p)
19  : base_class(t,n,p)
20 {
21 }
22 
24  ATH_CHECK(m_idHelperSvc.retrieve());
25  return StatusCode::SUCCESS;
26 }
27 
28 std::unique_ptr<Trk::PRDtoTrackMap> Trk::PRDtoTrackMapTool::createPRDtoTrackMap() const {
29  return std::make_unique<Trk::PRDtoTrackMapTool::PRDtoTrackMap>();
30 }
31 
32 std::unique_ptr<Trk::PRDtoTrackMap> Trk::PRDtoTrackMapTool::reduceToStorableMap(std::unique_ptr<Trk::PRDtoTrackMap> &&obj_in) const {
33  return std::move(obj_in);
34 }
35 
36 void Trk::PRDtoTrackMapTool::ensureType(Trk::PRDtoTrackMap &virt_prd_to_track_map) const
37 {
38  if (virt_prd_to_track_map.getType() != typeid(PRDtoTrackMapTool::PRDtoTrackMap)) {
39  ATH_MSG_FATAL( "Type mismap between tool and map. Expecting " << typeid(PRDtoTrackMap).name()
40  << " but got " << virt_prd_to_track_map.getType().name()
41  << " . The tool can only handle a map created by the same tool. ");
42  throw std::logic_error("Type mismap between tool and map");
43  }
44  assert( dynamic_cast<PRDtoTrackMap *>(&virt_prd_to_track_map) != nullptr );
45 }
46 
48 {
49  ensureType(virt_prd_to_track_map);
50  PRDtoTrackMap &prd_to_track_map = static_cast<PRDtoTrackMap&>(virt_prd_to_track_map);
51 
52  // test caching
53  PRDtoTrackMap::TrackPrepRawDataMap::const_iterator itvec = prd_to_track_map.m_trackPrepRawDataMap.find(&track);
54  if (itvec!=prd_to_track_map.m_trackPrepRawDataMap.end())
55  {
56  ATH_MSG_ERROR ("track already found in cache, should not happen");
57  return StatusCode::FAILURE;
58  }
59  // add all prds on track to map
60  std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack(prd_to_track_map, track );
61  for(const Trk::PrepRawData*a_prd : prds) {
62  if (prd_to_track_map.m_prepRawDataTrackMap.insert(std::make_pair(a_prd, &track) ) == prd_to_track_map.m_prepRawDataTrackMap.end()) {
63  ATH_MSG_ERROR ("failed to associate track to prd.");
64  }
65  }
66 
67  // cache this using m_trackPrepRawDataMap
68  prd_to_track_map.m_trackPrepRawDataMap.insert( std::make_pair(&track, std::move(prds)) );
69 
70  ATH_MSG_DEBUG ("Added PRDs from Track at ("<<&track<<") - map now has size: \t"<<
71  prd_to_track_map.m_prepRawDataTrackMap.size());
72  return StatusCode::SUCCESS;
73 }
74 
75 
78 {
79  ensureType(virt_prd_to_track_map);
80  PRDtoTrackMap &prd_to_track_map = static_cast<PRDtoTrackMap&>(virt_prd_to_track_map);
81 
82  TrackSet connectedTracks;
83 
84  std::vector< const Trk::PrepRawData* > prds = getPrdsOnTrack(prd_to_track_map, track);
85  for (const Trk::PrepRawData* a_prd : prds )
86  {
87  PRDtoTrackMap::PrepRawDataTrackMapRange range = prd_to_track_map.onTracks(*a_prd);
88 
89  // TODO use remove_copy_if instead.
90  for ( ; range.first!=range.second; ++(range.first) )
91  {
92  const Track* conTrack = (range.first)->second;
93  // don't copy this track!
94  if (conTrack!=&track) {
95  // this does actually not allow for double entries
96  connectedTracks.insert(conTrack);
97  ATH_MSG_VERBOSE ("Track "<<&track<<" \tshares PRD "<<a_prd<<" \twith track:"<<conTrack);
98  }
99  }
100  ATH_MSG_VERBOSE ("Added in connected tracks for PRD:"<<a_prd<<
101  "\tsize of list now:"<<connectedTracks.size());
102  }
103 
104  return connectedTracks;
105 }
106 
107 
108 std::vector< const Trk::PrepRawData* >
110  const Trk::Track& track) const
111 {
112  using PRDs_t = std::vector<const Trk::PrepRawData *>;
113 
114  ensureType(virt_prd_to_track_map);
115  PRDtoTrackMap &prd_to_track_map = static_cast<PRDtoTrackMap&>(virt_prd_to_track_map);
116 
117  // test caching
118  PRDtoTrackMap::TrackPrepRawDataMap::const_iterator itvec = prd_to_track_map.m_trackPrepRawDataMap.find(&track);
119  if (itvec!=prd_to_track_map.m_trackPrepRawDataMap.end())
120  {
121  ATH_MSG_VERBOSE ("found track in cache, return cached PRD vector for track");
122  return itvec->second;
123  }
124 
125  if (!track.measurementsOnTrack()) {
126  ATH_MSG_WARNING ("Track has no RoTs");
127  return {};
128  }
129 
130  // FIXME can I do this without copying the vector?
131  /* transform(
132  track.measurementsOnTrack()->begin(),
133  track.measurementsOnTrack()->end() ,
134  back_inserter(vec),
135  bind2nd(CreatePRD_VectorFromTrack(), &track) );*/
136 
137  PRDs_t vec;
138  vec.reserve(track.measurementsOnTrack()->size());
139 
140  auto add_prd = [&vec, this] (const Trk::RIO_OnTrack* rot) {
141  if (!rot) return;
142  const PrepRawData* prd = rot->prepRawData();
143  if (!prd) return;
144  const Identifier rot_id = prd->identify();
146  if ( m_idHelperSvc->isMuon(rot_id) && !m_idHelperSvc->isMdt(rot_id) && !m_idHelperSvc->isMM(rot_id) && !m_idHelperSvc->issTgc(rot_id) &&
147  (!m_idHelperSvc->isCsc(rot_id) || m_idHelperSvc->measuresPhi(rot_id)) ) return;
148  vec.push_back(prd);
149  };
150  for (const MeasurementBase* meas : *track.measurementsOnTrack()) {
151  const Trk::RIO_OnTrack* rot = nullptr;
152  if (meas->type(Trk::MeasurementBaseType::RIO_OnTrack)) {
153  rot = static_cast<const RIO_OnTrack*>(meas);
154  }
155  if (rot) {
156  add_prd(rot);
157  continue;
158  }
159  const Trk::CompetingRIOsOnTrack* competingROT = nullptr;
161  competingROT = static_cast<const Trk::CompetingRIOsOnTrack*>(meas);
162  }
163  if (!competingROT) { continue;}
164  const unsigned int numROTs = competingROT->numberOfContainedROTs();
165  for( unsigned int i=0;i<numROTs;++i ){
166  const Trk::RIO_OnTrack* rot = &competingROT->rioOnTrack(i);
167  add_prd(rot);
168  }
169  }
170  ATH_MSG_DEBUG (" Getting "<<vec.size()<<" PRDs from track at:"<<&track);
171 
172  return vec;
173 }
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
PRDtoTrackMapTool.h
Trk::PRDtoTrackMap::PrepRawDataTrackMapRange
std::pair< PrepRawDataTrackMap::iterator, PrepRawDataTrackMap::iterator > PrepRawDataTrackMapRange
Definition: PRDtoTrackMap.h:40
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CompetingRIOsOnTrack.h
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.
Trk::PRDtoTrackMap
Definition: PRDtoTrackMap.h:17
CP::TrackSet
std::set< TrackPtr > TrackSet
Definition: PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/Defs.h:72
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
Trk::PRDtoTrackMapTool::PRDtoTrackMap
Definition: PRDtoTrackMapTool.h:56
PrepRawData.h
Track.h
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
Trk::CompetingRIOsOnTrack::rioOnTrack
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
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
Trk::PRDtoTrackMapTool::ensureType
void ensureType(Trk::PRDtoTrackMap &virt_prd_to_track_map) const
Definition: PRDtoTrackMapTool.cxx:36
Trk::CompetingRIOsOnTrack::numberOfContainedROTs
virtual unsigned int numberOfContainedROTs() const =0
Number of RIO_OnTracks to be contained by this CompetingRIOsOnTrack.
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::MeasurementBaseType::CompetingRIOsOnTrack
@ CompetingRIOsOnTrack
Definition: MeasurementBase.h:50
beamspotman.n
n
Definition: beamspotman.py:731
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
Trk::CompetingRIOsOnTrack
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
Definition: CompetingRIOsOnTrack.h:64
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::PRDtoTrackMap::getType
virtual const std::type_info & getType() const
Trk::PrepRawData
Definition: PrepRawData.h:62
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
Trk::PRDtoTrackMapTool::PRDtoTrackMapTool
PRDtoTrackMapTool(const std::string &, const std::string &, const IInterface *)
Definition: PRDtoTrackMapTool.cxx:16
Trk::PRDtoTrackMapTool::initialize
virtual StatusCode initialize() override
Definition: PRDtoTrackMapTool.cxx:23
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RIO_OnTrack.h
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
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::PRDtoTrackMapTool::reduceToStorableMap
virtual std::unique_ptr< Trk::PRDtoTrackMap > reduceToStorableMap(std::unique_ptr< Trk::PRDtoTrackMap > &&obj_in) const override
Definition: PRDtoTrackMapTool.cxx:32
Trk::PRDtoTrackMapTool::createPRDtoTrackMap
virtual std::unique_ptr< Trk::PRDtoTrackMap > createPRDtoTrackMap() const override
Definition: PRDtoTrackMapTool.cxx:28
Track
Definition: TriggerChamberClusterOnTrackCreator.h:21
Trk::PRDtoTrackMapTool::findConnectedTracks
virtual IPRDtoTrackMapTool::TrackSet findConnectedTracks(Trk::PRDtoTrackMap &virt_prd_to_track_map, const Track &track) const override
Definition: PRDtoTrackMapTool.cxx:77
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Trk::PRDtoTrackMapTool::addPRDs
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: PRDtoTrackMapTool.cxx:47
Trk::PRDtoTrackMapTool::getPrdsOnTrack
virtual std::vector< const PrepRawData * > getPrdsOnTrack(Trk::PRDtoTrackMap &virt_prd_to_track_map, const Track &track) const override
returns a vector of PRDs belonging to the passed track.
Definition: PRDtoTrackMapTool.cxx:109
Identifier
Definition: IdentifierFieldParser.cxx:14