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!
10 BoundDiskSector*
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  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().phiExtension()/2.;
66  float phi2 = (**iw).surface().position().phi() + (**iw).specificSurface().phiExtension()/2.;
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
T y() const
Definition: PV3DBase.h:63
#define min(a, b)
Definition: mlp_lapack.h:161
double phidiff(double phi)
Normalized difference in azimuthal angles to a range between .
Definition: fourvec.cc:231
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
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:62
Global3DVector GlobalVector
Definition: GlobalVector.h:10