CMS 3D CMS Logo

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 DetGroupElementPerpLess {
21  public:
22  bool operator()(DetGroup a,DetGroup b) const
23  {
24  return (a.front().det()->position().perp() < b.front().det()->position().perp());
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  // modules be already sorted in z
49 
52 
53 
54 
55 #ifdef EDM_ML_DEBUG
56  LogDebug("TkDetLayers") << "==== DEBUG Phase2OTBarrelRod =====" ;
57  for (vector<const GeomDet*>::const_iterator i=theInnerDets.begin();
58  i != theInnerDets.end(); i++){
59  LogDebug("TkDetLayers") << "inner Phase2OTBarrelRod's Det pos z,perp,eta,phi: "
60  << (**i).position().z() << " , "
61  << (**i).position().perp() << " , "
62  << (**i).position().eta() << " , "
63  << (**i).position().phi() ;
64  }
65 
66  for (vector<const GeomDet*>::const_iterator i=theInnerDetBrothers.begin();
67  i != theInnerDetBrothers.end(); i++){
68  LogDebug("TkDetLayers") << "inner Phase2OTBarrelRod's Det Brother pos z,perp,eta,phi: "
69  << (**i).position().z() << " , "
70  << (**i).position().perp() << " , "
71  << (**i).position().eta() << " , "
72  << (**i).position().phi() ;
73  }
74 
75  for (vector<const GeomDet*>::const_iterator i=theOuterDets.begin();
76  i != theOuterDets.end(); i++){
77  LogDebug("TkDetLayers") << "outer Phase2OTBarrelRod's Det pos z,perp,eta,phi: "
78  << (**i).position().z() << " , "
79  << (**i).position().perp() << " , "
80  << (**i).position().eta() << " , "
81  << (**i).position().phi() ;
82  }
83 
84  for (vector<const GeomDet*>::const_iterator i=theOuterDetBrothers.begin();
85  i != theOuterDetBrothers.end(); i++){
86  LogDebug("TkDetLayers") << "outer Phase2OTBarrelRod's Det Brother pos z,perp,eta,phi: "
87  << (**i).position().z() << " , "
88  << (**i).position().perp() << " , "
89  << (**i).position().eta() << " , "
90  << (**i).position().phi() ;
91  }
92  LogDebug("TkDetLayers") << "==== end DEBUG Phase2OTBarrelRod =====" ;
93 #endif
94 
95 
96 }
97 
99 
100 }
101 
102 
103 const vector<const GeometricSearchDet*>&
105  throw DetLayerException("Phase2OTBarrelRod doesn't have GeometricSearchDet components");
106 }
107 
108 pair<bool, TrajectoryStateOnSurface>
110  const MeasurementEstimator&) const{
111  edm::LogError("TkDetLayers") << "temporary dummy implementation of Phase2OTBarrelRod::compatible()!!" ;
112  return pair<bool,TrajectoryStateOnSurface>();
113 }
114 
115 
116 
117 
118 
119 void
121  const Propagator& prop,
122  const MeasurementEstimator& est,
123  std::vector<DetGroup> & result) const{
124 
125  SubLayerCrossings crossings;
126  crossings = computeCrossings( tsos, prop.propagationDirection());
127  if(! crossings.isValid()) return;
128 
129  std::vector<DetGroup> closestResult;
130  std::vector<DetGroup> closestBrotherResult;
131  addClosest( tsos, prop, est, crossings.closest(), closestResult, closestBrotherResult);
132  if (closestResult.empty()){
133  std::vector<DetGroup> nextResult;
134  std::vector<DetGroup> nextBrotherResult;
135  addClosest( tsos, prop, est, crossings.other(), nextResult, nextBrotherResult);
136  if(nextResult.empty()) return;
137 
138  DetGroupElement nextGel( nextResult.front().front());
139  int crossingSide = LayerCrossingSide().barrelSide( nextGel.trajectoryState(), prop);
140  std::vector<DetGroup> closestCompleteResult;
141  DetGroupMerger::orderAndMergeTwoLevels(std::move(closestResult),std::move(closestBrotherResult),closestCompleteResult,
142  0, crossingSide);
143  std::vector<DetGroup> nextCompleteResult;
144  DetGroupMerger::orderAndMergeTwoLevels(std::move(nextResult),std::move(nextBrotherResult),nextCompleteResult,
145  0, crossingSide);
146 
147  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestCompleteResult), std::move(nextCompleteResult), result,
148  crossings.closestIndex(), crossingSide);
149  } else {
150 
151  DetGroupElement closestGel( closestResult.front().front());
152  int crossingSide = LayerCrossingSide().barrelSide( closestGel.trajectoryState(), prop);
153  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
154 
155  searchNeighbors( tsos, prop, est, crossings.closest(), window,
156  closestResult, closestBrotherResult, false);
157 
158  std::vector<DetGroup> closestCompleteResult;
159  DetGroupMerger::orderAndMergeTwoLevels(std::move(closestResult),std::move(closestBrotherResult),closestCompleteResult,
160  0, crossingSide);
161 
162  std::vector<DetGroup> nextResult;
163  std::vector<DetGroup> nextBrotherResult;
164  searchNeighbors( tsos, prop, est, crossings.other(), window,
165  nextResult, nextBrotherResult, true);
166 
167  std::vector<DetGroup> nextCompleteResult;
168  DetGroupMerger::orderAndMergeTwoLevels(std::move(nextResult),std::move(nextBrotherResult),nextCompleteResult,
169  0, crossingSide);
170 
171  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestCompleteResult), std::move(nextCompleteResult), result,
172  crossings.closestIndex(), crossingSide);
173  }
174 
175  //due to propagator problems, when we add single pt sub modules, we should order them in r (barrel)
176  sort(result.begin(),result.end(),DetGroupElementPerpLess());
177  for (auto& grp : result) {
178  if ( grp.empty() ) continue;
179  LogTrace("TkDetLayers") <<"New group in Phase2OTBarrelRod made by : ";
180  for (auto const & det : grp) {
181  LogTrace("TkDetLayers") <<" geom det at r: " << det.det()->position().perp() <<" id:" << det.det()->geographicalId().rawId()
182  <<" tsos at:" << det.trajectoryState().globalPosition();
183  }
184  }
185 
186 }
187 
188 
191  PropagationDirection propDir) const
192 {
193  GlobalPoint startPos( startingState.globalPosition());
194  GlobalVector startDir( startingState.globalMomentum());
195  double rho( startingState.transverseCurvature());
196 
197  HelixBarrelPlaneCrossingByCircle crossing( startPos, startDir, rho, propDir);
198 
199 
200  std::pair<bool,double> outerPath = crossing.pathLength( *theOuterPlane);
201  if (!outerPath.first) return SubLayerCrossings();
202  GlobalPoint gOuterPoint( crossing.position(outerPath.second));
203 
204  std::pair<bool,double> innerPath = crossing.pathLength( *theInnerPlane);
205  if (!innerPath.first) return SubLayerCrossings();
206  GlobalPoint gInnerPoint( crossing.position(innerPath.second));
207 
208 
209  int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.z());
210  float innerDist = std::abs( theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.z());
211  SubLayerCrossing innerSLC( 0, innerIndex, gInnerPoint);
212 
213  int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.z());
214  float outerDist = std::abs( theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.z());
215  SubLayerCrossing outerSLC( 1, outerIndex, gOuterPoint);
216 
217  if (innerDist < outerDist) {
218  return SubLayerCrossings( innerSLC, outerSLC, 0);
219  }
220  else {
221  return SubLayerCrossings( outerSLC, innerSLC, 1);
222  }
223 }
224 
225 
226 
227 
228 bool
230  const Propagator& prop,
231  const MeasurementEstimator& est,
232  const SubLayerCrossing& crossing,
233  vector<DetGroup>& result,
234  vector<DetGroup>& brotherresult) const
235 {
236 
237  const vector<const GeomDet*>& sRod( subRod( crossing.subLayerIndex()));
238  bool firstgroup = CompatibleDetToGroupAdder::add( *sRod[crossing.closestDetIndex()],
239  tsos, prop, est, result);
240  // it assumes that the closestDetIndex is ok also for the brother detectors: the crossing is NOT recomputed
241  const vector<const GeomDet*>& sRodBrothers( subRodBrothers( crossing.subLayerIndex()));
242  bool brothergroup = CompatibleDetToGroupAdder::add( *sRodBrothers[crossing.closestDetIndex()],
243  tsos, prop, est, brotherresult);
244 
245  return firstgroup || brothergroup;
246 }
247 
248 
250  const TrajectoryStateOnSurface& tsos,
251  const MeasurementEstimator& est) const
252 {
253  return
254  est.maximalLocalDisplacement(tsos, det->surface()).y();
255 }
256 
257 
258 
259 
260 
261 namespace {
262 
263  inline
264  bool overlap( const GlobalPoint& crossPoint, const GeomDet& det, float window) {
265  // check if the z window around TSOS overlaps with the detector theDet (with a 1% margin added)
266 
267  // const float tolerance = 0.1;
268  constexpr float relativeMargin = 1.01;
269 
270  LocalPoint localCrossPoint( det.surface().toLocal(crossPoint));
271  // if (std::abs(localCrossPoint.z()) > tolerance) {
272  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap calculation assumes point on surface, but it is off by "
273  // << localCrossPoint.z() ;
274  // }
275 
276  float localY = localCrossPoint.y();
277  float detHalfLength = 0.5f*det.surface().bounds().length();
278 
279  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap: Det at " << det.position() << " hit at " << localY
280  // << " Window " << window << " halflength " << detHalfLength ;
281 
282  return (std::abs(localY)-window) < relativeMargin*detHalfLength;
283 
284  }
285 
286 }
287 
288 
290  const Propagator& prop,
291  const MeasurementEstimator& est,
292  const SubLayerCrossing& crossing,
293  float window,
294  vector<DetGroup>& result,
295  vector<DetGroup>& brotherresult,
296  bool checkClosest) const
297 {
298  GlobalPoint gCrossingPos = crossing.position();
299 
300  const vector<const GeomDet*>& sRod( subRod( crossing.subLayerIndex()));
301  const vector<const GeomDet*>& sBrotherRod( subRodBrothers( crossing.subLayerIndex()));
302 
303  int closestIndex = crossing.closestDetIndex();
304  int negStartIndex = closestIndex-1;
305  int posStartIndex = closestIndex+1;
306 
307  if (checkClosest) { // must decide if the closest is on the neg or pos side
308  if (gCrossingPos.z() < sRod[closestIndex]->surface().position().z()) {
309  posStartIndex = closestIndex;
310  }
311  else {
312  negStartIndex = closestIndex;
313  }
314  }
315 
316  typedef CompatibleDetToGroupAdder Adder;
317  for (int idet=negStartIndex; idet >= 0; idet--) {
318  if (!overlap( gCrossingPos, *sRod[idet], window)) break;
319  if (!Adder::add( *sRod[idet], tsos, prop, est, result)) break;
320  // If the two above checks are passed also the brother module will be added with no further checks
321  Adder::add( *sBrotherRod[idet], tsos, prop, est, brotherresult);
322  }
323  for (int idet=posStartIndex; idet < static_cast<int>(sRod.size()); idet++) {
324  if (!overlap( gCrossingPos, *sRod[idet], window)) break;
325  if (!Adder::add( *sRod[idet], tsos, prop, est, result)) break;
326  // If the two above checks are passed also the brother module will be added with no further checks
327  Adder::add( *sBrotherRod[idet], tsos, prop, est, brotherresult);
328  }
329 }
330 
331 
332 
333 
334 
#define LogDebug(id)
Common base class.
virtual float length() const =0
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
int closestIndex() const
int closestDetIndex() const
BinFinderType theOuterBinFinder
T y() const
Definition: PV3DBase.h:63
~Phase2OTBarrelRod() __attribute__((cold))
GlobalPoint globalPosition() const
const Bounds & bounds() const
Definition: Surface.h:120
PropagationDirection
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
#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
GeometricSearchDet::DetWithState DetWithState
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:151
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
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))
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:642
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))
#define LogTrace(id)
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
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
Definition: DetRod.h:13
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
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
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
def move(src, dest)
Definition: eostools.py:510
std::vector< const GeomDet * > theOuterDets
std::vector< const GeomDet * > theInnerDets
std::vector< const GeomDet * > theInnerDetBrothers