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