CMS 3D CMS Logo

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