CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TECLayer.cc
Go to the documentation of this file.
1 #include "TECLayer.h"
2 
4 
6 #include "DetGroupMerger.h"
7 #include "LayerCrossingSide.h"
8 
14 #include "TkDetUtil.h"
15 
16 
17 using namespace std;
18 
20 
21 namespace {
22 
23  template<typename T>
24  BoundDisk*
25  computeDisk( vector<const T*>& petals) {
26  // Attention: it is assumed that the petals do belong to one layer, and are all
27  // of the same rmin/rmax extension !!
28 
29  const BoundDiskSector& diskSector = static_cast<const BoundDiskSector&>(petals.front()->surface());
30 
31  float rmin = diskSector.innerRadius();
32  float rmax = diskSector.outerRadius();
33 
34  float theZmax(petals.front()->position().z());
35  float theZmin(theZmax);
36  for ( auto i = petals.begin(); i != petals.end(); i++ ) {
37  float zmin = (**i).position().z() - (**i).surface().bounds().thickness()/2.;
38  float zmax = (**i).position().z() + (**i).surface().bounds().thickness()/2.;
39  theZmax = max( theZmax, zmax);
40  theZmin = min( theZmin, zmin);
41  }
42 
43  float zPos = (theZmax+theZmin)/2.;
44  Surface::PositionType pos(0.,0.,zPos);
46 
47  return new BoundDisk( pos, rot, new SimpleDiskBounds(rmin, rmax,
48  theZmin-zPos, theZmax-zPos));
49  }
50 
51 }
52 
53 
54 
55 
56 TECLayer::TECLayer(vector<const TECPetal*>& innerPetals,
57  vector<const TECPetal*>& outerPetals) :
59  theFrontComps(innerPetals.begin(),innerPetals.end()),
60  theBackComps(outerPetals.begin(),outerPetals.end())
61 {
62  theComps.assign(theFrontComps.begin(),theFrontComps.end());
63  theComps.insert(theComps.end(),theBackComps.begin(),theBackComps.end());
64 
65  for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
66  it!=theComps.end();it++){
67  theBasicComps.insert(theBasicComps.end(),
68  (**it).basicComponents().begin(),
69  (**it).basicComponents().end());
70  }
71 
72 
73  //This should be no necessary. TO BE CHECKED
74  //sort(theFrontPetals.begin(), theFrontPetals.end(), PetalLessPhi());
75  //sort(theBackPetals.begin(), theBackPetals.end(), PetalLessPhi());
76 
77  // building disk for front and back petals
78  setSurface( computeDisk( theComps ) );
79  theFrontDisk = computeDisk( theFrontComps);
80  theBackDisk = computeDisk( theBackComps);
81 
82  // set up the bin finders
83  theFrontBinFinder = BinFinderPhi(theFrontComps.front()->position().phi(),
84  theFrontComps.size());
85  theBackBinFinder = BinFinderPhi(theBackComps.front()->position().phi(),
86  theBackComps.size());
87 
88  //--------- DEBUG INFO --------------
89  LogDebug("TkDetLayers") << "DEBUG INFO for TECLayer" << "\n"
90  << "TECLayer z,perp, innerRadius, outerR: "
91  << this->position().z() << " , "
92  << this->position().perp() << " , "
93  << this->specificSurface().innerRadius() << " , "
94  << this->specificSurface().outerRadius() ;
95 
96 
97  for(auto it=theFrontComps.begin();
98  it!=theFrontComps.end(); it++){
99  LogDebug("TkDetLayers") << "frontPetal phi,z,r: "
100  << (*it)->surface().position().phi() << " , "
101  << (*it)->surface().position().z() << " , "
102  << (*it)->surface().position().perp() ;
103  }
104 
105  for(auto it=theBackComps.begin();
106  it!=theBackComps.end(); it++){
107  LogDebug("TkDetLayers") << "backPetal phi,z,r: "
108  << (*it)->surface().position().phi() << " , "
109  << (*it)->surface().position().z() << " , "
110  << (*it)->surface().position().perp() ;
111  }
112  //-----------------------------------
113 
114 
115 }
116 
117 
118 
120  for (auto i=theComps.begin(); i!=theComps.end(); i++) {
121  delete *i;
122  }
123 }
124 
125 
126 void
128  const Propagator& prop,
129  const MeasurementEstimator& est,
130  std::vector<DetGroup> & result) const {
131  SubLayerCrossings crossings;
132  crossings = computeCrossings( tsos, prop.propagationDirection());
133  if(! crossings.isValid()) return;
134 
135  vector<DetGroup> closestResult;
136  addClosest( tsos, prop, est, crossings.closest(), closestResult);
137  LogDebug("TkDetLayers") << "in TECLayer, closestResult.size(): " << closestResult.size();
138 
139  // this differs from other groupedCompatibleDets logic, which DON'T check next in such cases!!!
140  if(closestResult.empty()){
141  vector<DetGroup> nextResult;
142  addClosest( tsos, prop, est, crossings.other(), nextResult);
143  LogDebug("TkDetLayers") << "in TECLayer, nextResult.size(): " << nextResult.size();
144  if(nextResult.empty()) return;
145 
146 
147  DetGroupElement nextGel( nextResult.front().front());
148  int crossingSide = LayerCrossingSide::endcapSide( nextGel.trajectoryState(), prop);
149  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
150  crossings.closestIndex(), crossingSide);
151  }
152  else {
153  DetGroupElement closestGel( closestResult.front().front());
154  float phiWindow = tkDetUtil::computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
155  searchNeighbors( tsos, prop, est, crossings.closest(), phiWindow,
156  closestResult, false);
157  vector<DetGroup> nextResult;
158  searchNeighbors( tsos, prop, est, crossings.other(), phiWindow,
159  nextResult, true);
160 
161  int crossingSide = LayerCrossingSide::endcapSide( closestGel.trajectoryState(), prop);
162  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
163  crossings.closestIndex(), crossingSide);
164  }
165 }
166 
168  PropagationDirection propDir) const
169 {
170  double rho( startingState.transverseCurvature());
171 
172  HelixPlaneCrossing::PositionType startPos( startingState.globalPosition() );
173  HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum() );
174  HelixForwardPlaneCrossing crossing(startPos,startDir,rho,propDir);
175 
176  pair<bool,double> frontPath = crossing.pathLength( *theFrontDisk);
177  if (!frontPath.first) SubLayerCrossings();
178 
179 
180  GlobalPoint gFrontPoint(crossing.position(frontPath.second));
181 
182  LogDebug("TkDetLayers")
183  << "in TECLayer,front crossing point: r,z,phi: ("
184  << gFrontPoint.perp() << ","
185  << gFrontPoint.z() << ","
186  << gFrontPoint.phi() << ")" << endl;
187 
188 
189  int frontIndex = theFrontBinFinder.binIndex(gFrontPoint.barePhi());
190  SubLayerCrossing frontSLC( 0, frontIndex, gFrontPoint);
191 
192 
193 
194  pair<bool,double> backPath = crossing.pathLength( *theBackDisk);
195  if (!backPath.first) SubLayerCrossings();
196 
197 
198  GlobalPoint gBackPoint( crossing.position(backPath.second));
199  LogDebug("TkDetLayers")
200  << "in TECLayer,back crossing point: r,z,phi: ("
201  << gBackPoint.perp() << ","
202  << gFrontPoint.z() << ","
203  << gBackPoint.phi() << ")" << endl;
204 
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  theFrontComps[frontIndex]->surface().phi()) );
213  float backDist = std::abs(Geom::deltaPhi( gBackPoint.barePhi(),
214  theBackComps[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) const
230 {
231  const auto & sub( subLayer( crossing.subLayerIndex()));
232  const auto det(sub[crossing.closestDetIndex()]);
233 
234  LogDebug("TkDetLayers")
235  << "in TECLayer, adding petal at r,z,phi: ("
236  << det->position().perp() << ","
237  << det->position().z() << ","
238  << det->position().phi() << ")" << endl;
239 
240  return CompatibleDetToGroupAdder().add( *det, tsos, prop, est, result);
241 }
242 
243 
244 namespace {
245  inline
246  bool overlap(float phi, const TECPetal& gsdet, float phiWin) {
247 
248  const BoundDiskSector & diskSector = gsdet.specificSurface();
249  pair<float,float> phiRange(phi-phiWin,phi+phiWin);
250  pair<float,float> petalPhiRange(diskSector.phi() - diskSector.phiHalfExtension(),
251  diskSector.phi() + diskSector.phiHalfExtension());
252 
253 
254  return rangesIntersect(phiRange, petalPhiRange, PhiLess());
255  }
256 
257 }
258 
260  const Propagator& prop,
261  const MeasurementEstimator& est,
262  const SubLayerCrossing& crossing,
263  float window,
264  vector<DetGroup>& result,
265  bool checkClosest) const
266 {
267  GlobalPoint gCrossingPos = crossing.position();
268  auto gphi = gCrossingPos.barePhi();
269 
270  const auto & sLayer( subLayer( crossing.subLayerIndex()));
271 
272  int closestIndex = crossing.closestDetIndex();
273  int negStartIndex = closestIndex-1;
274  int posStartIndex = closestIndex+1;
275 
276  if (checkClosest) { // must decide if the closest is on the neg or pos side
277  if ( PhiLess()( gphi, sLayer[closestIndex]->surface().phi())) {
278  posStartIndex = closestIndex;
279  }
280  else {
281  negStartIndex = closestIndex;
282  }
283  }
284 
285  const BinFinderPhi& binFinder = (crossing.subLayerIndex()==0 ? theFrontBinFinder : theBackBinFinder);
286 
287  typedef CompatibleDetToGroupAdder Adder;
288  int half = sLayer.size()/2; // to check if dets are called twice....
289  for (int idet=negStartIndex; idet >= negStartIndex - half; idet--) {
290  const auto & neighborPetal = *sLayer[binFinder.binIndex(idet)];
291  if (!overlap( gphi, neighborPetal, window)) break;
292  if (!Adder::add( neighborPetal, tsos, prop, est, result)) break;
293  // maybe also add shallow crossing angle test here???
294  }
295  for (int idet=posStartIndex; idet < posStartIndex + half; idet++) {
296  const auto & neighborPetal = *sLayer[binFinder.binIndex(idet)];
297  if (!overlap( gphi, neighborPetal, window)) break;
298  if (!Adder::add( neighborPetal, tsos, prop, est, result)) break;
299  // maybe also add shallow crossing angle test here???
300  }
301 }
302 
303 
304 
305 
306 
307 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::vector< const TECPetal * > theBackComps
Definition: TECLayer.h:72
def window
Definition: svgfig.py:642
float innerRadius() const
T perp() const
Definition: PV3DBase.h:72
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:155
std::vector< const GeomDet * > theBasicComps
Definition: TECLayer.h:69
int closestIndex() const
int closestDetIndex() const
double zPos
virtual const BoundSurface & surface() const
The surface of the GeometricSearchDet.
void setSurface(BoundDisk *cp)
Definition: DDAxes.h:10
GlobalPoint globalPosition() const
float phiHalfExtension() const
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
ReferenceCountingPointer< BoundDisk > theFrontDisk
Definition: TECLayer.h:75
PropagationDirection
virtual const BoundDiskSector & specificSurface() const final
const std::vector< const TECPetal * > & subLayer(int ind) const
Definition: TECLayer.h:61
virtual int binIndex(T phi) const
returns an index in the valid range for the bin that contains phi
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
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
std::vector< const GeometricSearchDet * > theComps
Definition: TECLayer.h:68
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))
Definition: TECLayer.cc:259
ReferenceCountingPointer< BoundDisk > theBackDisk
Definition: TECLayer.h:76
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: TECLayer.cc:225
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &startingState, PropagationDirection propDir) const __attribute__((hot))
Definition: TECLayer.cc:167
float outerRadius() const
bool rangesIntersect(const Range &a, const Range &b)
int subLayerIndex() const
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
virtual const BoundDisk & specificSurface() const
~TECLayer() __attribute__((cold))
Definition: TECLayer.cc:119
BinFinderPhi theBackBinFinder
Definition: TECLayer.h:81
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
TECLayer(std::vector< const TECPetal * > &innerPetals, std::vector< const TECPetal * > &outerPetals) __attribute__((cold))
Definition: TECLayer.cc:56
#define end
Definition: vmac.h:37
T min(T a, T b)
Definition: MathUtil.h:58
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
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))
virtual const Surface::PositionType & position() const
Returns position of the surface.
BinFinderPhi theFrontBinFinder
Definition: TECLayer.h:80
Disk BoundDisk
Definition: BoundDisk.h:62
const SubLayerCrossing & closest() const
#define begin
Definition: vmac.h:30
GlobalVector globalMomentum() const
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const __attribute__((hot))
Definition: TECLayer.cc:127
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
std::vector< const TECPetal * > theFrontComps
Definition: TECLayer.h:71
PeriodicBinFinderInPhi< float > BinFinderPhi
Definition: TECLayer.h:78
Definition: DDAxes.h:10