CMS 3D CMS Logo

DDLinear.cc
Go to the documentation of this file.
15 
16 #include <cmath>
17 #include <memory>
18 
19 using namespace geant_units::operators;
20 
21 class DDLinear : public DDAlgorithm
22 {
23 public:
25  : m_n( 1 ),
26  m_startCopyNo( 1 ),
27  m_incrCopyNo( 1 ),
28  m_theta( 0. ),
29  m_phi( 0. ),
30  m_delta( 0. ) {}
31 
32  void initialize( const DDNumericArguments & nArgs,
33  const DDVectorArguments & vArgs,
34  const DDMapArguments & mArgs,
35  const DDStringArguments & sArgs,
36  const DDStringVectorArguments & vsArgs ) override;
37 
38  void execute( DDCompactView& cpv ) override;
39 
40 private:
41 
42  int m_n; //Number of copies
43  int m_startCopyNo; //Start Copy number
44  int m_incrCopyNo; //Increment in Copy number
45  double m_theta; //Theta
46  double m_phi; //Phi dir[Theta,Phi] ... unit-std::vector in direction Theta, Phi
47  double m_delta; //Delta - distance between two subsequent positions along dir[Theta,Phi]
48  std::vector<double> m_base; //Base values - a 3d-point where the offset is calculated from
49  //base is optional, if omitted base=(0,0,0)
50  std::pair<std::string, std::string> m_childNmNs; //Child name
51  //Namespace of the child
52 };
53 
54 void
56  const DDVectorArguments & vArgs,
57  const DDMapArguments & ,
58  const DDStringArguments & sArgs,
59  const DDStringVectorArguments & )
60 {
61  m_n = int(nArgs["N"]);
62  m_startCopyNo = int(nArgs["StartCopyNo"]);
63  m_incrCopyNo = int(nArgs["IncrCopyNo"]);
64  m_theta = nArgs["Theta"];
65  m_phi = nArgs["Phi"];
66  m_delta = nArgs["Delta"];
67  m_base = vArgs["Base"];
68 
69  LogDebug( "DDAlgorithm" ) << "DDLinear: Parameters for position"
70  << "ing:: n " << m_n << " Direction Theta, Phi, Offset, Delta "
71  << convertRadToDeg( m_theta ) << " "
72  << convertRadToDeg( m_phi ) << " "
73  << " " << convertRadToDeg( m_delta )
74  << " Base " << m_base[0]
75  << ", " << m_base[1] << ", " << m_base[2];
76 
77  m_childNmNs = DDSplit( sArgs["ChildName"] );
78  if( m_childNmNs.second.empty())
79  m_childNmNs.second = DDCurrentNamespace::ns();
80 
81  DDName parentName = parent().name();
82  LogDebug( "DDAlgorithm" ) << "DDLinear: Parent " << parentName
83  << "\tChild " << m_childNmNs.first << " NameSpace "
84  << m_childNmNs.second;
85 }
86 
87 void
89 {
90  DDName mother = parent().name();
91  DDName ddname( m_childNmNs.first, m_childNmNs.second );
92  int copy = m_startCopyNo;
93 
94  DDTranslation direction( sin( m_theta ) * cos( m_phi ),
95  sin( m_theta ) * sin( m_phi ),
96  cos( m_theta ));
97 
98  DDTranslation basetr( m_base[0],
99  m_base[1],
100  m_base[2] );
101 
102  DDRotation rotation = DDRotation( "IdentityRotation" );
103  if( !rotation )
104  {
105  LogDebug( "DDAlgorithm" ) << "DDLinear: Creating a new "
106  << "rotation: IdentityRotation for " << ddname;
107 
108  rotation = DDrot( "IdentityRotation", std::make_unique< DDRotationMatrix >());
109  }
110 
111  for( int i = 0; i < m_n; ++i )
112  {
113  DDTranslation tran = basetr + ( double( copy ) * m_delta ) * direction;
114  cpv.position( ddname, mother, copy, tran, rotation );
115  LogDebug( "DDAlgorithm" ) << "DDLinear: " << m_childNmNs.second << ":" << m_childNmNs.first << " number "
116  << copy << " positioned in " << mother << " at "
117  << tran << " with " << rotation;
118  copy += m_incrCopyNo;
119  }
120 }
121 
122 DEFINE_EDM_PLUGIN( DDAlgorithmFactory, DDLinear, "global:DDLinear");
#define LogDebug(id)
static AlgebraicMatrix initialize()
int m_startCopyNo
Definition: DDLinear.cc:43
def copy(args, dbName)
DDLinear()
Definition: DDLinear.cc:24
double m_phi
Definition: DDLinear.cc:46
int m_incrCopyNo
Definition: DDLinear.cc:44
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
constexpr NumType convertRadToDeg(NumType radians)
Definition: GeantUnits.h:98
double m_delta
Definition: DDLinear.cc:47
static std::string & ns()
void execute(DDCompactView &cpv) override
Definition: DDLinear.cc:88
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
std::pair< std::string, std::string > m_childNmNs
Definition: DDLinear.cc:50
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:68
double m_theta
Definition: DDLinear.cc:45
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:80
int m_n
Definition: DDLinear.cc:42
std::vector< double > m_base
Definition: DDLinear.cc:48
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
Definition: DDLinear.cc:55
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3