CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
PedeSteerer Class Reference

#include <PedeSteerer.h>

Public Member Functions

std::string buildMasterSteer (const std::vector< std::string > &binaryFiles)
 construct (and return name of) master steering file from config, binaryFiles etc. More...
 
void buildSubSteer (AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras)
 construct steering files about hierarchy, fixing etc. an keep track of their names More...
 
double cmsToPedeFactor (unsigned int parNum) const
 
void correctToReferenceSystem ()
 
const std::string & directory () const
 directory from constructor input, '/' is attached if needed More...
 
bool isCorrectToRefSystem (const std::vector< Alignable * > &coordDefiners) const
 
bool isNoHiera (const Alignable *ali) const
 True if 'ali' was deselected from hierarchy and any ancestor (e.g. mother) has parameters. More...
 
int parameterSign () const
 results from pede (and start values for pede) might need a sign flip More...
 
 PedeSteerer (AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras, AlignmentParameterStore *store, const PedeLabelerBase *labels, const edm::ParameterSet &config, const std::string &defaultDir, bool noSteerFiles)
 
int runPede (const std::string &masterSteer) const
 run pede, masterSteer should be as returned from buildMasterSteer(...) More...
 
 ~PedeSteerer ()
 

Private Types

typedef std::map< const Alignable *, std::vector< float > > AlignablePresigmasMap
 

Private Member Functions

unsigned int buildNoHierarchyCollection (const std::vector< Alignable * > &alis)
 
bool checkParameterChoices (const std::vector< Alignable * > &alis) const
 
std::ofstream * createSteerFile (const std::string &name, bool addToList)
 create and open file with name, if (addToList) append to mySteeringFiles More...
 
void defineCoordinates (const std::vector< Alignable * > &alis, Alignable *aliMaster, const std::string &fileName)
 
std::string fileName (const std::string &addendum) const
 full name with directory and 'idenitfier' More...
 
int fixParameter (Alignable *ali, unsigned int iRunRange, unsigned int iParam, char selector, std::ofstream *&filePtr, const std::string &fileName)
 
std::pair< unsigned int, unsigned int > fixParameters (const std::vector< Alignable * > &alignables, const std::string &file)
 
void hierarchyConstraint (const Alignable *ali, const std::vector< Alignable * > &components, std::ofstream &file) const
 
unsigned int hierarchyConstraints (const std::vector< Alignable * > &alis, const std::string &file)
 
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 More...
 
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 More...
 
std::vector< Alignable * > selectCoordinateAlis (const std::vector< Alignable * > &alignables) const
 

Private Attributes

const AlignableObjectId alignableObjectId_
 pointer to labeler (not the owner) More...
 
const edm::ParameterSet myConfig
 
std::string myDirectory
 
bool myIsSteerFileDebug
 flag to write steering files to /dev/null More...
 
const PedeLabelerBasemyLabels
 not the owner! More...
 
std::set< const Alignable * > myNoHieraCollection
 keeps track of created 'secondary' steering files More...
 
bool myNoSteerFiles
 directory of all files More...
 
int myParameterSign
 whether or not to fill pede steering files with debug info More...
 
const AlignmentParameterStoremyParameterStore
 
std::vector< std::string > mySteeringFiles
 precision for writing constraints to text file More...
 
unsigned int theConstrPrecision
 hierarchy constraints with less params are ignored More...
 
std::vector< Alignable * > theCoordDefiners
 master coordinates, must (?) be global frame More...
 
AlignabletheCoordMaster
 Alignables deselected for hierarchy constr. More...
 
double theMinHieraConstrCoeff
 old pede versions (before May '07) need a sign flip... More...
 
unsigned int theMinHieraParPerConstr
 min absolute value of coefficients in hierarchy constraints More...
 

Detailed Description

provides steering for pede according to configuration

Author
: Gero Flucke date : October 2006
Date
2013/06/18 13:31:29
Revision
1.29

(last update by

Author
jbehr

)

Definition at line 36 of file PedeSteerer.h.

Member Typedef Documentation

typedef std::map<const Alignable*,std::vector<float> > PedeSteerer::AlignablePresigmasMap
private

Definition at line 70 of file PedeSteerer.h.

Constructor & Destructor Documentation

PedeSteerer::PedeSteerer ( AlignableTracker aliTracker,
AlignableMuon aliMuon,
AlignableExtras aliExtras,
AlignmentParameterStore store,
const PedeLabelerBase labels,
const edm::ParameterSet config,
const std::string &  defaultDir,
bool  noSteerFiles 
)

constructor from AlignableTracker/AlignableMuon, their AlignmentParameterStore and the labeler (NOTE: The latter two must live longer than the constructed PedeSteerer!)

Definition at line 54 of file PedeSteerer.cc.

References Alignable::addComponent(), AlignmentParameterStore::alignables(), checkParameterChoices(), AlignableObjectId::commonObjectIdProvider(), correctToReferenceSystem(), Exception, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), Alignable::globalPosition(), align::invalid, isCorrectToRefSystem(), GloballyPositioned< T >::move(), myConfig, myDirectory, myIsSteerFileDebug, myNoSteerFiles, myParameterSign, myParameterStore, selectCoordinateAlis(), AlCaHLTBitMon_QueryRunRegistry::string, Alignable::surface(), theConstrPrecision, theCoordDefiners, theCoordMaster, theMinHieraConstrCoeff, theMinHieraParPerConstr, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

