CMS 3D CMS Logo

Public Member Functions | Public Attributes

LightRay Class Reference

#include <LightRay.h>

List of all members.

Public Member Functions

const CLHEP::Hep3Vector & direction () const
void dumpData (const ALIstring &str) const
void intersect (const OpticalObject &opto)
void intersect (const ALIPlane &plane)
CLHEP::Hep3Vector IntersectWithOptOPlane (const OpticalObject *optoplane)
CLHEP::Hep3Vector IntersectWithPlane (const CLHEP::Hep3Vector &plane_point, const CLHEP::Hep3Vector &plane_normal)
 LightRay (OpticalObject *p1, OpticalObject *p2)
 LightRay (CLHEP::Hep3Vector &vec1, CLHEP::Hep3Vector &vec2)
 LightRay ()
const CLHEP::Hep3Vector & point () const
void reflect (const ALIPlane &plane)
void refract (const ALIPlane plate, const ALIdouble refra_ind1, const ALIdouble refra_ind2)
void setDirection (const CLHEP::Hep3Vector &direc)
void setPoint (const CLHEP::Hep3Vector &point)
void shiftAndDeviateWhileTraversing (const OpticalObject *opto, char behav)
void shiftAndDeviateWhileTraversing (const OpticalObject *opto, ALIdouble shiftX, ALIdouble shiftY, ALIdouble shiftZ, ALIdouble deviX, ALIdouble deviY, ALIdouble deviZ)
void startLightRay (OpticalObject *opto)
 ~LightRay ()

Public Attributes

CLHEP::Hep3Vector _direction
CLHEP::Hep3Vector _point

Detailed Description

Definition at line 20 of file LightRay.h.


Constructor & Destructor Documentation

LightRay::LightRay ( )

Definition at line 18 of file LightRay.cc.

References _direction, and _point.

{
  _point = CLHEP::Hep3Vector(0.,0.,0.);
  _direction = CLHEP::Hep3Vector(0.,0.,1.);
}
LightRay::LightRay ( OpticalObject p1,
OpticalObject p2 
)

Definition at line 51 of file LightRay.cc.

References OpticalObject::centreGlob(), gather_cfg::cout, ALIUtils::debug, dumpData(), OpticalObject::name(), setDirection(), and setPoint().

{
  if(ALIUtils::debug >= 7) std::cout << std::endl << "LR:CREATE LIGHTRAY FROM SOURCE" << opto2->name() << std::endl;

  CLHEP::Hep3Vector _ZAxis(0.,0.,1.);
  //-  LightRay* linetmp;
  //-linetmp = new LightRay; 
  //---------- set direction and point
  setDirection( opto2->centreGlob() - opto1->centreGlob() );
  setPoint( opto1->centreGlob() );

  if(ALIUtils::debug >= 9) std::cout << "OPT" << opto1 << opto1->name() << std::endl;
  //-  std::cout << "centre glob" << &p1->aff()->centre_glob() << std::endl;
  if (ALIUtils::debug >= 9) {
    dumpData(" ");
  }

}
LightRay::LightRay ( CLHEP::Hep3Vector &  vec1,
CLHEP::Hep3Vector &  vec2 
)

Definition at line 72 of file LightRay.cc.

References ALIUtils::debug, dir, dumpData(), setDirection(), and setPoint().

{
  CLHEP::Hep3Vector dir = vec2 - vec1;
  dir *= 1./dir.mag();
  setDirection( dir );
  setPoint( vec1 );
  if (ALIUtils::debug >= 9) {
    dumpData(" ");
  }
}
LightRay::~LightRay ( ) [inline]

Definition at line 28 of file LightRay.h.

{};

Member Function Documentation

const CLHEP::Hep3Vector& LightRay::direction ( ) const [inline]
void LightRay::dumpData ( const ALIstring str) const

Definition at line 381 of file LightRay.cc.

References _direction, _point, gather_cfg::cout, and ALIUtils::dump3v().

