CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TECLayer.cc
Go to the documentation of this file.
1 #include "TECLayer.h"
2 
4 
6 #include "DetGroupMerger.h"
7 #include "LayerCrossingSide.h"
8 
14 #include "TkDetUtil.h"
15 
16 using namespace std;
17 
19 
20 namespace {
21 
22  template <typename T>
23  BoundDisk* computeDisk(vector<const T*>& petals) {
24  // Attention: it is assumed that the petals do belong to one layer, and are all
25  // of the same rmin/rmax extension !!
26 
27  const BoundDiskSector& diskSector = static_cast<const BoundDiskSector&>(petals.front()->surface());
28 
29  float rmin = diskSector.innerRadius();
30  float rmax = diskSector.outerRadius();
31 
32  float theZmax(petals.front()->position().z());
33  float theZmin(theZmax);
34  for (auto i = petals.begin(); i != petals.end(); i++) {
35  float zmin = (**i).position().z() - (**i).surface().bounds().thickness() / 2.;
36  float zmax = (**i).position().z() + (**i).surface().bounds().thickness() / 2.;
37  theZmax = max(theZmax, zmax);
38  theZmin = min(theZmin, zmin);
39  }
40 
41  float zPos = (theZmax + theZmin) / 2.;
42  Surface::PositionType pos(0., 0., zPos);
44 
45  return new BoundDisk(pos, rot, new SimpleDiskBounds(rmin, rmax, theZmin - zPos, theZmax - zPos));
46  }
47 
48 } // namespace
49 
50 TECLayer::TECLayer(vector<const TECPetal*>& innerPetals, vector<const TECPetal*>& outerPetals)
52  theFrontComps(innerPetals.begin(), innerPetals.end()),
53  theBackComps(outerPetals.begin(), outerPetals.end()) {
54  theComps.assign(theFrontComps.begin(), theFrontComps.end());
55  theComps.insert(theComps.end(), theBackComps.begin(), theBackComps.end());
56 
57  for (vector<const GeometricSearchDet*>::const_iterator it = theComps.begin(); it != theComps.end(); it++) {
58  theBasicComps.insert(theBasicComps.end(), (**it).basicComponents().begin(), (**it).basicComponents().end());
59  }
60 
61  //This should be no necessary. TO BE CHECKED
62  //sort(theFrontPetals.begin(), theFrontPetals.end(), PetalLessPhi());
63  //sort(theBackPetals.begin(), theBackPetals.end(), PetalLessPhi());
64 
65  // building disk for front and back petals
66  setSurface(computeDisk(theComps));
67  theFrontDisk = computeDisk(theFrontComps);
68  theBackDisk = computeDisk(theBackComps);
69 
70  // set up the bin finders
71  theFrontBinFinder = BinFinderPhi(theFrontComps.front()->position().phi(), theFrontComps.size());
72  theBackBinFinder = BinFinderPhi(theBackComps.front()->position().phi(), theBackComps.size());
73 
74  //--------- DEBUG INFO --------------
75  LogDebug("TkDetLayers") << "DEBUG INFO for TECLayer"
76  << "\n"
77  << "TECLayer z,perp, innerRadius, outerR: " << this->position().z() << " , "
78  << this->position().perp() << " , " << this->specificSurface().innerRadius() << " , "
79  << this->specificSurface().outerRadius();
80 
81  for (auto it = theFrontComps.begin(); it != theFrontComps.end(); it++) {
82  LogDebug("TkDetLayers") << "frontPetal phi,z,r: " << (*it)->surface().position().phi() << " , "
83  << (*it)->surface().position().z() << " , " << (*it)->surface().position().perp();
84  }
85 
86  for (auto it = theBackComps.begin(); it != theBackComps.end(); it++) {
87  LogDebug("TkDetLayers") << "backPetal phi,z,r: " << (*it)->surface().position().phi() << " , "
88  << (*it)->surface().position().z() << " , " << (*it)->surface().position().perp();
89  }
90  //-----------------------------------
91 }
92 
94  for (auto i = theComps.begin(); i != theComps.end(); i++) {
95  delete *i;
96  }
97 }
98 
100  const Propagator& prop,
101  const MeasurementEstimator& est,
102  std::vector<DetGroup>& result) const {
103  SubLayerCrossings crossings;
104  crossings = computeCrossings(tsos, prop.propagationDirection());
105  if (!crossings.isValid())
106  return;
107 
108  vector<DetGroup> closestResult;
109  addClosest(tsos, prop, est, crossings.closest(), closestResult);
110  LogDebug("TkDetLayers") << "in TECLayer, closestResult.size(): " << closestResult.size();
111 
112  // this differs from other groupedCompatibleDets logic, which DON'T check next in such cases!!!
113  if (closestResult.empty()) {
114  vector<DetGroup> nextResult;
115  addClosest(tsos, prop, est, crossings.other(), nextResult);
116  LogDebug("TkDetLayers") << "in TECLayer, nextResult.size(): " << nextResult.size();
117  if (nextResult.empty())
118  return;
119 
120  DetGroupElement nextGel(nextResult.front().front());
121  int crossingSide = LayerCrossingSide::endcapSide(nextGel.trajectoryState(), prop);
123  std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
124  } else {
125  DetGroupElement closestGel(closestResult.front().front());
126  float phiWindow = tkDetUtil::computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
127  searchNeighbors(tsos, prop, est, crossings.closest(), phiWindow, closestResult, false);
128  vector<DetGroup> nextResult;
129  searchNeighbors(tsos, prop, est, crossings.other(), phiWindow, nextResult, true);
130 
131  int crossingSide = LayerCrossingSide::endcapSide(closestGel.trajectoryState(), prop);
133  std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
134  }
135 }
136 
138  PropagationDirection propDir) const {
139  double rho(startingState.transverseCurvature());
140 
141  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
142  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
143  HelixForwardPlaneCrossing crossing(startPos, startDir, rho, propDir);
144 
145  pair<bool, double> frontPath = crossing.pathLength(*theFrontDisk);
146  if (!frontPath.first)
147  return SubLayerCrossings();
148 
149  GlobalPoint gFrontPoint(crossing.position(frontPath.second));
150 
151  LogDebug("TkDetLayers") << "in TECLayer,front crossing point: r,z,phi: (" << gFrontPoint.perp() << ","
152  << gFrontPoint.z() << "," << gFrontPoint.phi() << ")" << endl;
153 
154  int frontIndex = theFrontBinFinder.binIndex(gFrontPoint.barePhi());
155  SubLayerCrossing frontSLC(0, frontIndex, gFrontPoint);
156 
157  pair<bool, double> backPath = crossing.pathLength(*theBackDisk);
158  if (!backPath.first)
159  return SubLayerCrossings();
160 
161  GlobalPoint gBackPoint(crossing.position(backPath.second));
162  LogDebug("TkDetLayers") << "in TECLayer,back crossing point: r,z,phi: (" << gBackPoint.perp() << ","
163  << gFrontPoint.z() << "," << gBackPoint.phi() << ")" << endl;
164 
165  int backIndex = theBackBinFinder.binIndex(gBackPoint.barePhi());
166  SubLayerCrossing backSLC(1, backIndex, gBackPoint);
167 
168  // 0ss: frontDisk has index=0, backDisk has index=1
169  float frontDist = std::abs(Geom::deltaPhi(gFrontPoint.barePhi(), theFrontComps[frontIndex]->surface().phi()));
170  float backDist = std::abs(Geom::deltaPhi(gBackPoint.barePhi(), theBackComps[backIndex]->surface().phi()));
171 
172  if (frontDist < backDist) {
173  return SubLayerCrossings(frontSLC, backSLC, 0);
174  } else {
175  return SubLayerCrossings(backSLC, frontSLC, 1);
176  }
177 }
178 
180  const Propagator& prop,
181  const MeasurementEstimator& est,
182  const SubLayerCrossing& crossing,
183  vector<DetGroup>& result) const {
184  const auto& sub(subLayer(crossing.subLayerIndex()));
185  const auto det(sub[crossing.closestDetIndex()]);
186 
187  LogDebug("TkDetLayers") << "in TECLayer, adding petal at r,z,phi: (" << det->position().perp() << ","
188  << det->position().z() << "," << det->position().phi() << ")" << endl;
189 
190  return CompatibleDetToGroupAdder().add(*det, tsos, prop, est, result);
191 }
192 
193 namespace {
194  inline bool overlap(float phi, const TECPetal& gsdet, float phiWin) {
195  const BoundDiskSector& diskSector = gsdet.specificSurface();
196  pair<float, float> phiRange(phi - phiWin, phi + phiWin);
197  pair<float, float> petalPhiRange(diskSector.phi() - diskSector.phiHalfExtension(),
198  diskSector.phi() + diskSector.phiHalfExtension());
199 
200  return rangesIntersect(phiRange, petalPhiRange, [](auto x, auto y) { return Geom::phiLess(x, y); });
201  }
202 
203 } // namespace
204 
206  const Propagator& prop,
207  const MeasurementEstimator& est,
208  const SubLayerCrossing& crossing,
209  float window,
210  vector<DetGroup>& result,
211  bool checkClosest) const {
212  const GlobalPoint& gCrossingPos = crossing.position();
213  auto gphi = gCrossingPos.barePhi();
214 
215  const auto& sLayer(subLayer(crossing.subLayerIndex()));
216 
217  int closestIndex = crossing.closestDetIndex();
218  int negStartIndex = closestIndex - 1;
219  int posStartIndex = closestIndex + 1;
220 
221  if (checkClosest) { // must decide if the closest is on the neg or pos side
222  if (Geom::phiLess(gphi, sLayer[closestIndex]->surface().phi())) {
223  posStartIndex = closestIndex;
224  } else {
225  negStartIndex = closestIndex;
226  }
227  }
228 
229  const BinFinderPhi& binFinder = (crossing.subLayerIndex() == 0 ? theFrontBinFinder : theBackBinFinder);
230 
231  typedef CompatibleDetToGroupAdder Adder;
232  int half = sLayer.size() / 2; // to check if dets are called twice....
233  for (int idet = negStartIndex; idet >= negStartIndex - half; idet--) {
234  const auto& neighborPetal = *sLayer[binFinder.binIndex(idet)];
235  if (!overlap(gphi, neighborPetal, window))
236  break;
237  if (!Adder::add(neighborPetal, tsos, prop, est, result))
238  break;
239  // maybe also add shallow crossing angle test here???
240  }
241  for (int idet = posStartIndex; idet < posStartIndex + half; idet++) {
242  const auto& neighborPetal = *sLayer[binFinder.binIndex(idet)];
243  if (!overlap(gphi, neighborPetal, window))
244  break;
245  if (!Adder::add(neighborPetal, tsos, prop, est, result))
246  break;
247  // maybe also add shallow crossing angle test here???
248  }
249 }
std::vector< const TECPetal * > theBackComps
Definition: TECLayer.h:60
def window
Definition: svgfig.py:643
float innerRadius() const
T perp() const
Definition: PV3DBase.h:69
std::vector< const GeomDet * > theBasicComps
Definition: TECLayer.h:57
int binIndex(T phi) const override
returns an index in the valid range for the bin that contains phi
const BoundSurface & surface() const final
The surface of the GeometricSearchDet.
int closestIndex() const
int closestDetIndex() const
void setSurface(BoundDisk *cp)
GlobalPoint globalPosition() const
float phiHalfExtension() const
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
ReferenceCountingPointer< BoundDisk > theFrontDisk
Definition: TECLayer.h:62
PropagationDirection
virtual const BoundDiskSector & specificSurface() const final
const std::vector< const TECPetal * > & subLayer(int ind) const
Definition: TECLayer.h:53
tuple result
Definition: mps_fire.py:311
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
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
Definition: TkDetUtil.cc:10
T barePhi() const
Definition: PV3DBase.h:65
std::vector< const GeometricSearchDet * > theComps
Definition: TECLayer.h:56
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: TECLayer.cc:205
ReferenceCountingPointer< BoundDisk > theBackDisk
Definition: TECLayer.h:63
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: TECLayer.cc:179
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &startingState, PropagationDirection propDir) const __attribute__((hot))
Definition: TECLayer.cc:137
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
float outerRadius() const
int subLayerIndex() const
T z() const
Definition: PV3DBase.h:61
def move
Definition: eostools.py:511
BinFinderPhi theBackBinFinder
Definition: TECLayer.h:68
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
TECLayer(std::vector< const TECPetal * > &innerPetals, std::vector< const TECPetal * > &outerPetals) __attribute__((cold))
Definition: TECLayer.cc:50
T min(T a, T b)
Definition: MathUtil.h:58
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
Definition: TECLayer.cc:99
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:18
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))
bool rangesIntersect(const Range &a, const Range &b)
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
virtual const Surface::PositionType & position() const
Returns position of the surface.
BinFinderPhi theFrontBinFinder
Definition: TECLayer.h:67
Disk BoundDisk
Definition: BoundDisk.h:54
const SubLayerCrossing & closest() const
GlobalVector globalMomentum() const
string end
Definition: dataset.py:937
virtual const BoundDisk & specificSurface() const final
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
std::vector< const TECPetal * > theFrontComps
Definition: TECLayer.h:59
PeriodicBinFinderInPhi< float > BinFinderPhi
Definition: TECLayer.h:65
~TECLayer() override __attribute__((cold))
Definition: TECLayer.cc:93
#define LogDebug(id)