CMS 3D CMS Logo

DDHGCalWafer.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cmath>
3 #include <map>
4 #include <string>
5 #include <vector>
6 
18 
19 //#define EDM_ML_DEBUG
20 using namespace angle_units::operators;
21 
22 class DDHGCalWafer : public DDAlgorithm {
23 public:
24  // Constructor and Destructor
25  DDHGCalWafer();
26  ~DDHGCalWafer() override;
27 
28  void initialize(const DDNumericArguments& nArgs,
29  const DDVectorArguments& vArgs,
30  const DDMapArguments& mArgs,
31  const DDStringArguments& sArgs,
32  const DDStringVectorArguments& vsArgs) override;
33  void execute(DDCompactView& cpv) override;
34 
35 private:
36  double waferSize_; // Wafer Size
37  int cellType_; // Type (1 fine; 2 coarse)
38  int nColumns_; // Maximum number of columns
39  int nBottomY_; // Index of cell position of bottom row
40  std::vector<std::string> childNames_; // Names of children
41  std::vector<int> nCellsRow_; // Number of cells in a row
42  std::vector<int> angleEdges_; // Rotation angles to be used for edges
43  std::vector<int> detectorType_; // Detector type of edge cells
44  std::string idNameSpace_; // Namespace of this and ALL sub-parts
45  DDName parentName_; // Parent name
46 };
47 
49 #ifdef EDM_ML_DEBUG
50  edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer: Creating an instance";
51 #endif
52 }
53 
55 
57  const DDVectorArguments& vArgs,
58  const DDMapArguments&,
59  const DDStringArguments& sArgs,
60  const DDStringVectorArguments& vsArgs) {
61  waferSize_ = nArgs["WaferSize"];
62  cellType_ = (int)(nArgs["CellType"]);
63  nColumns_ = (int)(nArgs["NColumns"]);
64  nBottomY_ = (int)(nArgs["NBottomY"]);
65  childNames_ = vsArgs["ChildNames"];
66  nCellsRow_ = dbl_to_int(vArgs["NCellsRow"]);
67  angleEdges_ = dbl_to_int(vArgs["AngleEdges"]);
68  detectorType_ = dbl_to_int(vArgs["DetectorType"]);
69  idNameSpace_ = DDCurrentNamespace::ns();
70  parentName_ = parent().name();
71 #ifdef EDM_ML_DEBUG
72  edm::LogVerbatim("HGCalGeom") << childNames_.size() << " children: " << childNames_[0] << "; " << childNames_[1]
73  << " in namespace " << idNameSpace_ << " positioned in " << nCellsRow_.size()
74  << " rows and " << nColumns_ << " columns with lowest column at " << nBottomY_
75  << " in mother " << parentName_ << " of size " << waferSize_;
76  for (unsigned int k = 0; k < nCellsRow_.size(); ++k)
77  edm::LogVerbatim("HGCalGeom") << "[" << k << "] Ncells " << nCellsRow_[k] << " Edge rotations "
78  << angleEdges_[2 * k] << ":" << angleEdges_[2 * k + 1] << " Type of edge cells "
79  << detectorType_[2 * k] << ":" << detectorType_[2 * k + 1];
80 #endif
81 }
82 
84 #ifdef EDM_ML_DEBUG
85  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalWafer...";
86 #endif
87  double dx = 0.5 * waferSize_ / nColumns_;
88  double dy = 0.5 * dx * tan(30._deg);
89  int ny = nBottomY_;
90  int kount(0);
91 
92  for (unsigned int ir = 0; ir < nCellsRow_.size(); ++ir) {
93  int nx = 1 - nCellsRow_[ir];
94  double ypos = dy * ny;
95  for (int ic = 0; ic < nCellsRow_[ir]; ++ic) {
96  std::string name(childNames_[0]), rotstr("NULL");
97  int irot(0);
98  if (ic == 0) {
99  name = childNames_[detectorType_[2 * ir]];
100  irot = angleEdges_[2 * ir];
101  } else if (ic + 1 == nCellsRow_[ir]) {
102  name = childNames_[detectorType_[2 * ir + 1]];
103  irot = angleEdges_[2 * ir + 1];
104  }
105  DDRotation rot;
106  if (irot != 0) {
107  double phi = convertDegToRad(irot);
108  rotstr = "R" + formatAsDegrees(phi);
109  rot = DDRotation(DDName(rotstr, idNameSpace_));
110  if (!rot) {
111 #ifdef EDM_ML_DEBUG
112  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating new rotation " << DDName(rotstr, idNameSpace_)
113  << "\t90, " << irot << ", 90, " << (irot + 90) << ", 0, 0";
114 #endif
115  rot = DDrot(DDName(rotstr, idNameSpace_), 90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
116  }
117  }
118  double xpos = dx * nx;
119  nx += 2;
120  DDTranslation tran(xpos, ypos, 0);
121  int copy = HGCalTypes::packCellType6(cellType_, kount);
122  cpv.position(DDName(name, idNameSpace_), parentName_, copy, tran, rot);
123  ++kount;
124 #ifdef EDM_ML_DEBUG
125  edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer: " << DDName(name, idNameSpace_) << " number " << copy
126  << " positioned in " << parentName_ << " at " << tran << " with " << rot;
127 #endif
128  }
129  ny += 6;
130  }
131 }
132 
133 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWafer, "hgcal:DDHGCalWafer");
Log< level::Info, true > LogVerbatim
static AlgebraicMatrix initialize()
constexpr double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
Definition: DDHGCalWafer.cc:56
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
static std::string & ns()
std::vector< int > detectorType_
Definition: DDHGCalWafer.cc:43
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
double waferSize_
Definition: DDHGCalWafer.cc:36
std::vector< std::string > childNames_
Definition: DDHGCalWafer.cc:40
std::vector< int > nCellsRow_
Definition: DDHGCalWafer.cc:41
Tan< T >::type tan(const T &t)
Definition: Tan.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 formatAsDegrees(double radianVal)
Definition: DDTypes.cc:68
static int32_t packCellType6(int type, int cell)
Definition: HGCalTypes.cc:36
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
~DDHGCalWafer() override
Definition: DDHGCalWafer.cc:54
std::vector< int > angleEdges_
Definition: DDHGCalWafer.cc:42
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::string idNameSpace_
Definition: DDHGCalWafer.cc:44
void execute(DDCompactView &cpv) override
Definition: DDHGCalWafer.cc:83
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
DDName parentName_
Definition: DDHGCalWafer.cc:45