CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ForwardDiskSectorBuilderFromWedges.cc
Go to the documentation of this file.
2 
4 
6 
7 using namespace std;
8 
9 // Warning, remember to assign this pointer to a ReferenceCountingPointer!
11 ForwardDiskSectorBuilderFromWedges::operator()( const vector<const TECWedge*>& wedges) const
12 {
13  // check first that all wedges are about at the same phi and z !
14  float phiStart = wedges.front()->position().phi();
15  float zStart = wedges.front()->position().z();
16  float wphimin, wphimax;
17  for (vector<const TECWedge*>::const_iterator i = wedges.begin(); i != wedges.end(); i++){
18  float zdiff = (**i).surface().position().z() - zStart;
19  if ( fabs( zdiff) > 5.)
20  edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges: Trying to build "
21  << "Petal from Wedges at different z ! Delta Z = " << zdiff ;
22  float wphi = (**i).surface().position().phi();
23  if ( PhiLess()( phiStart, wphi)) {
24  wphimin = phiStart;
25  wphimax = wphi;
26  } else {
27  wphimin = wphi;
28  wphimax = phiStart;
29  }
30  float phidiff = wphimax - wphimin;
31  if ( phidiff < 0.) phidiff += 2.*Geom::pi();
32  if ( phidiff > 0.3 )
33  edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges: Trying to build "
34  << "Petal from Wedges at different phi ! Delta phi = "
35  << phidiff ;
36  }
37 
38  pair<DiskSectorBounds,GlobalVector> bo =
39  computeBounds( wedges );
40 
41  Surface::PositionType pos( bo.second.x(), bo.second.y(), bo.second.z() );
42  Surface::RotationType rot = computeRotation( wedges, pos);
43  return new BoundDiskSector( pos, rot, bo.first);
44 }
45 
46 pair<DiskSectorBounds, GlobalVector>
47 ForwardDiskSectorBuilderFromWedges::computeBounds( const vector<const TECWedge*>& wedges) const
48 {
49 
50  // compute maximum and minimum radius and phi
51  float rmin((**(wedges.begin())).specificSurface().innerRadius());
52  float rmax(rmin);
53  float zmin((**(wedges.begin())).surface().position().z());
54  float zmax(zmin);
55  float phimin((**(wedges.begin())).surface().position().phi());
56  float phimax(phimin);
57 
58  for (vector<const TECWedge*>::const_iterator iw=wedges.begin();
59  iw != wedges.end(); iw++) {
60  // edm::LogInfo(TkDetLayers) << "---------------------------------------------" ;
61  // edm::LogInfo(TkDetLayers) << " Builder: Position of wedge :" << (**iw).position() ;
62  float ri = (**iw).specificSurface().innerRadius();
63  float ro = (**iw).specificSurface().outerRadius();
64  float zmi = (**iw).surface().position().z() - (**iw).specificSurface().bounds().thickness()/2.;
65  float zma = (**iw).surface().position().z() + (**iw).specificSurface().bounds().thickness()/2.;
66  float phi1 = (**iw).surface().position().phi() - (**iw).specificSurface().phiExtension()/2.;
67  float phi2 = (**iw).surface().position().phi() + (**iw).specificSurface().phiExtension()/2.;
68  rmin = min( rmin, ri);
69  rmax = max( rmax, ro);
70  zmin = min( zmin, zmi);
71  zmax = max( zmax, zma);
72  if ( PhiLess()( phi1, phimin)) phimin = phi1;
73  if ( PhiLess()( phimax, phi2)) phimax = phi2;
74  }
75 
76  if (!PhiLess()(phimin, phimax))
77  edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges : "
78  << "Something went wrong with Phi Sorting !";
79  float zPos = (zmax+zmin)/2.;
80  float phiWin = phimax - phimin;
81  float phiPos = (phimax+phimin)/2.;
82  float rmed = (rmin+rmax)/2.;
83  if ( phiWin < 0. ) {
84  if ( (phimin < Geom::pi() / 2.) || (phimax > -Geom::pi()/2.) ){
85  edm::LogError("TkDetLayers") << " Debug: something strange going on, please check " ;
86  }
87  // edm::LogInfo(TkDetLayers) << " Petal at pi: phi " << phimin << " " << phimax << " " << phiWin
88  // << " " << 2.*Geom::pi()+phiWin << " " ;
89  phiWin += 2.*Geom::pi();
90  phiPos += Geom::pi();
91  }
92 
93  GlobalVector pos( rmed*cos(phiPos), rmed*sin(phiPos), zPos);
94  return make_pair(DiskSectorBounds(rmin,rmax,zmin-zPos,zmax-zPos,phiWin), pos);
95 }
96 
98 ForwardDiskSectorBuilderFromWedges::computeRotation( const vector<const TECWedge*>& wedges,
99  Surface::PositionType pos) const {
100 
101  GlobalVector yAxis = ( GlobalVector( pos.x(), pos.y(), 0.)).unit();
102 
103  GlobalVector zAxis( 0., 0., 1.);
104  GlobalVector xAxis = yAxis.cross( zAxis);
105 
106  return Surface::RotationType( xAxis, yAxis);
107 }
108 
int i
Definition: DBlmapReader.cc:9
double zPos
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
T y() const
Definition: PV3DBase.h:57
#define min(a, b)
Definition: mlp_lapack.h:161
BoundDiskSector * operator()(const std::vector< const TECWedge * > &wedges) const
Surface::RotationType computeRotation(const std::vector< const TECWedge * > &wedges, Surface::PositionType pos) const
const T & max(const T &a, const T &b)
string unit
Definition: csvLumiCalc.py:46
std::pair< DiskSectorBounds, GlobalVector > computeBounds(const std::vector< const TECWedge * > &wedges) const
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:119
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double pi()
Definition: Pi.h:31
TkRotation< float > RotationType
T x() const
Definition: PV3DBase.h:56
const PositionType & position() const
Global3DVector GlobalVector
Definition: GlobalVector.h:10