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  // FIXME << " TS at R,phi: " << startingState.position().perp() << ","
49  // << startingState.position().phi()
50 
51  vector<DetWithState> result;
52 
53  // Propagate and check that the result is within bounds
54  pair<bool, TrajectoryStateOnSurface> compat = compatible(startingState, prop, est);
55 
56  if (!compat.first) {
57  LogTrace("MTDDetLayers") << " MTDDetTray::compatibleDets: not compatible"
58  << " (should not have been selected!)";
59  return result;
60  }
61 
62  // Find the most probable destination component
63  TrajectoryStateOnSurface& tsos = compat.second;
64  GlobalPoint startPos = tsos.globalPosition();
65  int closest = theBinFinder.binIndex(startPos.z());
66  const vector<const GeomDet*> dets = basicComponents();
67  LogTrace("MTDDetLayers") << " MTDDetTray::compatibleDets, closest det: " << closest
68  << " pos: " << dets[closest]->surface().position() << " impact " << startPos;
69 
70  // Add this detector, if it is compatible
71  // NOTE: add performs a null propagation
72  add(closest, result, tsos, prop, est);
73 
74 #ifdef EDM_ML_DEBUG
75  int nclosest = result.size();
76  int nnextdet = 0; // just DEBUG counters
77 #endif
78 
79  // Try the neighbors on each side until no more compatible.
80  // If closest is not compatible the next cannot be either
81  if (!result.empty()) {
82  const BoundPlane& closestPlane(dets[closest]->surface());
84 
85  // detHalfLen is assumed to be the same for all detectors.
86  float detHalfLen = closestPlane.bounds().length() / 2.;
87 
88  for (unsigned int idet = closest + 1; idet < dets.size(); idet++) {
89  LocalPoint nextPos(dets[idet]->toLocal(startPos));
90  if (fabs(nextPos.y()) < detHalfLen + maxDistance.y()) {
91 #ifdef EDM_ML_DEBUG
92  LogTrace("MTDDetLayers") << " negativeZ: det:" << idet << " pos " << nextPos.y() << " maxDistance "
93  << maxDistance.y();
94  nnextdet++;
95 #endif
96  if (!add(idet, result, tsos, prop, est))
97  break;
98  } else {
99  break;
100  }
101  }
102 
103  for (int idet = closest - 1; idet >= 0; idet--) {
104  LocalPoint nextPos(dets[idet]->toLocal(startPos));
105  if (fabs(nextPos.y()) < detHalfLen + maxDistance.y()) {
106 #ifdef EDM_ML_DEBUG
107  LogTrace("MTDDetLayers") << " positiveZ: det:" << idet << " pos " << nextPos.y() << " maxDistance "
108  << maxDistance.y();
109  nnextdet++;
110 #endif
111  if (!add(idet, result, tsos, prop, est))
112  break;
113  } else {
114  break;
115  }
116  }
117  }
118 
119 #ifdef EDM_ML_DEBUG
120  LogTrace("MTDDetLayers") << " MTDDetTray::compatibleDets, size: " << result.size() << " on closest: " << nclosest
121  << " # checked dets: " << nnextdet + 1;
122  if (result.empty()) {
123  LogTrace("MTDDetLayers") << " ***Rod not compatible---should have been discarded before!!!";
124  }
125 #endif
126  return result;
127 }
128 
129 vector<DetGroup> MTDDetTray::groupedCompatibleDets(const TrajectoryStateOnSurface& startingState,
130  const Propagator& prop,
131  const MeasurementEstimator& est) const {
132  vector<GeometricSearchDet::DetWithState> detWithStates;
133 
134  detWithStates = compatibleDets(startingState, prop, est);
135 
136  vector<DetGroup> result;
137  if (!detWithStates.empty()) {
138  result.push_back(DetGroup(detWithStates));
139  }
140  LogTrace("MTDDetLayers") << "MTDdetTray Compatible modules: " << result.size();
141  return result;
142 }
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
void init()
Definition: MTDDetTray.cc:25
T z() const
Definition: PV3DBase.h:61
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
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
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
#define LogTrace(id)
T y() const
Definition: PV3DBase.h:60
GlobalPoint globalPosition() const
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:129