CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelBarrelLayer.cc
Go to the documentation of this file.
1 #include "PixelBarrelLayer.h"
2 
4 
5 #include "LayerCrossingSide.h"
6 #include "DetGroupMerger.h"
8 
15 
16 using namespace std;
17 
19 
20 PixelBarrelLayer::PixelBarrelLayer(vector<const PixelRod*>& innerRods,
21  vector<const PixelRod*>& outerRods) :
22  theInnerComps(innerRods.begin(),innerRods.end()),
23  theOuterComps(outerRods.begin(),outerRods.end())
24 {
25  theComps.assign(theInnerComps.begin(),theInnerComps.end());
26  theComps.insert(theComps.end(),theOuterComps.begin(),theOuterComps.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  theInnerCylinder = cylinder( theInnerComps);
36  theOuterCylinder = cylinder( theOuterComps);
37 
38  theInnerBinFinder = BinFinderType(theInnerComps.front()->position().phi(),
39  theInnerComps.size());
40  theOuterBinFinder = BinFinderType(theOuterComps.front()->position().phi(),
41  theOuterComps.size());
42 
43 
45 
46 
47  //--------- DEBUG INFO --------------
48  LogDebug("TkDetLayers") << "==== DEBUG PixelBarrelLayer =====" ;
49  LogDebug("TkDetLayers") << "PixelBarrelLayer innerCyl r,lenght: "
50  << theInnerCylinder->radius() << " , "
51  << theInnerCylinder->bounds().length();
52 
53  LogDebug("TkDetLayers") << "PixelBarrelLayer outerCyl r,lenght: "
54  << theOuterCylinder->radius() << " , "
55  << theOuterCylinder->bounds().length();
56 
57 
58  for (vector<const GeometricSearchDet*>::const_iterator i=theInnerComps.begin();
59  i != theInnerComps.end(); i++){
60  LogDebug("TkDetLayers") << "inner PixelRod pos z,perp,eta,phi: "
61  << (**i).position().z() << " , "
62  << (**i).position().perp() << " , "
63  << (**i).position().eta() << " , "
64  << (**i).position().phi() ;
65  }
66 
67  for (vector<const GeometricSearchDet*>::const_iterator i=theOuterComps.begin();
68  i != theOuterComps.end(); i++){
69  LogDebug("TkDetLayers") << "outer PixelRod pos z,perp,eta,phi: "
70  << (**i).position().z() << " , "
71  << (**i).position().perp() << " , "
72  << (**i).position().eta() << " , "
73  << (**i).position().phi() ;
74  }
75  LogDebug("TkDetLayers") << "==== end DEBUG PixelBarrelLayer =====" ;
76  //-----------------------------------
77 }
78 
79 PixelBarrelLayer::~PixelBarrelLayer(){
80  vector<const GeometricSearchDet*>::const_iterator i;
81  for (i=theComps.begin(); i!=theComps.end(); i++) {
82  delete *i;
83  }
84 }
85 
86 
87 void
88 PixelBarrelLayer::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
89  const Propagator& prop,
90  const MeasurementEstimator& est,
91  std::vector<DetGroup> & result) const {
92  vector<DetGroup> closestResult;
93  SubLayerCrossings crossings;
94  crossings = computeCrossings( tsos, prop.propagationDirection());
95  if(! crossings.isValid()) return;
96 
97  addClosest( tsos, prop, est, crossings.closest(), closestResult);
98  if (closestResult.empty()) {
99  addClosest( tsos, prop, est, crossings.other(), result);
100  return;
101  }
102 
103  DetGroupElement closestGel( closestResult.front().front());
104  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
105 
106  searchNeighbors( tsos, prop, est, crossings.closest(), window,
107  closestResult, false);
108 
109  vector<DetGroup> nextResult;
110  searchNeighbors( tsos, prop, est, crossings.other(), window,
111  nextResult, true);
112 
113  int crossingSide = LayerCrossingSide().barrelSide( closestGel.trajectoryState(), prop);
114  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
115  crossings.closestIndex(), crossingSide);
116 }
117 
118 
119 // private methods for the implementation of groupedCompatibleDets()
120 
121 SubLayerCrossings PixelBarrelLayer::computeCrossings( const TrajectoryStateOnSurface& startingState,
122  PropagationDirection propDir) const
123 {
124  GlobalPoint startPos( startingState.globalPosition());
125  GlobalVector startDir( startingState.globalMomentum());
126  double rho( startingState.transverseCurvature());
127 
128  HelixBarrelCylinderCrossing innerCrossing( startPos, startDir, rho,
129  propDir,*theInnerCylinder);
130 
131  if (!innerCrossing.hasSolution()) return SubLayerCrossings();
132  //{
133  //edm::LogInfo(TkDetLayers) << "ERROR in PixelBarrelLayer: inner cylinder not crossed by track" ;
134  //throw DetLayerException("TkRodBarrelLayer: inner subRod not crossed by track");
135  //}
136 
137  GlobalPoint gInnerPoint( innerCrossing.position());
138  int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.phi());
139  float innerDist = theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.phi();
140  SubLayerCrossing innerSLC( 0, innerIndex, gInnerPoint);
141 
142  HelixBarrelCylinderCrossing outerCrossing( startPos, startDir, rho,
143  propDir,*theOuterCylinder);
144 
145  if (!outerCrossing.hasSolution()) return SubLayerCrossings();
146  //if (!outerCrossing.hasSolution()) {
147  // throw DetLayerException("PixelBarrelLayer: inner cylinder not crossed by track");
148  //}
149 
150  GlobalPoint gOuterPoint( outerCrossing.position());
151  int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.phi());
152  float outerDist = theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.phi() ;
153  SubLayerCrossing outerSLC( 1, outerIndex, gOuterPoint);
154 
155  innerDist *= PhiLess()( theInnerBinFinder.binPosition(innerIndex),gInnerPoint.phi()) ? -1. : 1.;
156  outerDist *= PhiLess()( theOuterBinFinder.binPosition(outerIndex),gOuterPoint.phi()) ? -1. : 1.;
157  if (innerDist < 0.) { innerDist += 2.*Geom::pi();}
158  if (outerDist < 0.) { outerDist += 2.*Geom::pi();}
159 
160 
161  if (innerDist < outerDist) {
162  return SubLayerCrossings( innerSLC, outerSLC, 0);
163  }
164  else {
165  return SubLayerCrossings( outerSLC, innerSLC, 1);
166  }
167 }
168 
169 bool PixelBarrelLayer::addClosest( const TrajectoryStateOnSurface& tsos,
170  const Propagator& prop,
171  const MeasurementEstimator& est,
172  const SubLayerCrossing& crossing,
173  vector<DetGroup>& result) const
174 {
175  const vector<const GeometricSearchDet*>& sub( subLayer( crossing.subLayerIndex()));
176  const GeometricSearchDet* det(sub[crossing.closestDetIndex()]);
177  return CompatibleDetToGroupAdder::add( *det, tsos, prop, est, result);
178 }
179 
181  const TrajectoryStateOnSurface& tsos,
182  const MeasurementEstimator& est) const
183 {
184  double xmax =
185  est.maximalLocalDisplacement(tsos, det->surface()).x();
186  return calculatePhiWindow( xmax, *det, tsos);
187 }
188 
189 
190 double PixelBarrelLayer::calculatePhiWindow( double Xmax, const GeomDet& det,
191  const TrajectoryStateOnSurface& state) const
192 {
193 
194  LocalPoint startPoint = state.localPosition();
195  LocalVector shift( Xmax , 0. , 0.);
196  LocalPoint shift1 = startPoint + shift;
197  LocalPoint shift2 = startPoint + (-shift);
198  //LocalPoint shift2( startPoint); //original code;
199  //shift2 -= shift;
200 
201  double phi1 = det.surface().toGlobal(shift1).phi();
202  double phi2 = det.surface().toGlobal(shift2).phi();
203  double phiStart = state.globalPosition().phi();
204  double phiWin = min(fabs(phiStart-phi1),fabs(phiStart-phi2));
205 
206  return phiWin;
207 }
208 
209 
210 void PixelBarrelLayer::searchNeighbors( const TrajectoryStateOnSurface& tsos,
211  const Propagator& prop,
212  const MeasurementEstimator& est,
213  const SubLayerCrossing& crossing,
214  float window,
215  vector<DetGroup>& result,
216  bool checkClosest) const
217 {
218  GlobalPoint gCrossingPos = crossing.position();
219 
220  const vector<const GeometricSearchDet*>& sLayer( subLayer( crossing.subLayerIndex()));
221 
222  int closestIndex = crossing.closestDetIndex();
223  int negStartIndex = closestIndex-1;
224  int posStartIndex = closestIndex+1;
225 
226  if (checkClosest) { // must decide if the closest is on the neg or pos side
227  if ( PhiLess()( gCrossingPos.phi(), sLayer[closestIndex]->position().phi())) {
228  posStartIndex = closestIndex;
229  }
230  else {
231  negStartIndex = closestIndex;
232  }
233  }
234 
235  const BinFinderType& binFinder = (crossing.subLayerIndex()==0 ? theInnerBinFinder : theOuterBinFinder);
236 
238  int quarter = sLayer.size()/4;
239  for (int idet=negStartIndex; idet >= negStartIndex - quarter; idet--) {
240  const GeometricSearchDet* neighborRod = sLayer[binFinder.binIndex(idet)];
241  if (!overlap( gCrossingPos, *neighborRod, window)) break;
242  if (!adder.add( *neighborRod, tsos, prop, est, result)) break;
243  // maybe also add shallow crossing angle test here???
244  }
245  for (int idet=posStartIndex; idet < posStartIndex + quarter; idet++) {
246  const GeometricSearchDet* neighborRod = sLayer[binFinder.binIndex(idet)];
247  if (!overlap( gCrossingPos, *neighborRod, window)) break;
248  if (!adder.add( *neighborRod, tsos, prop, est, result)) break;
249  // maybe also add shallow crossing angle test here???
250  }
251 }
252 
253 bool PixelBarrelLayer::overlap( const GlobalPoint& gpos, const GeometricSearchDet& gsdet, float phiWin) const
254 {
255  GlobalPoint crossPoint(gpos);
256 
257  // introduce offset (extrapolated point and true propagated point differ by 0.0003 - 0.00033,
258  // due to thickness of Rod of 1 cm)
259  const float phiOffset = 0.00034; //...TOBE CHECKED LATER...
260  phiWin += phiOffset;
261 
262  // detector phi range
263 
264  pair<float,float> phiRange(crossPoint.phi()-phiWin, crossPoint.phi()+phiWin);
265 
266  return rangesIntersect(phiRange, gsdet.surface().phiSpan(), PhiLess());
267 
268 }
269 
270 
271 BoundCylinder* PixelBarrelLayer::cylinder( const vector<const GeometricSearchDet*>& rods) const
272 {
273  vector<const GeomDet*> tmp;
274  for (vector<const GeometricSearchDet*>::const_iterator it=rods.begin(); it!=rods.end(); it++) {
275  tmp.insert(tmp.end(),(*it)->basicComponents().begin(),(*it)->basicComponents().end());
276  }
277  return CylinderBuilderFromDet()( tmp.begin(), tmp.end());
278 }
279 
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
int i
Definition: DBlmapReader.cc:9
def window
Definition: svgfig.py:642
virtual void initialize()
int closestIndex() const
int closestDetIndex() const
std::pair< float, float > const & phiSpan() const
Definition: Surface.h:131
Definition: DDAxes.h:10
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
GlobalPoint globalPosition() const
PropagationDirection
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
virtual PropagationDirection propagationDirection() const GCC11_FINAL
Definition: Propagator.h:145
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
const GlobalPoint & position() const
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
Definition: TkDetUtil.cc:31
bool rangesIntersect(const Range &a, const Range &b)
int subLayerIndex() const
T phi() const
Definition: Phi.h:41
tuple result
Definition: query.py:137
#define end
Definition: vmac.h:37
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
const SubLayerCrossing & other() const
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const
static bool add(const GeometricSearchDet &det, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result)
int barrelSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop) const
returns 0 if barrel layer crossed from inside, 1 if from outside
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
const SubLayerCrossing & closest() const
#define begin
Definition: vmac.h:30
GlobalVector globalMomentum() const
double pi()
Definition: Pi.h:31
static unsigned int const shift
float calculatePhiWindow(const MeasurementEstimator::Local2DVector &maxDistance, const TrajectoryStateOnSurface &ts, const Plane &plane)
Definition: TkDetUtil.cc:44
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