4 #include "CLHEP/Random/DRand48Engine.h"
5 #include "CLHEP/Random/RandGauss.h"
6 #include "CLHEP/Random/Randomize.h"
27 setTranslations_(
false),
85 if (parameterName ==
"distribution" || parameterName ==
"setError" || parameterName ==
"scaleError" ||
86 parameterName ==
"setRotations" || parameterName ==
"setTranslations" || parameterName ==
"scale")
97 int rotX_ = 0, rotY_ = 0, rotZ_ = 0;
103 std::ostringstream
error;
105 for (std::vector<std::string>::iterator iParam = parameterNames.begin(); iParam != parameterNames.end(); ++iParam) {
106 if ((*iParam) ==
"distribution")
108 else if ((*iParam) ==
"setError")
110 else if ((*iParam) ==
"setRotations")
112 else if ((*iParam) ==
"setTranslations")
114 else if ((*iParam) ==
"scale")
116 else if ((*iParam) ==
"scaleError")
118 else if ((*iParam) ==
"phiX")
120 else if ((*iParam) ==
"phiY")
122 else if ((*iParam) ==
"phiZ")
124 else if ((*iParam) ==
"dX")
126 else if ((*iParam) ==
"dY")
128 else if ((*iParam) ==
"dZ")
130 else if ((*iParam) ==
"dXlocal")
132 else if ((*iParam) ==
"dYlocal")
134 else if ((*iParam) ==
"dZlocal")
136 else if ((*iParam) ==
"twist")
138 else if ((*iParam) ==
"shear")
140 else if ((*iParam) ==
"localX") {
143 }
else if ((*iParam) ==
"localY") {
146 }
else if ((*iParam) ==
"localZ") {
149 }
else if ((*iParam) ==
"phiXlocal") {
152 }
else if ((*iParam) ==
"phiYlocal") {
155 }
else if ((*iParam) ==
"phiZlocal") {
158 }
else if ((*iParam) ==
"deformation") {
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";
177 if (!error.str().length())
178 error <<
"Unknown parameter name(s): ";
179 error <<
" " << *iParam;
185 throw cms::Exception(
"BadConfig") <<
"Found both localX and phiXlocal";
187 throw cms::Exception(
"BadConfig") <<
"Found both localY and phiYlocal";
189 throw cms::Exception(
"BadConfig") <<
"Found both localZ and phiZlocal";
192 if (error.str().length())
219 edm::LogError(
"NotImplemented") <<
"Twist is not implemented yet";
223 edm::LogError(
"NotImplemented") <<
"Shear is not implemented yet";
264 if (distr ==
"fixed")
266 else if (distr ==
"flat") {
269 }
else if (distr ==
"gaussian") {
287 LogDebug(
"PrintArgs") <<
"Setting generator seed to " << m_seed;
297 std::ostringstream message;
302 std::vector<float> randomNumbers;
303 message <<
"random ";
306 message <<
"gaussian ";
311 moveV =
GlobalVector(randomNumbers[0], randomNumbers[1], randomNumbers[2]);
314 message <<
" move with sigma " << sigmaX <<
" " << sigmaY <<
" " <<
sigmaZ;
316 LogDebug(
"PrintArgs") << message.str();
318 LogDebug(
"PrintMovement") <<
"applied displacement: " << moveV;
319 alignable->
move(moveV);
328 std::ostringstream message;
333 std::vector<float> randomNumbers;
334 message <<
"random ";
337 message <<
"gaussian ";
345 message <<
" move with sigma " << sigmaX <<
" " << sigmaY <<
" " <<
sigmaZ;
347 LogDebug(
"PrintArgs") << message.str();
349 LogDebug(
"PrintMovement") <<
"applied local displacement: " << moveV;
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;
371 this->
randomise(rndDeformation, gaussian);
374 rndDeformation.push_back(deformation.second.back());
388 Alignable* alignable,
bool random,
bool gaussian,
float sigmaPhiX,
float sigmaPhiY,
float sigmaPhiZ) {
389 std::ostringstream message;
394 std::vector<float> randomNumbers;
395 message <<
"random ";
398 message <<
"gaussian ";
403 rotV =
GlobalVector(randomNumbers[0], randomNumbers[1], randomNumbers[2]);
406 message <<
"global rotation by angles " << sigmaPhiX <<
" " << sigmaPhiY <<
" " << sigmaPhiZ;
408 LogDebug(
"PrintArgs") << message.str();
410 LogDebug(
"PrintMovement") <<
"applied rotation angles: " << rotV;
424 Alignable* alignable,
bool random,
bool gaussian,
float sigmaPhiX,
float sigmaPhiY,
float sigmaPhiZ) {
425 std::ostringstream message;
430 std::vector<float> randomNumbers;
431 message <<
"random ";
434 message <<
"gaussian ";
442 message <<
"local rotation by angles " << sigmaPhiX <<
" " << sigmaPhiY <<
" " << sigmaPhiZ;
444 LogDebug(
"PrintArgs") << message.str();
446 LogDebug(
"PrintMovement") <<
"applied local rotation angles: " << rotV;
460 edm::LogWarning(
"BadConfig") <<
" taking absolute value for gaussian sigma_x";
464 edm::LogWarning(
"BadConfig") <<
" taking absolute value for gaussian sigma_y";
468 edm::LogWarning(
"BadConfig") <<
" taking absolute value for gaussian sigma_z";
477 std::vector<float> randomVector;
478 randomVector.push_back(aGaussObjX.fire());
479 randomVector.push_back(aGaussObjY.fire());
480 randomVector.push_back(aGaussObjZ.fire());
489 edm::LogWarning(
"BadConfig") <<
" taking absolute value for flat sigma_x";
493 edm::LogWarning(
"BadConfig") <<
" taking absolute value for flat sigma_y";
497 edm::LogWarning(
"BadConfig") <<
" taking absolute value for flat sigma_z";
505 std::vector<float> randomVector;
506 randomVector.push_back(aFlatObjX.fire());
507 randomVector.push_back(aFlatObjY.fire());
508 randomVector.push_back(aFlatObjZ.fire());
515 for (
unsigned int i = 0;
i < rnd.size(); ++
i) {
517 edm::LogWarning(
"BadConfig") <<
" taking absolute value to randomise " <<
i;
523 rnd[
i] = aGaussObj.fire();
526 rnd[
i] = aFlatObj.fire();
533 LogDebug(
"PrintArgs") <<
"Adding an AlignmentPositionError of size " << dx <<
" " << dy <<
" " <<
dz;
541 LogDebug(
"PrintArgs") <<
"Adding a local AlignmentPositionError of size " << dx <<
" " << dy <<
" " <<
dz;
558 as = as.similarityT(am);
612 LogDebug(
"PrintArgs") <<
"Adding an AlignmentPositionError from Rotation" << std::endl <<
rotation;
620 LogDebug(
"PrintArgs") <<
"Adding an AlignmentPositionError from Local Rotation" << std::endl <<
rotation;
void addAlignmentPositionErrorFromLocalRotation(Alignable *alignable, float phiX, float phiY, float phiZ)
Add alignment position error resulting from rotation in local frame.
void rotateAlignableLocal(Alignable *alignable, bool random, bool gaussian, float sigmaPhiX, float sigmaPhiY, float sigmaPhiZ)
Rotate alignable in local space according to parameters.
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
virtual void rotateAroundLocalZ(Scalar radians)
Rotation around local z-axis.
void setSeed(long seed)
Resets the generator seed according to the argument.
virtual void addAlignmentPositionErrorFromRotation(const RotationType &rotation, bool propagateDown)=0
void addAlignmentPositionError(Alignable *alignable, float dx, float dy, float dz)
Add the AlignmentPositionError (in global frame) to Alignable.
~AlignableModifier()
Destructor.
const std::vector< float > gaussianRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (gaussian distribution)
void init_()
Initialisation of all parameters.
const RotationType & globalRotation() const
Return the global orientation of the object.
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
Log< level::Error, false > LogError
virtual void addAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown)=0
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)
virtual void rotateAroundGlobalZ(Scalar radians)
Rotation around global z-axis.
virtual void addAlignmentPositionErrorFromLocalRotation(const RotationType &rotation, bool propagateDown)=0
void moveAlignable(Alignable *alignable, bool random, bool gaussian, float sigmaX, float sigmaY, float sigmaZ)
Move alignable in global space according to parameters.
AlignableModifier()
Constructor.
virtual std::uint32_t mySeed() const =0
CLHEP::HepMatrix AlgebraicMatrix
virtual void addSurfaceDeformation(const SurfaceDeformation *deformation, bool propagateDown)=0
void setDistribution(const std::string &distr)
Decodes string and sets distribution accordingly ('fixed', 'flat' or 'gaussian'). ...
Abs< T >::type abs(const T &t)
CLHEP::DRand48Engine * theDRand48Engine
Unique random number generator.
std::vector< std::string > getParameterNames() const
const std::vector< float > flatRandomVector(float sigmaX, float sigmaY, float sigmaZ) const
Return a vector of random numbers (flat distribution)
void randomise(std::vector< double > &rnd, bool gaussian) const
Vector3DBase< Scalar, LocalTag > LocalVector
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
DeformationMemberType deformation_
void rotateAlignable(Alignable *alignable, bool random, bool gaussian, float sigmaPhiX, float sigmaPhiY, float sigmaPhiZ)
Rotate alignable in global space according to parameters.
virtual void rotateAroundGlobalX(Scalar radians)
Rotation around global x-axis.
bool modify(Alignable *alignable, const edm::ParameterSet &pSet)
Modify given set of alignables according to parameters.
T getParameter(std::string const &) const
void addAlignmentPositionErrorFromRotation(Alignable *alignable, float phiX, float phiY, float phiZ)
Add alignment position error resulting from rotation in global frame.
virtual void rotateAroundLocalY(Scalar radians)
Rotation around local y-axis.
virtual void rotateAroundGlobalY(Scalar radians)
Rotation around global y-axis.
virtual void rotateAroundLocalX(Scalar radians)
Rotation around local x-axis.
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
CLHEP::HepSymMatrix AlgebraicSymMatrix
bool isPropagated(const std::string ¶meterName) const
Check if given parameter should be propagated.
void moveAlignableLocal(Alignable *alignable, bool random, bool gaussian, float sigmaX, float sigmaY, float sigmaZ)
Move alignable in local space according to parameters.
Log< level::Warning, false > LogWarning
std::pair< std::string, std::vector< double > > DeformationMemberType
Global3DVector GlobalVector