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.

13  :
14  theMother(nullptr),
15  theSurface( ali.surface() ),
17 {
18 // Find mother matching given type
19 
20  theMother = &ali; // start finding from this alignable
21 
22  while (theMother->alignableObjectId() != type)
23  {
24  theMother = theMother->mother(); // move up a level
25 
26  if (!theMother) return;
27 // {
28 // throw cms::Exception("ConfigError")
29 // << "Alignable (id = " << ali.geomDetId().rawId()
30 // << ") does not belong to a composite of type " << type;
31 // }
32  }
33 
34  if ( !theMother->mother() )
35  {
36  throw cms::Exception("ConfigError")
37  << "The type " << type << " does not have a survey residual defined!\n"
38  << "You have probably set the highest hierarchy. Choose a lower level.";
39  }
40 
41  findSisters(theMother, bias);
42 
43  if (theSisters.empty())
44  {
45  throw cms::Exception("ConfigError")
46  << "You are finding an unbiased residual of an alignable "
47  << " (id = " << ali.geomDetId().rawId()
48  << ") which has no sister. Abort!";
49  }
50 
51  calculate(ali);
52 }
type
Definition: HCALResponse.h:21
std::vector< const Alignable * > theSisters
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:61
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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:135
const Alignable * theMother
const AlignableSurface & theSurface
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:94
const DetId & geomDetId() const
Definition: Alignable.h:186

Member Function Documentation

void SurveyResidual::calculate ( const Alignable ali)
private

Find the nominal and current vectors.

Definition at line 166 of file SurveyResidual.cc.

References a, PV3DBase< T, PVType, FrameType >::basicVector(), deltaR(), align::diffRot(), Exception, Alignable::geomDetId(), SurveyDet::globalPoints(), Alignable::globalPosition(), Alignable::globalRotation(), mps_fire::i, 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().

