CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TOBRod.cc
Go to the documentation of this file.
1 #include "TOBRod.h"
2 
4 
9 
10 #include "LayerCrossingSide.h"
11 #include "DetGroupMerger.h"
13 
14 
15 using namespace std;
16 
18 
19 namespace {
20  class DetZLess {
21  public:
22  bool operator()(const GeomDet* a,const GeomDet* b) const
23  {
24  return (a->position().z() < b->position().z());
25  }
26  };
27 }
28 
29 TOBRod::TOBRod(vector<const GeomDet*>& innerDets,
30  vector<const GeomDet*>& outerDets):
31  DetRod(true),
32  theInnerDets(innerDets),theOuterDets(outerDets)
33 {
34  theDets.assign(theInnerDets.begin(),theInnerDets.end());
35  theDets.insert(theDets.end(),theOuterDets.begin(),theOuterDets.end());
36 
37 
38  RodPlaneBuilderFromDet planeBuilder;
39  setPlane( planeBuilder( theDets));
40  theInnerPlane = planeBuilder( theInnerDets);
41  theOuterPlane = planeBuilder( theOuterDets);
42 
43 
44  sort(theDets.begin(),theDets.end(),DetZLess());
45  sort(theInnerDets.begin(),theInnerDets.end(),DetZLess());
46  sort(theOuterDets.begin(),theOuterDets.end(),DetZLess());
49 
50 
51 
52  LogDebug("TkDetLayers") << "==== DEBUG TOBRod =====" ;
53  for (vector<const GeomDet*>::const_iterator i=theInnerDets.begin();
54  i != theInnerDets.end(); i++){
55  LogDebug("TkDetLayers") << "inner TOBRod's Det pos z,perp,eta,phi: "
56  << (**i).position().z() << " , "
57  << (**i).position().perp() << " , "
58  << (**i).position().eta() << " , "
59  << (**i).position().phi() ;
60  }
61 
62  for (vector<const GeomDet*>::const_iterator i=theOuterDets.begin();
63  i != theOuterDets.end(); i++){
64  LogDebug("TkDetLayers") << "outer TOBRod's Det pos z,perp,eta,phi: "
65  << (**i).position().z() << " , "
66  << (**i).position().perp() << " , "
67  << (**i).position().eta() << " , "
68  << (**i).position().phi() ;
69  }
70  LogDebug("TkDetLayers") << "==== end DEBUG TOBRod =====" ;
71 
72 
73 
74 }
75 
77 
78 }
79 
80 
81 const vector<const GeometricSearchDet*>&
83  throw DetLayerException("TOBRod doesn't have GeometricSearchDet components");
84 }
85 
86 pair<bool, TrajectoryStateOnSurface>
88  const MeasurementEstimator&) const{
89  edm::LogError("TkDetLayers") << "temporary dummy implementation of TOBRod::compatible()!!" ;
90  return pair<bool,TrajectoryStateOnSurface>();
91 }
92 
93 
94 
95 
96 
97 void
99  const Propagator& prop,
100  const MeasurementEstimator& est,
101  std::vector<DetGroup> & result) const{
102 
103  SubLayerCrossings crossings;
104  crossings = computeCrossings( tsos, prop.propagationDirection());
105  if(! crossings.isValid()) return;
106 
107  std::vector<DetGroup> closestResult;
108  addClosest( tsos, prop, est, crossings.closest(), closestResult);
109  if (closestResult.empty()){
110  std::vector<DetGroup> nextResult;
111  addClosest( tsos, prop, est, crossings.other(), nextResult);
112  if(nextResult.empty()) return;
113 
114  DetGroupElement nextGel( nextResult.front().front());
115  int crossingSide = LayerCrossingSide().barrelSide( nextGel.trajectoryState(), prop);
116  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
117  crossings.closestIndex(), crossingSide);
118  } else {
119 
120  DetGroupElement closestGel( closestResult.front().front());
121  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
122 
123  searchNeighbors( tsos, prop, est, crossings.closest(), window,
124  closestResult, false);
125 
126  std::vector<DetGroup> nextResult;
127  searchNeighbors( tsos, prop, est, crossings.other(), window,
128  nextResult, true);
129 
130  int crossingSide = LayerCrossingSide().barrelSide( closestGel.trajectoryState(), prop);
131  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
132  crossings.closestIndex(), crossingSide);
133  }
134 }
135 
136 
139  PropagationDirection propDir) const
140 {
141  GlobalPoint startPos( startingState.globalPosition());
142  GlobalVector startDir( startingState.globalMomentum());
143  double rho( startingState.transverseCurvature());
144 
145  HelixBarrelPlaneCrossingByCircle crossing( startPos, startDir, rho, propDir);
146 
147 
148  std::pair<bool,double> outerPath = crossing.pathLength( *theOuterPlane);
149  if (!outerPath.first) return SubLayerCrossings();
150  GlobalPoint gOuterPoint( crossing.position(outerPath.second));
151 
152  std::pair<bool,double> innerPath = crossing.pathLength( *theInnerPlane);
153  if (!innerPath.first) return SubLayerCrossings();
154  GlobalPoint gInnerPoint( crossing.position(innerPath.second));
155 
156 
157  int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.z());
158  float innerDist = std::abs( theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.z());
159  SubLayerCrossing innerSLC( 0, innerIndex, gInnerPoint);
160 
161  int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.z());
162  float outerDist = std::abs( theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.z());
163  SubLayerCrossing outerSLC( 1, outerIndex, gOuterPoint);
164 
165  if (innerDist < outerDist) {
166  return SubLayerCrossings( innerSLC, outerSLC, 0);
167  }
168  else {
169  return SubLayerCrossings( outerSLC, innerSLC, 1);
170  }
171 }
172 
173 
174 
175 
176 bool
178  const Propagator& prop,
179  const MeasurementEstimator& est,
180  const SubLayerCrossing& crossing,
181  vector<DetGroup>& result) const
182 {
183 
184  const vector<const GeomDet*>& sRod( subRod( crossing.subLayerIndex()));
185  return CompatibleDetToGroupAdder::add( *sRod[crossing.closestDetIndex()],
186  tsos, prop, est, result);
187 }
188 
189 
191  const TrajectoryStateOnSurface& tsos,
192  const MeasurementEstimator& est) const
193 {
194  return
195  est.maximalLocalDisplacement(tsos, det->surface()).y();
196 }
197 
198 
199 
200 
201 namespace {
202 
203  inline
204  bool overlap( const GlobalPoint& crossPoint, const GeomDet& det, float window) {
205  // check if the z window around TSOS overlaps with the detector theDet (with a 1% margin added)
206 
207  // const float tolerance = 0.1;
208  constexpr float relativeMargin = 1.01;
209 
210  LocalPoint localCrossPoint( det.surface().toLocal(crossPoint));
211  // if (std::abs(localCrossPoint.z()) > tolerance) {
212  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap calculation assumes point on surface, but it is off by "
213  // << localCrossPoint.z() ;
214  // }
215 
216  float localY = localCrossPoint.y();
217  float detHalfLength = 0.5f*det.surface().bounds().length();
218 
219  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap: Det at " << det.position() << " hit at " << localY
220  // << " Window " << window << " halflength " << detHalfLength ;
221 
222  return (std::abs(localY)-window) < relativeMargin*detHalfLength;
223 
224  }
225 
226 }
227 
229  const Propagator& prop,
230  const MeasurementEstimator& est,
231  const SubLayerCrossing& crossing,
232  float window,
233  vector<DetGroup>& result,
234  bool checkClosest) const
235 {
236  GlobalPoint gCrossingPos = crossing.position();
237 
238  const vector<const GeomDet*>& sRod( subRod( crossing.subLayerIndex()));
239 
240  int closestIndex = crossing.closestDetIndex();
241  int negStartIndex = closestIndex-1;
242  int posStartIndex = closestIndex+1;
243 
244  if (checkClosest) { // must decide if the closest is on the neg or pos side
245  if (gCrossingPos.z() < sRod[closestIndex]->surface().position().z()) {
246  posStartIndex = closestIndex;
247  }
248  else {
249  negStartIndex = closestIndex;
250  }
251  }
252 
253  typedef CompatibleDetToGroupAdder Adder;
254  for (int idet=negStartIndex; idet >= 0; idet--) {
255  if (!overlap( gCrossingPos, *sRod[idet], window)) break;
256  if (!Adder::add( *sRod[idet], tsos, prop, est, result)) break;
257  }
258  for (int idet=posStartIndex; idet < static_cast<int>(sRod.size()); idet++) {
259  if (!overlap( gCrossingPos, *sRod[idet], window)) break;
260  if (!Adder::add( *sRod[idet], tsos, prop, est, result)) break;
261  }
262 }
263 
264 
265 
266 
#define LogDebug(id)
Common base class.
int i
Definition: DBlmapReader.cc:9
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const __attribute__((hot))
Definition: TOBRod.cc:190
def window
Definition: svgfig.py:642
BinFinderType theOuterBinFinder
Definition: TOBRod.h:81
static int barrelSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
returns 0 if barrel layer crossed from inside, 1 if from outside
virtual float length() const =0
std::vector< const GeomDet * > theInnerDets
Definition: TOBRod.h:74
int closestIndex() const
int closestDetIndex() const
virtual const std::vector< const GeometricSearchDet * > & components() const __attribute__((cold))
Returns basic components, if any.
Definition: TOBRod.cc:82
PeriodicBinFinderInZ< float > BinFinderType
Definition: TOBRod.h:18
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
std::vector< const GeomDet * > theDets
Definition: TOBRod.h:73
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
const Bounds & bounds() const
Definition: Surface.h:120
std::vector< const GeomDet * > theOuterDets
Definition: TOBRod.h:75
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:151
virtual T binPosition(int ind) const
the middle of the bin
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: TOBRod.cc:98
PropagationDirection
~TOBRod() __attribute__((cold))
Definition: TOBRod.cc:76
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
virtual std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const __attribute__((cold))
Definition: TOBRod.cc:87
#define constexpr
virtual int binIndex(T z) const
returns an index in the valid range for the bin that contains Z
tuple result
Definition: mps_fire.py:83
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
const std::vector< const GeomDet * > & subRod(int ind) const
Definition: TOBRod.h:67
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:46
LocalPoint toLocal(const GlobalPoint &gp) const
int subLayerIndex() const
T z() const
Definition: PV3DBase.h:64
def move
Definition: eostools.py:510
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
Definition: TOBRod.cc:138
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TOBRod(std::vector< const GeomDet * > &innerDets, std::vector< const GeomDet * > &outerDets) __attribute__((cold))
Definition: TOBRod.cc:29
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
ReferenceCountingPointer< Plane > theOuterPlane
Definition: TOBRod.h:78
BinFinderType theInnerBinFinder
Definition: TOBRod.h:80
const SubLayerCrossing & other() const
static bool add(const GeometricSearchDet &det, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) __attribute__((hot))
ReferenceCountingPointer< Plane > theInnerPlane
Definition: TOBRod.h:77
Definition: DetRod.h:13
double b
Definition: hdecay.h:120
void setPlane(Plane *plane)
Set the rod&#39;s plane.
Definition: DetRod.h:32
const SubLayerCrossing & closest() const
GlobalVector globalMomentum() const
double a
Definition: hdecay.h:121
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)
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, float window, std::vector< DetGroup > &result, bool checkClosest) const __attribute__((hot))
Definition: TOBRod.cc:228
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: TOBRod.cc:177