CMS 3D CMS Logo

DDTrackerPhiAltAlgo.cc
Go to the documentation of this file.
1 // File: DDTrackerPhiAltAlgo.cc
3 // Description: Position n copies inside and outside at alternate 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 DDTrackerPhiAltAlgo : public DDAlgorithm {
21 public:
22  //Constructor and Destructor
24  ~DDTrackerPhiAltAlgo() 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  double tilt; //Tilt of the module
36  double startAngle; //offset in phi
37  double rangeAngle; //Maximum range in phi
38  double radiusIn; //Inner radius
39  double radiusOut; //Outer radius
40  double zpos; //z position
41  int number; //Number of copies
42  int startCopyNo; //Start copy number
43  int incrCopyNo; //Increment in copy number
44 
45  string idNameSpace; //Namespace of this and ALL sub-parts
46  string childName; //Child name
47 };
48 
50  LogDebug("TrackerGeom") << "DDTrackerPhiAltAlgo info: Creating an instance";
51 }
52 
54 
56  const DDVectorArguments&,
57  const DDMapArguments&,
58  const DDStringArguments& sArgs,
59  const DDStringVectorArguments&) {
60  tilt = nArgs["Tilt"];
61  startAngle = nArgs["StartAngle"];
62  rangeAngle = nArgs["RangeAngle"];
63  radiusIn = nArgs["RadiusIn"];
64  radiusOut = nArgs["RadiusOut"];
65  zpos = nArgs["ZPosition"];
66  number = int(nArgs["Number"]);
67  startCopyNo = int(nArgs["StartCopyNo"]);
68  incrCopyNo = int(nArgs["IncrCopyNo"]);
69 
70  LogDebug("TrackerGeom") << "DDTrackerPhiAltAlgo debug: Parameters for "
71  << "positioning--"
72  << " Tilt " << tilt << "\tStartAngle " << startAngle / CLHEP::deg << "\tRangeAngle "
73  << rangeAngle / CLHEP::deg << "\tRin " << radiusIn << "\tRout " << radiusOut << "\t ZPos "
74  << zpos << "\tCopy Numbers " << number << " Start/Increment " << startCopyNo << ", "
75  << incrCopyNo;
76 
77  idNameSpace = DDCurrentNamespace::ns();
78  childName = sArgs["ChildName"];
79  DDName parentName = parent().name();
80  LogDebug("TrackerGeom") << "DDTrackerPhiAltAlgo debug: Parent " << parentName << "\tChild " << childName
81  << " NameSpace " << idNameSpace;
82 }
83 
85  if (number > 0) {
86  double theta = 90. * CLHEP::deg;
87  double dphi;
88  if (number == 1 || fabs(rangeAngle - 360.0 * CLHEP::deg) < 0.001 * CLHEP::deg)
89  dphi = rangeAngle / number;
90  else
91  dphi = rangeAngle / (number - 1);
92  int copyNo = startCopyNo;
93 
94  DDName mother = parent().name();
95  DDName child(DDSplit(childName).first, DDSplit(childName).second);
96  for (int i = 0; i < number; i++) {
97  double phi = startAngle + i * dphi;
98  double phix = phi - tilt + 90. * CLHEP::deg;
99  double phiy = phix + 90. * CLHEP::deg;
100  double phideg = phix / CLHEP::deg;
101 
103  if (phideg != 0) {
104  string rotstr = DDSplit(childName).first + to_string(phideg * 10.);
105  rotation = DDRotation(DDName(rotstr, idNameSpace));
106  if (!rotation) {
107  LogDebug("TrackerGeom") << "DDTrackerPhiAltAlgo test: Creating a new"
108  << " rotation " << rotstr << "\t"
109  << "90., " << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg << ", 0, 0";
110  rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
111  }
112  }
113 
114  double xpos, ypos;
115  if (i % 2 == 0) {
116  xpos = radiusIn * cos(phi);
117  ypos = radiusIn * sin(phi);
118  } else {
119  xpos = radiusOut * cos(phi);
120  ypos = radiusOut * sin(phi);
121  }
122  DDTranslation tran(xpos, ypos, zpos);
123 
124  cpv.position(child, mother, copyNo, tran, rotation);
125  LogDebug("TrackerGeom") << "DDTrackerPhiAltAlgo test: " << child << " number " << copyNo << " positioned in "
126  << mother << " at " << tran << " with " << rotation;
127  copyNo += incrCopyNo;
128  }
129  }
130 }
131 
132 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerPhiAltAlgo, "track:DDTrackerPhiAltAlgo");
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
static std::string & ns()
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)
void execute(DDCompactView &cpv) override
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
#define LogDebug(id)