CMS 3D CMS Logo

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 TECWedge*> 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  inline
50  int findBin(std::vector<float> const & boundaries, float r) {
51  return
52  std::lower_bound(boundaries.begin()+1,boundaries.end(),r)
53  -boundaries.begin()-1;
54  }
55 
56 
57  void fillPars(std::vector<const TECWedge*> const & dets, std::vector<CompositeTECPetal::WedgePar> & pars) {
58 
59  for (auto gsdet : dets) {
60  const BoundDiskSector& wedgeSector = static_cast<const BoundDiskSector&>( gsdet->surface());
61  float wedgeMinZ = std::abs( wedgeSector.position().z()) - 0.5*wedgeSector.bounds().thickness();
62  float wedgeMaxZ = std::abs( wedgeSector.position().z()) + 0.5*wedgeSector.bounds().thickness();
63  float thetaWedgeMin = wedgeSector.innerRadius()/ wedgeMaxZ;
64  float thetaWedgeMax = wedgeSector.outerRadius()/ wedgeMinZ;
65  CompositeTECPetal::WedgePar apar = {gsdet->position().perp(),thetaWedgeMin,thetaWedgeMax};
66  pars.push_back(apar);
67  }
68  }
69 
70  inline
71  bool overlap( const GlobalPoint& gpos, const CompositeTECPetal::WedgePar & wpar, float ymax)
72  {
73  // this method is just a duplication of overlapInR
74  // adapeted for groupedCompatibleDets() needs
75 
76  // assume "fixed theta window", i.e. margin in local y = r is changing linearly with z
77  auto tsRadius = gpos.perp();
78  auto rmin = std::max(0.f,tsRadius-ymax);
79  auto zmax = std::abs(gpos.z())+10.f; // add 10 cm contingency
80  auto rmax = (tsRadius + ymax);
81  auto zmin = std::abs(gpos.z())-10.f;
82 
83 
84  // do the theta regions overlap ?
85 
86  return !( (rmin > zmax*wpar.thetaMax) | ( zmin*wpar.thetaMin > rmax) );
87 
88  }
89 
90  }
91 }
92 
93 
94 CompositeTECPetal::CompositeTECPetal(vector<const TECWedge*>& innerWedges,
95  vector<const TECWedge*>& outerWedges) :
97  theFrontComps(innerWedges),
98  theBackComps(outerWedges)
99 {
100  theComps.assign(theFrontComps.begin(),theFrontComps.end());
101  theComps.insert(theComps.end(),theBackComps.begin(),theBackComps.end());
102 
103  details::fillBoundaries( theFrontComps, theFrontBoundaries);
104  details::fillBoundaries( theBackComps, theBackBoundaries);
105  details::fillPars(theFrontComps, theFrontPars);
106  details::fillPars(theBackComps, theBackPars);
107 
108  for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
109  it!=theComps.end();it++){
110  theBasicComps.insert(theBasicComps.end(),
111  (**it).basicComponents().begin(),
112  (**it).basicComponents().end());
113  }
114 
115 
116  //the Wedge are already R ordered
117  //sort( theWedges.begin(), theWedges.end(), DetLessR());
118  //sort( theFrontWedges.begin(), theFrontWedges.end(), DetLessR() );
119  //sort( theBackWedges.begin(), theBackWedges.end(), DetLessR() );
120  vector<const TECWedge*> allWedges;
121  allWedges.assign(innerWedges.begin(),innerWedges.end());
122  allWedges.insert(allWedges.end(),outerWedges.begin(),outerWedges.end());
123 
127 
128  //--------- DEBUG INFO --------------
129  LogDebug("TkDetLayers") << "DEBUG INFO for CompositeTECPetal" ;
130 
131  for(auto it=theFrontComps.begin();
132  it!=theFrontComps.end(); it++){
133  LogDebug("TkDetLayers") << "frontWedge phi,z,r: "
134  << (*it)->surface().position().phi() << " , "
135  << (*it)->surface().position().z() << " , "
136  << (*it)->surface().position().perp() ;
137  }
138 
139  for(auto it=theBackComps.begin();
140  it!=theBackComps.end(); it++){
141  LogDebug("TkDetLayers") << "backWedge phi,z,r: "
142  << (*it)->surface().position().phi() << " , "
143  << (*it)->surface().position().z() << " , "
144  << (*it)->surface().position().perp() ;
145  }
146  //-----------------------------------
147 
148 
149 }
150 
151 
153  vector<const GeometricSearchDet*>::const_iterator i;
154  for (i=theComps.begin(); i!=theComps.end(); i++) {
155  delete *i;
156  }
157 }
158 
159 
160 pair<bool, TrajectoryStateOnSurface>
162  const MeasurementEstimator&) const{
163  edm::LogError("TkDetLayers") << "temporary dummy implementation of CompositeTECPetal::compatible()!!" ;
164  return pair<bool,TrajectoryStateOnSurface>();
165 }
166 
167 
168 void
170  const Propagator& prop,
171  const MeasurementEstimator& est,
172  std::vector<DetGroup> & result) const {
173 
174  vector<DetGroup> closestResult;
175  SubLayerCrossings crossings;
176  crossings = computeCrossings( tsos, prop.propagationDirection());
177  if(! crossings.isValid()) return;
178 
179  addClosest( tsos, prop, est, crossings.closest(), closestResult);
180  LogDebug("TkDetLayers") << "in TECPetal, closestResult.size(): "<< closestResult.size();
181 
182  if (closestResult.empty()){
183  vector<DetGroup> nextResult;
184  addClosest( tsos, prop, est, crossings.other(), nextResult);
185  LogDebug("TkDetLayers") << "in TECPetal, nextResult.size(): "<< nextResult.size() ;
186  if(nextResult.empty()) return;
187 
188  DetGroupElement nextGel( nextResult.front().front());
189  int crossingSide = LayerCrossingSide::endcapSide( nextGel.trajectoryState(), prop);
190  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
191  crossings.closestIndex(), crossingSide);
192  } else {
193 
194  DetGroupElement closestGel( closestResult.front().front());
195  float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
196 
197  searchNeighbors( tsos, prop, est, crossings.closest(), window,
198  closestResult, false);
199 
200  vector<DetGroup> nextResult;
201  searchNeighbors( tsos, prop, est, crossings.other(), window,
202  nextResult, true);
203 
204  int crossingSide = LayerCrossingSide::endcapSide( closestGel.trajectoryState(), prop);
205  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
206  crossings.closestIndex(), crossingSide);
207  }
208 }
209 
212  PropagationDirection propDir) const
213 {
214 
215  HelixPlaneCrossing::PositionType startPos( startingState.globalPosition() );
216  HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum() );
217 
218  auto rho = startingState.transverseCurvature();
219 
220  HelixForwardPlaneCrossing crossing(startPos,startDir,rho,propDir);
221 
222  pair<bool,double> frontPath = crossing.pathLength( *theFrontSector);
223  if (!frontPath.first) return SubLayerCrossings();
224 
225  pair<bool,double> backPath = crossing.pathLength(*theBackSector);
226  if (!backPath.first) return SubLayerCrossings();
227 
228  GlobalPoint gFrontPoint(crossing.position(frontPath.second));
229  GlobalPoint gBackPoint( crossing.position(backPath.second));
230 
231 
232  LogDebug("TkDetLayers")
233  << "in TECPetal,front crossing : r,z,phi: ("
234  << gFrontPoint.perp() << ","
235  << gFrontPoint.z() << ","
236  << gFrontPoint.phi() << ")";
237 
238  LogDebug("TkDetLayers")
239  << "in TECPetal,back crossing r,z,phi: ("
240  << gBackPoint.perp() << ","
241  << gBackPoint.z() << ","
242  << gBackPoint.phi() << ")" ;
243 
244 
245 
246  int frontIndex = findBin(gFrontPoint.perp(),0);
247  SubLayerCrossing frontSLC( 0, frontIndex, gFrontPoint);
248 
249  int backIndex = findBin(gBackPoint.perp(),1);
250  SubLayerCrossing backSLC( 1, backIndex, gBackPoint);
251 
252  auto frontDist = std::abs( theFrontPars[frontIndex].theR - gFrontPoint.perp());
253  auto backDist = std::abs( theBackPars[backIndex].theR - gBackPoint.perp());
254 
255 
256 
257  // 0ss: frontDisk has index=0, backDisk has index=1
258  if (frontDist < backDist) {
259  return SubLayerCrossings( frontSLC, backSLC, 0);
260  }
261  else {
262  return SubLayerCrossings( backSLC, frontSLC, 1);
263  }
264 }
265 
267  const Propagator& prop,
268  const MeasurementEstimator& est,
269  const SubLayerCrossing& crossing,
270  vector<DetGroup>& result) const
271 {
272 
273  auto det = subLayer( crossing.subLayerIndex())[crossing.closestDetIndex()];
274 
275  LogDebug("TkDetLayers")
276  << "in TECPetal, adding Wedge at r,z,phi: ("
277  << det->position().perp() << ","
278  << det->position().z() << ","
279  << det->position().phi() << ")" ;
280  LogDebug("TkDetLayers")
281  << "wedge comps size: "
282  << det->basicComponents().size();
283 
284  return CompatibleDetToGroupAdder::add( *det, tsos, prop, est, result);
285 }
286 
287 
288 
289 void
291  const Propagator& prop,
292  const MeasurementEstimator& est,
293  const SubLayerCrossing& crossing,
294  float window,
295  vector<DetGroup>& result,
296  bool checkClosest) const
297 {
298  const GlobalPoint& gCrossingPos = crossing.position();
299 
300 
301  int closestIndex = crossing.closestDetIndex();
302  int negStartIndex = closestIndex-1;
303  int posStartIndex = closestIndex+1;
304 
305  float detR = findPar(closestIndex,crossing.subLayerIndex()).theR;
306 
307  if (checkClosest) { // must decide if the closest is on the neg or pos side
308  if ( gCrossingPos.perp2() < detR*detR ) {
309  posStartIndex = closestIndex;
310  }
311  else {
312  negStartIndex = closestIndex;
313  }
314  }
315 
316  const std::vector<const TECWedge*>& sLayer = subLayer(crossing.subLayerIndex() );
317 
318  //const BinFinderType& binFinder = (crossing.subLayerIndex()==0 ? theFrontBinFinder : theBackBinFinder);
319  int theSize = crossing.subLayerIndex()==0 ? theFrontComps.size() : theBackComps.size();
320 
321  typedef CompatibleDetToGroupAdder Adder;
322  for (int idet=negStartIndex; idet >= 0; idet--) {
323  //if(idet<0 || idet>= theSize) {edm::LogInfo(TkDetLayers) << "===== error! gone out vector bounds.idet: " << idet ;exit;}
324  const GeometricSearchDet & neighborWedge = *sLayer[idet];
325  WedgePar const & wpar = findPar(idet, crossing.subLayerIndex());
326  if (!details::overlap( gCrossingPos, wpar, window)) break; // --- to check
327  if (!Adder::add( neighborWedge, tsos, prop, est, result)) break;
328  // maybe also add shallow crossing angle test here???
329  }
330  for (int idet=posStartIndex; idet <theSize; idet++) {
331  //if(idet<0 || idet>= theSize) {edm::LogInfo(TkDetLayers) << "===== error! gone out vector bounds.idet: " << idet ;exit;}
332  const GeometricSearchDet & neighborWedge = *sLayer[idet];
333  WedgePar const & wpar = findPar(idet, crossing.subLayerIndex());
334  if (!details::overlap( gCrossingPos, wpar, window)) break; // ---- to check
335  if (!Adder::add( neighborWedge, tsos, prop, est, result)) break;
336  // maybe also add shallow crossing angle test here???
337  }
338 }
339 
340 
341 
342 
343 
344 
346  const TrajectoryStateOnSurface& tsos,
347  const MeasurementEstimator& est)
348 {
349  return est.maximalLocalDisplacement(tsos, det->surface()).y();
350 }
351 
352 
353 int CompositeTECPetal::findBin( float R, int diskSectorType) const
354 {
355  return details::findBin(diskSectorType==0 ? theFrontBoundaries : theBackBoundaries,R);
356 }
357 
#define LogDebug(id)
std::vector< float > theFrontBoundaries
int findBin(float R, int layer) const
WedgePar const & findPar(int index, int diskSectorType) const
float innerRadius() const
T perp() const
Definition: PV3DBase.h:72
bool addClosest(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, const SubLayerCrossing &crossing, std::vector< DetGroup > &result) const __attribute__((hot))
int closestIndex() const
int closestDetIndex() const
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
CompositeTECPetal(std::vector< const TECWedge * > &innerWedges, std::vector< const TECWedge * > &outerWedges) __attribute__((cold))
GlobalPoint globalPosition() const
std::vector< const GeometricSearchDet * > theComps
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))
T perp2() const
Definition: PV3DBase.h:71
~CompositeTECPetal() override __attribute__((cold))
PropagationDirection
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
DiskSectorBounds const & bounds() const
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
GeometricSearchDet::DetWithState DetWithState
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:151
float outerRadius() const
int subLayerIndex() const
T z() const
Definition: PV3DBase.h:64
const std::vector< const TECWedge * > & subLayer(int ind) const
SubLayerCrossings computeCrossings(const TrajectoryStateOnSurface &tsos, PropagationDirection propDir) const __attribute__((hot))
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ReferenceCountingPointer< BoundDiskSector > theDiskSector
static int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop)
float thickness() const override
double f[11][100]
std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const override __attribute__((cold))
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
static float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) __attribute__((hot))
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)
ReferenceCountingPointer< BoundDiskSector > theFrontSector
std::vector< const TECWedge * > theFrontComps
virtual const Surface::PositionType & position() const
Returns position of the surface.
double b
Definition: hdecay.h:120
ReferenceCountingPointer< BoundDiskSector > theBackSector
std::pair< bool, double > pathLength(const Plane &plane) override
std::vector< WedgePar > theBackPars
const SubLayerCrossing & closest() const
GlobalVector globalMomentum() const
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0
double a
Definition: hdecay.h:121
std::vector< const GeomDet * > theBasicComps
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)
const PositionType & position() const
PositionType position(double s) const override
std::vector< float > theBackBoundaries
def move(src, dest)
Definition: eostools.py:510
std::vector< const TECWedge * > theBackComps
std::vector< WedgePar > theFrontPars