test
CMS 3D CMS Logo

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