CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TkDetUtil.h
Go to the documentation of this file.
1 #ifndef TkDetLayers_TkDetUtil_h
2 #define TkDetLayers_TkDetUtil_h
3 
13 
15 
17 
18 #include "DetGroupMerger.h"
19 
20 class GeomDet;
21 class Plane;
23 
24 #pragma GCC visibility push(hidden)
25 
26 namespace tkDetUtil {
27 
28  struct RingPar {
30  };
31 
32  inline bool overlapInPhi(float phi, const GeomDet& det, float phiWindow) {
33  std::pair<float, float> phiRange(phi - phiWindow, phi + phiWindow);
34  return rangesIntersect(phiRange, det.surface().phiSpan(), [](auto x, auto y) { return Geom::phiLess(x, y); });
35  }
36 
37  inline bool overlapInPhi(GlobalPoint crossPoint, const GeomDet& det, float phiWindow) {
38  return overlapInPhi(crossPoint.barePhi(), det, phiWindow);
39  }
40 
41  float computeWindowSize(const GeomDet* det, const TrajectoryStateOnSurface& tsos, const MeasurementEstimator& est);
42 
44  const TrajectoryStateOnSurface& ts,
45  const Plane& plane);
46 
47  float computeYdirWindowSize(const GeomDet* det,
48  const TrajectoryStateOnSurface& tsos,
49  const MeasurementEstimator& est);
50 
51  std::array<int, 3> findThreeClosest(const std::vector<RingPar>& ringParams,
52  const std::vector<GlobalPoint>& ringCrossing,
53  const int ringSize);
54 
55  bool overlapInR(const TrajectoryStateOnSurface& tsos, int index, double ymax, const std::vector<RingPar>& ringParams);
56 
57  RingPar fillRingParametersFromDisk(const BoundDisk& ringDisk);
58 
59  template <class T>
60  std::array<int, 3> ringIndicesByCrossingProximity(const TrajectoryStateOnSurface& startingState,
61  const Propagator& prop,
62  const int ringSize,
63  const T& diskComponents,
64  const std::vector<RingPar>& ringParams) {
65  typedef HelixForwardPlaneCrossing Crossing;
67 
68  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
69  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
71  float rho(startingState.transverseCurvature());
72 
73  // calculate the crossings with the ring surfaces
74  // rings are assumed to be sorted in R !
75 
76  Crossing myXing(startPos, startDir, rho, propDir);
77 
78  std::vector<GlobalPoint> ringCrossings;
79  ringCrossings.reserve(ringSize);
80 
81  for (int i = 0; i < ringSize; i++) {
82  const BoundDisk& theRing = static_cast<const BoundDisk&>(diskComponents[i]->surface());
83  std::pair<bool, double> pathlen = myXing.pathLength(theRing);
84  if (pathlen.first) {
85  ringCrossings.push_back(GlobalPoint(myXing.position(pathlen.second)));
86  } else {
87  // TO FIX.... perhaps there is something smarter to do
88  ringCrossings.push_back(GlobalPoint(0., 0., 0.));
89  }
90  }
91 
92  //find three closest rings to the crossing
93 
94  std::array<int, 3> closests = findThreeClosest(ringParams, ringCrossings, ringSize);
95 
96  return closests;
97  }
98 
99  template <class T>
101  const Propagator& prop,
102  const MeasurementEstimator& est,
103  std::vector<DetGroup>& result,
104  const int ringSize,
105  const std::vector<const T*>& diskComponents,
106  const std::vector<RingPar>& ringParams) {
107  std::array<int, 3> const& ringIndices =
108  ringIndicesByCrossingProximity(startingState, prop, ringSize, diskComponents, ringParams);
109  if (ringIndices[0] == -1 || ringIndices[1] == -1 || ringIndices[2] == -1) {
110  edm::LogError("TkDetLayers") << "TkRingedForwardLayer::groupedCompatibleDets : error in CrossingProximity";
111  return;
112  }
113 
114  //order is: rings in front = 0; rings in back = 1
115  //rings should be already ordered in r
116  //if the layer has 1 ring, it does not matter
117  //FIXME: to be optimized once the geometry is stable
118  std::vector<int> ringOrder(ringSize);
119  std::fill(ringOrder.begin(), ringOrder.end(), 1);
120  if (ringSize > 1) {
121  if (std::abs(diskComponents[0]->position().z()) < std::abs(diskComponents[1]->position().z())) {
122  for (int i = 0; i < ringSize; i++) {
123  if (i % 2 == 0)
124  ringOrder[i] = 0;
125  }
126  } else if (std::abs(diskComponents[0]->position().z()) > std::abs(diskComponents[1]->position().z())) {
127  std::fill(ringOrder.begin(), ringOrder.end(), 0);
128  for (int i = 0; i < ringSize; i++) {
129  if (i % 2 == 0)
130  ringOrder[i] = 1;
131  }
132  } else {
133  throw DetLayerException("Rings in Endcap Layer have same z position, no idea how to order them!");
134  }
135  }
136 
137  auto index = [&ringIndices, &ringOrder](int i) { return ringOrder[ringIndices[i]]; };
138 
139  std::vector<DetGroup> closestResult;
140  diskComponents[ringIndices[0]]->groupedCompatibleDetsV(startingState, prop, est, closestResult);
141  // if the closest is empty, use the next one and exit: inherited from TID !
142  if (closestResult.empty()) {
143  diskComponents[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, result);
144  return;
145  }
146 
147  DetGroupElement closestGel(closestResult.front().front());
148  float rWindow = computeYdirWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
149 
150  // check if next ring and next next ring are found and if there is overlap
151 
152  bool ring1ok =
153  ringIndices[1] != -1 && overlapInR(closestGel.trajectoryState(), ringIndices[1], rWindow, ringParams);
154  bool ring2ok =
155  ringIndices[2] != -1 && overlapInR(closestGel.trajectoryState(), ringIndices[2], rWindow, ringParams);
156 
157  // look for the two rings in the same plane (are they only two?)
158 
159  // determine if we are propagating from in to out (0) or from out to in (1)
160 
161  int direction = 0;
162  if (startingState.globalPosition().z() * startingState.globalMomentum().z() > 0) {
163  if (prop.propagationDirection() == alongMomentum)
164  direction = 0;
165  else
166  direction = 1;
167  } else {
168  if (prop.propagationDirection() == alongMomentum)
169  direction = 1;
170  else
171  direction = 0;
172  }
173 
174  if ((index(0) == index(1)) && (index(0) == index(2))) {
175  edm::LogInfo("AllRingsInOnePlane") << " All rings: " << ringIndices[0] << " " << ringIndices[1] << " "
176  << ringIndices[2] << " in one plane. Only the first two will be considered";
177  ring2ok = false;
178  }
179 
180  if (index(0) == index(1)) {
181  if (ring1ok) {
182  std::vector<DetGroup> ring1res;
183  diskComponents[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, ring1res);
184  DetGroupMerger::addSameLevel(std::move(ring1res), closestResult);
185  }
186  if (ring2ok) {
187  std::vector<DetGroup> ring2res;
188  diskComponents[ringIndices[2]]->groupedCompatibleDetsV(startingState, prop, est, ring2res);
190  std::move(closestResult), std::move(ring2res), result, index(0), direction);
191  return;
192  } else {
193  result.swap(closestResult);
194  return;
195  }
196  } else if (index(0) == index(2)) {
197  if (ring2ok) {
198  std::vector<DetGroup> ring2res;
199  diskComponents[ringIndices[2]]->groupedCompatibleDetsV(startingState, prop, est, ring2res);
200  DetGroupMerger::addSameLevel(std::move(ring2res), closestResult);
201  }
202  if (ring1ok) {
203  std::vector<DetGroup> ring1res;
204  diskComponents[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, ring1res);
206  std::move(closestResult), std::move(ring1res), result, index(0), direction);
207  return;
208  } else {
209  result.swap(closestResult);
210  return;
211  }
212  } else {
213  std::vector<DetGroup> ring12res;
214  if (ring1ok) {
215  std::vector<DetGroup> ring1res;
216  diskComponents[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, ring1res);
217  ring12res.swap(ring1res);
218  }
219  if (ring2ok) {
220  std::vector<DetGroup> ring2res;
221  diskComponents[ringIndices[2]]->groupedCompatibleDetsV(startingState, prop, est, ring2res);
222  DetGroupMerger::addSameLevel(std::move(ring2res), ring12res);
223  }
224  if (!ring12res.empty()) {
226  std::move(closestResult), std::move(ring12res), result, index(0), direction);
227  return;
228  } else {
229  result.swap(closestResult);
230  return;
231  }
232  }
233  }
234 
235  template <class T>
236  BoundDisk* computeDisk(const std::vector<const T*>& structures) {
237  float theRmin = structures.front()->specificSurface().innerRadius();
238  float theRmax = structures.front()->specificSurface().outerRadius();
239  float theZmin = structures.front()->position().z() - structures.front()->surface().bounds().thickness() / 2;
240  float theZmax = structures.front()->position().z() + structures.front()->surface().bounds().thickness() / 2;
241 
242  for (typename std::vector<const T*>::const_iterator i = structures.begin(); i != structures.end(); i++) {
243  float rmin = (**i).specificSurface().innerRadius();
244  float rmax = (**i).specificSurface().outerRadius();
245  float zmin = (**i).position().z() - (**i).surface().bounds().thickness() / 2.;
246  float zmax = (**i).position().z() + (**i).surface().bounds().thickness() / 2.;
247  theRmin = std::min(theRmin, rmin);
248  theRmax = std::max(theRmax, rmax);
249  theZmin = std::min(theZmin, zmin);
250  theZmax = std::max(theZmax, zmax);
251  }
252 
253  float zPos = (theZmax + theZmin) / 2.;
254  Plane::PositionType pos(0., 0., zPos);
256 
257  return new BoundDisk(pos, rot, new SimpleDiskBounds(theRmin, theRmax, theZmin - zPos, theZmax - zPos));
258  }
259 
260 } // namespace tkDetUtil
261 
262 #pragma GCC visibility pop
263 #endif // TkDetLayers_TkDetUtil_h
Common base class.
bool overlapInR(const TrajectoryStateOnSurface &tsos, int index, double ymax, const std::vector< RingPar > &ringParams)
Definition: TkDetUtil.cc:112
std::array< int, 3 > ringIndicesByCrossingProximity(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const int ringSize, const T &diskComponents, const std::vector< RingPar > &ringParams)
Definition: TkDetUtil.h:60
BoundDisk * computeDisk(const std::vector< const T * > &structures)
Definition: TkDetUtil.h:236
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint globalPosition() const
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
PropagationDirection
Log< level::Error, false > LogError
bool overlapInPhi(float phi, const GeomDet &det, float phiWindow)
Definition: TkDetUtil.h:32
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
std::array< int, 3 > findThreeClosest(const std::vector< RingPar > &ringParams, const std::vector< GlobalPoint > &ringCrossing, const int ringSize)
Definition: TkDetUtil.cc:79
Definition: Plane.h:16
tuple result
Definition: mps_fire.py:311
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
Definition: TkDetUtil.cc:10
T barePhi() const
Definition: PV3DBase.h:65
float computeYdirWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
Definition: TkDetUtil.cc:71
static void addSameLevel(std::vector< DetGroup > &&gvec, std::vector< DetGroup > &result)
T z() const
Definition: PV3DBase.h:61
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< float, float > const & phiSpan() const
Definition: Surface.h:90
RingPar fillRingParametersFromDisk(const BoundDisk &ringDisk)
Definition: TkDetUtil.cc:124
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:18
Log< level::Info, false > LogInfo
bool rangesIntersect(const Range &a, const Range &b)
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result, const int ringSize, const std::vector< const T * > &diskComponents, const std::vector< RingPar > &ringParams)
Definition: TkDetUtil.h:100
Disk BoundDisk
Definition: BoundDisk.h:54
GlobalVector globalMomentum() const
static int position[264][3]
Definition: ReadPGInfo.cc:289
Vector2DBase< float, LocalTag > Local2DVector
float x
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
long double T
float calculatePhiWindow(const MeasurementEstimator::Local2DVector &imaxDistance, const TrajectoryStateOnSurface &ts, const Plane &plane)
Definition: TkDetUtil.cc:16