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