CMS 3D CMS Logo

ConvertFromToCLHEP.h
Go to the documentation of this file.
1 #ifndef TrackPropagation_ConvertFromToCLHEP_h
2 #define TrackPropagation_ConvertFromToCLHEP_h
3 
4 // CLHEP
5 #include <CLHEP/Geometry/Normal3D.h>
6 #include <CLHEP/Geometry/Point3D.h>
7 #include <CLHEP/Units/SystemOfUnits.h>
8 #include <CLHEP/Vector/Rotation.h>
9 #include <CLHEP/Vector/ThreeVector.h>
10 
11 // CMS
16 
17 // Geant4
18 #include "G4ErrorFreeTrajState.hh"
19 
23 namespace TrackPropagation {
24  using CLHEP::cm;
31  inline HepGeom::Point3D<double> globalPointToHepPoint3D(const GlobalPoint &r) {
32  return HepGeom::Point3D<double>(r.x() * cm, r.y() * cm, r.z() * cm);
33  }
34 
39  inline GlobalPoint hepPoint3DToGlobalPoint(const HepGeom::Point3D<double> &r) {
40  return GlobalPoint(r.x() / cm, r.y() / cm, r.z() / cm);
41  }
42 
46  inline double g4doubleToCmsDouble(const G4double &d) { return d / cm; }
47 
51  inline HepGeom::Normal3D<double> globalVectorToHepNormal3D(const GlobalVector &p) {
52  return HepGeom::Normal3D<double>(p.x(), p.y(), p.z());
53  }
54 
58  inline GlobalVector hepNormal3DToGlobalVector(const HepGeom::Normal3D<double> &p) {
59  return GlobalVector(p.x(), p.y(), p.z());
60  }
61 
64  inline CLHEP::Hep3Vector globalVectorToHep3Vector(const GlobalVector &p) {
65  return CLHEP::Hep3Vector(p.x(), p.y(), p.z());
66  }
67 
70  inline GlobalVector hep3VectorToGlobalVector(const CLHEP::Hep3Vector &p) { return GlobalVector(p.x(), p.y(), p.z()); }
71 
76  inline CLHEP::Hep3Vector globalPointToHep3Vector(const GlobalPoint &r) {
77  return CLHEP::Hep3Vector(r.x() * cm, r.y() * cm, r.z() * cm);
78  }
79 
84  inline GlobalPoint hep3VectorToGlobalPoint(const CLHEP::Hep3Vector &v) {
85  return GlobalPoint(v.x() / cm, v.y() / cm, v.z() / cm);
86  }
87 
91  inline CLHEP::HepRotation tkRotationFToHepRotation(const TkRotation<float> &tkr) {
92  return CLHEP::HepRotation(CLHEP::Hep3Vector(tkr.xx(), tkr.yx(), tkr.zx()),
93  CLHEP::Hep3Vector(tkr.xy(), tkr.yy(), tkr.zy()),
94  CLHEP::Hep3Vector(tkr.xz(), tkr.yz(), tkr.zz()));
95  }
96 
99  inline TkRotation<float> hepRotationToTkRotationF(const CLHEP::HepRotation &r) {
100  return TkRotation<float>(r.xx(), r.xy(), r.xz(), r.yx(), r.yy(), r.yz(), r.zx(), r.zy(), r.zz());
101  }
102 
107  inline AlgebraicSymMatrix55 g4ErrorTrajErrToAlgebraicSymMatrix55(const G4ErrorTrajErr &e, const int q) {
108  assert(q != 0);
109  // From DataFormats/CLHEP/interface/Migration.h
110  // typedef ROOT::Math::SMatrix<double,5,5,ROOT::Math::MatRepSym<double,5> >
111  // AlgebraicSymMatrix55;
113  for (unsigned int i = 0; i < 5; i++)
114  for (unsigned int j = 0; j < 5; j++) {
115  m55(i, j) = e(i + 1, j + 1);
116  if (i == 0)
117  m55(i, j) = double(q) * m55(i, j);
118  if (j == 0)
119  m55(i, j) = double(q) * m55(i, j);
120  }
121  return m55;
122  }
123 
127  inline G4ErrorTrajErr algebraicSymMatrix55ToG4ErrorTrajErr(const AlgebraicSymMatrix55 &e, const int q) {
128  assert(q != 0);
129  G4ErrorTrajErr g4err(5, 1);
130  for (unsigned int i = 0; i < 5; i++)
131  for (unsigned int j = 0; j < 5; j++) {
132  g4err(i + 1, j + 1) = e(i, j);
133 
134  if (i == 0)
135  g4err(i + 1, j + 1) = g4err(i + 1, j + 1) * double(q);
136  if (j == 0)
137  g4err(i + 1, j + 1) = g4err(i + 1, j + 1) * double(q);
138  }
139  return g4err;
140  }
141 
142 } // namespace TrackPropagation
143 
144 #endif
T xx() const
HepGeom::Normal3D< double > globalVectorToHepNormal3D(const GlobalVector &p)
T xy() const
TkRotation< float > hepRotationToTkRotationF(const CLHEP::HepRotation &r)
double g4doubleToCmsDouble(const G4double &d)
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T zz() const
GlobalVector hepNormal3DToGlobalVector(const HepGeom::Normal3D< double > &p)
T yy() const
CLHEP::Hep3Vector globalVectorToHep3Vector(const GlobalVector &p)
T yz() const
assert(be >=bs)
CLHEP::HepRotation tkRotationFToHepRotation(const TkRotation< float > &tkr)
T zx() const
AlgebraicSymMatrix55 g4ErrorTrajErrToAlgebraicSymMatrix55(const G4ErrorTrajErr &e, const int q)
GlobalPoint hepPoint3DToGlobalPoint(const HepGeom::Point3D< double > &r)
T zy() const
d
Definition: ztail.py:151
HepGeom::Point3D< double > globalPointToHepPoint3D(const GlobalPoint &r)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
GlobalVector hep3VectorToGlobalVector(const CLHEP::Hep3Vector &p)
G4ErrorTrajErr algebraicSymMatrix55ToG4ErrorTrajErr(const AlgebraicSymMatrix55 &e, const int q)
CLHEP::Hep3Vector globalPointToHep3Vector(const GlobalPoint &r)
T xz() const
GlobalPoint hep3VectorToGlobalPoint(const CLHEP::Hep3Vector &v)
T yx() const
Global3DVector GlobalVector
Definition: GlobalVector.h:10