test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FlatTrd.cc
Go to the documentation of this file.
3 #include <algorithm>
4 #include <iostream>
5 
6 //#define DebugLog
7 
9 typedef FlatTrd::Pt3D Pt3D ;
12 
13 typedef HepGeom::Vector3D<CCGFloat> FVec3D ;
14 typedef HepGeom::Plane3D<CCGFloat> Plane3D ;
15 
16 typedef HepGeom::Vector3D<double> DVec3D ;
17 typedef HepGeom::Plane3D<double> DPlane3D ;
18 typedef HepGeom::Point3D<double> DPt3D ;
19 
20 //----------------------------------------------------------------------
21 
22 FlatTrd::FlatTrd() : CaloCellGeometry(), m_axis ( 0., 0., 0. ),
23  m_corOne ( 0., 0., 0. ), m_local (0., 0., 0.),
24  m_global ( 0., 0., 0. ) {
25 }
26 
28  *this = tr ;
29 }
30 
32  CaloCellGeometry::operator=( tr ) ;
33  if ( this != &tr ) {
34  m_axis = tr.m_axis ;
35  m_corOne = tr.m_corOne ;
36  m_local = tr.m_local;
37  m_global = tr.m_global;
38  m_tr = tr.m_tr;
39  }
40 #ifdef DebugLog
41  std::cout << "FlatTrd(Copy): Local " << m_local << " Global " << m_global
42  << " eta " << etaPos() << " phi " << phiPos() << " Translation "
43  << m_tr.getTranslation() << " and rotation " << m_tr.getRotation();
44 #endif
45  return *this ;
46 }
47 
49 CornersMgr* cMgr ,
50  const GlobalPoint& fCtr ,
51  const GlobalPoint& bCtr ,
52  const GlobalPoint& cor1 ,
53  const CCGFloat* parV ) :
54  CaloCellGeometry ( fCtr, cMgr, parV ) ,
55  m_axis ( ( bCtr - fCtr ).unit() ) ,
56  m_corOne ( cor1.x(), cor1.y(), cor1.z() ),
57  m_local (0., 0., 0.) {
58  getTransform(m_tr,0);
59  Pt3D glb = m_tr*m_local;
60  m_global = GlobalPoint(glb.x(),glb.y(),glb.z());
61 #ifdef DebugLog
62  std::cout << "FlatTrd: Local " << m_local << " Global " << glb << " eta "
63  << etaPos() << " phi " << phiPos() << " Translation "
64  << m_tr.getTranslation() << " and rotation " << m_tr.getRotation();
65 #endif
66 }
67 
69  const CCGFloat* par ) :
70  CaloCellGeometry ( corn, par ) ,
71  m_corOne ( corn[0].x(), corn[0].y(), corn[0].z() ),
72  m_local (0., 0., 0.) {
73  getTransform(m_tr,0);
74  m_axis = makeAxis();
75  Pt3D glb = m_tr*m_local;
76  m_global = GlobalPoint(glb.x(),glb.y(),glb.z());
77 #ifdef DebugLog
78  std::cout << "FlatTrd: Local " << m_local << " Global " << glb << " eta "
79  << etaPos() << " phi " << phiPos() << " Translation "
80  << m_tr.getTranslation() << " and rotation " << m_tr.getRotation();
81 #endif
82 }
83 
84 FlatTrd::FlatTrd( const FlatTrd& tr, const Pt3D & local ) :
85  CaloCellGeometry( tr ), m_local(local) {
86  *this = tr;
87  Pt3D glb = m_tr*m_local;
88  m_global = GlobalPoint(glb.x(),glb.y(),glb.z());
89 #ifdef DebugLog
90  std::cout << "FlatTrd: Local " << m_local << " Global " << glb << " eta "
91  << etaPos() << " phi " << phiPos() << " Translation "
92  << m_tr.getTranslation() << " and rotation " << m_tr.getRotation();
93 #endif
94 }
95 
97 
98 GlobalPoint FlatTrd::getPosition(const Pt3D& local ) const {
99  Pt3D glb = m_tr*local;
100 #ifdef DebugLog
101  std::cout << "FlatTrd::Local " << local.x() << ":" << local.y() << ":"
102  << local.z() << " Global " << glb.x() << ":" << glb.y() << ":"
103  << glb.z() << std::endl;
104 #endif
105  return GlobalPoint(glb.x(),glb.y(),glb.z());
106 }
107 
108 Pt3D FlatTrd::getLocal(const GlobalPoint& global) const {
109  Pt3D local = m_tr.inverse()*Pt3D(global.x(),global.y(),global.z());
110 #ifdef DebugLog
111  std::cout << "FlatTrd::Global " << global.x() << ":" << global.y() << ":"
112  << global.z() << " Local " << local.x() << ":" << local.y() << ":"
113  << local.z() << std::endl;
114 #endif
115  return local;
116 }
117 
119  return m_axis.theta() ;
120 }
121 
123  return m_axis.phi() ;
124 }
125 
126 const GlobalVector& FlatTrd::axis() const {
127  return m_axis ;
128 }
129 
131  const CCGFloat* pv ,
132  Pt3D& ref ) const {
133  localCorners( vec, pv, ref ) ;
134 }
135 
136 void FlatTrd::createCorners( const std::vector<CCGFloat>& pv ,
137  const Tr3D& tr ,
138  std::vector<GlobalPoint>& co ) {
139 
140  assert( 11 <= pv.size() ) ;
141  assert( 8 == co.size() ) ;
142 
143  Pt3DVec ko ( 8, Pt3D(0,0,0) ) ;
144 
145  Pt3D tmp ;
146  Pt3DVec to ( 8, Pt3D(0,0,0) ) ;
147  localCorners( to, &pv.front(), tmp ) ;
148 
149  for( unsigned int i ( 0 ) ; i != 8 ; ++i ) {
150  ko[i] = tr * to[i] ; // apply transformation
151  const Pt3D & p ( ko[i] ) ;
152  co[ i ] = GlobalPoint( p.x(), p.y(), p.z() ) ;
153 #ifdef DebugLog
154  std::cout << "Corner[" << i << "] = " << co[i] << std::endl;
155 #endif
156  }
157 }
158 
160  const CCGFloat* pv ,
161  Pt3D& ref ) {
162  assert( 0 != pv ) ;
163  assert( 8 == lc.size() ) ;
164 
165  const CCGFloat dz ( pv[0] ) ;
166  const CCGFloat h ( pv[3] ) ;
167  const CCGFloat bl ( pv[4] ) ;
168  const CCGFloat tl ( pv[5] ) ;
169  const CCGFloat a1 ( pv[6] ) ;
170 
171  const CCGFloat ta1 ( tan( a1 ) ) ;
172 
173  lc[0] = Pt3D ( - h*ta1 - bl, - h , -dz ); // (-,-,-)
174  lc[1] = Pt3D ( + h*ta1 - tl, + h , -dz ); // (-,+,-)
175  lc[2] = Pt3D ( + h*ta1 + tl, + h , -dz ); // (+,+,-)
176  lc[3] = Pt3D ( - h*ta1 + bl, - h , -dz ); // (+,-,-)
177  lc[4] = Pt3D ( - h*ta1 - bl, - h , dz ); // (-,-,+)
178  lc[5] = Pt3D ( + h*ta1 - tl, + h , dz ); // (-,+,+)
179  lc[6] = Pt3D ( + h*ta1 + tl, + h , dz ); // (+,+,+)
180  lc[7] = Pt3D ( - h*ta1 + bl, - h , dz ); // (+,-,+)
181 
182  ref = 0.25*( lc[0] + lc[1] + lc[2] + lc[3] ) ;
183 #ifdef DebugLog
184  std::cout << "Ref " << ref << " Local Corners " << lc[0] << "|" << lc[1]
185  << "|" << lc[2] << "|" << lc[3] << "|" << lc[4] << "|" << lc[5]
186  << "|" << lc[6] << "|" << lc[7] << std::endl;
187 #endif
188 }
189 
190 void FlatTrd::getTransform( Tr3D& tr, Pt3DVec* lptr ) const {
192  const Pt3D gFront ( p.x(), p.y(), p.z() ) ;
193  const DPt3D dgFront ( p.x(), p.y(), p.z() ) ;
194 
195  Pt3D lFront ;
196  assert( 0 != param() ) ;
197  std::vector<Pt3D > lc( 8, Pt3D(0,0,0) ) ;
198  localCorners( lc, param(), lFront ) ;
199 
200  // figure out if reflction volume or not
201 
202  Pt3D lBack ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7]) ) ;
203 
204  const DPt3D dlFront ( lFront.x(), lFront.y(), lFront.z() ) ;
205  const DPt3D dlBack ( lBack.x() , lBack.y() , lBack.z() ) ;
206  const DPt3D dlOne ( lc[0].x() , lc[0].y() , lc[0].z() ) ;
207 
208  const FVec3D dgAxis ( axis().x(), axis().y(), axis().z() ) ;
209 
210  const DPt3D dmOne ( m_corOne.x(), m_corOne.y(), m_corOne.z() ) ;
211 
212  const DPt3D dgBack ( dgFront + ( dlBack - dlFront ).mag()*dgAxis ) ;
213  DPt3D dgOne ( dgFront + ( dlOne - dlFront ).mag()*( dmOne - dgFront ).unit() ) ;
214 
215  const double dlangle ( ( dlBack - dlFront).angle( dlOne - dlFront ) ) ;
216  const double dgangle ( ( dgBack - dgFront).angle( dgOne - dgFront ) ) ;
217  const double dangle ( dlangle - dgangle ) ;
218 
219  if( 1.e-6 < fabs(dangle) ) {//guard against precision problems
220  const DPlane3D dgPl ( dgFront, dgOne, dgBack ) ;
221  const DPt3D dp2 ( dgFront + dgPl.normal().unit() ) ;
222 
223  DPt3D dgOld ( dgOne ) ;
224 
225  dgOne = ( dgFront + HepGeom::Rotate3D( -dangle, dgFront, dp2 )*
226  DVec3D( dgOld - dgFront ) ) ;
227  }
228 
229  tr = Tr3D( dlFront , dlBack , dlOne ,
230  dgFront , dgBack , dgOne ) ;
231 
232  if( 0 != lptr ) (*lptr) = lc ;
233 }
234 
236 
237  if( co.uninitialized() ) {
238  CornersVec& corners ( co ) ;
239  Pt3DVec lc ;
240  Tr3D tr ;
241  getTransform( tr, &lc ) ;
242 
243  for (unsigned int i ( 0 ) ; i != 8 ; ++i ) {
244  const Pt3D corn ( tr*lc[i] ) ;
245  corners[i] = GlobalPoint( corn.x(), corn.y(), corn.z() ) ;
246  }
247  }
248 }
249 
251  return GlobalVector( backCtr() - getPosition() ).unit() ;
252 }
253 
255  float dz = (getCorners()[4].z() > getCorners()[0].z()) ?
256  param()[0] : -param()[0];
257  Pt3D local_b(m_local.x(),m_local.y(),m_local.z()+dz);
258  Pt3D global_b = m_tr*local_b;
259  GlobalPoint global(global_b.x(),global_b.y(),global_b.z());
260  return global;
261 }
262 
263 //----------------------------------------------------------------------
264 //----------------------------------------------------------------------
265 
266 std::ostream& operator<<( std::ostream& s, const FlatTrd& cell ) {
267  s << "Center: " << cell.getPosition() << " eta " << cell.etaPos()
268  << " phi " << cell.phiPos() << std::endl;
269  s << "Axis: " << cell.getThetaAxis() << " " << cell.getPhiAxis() <<std::endl;
270  const CaloCellGeometry::CornersVec& corners ( cell.getCorners() ) ;
271  for ( unsigned int i=0 ; i != corners.size() ; ++i ) {
272  s << "Corner: " << corners[i] << std::endl;
273  }
274  return s ;
275 }
276 
int i
Definition: DBlmapReader.cc:9
const GlobalVector & axis() const
Definition: FlatTrd.cc:126
A base class to handle the particular shape of HGCal volumes.
Definition: FlatTrd.h:19
FlatTrd & operator=(const FlatTrd &tr)
Definition: FlatTrd.cc:31
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
CaloCellGeometry::Pt3D Pt3D
Definition: FlatTrd.h:23
HepGeom::Point3D< double > DPt3D
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
assert(m_qm.get())
double glb
Definition: hdecay.h:105
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: FlatTrd.h:24
HepGeom::Transform3D Tr3D
std::vector< Pt3D > Pt3DVec
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
Tr3D m_tr
Definition: FlatTrd.h:84
float float float z
virtual void getTransform(Tr3D &tr, Pt3DVec *lptr) const override
--------— only needed by specific utility; overloaded when needed -—
Definition: FlatTrd.cc:190
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
T x() const
Cartesian x coordinate.
const GlobalPoint backCtr(void) const
Definition: FlatTrd.cc:254
const CCGFloat * param() const
Pt3D m_local
Definition: FlatTrd.h:82
CaloCellGeometry::CCGFloat CCGFloat
Definition: FlatTrd.h:22
string unit
Definition: csvLumiCalc.py:46
T z() const
Definition: PV3DBase.h:64
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
HepGeom::Vector3D< double > DVec3D
CaloCellGeometry::CCGFloat CCGFloat
Pt3D m_corOne
Definition: FlatTrd.h:82
virtual const GlobalPoint & getPosition() const
Definition: FlatTrd.h:46
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: FlatTrd.cc:159
virtual void vocalCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref) const override
Definition: FlatTrd.cc:130
CaloCellGeometry::Pt3D Pt3D
Vector3DBase unit() const
Definition: Vector3DBase.h:57
Pt3D getLocal(const GlobalPoint &global) const
Definition: FlatTrd.cc:108
GlobalVector makeAxis(void)
Definition: FlatTrd.cc:250
HepGeom::Plane3D< double > DPlane3D
virtual void initCorners(CornersVec &) override
Definition: FlatTrd.cc:235
CaloCellGeometry::Pt3DVec Pt3DVec
HepGeom::Point3D< CCGFloat > Pt3D
Definition: EZMgrFL.h:8
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatTrd.cc:136
CaloCellGeometry::Tr3D Tr3D
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
virtual ~FlatTrd()
Definition: FlatTrd.cc:96
bool uninitialized() const
Definition: EZArrayFL.h:77
GlobalPoint m_global
Definition: FlatTrd.h:83
CaloCellGeometry::Tr3D Tr3D
Definition: FlatTrd.h:25
CCGFloat getThetaAxis() const
Definition: FlatTrd.cc:118
virtual float phiPos() const
Definition: FlatTrd.h:49
tuple cout
Definition: gather_cfg.py:145
virtual float etaPos() const
Definition: FlatTrd.h:48
FlatTrd(void)
Definition: FlatTrd.cc:22
const CornersVec & getCorners() const
Returns the corner points of this cell&#39;s volume.
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
T x() const
Definition: PV3DBase.h:62
CCGFloat getPhiAxis() const
Definition: FlatTrd.cc:122
HepGeom::Vector3D< CCGFloat > FVec3D
ROOT::Math::Plane3D Plane3D
Global3DVector GlobalVector
Definition: GlobalVector.h:10
GlobalVector m_axis
Definition: FlatTrd.h:81
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11