CMS 3D CMS Logo

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