CMS 3D CMS Logo

MTDDetSector.cc
Go to the documentation of this file.
1 //#define EDM_ML_DEBUG
2 
11 
12 #include <iostream>
13 #include <iomanip>
14 #include <vector>
15 
16 using namespace std;
17 
18 MTDDetSector::MTDDetSector(vector<const GeomDet*>::const_iterator first,
19  vector<const GeomDet*>::const_iterator last,
20  const MTDTopology& topo)
21  : GeometricSearchDet(false), theDets(first, last), topo_(&topo) {
22  init();
23 }
24 
25 MTDDetSector::MTDDetSector(const vector<const GeomDet*>& vdets, const MTDTopology& topo)
26  : GeometricSearchDet(false), theDets(vdets), topo_(&topo) {
27  init();
28 }
29 
31  // Add here the sector build based on a collection of GeomDets, mimic what done in ForwardDetRingOneZ
32  // using the code from tracker BladeShapeBuilderFromDet
33  // simple initial version, no sorting for the time being
35 }
36 
37 const vector<const GeometricSearchDet*>& MTDDetSector::components() const {
38  // FIXME dummy impl.
39  edm::LogError("MTDDetLayers") << "temporary dummy implementation of MTDDetSector::components()!!";
40  static const vector<const GeometricSearchDet*> result;
41  return result;
42 }
43 
44 pair<bool, TrajectoryStateOnSurface> MTDDetSector::compatible(const TrajectoryStateOnSurface& ts,
45  const Propagator& prop,
46  const MeasurementEstimator& est) const {
48 
49 #ifdef EDM_ML_DEBUG
50  LogTrace("MTDDetLayers") << "MTDDetSector::compatible, sector: \n"
51  << (*this) << "\n TS at Z,R,phi: " << std::fixed << std::setw(14) << ts.globalPosition().z()
52  << " , " << std::setw(14) << ts.globalPosition().perp() << " , " << std::setw(14)
53  << ts.globalPosition().phi();
54  if (ms.isValid()) {
55  LogTrace("MTDDetLayers") << " DEST at Z,R,phi: " << std::fixed << std::setw(14) << ms.globalPosition().z() << " , "
56  << std::setw(14) << ms.globalPosition().perp() << " , " << std::setw(14)
57  << ms.globalPosition().phi() << " local Z: " << std::setw(14) << ms.localPosition().z();
58  } else {
59  LogTrace("MTDDetLayers") << " DEST: not valid";
60  }
61 #endif
62 
63  return make_pair(ms.isValid() and est.estimate(ms, specificSurface()) != 0, ms);
64 }
65 
66 vector<GeometricSearchDet::DetWithState> MTDDetSector::compatibleDets(const TrajectoryStateOnSurface& startingState,
67  const Propagator& prop,
68  const MeasurementEstimator& est) const {
69  LogTrace("MTDDetLayers") << "MTDDetSector::compatibleDets, sector: \n"
70  << (*this) << "\n TS at Z,R,phi: " << std::fixed << std::setw(14)
71  << startingState.globalPosition().z() << " , " << std::setw(14)
72  << startingState.globalPosition().perp() << " , " << std::setw(14)
73  << startingState.globalPosition().phi();
74 
75  vector<DetWithState> result;
76 
77  // Propagate and check that the result is within bounds
78  pair<bool, TrajectoryStateOnSurface> compat = compatible(startingState, prop, est);
79  if (!compat.first) {
80  LogTrace("MTDDetLayers") << " MTDDetSector::compatibleDets: not compatible"
81  << " (should not have been selected!)";
82  return result;
83  }
84 
85  TrajectoryStateOnSurface& tsos = compat.second;
86  GlobalPoint startPos = tsos.globalPosition();
87 
88  LogTrace("MTDDetLayers") << "Starting position: " << startPos << " starting p/pT: " << tsos.globalMomentum().mag()
89  << " / " << tsos.globalMomentum().perp();
90 
91  // determine distance of det center from extrapolation on the surface, sort dets accordingly
92 
93  size_t idetMin = basicComponents().size();
94  double dist2Min = std::numeric_limits<double>::max();
95  std::vector<std::pair<double, size_t> > tmpDets;
96  tmpDets.reserve(basicComponents().size());
97 
98  for (size_t idet = 0; idet < basicComponents().size(); idet++) {
99  double dist2 = (startPos - theDets[idet]->position()).mag2();
100  tmpDets.emplace_back(dist2, idet);
101  if (dist2 < dist2Min) {
102  dist2Min = dist2;
103  idetMin = idet;
104  }
105  }
106 
107  //look for the compatibledets considering each line of the sector
108 
109  if (add(idetMin, result, tsos, prop, est)) {
110  compatibleDetsLine(idetMin, result, tsos, prop, est);
111 
112  for (int iside = -1; iside <= 1; iside += 2) {
113  bool isCompatible(true);
114  size_t idetNew(idetMin);
115  size_t closest = theDets.size();
116 
117  while (isCompatible) {
118  idetNew = vshift(theDets[idetNew]->geographicalId().rawId(), iside, closest);
119  if (idetNew >= theDets.size()) {
120  if (closest < theDets.size()) {
121  idetNew = closest;
122  } else {
123  break;
124  }
125  }
126  isCompatible = add(idetNew, result, tsos, prop, est);
127  if (isCompatible) {
128  compatibleDetsLine(idetNew, result, tsos, prop, est);
129  }
130  }
131  }
132  }
133 
134 #ifdef EDM_ML_DEBUG
135  if (result.empty()) {
136  LogTrace("MTDDetLayers") << "MTDDetSector::compatibleDets, closest not compatible!";
137  } else {
138  LogTrace("MTDDetLayers") << "MTDDetSector::compatibleDets, found " << result.size() << " compatible dets";
139  }
140 #endif
141 
142  return result;
143 }
144 
146  const Propagator&,
147  const MeasurementEstimator&,
148  std::vector<DetWithState>&) const {
149  edm::LogError("MTDDetLayers") << "At the moment not a real implementation";
150 }
151 
152 vector<DetGroup> MTDDetSector::groupedCompatibleDets(const TrajectoryStateOnSurface& startingState,
153  const Propagator& prop,
154  const MeasurementEstimator& est) const {
155  // FIXME should be implemented to allow returning overlapping chambers
156  // as separate groups!
157  edm::LogInfo("MTDDetLayers") << "dummy implementation of MTDDetSector::groupedCompatibleDets()";
158  vector<DetGroup> result;
159  return result;
160 }
161 
162 bool MTDDetSector::add(size_t idet,
163  vector<DetWithState>& result,
164  const TrajectoryStateOnSurface& tsos,
165  const Propagator& prop,
166  const MeasurementEstimator& est) const {
167  pair<bool, TrajectoryStateOnSurface> compat = theCompatibilityChecker.isCompatible(theDets[idet], tsos, prop, est);
168 
169  if (compat.first) {
170  result.push_back(DetWithState(theDets[idet], compat.second));
171  LogTrace("MTDDetLayers") << "MTDDetSector::compatibleDets found compatible det idetMin " << idet
172  << " detId = " << theDets[idet]->geographicalId().rawId() << " at "
173  << theDets[idet]->position()
174  << " dist = " << std::sqrt((tsos.globalPosition() - theDets[idet]->position()).mag2());
175  }
176 
177  return compat.first;
178 }
179 
180 std::ostream& operator<<(std::ostream& os, const MTDDetSector& id) {
181  os << " MTDDetSector at " << std::fixed << id.specificSurface().position() << std::endl
182  << " L/W/T : " << std::setw(14) << id.specificSurface().bounds().length() << " / " << std::setw(14)
183  << id.specificSurface().bounds().width() << " / " << std::setw(14) << id.specificSurface().bounds().thickness()
184  << std::endl
185  << " rmin : " << std::setw(14) << id.specificSurface().innerRadius() << std::endl
186  << " rmax : " << std::setw(14) << id.specificSurface().outerRadius() << std::endl
187  << " phi ref : " << std::setw(14) << id.specificSurface().position().phi() << std::endl
188  << " phi w/2 : " << std::setw(14) << id.specificSurface().phiHalfExtension() << std::endl;
189  return os;
190 }
191 
192 void MTDDetSector::compatibleDetsLine(const size_t idetMin,
193  vector<DetWithState>& result,
194  const TrajectoryStateOnSurface& tsos,
195  const Propagator& prop,
196  const MeasurementEstimator& est) const {
197  for (int iside = -1; iside <= 1; iside += 2) {
198  bool isCompatible(true);
199  size_t idetNew(idetMin);
200 
201  while (isCompatible) {
202  idetNew = hshift(theDets[idetNew]->geographicalId().rawId(), iside);
203  if (idetNew >= theDets.size()) {
204  break;
205  }
206  isCompatible = add(idetNew, result, tsos, prop, est);
207  }
208  }
209 
210  return;
211 }
212 
213 size_t MTDDetSector::hshift(const uint32_t detid, const int horizontalShift) const {
214  return topo_->hshiftETL(detid, horizontalShift);
215 }
216 
217 size_t MTDDetSector::vshift(const uint32_t detid, const int verticalShift, size_t& closest) const {
218  return topo_->vshiftETL(detid, verticalShift, closest);
219 }
size
Write out results.
size_t hshiftETL(const uint32_t detid, const int horizontalShift) const
Definition: MTDTopology.cc:23
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &prop, const MeasurementEstimator &est) const override
Definition: MTDDetSector.cc:44
T perp() const
Definition: PV3DBase.h:69
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)
const BoundDiskSector & specificSurface() const
Definition: MTDDetSector.h:53
const std::vector< const GeometricSearchDet * > & components() const override
Returns basic components, if any.
Definition: MTDDetSector.cc:37
std::vector< const GeomDet * > theDets
Definition: MTDDetSector.h:75
void compatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetWithState > &result) const override
Log< level::Error, false > LogError
GeomDetCompatibilityChecker theCompatibilityChecker
void setDisk(BoundDiskSector *diskS)
Definition: MTDDetSector.h:65
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
#define LogTrace(id)
MTDDetSector(std::vector< const GeomDet *>::const_iterator first, std::vector< const GeomDet *>::const_iterator last, const MTDTopology &topo)
Construct from iterators on GeomDet*.
Definition: MTDDetSector.cc:18
size_t vshift(const uint32_t detid, const int verticalShift, size_t &closest) const
GlobalPoint globalPosition() const
static std::pair< bool, TrajectoryStateOnSurface > isCompatible(const GeomDet *theDet, const TrajectoryStateOnSurface &ts, const Propagator &prop, const MeasurementEstimator &est)
std::ostream & operator<<(std::ostream &os, const MTDDetSector &id)
std::vector< DetGroup > groupedCompatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const override
T sqrt(T t)
Definition: SSEVec.h:19
T mag() const
Definition: PV3DBase.h:64
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const override
Definition: MTDDetSector.cc:66
Log< level::Info, false > LogInfo
const std::vector< const GeomDet * > & basicComponents() const override
Definition: MTDDetSector.h:28
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
const MTDTopology * topo_
Definition: MTDDetSector.h:77
GlobalVector globalMomentum() const
size_t vshiftETL(const uint32_t detid, const int verticalShift, size_t &closest) const
Definition: MTDTopology.cc:68
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
bool add(size_t idet, std::vector< DetWithState > &result, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est) const
void compatibleDetsLine(const size_t idetMin, std::vector< DetWithState > &result, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est) const
size_t hshift(const uint32_t detid, const int horizontalShift) const