CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BladeShapeBuilderFromDet.cc
Go to the documentation of this file.
2 
4 
7 
8 #include <iomanip>
9 
10 using namespace std;
11 
12 BoundDiskSector*
13 BladeShapeBuilderFromDet::operator()( const vector<const GeomDet*>& dets) const
14 {
15  // find mean position
17  Vector posSum(0,0,0);
18  for (vector<const GeomDet*>::const_iterator i=dets.begin(); i!=dets.end(); i++) {
19  posSum += (**i).surface().position().basicVector();
20  }
21  Surface::PositionType meanPos( 0.,0.,posSum.z()/float(dets.size()) );
22 
23  // temporary plane - for the computation of bounds
24  Surface::RotationType rotation = computeRotation( dets, meanPos);
25  Plane tmpPlane( meanPos, rotation);
26 
27 
28  auto bo =
29  computeBounds( dets,tmpPlane );
30  GlobalPoint pos = meanPos+bo.second;
31  //edm::LogInfo(TkDetLayers) << "global pos in operator: " << pos ;
32  return new BoundDiskSector( pos, rotation, bo.first);
33 }
34 
35 pair<DiskSectorBounds *, GlobalVector>
36 BladeShapeBuilderFromDet::computeBounds( const vector<const GeomDet*>& dets,
37  const Plane& plane) const
38 {
39  Surface::PositionType tmpPos = dets.front()->surface().position();
40 
41 
42  float rmin(plane.toLocal(tmpPos).perp());
43  float rmax(plane.toLocal(tmpPos).perp());
44  float zmin(plane.toLocal(tmpPos).z());
45  float zmax(plane.toLocal(tmpPos).z());
46  float phimin(plane.toLocal(tmpPos).phi());
47  float phimax(plane.toLocal(tmpPos).phi());
48 
49  for(vector<const GeomDet*>::const_iterator it=dets.begin(); it!=dets.end(); it++){
50  vector<GlobalPoint> corners = BoundingBox().corners( (*it)->specificSurface() );
51 
52  for(vector<GlobalPoint>::const_iterator i=corners.begin();
53  i!=corners.end(); i++) {
54 
55  float r = plane.toLocal(*i).perp();
56  float z = plane.toLocal(*i).z();
57  float phi = plane.toLocal(*i).phi();
58  rmin = min( rmin, r);
59  rmax = max( rmax, r);
60  zmin = min( zmin, z);
61  zmax = max( zmax, z);
62  if ( PhiLess()( phi, phimin)) phimin = phi;
63  if ( PhiLess()( phimax, phi)) phimax = phi;
64  }
65  // in addition to the corners we have to check the middle of the
66  // det +/- length/2, since the min (max) radius for typical fw
67  // dets is reached there
68 
69  float rdet = (*it)->position().perp();
70  float height = (*it)->surface().bounds().width();
71  rmin = min( rmin, rdet-height/2.F);
72  rmax = max( rmax, rdet+height/2.F);
73 
74 
75  }
76 
77  if (!PhiLess()(phimin, phimax))
78  edm::LogError("TkDetLayers") << " BladeShapeBuilderFromDet : "
79  << "Something went wrong with Phi Sorting !" ;
80  float zPos = (zmax+zmin)/2.;
81  float phiWin = phimax - phimin;
82  float phiPos = (phimax+phimin)/2.;
83  float rmed = (rmin+rmax)/2.;
84  if ( phiWin < 0. ) {
85  if ( (phimin < Geom::pi() / 2.) || (phimax > -Geom::pi()/2.) ){
86  edm::LogError("TkDetLayers") << " something strange going on, please check " ;
87  }
88  //edm::LogInfo(TkDetLayers) << " Wedge at pi: phi " << phimin << " " << phimax << " " << phiWin
89  // << " " << 2.*Geom::pi()+phiWin << " " ;
90  phiWin += 2.*Geom::pi();
91  phiPos += Geom::pi();
92  }
93 
94  LocalVector localPos( rmed*cos(phiPos), rmed*sin(phiPos), zPos);
95 
96  LogDebug("TkDetLayers") << "localPos in computeBounds: " << localPos << "\n"
97  << "rmin: " << rmin << "\n"
98  << "rmax: " << rmax << "\n"
99  << "zmin: " << zmin << "\n"
100  << "zmax: " << zmax << "\n"
101  << "phiWin: " << phiWin ;
102 
103  return make_pair(new DiskSectorBounds(rmin,rmax,zmin,zmax,phiWin),
104  plane.toGlobal(localPos) );
105 
106 }
107 
108 
110 BladeShapeBuilderFromDet::computeRotation( const vector<const GeomDet*>& dets,
111  const Surface::PositionType& meanPos) const
112 {
113  const Plane& plane = dets.front()->surface();
114 
115  GlobalVector xAxis;
116  GlobalVector yAxis;
117  GlobalVector zAxis;
118 
119  GlobalVector planeXAxis = plane.toGlobal( LocalVector( 1, 0, 0));
120  GlobalPoint planePosition = plane.position();
121 
122  if(planePosition.x()*planeXAxis.x()+planePosition.y()*planeXAxis.y() > 0.){
123  yAxis = planeXAxis;
124  }else{
125  yAxis = -planeXAxis;
126  }
127 
128  GlobalVector planeZAxis = plane.toGlobal( LocalVector( 0, 0, 1));
129  if(planeZAxis.z()*planePosition.z() > 0.){
130  zAxis = planeZAxis;
131  }else{
132  zAxis = -planeZAxis;
133  }
134 
135  xAxis = yAxis.cross( zAxis);
136 
137  return Surface::RotationType( xAxis, yAxis);
138 }
139 
140 
141 
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
int i
Definition: DBlmapReader.cc:9
Local3DVector LocalVector
Definition: LocalVector.h:12
T perp() const
Definition: PV3DBase.h:72
std::pair< DiskSectorBounds *, GlobalVector > computeBounds(const std::vector< const GeomDet * > &dets, const Plane &plane) const
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
double zPos
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
BoundDiskSector * operator()(const std::vector< const GeomDet * > &dets) const
T y() const
Definition: PV3DBase.h:63
#define min(a, b)
Definition: mlp_lapack.h:161
Definition: Plane.h:17
float float float z
const T & max(const T &a, const T &b)
Surface::RotationType computeRotation(const std::vector< const GeomDet * > &dets, const Surface::PositionType &pos) const
LocalPoint toLocal(const GlobalPoint &gp) const
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:119
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
static std::vector< GlobalPoint > corners(const Plane &)
Definition: BoundingBox.cc:24
double pi()
Definition: Pi.h:31
TkRotation< float > RotationType
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
T x() const
Definition: PV3DBase.h:62
const PositionType & position() const
Definition: DDAxes.h:10