Referenced by OptOPinhole::defaultBehaviour(), OptOCubeSplitter::detailedDeviatesLightRay(), OptOOpticalSquare::detailedDeviatesLightRay(), OptOMirror::detailedDeviatesLightRay(), OptOPlateSplitter::detailedDeviatesLightRay(), OptOModifiedRhomboidPrism::detailedDeviatesLightRay(), OptOModifiedRhomboidPrism::detailedTraversesLightRay(), OptOCubeSplitter::detailedTraversesLightRay(), OptOPlateSplitter::detailedTraversesLightRay(), OptOMirror::detailedTraversesLightRay(), OptOSensor2D::detailedTraversesLightRay(), OptOOpticalSquare::fastDeviatesLightRay(), OptOCubeSplitter::fastDeviatesLightRay(), OptOModifiedRhomboidPrism::fastDeviatesLightRay(), OptOPlateSplitter::fastDeviatesLightRay(), OptOMirror::fastDeviatesLightRay(), OptOPlateSplitter::fastTraversesLightRay(), OptOMirror::fastTraversesLightRay(), OptOCubeSplitter::fastTraversesLightRay(), OptOCOPS::fastTraversesLightRay(), OptOModifiedRhomboidPrism::fastTraversesLightRay(), OptOOpticalSquare::fastTraversesLightRay(), OptOSensor2D::fastTraversesLightRay(), LightRay(), reflect(), refract(), startLightRay(), and OptOUserDefined::userDefinedBehaviour().

{
  std::cout << str << std::endl;
  ALIUtils::dump3v( _point, "$$ LightRay point: ");
  ALIUtils::dump3v( _direction, "$$ LightRay direction: ");
  /*
  CLHEP::Hep3Vector dirn = _direction;
  dirn.rotateZ( -23.72876*3.1415926/180.);
  ALIUtils::dump3v( dirn, "$$ LightRay direction: ");
  */
}
void LightRay::intersect ( const ALIPlane plane)

Definition at line 100 of file LightRay.cc.

References _direction, _point, benchmark_cfg::cerr, gather_cfg::cout, ALIUtils::debug, direction(), ALIUtils::dump3v(), cmsRelvalreport::exit, ALIPlane::normal(), and ALIPlane::point().

Referenced by OptOMirror::detailedDeviatesLightRay(), OptOSensor2D::detailedTraversesLightRay(), OptOOpticalSquare::fastDeviatesLightRay(), OptOModifiedRhomboidPrism::fastDeviatesLightRay(), OptOPlateSplitter::fastTraversesLightRay(), OptOMirror::fastTraversesLightRay(), OptOCubeSplitter::fastTraversesLightRay(), OptOCOPS::fastTraversesLightRay(), OptOModifiedRhomboidPrism::fastTraversesLightRay(), OptOOpticalSquare::fastTraversesLightRay(), OptOSensor2D::fastTraversesLightRay(), intersect(), OptOSensor2D::makeMeasurement(), OptOCOPS::makeMeasurement(), reflect(), refract(), and OptOUserDefined::userDefinedBehaviour().

{
  if(ALIUtils::debug >= 4) std::cout << "% LR INTERSECT WITH PLANE" << std::endl;
  if(ALIUtils::debug >= 4) {
    ALIUtils::dump3v( plane.point(), "plane point"); 
    ALIUtils::dump3v( plane.normal(), "plane normal"); 
    //-    dumpData(" ");
  }
  
  //---------- Check that they intersect
  if( fabs( plane.normal()*direction() ) < 1.E-10 ) {
    std::cerr << " !!!! INTERSECTION NOT POSSIBLE: LightRay is perpendicular to plane " << std::endl;
    std::cerr << " plane.normal()*direction() = " << plane.normal()*direction() << std::endl;
    ALIUtils::dump3v( direction(), "LightRay direction ");
    ALIUtils::dump3v( plane.normal(), "plane normal ");
    exit(1);
  }

  //---------- Get intersection point between LightRay and plane
  CLHEP::Hep3Vector vtemp = plane.point() - _point;
  if(ALIUtils::debug >= 5) ALIUtils::dump3v( vtemp, "n_r = point  - point_plane"); 
  ALIdouble dtemp = _direction * plane.normal();
  if(ALIUtils::debug >= 5) std::cout << " lightray* plate normal" << dtemp << std::endl;
  if ( dtemp != 0. ) {
      dtemp = (vtemp * plane.normal()) / dtemp;
      if(ALIUtils::debug >= 5)  std::cout << " n_r*plate normal" << dtemp << std::endl;
  } else {
      std::cerr << "!!! LightRay: Intersect With Plane: plane and light ray parallel: no intersection" << std::endl;     
  } 
  vtemp = _direction * dtemp;
  if(ALIUtils::debug >= 5) ALIUtils::dump3v( vtemp, "n_r scaled"); 
  CLHEP::Hep3Vector inters = vtemp + _point;
  if(ALIUtils::debug >= 3) ALIUtils::dump3v( inters, "INTERSECTION point "); 

  _point = inters;
}
void LightRay::intersect ( const OpticalObject opto)

