61 : myParameterStore(store),
65 myDirectory(myConfig.getUntrackedParameter<
std::string>(
"fileDir")),
66 myRunDirectory(myConfig.getUntrackedParameter<
std::string>(
"runDir")),
67 myNoSteerFiles(noSteerFiles),
68 myIsSteerFileDebug(myConfig.getUntrackedParameter<
bool>(
"steerFileDebug")),
69 myParameterSign(myConfig.getUntrackedParameter<
int>(
"parameterSign")),
70 theMinHieraConstrCoeff(myConfig.getParameter<
double>(
"minHieraConstrCoeff")),
71 theMinHieraParPerConstr(myConfig.getParameter<
unsigned int>(
"minHieraParPerConstr")),
72 theConstrPrecision(myConfig.getParameter<
unsigned int>(
"constrPrecision")),
73 theCoordMaster(
nullptr) {
74 if (myParameterSign != 1 && myParameterSign != -1) {
75 cms::Exception(
"BadConfig") <<
"Expect PedeSteerer.parameterSign = +/-1, " 76 <<
"found " << myParameterSign <<
".";
80 if (myDirectory.empty())
81 myDirectory = defaultDir;
82 if (!myDirectory.empty() && myDirectory.find_last_of(
'/') != myDirectory.size() - 1) {
86 if (myRunDirectory.empty())
87 myRunDirectory = defaultDir;
88 if (!myRunDirectory.empty() && myRunDirectory.find_last_of(
'/') != myRunDirectory.size() - 1) {
89 myRunDirectory +=
'/';
90 myDirectory = myRunDirectory;
93 const auto &alis = myParameterStore->alignables();
94 if (!this->checkParameterChoices(alis)) {
98 theCoordDefiners = this->selectCoordinateAlis(alis);
99 if (!theCoordDefiners.empty()) {
115 }
else if (aliMuon) {
119 <<
"Cannot define global coordinate system " 120 <<
"with neither tracker nor muon!";
123 theCoordMaster->addComponent(aliMuon);
126 for (
const auto &it : allExtras)
127 theCoordMaster->addComponent(it);
130 theCoordMaster->recenterSurface();
132 if (this->isCorrectToRefSystem(theCoordDefiners)) {
133 this->correctToReferenceSystem();
172 for (
const auto &iAli : alis) {
178 unsigned int numNoHieraPar = 0;
179 unsigned int numHieraPar = 0;
180 for (
unsigned int iParam = 0;
static_cast<int>(iParam) <
params->size(); ++iParam) {
182 if (selector ==
'C' || selector ==
'F' || selector ==
'H') {
184 }
else if (selector ==
'c' || selector ==
'f' || selector ==
'1' || selector ==
'r' || selector ==
's') {
191 <<
"[PedeSteerer::buildNoHierarchyCollection] All active parameters of alignables to be " 192 <<
" taken out of the hierarchy must be marked with capital letters 'C', 'F' or 'H'!";
194 bool isInHiera =
false;
196 while ((mother = mother->mother())) {
197 if (mother->alignmentParameters())
204 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::buildNoHierarchyCollection" 205 <<
"Alignable not in hierarchy, no need to remove it!";
214 for (
const auto &iAli : alis) {
219 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < paras->
size(); ++iParam) {
221 if (
sel !=
'f' &&
sel !=
'F' &&
sel !=
'c' &&
sel !=
'C' &&
sel !=
'0' &&
sel !=
'1' &&
sel !=
'H' &&
222 sel !=
'r' &&
sel !=
's') {
224 <<
"[PedeSteerer::unknownParameterChoices] " 225 <<
"Unexpected parameter selector '" <<
sel 226 <<
"', use \n'f/F' (fix),\n'c/C' (fix at correct pos.),\n'1/H' (free),\n" 227 <<
"'r/s' (free, but defining reference system, trying to correct misalignment if 's')" 228 <<
" or \n'0' (ignore).\n" 229 <<
"Capital letters mean that the Alignable is taken out of a possible hierarchy,\n" 230 <<
"but must be used consistently for all its parameters.";
243 std::pair<unsigned int, unsigned int> numFixNumFixCor(0, 0);
245 std::ofstream *filePtr =
nullptr;
247 for (
const auto &iAli : alis) {
253 for (
unsigned int iParam = 0;
static_cast<int>(iParam) <
params->size(); ++iParam) {
255 for (
unsigned int iInstance = 0; iInstance < nInstances; ++iInstance) {
258 ++(numFixNumFixCor.first);
259 }
else if (whichFix == -1) {
260 ++(numFixNumFixCor.second);
268 return numFixNumFixCor;
273 unsigned int iInstance,
276 std::ofstream *&filePtr,
280 if (selector ==
'c' || selector ==
'C') {
283 <<
"PedeSteerer::fixParameter: correction (c/C) possible only for RigidBodyParameters";
287 }
else if (selector ==
'f' || selector ==
'F') {
294 (*filePtr) <<
"Parameter\n";
296 std::ofstream &
file = *filePtr;
315 for (
const auto &iAli : alis) {
320 unsigned int refParam = 0;
321 unsigned int nonRefParam = 0;
322 for (
unsigned int iParam = 0;
static_cast<int>(iParam) <
params->size(); ++iParam) {
324 if (selector ==
'r' || selector ==
's') {
326 }
else if (selector !=
'0' && selector !=
'f') {
334 <<
"[PedeSteerer::selectCoordinateAlis] All active parameters of alignables defining " 335 <<
"the coordinate system must be marked with 'r/s' (or fixed, 'f')!";
338 while ((mother = mother->mother())) {
339 if (mother->alignmentParameters()) {
340 throw cms::Exception(
"BadConfig") <<
"[PedeSteerer::selectCoordinateAlis] " 341 <<
"Alignables defining the coordinate system must " 342 <<
"be highest level!";
345 coordAlis.push_back(iAli);
356 (*filePtr) <<
"* Constraints to define coordinate system:\n";
358 throw cms::Exception(
"BadConfig") <<
"[PedeSteerer::defineCoordinates] " 359 <<
"No master alignable or it has parameters!";
362 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::defineCoordinates" 363 <<
"Ignore following LogicErrors from PedeLabeler.";
375 bool doCorrect =
false;
376 bool doNotCorrect =
false;
377 for (
const auto &it : coordDefiners) {
379 (it->alignmentParameters() ?
dynamic_cast<SelectionUserVariables *
>(it->alignmentParameters()->userVariables())
392 if (doCorrect && doNotCorrect) {
394 <<
"[PedeSteerer::doCorrectToRefSystem]: Parameter selection 's' and 'r' must not coexist!";
407 for (
const auto &it :
409 const auto &
comp = it->deepComponents();
410 definerDets.insert(definerDets.end(),
comp.begin(),
comp.end());
413 for (
unsigned int iLoop = 0;; ++iLoop) {
415 for (
const auto &it : definerDets) {
416 meanPars += RbPars(it,
true).globalParameters();
418 meanPars /= definerDets.size();
421 if (squareSum < 1.
e-20)
424 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem" 425 <<
"Loop " << iLoop <<
" " 426 <<
"Mean misalignment of dets of defined coordinate system" 427 << (squareSum < 1.e-20 ?
":" :
" (will be iteratively corrected to < 1.e-10):")
431 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem" 432 <<
"No convergence in " << iLoop <<
" iterations, " 433 <<
"remaining misalignment: " << meanPars;
440 globalAngles[0] = meanPars[RbPars::dalpha];
441 globalAngles[1] = meanPars[RbPars::dbeta];
442 globalAngles[2] = meanPars[RbPars::dgamma];
449 std::ofstream *filePtr =
nullptr;
451 unsigned int nConstraints = 0;
453 for (
const auto &iA : alis) {
455 if (!(iA->firstCompsWithParams(aliDaughts))) {
456 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraints" 457 <<
"Some but not all daughters of " 462 if (aliDaughts.empty())
484 std::ofstream &
file)
const {
487 std::vector<std::vector<ParameterId> > paramIdsVec;
488 std::vector<std::vector<double> > factorsVec;
489 const bool allConstr =
false;
490 static std::atomic<bool> allConstrWarning{
false};
491 bool expected{
false};
492 if (allConstr && allConstrWarning.compare_exchange_strong(expected,
true)) {
493 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 494 <<
"changed to use all 6 constraints";
498 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 499 <<
"Problems from store.";
502 for (
unsigned int iConstr = 0; iConstr < paramIdsVec.size(); ++iConstr) {
503 std::ostringstream aConstr;
505 const std::vector<ParameterId> &parIds = paramIdsVec[iConstr];
506 const std::vector<double> &factors = factorsVec[iConstr];
507 unsigned int nParPerConstr = 0;
509 for (
unsigned int iParam = 0; iParam < parIds.size(); ++iParam) {
510 Alignable *aliSubComp = parIds[iParam].first;
511 const unsigned int compParNum = parIds[iParam].second;
514 aConstr <<
"* Taken out of hierarchy: ";
523 aConstr <<
paramLabel <<
" " << factors[iParam];
525 aConstr <<
" ! for param " << compParNum <<
" of a " 540 file <<
"\nConstraint 0.\n" << aConstr.str();
541 }
else if (nParPerConstr > 0) {
542 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 543 <<
"Skip constraint on " << nParPerConstr <<
" parameter(s):\n" 562 for (std::vector<edm::ParameterSet>::const_iterator iSet = cffPresi.begin(), iE = cffPresi.end(); iSet != iE;
568 const float presigma = (*iSet).getParameter<
double>(
"presigma");
569 if (presigma <= 0.) {
570 throw cms::Exception(
"BadConfig") <<
"[PedeSteerer::presigmas]: Pre-sigma must be > 0., but is " << presigma
574 for (
unsigned int iAli = 0; iAli < alis.size(); ++iAli) {
575 std::vector<float> &
presigmas = aliPresiMap[alis[iAli]];
578 for (
unsigned int iParam = 0; iParam <
sels[iAli].size(); ++iParam) {
579 if (
sels[iAli][iParam] !=
'0') {
582 <<
"[PedeSteerer::presigmas]: Try to set pre-sigma " << presigma <<
", but already " 583 <<
"set " <<
presigmas[iParam] <<
" (for a " 592 if (aliPresiMap.empty())
604 std::ofstream *filePtr =
nullptr;
606 unsigned int nPresiParam = 0;
607 for (
const auto &iAli : alis) {
609 AlignablePresigmasMap::const_iterator presigmasIt = aliPresiMap.find(iAli);
610 if (presigmasIt == aliPresiMap.end())
615 const std::vector<float> &
presigmas = presigmasIt->second;
616 for (
unsigned int iParam = 0; iParam <
presigmas.size(); ++iParam) {
621 if (!(iAli->alignmentParameters()->selector()[iParam]))
625 const char selChar = (selVar ? selVar->
fullSelection()[iParam] :
'1');
626 if (selChar ==
'f' || selChar ==
'F' || selChar ==
'c' || selChar ==
'C')
631 (*filePtr) <<
"* Presigma values for active parameters: \nParameter\n";
656 throw cms::Exception(
"FileOpenProblem") <<
"[PedeSteerer::createSteerFile]" 657 <<
"Could not open " << realName <<
" as output file.";
658 }
else if (addToList) {
683 <<
" highest level objects define the " 684 <<
"coordinate system, steering file " << nameCoordFile <<
".";
688 const std::pair<unsigned int, unsigned int> nFixFixCor(this->
fixParameters(alis, nameFixFile));
689 if (nFixFixCor.first != 0 || nFixFixCor.second != 0) {
690 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" << nFixFixCor.first <<
" parameters fixed at 0. and " 691 << nFixFixCor.second <<
" at 'original' position, " 692 <<
"steering file " << nameFixFile <<
".";
697 <<
" alignables taken out of hierarchy.";
703 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 704 <<
"Hierarchy constraints for " << nConstraint <<
" alignables, " 705 <<
"steering file " << nameHierarchyFile <<
".";
719 auto &ConstraintsConfigContainer = GeometryConstraints.
getConfigData();
722 for (
auto &it : ConstraintsConfigContainer) {
724 for (
const auto &ilevelsFilename : it.levelsFilenames_) {
725 it.mapFileName_.insert(
726 std::make_pair(ilevelsFilename.second, this->createSteerFile(ilevelsFilename.second,
true)));
731 if (nGeometryConstraint) {
732 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 733 <<
"Geometry constraints for " << nGeometryConstraint <<
" alignables.";
745 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 746 <<
"Presigma values set for " << nPresigma <<
" parameters, " 747 <<
"steering file " << namePresigmaFile <<
".";
756 std::ofstream *mainSteerPtr = this->
createSteerFile(nameMasterSteer,
false);
761 std::vector<std::string> addfiles =
myConfig.
getParameter<std::vector<std::string> >(
"additionalSteerFiles");
765 std::ofstream &mainSteerRef = *mainSteerPtr;
766 for (
unsigned int iFile = 0; iFile <
mySteeringFiles.size(); ++iFile) {
771 mainSteerRef <<
"\nCfiles\n";
772 for (
unsigned int iFile = 0; iFile < binaryFiles.size(); ++iFile) {
774 mainSteerRef << binaryFiles[iFile] <<
"\n";
776 mainSteerRef <<
"../" + binaryFiles[iFile] <<
"\n";
784 mainSteerRef <<
"\n* Outlier treatment and other options \n";
785 for (
unsigned int i = 0;
i <
opt.size(); ++
i) {
786 mainSteerRef <<
opt[
i] <<
"\n";
791 return nameMasterSteer;
796 if (masterSteer.empty()) {
798 <<
"Empty master steer file, stop";
806 (
command +=
" ") += masterSteer;
810 (
command +=
" ") +=
"../" + masterSteer;
820 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::runPede" 821 <<
"Start running " <<
command;
823 int shellReturn = gSystem->Exec(
command.c_str());
824 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::runPede" 825 <<
"Command returns " << shellReturn;
bool isCorrectToRefSystem(const align::Alignables &coordDefiners) const
void correctToReferenceSystem()
std::set< const Alignable * > myNoHieraCollection
keeps track of created 'secondary' steering files
std::string fileName(const std::string &addendum) const
full name with directory and 'idenitfier'
const edm::ParameterSet myConfig
T getParameter(std::string const &) const
unsigned int constructConstraints(const align::Alignables &)
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
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 align::Alignables & selectedAlignables() const
vector of alignables selected so far
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
const std::vector< char > & fullSelection() const
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
const AlgebraicVector & parameters(void) const
Get alignment parameters.
void hierarchyConstraint(const Alignable *ali, const align::Alignables &components, std::ofstream &file) const
unsigned int hierarchyConstraints(const align::Alignables &, const std::string &file)
const align::Alignables & alignables(void) const
get all alignables
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
const std::vector< std::vector< char > > & selectedParameters() const
vector of selection 'strings' for alignables, parallel to selectedAlignables()
Log< level::Error, false > LogError
unsigned int theMinHieraParPerConstr
min absolute value of coefficients in hierarchy constraints
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
T getUntrackedParameter(std::string const &, T const &) const
int fixParameter(Alignable *ali, unsigned int iRunRange, unsigned int iParam, char selector, std::ofstream *&filePtr, const std::string &fileName)
std::ofstream * createSteerFile(const std::string &name, bool addToList)
create and open file with name, if (addToList) append to mySteeringFiles
int parameterSign() const
results from pede (and start values for pede) might need a sign flip
void clear()
remove all selected Alignables and geometrical restrictions
const PositionType & globalPosition() const
Return the global position of the object.
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
int runPede(const std::string &masterSteer) const
run pede, masterSteer should be as returned from buildMasterSteer(...)
bool checkParameterChoices(const align::Alignables &) const
const PedeLabelerBase * myLabels
not the owner!
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
const AlignableObjectId alignableObjectId_
pointer to labeler (not the owner)
int size(void) const
Get number of parameters.
std::string myRunDirectory
directory of all files
std::string buildMasterSteer(const std::vector< std::string > &binaryFiles)
construct (and return name of) master steering file from config, binaryFiles etc. ...
Log< level::Info, false > LogInfo
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
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
AlgebraicVector EulerAngles
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
bool myNoSteerFiles
directory where pede is executed
align::Alignables theCoordDefiners
master coordinates, must (?) be global frame
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 ...
const char * idToString(align::StructureType type) const
virtual unsigned int alignableLabelFromParamAndInstance(const Alignable *alignable, unsigned int param, unsigned int instance) const =0
void defineCoordinates(const align::Alignables &, Alignable *aliMaster, const std::string &fileName)
virtual unsigned int alignableLabel(const Alignable *alignable) const =0
std::vector< std::string > mySteeringFiles
precision for writing constraints to text file
std::map< const Alignable *, std::vector< float > > AlignablePresigmasMap
std::vector< Alignable * > Alignables
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)
bool isNoHiera(const Alignable *ali) const
True if 'ali' was deselected from hierarchy and any ancestor (e.g. mother) has parameters.
Log< level::Warning, false > LogWarning
Constructor of the full muon geometry.
unsigned int buildNoHierarchyCollection(const align::Alignables &)
void addComponent(Alignable *component) final
virtual unsigned int numberOfParameterInstances(Alignable *alignable, int param=-1) const =0
returns the number of instances for a given parameter
double cmsToPedeFactor(unsigned int parNum) const