Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:38:40

0001 //   COCOA class implementation file

0002 //Id:  EntryLengthAffAngles.C

0003 //CAT: Model

0004 //

0005 //   History: v1.0

0006 //   Pedro Arce

0007 
0008 #include "Alignment/CocoaModel/interface/EntryAngleAffAngles.h"
0009 #include "Alignment/CocoaModel/interface/OpticalObject.h"
0010 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
0011 
0012 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0013 EntryAngleAffAngles::EntryAngleAffAngles(const ALIstring& type) : EntryAngle(type) {}
0014 
0015 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0016 void EntryAngleAffAngles::FillName(const ALIstring& name) {
0017   ALIstring nn = "Angles ";
0018   nn += name;
0019   setName(nn);
0020 }
0021 
0022 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0023 //@@

0024 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0025 void EntryAngleAffAngles::displace(ALIdouble disp) {
0026   XYZcoor coor = XCoor;
0027   ALIint namelength = name().length() - 1;
0028   //-  std::cout << this << "ENtryAnglesAffAngle" << name_ << namelength <<std::endl;

0029   if (name_[namelength] == 'X') {
0030     coor = XCoor;
0031   } else if (name_[namelength] == 'Y') {
0032     coor = YCoor;
0033   } else if (name_[namelength] == 'Z') {
0034     coor = ZCoor;
0035   }
0036 
0037   GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0038   if (gomgr->GlobalOptions()["rotateAroundLocal"] == 0) {
0039     OptOCurrent()->displaceRmGlobAroundGlobal(OptOCurrent(), coor, disp);
0040   } else {
0041     OptOCurrent()->displaceRmGlobAroundLocal(OptOCurrent(), coor, disp);
0042   }
0043 }
0044 
0045 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0046 void EntryAngleAffAngles::displaceOriginal(ALIdouble disp) {
0047   ALIint namelength = name().length() - 1;
0048   //-  std::cout << this << "ENtryAnglesAffAngle" << name_ << namelength <<std::endl;

0049   if (name_[namelength] == 'X') {
0050     //-    std::cout << "displaX";

0051     OptOCurrent()->displaceRmGlobOriginal(OptOCurrent(), XCoor, disp);
0052   } else if (name_[namelength] == 'Y') {
0053     //-    std::cout << "displaY";

0054     OptOCurrent()->displaceRmGlobOriginal(OptOCurrent(), YCoor, disp);
0055   } else if (name_[namelength] == 'Z') {
0056     OptOCurrent()->displaceRmGlobOriginal(OptOCurrent(), ZCoor, disp);
0057   }
0058 }
0059 
0060 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0061 void EntryAngleAffAngles::displaceOriginalOriginal(ALIdouble disp) {
0062   ALIint namelength = name().length() - 1;
0063   if (ALIUtils::debug >= 5)
0064     std::cout << this << "ENtryAnglesAffAngle displaceOriginalOriginal" << name_ << std::endl;
0065   if (name_[namelength] == 'X') {
0066     //-    std::cout << "displaX";

0067     OptOCurrent()->displaceRmGlobOriginalOriginal(OptOCurrent(), XCoor, disp);
0068   } else if (name_[namelength] == 'Y') {
0069     //-    std::cout << "displaY";

0070     OptOCurrent()->displaceRmGlobOriginalOriginal(OptOCurrent(), YCoor, disp);
0071   } else if (name_[namelength] == 'Z') {
0072     OptOCurrent()->displaceRmGlobOriginalOriginal(OptOCurrent(), ZCoor, disp);
0073   }
0074 }
0075 
0076 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0077 ALIdouble EntryAngleAffAngles::valueDisplaced() const {
0078   //  std::cout << "  EntryAngleAffAngles::valueDisplaced() parent " << OptOCurrent()->parent()->name() << std::endl;

0079   //  ALIUtils::dumprm( OptOCurrent()->parent()->rmGlob() , " parent RmGlob ");

0080   if (ALIUtils::debug >= 5) {
0081     std::cout << "  EntryAngleAffAngles::valueDisplaced() parent opto  " << OptOCurrent()->parent()->name()
0082               << std::endl;
0083     ALIUtils::dumprm(OptOCurrent()->rmGlob(), " RmGlob ");
0084     ALIUtils::dumprm(OptOCurrent()->rmGlobOriginal(), " RmGlobOriginal ");
0085     ALIUtils::dumprm(OptOCurrent()->parent()->rmGlobOriginal(), " parent RmGlobOriginal ");
0086   }
0087 
0088   CLHEP::HepRotation diffRm = OptOCurrent()->rmGlob() * OptOCurrent()->rmGlobOriginal().inverse();
0089   CLHEP::HepRotation rmLocal = diffRm * OptOCurrent()->parent()->rmGlobOriginal().inverse();
0090   std::vector<double> localrot =
0091       OptOCurrent()->getRotationAnglesFromMatrix(rmLocal, OptOCurrent()->CoordinateEntryList());
0092   if (ALIUtils::debug >= 5) {
0093     ALIUtils::dumprm(diffRm, " diffRm ");
0094     ALIUtils::dumprm(rmLocal, " rmLocal ");
0095     std::cout << " localrot " << localrot[0] << " " << localrot[1] << " " << localrot[2] << std::endl;
0096   }
0097 
0098   if (name() == "angles_X") {
0099     return localrot[0];
0100   } else if (name() == "angles_Y") {
0101     return localrot[1];
0102   } else if (name() == "angles_Z") {
0103     return localrot[2];
0104   }
0105 
0106   /*

0107   CLHEP::HepRotation rmLocalOrig = OptOCurrent()->parent()->rmGlobOriginal().inverse() *  OptOCurrent()->rmGlobOriginal();

0108 

0109   CLHEP::HepRotation rmLocal = OptOCurrent()->parent()->rmGlob().inverse() * OptOCurrent()->rmGlob();

0110   std::vector<double> localrot = OptOCurrent()->getRotationAnglesFromMatrix(  rmLocal, OptOCurrent()->CoordinateEntryList() );

0111 

0112   std::cout << " localrot " << localrot[0] << " " << localrot[1] << " " << localrot[2] << std::endl;

0113   std::cout << " localrotorig " << localrotorig[0] << " " << localrotorig[1] << " " << localrotorig[2] << std::endl;

0114   ALIdouble diff;

0115   CLHEP::Hep3Vector Xaxis(0.,0.,1.);

0116   Xaxis = OptOCurrent()->parent()->rmGlob() * Xaxis;

0117   CLHEP::Hep3Vector XaxisOrig(0.,0.,1.);

0118   XaxisOrig = OptOCurrent()->parent()->rmGlobOriginal() * XaxisOrig;

0119 

0120   diff = fabs( checkDiff( Xaxis, XaxisOrig, localrot, localrotorig ) );

0121 

0122   //maybe X is not a good axis because the rotation is done precisely around X

0123   if( diff <= 1.E-9 ){

0124     CLHEP::Hep3Vector Yaxis(0.,1.,0.);

0125     Yaxis = OptOCurrent()->parent()->rmGlob() * Yaxis;

0126     CLHEP::Hep3Vector YaxisOrig(0.,1.,0.);

0127     YaxisOrig = OptOCurrent()->parent()->rmGlobOriginal() * YaxisOrig;

0128 

0129     diff = fabs( checkDiff( Yaxis, YaxisOrig, localrot, localrotorig ) );

0130   }

0131 

0132   return diff;

0133   */
0134 
0135   return 0.;  // to avoid warning

0136 }
0137 
0138 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

