61 : myParameterStore(store),
74 cms::Exception(
"BadConfig") <<
"Expect PedeSteerer.parameterSign = +/-1, " 107 }
else if (aliMuon) {
111 <<
"Cannot define global coordinate system " 112 <<
"with neither tracker nor muon!";
118 for (
const auto &it : allExtras)
164 for (
const auto &iAli : alis) {
170 unsigned int numNoHieraPar = 0;
171 unsigned int numHieraPar = 0;
172 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
174 if (selector ==
'C' || selector ==
'F' || selector ==
'H') {
176 }
else if (selector ==
'c' || selector ==
'f' || selector ==
'1' || selector ==
'r' || selector ==
's') {
183 <<
"[PedeSteerer::buildNoHierarchyCollection] All active parameters of alignables to be " 184 <<
" taken out of the hierarchy must be marked with capital letters 'C', 'F' or 'H'!";
186 bool isInHiera =
false;
188 while ((mother = mother->mother())) {
189 if (mother->alignmentParameters())
196 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::buildNoHierarchyCollection" 197 <<
"Alignable not in hierarchy, no need to remove it!";
206 for (
const auto &iAli : alis) {
211 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < paras->
size(); ++iParam) {
213 if (sel !=
'f' && sel !=
'F' && sel !=
'c' && sel !=
'C' && sel !=
'0' && sel !=
'1' && sel !=
'H' &&
214 sel !=
'r' && sel !=
's') {
216 <<
"[PedeSteerer::unknownParameterChoices] " 217 <<
"Unexpected parameter selector '" << sel
218 <<
"', use \n'f/F' (fix),\n'c/C' (fix at correct pos.),\n'1/H' (free),\n" 219 <<
"'r/s' (free, but defining reference system, trying to correct misalignment if 's')" 220 <<
" or \n'0' (ignore).\n" 221 <<
"Capital letters mean that the Alignable is taken out of a possible hierarchy,\n" 222 <<
"but must be used consistently for all its parameters.";
235 std::pair<unsigned int, unsigned int> numFixNumFixCor(0, 0);
237 std::ofstream *filePtr =
nullptr;
239 for (
const auto &iAli : alis) {
245 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
247 for (
unsigned int iInstance = 0; iInstance < nInstances; ++iInstance) {
250 ++(numFixNumFixCor.first);
251 }
else if (whichFix == -1) {
252 ++(numFixNumFixCor.second);
260 return numFixNumFixCor;
265 unsigned int iInstance,
268 std::ofstream *&filePtr,
272 if (selector ==
'c' || selector ==
'C') {
275 <<
"PedeSteerer::fixParameter: correction (c/C) possible only for RigidBodyParameters";
279 }
else if (selector ==
'f' || selector ==
'F') {
286 (*filePtr) <<
"Parameter\n";
288 std::ofstream &
file = *filePtr;
294 file <<
" * id " << ali->
id() <<
", eta " <<
position.eta() <<
", z " <<
position.z() <<
", r " 307 for (
const auto &iAli : alis) {
312 unsigned int refParam = 0;
313 unsigned int nonRefParam = 0;
314 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
316 if (selector ==
'r' || selector ==
's') {
318 }
else if (selector !=
'0' && selector !=
'f') {
326 <<
"[PedeSteerer::selectCoordinateAlis] All active parameters of alignables defining " 327 <<
"the coordinate system must be marked with 'r/s' (or fixed, 'f')!";
330 while ((mother = mother->mother())) {
331 if (mother->alignmentParameters()) {
332 throw cms::Exception(
"BadConfig") <<
"[PedeSteerer::selectCoordinateAlis] " 333 <<
"Alignables defining the coordinate system must " 334 <<
"be highest level!";
337 coordAlis.push_back(iAli);
348 (*filePtr) <<
"* Constraints to define coordinate system:\n";
350 throw cms::Exception(
"BadConfig") <<
"[PedeSteerer::defineCoordinates] " 351 <<
"No master alignable or it has parameters!";
354 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::defineCoordinates" 355 <<
"Ignore following LogicErrors from PedeLabeler.";
367 bool doCorrect =
false;
368 bool doNotCorrect =
false;
369 for (
const auto &it : coordDefiners) {
371 (it->alignmentParameters() ?
dynamic_cast<SelectionUserVariables *
>(it->alignmentParameters()->userVariables())
384 if (doCorrect && doNotCorrect) {
386 <<
"[PedeSteerer::doCorrectToRefSystem]: Parameter selection 's' and 'r' must not coexist!";
399 for (
const auto &it :
401 const auto &
comp = it->deepComponents();
402 definerDets.insert(definerDets.end(),
comp.begin(),
comp.end());
405 for (
unsigned int iLoop = 0;; ++iLoop) {
407 for (
const auto &it : definerDets) {
408 meanPars += RbPars(it,
true).globalParameters();
410 meanPars /= definerDets.size();
413 if (squareSum < 1.
e-20)
416 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem" 417 <<
"Loop " << iLoop <<
" " 418 <<
"Mean misalignment of dets of defined coordinate system" 419 << (squareSum < 1.e-20 ?
":" :
" (will be iteratively corrected to < 1.e-10):")
423 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem" 424 <<
"No convergence in " << iLoop <<
" iterations, " 425 <<
"remaining misalignment: " << meanPars;
432 globalAngles[0] = meanPars[RbPars::dalpha];
433 globalAngles[1] = meanPars[RbPars::dbeta];
434 globalAngles[2] = meanPars[RbPars::dgamma];
441 std::ofstream *filePtr =
nullptr;
443 unsigned int nConstraints = 0;
445 for (
const auto &iA : alis) {
447 if (!(iA->firstCompsWithParams(aliDaughts))) {
448 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraints" 449 <<
"Some but not all daughters of " 454 if (aliDaughts.empty())
476 std::ofstream &
file)
const {
479 std::vector<std::vector<ParameterId> > paramIdsVec;
480 std::vector<std::vector<double> > factorsVec;
481 const bool allConstr =
false;
482 static std::atomic<bool> allConstrWarning{
false};
483 bool expected{
false};
484 if (allConstr && allConstrWarning.compare_exchange_strong(expected,
true)) {
485 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 486 <<
"changed to use all 6 constraints";
490 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 491 <<
"Problems from store.";
494 for (
unsigned int iConstr = 0; iConstr < paramIdsVec.size(); ++iConstr) {
495 std::ostringstream aConstr;
497 const std::vector<ParameterId> &parIds = paramIdsVec[iConstr];
498 const std::vector<double> &factors = factorsVec[iConstr];
499 unsigned int nParPerConstr = 0;
501 for (
unsigned int iParam = 0; iParam < parIds.size(); ++iParam) {
502 Alignable *aliSubComp = parIds[iParam].first;
503 const unsigned int compParNum = parIds[iParam].second;
506 aConstr <<
"* Taken out of hierarchy: ";
513 aConstr << paramLabel <<
" " << std::setprecision(
theConstrPrecision) << factors[iParam];
515 aConstr << paramLabel <<
" " << factors[iParam];
517 aConstr <<
" ! for param " << compParNum <<
" of a " 532 file <<
"\nConstraint 0.\n" << aConstr.str();
533 }
else if (nParPerConstr > 0) {
534 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 535 <<
"Skip constraint on " << nParPerConstr <<
" parameter(s):\n" 554 for (std::vector<edm::ParameterSet>::const_iterator iSet = cffPresi.begin(), iE = cffPresi.end(); iSet != iE;
560 const float presigma = (*iSet).getParameter<
double>(
"presigma");
561 if (presigma <= 0.) {
562 throw cms::Exception(
"BadConfig") <<
"[PedeSteerer::presigmas]: Pre-sigma must be > 0., but is " << presigma
566 for (
unsigned int iAli = 0; iAli < alis.size(); ++iAli) {
567 std::vector<float> &
presigmas = aliPresiMap[alis[iAli]];
568 if (presigmas.size() < sels[iAli].size())
569 presigmas.resize(sels[iAli].size(), 0.);
570 for (
unsigned int iParam = 0; iParam < sels[iAli].size(); ++iParam) {
571 if (sels[iAli][iParam] !=
'0') {
572 if (presigmas[iParam] != 0.) {
574 <<
"[PedeSteerer::presigmas]: Try to set pre-sigma " << presigma <<
", but already " 575 <<
"set " << presigmas[iParam] <<
" (for a " 578 presigmas[iParam] = presigma;
584 if (aliPresiMap.empty())
596 std::ofstream *filePtr =
nullptr;
598 unsigned int nPresiParam = 0;
599 for (
const auto &iAli : alis) {
601 AlignablePresigmasMap::const_iterator presigmasIt = aliPresiMap.find(iAli);
602 if (presigmasIt == aliPresiMap.end())
607 const std::vector<float> &
presigmas = presigmasIt->second;
608 for (
unsigned int iParam = 0; iParam < presigmas.size(); ++iParam) {
610 if (presigmas[iParam] <= 0.)
613 if (!(iAli->alignmentParameters()->selector()[iParam]))
617 const char selChar = (selVar ? selVar->
fullSelection()[iParam] :
'1');
618 if (selChar ==
'f' || selChar ==
'F' || selChar ==
'c' || selChar ==
'C')
623 (*filePtr) <<
"* Presigma values for active parameters: \nParameter\n";
646 if (!result || !result->is_open()) {
648 throw cms::Exception(
"FileOpenProblem") <<
"[PedeSteerer::createSteerFile]" 649 <<
"Could not open " << realName <<
" as output file.";
650 }
else if (addToList) {
675 <<
" highest level objects define the " 676 <<
"coordinate system, steering file " << nameCoordFile <<
".";
680 const std::pair<unsigned int, unsigned int> nFixFixCor(this->
fixParameters(alis, nameFixFile));
681 if (nFixFixCor.first != 0 || nFixFixCor.second != 0) {
682 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" << nFixFixCor.first <<
" parameters fixed at 0. and " 683 << nFixFixCor.second <<
" at 'original' position, " 684 <<
"steering file " << nameFixFile <<
".";
689 <<
" alignables taken out of hierarchy.";
695 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 696 <<
"Hierarchy constraints for " << nConstraint <<
" alignables, " 697 <<
"steering file " << nameHierarchyFile <<
".";
711 auto &ConstraintsConfigContainer = GeometryConstraints.
getConfigData();
714 for (
auto &it : ConstraintsConfigContainer) {
716 for (
const auto &ilevelsFilename : it.levelsFilenames_) {
717 it.mapFileName_.insert(
718 std::make_pair(ilevelsFilename.second, this->createSteerFile(ilevelsFilename.second,
true)));
723 if (nGeometryConstraint) {
724 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 725 <<
"Geometry constraints for " << nGeometryConstraint <<
" alignables.";
737 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 738 <<
"Presigma values set for " << nPresigma <<
" parameters, " 739 <<
"steering file " << namePresigmaFile <<
".";
748 std::ofstream *mainSteerPtr = this->
createSteerFile(nameMasterSteer,
false);
753 std::vector<std::string> addfiles =
myConfig.
getParameter<std::vector<std::string> >(
"additionalSteerFiles");
757 std::ofstream &mainSteerRef = *mainSteerPtr;
758 for (
unsigned int iFile = 0; iFile <
mySteeringFiles.size(); ++iFile) {
763 mainSteerRef <<
"\nCfiles\n";
764 for (
unsigned int iFile = 0; iFile < binaryFiles.size(); ++iFile) {
765 mainSteerRef << binaryFiles[iFile] <<
"\n";
773 mainSteerRef <<
"\n* Outlier treatment and other options \n";
774 for (
unsigned int i = 0;
i < opt.size(); ++
i) {
775 mainSteerRef << opt[
i] <<
"\n";
780 return nameMasterSteer;
785 if (masterSteer.empty()) {
787 <<
"Empty master steer file, stop";
792 (command +=
" ") += masterSteer;
799 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::runPede" 800 <<
"Start running " <<
command;
802 int shellReturn = gSystem->Exec(command.c_str());
803 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::runPede" 804 <<
"Command returns " << shellReturn;
void correctToReferenceSystem()
std::set< const Alignable * > myNoHieraCollection
keeps track of created 'secondary' steering files
T getParameter(std::string const &) const
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
T getUntrackedParameter(std::string const &, T const &) const
const edm::ParameterSet myConfig
unsigned int constructConstraints(const align::Alignables &)
std::pair< unsigned int, unsigned int > fixParameters(const align::Alignables &, const std::string &file)
unsigned int presigmas(const std::vector< edm::ParameterSet > &cffPresi, const std::string &fileName, const align::Alignables &, AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras)
interprete content of presigma VPSet 'cffPresi' and call presigmasFile
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
std::pair< Alignable *, unsigned int > ParameterId
a single alignable parameter of an Alignable
PedeSteerer(AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras, AlignmentParameterStore *store, const PedeLabelerBase *labels, const edm::ParameterSet &config, const std::string &defaultDir, bool noSteerFiles)
Alignable * theCoordMaster
Alignables deselected for hierarchy constr.
unsigned int presigmasFile(const std::string &fileName, const align::Alignables &, const AlignablePresigmasMap &aliPresisMap)
look for active 'alis' in map of presigma values and create steering file
unsigned int hierarchyConstraints(const align::Alignables &, const std::string &file)
std::list< GeometryConstraintConfigData > & getConfigData()
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
align::Alignables selectCoordinateAlis(const align::Alignables &) const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
unsigned int theMinHieraParPerConstr
min absolute value of coefficients in hierarchy constraints
int fixParameter(Alignable *ali, unsigned int iRunRange, unsigned int iParam, char selector, std::ofstream *&filePtr, const std::string &fileName)
const AlgebraicVector & parameters(void) const
Get alignment parameters.
std::ofstream * createSteerFile(const std::string &name, bool addToList)
create and open file with name, if (addToList) append to mySteeringFiles
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
void clear()
remove all selected Alignables and geometrical restrictions
virtual void recenterSurface()
Recenter surface object without moving possible components.
const std::vector< char > & fullSelection() const
virtual unsigned int numberOfParameterInstances(Alignable *alignable, int param=-1) const =0
returns the number of instances for a given parameter
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
bool isCorrectToRefSystem(const align::Alignables &coordDefiners) const
bool hierarchyConstraints(const Alignable *aliMaster, const align::Alignables &aliComps, std::vector< std::vector< ParameterId > > ¶mIdsVecOut, std::vector< std::vector< double > > &factorsVecOut, bool all, double epsilon) const
const PedeLabelerBase * myLabels
not the owner!
int runPede(const std::string &masterSteer) const
run pede, masterSteer should be as returned from buildMasterSteer(...)
const AlignableObjectId alignableObjectId_
pointer to labeler (not the owner)
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
virtual void addComponent(Alignable *)=0
virtual unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const =0
std::string buildMasterSteer(const std::vector< std::string > &binaryFiles)
construct (and return name of) master steering file from config, binaryFiles etc. ...
int myParameterSign
whether or not to fill pede steering files with debug info
const align::Alignables & selectedAlignables() const
vector of alignables selected so far
double theMinHieraConstrCoeff
old pede versions (before May '07) need a sign flip...
unsigned int theConstrPrecision
hierarchy constraints with less params are ignored
const AlignmentParameterStore * myParameterStore
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
bool myNoSteerFiles
directory of all files
align::Alignables theCoordDefiners
master coordinates, must (?) be global frame
int size(void) const
Get number of parameters.
const char * idToString(align::StructureType type) const
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
void buildSubSteer(AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras)
construct steering files about hierarchy, fixing etc. an keep track of their names ...
virtual unsigned int alignableLabel(Alignable *alignable) const =0
void defineCoordinates(const align::Alignables &, Alignable *aliMaster, const std::string &fileName)
std::vector< std::string > mySteeringFiles
precision for writing constraints to text file
std::map< const Alignable *, std::vector< float > > AlignablePresigmasMap
double cmsToPedeFactor(unsigned int parNum) const
std::string fileName(const std::string &addendum) const
full name with directory and 'idenitfier'
bool isNoHiera(const Alignable *ali) const
True if 'ali' was deselected from hierarchy and any ancestor (e.g. mother) has parameters.
std::vector< Alignable * > Alignables
bool checkParameterChoices(const align::Alignables &) const
bool myIsSteerFileDebug
flag to write steering files to /dev/null
static int position[264][3]
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
unsigned int addSelections(const edm::ParameterSet &pSet)
const PositionType & globalPosition() const
Return the global position of the object.
const std::vector< std::vector< char > > & selectedParameters() const
vector of selection 'strings' for alignables, parallel to selectedAlignables()
void hierarchyConstraint(const Alignable *ali, const align::Alignables &components, std::ofstream &file) const
Constructor of the full muon geometry.
unsigned int buildNoHierarchyCollection(const align::Alignables &)
const align::Alignables & alignables(void) const
get all alignables
int parameterSign() const
results from pede (and start values for pede) might need a sign flip