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