CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CompositeTECPetal.cc
Go to the documentation of this file.
1 #include "CompositeTECPetal.h"
2 
4 
6 #include "LayerCrossingSide.h"
7 #include "DetGroupMerger.h"
9 
13 
14 #include "TkDetUtil.h"
16 
17 #include <boost/function.hpp>
18 #include <boost/bind.hpp>
19 #include<algorithm>
20 #include<numeric>
21 #include<iterator>
22 
23 using namespace std;
24 
26 
27 
28 namespace {
29 namespace details {
30 
31  struct Mean {
32  float operator()(const GeometricSearchDet* a, const GeometricSearchDet* b) const {
33  return 0.5*(b->position().perp()+a->position().perp());
34  }
35  float operator()(float a, float b) const {
36  return 0.5*(b+a);
37  }
38  };
39 
40  void fillBoundaries(std::vector<const GeometricSearchDet*> const & dets,
41  std::vector<float> & boundaries) {
42  boundaries.resize(dets.size());
43  std::transform(dets.begin(), dets.end(), boundaries.begin(),
44  boost::bind(&GlobalPoint::perp,boost::bind(&GeometricSearchDet::position,_1))
45  );
46  std::adjacent_difference(boundaries.begin(),boundaries.end(), boundaries.begin(), Mean());
47  }
48 
49  int findBin(std::vector<float> const & boundaries, float r) {
50  return
51  std::lower_bound(boundaries.begin()+1,boundaries.end(),r)
52  -boundaries.begin()-1;
53  }
54 
55 }
56 }
57 
58 CompositeTECPetal::CompositeTECPetal(vector<const TECWedge*>& innerWedges,
59  vector<const TECWedge*>& outerWedges) :
60  theFrontComps(innerWedges.begin(),innerWedges.end()),
61  theBackComps(outerWedges.begin(),outerWedges.end())
62 {
63  theComps.assign(theFrontComps.begin(),theFrontComps.end());
64  theComps.insert(theComps.end(),theBackComps.begin(),theBackComps.end());
65 
66  details::fillBoundaries( theFrontComps, theFrontBoundaries);
67  details::fillBoundaries( theBackComps, theBackBoundaries);
68 
69 
70  for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
71  it!=theComps.end();it++){
72  theBasicComps.insert(theBasicComps.end(),
73  (**it).basicComponents().begin(),
74  (**it).basicComponents().end());
75  }
76 
77 
78  //the Wedge are already R ordered
79  //sort( theWedges.begin(), theWedges.end(), DetLessR());
80  //sort( theFrontWedges.begin(), theFrontWedges.end(), DetLessR() );
81  //sort( theBackWedges.begin(), theBackWedges.end(), DetLessR() );
82  vector<const TECWedge*> allWedges;
83  allWedges.assign(innerWedges.begin(),innerWedges.end());
84  allWedges.insert(allWedges.end(),outerWedges.begin(),outerWedges.end());
85 
89 
90  //--------- DEBUG INFO --------------
91  LogDebug("TkDetLayers") << "DEBUG INFO for CompositeTECPetal" ;
92 
93  for(vector<const GeometricSearchDet*>::const_iterator it=theFrontComps.begin();
94  it!=theFrontComps.end(); it++){
95  LogDebug("TkDetLayers") << "frontWedge phi,z,r: "
96  << (*it)->surface().position().phi() << " , "
97  << (*it)->surface().position().z() << " , "
98  << (*it)->surface().position().perp() ;
99  }
100 
101  for(vector<const GeometricSearchDet*>::const_iterator it=theBackComps.begin();
102  it!=theBackComps.end(); it++){
103  LogDebug("TkDetLayers") << "backWedge phi,z,r: "
104  << (*it)->surface().position().phi() << " , "
105  << (*it)->surface().position().z() << " , "
106  << (*it)->surface().position().perp() ;
107  }
108  //-----------------------------------
109 
110 
111 }
112 
113 
115  vector<const GeometricSearchDet*>::const_iterator i;
116  for (i=theComps.begin(); i!=theComps.end(); i++) {
117  delete *i;
118  }
119 }
120 
121 
122 pair<bool, TrajectoryStateOnSurface>
124  const MeasurementEstimator&) const{
125  edm::LogError("TkDetLayers") << "temporary dummy implementation of CompositeTECPetal::compatible()!!" ;
126  return pair<bool,TrajectoryStateOnSurface>();
127 }
128 
129 
130 void
132  const Propagator& prop,
133  const MeasurementEstimator& est,
134  std::vector<DetGroup> & result) const {
135 
136  vector<DetGroup> closestResult;
137  SubLayerCrossings crossings;
138  crossings = computeCrossings( tsos, prop.propagationDirection());
139  if(! crossings.isValid()) return;
140 
141  addClosest( tsos, prop, est, crossings.closest(), closestResult);
142  LogDebug("TkDetLayers") << "in TECPetal, closestResult.size(): "<< closestResult.size();
143 
144  if (closestResult.empty()){
145  vector<DetGroup> nextResult;
146  addClosest( tsos, prop, est, crossings.other(), nextResult);
147  LogDebug("TkDetLayers") << "in TECPetal, nextResult.size(): "<< nextResult.size() ;
148  if(nextResult.empty()) return;
149 
150  DetGroupElement nextGel( nextResult.front().front());
151  int crossingSide = LayerCrossingSide().endcapSide( nextGel.trajectoryState(), prop);
152  DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result,
153  crossings.closestIndex(), crossingSide);
154  } else {
155 
156  DetGroupElement closestGel( closestResult.front().front());
157  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
158 
159  searchNeighbors( tsos, prop, est, crossings.closest(), window,
160  closestResult, false);
161 
162  vector<DetGroup> nextResult;
163  searchNeighbors( tsos, prop, est, crossings.other(), window,
164  nextResult, true);
165 
166  int crossingSide = LayerCrossingSide().endcapSide( closestGel.trajectoryState(), prop);
167  DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result,
168  crossings.closestIndex(), crossingSide);
169  }
170 }
171 
174  PropagationDirection propDir) const
175 {
176  double rho( startingState.transverseCurvature());
177 
178  HelixPlaneCrossing::PositionType startPos( startingState.globalPosition() );
179  HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum() );
180  HelixForwardPlaneCrossing crossing(startPos,startDir,rho,propDir);
181  pair<bool,double> frontPath = crossing.pathLength( *theFrontSector);
182 
183  if (!frontPath.first) return SubLayerCrossings();
184 
185  GlobalPoint gFrontPoint(crossing.position(frontPath.second));
186  LogDebug("TkDetLayers")
187  << "in TECPetal,front crossing : r,z,phi: ("
188  << gFrontPoint.perp() << ","
189  << gFrontPoint.z() << ","
190  << gFrontPoint.phi() << ")";
191 
192 
193  int frontIndex = findBin(gFrontPoint.perp(),0);
194  float frontDist = fabs( findPosition(frontIndex,0).perp() - gFrontPoint.perp());
195  SubLayerCrossing frontSLC( 0, frontIndex, gFrontPoint);
196 
197 
198 
199  pair<bool,double> backPath = crossing.pathLength( *theBackSector);
200 
201  if (!backPath.first) return SubLayerCrossings();
202 
203 
204  GlobalPoint gBackPoint( crossing.position(backPath.second));
205  LogDebug("TkDetLayers")
206  << "in TECPetal,back crossing r,z,phi: ("
207  << gBackPoint.perp() << ","
208  << gBackPoint.z() << ","
209  << gBackPoint.phi() << ")" ;
210 
211  int backIndex = findBin(gBackPoint.perp(),1);
212  float backDist = fabs( findPosition(backIndex,1).perp() - gBackPoint.perp());
213 
214  SubLayerCrossing backSLC( 1, backIndex, gBackPoint);
215 
216 
217  // 0ss: frontDisk has index=0, backDisk has index=1
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) const
231 {
232  const vector<const GeometricSearchDet*>& sub( subLayer( crossing.subLayerIndex()));
233  const GeometricSearchDet* det(sub[crossing.closestDetIndex()]);
234 
235  LogDebug("TkDetLayers")
236  << "in TECPetal, adding Wedge at r,z,phi: ("
237  << det->position().perp() << ","
238  << det->position().z() << ","
239  << det->position().phi() << ")" ;
240  LogDebug("TkDetLayers")
241  << "wedge comps size: "
242  << det->basicComponents().size();
243 
244  return CompatibleDetToGroupAdder::add( *det, tsos, prop, est, result);
245 }
246 
247 
248 
249 void
251  const Propagator& prop,
252  const MeasurementEstimator& est,
253  const SubLayerCrossing& crossing,
254  float window,
255  vector<DetGroup>& result,
256  bool checkClosest) const
257 {
258  GlobalPoint gCrossingPos = crossing.position();
259 
260  const vector<const GeometricSearchDet*>& sLayer( subLayer( crossing.subLayerIndex()));
261 
262  int closestIndex = crossing.closestDetIndex();
263  int negStartIndex = closestIndex-1;
264  int posStartIndex = closestIndex+1;
265 
266  if (checkClosest) { // must decide if the closest is on the neg or pos side
267  if ( gCrossingPos.perp() < sLayer[closestIndex]->position().perp() ) {
268  posStartIndex = closestIndex;
269  }
270  else {
271  negStartIndex = closestIndex;
272  }
273  }
274 
275 
276  //const BinFinderType& binFinder = (crossing.subLayerIndex()==0 ? theFrontBinFinder : theBackBinFinder);
277  int theSize = crossing.subLayerIndex()==0 ? theFrontComps.size() : theBackComps.size();
278 
279  typedef CompatibleDetToGroupAdder Adder;
280  for (int idet=negStartIndex; idet >= 0; idet--) {
281  //if(idet<0 || idet>= theSize) {edm::LogInfo(TkDetLayers) << "===== error! gone out vector bounds.idet: " << idet ;exit;}
282  const GeometricSearchDet & neighborWedge = *sLayer[idet];
283  if (!overlap( gCrossingPos, neighborWedge, window)) break; // --- to check
284  if (!Adder::add( neighborWedge, tsos, prop, est, result)) break;
285  // maybe also add shallow crossing angle test here???
286  }
287  for (int idet=posStartIndex; idet <theSize; idet++) {
288  //if(idet<0 || idet>= theSize) {edm::LogInfo(TkDetLayers) << "===== error! gone out vector bounds.idet: " << idet ;exit;}
289  const GeometricSearchDet & neighborWedge = *sLayer[idet];
290  if (!overlap( gCrossingPos, neighborWedge, window)) break; // ---- to check
291  if (!Adder::add( neighborWedge, tsos, prop, est, result)) break;
292  // maybe also add shallow crossing angle test here???
293  }
294 }
295 
296 bool
297 CompositeTECPetal::overlap( const GlobalPoint& gpos, const GeometricSearchDet& gsdet, float ymax)
298 {
299  // this method is just a duplication of overlapInR
300  // adapeted for groupedCompatibleDets() needs
301 
302  // assume "fixed theta window", i.e. margin in local y = r is changing linearly with z
303  float tsRadius = gpos.perp();
304  float thetamin = ( max((float)0.,tsRadius-ymax))/(fabs(gpos.z())+10.); // add 10 cm contingency
305  float thetamax = ( tsRadius + ymax)/(fabs(gpos.z())-10.);
306 
307  const BoundDiskSector& wedgeSector = static_cast<const BoundDiskSector&>( gsdet.surface());
308  float wedgeMinZ = fabs( wedgeSector.position().z()) - 0.5*wedgeSector.bounds().thickness();
309  float wedgeMaxZ = fabs( wedgeSector.position().z()) + 0.5*wedgeSector.bounds().thickness();
310  float thetaWedgeMin = wedgeSector.innerRadius()/ wedgeMaxZ;
311  float thetaWedgeMax = wedgeSector.outerRadius()/ wedgeMinZ;
312 
313  // do the theta regions overlap ?
314 
315  return !( thetamin > thetaWedgeMax || thetaWedgeMin > thetamax);
316 
317 }
318 
319 
320 
321 
322 
324  const TrajectoryStateOnSurface& tsos,
325  const MeasurementEstimator& est)
326 {
327  return est.maximalLocalDisplacement(tsos, det->surface()).y();
328 }
329 
330 
331 int CompositeTECPetal::findBin( float R, int diskSectorType) const
332 {
333  return details::findBin(diskSectorType==0 ? theFrontBoundaries : theBackBoundaries,R);
334 }
335 
336 
337 
338 
339 GlobalPoint CompositeTECPetal::findPosition(int index,int diskSectorType) const
340 {
341  vector<const GeometricSearchDet*> const & diskSector = diskSectorType == 0 ? theFrontComps : theBackComps;
342  return (diskSector[index])->position();
343 }
344 
#define LogDebug(id)
std::vector< float > theFrontBoundaries
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
int i
Definition: DBlmapReader.cc:9
static void orderAndMergeTwoLevels(const std::vector< DetGroup > &one, const std::vector< DetGroup > &two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
int findBin(float R, int layer) const
def window
Definition: svgfig.py:642
std::vector< const GeometricSearchDet * > theFrontComps
virtual float thickness() const
float innerRadius() const
T perp() const
Definition: PV3DBase.h:71
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:143
int closestIndex() const
int closestDetIndex() const
Definition: DDAxes.h:10
const std::vector< const GeometricSearchDet * > & subLayer(int ind) const
GlobalPoint globalPosition() const
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
std::vector< const GeometricSearchDet * > theComps
static bool overlap(const GlobalPoint &gpos, const GeometricSearchDet &rod, float window)
PropagationDirection
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const BoundPlane &plane) const
void searchNeighbors(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, float window, std::vector< DetGroup > &result, bool checkClosest) const
DiskSectorBounds const & bounds() const
const GlobalPoint & position() const
int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop) const
CompositeTECPetal(std::vector< const TECWedge * > &innerWedges, std::vector< const TECWedge * > &outerWedges)
const T & max(const T &a, const T &b)
float outerRadius() const
int subLayerIndex() const
T z() const
Definition: PV3DBase.h:63
tuple result
Definition: query.py:137
#define end
Definition: vmac.h:38
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
std::vector< const GeometricSearchDet * > theBackComps
static float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
const SubLayerCrossing & other() const
ReferenceCountingPointer< BoundDiskSector > theFrontSector
GlobalPoint findPosition(int index, int diskSectorIndex) const
virtual const Surface::PositionType & position() const
Returns position of the surface.
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const
double b
Definition: hdecay.h:120
ReferenceCountingPointer< BoundDiskSector > theBackSector
static bool add(const GeometricSearchDet &det, const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result)
virtual std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const
ReferenceCountingPointer< BoundDiskSector > theDiskSector
Definition: TECPetal.h:25
const SubLayerCrossing & closest() const
T perp() const
Magnitude of transverse component.
#define begin
Definition: vmac.h:31
GlobalVector globalMomentum() const
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
double a
Definition: hdecay.h:121
std::vector< const GeomDet * > theBasicComps
virtual void groupedCompatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
const PositionType & position() const
std::vector< float > theBackBoundaries