CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelForwardLayerPhase1.cc
Go to the documentation of this file.
2 
4 
7 
13 
14 
15 #include "LayerCrossingSide.h"
16 #include "DetGroupMerger.h"
18 
19 #include <algorithm>
20 
21 using namespace std;
22 
24 
25 PixelForwardLayerPhase1::PixelForwardLayerPhase1(vector<const PixelBlade*>& blades):
27  theComps(blades.begin(),blades.end())
28 {
29  for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
30  it!=theComps.end();it++){
31  theBasicComps.insert(theBasicComps.end(),
32  (**it).basicComponents().begin(),
33  (**it).basicComponents().end());
34  }
35 
36  //They should be already phi-ordered. TO BE CHECKED!!
37  //sort( theBlades.begin(), theBlades.end(), PhiLess());
39 
40 
41  // Assumes blades are ordered inner first then outer; and within each by phi
42  // where we go 0 -> pi, and then -pi -> 0
43  // we also need the number of inner blades for the offset in theComps vector
44  //
45  // this->specificSurface() not yet available so need to calculate average R
46  // we need some way to flag if FPIX is made of an inner and outer disk
47  // or probably need to change the way this is done, e.g. a smarter binFinder
48  float theRmin = (*(theComps.begin()))->surface().position().perp();
49  float theRmax = theRmin;
50  for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
51  it!=theComps.end(); it++){
52  theRmin = std::min( theRmin, (*it)->surface().position().perp());
53  theRmax = std::max( theRmax, (*it)->surface().position().perp());
54  }
55  float split_inner_outer_radius = 0.5 * (theRmin + theRmax);
56  _num_innerpanels = 0;
57  for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
58  it!=theComps.end();it++){
59  if((**it).surface().position().perp() <= split_inner_outer_radius) ++_num_innerpanels;
60  }
62  //std::cout << " Rmin, Rmax, R_average = " << theRmin << ", " << theRmax << ", "
63  // << split_inner_outer_radius << std::endl;
64  //std::cout << " num inner, outer disks = " << _num_innerpanels << ", " << _num_outerpanels << std::endl;
65 
66  theBinFinder_inner = BinFinderType( theComps.front()->surface().position().phi(),
70 
71 }
72 
74  vector<const GeometricSearchDet*>::const_iterator i;
75  for (i=theComps.begin(); i!=theComps.end(); i++) {
76  delete *i;
77  }
78 }
79 
80 void
82  const Propagator& prop,
83  const MeasurementEstimator& est,
84  std::vector<DetGroup> & result) const {
85  vector<DetGroup> closestResult_inner;
86  vector<DetGroup> closestResult_outer;
87  vector<DetGroup> nextResult_inner;
88  vector<DetGroup> nextResult_outer;
89  vector<DetGroup> result_inner;
90  vector<DetGroup> result_outer;
91  int frontindex_inner = 0;
92  int frontindex_outer = 0;
93  SubTurbineCrossings crossings_inner;
94  SubTurbineCrossings crossings_outer;
95 
96  crossings_inner = computeCrossings( tsos, prop.propagationDirection(), true);
97  crossings_outer = computeCrossings( tsos, prop.propagationDirection(), false);
98  if (!crossings_inner.isValid){
99  //edm::LogInfo("TkDetLayers") << "inner computeCrossings returns invalid in PixelForwardLayerPhase1::groupedCompatibleDets:";
100  return;
101  }
102  if (!crossings_outer.isValid){
103  //edm::LogInfo("TkDetLayers") << "outer computeCrossings returns invalid in PixelForwardLayerPhase1::groupedCompatibleDets:";
104  return;
105  }
106 
107  typedef CompatibleDetToGroupAdder Adder;
109  tsos, prop, est, closestResult_inner);
110 
111  if(closestResult_inner.empty()){
113  tsos, prop, est, result_inner);
114  frontindex_inner = crossings_inner.nextIndex;
115  } else {
116  if (Adder::add( *theComps[theBinFinder_inner.binIndex(crossings_inner.nextIndex)],
117  tsos, prop, est, nextResult_inner)) {
118  int crossingSide = LayerCrossingSide().endcapSide( tsos, prop);
119  int theHelicity = computeHelicity(theComps[theBinFinder_inner.binIndex(crossings_inner.closestIndex)],
120  theComps[theBinFinder_inner.binIndex(crossings_inner.nextIndex)] );
121  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult_inner), std::move(nextResult_inner), result_inner,
122  theHelicity, crossingSide);
123  if (theHelicity == crossingSide) frontindex_inner = crossings_inner.closestIndex;
124  else frontindex_inner = crossings_inner.nextIndex;
125  } else {
126  result_inner.swap(closestResult_inner);
127  frontindex_inner = crossings_inner.closestIndex;
128  }
129  }
130  if(!closestResult_inner.empty()){
131  DetGroupElement closestGel( closestResult_inner.front().front());
132  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
133  searchNeighbors( tsos, prop, est, crossings_inner, window, result_inner, true);
134  }
135 
136  //DetGroupElement closestGel( closestResult.front().front());
137  //float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
138  //float detWidth = closestGel.det()->surface().bounds().width();
139  //if (crossings.nextDistance < detWidth + window) {
140 
141  Adder::add( *theComps[(theBinFinder_outer.binIndex(crossings_outer.closestIndex)) + _num_innerpanels],
142  tsos, prop, est, closestResult_outer);
143 
144  if(closestResult_outer.empty()){
145  Adder::add( *theComps[theBinFinder_outer.binIndex(crossings_outer.nextIndex) + _num_innerpanels],
146  tsos, prop, est, result_outer);
147  frontindex_outer = crossings_outer.nextIndex;
148  } else {
149  if (Adder::add( *theComps[theBinFinder_outer.binIndex(crossings_outer.nextIndex) + _num_innerpanels],
150  tsos, prop, est, nextResult_outer)) {
151  int crossingSide = LayerCrossingSide().endcapSide( tsos, prop);
152  int theHelicity = computeHelicity(theComps[theBinFinder_outer.binIndex(crossings_outer.closestIndex) + _num_innerpanels],
153  theComps[theBinFinder_outer.binIndex(crossings_outer.nextIndex) + _num_innerpanels] );
154  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult_outer), std::move(nextResult_outer), result_outer,
155  theHelicity, crossingSide);
156  if (theHelicity == crossingSide) frontindex_outer = crossings_outer.closestIndex;
157  else frontindex_outer = crossings_outer.nextIndex;
158  } else {
159  result_outer.swap(closestResult_outer);
160  frontindex_outer = crossings_outer.closestIndex;
161  }
162  }
163  if(!closestResult_outer.empty()){
164  DetGroupElement closestGel( closestResult_outer.front().front());
165  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
166  searchNeighbors( tsos, prop, est, crossings_inner, window, result_outer, false);
167  }
168 
169  if(result_inner.empty() && result_outer.empty() ) return;
170  if(result_inner.empty()) result.swap(result_outer);
171  else if(result_outer.empty()) result.swap(result_inner);
172  else {
173  int crossingSide = LayerCrossingSide().endcapSide( tsos, prop);
174  int theHelicity = computeHelicity(theComps[theBinFinder_inner.binIndex(frontindex_inner)],
175  theComps[theBinFinder_outer.binIndex(frontindex_outer) + _num_innerpanels] );
176  DetGroupMerger::orderAndMergeTwoLevels( std::move(result_inner), std::move(result_outer), result,
177  theHelicity, crossingSide);
178  }
179 }
180 
181 
182 
183 void
185  const Propagator& prop,
186  const MeasurementEstimator& est,
187  const SubTurbineCrossings& crossings,
188  float window,
189  vector<DetGroup>& result,
190  bool innerDisk) const
191 {
192  typedef CompatibleDetToGroupAdder Adder;
193  int crossingSide = LayerCrossingSide().endcapSide( tsos, prop);
194  typedef DetGroupMerger Merger;
195 
196  int negStart = min( crossings.closestIndex, crossings.nextIndex) - 1;
197  int posStart = max( crossings.closestIndex, crossings.nextIndex) + 1;
198 
199  int quarter = theComps.size()/4;
200  if(innerDisk) quarter = _num_innerpanels/4;
201  else quarter = _num_outerpanels/4;
202 
203  vector<DetGroup> tmp;
204  vector<DetGroup> newResult;
205  for (int idet=negStart; idet >= negStart - quarter+1; idet--) {
206  tmp.clear();
207  newResult.clear();
208  if(innerDisk) {
209  const GeometricSearchDet* neighbor = theComps[theBinFinder_inner.binIndex(idet)];
210  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
211  // maybe also add shallow crossing angle test here???
212  if (!Adder::add( *neighbor, tsos, prop, est, tmp)) break;
213  int theHelicity = computeHelicity(theComps[theBinFinder_inner.binIndex(idet)],
215  Merger::orderAndMergeTwoLevels( std::move(tmp), std::move(result), newResult, theHelicity, crossingSide);
216  } else {
218  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
219  // maybe also add shallow crossing angle test here???
220  if (!Adder::add( *neighbor, tsos, prop, est, tmp)) break;
223  Merger::orderAndMergeTwoLevels( std::move(tmp), std::move(result), newResult, theHelicity, crossingSide);
224  }
225  result.swap(newResult);
226  }
227  for (int idet=posStart; idet < posStart + quarter-1; idet++) {
228  tmp.clear();
229  newResult.clear();
230  if(innerDisk) {
231  const GeometricSearchDet* neighbor = theComps[theBinFinder_inner.binIndex(idet)];
232  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
233  // maybe also add shallow crossing angle test here???
234  if (!Adder::add( *neighbor, tsos, prop, est, tmp)) break;
235  int theHelicity = computeHelicity(theComps[theBinFinder_inner.binIndex(idet-1)],
237  Merger::orderAndMergeTwoLevels( std::move(result), std::move(tmp), newResult, theHelicity, crossingSide);
238  } else {
240  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
241  // maybe also add shallow crossing angle test here???
242  if (!Adder::add( *neighbor, tsos, prop, est, tmp)) break;
245  Merger::orderAndMergeTwoLevels( std::move(result), std::move(tmp), newResult, theHelicity, crossingSide);
246  }
247  result.swap(newResult);
248  }
249 }
250 
251 int
253 {
254  if( std::abs(firstBlade->position().z()) < std::abs(secondBlade->position().z()) ) return 0;
255  return 1;
256 }
257 
260  PropagationDirection propDir, bool innerDisk) const
261 {
263 
264  HelixPlaneCrossing::PositionType startPos( startingState.globalPosition());
265  HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum());
266  float rho( startingState.transverseCurvature());
267 
268  HelixArbitraryPlaneCrossing turbineCrossing( startPos, startDir, rho,
269  propDir);
270 
271  pair<bool,double> thePath = turbineCrossing.pathLength( specificSurface() );
272 
273  if (!thePath.first) {
274  //edm::LogInfo("TkDetLayers") << "ERROR in PixelForwardLayerPhase1: disk not crossed by track" ;
275  return SubTurbineCrossings();
276  }
277 
278  HelixPlaneCrossing::PositionType turbinePoint( turbineCrossing.position(thePath.second));
279  HelixPlaneCrossing::DirectionType turbineDir( turbineCrossing.direction(thePath.second));
280  int closestIndex = 0;
281  if(innerDisk)
282  closestIndex = theBinFinder_inner.binIndex(turbinePoint.phi());
283  else
284  closestIndex = theBinFinder_outer.binIndex(turbinePoint.phi());
285 
286  HelixArbitraryPlaneCrossing2Order theBladeCrossing(turbinePoint, turbineDir, rho);
287 
288  float closestDist = 0;
289  int nextIndex = 0;
290  if(innerDisk) {
291  const Plane& closestPlane( static_cast<const Plane&>(
292  theComps[closestIndex]->surface()));
293 
294  pair<bool,double> theClosestBladePath = theBladeCrossing.pathLength( closestPlane );
295  LocalPoint closestPos = closestPlane.toLocal(GlobalPoint(theBladeCrossing.position(theClosestBladePath.second)) );
296 
297  closestDist = closestPos.x(); // use fact that local X perp to global Y
298 
299  nextIndex = PhiLess()( closestPlane.position().phi(), turbinePoint.phi()) ?
300  closestIndex+1 : closestIndex-1;
301  } else {
302  const Plane& closestPlane( static_cast<const Plane&>(
303  theComps[closestIndex + _num_innerpanels]->surface()));
304 
305  pair<bool,double> theClosestBladePath = theBladeCrossing.pathLength( closestPlane );
306  LocalPoint closestPos = closestPlane.toLocal(GlobalPoint(theBladeCrossing.position(theClosestBladePath.second)) );
307 
308  closestDist = closestPos.x(); // use fact that local X perp to global Y
309 
310  nextIndex = PhiLess()( closestPlane.position().phi(), turbinePoint.phi()) ?
311  closestIndex+1 : closestIndex-1;
312  }
313 
314  float nextDist = 0;
315  if(innerDisk) {
316  const Plane& nextPlane( static_cast<const Plane&>(
317  theComps[ theBinFinder_inner.binIndex(nextIndex)]->surface()));
318  pair<bool,double> theNextBladePath = theBladeCrossing.pathLength( nextPlane );
319  LocalPoint nextPos = nextPlane.toLocal(GlobalPoint(theBladeCrossing.position(theNextBladePath.second)) );
320  nextDist = nextPos.x();
321  } else {
322  const Plane& nextPlane( static_cast<const Plane&>(
323  theComps[ theBinFinder_outer.binIndex(nextIndex) + _num_innerpanels]->surface()));
324  pair<bool,double> theNextBladePath = theBladeCrossing.pathLength( nextPlane );
325  LocalPoint nextPos = nextPlane.toLocal(GlobalPoint(theBladeCrossing.position(theNextBladePath.second)) );
326  nextDist = nextPos.x();
327  }
328 
329  if (std::abs(closestDist) < std::abs(nextDist)) {
330  return SubTurbineCrossings( closestIndex, nextIndex, nextDist);
331  }
332  else {
333  return SubTurbineCrossings( nextIndex, closestIndex, closestDist);
334  }
335 }
336 
337 
338 
339 float
341  const TrajectoryStateOnSurface& tsos,
342  const MeasurementEstimator& est) const
343 {
344  return est.maximalLocalDisplacement(tsos, det->surface()).x();
345 }
346 
int i
Definition: DBlmapReader.cc:9
def window
Definition: svgfig.py:642
virtual BoundDisk * computeSurface()
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:155
virtual const BoundSurface & surface() const
The surface of the GeometricSearchDet.
void setSurface(BoundDisk *cp)
Definition: DDAxes.h:10
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
virtual std::pair< bool, double > pathLength(const Plane &)
GlobalPoint globalPosition() const
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
Vector2DBase< float, LocalTag > Local2DVector
PropagationDirection
std::vector< const GeometricSearchDet * > theComps
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
Definition: Plane.h:17
virtual int binIndex(T phi) const
returns an index in the valid range for the bin that contains phi
std::vector< const GeomDet * > theBasicComps
int computeHelicity(const GeometricSearchDet *firstBlade, const GeometricSearchDet *secondBlade) const
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const
LocalPoint toLocal(const GlobalPoint &gp) const
T phi() const
Definition: Phi.h:41
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
virtual const BoundDisk & specificSurface() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
#define end
Definition: vmac.h:37
Definition: Merger.h:31
T min(T a, T b)
Definition: MathUtil.h:58
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
PixelForwardLayerPhase1(std::vector< const PixelBlade * > &blades)
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const
virtual PositionType position(double s) const
virtual const Surface::PositionType & position() const
Returns position of the surface.
PeriodicBinFinderInPhi< double > BinFinderType
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
#define begin
Definition: vmac.h:30
GlobalVector globalMomentum() const
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)
Definition: DDAxes.h:10
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubTurbineCrossings &crossings, float window, std::vector< DetGroup > &result, bool innerDisk) const
T x() const
Definition: PV3DBase.h:62
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const __attribute__((hot))
const PositionType & position() const
Definition: DDAxes.h:10
SubTurbineCrossings computeCrossings(const TrajectoryStateOnSurface &startingState, PropagationDirection propDir, bool innerDisk) const