CMS 3D CMS Logo

DDHGCalWaferAlgo.cc
Go to the documentation of this file.
1 // File: DDHGCalWaferAlgo.cc
3 // Description: Position inside the mother according to (eta,phi)
5 
6 #include <algorithm>
7 #include <cmath>
8 #include <map>
9 #include <string>
10 #include <vector>
11 
21 
22 //#define EDM_ML_DEBUG
23 using namespace geant_units::operators;
24 
25 class DDHGCalWaferAlgo : public DDAlgorithm {
26 public:
27  // Constructor and Destructor
29  ~DDHGCalWaferAlgo() override;
30 
31  void initialize(const DDNumericArguments& nArgs,
32  const DDVectorArguments& vArgs,
33  const DDMapArguments& mArgs,
34  const DDStringArguments& sArgs,
35  const DDStringVectorArguments& vsArgs) override;
36  void execute(DDCompactView& cpv) override;
37 
38 private:
39  double cellSize; // Cell Size
40  int cellType; // Type (1 fine; 2 coarse)
41  std::vector<std::string> childNames; // Names of children
42  std::vector<int> positionX; // Position in X
43  std::vector<int> positionY; // Position in Y
44  std::vector<double> angles; // Rotation angle
45  std::vector<int> detectorType; // Detector type
46  std::string idName; // Name of the "parent" volume.
47  std::string rotns; // Namespace for rotation matrix
48  std::string idNameSpace; // Namespace of this and ALL sub-parts
49  DDName parentName; // Parent name
50 };
51 
53 #ifdef EDM_ML_DEBUG
54  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating an instance";
55 #endif
56 }
57 
59 
61  const DDVectorArguments& vArgs,
62  const DDMapArguments&,
63  const DDStringArguments& sArgs,
64  const DDStringVectorArguments& vsArgs) {
65  cellSize = nArgs["CellSize"];
66  cellType = (int)(nArgs["CellType"]);
67  childNames = vsArgs["ChildNames"];
68  positionX = dbl_to_int(vArgs["PositionX"]);
69  positionY = dbl_to_int(vArgs["PositionY"]);
70  angles = vArgs["Angles"];
71  detectorType = dbl_to_int(vArgs["DetectorType"]);
72 #ifdef EDM_ML_DEBUG
73  edm::LogVerbatim("HGCalGeom") << childNames.size() << " children: " << childNames[0] << "; " << childNames[1]
74  << " positioned " << positionX.size() << " times with cell size " << cellSize;
75  for (unsigned int k = 0; k < positionX.size(); ++k)
76  edm::LogVerbatim("HGCalGeom") << "[" << k << "] x " << positionX[k] << " y " << positionY[k] << " angle "
77  << angles[k] << " detector " << detectorType[k];
78 #endif
79  rotns = sArgs["RotNameSpace"];
80  idNameSpace = DDCurrentNamespace::ns();
81  parentName = parent().name();
82 #ifdef EDM_ML_DEBUG
83  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo debug: Parent " << parentName << " NameSpace " << idNameSpace
84  << " for Rotation " << rotns;
85 #endif
86 }
87 
89 #ifdef EDM_ML_DEBUG
90  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalWaferAlgo...";
91 #endif
92  double dx = 0.5 * cellSize;
93  double dy = 0.5 * dx * tan(30._deg);
94 
95  for (unsigned int k = 0; k < positionX.size(); ++k) {
96  std::string name(childNames[detectorType[k]]);
98  std::string rotstr("NULL");
99  if (angles[k] != 0) {
100  double phi = convertDegToRad(angles[k]);
101  rotstr = "R" + formatAsDegrees(phi);
102  rotation = DDRotation(DDName(rotstr, rotns));
103  if (!rotation) {
104 #ifdef EDM_ML_DEBUG
105  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating new rotation " << DDName(rotstr, rotns) << "\t90, "
106  << angles[k] << ", 90, " << (angles[k] + 90) << ", 0, 0";
107 #endif
108  rotation = DDrot(DDName(rotstr, rotns), 90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
109  }
110  }
111  double xpos = dx * positionX[k];
112  double ypos = dy * positionY[k];
113  DDTranslation tran(xpos, ypos, 0);
114  int copy = cellType * 1000 + k;
115  cpv.position(DDName(name, idNameSpace), parentName, copy, tran, rotation);
116 #ifdef EDM_ML_DEBUG
117  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: " << DDName(name, idNameSpace) << " number " << copy
118  << " positioned in " << parentName << " at " << tran << " with " << rotation;
119 #endif
120  }
121 }
122 
123 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferAlgo, "hgcal:DDHGCalWaferAlgo");
static AlgebraicMatrix initialize()
constexpr long double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
Definition: DDutils.h:7
std::string idNameSpace
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
std::vector< int > positionX
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 formatAsDegrees(double radianVal)
Definition: DDTypes.cc:68
std::vector< int > detectorType
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
std::vector< std::string > childNames
std::vector< int > positionY
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
~DDHGCalWaferAlgo() override
std::vector< double > angles
#define DEFINE_EDM_PLUGIN(factory, type, name)
ROOT::Math::Rotation3D DDRotation
void execute(DDCompactView &cpv) override