167 {
168  unsigned int nSister = theSisters.size();
169 
170 // First get sisters' positions
171 
172  std::vector<const PositionType*> nominalSisPos; // nominal sisters' pos
173  std::vector<const PositionType*> currentSisPos; // current sisters' pos
174 
175  nominalSisPos.reserve(nSister);
176  currentSisPos.reserve(nSister);
177 
178  for (unsigned int i = 0; i < nSister; ++i)
179  {
180  const Alignable* sis = theSisters[i];
181  const SurveyDet* survey = sis->survey();
182 
183  if (!survey)
184  {
185  throw cms::Exception("ConfigError")
186  << "No survey info is found for Alignable "
187  << " (id = " << sis->geomDetId().rawId() << "). Abort!";
188  }
189 
190  nominalSisPos.push_back( &survey->position() );
191  currentSisPos.push_back( &sis->globalPosition() );
192  }
193 
194 // Then find mother's position using sisters' positions
195 
196  PositionType nominalMomPos = motherPosition(nominalSisPos);
197  PositionType currentMomPos = motherPosition(currentSisPos);
198 
199 // Now find rotation from nominal mother to current mother
200 
201  GlobalVectors nominalSisVs; // nominal sisters' pos from mother's pos
202  GlobalVectors currentSisVs; // current sisters' pos from mother's pos
203 
204  for (unsigned int i = 0; i < nSister; ++i)
205  {
206  const Alignable* sis = theSisters[i];
207 
208  const GlobalPoints& nominalSisPoints = sis->survey()->globalPoints();
209  const GlobalPoints& currentSisPoints = sis->surface().toGlobal( sis->survey()->localPoints() );
210 
211  for (unsigned int j = 0; j < nominalSisPoints.size(); ++j)
212  {
213  nominalSisVs.push_back(nominalSisPoints[j] - *nominalSisPos[i]);
214  currentSisVs.push_back(currentSisPoints[j] - *currentSisPos[i]);
215 // nominalSisVs.push_back(nominalSisPoints[j] - nominalMomPos);
216 // currentSisVs.push_back(currentSisPoints[j] - currentMomPos);
217  }
218  }
219 
220  RotationType toCurrent = diffRot(currentSisVs, nominalSisVs);
221 
222 // Finally shift and rotate nominal sensor to current sensor
223 
224  const SurveyDet* survey = ali.survey();
225 
226  if (!survey)
227  {
228  throw cms::Exception("ConfigError")
229  << "No survey info is found for Alignable "
230  << " (id = " << ali.geomDetId().rawId() << "). Abort!";
231  }
232 
233  const GlobalPoints& nominalPoints = survey->globalPoints();
234  const GlobalPoints& currentPoints = theSurface.toGlobal( survey->localPoints() );
235 
236  for (unsigned int j = 0; j < nominalPoints.size(); ++j)
237  {
238  align::GlobalVector nv = nominalPoints[j] - nominalMomPos;
239 
240  theNominalVs.push_back( align::GlobalVector( toCurrent * nv.basicVector() ) );
241  theCurrentVs.push_back(currentPoints[j] - currentMomPos);
242  }
243 
244 // Find the covariance
245 
246  const RotationType& currentFrame = ali.globalRotation();
247 
248  for ( const Alignable* a = &ali; a != theMother->mother(); a = a->mother() )
249  {
250  RotationType deltaR = currentFrame * a->survey()->rotation().transposed();
251 
252  math::Matrix<6, 6>::type jac; // 6 by 6 Jacobian init to 0
253 
254  jac(0, 0) = deltaR.xx(); jac(0, 1) = deltaR.xy(); jac(0, 2) = deltaR.xz();
255  jac(1, 0) = deltaR.yx(); jac(1, 1) = deltaR.yy(); jac(1, 2) = deltaR.yz();
256  jac(2, 0) = deltaR.zx(); jac(2, 1) = deltaR.zy(); jac(2, 2) = deltaR.zz();
257  jac(3, 3) = deltaR.xx(); jac(3, 4) = deltaR.xy(); jac(3, 5) = deltaR.xz();
258  jac(4, 3) = deltaR.yx(); jac(4, 4) = deltaR.yy(); jac(4, 5) = deltaR.yz();
259  jac(5, 3) = deltaR.zx(); jac(5, 4) = deltaR.zy(); jac(5, 5) = deltaR.zz();
260 
261  theCovariance += ROOT::Math::Similarity( jac, a->survey()->errors() );
262  }
263 }
T xx() const
std::vector< const Alignable * > theSisters
ROOT::Math::SMatrix< double, N, M > type
Definition: Matrix.h:10
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:225
T yx() const
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:141
RotationType diffRot(const GlobalVectors &current, const GlobalVectors &nominal)
Definition: Utilities.cc:73
std::vector< GlobalPoint > GlobalPoints
Definition: Utilities.h:27
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
T zx() const
T xy() const
const align::PositionType & position() const
Definition: SurveyDet.h:63
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:135
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::vector< GlobalVector > GlobalVectors
Definition: Utilities.h:28
const Alignable * theMother
align::GlobalPoints globalPoints() const
Definition: SurveyDet.h:83
double a
Definition: hdecay.h:121
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:138
PositionType motherPosition(const std::vector< const PositionType * > &dauPos)
Find mother&#39;s position from the average of its daughters&#39; positions.
Definition: Utilities.cc:53
const AlignableSurface & theSurface
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
const align::LocalPoints & localPoints() const
Definition: SurveyDet.h:78
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:94
T yz() const
const DetId & geomDetId() const
Definition: Alignable.h:186
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 146 of file SurveyResidual.cc.

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

Referenced by SurveyResidual().

148 {
149  theSisters.clear();
150  theSisters.reserve(1000);
151 
152  const std::vector<Alignable*>& comp = ali->mother()->components();
153 
154  unsigned int nComp = comp.size();
155 
156  for (unsigned int i = 0; i < nComp; ++i)
157  {
158  const Alignable* dau = comp[i];
159 
160  if (dau != ali || bias)
161  theSisters.insert( theSisters.end(), dau->deepComponents().begin(), dau->deepComponents().end() );
162 // if (dau != ali || bias) theSisters.push_back(dau);
163  }
164 }
std::vector< const Alignable * > theSisters
virtual Alignables components() const =0
Return vector of all direct components.
const Alignables & deepComponents() const
Definition: Alignable.h:75
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:94
AlgebraicSymMatrix SurveyResidual::inverseCovariance ( ) const

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

Definition at line 114 of file SurveyResidual.cc.

References Exception, cmsPerfPublish::fail(), mps_fire::i, theCovariance, and theSelector.

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

