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