test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDTrackerRingAlgo.cc
Go to the documentation of this file.
1 // File: DDTrackerRingAlgo.cc
3 // Description: Tilts and positions n copies of a module at prescribed phi
4 // values within a ring. The module can also be flipped if requested.
6 
7 
8 #include <cmath>
9 #include <algorithm>
10 
18 #include "CLHEP/Units/GlobalPhysicalConstants.h"
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
20 
21 
23  LogDebug("TrackerGeom") << "DDTrackerRingAlgo info: Creating an instance";
24 }
25 
27 
29  const DDVectorArguments & vArgs,
30  const DDMapArguments & ,
31  const DDStringArguments & sArgs,
32  const DDStringVectorArguments & ) {
33 
34  n = int(nArgs["N"]);
35  startCopyNo = int(nArgs["StartCopyNo"]);
36  incrCopyNo = int(nArgs["IncrCopyNo"]);
37  rangeAngle = nArgs["RangeAngle"];
38  startAngle = nArgs["StartAngle"];
39  radius = nArgs["Radius"];
40  center = vArgs["Center"];
41  isZPlus = bool(nArgs["IsZPlus"]);
42  tiltAngle = nArgs["TiltAngle"];
43  isFlipped = bool(nArgs["IsFlipped"]);
44 
45  if (fabs(rangeAngle-360.0*CLHEP::deg)<0.001*CLHEP::deg) {
46  delta = rangeAngle/double(n);
47  } else {
48  if (n > 1) {
49  delta = rangeAngle/double(n-1);
50  } else {
51  delta = 0.;
52  }
53  }
54 
55  LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parameters for position"
56  << "ing:: n " << n << " Start, Range, Delta "
57  << startAngle/CLHEP::deg << " "
58  << rangeAngle/CLHEP::deg << " " << delta/CLHEP::deg
59  << " Radius " << radius << " Centre " << center[0]
60  << ", " << center[1] << ", "<<center[2];
61 
63  childName = sArgs["ChildName"];
64 
65  DDName parentName = parent().name();
66  LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parent " << parentName
67  << "\tChild " << childName << " NameSpace "
68  << idNameSpace;
69 }
70 
72 
73  DDRotation flipRot, tiltRot, phiRot, globalRot; // Identity
74  DDRotationMatrix flipMatrix, tiltMatrix, phiRotMatrix, globalRotMatrix; // Identity matrix
75  std::string rotstr = "RTrackerRingAlgo";
76 
77  // flipMatrix calculus
78  if (isFlipped) {
79  std::string flipRotstr = rotstr + "Flip";
80  flipRot = DDRotation(DDName(flipRotstr, idNameSpace));
81  if (!flipRot) {
82  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << flipRotstr
83  << "\t90., 180., "
84  << "90., 90., "
85  << "180., 0.";
86  flipRot = DDrot(DDName(flipRotstr, idNameSpace),
87  90.*CLHEP::deg, 180.*CLHEP::deg, 90.*CLHEP::deg, 90.*CLHEP::deg, 180.*CLHEP::deg, 0.);
88  }
89  flipMatrix = *flipRot.matrix();
90  }
91  // tiltMatrix calculus
92  if (isZPlus) {
93  std::string tiltRotstr = rotstr + "Tilt" + dbl_to_string(tiltAngle/CLHEP::deg) + "ZPlus";
94  tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
95  if (!tiltRot) {
96  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr
97  << "\t90., 90., "
98  << tiltAngle/CLHEP::deg << ", 180., "
99  << 90. - tiltAngle/CLHEP::deg << ", 0.";
100  tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
101  90.*CLHEP::deg, 90.*CLHEP::deg, tiltAngle, 180.*CLHEP::deg, 90.*CLHEP::deg - tiltAngle, 0.);
102  }
103  tiltMatrix = *tiltRot.matrix();
104  if (isFlipped) { tiltMatrix *= flipMatrix; }
105  }
106  else {
107  std::string tiltRotstr = rotstr + "Tilt" + dbl_to_string(tiltAngle/CLHEP::deg) + "ZMinus";
108  tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
109  if (!tiltRot) {
110  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr
111  << "\t90., 90., "
112  << tiltAngle/CLHEP::deg << ", 0., "
113  << 90. + tiltAngle/CLHEP::deg << ", 0.";
114  tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
115  90.*CLHEP::deg, 90.*CLHEP::deg, tiltAngle, 0., 90.*CLHEP::deg + tiltAngle, 0.);
116  }
117  tiltMatrix = *tiltRot.matrix();
118  if (isFlipped) { tiltMatrix *= flipMatrix; }
119  }
120 
121  // Loops for all phi values
122  DDName mother = parent().name();
124  double theta = 90.*CLHEP::deg;
125  int copy = startCopyNo;
126  double phi = startAngle;
127 
128  for (int i=0; i<n; i++) {
129 
130  // phiRotMatrix calculus
131  double phix = phi;
132  double phiy = phix + 90.*CLHEP::deg;
133  double phideg = phix/CLHEP::deg;
134  if (phideg != 0) {
135  std::string phiRotstr = rotstr + "Phi" + dbl_to_string(phideg*10.);
136  phiRot = DDRotation(DDName(phiRotstr, idNameSpace));
137  if (!phiRot) {
138  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << phiRotstr
139  << "\t90., " << phix/CLHEP::deg
140  << ", 90.," << phiy/CLHEP::deg
141  <<", 0., 0.";
142  phiRot = DDrot(DDName(phiRotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
143  }
144  phiRotMatrix = *phiRot.matrix();
145  }
146 
147  // globalRot def
148  std::string globalRotstr = rotstr + "Phi" + dbl_to_string(phideg*10.) + "Tilt" + dbl_to_string(tiltAngle/CLHEP::deg);
149  if (isZPlus) {
150  globalRotstr += "ZPlus";
151  if (isFlipped) { globalRotstr += "Flip"; }
152  }
153  else {
154  globalRotstr += "ZMinus";
155  if (isFlipped) { globalRotstr += "Flip"; }
156  }
157  globalRot = DDRotation(DDName(globalRotstr, idNameSpace));
158  if (!globalRot) {
159  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new "
160  << "rotation: " << globalRotstr;
161  globalRotMatrix = phiRotMatrix * tiltMatrix;
162  globalRot = DDrot(DDName(globalRotstr, idNameSpace), new DDRotationMatrix(globalRotMatrix));
163  }
164 
165  // translation def
166  double xpos = radius*cos(phi) + center[0];
167  double ypos = radius*sin(phi) + center[1];
168  double zpos = center[2];
169  DDTranslation tran(xpos, ypos, zpos);
170 
171  // Positions child with respect to parent
172  cpv.position(child, mother, copy, tran, globalRot);
173  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test " << child << " number "
174  << copy << " positioned in " << mother << " at "
175  << tran << " with " << globalRot;
176 
177  copy += incrCopyNo;
178  phi += delta;
179  }
180 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
void execute(DDCompactView &cpv)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
void position(const DDLogicalPart &self, const DDLogicalPart &parent, std::string copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=NULL)
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:14
static std::string & ns()
std::string dbl_to_string(const double &in)
Converts only the integer part of a double to a string.
Definition: DDutils.cc:12
type of data representation of DDCompactView
Definition: DDCompactView.h:77
std::string idNameSpace
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
U second(std::pair< T, U > const &p)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs)
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:90
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:4
virtual ~DDTrackerRingAlgo()
DDRotationMatrix * matrix()
Definition: DDTransform.h:94
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const std::string & name() const
Returns the name.
Definition: DDName.cc:87
std::vector< double > center