Definition at line 86 of file LightRay.cc.

References OpticalObject::centreGlob(), gather_cfg::cout, ALIUtils::debug, intersect(), and OpticalObject::rmGlob().

{
  if(ALIUtils::debug >= 3) std::cout << "% LR INTERSECT WITH OPTO" << std::endl;
  CLHEP::Hep3Vector ZAxis(0.,0.,1.);
  CLHEP::HepRotation rmt = opto.rmGlob(); 
  ZAxis = rmt*ZAxis;
  ALIPlane optoPlane(opto.centreGlob(), ZAxis);
  intersect( optoPlane );
}
CLHEP::Hep3Vector LightRay::IntersectWithOptOPlane ( const OpticalObject optoplane)
CLHEP::Hep3Vector LightRay::IntersectWithPlane ( const CLHEP::Hep3Vector &  plane_point,
const CLHEP::Hep3Vector &  plane_normal 
)
const CLHEP::Hep3Vector& LightRay::point ( ) const [inline]
void LightRay::reflect ( const ALIPlane plane)
void LightRay::refract ( const ALIPlane  plate,
const ALIdouble  refra_ind1,
const ALIdouble  refra_ind2 
)

Definition at line 162 of file LightRay.cc.

References benchmark_cfg::cerr, gather_cfg::cout, ALIUtils::debug, direction(), ALIUtils::dump3v(), dumpData(), cmsRelvalreport::exit, intersect(), ALIPlane::normal(), setDirection(), and mathSSE::sqrt().

Referenced by OptOOpticalSquare::detailedDeviatesLightRay(), OptOCubeSplitter::detailedDeviatesLightRay(), OptOModifiedRhomboidPrism::detailedDeviatesLightRay(), OptOModifiedRhomboidPrism::detailedTraversesLightRay(), OptOCubeSplitter::detailedTraversesLightRay(), OptOPlateSplitter::detailedTraversesLightRay(), OptOSensor2D::detailedTraversesLightRay(), OptOMirror::detailedTraversesLightRay(), and OptOOpticalSquare::detailedTraversesLightRay().