115 {
116  if (theSelector.size() != ErrorMatrix::kRows)
117  {
118  throw cms::Exception("LogicError")
119  << "Mismatched number of dof between ErrorMatrix and Selector.";
120  }
121 
122  std::vector<unsigned int> indices; // selected indices
123 
124  indices.reserve(ErrorMatrix::kRows);
125 
126  for (unsigned int i = 0; i < ErrorMatrix::kRows; ++i)
127  if (theSelector[i]) indices.push_back(i);
128 
129  AlgebraicSymMatrix invCov( indices.size() );
130 
131  for (unsigned int i = 0; i < indices.size(); ++i)
132  for (unsigned int j = 0; j <= i; ++j)
133  invCov.fast(i + 1, j + 1) = theCovariance(indices[i], indices[j]);
134 
135  int fail(0); invCov.invert(fail);
136 
137  if (fail)
138  {
139  throw cms::Exception("ConfigError")
140  << "Cannot invert survey error " << invCov;
141  }
142 
143  return invCov;
144 }
const std::vector< bool > & theSelector
CLHEP::HepSymMatrix AlgebraicSymMatrix
def fail(errstr="")
align::ErrorMatrix theCovariance
LocalVectors SurveyResidual::pointsResidual ( ) const

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

Definition at line 98 of file SurveyResidual.cc.

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

Referenced by SurveyAlignmentPoints::findAlignPars().

99 {
100  LocalVectors residuals;
101 
102  unsigned int nPoint = theNominalVs.size();
103 
104  residuals.reserve(nPoint);
105 
106  for (unsigned int j = 0; j < nPoint; ++j)
107  {
108  residuals.push_back( theSurface.toLocal(theCurrentVs[j] - theNominalVs[j]) );
109  }
110 
111  return residuals;
112 }
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 54 of file SurveyResidual.cc.

References deltaR(), align::diffRot(), 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().

55 {
56  std::vector<Scalar> pars; // selected parameters
57 
58  pars.reserve(AlignParams::kSize);
59 
60 // Find linear displacements.
61 
63 
64  if (theSelector[0]) pars.push_back( deltaR.x() );
65  if (theSelector[1]) pars.push_back( deltaR.y() );
66  if (theSelector[2]) pars.push_back( deltaR.z() );
67 
68 // Match the centers of current and nominal surfaces to find the angular
69 // displacements about the center. Only do this if angular dof are selected.
70 
71  if (theSelector[3] || theSelector[4] || theSelector[5])
72  {
73  GlobalVectors nominalVs = theNominalVs;
74  GlobalVectors currentVs = theCurrentVs;
75 
76  for (unsigned int j = 0; j < nominalVs.size(); ++j)
77  {
78  nominalVs[j] -= theNominalVs[0]; // move to nominal pos
79  currentVs[j] -= theCurrentVs[0]; // move to current pos
80  }
81 
82  RotationType rot = diffRot(nominalVs, currentVs); // frame rotation
83 
84  EulerAngles deltaW = toAngles( theSurface.toLocal(rot) );
85 
86  if (theSelector[3]) pars.push_back( deltaW(1) );
87  if (theSelector[4]) pars.push_back( deltaW(2) );
88  if (theSelector[5]) pars.push_back( deltaW(3) );
89  }
90 
91  AlgebraicVector deltaRW( pars.size() ); // (deltaR, deltaW)
92 
93  for (unsigned int j = 0; j < pars.size(); ++j) deltaRW(j + 1) = pars[j];
94 
95  return deltaRW;
96 }
T y() const
Definition: PV3DBase.h:63
RotationType diffRot(const GlobalVectors &current, const GlobalVectors &nominal)
Definition: Utilities.cc:73
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:64
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:9
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
Definition: Definitions.h:36
std::vector< GlobalVector > GlobalVectors
Definition: Utilities.h:28
const AlignableSurface & theSurface
T x() const
Definition: PV3DBase.h:62
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 84 of file SurveyResidual.h.

References theMother.

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

85 {
86  return theMother != 0;
87 }
const Alignable * theMother

Member Data Documentation

align::ErrorMatrix SurveyResidual::theCovariance
private

Definition at line 81 of file SurveyResidual.h.

Referenced by calculate(), and inverseCovariance().

align::GlobalVectors SurveyResidual::theCurrentVs
private

Definition at line 79 of file SurveyResidual.h.

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

const Alignable* SurveyResidual::theMother
private

Definition at line 68 of file SurveyResidual.h.

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

align::GlobalVectors SurveyResidual::theNominalVs
private

Definition at line 78 of file SurveyResidual.h.

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

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

Definition at line 73 of file SurveyResidual.h.

Referenced by inverseCovariance(), and sensorResidual().

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

Definition at line 75 of file SurveyResidual.h.

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

const AlignableSurface& SurveyResidual::theSurface
private

Definition at line 71 of file SurveyResidual.h.

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