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 #include <map>
9 #include <string>
10 #include <vector>
11 
20 
21 //#define EDM_ML_DEBUG
22 using namespace geant_units::operators;
23 
24 class DDHCalXtalAlgo : public DDAlgorithm {
25 public:
26  //Constructor and Destructor
28  ~DDHCalXtalAlgo() override;
29 
30  void initialize(const DDNumericArguments& nArgs,
31  const DDVectorArguments& vArgs,
32  const DDMapArguments& mArgs,
33  const DDStringArguments& sArgs,
34  const DDStringVectorArguments& vsArgs) override;
35 
36  void execute(DDCompactView& cpv) override;
37 
38 private:
39  double radius; //Pointing distance from front surface
40  double offset; //Offset along Z
41  double dx; //Half size along x
42  double dz; //Half size along z
43  double angwidth; //Angular width
44  int iaxis; //Axis of rotation
45  std::vector<std::string> names; //Names for rotation matrices
46 
47  std::string idNameSpace; //Namespace of this and ALL sub-parts
48  std::string idName; //Children name
49 };
50 
52 #ifdef EDM_ML_DEBUG
53  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo info: Creating an instance";
54 #endif
55 }
56 
58 
60  const DDVectorArguments&,
61  const DDMapArguments&,
62  const DDStringArguments& sArgs,
63  const DDStringVectorArguments& vsArgs) {
64  radius = nArgs["Radius"];
65  offset = nArgs["Offset"];
66  dx = nArgs["Dx"];
67  dz = nArgs["Dz"];
68  angwidth = nArgs["AngWidth"];
69  iaxis = int(nArgs["Axis"]);
70  names = vsArgs["Names"];
71 
72 #ifdef EDM_ML_DEBUG
73  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo::Parameters for positioning:"
74  << " Axis " << iaxis << "\tRadius " << radius << "\tOffset " << offset << "\tDx " << dx
75  << "\tDz " << dz << "\tAngWidth " << convertRadToDeg(angwidth) << "\tNumbers "
76  << names.size();
77  for (unsigned int i = 0; i < names.size(); i++)
78  edm::LogVerbatim("HCalGeom") << "\tnames[" << i << "] = " << names[i];
79 #endif
80  idNameSpace = DDCurrentNamespace::ns();
81  idName = sArgs["ChildName"];
82 #ifdef EDM_ML_DEBUG
83  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Parent " << parent().name() << "\tChild " << idName << " NameSpace "
84  << idNameSpace;
85 #endif
86 }
87 
89  double theta[3], phi[3], pos[3];
90  phi[0] = 0;
91  phi[1] = 90._deg;
92  theta[1 - iaxis] = 90._deg;
93  pos[1 - iaxis] = 0;
94  int number = (int)(names.size());
95  for (int i = 0; i < number; i++) {
96  double angle = 0.5 * angwidth * (2 * i + 1 - number);
97  theta[iaxis] = 90._deg + angle;
98  if (angle > 0) {
99  theta[2] = angle;
100  phi[2] = iaxis * 90._deg;
101  } else {
102  theta[2] = -angle;
103  phi[2] = (2 - 3 * iaxis) * 90._deg;
104  }
105  pos[iaxis] = angle * (dz + radius);
106  pos[2] = dx * std::abs(sin(angle)) + offset;
107 
109  std::string rotstr = names[i];
110  DDTranslation tran(pos[0], pos[1], pos[2]);
111  DDName parentName = parent().name();
112 
113  static const double tol = 0.01_deg; // 0.01 degree
114  if (std::abs(angle) > tol) {
115 #ifdef EDM_ML_DEBUG
116  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Creating a rotation " << rotstr << "\t"
117  << convertRadToDeg(theta[0]) << "," << convertRadToDeg(phi[0]) << ","
118  << convertRadToDeg(theta[1]) << "," << convertRadToDeg(phi[1]) << ","
119  << convertRadToDeg(theta[2]) << "," << convertRadToDeg(phi[2]);
120 #endif
121  rotation = DDrot(DDName(rotstr, idNameSpace), theta[0], phi[0], theta[1], phi[1], theta[2], phi[2]);
122  }
123  cpv.position(DDName(idName, idNameSpace), parentName, i + 1, tran, rotation);
124 #ifdef EDM_ML_DEBUG
125  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: " << DDName(idName, idNameSpace) << " number " << i + 1
126  << " positioned in " << parentName << " at " << tran << " with " << rotation;
127 #endif
128  }
129 }
130 
131 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalXtalAlgo, "hcal:DDHCalXtalAlgo");
static AlgebraicMatrix initialize()
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
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
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
static std::string & ns()
std::vector< std::string > names
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:57
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:67
std::string idName
~DDHCalXtalAlgo() override
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::string idNameSpace
void execute(DDCompactView &cpv) override
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11