{
  if(ALIUtils::debug >= 5) {
    std::cout << "% LR REFRACT: " <<  "refra_ind1 = " << refra_ind1 << " refra_ind2 = " << refra_ind2 <<std::endl;
    std::cout << "@ First intersect with plate plane " << std::endl;
  }

  intersect( plate );

  //---------- First plane: formed by plate normal and lightray, but get two ortonormal std::vectors in this plane (one of it plate normal)
  CLHEP::Hep3Vector Axis1 = plate.normal().cross( direction() );
  //----- Check lightray is not parallel to plate normal
  if( Axis1.mag() < 1.E-6 ) {
    if(ALIUtils::debug >= 3) {
      std::cout << " light ray normal to plane, no refraction " << std::endl;
    }
    if (ALIUtils::debug >= 2) {
      dumpData("LightRay after refraction: "); 
    }

    return;
  }

  if(ALIUtils::debug >= 5) {
    ALIUtils::dump3v( Axis1,  " axis 1 temp ");
  }
  Axis1 = Axis1.cross( plate.normal() );
  Axis1 *= 1./Axis1.mag();
  //----- Project lightray on this plane 
  if(ALIUtils::debug >= 4) {
    ALIUtils::dump3v( plate.normal(),  " plate normal ");
    ALIUtils::dump3v( Axis1,  " axis 1 ");
  }

  //----- Angle between LightRay and plate_normal before traversing
  ALIdouble cosang = -(plate.normal() * direction()) / 
                     plate.normal().mag() / direction().mag();
  ALIdouble sinang = sqrt( 1. - cosang*cosang );
  
  //----- Angle between LightRay projection and plate normal after traversing (refracted)
  ALIdouble sinangp = sinang * refra_ind1 / refra_ind2; 
  if( fabs(sinangp) > 1. ) {
    std::cerr << " !!!EXITING LightRay::refract: incidence ray on plane too close to face, refraction will not allow entering " << std::endl;
    ALIUtils::dump3v( plate.normal(), " plate normal ");
    ALIUtils::dump3v( direction(), " light ray direction ");
    std::cout << " refraction index first medium " << refra_ind1  << " refraction index second medium " << refra_ind2 << std::endl; 
    exit(1);
  }

  if(ALIUtils::debug >= 4) {
    std::cout << "LightRay refract on plane 1: sin(ang) before = " << sinang 
         << " sinang after " << sinangp << std::endl;
  }
  ALIdouble cosangp = sqrt( 1. - sinangp*sinangp );
  //----- Change Lightray direction in this plane 
  //--- Get sign of projections in plate normal and axis1
  ALIdouble signN = direction()*plate.normal();
  signN /= fabs(signN);
  ALIdouble sign1 = direction()*Axis1;
  sign1 /= fabs(sign1);
  if(ALIUtils::debug >= 4) {
    dumpData("LightRay refract: direction before plate");
    std::cout << " sign projection on plate normal " << signN << " sign projection on Axis1 " << sign1 << std::endl;
  }
  setDirection( signN * cosangp * plate.normal() + sign1 * sinangp * Axis1);
  //-  std::cout << " " << signN  << " " << cosangp  << " " << plate.normal() << " " << sign1  << " " << sinangp   << " " << Axis1 << std::endl;
  
  if(ALIUtils::debug >= 3) {
    dumpData("LightRay refract: direction after plate");
  }

}
void LightRay::setDirection ( const CLHEP::Hep3Vector &  direc) [inline]
void LightRay::setPoint ( const CLHEP::Hep3Vector &  point) [inline]
void LightRay::shiftAndDeviateWhileTraversing ( const OpticalObject opto,
ALIdouble  shiftX,
ALIdouble  shiftY,
ALIdouble  shiftZ,
ALIdouble  deviX,
ALIdouble  deviY,
ALIdouble  deviZ 
)

Definition at line 272 of file LightRay.cc.

References _direction, _point, gather_cfg::cout, ALIUtils::debug, ALIUtils::dump3v(), and OpticalObject::rmGlob().

{

  //----- Get local opto X, Y and Z axis
  CLHEP::Hep3Vector XAxis(1.,0.,0.);
  CLHEP::Hep3Vector YAxis(0.,1.,0.);
  CLHEP::Hep3Vector ZAxis(0.,0.,1.);
  CLHEP::HepRotation rmt = opto->rmGlob();
  XAxis = rmt*XAxis;
  YAxis = rmt*YAxis;
  ZAxis = rmt*ZAxis;
  
  if (ALIUtils::debug >= 5) {
    ALIUtils::dump3v( XAxis, "X axis of opto");
    ALIUtils::dump3v( YAxis, "Y axis of opto");
    ALIUtils::dump3v( ZAxis, "Z axis of opto");
  }

  //---------- Shift
  CLHEP::Hep3Vector pointold = _point;
  _point += shiftX*XAxis;
  _point += shiftY*YAxis;
  _point += shiftZ*ZAxis;
  if(_point != pointold && ALIUtils::debug >= 3 ) {
    ALIUtils::dump3v( _point-pointold, "CHANGE point");
  }

  //---------- Deviate  
  CLHEP::Hep3Vector direcold = _direction;
  if( ALIUtils::debug >= 5) { 
    ALIUtils::dump3v( XAxis, "XAxis");
    ALIUtils::dump3v( YAxis, "YAxis");
    ALIUtils::dump3v( ZAxis, "ZAxis");
    ALIUtils::dump3v( _direction, "LightRay direction");
  }
  
  _direction.rotate(deviX, XAxis);
  if(_direction != direcold && ALIUtils::debug >= 3) {
    std::cout << " deviX " << deviX << std::endl;
    ALIUtils::dump3v( _direction-direcold, "CHANGE direction");
  }
  _direction.rotate(deviY, YAxis);
  if(_direction != direcold && ALIUtils::debug >= 3) {
    std::cout << " deviY " << deviY << std::endl;
    ALIUtils::dump3v( _direction-direcold, "CHANGE direction");
  }
  _direction.rotate(deviZ, ZAxis);
  if(_direction != direcold && ALIUtils::debug >= 3) {
    std::cout << " deviZ " << deviZ << std::endl;
    ALIUtils::dump3v( _direction-direcold, "CHANGE direction");
  }

  if(_direction != direcold && ALIUtils::debug >= 3) {
    ALIUtils::dump3v( _direction-direcold, "CHANGE direction");
  }

}
void LightRay::shiftAndDeviateWhileTraversing ( const OpticalObject opto,
char  behav 
)

