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