Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:37

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDBHMAngular.cc
0003 // Description: Position inside the mother according to phi
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include <algorithm>
0007 #include <cmath>
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/GeantUnits.h"
0015 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0016 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0017 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0018 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0019 #include "DetectorDescription/Core/interface/DDSplit.h"
0020 #include "DetectorDescription/Core/interface/DDTypes.h"
0021 #include "DetectorDescription/Core/interface/DDutils.h"
0022 
0023 using namespace geant_units::operators;
0024 
0025 //#define EDM_ML_DEBUG
0026 
0027 class DDBHMAngular : public DDAlgorithm {
0028 public:
0029   //Constructor and Destructor
0030   DDBHMAngular();
0031 
0032   void initialize(const DDNumericArguments& nArgs,
0033                   const DDVectorArguments& vArgs,
0034                   const DDMapArguments& mArgs,
0035                   const DDStringArguments& sArgs,
0036                   const DDStringVectorArguments& vsArgs) override;
0037 
0038   void execute(DDCompactView& cpv) override;
0039 
0040 private:
0041   int units;    //Number of copies
0042   double rr;    //Radial position of the detectors
0043   double dphi;  //the distance in phi between the detectors
0044 
0045   std::string rotMat;     //Name of the rotation matrix
0046   std::string childName;  //Children name
0047 };
0048 
0049 DDBHMAngular::DDBHMAngular() { edm::LogVerbatim("ForwardGeom") << "DDBHMAngular test: Creating an instance"; }
0050 
0051 void DDBHMAngular::initialize(const DDNumericArguments& nArgs,
0052                               const DDVectorArguments&,
0053                               const DDMapArguments&,
0054                               const DDStringArguments& sArgs,
0055                               const DDStringVectorArguments&) {
0056   units = int(nArgs["number"]);
0057   rr = nArgs["radius"];
0058   dphi = nArgs["deltaPhi"];
0059 #ifdef EDM_ML_DEBUG
0060   edm::LogVerbatim("ForwardGeom") << "DDBHMAngular debug: Parameters for positioning-- " << units
0061                                   << " copies at radius " << convertMmToCm(rr) << " cm with delta(phi) "
0062                                   << convertRadToDeg(dphi);
0063 #endif
0064   rotMat = sArgs["Rotation"];
0065   childName = sArgs["ChildName"];
0066 #ifdef EDM_ML_DEBUG
0067   edm::LogVerbatim("ForwardGeom") << "DDBHMAngular debug: Parent " << parent().name() << "\tChild " << childName
0068                                   << "\tRotation matrix " << rotMat;
0069 #endif
0070 }
0071 
0072 void DDBHMAngular::execute(DDCompactView& cpv) {
0073   DDName child(DDSplit(childName).first, DDSplit(childName).second);
0074   DDName parentName = parent().name();
0075   std::string rotstr = DDSplit(rotMat).first;
0076   DDRotation rot;
0077   if (rotstr != "NULL") {
0078     std::string rotns = DDSplit(rotMat).second;
0079     rot = DDRotation(DDName(rotstr, rotns));
0080   }
0081 
0082   static const double fac1 = 0.5;
0083   static const double fac2 = 1.5;
0084   static const double fac3 = 14.5;
0085   static const double fac4 = 15.5;
0086   for (int jj = 0; jj < units; jj++) {
0087     double driverX(0), driverY(0), driverZ(0);
0088     if (jj < 16) {
0089       driverX = rr * cos((jj + fac1) * dphi);
0090       driverY = sqrt(rr * rr - driverX * driverX);
0091     } else if (jj == 16) {
0092       driverX = rr * cos(fac4 * dphi);
0093       driverY = -sqrt(rr * rr - driverX * driverX);
0094     } else if (jj == 17) {
0095       driverX = rr * cos(fac3 * dphi);
0096       driverY = -sqrt(rr * rr - driverX * driverX);
0097     } else if (jj == 18) {
0098       driverX = rr * cos(fac1 * dphi);
0099       driverY = -sqrt(rr * rr - driverX * driverX);
0100     } else if (jj == 19) {
0101       driverX = rr * cos(fac2 * dphi);
0102       driverY = -sqrt(rr * rr - driverX * driverX);
0103     }
0104     DDTranslation tran(driverX, driverY, driverZ);
0105 
0106     cpv.position(child, parentName, jj + 1, tran, rot);
0107 #ifdef EDM_ML_DEBUG
0108     edm::LogVerbatim("ForwardGeom") << "DDBHMAngular test: " << child << " number " << jj + 1 << " positioned in "
0109                                     << parentName << " at " << tran << " with " << rot;
0110 #endif
0111   }
0112 }
0113 
0114 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDBHMAngular, "bhmalgo:DDBHMAngular");