CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Phase2OTBarrelRod.cc
Go to the documentation of this file.
1 #include "Phase2OTBarrelRod.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 
30 Phase2OTBarrelRod::Phase2OTBarrelRod(vector<const GeomDet*>& innerDets,
31  vector<const GeomDet*>& outerDets,
32  vector<const GeomDet*>& innerDetBrothers,
33  vector<const GeomDet*>& outerDetBrothers):
34  DetRod(true),
35  theInnerDets(innerDets),theOuterDets(outerDets),theInnerDetBrothers(innerDetBrothers),theOuterDetBrothers(outerDetBrothers)
36 {
37  theDets.assign(theInnerDets.begin(),theInnerDets.end());
38  theDets.insert(theDets.end(),theOuterDets.begin(),theOuterDets.end());
39  theDets.insert(theDets.end(),theInnerDetBrothers.begin(),theInnerDetBrothers.end());
40  theDets.insert(theDets.end(),theOuterDetBrothers.begin(),theOuterDetBrothers.end());
41 
42 
43  RodPlaneBuilderFromDet planeBuilder;
44  setPlane( planeBuilder( theDets));
45  theInnerPlane = planeBuilder( theInnerDets);
46  theOuterPlane = planeBuilder( theOuterDets);
47 
48 
49  sort(theDets.begin(),theDets.end(),DetZLess()); // this can be dangerous because of the pt modules. On the other hand theDets is never used
50  // shouldn't the modules be already sorted in Z?
51  sort(theInnerDets.begin(),theInnerDets.end(),DetZLess());
52  sort(theOuterDets.begin(),theOuterDets.end(),DetZLess());
53  sort(theInnerDetBrothers.begin(),theInnerDetBrothers.end(),DetZLess());
54  sort(theOuterDetBrothers.begin(),theOuterDetBrothers.end(),DetZLess());
57 
58 
59 
60  LogDebug("TkDetLayers") << "==== DEBUG Phase2OTBarrelRod =====" ;
61  for (vector<const GeomDet*>::const_iterator i=theInnerDets.begin();
62  i != theInnerDets.end(); i++){
63  LogDebug("TkDetLayers") << "inner Phase2OTBarrelRod's Det pos z,perp,eta,phi: "
64  << (**i).position().z() << " , "
65  << (**i).position().perp() << " , "
66  << (**i).position().eta() << " , "
67  << (**i).position().phi() ;
68  }
69 
70  for (vector<const GeomDet*>::const_iterator i=theOuterDets.begin();
71  i != theOuterDets.end(); i++){
72  LogDebug("TkDetLayers") << "outer Phase2OTBarrelRod's Det pos z,perp,eta,phi: "
73  << (**i).position().z() << " , "
74  << (**i).position().perp() << " , "
75  << (**i).position().eta() << " , "
76  << (**i).position().phi() ;
77  }
78  LogDebug("TkDetLayers") << "==== end DEBUG Phase2OTBarrelRod =====" ;
79 
80 
81 
82 }
83 
85 
86 }
87 
88 
89 const vector<const GeometricSearchDet*>&
91  throw DetLayerException("Phase2OTBarrelRod doesn't have GeometricSearchDet components");
92 }
93 
94 pair<bool, TrajectoryStateOnSurface>
96  const MeasurementEstimator&) const{
97  edm::LogError("TkDetLayers") << "temporary dummy implementation of Phase2OTBarrelRod::compatible()!!" ;
98  return pair<bool,TrajectoryStateOnSurface>();
99 }
100 
101 
102 
103 
104 
105 void
107  const Propagator& prop,
108  const MeasurementEstimator& est,
109  std::vector<DetGroup> & result) const{
110 
111  SubLayerCrossings crossings;
112  crossings = computeCrossings( tsos, prop.propagationDirection());
113  if(! crossings.isValid()) return;
114 
115  std::vector<DetGroup> closestResult;
116  std::vector<DetGroup> closestBrotherResult;
117  addClosest( tsos, prop, est, crossings.closest(), closestResult, closestBrotherResult);
118  if (closestResult.empty()){
119  std::vector<DetGroup> nextResult;
120  std::vector<DetGroup> nextBrotherResult;
121  addClosest( tsos, prop, est, crossings.other(), nextResult, nextBrotherResult);
122  if(nextResult.empty()) return;
123 
124  DetGroupElement nextGel( nextResult.front().front());
125  int crossingSide = LayerCrossingSide().barrelSide( nextGel.trajectoryState(), prop);
126  std::vector<DetGroup> closestCompleteResult;
127  DetGroupMerger::orderAndMergeTwoLevels(std::move(closestResult),std::move(closestBrotherResult),closestCompleteResult,
128  0, crossingSide);
129  std::vector<DetGroup> nextCompleteResult;
130  DetGroupMerger::orderAndMergeTwoLevels(std::move(nextResult),std::move(nextBrotherResult),nextCompleteResult,
131  0, crossingSide);
132 
133  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestCompleteResult), std::move(nextCompleteResult), result,
134  crossings.closestIndex(), crossingSide);
135  } else {
136 
137  DetGroupElement closestGel( closestResult.front().front());
138  int crossingSide = LayerCrossingSide().barrelSide( closestGel.trajectoryState(), prop);
139  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
140 
141  searchNeighbors( tsos, prop, est, crossings.closest(), window,
142  closestResult, closestBrotherResult, false);
143 
144  std::vector<DetGroup> closestCompleteResult;
145  DetGroupMerger::orderAndMergeTwoLevels(std::move(closestResult),std::move(closestBrotherResult),closestCompleteResult,
146  0, crossingSide);
147 
148  std::vector<DetGroup> nextResult;
149  std::vector<DetGroup> nextBrotherResult;
150  searchNeighbors( tsos, prop, est, crossings.other(), window,
151  nextResult, nextBrotherResult, true);
152 
153  std::vector<DetGroup> nextCompleteResult;
154  DetGroupMerger::orderAndMergeTwoLevels(std::move(nextResult),std::move(nextBrotherResult),nextCompleteResult,
155  0, crossingSide);
156 
157  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestCompleteResult), std::move(nextCompleteResult), result,
158  crossings.closestIndex(), crossingSide);
159  }
160 }
161 
162 
165  PropagationDirection propDir) const
166 {
167  GlobalPoint startPos( startingState.globalPosition());
168  GlobalVector startDir( startingState.globalMomentum());
169  double rho( startingState.transverseCurvature());
170 
171  HelixBarrelPlaneCrossingByCircle crossing( startPos, startDir, rho, propDir);
172 
173 
174  std::pair<bool,double> outerPath = crossing.pathLength( *theOuterPlane);
175  if (!outerPath.first) return SubLayerCrossings();
176  GlobalPoint gOuterPoint( crossing.position(outerPath.second));
177 
178  std::pair<bool,double> innerPath = crossing.pathLength( *theInnerPlane);
179  if (!innerPath.first) return SubLayerCrossings();
180  GlobalPoint gInnerPoint( crossing.position(innerPath.second));
181 
182 
183  int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.z());
184  float innerDist = std::abs( theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.z());
185  SubLayerCrossing innerSLC( 0, innerIndex, gInnerPoint);
186 
187  int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.z());
188  float outerDist = std::abs( theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.z());
189  SubLayerCrossing outerSLC( 1, outerIndex, gOuterPoint);
190 
191  if (innerDist < outerDist) {
192  return SubLayerCrossings( innerSLC, outerSLC, 0);
193  }
194  else {
195  return SubLayerCrossings( outerSLC, innerSLC, 1);
196  }
197 }
198 
199 
200 
201 
202 bool
204  const Propagator& prop,
205  const MeasurementEstimator& est,
206  const SubLayerCrossing& crossing,
207  vector<DetGroup>& result,
208  vector<DetGroup>& brotherresult) const
209 {
210 
211  const vector<const GeomDet*>& sRod( subRod( crossing.subLayerIndex()));
212  bool firstgroup = CompatibleDetToGroupAdder::add( *sRod[crossing.closestDetIndex()],
213  tsos, prop, est, result);
214  // it assumes that the closestDetIndex is ok also for the brother detectors: the crossing is NOT recomputed
215  const vector<const GeomDet*>& sRodBrothers( subRodBrothers( crossing.subLayerIndex()));
216  bool brothergroup = CompatibleDetToGroupAdder::add( *sRodBrothers[crossing.closestDetIndex()],
217  tsos, prop, est, brotherresult);
218 
219  return firstgroup || brothergroup;
220 }
221 
222 
224  const TrajectoryStateOnSurface& tsos,
225  const MeasurementEstimator& est) const
226 {
227  return
228  est.maximalLocalDisplacement(tsos, det->surface()).y();
229 }
230 
231 
232 
233 
234 
235 namespace {
236 
237  inline
238  bool overlap( const GlobalPoint& crossPoint, const GeomDet& det, float window) {
239  // check if the z window around TSOS overlaps with the detector theDet (with a 1% margin added)
240 
241  // const float tolerance = 0.1;
242  constexpr float relativeMargin = 1.01;
243 
244  LocalPoint localCrossPoint( det.surface().toLocal(crossPoint));
245  // if (std::abs(localCrossPoint.z()) > tolerance) {
246  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap calculation assumes point on surface, but it is off by "
247  // << localCrossPoint.z() ;
248  // }
249 
250  float localY = localCrossPoint.y();
251  float detHalfLength = 0.5f*det.surface().bounds().length();
252 
253  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap: Det at " << det.position() << " hit at " << localY
254  // << " Window " << window << " halflength " << detHalfLength ;
255 
256  return (std::abs(localY)-window) < relativeMargin*detHalfLength;
257 
258  }
259 
260 }
261 
262 
264  const Propagator& prop,
265  const MeasurementEstimator& est,
266  const SubLayerCrossing& crossing,
267  float window,
268  vector<DetGroup>& result,
269  vector<DetGroup>& brotherresult,
270  bool checkClosest) const
271 {
272  GlobalPoint gCrossingPos = crossing.position();
273 
274  const vector<const GeomDet*>& sRod( subRod( crossing.subLayerIndex()));
275  const vector<const GeomDet*>& sBrotherRod( subRodBrothers( crossing.subLayerIndex()));
276 
277  int closestIndex = crossing.closestDetIndex();
278  int negStartIndex = closestIndex-1;
279  int posStartIndex = closestIndex+1;
280 
281  if (checkClosest) { // must decide if the closest is on the neg or pos side
282  if (gCrossingPos.z() < sRod[closestIndex]->surface().position().z()) {
283  posStartIndex = closestIndex;
284  }
285  else {
286  negStartIndex = closestIndex;
287  }
288  }
289 
290  typedef CompatibleDetToGroupAdder Adder;
291  for (int idet=negStartIndex; idet >= 0; idet--) {
292  if (!overlap( gCrossingPos, *sRod[idet], window)) break;
293  if (!Adder::add( *sRod[idet], tsos, prop, est, result)) break;
294  // If the two above checks are passed also the brother module will be added with no further checks
295  Adder::add( *sBrotherRod[idet], tsos, prop, est, brotherresult);
296  }
297  for (int idet=posStartIndex; idet < static_cast<int>(sRod.size()); idet++) {
298  if (!overlap( gCrossingPos, *sRod[idet], window)) break;
299  if (!Adder::add( *sRod[idet], tsos, prop, est, result)) break;
300  // If the two above checks are passed also the brother module will be added with no further checks
301  Adder::add( *sBrotherRod[idet], tsos, prop, est, brotherresult);
302  }
303 }
304 
305 
306 
307 
308 
#define LogDebug(id)
Common base class.
int i
Definition: DBlmapReader.cc:9
def window
Definition: svgfig.py:642
Phase2OTBarrelRod(std::vector< const GeomDet * > &innerDets, std::vector< const GeomDet * > &outerDets, std::vector< const GeomDet * > &innerDetBrothers, std::vector< const GeomDet * > &outerDetBrothers) __attribute__((cold))
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
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:155
int closestIndex() const
int closestDetIndex() const
BinFinderType theOuterBinFinder
Definition: DDAxes.h:10
T y() const
Definition: PV3DBase.h:63
~Phase2OTBarrelRod() __attribute__((cold))
GlobalPoint globalPosition() const
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
const Bounds & bounds() const
Definition: Surface.h:128
PropagationDirection
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
#define constexpr
virtual T binPosition(int ind) const
the middle of the bin.
std::vector< const GeomDet * > theDets
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 Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:46
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const __attribute__((hot))
BinFinderType theInnerBinFinder
LocalPoint toLocal(const GlobalPoint &gp) const
int subLayerIndex() const
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
def move
Definition: eostools.py:508
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< const GeomDet * > theOuterDetBrothers
virtual std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const __attribute__((cold))
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, float window, std::vector< DetGroup > &result, std::vector< DetGroup > &brotherresult, bool checkClosest) const __attribute__((hot))
GenericBinFinderInZ< float, GeomDet > BinFinderType
virtual const std::vector< const GeometricSearchDet * > & components() const __attribute__((cold))
Returns basic components, if any.
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))
const std::vector< const GeomDet * > & subRodBrothers(int ind) const
Definition: DetRod.h:13
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const
ReferenceCountingPointer< Plane > theOuterPlane
double b
Definition: hdecay.h:120
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const __attribute__((hot))
void setPlane(Plane *plane)
Set the rod&#39;s plane.
Definition: DetRod.h:32
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
const SubLayerCrossing & closest() const
GlobalVector globalMomentum() const
double a
Definition: hdecay.h:121
ReferenceCountingPointer< Plane > theInnerPlane
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
virtual int binIndex(T z) const
returns an index in the valid range for the bin closest to Z
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result, std::vector< DetGroup > &brotherresult) const __attribute__((hot))
const std::vector< const GeomDet * > & subRod(int ind) const
std::vector< const GeomDet * > theOuterDets
std::vector< const GeomDet * > theInnerDets
std::vector< const GeomDet * > theInnerDetBrothers