CMS 3D CMS Logo

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