Definition at line 240 of file LightRay.cc.

References gather_cfg::cout, ALIUtils::debug, and OpticalObject::findExtraEntryValue().

Referenced by OptOOpticalSquare::fastDeviatesLightRay(), OptOCubeSplitter::fastDeviatesLightRay(), OptOModifiedRhomboidPrism::fastDeviatesLightRay(), OptOPlateSplitter::fastDeviatesLightRay(), OptOMirror::fastDeviatesLightRay(), OptOPlateSplitter::fastTraversesLightRay(), OptOMirror::fastTraversesLightRay(), OptOCubeSplitter::fastTraversesLightRay(), OptOModifiedRhomboidPrism::fastTraversesLightRay(), OptOSensor2D::fastTraversesLightRay(), and OptOOpticalSquare::fastTraversesLightRay().

{
  ALIstring ename("devi X");
  ename[4] = behav;
  ename[5] = 'X';
  ALIdouble deviX = opto->findExtraEntryValue(ename);
  ename[5] = 'Y';
  ALIdouble deviY = opto->findExtraEntryValue(ename);
  ename[5] = 'Z';
  ALIdouble deviZ = opto->findExtraEntryValue(ename);
  
  ename = "shift X";
  ename[5] = behav;
  ename[6] = 'X';
  ALIdouble shiftX = opto->findExtraEntryValue(ename);
  ename[6] = 'Y';
  ALIdouble shiftY = opto->findExtraEntryValue(ename);
  ename[6] = 'Z';
  ALIdouble shiftZ = opto->findExtraEntryValue(ename);

  if(ALIUtils::debug >= 3) {
    //-    std::cout << " shift X " << shiftX << " shiftY " << shiftY << " shiftZ " << shiftZ << std::endl;
    //-    std::cout << " deviX " << deviX << " deviY " << deviY << " deviZ " << deviZ << std::endl;
    std::cout << " shift X " << shiftX << " shift Y " << shiftY << std::endl;
    std::cout << " devi X " << deviX << " devi Y " << deviY << std::endl;
  }

  shiftAndDeviateWhileTraversing( opto, shiftX, shiftY, shiftZ, deviX, deviY, deviZ );
  //  shiftAndDeviateWhileTraversing( shiftX, shiftY, deviX, deviY );
} 
void LightRay::startLightRay ( OpticalObject opto)

Definition at line 27 of file LightRay.cc.

References OpticalObject::centreGlob(), gather_cfg::cout, ALIUtils::debug, dumpData(), ALIUtils::dumprm(), OpticalObject::name(), OpticalObject::rmGlob(), setDirection(), setPoint(), and OpticalObject::type().

Referenced by OptOLaser::defaultBehaviour(), OptOXLaser::defaultBehaviour(), OptOSource::defaultBehaviour(), and FittedEntriesManager::GetDifferentBetweenLasers().

{
  if(ALIUtils::debug >= 3) std::cout << std::endl << "LR: CREATE LIGHTRAY " << opto->name() << " OptO type is " << opto->type() << std::endl;

  //---------- Get Z axis of opto
  CLHEP::Hep3Vector ZAxis(0.,0.,1.);
  CLHEP::HepRotation rmt = opto->rmGlob();
  ZAxis = rmt * ZAxis;

  //---------- By convention, direction of LightRay = opto_ZAxis
  setDirection( ZAxis );
  setPoint( opto->centreGlob() );

 if (ALIUtils::debug >= 3) {
    dumpData(" LightRay at creation ");
  }
  if (ALIUtils::debug >= 5) {
    ALIUtils::dumprm( rmt, "laser Rotation matrix");
  }

} 

Member Data Documentation

CLHEP::Hep3Vector LightRay::_direction
CLHEP::Hep3Vector LightRay::_point