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
00010 AlgebraicVector align::diffAlignables(Alignable* refAli, Alignable*curAli, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector){
00011
00012
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
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
00027
00028 align::GlobalVector theR = align::diffR(curVs,refVs);
00029
00030
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
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
00045 align::RotationType rot = align::diffRot(curVs, refVs);
00046 align::EulerAngles theW = align::toAngles( rot );
00047
00048
00049
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
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
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
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
00093 if (ali->alignableObjectId() == align::AlignableDetUnit){
00094
00095 bool createPointsForDetUnit = true;
00096 if (weightById) createPointsForDetUnit = align::readModuleList( ali->id(), ali->mother()->id(), weightByIdVector);
00097 if (createPointsForDetUnit){
00098
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