CMS 3D CMS Logo

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;
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  }
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 }
DDEcalEndcapTrapX::m_corners
double m_corners[25]
Definition: DDEcalEndcapTrapX.h:44
DDEcalEndcapTrapX::elevationAngle
double elevationAngle()
Definition: DDEcalEndcapTrapX.cc:243
DDEcalEndcapTrapX.h
DDEcalEndcapTrapX::m_rotation
DDRotationMatrix m_rotation
Definition: DDEcalEndcapTrapX.h:38
DDEcalEndcapTrapX::centrePos
DDTranslation centrePos()
Definition: DDEcalEndcapTrapX.cc:214
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
DDEcalEndcapTrapX::calculateCentres
void calculateCentres()
Definition: DDEcalEndcapTrapX.cc:170
DDTranslation
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
DDEcalEndcapTrapX::translate
void translate()
Definition: DDEcalEndcapTrapX.cc:99
DDEcalEndcapTrapX::m_rear
double m_rear
Definition: DDEcalEndcapTrapX.h:46
DDEcalEndcapTrapX::m_centre
double m_centre[4]
Definition: DDEcalEndcapTrapX.h:41
DDEcalEndcapTrapX::polarAngle
double polarAngle()
Definition: DDEcalEndcapTrapX.cc:259
DDEcalEndcapTrapX::print
void print()
Definition: DDEcalEndcapTrapX.cc:267
cc
DDEcalEndcapTrapX::m_fcentre
double m_fcentre[4]
Definition: DDEcalEndcapTrapX.h:42
DDEcalEndcapTrapX::rotateX
void rotateX(const double angle)
Definition: DDEcalEndcapTrapX.cc:151
DDEcalEndcapTrapX::DDEcalEndcapTrapX
DDEcalEndcapTrapX()=delete
DDRotationMatrix
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
Definition: DDRotationMatrix.h:8
DDEcalEndcapTrapX::rotate
void rotate(const DDRotationMatrix &rot)
Definition: DDEcalEndcapTrapX.cc:74
DDEcalEndcapTrapX::m_front
double m_front
Definition: DDEcalEndcapTrapX.h:45
DDEcalEndcapTrapX::cornerPos
DDTranslation cornerPos(const int icorner)
Definition: DDEcalEndcapTrapX.cc:197
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
DDEcalEndcapTrapX::fcentrePos
DDTranslation fcentrePos()
Definition: DDEcalEndcapTrapX.cc:221
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
DDEcalEndcapTrapX::m_translation
DDTranslation m_translation
Definition: DDEcalEndcapTrapX.h:39
DDEcalEndcapTrapX::m_length
double m_length
Definition: DDEcalEndcapTrapX.h:47
DDEcalEndcapTrapX::moveto
void moveto(const DDTranslation &frontCentre, const DDTranslation &rearCentre)
Definition: DDEcalEndcapTrapX.cc:120
DDEcalEndcapTrapX::m_rcentre
double m_rcentre[4]
Definition: DDEcalEndcapTrapX.h:43
DDEcalEndcapTrapX::rcentrePos
DDTranslation rcentrePos()
Definition: DDEcalEndcapTrapX.cc:228
DDEcalEndcapTrapX::rotateY
void rotateY(const double angle)
Definition: DDEcalEndcapTrapX.cc:161
DDEcalEndcapTrapX::m_hand
int m_hand
Definition: DDEcalEndcapTrapX.h:49