CMS 3D CMS Logo

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

#include <AlignableModifier.h>

Public Member Functions

void addAlignmentPositionError (Alignable *alignable, float dx, float dy, float dz)
 Add the AlignmentPositionError (in global frame) to Alignable. More...
 
void addAlignmentPositionErrorFromLocalRotation (Alignable *alignable, float phiX, float phiY, float phiZ)
 Add alignment position error resulting from rotation in local frame. More...
 
void addAlignmentPositionErrorFromLocalRotation (Alignable *alignable, align::RotationType &)
 Add alignment position error resulting from rotation in local frame. More...
 
void addAlignmentPositionErrorFromRotation (Alignable *alignable, float phiX, float phiY, float phiZ)
 Add alignment position error resulting from rotation in global frame. More...
 
void addAlignmentPositionErrorFromRotation (Alignable *alignable, align::RotationType &)
 Add alignment position error resulting from rotation in global frame. More...
 
void addAlignmentPositionErrorLocal (Alignable *alignable, float dx, float dy, float dz)
 Add the AlignmentPositionError (in local frame) to Alignable. More...
 
 AlignableModifier ()
 Constructor. More...
 
const std::vector< float > flatRandomVector (float sigmaX, float sigmaY, float sigmaZ) const
 Return a vector of random numbers (flat distribution) More...
 
const std::vector< float > gaussianRandomVector (float sigmaX, float sigmaY, float sigmaZ) const
 Return a vector of random numbers (gaussian distribution) More...
 
bool isPropagated (const std::string &parameterName) const
 Check if given parameter should be propagated. More...
 
bool modify (Alignable *alignable, const edm::ParameterSet &pSet)
 Modify given set of alignables according to parameters. More...
 
void moveAlignable (Alignable *alignable, bool random, bool gaussian, float sigmaX, float sigmaY, float sigmaZ)
 Move alignable in global space according to parameters. More...
 
void moveAlignableLocal (Alignable *alignable, bool random, bool gaussian, float sigmaX, float sigmaY, float sigmaZ)
 Move alignable in local space according to parameters. More...
 
void randomise (std::vector< double > &rnd, bool gaussian) const
 
void rotateAlignable (Alignable *alignable, bool random, bool gaussian, float sigmaPhiX, float sigmaPhiY, float sigmaPhiZ)
 Rotate alignable in global space according to parameters. More...
 
void rotateAlignableLocal (Alignable *alignable, bool random, bool gaussian, float sigmaPhiX, float sigmaPhiY, float sigmaPhiZ)
 Rotate alignable in local space according to parameters. More...
 
void setDistribution (const std::string &distr)
 Decodes string and sets distribution accordingly ('fixed', 'flat' or 'gaussian'). More...
 
void setSeed (long seed)
 Resets the generator seed according to the argument. More...
 
 ~AlignableModifier ()
 Destructor. More...
 

Private Types

typedef std::pair< std::string, std::vector< double > > DeformationMemberType
 

Private Member Functions

void addDeformation (Alignable *alignable, const DeformationMemberType &deformation, bool random, bool gaussian, double scale)
 
void init_ ()
 Initialisation of all parameters. More...
 

Private Attributes

DeformationMemberType deformation_
 
std::string distribution_
 
double dX_
 
double dXlocal_
 
double dY_
 
double dYlocal_
 
double dZ_
 
double dZlocal_
 
bool gaussian_
 
int m_modified
 
double phiX_
 
double phiXlocal_
 
double phiY_
 
double phiYlocal_
 
double phiZ_
 
double phiZlocal_
 
bool random_
 
double scale_
 
double scaleError_
 
long seed_
 
bool setError_
 
bool setRotations_
 
bool setTranslations_
 
double shear_
 
CLHEP::DRand48Engine * theDRand48Engine
 Unique random number generator. More...
 
double twist_
 

Detailed Description

Definition at line 23 of file AlignableModifier.h.

Member Typedef Documentation

◆ DeformationMemberType

typedef std::pair<std::string, std::vector<double> > AlignableModifier::DeformationMemberType
private

Definition at line 85 of file AlignableModifier.h.

Constructor & Destructor Documentation

◆ AlignableModifier()

AlignableModifier::AlignableModifier ( void  )

Constructor.

Definition at line 21 of file AlignableModifier.cc.

References theDRand48Engine.

22  : distribution_(""),
23  random_(false),
24  gaussian_(false),
25  setError_(false),
26  setRotations_(false),
27  setTranslations_(false),
28  seed_(0),
29  scaleError_(0.),
30  scale_(0.),
31  phiX_(0.),
32  phiY_(0.),
33  phiZ_(0.),
34  phiXlocal_(0.),
35  phiYlocal_(0.),
36  phiZlocal_(0.),
37  dX_(0.),
38  dY_(0.),
39  dZ_(0.),
40  dXlocal_(0.),
41  dYlocal_(0.),
42  dZlocal_(0.),
43  twist_(0.),
44  shear_(0.) {
45  theDRand48Engine = new CLHEP::DRand48Engine();
46 }
std::string distribution_
CLHEP::DRand48Engine * theDRand48Engine
Unique random number generator.

◆ ~AlignableModifier()

AlignableModifier::~AlignableModifier ( )

Destructor.

Definition at line 49 of file AlignableModifier.cc.

References theDRand48Engine.

49 { delete theDRand48Engine; }
CLHEP::DRand48Engine * theDRand48Engine
Unique random number generator.

Member Function Documentation

◆ addAlignmentPositionError()

void AlignableModifier::addAlignmentPositionError ( Alignable alignable,
float  dx,
float  dy,
float  dz 
)

Add the AlignmentPositionError (in global frame) to Alignable.

Definition at line 532 of file AlignableModifier.cc.

