CMS 3D CMS Logo

CompositeTECPetal.cc
Go to the documentation of this file.
1 #include "CompositeTECPetal.h"
2 
4 
6 #include "LayerCrossingSide.h"
7 #include "DetGroupMerger.h"
9 
13 
14 #include "TkDetUtil.h"
16 
17 #include <algorithm>
18 #include <functional>
19 #include <iterator>
20 #include <numeric>
21 
22 using namespace std;
23 
25 
26 namespace {
27  namespace details {
28 
29  struct Mean {
30  float operator()(const GeometricSearchDet* a, const GeometricSearchDet* b) const {
31  return 0.5 * (b->position().perp() + a->position().perp());
32  }
33  float operator()(float a, float b) const { return 0.5 * (b + a); }
34  };
35 
36  void fillBoundaries(std::vector<const TECWedge*> const& dets, std::vector<float>& boundaries) {
37  boundaries.resize(dets.size());
38  std::transform(dets.begin(),
39  dets.end(),
40  boundaries.begin(),
41  std::bind(&GlobalPoint::perp, std::bind(&GeometricSearchDet::position, std::placeholders::_1)));
42  std::adjacent_difference(boundaries.begin(), boundaries.end(), boundaries.begin(), Mean());
43  }
44 
45  inline int findBin(std::vector<float> const& boundaries, float r) {
46  return std::lower_bound(boundaries.begin() + 1, boundaries.end(), r) - boundaries.begin() - 1;
47  }
48 
49  void fillPars(std::vector<const TECWedge*> const& dets, std::vector<CompositeTECPetal::WedgePar>& pars) {
50  for (auto gsdet : dets) {
51  const BoundDiskSector& wedgeSector = static_cast<const BoundDiskSector&>(gsdet->surface());
52  float wedgeMinZ = std::abs(wedgeSector.position().z()) - 0.5 * wedgeSector.bounds().thickness();
53  float wedgeMaxZ = std::abs(wedgeSector.position().z()) + 0.5 * wedgeSector.bounds().thickness();
54  float thetaWedgeMin = wedgeSector.innerRadius() / wedgeMaxZ;
55  float thetaWedgeMax = wedgeSector.outerRadius() / wedgeMinZ;
56  CompositeTECPetal::WedgePar apar = {gsdet->position().perp(), thetaWedgeMin, thetaWedgeMax};
57  pars.push_back(apar);
58  }
59  }
60 
61  inline bool overlap(const GlobalPoint& gpos, const CompositeTECPetal::WedgePar& wpar, float ymax) {
62  // this method is just a duplication of overlapInR
63  // adapeted for groupedCompatibleDets() needs
64 
65  // assume "fixed theta window", i.e. margin in local y = r is changing linearly with z
66  auto tsRadius = gpos.perp();
67  auto rmin = std::max(0.f, tsRadius - ymax);
68  auto zmax = std::abs(gpos.z()) + 10.f; // add 10 cm contingency
69  auto rmax = (tsRadius + ymax);
70  auto zmin = std::abs(gpos.z()) - 10.f;
71 
72  // do the theta regions overlap ?
73 
74  return !((rmin > zmax * wpar.thetaMax) | (zmin * wpar.thetaMin > rmax));
75  }
76 
77  } // namespace details
78 } // namespace
79 
80 CompositeTECPetal::CompositeTECPetal(vector<const TECWedge*>& innerWedges, vector<const TECWedge*>& outerWedges)
81  : GeometricSearchDet(true), theFrontComps(innerWedges), theBackComps(outerWedges) {
82  theComps.assign(theFrontComps.begin(), theFrontComps.end());
83  theComps.insert(theComps.end(), theBackComps.begin(), theBackComps.end());
84 
85  details::fillBoundaries(theFrontComps, theFrontBoundaries);
86  details::fillBoundaries(theBackComps, theBackBoundaries);
87  details::fillPars(theFrontComps, theFrontPars);
88  details::fillPars(theBackComps, theBackPars);
89 
90  for (vector<const GeometricSearchDet*>::const_iterator it = theComps.begin(); it != theComps.end(); it++) {
91  theBasicComps.insert(theBasicComps.end(), (**it).basicComponents().begin(), (**it).basicComponents().end());
92  }
93 
94  //the Wedge are already R ordered
95  //sort( theWedges.begin(), theWedges.end(), DetLessR());
96  //sort( theFrontWedges.begin(), theFrontWedges.end(), DetLessR() );
97  //sort( theBackWedges.begin(), theBackWedges.end(), DetLessR() );
98  vector<const TECWedge*> allWedges;
99  allWedges.assign(innerWedges.begin(), innerWedges.end());
100  allWedges.insert(allWedges.end(), outerWedges.begin(), outerWedges.end());
101 
105 
106  //--------- DEBUG INFO --------------
107  LogDebug("TkDetLayers") << "DEBUG INFO for CompositeTECPetal";
108 
109  for (auto it = theFrontComps.begin(); it != theFrontComps.end(); it++) {
110  LogDebug("TkDetLayers") << "frontWedge phi,z,r: " << (*it)->surface().position().phi() << " , "
111  << (*it)->surface().position().z() << " , " << (*it)->surface().position().perp();
112  }
113 
114  for (auto it = theBackComps.begin(); it != theBackComps.end(); it++) {
115  LogDebug("TkDetLayers") << "backWedge phi,z,r: " << (*it)->surface().position().phi() << " , "
116  << (*it)->surface().position().z() << " , " << (*it)->surface().position().perp();
117  }
118  //-----------------------------------
119 }
120 
122  vector<const GeometricSearchDet*>::const_iterator i;
123  for (i = theComps.begin(); i != theComps.end(); i++) {
124  delete *i;
125  }
126 }
127 
128 pair<bool, TrajectoryStateOnSurface> CompositeTECPetal::compatible(const TrajectoryStateOnSurface& ts,
129  const Propagator&,
130  const MeasurementEstimator&) const {
131  edm::LogError("TkDetLayers") << "temporary dummy implementation of CompositeTECPetal::compatible()!!";
132  return pair<bool, TrajectoryStateOnSurface>();
133 }
134 
136  const Propagator& prop,
137  const MeasurementEstimator& est,
138  std::vector<DetGroup>& result) const {
139  vector<DetGroup> closestResult;
140  SubLayerCrossings crossings;
141  crossings = computeCrossings(tsos, prop.propagationDirection());
142  if (!crossings.isValid())
143  return;
144 
145  addClosest(tsos, prop, est, crossings.closest(), closestResult);
146  LogDebug("TkDetLayers") << "in TECPetal, closestResult.size(): " << closestResult.size();
147 
148  if (closestResult.empty()) {
149  vector<DetGroup> nextResult;
150  addClosest(tsos, prop, est, crossings.other(), nextResult);
151  LogDebug("TkDetLayers") << "in TECPetal, nextResult.size(): " << nextResult.size();
152  if (nextResult.empty())
153  return;
154 
155  DetGroupElement nextGel(nextResult.front().front());
156  int crossingSide = LayerCrossingSide::endcapSide(nextGel.trajectoryState(), prop);
158  std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
159  } else {
160  DetGroupElement closestGel(closestResult.front().front());
161  float window = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
162 
163  searchNeighbors(tsos, prop, est, crossings.closest(), window, closestResult, false);
164 
165  vector<DetGroup> nextResult;
166  searchNeighbors(tsos, prop, est, crossings.other(), window, nextResult, true);
167 
168  int crossingSide = LayerCrossingSide::endcapSide(closestGel.trajectoryState(), prop);
170  std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
171  }
172 }
173 
175  PropagationDirection propDir) const {
176  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
177  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
178 
179  auto rho = startingState.transverseCurvature();
180 
181  HelixForwardPlaneCrossing crossing(startPos, startDir, rho, propDir);
182 
183  pair<bool, double> frontPath = crossing.pathLength(*theFrontSector);
184  if (!frontPath.first)
185  return SubLayerCrossings();
186 
187  pair<bool, double> backPath = crossing.pathLength(*theBackSector);
188  if (!backPath.first)
189  return SubLayerCrossings();
190 
191  GlobalPoint gFrontPoint(crossing.position(frontPath.second));
192  GlobalPoint gBackPoint(crossing.position(backPath.second));
193 
194  LogDebug("TkDetLayers") << "in TECPetal,front crossing : r,z,phi: (" << gFrontPoint.perp() << "," << gFrontPoint.z()
195  << "," << gFrontPoint.phi() << ")";
196 
197  LogDebug("TkDetLayers") << "in TECPetal,back crossing r,z,phi: (" << gBackPoint.perp() << "," << gBackPoint.z() << ","
198  << gBackPoint.phi() << ")";
199 
200  int frontIndex = findBin(gFrontPoint.perp(), 0);
201  SubLayerCrossing frontSLC(0, frontIndex, gFrontPoint);
202 
203  int backIndex = findBin(gBackPoint.perp(), 1);
204  SubLayerCrossing backSLC(1, backIndex, gBackPoint);
205 
206  auto frontDist = std::abs(theFrontPars[frontIndex].theR - gFrontPoint.perp());
207  auto backDist = std::abs(theBackPars[backIndex].theR - gBackPoint.perp());
208 
209  // 0ss: frontDisk has index=0, backDisk has index=1
210  if (frontDist < backDist) {
211  return SubLayerCrossings(frontSLC, backSLC, 0);
212  } else {
213  return SubLayerCrossings(backSLC, frontSLC, 1);
214  }
215 }
216 
218  const Propagator& prop,
219  const MeasurementEstimator& est,
220  const SubLayerCrossing& crossing,
221  vector<DetGroup>& result) const {
222  auto det = subLayer(crossing.subLayerIndex())[crossing.closestDetIndex()];
223 
224  LogDebug("TkDetLayers") << "in TECPetal, adding Wedge at r,z,phi: (" << det->position().perp() << ","
225  << det->position().z() << "," << det->position().phi() << ")";
226  LogDebug("TkDetLayers") << "wedge comps size: " << det->basicComponents().size();
227 
228  return CompatibleDetToGroupAdder::add(*det, tsos, prop, est, result);
229 }
230 
232  const Propagator& prop,
233  const MeasurementEstimator& est,
234  const SubLayerCrossing& crossing,
235  float window,
236  vector<DetGroup>& result,
237  bool checkClosest) const {
238  const GlobalPoint& gCrossingPos = crossing.position();
239 
240  int closestIndex = crossing.closestDetIndex();
241  int negStartIndex = closestIndex - 1;
242  int posStartIndex = closestIndex + 1;
243 
244  float detR = findPar(closestIndex, crossing.subLayerIndex()).theR;
245 
246  if (checkClosest) { // must decide if the closest is on the neg or pos side
247  if (gCrossingPos.perp2() < detR * detR) {
248  posStartIndex = closestIndex;
249  } else {
250  negStartIndex = closestIndex;
251  }
252  }
253 
254  const std::vector<const TECWedge*>& sLayer = subLayer(crossing.subLayerIndex());
255 
256  //const BinFinderType& binFinder = (crossing.subLayerIndex()==0 ? theFrontBinFinder : theBackBinFinder);
257  int theSize = crossing.subLayerIndex() == 0 ? theFrontComps.size() : theBackComps.size();
258 
259  typedef CompatibleDetToGroupAdder Adder;
260  for (int idet = negStartIndex; idet >= 0; idet--) {
261  //if(idet<0 || idet>= theSize) {edm::LogInfo(TkDetLayers) << "===== error! gone out vector bounds.idet: " << idet ;exit;}
262  const GeometricSearchDet& neighborWedge = *sLayer[idet];
263  WedgePar const& wpar = findPar(idet, crossing.subLayerIndex());
264  if (!details::overlap(gCrossingPos, wpar, window))
265  break; // --- to check
266  if (!Adder::add(neighborWedge, tsos, prop, est, result))
267  break;
268  // maybe also add shallow crossing angle test here???
269  }
270  for (int idet = posStartIndex; idet < theSize; idet++) {
271  //if(idet<0 || idet>= theSize) {edm::LogInfo(TkDetLayers) << "===== error! gone out vector bounds.idet: " << idet ;exit;}
272  const GeometricSearchDet& neighborWedge = *sLayer[idet];
273  WedgePar const& wpar = findPar(idet, crossing.subLayerIndex());
274  if (!details::overlap(gCrossingPos, wpar, window))
275  break; // ---- to check
276  if (!Adder::add(neighborWedge, tsos, prop, est, result))
277  break;
278  // maybe also add shallow crossing angle test here???
279  }
280 }
281 
283  const TrajectoryStateOnSurface& tsos,
284  const MeasurementEstimator& est) {
285  return est.maximalLocalDisplacement(tsos, det->surface()).y();
286 }
287 
288 int CompositeTECPetal::findBin(float R, int diskSectorType) const {
289  return details::findBin(diskSectorType == 0 ? theFrontBoundaries : theBackBoundaries, R);
290 }
std::vector< float > theFrontBoundaries
CompositeTECPetal(std::vector< const TECWedge *> &innerWedges, std::vector< const TECWedge *> &outerWedges) __attribute__((cold))
virtual const Surface::PositionType & position() const
Returns position of the surface.
int closestIndex() const
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
T z() const
Definition: PV3DBase.h:61
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
DiskSectorBounds const & bounds() const
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
std::vector< const GeometricSearchDet * > theComps
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))
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
~CompositeTECPetal() override __attribute__((cold))
PropagationDirection
Log< level::Error, false > LogError
const std::vector< const TECWedge * > & subLayer(int ind) const
std::pair< bool, double > pathLength(const Plane &plane) override
float innerRadius() const
GlobalPoint globalPosition() const
GeometricSearchDet::DetWithState DetWithState
const GlobalPoint & position() const
int closestDetIndex() const
int findBin(float R, int layer) const
Definition: helper.h:56
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ReferenceCountingPointer< BoundDiskSector > theDiskSector
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
float thickness() const override
double f[11][100]
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
float outerRadius() const
const SubLayerCrossing & closest() const
int subLayerIndex() const
static float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) __attribute__((hot))
static bool add(const GeometricSearchDet &det, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) __attribute__((hot))
const SubLayerCrossing & other() const
ReferenceCountingPointer< BoundDiskSector > theFrontSector
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const PositionType & position() const
std::vector< const TECWedge * > theFrontComps
double b
Definition: hdecay.h:120
GlobalVector globalMomentum() const
ReferenceCountingPointer< BoundDiskSector > theBackSector
T perp2() const
Definition: PV3DBase.h:68
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const override __attribute__((cold))
std::vector< WedgePar > theBackPars
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
double a
Definition: hdecay.h:121
std::vector< const GeomDet * > theBasicComps
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
WedgePar const & findPar(int index, int diskSectorType) const
PositionType position(double s) const override
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
std::vector< float > theBackBoundaries
def move(src, dest)
Definition: eostools.py:511
std::vector< const TECWedge * > theBackComps
std::vector< WedgePar > theFrontPars
#define LogDebug(id)
unsigned transform(const HcalDetId &id, unsigned transformCode)