CMS 3D CMS Logo

DDTrackerPhiAlgo.cc
Go to the documentation of this file.
1 // File: DDTrackerPhiAlgo.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 DDTrackerPhiAlgo : public DDAlgorithm {
21 public:
22  //Constructor and Destructor
24  ~DDTrackerPhiAlgo() 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 radius; //Radius
36  double tilt; //Tilt angle
37  vector<double> phi; //Phi values
38  vector<double> zpos; //Z positions
39 
40  string idNameSpace; //Namespace of this and ALL sub-parts
41  string childName; //Child name
42 
43  size_t startcn; //Start index of copy numbers.
44  int incrcn; //Increment of copy number index.
45  size_t numcopies; //Number of copies == phi.size() above.
46 };
47 
48 DDTrackerPhiAlgo::DDTrackerPhiAlgo() : startcn(1), incrcn(1) {
49  LogDebug("TrackerGeom") << "DDTrackerPhiAlgo info: Creating an instance";
50 }
51 
53 
55  const DDVectorArguments& vArgs,
56  const DDMapArguments&,
57  const DDStringArguments& sArgs,
58  const DDStringVectorArguments&) {
59  if (nArgs.find("StartCopyNo") != nArgs.end()) {
60  startcn = size_t(nArgs["StartCopyNo"]);
61  } else {
62  startcn = 1;
63  }
64  if (nArgs.find("IncrCopyNo") != nArgs.end()) {
65  incrcn = int(nArgs["IncrCopyNo"]);
66  } else {
67  incrcn = 1;
68  }
69 
70  radius = nArgs["Radius"];
71  tilt = nArgs["Tilt"];
72  phi = vArgs["Phi"];
73  zpos = vArgs["ZPos"];
74 
75  if (nArgs.find("NumCopies") != nArgs.end()) {
76  numcopies = size_t(nArgs["NumCopies"]);
77  if (numcopies != phi.size()) {
78  edm::LogError("TrackerGeom") << "DDTrackerPhiAlgo error: Parameter "
79  << "NumCopies does not agree with the size "
80  << "of the Phi vector. It was adjusted to "
81  << "be the size of the Phi vector and may "
82  << "lead to crashes or errors.";
83  }
84  } else {
85  numcopies = phi.size();
86  }
87 
88  LogDebug("TrackerGeom") << "DDTrackerPhiAlgo debug: Parameters for position"
89  << "ing:: "
90  << " Radius " << radius << " Tilt " << tilt / CLHEP::deg << " Copies " << phi.size() << " at";
91  for (int i = 0; i < (int)(phi.size()); i++)
92  LogDebug("TrackerGeom") << "\t[" << i << "] phi = " << phi[i] / CLHEP::deg << " z = " << zpos[i];
93 
95  childName = sArgs["ChildName"];
96  DDName parentName = parent().name();
97  LogDebug("TrackerGeom") << "DDTrackerPhiAlgo debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
98  << idNameSpace;
99 }
100 
102  DDName mother = parent().name();
104  double theta = 90. * CLHEP::deg;
105  size_t i = 0;
106  int ci = startcn;
107  for (; i < numcopies; ++i) {
108  double phix = phi[i] + tilt;
109  double phiy = phix + 90. * CLHEP::deg;
110  double phideg = phi[i] / CLHEP::deg;
111 
112  string rotstr = DDSplit(childName).first + to_string(phideg);
114  if (!rotation) {
115  LogDebug("TrackerGeom") << "DDTrackerPhiAlgo test: Creating a new "
116  << "rotation: " << rotstr << "\t"
117  << "90., " << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg << ", 0, 0";
118  rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
119  }
120 
121  double xpos = radius * cos(phi[i]);
122  double ypos = radius * sin(phi[i]);
123  DDTranslation tran(xpos, ypos, zpos[i]);
124 
125  cpv.position(child, mother, ci, tran, rotation);
126  LogDebug("TrackerGeom") << "DDTrackerPhiAlgo test: " << child << " number " << ci << " positioned in " << mother
127  << " at " << tran << " with " << rotation;
128  ci = ci + incrcn;
129  }
130 }
131 
132 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerPhiAlgo, "track:DDTrackerPhiAlgo");
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()
Log< level::Error, false > LogError
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
vector< double > phi
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
~DDTrackerPhiAlgo() override
void execute(DDCompactView &cpv) 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
vector< double > zpos
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
#define LogDebug(id)