CMS 3D CMS Logo

DDTrackerAngular.cc
Go to the documentation of this file.
1 // File: DDTrackerAngular.cc
3 // Description: Position n copies at prescribed phi values
5 
12 #include "CLHEP/Units/GlobalPhysicalConstants.h"
13 #include "CLHEP/Units/GlobalSystemOfUnits.h"
14 
15 #include <string>
16 #include <vector>
17 
18 using namespace std;
19 
20 class DDTrackerAngular : public DDAlgorithm {
21 public:
22  //Constructor and Destructor
24  ~DDTrackerAngular() override;
25 
26  void initialize(const DDNumericArguments& nArgs,
27  const DDVectorArguments& vArgs,
28  const DDMapArguments& mArgs,
29  const DDStringArguments& sArgs,
30  const DDStringVectorArguments& vsArgs) override;
31 
32  void execute(DDCompactView& cpv) override;
33 
34 private:
35  int n; //Number of copies
36  int startCopyNo; //Start Copy number
37  int incrCopyNo; //Increment in Copy number
38  double rangeAngle; //Range in angle
39  double startAngle; //Start anle
40  double radius; //Radius
41  vector<double> center; //Phi values
42  double delta; //Increment in phi
43 
44  string idNameSpace; //Namespace of this and ALL sub-parts
45  string childName; //Child name
46 };
47 
48 DDTrackerAngular::DDTrackerAngular() { LogDebug("TrackerGeom") << "DDTrackerAngular info: Creating an instance"; }
49 
51 
53  const DDVectorArguments& vArgs,
54  const DDMapArguments&,
55  const DDStringArguments& sArgs,
56  const DDStringVectorArguments&) {
57  n = int(nArgs["N"]);
58  startCopyNo = int(nArgs["StartCopyNo"]);
59  incrCopyNo = int(nArgs["IncrCopyNo"]);
60  rangeAngle = nArgs["RangeAngle"];
61  startAngle = nArgs["StartAngle"];
62  radius = nArgs["Radius"];
63  center = vArgs["Center"];
64 
65  if (fabs(rangeAngle - 360.0 * CLHEP::deg) < 0.001 * CLHEP::deg) {
66  delta = rangeAngle / double(n);
67  } else {
68  if (n > 1) {
69  delta = rangeAngle / double(n - 1);
70  } else {
71  delta = 0.;
72  }
73  }
74 
75  LogDebug("TrackerGeom") << "DDTrackerAngular debug: Parameters for position"
76  << "ing:: n " << n << " Start, Range, Delta " << startAngle / CLHEP::deg << " "
77  << rangeAngle / CLHEP::deg << " " << delta / CLHEP::deg << " Radius " << radius << " Centre "
78  << center[0] << ", " << center[1] << ", " << center[2];
79 
80  idNameSpace = DDCurrentNamespace::ns();
81  childName = sArgs["ChildName"];
82 
83  DDName parentName = parent().name();
84  LogDebug("TrackerGeom") << "DDTrackerAngular debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
85  << idNameSpace;
86 }
87 
89  DDName mother = parent().name();
90  DDName child(DDSplit(childName).first, DDSplit(childName).second);
91  double theta = 90. * CLHEP::deg;
92  int copy = startCopyNo;
93  double phi = startAngle;
94  for (int i = 0; i < n; i++) {
95  double phix = phi;
96  double phiy = phix + 90. * CLHEP::deg;
97  double phideg = phix / CLHEP::deg;
98 
100  if (phideg != 0) {
101  string rotstr = DDSplit(childName).first + to_string(phideg * 10.);
102  rotation = DDRotation(DDName(rotstr, idNameSpace));
103  if (!rotation) {
104  LogDebug("TrackerGeom") << "DDTrackerAngular test: Creating a new "
105  << "rotation: " << rotstr << "\t90., " << phix / CLHEP::deg << ", 90.,"
106  << phiy / CLHEP::deg << ", 0, 0";
107  rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
108  }
109  }
110 
111  double xpos = radius * cos(phi) + center[0];
112  double ypos = radius * sin(phi) + center[1];
113  double zpos = center[2];
114  DDTranslation tran(xpos, ypos, zpos);
115 
116  cpv.position(child, mother, copy, tran, rotation);
117  LogDebug("TrackerGeom") << "DDTrackerAngular test " << child << " number " << copy << " positioned in " << mother
118  << " at " << tran << " with " << rotation;
119  copy += incrCopyNo;
120  phi += delta;
121  }
122 }
123 
124 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerAngular, "track:DDTrackerAngular");
static AlgebraicMatrix initialize()
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
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:71
static std::string & ns()
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
~DDTrackerAngular() override
vector< double > center
#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)