References Alignable::addAlignmentPositionError(), PVValHelper::dx, PVValHelper::dy, PVValHelper::dz, and LogDebug.

Referenced by modify(), MuonScenarioBuilder::moveChamberInSector(), and MuonScenarioBuilder::moveMuon().

532  {
533  LogDebug("PrintArgs") << "Adding an AlignmentPositionError of size " << dx << " " << dy << " " << dz;
534 
536  alignable->addAlignmentPositionError(ape, true);
537 }
virtual void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown)=0
#define LogDebug(id)

◆ addAlignmentPositionErrorFromLocalRotation() [1/2]

void AlignableModifier::addAlignmentPositionErrorFromLocalRotation ( Alignable alignable,
float  phiX,
float  phiY,
float  phiZ 
)

Add alignment position error resulting from rotation in local frame.

Definition at line 598 of file AlignableModifier.cc.

References makeMuonMisalignmentScenario::rot.

Referenced by modify().

601  {
602  align::RotationType rotx(Basic3DVector<float>(1.0, 0.0, 0.0), phiX);
603  align::RotationType roty(Basic3DVector<float>(0.0, 1.0, 0.0), phiY);
604  align::RotationType rotz(Basic3DVector<float>(0.0, 0.0, 1.0), phiZ);
605  align::RotationType rot = rotz * roty * rotx;
606 
608 }
void addAlignmentPositionErrorFromLocalRotation(Alignable *alignable, float phiX, float phiY, float phiZ)
Add alignment position error resulting from rotation in local frame.

◆ addAlignmentPositionErrorFromLocalRotation() [2/2]

void AlignableModifier::addAlignmentPositionErrorFromLocalRotation ( Alignable alignable,
align::RotationType rotation 
)

Add alignment position error resulting from rotation in local frame.

Definition at line 618 of file AlignableModifier.cc.

References Alignable::addAlignmentPositionErrorFromLocalRotation(), LogDebug, and idealTransformation::rotation.

619  {
620  LogDebug("PrintArgs") << "Adding an AlignmentPositionError from Local Rotation" << std::endl << rotation;
621 
622  // true: propagate down to components
624 }
virtual void addAlignmentPositionErrorFromLocalRotation(const RotationType &rotation, bool propagateDown)=0
#define LogDebug(id)

◆ addAlignmentPositionErrorFromRotation() [1/2]

void AlignableModifier::addAlignmentPositionErrorFromRotation ( Alignable alignable,
float  phiX,
float  phiY,
float  phiZ 
)

Add alignment position error resulting from rotation in global frame.

Definition at line 588 of file AlignableModifier.cc.

References makeMuonMisalignmentScenario::rot.

Referenced by modify(), MuonScenarioBuilder::moveChamberInSector(), and MuonScenarioBuilder::moveMuon().

588  {
589  align::RotationType rotx(Basic3DVector<float>(1.0, 0.0, 0.0), phiX);
590  align::RotationType roty(Basic3DVector<float>(0.0, 1.0, 0.0), phiY);
591  align::RotationType rotz(Basic3DVector<float>(0.0, 0.0, 1.0), phiZ);
592  align::RotationType rot = rotz * roty * rotx;
593 
594  this->addAlignmentPositionErrorFromRotation(alignable, rot);
595 }
void addAlignmentPositionErrorFromRotation(Alignable *alignable, float phiX, float phiY, float phiZ)
Add alignment position error resulting from rotation in global frame.

◆ addAlignmentPositionErrorFromRotation() [2/2]

void AlignableModifier::addAlignmentPositionErrorFromRotation ( Alignable alignable,
align::RotationType rotation 
)

Add alignment position error resulting from rotation in global frame.

Definition at line 611 of file AlignableModifier.cc.

References Alignable::addAlignmentPositionErrorFromRotation(), LogDebug, and idealTransformation::rotation.

611  {
612  LogDebug("PrintArgs") << "Adding an AlignmentPositionError from Rotation" << std::endl << rotation;
613 
614  alignable->addAlignmentPositionErrorFromRotation(rotation, true); // propagate down to components
615 }
virtual void addAlignmentPositionErrorFromRotation(const RotationType &rotation, bool propagateDown)=0
#define LogDebug(id)

◆ addAlignmentPositionErrorLocal()

void AlignableModifier::addAlignmentPositionErrorLocal ( Alignable alignable,
float  dx,
float  dy,
float  dz 
)

Add the AlignmentPositionError (in local frame) to Alignable.

Definition at line 540 of file AlignableModifier.cc.

References Alignable::addAlignmentPositionError(), GlobalErrorBase< T, ErrorWeightType >::cxx(), GlobalErrorBase< T, ErrorWeightType >::cyx(), GlobalErrorBase< T, ErrorWeightType >::cyy(), GlobalErrorBase< T, ErrorWeightType >::czx(), GlobalErrorBase< T, ErrorWeightType >::czy(), GlobalErrorBase< T, ErrorWeightType >::czz(), PVValHelper::dx, PVValHelper::dy, PVValHelper::dz, Alignable::globalRotation(), LogDebug, and hcal_runs::rt.

Referenced by modify().

