File indexing completed on 2023-10-25 09:49:30
0001
0002
0003
0004
0005
0006 #include <cmath>
0007 #include <algorithm>
0008 #include <map>
0009 #include <string>
0010 #include <vector>
0011
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/PluginManager/interface/PluginFactory.h"
0014 #include "DataFormats/Math/interface/angle_units.h"
0015 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0016 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0017 #include "DetectorDescription/Core/interface/DDTypes.h"
0018 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0019 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0020
0021
0022 using namespace angle_units::operators;
0023
0024 class DDHCalXtalAlgo : public DDAlgorithm {
0025 public:
0026
0027 DDHCalXtalAlgo();
0028 ~DDHCalXtalAlgo() override;
0029
0030 void initialize(const DDNumericArguments& nArgs,
0031 const DDVectorArguments& vArgs,
0032 const DDMapArguments& mArgs,
0033 const DDStringArguments& sArgs,
0034 const DDStringVectorArguments& vsArgs) override;
0035
0036 void execute(DDCompactView& cpv) override;
0037
0038 private:
0039 double radius;
0040 double offset;
0041 double dx;
0042 double dz;
0043 double angwidth;
0044 int iaxis;
0045 std::vector<std::string> names;
0046
0047 std::string idNameSpace;
0048 std::string idName;
0049 };
0050
0051 DDHCalXtalAlgo::DDHCalXtalAlgo() {
0052 #ifdef EDM_ML_DEBUG
0053 edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo info: Creating an instance";
0054 #endif
0055 }
0056
0057 DDHCalXtalAlgo::~DDHCalXtalAlgo() {}
0058
0059 void DDHCalXtalAlgo::initialize(const DDNumericArguments& nArgs,
0060 const DDVectorArguments&,
0061 const DDMapArguments&,
0062 const DDStringArguments& sArgs,
0063 const DDStringVectorArguments& vsArgs) {
0064 radius = nArgs["Radius"];
0065 offset = nArgs["Offset"];
0066 dx = nArgs["Dx"];
0067 dz = nArgs["Dz"];
0068 angwidth = nArgs["AngWidth"];
0069 iaxis = int(nArgs["Axis"]);
0070 names = vsArgs["Names"];
0071
0072 #ifdef EDM_ML_DEBUG
0073 edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo::Parameters for positioning:"
0074 << " Axis " << iaxis << "\tRadius " << radius << "\tOffset " << offset << "\tDx " << dx
0075 << "\tDz " << dz << "\tAngWidth " << convertRadToDeg(angwidth) << "\tNumbers "
0076 << names.size();
0077 for (unsigned int i = 0; i < names.size(); i++)
0078 edm::LogVerbatim("HCalGeom") << "\tnames[" << i << "] = " << names[i];
0079 #endif
0080 idNameSpace = DDCurrentNamespace::ns();
0081 idName = sArgs["ChildName"];
0082 #ifdef EDM_ML_DEBUG
0083 edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Parent " << parent().name() << "\tChild " << idName << " NameSpace "
0084 << idNameSpace;
0085 #endif
0086 }
0087
0088 void DDHCalXtalAlgo::execute(DDCompactView& cpv) {
0089 double theta[3], phi[3], pos[3];
0090 phi[0] = 0;
0091 phi[1] = 90._deg;
0092 theta[1 - iaxis] = 90._deg;
0093 pos[1 - iaxis] = 0;
0094 int number = (int)(names.size());
0095 for (int i = 0; i < number; i++) {
0096 double angle = 0.5 * angwidth * (2 * i + 1 - number);
0097 theta[iaxis] = 90._deg + angle;
0098 if (angle > 0) {
0099 theta[2] = angle;
0100 phi[2] = iaxis * 90._deg;
0101 } else {
0102 theta[2] = -angle;
0103 phi[2] = (2 - 3 * iaxis) * 90._deg;
0104 }
0105 pos[iaxis] = angle * (dz + radius);
0106 pos[2] = dx * std::abs(sin(angle)) + offset;
0107
0108 DDRotation rotation;
0109 std::string rotstr = names[i];
0110 DDTranslation tran(pos[0], pos[1], pos[2]);
0111 DDName parentName = parent().name();
0112
0113 static const double tol = 0.01_deg;
0114 if (std::abs(angle) > tol) {
0115 #ifdef EDM_ML_DEBUG
0116 edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Creating a rotation " << rotstr << "\t"
0117 << convertRadToDeg(theta[0]) << "," << convertRadToDeg(phi[0]) << ","
0118 << convertRadToDeg(theta[1]) << "," << convertRadToDeg(phi[1]) << ","
0119 << convertRadToDeg(theta[2]) << "," << convertRadToDeg(phi[2]);
0120 #endif
0121 rotation = DDrot(DDName(rotstr, idNameSpace), theta[0], phi[0], theta[1], phi[1], theta[2], phi[2]);
0122 }
0123 cpv.position(DDName(idName, idNameSpace), parentName, i + 1, tran, rotation);
0124 #ifdef EDM_ML_DEBUG
0125 edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: " << DDName(idName, idNameSpace) << " number " << i + 1
0126 << " positioned in " << parentName << " at " << tran << " with " << rotation;
0127 #endif
0128 }
0129 }
0130
0131 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalXtalAlgo, "hcal:DDHCalXtalAlgo");