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 using namespace std;
15 
17 
18 namespace {
19  class DetGroupElementPerpLess {
20  public:
21  bool operator()(DetGroup a, DetGroup b) const {
22  return (a.front().det()->position().perp() < b.front().det()->position().perp());
23  }
24  };
25 } // namespace
26 
27 Phase2OTBarrelRod::Phase2OTBarrelRod(vector<const GeomDet*>& innerDets,
28  vector<const GeomDet*>& outerDets,
29  const vector<const GeomDet*>& innerDetBrothers,
30  const vector<const GeomDet*>& outerDetBrothers)
31  : DetRod(true),
32  theInnerDets(innerDets),
33  theOuterDets(outerDets),
34  theInnerDetBrothers(innerDetBrothers),
35  theOuterDetBrothers(outerDetBrothers) {
36  theDets.assign(theInnerDets.begin(), theInnerDets.end());
37  theDets.insert(theDets.end(), theOuterDets.begin(), theOuterDets.end());
38  theDets.insert(theDets.end(), theInnerDetBrothers.begin(), theInnerDetBrothers.end());
39  theDets.insert(theDets.end(), theOuterDetBrothers.begin(), theOuterDetBrothers.end());
40 
41  RodPlaneBuilderFromDet planeBuilder;
42  setPlane(planeBuilder(theDets));
43  theInnerPlane = planeBuilder(theInnerDets);
44  theOuterPlane = planeBuilder(theOuterDets);
45 
46  // modules be already sorted in z
47 
50 
51 #ifdef EDM_ML_DEBUG
52  LogDebug("TkDetLayers") << "==== DEBUG Phase2OTBarrelRod =====";
53  for (vector<const GeomDet*>::const_iterator i = theInnerDets.begin(); i != theInnerDets.end(); i++) {
54  LogDebug("TkDetLayers") << "inner Phase2OTBarrelRod's Det pos z,perp,eta,phi: " << (**i).position().z() << " , "
55  << (**i).position().perp() << " , " << (**i).position().eta() << " , "
56  << (**i).position().phi();
57  }
58 
59  for (vector<const GeomDet*>::const_iterator i = theInnerDetBrothers.begin(); i != theInnerDetBrothers.end(); i++) {
60  LogDebug("TkDetLayers") << "inner Phase2OTBarrelRod's Det Brother pos z,perp,eta,phi: " << (**i).position().z()
61  << " , " << (**i).position().perp() << " , " << (**i).position().eta() << " , "
62  << (**i).position().phi();
63  }
64  if (theInnerDetBrothers.empty() && theOuterDetBrothers.empty())
65  LogDebug("TkDetLayers") << "==== with stacks =====";
66  if (!theInnerDetBrothers.empty() && !theOuterDetBrothers.empty())
67  LogDebug("TkDetLayers") << "==== without stacks =====";
68 
69  for (vector<const GeomDet*>::const_iterator i = theOuterDets.begin(); i != theOuterDets.end(); i++) {
70  LogDebug("TkDetLayers") << "outer Phase2OTBarrelRod's Det pos z,perp,eta,phi: " << (**i).position().z() << " , "
71  << (**i).position().perp() << " , " << (**i).position().eta() << " , "
72  << (**i).position().phi();
73  }
74 
75  for (vector<const GeomDet*>::const_iterator i = theOuterDetBrothers.begin(); i != theOuterDetBrothers.end(); i++) {
76  LogDebug("TkDetLayers") << "outer Phase2OTBarrelRod's Det Brother pos z,perp,eta,phi: " << (**i).position().z()
77  << " , " << (**i).position().perp() << " , " << (**i).position().eta() << " , "
78  << (**i).position().phi();
79  }
80  LogDebug("TkDetLayers") << "==== end DEBUG Phase2OTBarrelRod =====";
81 #endif
82 }
83 
85 
86 const vector<const GeometricSearchDet*>& Phase2OTBarrelRod::components() const {
87  throw DetLayerException("Phase2OTBarrelRod doesn't have GeometricSearchDet components");
88 }
89 
90 pair<bool, TrajectoryStateOnSurface> Phase2OTBarrelRod::compatible(const TrajectoryStateOnSurface& ts,
91  const Propagator&,
92  const MeasurementEstimator&) const {
93  edm::LogError("TkDetLayers") << "temporary dummy implementation of Phase2OTBarrelRod::compatible()!!";
94  return pair<bool, TrajectoryStateOnSurface>();
95 }
96 
98  const Propagator& prop,
99  const MeasurementEstimator& est,
100  std::vector<DetGroup>& result) const {
101  SubLayerCrossings crossings;
102  crossings = computeCrossings(tsos, prop.propagationDirection());
103  if (!crossings.isValid())
104  return;
105 
106  std::vector<DetGroup> closestResult;
107  std::vector<DetGroup> closestBrotherResult;
108  addClosest(tsos, prop, est, crossings.closest(), closestResult, closestBrotherResult);
109  if (closestResult.empty()) {
110  std::vector<DetGroup> nextResult;
111  std::vector<DetGroup> nextBrotherResult;
112  addClosest(tsos, prop, est, crossings.other(), nextResult, nextBrotherResult);
113  if (nextResult.empty())
114  return;
115 
116  DetGroupElement nextGel(nextResult.front().front());
117  int crossingSide = LayerCrossingSide().barrelSide(nextGel.trajectoryState(), prop);
118  std::vector<DetGroup> closestCompleteResult;
120  std::move(closestResult), std::move(closestBrotherResult), closestCompleteResult, 0, crossingSide);
121  std::vector<DetGroup> nextCompleteResult;
123  std::move(nextResult), std::move(nextBrotherResult), nextCompleteResult, 0, crossingSide);
124 
126  std::move(closestCompleteResult), std::move(nextCompleteResult), result, crossings.closestIndex(), crossingSide);
127  } else {
128  DetGroupElement closestGel(closestResult.front().front());
129  int crossingSide = LayerCrossingSide().barrelSide(closestGel.trajectoryState(), prop);
130  float window = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
131 
132  searchNeighbors(tsos, prop, est, crossings.closest(), window, closestResult, closestBrotherResult, false);
133 
134  std::vector<DetGroup> closestCompleteResult;
136  std::move(closestResult), std::move(closestBrotherResult), closestCompleteResult, 0, crossingSide);
137 
138  std::vector<DetGroup> nextResult;
139  std::vector<DetGroup> nextBrotherResult;
140  searchNeighbors(tsos, prop, est, crossings.other(), window, nextResult, nextBrotherResult, true);
141 
142  std::vector<DetGroup> nextCompleteResult;
144  std::move(nextResult), std::move(nextBrotherResult), nextCompleteResult, 0, crossingSide);
145 
147  std::move(closestCompleteResult), std::move(nextCompleteResult), result, crossings.closestIndex(), crossingSide);
148  }
149 
150  //due to propagator problems, when we add single pt sub modules, we should order them in r (barrel)
151  sort(result.begin(), result.end(), DetGroupElementPerpLess());
152  for (auto& grp : result) {
153  if (grp.empty())
154  continue;
155  LogTrace("TkDetLayers") << "New group in Phase2OTBarrelRod made by : ";
156  for (auto const& det : grp) {
157  LogTrace("TkDetLayers") << " geom det at r: " << det.det()->position().perp()
158  << " id:" << det.det()->geographicalId().rawId()
159  << " tsos at:" << det.trajectoryState().globalPosition();
160  }
161  }
162 }
163 
165  PropagationDirection propDir) const {
166  GlobalPoint startPos(startingState.globalPosition());
167  GlobalVector startDir(startingState.globalMomentum());
168  double rho(startingState.transverseCurvature());
169 
170  HelixBarrelPlaneCrossingByCircle crossing(startPos, startDir, rho, propDir);
171 
172  std::pair<bool, double> outerPath = crossing.pathLength(*theOuterPlane);
173  if (!outerPath.first)
174  return SubLayerCrossings();
175  GlobalPoint gOuterPoint(crossing.position(outerPath.second));
176 
177  std::pair<bool, double> innerPath = crossing.pathLength(*theInnerPlane);
178  if (!innerPath.first)
179  return SubLayerCrossings();
180  GlobalPoint gInnerPoint(crossing.position(innerPath.second));
181 
182  int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.z());
183  float innerDist = std::abs(theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.z());
184  SubLayerCrossing innerSLC(0, innerIndex, gInnerPoint);
185 
186  int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.z());
187  float outerDist = std::abs(theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.z());
188  SubLayerCrossing outerSLC(1, outerIndex, gOuterPoint);
189 
190  if (innerDist < outerDist) {
191  return SubLayerCrossings(innerSLC, outerSLC, 0);
192  } else {
193  return SubLayerCrossings(outerSLC, innerSLC, 1);
194  }
195 }
196 
198  const Propagator& prop,
199  const MeasurementEstimator& est,
200  const SubLayerCrossing& crossing,
201  vector<DetGroup>& result,
202  vector<DetGroup>& brotherresult) const {
203  const vector<const GeomDet*>& sRod(subRod(crossing.subLayerIndex()));
204  bool firstgroup = CompatibleDetToGroupAdder::add(*sRod[crossing.closestDetIndex()], tsos, prop, est, result);
205  if (theInnerDetBrothers.empty() && theOuterDetBrothers.empty())
206  return firstgroup;
207 
208  // it assumes that the closestDetIndex is ok also for the brother detectors: the crossing is NOT recomputed
209  const vector<const GeomDet*>& sRodBrothers(subRodBrothers(crossing.subLayerIndex()));
210  bool brothergroup =
211  CompatibleDetToGroupAdder::add(*sRodBrothers[crossing.closestDetIndex()], tsos, prop, est, brotherresult);
212 
213  return firstgroup || brothergroup;
214 }
215 
217  const TrajectoryStateOnSurface& tsos,
218  const MeasurementEstimator& est) const {
219  return est.maximalLocalDisplacement(tsos, det->surface()).y();
220 }
221 
222 namespace {
223 
224  inline bool overlap(const GlobalPoint& crossPoint, const GeomDet& det, float window) {
225  // check if the z window around TSOS overlaps with the detector theDet (with a 1% margin added)
226 
227  // const float tolerance = 0.1;
228  constexpr float relativeMargin = 1.01;
229 
230  LocalPoint localCrossPoint(det.surface().toLocal(crossPoint));
231  // if (std::abs(localCrossPoint.z()) > tolerance) {
232  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap calculation assumes point on surface, but it is off by "
233  // << localCrossPoint.z() ;
234  // }
235 
236  float localY = localCrossPoint.y();
237  float detHalfLength = 0.5f * det.surface().bounds().length();
238 
239  // edm::LogInfo(TkDetLayers) << "TOBRod::overlap: Det at " << det.position() << " hit at " << localY
240  // << " Window " << window << " halflength " << detHalfLength ;
241 
242  return (std::abs(localY) - window) < relativeMargin * detHalfLength;
243  }
244 
245 } // namespace
246 
248  const Propagator& prop,
249  const MeasurementEstimator& est,
250  const SubLayerCrossing& crossing,
251  float window,
252  vector<DetGroup>& result,
253  vector<DetGroup>& brotherresult,
254  bool checkClosest) const {
255  const GlobalPoint& gCrossingPos = crossing.position();
256 
257  const vector<const GeomDet*>& sRod(subRod(crossing.subLayerIndex()));
258  const vector<const GeomDet*>& sBrotherRod(subRodBrothers(crossing.subLayerIndex()));
259 
260  int closestIndex = crossing.closestDetIndex();
261  int negStartIndex = closestIndex - 1;
262  int posStartIndex = closestIndex + 1;
263 
264  if (checkClosest) { // must decide if the closest is on the neg or pos side
265  if (gCrossingPos.z() < sRod[closestIndex]->surface().position().z()) {
266  posStartIndex = closestIndex;
267  } else {
268  negStartIndex = closestIndex;
269  }
270  }
271 
272  typedef CompatibleDetToGroupAdder Adder;
273  for (int idet = negStartIndex; idet >= 0; idet--) {
274  if (!overlap(gCrossingPos, *sRod[idet], window))
275  break;
276  if (!Adder::add(*sRod[idet], tsos, prop, est, result))
277  break;
278  if (theInnerDetBrothers.empty() && theOuterDetBrothers.empty())
279  break;
280  // If the two above checks are passed also the brother module will be added with no further checks
281  Adder::add(*sBrotherRod[idet], tsos, prop, est, brotherresult);
282  }
283  for (int idet = posStartIndex; idet < static_cast<int>(sRod.size()); idet++) {
284  if (!overlap(gCrossingPos, *sRod[idet], window))
285  break;
286  if (!Adder::add(*sRod[idet], tsos, prop, est, result))
287  break;
288  if (theInnerDetBrothers.empty() && theOuterDetBrothers.empty())
289  break;
290  // If the two above checks are passed also the brother module will be added with no further checks
291  Adder::add(*sBrotherRod[idet], tsos, prop, est, brotherresult);
292  }
293 }
Vector3DBase
Definition: Vector3DBase.h:8
SubLayerCrossing::position
const GlobalPoint & position() const
Definition: SubLayerCrossings.h:14
MeasurementEstimator
Definition: MeasurementEstimator.h:19
SubLayerCrossings::isValid
bool isValid()
Definition: SubLayerCrossings.h:28
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:428
DetWithState
GeometricSearchDet::DetWithState DetWithState
Definition: Phase2OTBarrelRod.cc:16
MessageLogger.h
Phase2OTBarrelRod.h
GeomDet
Definition: GeomDet.h:27
LayerCrossingSide
Definition: LayerCrossingSide.h:15
LayerCrossingSide.h
phase1PixelTopology::localY
constexpr uint16_t localY(uint16_t py)
Definition: phase1PixelTopology.h:151
Phase2OTBarrelRod::~Phase2OTBarrelRod
~Phase2OTBarrelRod() override __attribute__((cold))
Definition: Phase2OTBarrelRod.cc:84
SubLayerCrossings::closestIndex
int closestIndex() const
Definition: SubLayerCrossings.h:31
Phase2OTBarrelRod::subRod
const std::vector< const GeomDet * > & subRod(int ind) const
Definition: Phase2OTBarrelRod.h:67
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
RodPlaneBuilderFromDet.h
svgfig.window
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:643
Phase2OTBarrelRod::theInnerDetBrothers
std::vector< const GeomDet * > theInnerDetBrothers
Definition: Phase2OTBarrelRod.h:77
Phase2OTBarrelRod::theOuterDets
std::vector< const GeomDet * > theOuterDets
Definition: Phase2OTBarrelRod.h:76
TrajectoryStateOnSurface::transverseCurvature
double transverseCurvature() const
Definition: TrajectoryStateOnSurface.h:70
Phase2OTBarrelRod::groupedCompatibleDetsV
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
Definition: Phase2OTBarrelRod.cc:97
GenericBinFinderInZ::binPosition
T binPosition(int ind) const override
the middle of the bin.
Definition: GenericBinFinderInZ.h:74
Bounds::length
virtual float length() const =0
Phase2OTBarrelRod::compatible
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const override __attribute__((cold))
Definition: Phase2OTBarrelRod.cc:90
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
Propagator
Definition: Propagator.h:44
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
DetLayerException.h
Phase2OTBarrelRod::searchNeighbors
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))
Definition: Phase2OTBarrelRod.cc:247
MeasurementEstimator.h
DetRod
Definition: DetRod.h:13
Surface::bounds
const Bounds & bounds() const
Definition: Surface.h:87
Propagator::propagationDirection
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
Phase2OTBarrelRod::Phase2OTBarrelRod
Phase2OTBarrelRod(std::vector< const GeomDet * > &innerDets, std::vector< const GeomDet * > &outerDets, const std::vector< const GeomDet * > &innerDetBrothers=std::vector< const GeomDet * >(), const std::vector< const GeomDet * > &outerDetBrothers=std::vector< const GeomDet * >()) __attribute__((cold))
Definition: Phase2OTBarrelRod.cc:27
DetGroupMerger.h
Phase2OTBarrelRod::components
const std::vector< const GeometricSearchDet * > & components() const override __attribute__((cold))
Returns basic components, if any.
Definition: Phase2OTBarrelRod.cc:86
Point3DBase< float, GlobalTag >
b
double b
Definition: hdecay.h:118
GenericBinFinderInZ::binIndex
int binIndex(T z) const override
returns an index in the valid range for the bin closest to Z
Definition: GenericBinFinderInZ.h:35
Phase2OTBarrelRod::subRodBrothers
const std::vector< const GeomDet * > & subRodBrothers(int ind) const
Definition: Phase2OTBarrelRod.h:69
DDAxes::rho
DetGroupMerger::orderAndMergeTwoLevels
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
Definition: DetGroupMerger.cc:6
funct::true
true
Definition: Factorize.h:173
RodPlaneBuilderFromDet
Definition: RodPlaneBuilderFromDet.h:15
CompatibleDetToGroupAdder::add
static bool add(const GeometricSearchDet &det, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) __attribute__((hot))
Definition: CompatibleDetToGroupAdder.cc:7
SubLayerCrossings::closest
const SubLayerCrossing & closest() const
Definition: SubLayerCrossings.h:29
Phase2OTBarrelRod::theOuterPlane
ReferenceCountingPointer< Plane > theOuterPlane
Definition: Phase2OTBarrelRod.h:81
Phase2OTBarrelRod::theDets
std::vector< const GeomDet * > theDets
Definition: Phase2OTBarrelRod.h:74
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
a
double a
Definition: hdecay.h:119
DetRod::setPlane
void setPlane(Plane *plane)
Set the rod's plane.
Definition: DetRod.h:28
HelixBarrelPlaneCrossingByCircle
Definition: HelixBarrelPlaneCrossingByCircle.h:13
Phase2OTBarrelRod::computeCrossings
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
Definition: Phase2OTBarrelRod.cc:164
PVValHelper::add
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
Definition: PVValidationHelpers.cc:12
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
Phase2OTBarrelRod::theInnerPlane
ReferenceCountingPointer< Plane > theInnerPlane
Definition: Phase2OTBarrelRod.h:80
SubLayerCrossing::closestDetIndex
int closestDetIndex() const
Definition: SubLayerCrossings.h:13
Phase2OTBarrelRod::theInnerBinFinder
BinFinderType theInnerBinFinder
Definition: Phase2OTBarrelRod.h:83
muon::overlap
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
Definition: MuonSelectors.cc:791
DetGroupElement
Definition: DetGroup.h:10
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
GeometricSearchDet::DetWithState
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
Definition: GeometricSearchDet.h:19
Phase2OTBarrelRod::addClosest
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))
Definition: Phase2OTBarrelRod.cc:197
CompatibleDetToGroupAdder.h
Phase2OTBarrelRod::theOuterDetBrothers
std::vector< const GeomDet * > theOuterDetBrothers
Definition: Phase2OTBarrelRod.h:78
DetLayerException
Common base class.
Definition: DetLayerException.h:15
TrajectoryStateOnSurface::globalMomentum
GlobalVector globalMomentum() const
Definition: TrajectoryStateOnSurface.h:66
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
GloballyPositioned::toLocal
LocalPoint toLocal(const GlobalPoint &gp) const
Definition: GloballyPositioned.h:98
Phase2OTBarrelRod::theInnerDets
std::vector< const GeomDet * > theInnerDets
Definition: Phase2OTBarrelRod.h:75
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
CompatibleDetToGroupAdder
Definition: CompatibleDetToGroupAdder.h:13
LayerCrossingSide::barrelSide
static int barrelSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
returns 0 if barrel layer crossed from inside, 1 if from outside
Definition: LayerCrossingSide.h:18
SubLayerCrossings::other
const SubLayerCrossing & other() const
Definition: SubLayerCrossings.h:30
SubLayerCrossing
Definition: SubLayerCrossings.h:7
SubLayerCrossing::subLayerIndex
int subLayerIndex() const
Definition: SubLayerCrossings.h:12
DetGroup
Definition: DetGroup.h:41
mps_fire.result
result
Definition: mps_fire.py:311
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
Phase2OTBarrelRod::theOuterBinFinder
BinFinderType theOuterBinFinder
Definition: Phase2OTBarrelRod.h:84
Phase2OTBarrelRod::computeWindowSize
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const __attribute__((hot))
Definition: Phase2OTBarrelRod.cc:216
MeasurementEstimator::maximalLocalDisplacement
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
SubLayerCrossings
Definition: SubLayerCrossings.h:22
Phase2OTBarrelRod::BinFinderType
GenericBinFinderInZ< float, GeomDet > BinFinderType
Definition: Phase2OTBarrelRod.h:16
HelixBarrelPlaneCrossingByCircle.h