CMS 3D CMS Logo

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