Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:56

0001 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0002 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0003 #include "DetectorDescription/Core/interface/DDCompactView.h"
0004 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0005 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0006 #include "DetectorDescription/Core/interface/DDName.h"
0007 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0008 #include "DetectorDescription/Core/interface/DDSplit.h"
0009 #include "DetectorDescription/Core/interface/DDTransform.h"
0010 #include "DetectorDescription/Core/interface/DDTranslation.h"
0011 #include "DetectorDescription/Core/interface/DDTypes.h"
0012 #include "DataFormats/Math/interface/GeantUnits.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/PluginManager/interface/PluginFactory.h"
0015 
0016 #include <cmath>
0017 #include <memory>
0018 
0019 using namespace geant_units::operators;
0020 
0021 class DDLinear : public DDAlgorithm {
0022 public:
0023   DDLinear() : m_n(1), m_startCopyNo(1), m_incrCopyNo(1), m_theta(0.), m_phi(0.), m_delta(0.) {}
0024 
0025   void initialize(const DDNumericArguments& nArgs,
0026                   const DDVectorArguments& vArgs,
0027                   const DDMapArguments& mArgs,
0028                   const DDStringArguments& sArgs,
0029                   const DDStringVectorArguments& vsArgs) override;
0030 
0031   void execute(DDCompactView& cpv) override;
0032 
0033 private:
0034   int m_n;                     //Number of copies
0035   int m_startCopyNo;           //Start Copy number
0036   int m_incrCopyNo;            //Increment in Copy number
0037   double m_theta;              //Theta
0038   double m_phi;                //Phi dir[Theta,Phi] ... unit-std::vector in direction Theta, Phi
0039   double m_delta;              //Delta - distance between two subsequent positions along dir[Theta,Phi]
0040   std::vector<double> m_base;  //Base values - a 3d-point where the offset is calculated from
0041                                //base is optional, if omitted base=(0,0,0)
0042   std::pair<std::string, std::string> m_childNmNs;  //Child name
0043                                                     //Namespace of the child
0044 };
0045 
0046 void DDLinear::initialize(const DDNumericArguments& nArgs,
0047                           const DDVectorArguments& vArgs,
0048                           const DDMapArguments&,
0049                           const DDStringArguments& sArgs,
0050                           const DDStringVectorArguments&) {
0051   m_n = int(nArgs["N"]);
0052   m_startCopyNo = int(nArgs["StartCopyNo"]);
0053   m_incrCopyNo = int(nArgs["IncrCopyNo"]);
0054   m_theta = nArgs["Theta"];
0055   m_phi = nArgs["Phi"];
0056   m_delta = nArgs["Delta"];
0057   m_base = vArgs["Base"];
0058 
0059   LogDebug("DDAlgorithm") << "DDLinear: Parameters for position"
0060                           << "ing:: n " << m_n << " Direction Theta, Phi, Offset, Delta " << convertRadToDeg(m_theta)
0061                           << " " << convertRadToDeg(m_phi) << " "
0062                           << " " << convertRadToDeg(m_delta) << " Base " << m_base[0] << ", " << m_base[1] << ", "
0063                           << m_base[2];
0064 
0065   m_childNmNs = DDSplit(sArgs["ChildName"]);
0066   if (m_childNmNs.second.empty())
0067     m_childNmNs.second = DDCurrentNamespace::ns();
0068 
0069   DDName parentName = parent().name();
0070   LogDebug("DDAlgorithm") << "DDLinear: Parent " << parentName << "\tChild " << m_childNmNs.first << " NameSpace "
0071                           << m_childNmNs.second;
0072 }
0073 
0074 void DDLinear::execute(DDCompactView& cpv) {
0075   DDName mother = parent().name();
0076   DDName ddname(m_childNmNs.first, m_childNmNs.second);
0077   int copy = m_startCopyNo;
0078 
0079   DDTranslation direction(sin(m_theta) * cos(m_phi), sin(m_theta) * sin(m_phi), cos(m_theta));
0080 
0081   DDTranslation basetr(m_base[0], m_base[1], m_base[2]);
0082 
0083   DDRotation rotation = DDRotation("IdentityRotation");
0084   if (!rotation) {
0085     LogDebug("DDAlgorithm") << "DDLinear: Creating a new "
0086                             << "rotation: IdentityRotation for " << ddname;
0087 
0088     rotation = DDrot("IdentityRotation", std::make_unique<DDRotationMatrix>());
0089   }
0090 
0091   for (int i = 0; i < m_n; ++i) {
0092     DDTranslation tran = basetr + (double(copy) * m_delta) * direction;
0093     cpv.position(ddname, mother, copy, tran, rotation);
0094     LogDebug("DDAlgorithm") << "DDLinear: " << m_childNmNs.second << ":" << m_childNmNs.first << " number " << copy
0095                             << " positioned in " << mother << " at " << tran << " with " << rotation;
0096     copy += m_incrCopyNo;
0097   }
0098 }
0099 
0100 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDLinear, "global:DDLinear");