CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LayerMeasurements.cc
Go to the documentation of this file.
5 
10 
14 
16 
17 
19 
20 #include <algorithm>
21 
22 using namespace std;
23 
24 
25 namespace {
27  inline
28  void addInvalidMeas( std::vector<TrajectoryMeasurement>& result,
29  const TrajectoryStateOnSurface& ts, const GeomDet* det, const DetLayer& layer) {
30  result.emplace_back(ts, std::make_shared<InvalidTrackingRecHit>(*det, TrackingRecHit::missing), 0.F,&layer);
31  }
32 
33 
34 
42  inline
43  std::vector<TrajectoryMeasurement>
44  get(const MeasurementDetSystem* theDetSystem,
45  const MeasurementTrackerEvent* theData,
46  const DetLayer& layer,
47  std::vector<DetWithState> const& compatDets,
48  const TrajectoryStateOnSurface& ts,
49  const Propagator& prop,
50  const MeasurementEstimator& est) {
51  std::vector<TrajectoryMeasurement> result;
52  typedef TrajectoryMeasurement TM;
53 
55 
56  for ( auto const & ds : compatDets) {
57  MeasurementDetWithData mdet = theDetSystem->idToDet(ds.first->geographicalId(), *theData);
58  if unlikely(mdet.isNull()) {
59  throw MeasurementDetException( "MeasurementDet not found");
60  }
61 
62  if (mdet.measurements(ds.second, est,tmps))
63  for (std::size_t i=0; i!=tmps.size(); ++i)
64  result.emplace_back(ds.second,std::move(tmps.hits[i]),tmps.distances[i],&layer);
65  tmps.clear();
66  }
67  // WARNING: we might end up with more than one invalid hit of type 'inactive' in result
68  // to be fixed in order to avoid usless double traj candidates.
69 
70  // sort the final result
71  if ( result.size() > 1) {
72  sort( result.begin(), result.end(), TrajMeasLessEstim());
73  }
74 
75 
76  if ( !result.empty()) {
77  // invalidMeas on Det of most compatible hit
78  addInvalidMeas( result, result.front().predictedState(), result.front().recHit()->det(),layer);
79  }
80  else {
81  // invalid state on first compatible Det
82  addInvalidMeas( result, compatDets.front().second, compatDets.front().first,layer);
83  }
84 
85  return result;
86  }
87 
88 }
89 
90 
91 // return just valid hits, no sorting (for seeding mostly)
93  const DetLayer& layer,
94  const TrajectoryStateOnSurface& startingState,
95  const Propagator& prop,
96  const MeasurementEstimator& est) const {
97 
98  auto const & compatDets = layer.compatibleDets( startingState, prop, est);
99  if (compatDets.empty()) return false;
100  bool ret=false;
101  for ( auto const & ds : compatDets) {
102  auto mdet = theDetSystem->idToDet(ds.first->geographicalId(), *theData);
103  ret |=mdet.recHits(result,ds.second,est);
104  }
105  return ret;
106 }
107 
108 
109 vector<TrajectoryMeasurement>
111  const TrajectoryStateOnSurface& startingState,
112  const Propagator& prop,
113  const MeasurementEstimator& est) const {
114 
116 
117  vector<DetWithState> const & compatDets = layer.compatibleDets( startingState, prop, est);
118 
119  if (!compatDets.empty()) return get(theDetSystem, theData, layer, compatDets, startingState, prop, est);
120 
121  vector<TrajectoryMeasurement> result;
122  pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
123 
124  if ( compat.first) {
125  result.push_back( TrajectoryMeasurement( compat.second,
126  std::make_shared<InvalidTrackingRecHitNoDet>(layer.surface(), TrackingRecHit::inactive), 0.F,
127  &layer));
128  LogDebug("LayerMeasurements")<<"adding a missing hit.";
129  }else LogDebug("LayerMeasurements")<<"adding not measurement.";
130 
131 
132  return result;
133 
134 }
135 
136 
137 vector<TrajectoryMeasurementGroup>
139  const TrajectoryStateOnSurface& startingState,
140  const Propagator& prop,
141  const MeasurementEstimator& est) const {
142  vector<TrajectoryMeasurementGroup> result;
143 
144  vector<DetGroup> && groups = layer.groupedCompatibleDets( startingState, prop, est);
145  result.reserve(groups.size());
146 
148  for (auto& grp : groups) {
149  if ( grp.empty() ) continue;
150 
151  vector<TrajectoryMeasurement> tmpVec;
152  for (auto const & det : grp) {
153  MeasurementDetWithData mdet = theDetSystem->idToDet(det.det()->geographicalId(), *theData);
154  if (mdet.isNull()) {
155  throw MeasurementDetException( "MeasurementDet not found");
156  }
157  if (mdet.measurements( det.trajectoryState(), est,tmps))
158  for (std::size_t i=0; i!=tmps.size(); ++i)
159  tmpVec.emplace_back(det.trajectoryState(),std::move(tmps.hits[i]),tmps.distances[i],&layer);
160  tmps.clear();
161  }
162 
163  // sort the final result
164  LogDebug("LayerMeasurements")<<"Sorting " << tmpVec.size() << " measurements in this grp.";
165  sort( tmpVec.begin(), tmpVec.end(), TrajMeasLessEstim());
166  addInvalidMeas( tmpVec, grp,layer);
167  result.emplace_back(std::move(tmpVec), std::move(grp));
168  }
169 
170 
171  // if the result is empty check if the layer is compatible (for invalid measurement)
172  if (result.empty()) {
173  pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
174  if ( compat.first) {
175  vector<TrajectoryMeasurement> tmVec;
176  tmVec.emplace_back(compat.second, std::make_shared<InvalidTrackingRecHitNoDet>(layer.surface(), TrackingRecHit::inactive), 0.F,&layer);
177  result.emplace_back(std::move(tmVec), DetGroup());
178  }
179  }
180  return result;
181 }
182 
183 void LayerMeasurements::addInvalidMeas( vector<TrajectoryMeasurement>& measVec,
184  const DetGroup& group,
185  const DetLayer& layer) const
186 {
187  if (!measVec.empty()) {
188  // invalidMeas on Det of most compatible hit
189  measVec.emplace_back(measVec.front().predictedState(),
190  std::make_shared<InvalidTrackingRecHit>(*measVec.front().recHit()->det(), TrackingRecHit::missing),
191  0.,&layer);
192  }
193  else if (!group.empty()) {
194  // invalid state on first compatible Det
195  measVec.emplace_back(group.front().trajectoryState(),
196  std::make_shared<InvalidTrackingRecHit>(*group.front().det(), TrackingRecHit::missing), 0.,&layer);
197  }
198 }
#define LogDebug(id)
virtual std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const =0
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
std::size_t size() const
virtual std::vector< DetGroup > groupedCompatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
std::vector< BaseTrackerRecHit * > SimpleHitContainer
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
tuple result
Definition: mps_fire.py:84
#define unlikely(x)
bool recHits(SimpleHitContainer &result, const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
RecHitContainer recHits(const TrajectoryStateOnSurface &tsos) const
def move
Definition: eostools.py:510
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
tuple group
Definition: watchdog.py:82
void addInvalidMeas(std::vector< TrajectoryMeasurement > &measVec, const DetGroup &group, const DetLayer &layer) const
std::vector< TrajectoryMeasurementGroup > groupedMeasurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
bool measurements(const TrajectoryStateOnSurface &stateOnThisDet, const MeasurementEstimator &est, TempMeasurements &result) const