CMS 3D CMS Logo

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         
00036         //readjust points before finding rotation
00037         align::GlobalVector CMref = align::centerOfMass(refVs);
00038         align::GlobalVector CMcur = align::centerOfMass(curVs);
00039         for (unsigned int k = 0; k < refVs.size(); ++k){
00040                 refVs[k] -= CMref;
00041                 curVs[k] -= CMcur;
00042         }
00043         
00044         //find rotational difference
00045         align::RotationType rot = align::diffRot(curVs, refVs);
00046         align::EulerAngles theW = align::toAngles( rot );
00047         
00048         //adjust translational difference factoring in different rotational CM
00049         //needed because rotateInGlobalFrame is about CM of alignable, not points
00050         align::GlobalVector::BasicVectorType lpvgf = cmdiff.basicVector();
00051         align::GlobalVector moveV( rot.multiplyInverse(lpvgf) - lpvgf);
00052         align::GlobalVector theRprime(theR + moveV);
00053         
00054         AlgebraicVector deltaRW(6);
00055         deltaRW(1) = theRprime.x();
00056         deltaRW(2) = theRprime.y();
00057         deltaRW(3) = theRprime.z();
00058         deltaRW(4) = theW(1);
00059         deltaRW(5) = theW(2);
00060         deltaRW(6) = theW(3);
00061         
00062         refVs.clear();
00063         curVs.clear();
00064         
00065         return deltaRW;
00066         
00067 }
00068 
00069 //Moves the alignable by the AlgebraicVector
00070 void align::moveAlignable(Alignable* ali, AlgebraicVector diff){
00071         
00072         GlobalVector dR(diff[0],diff[1],diff[2]);
00073         align::EulerAngles dOmega(3); dOmega[0] = diff[3]; dOmega[1] = diff[4]; dOmega[2] = diff[5];
00074         align::RotationType dRot = align::toMatrix(dOmega);
00075         ali->move(dR);
00076         ali->rotateInGlobalFrame(dRot);
00077         
00078 }
00079 
00080 //Creates the points which are used in diffAlignables
00081 void align::createPoints(align::GlobalVectors* Vs, Alignable* ali, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector){
00082         
00083         
00084         const align::Alignables& comp = ali->components();
00085         unsigned int nComp = comp.size();
00086         for (unsigned int i = 0; i < nComp; ++i) align::createPoints(Vs, comp[i], weightBy, weightById, weightByIdVector);
00087         // double the weight for SS modules if weight by Det
00088         if ((ali->alignableObjectId() == align::AlignableDet)&&(weightBy == "Det")){
00089                 for (unsigned int i = 0; i < nComp; ++i) align::createPoints(Vs, comp[i], weightBy, weightById, weightByIdVector);
00090         }
00091         
00092         //only create points for lowest hiearchical level
00093         if (ali->alignableObjectId() == align::AlignableDetUnit){
00094                 //check if the raw id or the mother's raw id is on the list
00095                 bool createPointsForDetUnit = true;
00096                 if (weightById) createPointsForDetUnit = align::readModuleList( ali->id(), ali->mother()->id(), weightByIdVector);
00097                 if (createPointsForDetUnit){
00098                         //if no survey information, create local points
00099                         if(!(ali->survey())){
00100                                 align::ErrorMatrix error;
00101                                 ali->setSurvey( new SurveyDet (ali->surface(), error*1e-6) );
00102                         }
00103                         const align::GlobalPoints& points = ali->surface().toGlobal(ali->survey()->localPoints());
00104                         for (unsigned int j = 0; j < points.size(); ++j){
00105                                 align::GlobalVector dummy(points[j].x(),points[j].y(),points[j].z());
00106                                 Vs->push_back(dummy);
00107                         }
00108                 }
00109         }
00110         
00111 }
00112 
00113 
00114 bool align::readModuleList(unsigned int aliId, unsigned int motherId, const std::vector< unsigned int > &weightByIdVector){
00115         
00116         bool foundId = false; 
00117         
00118         unsigned int sizeVector = weightByIdVector.size();
00119         
00120         for (unsigned int i = 0; i < sizeVector; ++i){
00121                 
00122                 unsigned int listId = weightByIdVector[i];
00123                 
00124                 if (listId == aliId){ foundId = true; break; }
00125                 if (listId == motherId){ foundId = true; break; }
00126         }
00127         
00128         return foundId;
00129 }
00130 
00131 
00132 
00133 

Generated on Tue Jun 9 17:23:45 2009 for CMSSW by  doxygen 1.5.4