CMS 3D CMS Logo

PixelForwardLayerPhase1.cc
Go to the documentation of this file.
2 
4 
7 
12 
13 #include "LayerCrossingSide.h"
14 #include "DetGroupMerger.h"
16 
18 
19 #include <algorithm>
20 #include <climits>
21 
22 using namespace std;
23 
25 
26 PixelForwardLayerPhase1::PixelForwardLayerPhase1(vector<const Phase1PixelBlade*>& blades)
27  : ForwardDetLayer(true), theComps(blades.begin(), blades.end()) {
28  // Assumes blades are ordered inner first then outer; and within each by phi
29  // where we go 0 -> pi, and then -pi -> 0
30  // we also need the number of inner blades for the offset in theComps vector
31  //
32  // this->specificSurface() not yet available so need to calculate average R
33  // we need some way to flag if FPIX is made of an inner and outer disk
34  // or probably need to change the way this is done, e.g. a smarter binFinder
35  float theRmin = (*(theComps.begin()))->surface().position().perp();
36  float theRmax = theRmin;
37  for (vector<const GeometricSearchDet*>::const_iterator it = theComps.begin(); it != theComps.end(); it++) {
38  theRmin = std::min(theRmin, (*it)->surface().position().perp());
39  theRmax = std::max(theRmax, (*it)->surface().position().perp());
40  }
41  //float split_inner_outer_radius = 0.5 * (theRmin + theRmax);
42  // force the splitting rdius to be 10 cm to cope also with the FPIX disks with only the outer ring
43  float split_inner_outer_radius = 10.;
44  _num_innerpanels = 0;
45  for (vector<const GeometricSearchDet*>::const_iterator it = theComps.begin(); it != theComps.end(); it++) {
46  if ((**it).surface().position().perp() <= split_inner_outer_radius)
48  }
50  edm::LogInfo("TkDetLayers") << " Rmin, Rmax, R_average = " << theRmin << ", " << theRmax << ", "
51  << split_inner_outer_radius << std::endl
52  << " num inner, outer disks = " << _num_innerpanels << ", " << _num_outerpanels
53  << std::endl;
54 
55  for (vector<const GeometricSearchDet*>::const_iterator it = theComps.begin(); it != theComps.end(); it++) {
56  theBasicComps.insert(theBasicComps.end(), (**it).basicComponents().begin(), (**it).basicComponents().end());
57  }
58 
59  //They should be already phi-ordered. TO BE CHECKED!!
60  //sort( theBlades.begin(), theBlades.end(), PhiLess());
62 
63  theBinFinder_inner = BinFinderType(theComps.front()->surface().position().phi(), _num_innerpanels);
65 
66  //--------- DEBUG INFO --------------
67  LogDebug("TkDetLayers") << "DEBUG INFO for PixelForwardLayerPhase1"
68  << "\n"
69  << "Num of inner and outer panels = " << _num_innerpanels << ", " << _num_outerpanels << "\n"
70  << "Based on phi separation for inner: " << theComps.front()->surface().position().phi()
71  << " and on phi separation for outer: "
72  << theComps[_num_innerpanels]->surface().position().phi()
73  << "PixelForwardLayerPhase1.surfcace.phi(): " << std::endl
74  << this->surface().position().phi() << "\n"
75  << "PixelForwardLayerPhase1.surfcace.z(): " << this->surface().position().z() << "\n"
76  << "PixelForwardLayerPhase1.surfcace.innerR(): " << this->specificSurface().innerRadius()
77  << "\n"
78  << "PixelForwardLayerPhase1.surfcace.outerR(): " << this->specificSurface().outerRadius();
79 
80  for (vector<const GeometricSearchDet*>::const_iterator it = theComps.begin(); it != theComps.end(); it++) {
81  LogDebug("TkDetLayers") << "blades phi,z,r: " << (*it)->surface().position().phi() << " , "
82  << (*it)->surface().position().z() << " , " << (*it)->surface().position().perp();
83  //for(vector<const GeomDet*>::const_iterator iu=(**it).basicComponents().begin();
84  // iu!=(**it).basicComponents().end();iu++){
85  // std::cout << " basic component rawId = " << hex << (**iu).geographicalId().rawId() << dec <<std::endl;
86  //}
87  }
88  //-----------------------------------
89 }
90 
92  vector<const GeometricSearchDet*>::const_iterator i;
93  for (i = theComps.begin(); i != theComps.end(); i++) {
94  delete *i;
95  }
96 }
97 
99  const Propagator& prop,
100  const MeasurementEstimator& est,
101  std::vector<DetGroup>& result) const {
102  std::vector<DetGroup> closestResult_inner;
103  std::vector<DetGroup> closestResult_outer;
104  std::vector<DetGroup> nextResult_inner;
105  std::vector<DetGroup> nextResult_outer;
106  std::vector<DetGroup> result_inner;
107  std::vector<DetGroup> result_outer;
108  int frontindex_inner = 0;
109  int frontindex_outer = 0;
110  SubTurbineCrossings crossings_inner;
111  SubTurbineCrossings crossings_outer;
112 
113  if (_num_innerpanels > 0)
114  crossings_inner = computeCrossings(tsos, prop.propagationDirection(), true);
115  crossings_outer = computeCrossings(tsos, prop.propagationDirection(), false);
116  // if (!crossings_inner.isValid){
117  // edm::LogInfo("TkDetLayers") << "inner computeCrossings returns invalid in PixelForwardLayerPhase1::groupedCompatibleDets:";
118  // return;
119  // }
120  if (!crossings_outer.isValid) {
121  edm::LogInfo("TkDetLayers")
122  << "outer computeCrossings returns invalid in PixelForwardLayerPhase1::groupedCompatibleDets:";
123  return;
124  }
125 
126  typedef CompatibleDetToGroupAdder Adder;
127  if (crossings_inner.isValid) {
128  Adder::add(
129  *theComps[theBinFinder_inner.binIndex(crossings_inner.closestIndex)], tsos, prop, est, closestResult_inner);
130 
131  if (closestResult_inner.empty()) {
132  Adder::add(*theComps[theBinFinder_inner.binIndex(crossings_inner.nextIndex)], tsos, prop, est, result_inner);
133  frontindex_inner = crossings_inner.nextIndex;
134  } else {
135  if (Adder::add(
136  *theComps[theBinFinder_inner.binIndex(crossings_inner.nextIndex)], tsos, prop, est, nextResult_inner)) {
137  int crossingSide = LayerCrossingSide().endcapSide(tsos, prop);
138  int theHelicity = computeHelicity(theComps[theBinFinder_inner.binIndex(crossings_inner.closestIndex)],
139  theComps[theBinFinder_inner.binIndex(crossings_inner.nextIndex)]);
140  std::vector<DetGroup> tmp99 = closestResult_inner;
142  std::move(tmp99), std::move(nextResult_inner), result_inner, theHelicity, crossingSide);
143  if (theHelicity == crossingSide)
144  frontindex_inner = crossings_inner.closestIndex;
145  else
146  frontindex_inner = crossings_inner.nextIndex;
147  } else {
148  result_inner.swap(closestResult_inner);
149  frontindex_inner = crossings_inner.closestIndex;
150  }
151  }
152  }
153  if (!closestResult_inner.empty()) {
154  DetGroupElement closestGel(closestResult_inner.front().front());
155  float window = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
156  searchNeighbors(tsos, prop, est, crossings_inner, window, result_inner, true);
157  }
158 
159  //DetGroupElement closestGel( closestResult.front().front());
160  //float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
161  //float detWidth = closestGel.det()->surface().bounds().width();
162  //if (crossings.nextDistance < detWidth + window) {
163 
164  Adder::add(*theComps[(theBinFinder_outer.binIndex(crossings_outer.closestIndex)) + _num_innerpanels],
165  tsos,
166  prop,
167  est,
168  closestResult_outer);
169 
170  if (closestResult_outer.empty()) {
171  Adder::add(*theComps[theBinFinder_outer.binIndex(crossings_outer.nextIndex) + _num_innerpanels],
172  tsos,
173  prop,
174  est,
175  result_outer);
176  frontindex_outer = crossings_outer.nextIndex;
177  } else {
178  if (Adder::add(*theComps[theBinFinder_outer.binIndex(crossings_outer.nextIndex) + _num_innerpanels],
179  tsos,
180  prop,
181  est,
182  nextResult_outer)) {
183  int crossingSide = LayerCrossingSide().endcapSide(tsos, prop);
184  int theHelicity =
185  computeHelicity(theComps[theBinFinder_outer.binIndex(crossings_outer.closestIndex) + _num_innerpanels],
186  theComps[theBinFinder_outer.binIndex(crossings_outer.nextIndex) + _num_innerpanels]);
187  std::vector<DetGroup> tmp99 = closestResult_outer;
189  std::move(tmp99), std::move(nextResult_outer), result_outer, theHelicity, crossingSide);
190  if (theHelicity == crossingSide)
191  frontindex_outer = crossings_outer.closestIndex;
192  else
193  frontindex_outer = crossings_outer.nextIndex;
194  } else {
195  result_outer.swap(closestResult_outer);
196  frontindex_outer = crossings_outer.closestIndex;
197  }
198  }
199  if (!closestResult_outer.empty()) {
200  DetGroupElement closestGel(closestResult_outer.front().front());
201  float window = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
202  searchNeighbors(tsos, prop, est, crossings_outer, window, result_outer, false);
203  }
204 
205  if (result_inner.empty() && result_outer.empty())
206  return;
207  if (result_inner.empty())
208  result.swap(result_outer);
209  else if (result_outer.empty())
210  result.swap(result_inner);
211  else {
212  int crossingSide = LayerCrossingSide().endcapSide(tsos, prop);
213  int theHelicity = computeHelicity(theComps[theBinFinder_inner.binIndex(frontindex_inner)],
216  std::move(result_inner), std::move(result_outer), result, theHelicity, crossingSide);
217  }
218 }
219 
221  const Propagator& prop,
222  const MeasurementEstimator& est,
223  const SubTurbineCrossings& crossings,
224  float window,
225  vector<DetGroup>& result,
226  bool innerDisk) const {
227  typedef CompatibleDetToGroupAdder Adder;
228  int crossingSide = LayerCrossingSide().endcapSide(tsos, prop);
229  typedef DetGroupMerger Merger;
230 
231  int negStart = min(crossings.closestIndex, crossings.nextIndex) - 1;
232  int posStart = max(crossings.closestIndex, crossings.nextIndex) + 1;
233 
234  int quarter = (innerDisk ? _num_innerpanels / 4 : _num_outerpanels / 4);
235 
236  for (int idet = negStart; idet >= negStart - quarter + 1; idet--) {
237  std::vector<DetGroup> tmp1;
238  std::vector<DetGroup> newResult;
239  if (innerDisk) {
240  const GeometricSearchDet* neighbor = theComps[theBinFinder_inner.binIndex(idet)];
241  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
242  // maybe also add shallow crossing angle test here???
243  if (!Adder::add(*neighbor, tsos, prop, est, tmp1))
244  break;
245  int theHelicity =
247  std::vector<DetGroup> tmp2;
248  tmp2.swap(result);
249  Merger::orderAndMergeTwoLevels(std::move(tmp1), std::move(tmp2), newResult, theHelicity, crossingSide);
250  } else {
252  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
253  // maybe also add shallow crossing angle test here???
254  if (!Adder::add(*neighbor, tsos, prop, est, tmp1))
255  break;
258  std::vector<DetGroup> tmp2;
259  tmp2.swap(result);
260  Merger::orderAndMergeTwoLevels(std::move(tmp1), std::move(tmp2), newResult, theHelicity, crossingSide);
261  }
262  result.swap(newResult);
263  }
264  for (int idet = posStart; idet < posStart + quarter - 1; idet++) {
265  std::vector<DetGroup> tmp1;
266  std::vector<DetGroup> newResult;
267  if (innerDisk) {
268  const GeometricSearchDet* neighbor = theComps[theBinFinder_inner.binIndex(idet)];
269  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
270  // maybe also add shallow crossing angle test here???
271  if (!Adder::add(*neighbor, tsos, prop, est, tmp1))
272  break;
273  int theHelicity =
275  std::vector<DetGroup> tmp2;
276  tmp2.swap(result);
277  Merger::orderAndMergeTwoLevels(std::move(tmp2), std::move(tmp1), newResult, theHelicity, crossingSide);
278  } else {
280  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
281  // maybe also add shallow crossing angle test here???
282  if (!Adder::add(*neighbor, tsos, prop, est, tmp1))
283  break;
284  int theHelicity = computeHelicity(theComps[(theBinFinder_outer.binIndex(idet - 1)) + _num_innerpanels],
286  std::vector<DetGroup> tmp2;
287  tmp2.swap(result);
288  Merger::orderAndMergeTwoLevels(std::move(tmp2), std::move(tmp1), newResult, theHelicity, crossingSide);
289  }
290  result.swap(newResult);
291  }
292 }
293 
295  const GeometricSearchDet* secondBlade) {
296  return std::abs(firstBlade->position().z()) < std::abs(secondBlade->position().z()) ? 0 : 1;
297 }
298 
300  const TrajectoryStateOnSurface& startingState, PropagationDirection propDir, bool innerDisk) const {
302 
303  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
304  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
305  auto rho = startingState.transverseCurvature();
306 
307  HelixArbitraryPlaneCrossing turbineCrossing(startPos, startDir, rho, propDir);
308 
309  pair<bool, double> thePath = turbineCrossing.pathLength(specificSurface());
310 
311  if (!thePath.first) {
312  return SubTurbineCrossings();
313  }
314 
315  HelixPlaneCrossing::PositionType turbinePoint(turbineCrossing.position(thePath.second));
316  HelixPlaneCrossing::DirectionType turbineDir(turbineCrossing.direction(thePath.second));
317  int closestIndex = 0;
318  int nextIndex = 0;
319  if (innerDisk)
320  closestIndex = theBinFinder_inner.binIndex(turbinePoint.barePhi());
321  else
322  closestIndex = theBinFinder_outer.binIndex(turbinePoint.barePhi());
323 
324  HelixArbitraryPlaneCrossing2Order theBladeCrossing(turbinePoint, turbineDir, rho);
325 
326  float closestDist = 0;
327  if (innerDisk) {
328  const BoundPlane& closestPlane(static_cast<const BoundPlane&>(theComps[closestIndex]->surface()));
329 
330  pair<bool, double> theClosestBladePath = theBladeCrossing.pathLength(closestPlane);
331  LocalPoint closestPos = closestPlane.toLocal(GlobalPoint(theBladeCrossing.position(theClosestBladePath.second)));
332  closestDist = closestPos.x();
333  // use fact that local X perp to global Y
334  nextIndex = Geom::phiLess(closestPlane.phi(), turbinePoint.barePhi()) ? closestIndex + 1 : closestIndex - 1;
335  } else {
336  const BoundPlane& closestPlane(
337  static_cast<const BoundPlane&>(theComps[closestIndex + _num_innerpanels]->surface()));
338 
339  pair<bool, double> theClosestBladePath = theBladeCrossing.pathLength(closestPlane);
340  LocalPoint closestPos = closestPlane.toLocal(GlobalPoint(theBladeCrossing.position(theClosestBladePath.second)));
341  closestDist = closestPos.x();
342  // use fact that local X perp to global Y
343  nextIndex = Geom::phiLess(closestPlane.phi(), turbinePoint.barePhi()) ? closestIndex + 1 : closestIndex - 1;
344  }
345 
346  float nextDist = 0;
347  if (innerDisk) {
348  const BoundPlane& nextPlane(
349  static_cast<const BoundPlane&>(theComps[theBinFinder_inner.binIndex(nextIndex)]->surface()));
350  pair<bool, double> theNextBladePath = theBladeCrossing.pathLength(nextPlane);
351  LocalPoint nextPos = nextPlane.toLocal(GlobalPoint(theBladeCrossing.position(theNextBladePath.second)));
352  nextDist = nextPos.x();
353  } else {
354  const BoundPlane& nextPlane(
355  static_cast<const BoundPlane&>(theComps[theBinFinder_outer.binIndex(nextIndex) + _num_innerpanels]->surface()));
356  pair<bool, double> theNextBladePath = theBladeCrossing.pathLength(nextPlane);
357  LocalPoint nextPos = nextPlane.toLocal(GlobalPoint(theBladeCrossing.position(theNextBladePath.second)));
358  nextDist = nextPos.x();
359  }
360  if (std::abs(closestDist) < std::abs(nextDist)) {
361  return SubTurbineCrossings(closestIndex, nextIndex, nextDist);
362  } else {
363  return SubTurbineCrossings(nextIndex, closestIndex, closestDist);
364  }
365 }
366 
368  const TrajectoryStateOnSurface& tsos,
369  const MeasurementEstimator& est) {
370  return est.maximalLocalDisplacement(tsos, det->surface()).x();
371 }
PeriodicBinFinderInPhi< float > BinFinderType
std::pair< bool, double > pathLength(const Plane &plane) override
virtual BoundDisk * computeSurface()
virtual const Surface::PositionType & position() const
Returns position of the surface.
T perp() const
Definition: PV3DBase.h:69
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
int binIndex(T phi) const override
returns an index in the valid range for the bin that contains phi
GeometricSearchDet::DetWithState DetWithState
const BoundSurface & surface() const final
The surface of the GeometricSearchDet.
T z() const
Definition: PV3DBase.h:61
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
void setSurface(BoundDisk *cp)
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
static int computeHelicity(const GeometricSearchDet *firstBlade, const GeometricSearchDet *secondBlade)
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
PropagationDirection
std::vector< const GeometricSearchDet * > theComps
PositionType position(double s) const override
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubTurbineCrossings &crossings, float window, std::vector< DetGroup > &result, bool innerDisk) const __attribute__((hot))
std::vector< const GeomDet * > theBasicComps
T x() const
Definition: PV3DBase.h:59
GlobalPoint globalPosition() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
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
static float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
PositionType position(double s) const override
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:18
Log< level::Info, false > LogInfo
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const PositionType & position() const
std::pair< bool, double > pathLength(const Plane &) override
GlobalVector globalMomentum() const
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
Vector2DBase< float, LocalTag > Local2DVector
virtual const BoundDisk & specificSurface() const final
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
SubTurbineCrossings computeCrossings(const TrajectoryStateOnSurface &startingState, PropagationDirection propDir, bool innerDisk) const __attribute__((hot))
DirectionType direction(double s) const override
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)
PixelForwardLayerPhase1(std::vector< const Phase1PixelBlade *> &blades)