CMS 3D CMS Logo

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