CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Geometry/EcalCommonData/src/DDEcalEndcapTrap.cc

Go to the documentation of this file.
00001 #include "Geometry/EcalCommonData/interface/DDEcalEndcapTrap.h"
00002 
00003 // Implementation of DDEcalEndcapTrap class
00004 
00005 DDEcalEndcapTrap::DDEcalEndcapTrap( const int hand,
00006                                     const double front,
00007                                     const double rear,
00008                                     const double length) 
00009 {
00010   //
00011   //  Initialise corners of supercrystal.
00012 
00013   // Start out with bottom surface on (x,z) plane, front face in (x,y) plane.
00014 
00015   double xsign;
00016 
00017   if (hand==2) {
00018    xsign = -1.;
00019   } else {
00020     xsign = 1.;
00021   }
00022 
00023   m_hand = hand;
00024   m_front = front;
00025   m_rear = rear;
00026   m_length = length;
00027 
00028   int icorner;
00029   icorner = 1;
00030   m_corners[3*icorner-3] = xsign*front;
00031   m_corners[3*icorner-2] = front;
00032   m_corners[3*icorner-1] = 0.;
00033   icorner = 2;
00034   m_corners[3*icorner-3] = xsign*front;
00035   m_corners[3*icorner-2] = 0.;
00036   m_corners[3*icorner-1] = 0.;
00037   icorner = 3;
00038   m_corners[3*icorner-3] = 0.;
00039   m_corners[3*icorner-2] = 0.;
00040   m_corners[3*icorner-1] = 0.;
00041   icorner = 4;
00042   m_corners[3*icorner-3] = 0.;
00043   m_corners[3*icorner-2] = front;
00044   m_corners[3*icorner-1] = 0.;
00045 
00046   icorner = 5;
00047   m_corners[3*icorner-3] = xsign*rear;
00048   m_corners[3*icorner-2] = rear;
00049   m_corners[3*icorner-1] = length;
00050   icorner = 6;
00051   m_corners[3*icorner-3] = xsign*rear;
00052   m_corners[3*icorner-2] = 0.;
00053   m_corners[3*icorner-1] = length;
00054   icorner = 7;
00055   m_corners[3*icorner-3] = 0.;
00056   m_corners[3*icorner-2] = 0.;
00057   m_corners[3*icorner-1] = length;
00058   icorner = 8;
00059   m_corners[3*icorner-3] = 0.;
00060   m_corners[3*icorner-2] = rear;
00061   m_corners[3*icorner-1] = length;
00062   
00063   calculateCentres();
00064 
00065   // Move centre of SC to (0,0,0)
00066 
00067   translate();
00068 
00069   // Rotate into standard position (face centres on z axis)
00070 
00071   //  this->rotate();
00072 
00073   calculateCentres();
00074 }
00075 
00076 
00077 //void DDEcalEndcapTrap::rotate() {
00078 //  //
00079 //  //  Rotate supercrystal to standard position
00080 //  //
00081 //  std::cout << "DDEcalEndcapTrap::rotate() - not yet implemented" << std::endl;
00082 //}
00083 
00084 void 
00085 DDEcalEndcapTrap::rotate( const DDTranslation frontCentre, 
00086                           const DDTranslation rearCentre   ) 
00087 {
00088   //
00089   //  Rotate supercrystal to bring front and rear face centres to specified points
00090   //
00091   edm::LogInfo("EcalGeom") << "DDEcalEndcapTrap::rotate(DDTranslation,DDTranslation) - not yet implemented" << std::endl;
00092 }
00093 
00094 void 
00095 DDEcalEndcapTrap::rotate(const DDRotationMatrix rot) 
00096 {
00097   //
00098   //  Rotate supercrystal by specified rotation about (0,0,0)
00099   //
00100 
00101   int icorner;
00102   DDTranslation cc;
00103   //  edm::LogInfo("EcalGeom") << "DDEcalEndcapTrap::rotate - rotation " << rot << std::endl;
00104   for (icorner=1; icorner<=8; icorner++) {
00105      cc = cornerPos(icorner);
00106      //     edm::LogInfo("EcalGeom") << "   Corner (orig) " << icorner << cc << std::endl;
00107      cc = rot*cc;
00108      //     edm::LogInfo("EcalGeom") << "   Corner (rot)  " << icorner << cc << std::endl;
00109      cornerPos(icorner,cc);
00110   }
00111   m_rotation = rot*m_rotation;
00112   calculateCentres();
00113 }
00114 
00115 void 
00116 DDEcalEndcapTrap::translate() 
00117 {
00118   //  edm::LogInfo("EcalGeom") << "DDEcalEndcapTrap::translate() not yet implemented" << std::endl;
00119    translate(-1.*centrePos());
00120 }
00121 
00122 void 
00123 DDEcalEndcapTrap::translate(const DDTranslation trans) 
00124 {
00125   //
00126   //  Translate supercrystal by specified amount
00127   //
00128 
00129   DDTranslation tcorner;
00130   for (int icorner=1; icorner<=8; icorner++) 
00131   {
00132     tcorner = cornerPos(icorner) + trans;
00133     cornerPos(icorner,tcorner);
00134   }
00135   calculateCentres();
00136   m_translation = trans + m_translation;
00137 }
00138 
00139 void 
00140 DDEcalEndcapTrap::moveto( const DDTranslation frontCentre,
00141                           const DDTranslation rearCentre   ) 
00142 {
00143   //
00144   //  Rotate (about X then about Y) and translate supercrystal to bring axis joining front and rear face centres parallel to line connecting specified points
00145   //
00146 
00147   //  Get azimuthal and polar angles of current axis and target axis
00148   double currentTheta = elevationAngle();
00149   double currentPhi   = polarAngle();
00150   double targetTheta  = elevationAngle(frontCentre-rearCentre);
00151   double targetPhi    = polarAngle(frontCentre-rearCentre);
00152 
00153   //  Rotate to correct angle (X then Y)
00154   // edm::LogInfo("EcalGeom") << "moveto: frontCentre " << frontCentre << std::endl;
00155   // edm::LogInfo("EcalGeom") << "moveto: rearCentre  " << rearCentre << std::endl;
00156   // edm::LogInfo("EcalGeom") << "moveto: X rotation: " << targetTheta << " " << currentTheta << " " << targetTheta-currentTheta << std::endl;
00157   // edm::LogInfo("EcalGeom") << "moveto: Y rotation: " << targetPhi << " " << currentPhi << " " << " " << targetPhi-currentPhi << std::endl;
00158   rotateX(targetTheta-currentTheta);
00159   rotateY(targetPhi-currentPhi);
00160 
00161   //  Translate SC to final position
00162   DDTranslation targetCentre = 0.5*(frontCentre + rearCentre);
00163   // edm::LogInfo("EcalGeom") << "moveto: translation " << targetCentre-centrePos() << std::endl;
00164   translate(targetCentre-centrePos());
00165 }
00166 
00167 void 
00168 DDEcalEndcapTrap::rotateX(const double angle) 
00169 {
00170   //
00171   //  Rotate SC through given angle about X axis
00172   //
00173 
00174    const CLHEP::HepRotation tmp ( CLHEP::Hep3Vector(1.,0.,0.), angle ) ;
00175 
00176    rotate( DDRotationMatrix( tmp.xx(), tmp.xy(), tmp.xz(),
00177                              tmp.yx(), tmp.yy(), tmp.yz(),
00178                              tmp.zx(), tmp.zy(), tmp.zz()  ) );
00179 }
00180 
00181 void 
00182 DDEcalEndcapTrap::rotateY(const double angle) 
00183 {
00184    //
00185    //  Rotate SC through given angle about Y axis
00186    //
00187    const CLHEP::HepRotation tmp ( CLHEP::Hep3Vector(0.,1.,0.), angle ) ;
00188 
00189    rotate( DDRotationMatrix( tmp.xx(), tmp.xy(), tmp.xz(),
00190                              tmp.yx(), tmp.yy(), tmp.yz(),
00191                              tmp.zx(), tmp.zy(), tmp.zz()  ) );
00192 }
00193 
00194 void DDEcalEndcapTrap::calculateCentres() 
00195 {
00196   //
00197   //  Calculate crystal centre and front & rear face centres
00198   //
00199 
00200   int ixyz, icorner;
00201 
00202   for (ixyz = 0; ixyz <3; ixyz++) 
00203   {
00204     m_centre[ixyz] = 0;
00205     m_fcentre[ixyz] = 0;
00206     m_rcentre[ixyz] = 0;
00207   }
00208 
00209   for (icorner=1; icorner<=4; icorner++) 
00210   {
00211     for (ixyz=0; ixyz<3; ixyz++) {
00212        m_centre[ixyz] = m_centre[ixyz] + 0.125*m_corners[3*icorner-3+ixyz];
00213        m_fcentre[ixyz] = m_fcentre[ixyz] + 0.25*m_corners[3*icorner-3+ixyz];
00214     }
00215   }
00216   for (icorner=5; icorner<=8; icorner++) {
00217     for (ixyz=0; ixyz<3; ixyz++) {
00218        m_centre[ixyz] = m_centre[ixyz] + 0.125*m_corners[3*icorner-3+ixyz];
00219        m_rcentre[ixyz] = m_rcentre[ixyz] +  0.25*m_corners[3*icorner-3+ixyz];
00220     }
00221   }
00222 }
00223 
00224 DDTranslation 
00225 DDEcalEndcapTrap::cornerPos(const int icorner) 
00226 {
00227   //
00228   //  Return specified corner as a DDTranslation
00229   //
00230   return DDTranslation( m_corners[3*icorner-3],
00231                         m_corners[3*icorner-2],
00232                         m_corners[3*icorner-1]  );
00233 }
00234 
00235 void 
00236 DDEcalEndcapTrap::cornerPos( const int           icorner, 
00237                              const DDTranslation cornerxyz ) 
00238 {
00239   //
00240   //  Save position of specified corner.
00241   //
00242   for (int ixyz=0; ixyz<3; ixyz++) 
00243   {
00244      m_corners[3*icorner-3+ixyz] = ( 0==ixyz ? cornerxyz.x() :
00245                                      ( 1==ixyz ? cornerxyz.y() :
00246                                        cornerxyz.z() ) ) ;;
00247   }
00248 }
00249 
00250 DDTranslation 
00251 DDEcalEndcapTrap::centrePos() 
00252 {
00253   //
00254   //  Return SC centre as a DDTranslation
00255   //
00256    return DDTranslation(m_centre[0], m_centre[1], m_centre[2]);
00257 }
00258 
00259 DDTranslation 
00260 DDEcalEndcapTrap::fcentrePos() 
00261 {
00262   //
00263   //  Return SC front face centre as a DDTranslation
00264   //
00265    return DDTranslation( m_fcentre[0], 
00266                          m_fcentre[1], 
00267                          m_fcentre[2]  ) ;
00268 }
00269 
00270 DDTranslation 
00271 DDEcalEndcapTrap::rcentrePos() 
00272 {
00273   //
00274   //  Return SC rear face centre as a DDTranslation
00275   //
00276   return DDTranslation( m_rcentre[0], 
00277                         m_rcentre[1], 
00278                         m_rcentre[2]  );
00279 }
00280 
00281 double 
00282 DDEcalEndcapTrap::elevationAngle( const DDTranslation trans ) 
00283 {
00284   //
00285   //  Return elevation angle (out of x-z plane) of a given translation (seen as a vector from the origin).
00286   //
00287   double sintheta = trans.y()/trans.r();
00288   return asin(sintheta);
00289 }
00290 
00291 double 
00292 DDEcalEndcapTrap::elevationAngle() 
00293 {
00294   //
00295   //  Return elevation angle (out of x-z plane) of SC in current position.
00296   //
00297   DDTranslation current = fcentrePos() - rcentrePos();
00298   return elevationAngle(current);
00299 }
00300 
00301 double 
00302 DDEcalEndcapTrap::polarAngle(const DDTranslation trans) 
00303 {
00304   //
00305   //  Return polar angle (from x to z) of a given translation (seen as a vector from the origin).
00306   //
00307   double tanphi = trans.x()/trans.z();
00308   return atan(tanphi);
00309 }
00310 
00311 double 
00312 DDEcalEndcapTrap::polarAngle() 
00313 {
00314   //
00315   //  Return elevation angle (out of x-z plane) of SC in current position.
00316   //
00317   DDTranslation current = fcentrePos() - rcentrePos();
00318   return polarAngle(current);
00319 }
00320 
00321 void 
00322 DDEcalEndcapTrap::print() 
00323 {
00324   //
00325   //  Print SC coordinates for debugging
00326   //
00327   edm::LogInfo("EcalGeom") << "Endcap supercrystal" << std::endl;
00328    for (int ic=1; ic<=8; ic++) 
00329    {
00330       DDTranslation cc = cornerPos(ic);
00331       edm::LogInfo("EcalGeom") << "Corner " << ic << " " << cc << std::endl;
00332    }
00333    edm::LogInfo("EcalGeom") << "    Centre " << centrePos() << std::endl;
00334    edm::LogInfo("EcalGeom") << "   fCentre " << fcentrePos() << std::endl;
00335    edm::LogInfo("EcalGeom") << "   rCentre " << rcentrePos() << std::endl;
00336 }
00337 
00338 
00339 
00340