CMS 3D CMS Logo

Phase1PixelBlade.cc
Go to the documentation of this file.
1 #include "Phase1PixelBlade.h"
2 
4 
6 #include "LayerCrossingSide.h"
7 #include "DetGroupMerger.h"
10 
14 
15 using namespace std;
16 
18 
20 
21 Phase1PixelBlade::Phase1PixelBlade(vector<const GeomDet*>& frontDets, vector<const GeomDet*>& backDets)
23  theFrontDets(frontDets),
24  theBackDets(backDets),
25  front_radius_range_(std::make_pair(0, 0)),
26  back_radius_range_(std::make_pair(0, 0)) {
27  theDets.assign(theFrontDets.begin(), theFrontDets.end());
28  theDets.insert(theDets.end(), theBackDets.begin(), theBackDets.end());
29 
33 
34  //--------- DEBUG INFO --------------
35  LogDebug("TkDetLayers") << "DEBUG INFO for Phase1PixelBlade";
36  LogDebug("TkDetLayers") << "Blade z, perp, innerRadius, outerR[disk, front, back]: " << this->position().z() << " , "
37  << this->position().perp() << " , (" << theDiskSector->innerRadius() << " , "
38  << theDiskSector->outerRadius() << "), (" << theFrontDiskSector->innerRadius() << " , "
39  << theFrontDiskSector->outerRadius() << "), (" << theBackDiskSector->innerRadius() << " , "
40  << theBackDiskSector->outerRadius() << ")" << std::endl;
41 
42  for (vector<const GeomDet*>::const_iterator it = theFrontDets.begin(); it != theFrontDets.end(); it++) {
43  LogDebug("TkDetLayers") << "frontDet phi,z,r: " << (*it)->position().phi() << " , " << (*it)->position().z()
44  << " , " << (*it)->position().perp() << " , "
45  << " rmin: " << (*it)->surface().rSpan().first
46  << " rmax: " << (*it)->surface().rSpan().second << std::endl;
47  }
48 
49  for (vector<const GeomDet*>::const_iterator it = theBackDets.begin(); it != theBackDets.end(); it++) {
50  LogDebug("TkDetLayers") << "backDet phi,z,r: " << (*it)->position().phi() << " , " << (*it)->position().z() << " , "
51  << (*it)->position().perp() << " , "
52  << " rmin: " << (*it)->surface().rSpan().first
53  << " rmax: " << (*it)->surface().rSpan().second << std::endl;
54  }
55 }
56 
57 const vector<const GeometricSearchDet*>& Phase1PixelBlade::components() const {
58  throw DetLayerException("TOBRod doesn't have GeometricSearchDet components");
59 }
60 
61 pair<bool, TrajectoryStateOnSurface> Phase1PixelBlade::compatible(const TrajectoryStateOnSurface& ts,
62  const Propagator&,
63  const MeasurementEstimator&) const {
64  edm::LogError("TkDetLayers") << "temporary dummy implementation of Phase1PixelBlade::compatible()!!";
65  return pair<bool, TrajectoryStateOnSurface>();
66 }
67 
69  const Propagator& prop,
70  const MeasurementEstimator& est,
71  std::vector<DetGroup>& result) const {
72  SubLayerCrossings crossings;
73 
74  crossings = computeCrossings(tsos, prop.propagationDirection());
75  if (!crossings.isValid())
76  return;
77 
78  vector<DetGroup> closestResult;
79  addClosest(tsos, prop, est, crossings.closest(), closestResult);
80 
81  if (closestResult.empty()) {
82  vector<DetGroup> nextResult;
83  addClosest(tsos, prop, est, crossings.other(), nextResult);
84  if (nextResult.empty())
85  return;
86 
87  //DetGroupElement nextGel( nextResult.front().front());
88  //int crossingSide = LayerCrossingSide().endcapSide( nextGel.trajectoryState(), prop);
89 
91  std::move(nextResult),
92  result,
93  0,
94  0); //fixme gc patched for SLHC - already correctly sorted for SLHC
95  //crossings.closestIndex(), crossingSide);
96  } else {
97  DetGroupElement closestGel(closestResult.front().front());
98  float window = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
99 
100  searchNeighbors(tsos, prop, est, crossings.closest(), window, closestResult, false);
101 
102  vector<DetGroup> nextResult;
103  searchNeighbors(tsos, prop, est, crossings.other(), window, nextResult, true);
104 
105  //int crossingSide = LayerCrossingSide().endcapSide( closestGel.trajectoryState(), prop);
107  std::move(nextResult),
108  result,
109  0,
110  0); //fixme gc patched for SLHC - already correctly sorted for SLHC
111  //crossings.closestIndex(), crossingSide);
112  }
113 }
114 
116  PropagationDirection propDir) const {
117  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
118  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
119  double rho(startingState.transverseCurvature());
120  HelixArbitraryPlaneCrossing crossing(startPos, startDir, rho, propDir);
121 
122  pair<bool, double> innerPath = crossing.pathLength(*theFrontDiskSector);
123  if (!innerPath.first)
124  return SubLayerCrossings();
125 
126  GlobalPoint gInnerPoint(crossing.position(innerPath.second));
127  //Code for use of binfinder
128  //int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.perp());
129  //float innerDist = std::abs( theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.z());
130 
131  // int innerIndex = findBin(gInnerPoint.perp(),0);
132  int innerIndex = findBin2(gInnerPoint, 0);
133 
134  //fixme gc patched for SLHC - force order here to be in z
135  //float innerDist = std::abs( findPosition(innerIndex,0).perp() - gInnerPoint.perp());
136  float innerDist = (startingState.globalPosition() - gInnerPoint).mag();
137  SubLayerCrossing innerSLC(0, innerIndex, gInnerPoint);
138 
139  pair<bool, double> outerPath = crossing.pathLength(*theBackDiskSector);
140  if (!outerPath.first)
141  return SubLayerCrossings();
142 
143  GlobalPoint gOuterPoint(crossing.position(outerPath.second));
144  //Code for use of binfinder
145  //int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.perp());
146  //float outerDist = std::abs( theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.perp());
147  // int outerIndex = findBin(gOuterPoint.perp(),1);
148  int outerIndex = findBin2(gOuterPoint, 1);
149 
150  //fixme gc patched for SLHC - force order here to be in z
151  //float outerDist = std::abs( findPosition(outerIndex,1).perp() - gOuterPoint.perp());
152  float outerDist = (startingState.globalPosition() - gOuterPoint).mag();
153  SubLayerCrossing outerSLC(1, outerIndex, gOuterPoint);
154 
155  if (innerDist < outerDist) {
156  return SubLayerCrossings(innerSLC, outerSLC, 0);
157  } else {
158  return SubLayerCrossings(outerSLC, innerSLC, 1);
159  }
160 }
161 
163  const Propagator& prop,
164  const MeasurementEstimator& est,
165  const SubLayerCrossing& crossing,
166  vector<DetGroup>& result) const {
167  const vector<const GeomDet*>& sBlade(subBlade(crossing.subLayerIndex()));
168 
169  return CompatibleDetToGroupAdder().add(*sBlade[crossing.closestDetIndex()], tsos, prop, est, result);
170 }
171 
173  const TrajectoryStateOnSurface& tsos,
174  const MeasurementEstimator& est) const {
175  return est.maximalLocalDisplacement(tsos, det->surface()).x();
176 }
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  const vector<const GeomDet*>& sBlade(subBlade(crossing.subLayerIndex()));
187 
188  int closestIndex = crossing.closestDetIndex();
189  int negStartIndex = closestIndex - 1;
190  int posStartIndex = closestIndex + 1;
191 
192  if (checkClosest) { // must decide if the closest is on the neg or pos side
193  if (gCrossingPos.perp() < sBlade[closestIndex]->surface().position().perp()) {
194  posStartIndex = closestIndex;
195  } else {
196  negStartIndex = closestIndex;
197  }
198  }
199 
200  typedef CompatibleDetToGroupAdder Adder;
201  for (int idet = negStartIndex; idet >= 0; idet--) {
202  if (!overlap(gCrossingPos, *sBlade[idet], window))
203  break;
204  if (!Adder::add(*sBlade[idet], tsos, prop, est, result))
205  break;
206  }
207  for (int idet = posStartIndex; idet < static_cast<int>(sBlade.size()); idet++) {
208  if (!overlap(gCrossingPos, *sBlade[idet], window))
209  break;
210  if (!Adder::add(*sBlade[idet], tsos, prop, est, result))
211  break;
212  }
213 }
214 
215 bool Phase1PixelBlade::overlap(const GlobalPoint& crossPoint, const GeomDet& det, float window) const {
216  // check if the z window around TSOS overlaps with the detector theDet (with a 1% margin added)
217 
218  // const float tolerance = 0.1;
219  const float relativeMargin = 1.01;
220 
221  LocalPoint localCrossPoint(det.surface().toLocal(crossPoint));
222  // if (std::abs(localCrossPoint.z()) > tolerance) {
223  // edm::LogInfo(TkDetLayers) << "Phase1PixelBlade::overlap calculation assumes point on surface, but it is off by "
224  // << localCrossPoint.z() ;
225  // }
226 
227  float localX = localCrossPoint.x();
228  float detHalfLength = det.surface().bounds().length() / 2.;
229 
230  // edm::LogInfo(TkDetLayers) << "Phase1PixelBlade::overlap: Det at " << det.position() << " hit at " << localY
231  // << " Window " << window << " halflength " << detHalfLength ;
232 
233  if ((std::abs(localX) - window) < relativeMargin * detHalfLength) { // FIXME: margin hard-wired!
234  return true;
235  } else {
236  return false;
237  }
238 }
239 
240 int Phase1PixelBlade::findBin(float R, int diskSectorIndex) const {
241  vector<const GeomDet*> localDets = diskSectorIndex == 0 ? theFrontDets : theBackDets;
242 
243  int theBin = 0;
244  float rDiff = std::abs(R - localDets.front()->surface().position().perp());
245  for (vector<const GeomDet*>::const_iterator i = localDets.begin(); i != localDets.end(); i++) {
246  float testDiff = std::abs(R - (**i).surface().position().perp());
247  if (testDiff < rDiff) {
248  rDiff = testDiff;
249  theBin = i - localDets.begin();
250  }
251  }
252  return theBin;
253 }
254 
255 int Phase1PixelBlade::findBin2(GlobalPoint thispoint, int diskSectorIndex) const {
256  const vector<const GeomDet*>& localDets = diskSectorIndex == 0 ? theFrontDets : theBackDets;
257 
258  int theBin = 0;
259  float sDiff = (thispoint - localDets.front()->surface().position()).mag();
260 
261  for (vector<const GeomDet*>::const_iterator i = localDets.begin(); i != localDets.end(); i++) {
262  float testDiff = (thispoint - (**i).surface().position()).mag();
263  if (testDiff < sDiff) {
264  sDiff = testDiff;
265  theBin = i - localDets.begin();
266  }
267  }
268  return theBin;
269 }
270 
271 GlobalPoint Phase1PixelBlade::findPosition(int index, int diskSectorType) const {
272  vector<const GeomDet*> diskSector = diskSectorType == 0 ? theFrontDets : theBackDets;
273  return (diskSector[index])->surface().position();
274 }
275 
276 std::pair<float, float> Phase1PixelBlade::computeRadiusRanges(const std::vector<const GeomDet*>& current_dets) {
278  Vector posSum(0, 0, 0);
279  for (auto i : current_dets)
280  posSum += (*i).surface().position().basicVector();
281 
282  Surface::PositionType meanPos(0., 0., posSum.z() / float(current_dets.size()));
283 
284  // temporary plane - for the computation of bounds
285  const Plane& tmpplane = current_dets.front()->surface();
286 
290 
291  GlobalVector planeXAxis = tmpplane.toGlobal(LocalVector(1, 0, 0));
292  const GlobalPoint& planePosition = tmpplane.position();
293 
294  if (planePosition.x() * planeXAxis.x() + planePosition.y() * planeXAxis.y() > 0.) {
295  yAxis = planeXAxis;
296  } else {
297  yAxis = -planeXAxis;
298  }
299 
300  GlobalVector planeZAxis = tmpplane.toGlobal(LocalVector(0, 0, 1));
301  if (planeZAxis.z() * planePosition.z() > 0.) {
302  zAxis = planeZAxis;
303  } else {
304  zAxis = -planeZAxis;
305  }
306 
307  xAxis = yAxis.cross(zAxis);
308 
310  Plane plane(meanPos, rotation);
311 
312  Surface::PositionType tmpPos = current_dets.front()->surface().position();
313 
314  float rmin(plane.toLocal(tmpPos).perp());
315  float rmax(plane.toLocal(tmpPos).perp());
316 
317  for (auto it : current_dets) {
318  vector<GlobalPoint> corners = BoundingBox().corners(it->specificSurface());
319  for (const auto& i : corners) {
320  float r = plane.toLocal(i).perp();
321  rmin = min(rmin, r);
322  rmax = max(rmax, r);
323  }
324  }
325 
326  return std::make_pair(rmin, rmax);
327 }
static BoundDiskSector * build(const std::vector< const GeomDet *> &dets) __attribute__((cold))
Common base class.
virtual const Surface::PositionType & position() const
Returns position of the surface.
Local3DVector LocalVector
Definition: LocalVector.h:12
T perp() const
Definition: PV3DBase.h:69
std::vector< const GeomDet * > theBackDets
virtual float length() const =0
std::pair< float, float > computeRadiusRanges(const std::vector< const GeomDet *> &)
T z() const
Definition: PV3DBase.h:61
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
const std::vector< const GeomDet * > & subBlade(int ind) const
int findBin(float R, int layer) const
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))
bool overlap(const GlobalPoint &gpos, const GeomDet &det, float phiWin) const
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
PropagationDirection
Log< level::Error, false > LogError
LocalPoint toLocal(const GlobalPoint &gp) const
Definition: Plane.h:16
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
GlobalPoint globalPosition() const
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
const GlobalPoint & position() const
int closestDetIndex() const
GeometricSearchDet::DetWithState DetWithState
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
std::vector< const GeomDet * > theDets
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
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
const SubLayerCrossing & closest() const
int subLayerIndex() const
const std::vector< const GeometricSearchDet * > & components() const override __attribute__((cold))
Returns basic components, if any.
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
static bool add(const GeometricSearchDet &det, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) __attribute__((hot))
GlobalPoint findPosition(int index, int diskSectorIndex) const
const SubLayerCrossing & other() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const PositionType & position() const
constexpr uint16_t localX(uint16_t px)
~Phase1PixelBlade() override __attribute__((cold))
ReferenceCountingPointer< BoundDiskSector > theDiskSector
GlobalVector globalMomentum() const
static std::vector< GlobalPoint > corners(const Plane &)
Definition: BoundingBox.cc:20
ReferenceCountingPointer< BoundDiskSector > theFrontDiskSector
int findBin2(GlobalPoint thispoint, int layer) const
Phase1PixelBlade(std::vector< const GeomDet *> &frontDets, std::vector< const GeomDet *> &backDets) __attribute__((cold))
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
TkRotation< float > RotationType
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))
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
std::vector< const GeomDet * > theFrontDets
def move(src, dest)
Definition: eostools.py:511
ReferenceCountingPointer< BoundDiskSector > theBackDiskSector
#define LogDebug(id)
const Bounds & bounds() const
Definition: Surface.h:87