CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SurveyResidual Class Reference

#include <SurveyResidual.h>

Public Member Functions

AlgebraicSymMatrix inverseCovariance () const
 Get inverse of survey covariance wrt given structure type in constructor. More...
 
align::LocalVectors pointsResidual () const
 
AlgebraicVector sensorResidual () const
 
 SurveyResidual (const Alignable &, align::StructureType, bool bias=false)
 
bool valid () const
 

Private Member Functions

void calculate (const Alignable &)
 Find the nominal and current vectors. More...
 
void findSisters (const Alignable *, bool bias)
 

Private Attributes

align::ErrorMatrix theCovariance
 
align::GlobalVectors theCurrentVs
 
const AlignabletheMother
 
align::GlobalVectors theNominalVs
 
const std::vector< bool > & theSelector
 
std::vector< const Alignable * > theSisters
 
const AlignableSurfacetheSurface
 

Detailed Description

Class to find the residuals for survey constraint alignment.

For more info, please refer to http://www.pha.jhu.edu/~gritsan/cms/cms-note-survey.pdf

Date
2007/11/09 07:45:04
Revision
1.6
Author
Chung Khim Lae

Definition at line 22 of file SurveyResidual.h.

Constructor & Destructor Documentation

SurveyResidual::SurveyResidual ( const Alignable ali,
align::StructureType  type,
bool  bias = false 
)

Constructor from an alignable whose residuals are to be found. The type of residuals (panel, disc etc.) is given by StructureType. Set bias to true for biased residuals. Default is to find unbiased residuals.

Definition at line 11 of file SurveyResidual.cc.

References Alignable::alignableObjectId(), calculate(), Exception, findSisters(), Alignable::geomDetId(), Alignable::mother(), DetId::rawId(), theMother, and theSisters.

12  : theMother(nullptr), theSurface(ali.surface()), theSelector(ali.alignmentParameters()->selector()) {
13  // Find mother matching given type
14 
15  theMother = &ali; // start finding from this alignable
16 
17  while (theMother->alignableObjectId() != type) {
18  theMother = theMother->mother(); // move up a level
19 
20  if (!theMother)
21  return;
22  // {
23  // throw cms::Exception("ConfigError")
24  // << "Alignable (id = " << ali.geomDetId().rawId()
25  // << ") does not belong to a composite of type " << type;
26  // }
27  }
28 
29  if (!theMother->mother()) {
30  throw cms::Exception("ConfigError") << "The type " << type << " does not have a survey residual defined!\n"
31  << "You have probably set the highest hierarchy. Choose a lower level.";
32  }
33 
34  findSisters(theMother, bias);
35 
36  if (theSisters.empty()) {
37  throw cms::Exception("ConfigError") << "You are finding an unbiased residual of an alignable "
38  << " (id = " << ali.geomDetId().rawId() << ") which has no sister. Abort!";
39  }
40 
41  calculate(ali);
42 }
type
Definition: HCALResponse.h:21
std::vector< const Alignable * > theSisters
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void calculate(const Alignable &)
Find the nominal and current vectors.
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
const std::vector< bool > & theSelector
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
void findSisters(const Alignable *, bool bias)
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
const Alignable * theMother
const AlignableSurface & theSurface
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91
const DetId & geomDetId() const
Definition: Alignable.h:177

Member Function Documentation

void SurveyResidual::calculate ( const Alignable ali)
private

Find the nominal and current vectors.

Definition at line 152 of file SurveyResidual.cc.

References a, PV3DBase< T, PVType, FrameType >::basicVector(), PbPb_ZMuSkimMuonDPG_cff::deltaR, align::diffRot(), Exception, Alignable::geomDetId(), SurveyDet::globalPoints(), Alignable::globalPosition(), Alignable::globalRotation(), mps_fire::i, dqmiolumiharvest::j, SurveyDet::localPoints(), Alignable::mother(), align::motherPosition(), SurveyDet::position(), DetId::rawId(), Alignable::surface(), Alignable::survey(), theCovariance, theCurrentVs, theMother, theNominalVs, theSisters, theSurface, AlignableSurface::toGlobal(), TkRotation< T >::xx(), TkRotation< T >::xy(), TkRotation< T >::xz(), TkRotation< T >::yx(), TkRotation< T >::yy(), TkRotation< T >::yz(), TkRotation< T >::zx(), TkRotation< T >::zy(), and TkRotation< T >::zz().

Referenced by SurveyResidual().