57  :
58  myParameterStore(store), myLabels(labels),
60  myConfig(config),
62  myNoSteerFiles(noSteerFiles),
63  myIsSteerFileDebug(myConfig.getUntrackedParameter<bool>("steerFileDebug")),
64  myParameterSign(myConfig.getUntrackedParameter<int>("parameterSign")),
65  theMinHieraConstrCoeff(myConfig.getParameter<double>("minHieraConstrCoeff")),
66  theMinHieraParPerConstr(myConfig.getParameter<unsigned int>("minHieraParPerConstr")),
67  theConstrPrecision(myConfig.getParameter<unsigned int>("constrPrecision")),
68  theCoordMaster(nullptr)
69 {
70  if (myParameterSign != 1 && myParameterSign != -1) {
71  cms::Exception("BadConfig") << "Expect PedeSteerer.parameterSign = +/-1, "
72  << "found " << myParameterSign << ".";
73  }
74 
75  // Correct directory, needed before asking for fileName(..):
76  if (myDirectory.empty()) myDirectory = defaultDir;
77  if (!myDirectory.empty() && myDirectory.find_last_of('/') != myDirectory.size() - 1) {
78  myDirectory += '/'; // directory may need '/'
79  }
80 
81  const std::vector<Alignable*> &alis = myParameterStore->alignables();
82  if (!this->checkParameterChoices(alis)) {} // anyway thrown exception
83 
84  // Coordinate system selection and correction before everything
86  if (!theCoordDefiners.empty()) { // Create steering with constraints to define coordinate system:
87  // OK, some hacks:
88  // - we want a composite with global coordinates where tracker and muon are components
89  // (to call RigidBodyAl.Param.->globalParameters() in correctToReferenceSystem(..))
90  // - so we create a AlignableComposite and add tracker and muon
91  // - but the addComponent(..) method is so cute that it calculates position from
92  // daughters' deepComponents()
93  // - so we want to move it back to (0,0,0), but ali->move(..) would move daughters as well
94  // => cheat with a const_cast and move only the surface back
95  // - this hacked master object does not have a label for its parameters
96  // => some warnings if debug output selected in pedeSteer files
97  // - we must not delete our new master (little mem. leak...) since that would delete
98  // the daughters as well!
99  if (aliTracker) {
100  theCoordMaster = new AlignableComposite(aliTracker->id(), align::invalid);
101  theCoordMaster->addComponent(aliTracker);
102  } else if (aliMuon) {
104  } else {
105  throw cms::Exception("BadConfig")
106  << "[PedeSteerer]" << "Cannot define global coordinate system "
107  << "with neither tracker nor muon!";
108  }
109  if (aliMuon) theCoordMaster->addComponent(aliMuon); // tracker is already added if existing
110  if (aliExtras) { // tracker and/or muon are already added if existing
111  align::Alignables allExtras = aliExtras->components();
112  for ( std::vector<Alignable*>::iterator it = allExtras.begin(); it != allExtras.end(); ++it ) {
114  }
115  }
116 
118  AlignableSurface & masterSurf = const_cast<AlignableSurface&>(theCoordMaster->surface());
119  masterSurf.move(align::GlobalVector(-tmpPos.x(),-tmpPos.y(),-tmpPos.z()));
120 
121  if (this->isCorrectToRefSystem(theCoordDefiners)) { // defined by 's' (MC): 'correct' misalignment
122  this->correctToReferenceSystem(); // really before 'defineCoordinates'?
123  }
124  }
125 
126 }
void correctToReferenceSystem()
Definition: PedeSteerer.cc:396
T getParameter(std::string const &) const
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:189
T getUntrackedParameter(std::string const &, T const &) const
const edm::ParameterSet myConfig
Definition: PedeSteerer.h:120
bool checkParameterChoices(const std::vector< Alignable * > &alis) const
Definition: PedeSteerer.cc:204
std::vector< Alignable * > theCoordDefiners
master coordinates, must (?) be global frame
Definition: PedeSteerer.h:133
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
Alignable * theCoordMaster
Alignables deselected for hierarchy constr.
Definition: PedeSteerer.h:132
T y() const
Definition: PV3DBase.h:63
void move(const GlobalVector &displacement)
std::string myDirectory
Definition: PedeSteerer.h:121
bool isCorrectToRefSystem(const std::vector< Alignable * > &coordDefiners) const
Definition: PedeSteerer.cc:370
unsigned int theMinHieraParPerConstr
min absolute value of coefficients in hierarchy constraints
Definition: PedeSteerer.h:126
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:117
T z() const
Definition: PV3DBase.h:64
const AlignableObjectId alignableObjectId_
pointer to labeler (not the owner)
Definition: PedeSteerer.h:118
virtual void addComponent(Alignable *)=0
int myParameterSign
whether or not to fill pede steering files with debug info
Definition: PedeSteerer.h:124
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:135
Alignables components() const
double theMinHieraConstrCoeff
old pede versions (before May &#39;07) need a sign flip...
Definition: PedeSteerer.h:125
unsigned int theConstrPrecision
hierarchy constraints with less params are ignored
Definition: PedeSteerer.h:127
const AlignmentParameterStore * myParameterStore
Definition: PedeSteerer.h:116
bool myNoSteerFiles
directory of all files
Definition: PedeSteerer.h:122
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
bool myIsSteerFileDebug
flag to write steering files to /dev/null
Definition: PedeSteerer.h:123
std::vector< Alignable * > selectCoordinateAlis(const std::vector< Alignable * > &alignables) const
Definition: PedeSteerer.cc:305
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:138
T x() const
Definition: PV3DBase.h:62
const align::Alignables & alignables(void) const
get all alignables
PedeSteerer::~PedeSteerer ( )

non-virtual destructor: do not inherit from this class

Definition at line 129 of file PedeSteerer.cc.

130 {
131  // delete theCoordMaster; NO, see above
132 }

Member Function Documentation

std::string PedeSteerer::buildMasterSteer ( const std::vector< std::string > &  binaryFiles)

construct (and return name of) master steering file from config, binaryFiles etc.

Definition at line 752 of file PedeSteerer.cc.

References createSteerFile(), fileName(), edm::ParameterSet::getParameter(), mps_fire::i, myConfig, mySteeringFiles, and AlCaHLTBitMon_QueryRunRegistry::string.

753 {
754  const std::string nameMasterSteer(this->fileName("Master"));
755  std::ofstream *mainSteerPtr = this->createSteerFile(nameMasterSteer, false);
756  if (!mainSteerPtr) return "";
757 
758  // add external steering files, if any
759  std::vector<std::string> addfiles = myConfig.getParameter<std::vector<std::string> >("additionalSteerFiles");
760  mySteeringFiles.insert(mySteeringFiles.end(),
761  addfiles.begin(),
762  addfiles.end());
763 
764  // add steering files to master steering file
765  std::ofstream &mainSteerRef = *mainSteerPtr;
766  for (unsigned int iFile = 0; iFile < mySteeringFiles.size(); ++iFile) {
767  mainSteerRef << mySteeringFiles[iFile] << "\n";
768  }
769 
770  // add binary files to master steering file
771  mainSteerRef << "\nCfiles\n";
772  for (unsigned int iFile = 0; iFile < binaryFiles.size(); ++iFile) {
773  mainSteerRef << binaryFiles[iFile] << "\n";
774  }
775 
776  // add method
777  mainSteerRef << "\nmethod " << myConfig.getParameter<std::string>("method") << "\n";
778 
779  // add further options
780  const std::vector<std::string> opt(myConfig.getParameter<std::vector<std::string> >("options"));
781  mainSteerRef << "\n* Outlier treatment and other options \n";
782  for (unsigned int i = 0; i < opt.size(); ++i) {
783  mainSteerRef << opt[i] << "\n";
784  }
785 
786  delete mainSteerPtr; // close (and flush) again
787 
788  return nameMasterSteer;
789 }
T getParameter(std::string const &) const
const edm::ParameterSet myConfig
Definition: PedeSteerer.h:120
std::ofstream * createSteerFile(const std::string &name, bool addToList)
create and open file with name, if (addToList) append to mySteeringFiles
Definition: PedeSteerer.cc:644
std::vector< std::string > mySteeringFiles
precision for writing constraints to text file
Definition: PedeSteerer.h:129
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:663
unsigned int PedeSteerer::buildNoHierarchyCollection ( const std::vector< Alignable * > &  alis)
private

Store Alignables that have SelectionUserVariables attached to their AlignmentParameters (these must exist) that indicate removal from hierarchy, i.e. make it 'top level'.

Definition at line 162 of file PedeSteerer.cc.

References Alignable::alignmentParameters(), Exception, SelectionUserVariables::fullSelection(), Alignable::mother(), myNoHieraCollection, AlignmentParameters::size(), and AlignmentParameters::userVariables().

Referenced by buildSubSteer().

163 {
164  myNoHieraCollection.clear(); // just in case of re-use...
165 
166  for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
167  AlignmentParameters *params = (*iAli)->alignmentParameters();
168  SelectionUserVariables *selVar = dynamic_cast<SelectionUserVariables*>(params->userVariables());
169  if (!selVar) continue;
170  // Now check whether taking out of hierarchy is selected - must be consistent!
171  unsigned int numNoHieraPar = 0;
172  unsigned int numHieraPar = 0;
173  for (unsigned int iParam = 0; static_cast<int>(iParam) < params->size(); ++iParam) {
174  const char selector = selVar->fullSelection()[iParam];
175  if (selector == 'C' || selector == 'F' || selector == 'H') {
176  ++numNoHieraPar;
177  } else if (selector == 'c' || selector == 'f' || selector == '1' || selector == 'r'
178  || selector == 's') {
179  ++numHieraPar;
180  } // else ... accept '0' as undetermined
181  }
182  if (numNoHieraPar) { // Selected to be taken out.
183  if (numHieraPar) { // Inconsistent: Some parameters still in hierarchy ==> exception!
184  throw cms::Exception("BadConfig")
185  << "[PedeSteerer::buildNoHierarchyCollection] All active parameters of alignables to be "
186  << " taken out of the hierarchy must be marked with capital letters 'C', 'F' or 'H'!";
187  }
188  bool isInHiera = false; // Check whether Alignable is really part of hierarchy:
189  Alignable *mother = *iAli;
190  while ((mother = mother->mother())) {
191  if (mother->alignmentParameters()) isInHiera = true; // could 'break;', but loop is short
192  }
193  // Complain, but keep collection short if not in hierarchy:
194  if (isInHiera) myNoHieraCollection.insert(*iAli);
195  else edm::LogWarning("Alignment") << "@SUB=PedeSteerer::buildNoHierarchyCollection"
196  << "Alignable not in hierarchy, no need to remove it!";
197  }
198  } // end loop on alignables
199 
200  return myNoHieraCollection.size();
201 }
std::set< const Alignable * > myNoHieraCollection
keeps track of created &#39;secondary&#39; steering files
Definition: PedeSteerer.h:131
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
const std::vector< char > & fullSelection() const
int size(void) const
Get number of parameters.
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:94
void PedeSteerer::buildSubSteer ( AlignableTracker aliTracker,
AlignableMuon aliMuon,
AlignableExtras aliExtras 
)

