CMS 3D CMS Logo

MTDDetTray.cc
Go to the documentation of this file.
1 //#define EDM_ML_DEBUG
2 
13 
14 #include <iostream>
15 
16 using namespace std;
17 
18 MTDDetTray::MTDDetTray(vector<const GeomDet*>::const_iterator first, vector<const GeomDet*>::const_iterator last)
19  : DetRodOneR(first, last) {
20  init();
21 }
22 
23 MTDDetTray::MTDDetTray(const vector<const GeomDet*>& vdets) : DetRodOneR(vdets) { init(); }
24 
26 
28 
29 const vector<const GeometricSearchDet*>& MTDDetTray::components() const {
30  // FIXME dummy impl.
31  edm::LogError("MTDDetLayers") << "temporary dummy implementation of MTDDetTray::components()!!";
32  static const vector<const GeometricSearchDet*> result;
33  return result;
34 }
35 
36 pair<bool, TrajectoryStateOnSurface> MTDDetTray::compatible(const TrajectoryStateOnSurface& ts,
37  const Propagator& prop,
38  const MeasurementEstimator& est) const {
40  return make_pair(ms.isValid() and est.estimate(ms, specificSurface()) != 0, ms);
41 }
42 
43 vector<GeometricSearchDet::DetWithState> MTDDetTray::compatibleDets(const TrajectoryStateOnSurface& startingState,
44  const Propagator& prop,
45  const MeasurementEstimator& est) const {
46  LogTrace("MTDDetLayers") << "MTDDetTray::compatibleDets, Surface at R,phi: " << surface().position().perp() << ","
47  << surface().position().phi() << " DetRod pos."
48  << " TS at R,phi: " << startingState.globalPosition().perp() << ","
49  << startingState.globalPosition().phi() << " TSOS dx/dy "
50  << std::sqrt(startingState.localError().positionError().xx()) << " "
51  << std::sqrt(startingState.localError().positionError().yy());
52 
53  vector<DetWithState> result;
54 
55  // Propagate and check that the result is within bounds
56  pair<bool, TrajectoryStateOnSurface> compat = compatible(startingState, prop, est);
57 
58  if (!compat.first) {
59  LogTrace("MTDDetLayers") << " MTDDetTray::compatibleDets: not compatible"
60  << " (should not have been selected!)";
61  return result;
62  }
63 
64  // Find the most probable destination component
65  TrajectoryStateOnSurface& tsos = compat.second;
66  GlobalPoint startPos = tsos.globalPosition();
67  int closest = theBinFinder.binIndex(startPos.z());
68  const vector<const GeomDet*> dets = basicComponents();
69  LogTrace("MTDDetLayers") << " MTDDetTray::compatibleDets, closest det: " << closest
70  << " pos: " << dets[closest]->surface().position() << " impact " << startPos;
71 
72  // Add this detector, if it is compatible
73  // NOTE: add performs a null propagation
74  add(closest, result, tsos, prop, est);
75 
76 #ifdef EDM_ML_DEBUG
77  int nclosest = result.size();
78  int nnextdet = 0; // just DEBUG counters
79 #endif
80 
81  // Try the neighbors on each side until no more compatible.
82  // If closest is not compatible the next cannot be either
83  if (!result.empty()) {
84  const BoundPlane& closestPlane(dets[closest]->surface());
86 
87  // detHalfLen is assumed to be the same for all detectors.
88  float detHalfLen = closestPlane.bounds().length() / 2.;
89 
90  for (unsigned int idet = closest + 1; idet < dets.size(); idet++) {
91  LocalPoint nextPos(dets[idet]->toLocal(startPos));
92  if (fabs(nextPos.y()) < detHalfLen + maxDistance.y()) {
93 #ifdef EDM_ML_DEBUG
94  LogTrace("MTDDetLayers") << " negativeZ: det:" << idet << " pos " << nextPos.y() << " maxDistance "
95  << maxDistance.y();
96  nnextdet++;
97 #endif
98  if (!add(idet, result, tsos, prop, est))
99  break;
100  } else {
101  break;
102  }
103  }
104 
105  for (int idet = closest - 1; idet >= 0; idet--) {
106  LocalPoint nextPos(dets[idet]->toLocal(startPos));
107  if (fabs(nextPos.y()) < detHalfLen + maxDistance.y()) {
108 #ifdef EDM_ML_DEBUG
109  LogTrace("MTDDetLayers") << " positiveZ: det:" << idet << " pos " << nextPos.y() << " maxDistance "
110  << maxDistance.y();
111  nnextdet++;
112 #endif
113  if (!add(idet, result, tsos, prop, est))
114  break;
115  } else {
116  break;
117  }
118  }
119  }
120 
121 #ifdef EDM_ML_DEBUG
122  LogTrace("MTDDetLayers") << " MTDDetTray::compatibleDets, size: " << result.size() << " on closest: " << nclosest
123  << " # checked dets: " << nnextdet + 1;
124  if (result.empty()) {
125  LogTrace("MTDDetLayers") << " ***Rod not compatible---should have been discarded before!!!";
126  }
127 #endif
128  return result;
129 }
130 
131 vector<DetGroup> MTDDetTray::groupedCompatibleDets(const TrajectoryStateOnSurface& startingState,
132  const Propagator& prop,
133  const MeasurementEstimator& est) const {
134  vector<GeometricSearchDet::DetWithState> detWithStates;
135 
136  detWithStates = compatibleDets(startingState, prop, est);
137 
138  vector<DetGroup> result;
139  if (!detWithStates.empty()) {
140  result.push_back(DetGroup(detWithStates));
141  }
142  LogTrace("MTDDetLayers") << "MTDdetTray Compatible modules: " << result.size();
143  return result;
144 }
GenericBinFinderInZ< float, GeomDet > BinFinderType
Definition: MTDDetTray.h:45
const std::vector< const GeometricSearchDet * > & components() const override
Returns basic components, if any.
Definition: MTDDetTray.cc:29
const BoundSurface & surface() const final
The surface of the GeometricSearchDet.
Definition: DetRod.h:19
T perp() const
Definition: PV3DBase.h:69
const LocalTrajectoryError & localError() const
void init()
Definition: MTDDetTray.cc:25
T z() const
Definition: PV3DBase.h:61
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
int closest(std::vector< int > const &vec, int value)
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const override
Definition: MTDDetTray.cc:43
Log< level::Error, false > LogError
LocalError positionError() const
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
#define LogTrace(id)
float yy() const
Definition: LocalError.h:24
T y() const
Definition: PV3DBase.h:60
GlobalPoint globalPosition() const
T sqrt(T t)
Definition: SSEVec.h:23
int binIndex(T z) const override
returns an index in the valid range for the bin closest to Z
MTDDetTray(std::vector< const GeomDet *>::const_iterator first, std::vector< const GeomDet *>::const_iterator last)
Construct from iterators on GeomDet*.
Definition: MTDDetTray.cc:18
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
bool add(int idet, std::vector< DetWithState > &result, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
Query detector idet for compatible and add the output to result.
Definition: DetRodOneR.cc:32
const PositionType & position() const
const std::vector< const GeomDet * > & basicComponents() const override
Definition: DetRodOneR.h:26
virtual const Plane & specificSurface() const final
Return the rod surface as a Plane.
Definition: DetRod.h:24
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &prop, const MeasurementEstimator &est) const override
Definition: MTDDetTray.cc:36
BinFinderType theBinFinder
Definition: MTDDetTray.h:46
~MTDDetTray() override
Destructor.
Definition: MTDDetTray.cc:27
std::vector< DetGroup > groupedCompatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const override
Definition: MTDDetTray.cc:131
float xx() const
Definition: LocalError.h:22