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 ( std::abs( 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  auto bo = computeBounds( wedges );
39 
40  Surface::PositionType pos( bo.second.x(), bo.second.y(), bo.second.z() );
41  Surface::RotationType rot = computeRotation( wedges, pos);
42  return new BoundDiskSector( pos, rot, bo.first);
43 }
44 
45 pair<DiskSectorBounds*, GlobalVector>
46 ForwardDiskSectorBuilderFromWedges::computeBounds( const vector<const TECWedge*>& wedges) const
47 {
48 
49  // compute maximum and minimum radius and phi
50  float rmin((**(wedges.begin())).specificSurface().innerRadius());
51  float rmax(rmin);
52  float zmin((**(wedges.begin())).surface().position().z());
53  float zmax(zmin);
54  float phimin((**(wedges.begin())).surface().position().phi());
55  float phimax(phimin);
56 
57  for (vector<const TECWedge*>::const_iterator iw=wedges.begin();
58  iw != wedges.end(); iw++) {
59  // edm::LogInfo(TkDetLayers) << "---------------------------------------------" ;
60  // edm::LogInfo(TkDetLayers) << " Builder: Position of wedge :" << (**iw).position() ;
61  float ri = (**iw).specificSurface().innerRadius();
62  float ro = (**iw).specificSurface().outerRadius();
63  float zmi = (**iw).surface().position().z() - (**iw).specificSurface().bounds().thickness()/2.;
64  float zma = (**iw).surface().position().z() + (**iw).specificSurface().bounds().thickness()/2.;
65  float phi1 = (**iw).surface().position().phi() - (**iw).specificSurface().phiHalfExtension();
66  float phi2 = (**iw).surface().position().phi() + (**iw).specificSurface().phiHalfExtension();
67  rmin = min( rmin, ri);
68  rmax = max( rmax, ro);
69  zmin = min( zmin, zmi);
70  zmax = max( zmax, zma);
71  if ( PhiLess()( phi1, phimin)) phimin = phi1;
72  if ( PhiLess()( phimax, phi2)) phimax = phi2;
73  }
74 
75  if (!PhiLess()(phimin, phimax))
76  edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges : "
77  << "Something went wrong with Phi Sorting !";
78  float zPos = (zmax+zmin)/2.;
79  float phiWin = phimax - phimin;
80  float phiPos = (phimax+phimin)/2.;
81  float rmed = (rmin+rmax)/2.;
82  if ( phiWin < 0. ) {
83  if ( (phimin < Geom::pi() / 2.) || (phimax > -Geom::pi()/2.) ){
84  edm::LogError("TkDetLayers") << " Debug: something strange going on, please check " ;
85  }
86  // edm::LogInfo(TkDetLayers) << " Petal at pi: phi " << phimin << " " << phimax << " " << phiWin
87  // << " " << 2.*Geom::pi()+phiWin << " " ;
88  phiWin += 2.*Geom::pi();
89  phiPos += Geom::pi();
90  }
91 
92  GlobalVector pos( rmed*cos(phiPos), rmed*sin(phiPos), zPos);
93  return make_pair(new DiskSectorBounds(rmin,rmax,zmin-zPos,zmax-zPos,phiWin), pos);
94 }
95 
97 ForwardDiskSectorBuilderFromWedges::computeRotation( const vector<const TECWedge*>& wedges,
98  Surface::PositionType pos) const {
99 
100  GlobalVector yAxis = ( GlobalVector( pos.x(), pos.y(), 0.)).unit();
101 
102  GlobalVector zAxis( 0., 0., 1.);
103  GlobalVector xAxis = yAxis.cross( zAxis);
104 
105  return Surface::RotationType( xAxis, yAxis);
106 }
107 
std::pair< DiskSectorBounds *, GlobalVector > computeBounds(const std::vector< const TECWedge * > &wedges) const
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:69
T y() const
Definition: PV3DBase.h:63
double phidiff(double phi)
Normalized difference in azimuthal angles to a range between .
Definition: fourvec.cc:230
BoundDiskSector * operator()(const std::vector< const TECWedge * > &wedges) const
Surface::RotationType computeRotation(const std::vector< const TECWedge * > &wedges, Surface::PositionType pos) const
string unit
Definition: csvLumiCalc.py:46
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
double pi()
Definition: Pi.h:31
TkRotation< float > RotationType
tuple zAxis
Definition: MetAnalyzer.py:56
T x() const
Definition: PV3DBase.h:62
const PositionType & position() const
Global3DVector GlobalVector
Definition: GlobalVector.h:10