CMS 3D CMS Logo

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