construct steering files about hierarchy, fixing etc. an keep track of their names

Definition at line 675 of file PedeSteerer.cc.

References AlignmentParameterStore::alignables(), buildNoHierarchyCollection(), PedeSteererWeakModeConstraints::constructConstraints(), defineCoordinates(), fileName(), fixParameters(), PedeSteererWeakModeConstraints::getConfigData(), edm::ParameterSet::getParameter(), hierarchyConstraints(), myConfig, myLabels, myNoHieraCollection, myParameterStore, presigmas(), AlCaHLTBitMon_QueryRunRegistry::string, theCoordDefiners, and theCoordMaster.

676 {
677  const std::vector<Alignable*> &alis = myParameterStore->alignables();
678 
679  if (theCoordMaster && !theCoordDefiners.empty()) {
680  const std::string nameCoordFile(this->fileName("Coord"));
681  this->defineCoordinates(theCoordDefiners, theCoordMaster, nameCoordFile);
682  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
683  << theCoordDefiners.size() << " highest level objects define the "
684  << "coordinate system, steering file " << nameCoordFile << ".";
685  }
686 
687  const std::string nameFixFile(this->fileName("FixPara"));
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"
691  << nFixFixCor.first << " parameters fixed at 0. and "
692  << nFixFixCor.second << " at 'original' position, "
693  << "steering file " << nameFixFile << ".";
694  }
695 
696  if (this->buildNoHierarchyCollection(alis)) { // before hierarchyConstraints(..)
697  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
698  << myNoHieraCollection.size()<<" alignables taken out of hierarchy.";
699  }
700 
701  const std::string nameHierarchyFile(this->fileName("Hierarchy"));
702  unsigned int nConstraint = this->hierarchyConstraints(alis, nameHierarchyFile);
703  if (nConstraint) {
704  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
705  << "Hierarchy constraints for " << nConstraint << " alignables, "
706  << "steering file " << nameHierarchyFile << ".";
707  }
708 
709  //construct the systematic geometry deformations
710  if(!(myConfig.getParameter<std::vector<edm::ParameterSet> >("constraints")).empty()) {
711  PedeSteererWeakModeConstraints GeometryConstraints(aliTracker,
712  myLabels,
713  myConfig.getParameter<std::vector<edm::ParameterSet> >("constraints"),
714  myConfig.getParameter<std::string>("steerFile"));
715 
716  //prepare the output files
717  //Get the data structure in which the configuration data are stored.
718  //The relation between the ostream* and the corresponding file name needs to be filled
719  auto& ConstraintsConfigContainer = GeometryConstraints.getConfigData();
720 
721  //loop over all configured constraints
722  for(auto& it: ConstraintsConfigContainer) {
723  //each level has its own constraint which means the output is stored in a separate file
724  for(const auto& ilevelsFilename: it.levelsFilenames_) {
725  it.mapFileName_.insert(std::make_pair
726  (ilevelsFilename.second,this->createSteerFile(ilevelsFilename.second,true))
727  );
728  }
729  }
730 
731  unsigned int nGeometryConstraint = GeometryConstraints.constructConstraints(alis);
732  if (nGeometryConstraint) {
733  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
734  << "Geometry constraints for " << nGeometryConstraint << " alignables.";
735  }
736  }
737 
738  const std::string namePresigmaFile(this->fileName("Presigma"));
739  unsigned int nPresigma =
740  this->presigmas(myConfig.getParameter<std::vector<edm::ParameterSet> >("Presigmas"),
741  namePresigmaFile, alis, aliTracker, aliMuon, aliExtras);
742  if (nPresigma) {
743  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
744  << "Presigma values set for " << nPresigma << " parameters, "
745  << "steering file " << namePresigmaFile << ".";
746  }
747 
748  // Delete all SelectionUserVariables now? They will anyway be overwritten by MillePedeVariables...
749 }
T getParameter(std::string const &) const
const edm::ParameterSet myConfig
Definition: PedeSteerer.h:120
std::vector< Alignable * > theCoordDefiners
master coordinates, must (?) be global frame
Definition: PedeSteerer.h:133
Alignable * theCoordMaster
Alignables deselected for hierarchy constr.
Definition: PedeSteerer.h:132
std::set< const Alignable * > myNoHieraCollection
keeps track of created &#39;secondary&#39; steering files
Definition: PedeSteerer.h:131
unsigned int hierarchyConstraints(const std::vector< Alignable * > &alis, const std::string &file)
Definition: PedeSteerer.cc:444
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:117
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 &#39;cffPresi&#39; and call presigmasFile
Definition: PedeSteerer.cc:550
const AlignmentParameterStore * myParameterStore
Definition: PedeSteerer.h:116
std::pair< unsigned int, unsigned int > fixParameters(const std::vector< Alignable * > &alignables, const std::string &file)
Definition: PedeSteerer.cc:232
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:663
unsigned int buildNoHierarchyCollection(const std::vector< Alignable * > &alis)
Definition: PedeSteerer.cc:162
const align::Alignables & alignables(void) const
get all alignables
void defineCoordinates(const std::vector< Alignable * > &alis, Alignable *aliMaster, const std::string &fileName)
Definition: PedeSteerer.cc:348
bool PedeSteerer::checkParameterChoices ( const std::vector< Alignable * > &  alis) const
private

Checks whether SelectionUserVariables that might be attached to alis' AlignmentParameters (these must exist) are all known.

Definition at line 204 of file PedeSteerer.cc.

References Exception, SelectionUserVariables::fullSelection(), triggerObjects_cff::sel, AlignmentParameters::size(), and AlignmentParameters::userVariables().

Referenced by PedeSteerer().

205 {
206  for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
207  AlignmentParameters *paras = (*iAli)->alignmentParameters();
208  SelectionUserVariables *selVar = dynamic_cast<SelectionUserVariables*>(paras->userVariables());
209  if (!selVar) continue;
210  for (unsigned int iParam = 0; static_cast<int>(iParam) < paras->size(); ++iParam) {
211  const char sel = selVar->fullSelection()[iParam];
212  if (sel != 'f' && sel != 'F' && sel != 'c' && sel != 'C' &&
213  sel != '0' && sel != '1' && sel != 'H' && sel != 'r' && sel != 's') {
214  throw cms::Exception("BadConfig")
215  << "[PedeSteerer::unknownParameterChoices] "
216  << "Unexpected parameter selector '" << sel
217  << "', use \n'f/F' (fix),\n'c/C' (fix at correct pos.),\n'1/H' (free),\n"
218  << "'r/s' (free, but defining reference system, trying to correct misalignment if 's')"
219  << " or \n'0' (ignore).\n"
220  << "Capital letters mean that the Alignable is taken out of a possible hierarchy,\n"
221  << "but must be used consistently for all its parameters.";
222  return false; // unreached
223  }
224  }
225  }
226 
227  return true;
228 }
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
const std::vector< char > & fullSelection() const
int size(void) const
Get number of parameters.
double PedeSteerer::cmsToPedeFactor ( unsigned int  parNum) const

