CMS 3D CMS Logo

DDTECPhiAlgo.cc
Go to the documentation of this file.
1 // File: DDTECPhiAlgo.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 DDTECPhiAlgo : public DDAlgorithm {
24 public:
25  //Constructor and Destructor
26  DDTECPhiAlgo();
27  ~DDTECPhiAlgo() 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 zIn; //z position for the even ones
41  double zOut; //z position for the odd ones
42  int number; //Number of copies
43  int startCopyNo; //Start copy number
44  int incrCopyNo; //Increment in copy number
45 
46  string idNameSpace; //Namespace of this and ALL sub-parts
47  string childName; //Child name
48 };
49 
50 DDTECPhiAlgo::DDTECPhiAlgo() { LogDebug("TECGeom") << "DDTECPhiAlgo info: Creating an instance"; }
51 
53 
55  const DDVectorArguments&,
56  const DDMapArguments&,
57  const DDStringArguments& sArgs,
58  const DDStringVectorArguments&) {
59  startAngle = nArgs["StartAngle"];
60  incrAngle = nArgs["IncrAngle"];
61  zIn = nArgs["ZIn"];
62  zOut = nArgs["ZOut"];
63  number = int(nArgs["Number"]);
64  startCopyNo = int(nArgs["StartCopyNo"]);
65  incrCopyNo = int(nArgs["IncrCopyNo"]);
66 
67  LogDebug("TECGeom") << "DDTECPhiAlgo debug: Parameters for "
68  << "positioning--"
69  << "\tStartAngle " << startAngle / CLHEP::deg << "\tIncrAngle " << incrAngle / CLHEP::deg
70  << "\tZ in/out " << zIn << ", " << zOut << "\tCopy Numbers " << number << " Start/Increment "
71  << startCopyNo << ", " << incrCopyNo;
72 
73  idNameSpace = DDCurrentNamespace::ns();
74  childName = sArgs["ChildName"];
75  DDName parentName = parent().name();
76  LogDebug("TECGeom") << "DDTECPhiAlgo debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
77  << idNameSpace;
78 }
79 
81  if (number > 0) {
82  double theta = 90. * CLHEP::deg;
83  int copyNo = startCopyNo;
84 
85  DDName mother = parent().name();
86  DDName child(DDSplit(childName).first, DDSplit(childName).second);
87  for (int i = 0; i < number; i++) {
88  double phix = startAngle + i * incrAngle;
89  double phiy = phix + 90. * CLHEP::deg;
90  double phideg = phix / CLHEP::deg;
91 
93  string rotstr = DDSplit(childName).first + to_string(phideg * 10.);
94  rotation = DDRotation(DDName(rotstr, idNameSpace));
95  if (!rotation) {
96  LogDebug("TECGeom") << "DDTECPhiAlgo test: Creating a new "
97  << "rotation " << rotstr << "\t" << theta / CLHEP::deg << ", " << phix / CLHEP::deg << ", "
98  << theta / CLHEP::deg << ", " << phiy / CLHEP::deg << ", 0, 0";
99  rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
100  }
101 
102  double zpos = zOut;
103  if (i % 2 == 0)
104  zpos = zIn;
105  DDTranslation tran(0., 0., zpos);
106 
107  cpv.position(child, mother, copyNo, tran, rotation);
108  LogDebug("TECGeom") << "DDTECPhiAlgo test: " << child << " number " << copyNo << " positioned in " << mother
109  << " at " << tran << " with " << rotation;
110  copyNo += incrCopyNo;
111  }
112  }
113 }
114 
115 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTECPhiAlgo, "track:DDTECPhiAlgo");
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)
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
string childName
Definition: DDTECPhiAlgo.cc:47
static std::string & ns()
double incrAngle
Definition: DDTECPhiAlgo.cc:39
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
Definition: DDTECPhiAlgo.cc:54
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
static std::string to_string(const XMLCh *ch)
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
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
double startAngle
Definition: DDTECPhiAlgo.cc:38
#define DEFINE_EDM_PLUGIN(factory, type, name)
void execute(DDCompactView &cpv) override
Definition: DDTECPhiAlgo.cc:80
string idNameSpace
Definition: DDTECPhiAlgo.cc:46
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
~DDTECPhiAlgo() override
Definition: DDTECPhiAlgo.cc:52
#define LogDebug(id)