CMS 3D CMS Logo

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