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