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