CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PixelBlade.cc
Go to the documentation of this file.
1 #include "PixelBlade.h"
2 
4 
6 #include "LayerCrossingSide.h"
7 #include "DetGroupMerger.h"
9 
13 
14 using namespace std;
15 
17 
19 
20 PixelBlade::PixelBlade(vector<const GeomDet*>& frontDets, vector<const GeomDet*>& backDets)
21  : GeometricSearchDet(true), theFrontDets(frontDets), theBackDets(backDets) {
22  theDets.assign(theFrontDets.begin(), theFrontDets.end());
23  theDets.insert(theDets.end(), theBackDets.begin(), theBackDets.end());
24 
28 
29  //--------- DEBUG INFO --------------
30  LogDebug("TkDetLayers") << "DEBUG INFO for PixelBlade";
31  LogDebug("TkDetLayers") << "Blade z, perp, innerRadius, outerR: " << this->position().z() << " , "
32  << this->position().perp() << " , " << theDiskSector->innerRadius() << " , "
33  << theDiskSector->outerRadius();
34 
35  for (vector<const GeomDet*>::const_iterator it = theFrontDets.begin(); it != theFrontDets.end(); it++) {
36  LogDebug("TkDetLayers") << "frontDet phi,z,r: " << (*it)->position().phi() << " , " << (*it)->position().z()
37  << " , " << (*it)->position().perp();
38  ;
39  }
40 
41  for (vector<const GeomDet*>::const_iterator it = theBackDets.begin(); it != theBackDets.end(); it++) {
42  LogDebug("TkDetLayers") << "backDet phi,z,r: " << (*it)->position().phi() << " , " << (*it)->position().z() << " , "
43  << (*it)->position().perp();
44  }
45  //-----------------------------------
46 }
47 
48 const vector<const GeometricSearchDet*>& PixelBlade::components() const {
49  throw DetLayerException("TOBRod doesn't have GeometricSearchDet components");
50 }
51 
52 pair<bool, TrajectoryStateOnSurface> PixelBlade::compatible(const TrajectoryStateOnSurface& ts,
53  const Propagator&,
54  const MeasurementEstimator&) const {
55  edm::LogError("TkDetLayers") << "temporary dummy implementation of PixelBlade::compatible()!!";
56  return pair<bool, TrajectoryStateOnSurface>();
57 }
58 
60  const Propagator& prop,
61  const MeasurementEstimator& est,
62  std::vector<DetGroup>& result) const {
63  SubLayerCrossings crossings;
64  crossings = computeCrossings(tsos, prop.propagationDirection());
65  if (!crossings.isValid())
66  return;
67 
68  vector<DetGroup> closestResult;
69  addClosest(tsos, prop, est, crossings.closest(), closestResult);
70 
71  if (closestResult.empty()) {
72  vector<DetGroup> nextResult;
73  addClosest(tsos, prop, est, crossings.other(), nextResult);
74  if (nextResult.empty())
75  return;
76 
77  DetGroupElement nextGel(nextResult.front().front());
78  int crossingSide = LayerCrossingSide().endcapSide(nextGel.trajectoryState(), prop);
79 
81  std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
82  } else {
83  DetGroupElement closestGel(closestResult.front().front());
84  float window = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
85 
86  searchNeighbors(tsos, prop, est, crossings.closest(), window, closestResult, false);
87 
88  vector<DetGroup> nextResult;
89  searchNeighbors(tsos, prop, est, crossings.other(), window, nextResult, true);
90 
91  int crossingSide = LayerCrossingSide().endcapSide(closestGel.trajectoryState(), prop);
93  std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
94  }
95 }
96 
98  PropagationDirection propDir) const {
99  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
100  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
101  double rho(startingState.transverseCurvature());
102 
103  HelixArbitraryPlaneCrossing crossing(startPos, startDir, rho, propDir);
104 
105  pair<bool, double> innerPath = crossing.pathLength(*theFrontDiskSector);
106  if (!innerPath.first)
107  return SubLayerCrossings();
108 
109  GlobalPoint gInnerPoint(crossing.position(innerPath.second));
110  //Code for use of binfinder
111  //int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.perp());
112  //float innerDist = std::abs( theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.z());
113  int innerIndex = findBin(gInnerPoint.perp(), 0);
114  float innerDist = std::abs(findPosition(innerIndex, 0).perp() - gInnerPoint.perp());
115  SubLayerCrossing innerSLC(0, innerIndex, gInnerPoint);
116 
117  pair<bool, double> outerPath = crossing.pathLength(*theBackDiskSector);
118  if (!outerPath.first)
119  return SubLayerCrossings();
120 
121  GlobalPoint gOuterPoint(crossing.position(outerPath.second));
122  //Code for use of binfinder
123  //int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.perp());
124  //float outerDist = std::abs( theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.perp());
125  int outerIndex = findBin(gOuterPoint.perp(), 1);
126  float outerDist = std::abs(findPosition(outerIndex, 1).perp() - gOuterPoint.perp());
127  SubLayerCrossing outerSLC(1, outerIndex, gOuterPoint);
128 
129  if (innerDist < outerDist) {
130  return SubLayerCrossings(innerSLC, outerSLC, 0);
131  } else {
132  return SubLayerCrossings(outerSLC, innerSLC, 1);
133  }
134 }
135 
137  const Propagator& prop,
138  const MeasurementEstimator& est,
139  const SubLayerCrossing& crossing,
140  vector<DetGroup>& result) const {
141  const vector<const GeomDet*>& sBlade(subBlade(crossing.subLayerIndex()));
142  return CompatibleDetToGroupAdder().add(*sBlade[crossing.closestDetIndex()], tsos, prop, est, result);
143 }
144 
146  const TrajectoryStateOnSurface& tsos,
147  const MeasurementEstimator& est) const {
148  return est.maximalLocalDisplacement(tsos, det->surface()).x();
149 }
150 
152  const Propagator& prop,
153  const MeasurementEstimator& est,
154  const SubLayerCrossing& crossing,
155  float window,
156  vector<DetGroup>& result,
157  bool checkClosest) const {
158  const GlobalPoint& gCrossingPos = crossing.position();
159 
160  const vector<const GeomDet*>& sBlade(subBlade(crossing.subLayerIndex()));
161 
162  int closestIndex = crossing.closestDetIndex();
163  int negStartIndex = closestIndex - 1;
164  int posStartIndex = closestIndex + 1;
165 
166  if (checkClosest) { // must decide if the closest is on the neg or pos side
167  if (gCrossingPos.perp() < sBlade[closestIndex]->surface().position().perp()) {
168  posStartIndex = closestIndex;
169  } else {
170  negStartIndex = closestIndex;
171  }
172  }
173 
174  typedef CompatibleDetToGroupAdder Adder;
175  for (int idet = negStartIndex; idet >= 0; idet--) {
176  if (!overlap(gCrossingPos, *sBlade[idet], window))
177  break;
178  if (!Adder::add(*sBlade[idet], tsos, prop, est, result))
179  break;
180  }
181  for (int idet = posStartIndex; idet < static_cast<int>(sBlade.size()); idet++) {
182  if (!overlap(gCrossingPos, *sBlade[idet], window))
183  break;
184  if (!Adder::add(*sBlade[idet], tsos, prop, est, result))
185  break;
186  }
187 }
188 
189 bool PixelBlade::overlap(const GlobalPoint& crossPoint, const GeomDet& det, float window) const {
190  // check if the z window around TSOS overlaps with the detector theDet (with a 1% margin added)
191 
192  // const float tolerance = 0.1;
193  const float relativeMargin = 1.01;
194 
195  LocalPoint localCrossPoint(det.surface().toLocal(crossPoint));
196  // if (std::abs(localCrossPoint.z()) > tolerance) {
197  // edm::LogInfo(TkDetLayers) << "PixelBlade::overlap calculation assumes point on surface, but it is off by "
198  // << localCrossPoint.z() ;
199  // }
200 
201  float localX = localCrossPoint.x();
202  float detHalfLength = det.surface().bounds().length() / 2.;
203 
204  // edm::LogInfo(TkDetLayers) << "PixelBlade::overlap: Det at " << det.position() << " hit at " << localY
205  // << " Window " << window << " halflength " << detHalfLength ;
206 
207  if ((std::abs(localX) - window) < relativeMargin * detHalfLength) { // FIXME: margin hard-wired!
208  return true;
209  } else {
210  return false;
211  }
212 }
213 
214 int PixelBlade::findBin(float R, int diskSectorIndex) const {
215  vector<const GeomDet*> localDets = diskSectorIndex == 0 ? theFrontDets : theBackDets;
216 
217  int theBin = 0;
218  float rDiff = std::abs(R - localDets.front()->surface().position().perp());
219  ;
220  for (vector<const GeomDet*>::const_iterator i = localDets.begin(); i != localDets.end(); i++) {
221  float testDiff = std::abs(R - (**i).surface().position().perp());
222  if (testDiff < rDiff) {
223  rDiff = testDiff;
224  theBin = i - localDets.begin();
225  }
226  }
227  return theBin;
228 }
229 
230 GlobalPoint PixelBlade::findPosition(int index, int diskSectorType) const {
231  vector<const GeomDet*> diskSector = diskSectorType == 0 ? theFrontDets : theBackDets;
232  return (diskSector[index])->surface().position();
233 }
Common base class.
def window
Definition: svgfig.py:643
ReferenceCountingPointer< BoundDiskSector > theFrontDiskSector
Definition: PixelBlade.h:81
virtual float length() const =0
T perp() const
Definition: PV3DBase.h:69
ReferenceCountingPointer< BoundDiskSector > theBackDiskSector
Definition: PixelBlade.h:82
int closestIndex() const
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
Definition: PixelBlade.cc:59
int closestDetIndex() const
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: PixelBlade.cc:136
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const override __attribute__((cold))
Definition: PixelBlade.cc:52
GlobalPoint globalPosition() const
const Bounds & bounds() const
Definition: Surface.h:87
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const
Definition: PixelBlade.cc:145
PropagationDirection
Log< level::Error, false > LogError
std::vector< const GeomDet * > theFrontDets
Definition: PixelBlade.h:77
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
GlobalPoint findPosition(int index, int diskSectorIndex) const
Definition: PixelBlade.cc:230
std::vector< const GeomDet * > theBackDets
Definition: PixelBlade.h:78
const std::vector< const GeomDet * > & subBlade(int ind) const
Definition: PixelBlade.h:73
tuple result
Definition: mps_fire.py:311
const GlobalPoint & position() const
bool overlap(const GlobalPoint &gpos, const GeomDet &det, float phiWin) const
Definition: PixelBlade.cc:189
int findBin(float R, int layer) const
Definition: PixelBlade.cc:214
const std::vector< const GeometricSearchDet * > & components() const override __attribute__((cold))
Returns basic components, if any.
Definition: PixelBlade.cc:48
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
LocalPoint toLocal(const GlobalPoint &gp) const
int subLayerIndex() const
T z() const
Definition: PV3DBase.h:61
~PixelBlade() override __attribute__((cold))
Definition: PixelBlade.cc:18
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
PixelBlade(std::vector< const GeomDet * > &frontDets, std::vector< const GeomDet * > &backDets) __attribute__((cold))
Definition: PixelBlade.cc:20
const SubLayerCrossing & other() const
static bool add(const GeometricSearchDet &det, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) __attribute__((hot))
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
static BoundDiskSector * build(const std::vector< const GeomDet * > &dets) __attribute__((cold))
virtual const Surface::PositionType & position() const
Returns position of the surface.
constexpr uint16_t localX(uint16_t px)
std::vector< const GeomDet * > theDets
Definition: PixelBlade.h:76
const SubLayerCrossing & closest() const
T perp() const
Magnitude of transverse component.
GlobalVector globalMomentum() const
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
ReferenceCountingPointer< BoundDiskSector > theDiskSector
Definition: PixelBlade.h:80
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
Definition: PixelBlade.cc:97
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: PixelBlade.cc:151
#define LogDebug(id)