CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDEcalEndcapTrap.cc
Go to the documentation of this file.
2 #include "CLHEP/Units/GlobalPhysicalConstants.h"
3 #include "CLHEP/Units/GlobalSystemOfUnits.h"
4 #include "CLHEP/Geometry/Point3D.h"
5 #include "CLHEP/Geometry/Plane3D.h"
6 #include "CLHEP/Geometry/Vector3D.h"
7 #include "CLHEP/Geometry/Transform3D.h"
8 #include "CLHEP/Vector/EulerAngles.h"
9 
10 //#define EDM_ML_DEBUG
11 
12 // Implementation of DDEcalEndcapTrap class
13 
14 DDEcalEndcapTrap::DDEcalEndcapTrap(const int hand, const double front, const double rear, const double length) {
15  //
16  // Initialise corners of supercrystal.
17 
18  // Start out with bottom surface on (x,z) plane, front face in (x,y) plane.
19 
20  double xsign;
21 
22  if (hand == 2) {
23  xsign = -1.;
24  } else {
25  xsign = 1.;
26  }
27 
28  m_hand = hand;
29  m_front = front;
30  m_rear = rear;
31  m_length = length;
32 
33  int icorner;
34  icorner = 1;
35  m_corners[3 * icorner - 3] = xsign * front;
36  m_corners[3 * icorner - 2] = front;
37  m_corners[3 * icorner - 1] = 0.;
38  icorner = 2;
39  m_corners[3 * icorner - 3] = xsign * front;
40  m_corners[3 * icorner - 2] = 0.;
41  m_corners[3 * icorner - 1] = 0.;
42  icorner = 3;
43  m_corners[3 * icorner - 3] = 0.;
44  m_corners[3 * icorner - 2] = 0.;
45  m_corners[3 * icorner - 1] = 0.;
46  icorner = 4;
47  m_corners[3 * icorner - 3] = 0.;
48  m_corners[3 * icorner - 2] = front;
49  m_corners[3 * icorner - 1] = 0.;
50 
51  icorner = 5;
52  m_corners[3 * icorner - 3] = xsign * rear;
53  m_corners[3 * icorner - 2] = rear;
54  m_corners[3 * icorner - 1] = length;
55  icorner = 6;
56  m_corners[3 * icorner - 3] = xsign * rear;
57  m_corners[3 * icorner - 2] = 0.;
58  m_corners[3 * icorner - 1] = length;
59  icorner = 7;
60  m_corners[3 * icorner - 3] = 0.;
61  m_corners[3 * icorner - 2] = 0.;
62  m_corners[3 * icorner - 1] = length;
63  icorner = 8;
64  m_corners[3 * icorner - 3] = 0.;
65  m_corners[3 * icorner - 2] = rear;
66  m_corners[3 * icorner - 1] = length;
67 
69 
70  // Move centre of SC to (0,0,0)
71 
72  translate();
73 
74  // Rotate into standard position (face centres on z axis)
75 
76  // this->rotate();
77 
79 }
80 
81 //void DDEcalEndcapTrap::rotate() {
82 // //
83 // // Rotate supercrystal to standard position
84 // //
85 // edm::LogaVerbatim("EcalGeom") << "DDEcalEndcapTrap::rotate() - not yet implemented";
86 //}
87 
88 void DDEcalEndcapTrap::rotate(const DDTranslation& frontCentre, const DDTranslation& rearCentre) {
89  //
90  // Rotate supercrystal to bring front and rear face centres to specified points
91  //
92  edm::LogWarning("EcalGeom") << "DDEcalEndcapTrap::rotate(DDTranslation,DDTranslation) - not yet implemented";
93 }
94 
96  //
97  // Rotate supercrystal by specified rotation about (0,0,0)
98  //
99 
100  int icorner;
101  DDTranslation cc;
102 #ifdef EDM_ML_DEBUG
103  edm::LogVerbatim("EcalGeom") << "DDEcalEndcapTrap::rotate - rotation " << rot;
104 #endif
105  for (icorner = 1; icorner <= 8; icorner++) {
106  cc = cornerPos(icorner);
107 #ifdef EDM_ML_DEBUG
108  edm::LogVerbatim("EcalGeom") << " Corner (orig) " << icorner << cc;
109 #endif
110  cc = rot * cc;
111 #ifdef EDM_ML_DEBUG
112  edm::LogVerbatim("EcalGeom") << " Corner (rot) " << icorner << cc;
113 #endif
114  cornerPos(icorner, cc);
115  }
116  m_rotation = rot * m_rotation;
118 }
119 
121 #ifdef EDM_ML_DEBUG
122  edm::LogVerbatim("EcalGeom") << "DDEcalEndcapTrap::translate() not yet implemented";
123 #endif
124  translate(-1. * centrePos());
125 }
126 
128  //
129  // Translate supercrystal by specified amount
130  //
131 
132  DDTranslation tcorner;
133  for (int icorner = 1; icorner <= 8; icorner++) {
134  tcorner = cornerPos(icorner) + trans;
135  cornerPos(icorner, tcorner);
136  }
138  m_translation = trans + m_translation;
139 }
140 
141 void DDEcalEndcapTrap::moveto(const DDTranslation& frontCentre, const DDTranslation& rearCentre) {
142  //
143  // Rotate (about X then about Y) and translate supercrystal to bring axis joining front and rear face centres parallel to line connecting specified points
144  //
145 
146  // Get azimuthal and polar angles of current axis and target axis
147  double currentTheta = elevationAngle();
148  double currentPhi = polarAngle();
149  double targetTheta = elevationAngle(frontCentre - rearCentre);
150  double targetPhi = polarAngle(frontCentre - rearCentre);
151 
152  // Rotate to correct angle (X then Y)
153 #ifdef EDM_ML_DEBUG
154  edm::LogVerbatim("EcalGeom") << "moveto: frontCentre " << frontCentre << std::endl
155  << "moveto: rearCentre " << rearCentre << std::endl
156  << "moveto: X rotation: " << targetTheta << " " << currentTheta << " "
157  << targetTheta - currentTheta << std::endl
158  << "moveto: Y rotation: " << targetPhi << " " << currentPhi << " "
159  << " " << targetPhi - currentPhi;
160 #endif
161  rotateX(targetTheta - currentTheta);
162  rotateY(targetPhi - currentPhi);
163 
164  // Translate SC to final position
165  DDTranslation targetCentre = 0.5 * (frontCentre + rearCentre);
166 #ifdef EDM_ML_DEBUG
167  edm::LogVerbatim("EcalGeom") << "moveto: translation " << targetCentre - centrePos();
168 #endif
169  translate(targetCentre - centrePos());
170 }
171 
172 void DDEcalEndcapTrap::rotateX(const double angle) {
173  //
174  // Rotate SC through given angle about X axis
175  //
176 
177  const CLHEP::HepRotation tmp(CLHEP::Hep3Vector(1., 0., 0.), angle);
178 
179  rotate(DDRotationMatrix(tmp.xx(), tmp.xy(), tmp.xz(), tmp.yx(), tmp.yy(), tmp.yz(), tmp.zx(), tmp.zy(), tmp.zz()));
180 }
181 
182 void DDEcalEndcapTrap::rotateY(const double angle) {
183  //
184  // Rotate SC through given angle about Y axis
185  //
186  const CLHEP::HepRotation tmp(CLHEP::Hep3Vector(0., 1., 0.), angle);
187 
188  rotate(DDRotationMatrix(tmp.xx(), tmp.xy(), tmp.xz(), tmp.yx(), tmp.yy(), tmp.yz(), tmp.zx(), tmp.zy(), tmp.zz()));
189 }
190 
192  //
193  // Calculate crystal centre and front & rear face centres
194  //
195 
196  int ixyz, icorner;
197 
198  for (ixyz = 0; ixyz < 3; ixyz++) {
199  m_centre[ixyz] = 0;
200  m_fcentre[ixyz] = 0;
201  m_rcentre[ixyz] = 0;
202  }
203 
204  for (icorner = 1; icorner <= 4; icorner++) {
205  for (ixyz = 0; ixyz < 3; ixyz++) {
206  m_centre[ixyz] = m_centre[ixyz] + 0.125 * m_corners[3 * icorner - 3 + ixyz];
207  m_fcentre[ixyz] = m_fcentre[ixyz] + 0.25 * m_corners[3 * icorner - 3 + ixyz];
208  }
209  }
210  for (icorner = 5; icorner <= 8; icorner++) {
211  for (ixyz = 0; ixyz < 3; ixyz++) {
212  m_centre[ixyz] = m_centre[ixyz] + 0.125 * m_corners[3 * icorner - 3 + ixyz];
213  m_rcentre[ixyz] = m_rcentre[ixyz] + 0.25 * m_corners[3 * icorner - 3 + ixyz];
214  }
215  }
216 }
217 
219  //
220  // Return specified corner as a DDTranslation
221  //
222  return DDTranslation(m_corners[3 * icorner - 3], m_corners[3 * icorner - 2], m_corners[3 * icorner - 1]);
223 }
224 
225 void DDEcalEndcapTrap::cornerPos(const int icorner, const DDTranslation& cornerxyz) {
226  //
227  // Save position of specified corner.
228  //
229  for (int ixyz = 0; ixyz < 3; ixyz++) {
230  m_corners[3 * icorner - 3 + ixyz] = (0 == ixyz ? cornerxyz.x() : (1 == ixyz ? cornerxyz.y() : cornerxyz.z()));
231  ;
232  }
233 }
234 
236  //
237  // Return SC centre as a DDTranslation
238  //
239  return DDTranslation(m_centre[0], m_centre[1], m_centre[2]);
240 }
241 
243  //
244  // Return SC front face centre as a DDTranslation
245  //
246  return DDTranslation(m_fcentre[0], m_fcentre[1], m_fcentre[2]);
247 }
248 
250  //
251  // Return SC rear face centre as a DDTranslation
252  //
253  return DDTranslation(m_rcentre[0], m_rcentre[1], m_rcentre[2]);
254 }
255 
257  //
258  // Return elevation angle (out of x-z plane) of a given translation (seen as a vector from the origin).
259  //
260  double sintheta = trans.y() / trans.r();
261  return asin(sintheta);
262 }
263 
265  //
266  // Return elevation angle (out of x-z plane) of SC in current position.
267  //
268  DDTranslation current = fcentrePos() - rcentrePos();
269  return elevationAngle(current);
270 }
271 
273  //
274  // Return polar angle (from x to z) of a given translation (seen as a vector from the origin).
275  //
276  double tanphi = trans.x() / trans.z();
277  return atan(tanphi);
278 }
279 
281  //
282  // Return elevation angle (out of x-z plane) of SC in current position.
283  //
284  DDTranslation current = fcentrePos() - rcentrePos();
285  return polarAngle(current);
286 }
287 
289  //
290  // Print SC coordinates for debugging
291  //
292  edm::LogVerbatim("EcalGeom") << "Endcap supercrystal";
293  for (int ic = 1; ic <= 8; ic++) {
294  DDTranslation cc = cornerPos(ic);
295  edm::LogVerbatim("EcalGeom") << "Corner " << ic << " " << cc;
296  }
297  edm::LogVerbatim("EcalGeom") << " Centre " << centrePos() << std::endl
298  << " fCentre " << fcentrePos() << std::endl
299  << " rCentre " << rcentrePos();
300 }
Log< level::Info, true > LogVerbatim
void rotate(const DDRotationMatrix &rot)
void rotateY(const double angle)
double m_corners[25]
DDRotationMatrix m_rotation
DDTranslation cornerPos(const int icorner)
void moveto(const DDTranslation &frontCentre, const DDTranslation &rearCentre)
DDTranslation rcentrePos()
DDTranslation fcentrePos()
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
DDTranslation m_translation
Log< level::Warning, false > LogWarning
DDTranslation centrePos()
tmp
align.sh
Definition: createJobs.py:716
DDEcalEndcapTrap()=delete
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
void rotateX(const double angle)