CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CompositeTECWedge.cc
Go to the documentation of this file.
1 #include "CompositeTECWedge.h"
2 
4 
6 #include "LayerCrossingSide.h"
7 #include "DetGroupMerger.h"
9 
11 
15 
16 #include "TkDetUtil.h"
18 #include <boost/function.hpp>
19 
20 using namespace std;
21 
23 
24 // --------- Temporary solution. DetSorting.h has to be used.
25 namespace {
26  class DetPhiLess {
27  public:
28  bool operator()(const GeomDet* a,const GeomDet* b)
29  {
30  return Geom::phiLess(a->surface(), b->surface());
31  }
32  };
33 }
34 // ---------------------
35 
36 CompositeTECWedge::CompositeTECWedge(vector<const GeomDet*>& innerDets,
37  vector<const GeomDet*>& outerDets):
38  theFrontDets(innerDets.begin(),innerDets.end()), theBackDets(outerDets.begin(),outerDets.end())
39 {
40  theDets.assign(theFrontDets.begin(),theFrontDets.end());
41  theDets.insert(theDets.end(),theBackDets.begin(),theBackDets.end());
42 
43 
44  //
45  std::sort( theFrontDets.begin(), theFrontDets.end(), DetPhiLess() );
46  std::sort( theBackDets.begin(), theBackDets.end(), DetPhiLess() );
47 
48  theFrontSector = ForwardDiskSectorBuilderFromDet()( theFrontDets );
49  theBackSector = ForwardDiskSectorBuilderFromDet()( theBackDets );
50  theDiskSector = ForwardDiskSectorBuilderFromDet()( theDets );
51 
52  //--------- DEBUG INFO --------------
53  LogDebug("TkDetLayers") << "DEBUG INFO for CompositeTECWedge" << "\n"
54  << "TECWedge z, perp,innerRadius,outerR: "
55  << this->position().z() << " , "
56  << this->position().perp() << " , "
57  << theDiskSector->innerRadius() << " , "
58  << theDiskSector->outerRadius() ;
59 
60 
61  for(vector<const GeomDet*>::const_iterator it=theFrontDets.begin();
62  it!=theFrontDets.end(); it++){
63  LogDebug("TkDetLayers") << "frontDet phi,z,r: "
64  << (*it)->surface().position().phi() << " , "
65  << (*it)->surface().position().z() << " , "
66  << (*it)->surface().position().perp();
67  }
68 
69  for(vector<const GeomDet*>::const_iterator it=theBackDets.begin();
70  it!=theBackDets.end(); it++){
71  LogDebug("TkDetLayers") << "backDet phi,z,r: "
72  << (*it)->surface().phi() << " , "
73  << (*it)->surface().position().z() << " , "
74  << (*it)->surface().position().perp() ;
75  }
76  //-----------------------------------
77 
78 
79 }
80 
81 CompositeTECWedge::~CompositeTECWedge(){
82 
83 }
84 
85 
86 const vector<const GeometricSearchDet*>&
88  throw DetLayerException("CompositeTECWedge doesn't have GeometricSearchDet components");
89 }
90 
91 
92 pair<bool, TrajectoryStateOnSurface>
93 CompositeTECWedge::compatible( const TrajectoryStateOnSurface& ts, const Propagator&,
94  const MeasurementEstimator&) const{
95  edm::LogError("TkDetLayers") << "temporary dummy implementation of CompositeTECWedge::compatible()!!" ;
96  return pair<bool,TrajectoryStateOnSurface>();
97 }
98 
99 
100 void
101 CompositeTECWedge::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
102  const Propagator& prop,
103  const MeasurementEstimator& est,
104  std::vector<DetGroup> & result) const{
105  SubLayerCrossings crossings;
106  crossings = computeCrossings( tsos, prop.propagationDirection());
107  if(! crossings.isValid()) return;
108 
109  std::vector<DetGroup> closestResult;
110  addClosest( tsos, prop, est, crossings.closest(), closestResult);
111  LogDebug("TkDetLayers")
112  << "in CompositeTECWedge::groupedCompatibleDets,closestResult.size(): "
113  << closestResult.size() ;
114 
115  if (closestResult.empty()) return;
116 
117  DetGroupElement closestGel( closestResult.front().front());
118  float window = tkDetUtil::computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
119 
120  searchNeighbors( tsos, prop, est, crossings.closest(), window,
121  closestResult, false);
122 
123  vector<DetGroup> nextResult;
124  searchNeighbors( tsos, prop, est, crossings.other(), window,
125  nextResult, true);
126 
127  int crossingSide = LayerCrossingSide().endcapSide( closestGel.trajectoryState(), prop);
128  DetGroupMerger::orderAndMergeTwoLevels( std::move(closestResult), std::move(nextResult), result,
129  crossings.closestIndex(), crossingSide);
130 }
131 
132 
133 
134 // private methods for the implementation of groupedCompatibleDets()
135 
136 
137 
139 CompositeTECWedge::computeCrossings( const TrajectoryStateOnSurface& startingState,
140  PropagationDirection propDir) const
141 {
142  HelixPlaneCrossing::PositionType startPos( startingState.globalPosition() );
143  HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum() );
144  float rho( startingState.transverseCurvature());
145 
146  HelixForwardPlaneCrossing crossing( startPos, startDir, rho, propDir);
147 
148  pair<bool,double> frontPath = crossing.pathLength( *theFrontSector);
149  if (!frontPath.first) return SubLayerCrossings();
150 
151  GlobalPoint gFrontPoint( crossing.position(frontPath.second));
152  LogDebug("TkDetLayers") << "in TECWedge,front crossing r,z,phi: ("
153  << gFrontPoint.perp() << ","
154  << gFrontPoint.z() << ","
155  << gFrontPoint.phi() << ")" ;
156 
157 
158  int frontIndex = findClosestDet(gFrontPoint,0);
159  SubLayerCrossing frontSLC( 0, frontIndex, gFrontPoint);
160 
161  pair<bool,double> backPath = crossing.pathLength( *theBackSector);
162  if (!backPath.first) return SubLayerCrossings();
163 
164  GlobalPoint gBackPoint( crossing.position(backPath.second));
165  LogDebug("TkDetLayers")
166  << "in TECWedge,back crossing r,z,phi: ("
167  << gBackPoint.perp() << ","
168  << gBackPoint.z() << ","
169  << gBackPoint.phi() << ")" << endl;
170 
171  int backIndex = findClosestDet(gBackPoint,1);
172  SubLayerCrossing backSLC( 1, backIndex, gBackPoint);
173 
174  float frontDist = std::abs(Geom::deltaPhi( double(gFrontPoint.barePhi()),
175  double(theFrontDets[frontIndex]->surface().phi())));
176  /*
177  float frontDist = theFrontDets[frontIndex]->surface().phi() - gFrontPoint.phi();
178  frontDist *= Geom::phiLess( theFrontDets[frontIndex]->surface().phi(),gFrontPoint.barePhi()) ? -1. : 1.;
179  if (frontDist < 0.) { frontDist += 2.*Geom::pi();}
180  */
181  float backDist = std::abs(Geom::deltaPhi( double(gBackPoint.barePhi()),
182  double(theBackDets[backIndex]->surface().phi())));
183  /*
184  float backDist = theBackDets[backIndex]->surface().phi() - gBackPoint.phi();
185  backDist *= Geom::phiLess( theBackDets[backIndex]->surface().phi(),gBackPoint.barePhi()) ? -1. : 1.;
186  if ( backDist < 0.) { backDist += 2.*Geom::pi();}
187  */
188 
189  if (frontDist < backDist) {
190  return SubLayerCrossings( frontSLC, backSLC, 0);
191  }
192  else {
193  return SubLayerCrossings( backSLC, frontSLC, 1);
194  }
195 }
196 
197 
198 bool CompositeTECWedge::addClosest( const TrajectoryStateOnSurface& tsos,
199  const Propagator& prop,
200  const MeasurementEstimator& est,
201  const SubLayerCrossing& crossing,
202  vector<DetGroup>& result) const
203 {
204  const vector<const GeomDet*>& sWedge( subWedge( crossing.subLayerIndex()));
205 
206  LogDebug("TkDetLayers")
207  << "in CompositeTECWedge,adding GeomDet at r,z,phi: ("
208  << sWedge[crossing.closestDetIndex()]->position().perp() << ","
209  << sWedge[crossing.closestDetIndex()]->position().z() << ","
210  << sWedge[crossing.closestDetIndex()]->position().phi() << ")" ;
211 
212  return CompatibleDetToGroupAdder().add( *sWedge[crossing.closestDetIndex()],
213  tsos, prop, est, result);
214 }
215 
216 
217 void CompositeTECWedge::searchNeighbors( const TrajectoryStateOnSurface& tsos,
218  const Propagator& prop,
219  const MeasurementEstimator& est,
220  const SubLayerCrossing& crossing,
221  float window,
222  vector<DetGroup>& result,
223  bool checkClosest) const
224 {
225  GlobalPoint gCrossingPos = crossing.position();
226 
227  const vector<const GeomDet*>& sWedge( subWedge( crossing.subLayerIndex()));
228 
229  int closestIndex = crossing.closestDetIndex();
230  int negStartIndex = closestIndex-1;
231  int posStartIndex = closestIndex+1;
232 
233  if (checkClosest) { // must decide if the closest is on the neg or pos side
234  if ( Geom::phiLess(gCrossingPos.barePhi(), sWedge[closestIndex]->surface().phi()) ) {
235  posStartIndex = closestIndex;
236  }
237  else {
238  negStartIndex = closestIndex;
239  }
240  }
241 
242  typedef CompatibleDetToGroupAdder Adder;
243  for (int idet=negStartIndex; idet >= 0; idet--) {
244  //if(idet <0 || idet>=sWedge.size()) {edm::LogInfo(TkDetLayers) << "==== warning! gone out vector bounds.idet: " << idet ;break;}
245  if (!tkDetUtil::overlapInPhi( gCrossingPos, *sWedge[idet], window)) break;
246  if (!Adder::add( *sWedge[idet], tsos, prop, est, result)) break;
247  }
248  for (int idet=posStartIndex; idet < static_cast<int>(sWedge.size()); idet++) {
249  //if(idet <0 || idet>=sWedge.size()) {edm::LogInfo(TkDetLayers) << "==== warning! gone out vector bounds.idet: " << idet ;break;}
250  if (!tkDetUtil::overlapInPhi( gCrossingPos, *sWedge[idet], window)) break;
251  if (!Adder::add( *sWedge[idet], tsos, prop, est, result)) break;
252  }
253 }
254 
255 
256 
257 int
258 CompositeTECWedge::findClosestDet( const GlobalPoint& startPos,int sectorId) const
259 {
260  vector<const GeomDet*> const & myDets = sectorId==0 ? theFrontDets : theBackDets;
261 
262  int close = 0;
263  float closeDist = fabs( (myDets.front()->toLocal(startPos)).x());
264  for (unsigned int i = 0; i < myDets.size(); i++ ) {
265  float dist = (myDets[i]->surface().toLocal(startPos)).x();
266  if ( fabs(dist) < fabs(closeDist) ) {
267  close = i;
268  closeDist = dist;
269  }
270  }
271  return close;
272 }
#define LogDebug(id)
Common base class.
int i
Definition: DBlmapReader.cc:9
def window
Definition: svgfig.py:642
int closestIndex() const
int closestDetIndex() const
double deltaPhi(float phi1, float phi2)
Definition: VectorUtil.h:30
Definition: DDAxes.h:10
GlobalPoint globalPosition() const
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
PropagationDirection
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
virtual PropagationDirection propagationDirection() const GCC11_FINAL
Definition: Propagator.h:145
const GlobalPoint & position() const
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est)
Definition: TkDetUtil.cc:31
T barePhi() const
Definition: PV3DBase.h:68
int endcapSide(const TrajectoryStateOnSurface &startingState, const Propagator &prop) const
int subLayerIndex() const
bool overlapInPhi(const GlobalPoint &crossPoint, const GeomDet &det, float phiWindow)
Definition: TkDetUtil.cc:21
tuple result
Definition: query.py:137
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define end
Definition: vmac.h:37
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:57
const SubLayerCrossing & other() const
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
#define begin
Definition: vmac.h:30
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)
Definition: DDAxes.h:10