19 #include <boost/cstdint.hpp>
58 myParameterStore(store), myLabels(labels), myConfig(config),
59 myDirectory(myConfig.getUntrackedParameter<std::
string>(
"fileDir")),
60 myNoSteerFiles(noSteerFiles),
61 myIsSteerFileDebug(myConfig.getUntrackedParameter<bool>(
"steerFileDebug")),
62 myParameterSign(myConfig.getUntrackedParameter<int>(
"parameterSign")),
63 theMinHieraConstrCoeff(myConfig.getParameter<double>(
"minHieraConstrCoeff")),
64 theMinHieraParPerConstr(myConfig.getParameter<unsigned int>(
"minHieraParPerConstr")),
68 cms::Exception(
"BadConfig") <<
"Expect PedeSteerer.parameterSign = +/-1, "
103 <<
"[PedeSteerer]" <<
"Cannot define global coordinate system "
104 <<
"with neither tracker nor muon!";
109 for ( std::vector<Alignable*>::iterator it = allExtras.begin(); it != allExtras.end(); ++it ) {
163 for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
166 if (!selVar)
continue;
168 unsigned int numNoHieraPar = 0;
169 unsigned int numHieraPar = 0;
170 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
172 if (selector ==
'C' || selector ==
'F' || selector ==
'H') {
174 }
else if (selector ==
'c' || selector ==
'f' || selector ==
'1' || selector ==
'r'
175 || selector ==
's') {
182 <<
"[PedeSteerer::buildNoHierarchyCollection] All active parameters of alignables to be "
183 <<
" taken out of the hierarchy must be marked with capital letters 'C', 'F' or 'H'!";
185 bool isInHiera =
false;
187 while ((mother = mother->
mother())) {
192 else edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::buildNoHierarchyCollection"
193 <<
"Alignable not in hierarchy, no need to remove it!";
203 for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
206 if (!selVar)
continue;
207 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < paras->
size(); ++iParam) {
209 if (sel !=
'f' && sel !=
'F' && sel !=
'c' && sel !=
'C' &&
210 sel !=
'0' && sel !=
'1' && sel !=
'H' && sel !=
'r' && sel !=
's') {
212 <<
"[PedeSteerer::unknownParameterChoices] "
213 <<
"Unexpected parameter selector '" << sel
214 <<
"', use \n'f/F' (fix),\n'c/C' (fix at correct pos.),\n'1/H' (free),\n"
215 <<
"'r/s' (free, but defining reference system, trying to correct misalignment if 's')"
216 <<
" or \n'0' (ignore).\n"
217 <<
"Capital letters mean that the Alignable is taken out of a possible hierarchy,\n"
218 <<
"but must be used consistently for all its parameters.";
228 std::pair<unsigned int, unsigned int>
232 std::pair<unsigned int, unsigned int> numFixNumFixCor(0, 0);
234 std::ofstream *filePtr = 0;
236 for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
240 if (!selVar)
continue;
242 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
244 for (
unsigned int iInstance=0;iInstance<nInstances;++iInstance) {
245 int whichFix = this->
fixParameter(*iAli, iInstance, iParam,
249 ++(numFixNumFixCor.first);
250 }
else if (whichFix == -1) {
251 ++(numFixNumFixCor.second);
259 return numFixNumFixCor;
264 unsigned int iParam,
char selector,
269 if (selector ==
'c' || selector ==
'C') {
272 <<
"PedeSteerer::fixParameter: correction (c/C) possible only for RigidBodyParameters";
276 }
else if (selector ==
'f' || selector ==
'F') {
283 (*filePtr) <<
"Parameter\n";
285 std::ofstream &
file = *filePtr;
304 std::vector<Alignable*> coordAlis;
306 for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
309 if (!selVar)
continue;
310 unsigned int refParam = 0;
311 unsigned int nonRefParam = 0;
312 for (
unsigned int iParam = 0;
static_cast<int>(iParam) < params->
size(); ++iParam) {
314 if (selector ==
'r' || selector ==
's') {
316 }
else if (selector !=
'0' && selector !=
'f') {
324 <<
"[PedeSteerer::selectCoordinateAlis] All active parameters of alignables defining "
325 <<
"the coordinate system must be marked with 'r/s' (or fixed, 'f')!";
328 while ((mother = mother->
mother())) {
330 throw cms::Exception(
"BadConfig") <<
"[PedeSteerer::selectCoordinateAlis] "
331 <<
"Alignables defining the coordinate system must "
332 <<
"be highest level!";
335 coordAlis.push_back(*iAli);
349 (*filePtr) <<
"* Constraints to define coordinate system:\n";
352 <<
"[PedeSteerer::defineCoordinates] " <<
"No master alignable or it has parameters!";
355 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::defineCoordinates"
356 <<
"Ignore following LogicErrors from PedeLabeler.";
369 bool doCorrect =
false;
370 bool doNotCorrect =
false;
371 for (std::vector<Alignable*>::const_iterator it = coordDefiners.begin(), iE=coordDefiners.end();
374 ((*it)->alignmentParameters() ?
376 if (!selVar)
continue;
384 if (doCorrect && doNotCorrect) {
386 <<
"[PedeSteerer::doCorrectToRefSystem]: Parameter selection 's' and 'r' must not coexist!";
398 std::vector<Alignable*> definerDets;
401 const std::vector<Alignable*> &
comp = (*it)->deepComponents();
402 definerDets.insert(definerDets.end(), comp.begin(), comp.end());
405 for (
unsigned int iLoop = 0; ; ++iLoop) {
407 for (std::vector<Alignable*>::iterator it = definerDets.begin(), iE = definerDets.end();
409 meanPars += RbPars(*it,
true).globalParameters();
411 meanPars /= definerDets.size();
414 if (squareSum < 1.
e-20)
break;
416 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem"
417 <<
"Loop " << iLoop <<
" "
418 <<
"Mean misalignment of dets of defined coordinate system"
419 << (squareSum < 1.e-20 ?
":" :
420 " (will be iteratively corrected to < 1.e-10):") << meanPars;
423 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::correctToReferenceSystem"
424 <<
"No convergence in " << iLoop <<
" iterations, "
425 <<
"remaining misalignment: " << meanPars;
429 const GlobalVector globalShift(meanPars[RbPars::dx],meanPars[RbPars::dy],meanPars[RbPars::dz]);
432 globalAngles[0] = meanPars[RbPars::dalpha];
433 globalAngles[1] = meanPars[RbPars::dbeta];
434 globalAngles[2] = meanPars[RbPars::dgamma];
444 std::ofstream *filePtr = 0;
446 unsigned int nConstraints = 0;
447 std::vector<Alignable*> aliDaughts;
448 for (std::vector<Alignable*>::const_iterator iA = alis.begin(), iEnd = alis.end();
451 if (!(*iA)->firstCompsWithParams(aliDaughts)) {
452 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraints"
453 <<
"Some but not all daughters of "
459 if (aliDaughts.empty())
continue;
479 std::ofstream &
file)
const
483 std::vector<std::vector<ParameterId> > paramIdsVec;
484 std::vector<std::vector<double> > factorsVec;
485 const bool allConstr =
false;
486 static bool first =
true;
487 if (allConstr && first) {
488 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint"
489 <<
"changed to use all 6 constraints";
494 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint"
495 <<
"Problems from store.";
498 for (
unsigned int iConstr = 0; iConstr < paramIdsVec.size(); ++iConstr) {
499 std::ostringstream aConstr;
501 const std::vector<ParameterId> &parIds = paramIdsVec[iConstr];
502 const std::vector<double> &factors = factorsVec[iConstr];
503 unsigned int nParPerConstr = 0;
505 for (
unsigned int iParam = 0; iParam < parIds.size(); ++iParam) {
506 Alignable *aliSubComp = parIds[iParam].first;
507 const unsigned int compParNum = parIds[iParam].second;
515 aConstr << paramLabel <<
" " << factors[iParam];
517 aConstr <<
" ! for param " << compParNum <<
" of a "
528 file <<
"\n* Nr. " << iConstr <<
" of a '"
534 file <<
"\nConstraint 0.\n" << aConstr.str();
535 }
else if (nParPerConstr > 0) {
536 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteerer::hierarchyConstraint"
537 <<
"Skip constraint on " << nParPerConstr
538 <<
" parameter(s):\n" << aConstr.str();
546 const std::vector<Alignable*> &alis,
555 for (std::vector<edm::ParameterSet>::const_iterator iSet = cffPresi.begin(), iE = cffPresi.end();
556 iSet != iE; ++iSet) {
561 const float presigma = (*iSet).getParameter<
double>(
"presigma");
562 if (presigma <= 0.) {
564 <<
"[PedeSteerer::presigmas]: Pre-sigma must be > 0., but is " << presigma <<
".";
567 for (
unsigned int iAli = 0; iAli < alis.size(); ++iAli) {
568 std::vector<float> &
presigmas = aliPresiMap[alis[iAli]];
569 if (presigmas.size() < sels[iAli].size()) 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())
return 0;
585 else return this->
presigmasFile(fileName, alis, aliPresiMap);
590 const std::vector<Alignable*> &alis,
595 std::ofstream *filePtr = 0;
597 unsigned int nPresiParam = 0;
598 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(), iAliE = alis.end();
599 iAli != iAliE; ++iAli) {
601 AlignablePresigmasMap::const_iterator presigmasIt = aliPresiMap.find(*iAli);
602 if (presigmasIt == aliPresiMap.end())
continue;
606 const std::vector<float> &
presigmas = presigmasIt->second;
607 for (
unsigned int iParam = 0; iParam < presigmas.size(); ++iParam) {
609 if (presigmas[iParam] <= 0.)
continue;
611 if (!(*iAli)->alignmentParameters()->selector()[iParam])
continue;
614 const char selChar = (selVar ? selVar->
fullSelection()[iParam] :
'1');
615 if (selChar ==
'f' || selChar ==
'F' || selChar ==
'c' || selChar ==
'C')
continue;
619 (*filePtr) <<
"* Presigma values for active parameters: \nParameter\n";
643 if (!result || !result->is_open()) {
645 throw cms::Exception(
"FileOpenProblem") <<
"[PedeSteerer::createSteerFile]"
646 <<
"Could not open " << realName
647 <<
" as output file.";
648 }
else if (addToList) {
676 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer"
678 <<
"coordinate system, steering file " << nameCoordFile <<
".";
682 const std::pair<unsigned int, unsigned int> nFixFixCor(this->
fixParameters(alis, nameFixFile));
683 if (nFixFixCor.first != 0 || nFixFixCor.second != 0) {
684 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer"
685 << nFixFixCor.first <<
" parameters fixed at 0. and "
686 << nFixFixCor.second <<
" at 'original' position, "
687 <<
"steering file " << nameFixFile <<
".";
691 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer"
698 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer"
699 <<
"Hierarchy constraints for " << nConstraint <<
" alignables, "
700 <<
"steering file " << nameHierarchyFile <<
".";
713 std::list<GeometryConstraintConfigData>* ConstraintsConfigContainer = GeometryConstraints.
getConfigData();
716 for(std::list<GeometryConstraintConfigData>::iterator it = ConstraintsConfigContainer->begin();
717 it != ConstraintsConfigContainer->end(); it++) {
719 for(std::vector<std::pair<Alignable*, std::string> >::const_iterator ilevelsFilename = it->levelsFilenames_.begin();
720 ilevelsFilename != it->levelsFilenames_.end(); ilevelsFilename++) {
721 it->mapFileName_.insert(
722 std::pair<std::string, std::ofstream*>
723 (ilevelsFilename->second,this->createSteerFile(ilevelsFilename->second,
true))
730 if (nGeometryConstraint) {
731 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer"
732 <<
"Geometry constraints for " << nGeometryConstraint <<
" alignables.";
737 unsigned int nPresigma =
739 namePresigmaFile, alis, aliTracker, aliMuon, aliExtras);
741 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteerer::buildSubSteer"
742 <<
"Presigma values set for " << nPresigma <<
" parameters, "
743 <<
"steering file " << namePresigmaFile <<
".";
753 std::ofstream *mainSteerPtr = this->
createSteerFile(nameMasterSteer,
false);
754 if (!mainSteerPtr)
return "";
757 std::vector<std::string> addfiles =
myConfig.
getParameter<std::vector<std::string> >(
"additionalSteerFiles");
763 std::ofstream &mainSteerRef = *mainSteerPtr;
764 for (
unsigned int iFile = 0; iFile <
mySteeringFiles.size(); ++iFile) {
769 mainSteerRef <<
"\nCfiles\n";
770 for (
unsigned int iFile = 0; iFile < binaryFiles.size(); ++iFile) {
771 mainSteerRef << binaryFiles[iFile] <<
"\n";
778 const std::vector<std::string> opt(
myConfig.
getParameter<std::vector<std::string> >(
"options"));
779 mainSteerRef <<
"\n* Outlier treatment and other options \n";
780 for (
unsigned int i = 0;
i < opt.size(); ++
i) {
781 mainSteerRef << opt[
i] <<
"\n";
786 return nameMasterSteer;
792 if (masterSteer.empty()) {
793 edm::LogError(
"Alignment") <<
"@SUB=PedeSteerer::runPede" <<
"Empty master steer file, stop";
798 (command +=
" ") += masterSteer;
807 int shellReturn = gSystem->Exec(command.c_str());
808 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
bool checkParameterChoices(const std::vector< Alignable * > &alis) const
std::vector< Alignable * > theCoordDefiners
master coordinates, must (?) be global frame
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
virtual unsigned int alignableLabel(Alignable *alignable) const =0
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
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
edm::ParameterSet myConfig
pointer to labeler (not the owner)
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.
static int position[TOTALCHAMBERS][3]
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
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
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
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
virtual void addComponent(Alignable *)=0
std::string buildMasterSteer(const std::vector< std::string > &binaryFiles)
construct (and return name of) master steering file from config, binaryFiles etc. ...
virtual unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const =0
std::list< GeometryConstraintConfigData > * getConfigData()
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...
const AlignmentParameterStore * myParameterStore
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
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.
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 ...
std::vector< std::string > mySteeringFiles
hierarchy constraints with less params are ignored
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
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()
static const char * idToString(align::StructureType type)
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
virtual unsigned int numberOfParameterInstances(Alignable *alignable, int param=-1) const =0
returns the number of instances for a given parameter
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