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