File indexing completed on 2024-04-06 12:14:45
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/DDTypes.h"
0016 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0017 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0018 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0019 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0020
0021 using namespace angle_units::operators;
0022
0023 class DDHCalTestBeamAlgo : public DDAlgorithm {
0024 public:
0025
0026 DDHCalTestBeamAlgo();
0027 ~DDHCalTestBeamAlgo() override;
0028
0029 void initialize(const DDNumericArguments& nArgs,
0030 const DDVectorArguments& vArgs,
0031 const DDMapArguments& mArgs,
0032 const DDStringArguments& sArgs,
0033 const DDStringVectorArguments& vsArgs) override;
0034
0035 void execute(DDCompactView& cpv) override;
0036
0037 private:
0038 double eta;
0039 double phi;
0040 double theta;
0041 double distance;
0042 double distanceZ;
0043 double dist;
0044 double dz;
0045 int copyNumber;
0046
0047 std::string idNameSpace;
0048 std::string childName;
0049 };
0050
0051 DDHCalTestBeamAlgo::DDHCalTestBeamAlgo() {
0052 #ifdef EDM_ML_DEBUG
0053 edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: Creating an instance";
0054 #endif
0055 }
0056
0057 DDHCalTestBeamAlgo::~DDHCalTestBeamAlgo() {}
0058
0059 void DDHCalTestBeamAlgo::initialize(const DDNumericArguments& nArgs,
0060 const DDVectorArguments&,
0061 const DDMapArguments&,
0062 const DDStringArguments& sArgs,
0063 const DDStringVectorArguments&) {
0064 eta = nArgs["Eta"];
0065 theta = 2.0 * atan(exp(-eta));
0066 phi = nArgs["Phi"];
0067 distance = nArgs["Dist"];
0068 distanceZ = nArgs["DistZ"];
0069 dz = nArgs["Dz"];
0070 copyNumber = int(nArgs["Number"]);
0071 dist = (distance + distanceZ / sin(theta));
0072 #ifdef EDM_ML_DEBUG
0073 edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: Parameters for position"
0074 << "ing--"
0075 << " Eta " << eta << "\tPhi " << convertRadToDeg(phi) << "\tTheta "
0076 << convertRadToDeg(theta) << "\tDistance " << distance << "/" << distanceZ << "/" << dist
0077 << "\tDz " << dz << "\tcopyNumber " << copyNumber;
0078 #endif
0079 idNameSpace = DDCurrentNamespace::ns();
0080 childName = sArgs["ChildName"];
0081 #ifdef EDM_ML_DEBUG
0082 edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo:Parent " << parent().name() << "\tChild " << childName
0083 << " NameSpace " << idNameSpace;
0084 #endif
0085 }
0086
0087 void DDHCalTestBeamAlgo::execute(DDCompactView& cpv) {
0088 double thetax = 90._deg + theta;
0089 double sthx = sin(thetax);
0090 if (std::abs(sthx) > 1.e-12)
0091 sthx = 1. / sthx;
0092 else
0093 sthx = 1.;
0094 double phix = atan2(sthx * cos(theta) * sin(phi), sthx * cos(theta) * cos(phi));
0095 double thetay = 90._deg;
0096 double phiy = 90._deg + phi;
0097 double thetaz = theta;
0098 double phiz = phi;
0099
0100 DDRotation rotation;
0101 std::string rotstr = childName;
0102 #ifdef EDM_ML_DEBUG
0103 edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: Creating a rotation " << rotstr << "\t"
0104 << convertRadToDeg(thetax) << "," << convertRadToDeg(phix) << ","
0105 << convertRadToDeg(thetay) << "," << convertRadToDeg(phiy) << ","
0106 << convertRadToDeg(thetaz) << "," << convertRadToDeg(phiz);
0107 #endif
0108 rotation = DDrot(DDName(rotstr, idNameSpace), thetax, phix, thetay, phiy, thetaz, phiz);
0109
0110 double r = dist * sin(theta);
0111 double xpos = r * cos(phi);
0112 double ypos = r * sin(phi);
0113 double zpos = dist * cos(theta);
0114 DDTranslation tran(xpos, ypos, zpos);
0115
0116 DDName parentName = parent().name();
0117 cpv.position(DDName(childName, idNameSpace), parentName, copyNumber, tran, rotation);
0118 #ifdef EDM_ML_DEBUG
0119 edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: " << DDName(childName, idNameSpace) << " number " << copyNumber
0120 << " positioned in " << parentName << " at " << tran << " with " << rotation;
0121
0122 xpos = (dist - dz) * sin(theta) * cos(phi);
0123 ypos = (dist - dz) * sin(theta) * sin(phi);
0124 zpos = (dist - dz) * cos(theta);
0125
0126 edm::LogInfo("HCalGeom") << "DDHCalTestBeamAlgo: Suggested Beam position "
0127 << "(" << xpos << ", " << ypos << ", " << zpos << ") and (dist, eta, phi) = (" << (dist - dz)
0128 << ", " << eta << ", " << phi << ")";
0129 #endif
0130 }
0131
0132 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalTestBeamAlgo, "hcal:DDHCalTestBeamAlgo");