19 #include <boost/cstdint.hpp> 57 myParameterStore(store), myLabels(labels),
70 cms::Exception(
"BadConfig") <<
"Expect PedeSteerer.parameterSign = +/-1, " 101 }
else if (aliMuon) {
105 <<
"[PedeSteerer]" <<
"Cannot define global coordinate system " 106 <<
"with neither tracker nor muon!";
111 for ( std::vector<Alignable*>::iterator it = allExtras.begin(); it != allExtras.end(); ++it ) {
165 for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
168 if (!selVar)
continue;
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' 177 || selector ==
's') {
184 <<
"[PedeSteerer::buildNoHierarchyCollection] All active parameters of alignables to be " 185 <<
" taken out of the hierarchy must be marked with capital letters 'C', 'F' or 'H'!";
187 bool isInHiera =
false;
189 while ((mother = mother->
mother())) {
194 else edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::buildNoHierarchyCollection" 195 <<
"Alignable not in hierarchy, no need to remove it!";
205 for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
208 if (!selVar)
continue;
209 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < paras->
size(); ++iParam) {
211 if (sel !=
'f' && sel !=
'F' && sel !=
'c' && sel !=
'C' &&
212 sel !=
'0' && sel !=
'1' && sel !=
'H' && sel !=
'r' && sel !=
's') {
214 <<
"[PedeSteerer::unknownParameterChoices] " 215 <<
"Unexpected parameter selector '" << sel
216 <<
"', use \n'f/F' (fix),\n'c/C' (fix at correct pos.),\n'1/H' (free),\n" 217 <<
"'r/s' (free, but defining reference system, trying to correct misalignment if 's')" 218 <<
" or \n'0' (ignore).\n" 219 <<
"Capital letters mean that the Alignable is taken out of a possible hierarchy,\n" 220 <<
"but must be used consistently for all its parameters.";
230 std::pair<unsigned int, unsigned int>
234 std::pair<unsigned int, unsigned int> numFixNumFixCor(0, 0);
236 std::ofstream *filePtr = 0;
238 for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
242 if (!selVar)
continue;
244 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
246 for (
unsigned int iInstance=0;iInstance<nInstances;++iInstance) {
247 int whichFix = this->
fixParameter(*iAli, iInstance, iParam,
251 ++(numFixNumFixCor.first);
252 }
else if (whichFix == -1) {
253 ++(numFixNumFixCor.second);
261 return numFixNumFixCor;
266 unsigned int iParam,
char selector,
271 if (selector ==
'c' || selector ==
'C') {
274 <<
"PedeSteerer::fixParameter: correction (c/C) possible only for RigidBodyParameters";
278 }
else if (selector ==
'f' || selector ==
'F') {
285 (*filePtr) <<
"Parameter\n";
287 std::ofstream &
file = *filePtr;
306 std::vector<Alignable*> coordAlis;
308 for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
311 if (!selVar)
continue;
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())) {
332 throw cms::Exception(
"BadConfig") <<
"[PedeSteerer::selectCoordinateAlis] " 333 <<
"Alignables defining the coordinate system must " 334 <<
"be highest level!";
337 coordAlis.push_back(*iAli);
351 (*filePtr) <<
"* Constraints to define coordinate system:\n";
354 <<
"[PedeSteerer::defineCoordinates] " <<
"No master alignable or it has parameters!";
357 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::defineCoordinates" 358 <<
"Ignore following LogicErrors from PedeLabeler.";
371 bool doCorrect =
false;
372 bool doNotCorrect =
false;
373 for (std::vector<Alignable*>::const_iterator it = coordDefiners.begin(), iE=coordDefiners.end();
376 ((*it)->alignmentParameters() ?
378 if (!selVar)
continue;
386 if (doCorrect && doNotCorrect) {
388 <<
"[PedeSteerer::doCorrectToRefSystem]: Parameter selection 's' and 'r' must not coexist!";
400 std::vector<Alignable*> definerDets;
403 const std::vector<Alignable*> &
comp = (*it)->deepComponents();
404 definerDets.insert(definerDets.end(), comp.begin(), comp.end());
407 for (
unsigned int iLoop = 0; ; ++iLoop) {
409 for (std::vector<Alignable*>::iterator it = definerDets.begin(), iE = definerDets.end();
411 meanPars += RbPars(*it,
true).globalParameters();
413 meanPars /= definerDets.size();
416 if (squareSum < 1.
e-20)
break;
418 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem" 419 <<
"Loop " << iLoop <<
" " 420 <<
"Mean misalignment of dets of defined coordinate system" 421 << (squareSum < 1.e-20 ?
":" :
422 " (will be iteratively corrected to < 1.e-10):") << meanPars;
425 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem" 426 <<
"No convergence in " << iLoop <<
" iterations, " 427 <<
"remaining misalignment: " << meanPars;
434 globalAngles[0] = meanPars[RbPars::dalpha];
435 globalAngles[1] = meanPars[RbPars::dbeta];
436 globalAngles[2] = meanPars[RbPars::dgamma];
446 std::ofstream *filePtr = 0;
448 unsigned int nConstraints = 0;
449 std::vector<Alignable*> aliDaughts;
450 for (std::vector<Alignable*>::const_iterator iA = alis.begin(), iEnd = alis.end();
453 if (!(*iA)->firstCompsWithParams(aliDaughts)) {
454 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraints" 455 <<
"Some but not all daughters of " 461 if (aliDaughts.empty())
continue;
481 std::ofstream &
file)
const 485 std::vector<std::vector<ParameterId> > paramIdsVec;
486 std::vector<std::vector<double> > factorsVec;
487 const bool allConstr =
false;
488 static bool first =
true;
489 if (allConstr && first) {
490 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 491 <<
"changed to use all 6 constraints";
496 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 497 <<
"Problems from store.";
500 for (
unsigned int iConstr = 0; iConstr < paramIdsVec.size(); ++iConstr) {
501 std::ostringstream aConstr;
503 const std::vector<ParameterId> &parIds = paramIdsVec[iConstr];
504 const std::vector<double> &factors = factorsVec[iConstr];
505 unsigned int nParPerConstr = 0;
507 for (
unsigned int iParam = 0; iParam < parIds.size(); ++iParam) {
508 Alignable *aliSubComp = parIds[iParam].first;
509 const unsigned int compParNum = parIds[iParam].second;
518 aConstr << paramLabel <<
" " << std::setprecision(
theConstrPrecision) << factors[iParam];
520 aConstr << paramLabel <<
" " << factors[iParam];
522 aConstr <<
" ! for param " << compParNum <<
" of a " 533 file <<
"\n* Nr. " << iConstr <<
" of a '" 539 file <<
"\nConstraint 0.\n" << aConstr.str();
540 }
else if (nParPerConstr > 0) {
541 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint" 542 <<
"Skip constraint on " << nParPerConstr
543 <<
" parameter(s):\n" << aConstr.str();
551 const std::vector<Alignable*> &alis,
560 for (std::vector<edm::ParameterSet>::const_iterator iSet = cffPresi.begin(), iE = cffPresi.end();
561 iSet != iE; ++iSet) {
566 const float presigma = (*iSet).getParameter<
double>(
"presigma");
567 if (presigma <= 0.) {
569 <<
"[PedeSteerer::presigmas]: Pre-sigma must be > 0., but is " << presigma <<
".";
572 for (
unsigned int iAli = 0; iAli < alis.size(); ++iAli) {
573 std::vector<float> &
presigmas = aliPresiMap[alis[iAli]];
574 if (presigmas.size() < sels[iAli].size()) presigmas.resize(sels[iAli].size(), 0.);
575 for (
unsigned int iParam = 0; iParam < sels[iAli].size(); ++iParam) {
576 if (sels[iAli][iParam] !=
'0') {
577 if (presigmas[iParam] != 0.) {
579 <<
"[PedeSteerer::presigmas]: Try to set pre-sigma " << presigma <<
", but already " 580 <<
"set " << presigmas[iParam] <<
" (for a " 583 presigmas[iParam] = presigma;
589 if (aliPresiMap.empty())
return 0;
590 else return this->
presigmasFile(fileName, alis, aliPresiMap);
595 const std::vector<Alignable*> &alis,
600 std::ofstream *filePtr = 0;
602 unsigned int nPresiParam = 0;
603 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(), iAliE = alis.end();
604 iAli != iAliE; ++iAli) {
606 AlignablePresigmasMap::const_iterator presigmasIt = aliPresiMap.find(*iAli);
607 if (presigmasIt == aliPresiMap.end())
continue;
611 const std::vector<float> &
presigmas = presigmasIt->second;
612 for (
unsigned int iParam = 0; iParam < presigmas.size(); ++iParam) {
614 if (presigmas[iParam] <= 0.)
continue;
616 if (!(*iAli)->alignmentParameters()->selector()[iParam])
continue;
619 const char selChar = (selVar ? selVar->
fullSelection()[iParam] :
'1');
620 if (selChar ==
'f' || selChar ==
'F' || selChar ==
'c' || selChar ==
'C')
continue;
624 (*filePtr) <<
"* Presigma values for active parameters: \nParameter\n";
648 if (!result || !result->is_open()) {
650 throw cms::Exception(
"FileOpenProblem") <<
"[PedeSteerer::createSteerFile]" 651 <<
"Could not open " << realName
652 <<
" as output file.";
653 }
else if (addToList) {
681 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 683 <<
"coordinate system, steering file " << nameCoordFile <<
".";
687 const std::pair<unsigned int, unsigned int> nFixFixCor(this->
fixParameters(alis, nameFixFile));
688 if (nFixFixCor.first != 0 || nFixFixCor.second != 0) {
689 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 690 << nFixFixCor.first <<
" parameters fixed at 0. and " 691 << nFixFixCor.second <<
" at 'original' position, " 692 <<
"steering file " << nameFixFile <<
".";
696 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 703 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 704 <<
"Hierarchy constraints for " << nConstraint <<
" alignables, " 705 <<
"steering file " << nameHierarchyFile <<
".";
718 auto& ConstraintsConfigContainer = GeometryConstraints.
getConfigData();
721 for(
auto& it: ConstraintsConfigContainer) {
723 for(
const auto& ilevelsFilename: it.levelsFilenames_) {
724 it.mapFileName_.insert(std::make_pair
725 (ilevelsFilename.second,this->createSteerFile(ilevelsFilename.second,
true))
731 if (nGeometryConstraint) {
732 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 733 <<
"Geometry constraints for " << nGeometryConstraint <<
" alignables.";
738 unsigned int nPresigma =
740 namePresigmaFile, alis, aliTracker, aliMuon, aliExtras);
742 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer" 743 <<
"Presigma values set for " << nPresigma <<
" parameters, " 744 <<
"steering file " << namePresigmaFile <<
".";
754 std::ofstream *mainSteerPtr = this->
createSteerFile(nameMasterSteer,
false);
755 if (!mainSteerPtr)
return "";
758 std::vector<std::string> addfiles =
myConfig.
getParameter<std::vector<std::string> >(
"additionalSteerFiles");
764 std::ofstream &mainSteerRef = *mainSteerPtr;
765 for (
unsigned int iFile = 0; iFile <
mySteeringFiles.size(); ++iFile) {
770 mainSteerRef <<
"\nCfiles\n";
771 for (
unsigned int iFile = 0; iFile < binaryFiles.size(); ++iFile) {
772 mainSteerRef << binaryFiles[iFile] <<
"\n";
779 const std::vector<std::string> opt(
myConfig.
getParameter<std::vector<std::string> >(
"options"));
780 mainSteerRef <<
"\n* Outlier treatment and other options \n";
781 for (
unsigned int i = 0;
i < opt.size(); ++
i) {
782 mainSteerRef << opt[
i] <<
"\n";
787 return nameMasterSteer;
793 if (masterSteer.empty()) {
794 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::runPede" <<
"Empty master steer file, stop";
799 (command +=
" ") += masterSteer;
808 int shellReturn = gSystem->Exec(command.c_str());
809 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
bool checkParameterChoices(const std::vector< Alignable * > &alis) const
std::vector< Alignable * > theCoordDefiners
master coordinates, must (?) be global frame
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
void move(const GlobalVector &displacement)
unsigned int presigmasFile(const std::string &fileName, const std::vector< Alignable * > &alis, const AlignablePresigmasMap &aliPresisMap)
look for active 'alis' in map of presigma values and create steering file
std::list< GeometryConstraintConfigData > & getConfigData()
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
std::set< const Alignable * > myNoHieraCollection
keeps track of created 'secondary' steering files
bool isCorrectToRefSystem(const std::vector< Alignable * > &coordDefiners) const
unsigned int hierarchyConstraints(const std::vector< Alignable * > &alis, const std::string &file)
unsigned int constructConstraints(const std::vector< Alignable * > &alis)
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
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 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(...)
unsigned int presigmas(const std::vector< edm::ParameterSet > &cffPresi, const std::string &fileName, const std::vector< Alignable * > &alis, AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras)
interprete content of presigma VPSet 'cffPresi' and call presigmasFile
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 AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
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
std::pair< unsigned int, unsigned int > fixParameters(const std::vector< Alignable * > &alignables, const std::string &file)
bool myNoSteerFiles
directory of all files
void hierarchyConstraint(const Alignable *ali, const std::vector< Alignable * > &components, std::ofstream &file) const
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
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
unsigned int buildNoHierarchyCollection(const std::vector< Alignable * > &alis)
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)
std::vector< Alignable * > selectCoordinateAlis(const std::vector< Alignable * > &alignables) const
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()
Constructor of the full muon geometry.
Alignable * mother() const
Return pointer to container alignable (if any)
const align::Alignables & alignables(void) const
get all alignables
void defineCoordinates(const std::vector< Alignable * > &alis, Alignable *aliMaster, const std::string &fileName)
int parameterSign() const
results from pede (and start values for pede) might need a sign flip