152  {
153  unsigned int nSister = theSisters.size();
154 
155  // First get sisters' positions
156 
157  std::vector<const PositionType*> nominalSisPos; // nominal sisters' pos
158  std::vector<const PositionType*> currentSisPos; // current sisters' pos
159 
160  nominalSisPos.reserve(nSister);
161  currentSisPos.reserve(nSister);
162 
163  for (unsigned int i = 0; i < nSister; ++i) {
164  const Alignable* sis = theSisters[i];
165  const SurveyDet* survey = sis->survey();
166 
167  if (!survey) {
168  throw cms::Exception("ConfigError") << "No survey info is found for Alignable "
169  << " (id = " << sis->geomDetId().rawId() << "). Abort!";
170  }
171 
172  nominalSisPos.push_back(&survey->position());
173  currentSisPos.push_back(&sis->globalPosition());
174  }
175 
176  // Then find mother's position using sisters' positions
177 
178  PositionType nominalMomPos = motherPosition(nominalSisPos);
179  PositionType currentMomPos = motherPosition(currentSisPos);
180 
181  // Now find rotation from nominal mother to current mother
182 
183  GlobalVectors nominalSisVs; // nominal sisters' pos from mother's pos
184  GlobalVectors currentSisVs; // current sisters' pos from mother's pos
185 
186  for (unsigned int i = 0; i < nSister; ++i) {
187  const Alignable* sis = theSisters[i];
188 
189  const GlobalPoints& nominalSisPoints = sis->survey()->globalPoints();
190  const GlobalPoints& currentSisPoints = sis->surface().toGlobal(sis->survey()->localPoints());
191 
192  for (unsigned int j = 0; j < nominalSisPoints.size(); ++j) {
193  nominalSisVs.push_back(nominalSisPoints[j] - *nominalSisPos[i]);
194  currentSisVs.push_back(currentSisPoints[j] - *currentSisPos[i]);
195  // nominalSisVs.push_back(nominalSisPoints[j] - nominalMomPos);
196  // currentSisVs.push_back(currentSisPoints[j] - currentMomPos);
197  }
198  }
199 
200  RotationType toCurrent = diffRot(currentSisVs, nominalSisVs);
201 
202  // Finally shift and rotate nominal sensor to current sensor
203 
204  const SurveyDet* survey = ali.survey();
205 
206  if (!survey) {
207  throw cms::Exception("ConfigError") << "No survey info is found for Alignable "
208  << " (id = " << ali.geomDetId().rawId() << "). Abort!";
209  }
210 
211  const GlobalPoints& nominalPoints = survey->globalPoints();
212  const GlobalPoints& currentPoints = theSurface.toGlobal(survey->localPoints());
213 
214  for (unsigned int j = 0; j < nominalPoints.size(); ++j) {
215  align::GlobalVector nv = nominalPoints[j] - nominalMomPos;
216 
217  theNominalVs.push_back(align::GlobalVector(toCurrent * nv.basicVector()));
218  theCurrentVs.push_back(currentPoints[j] - currentMomPos);
219  }
220 
221  // Find the covariance
222 
223  const RotationType& currentFrame = ali.globalRotation();
224 
225  for (const Alignable* a = &ali; a != theMother->mother(); a = a->mother()) {
226  RotationType deltaR = currentFrame * a->survey()->rotation().transposed();
227 
228  math::Matrix<6, 6>::type jac; // 6 by 6 Jacobian init to 0
229 
230  jac(0, 0) = deltaR.xx();
231  jac(0, 1) = deltaR.xy();
232  jac(0, 2) = deltaR.xz();
233  jac(1, 0) = deltaR.yx();
234  jac(1, 1) = deltaR.yy();
235  jac(1, 2) = deltaR.yz();
236  jac(2, 0) = deltaR.zx();
237  jac(2, 1) = deltaR.zy();
238  jac(2, 2) = deltaR.zz();
239  jac(3, 3) = deltaR.xx();
240  jac(3, 4) = deltaR.xy();
241  jac(3, 5) = deltaR.xz();
242  jac(4, 3) = deltaR.yx();
243  jac(4, 4) = deltaR.yy();
244  jac(4, 5) = deltaR.yz();
245  jac(5, 3) = deltaR.zx();
246  jac(5, 4) = deltaR.zy();
247  jac(5, 5) = deltaR.zz();
248 
249  theCovariance += ROOT::Math::Similarity(jac, a->survey()->errors());
250  }
251 }
T xx() const
std::vector< const Alignable * > theSisters
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:216
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
T yx() const
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
RotationType diffRot(const GlobalVectors &current, const GlobalVectors &nominal)
Definition: Utilities.cc:68
std::vector< GlobalPoint > GlobalPoints
Definition: Utilities.h:27
T zx() const
T xy() const
const align::PositionType & position() const
Definition: SurveyDet.h:58
T zz() const
align::GlobalVectors theCurrentVs
align::GlobalVectors theNominalVs
T zy() const
T yy() const
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
ROOT::Math::SMatrix< double, N, M > type
Definition: Matrix.h:9
std::vector< GlobalVector > GlobalVectors
Definition: Utilities.h:28
const Alignable * theMother
align::GlobalPoints globalPoints() const
Definition: SurveyDet.h:66
double a
Definition: hdecay.h:119
T xz() const
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
PositionType motherPosition(const std::vector< const PositionType * > &dauPos)
Find mother&#39;s position from the average of its daughters&#39; positions.
Definition: Utilities.cc:50
const AlignableSurface & theSurface
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
const align::LocalPoints & localPoints() const
Definition: SurveyDet.h:64
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91
T yz() const
const DetId & geomDetId() const
Definition: Alignable.h:177
align::ErrorMatrix theCovariance
void SurveyResidual::findSisters ( const Alignable ali,
bool  bias 
)
private