540  {
541  LogDebug("PrintArgs") << "Adding a local AlignmentPositionError of size " << dx << " " << dy << " " << dz;
542 
543  AlgebraicSymMatrix as(3, 0); //3x3, zeroed
544  as[0][0] = dx * dx;
545  as[1][1] = dy * dy;
546  as[2][2] = dz * dz; //diagonals
547  align::RotationType rt = alignable->globalRotation(); //get rotation
548  AlgebraicMatrix am(3, 3);
549  am[0][0] = rt.xx();
550  am[0][1] = rt.xy();
551  am[0][2] = rt.xz();
552  am[1][0] = rt.yx();
553  am[1][1] = rt.yy();
554  am[1][2] = rt.yz();
555  am[2][0] = rt.zx();
556  am[2][1] = rt.zy();
557  am[2][2] = rt.zz();
558  as = as.similarityT(am); //rotate error matrix
559 
560  GlobalError ge(asSMatrix<3>(as));
561  GlobalErrorExtended gee(ge.cxx(),
562  ge.cyx(),
563  ge.czx(),
564  0.,
565  0.,
566  0.,
567  ge.cyy(),
568  ge.czy(),
569  0.,
570  0.,
571  0.,
572  ge.czz(),
573  0.,
574  0.,
575  0.,
576  0.,
577  0.,
578  0.,
579  0.,
580  0.,
581  0.);
582  AlignmentPositionError ape(gee);
583 
584  alignable->addAlignmentPositionError(ape, true); // propagate down to components
585 }
virtual void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown)=0
CLHEP::HepMatrix AlgebraicMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
#define LogDebug(id)

◆ addDeformation()

void AlignableModifier::addDeformation ( Alignable alignable,
const DeformationMemberType deformation,
bool  random,
bool  gaussian,
double  scale 
)
private

Definition at line 355 of file AlignableModifier.cc.

References Alignable::addSurfaceDeformation(), SurfaceDeformationFactory::create(), mps_fire::i, SurfaceDeformationFactory::kTwoBowedSurfaces, m_modified, randomise(), L1EGammaClusterEmuProducer_cfi::scale, and SurfaceDeformationFactory::surfaceDeformationType().

Referenced by modify().

359  {
360  const SurfaceDeformationFactory::Type deformType =
362 
363  // Scale and randomize
364  // (need a little hack since ySplit must not be treated)!
365  const bool rndNotLast = (deformType == SurfaceDeformationFactory::kTwoBowedSurfaces);
366  std::vector<double> rndDeformation(deformation.second.begin(), deformation.second.end() - (rndNotLast ? 1 : 0));
367  for (unsigned int i = 0; i < rndDeformation.size(); ++i) {
368  rndDeformation[i] *= scale;
369  }
370  if (random) {
371  this->randomise(rndDeformation, gaussian);
372  }
373  if (rndNotLast) { // put back ySplit at the end
374  rndDeformation.push_back(deformation.second.back());
375  }
376 
377  // auto_ptr has exception safe delete (in contrast to bare pointer)
378  const std::unique_ptr<SurfaceDeformation> surfDef(SurfaceDeformationFactory::create(deformType, rndDeformation));
379 
380  alignable->addSurfaceDeformation(surfDef.get(), true); // true to propagate down
381  ++m_modified;
382 }
virtual void addSurfaceDeformation(const SurfaceDeformation *deformation, bool propagateDown)=0
void randomise(std::vector< double > &rnd, bool gaussian) const
Type surfaceDeformationType(const std::string &typeString)
convert string to &#39;Type&#39; - exception if string is not known
SurfaceDeformation * create(int type, const std::vector< double > &params)

◆ flatRandomVector()

const std::vector< float > AlignableModifier::flatRandomVector ( float  sigmaX,
float  sigmaY,
float  sigmaZ 
) const

Return a vector of random numbers (flat distribution)

Definition at line 486 of file AlignableModifier.cc.

References funct::abs(), BeamSpotPI::sigmaX, BeamSpotPI::sigmaY, BeamSpotPI::sigmaZ, and theDRand48Engine.

Referenced by moveAlignable(), moveAlignableLocal(), MuonScenarioBuilder::moveCSCSectors(), MuonScenarioBuilder::moveDTSectors(), MuonScenarioBuilder::moveGEMSectors(), MuonScenarioBuilder::moveMuon(), rotateAlignable(), and rotateAlignableLocal().

