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