Find the terminal sisters of an alignable. bias = true to include itself in the list.

Definition at line 135 of file SurveyResidual.cc.

References AlCaHLTBitMon_QueryRunRegistry::comp, Alignable::components(), Alignable::deepComponents(), mps_fire::i, Alignable::mother(), and theSisters.

Referenced by SurveyResidual().

135  {
136  theSisters.clear();
137  theSisters.reserve(1000);
138 
139  const auto& comp = ali->mother()->components();
140 
141  unsigned int nComp = comp.size();
142 
143  for (unsigned int i = 0; i < nComp; ++i) {
144  const Alignable* dau = comp[i];
145 
146  if (dau != ali || bias)
147  theSisters.insert(theSisters.end(), dau->deepComponents().begin(), dau->deepComponents().end());
148  // if (dau != ali || bias) theSisters.push_back(dau);
149  }
150 }
std::vector< const Alignable * > theSisters
virtual const Alignables & components() const =0
Return vector of all direct components.
const Alignables & deepComponents() const
Definition: Alignable.h:72
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91
AlgebraicSymMatrix SurveyResidual::inverseCovariance ( ) const

Get inverse of survey covariance wrt given structure type in constructor.

Definition at line 106 of file SurveyResidual.cc.

References Exception, mps_fire::i, bTagCombinedSVVariables_cff::indices, dqmiolumiharvest::j, theCovariance, and theSelector.

Referenced by SurveyAlignmentSensor::findAlignPars(), and HIPAlignmentAlgorithm::terminate().

106  {
107  if (theSelector.size() != ErrorMatrix::kRows) {
108  throw cms::Exception("LogicError") << "Mismatched number of dof between ErrorMatrix and Selector.";
109  }
110 
111  std::vector<unsigned int> indices; // selected indices
112 
113  indices.reserve(ErrorMatrix::kRows);
114 
115  for (unsigned int i = 0; i < ErrorMatrix::kRows; ++i)
116  if (theSelector[i])
117  indices.push_back(i);
118 
119  AlgebraicSymMatrix invCov(indices.size());
120 
121  for (unsigned int i = 0; i < indices.size(); ++i)
122  for (unsigned int j = 0; j <= i; ++j)
123  invCov.fast(i + 1, j + 1) = theCovariance(indices[i], indices[j]);
124 
125  int fail(0);
126  invCov.invert(fail);
127 
128  if (fail) {
129  throw cms::Exception("ConfigError") << "Cannot invert survey error " << invCov;
130  }
131 
132  return invCov;
133 }
const std::vector< bool > & theSelector
CLHEP::HepSymMatrix AlgebraicSymMatrix
align::ErrorMatrix theCovariance
LocalVectors SurveyResidual::pointsResidual ( ) const

Find residuals in local frame for points on the alignable (current - nominal vectors).

Definition at line 92 of file SurveyResidual.cc.

References dqmiolumiharvest::j, theCurrentVs, theNominalVs, theSurface, and AlignableSurface::toLocal().

Referenced by SurveyAlignmentPoints::findAlignPars().

92  {
93  LocalVectors residuals;
94 
95  unsigned int nPoint = theNominalVs.size();
96 
97  residuals.reserve(nPoint);
98 
99  for (unsigned int j = 0; j < nPoint; ++j) {
100  residuals.push_back(theSurface.toLocal(theCurrentVs[j] - theNominalVs[j]));
101  }
102 
103  return residuals;
104 }
align::GlobalVectors theCurrentVs
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
align::GlobalVectors theNominalVs
std::vector< LocalVector > LocalVectors
Definition: Utilities.h:30
const AlignableSurface & theSurface
AlgebraicVector SurveyResidual::sensorResidual ( ) const

