Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
//   COCOA class implementation file
//Id:  OptOTiltmeter.cc
//CAT: Model
//
//   History: v1.0
//   Pedro Arce

#include "Alignment/CocoaModel/interface/OptOTiltmeter.h"
#include "Alignment/CocoaModel/interface/Measurement.h"
#include <iostream>
#include <iomanip>
#ifdef COCOA_VIS
#include "Alignment/CocoaVisMgr/interface/ALIVRMLMgr.h"
#include "Alignment/IgCocoaFileWriter/interface/IgCocoaFileMgr.h"
#endif
#include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
#include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"

using namespace CLHEP;

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@  Default behaviour: make measurement
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void OptOTiltmeter::defaultBehaviour(LightRay& lightray, Measurement& meas) { makeMeasurement(lightray, meas); }

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@  Make measurement as angle with the horizontal plane = angle between local  Z axis and its projection on the global XZ plane
//-Make measurement as rotations around X axis: difference between current Z axis and Z axis (0,0,1)
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void OptOTiltmeter::makeMeasurement(LightRay& lightray, Measurement& meas) {
  //---------- Get local Z axix
  CLHEP::HepRotation rmt = rmGlob();
  CLHEP::Hep3Vector ZAxisl(0., 0., 1.);
  ZAxisl *= rmt;

  //--------- Get projection in a global XZ plane
  /*-plane parallel to global Y (gravity) and to tiltmeter Z
  CLHEP::Hep3Vector plane_point(0.,0.,0.);
  CLHEP::Hep3Vector plane_normal = ZAxisl.cross( CLHEP::Hep3Vector(0.,1.,0.) );
  CLHEP::Hep3Vector ZAxis_proj = (ALIPlane( plane_point, plane_normal)).project( ZAxisl );
  */
  CLHEP::Hep3Vector XAxisg(1., 0., 0.);
  CLHEP::Hep3Vector ZAxisg(0., 0., 1.);
  CLHEP::Hep3Vector ZAxis_proj = (ZAxisl * XAxisg) * XAxisg + (ZAxisl * ZAxisg) * ZAxisg;
  ZAxis_proj *= (1. / ZAxis_proj.mag());

  //--------- Get measurement
  ALIdouble measvalue = acos(ZAxisl * ZAxis_proj / ZAxisl.mag() / ZAxis_proj.mag());
  //----- get sign of angle as sign of y component of ZAxis
  if (ZAxisl.y() != 0)
    measvalue *= (ZAxisl.y() / fabs(ZAxisl.y()));
  meas.setValueSimulated(0, measvalue);

  if (ALIUtils::debug >= 3) {
    ALIUtils::dump3v(ZAxisl, " OptOTiltmeter: Local Z axis ");
    ALIUtils::dumprm(rmt, " tiltmeter rotation matrix");
    ALIUtils::dump3v(ZAxis_proj, " Projection of Local Z axis on global XZ plane ");
    std::cout << "SIMU value: TA: " << std::setprecision(8) << 1000 * meas.valueSimulated(0) << " (mrad)  "
              << (this)->name() << std::endl;
    std::cout << "REAL value: TA: " << std::setprecision(8) << 1000 * meas.value()[0] << " (mrad)  " << (this)->name()
              << std::endl;
  }

  /*-  //---------- Get simulated value:
  CLHEP::HepRotation rmtori = rmGlobOriginal();
  CLHEP::Hep3Vector ZAxism(0.,0.,1.);
  CLHEP::Hep3Vector ZAxism_ori = ZAxism;
  ZAxism_ori *= rmtori;

  //---------- Measure rotation with respect to original position, around the X axis defined by the original position, in the original YZ plane
  CLHEP::Hep3Vector ZAxism_rot = ZAxism;
  CLHEP::HepRotation rmt = rmGlob();
  ZAxism_rot *= rmt;
  //----- Project on original YZ plane
  CLHEP::Hep3Vector YAxism_ori(0.,1.,0.);
  YAxism_ori *= rmtori;
  //--- create original YZ plane
  CLHEP::Hep3Vector YZplanePoint = centreGlob();
  CLHEP::Hep3Vector YZplaneNormal = YAxism_ori.cross( ZAxism_ori );
  ALIPlane yzorig( YZplanePoint, YZplaneNormal );
  CLHEP::Hep3Vector ZAxism_proj = yzorig.project( ZAxism_rot);
  //- ALIUtils::dump3v( YAxism_ori, "YAxism_ori");
  //- ALIUtils::dump3v( ZAxism_ori, "ZAxism_ori");
  //- ALIUtils::dump3v( ZAxism_rot, "ZAxism_rot");
  //- ALIUtils::dump3v( ZAxism_proj, "ZAxism_proj");
  ALIdouble measValue =  acos( ZAxism.dot(ZAxism_proj)/ZAxism_proj.mag() );
  if( ZAxism_proj.x() < 0) measValue *= -1.;
  meas.setValueSimulated(0 , measValue );

  if (ALIUtils::debug >= 3) {
    std::cout << " OptOTiltmeter: Original Z axis " << ZAxism_ori << std::endl;
    ALIUtils::dumprm(rmt," tiltmeter original rotation matrix");
    std::cout << " OptOTiltmeter: current Z axis " << ZAxism_rot << std::endl;
    ALIUtils::dumprm(rmt," tiltmeter current rotation matrix");
    std::cout << "SIMU value; TA: " << std::setprecision(8) << meas.valueSimulated(0)
 	 << " (rad)  " << (this)->name() << std::endl;
    std::cout << "REAL value: TA: " << std::setprecision(8) << meas.value()[0] 
 	 << " (rad)  " << (this)->name() << std::endl;

  }
  */
}

#ifdef COCOA_VIS
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void OptOTiltmeter::fillVRML() {
  //-  std::cout << " filling optosensor " << std::endl;
  ALIVRMLMgr& vrmlmgr = ALIVRMLMgr::getInstance();
  ALIColour* col = new ALIColour(1., 1., 0., 0.);
  vrmlmgr.AddBox(*this, .2, .2, 1., col);
  vrmlmgr.SendReferenceFrame(*this, 0.6);
  vrmlmgr.SendName(*this, 0.01);
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void OptOTiltmeter::fillIguana() {
  ALIColour* col = new ALIColour(1., 0., 0.9, 0.);
  std::vector<ALIdouble> spar;
  spar.push_back(1.);
  spar.push_back(1.);
  spar.push_back(4.);
  IgCocoaFileMgr::getInstance().addSolid(*this, "BOX", spar, col);
}
#endif

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void OptOTiltmeter::constructSolidShape() {
  ALIdouble go;
  GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
  gomgr->getGlobalOptionValue("VisScale", go);

  theSolidShape = new CocoaSolidShapeBox(
      "Box", go * 2. * cm / m, go * 2. * cm / m, go * 5. * cm / m);  //COCOA internal units are meters
}