CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlignTools.cc
Go to the documentation of this file.
5 
6 #include <iostream>
7 #include <fstream>
8 
9 //Finds the TR between two alignables - first alignable is reference
10 AlgebraicVector align::diffAlignables(Alignable* refAli, Alignable*curAli, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector){
11 
12  //check they are the same
13  if (refAli->alignableObjectId() != curAli->alignableObjectId()){
14  if (refAli->id() != curAli->id()){
15  throw cms::Exception("Geometry Error")
16  << "[AlignTools] Error, Alignables do not match";
17  }
18  }
19 
20  //create points
23  align::createPoints(&refVs, refAli, weightBy, weightById, weightByIdVector);
24  align::createPoints(&curVs, curAli, weightBy, weightById, weightByIdVector);
25 
26  //redefine the set of points
27  //find the translational difference
28  align::GlobalVector theR = align::diffR(curVs,refVs);
29 
30  //CM difference (needed below in rotational transformation)
31  align::GlobalVector pointsCM = align::centerOfMass(curVs);
32  align::PositionType alignableCM = curAli->globalPosition();
33  align::GlobalVector cmdiff(alignableCM.x()-pointsCM.x(), alignableCM.y()-pointsCM.y(), alignableCM.z()-pointsCM.z());
34 
35  //readjust points before finding rotation
38  for (unsigned int k = 0; k < refVs.size(); ++k){
39  refVs[k] -= CMref;
40  curVs[k] -= CMcur;
41  }
42 
43  //find rotational difference (global)
44  align::RotationType rot = align::diffRot(curVs, refVs);
46  //convert to local rotation
47  align::RotationType localrot = refAli->surface().toLocal(rot);
48  align::EulerAngles theLocalW = align::toAngles( localrot );
49 
50  //adjust translational difference factoring in different rotational CM
51  //needed because rotateInGlobalFrame is about CM of alignable, not points
52  align::GlobalVector::BasicVectorType lpvgf = cmdiff.basicVector();
53  align::GlobalVector moveV( rot.multiplyInverse(lpvgf) - lpvgf);
54  align::GlobalVector theRprime(theR + moveV);
55  //convert to local movement
56  align::LocalVector theLocalRprime = refAli->surface().toLocal(theRprime);
57 
58  AlgebraicVector deltaRW(12);
59  // global values
60  deltaRW(1) = theRprime.x();
61  deltaRW(2) = theRprime.y();
62  deltaRW(3) = theRprime.z();
63  deltaRW(4) = theW(1);
64  deltaRW(5) = theW(2);
65  deltaRW(6) = theW(3);
66  // local values
67  deltaRW(7) = theLocalRprime.x();
68  deltaRW(8) = theLocalRprime.y();
69  deltaRW(9) = theLocalRprime.z();
70  deltaRW(10) = theLocalW(1);
71  deltaRW(11) = theLocalW(2);
72  deltaRW(12) = theLocalW(3);
73 
74  refVs.clear();
75  curVs.clear();
76 
77  return deltaRW;
78 }
79 
80 //Moves the alignable by the AlgebraicVector
82 
83  GlobalVector dR(diff[0],diff[1],diff[2]);
84  align::EulerAngles dOmega(3); dOmega[0] = diff[3]; dOmega[1] = diff[4]; dOmega[2] = diff[5];
85  align::RotationType dRot = align::toMatrix(dOmega);
86  ali->move(dR);
87  ali->rotateInGlobalFrame(dRot);
88 
89 }
90 
91 //Creates the points which are used in diffAlignables
92 void align::createPoints(align::GlobalVectors* Vs, Alignable* ali, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector){
93 
94  std::string copy=weightBy;
95  std::transform(copy.begin(), copy.end(), copy.begin(), (int(*)(int)) toupper);
96  if(copy != "SELF"){
97  const align::Alignables& comp = ali->components();
98  unsigned int nComp = comp.size();
99  for (unsigned int i = 0; i < nComp; ++i) align::createPoints(Vs, comp[i], weightBy, weightById, weightByIdVector);
100  // double the weight for SS modules if weight by Det
101  if ((ali->alignableObjectId() == align::AlignableDet)&&(weightBy == "Det")){
102  for (unsigned int i = 0; i < nComp; ++i) align::createPoints(Vs, comp[i], weightBy, weightById, weightByIdVector);
103  }
104 
105  //only create points for lowest hiearchical level
107  //check if the raw id or the mother's raw id is on the list
108  bool createPointsForDetUnit = true;
109  if (weightById) createPointsForDetUnit = align::readModuleList( ali->id(), ali->mother()->id(), weightByIdVector);
110  if (createPointsForDetUnit){
111  //if no survey information, create local points
112  if(!(ali->survey())){
114  ali->setSurvey( new SurveyDet (ali->surface(), error*1e-6) );
115  }
116  const align::GlobalPoints& points = ali->surface().toGlobal(ali->survey()->localPoints());
117  for (unsigned int j = 0; j < points.size(); ++j){
118  align::GlobalVector dummy(points[j].x(),points[j].y(),points[j].z());
119  Vs->push_back(dummy);
120  }
121  }
122  }
123  }
124  else{
125  bool createPointsForDetUnit = true;
126  if (weightById) createPointsForDetUnit = align::readModuleList( ali->id(), ali->mother()->id(), weightByIdVector);
127  if (createPointsForDetUnit){
128  //if no survey information, create local points
129  if(!(ali->survey())){
131  ali->setSurvey( new SurveyDet (ali->surface(), error*1e-6) );
132  }
133  const align::GlobalPoints& points = ali->surface().toGlobal(ali->survey()->localPoints());
134  for (unsigned int j = 0; j < points.size(); ++j){
135  align::GlobalVector dummy(points[j].x(),points[j].y(),points[j].z());
136  Vs->push_back(dummy);
137  }
138  }
139  }
140 }
141 
142 bool align::readModuleList(unsigned int aliId, unsigned int motherId, const std::vector< unsigned int > &weightByIdVector){
143 
144  bool foundId = false;
145 
146  unsigned int sizeVector = weightByIdVector.size();
147 
148  for (unsigned int i = 0; i < sizeVector; ++i){
149 
150  unsigned int listId = weightByIdVector[i];
151 
152  if (listId == aliId){ foundId = true; break; }
153  if (listId == motherId){ foundId = true; break; }
154  }
155 
156  return foundId;
157 }
158 
159 
160 
161 
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
int i
Definition: DBlmapReader.cc:9
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:205
T y() const
Definition: PV3DBase.h:63
AlgebraicVector diffAlignables(Alignable *refAli, Alignable *curAli, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector)
Definition: AlignTools.cc:10
GlobalVector diffR(const GlobalVectors &current, const GlobalVectors &nominal)
Definition: Utilities.cc:166
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
T theW
void createPoints(GlobalVectors *Vs, Alignable *ali, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector)
Definition: AlignTools.cc:92
virtual Alignables components() const =0
Return vector of all direct components.
RotationType diffRot(const GlobalVectors &current, const GlobalVectors &nominal)
Definition: Utilities.cc:71
float float float z
std::vector< GlobalPoint > GlobalPoints
Definition: Utilities.h:23
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
T z() const
Definition: PV3DBase.h:64
bool readModuleList(unsigned int, unsigned int, const std::vector< unsigned int > &)
Definition: AlignTools.cc:142
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
int j
Definition: DBlmapReader.cc:9
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:7
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:126
GlobalVector centerOfMass(const GlobalVectors &theVs)
Find the CM of a set of points.
Definition: Utilities.cc:185
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
Definition: Definitions.h:36
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:268
std::vector< GlobalVector > GlobalVectors
Definition: Utilities.h:24
std::vector< Alignable * > Alignables
Definition: Utilities.h:28
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:40
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:129
math::Error< 6 >::type ErrorMatrix
Definition: Definitions.h:39
Definition: DDAxes.h:10
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
T x() const
Definition: PV3DBase.h:62
void moveAlignable(Alignable *ali, AlgebraicVector diff)
Moves the alignable by the AlgebraicVector.
Definition: AlignTools.cc:81
const align::LocalPoints & localPoints() const
Definition: SurveyDet.h:78
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:85