CMS 3D CMS Logo

DDHCalXtalAlgo.cc
Go to the documentation of this file.
1 // File: DDHCalXtalAlgo.cc
3 // Description: Positioning the crystal (layers) in the mother volume
5 
6 #include <cmath>
7 #include <algorithm>
8 
14 
15 //#define EDM_ML_DEBUG
16 using namespace geant_units::operators;
17 
19 #ifdef EDM_ML_DEBUG
20  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo info: Creating an instance";
21 #endif
22 }
23 
25 
27  const DDVectorArguments & ,
28  const DDMapArguments & ,
29  const DDStringArguments & sArgs,
30  const DDStringVectorArguments & vsArgs) {
31 
32  radius = nArgs["Radius"];
33  offset = nArgs["Offset"];
34  dx = nArgs["Dx"];
35  dz = nArgs["Dz"];
36  angwidth = nArgs["AngWidth"];
37  iaxis = int (nArgs["Axis"]);
38  names = vsArgs["Names"];
39 
40 #ifdef EDM_ML_DEBUG
41  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo::Parameters for positioning:"
42  << " Axis " << iaxis << "\tRadius " << radius
43  << "\tOffset " << offset << "\tDx " << dx
44  << "\tDz " << dz << "\tAngWidth "
45  << convertRadToDeg(angwidth) << "\tNumbers "
46  << names.size();
47  for (unsigned int i = 0; i < names.size(); i++)
48  edm::LogVerbatim("HCalGeom") << "\tnames[" << i << "] = " << names[i];
49 #endif
50  idNameSpace = DDCurrentNamespace::ns();
51  idName = sArgs["ChildName"];
52 #ifdef EDM_ML_DEBUG
53  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Parent " << parent().name()
54  << "\tChild " << idName << " NameSpace "
55  << idNameSpace;
56 #endif
57 }
58 
60 
61  double theta[3], phi[3], pos[3];
62  phi[0] = 0;
63  phi[1] = 90._deg;
64  theta[1-iaxis] = 90._deg;
65  pos[1-iaxis] = 0;
66  int number = (int)(names.size());
67  for (int i=0; i<number; i++) {
68  double angle = 0.5*angwidth*(2*i+1-number);
69  theta[iaxis] = 90._deg + angle;
70  if (angle>0) {
71  theta[2] = angle;
72  phi[2] = iaxis*90._deg;
73  } else {
74  theta[2] =-angle;
75  phi[2] = (2-3*iaxis)*90._deg;
76  }
77  pos[iaxis] = angle*(dz+radius);
78  pos[2] = dx*std::abs(sin(angle)) + offset;
79 
81  std::string rotstr = names[i];
82  DDTranslation tran(pos[0], pos[1], pos[2]);
83  DDName parentName = parent().name();
84 
85  static const double tol = 0.01_deg; // 0.01 degree
86  if (std::abs(angle) > tol) {
87 #ifdef EDM_ML_DEBUG
88  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Creating a rotation "
89  << rotstr << "\t"
90  << convertRadToDeg(theta[0]) << ","
91  << convertRadToDeg(phi[0]) << ","
92  << convertRadToDeg(theta[1]) << ","
93  << convertRadToDeg(phi[1]) << ","
94  << convertRadToDeg(theta[2]) << ","
95  << convertRadToDeg(phi[2]);
96 #endif
97  rotation = DDrot(DDName(rotstr, idNameSpace), theta[0], phi[0], theta[1],
98  phi[1], theta[2], phi[2]);
99  }
100  cpv.position(DDName(idName, idNameSpace), parentName, i+1, tran, rotation);
101 #ifdef EDM_ML_DEBUG
102  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: "
103  << DDName(idName,idNameSpace) << " number "
104  << i+1 << " positioned in " << parentName
105  << " at " << tran << " with " << rotation;
106 #endif
107  }
108 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
constexpr NumType convertRadToDeg(NumType radians)
Definition: GeantUnits.h:98
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
const std::string names[nVars_]
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:68
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:80
~DDHCalXtalAlgo() override
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
void execute(DDCompactView &cpv) override
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11