Definition at line 141 of file PedeSteerer.cc.

References RigidBodyAlignmentParameters::dalpha, RigidBodyAlignmentParameters::dbeta, RigidBodyAlignmentParameters::dgamma, RigidBodyAlignmentParameters::dx, RigidBodyAlignmentParameters::dy, and RigidBodyAlignmentParameters::dz.

Referenced by fixParameter(), presigmasFile(), and PedeReader::setParameter().

142 {
143  return 1.; // mmh, otherwise would need to FIXME hierarchyConstraint...
144 
145  switch (parNum) {
148  return 1000.; // cm to mum *1/10 to get smaller values
150  return 2500.; // cm to mum *1/4
153  return 1000.; // rad to mrad (no first guess for sensitivity yet)
155  return 10000.; // rad to mrad *10 to get larger values
156  default:
157  return 1.;
158  }
159 }
void PedeSteerer::correctToReferenceSystem ( )

If reference alignables have been configured, shift everything such that mean position and orientation of dets in these alignables are zero.

Definition at line 396 of file PedeSteerer.cc.

References AlCaHLTBitMon_QueryRunRegistry::comp, PVValHelper::dx, PVValHelper::dy, PVValHelper::dz, MillePedeFileConverter_cfg::e, Alignable::move(), Alignable::rotateInGlobalFrame(), theCoordDefiners, theCoordMaster, and align::toMatrix().

Referenced by PedeSteerer().

397 {
398  typedef RigidBodyAlignmentParameters RbPars;
399  if (!theCoordMaster || theCoordDefiners.empty()) return; // nothing was defined
400 
401  std::vector<Alignable*> definerDets; // or ...DetUnits
402  for (std::vector<Alignable*>::iterator it = theCoordDefiners.begin(), iE = theCoordDefiners.end();
403  it != iE; ++it) {// find lowest level objects of alignables that define the coordinate system
404  const std::vector<Alignable*> &comp = (*it)->deepComponents();
405  definerDets.insert(definerDets.end(), comp.begin(), comp.end());
406  }
407 
408  for (unsigned int iLoop = 0; ; ++iLoop) { // iterate: shifts and rotations are not independent
409  AlgebraicVector meanPars(RbPars::N_PARAM);
410  for (std::vector<Alignable*>::iterator it = definerDets.begin(), iE = definerDets.end();
411  it != iE; ++it) { // sum up mean displacements/misrotations:
412  meanPars += RbPars(*it, true).globalParameters();// requires theCoordMaster has global frame
413  }
414  meanPars /= definerDets.size();
415  const align::Scalar squareSum = meanPars.normsq();
416 
417  if (squareSum < 1.e-20) break; // sqrt(1.e-20)=1.e-10: close enough to stop iterating
418  if (iLoop == 0) {
419  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::correctToReferenceSystem"
420  << "Loop " << iLoop << " "
421  << "Mean misalignment of dets of defined coordinate system"
422  << (squareSum < 1.e-20 ? ":" :
423  " (will be iteratively corrected to < 1.e-10):") << meanPars;
424  }
425  if (iLoop >=5) { // 3 iterations should be safe, use 5 for 'more' safety...
426  edm::LogError("Alignment") << "@SUB=PedeSteerer::correctToReferenceSystem"
427  << "No convergence in " << iLoop << " iterations, "
428  << "remaining misalignment: " << meanPars;
429  break;
430  }
431 
432  const GlobalVector globalShift(meanPars[RbPars::dx],meanPars[RbPars::dy],meanPars[RbPars::dz]);
433  theCoordMaster->move(-globalShift); // sign to revert
434  align::EulerAngles globalAngles(3);
435  globalAngles[0] = meanPars[RbPars::dalpha];
436  globalAngles[1] = meanPars[RbPars::dbeta];
437  globalAngles[2] = meanPars[RbPars::dgamma];
438  theCoordMaster->rotateInGlobalFrame(align::toMatrix(-globalAngles)); // sign to revert
439  }
440 
441 }
std::vector< Alignable * > theCoordDefiners
master coordinates, must (?) be global frame
Definition: PedeSteerer.h:133
double Scalar
Definition: Definitions.h:27
Alignable * theCoordMaster
Alignables deselected for hierarchy constr.
Definition: PedeSteerer.h:132
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
Definition: Definitions.h:36
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:42
std::ofstream * PedeSteerer::createSteerFile ( const std::string &  name,
bool  addToList 
)
private

create and open file with name, if (addToList) append to mySteeringFiles

Definition at line 644 of file PedeSteerer.cc.

References Exception, myNoSteerFiles, mySteeringFiles, MillePedeFileConverter_cfg::out, mps_fire::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by buildMasterSteer(), defineCoordinates(), fixParameter(), hierarchyConstraints(), and presigmasFile().

645 {
646  const std::string realName(myNoSteerFiles ? "/dev/null" : name.c_str());
647 
648  std::ofstream *result = new std::ofstream(realName.c_str(), std::ios::out);
649  if (!result || !result->is_open()) {
650  delete result; // needed before exception in case just open failed
651  throw cms::Exception("FileOpenProblem") << "[PedeSteerer::createSteerFile]"
652  << "Could not open " << realName
653  << " as output file.";
654  } else if (addToList) {
655  mySteeringFiles.push_back(realName); // keep track
656  }
657 
658  return result;
659 }
bool myNoSteerFiles
directory of all files
Definition: PedeSteerer.h:122
std::vector< std::string > mySteeringFiles
precision for writing constraints to text file
Definition: PedeSteerer.h:129
void PedeSteerer::defineCoordinates ( const std::vector< Alignable * > &  alis,
Alignable aliMaster,
const std::string &  fileName 
)
private

Create steering file with constraints defining coordinate system via hierarchy constraints between 'aliMaster' and 'alis'; 'aliMaster' must not have parameters: would not make sense!

Definition at line 348 of file PedeSteerer.cc.

References Alignable::alignmentParameters(), createSteerFile(), Exception, hierarchyConstraint(), myIsSteerFileDebug, and Alignable::setAlignmentParameters().

Referenced by buildSubSteer().

350 {
351  std::ofstream *filePtr = this->createSteerFile(fileName, true);
352  (*filePtr) << "* Constraints to define coordinate system:\n";
353  if (!aliMaster || aliMaster->alignmentParameters()) {
354  throw cms::Exception("BadConfig")
355  << "[PedeSteerer::defineCoordinates] " << "No master alignable or it has parameters!";
356  }
357  if (myIsSteerFileDebug) { // See constructor comments about hack:
358  edm::LogError("Alignment") << "@SUB=PedeSteerer::defineCoordinates"
359  << "Ignore following LogicErrors from PedeLabeler.";
360  }
361  AlignmentParameters *par = new RigidBodyAlignmentParameters(aliMaster, false);
362  aliMaster->setAlignmentParameters(par); // hierarchyConstraint needs parameters
363  this->hierarchyConstraint(aliMaster, alis, *filePtr);
364  aliMaster->setAlignmentParameters(nullptr); // erase dummy parameters
365 
366  delete filePtr; // automatically flushes, no problem if NULL ptr.
367 }
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
std::ofstream * createSteerFile(const std::string &name, bool addToList)
create and open file with name, if (addToList) append to mySteeringFiles
Definition: PedeSteerer.cc:644
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:129
void hierarchyConstraint(const Alignable *ali, const std::vector< Alignable * > &components, std::ofstream &file) const
Definition: PedeSteerer.cc:480
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:663
bool myIsSteerFileDebug
flag to write steering files to /dev/null
Definition: PedeSteerer.h:123
const std::string& PedeSteerer::directory ( ) const
inline

directory from constructor input, '/' is attached if needed

