File indexing completed on 2023-03-17 11:05:20
0001
0002
0003
0004
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0008 #include "DetectorDescription/Core/interface/DDSplit.h"
0009 #include "DetectorDescription/Core/interface/DDTypes.h"
0010 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0011 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0012 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0013 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0014
0015 #include <cmath>
0016 #include <algorithm>
0017 #include <map>
0018 #include <string>
0019 #include <vector>
0020
0021 using namespace std;
0022
0023 class DDTECOptoHybAlgo : public DDAlgorithm {
0024 public:
0025
0026 DDTECOptoHybAlgo();
0027 ~DDTECOptoHybAlgo() 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 string idNameSpace;
0039 string childName;
0040 double rpos;
0041 double zpos;
0042 double optoHeight;
0043 double optoWidth;
0044 int startCopyNo;
0045 vector<double> angles;
0046 };
0047
0048 DDTECOptoHybAlgo::DDTECOptoHybAlgo() : angles(0) {
0049 LogDebug("TECGeom") << "DDTECOptoHybAlgo info: Creating an instance";
0050 }
0051
0052 DDTECOptoHybAlgo::~DDTECOptoHybAlgo() {}
0053
0054 void DDTECOptoHybAlgo::initialize(const DDNumericArguments& nArgs,
0055 const DDVectorArguments& vArgs,
0056 const DDMapArguments&,
0057 const DDStringArguments& sArgs,
0058 const DDStringVectorArguments&) {
0059 idNameSpace = DDCurrentNamespace::ns();
0060 childName = sArgs["ChildName"];
0061
0062 DDName parentName = parent().name();
0063
0064 LogDebug("TECGeom") << "DDTECOptoHybAlgo debug: Parent " << parentName << " Child " << childName << " NameSpace "
0065 << idNameSpace;
0066
0067 optoHeight = nArgs["OptoHeight"];
0068 optoWidth = nArgs["OptoWidth"];
0069 rpos = nArgs["Rpos"];
0070 zpos = nArgs["Zpos"];
0071 startCopyNo = int(nArgs["StartCopyNo"]);
0072 angles = vArgs["Angles"];
0073
0074 LogDebug("TECGeom") << "DDTECOptoHybAlgo debug: Height of the Hybrid " << optoHeight << " and Width " << optoWidth
0075 << "Rpos " << rpos << " Zpos " << zpos << " StartCopyNo " << startCopyNo << " Number "
0076 << angles.size();
0077
0078 for (int i = 0; i < (int)(angles.size()); i++)
0079 LogDebug("TECGeom") << "\tAngles[" << i << "] = " << angles[i];
0080 }
0081
0082 void DDTECOptoHybAlgo::execute(DDCompactView& cpv) {
0083 LogDebug("TECGeom") << "==>> Constructing DDTECOptoHybAlgo...";
0084
0085 DDName mother = parent().name();
0086 DDName child = DDName(DDSplit(childName).first, DDSplit(childName).second);
0087
0088
0089 rpos += optoHeight / 2;
0090 int copyNo = startCopyNo;
0091 for (double angle : angles) {
0092 double phix = -angle;
0093
0094 phix += asin(optoWidth / 2 / rpos);
0095 double xpos = rpos * cos(phix);
0096 double ypos = rpos * sin(phix);
0097 DDTranslation tran(xpos, ypos, zpos);
0098
0099 DDRotation rotation;
0100 double phiy = phix + 90. * CLHEP::deg;
0101 double phideg = phix / CLHEP::deg;
0102 if (phideg != 0) {
0103 string rotstr = DDSplit(childName).first + to_string(phideg * 1000.);
0104 rotation = DDRotation(DDName(rotstr, idNameSpace));
0105 if (!rotation) {
0106 double theta = 90. * CLHEP::deg;
0107 LogDebug("TECGeom") << "DDTECOptoHybAlgo test: Creating a new "
0108 << "rotation: " << rotstr << "\t90., " << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg
0109 << ", 0, 0";
0110 rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
0111 }
0112 }
0113
0114 cpv.position(child, mother, copyNo, tran, rotation);
0115 LogDebug("TECGeom") << "DDTECOptoHybAlgo test " << child << " number " << copyNo << " positioned in " << mother
0116 << " at " << tran << " with " << rotation;
0117 copyNo++;
0118 }
0119
0120 LogDebug("TECGeom") << "<<== End of DDTECOptoHybAlgo construction ...";
0121 }
0122
0123 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTECOptoHybAlgo, "track:DDTECOptoHybAlgo");