CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelForwardLayer.cc
Go to the documentation of this file.
1 #include "PixelForwardLayer.h"
2 
4 
7 
13 
14 
15 #include "LayerCrossingSide.h"
16 #include "DetGroupMerger.h"
18 
19 using namespace std;
20 
22 
23 PixelForwardLayer::PixelForwardLayer(vector<const PixelBlade*>& blades):
24  theComps(blades.begin(),blades.end())
25 {
26  for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
27  it!=theComps.end();it++){
28  theBasicComps.insert(theBasicComps.end(),
29  (**it).basicComponents().begin(),
30  (**it).basicComponents().end());
31  }
32 
33  //They should be already phi-ordered. TO BE CHECKED!!
34  //sort( theBlades.begin(), theBlades.end(), PhiLess());
35  setSurface( computeSurface() );
36 
37  //Is a "periodic" binFinderInPhi enough?. TO BE CHECKED!!
38  theBinFinder = BinFinderType( theComps.front()->surface().position().phi(),
39  theComps.size());
40 
41  //--------- DEBUG INFO --------------
42  LogDebug("TkDetLayers") << "DEBUG INFO for PixelForwardLayer" << "\n"
43  << "PixelForwardLayer.surfcace.phi(): "
44  << this->surface().position().phi() << "\n"
45  << "PixelForwardLayer.surfcace.z(): "
46  << this->surface().position().z() << "\n"
47  << "PixelForwardLayer.surfcace.innerR(): "
48  << this->specificSurface().innerRadius() << "\n"
49  << "PixelForwardLayer.surfcace.outerR(): "
50  << this->specificSurface().outerRadius() ;
51 
52  for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
53  it!=theComps.end(); it++){
54  LogDebug("TkDetLayers") << "blades phi,z,r: "
55  << (*it)->surface().position().phi() << " , "
56  << (*it)->surface().position().z() << " , "
57  << (*it)->surface().position().perp();
58  }
59  //-----------------------------------
60 
61 
62 }
63 
64 PixelForwardLayer::~PixelForwardLayer(){
65  vector<const GeometricSearchDet*>::const_iterator i;
66  for (i=theComps.begin(); i!=theComps.end(); i++) {
67  delete *i;
68  }
69 }
70 
71 void
72 PixelForwardLayer::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
73  const Propagator& prop,
74  const MeasurementEstimator& est,
75  std::vector<DetGroup> & result) const {
76  vector<DetGroup> closestResult;
77  SubTurbineCrossings crossings;
78 
79  crossings = computeCrossings( tsos, prop.propagationDirection());
80  if (!crossings.isValid){
81  //edm::LogInfo("TkDetLayers") << "computeCrossings returns invalid in PixelForwardLayer::groupedCompatibleDets:";
82  return;
83  }
84 
85  typedef CompatibleDetToGroupAdder Adder;
86  Adder::add( *theComps[theBinFinder.binIndex(crossings.closestIndex)],
87  tsos, prop, est, closestResult);
88 
89  if(closestResult.empty()){
90  Adder::add( *theComps[theBinFinder.binIndex(crossings.nextIndex)],
91  tsos, prop, est, result);
92  return;
93  }
94 
95  DetGroupElement closestGel( closestResult.front().front());
96  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
97 
98  //float detWidth = closestGel.det()->surface().bounds().width();
99  //if (crossings.nextDistance < detWidth + window) {
100  vector<DetGroup> nextResult;
101  if (Adder::add( *theComps[theBinFinder.binIndex(crossings.nextIndex)],
102  tsos, prop, est, nextResult)) {
103  int crossingSide = LayerCrossingSide().endcapSide( tsos, prop);
104  int theHelicity = computeHelicity(theComps[theBinFinder.binIndex(crossings.closestIndex)],
105  theComps[theBinFinder.binIndex(crossings.nextIndex)] );
106  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
107  theHelicity, crossingSide);
108  }
109  else {
110  result.swap(closestResult);
111  }
112 
113  /*
114  }
115  else {
116  result.swap(closestResult);
117  }
118  */
119 
120  // --- THIS lines may speed up the reconstruction. But it reduces slightly the efficiency.
121  // only loop over neighbors (other than closest and next) if window is BIG
122  //if (window > 0.5*detWidth) {
123  searchNeighbors( tsos, prop, est, crossings, window, result);
124  //}
125 }
126 
127 
128 
129 void
130 PixelForwardLayer::searchNeighbors( const TrajectoryStateOnSurface& tsos,
131  const Propagator& prop,
132  const MeasurementEstimator& est,
133  const SubTurbineCrossings& crossings,
134  float window,
135  vector<DetGroup>& result) const
136 {
137  typedef CompatibleDetToGroupAdder Adder;
138  int crossingSide = LayerCrossingSide().endcapSide( tsos, prop);
139  typedef DetGroupMerger Merger;
140 
141  int negStart = min( crossings.closestIndex, crossings.nextIndex) - 1;
142  int posStart = max( crossings.closestIndex, crossings.nextIndex) + 1;
143 
144  int quarter = theComps.size()/4;
145 
146  for (int idet=negStart; idet >= negStart - quarter+1; idet--) {
147  vector<DetGroup> tmp1;
148  const GeometricSearchDet* neighbor = theComps[theBinFinder.binIndex(idet)];
149  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
150  // maybe also add shallow crossing angle test here???
151  if (!Adder::add( *neighbor, tsos, prop, est, tmp1)) break;
152  int theHelicity = computeHelicity(theComps[theBinFinder.binIndex(idet)],
153  theComps[theBinFinder.binIndex(idet+1)] );
154  vector<DetGroup> tmp2; tmp2.swap(result);
155  vector<DetGroup> newResult;
156  Merger::orderAndMergeTwoLevels( std::move(tmp1), std::move(tmp2), newResult, theHelicity, crossingSide);
157  result.swap(newResult);
158  }
159  for (int idet=posStart; idet < posStart + quarter-1; idet++) {
160  vector<DetGroup> tmp1;
161  const GeometricSearchDet* neighbor = theComps[theBinFinder.binIndex(idet)];
162  // if (!overlap( gCrossingPos, *neighbor, window)) break; // mybe not needed?
163  // maybe also add shallow crossing angle test here???
164  if (!Adder::add( *neighbor, tsos, prop, est, tmp1)) break;
165  int theHelicity = computeHelicity(theComps[theBinFinder.binIndex(idet-1)],
166  theComps[theBinFinder.binIndex(idet)] );
167  vector<DetGroup> tmp2; tmp2.swap(result);
168  vector<DetGroup> newResult;
169  Merger::orderAndMergeTwoLevels(std::move(tmp2), std::move(tmp1), newResult, theHelicity, crossingSide);
170  result.swap(newResult);
171  }
172 }
173 
174 int
175 PixelForwardLayer::computeHelicity(const GeometricSearchDet* firstBlade,const GeometricSearchDet* secondBlade) const
176 {
177  if( fabs(firstBlade->position().z()) < fabs(secondBlade->position().z()) ) return 0;
178  return 1;
179 }
180 
181 PixelForwardLayer::SubTurbineCrossings
182 PixelForwardLayer::computeCrossings( const TrajectoryStateOnSurface& startingState,
183  PropagationDirection propDir) const
184 {
186 
187  HelixPlaneCrossing::PositionType startPos( startingState.globalPosition());
188  HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum());
189  float rho( startingState.transverseCurvature());
190 
191  HelixArbitraryPlaneCrossing turbineCrossing( startPos, startDir, rho,
192  propDir);
193 
194  pair<bool,double> thePath = turbineCrossing.pathLength( specificSurface() );
195 
196  if (!thePath.first) {
197  //edm::LogInfo("TkDetLayers") << "ERROR in PixelForwardLayer: disk not crossed by track" ;
198  return SubTurbineCrossings();
199  }
200 
201  HelixPlaneCrossing::PositionType turbinePoint( turbineCrossing.position(thePath.second));
202  HelixPlaneCrossing::DirectionType turbineDir( turbineCrossing.direction(thePath.second));
203  int closestIndex = theBinFinder.binIndex(turbinePoint.phi());
204 
205  const Plane& closestPlane( static_cast<const Plane&>(
206  theComps[closestIndex]->surface()));
207 
208 
209  HelixArbitraryPlaneCrossing2Order theBladeCrossing(turbinePoint, turbineDir, rho);
210 
211  pair<bool,double> theClosestBladePath = theBladeCrossing.pathLength( closestPlane );
212  LocalPoint closestPos = closestPlane.toLocal(GlobalPoint(theBladeCrossing.position(theClosestBladePath.second)) );
213 
214  float closestDist = closestPos.x(); // use fact that local X perp to global Y
215 
216  //int next = turbinePoint.phi() - closestPlane.position().phi() > 0 ? closest+1 : closest-1;
217  int nextIndex = PhiLess()( closestPlane.position().phi(), turbinePoint.phi()) ?
218  closestIndex+1 : closestIndex-1;
219 
220  const Plane& nextPlane( static_cast<const Plane&>(
221  theComps[ theBinFinder.binIndex(nextIndex)]->surface()));
222 
223  pair<bool,double> theNextBladePath = theBladeCrossing.pathLength( nextPlane );
224  LocalPoint nextPos = nextPlane.toLocal(GlobalPoint(theBladeCrossing.position(theNextBladePath.second)) );
225 
226  float nextDist = nextPos.x();
227 
228  if (fabs(closestDist) < fabs(nextDist)) {
229  return SubTurbineCrossings( closestIndex, nextIndex, nextDist);
230  }
231  else {
232  return SubTurbineCrossings( nextIndex, closestIndex, closestDist);
233  }
234 }
235 
236 float
238  const TrajectoryStateOnSurface& tsos,
239  const MeasurementEstimator& est) const
240 {
241  return est.maximalLocalDisplacement(tsos, det->surface()).x();
242 }
243 
244 
#define LogDebug(id)
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
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.
#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