CMS 3D CMS Logo

CompositeTECWedge.cc
Go to the documentation of this file.
1 #include "CompositeTECWedge.h"
2 
4 
6 #include "LayerCrossingSide.h"
7 #include "DetGroupMerger.h"
9 
11 
15 
16 #include "TkDetUtil.h"
18 
19 using namespace std;
20 
22 
23 // --------- Temporary solution. DetSorting.h has to be used.
24 namespace {
25  class DetPhiLess {
26  public:
27  bool operator()(const GeomDet* a, const GeomDet* b) { return Geom::phiLess(a->surface(), b->surface()); }
28  };
29 } // namespace
30 // ---------------------
31 
32 CompositeTECWedge::CompositeTECWedge(vector<const GeomDet*>& innerDets, vector<const GeomDet*>& outerDets)
33  : theFrontDets(innerDets.begin(), innerDets.end()), theBackDets(outerDets.begin(), outerDets.end()) {
34  theDets.assign(theFrontDets.begin(), theFrontDets.end());
35  theDets.insert(theDets.end(), theBackDets.begin(), theBackDets.end());
36 
37  //
38  std::sort(theFrontDets.begin(), theFrontDets.end(), DetPhiLess());
39  std::sort(theBackDets.begin(), theBackDets.end(), DetPhiLess());
40 
44 
45  //--------- DEBUG INFO --------------
46  LogDebug("TkDetLayers") << "DEBUG INFO for CompositeTECWedge"
47  << "\n"
48  << "TECWedge z, perp,innerRadius,outerR: " << this->position().z() << " , "
49  << this->position().perp() << " , " << theDiskSector->innerRadius() << " , "
50  << theDiskSector->outerRadius();
51 
52  for (vector<const GeomDet*>::const_iterator it = theFrontDets.begin(); it != theFrontDets.end(); it++) {
53  LogDebug("TkDetLayers") << "frontDet phi,z,r: " << (*it)->surface().position().phi() << " , "
54  << (*it)->surface().position().z() << " , " << (*it)->surface().position().perp();
55  }
56 
57  for (vector<const GeomDet*>::const_iterator it = theBackDets.begin(); it != theBackDets.end(); it++) {
58  LogDebug("TkDetLayers") << "backDet phi,z,r: " << (*it)->surface().phi() << " , " << (*it)->surface().position().z()
59  << " , " << (*it)->surface().position().perp();
60  }
61  //-----------------------------------
62 }
63 
65 
66 const vector<const GeometricSearchDet*>& CompositeTECWedge::components() const {
67  throw DetLayerException("CompositeTECWedge doesn't have GeometricSearchDet components");
68 }
69 
70 pair<bool, TrajectoryStateOnSurface> CompositeTECWedge::compatible(const TrajectoryStateOnSurface& ts,
71  const Propagator&,
72  const MeasurementEstimator&) const {
73  edm::LogError("TkDetLayers") << "temporary dummy implementation of CompositeTECWedge::compatible()!!";
74  return pair<bool, TrajectoryStateOnSurface>();
75 }
76 
78  const Propagator& prop,
79  const MeasurementEstimator& est,
80  std::vector<DetGroup>& result) const {
82  if (!crossings.isValid())
83  return;
84 
85  std::vector<DetGroup> closestResult;
86  addClosest(tsos, prop, est, crossings.closest(), closestResult);
87 
88  LogDebug("TkDetLayers") << "in CompositeTECWedge::groupedCompatibleDets,closestResult.size(): "
89  << closestResult.size();
90 
91  if (closestResult.empty())
92  return;
93 
94  DetGroupElement closestGel(closestResult.front().front());
95  auto window = tkDetUtil::computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
96 
97  searchNeighbors(tsos, prop, est, crossings.closest(), window, closestResult, false);
98 
99  std::vector<DetGroup> nextResult;
100  searchNeighbors(tsos, prop, est, crossings.other(), window, nextResult, true);
101 
102  int crossingSide = LayerCrossingSide().endcapSide(closestGel.trajectoryState(), prop);
104  std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
105 }
106 
107 // private methods for the implementation of groupedCompatibleDets()
108 
110  PropagationDirection propDir) const {
111  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
112  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
113 
114  auto rho = startingState.transverseCurvature();
115 
116  HelixForwardPlaneCrossing crossing(startPos, startDir, rho, propDir);
117 
118  pair<bool, double> frontPath = crossing.pathLength(*theFrontSector);
119  if (!frontPath.first)
120  return SubLayerCrossings();
121 
122  pair<bool, double> backPath = crossing.pathLength(*theBackSector);
123  if (!backPath.first)
124  return SubLayerCrossings();
125 
126  GlobalPoint gFrontPoint(crossing.position(frontPath.second));
127  GlobalPoint gBackPoint(crossing.position(backPath.second));
128 
129  LogDebug("TkDetLayers") << "in TECWedge,front crossing r,z,phi: (" << gFrontPoint.perp() << "," << gFrontPoint.z()
130  << "," << gFrontPoint.phi() << ")";
131 
132  LogDebug("TkDetLayers") << "in TECWedge,back crossing r,z,phi: (" << gBackPoint.perp() << "," << gBackPoint.z() << ","
133  << gBackPoint.phi() << ")" << endl;
134 
135  int frontIndex = findClosestDet(gFrontPoint, 0);
136  SubLayerCrossing frontSLC(0, frontIndex, gFrontPoint);
137 
138  int backIndex = findClosestDet(gBackPoint, 1);
139  SubLayerCrossing backSLC(1, backIndex, gBackPoint);
140 
141  auto frontDist = std::abs(Geom::deltaPhi(gFrontPoint.barePhi(), theFrontDets[frontIndex]->surface().phi()));
142  /*
143  float frontDist = theFrontDets[frontIndex]->surface().phi() - gFrontPoint.phi();
144  frontDist *= Geom::phiLess( theFrontDets[frontIndex]->surface().phi(),gFrontPoint.barePhi()) ? -1. : 1.;
145  if (frontDist < 0.) { frontDist += 2.*Geom::pi();}
146  */
147  auto backDist = std::abs(Geom::deltaPhi(gBackPoint.barePhi(), theBackDets[backIndex]->surface().phi()));
148  /*
149  float backDist = theBackDets[backIndex]->surface().phi() - gBackPoint.phi();
150  backDist *= Geom::phiLess( theBackDets[backIndex]->surface().phi(),gBackPoint.barePhi()) ? -1. : 1.;
151  if ( backDist < 0.) { backDist += 2.*Geom::pi();}
152  */
153 
154  if (frontDist < backDist) {
155  return SubLayerCrossings(frontSLC, backSLC, 0);
156  } else {
157  return SubLayerCrossings(backSLC, frontSLC, 1);
158  }
159 }
160 
162  const Propagator& prop,
163  const MeasurementEstimator& est,
164  const SubLayerCrossing& crossing,
165  vector<DetGroup>& result) const {
166  const vector<const GeomDet*>& sWedge(subWedge(crossing.subLayerIndex()));
167 
168  LogDebug("TkDetLayers") << "in CompositeTECWedge,adding GeomDet at r,z,phi: ("
169  << sWedge[crossing.closestDetIndex()]->position().perp() << ","
170  << sWedge[crossing.closestDetIndex()]->position().z() << ","
171  << sWedge[crossing.closestDetIndex()]->position().phi() << ")";
172 
173  return CompatibleDetToGroupAdder().add(*sWedge[crossing.closestDetIndex()], tsos, prop, est, result);
174 }
175 
177  const Propagator& prop,
178  const MeasurementEstimator& est,
179  const SubLayerCrossing& crossing,
180  float window,
181  vector<DetGroup>& result,
182  bool checkClosest) const {
183  const GlobalPoint& gCrossingPos = crossing.position();
184 
185  const vector<const GeomDet*>& sWedge(subWedge(crossing.subLayerIndex()));
186 
187  int closestIndex = crossing.closestDetIndex();
188  int negStartIndex = closestIndex - 1;
189  int posStartIndex = closestIndex + 1;
190 
191  if (checkClosest) { // must decide if the closest is on the neg or pos side
192  if (Geom::phiLess(gCrossingPos.barePhi(), sWedge[closestIndex]->surface().phi())) {
193  posStartIndex = closestIndex;
194  } else {
195  negStartIndex = closestIndex;
196  }
197  }
198 
199  typedef CompatibleDetToGroupAdder Adder;
200  for (int idet = negStartIndex; idet >= 0; idet--) {
201  //if(idet <0 || idet>=sWedge.size()) {edm::LogInfo(TkDetLayers) << "==== warning! gone out vector bounds.idet: " << idet ;break;}
202  if (!tkDetUtil::overlapInPhi(gCrossingPos, *sWedge[idet], window))
203  break;
204  if (!Adder::add(*sWedge[idet], tsos, prop, est, result))
205  break;
206  }
207  for (int idet = posStartIndex; idet < static_cast<int>(sWedge.size()); idet++) {
208  //if(idet <0 || idet>=sWedge.size()) {edm::LogInfo(TkDetLayers) << "==== warning! gone out vector bounds.idet: " << idet ;break;}
209  if (!tkDetUtil::overlapInPhi(gCrossingPos, *sWedge[idet], window))
210  break;
211  if (!Adder::add(*sWedge[idet], tsos, prop, est, result))
212  break;
213  }
214 }
215 
216 int CompositeTECWedge::findClosestDet(const GlobalPoint& startPos, int sectorId) const {
217  vector<const GeomDet*> const& myDets = sectorId == 0 ? theFrontDets : theBackDets;
218 
219  int close = 0;
220  auto closeDist = std::abs((myDets.front()->toLocal(startPos)).x());
221  for (unsigned int i = 1; i < myDets.size(); i++) {
222  auto dist = std::abs((myDets[i]->toLocal(startPos)).x());
223  if (dist < closeDist) {
224  close = i;
225  closeDist = dist;
226  }
227  }
228  return close;
229 }
Common base class.
virtual const Surface::PositionType & position() const
Returns position of the surface.
T perp() const
Definition: PV3DBase.h:69
int closestIndex() const
std::vector< const GeomDet * > theDets
T z() const
Definition: PV3DBase.h:61
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
GeometricSearchDet::DetWithState DetWithState
PropagationDirection
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
Log< level::Error, false > LogError
~CompositeTECWedge() override __attribute__((cold))
bool overlapInPhi(float phi, const GeomDet &det, float phiWindow)
Definition: TkDetUtil.h:32
ReferenceCountingPointer< BoundDiskSector > theDiskSector
Definition: TECWedge.h:24
T barePhi() const
Definition: PV3DBase.h:65
std::vector< const GeomDet * > theFrontDets
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
Definition: TkDetUtil.cc:10
const std::vector< const GeomDet * > & subWedge(int ind) const
std::pair< bool, double > pathLength(const Plane &plane) override
GlobalPoint globalPosition() const
std::vector< const GeomDet * > theBackDets
const GlobalPoint & position() const
int closestDetIndex() const
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const override __attribute__((cold))
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
int findClosestDet(const GlobalPoint &startPos, int sectorId) const
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
const SubLayerCrossing & closest() const
int subLayerIndex() const
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
ReferenceCountingPointer< BoundDiskSector > theBackSector
CompositeTECWedge(std::vector< const GeomDet *> &innerDets, std::vector< const GeomDet *> &outerDets) __attribute__((cold))
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:18
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
const std::vector< const GeometricSearchDet * > & components() const override __attribute__((cold))
Returns basic components, if any.
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))
double b
Definition: hdecay.h:120
GlobalVector globalMomentum() const
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
double a
Definition: hdecay.h:121
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
PositionType position(double s) const override
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
ReferenceCountingPointer< BoundDiskSector > theFrontSector
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)