File indexing completed on 2023-03-17 13:03:28
0001
0002
0003
0004
0005
0006 #include <algorithm>
0007 #include <cmath>
0008 #include <map>
0009 #include <string>
0010 #include <vector>
0011
0012 #include "DataFormats/Math/interface/angle_units.h"
0013 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0014 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0015 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0016 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0017 #include "DetectorDescription/Core/interface/DDTypes.h"
0018 #include "DetectorDescription/Core/interface/DDutils.h"
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "FWCore/PluginManager/interface/PluginFactory.h"
0021 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0022
0023
0024 using namespace angle_units::operators;
0025
0026 class DDHGCalWaferAlgo : public DDAlgorithm {
0027 public:
0028
0029 DDHGCalWaferAlgo();
0030
0031 void initialize(const DDNumericArguments& nArgs,
0032 const DDVectorArguments& vArgs,
0033 const DDMapArguments& mArgs,
0034 const DDStringArguments& sArgs,
0035 const DDStringVectorArguments& vsArgs) override;
0036 void execute(DDCompactView& cpv) override;
0037
0038 private:
0039 double cellSize_;
0040 int cellType_;
0041 std::vector<std::string> childNames_;
0042 std::vector<int> positionX_;
0043 std::vector<int> positionY_;
0044 std::vector<double> angles_;
0045 std::vector<int> detectorType_;
0046 std::string rotns_;
0047 std::string idNameSpace_;
0048 DDName parentName_;
0049 };
0050
0051 DDHGCalWaferAlgo::DDHGCalWaferAlgo() {
0052 #ifdef EDM_ML_DEBUG
0053 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating an instance";
0054 #endif
0055 }
0056
0057 void DDHGCalWaferAlgo::initialize(const DDNumericArguments& nArgs,
0058 const DDVectorArguments& vArgs,
0059 const DDMapArguments&,
0060 const DDStringArguments& sArgs,
0061 const DDStringVectorArguments& vsArgs) {
0062 cellSize_ = nArgs["CellSize"];
0063 cellType_ = (int)(nArgs["CellType"]);
0064 childNames_ = vsArgs["ChildNames"];
0065 positionX_ = dbl_to_int(vArgs["PositionX"]);
0066 positionY_ = dbl_to_int(vArgs["PositionY"]);
0067 angles_ = vArgs["Angles"];
0068 detectorType_ = dbl_to_int(vArgs["DetectorType"]);
0069 #ifdef EDM_ML_DEBUG
0070 edm::LogVerbatim("HGCalGeom") << childNames_.size() << " children: " << childNames_[0] << "; " << childNames_[1]
0071 << " positioned " << positionX_.size() << " times with cell size " << cellSize_;
0072 for (unsigned int k = 0; k < positionX_.size(); ++k)
0073 edm::LogVerbatim("HGCalGeom") << "[" << k << "] x " << positionX_[k] << " y " << positionY_[k] << " angle "
0074 << angles_[k] << " detector " << detectorType_[k];
0075 #endif
0076 rotns_ = sArgs["RotNameSpace"];
0077 idNameSpace_ = DDCurrentNamespace::ns();
0078 parentName_ = parent().name();
0079 #ifdef EDM_ML_DEBUG
0080 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo debug: Parent " << parentName_ << " NameSpace " << idNameSpace_
0081 << " for Rotation " << rotns_;
0082 #endif
0083 }
0084
0085 void DDHGCalWaferAlgo::execute(DDCompactView& cpv) {
0086 #ifdef EDM_ML_DEBUG
0087 edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalWaferAlgo...";
0088 #endif
0089 double dx = 0.5 * cellSize_;
0090 double dy = 0.5 * dx * tan(30._deg);
0091
0092 for (unsigned int k = 0; k < positionX_.size(); ++k) {
0093 std::string name(childNames_[detectorType_[k]]);
0094 DDRotation rotation;
0095 std::string rotstr("NULL");
0096 if (angles_[k] != 0) {
0097 double phi = convertDegToRad(angles_[k]);
0098 rotstr = "R" + formatAsDegrees(phi);
0099 rotation = DDRotation(DDName(rotstr, rotns_));
0100 if (!rotation) {
0101 #ifdef EDM_ML_DEBUG
0102 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating new rotation " << DDName(rotstr, rotns_)
0103 << "\t90, " << angles_[k] << ", 90, " << (angles_[k] + 90) << ", 0, 0";
0104 #endif
0105 rotation = DDrot(DDName(rotstr, rotns_), 90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
0106 }
0107 }
0108 double xpos = dx * positionX_[k];
0109 double ypos = dy * positionY_[k];
0110 DDTranslation tran(xpos, ypos, 0);
0111 int copy = HGCalTypes::packCellType6(cellType_, k);
0112 cpv.position(DDName(name, idNameSpace_), parentName_, copy, tran, rotation);
0113 #ifdef EDM_ML_DEBUG
0114 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: " << DDName(name, idNameSpace_) << " number " << copy
0115 << " positioned in " << parentName_ << " at " << tran << " with " << rotation;
0116 #endif
0117 }
0118 }
0119
0120 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferAlgo, "hgcal:DDHGCalWaferAlgo");