486  {
487  // Get absolute value if negative arguments
488  if (sigmaX < 0) {
489  edm::LogWarning("BadConfig") << " taking absolute value for flat sigma_x";
491  }
492  if (sigmaY < 0) {
493  edm::LogWarning("BadConfig") << " taking absolute value for flat sigma_y";
495  }
496  if (sigmaZ < 0) {
497  edm::LogWarning("BadConfig") << " taking absolute value for flat sigma_z";
499  }
500 
501  CLHEP::RandFlat aFlatObjX(*theDRand48Engine, -sigmaX, sigmaX);
502  CLHEP::RandFlat aFlatObjY(*theDRand48Engine, -sigmaY, sigmaY);
503  CLHEP::RandFlat aFlatObjZ(*theDRand48Engine, -sigmaZ, sigmaZ);
504 
505  std::vector<float> randomVector;
506  randomVector.push_back(aFlatObjX.fire());
507  randomVector.push_back(aFlatObjY.fire());
508  randomVector.push_back(aFlatObjZ.fire());
509 
510  return randomVector;
511 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CLHEP::DRand48Engine * theDRand48Engine
Unique random number generator.
Log< level::Warning, false > LogWarning

◆ gaussianRandomVector()

const std::vector< float > AlignableModifier::gaussianRandomVector ( float  sigmaX,
float  sigmaY,
float  sigmaZ 
) const

Return a vector of random numbers (gaussian distribution)

Definition at line 457 of file AlignableModifier.cc.

References funct::abs(), BeamSpotPI::sigmaX, BeamSpotPI::sigmaY, BeamSpotPI::sigmaZ, and theDRand48Engine.

Referenced by moveAlignable(), moveAlignableLocal(), MuonScenarioBuilder::moveCSCSectors(), MuonScenarioBuilder::moveDTSectors(), MuonScenarioBuilder::moveGEMSectors(), MuonScenarioBuilder::moveMuon(), rotateAlignable(), and rotateAlignableLocal().

457  {
458  // Get absolute value if negative arguments
459  if (sigmaX < 0) {
460  edm::LogWarning("BadConfig") << " taking absolute value for gaussian sigma_x";
462  }
463  if (sigmaY < 0) {
464  edm::LogWarning("BadConfig") << " taking absolute value for gaussian sigma_y";
466  }
467  if (sigmaZ < 0) {
468  edm::LogWarning("BadConfig") << " taking absolute value for gaussian sigma_z";
470  }
471 
472  // Pass by reference, otherwise pointer is deleted!
473  CLHEP::RandGauss aGaussObjX(*theDRand48Engine, 0., sigmaX);
474  CLHEP::RandGauss aGaussObjY(*theDRand48Engine, 0., sigmaY);
475  CLHEP::RandGauss aGaussObjZ(*theDRand48Engine, 0., sigmaZ);
476 
477  std::vector<float> randomVector;
478  randomVector.push_back(aGaussObjX.fire());
479  randomVector.push_back(aGaussObjY.fire());
480  randomVector.push_back(aGaussObjZ.fire());
481 
482  return randomVector;
483 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CLHEP::DRand48Engine * theDRand48Engine
Unique random number generator.
Log< level::Warning, false > LogWarning

◆ init_()

void AlignableModifier::init_ ( void  )
private

Initialisation of all parameters.

Definition at line 52 of file AlignableModifier.cc.

References deformation_, distribution_, dX_, dXlocal_, dY_, dYlocal_, dZ_, dZlocal_, gaussian_, phiX_, phiXlocal_, phiY_, phiYlocal_, phiZ_, phiZlocal_, random_, scale_, scaleError_, setError_, setRotations_, setTranslations_, shear_, and twist_.

Referenced by modify().

52  {
53  // Initialize all known parameters (according to ORCA's MisalignmentScenario.cc)
54  distribution_ = ""; // Switch for distributions ("fixed","flat","gaussian")
55  setError_ = false; // Apply alignment errors
56  setRotations_ = true; // Apply rotations
57  setTranslations_ = true; // Apply translations
58  scale_ = 1.; // Scale to apply to all movements
59  scaleError_ = 1.; // Scale to apply to alignment errors
60  phiX_ = 0.; // Rotation angle around X [rad]
61  phiY_ = 0.; // Rotation angle around Y [rad]
62  phiZ_ = 0.; // Rotation angle around Z [rad]
63  phiXlocal_ = 0.; // Local rotation angle around X [rad]
64  phiYlocal_ = 0.; // Local rotation angle around Y [rad]
65  phiZlocal_ = 0.; // Local rotation angle around Z [rad]
66  dX_ = 0.; // X displacement [cm]
67  dY_ = 0.; // Y displacement [cm]
68  dZ_ = 0.; // Z displacement [cm]
69  dXlocal_ = 0.; // Local X displacement [cm]
70  dYlocal_ = 0.; // Local Y displacement [cm]
71  dZlocal_ = 0.; // Local Z displacement [cm]
72  deformation_.first.clear(); // SurfaceDeformation: type
73  deformation_.second.clear(); //SurfaceDeformation: parameter vector
74  twist_ = 0.; // Twist angle [rad]
75  shear_ = 0.; // Shear angle [rad]
76 
77  // These are set through 'distribution'
78  random_ = true; // Use random distributions
79  gaussian_ = true; // Use gaussian distribution (otherwise flat)
80 }
std::string distribution_
DeformationMemberType deformation_

◆ isPropagated()

bool AlignableModifier::isPropagated ( const std::string &  parameterName) const

Check if given parameter should be propagated.

Definition at line 84 of file AlignableModifier.cc.

Referenced by MisalignmentScenarioBuilder::propagateParameters_().

84  {
85  if (parameterName == "distribution" || parameterName == "setError" || parameterName == "scaleError" ||
86  parameterName == "setRotations" || parameterName == "setTranslations" || parameterName == "scale")
87  return true;
88 
89  return false;
90 }

◆ modify()

bool AlignableModifier::modify ( Alignable alignable,
const edm::ParameterSet pSet 
)

Modify given set of alignables according to parameters.

All known parameters and defaults are defined here! Returns true if modification actually applied.

Definition at line 94 of file AlignableModifier.cc.

References funct::abs(), addAlignmentPositionError(), addAlignmentPositionErrorFromLocalRotation(), addAlignmentPositionErrorFromRotation(), addAlignmentPositionErrorLocal(), addDeformation(), deformation_, distribution_, dX_, dXlocal_, dY_, dYlocal_, dZ_, dZlocal_, relativeConstraints::error, Exception, edm::ParameterSet::existsAs(), gaussian_, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), init_(), m_modified, moveAlignable(), moveAlignableLocal(), phiX_, phiXlocal_, phiY_, phiYlocal_, phiZ_, phiZlocal_, random_, rotateAlignable(), rotateAlignableLocal(), scale_, scaleError_, setDistribution(), setError_, setRotations_, setTranslations_, shear_, AlCaHLTBitMon_QueryRunRegistry::string, and twist_.

Referenced by MisalignmentScenarioBuilder::decodeMovements_().

94  {
95  // Initialize parameters
96  this->init_();
97  int rotX_ = 0, rotY_ = 0, rotZ_ = 0; // To check correct backward compatibility
98 
99  // Reset counter
100  m_modified = 0;
101 
102  // Retrieve parameters
103  std::ostringstream error;
104  std::vector<std::string> parameterNames = pSet.getParameterNames();
105  for (std::vector<std::string>::iterator iParam = parameterNames.begin(); iParam != parameterNames.end(); ++iParam) {
106  if ((*iParam) == "distribution")
107  distribution_ = pSet.getParameter<std::string>(*iParam);
108  else if ((*iParam) == "setError")
109  setError_ = pSet.getParameter<bool>(*iParam);
110  else if ((*iParam) == "setRotations")
111  setRotations_ = pSet.getParameter<bool>(*iParam);
112  else if ((*iParam) == "setTranslations")
113  setTranslations_ = pSet.getParameter<bool>(*iParam);
114  else if ((*iParam) == "scale")
115  scale_ = pSet.getParameter<double>(*iParam);
116  else if ((*iParam) == "scaleError")
117  scaleError_ = pSet.getParameter<double>(*iParam);
118  else if ((*iParam) == "phiX")
119  phiX_ = pSet.getParameter<double>(*iParam);
120  else if ((*iParam) == "phiY")
121  phiY_ = pSet.getParameter<double>(*iParam);
122  else if ((*iParam) == "phiZ")
123  phiZ_ = pSet.getParameter<double>(*iParam);
124  else if ((*iParam) == "dX")
125  dX_ = pSet.getParameter<double>(*iParam);
126  else if ((*iParam) == "dY")
127  dY_ = pSet.getParameter<double>(*iParam);
128  else if ((*iParam) == "dZ")
129  dZ_ = pSet.getParameter<double>(*iParam);
130  else if ((*iParam) == "dXlocal")
131  dXlocal_ = pSet.getParameter<double>(*iParam);
132  else if ((*iParam) == "dYlocal")
133  dYlocal_ = pSet.getParameter<double>(*iParam);
134  else if ((*iParam) == "dZlocal")
135  dZlocal_ = pSet.getParameter<double>(*iParam);
136  else if ((*iParam) == "twist")
137  twist_ = pSet.getParameter<double>(*iParam);
138  else if ((*iParam) == "shear")
139  shear_ = pSet.getParameter<double>(*iParam);
140  else if ((*iParam) == "localX") {
141  phiXlocal_ = pSet.getParameter<double>(*iParam);
142  rotX_++;
143  } else if ((*iParam) == "localY") {
144  phiYlocal_ = pSet.getParameter<double>(*iParam);
145  rotY_++;
146  } else if ((*iParam) == "localZ") {
147  phiZlocal_ = pSet.getParameter<double>(*iParam);
148  rotZ_++;
149  } else if ((*iParam) == "phiXlocal") {
150  phiXlocal_ = pSet.getParameter<double>(*iParam);
151  rotX_++;
152  } else if ((*iParam) == "phiYlocal") {
153  phiYlocal_ = pSet.getParameter<double>(*iParam);
154  rotY_++;
155  } else if ((*iParam) == "phiZlocal") {
156  phiZlocal_ = pSet.getParameter<double>(*iParam);
157  rotZ_++;
158  } else if ((*iParam) == "deformation") {
159  const edm::ParameterSet deform(pSet.getParameter<edm::ParameterSet>(*iParam));
160  deformation_.first = deform.getParameter<std::string>("type");
161  deformation_.second = deform.getParameter<std::vector<double> >("parameters");
162  } else if (pSet.existsAs<edm::ParameterSet>(*iParam)) {
163  // Other PSets than 'deformation' must refer to hierarchy structures, i.e. their name
164  // is a level name followed by 's' or ending with a digit (see
165  // MisalignmentScenarioBuilder::getParameterSet_). Pitfall is to forget the trailing 's'!
166  // 'Muon' is an especially allowed case used in MuonScenarioBuilder::moveMuon(..),
167  // also check that we do not have any mistyping like 'deformations' or 'deformation2'
168  const auto lastCharacter = (iParam->empty() ? '_' : (*iParam)[iParam->size() - 1]);
169  if ((lastCharacter != 's' && !isdigit(lastCharacter) && (*iParam) != "Muon") ||
170  iParam->find("deformation") != std::string::npos) {
171  throw cms::Exception("BadConfig") << "@SUB=AlignableModifier::modify(..):\n"
172  << "I see parameter '" << *iParam << "' of type PSet, "
173  << "but expect either 'deformation' or a level name "
174  << "with 's' or a digit at the end.\n";
175  } // other PSets should now be hierarchy levels and thus be OK to ignore here
176  } else {
177  if (!error.str().length())
178  error << "Unknown parameter name(s): ";
179  error << " " << *iParam;
180  }
181  }
182 
183  // Check if both 'localN' and 'phiNlocal' have been used
184  if (rotX_ == 2)
185  throw cms::Exception("BadConfig") << "Found both localX and phiXlocal";
186  if (rotY_ == 2)
187  throw cms::Exception("BadConfig") << "Found both localY and phiYlocal";
188  if (rotZ_ == 2)
189  throw cms::Exception("BadConfig") << "Found both localZ and phiZlocal";
190 
191  // Check error
192  if (error.str().length())
193  throw cms::Exception("BadConfig") << error.str();
194 
195  // Decode distribution
197 
198  //if (scale_) { NO! Different random sequence if only parts scale to zero!
199 
200  // Apply displacements
202  this->moveAlignable(alignable, random_, gaussian_, scale_ * dX_, scale_ * dY_, scale_ * dZ_);
203 
204  // Apply local displacements
207 
208  // Apply rotations
210  this->rotateAlignable(alignable, random_, gaussian_, scale_ * phiX_, scale_ * phiY_, scale_ * phiZ_);
211 
212  // Apply local rotations
214  this->rotateAlignableLocal(
216 
217  // Apply twist
218  if (std::abs(twist_) > 0)
219  edm::LogError("NotImplemented") << "Twist is not implemented yet";
220 
221  // Apply shear
222  if (std::abs(shear_) > 0)
223  edm::LogError("NotImplemented") << "Shear is not implemented yet";
224 
225  if (!deformation_.first.empty()) {
226  this->addDeformation(alignable, deformation_, random_, gaussian_, scale_);
227  }
228 
229  // Apply error - first add scale_ to error
230  scaleError_ *= scale_;
231  if (setError_ && scaleError_) {
232  // Alignment Position Error for flat distribution: 1 sigma
233  if (!gaussian_)
234  scaleError_ *= 0.68;
235 
236  // Error on displacement
239 
240  // Error on local displacements
244 
245  // Error on rotations
248  alignable, scaleError_ * phiX_, scaleError_ * phiY_, scaleError_ * phiZ_);
249 
250  // Error on local rotations
254  // Do we need to add any APE for deformations?
255  // Probably we would do so if there wouldn't be data, but only MC to play with... ;-)
256  }
257  // } // end if (scale_)
258 
259  return (m_modified > 0);
260 }
void addAlignmentPositionErrorFromLocalRotation(Alignable *alignable, float phiX, float phiY, float phiZ)
Add alignment position error resulting from rotation in local frame.
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void rotateAlignableLocal(Alignable *alignable, bool random, bool gaussian, float sigmaPhiX, float sigmaPhiY, float sigmaPhiZ)
Rotate alignable in local space according to parameters.
void addAlignmentPositionError(Alignable *alignable, float dx, float dy, float dz)
Add the AlignmentPositionError (in global frame) to Alignable.
void init_()
Initialisation of all parameters.
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
Log< level::Error, false > LogError
void addAlignmentPositionErrorLocal(Alignable *alignable, float dx, float dy, float dz)
Add the AlignmentPositionError (in local frame) to Alignable.
std::string distribution_
void addDeformation(Alignable *alignable, const DeformationMemberType &deformation, bool random, bool gaussian, double scale)
void moveAlignable(Alignable *alignable, bool random, bool gaussian, float sigmaX, float sigmaY, float sigmaZ)
Move alignable in global space according to parameters.
void setDistribution(const std::string &distr)
Decodes string and sets distribution accordingly (&#39;fixed&#39;, &#39;flat&#39; or &#39;gaussian&#39;). ...
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DeformationMemberType deformation_
void rotateAlignable(Alignable *alignable, bool random, bool gaussian, float sigmaPhiX, float sigmaPhiY, float sigmaPhiZ)
Rotate alignable in global space according to parameters.
void addAlignmentPositionErrorFromRotation(Alignable *alignable, float phiX, float phiY, float phiZ)
Add alignment position error resulting from rotation in global frame.
void moveAlignableLocal(Alignable *alignable, bool random, bool gaussian, float sigmaX, float sigmaY, float sigmaZ)
Move alignable in local space according to parameters.
std::vector< std::string > getParameterNames() const

◆ moveAlignable()

void AlignableModifier::moveAlignable ( Alignable alignable,
bool  random,
bool  gaussian,
float  sigmaX,
float  sigmaY,
float  sigmaZ 
)

Move alignable in global space according to parameters.

If 'random' is false, the given movements are strictly applied. Otherwise, a random number is generated according to a gaussian or a flat distribution depending on 'gaussian'.

Definition at line 295 of file AlignableModifier.cc.

References flatRandomVector(), gaussianRandomVector(), LogDebug, m_modified, Alignable::move(), BeamSpotPI::sigmaX, BeamSpotPI::sigmaY, and BeamSpotPI::sigmaZ.

Referenced by modify(), MuonScenarioBuilder::moveChamberInSector(), and MuonScenarioBuilder::moveMuon().

296  {
297  std::ostringstream message;
298 
299  // Get movement vector according to arguments
300  GlobalVector moveV(sigmaX, sigmaY, sigmaZ); // Default: fixed
301  if (random) {
302  std::vector<float> randomNumbers;
303  message << "random ";
304  if (gaussian) {
305  randomNumbers = this->gaussianRandomVector(sigmaX, sigmaY, sigmaZ);
306  message << "gaussian ";
307  } else {
308  randomNumbers = this->flatRandomVector(sigmaX, sigmaY, sigmaZ);
309  message << "flat ";
310  }
311  moveV = GlobalVector(randomNumbers[0], randomNumbers[1], randomNumbers[2]);
312  }
313 
314  message << " move with sigma " << sigmaX << " " << sigmaY << " " << sigmaZ;
315 
316  LogDebug("PrintArgs") << message.str(); // Arguments
317 
318  LogDebug("PrintMovement") << "applied displacement: " << moveV; // Actual movements
319  alignable->move(moveV);
320  m_modified++;
321 }
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
const std::vector< float > flatRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (flat distribution)
const std::vector< float > gaussianRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (gaussian distribution)
Global3DVector GlobalVector
Definition: GlobalVector.h:10
#define LogDebug(id)

◆ moveAlignableLocal()

void AlignableModifier::moveAlignableLocal ( Alignable alignable,
bool  random,
bool  gaussian,
float  sigmaX,
float  sigmaY,
float  sigmaZ 
)

Move alignable in local space according to parameters.

If 'random' is false, the given movements are strictly applied. Otherwise, a random number is generated according to a gaussian or a flat distribution depending on 'gaussian'.

Definition at line 326 of file AlignableModifier.cc.

References flatRandomVector(), gaussianRandomVector(), LogDebug, m_modified, Alignable::move(), BeamSpotPI::sigmaX, BeamSpotPI::sigmaY, BeamSpotPI::sigmaZ, Alignable::surface(), and AlignableSurface::toGlobal().

Referenced by modify().

327  {
328  std::ostringstream message;
329 
330  // Get movement vector according to arguments
331  align::LocalVector moveV(sigmaX, sigmaY, sigmaZ); // Default: fixed
332  if (random) {
333  std::vector<float> randomNumbers;
334  message << "random ";
335  if (gaussian) {
336  randomNumbers = this->gaussianRandomVector(sigmaX, sigmaY, sigmaZ);
337  message << "gaussian ";
338  } else {
339  randomNumbers = this->flatRandomVector(sigmaX, sigmaY, sigmaZ);
340  message << "flat ";
341  }
342  moveV = align::LocalVector(randomNumbers[0], randomNumbers[1], randomNumbers[2]);
343  }
344 
345  message << " move with sigma " << sigmaX << " " << sigmaY << " " << sigmaZ;
346 
347  LogDebug("PrintArgs") << message.str(); // Arguments
348 
349  LogDebug("PrintMovement") << "applied local displacement: " << moveV; // Actual movements
350  alignable->move(alignable->surface().toGlobal(moveV));
351  m_modified++;
352 }
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
const std::vector< float > flatRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (flat distribution)
Vector3DBase< Scalar, LocalTag > LocalVector
Definition: Definitions.h:32
const std::vector< float > gaussianRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (gaussian distribution)
#define LogDebug(id)

◆ randomise()

void AlignableModifier::randomise ( std::vector< double > &  rnd,
bool  gaussian 
) const

Randomise all entries in 'rnd':

  • either from gaussian with width rnd[i]
  • or from flat distribution between -rnd[i] and rnd[i]

Definition at line 514 of file AlignableModifier.cc.

References funct::abs(), mps_fire::i, and theDRand48Engine.

Referenced by addDeformation().

514  {
515  for (unsigned int i = 0; i < rnd.size(); ++i) {
516  if (rnd[i] < 0.) {
517  edm::LogWarning("BadConfig") << " taking absolute value to randomise " << i;
518  rnd[i] = std::abs(rnd[i]);
519  }
520 
521  if (gaussian) {
522  CLHEP::RandGauss aGaussObj(*theDRand48Engine, 0., rnd[i]);
523  rnd[i] = aGaussObj.fire();
524  } else {
525  CLHEP::RandFlat aFlatObj(*theDRand48Engine, -rnd[i], rnd[i]);
526  rnd[i] = aFlatObj.fire();
527  }
528  }
529 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CLHEP::DRand48Engine * theDRand48Engine
Unique random number generator.
Log< level::Warning, false > LogWarning

◆ rotateAlignable()

void AlignableModifier::rotateAlignable ( Alignable alignable,
bool  random,
bool  gaussian,
float  sigmaPhiX,
float  sigmaPhiY,
float  sigmaPhiZ 
)

Rotate alignable in global space according to parameters.

If 'random' is false, the given rotations are strictly applied. Otherwise, a random number is generated according to a gaussian or a flat distribution depending on 'gaussian'.

Definition at line 387 of file AlignableModifier.cc.

References funct::abs(), flatRandomVector(), gaussianRandomVector(), LogDebug, m_modified, Alignable::rotateAroundGlobalX(), Alignable::rotateAroundGlobalY(), Alignable::rotateAroundGlobalZ(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by modify(), MuonScenarioBuilder::moveChamberInSector(), and MuonScenarioBuilder::moveMuon().

388  {
389  std::ostringstream message;
390 
391  // Get rotation vector according to arguments
392  GlobalVector rotV(sigmaPhiX, sigmaPhiY, sigmaPhiZ); // Default: fixed
393  if (random) {
394  std::vector<float> randomNumbers;
395  message << "random ";
396  if (gaussian) {
397  randomNumbers = this->gaussianRandomVector(sigmaPhiX, sigmaPhiY, sigmaPhiZ);
398  message << "gaussian ";
399  } else {
400  randomNumbers = flatRandomVector(sigmaPhiX, sigmaPhiY, sigmaPhiZ);
401  message << "flat ";
402  }
403  rotV = GlobalVector(randomNumbers[0], randomNumbers[1], randomNumbers[2]);
404  }
405 
406  message << "global rotation by angles " << sigmaPhiX << " " << sigmaPhiY << " " << sigmaPhiZ;
407 
408  LogDebug("PrintArgs") << message.str(); // Arguments
409 
410  LogDebug("PrintMovement") << "applied rotation angles: " << rotV; // Actual movements
411  if (std::abs(sigmaPhiX))
412  alignable->rotateAroundGlobalX(rotV.x());
413  if (std::abs(sigmaPhiY))
414  alignable->rotateAroundGlobalY(rotV.y());
415  if (std::abs(sigmaPhiZ))
416  alignable->rotateAroundGlobalZ(rotV.z());
417  m_modified++;
418 }
virtual void rotateAroundGlobalZ(Scalar radians)
Rotation around global z-axis.
Definition: Alignable.cc:176
const std::vector< float > flatRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (flat distribution)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::vector< float > gaussianRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (gaussian distribution)
virtual void rotateAroundGlobalX(Scalar radians)
Rotation around global x-axis.
Definition: Alignable.cc:148
virtual void rotateAroundGlobalY(Scalar radians)
Rotation around global y-axis.
Definition: Alignable.cc:162
Global3DVector GlobalVector
Definition: GlobalVector.h:10
#define LogDebug(id)

◆ rotateAlignableLocal()

void AlignableModifier::rotateAlignableLocal ( Alignable alignable,
bool  random,
bool  gaussian,
float  sigmaPhiX,
float  sigmaPhiY,
float  sigmaPhiZ 
)

Rotate alignable in local space according to parameters.

If 'random' is false, the given rotations are strictly applied. Otherwise, a random number is generated according to a gaussian or a flat distribution depending on 'gaussian'.

Definition at line 423 of file AlignableModifier.cc.

References funct::abs(), flatRandomVector(), gaussianRandomVector(), LogDebug, m_modified, Alignable::rotateAroundLocalX(), Alignable::rotateAroundLocalY(), Alignable::rotateAroundLocalZ(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by modify().

424  {
425  std::ostringstream message;
426 
427  // Get rotation vector according to arguments
428  align::LocalVector rotV(sigmaPhiX, sigmaPhiY, sigmaPhiZ); // Default: fixed
429  if (random) {
430  std::vector<float> randomNumbers;
431  message << "random ";
432  if (gaussian) {
433  randomNumbers = this->gaussianRandomVector(sigmaPhiX, sigmaPhiY, sigmaPhiZ);
434  message << "gaussian ";
435  } else {
436  randomNumbers = flatRandomVector(sigmaPhiX, sigmaPhiY, sigmaPhiZ);
437  message << "flat ";
438  }
439  rotV = align::LocalVector(randomNumbers[0], randomNumbers[1], randomNumbers[2]);
440  }
441 
442  message << "local rotation by angles " << sigmaPhiX << " " << sigmaPhiY << " " << sigmaPhiZ;
443 
444  LogDebug("PrintArgs") << message.str(); // Arguments
445 
446  LogDebug("PrintMovement") << "applied local rotation angles: " << rotV; // Actual movements
447  if (std::abs(sigmaPhiX))
448  alignable->rotateAroundLocalX(rotV.x());
449  if (std::abs(sigmaPhiY))
450  alignable->rotateAroundLocalY(rotV.y());
451  if (std::abs(sigmaPhiZ))
452  alignable->rotateAroundLocalZ(rotV.z());
453  m_modified++;
454 }
virtual void rotateAroundLocalZ(Scalar radians)
Rotation around local z-axis.
Definition: Alignable.cc:183
const std::vector< float > flatRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (flat distribution)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Vector3DBase< Scalar, LocalTag > LocalVector
Definition: Definitions.h:32
const std::vector< float > gaussianRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (gaussian distribution)
virtual void rotateAroundLocalY(Scalar radians)
Rotation around local y-axis.
Definition: Alignable.cc:169
virtual void rotateAroundLocalX(Scalar radians)
Rotation around local x-axis.
Definition: Alignable.cc:155
#define LogDebug(id)

◆ setDistribution()

void AlignableModifier::setDistribution ( const std::string &  distr)

Decodes string and sets distribution accordingly ('fixed', 'flat' or 'gaussian').

Definition at line 263 of file AlignableModifier.cc.

References gaussian_, and random_.

Referenced by modify().

263  {
264  if (distr == "fixed")
265  random_ = false;
266  else if (distr == "flat") {
267  random_ = true;
268  gaussian_ = false;
269  } else if (distr == "gaussian") {
270  random_ = true;
271  gaussian_ = true;
272  }
273 }

◆ setSeed()

void AlignableModifier::setSeed ( long  seed)

Resets the generator seed according to the argument.

If 'seed' is zero, asks RandomNumberGenerator service.

Definition at line 277 of file AlignableModifier.cc.

References LogDebug, edm::RandomNumberGenerator::mySeed(), fileCollector::seed, and theDRand48Engine.

Referenced by MuonScenarioBuilder::applyScenario(), and TrackerScenarioBuilder::applyScenario().

277  {
278  long m_seed;
279 
280  if (seed > 0)
281  m_seed = seed;
282  else {
284  m_seed = rng->mySeed();
285  }
286 
287  LogDebug("PrintArgs") << "Setting generator seed to " << m_seed;
288 
289  theDRand48Engine->setSeed(m_seed);
290 }
virtual std::uint32_t mySeed() const =0
CLHEP::DRand48Engine * theDRand48Engine
Unique random number generator.
#define LogDebug(id)

Member Data Documentation

◆ deformation_

DeformationMemberType AlignableModifier::deformation_
private

Definition at line 107 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ distribution_

std::string AlignableModifier::distribution_
private

Definition at line 98 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ dX_

double AlignableModifier::dX_
private

Definition at line 105 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ dXlocal_

double AlignableModifier::dXlocal_
private

Definition at line 106 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ dY_

double AlignableModifier::dY_
private

Definition at line 105 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ dYlocal_

double AlignableModifier::dYlocal_
private

Definition at line 106 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ dZ_

double AlignableModifier::dZ_
private

Definition at line 105 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ dZlocal_

double AlignableModifier::dZlocal_
private

Definition at line 106 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ gaussian_

bool AlignableModifier::gaussian_
private

Definition at line 99 of file AlignableModifier.h.

Referenced by init_(), modify(), and setDistribution().

◆ m_modified

int AlignableModifier::m_modified
private

◆ phiX_

double AlignableModifier::phiX_
private

Definition at line 103 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ phiXlocal_

double AlignableModifier::phiXlocal_
private

Definition at line 104 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ phiY_

double AlignableModifier::phiY_
private

Definition at line 103 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ phiYlocal_

double AlignableModifier::phiYlocal_
private

Definition at line 104 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ phiZ_

double AlignableModifier::phiZ_
private

Definition at line 103 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ phiZlocal_

double AlignableModifier::phiZlocal_
private

Definition at line 104 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ random_

bool AlignableModifier::random_
private

Definition at line 99 of file AlignableModifier.h.

Referenced by init_(), modify(), and setDistribution().

◆ scale_

double AlignableModifier::scale_
private

Definition at line 102 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ scaleError_

double AlignableModifier::scaleError_
private

Definition at line 102 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ seed_

long AlignableModifier::seed_
private

Definition at line 101 of file AlignableModifier.h.

◆ setError_

bool AlignableModifier::setError_
private

Definition at line 99 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ setRotations_

bool AlignableModifier::setRotations_
private

Definition at line 100 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ setTranslations_

bool AlignableModifier::setTranslations_
private

Definition at line 100 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ shear_

double AlignableModifier::shear_
private

Definition at line 108 of file AlignableModifier.h.

Referenced by init_(), and modify().

◆ theDRand48Engine

CLHEP::DRand48Engine* AlignableModifier::theDRand48Engine
private

Unique random number generator.

Definition at line 90 of file AlignableModifier.h.

Referenced by AlignableModifier(), flatRandomVector(), gaussianRandomVector(), randomise(), setSeed(), and ~AlignableModifier().

◆ twist_

double AlignableModifier::twist_
private

Definition at line 108 of file AlignableModifier.h.

Referenced by init_(), and modify().