19 #include <boost/cstdint.hpp> 58 myParameterStore(store), myLabels(labels),
71 cms::Exception(
"BadConfig") <<
"Expect PedeSteerer.parameterSign = +/-1, " 102 }
else if (aliMuon) {
106 <<
"[PedeSteerer]" <<
"Cannot define global coordinate system " 107 <<
"with neither tracker nor muon!";
162 for (
const auto& iAli: alis) {
165 if (!selVar)
continue;
167 unsigned int numNoHieraPar = 0;
168 unsigned int numHieraPar = 0;
169 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
171 if (selector ==
'C' || selector ==
'F' || selector ==
'H') {
173 }
else if (selector ==
'c' || selector ==
'f' || selector ==
'1' || selector ==
'r' 174 || selector ==
's') {
181 <<
"[PedeSteerer::buildNoHierarchyCollection] All active parameters of alignables to be " 182 <<
" taken out of the hierarchy must be marked with capital letters 'C', 'F' or 'H'!";
184 bool isInHiera =
false;
186 while ((mother = mother->mother())) {
187 if (mother->alignmentParameters()) isInHiera =
true;
191 else edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::buildNoHierarchyCollection" 192 <<
"Alignable not in hierarchy, no need to remove it!";
202 for (
const auto& iAli: alis) {
205 if (!selVar)
continue;
206 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < paras->
size(); ++iParam) {
208 if (sel !=
'f' && sel !=
'F' && sel !=
'c' && sel !=
'C' &&
209 sel !=
'0' && sel !=
'1' && sel !=
'H' && sel !=
'r' && sel !=
's') {
211 <<
"[PedeSteerer::unknownParameterChoices] " 212 <<
"Unexpected parameter selector '" << sel
213 <<
"', use \n'f/F' (fix),\n'c/C' (fix at correct pos.),\n'1/H' (free),\n" 214 <<
"'r/s' (free, but defining reference system, trying to correct misalignment if 's')" 215 <<
" or \n'0' (ignore).\n" 216 <<
"Capital letters mean that the Alignable is taken out of a possible hierarchy,\n" 217 <<
"but must be used consistently for all its parameters.";
227 std::pair<unsigned int, unsigned int>
231 std::pair<unsigned int, unsigned int> numFixNumFixCor(0, 0);
233 std::ofstream *filePtr =
nullptr;
235 for (
const auto& iAli: alis) {
239 if (!selVar)
continue;
241 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
243 for (
unsigned int iInstance=0;iInstance<nInstances;++iInstance) {
244 int whichFix = this->
fixParameter(iAli, iInstance, iParam,
248 ++(numFixNumFixCor.first);
249 }
else if (whichFix == -1) {
250 ++(numFixNumFixCor.second);
258 return numFixNumFixCor;
263 unsigned int iParam,
char selector,
268 if (selector ==
'c' || selector ==
'C') {
271 <<
"PedeSteerer::fixParameter: correction (c/C) possible only for RigidBodyParameters";
275 }
else if (selector ==
'f' || selector ==
'F') {
282 (*filePtr) <<
"Parameter\n";
284 std::ofstream &
file = *filePtr;
305 for (
const auto& iAli: alis) {
308 if (!selVar)
continue;
309 unsigned int refParam = 0;
310 unsigned int nonRefParam = 0;
311 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
313 if (selector ==
'r' || selector ==
's') {
315 }
else if (selector !=
'0' && selector !=
'f') {
323 <<
"[PedeSteerer::selectCoordinateAlis] All active parameters of alignables defining " 324 <<
"the coordinate system must be marked with 'r/s' (or fixed, 'f')!";
327 while ((mother = mother->mother())) {
328 if (mother->alignmentParameters()) {
329 throw cms::Exception(
"BadConfig") <<
"[PedeSteerer::selectCoordinateAlis] " 330 <<
"Alignables defining the coordinate system must " 331 <<
"be highest level!";
334 coordAlis.push_back(iAli);
348 (*filePtr) <<
"* Constraints to define coordinate system:\n";
351 <<
"[PedeSteerer::defineCoordinates] " <<
"No master alignable or it has parameters!";
354 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::defineCoordinates" 355 <<
"Ignore following LogicErrors from PedeLabeler.";
368 bool doCorrect =
false;
369 bool doNotCorrect =
false;
370 for (
const auto& it: coordDefiners) {
372 (it->alignmentParameters() ?
374 if (!selVar)
continue;
382 if (doCorrect && doNotCorrect) {
384 <<
"[PedeSteerer::doCorrectToRefSystem]: Parameter selection 's' and 'r' must not coexist!";
398 const auto&
comp = it->deepComponents();
399 definerDets.insert(definerDets.end(),
comp.begin(),
comp.end());
402 for (
unsigned int iLoop = 0; ; ++iLoop) {
404 for (
const auto& it: definerDets) {
405 meanPars += RbPars(it,
true).globalParameters();
407 meanPars /= definerDets.size();
410 if (squareSum < 1.
e-20)
break;
412 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem" 413 <<
"Loop " << iLoop <<
" " 414 <<
"Mean misalignment of dets of defined coordinate system" 415 << (squareSum < 1.e-20 ?
":" :
416 " (will be iteratively corrected to < 1.e-10):") << meanPars;
419 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem" 420 <<
"No convergence in " << iLoop <<
" iterations, " 421 <<
"remaining misalignment: " << meanPars;
428 globalAngles[0] = meanPars[RbPars::dalpha];
429 globalAngles[1] = meanPars[RbPars::dbeta];
430 globalAngles[2] = meanPars[RbPars::dgamma];
440 std::ofstream *filePtr =
nullptr;
442 unsigned int nConstraints = 0;
444 for (
const auto& iA: alis) {
446 if (!(iA->firstCompsWithParams(aliDaughts))) {
447 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraints" 448 <<
"Some but not all daughters of " 454 if (aliDaughts.empty())
continue;
474 std::ofstream &
file)
const 478 std::vector<std::vector<ParameterId> > paramIdsVec;
479 std::vector<std::vector<double> > factorsVec;
480 const bool allConstr =
false;
481 static std::atomic<bool> allConstrWarning{
false};
482 bool expected{
false};
483 if (allConstr && allConstrWarning.compare_exchange_strong(expected,
true)) {
484 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 485 <<
"changed to use all 6 constraints";
489 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 490 <<
"Problems from store.";
493 for (
unsigned int iConstr = 0; iConstr < paramIdsVec.size(); ++iConstr) {
494 std::ostringstream aConstr;
496 const std::vector<ParameterId> &parIds = paramIdsVec[iConstr];
497 const std::vector<double> &factors = factorsVec[iConstr];
498 unsigned int nParPerConstr = 0;
500 for (
unsigned int iParam = 0; iParam < parIds.size(); ++iParam) {
501 Alignable *aliSubComp = parIds[iParam].first;
502 const unsigned int compParNum = parIds[iParam].second;
511 aConstr << paramLabel <<
" " << std::setprecision(
theConstrPrecision) << factors[iParam];
513 aConstr << paramLabel <<
" " << factors[iParam];
515 aConstr <<
" ! for param " << compParNum <<
" of a " 526 file <<
"\n* Nr. " << iConstr <<
" 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
536 <<
" parameter(s):\n" << aConstr.str();
553 for (std::vector<edm::ParameterSet>::const_iterator iSet = cffPresi.begin(), iE = cffPresi.end();
554 iSet != iE; ++iSet) {
559 const float presigma = (*iSet).getParameter<
double>(
"presigma");
560 if (presigma <= 0.) {
562 <<
"[PedeSteerer::presigmas]: Pre-sigma must be > 0., but is " << presigma <<
".";
565 for (
unsigned int iAli = 0; iAli < alis.size(); ++iAli) {
566 std::vector<float> &
presigmas = aliPresiMap[alis[iAli]];
567 if (presigmas.size() < sels[iAli].size()) presigmas.resize(sels[iAli].size(), 0.);
568 for (
unsigned int iParam = 0; iParam < sels[iAli].size(); ++iParam) {
569 if (sels[iAli][iParam] !=
'0') {
570 if (presigmas[iParam] != 0.) {
572 <<
"[PedeSteerer::presigmas]: Try to set pre-sigma " << presigma <<
", but already " 573 <<
"set " << presigmas[iParam] <<
" (for a " 576 presigmas[iParam] = presigma;
582 if (aliPresiMap.empty())
return 0;
583 else return this->
presigmasFile(fileName, alis, aliPresiMap);
593 std::ofstream *filePtr =
nullptr;
595 unsigned int nPresiParam = 0;
596 for (
const auto& iAli: alis) {
598 AlignablePresigmasMap::const_iterator presigmasIt = aliPresiMap.find(iAli);
599 if (presigmasIt == aliPresiMap.end())
continue;
603 const std::vector<float> &
presigmas = presigmasIt->second;
604 for (
unsigned int iParam = 0; iParam < presigmas.size(); ++iParam) {
606 if (presigmas[iParam] <= 0.)
continue;
608 if (!(iAli->alignmentParameters()->selector()[iParam]))
continue;
611 const char selChar = (selVar ? selVar->
fullSelection()[iParam] :
'1');
612 if (selChar ==
'f' || selChar ==
'F' || selChar ==
'c' || selChar ==
'C')
continue;
616 (*filePtr) <<
"* Presigma values for active parameters: \nParameter\n";
640 if (!result || !result->is_open()) {
642 throw cms::Exception(
"FileOpenProblem") <<
"[PedeSteerer::createSteerFile]" 643 <<
"Could not open " << realName
644 <<
" as output file.";
645 }
else if (addToList) {
673 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 675 <<
"coordinate system, steering file " << nameCoordFile <<
".";
679 const std::pair<unsigned int, unsigned int> nFixFixCor(this->
fixParameters(alis, nameFixFile));
680 if (nFixFixCor.first != 0 || nFixFixCor.second != 0) {
681 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 682 << nFixFixCor.first <<
" parameters fixed at 0. and " 683 << nFixFixCor.second <<
" at 'original' position, " 684 <<
"steering file " << nameFixFile <<
".";
688 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 695 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 696 <<
"Hierarchy constraints for " << nConstraint <<
" alignables, " 697 <<
"steering file " << nameHierarchyFile <<
".";
710 auto& ConstraintsConfigContainer = GeometryConstraints.
getConfigData();
713 for(
auto& it: ConstraintsConfigContainer) {
715 for(
const auto& ilevelsFilename: it.levelsFilenames_) {
716 it.mapFileName_.insert(std::make_pair
717 (ilevelsFilename.second,this->createSteerFile(ilevelsFilename.second,
true))
723 if (nGeometryConstraint) {
724 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 725 <<
"Geometry constraints for " << nGeometryConstraint <<
" alignables.";
730 unsigned int nPresigma =
732 namePresigmaFile, alis, aliTracker, aliMuon, aliExtras);
734 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 735 <<
"Presigma values set for " << nPresigma <<
" parameters, " 736 <<
"steering file " << namePresigmaFile <<
".";
746 std::ofstream *mainSteerPtr = this->
createSteerFile(nameMasterSteer,
false);
747 if (!mainSteerPtr)
return "";
750 std::vector<std::string> addfiles =
myConfig.
getParameter<std::vector<std::string> >(
"additionalSteerFiles");
756 std::ofstream &mainSteerRef = *mainSteerPtr;
757 for (
unsigned int iFile = 0; iFile <
mySteeringFiles.size(); ++iFile) {
762 mainSteerRef <<
"\nCfiles\n";
763 for (
unsigned int iFile = 0; iFile < binaryFiles.size(); ++iFile) {
764 mainSteerRef << binaryFiles[iFile] <<
"\n";
771 const std::vector<std::string> opt(
myConfig.
getParameter<std::vector<std::string> >(
"options"));
772 mainSteerRef <<
"\n* Outlier treatment and other options \n";
773 for (
unsigned int i = 0;
i < opt.size(); ++
i) {
774 mainSteerRef << opt[
i] <<
"\n";
779 return nameMasterSteer;
785 if (masterSteer.empty()) {
786 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::runPede" <<
"Empty master steer file, stop";
791 (command +=
" ") += masterSteer;
800 int shellReturn = gSystem->Exec(command.c_str());
801 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::runPede" <<
"Command returns " << shellReturn;
void correctToReferenceSystem()
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.
std::map< const Alignable *, std::vector< float > > AlignablePresigmasMap
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
std::set< const Alignable * > myNoHieraCollection
keeps track of created 'secondary' steering files
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
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