Find residual for the alignable in local frame. Returns a vector based on the alignable's dof.

Definition at line 44 of file SurveyResidual.cc.

References PbPb_ZMuSkimMuonDPG_cff::deltaR, align::diffRot(), dqmiolumiharvest::j, makeMuonMisalignmentScenario::rot, theCurrentVs, theNominalVs, theSelector, theSurface, align::toAngles(), AlignableSurface::toLocal(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by AlignmentMonitorSurvey::book(), SurveyAlignmentSensor::findAlignPars(), and HIPAlignmentAlgorithm::terminate().

44  {
45  std::vector<Scalar> pars; // selected parameters
46 
47  pars.reserve(AlignParams::kSize);
48 
49  // Find linear displacements.
50 
52 
53  if (theSelector[0])
54  pars.push_back(deltaR.x());
55  if (theSelector[1])
56  pars.push_back(deltaR.y());
57  if (theSelector[2])
58  pars.push_back(deltaR.z());
59 
60  // Match the centers of current and nominal surfaces to find the angular
61  // displacements about the center. Only do this if angular dof are selected.
62 
63  if (theSelector[3] || theSelector[4] || theSelector[5]) {
64  GlobalVectors nominalVs = theNominalVs;
65  GlobalVectors currentVs = theCurrentVs;
66 
67  for (unsigned int j = 0; j < nominalVs.size(); ++j) {
68  nominalVs[j] -= theNominalVs[0]; // move to nominal pos
69  currentVs[j] -= theCurrentVs[0]; // move to current pos
70  }
71 
72  RotationType rot = diffRot(nominalVs, currentVs); // frame rotation
73 
74  EulerAngles deltaW = toAngles(theSurface.toLocal(rot));
75 
76  if (theSelector[3])
77  pars.push_back(deltaW(1));
78  if (theSelector[4])
79  pars.push_back(deltaW(2));
80  if (theSelector[5])
81  pars.push_back(deltaW(3));
82  }
83 
84  AlgebraicVector deltaRW(pars.size()); // (deltaR, deltaW)
85 
86  for (unsigned int j = 0; j < pars.size(); ++j)
87  deltaRW(j + 1) = pars[j];
88 
89  return deltaRW;
90 }
T y() const
Definition: PV3DBase.h:60
RotationType diffRot(const GlobalVectors &current, const GlobalVectors &nominal)
Definition: Utilities.cc:68
const std::vector< bool > & theSelector
align::GlobalVectors theCurrentVs
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
align::GlobalVectors theNominalVs
T z() const
Definition: PV3DBase.h:61
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:8
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
Definition: Definitions.h:34
std::vector< GlobalVector > GlobalVectors
Definition: Utilities.h:28
const AlignableSurface & theSurface
T x() const
Definition: PV3DBase.h:59
bool SurveyResidual::valid ( ) const
inline

Check if survey residual is valid (theMother != 0). This check must be done before calling the other methods so that calculations can be performed correctly.

Definition at line 75 of file SurveyResidual.h.

References theMother.

Referenced by SurveyAlignmentPoints::findAlignPars(), SurveyAlignmentSensor::findAlignPars(), and HIPAlignmentAlgorithm::terminate().

75 { return theMother != nullptr; }
const Alignable * theMother

Member Data Documentation

align::ErrorMatrix SurveyResidual::theCovariance
private

Definition at line 72 of file SurveyResidual.h.

Referenced by calculate(), and inverseCovariance().

align::GlobalVectors SurveyResidual::theCurrentVs
private

Definition at line 70 of file SurveyResidual.h.

Referenced by calculate(), pointsResidual(), and sensorResidual().

const Alignable* SurveyResidual::theMother
private

Definition at line 59 of file SurveyResidual.h.

Referenced by calculate(), SurveyResidual(), and valid().

align::GlobalVectors SurveyResidual::theNominalVs
private

Definition at line 69 of file SurveyResidual.h.

Referenced by calculate(), pointsResidual(), and sensorResidual().

const std::vector<bool>& SurveyResidual::theSelector
private

Definition at line 64 of file SurveyResidual.h.

Referenced by inverseCovariance(), and sensorResidual().

std::vector<const Alignable*> SurveyResidual::theSisters
private

Definition at line 66 of file SurveyResidual.h.

Referenced by calculate(), findSisters(), and SurveyResidual().

const AlignableSurface& SurveyResidual::theSurface
private

Definition at line 62 of file SurveyResidual.h.

Referenced by calculate(), pointsResidual(), and sensorResidual().