Definition at line 67 of file PedeSteerer.h.

References myDirectory.

Referenced by PedeReader::PedeReader().

67 { return myDirectory;}
std::string myDirectory
Definition: PedeSteerer.h:121
std::string PedeSteerer::fileName ( const std::string &  addendum) const
private

full name with directory and 'idenitfier'

Definition at line 663 of file PedeSteerer.cc.

References edm::ParameterSet::getParameter(), myConfig, myDirectory, dataset::name, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by buildMasterSteer(), buildSubSteer(), and fixParameters().

664 {
665 
667  name += myConfig.getParameter<std::string>("steerFile");
668  name += addendum;
669  name += ".txt";
670 
671  return name;
672 }
T getParameter(std::string const &) const
const edm::ParameterSet myConfig
Definition: PedeSteerer.h:120
std::string myDirectory
Definition: PedeSteerer.h:121
int PedeSteerer::fixParameter ( Alignable ali,
unsigned int  iRunRange,
unsigned int  iParam,
char  selector,
std::ofstream *&  filePtr,
const std::string &  fileName 
)
private

If 'selector' means fixing, create corresponding steering file line in file pointed to by 'filePtr'. If 'filePtr == 0' create file with name 'fileName' (and return pointer via reference).

Definition at line 266 of file PedeSteerer.cc.

References PedeLabelerBase::alignableLabelFromParamAndInstance(), Alignable::alignmentParameters(), cmsToPedeFactor(), createSteerFile(), Exception, FrontierConditions_GlobalTag_cff::file, Alignable::globalPosition(), Alignable::id(), AlignmentParametersFactory::kRigidBody, myIsSteerFileDebug, myLabels, PedeLabelerBase::parameterLabel(), AlignmentParameters::parameters(), parameterSign(), position, mps_fire::result, and AlignmentParameters::type().

Referenced by fixParameters().

269 {
270  int result = 0;
271  float fixAt = 0.;
272  if (selector == 'c' || selector == 'C') {
274  throw cms::Exception("BadConfig")
275  << "PedeSteerer::fixParameter: correction (c/C) possible only for RigidBodyParameters";
276  }
277  fixAt = -this->parameterSign() * RigidBodyAlignmentParameters(ali, true).parameters()[iParam];
278  result = -1;
279  } else if (selector == 'f' || selector == 'F') {
280  result = 1;
281  }
282 
283  if (result) {
284  if (!filePtr) {
285  filePtr = this->createSteerFile(fileName, true);
286  (*filePtr) << "Parameter\n";
287  }
288  std::ofstream &file = *filePtr;
289 
290  const unsigned int aliLabel = myLabels->alignableLabelFromParamAndInstance(ali, iParam, iInstance);
291  file << myLabels->parameterLabel(aliLabel, iParam) << " "
292  << fixAt * this->cmsToPedeFactor(iParam) << " -1.0";
293  if (myIsSteerFileDebug) { // debug
294  const GlobalPoint position(ali->globalPosition());
295  file << " * id " << ali->id() << ", eta " << position.eta() << ", z " << position.z()
296  << ", r " << position.perp() << ", phi " << position.phi();
297  }
298  file << "\n";
299  }
300 
301  return result;
302 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:189
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
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
Definition: PedeSteerer.cc:644
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:117
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
virtual unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const =0
double cmsToPedeFactor(unsigned int parNum) const
Definition: PedeSteerer.cc:141
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:663
bool myIsSteerFileDebug
flag to write steering files to /dev/null
Definition: PedeSteerer.h:123
static int position[264][3]
Definition: ReadPGInfo.cc:509
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:138
int parameterSign() const
results from pede (and start values for pede) might need a sign flip
Definition: PedeSteerer.h:65
std::pair< unsigned int, unsigned int > PedeSteerer::fixParameters ( const std::vector< Alignable * > &  alignables,
const std::string &  file 
)
private

Checks whether 'alignables' have SelectionUserVariables attached to their AlignmentParameters (these must exist) that indicate fixation of a parameter, a steering 'file' is created accordingly. Returns number of parameters fixed at 0 and at 'nominal truth'.

Definition at line 232 of file PedeSteerer.cc.

References fileName(), fixParameter(), SelectionUserVariables::fullSelection(), myLabels, PedeLabelerBase::numberOfParameterInstances(), AlignmentParameters::size(), and AlignmentParameters::userVariables().

Referenced by buildSubSteer().

233 {
234  // return number of parameters fixed at 0. and fixed at original position
235  std::pair<unsigned int, unsigned int> numFixNumFixCor(0, 0);
236 
237  std::ofstream *filePtr = nullptr;
238 
239  for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
240 
241  AlignmentParameters *params = (*iAli)->alignmentParameters();
242  SelectionUserVariables *selVar = dynamic_cast<SelectionUserVariables*>(params->userVariables());
243  if (!selVar) continue;
244 
245  for (unsigned int iParam = 0; static_cast<int>(iParam) < params->size(); ++iParam) {
246  const unsigned int nInstances = myLabels->numberOfParameterInstances(*iAli, iParam);
247  for (unsigned int iInstance=0;iInstance<nInstances;++iInstance) {
248  int whichFix = this->fixParameter(*iAli, iInstance, iParam,
249  selVar->fullSelection()[iParam], filePtr,
250  fileName);
251  if (whichFix == 1) {
252  ++(numFixNumFixCor.first);
253  } else if (whichFix == -1) {
254  ++(numFixNumFixCor.second);
255  }
256  }
257  }
258  }
259 
260  delete filePtr; // automatically flushes, no problem if NULL ptr.
261 
262  return numFixNumFixCor;
263 }
int fixParameter(Alignable *ali, unsigned int iRunRange, unsigned int iParam, char selector, std::ofstream *&filePtr, const std::string &fileName)
Definition: PedeSteerer.cc:266
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
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
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:117
int size(void) const
Get number of parameters.
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:663
void PedeSteerer::hierarchyConstraint ( const Alignable ali,
const std::vector< Alignable * > &  components,
std::ofstream &  file 
) const
private

Definition at line 480 of file PedeSteerer.cc.

References PedeLabelerBase::alignableLabel(), Alignable::alignableObjectId(), alignableObjectId_, Alignable::globalPosition(), AlignmentParameterStore::hierarchyConstraints(), AlignableObjectId::idToString(), isNoHiera(), myIsSteerFileDebug, myLabels, myParameterStore, PedeLabelerBase::parameterLabel(), PV3DBase< T, PVType, FrameType >::perp(), theConstrPrecision, theMinHieraConstrCoeff, and theMinHieraParPerConstr.

Referenced by defineCoordinates(), and hierarchyConstraints().

