4 #include "CLHEP/Random/DRand48Engine.h"
5 #include "CLHEP/Random/RandGauss.h"
6 #include "CLHEP/Random/Randomize.h"
26 scaleError_(0.), scale_(0.),
27 phiX_(0.), phiY_(0.), phiZ_(0.),
28 phiXlocal_(0.), phiYlocal_(0.), phiZlocal_(0.),
29 dX_(0.), dY_(0.), dZ_(0.),
30 dXlocal_(0.), dYlocal_(0.), dZlocal_(0.),
31 twist_(0.), shear_(0.)
86 if ( parameterName ==
"distribution" ||
87 parameterName ==
"setError" ||
88 parameterName ==
"scaleError" ||
89 parameterName ==
"setRotations" ||
90 parameterName ==
"setTranslations" ||
91 parameterName ==
"scale"
106 int rotX_=0, rotY_=0, rotZ_=0;
113 std::ostringstream
error;
115 for ( std::vector<std::string>::iterator iParam = parameterNames.begin();
116 iParam != parameterNames.end(); iParam++ ) {
126 else if ( (*iParam) ==
"dX" )
dX_ = pSet.
getParameter<
double>( *iParam );
127 else if ( (*iParam) ==
"dY" )
dY_ = pSet.
getParameter<
double>( *iParam );
128 else if ( (*iParam) ==
"dZ" )
dZ_ = pSet.
getParameter<
double>( *iParam );
140 else if ( (*iParam) ==
"deformation" ) {
150 const auto lastCharacter = (iParam->empty() ?
'_' : (*iParam)[iParam->size()-1]);
151 if ( (lastCharacter !=
's' && !isdigit(lastCharacter) && (*iParam) !=
"Muon")
152 || iParam->find(
"deformation") != std::string::npos) {
153 throw cms::Exception(
"BadConfig") <<
"@SUB=AlignableModifier::modify(..):\n"
154 <<
"I see parameter '" << *iParam <<
"' of type PSet, "
155 <<
"but expect either 'deformation' or a level name "
156 <<
"with 's' or a digit at the end.\n";
159 if ( !error.str().length() ) error <<
"Unknown parameter name(s): ";
160 error <<
" " << *iParam;
165 if ( rotX_==2 )
throw cms::Exception(
"BadConfig") <<
"Found both localX and phiXlocal";
166 if ( rotY_==2 )
throw cms::Exception(
"BadConfig") <<
"Found both localY and phiYlocal";
167 if ( rotZ_==2 )
throw cms::Exception(
"BadConfig") <<
"Found both localZ and phiZlocal";
170 if ( error.str().length() )
199 edm::LogError(
"NotImplemented") <<
"Twist is not implemented yet";
203 edm::LogError(
"NotImplemented") <<
"Shear is not implemented yet";
254 if ( distr ==
"fixed" )
random_ =
false;
255 else if ( distr ==
"flat" ) {
258 }
else if ( distr ==
"gaussian" ) {
273 if ( seed > 0 ) m_seed =
seed;
279 LogDebug(
"PrintArgs") <<
"Setting generator seed to " << m_seed;
289 float sigmaX,
float sigmaY,
float sigmaZ )
298 std::vector<float> randomNumbers;
299 message <<
"random ";
302 message <<
"gaussian ";
307 moveV =
GlobalVector( randomNumbers[0], randomNumbers[1], randomNumbers[2] );
310 message <<
" move with sigma " << sigmaX <<
" " << sigmaY <<
" " << sigmaZ;
312 LogDebug(
"PrintArgs") << message.str();
314 LogDebug(
"PrintMovement") <<
"applied displacement: " << moveV;
315 alignable->
move(moveV);
325 float sigmaX,
float sigmaY,
float sigmaZ )
334 std::vector<float> randomNumbers;
335 message <<
"random ";
338 message <<
"gaussian ";
346 message <<
" move with sigma " << sigmaX <<
" " << sigmaY <<
" " << sigmaZ;
348 LogDebug(
"PrintArgs") << message.str();
350 LogDebug(
"PrintMovement") <<
"applied local displacement: " << moveV;
369 std::vector<double> rndDeformation(deformation.second.begin(),
370 deformation.second.end() - (rndNotLast ? 1 : 0));
371 for (
unsigned int i = 0;
i < rndDeformation.size(); ++
i) {
372 rndDeformation[
i] *=
scale;
375 this->randomise(rndDeformation, gaussian);
378 rndDeformation.push_back(deformation.second.back());
382 const std::auto_ptr<SurfaceDeformation> surfDef
393 float sigmaPhiX,
float sigmaPhiY,
float sigmaPhiZ )
402 std::vector<float> randomNumbers;
403 message <<
"random ";
406 message <<
"gaussian ";
411 rotV =
GlobalVector( randomNumbers[0], randomNumbers[1], randomNumbers[2] );
414 message <<
"global rotation by angles " << sigmaPhiX <<
" " << sigmaPhiY <<
" " << sigmaPhiZ;
416 LogDebug(
"PrintArgs") << message.str();
418 LogDebug(
"PrintMovement") <<
"applied rotation angles: " << rotV;
432 float sigmaPhiX,
float sigmaPhiY,
float sigmaPhiZ )
441 std::vector<float> randomNumbers;
442 message <<
"random ";
445 message <<
"gaussian ";
453 message <<
"local rotation by angles " << sigmaPhiX <<
" " << sigmaPhiY <<
" " << sigmaPhiZ;
455 LogDebug(
"PrintArgs") << message.str();
457 LogDebug(
"PrintMovement") <<
"applied local rotation angles: " << rotV;
468 const std::vector<float>
474 edm::LogWarning(
"BadConfig") <<
" taking absolute value for gaussian sigma_x";
478 edm::LogWarning(
"BadConfig") <<
" taking absolute value for gaussian sigma_y";
482 edm::LogWarning(
"BadConfig") <<
" taking absolute value for gaussian sigma_z";
491 std::vector<float> randomVector;
492 randomVector.push_back( aGaussObjX.fire() );
493 randomVector.push_back( aGaussObjY.fire() );
494 randomVector.push_back( aGaussObjZ.fire() );
502 const std::vector<float>
508 edm::LogWarning(
"BadConfig") <<
" taking absolute value for flat sigma_x";
512 edm::LogWarning(
"BadConfig") <<
" taking absolute value for flat sigma_y";
516 edm::LogWarning(
"BadConfig") <<
" taking absolute value for flat sigma_z";
524 std::vector<float> randomVector;
525 randomVector.push_back( aFlatObjX.fire() );
526 randomVector.push_back( aFlatObjY.fire() );
527 randomVector.push_back( aFlatObjZ.fire() );
536 for (
unsigned int i = 0;
i < rnd.size(); ++
i) {
538 edm::LogWarning(
"BadConfig") <<
" taking absolute value to randomise " <<
i;
544 rnd[
i] = aGaussObj.fire();
547 rnd[
i] = aFlatObj.fire();
554 float dx,
float dy,
float dz )
557 LogDebug(
"PrintArgs") <<
"Adding an AlignmentPositionError of size "
558 << dx <<
" " << dy <<
" " << dz;
568 float dx,
float dy,
float dz )
571 LogDebug(
"PrintArgs") <<
"Adding a local AlignmentPositionError of size "
572 << dx <<
" " << dy <<
" " << dz;
575 as[0][0] = dx*dx; as[1][1] = dy*dy; as[2][2] = dz*dz;
578 am[0][0]=rt.
xx(); am[0][1]=rt.
xy(); am[0][2]=rt.
xz();
579 am[1][0]=rt.
yx(); am[1][1]=rt.
yy(); am[1][2]=rt.
yz();
580 am[2][0]=rt.
zx(); am[2][1]=rt.
zy(); am[2][2]=rt.
zz();
581 as=as.similarityT(am);
594 float phiX,
float phiY,
610 float phiX,
float phiY,
629 LogDebug(
"PrintArgs") <<
"Adding an AlignmentPositionError from Rotation" << std::endl
642 LogDebug(
"PrintArgs") <<
"Adding an AlignmentPositionError from Local Rotation" << std::endl
T getParameter(std::string const &) const
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.
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.
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.
std::pair< std::string, std::vector< double > > DeformationMemberType
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.
volatile std::atomic< bool > shutdown_flag false
Global3DVector GlobalVector