CMS 3D CMS Logo

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