CMS 3D CMS Logo

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