CMS 3D CMS Logo

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