CMS 3D CMS Logo

LayerMeasurements.cc
Go to the documentation of this file.
5 
10 
14 
16 
19 
20 #include <algorithm>
21 #include <cstdlib>
22 
23 using namespace std;
24 
25 namespace {
27  inline void addInvalidMeas(std::vector<TrajectoryMeasurement>& result,
28  const TrajectoryStateOnSurface& ts,
29  const GeomDet& det,
30  const DetLayer& layer) {
31  result.emplace_back(ts, std::make_shared<InvalidTrackingRecHit>(det, TrackingRecHit::missing), 0.F, &layer);
32  }
33 
34  // layerIsCompatibleWithTSOS:
35  // - enforce minimum requirements of compatibility between DetLayer and TrajectoryStateOnSurface
36  // (e.g. global position of TSOS within detector volume)
37  // - current implementation does not make use of layer argument,
38  // see below for an example of how to use it
39  // #include "Geometry/CommonDetUnit/interface/GeomDetEnumerators.h"
40  // [..]
41  // using namespace GeomDetEnumerators;
42  // auto const& det = layer.subDetector();
43  // if (det == PixelBarrel or det == PixelEndcap) {
44  // return xa < 2e1 and ya < 2e1 and za < 6e1;
45  // }
46  bool layerIsCompatibleWithTSOS(DetLayer const& /* layer */, TrajectoryStateOnSurface const& tsos) {
47  auto const& gp = tsos.globalPosition();
48  auto const xa = std::abs(gp.x());
49  auto const ya = std::abs(gp.y());
50  auto const za = std::abs(gp.z());
51  return xa < 1e3 and ya < 1e3 and za < 12e2;
52  }
53 
61  inline std::vector<TrajectoryMeasurement> get(MeasurementDetSystem const& detSystem,
63  const DetLayer& layer,
64  std::vector<DetWithState> const& compatDets,
65  const TrajectoryStateOnSurface& ts,
66  const Propagator& prop,
67  const MeasurementEstimator& est) {
68  std::vector<TrajectoryMeasurement> result;
69  typedef TrajectoryMeasurement TM;
70 
72 
73  for (auto const& ds : compatDets) {
74  if (not layerIsCompatibleWithTSOS(layer, ds.second))
75  continue;
76 
77  MeasurementDetWithData mdet = detSystem.idToDet(ds.first->geographicalId(), data);
78  if UNLIKELY (mdet.isNull()) {
79  throw MeasurementDetException("MeasurementDet not found");
80  }
81 
82  if (mdet.measurements(ds.second, est, tmps))
83  for (std::size_t i = 0; i != tmps.size(); ++i)
84  result.emplace_back(ds.second, std::move(tmps.hits[i]), tmps.distances[i], &layer);
85  tmps.clear();
86  }
87  // WARNING: we might end up with more than one invalid hit of type 'inactive' in result
88  // to be fixed in order to avoid usless double traj candidates.
89 
90  // sort the final result
91  if (result.size() > 1) {
92  sort(result.begin(), result.end(), TrajMeasLessEstim());
93  }
94 
95  if (!result.empty()) {
96  // invalidMeas on Det of most compatible hit
97  addInvalidMeas(result, result.front().predictedState(), *(result.front().recHit()->det()), layer);
98  } else {
99  // invalid state on first compatible Det
100  addInvalidMeas(result, compatDets.front().second, *(compatDets.front().first), layer);
101  }
102 
103  return result;
104  }
105 
106  void addInvalidMeas(vector<TrajectoryMeasurement>& measVec, const DetGroup& group, const DetLayer& layer) {
107  if (!measVec.empty()) {
108  // invalidMeas on Det of most compatible hit
109  auto const& ts = measVec.front().predictedState();
110  auto toll = measVec.front().recHitR().det()->surface().bounds().significanceInside(
111  ts.localPosition(), ts.localError().positionError());
112  measVec.emplace_back(
113  measVec.front().predictedState(),
114  std::make_shared<InvalidTrackingRecHit>(*measVec.front().recHitR().det(), TrackingRecHit::missing),
115  toll,
116  &layer);
117  } else if (!group.empty()) {
118  // invalid state on first compatible Det
119  auto const& ts = group.front().trajectoryState();
120  auto toll = group.front().det()->surface().bounds().significanceInside(ts.localPosition(),
121  ts.localError().positionError());
122  measVec.emplace_back(group.front().trajectoryState(),
123  std::make_shared<InvalidTrackingRecHit>(*group.front().det(), TrackingRecHit::missing),
124  toll,
125  &layer);
126  }
127  }
128 
129 } // namespace
130 
131 // return just valid hits, no sorting (for seeding mostly)
132 std::vector<BaseTrackerRecHit*> LayerMeasurements::recHits(const DetLayer& layer,
133  const TrajectoryStateOnSurface& startingState,
134  const Propagator& prop,
135  const MeasurementEstimator& est) const {
136  std::vector<BaseTrackerRecHit*> result;
137  auto const& compatDets = layer.compatibleDets(startingState, prop, est);
138  if (compatDets.empty())
139  return result;
140  for (auto const& ds : compatDets) {
141  if (not layerIsCompatibleWithTSOS(layer, ds.second))
142  continue;
143 
144  auto mdet = detSystem_.idToDet(ds.first->geographicalId(), data_);
145  mdet.recHits(result, ds.second, est);
146  }
147  return result;
148 }
149 
150 vector<TrajectoryMeasurement> LayerMeasurements::measurements(const DetLayer& layer,
151  const TrajectoryStateOnSurface& startingState,
152  const Propagator& prop,
153  const MeasurementEstimator& est) const {
155 
156  vector<DetWithState> const& compatDets = layer.compatibleDets(startingState, prop, est);
157 
158  if (!compatDets.empty())
159  return get(detSystem_, data_, layer, compatDets, startingState, prop, est);
160 
161  vector<TrajectoryMeasurement> result;
162  pair<bool, TrajectoryStateOnSurface> compat = layer.compatible(startingState, prop, est);
163 
164  if (compat.first and layerIsCompatibleWithTSOS(layer, compat.second)) {
165  result.push_back(
166  TrajectoryMeasurement(compat.second,
167  std::make_shared<InvalidTrackingRecHitNoDet>(layer.surface(), TrackingRecHit::inactive),
168  0.F,
169  &layer));
170  LogDebug("LayerMeasurements") << "adding a missing hit.";
171  } else
172  LogDebug("LayerMeasurements") << "adding not measurement.";
173 
174  return result;
175 }
176 
177 vector<TrajectoryMeasurementGroup> LayerMeasurements::groupedMeasurements(const DetLayer& layer,
178  const TrajectoryStateOnSurface& startingState,
179  const Propagator& prop,
180  const MeasurementEstimator& est) const {
181  vector<TrajectoryMeasurementGroup> result;
182 
183  vector<DetGroup>&& groups = layer.groupedCompatibleDets(startingState, prop, est);
184  result.reserve(groups.size());
185 
187  for (auto& grp : groups) {
188  if (grp.empty())
189  continue;
190 
191  vector<TrajectoryMeasurement> tmpVec;
192  for (auto const& det : grp) {
193  auto const& detTS = det.trajectoryState();
194 
195  if (not layerIsCompatibleWithTSOS(layer, detTS))
196  continue;
197 
198  MeasurementDetWithData mdet = detSystem_.idToDet(det.det()->geographicalId(), data_);
199  if (mdet.isNull()) {
200  throw MeasurementDetException("MeasurementDet not found");
201  }
202  if (mdet.measurements(detTS, est, tmps))
203  for (std::size_t i = 0; i != tmps.size(); ++i)
204  tmpVec.emplace_back(detTS, std::move(tmps.hits[i]), tmps.distances[i], &layer);
205  tmps.clear();
206  }
207 
208  // sort the final result
209  LogDebug("LayerMeasurements") << "Sorting " << tmpVec.size() << " measurements in this grp.";
210  sort(tmpVec.begin(), tmpVec.end(), TrajMeasLessEstim());
211  addInvalidMeas(tmpVec, grp, layer);
212  result.emplace_back(std::move(tmpVec), std::move(grp));
213  }
214 
215  // if the result is empty check if the layer is compatible (for invalid measurement)
216  if (result.empty()) {
217  pair<bool, TrajectoryStateOnSurface> compat = layer.compatible(startingState, prop, est);
218  if (compat.first and layerIsCompatibleWithTSOS(layer, compat.second)) {
219  vector<TrajectoryMeasurement> tmVec;
220  tmVec.emplace_back(compat.second,
221  std::make_shared<InvalidTrackingRecHitNoDet>(layer.surface(), TrackingRecHit::inactive),
222  0.F,
223  &layer);
224  result.emplace_back(std::move(tmVec), DetGroup());
225  }
226  }
227  return result;
228 }
bool measurements(const TrajectoryStateOnSurface &stateOnThisDet, const MeasurementEstimator &est, TempMeasurements &result) const
GlobalPoint globalPosition() const
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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:80
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)