CMS 3D CMS Logo

ForwardDiskSectorBuilderFromDet.cc
Go to the documentation of this file.
3 
7 
8 using namespace std;
9 
10 // Warning, remember to assign this pointer to a ReferenceCountingPointer!
12 ForwardDiskSectorBuilderFromDet::operator()( const vector<const GeomDet*>& dets) const
13 {
14  // check that the dets are all at about the same radius and z
15  float rcheck = dets.front()->surface().position().perp();
16  float zcheck = dets.front()->surface().position().z();
17  for ( vector<const GeomDet*>::const_iterator i = dets.begin(); i != dets.end(); i++){
18  float rdiff = (**i).surface().position().perp()-rcheck;
19  if ( std::abs(rdiff) > 1.)
20  edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromDet: Trying to build Petal Wedge from "
21  << "Dets at different radii !! Delta_r = " << rdiff ;
22  float zdiff = zcheck - (**i).surface().position().z();
23  if ( std::abs(zdiff) > 0.8)
24  edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromDet: Trying to build Petal Wedge from "
25  << "Dets at different z positions !! Delta_z = " << zdiff ;
26  }
27 
28  auto bo = computeBounds( dets );
29 
30  Surface::PositionType pos( bo.second.x(), bo.second.y(), bo.second.z() );
31  Surface::RotationType rot = computeRotation( dets, pos);
32  return new BoundDiskSector( pos, rot, bo.first);
33 }
34 
35 pair<DiskSectorBounds*, GlobalVector>
36 ForwardDiskSectorBuilderFromDet::computeBounds( const vector<const GeomDet*>& dets) const
37 {
38  // go over all corners and compute maximum deviations
39  float rmin = (**(dets.begin())).surface().position().perp();
40  float rmax(rmin);
41  float zmin((**(dets.begin())).surface().position().z());
42  float zmax(zmin);
43  float phimin((**(dets.begin())).surface().position().phi());
44  float phimax(phimin);
45 
46 
47  for (vector<const GeomDet*>::const_iterator idet=dets.begin();
48  idet != dets.end(); idet++) {
49  vector<const GeomDet*> detUnits = (**idet).components();
50  if( !detUnits.empty() ){
51  for (vector<const GeomDet*>::const_iterator detu=detUnits.begin();
52  detu!=detUnits.end(); detu++) {
53  // edm::LogInfo(TkDetLayers) << " Builder: Position of detUnit :"<< (**detu).position() ;
54  vector<GlobalPoint> corners = computeTrapezoidalCorners(*detu) ;
55  for (vector<GlobalPoint>::const_iterator i=corners.begin();
56  i!=corners.end(); i++) {
57  float r = i->perp();
58  float z = i->z();
59  float phi = i->phi();
60  rmin = min( rmin, r);
61  rmax = max( rmax, r);
62  zmin = min( zmin, z);
63  zmax = max( zmax, z);
64  if ( Geom::phiLess( phi, phimin)) phimin = phi;
65  if ( Geom::phiLess( phimax, phi)) phimax = phi;
66  }
67  // in addition to the corners we have to check the middle of the
68  // det +/- length/2, since the min (max) radius for typical fw
69  // dets is reached there
70  float rdet = (**detu).position().perp();
71  float len = (**detu).surface().bounds().length();
72  float width = (**detu).surface().bounds().width();
73 
74  GlobalVector xAxis = (**detu).toGlobal(LocalVector(1,0,0));
75  GlobalVector yAxis = (**detu).toGlobal(LocalVector(0,1,0));
76  GlobalVector perpDir = GlobalVector( (**detu).position() - GlobalPoint(0,0,(**detu).position().z()) );
77 
78  double xAxisCos = xAxis.unit().dot(perpDir.unit());
79  double yAxisCos = yAxis.unit().dot(perpDir.unit());
80 
81  if( std::abs(xAxisCos) > std::abs(yAxisCos) ) {
82  rmin = min( rmin, rdet-width/2.F);
83  rmax = max( rmax, rdet+width/2.F);
84  }else{
85  rmin = min( rmin, rdet-len/2.F);
86  rmax = max( rmax, rdet+len/2.F);
87  }
88  }
89  }else{
90  vector<GlobalPoint> corners = computeTrapezoidalCorners(*idet) ;
91  for (vector<GlobalPoint>::const_iterator i=corners.begin();
92  i!=corners.end(); i++) {
93  float r = i->perp();
94  float z = i->z();
95  float phi = i->phi();
96  rmin = min( rmin, r);
97  rmax = max( rmax, r);
98  zmin = min( zmin, z);
99  zmax = max( zmax, z);
100  if ( Geom::phiLess( phi, phimin)) phimin = phi;
101  if ( Geom::phiLess( phimax, phi)) phimax = phi;
102  }
103  // in addition to the corners we have to check the middle of the
104  // det +/- length/2, since the min (max) radius for typical fw
105  // dets is reached there
106 
107  float rdet = (**idet).position().perp();
108  float len = (**idet).surface().bounds().length();
109  float width = (**idet).surface().bounds().width();
110 
111  GlobalVector xAxis = (**idet).toGlobal(LocalVector(1,0,0));
112  GlobalVector yAxis = (**idet).toGlobal(LocalVector(0,1,0));
113  GlobalVector perpDir = GlobalVector( (**idet).position() - GlobalPoint(0,0,(**idet).position().z()) );
114 
115  double xAxisCos = xAxis.unit().dot(perpDir.unit());
116  double yAxisCos = yAxis.unit().dot(perpDir.unit());
117 
118  if( std::abs(xAxisCos) > std::abs(yAxisCos) ) {
119  rmin = min( rmin, rdet-width/2.F);
120  rmax = max( rmax, rdet+width/2.F);
121  }else{
122  rmin = min( rmin, rdet-len/2.F);
123  rmax = max( rmax, rdet+len/2.F);
124  }
125  }
126  }
127 
128 
129  if (!Geom::phiLess(phimin, phimax))
130  edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromDet : "
131  << "Something went wrong with Phi Sorting !" ;
132  float zPos = (zmax+zmin)/2.;
133  float phiWin = phimax - phimin;
134  float phiPos = (phimax+phimin)/2.;
135  float rmed = (rmin+rmax)/2.;
136  if ( phiWin < 0. ) {
137  if ( (phimin < Geom::pi() / 2.) || (phimax > -Geom::pi()/2.) ){
138  edm::LogError("TkDetLayers") << " Debug: something strange going on, please check " ;
139  }
140  // edm::LogInfo(TkDetLayers) << " Wedge at pi: phi " << phimin << " " << phimax << " " << phiWin
141  // << " " << 2.*Geom::pi()+phiWin << " " ;
142  phiWin += 2.*Geom::pi();
143  phiPos += Geom::pi();
144  }
145  GlobalVector pos( rmed*cos(phiPos), rmed*sin(phiPos), zPos);
146  return make_pair(new DiskSectorBounds(rmin,rmax,zmin-zPos,zmax-zPos,phiWin), pos);
147 }
148 
150 ForwardDiskSectorBuilderFromDet::computeRotation( const vector<const GeomDet*>& dets,
151  Surface::PositionType pos) const {
152 
153  GlobalVector yAxis = ( GlobalVector( pos.x(), pos.y(), 0.)).unit();
154 
155  GlobalVector zAxis( 0., 0., 1.);
156  GlobalVector xAxis = yAxis.cross( zAxis);
157 
158  return Surface::RotationType( xAxis, yAxis);
159 }
160 
161 
162 vector<GlobalPoint>
164 
165 
166  const Plane& plane( det->specificSurface());
167 
168  const TrapezoidalPlaneBounds* myBounds( static_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
169 
170  /*
171  if (myBounds == 0) {
172  string errmsg="ForwardDiskSectorBuilderFromDet: problems with dynamic cast to trapezoidal bounds for DetUnits";
173  throw DetLayerException(errmsg);
174  edm::LogError("TkDetLayers") << errmsg ;
175  }
176  */
177 
178  // array<const float, 4>
179  auto const & parameters = (*myBounds).parameters();
180 
181  if ( parameters[0] == 0 ) {
182  edm::LogError("TkDetLayers") << "ForwardDiskSectorBuilder: something weird going on !" ;
183  edm::LogError("TkDetLayers") << " Trapezoidal parameters of GeomDet (L2/L1/T/H): " ;
184  for (int i = 0; i < 4; i++ ) edm::LogError("TkDetLayers") << " "
185  << 2.*parameters[i]
186  << "\n";
187  }
188 
189 
190  float hbotedge = parameters[0];
191  float htopedge = parameters[1];
192  float hapothem = parameters[3];
193  float hthick = parameters[2];
194 
195  vector<GlobalPoint> corners;
196 
197  corners.push_back( plane.toGlobal( LocalPoint( -htopedge, hapothem, hthick)));
198  corners.push_back( plane.toGlobal( LocalPoint( -htopedge, hapothem, -hthick)));
199  corners.push_back( plane.toGlobal( LocalPoint( htopedge, hapothem, hthick)));
200  corners.push_back( plane.toGlobal( LocalPoint( htopedge, hapothem, -hthick)));
201  corners.push_back( plane.toGlobal( LocalPoint( hbotedge, -hapothem, hthick)));
202  corners.push_back( plane.toGlobal( LocalPoint( hbotedge, -hapothem, -hthick)));
203  corners.push_back( plane.toGlobal( LocalPoint( -hbotedge, -hapothem, hthick)));
204  corners.push_back( plane.toGlobal( LocalPoint( -hbotedge, -hapothem, -hthick)));
205 
206  return corners;
207 }
Local3DVector LocalVector
Definition: LocalVector.h:12
std::pair< DiskSectorBounds *, GlobalVector > computeBounds(const std::vector< const GeomDet * > &dets) const
T perp() const
Definition: PV3DBase.h:72
virtual const std::array< const float, 4 > parameters() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
Definition: Plane.h:17
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
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:23
Vector3DBase unit() const
Definition: Vector3DBase.h:57
BoundDiskSector * operator()(const std::vector< const GeomDet * > &dets) const
std::vector< GlobalPoint > computeTrapezoidalCorners(const GeomDet *detu) const
TkRotation< float > RotationType
Surface::RotationType computeRotation(const std::vector< const GeomDet * > &dets, Surface::PositionType pos) const
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
const Plane & specificSurface() const
Same as surface(), kept for backward compatibility.
Definition: GeomDet.h:45
Global3DVector GlobalVector
Definition: GlobalVector.h:10