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) {
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) {
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 }
Vector3DBase< Scalar, GlobalTag >
align::toAngles
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:8
change_name.diff
diff
Definition: change_name.py:13
TkRotation< Scalar >
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
HLT_FULL_cff.points
points
Definition: HLT_FULL_cff.py:21455
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
Alignable::rotateInGlobalFrame
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
Alignable
Definition: Alignable.h:27
align::moveAlignable
void moveAlignable(Alignable *ali, AlgebraicVector diff)
Moves the alignable by the AlgebraicVector.
Definition: AlignTools.cc:84
align::readModuleList
bool readModuleList(unsigned int, unsigned int, const std::vector< unsigned int > &)
Definition: AlignTools.cc:152
align::ErrorMatrix
math::Error< 6 >::type ErrorMatrix
Definition: Definitions.h:37
align::diffR
GlobalVector diffR(const GlobalVectors &current, const GlobalVectors &nominal)
Definition: Utilities.cc:158
AlignableSurface::toLocal
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
Definition: AlignableSurface.cc:35
relativeConstraints.error
error
Definition: relativeConstraints.py:53
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
SurveyDet
Definition: SurveyDet.h:15
Alignable::setSurvey
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:266
AlgebraicVector
CLHEP::HepVector AlgebraicVector
Definition: AlgebraicObjects.h:13
align::createPoints
void createPoints(GlobalVectors *Vs, Alignable *ali, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector)
Definition: AlignTools.cc:96
Alignable::alignableObjectId
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
AlignableSurface::toGlobal
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
Definition: AlignableSurface.cc:15
align::centerOfMass
GlobalVector centerOfMass(const GlobalVectors &theVs)
Find the CM of a set of points.
Definition: Utilities.cc:174
Alignable::surface
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
dqmdumpme.k
k
Definition: dqmdumpme.py:60
Point3DBase< Scalar, GlobalTag >
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
align::AlignableDetUnit
Definition: StructureType.h:19
AlignTools.h
Alignable::id
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
Definition: Alignable.h:180
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
createfilelist.int
int
Definition: createfilelist.py:10
align::GlobalVectors
std::vector< GlobalVector > GlobalVectors
Definition: Utilities.h:28
align::EulerAngles
AlgebraicVector EulerAngles
Definition: Definitions.h:34
align::diffRot
RotationType diffRot(const GlobalVectors &current, const GlobalVectors &nominal)
Definition: Utilities.cc:68
SurveyDet::localPoints
const align::LocalPoints & localPoints() const
Definition: SurveyDet.h:64
Alignable::move
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
align::AlignableDet
Definition: StructureType.h:20
objects.autophobj.motherId
motherId
Definition: autophobj.py:237
Exception
Definition: hltDiff.cc:246
theW
T theW
Definition: Basic3DVectorLD.h:244
genVertex_cff.x
x
Definition: genVertex_cff.py:12
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
Alignable.h
align::toMatrix
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:34
align::GlobalPoints
std::vector< GlobalPoint > GlobalPoints
Definition: Utilities.h:27
align::diffAlignables
AlgebraicVector diffAlignables(Alignable *refAli, Alignable *curAli, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector)
Definition: AlignTools.cc:10
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
dummy
Definition: DummySelector.h:38
SurveyDet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
Alignable::globalPosition
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
Alignable::components
virtual const Alignables & components() const =0
Return vector of all direct components.
Alignable::survey
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:216
Basic3DVector< Scalar >
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
Alignable::mother
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91