CMS 3D CMS Logo

DDTECPhiAltAlgo.cc
Go to the documentation of this file.
1 // File: DDTECPhiAltAlgo.cc
3 // Description: Position n copies inside and outside Z at alternate phi values
5 
12 #include "CLHEP/Units/GlobalPhysicalConstants.h"
13 #include "CLHEP/Units/GlobalSystemOfUnits.h"
14 
15 #include <cmath>
16 #include <algorithm>
17 #include <map>
18 #include <string>
19 #include <vector>
20 
21 using namespace std;
22 
23 class DDTECPhiAltAlgo : public DDAlgorithm {
24 public:
25  //Constructor and Destructor
27  ~DDTECPhiAltAlgo() override;
28 
29  void initialize(const DDNumericArguments& nArgs,
30  const DDVectorArguments& vArgs,
31  const DDMapArguments& mArgs,
32  const DDStringArguments& sArgs,
33  const DDStringVectorArguments& vsArgs) override;
34 
35  void execute(DDCompactView& cpv) override;
36 
37 private:
38  double startAngle; //Start angle
39  double incrAngle; //Increment in angle
40  double radius; //Radius
41  double zIn; //z position for the even ones
42  double zOut; //z position for the odd ones
43  int number; //Number of copies
44  int startCopyNo; //Start copy number
45  int incrCopyNo; //Increment in copy number
46 
47  string idNameSpace; //Namespace of this and ALL sub-parts
48  string childName; //Child name
49 };
50 
51 DDTECPhiAltAlgo::DDTECPhiAltAlgo() { LogDebug("TECGeom") << "DDTECPhiAltAlgo info: Creating an instance"; }
52 
54 
56  const DDVectorArguments&,
57  const DDMapArguments&,
58  const DDStringArguments& sArgs,
59  const DDStringVectorArguments&) {
60  startAngle = nArgs["StartAngle"];
61  incrAngle = nArgs["IncrAngle"];
62  radius = nArgs["Radius"];
63  zIn = nArgs["ZIn"];
64  zOut = nArgs["ZOut"];
65  number = int(nArgs["Number"]);
66  startCopyNo = int(nArgs["StartCopyNo"]);
67  incrCopyNo = int(nArgs["IncrCopyNo"]);
68 
69  LogDebug("TECGeom") << "DDTECPhiAltAlgo debug: Parameters for "
70  << "positioning--"
71  << "\tStartAngle " << startAngle / CLHEP::deg << "\tIncrAngle " << incrAngle / CLHEP::deg
72  << "\tRadius " << radius << "\tZ in/out " << zIn << ", " << zOut << "\tCopy Numbers " << number
73  << " Start/Increment " << startCopyNo << ", " << incrCopyNo;
74 
75  idNameSpace = DDCurrentNamespace::ns();
76  childName = sArgs["ChildName"];
77  DDName parentName = parent().name();
78  LogDebug("TECGeom") << "DDTECPhiAltAlgo debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
79  << idNameSpace;
80 }
81 
83  if (number > 0) {
84  double theta = 90. * CLHEP::deg;
85  int copyNo = startCopyNo;
86 
87  DDName mother = parent().name();
88  DDName child(DDSplit(childName).first, DDSplit(childName).second);
89  for (int i = 0; i < number; i++) {
90  double phiz = startAngle + i * incrAngle;
91  double phix = phiz + 90. * CLHEP::deg;
92  double phideg = phiz / CLHEP::deg;
93 
95  string rotstr = DDSplit(childName).first + to_string(phideg * 10.);
96  rotation = DDRotation(DDName(rotstr, idNameSpace));
97  if (!rotation) {
98  LogDebug("TECGeom") << "DDTECPhiAltAlgo test: Creating a new "
99  << "rotation " << rotstr << "\t" << theta / CLHEP::deg << ", " << phix / CLHEP::deg
100  << ", 0, 0, " << theta / CLHEP::deg << ", " << phiz / CLHEP::deg;
101  rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, 0., 0., theta, phiz);
102  }
103 
104  double xpos = radius * cos(phiz);
105  double ypos = radius * sin(phiz);
106  double zpos;
107  if (i % 2 == 0)
108  zpos = zIn;
109  else
110  zpos = zOut;
111  DDTranslation tran(xpos, ypos, zpos);
112 
113  cpv.position(child, mother, copyNo, tran, rotation);
114  LogDebug("TECGeom") << "DDTECPhiAltAlgo test: " << child << " number " << copyNo << " positioned in " << mother
115  << " at " << tran << " with " << rotation;
116  copyNo += incrCopyNo;
117  }
118  }
119 }
120 
121 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTECPhiAltAlgo, "track:DDTECPhiAltAlgo");
static AlgebraicMatrix initialize()
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
std::string to_string(const V &value)
Definition: OMSAccess.h:77
static std::string & ns()
~DDTECPhiAltAlgo() override
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
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:67
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
#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
Geom::Theta< T > theta() const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
void execute(DDCompactView &cpv) override
#define LogDebug(id)