CMS 3D CMS Logo

TOBRod.cc
Go to the documentation of this file.
1 #include "TOBRod.h"
2 
4 
9 
10 #include "LayerCrossingSide.h"
11 #include "DetGroupMerger.h"
13 
14 using namespace std;
15 
17 
18 namespace {
19  class DetZLess {
20  public:
21  bool operator()(const GeomDet* a, const GeomDet* b) const { return (a->position().z() < b->position().z()); }
22  };
23 } // namespace
24 
25 TOBRod::TOBRod(vector<const GeomDet*>& innerDets, vector<const GeomDet*>& outerDets)
26  : DetRod(true), theInnerDets(innerDets), theOuterDets(outerDets) {
27  theDets.assign(theInnerDets.begin(), theInnerDets.end());
28  theDets.insert(theDets.end(), theOuterDets.begin(), theOuterDets.end());
29 
30  RodPlaneBuilderFromDet planeBuilder;
31  setPlane(planeBuilder(theDets));
32  theInnerPlane = planeBuilder(theInnerDets);
33  theOuterPlane = planeBuilder(theOuterDets);
34 
35  sort(theDets.begin(), theDets.end(), DetZLess());
36  sort(theInnerDets.begin(), theInnerDets.end(), DetZLess());
37  sort(theOuterDets.begin(), theOuterDets.end(), DetZLess());
40 
41  LogDebug("TkDetLayers") << "==== DEBUG TOBRod =====";
42  for (vector<const GeomDet*>::const_iterator i = theInnerDets.begin(); i != theInnerDets.end(); i++) {
43  LogDebug("TkDetLayers") << "inner TOBRod's Det pos z,perp,eta,phi: " << (**i).position().z() << " , "
44  << (**i).position().perp() << " , " << (**i).position().eta() << " , "
45  << (**i).position().phi();
46  }
47 
48  for (vector<const GeomDet*>::const_iterator i = theOuterDets.begin(); i != theOuterDets.end(); i++) {
49  LogDebug("TkDetLayers") << "outer TOBRod's Det pos z,perp,eta,phi: " << (**i).position().z() << " , "
50  << (**i).position().perp() << " , " << (**i).position().eta() << " , "
51  << (**i).position().phi();
52  }
53  LogDebug("TkDetLayers") << "==== end DEBUG TOBRod =====";
54 }
55 
57 
58 const vector<const GeometricSearchDet*>& TOBRod::components() const {
59  throw DetLayerException("TOBRod doesn't have GeometricSearchDet components");
60 }
61 
62 pair<bool, TrajectoryStateOnSurface> TOBRod::compatible(const TrajectoryStateOnSurface& ts,
63  const Propagator&,
64  const MeasurementEstimator&) const {
65  edm::LogError("TkDetLayers") << "temporary dummy implementation of TOBRod::compatible()!!";
66  return pair<bool, TrajectoryStateOnSurface>();
67 }
68 
70  const Propagator& prop,
71  const MeasurementEstimator& est,
72  std::vector<DetGroup>& result) const {
73  SubLayerCrossings crossings;
74  crossings = computeCrossings(tsos, prop.propagationDirection());
75  if (!crossings.isValid())
76  return;
77 
78  std::vector<DetGroup> closestResult;
79  addClosest(tsos, prop, est, crossings.closest(), closestResult);
80  if (closestResult.empty()) {
81  std::vector<DetGroup> nextResult;
82  addClosest(tsos, prop, est, crossings.other(), nextResult);
83  if (nextResult.empty())
84  return;
85 
86  DetGroupElement nextGel(nextResult.front().front());
87  int crossingSide = LayerCrossingSide().barrelSide(nextGel.trajectoryState(), prop);
89  std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
90  } else {
91  DetGroupElement closestGel(closestResult.front().front());
92  float window = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
93 
94  searchNeighbors(tsos, prop, est, crossings.closest(), window, closestResult, false);
95 
96  std::vector<DetGroup> nextResult;
97  searchNeighbors(tsos, prop, est, crossings.other(), window, nextResult, true);
98 
99  int crossingSide = LayerCrossingSide().barrelSide(closestGel.trajectoryState(), prop);
101  std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
102  }
103 }
104 
106  PropagationDirection propDir) const {
107  GlobalPoint startPos(startingState.globalPosition());
108  GlobalVector startDir(startingState.globalMomentum());
109  double rho(startingState.transverseCurvature());
110 
111  HelixBarrelPlaneCrossingByCircle crossing(startPos, startDir, rho, propDir);
112 
113  std::pair<bool, double> outerPath = crossing.pathLength(*theOuterPlane);
114  if (!outerPath.first)
115  return SubLayerCrossings();
116  GlobalPoint gOuterPoint(crossing.position(outerPath.second));
117 
118  std::pair<bool, double> innerPath = crossing.pathLength(*theInnerPlane);
119  if (!innerPath.first)
120  return SubLayerCrossings();
121  GlobalPoint gInnerPoint(crossing.position(innerPath.second));
122 
123  int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.z());
124  float innerDist = std::abs(theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.z());
125  SubLayerCrossing innerSLC(0, innerIndex, gInnerPoint);
126 
127  int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.z());
128  float outerDist = std::abs(theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.z());
129  SubLayerCrossing outerSLC(1, outerIndex, gOuterPoint);
130 
131  if (innerDist < outerDist) {
132  return SubLayerCrossings(innerSLC, outerSLC, 0);
133  } else {
134  return SubLayerCrossings(outerSLC, innerSLC, 1);
135  }
136 }
137 
139  const Propagator& prop,
140  const MeasurementEstimator& est,
141  const SubLayerCrossing& crossing,
142  vector<DetGroup>& result) const {
143  const vector<const GeomDet*>& sRod(subRod(crossing.subLayerIndex()));
144  return CompatibleDetToGroupAdder::add(*sRod[crossing.closestDetIndex()], tsos, prop, est, result);
145 }
146 
148  const TrajectoryStateOnSurface& tsos,
149  const MeasurementEstimator& est) const {
150  return est.maximalLocalDisplacement(tsos, det->surface()).y();
151 }
152 
153 namespace {
154 
155  inline bool overlap(const GlobalPoint& crossPoint, const GeomDet& det, float window) {
156  // check if the z window around TSOS overlaps with the detector theDet (with a 1% margin added)
157 
158  // const float tolerance = 0.1;
159  constexpr float relativeMargin = 1.01;
160 
161  LocalPoint localCrossPoint(det.surface().toLocal(crossPoint));
162  // if (std::abs(localCrossPoint.z()) > tolerance) {
163  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap calculation assumes point on surface, but it is off by "
164  // << localCrossPoint.z() ;
165  // }
166 
167  float localY = localCrossPoint.y();
168  float detHalfLength = 0.5f * det.surface().bounds().length();
169 
170  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap: Det at " << det.position() << " hit at " << localY
171  // << " Window " << window << " halflength " << detHalfLength ;
172 
173  return (std::abs(localY) - window) < relativeMargin * detHalfLength;
174  }
175 
176 } // namespace
177 
179  const Propagator& prop,
180  const MeasurementEstimator& est,
181  const SubLayerCrossing& crossing,
182  float window,
183  vector<DetGroup>& result,
184  bool checkClosest) const {
185  const GlobalPoint& gCrossingPos = crossing.position();
186 
187  const vector<const GeomDet*>& sRod(subRod(crossing.subLayerIndex()));
188 
189  int closestIndex = crossing.closestDetIndex();
190  int negStartIndex = closestIndex - 1;
191  int posStartIndex = closestIndex + 1;
192 
193  if (checkClosest) { // must decide if the closest is on the neg or pos side
194  if (gCrossingPos.z() < sRod[closestIndex]->surface().position().z()) {
195  posStartIndex = closestIndex;
196  } else {
197  negStartIndex = closestIndex;
198  }
199  }
200 
201  typedef CompatibleDetToGroupAdder Adder;
202  for (int idet = negStartIndex; idet >= 0; idet--) {
203  if (!overlap(gCrossingPos, *sRod[idet], window))
204  break;
205  if (!Adder::add(*sRod[idet], tsos, prop, est, result))
206  break;
207  }
208  for (int idet = posStartIndex; idet < static_cast<int>(sRod.size()); idet++) {
209  if (!overlap(gCrossingPos, *sRod[idet], window))
210  break;
211  if (!Adder::add(*sRod[idet], tsos, prop, est, result))
212  break;
213  }
214 }
Common base class.
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const __attribute__((hot))
Definition: TOBRod.cc:147
const std::vector< const GeomDet * > & subRod(int ind) const
Definition: TOBRod.h:61
BinFinderType theOuterBinFinder
Definition: TOBRod.h:72
int closestIndex() const
static int barrelSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
returns 0 if barrel layer crossed from inside, 1 if from outside
virtual float length() const =0
TOBRod(std::vector< const GeomDet *> &innerDets, std::vector< const GeomDet *> &outerDets) __attribute__((cold))
Definition: TOBRod.cc:25
std::vector< const GeomDet * > theInnerDets
Definition: TOBRod.h:65
~TOBRod() override __attribute__((cold))
Definition: TOBRod.cc:56
const std::vector< const GeometricSearchDet * > & components() const override __attribute__((cold))
Returns basic components, if any.
Definition: TOBRod.cc:58
T z() const
Definition: PV3DBase.h:61
PeriodicBinFinderInZ< float > BinFinderType
Definition: TOBRod.h:16
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
std::vector< const GeomDet * > theDets
Definition: TOBRod.h:64
std::vector< const GeomDet * > theOuterDets
Definition: TOBRod.h:66
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
PropagationDirection
Log< level::Error, false > LogError
LocalPoint toLocal(const GlobalPoint &gp) const
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 that contains Z
const GlobalPoint & position() const
int closestDetIndex() const
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const override __attribute__((cold))
Definition: TOBRod.cc:62
GeometricSearchDet::DetWithState DetWithState
Definition: TOBRod.cc:16
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
Definition: TOBRod.cc:69
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
Definition: TOBRod.cc:105
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:643
const SubLayerCrossing & closest() const
ReferenceCountingPointer< Plane > theOuterPlane
Definition: TOBRod.h:69
int subLayerIndex() const
BinFinderType theInnerBinFinder
Definition: TOBRod.h:71
static bool add(const GeometricSearchDet &det, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) __attribute__((hot))
T binPosition(int ind) const override
the middle of the bin
ReferenceCountingPointer< Plane > theInnerPlane
Definition: TOBRod.h:68
const SubLayerCrossing & other() const
Definition: DetRod.h:13
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
double b
Definition: hdecay.h:120
GlobalVector globalMomentum() const
void setPlane(Plane *plane)
Set the rod&#39;s plane.
Definition: DetRod.h:28
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
double a
Definition: hdecay.h:121
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, float window, std::vector< DetGroup > &result, bool checkClosest) const __attribute__((hot))
Definition: TOBRod.cc:178
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
def move(src, dest)
Definition: eostools.py:511
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: TOBRod.cc:138
#define LogDebug(id)
const Bounds & bounds() const
Definition: Surface.h:87