CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Phase2EndcapRing.cc
Go to the documentation of this file.
1 #include "Phase2EndcapRing.h"
2 
4 
10 
11 #include "LayerCrossingSide.h"
12 #include "DetGroupMerger.h"
14 
15 #include "TkDetUtil.h"
17 
18 #include "DetGroupElementZLess.h"
19 
20 using namespace std;
21 
23 
24 Phase2EndcapRing::Phase2EndcapRing(vector<const GeomDet*>& innerDets,
25  vector<const GeomDet*>& outerDets,
26  const vector<const GeomDet*>& innerDetBrothers,
27  const vector<const GeomDet*>& outerDetBrothers)
29  theFrontDets(innerDets.begin(), innerDets.end()),
30  theBackDets(outerDets.begin(), outerDets.end()),
31  theFrontDetBrothers(innerDetBrothers.begin(), innerDetBrothers.end()),
32  theBackDetBrothers(outerDetBrothers.begin(), outerDetBrothers.end()) {
33  theDets.assign(theFrontDets.begin(), theFrontDets.end());
34  theDets.insert(theDets.end(), theBackDets.begin(), theBackDets.end());
35  theDets.insert(theDets.end(), theFrontDetBrothers.begin(), theFrontDetBrothers.end());
36  theDets.insert(theDets.end(), theBackDetBrothers.begin(), theBackDetBrothers.end());
37 
38  // the dets should be already phi-ordered. TO BE CHECKED
39  //sort( theFrontDets.begin(), theFrontDets.end(), DetLessPhi() );
40  //sort( theBackDets.begin(), theBackDets.end(), DetLessPhi() );
41 
43 
46 
47  theFrontBinFinder = BinFinderType(theFrontDets.front()->surface().position().phi(), theFrontDets.size());
48  theBackBinFinder = BinFinderType(theBackDets.front()->surface().position().phi(), theBackDets.size());
49 
50 #ifdef EDM_ML_DEBUG
51  LogDebug("TkDetLayers") << "DEBUG INFO for Phase2EndcapRing";
52  for (vector<const GeomDet*>::const_iterator it = theFrontDets.begin(); it != theFrontDets.end(); it++) {
53  LogDebug("TkDetLayers") << "frontDet detId,phi,z,r: " << (*it)->geographicalId().rawId() << " , "
54  << (*it)->surface().position().phi() << " , " << (*it)->surface().position().z() << " , "
55  << (*it)->surface().position().perp();
56  }
57 
58  if (!theFrontDetBrothers.empty()) {
59  for (vector<const GeomDet*>::const_iterator it = theFrontDetBrothers.begin(); it != theFrontDetBrothers.end();
60  it++) {
61  LogDebug("TkDetLayers") << "frontDet brothers detId,phi,z,r: " << (*it)->geographicalId().rawId() << " , "
62  << (*it)->surface().position().phi() << " , " << (*it)->surface().position().z() << " , "
63  << (*it)->surface().position().perp();
64  }
65  }
66 
67  for (vector<const GeomDet*>::const_iterator it = theBackDets.begin(); it != theBackDets.end(); it++) {
68  LogDebug("TkDetLayers") << "backDet detId,phi,z,r: " << (*it)->geographicalId().rawId() << " , "
69  << (*it)->surface().position().phi() << " , " << (*it)->surface().position().z() << " , "
70  << (*it)->surface().position().perp();
71  }
72 
73  if (!theBackDetBrothers.empty()) {
74  for (vector<const GeomDet*>::const_iterator it = theBackDetBrothers.begin(); it != theBackDetBrothers.end(); it++) {
75  LogDebug("TkDetLayers") << "backDet brothers detId,phi,z,r: " << (*it)->geographicalId().rawId() << " , "
76  << (*it)->surface().position().phi() << " , " << (*it)->surface().position().z() << " , "
77  << (*it)->surface().position().perp();
78  }
79  }
80 #endif
81 }
82 
84 
85 const vector<const GeometricSearchDet*>& Phase2EndcapRing::components() const {
86  throw DetLayerException("Phase2EndcapRing doesn't have GeometricSearchDet components");
87 }
88 
89 pair<bool, TrajectoryStateOnSurface> Phase2EndcapRing::compatible(const TrajectoryStateOnSurface&,
90  const Propagator&,
91  const MeasurementEstimator&) const {
92  edm::LogError("TkDetLayers") << "temporary dummy implementation of Phase2EndcapRing::compatible()!!";
93  return pair<bool, TrajectoryStateOnSurface>();
94 }
95 
97  const Propagator& prop,
98  const MeasurementEstimator& est,
99  std::vector<DetGroup>& result) const {
100  SubLayerCrossings crossings;
101  crossings = computeCrossings(tsos, prop.propagationDirection());
102  if (!crossings.isValid())
103  return;
104 
105  std::vector<DetGroup> closestResult;
106  std::vector<DetGroup> closestBrotherResult;
107  addClosest(tsos, prop, est, crossings.closest(), closestResult, closestBrotherResult);
108  if (closestResult.empty())
109  return;
110 
111  DetGroupElement closestGel(closestResult.front().front());
112  int crossingSide = LayerCrossingSide().endcapSide(closestGel.trajectoryState(), prop);
113  float phiWindow = tkDetUtil::computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
114  searchNeighbors(tsos, prop, est, crossings.closest(), phiWindow, closestResult, closestBrotherResult, false);
115 
116  vector<DetGroup> closestCompleteResult;
118  std::move(closestResult), std::move(closestBrotherResult), closestCompleteResult, 0, crossingSide);
119 
120  vector<DetGroup> nextResult;
121  vector<DetGroup> nextBrotherResult;
122  searchNeighbors(tsos, prop, est, crossings.other(), phiWindow, nextResult, nextBrotherResult, true);
123 
124  vector<DetGroup> nextCompleteResult;
126  std::move(nextResult), std::move(nextBrotherResult), nextCompleteResult, 0, crossingSide);
127 
129  std::move(closestCompleteResult), std::move(nextCompleteResult), result, crossings.closestIndex(), crossingSide);
130 
131  //due to propagator problems, when we add single pt sub modules, we should order them in z (endcap)
132  if (!theFrontDetBrothers.empty() && !theBackDetBrothers.empty())
133  sort(result.begin(), result.end(), DetGroupElementZLess());
134 
135 #ifdef EDM_ML_DEBUG
136  LogTrace("TkDetLayers") << "Number of groups : " << result.size() << std::endl;
137  for (auto& grp : result) {
138  if (grp.empty())
139  continue;
140  LogTrace("TkDetLayers") << "New group in Phase2EndcapRing made by : " << std::endl;
141  for (auto const& det : grp) {
142  LogTrace("TkDetLayers") << " geom det at r: " << det.det()->position().perp()
143  << " id:" << det.det()->geographicalId().rawId()
144  << " tsos at:" << det.trajectoryState().globalPosition() << std::endl;
145  }
146  }
147 #endif
148 }
149 
151  PropagationDirection propDir) const {
152  auto rho = startingState.transverseCurvature();
153 
154  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
155  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
156  HelixForwardPlaneCrossing crossing(startPos, startDir, rho, propDir);
157 
158  pair<bool, double> frontPath = crossing.pathLength(*theFrontDisk);
159  if (!frontPath.first)
160  return SubLayerCrossings();
161 
162  pair<bool, double> backPath = crossing.pathLength(*theBackDisk);
163  if (!backPath.first)
164  return SubLayerCrossings();
165 
166  GlobalPoint gFrontPoint(crossing.position(frontPath.second));
167  GlobalPoint gBackPoint(crossing.position(backPath.second));
168 
169  int frontIndex = theFrontBinFinder.binIndex(gFrontPoint.barePhi());
170  SubLayerCrossing frontSLC(0, frontIndex, gFrontPoint);
171 
172  int backIndex = theBackBinFinder.binIndex(gBackPoint.barePhi());
173  SubLayerCrossing backSLC(1, backIndex, gBackPoint);
174 
175  // 0ss: frontDisk has index=0, backDisk has index=1
176  float frontDist = std::abs(Geom::deltaPhi(gFrontPoint.barePhi(), theFrontDets[frontIndex]->surface().phi()));
177  float backDist = std::abs(Geom::deltaPhi(gBackPoint.barePhi(), theBackDets[backIndex]->surface().phi()));
178 
179  if (frontDist < backDist) {
180  return SubLayerCrossings(frontSLC, backSLC, 0);
181  } else {
182  return SubLayerCrossings(backSLC, frontSLC, 1);
183  }
184 }
185 
187  const Propagator& prop,
188  const MeasurementEstimator& est,
189  const SubLayerCrossing& crossing,
190  vector<DetGroup>& result,
191  vector<DetGroup>& brotherresult) const {
192  const vector<const GeomDet*>& sub(subLayer(crossing.subLayerIndex()));
193  const GeomDet* det(sub[crossing.closestDetIndex()]);
194  bool firstgroup = CompatibleDetToGroupAdder::add(*det, tsos, prop, est, result);
195  if (theFrontDetBrothers.empty() && theBackDetBrothers.empty())
196  return firstgroup;
197  // it assumes that the closestDetIndex is ok also for the brother detectors: the crossing is NOT recomputed
198  const vector<const GeomDet*>& subBrothers(subLayerBrothers(crossing.subLayerIndex()));
199  const GeomDet* detBrother(subBrothers[crossing.closestDetIndex()]);
200  bool brothergroup = CompatibleDetToGroupAdder::add(*detBrother, tsos, prop, est, brotherresult);
201  return firstgroup || brothergroup;
202 }
203 
205  const Propagator& prop,
206  const MeasurementEstimator& est,
207  const SubLayerCrossing& crossing,
208  float window,
209  vector<DetGroup>& result,
210  vector<DetGroup>& brotherresult,
211  bool checkClosest) const {
212  const GlobalPoint& gCrossingPos = crossing.position();
213 
214  const vector<const GeomDet*>& sLayer(subLayer(crossing.subLayerIndex()));
215  // It assumes that what is ok for the front modules in the pt modules is ok also for the back module
216  const vector<const GeomDet*>& sBrotherLayer(subLayerBrothers(crossing.subLayerIndex()));
217 
218  int closestIndex = crossing.closestDetIndex();
219  int negStartIndex = closestIndex - 1;
220  int posStartIndex = closestIndex + 1;
221 
222  if (checkClosest) { // must decide if the closest is on the neg or pos side
223  if (Geom::phiLess(gCrossingPos.barePhi(), sLayer[closestIndex]->surface().phi())) {
224  posStartIndex = closestIndex;
225  } else {
226  negStartIndex = closestIndex;
227  }
228  }
229 
230  const BinFinderType& binFinder = (crossing.subLayerIndex() == 0 ? theFrontBinFinder : theBackBinFinder);
231 
232  typedef CompatibleDetToGroupAdder Adder;
233  int half = sLayer.size() / 2; // to check if dets are called twice....
234  for (int idet = negStartIndex; idet >= negStartIndex - half; idet--) {
235  const GeomDet& neighborDet = *sLayer[binFinder.binIndex(idet)];
236  if (!tkDetUtil::overlapInPhi(gCrossingPos, neighborDet, window))
237  break;
238  if (!Adder::add(neighborDet, tsos, prop, est, result))
239  break;
240  if (theFrontDetBrothers.empty() && theBackDetBrothers.empty())
241  break;
242  // If the two above checks are passed also the brother module will be added with no further checks
243  const GeomDet& neighborBrotherDet = *sBrotherLayer[binFinder.binIndex(idet)];
244  Adder::add(neighborBrotherDet, tsos, prop, est, brotherresult);
245  // maybe also add shallow crossing angle test here???
246  }
247  for (int idet = posStartIndex; idet < posStartIndex + half; idet++) {
248  const GeomDet& neighborDet = *sLayer[binFinder.binIndex(idet)];
249  if (!tkDetUtil::overlapInPhi(gCrossingPos, neighborDet, window))
250  break;
251  if (!Adder::add(neighborDet, tsos, prop, est, result))
252  break;
253  if (theFrontDetBrothers.empty() && theBackDetBrothers.empty())
254  break;
255  // If the two above checks are passed also the brother module will be added with no further checks
256  const GeomDet& neighborBrotherDet = *sBrotherLayer[binFinder.binIndex(idet)];
257  Adder::add(neighborBrotherDet, tsos, prop, est, brotherresult);
258  // maybe also add shallow crossing angle test here???
259  }
260 }
Common base class.
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
const std::vector< const GeometricSearchDet * > & components() const override __attribute__((cold))
Returns basic components, if any.
def window
Definition: svgfig.py:643
int binIndex(T phi) const override
returns an index in the valid range for the bin that contains phi
std::vector< const GeomDet * > theDets
int closestIndex() const
std::vector< const GeomDet * > theFrontDets
int closestDetIndex() const
std::vector< const GeomDet * > theFrontDetBrothers
GlobalPoint globalPosition() const
std::vector< const GeomDet * > theBackDets
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 std::vector< const GeomDet * > & subLayer(int ind) const
#define LogTrace(id)
tuple result
Definition: mps_fire.py:311
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::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
int subLayerIndex() const
ReferenceCountingPointer< BoundDisk > theFrontDisk
def move
Definition: eostools.py:511
BinFinderType theFrontBinFinder
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
ReferenceCountingPointer< BoundDisk > theDisk
const std::vector< const GeomDet * > & subLayerBrothers(int ind) const
std::vector< const GeomDet * > theBackDetBrothers
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, float window, std::vector< DetGroup > &result, std::vector< DetGroup > &brotherresult, bool checkClosest) const __attribute__((hot))
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))
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, std::vector< DetGroup > &brotherresult) const __attribute__((hot))
const SubLayerCrossing & closest() const
GlobalVector globalMomentum() const
~Phase2EndcapRing() override
string end
Definition: dataset.py:937
PeriodicBinFinderInPhi< float > BinFinderType
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
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
BinFinderType theBackBinFinder
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &, const Propagator &, const MeasurementEstimator &) const override
ReferenceCountingPointer< BoundDisk > theBackDisk
#define LogDebug(id)
Phase2EndcapRing(std::vector< const GeomDet * > &innerDets, std::vector< const GeomDet * > &outerDets, const std::vector< const GeomDet * > &innerDetBrothers=std::vector< const GeomDet * >(), const std::vector< const GeomDet * > &outerDetBrothers=std::vector< const GeomDet * >())