483 {
484  typedef AlignmentParameterStore::ParameterId ParameterId;
485 
486  std::vector<std::vector<ParameterId> > paramIdsVec;
487  std::vector<std::vector<double> > factorsVec;
488  const bool allConstr = false; // true; // make configurable?
489  static std::atomic<bool> allConstrWarning{false};
490  bool expected{false};
491  if (allConstr && allConstrWarning.compare_exchange_strong(expected, true)) {
492  edm::LogWarning("Alignment") << "@SUB=PedeSteerer::hierarchyConstraint"
493  << "changed to use all 6 constraints";
494  }
495  if (!myParameterStore->hierarchyConstraints(ali, components, paramIdsVec, factorsVec, allConstr,
497  edm::LogWarning("Alignment") << "@SUB=PedeSteerer::hierarchyConstraint"
498  << "Problems from store.";
499  }
500 
501  for (unsigned int iConstr = 0; iConstr < paramIdsVec.size(); ++iConstr) {
502  std::ostringstream aConstr;
503 
504  const std::vector<ParameterId> &parIds = paramIdsVec[iConstr];
505  const std::vector<double> &factors = factorsVec[iConstr];
506  unsigned int nParPerConstr = 0; // keep track of used factor/parId pair
507  // parIds.size() == factors.size() granted by myParameterStore->hierarchyConstraints
508  for (unsigned int iParam = 0; iParam < parIds.size(); ++iParam) {
509  Alignable *aliSubComp = parIds[iParam].first;
510  const unsigned int compParNum = parIds[iParam].second;
511  if (this->isNoHiera(aliSubComp)) {
512  if (myIsSteerFileDebug) aConstr << "* Taken out of hierarchy: ";
513  continue;
514  }
515  const unsigned int aliLabel = myLabels->alignableLabel(aliSubComp);
516  const unsigned int paramLabel = myLabels->parameterLabel(aliLabel, compParNum);
517  // FIXME: multiply by cmsToPedeFactor(subcomponent)/cmsToPedeFactor(mother) (or vice a versa?)
518  if (theConstrPrecision > 0)
519  aConstr << paramLabel << " " << std::setprecision(theConstrPrecision) << factors[iParam];
520  else
521  aConstr << paramLabel << " " << factors[iParam];
522  if (myIsSteerFileDebug) { // debug
523  aConstr << " ! for param " << compParNum << " of a "
524  << alignableObjectId_.idToString(aliSubComp->alignableObjectId()) << " at "
525  << aliSubComp->globalPosition() << ", r=" << aliSubComp->globalPosition().perp();
526  }
527  aConstr << "\n";
528  ++nParPerConstr; // OK, we used one.
529  } // end loop on params
530 
531  //
532  if (nParPerConstr && nParPerConstr >= theMinHieraParPerConstr) { // Enough to make sense?
533  if (myIsSteerFileDebug) { //debug
534  file << "\n* Nr. " << iConstr << " of a '"
535  << alignableObjectId_.idToString(ali->alignableObjectId()) << "' (label "
536  << myLabels->alignableLabel(const_cast<Alignable*>(ali)) // ugly cast: FIXME!
537  << "), position " << ali->globalPosition()
538  << ", r = " << ali->globalPosition().perp();
539  }
540  file << "\nConstraint 0.\n" << aConstr.str(); // in future 'Wconstraint'?
541  } else if (nParPerConstr > 0) { // no warning for trivial case...
542  edm::LogWarning("Alignment") << "@SUB=PedeSteerer::hierarchyConstraint"
543  << "Skip constraint on " << nParPerConstr
544  << " parameter(s):\n" << aConstr.str();
545  }
546  } // end loop on constraints
547 }
T perp() const
Definition: PV3DBase.h:72
std::pair< Alignable *, unsigned int > ParameterId
a single alignable parameter of an Alignable
unsigned int theMinHieraParPerConstr
min absolute value of coefficients in hierarchy constraints
Definition: PedeSteerer.h:126
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
bool hierarchyConstraints(const Alignable *aliMaster, const align::Alignables &aliComps, std::vector< std::vector< ParameterId > > &paramIdsVecOut, std::vector< std::vector< double > > &factorsVecOut, bool all, double epsilon) const
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:117
const AlignableObjectId alignableObjectId_
pointer to labeler (not the owner)
Definition: PedeSteerer.h:118
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
double theMinHieraConstrCoeff
old pede versions (before May &#39;07) need a sign flip...
Definition: PedeSteerer.h:125
unsigned int theConstrPrecision
hierarchy constraints with less params are ignored
Definition: PedeSteerer.h:127
const AlignmentParameterStore * myParameterStore
Definition: PedeSteerer.h:116
const char * idToString(align::StructureType type) const
virtual unsigned int alignableLabel(Alignable *alignable) const =0
bool isNoHiera(const Alignable *ali) const
True if &#39;ali&#39; was deselected from hierarchy and any ancestor (e.g. mother) has parameters.
Definition: PedeSteerer.cc:135
bool myIsSteerFileDebug
flag to write steering files to /dev/null
Definition: PedeSteerer.h:123
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:138
unsigned int PedeSteerer::hierarchyConstraints ( const std::vector< Alignable * > &  alis,
const std::string &  file 
)
private

Definition at line 444 of file PedeSteerer.cc.

References alignableObjectId_, createSteerFile(), hierarchyConstraint(), and AlignableObjectId::idToString().

Referenced by buildSubSteer().

446 {
447  std::ofstream *filePtr = nullptr;
448 
449  unsigned int nConstraints = 0;
450  std::vector<Alignable*> aliDaughts;
451  for (std::vector<Alignable*>::const_iterator iA = alis.begin(), iEnd = alis.end();
452  iA != iEnd; ++iA) {
453  aliDaughts.clear();
454  if (!(*iA)->firstCompsWithParams(aliDaughts)) {
455  edm::LogWarning("Alignment") << "@SUB=PedeSteerer::hierarchyConstraints"
456  << "Some but not all daughters of "
457  << alignableObjectId_.idToString((*iA)->alignableObjectId())
458  << " with params!";
459  }
460  // edm::LogInfo("Alignment") << "@SUB=PedeSteerer::hierarchyConstraints"
461  // << aliDaughts.size() << " ali param components";
462  if (aliDaughts.empty()) continue;
463  // edm::LogInfo("Alignment") << "@SUB=PedeSteerer::hierarchyConstraints"
464  // << aliDaughts.size() << " alignable components ("
465  // << (*iA)->size() << " in total) for "
466  // << aliId.alignableTypeName(*iA)
467  // << ", layer " << aliId.typeAndLayerFromAlignable(*iA).second
468  // << ", position " << (*iA)->globalPosition()
469  // << ", r = " << (*iA)->globalPosition().perp();
470  if (!filePtr) filePtr = this->createSteerFile(fileName, true);
471  ++nConstraints;
472  this->hierarchyConstraint(*iA, aliDaughts, *filePtr);
473  }
474 
475  delete filePtr; // automatically flushes, no problem if NULL ptr.
476 
477  return nConstraints;
478 }
std::ofstream * createSteerFile(const std::string &name, bool addToList)
create and open file with name, if (addToList) append to mySteeringFiles
Definition: PedeSteerer.cc:644
const AlignableObjectId alignableObjectId_
pointer to labeler (not the owner)
Definition: PedeSteerer.h:118
void hierarchyConstraint(const Alignable *ali, const std::vector< Alignable * > &components, std::ofstream &file) const
Definition: PedeSteerer.cc:480
const char * idToString(align::StructureType type) const
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:663
bool PedeSteerer::isCorrectToRefSystem ( const std::vector< Alignable * > &  coordDefiners) const

Definition at line 370 of file PedeSteerer.cc.

References Exception, SelectionUserVariables::fullSelection(), and mps_fire::i.

Referenced by PedeSteerer().

371 {
372  bool doCorrect = false;
373  bool doNotCorrect = false;
374  for (std::vector<Alignable*>::const_iterator it = coordDefiners.begin(), iE=coordDefiners.end();
375  it != iE; ++it) {
376  SelectionUserVariables *selVar =
377  ((*it)->alignmentParameters() ?
378  dynamic_cast<SelectionUserVariables*>((*it)->alignmentParameters()->userVariables()) : nullptr);
379  if (!selVar) continue; // is an error!?
380 
381  for (unsigned int i = 0; i < selVar->fullSelection().size(); ++i) {
382  if (selVar->fullSelection()[i] == 'r') doNotCorrect = true;
383  else if (selVar->fullSelection()[i] == 's') doCorrect = true;
384  }
385  }
386 
387  if (doCorrect && doNotCorrect) {
388  throw cms::Exception("BadConfig")
389  << "[PedeSteerer::doCorrectToRefSystem]: Parameter selection 's' and 'r' must not coexist!";
390  }
391 
392  return doCorrect;
393 }
const std::vector< char > & fullSelection() const
bool PedeSteerer::isNoHiera ( const Alignable ali) const

True if 'ali' was deselected from hierarchy and any ancestor (e.g. mother) has parameters.

Definition at line 135 of file PedeSteerer.cc.

References myNoHieraCollection.

Referenced by hierarchyConstraint().

136 {
137  return (myNoHieraCollection.find(ali) != myNoHieraCollection.end());
138 }
std::set< const Alignable * > myNoHieraCollection
keeps track of created &#39;secondary&#39; steering files
Definition: PedeSteerer.h:131
int PedeSteerer::parameterSign ( ) const
inline

results from pede (and start values for pede) might need a sign flip

Definition at line 65 of file PedeSteerer.h.

References myParameterSign.

Referenced by fixParameter(), PedeReader::setCalibrationParameter(), and PedeReader::setParameter().

65 { return myParameterSign; }
int myParameterSign
whether or not to fill pede steering files with debug info
Definition: PedeSteerer.h:124
unsigned int PedeSteerer::presigmas ( const std::vector< edm::ParameterSet > &  cffPresi,
const std::string &  fileName,
const std::vector< Alignable * > &  alis,
AlignableTracker aliTracker,
AlignableMuon aliMuon,
AlignableExtras aliExtras 
)
private

interprete content of presigma VPSet 'cffPresi' and call presigmasFile

Definition at line 550 of file PedeSteerer.cc.

References AlignmentParameterSelector::addSelections(), alignableObjectId_, AlignmentParameterSelector::clear(), Exception, AlignableObjectId::idToString(), presigmasFile(), AlignmentParameterSelector::selectedAlignables(), AlignmentParameterSelector::selectedParameters(), and nanoDQM_cfi::sels.

Referenced by buildSubSteer(), and presigmasFile().

554 {
555  // We loop on given PSet's, each containing a parameter selection and the presigma value
556  // The resulting presigmas are stored in a map with Alignable* as key.
557  // This map, 'fileName' and 'alis' are passed further to create the steering file.
558 
559  AlignmentParameterSelector selector(aliTracker, aliMuon, aliExtras);
560  AlignablePresigmasMap aliPresiMap; // map to store alis with presigmas of their parameters
561  for (std::vector<edm::ParameterSet>::const_iterator iSet = cffPresi.begin(), iE = cffPresi.end();
562  iSet != iE; ++iSet) { // loop on individual PSets defining ali-params with their presigma
563  selector.clear();
564  selector.addSelections((*iSet).getParameter<edm::ParameterSet>("Selector"));
565  const std::vector<Alignable*> &alis = selector.selectedAlignables();
566  const std::vector<std::vector<char> > &sels = selector.selectedParameters();
567  const float presigma = (*iSet).getParameter<double>("presigma");
568  if (presigma <= 0.) { // given presigma > 0., 0. later used if not (yet) chosen for parameter
569  throw cms::Exception("BadConfig")
570  << "[PedeSteerer::presigmas]: Pre-sigma must be > 0., but is " << presigma << ".";
571  }
572  // now loop on alis of present selection
573  for (unsigned int iAli = 0; iAli < alis.size(); ++iAli) {
574  std::vector<float> &presigmas = aliPresiMap[alis[iAli]]; // existing or empty, so ensure length:
575  if (presigmas.size() < sels[iAli].size()) presigmas.resize(sels[iAli].size(), 0.);
576  for (unsigned int iParam = 0; iParam < sels[iAli].size(); ++iParam) { // loop on parameters
577  if (sels[iAli][iParam] != '0') { // all but '0' means to apply the chosen presigma
578  if (presigmas[iParam] != 0.) { // reset forbidden (would make it order dependent!)
579  throw cms::Exception("BadConfig")
580  << "[PedeSteerer::presigmas]: Try to set pre-sigma " << presigma << ", but already "
581  << "set " << presigmas[iParam] << " (for a "
582  << alignableObjectId_.idToString(alis[iAli]->alignableObjectId()) << ").";
583  }
584  presigmas[iParam] = presigma;
585  } // end if selected for presigma
586  } // end loop on params
587  } // end loop on alignables for given selection and presigma
588  } // end loop on PSets
589 
590  if (aliPresiMap.empty()) return 0;
591  else return this->presigmasFile(fileName, alis, aliPresiMap);
592 }
std::map< const Alignable *, std::vector< float > > AlignablePresigmasMap
Definition: PedeSteerer.h:70
unsigned int presigmasFile(const std::string &fileName, const std::vector< Alignable * > &alis, const AlignablePresigmasMap &aliPresisMap)
look for active &#39;alis&#39; in map of presigma values and create steering file
Definition: PedeSteerer.cc:595
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 &#39;cffPresi&#39; and call presigmasFile
Definition: PedeSteerer.cc:550
const AlignableObjectId alignableObjectId_
pointer to labeler (not the owner)
Definition: PedeSteerer.h:118
const char * idToString(align::StructureType type) const
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:663
unsigned int PedeSteerer::presigmasFile ( const std::string &  fileName,
const std::vector< Alignable * > &  alis,
const AlignablePresigmasMap aliPresisMap 
)
private

look for active 'alis' in map of presigma values and create steering file

Definition at line 595 of file PedeSteerer.cc.

References PedeLabelerBase::alignableLabel(), alignableObjectId_, cmsToPedeFactor(), createSteerFile(), SelectionUserVariables::fullSelection(), AlignableObjectId::idToString(), myIsSteerFileDebug, myLabels, PedeLabelerBase::parameterLabel(), and presigmas().

Referenced by presigmas().

598 {
599  // Check if 'alis' are in aliPresiMap,
600  // if yes apply presigma - but NOT if parameter is fixed!
601  std::ofstream *filePtr = nullptr;
602 
603  unsigned int nPresiParam = 0;
604  for (std::vector<Alignable*>::const_iterator iAli = alis.begin(), iAliE = alis.end();
605  iAli != iAliE; ++iAli) {
606  // Any presigma chosen for alignable?
607  AlignablePresigmasMap::const_iterator presigmasIt = aliPresiMap.find(*iAli);
608  if (presigmasIt == aliPresiMap.end()) continue; // no presigma chosen for alignable
609 
610  // Why does the following not work? It does with CMSSW_1_3_X on SLC3...
611  // const AlignablePresigmasMap::data_type &presigmas = presigmasIt->second;
612  const std::vector<float> &presigmas = presigmasIt->second; // I want to hide float or double...
613  for (unsigned int iParam = 0; iParam < presigmas.size(); ++iParam) {
614  // Now check whether a presigma value > 0. chosen:
615  if (presigmas[iParam] <= 0.) continue; // must be positive, '<' checked above
616  // Do not apply presigma to inactive or fixed values.
617  if (!(*iAli)->alignmentParameters()->selector()[iParam]) continue;
618  SelectionUserVariables *selVar
619  = dynamic_cast<SelectionUserVariables*>((*iAli)->alignmentParameters()->userVariables());
620  const char selChar = (selVar ? selVar->fullSelection()[iParam] : '1');
621  if (selChar == 'f' || selChar == 'F' || selChar == 'c' || selChar == 'C') continue;
622  // Finally create and write steering file:
623  if (!filePtr) {
624  filePtr = this->createSteerFile(fileName, true);
625  (*filePtr) << "* Presigma values for active parameters: \nParameter\n";
626  }
627  const unsigned int aliLabel = myLabels->alignableLabel(*iAli);
628  (*filePtr) << myLabels->parameterLabel(aliLabel, iParam) << " 0. "
629  << presigmas[iParam] * fabs(this->cmsToPedeFactor(iParam));
630  if (myIsSteerFileDebug) {
631  (*filePtr) << " ! for a " << alignableObjectId_.idToString((*iAli)->alignableObjectId());
632  }
633  (*filePtr) << '\n';
634 
635  ++nPresiParam;
636  } // end loop on parameters for alignables with chosen presigmas
637  } // end loop on alignables
638 
639  delete filePtr; // close properly file
640  return nPresiParam;
641 }
std::ofstream * createSteerFile(const std::string &name, bool addToList)
create and open file with name, if (addToList) append to mySteeringFiles
Definition: PedeSteerer.cc:644
const std::vector< char > & fullSelection() const
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:117
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 &#39;cffPresi&#39; and call presigmasFile
Definition: PedeSteerer.cc:550
const AlignableObjectId alignableObjectId_
pointer to labeler (not the owner)
Definition: PedeSteerer.h:118
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
const char * idToString(align::StructureType type) const
virtual unsigned int alignableLabel(Alignable *alignable) const =0
double cmsToPedeFactor(unsigned int parNum) const
Definition: PedeSteerer.cc:141
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:663
bool myIsSteerFileDebug
flag to write steering files to /dev/null
Definition: PedeSteerer.h:123
int PedeSteerer::runPede ( const std::string &  masterSteer) const

run pede, masterSteer should be as returned from buildMasterSteer(...)

Definition at line 792 of file PedeSteerer.cc.

References mps_check::command, FrontierConditions_GlobalTag_cff::dump, edm::ParameterSet::getUntrackedParameter(), myConfig, myDirectory, and AlCaHLTBitMon_QueryRunRegistry::string.

793 {
794  if (masterSteer.empty()) {
795  edm::LogError("Alignment") << "@SUB=PedeSteerer::runPede" << "Empty master steer file, stop";
796  return 0; //false;
797  }
798 
800  (command += " ") += masterSteer;
802  if (!dump.empty()) {
803  command += " > ";
804  (command += myDirectory) += dump;
805  }
806 
807  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::runPede" << "Start running " << command;
808  // FIXME: Recommended interface to system commands?
809  int shellReturn = gSystem->Exec(command.c_str());
810  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::runPede" << "Command returns " << shellReturn;
811 
812  return shellReturn;
813 }
T getUntrackedParameter(std::string const &, T const &) const
const edm::ParameterSet myConfig
Definition: PedeSteerer.h:120
std::string myDirectory
Definition: PedeSteerer.h:121
list command
Definition: mps_check.py:23
std::vector< Alignable * > PedeSteerer::selectCoordinateAlis ( const std::vector< Alignable * > &  alignables) const
private

Return 'alignables' that have SelectionUserVariables attached to their AlignmentParameters (these must exist) that indicate a definition of a coordinate system. Throws if ill defined reference objects.

Definition at line 305 of file PedeSteerer.cc.

References Alignable::alignmentParameters(), Exception, SelectionUserVariables::fullSelection(), Alignable::mother(), AlignmentParameters::size(), and AlignmentParameters::userVariables().

Referenced by PedeSteerer().

306 {
307  std::vector<Alignable*> coordAlis;
308 
309  for (std::vector<Alignable*>::const_iterator iAli = alis.begin() ; iAli != alis.end(); ++iAli) {
310  AlignmentParameters *params = (*iAli)->alignmentParameters();
311  SelectionUserVariables *selVar = dynamic_cast<SelectionUserVariables*>(params->userVariables());
312  if (!selVar) continue;
313  unsigned int refParam = 0;
314  unsigned int nonRefParam = 0;
315  for (unsigned int iParam = 0; static_cast<int>(iParam) < params->size(); ++iParam) {
316  const char selector = selVar->fullSelection()[iParam];
317  if (selector == 'r' || selector == 's') {
318  ++refParam;
319  } else if (selector != '0' && selector != 'f') { // allow also 'c'?
320  ++nonRefParam;
321  }
322  }
323  // Check whether some 'r/s' selection string. If yes and selection makes sense, add to result:
324  if (refParam) {
325  if (nonRefParam) {
326  throw cms::Exception("BadConfig")
327  << "[PedeSteerer::selectCoordinateAlis] All active parameters of alignables defining "
328  << "the coordinate system must be marked with 'r/s' (or fixed, 'f')!";
329  } else {
330  Alignable *mother = *iAli;
331  while ((mother = mother->mother())) {
332  if (mother->alignmentParameters()) {
333  throw cms::Exception("BadConfig") << "[PedeSteerer::selectCoordinateAlis] "
334  << "Alignables defining the coordinate system must "
335  << "be highest level!";
336  }
337  }
338  coordAlis.push_back(*iAli);
339  }
340  }
341  } // end loop on alignables
342 
343  return coordAlis;
344 }
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
const std::vector< char > & fullSelection() const
int size(void) const
Get number of parameters.
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:94

Member Data Documentation

const AlignableObjectId PedeSteerer::alignableObjectId_
private

pointer to labeler (not the owner)

Definition at line 118 of file PedeSteerer.h.

Referenced by hierarchyConstraint(), hierarchyConstraints(), presigmas(), and presigmasFile().

const edm::ParameterSet PedeSteerer::myConfig
private

Definition at line 120 of file PedeSteerer.h.

Referenced by buildMasterSteer(), buildSubSteer(), fileName(), PedeSteerer(), and runPede().

std::string PedeSteerer::myDirectory
private

Definition at line 121 of file PedeSteerer.h.

Referenced by directory(), fileName(), PedeSteerer(), and runPede().

bool PedeSteerer::myIsSteerFileDebug
private

flag to write steering files to /dev/null

Definition at line 123 of file PedeSteerer.h.

Referenced by defineCoordinates(), fixParameter(), hierarchyConstraint(), PedeSteerer(), and presigmasFile().

const PedeLabelerBase* PedeSteerer::myLabels
private

not the owner!

Definition at line 117 of file PedeSteerer.h.

Referenced by buildSubSteer(), fixParameter(), fixParameters(), hierarchyConstraint(), and presigmasFile().

std::set<const Alignable*> PedeSteerer::myNoHieraCollection
private

keeps track of created 'secondary' steering files

Definition at line 131 of file PedeSteerer.h.

Referenced by buildNoHierarchyCollection(), buildSubSteer(), and isNoHiera().

bool PedeSteerer::myNoSteerFiles
private

directory of all files

Definition at line 122 of file PedeSteerer.h.

Referenced by createSteerFile(), and PedeSteerer().

int PedeSteerer::myParameterSign
private

whether or not to fill pede steering files with debug info

Definition at line 124 of file PedeSteerer.h.

Referenced by parameterSign(), and PedeSteerer().

const AlignmentParameterStore* PedeSteerer::myParameterStore
private

Definition at line 116 of file PedeSteerer.h.

Referenced by buildSubSteer(), hierarchyConstraint(), and PedeSteerer().

std::vector<std::string> PedeSteerer::mySteeringFiles
private

precision for writing constraints to text file

Definition at line 129 of file PedeSteerer.h.

Referenced by buildMasterSteer(), and createSteerFile().

unsigned int PedeSteerer::theConstrPrecision
private

hierarchy constraints with less params are ignored

Definition at line 127 of file PedeSteerer.h.

Referenced by hierarchyConstraint(), and PedeSteerer().

std::vector<Alignable*> PedeSteerer::theCoordDefiners
private

master coordinates, must (?) be global frame

Definition at line 133 of file PedeSteerer.h.

Referenced by buildSubSteer(), correctToReferenceSystem(), and PedeSteerer().

Alignable* PedeSteerer::theCoordMaster
private

Alignables deselected for hierarchy constr.

Definition at line 132 of file PedeSteerer.h.

Referenced by buildSubSteer(), correctToReferenceSystem(), and PedeSteerer().

double PedeSteerer::theMinHieraConstrCoeff
private

old pede versions (before May '07) need a sign flip...

Definition at line 125 of file PedeSteerer.h.

Referenced by hierarchyConstraint(), and PedeSteerer().

unsigned int PedeSteerer::theMinHieraParPerConstr
private

min absolute value of coefficients in hierarchy constraints

Definition at line 126 of file PedeSteerer.h.

Referenced by hierarchyConstraint(), and PedeSteerer().