CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/CommonAlignment/src/AlignTools.cc

Go to the documentation of this file.
00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 #include "Alignment/CommonAlignment/interface/Alignable.h"
00003 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
00004 #include "Alignment/CommonAlignment/interface/AlignTools.h"
00005 
00006 #include <iostream>
00007 #include <fstream>
00008 
00009 //Finds the TR between two alignables - first alignable is reference
00010 AlgebraicVector align::diffAlignables(Alignable* refAli, Alignable*curAli, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector){
00011         
00012         //check they are the same
00013         if (refAli->alignableObjectId() != curAli->alignableObjectId()){
00014                 if (refAli->id() != curAli->id()){
00015                         throw cms::Exception("Geometry Error")
00016                         << "[AlignTools] Error, Alignables do not match";
00017                 }
00018         }
00019         
00020         //create points
00021         align::GlobalVectors refVs;
00022         align::GlobalVectors curVs;
00023         align::createPoints(&refVs, refAli, weightBy, weightById, weightByIdVector);
00024         align::createPoints(&curVs, curAli, weightBy, weightById, weightByIdVector);
00025         
00026         //redefine the set of points
00027         //find the translational difference
00028         align::GlobalVector theR = align::diffR(curVs,refVs);
00029         
00030         //CM difference (needed below in rotational transformation)
00031         align::GlobalVector pointsCM = align::centerOfMass(curVs);
00032         align::PositionType alignableCM = curAli->globalPosition();
00033         align::GlobalVector cmdiff(alignableCM.x()-pointsCM.x(), alignableCM.y()-pointsCM.y(), alignableCM.z()-pointsCM.z());
00034 
00035         //readjust points before finding rotation
00036         align::GlobalVector CMref = align::centerOfMass(refVs);
00037         align::GlobalVector CMcur = align::centerOfMass(curVs);
00038         for (unsigned int k = 0; k < refVs.size(); ++k){
00039                 refVs[k] -= CMref;
00040                 curVs[k] -= CMcur;
00041         }
00042 
00043         //find rotational difference (global)
00044         align::RotationType rot = align::diffRot(curVs, refVs);
00045         align::EulerAngles theW = align::toAngles( rot );
00046         //convert to local rotation
00047         align::RotationType localrot = refAli->surface().toLocal(rot);
00048         align::EulerAngles theLocalW = align::toAngles( localrot );
00049 
00050         //adjust translational difference factoring in different rotational CM
00051         //needed because rotateInGlobalFrame is about CM of alignable, not points
00052         align::GlobalVector::BasicVectorType lpvgf = cmdiff.basicVector();
00053         align::GlobalVector moveV( rot.multiplyInverse(lpvgf) - lpvgf);
00054         align::GlobalVector theRprime(theR + moveV);
00055         //convert to local movement
00056         align::LocalVector theLocalRprime = refAli->surface().toLocal(theRprime);
00057 
00058         AlgebraicVector deltaRW(12);
00059         // global values
00060         deltaRW(1) = theRprime.x();
00061         deltaRW(2) = theRprime.y();
00062         deltaRW(3) = theRprime.z();
00063         deltaRW(4) = theW(1);
00064         deltaRW(5) = theW(2);
00065         deltaRW(6) = theW(3);
00066         // local values
00067         deltaRW(7) = theLocalRprime.x();
00068         deltaRW(8) = theLocalRprime.y();
00069         deltaRW(9) = theLocalRprime.z();
00070         deltaRW(10) = theLocalW(1);
00071         deltaRW(11) = theLocalW(2);
00072         deltaRW(12) = theLocalW(3);     
00073 
00074         refVs.clear();
00075         curVs.clear();
00076 
00077         return deltaRW; 
00078 }
00079 
00080 //Moves the alignable by the AlgebraicVector
00081 void align::moveAlignable(Alignable* ali, AlgebraicVector diff){
00082         
00083         GlobalVector dR(diff[0],diff[1],diff[2]);
00084         align::EulerAngles dOmega(3); dOmega[0] = diff[3]; dOmega[1] = diff[4]; dOmega[2] = diff[5];
00085         align::RotationType dRot = align::toMatrix(dOmega);
00086         ali->move(dR);
00087         ali->rotateInGlobalFrame(dRot);
00088         
00089 }
00090 
00091 //Creates the points which are used in diffAlignables
00092 void align::createPoints(align::GlobalVectors* Vs, Alignable* ali, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector){
00093         
00094         std::string copy=weightBy;       
00095         std::transform(copy.begin(), copy.end(), copy.begin(),  (int(*)(int)) toupper);          
00096         if(copy != "SELF"){
00097                 const align::Alignables& comp = ali->components();
00098                 unsigned int nComp = comp.size();
00099                 for (unsigned int i = 0; i < nComp; ++i) align::createPoints(Vs, comp[i], weightBy, weightById, weightByIdVector);
00100                 // double the weight for SS modules if weight by Det
00101                 if ((ali->alignableObjectId() == align::AlignableDet)&&(weightBy == "Det")){
00102                         for (unsigned int i = 0; i < nComp; ++i) align::createPoints(Vs, comp[i], weightBy, weightById, weightByIdVector);
00103                 }
00104                 
00105                 //only create points for lowest hiearchical level
00106                 if (ali->alignableObjectId() == align::AlignableDetUnit){
00107                         //check if the raw id or the mother's raw id is on the list
00108                         bool createPointsForDetUnit = true;
00109                         if (weightById) createPointsForDetUnit = align::readModuleList( ali->id(), ali->mother()->id(), weightByIdVector);
00110                         if (createPointsForDetUnit){
00111                                 //if no survey information, create local points
00112                                 if(!(ali->survey())){
00113                                         align::ErrorMatrix error;
00114                                         ali->setSurvey( new SurveyDet (ali->surface(), error*1e-6) );
00115                                 }
00116                                 const align::GlobalPoints& points = ali->surface().toGlobal(ali->survey()->localPoints());
00117                                 for (unsigned int j = 0; j < points.size(); ++j){
00118                                         align::GlobalVector dummy(points[j].x(),points[j].y(),points[j].z());
00119                                         Vs->push_back(dummy);
00120                                 }
00121                         }
00122                 }
00123         }
00124         else{
00125                 bool createPointsForDetUnit = true;
00126                 if (weightById) createPointsForDetUnit = align::readModuleList( ali->id(), ali->mother()->id(), weightByIdVector);
00127                 if (createPointsForDetUnit){
00128                         //if no survey information, create local points
00129                         if(!(ali->survey())){
00130                                 align::ErrorMatrix error;
00131                                 ali->setSurvey( new SurveyDet (ali->surface(), error*1e-6) );
00132                         }
00133                         const align::GlobalPoints& points = ali->surface().toGlobal(ali->survey()->localPoints());
00134                         for (unsigned int j = 0; j < points.size(); ++j){
00135                                 align::GlobalVector dummy(points[j].x(),points[j].y(),points[j].z());
00136                                 Vs->push_back(dummy);
00137                         }
00138                 }
00139         }
00140 }
00141 
00142 bool align::readModuleList(unsigned int aliId, unsigned int motherId, const std::vector< unsigned int > &weightByIdVector){
00143         
00144         bool foundId = false; 
00145         
00146         unsigned int sizeVector = weightByIdVector.size();
00147         
00148         for (unsigned int i = 0; i < sizeVector; ++i){
00149                 
00150                 unsigned int listId = weightByIdVector[i];
00151                 
00152                 if (listId == aliId){ foundId = true; break; }
00153                 if (listId == motherId){ foundId = true; break; }
00154         }
00155         
00156         return foundId;
00157 }
00158 
00159 
00160 
00161