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, InvalidTransientRecHit::build(det, TrackingRecHit::missing), 0.F,&layer);
31  }
32 
33 
34 
42  inline
43  std::vector<TrajectoryMeasurement>
44  get(const MeasurementDetSystem* theDetSystem,
45  const DetLayer& layer,
46  std::vector<DetWithState> const& compatDets,
47  const TrajectoryStateOnSurface& ts,
48  const Propagator& prop,
49  const MeasurementEstimator& est) {
50  std::vector<TrajectoryMeasurement> result;
51  typedef TrajectoryMeasurement TM;
52 
54 
55  for ( auto const & ds : compatDets) {
56  const MeasurementDet* mdet = theDetSystem->idToDet(ds.first->geographicalId());
57  if unlikely(mdet == nullptr) {
58  throw MeasurementDetException( "MeasurementDet not found");
59  }
60 
61  if (mdet->measurements(ds.second, est,tmps))
62  for (std::size_t i=0; i!=tmps.size(); ++i)
63  result.emplace_back(ds.second,std::move(tmps.hits[i]),tmps.distances[i],&layer);
64  tmps.clear();
65  }
66  // WARNING: we might end up with more than one invalid hit of type 'inactive' in result
67  // to be fixed in order to avoid usless double traj candidates.
68 
69  // sort the final result
70  if ( result.size() > 1) {
71  sort( result.begin(), result.end(), TrajMeasLessEstim());
72  }
73 
74 
75  if ( !result.empty()) {
76  // invalidMeas on Det of most compatible hit
77  addInvalidMeas( result, result.front().predictedState(), result.front().recHit()->det(),layer);
78  }
79  else {
80  // invalid state on first compatible Det
81  addInvalidMeas( result, compatDets.front().second, compatDets.front().first,layer);
82  }
83 
84  return result;
85  }
86 
87 }
88 
89 vector<TrajectoryMeasurement>
91  const TrajectoryStateOnSurface& startingState,
92  const Propagator& prop,
93  const MeasurementEstimator& est) const {
94 
96 
97  vector<DetWithState> const & compatDets = layer.compatibleDets( startingState, prop, est);
98 
99  if (!compatDets.empty()) return get(theDetSystem, layer, compatDets, startingState, prop, est);
100 
101  vector<TrajectoryMeasurement> result;
102  pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
103 
104  if ( compat.first) {
105  result.push_back( TrajectoryMeasurement( compat.second,
107  &layer));
108  LogDebug("LayerMeasurements")<<"adding a missing hit.";
109  }else LogDebug("LayerMeasurements")<<"adding not measurement.";
110 
111 
112  return result;
113 
114 }
115 
116 
117 vector<TrajectoryMeasurementGroup>
119  const TrajectoryStateOnSurface& startingState,
120  const Propagator& prop,
121  const MeasurementEstimator& est) const {
122  vector<TrajectoryMeasurementGroup> result;
123 
124  vector<DetGroup> && groups = layer.groupedCompatibleDets( startingState, prop, est);
125  result.reserve(groups.size());
126 
128  for (auto& grp : groups) {
129  if ( grp.empty() ) continue;
130 
131  vector<TrajectoryMeasurement> tmpVec;
132  for (auto const & det : grp) {
133  const MeasurementDet* mdet = theDetSystem->idToDet(det.det()->geographicalId());
134  if (mdet == 0) {
135  throw MeasurementDetException( "MeasurementDet not found");
136  }
137  if (mdet->measurements( det.trajectoryState(), est,tmps))
138  for (std::size_t i=0; i!=tmps.size(); ++i)
139  tmpVec.emplace_back(det.trajectoryState(),std::move(tmps.hits[i]),tmps.distances[i],&layer);
140  tmps.clear();
141  }
142 
143  // sort the final result
144  sort( tmpVec.begin(), tmpVec.end(), TrajMeasLessEstim());
145  addInvalidMeas( tmpVec, grp,layer);
146  result.emplace_back(std::move(tmpVec), std::move(grp));
147  }
148 
149 
150  // if the result is empty check if the layer is compatible (for invalid measurement)
151  if (result.empty()) {
152  pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
153  if ( compat.first) {
154  vector<TrajectoryMeasurement> tmVec;
155  tmVec.emplace_back(compat.second, InvalidTransientRecHit::build(nullptr, TrackingRecHit::inactive,&layer), 0.F,&layer);
156  result.emplace_back(std::move(tmVec), DetGroup());
157  }
158  }
159  return result;
160 }
161 
162 void LayerMeasurements::addInvalidMeas( vector<TrajectoryMeasurement>& measVec,
163  const DetGroup& group,
164  const DetLayer& layer) const
165 {
166  if (!measVec.empty()) {
167  // invalidMeas on Det of most compatible hit
168  measVec.emplace_back(measVec.front().predictedState(),
169  InvalidTransientRecHit::build(measVec.front().recHit()->det(), TrackingRecHit::missing),
170  0.,&layer);
171  }
172  else if (!group.empty()) {
173  // invalid state on first compatible Det
174  measVec.emplace_back(group.front().trajectoryState(),
175  InvalidTransientRecHit::build(group.front().det(), TrackingRecHit::missing), 0.,&layer);
176  }
177 }
#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
int i
Definition: DBlmapReader.cc:9
std::size_t size() const
virtual std::vector< DetGroup > groupedCompatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
#define unlikely(x)
Definition: Likely.h:21
tuple result
Definition: query.py:137
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:72
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
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
virtual bool measurements(const TrajectoryStateOnSurface &stateOnThisDet, const MeasurementEstimator &est, TempMeasurements &result) const =0