CMS 3D CMS Logo

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