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 
22 
23 //#define EDM_ML_DEBUG
24 using namespace angle_units::operators;
25 
26 class DDHGCalWaferAlgo : public DDAlgorithm {
27 public:
28  // Constructor and Destructor
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 rotns_; // Namespace for rotation matrix
47  std::string idNameSpace_; // Namespace of this and ALL sub-parts
48  DDName parentName_; // Parent name
49 };
50 
52 #ifdef EDM_ML_DEBUG
53  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating an instance";
54 #endif
55 }
56 
58  const DDVectorArguments& vArgs,
59  const DDMapArguments&,
60  const DDStringArguments& sArgs,
61  const DDStringVectorArguments& vsArgs) {
62  cellSize_ = nArgs["CellSize"];
63  cellType_ = (int)(nArgs["CellType"]);
64  childNames_ = vsArgs["ChildNames"];
65  positionX_ = dbl_to_int(vArgs["PositionX"]);
66  positionY_ = dbl_to_int(vArgs["PositionY"]);
67  angles_ = vArgs["Angles"];
68  detectorType_ = dbl_to_int(vArgs["DetectorType"]);
69 #ifdef EDM_ML_DEBUG
70  edm::LogVerbatim("HGCalGeom") << childNames_.size() << " children: " << childNames_[0] << "; " << childNames_[1]
71  << " positioned " << positionX_.size() << " times with cell size " << cellSize_;
72  for (unsigned int k = 0; k < positionX_.size(); ++k)
73  edm::LogVerbatim("HGCalGeom") << "[" << k << "] x " << positionX_[k] << " y " << positionY_[k] << " angle "
74  << angles_[k] << " detector " << detectorType_[k];
75 #endif
76  rotns_ = sArgs["RotNameSpace"];
77  idNameSpace_ = DDCurrentNamespace::ns();
78  parentName_ = parent().name();
79 #ifdef EDM_ML_DEBUG
80  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo debug: Parent " << parentName_ << " NameSpace " << idNameSpace_
81  << " for Rotation " << rotns_;
82 #endif
83 }
84 
86 #ifdef EDM_ML_DEBUG
87  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalWaferAlgo...";
88 #endif
89  double dx = 0.5 * cellSize_;
90  double dy = 0.5 * dx * tan(30._deg);
91 
92  for (unsigned int k = 0; k < positionX_.size(); ++k) {
93  std::string name(childNames_[detectorType_[k]]);
95  std::string rotstr("NULL");
96  if (angles_[k] != 0) {
97  double phi = convertDegToRad(angles_[k]);
98  rotstr = "R" + formatAsDegrees(phi);
99  rotation = DDRotation(DDName(rotstr, rotns_));
100  if (!rotation) {
101 #ifdef EDM_ML_DEBUG
102  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating new rotation " << DDName(rotstr, rotns_)
103  << "\t90, " << angles_[k] << ", 90, " << (angles_[k] + 90) << ", 0, 0";
104 #endif
105  rotation = DDrot(DDName(rotstr, rotns_), 90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
106  }
107  }
108  double xpos = dx * positionX_[k];
109  double ypos = dy * positionY_[k];
110  DDTranslation tran(xpos, ypos, 0);
111  int copy = HGCalTypes::packCellType6(cellType_, k);
112  cpv.position(DDName(name, idNameSpace_), parentName_, copy, tran, rotation);
113 #ifdef EDM_ML_DEBUG
114  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: " << DDName(name, idNameSpace_) << " number " << copy
115  << " positioned in " << parentName_ << " at " << tran << " with " << rotation;
116 #endif
117  }
118 }
119 
120 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferAlgo, "hgcal:DDHGCalWaferAlgo");
Log< level::Info, true > LogVerbatim
static AlgebraicMatrix initialize()
std::vector< int > positionY_
constexpr double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
std::string idNameSpace_
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
std::vector< int > positionX_
std::vector< int > detectorType_
std::vector< double > angles_
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
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
std::vector< std::string > childNames_
#define DEFINE_EDM_PLUGIN(factory, type, name)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
void execute(DDCompactView &cpv) override