0139 ALIdouble EntryAngleAffAngles::checkDiff(const CLHEP::Hep3Vector& _axis,
0140                                          const CLHEP::Hep3Vector& _axisOrig,
0141                                          const std::vector<double>& localrot,
0142                                          const std::vector<double>& localrotorig) const {
0143   CLHEP::Hep3Vector axis = _axis;
0144   CLHEP::Hep3Vector axisOrig = _axisOrig;
0145   int inam = 0;
0146   if (name() == "angles_X") {
0147     inam = 1;
0148   } else if (name() == "angles_Y") {
0149     inam = 2;
0150   } else if (name() == "angles_Z") {
0151     inam = 3;
0152   }
0153   switch (inam) {
0154     case 1:
0155       axis.rotateX(localrot[0]);
0156       axisOrig.rotateX(localrotorig[0]);
0157       [[fallthrough]];
0158     case 2:
0159       axis.rotateY(localrot[1]);
0160       axisOrig.rotateY(localrotorig[1]);
0161       [[fallthrough]];
0162     case 3:
0163       axis.rotateZ(localrot[2]);
0164       axisOrig.rotateZ(localrotorig[2]);
0165       break;
0166   }
0167 
0168   ALIdouble ang = axis.angle(axisOrig);
0169 
0170   /*  }else if( name() == "angles_Y" ) {

0171     return localrot[1] - localrotorig[1];

0172   }else if( name() == "angles_Z" ) {

0173     return localrot[2] - localrotorig[2];

0174     }*/
0175 
0176   return ang;
0177 }