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 align::Alignables &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 align::Alignables &)
 
bool checkParameterChoices (const align::Alignables &) 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 align::Alignables &, 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 align::Alignables &, const std::string &file)
 
void hierarchyConstraint (const Alignable *ali, const align::Alignables &components, std::ofstream &file) const
 
unsigned int hierarchyConstraints (const align::Alignables &, const std::string &file)
 
unsigned int presigmas (const std::vector< edm::ParameterSet > &cffPresi, const std::string &fileName, const align::Alignables &, AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras)
 interprete content of presigma VPSet 'cffPresi' and call presigmasFile More...
 
unsigned int presigmasFile (const std::string &fileName, const align::Alignables &, const AlignablePresigmasMap &aliPresisMap)
 look for active 'alis' in map of presigma values and create steering file More...
 
align::Alignables selectCoordinateAlis (const align::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 where pede is executed More...
 
int myParameterSign
 whether or not to fill pede steering files with debug info More...
 
const AlignmentParameterStoremyParameterStore
 
std::string myRunDirectory
 directory of all files More...
 
std::vector< std::string > mySteeringFiles
 precision for writing constraints to text file More...
 
unsigned int theConstrPrecision
 hierarchy constraints with less params are ignored More...
 
align::Alignables 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 37 of file PedeSteerer.h.

Member Typedef Documentation

◆ AlignablePresigmasMap

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

Definition at line 73 of file PedeSteerer.h.

Constructor & Destructor Documentation

◆ PedeSteerer()

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 53 of file PedeSteerer.cc.

References AlignableObjectId::commonObjectIdProvider().

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

◆ ~PedeSteerer()

PedeSteerer::~PedeSteerer ( )

non-virtual destructor: do not inherit from this class

Definition at line 139 of file PedeSteerer.cc.

139  {
140  // delete theCoordMaster; NO, see above
141 }

Member Function Documentation

◆ buildMasterSteer()

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 754 of file PedeSteerer.cc.

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

754  {
755  const std::string nameMasterSteer(this->fileName("Master"));
756  std::ofstream *mainSteerPtr = this->createSteerFile(nameMasterSteer, false);
757  if (!mainSteerPtr)
758  return "";
759 
760  // add external steering files, if any
761  std::vector<std::string> addfiles = myConfig.getParameter<std::vector<std::string> >("additionalSteerFiles");
762  mySteeringFiles.insert(mySteeringFiles.end(), addfiles.begin(), 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  if (myRunDirectory.empty())
774  mainSteerRef << binaryFiles[iFile] << "\n";
775  else
776  mainSteerRef << "../" + binaryFiles[iFile] << "\n";
777  }
778 
779  // add method
780  mainSteerRef << "\nmethod " << myConfig.getParameter<std::string>("method") << "\n";
781 
782  // add further options
783  const std::vector<std::string> opt(myConfig.getParameter<std::vector<std::string> >("options"));
784  mainSteerRef << "\n* Outlier treatment and other options \n";
785  for (unsigned int i = 0; i < opt.size(); ++i) {
786  mainSteerRef << opt[i] << "\n";
787  }
788 
789  delete mainSteerPtr; // close (and flush) again
790 
791  return nameMasterSteer;
792 }
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:666
const edm::ParameterSet myConfig
Definition: PedeSteerer.h:127
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::ofstream * createSteerFile(const std::string &name, bool addToList)
create and open file with name, if (addToList) append to mySteeringFiles
Definition: PedeSteerer.cc:650
std::string myRunDirectory
directory of all files
Definition: PedeSteerer.h:129
std::vector< std::string > mySteeringFiles
precision for writing constraints to text file
Definition: PedeSteerer.h:137

◆ buildNoHierarchyCollection()

unsigned int PedeSteerer::buildNoHierarchyCollection ( const align::Alignables 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 169 of file PedeSteerer.cc.

References Exception, SelectionUserVariables::fullSelection(), myNoHieraCollection, submitPVValidationJobs::params, and collectionMerger::selector.

Referenced by buildSubSteer().

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

◆ buildSubSteer()

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 676 of file PedeSteerer.cc.

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

676  {
677  const auto &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" << theCoordDefiners.size()
683  << " 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" << nFixFixCor.first << " parameters fixed at 0. and "
691  << nFixFixCor.second << " at 'original' position, "
692  << "steering file " << nameFixFile << ".";
693  }
694 
695  if (this->buildNoHierarchyCollection(alis)) { // before hierarchyConstraints(..)
696  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer" << myNoHieraCollection.size()
697  << " alignables taken out of hierarchy.";
698  }
699 
700  const std::string nameHierarchyFile(this->fileName("Hierarchy"));
701  unsigned int nConstraint = this->hierarchyConstraints(alis, nameHierarchyFile);
702  if (nConstraint) {
703  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
704  << "Hierarchy constraints for " << nConstraint << " alignables, "
705  << "steering file " << nameHierarchyFile << ".";
706  }
707 
708  //construct the systematic geometry deformations
709  if (!(myConfig.getParameter<std::vector<edm::ParameterSet> >("constraints")).empty()) {
710  PedeSteererWeakModeConstraints GeometryConstraints(
711  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(
726  std::make_pair(ilevelsFilename.second, this->createSteerFile(ilevelsFilename.second, true)));
727  }
728  }
729 
730  unsigned int nGeometryConstraint = GeometryConstraints.constructConstraints(alis);
731  if (nGeometryConstraint) {
732  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
733  << "Geometry constraints for " << nGeometryConstraint << " alignables.";
734  }
735  }
736 
737  const std::string namePresigmaFile(this->fileName("Presigma"));
738  unsigned int nPresigma = this->presigmas(myConfig.getParameter<std::vector<edm::ParameterSet> >("Presigmas"),
739  namePresigmaFile,
740  alis,
741  aliTracker,
742  aliMuon,
743  aliExtras);
744  if (nPresigma) {
745  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
746  << "Presigma values set for " << nPresigma << " parameters, "
747  << "steering file " << namePresigmaFile << ".";
748  }
749 
750  // Delete all SelectionUserVariables now? They will anyway be overwritten by MillePedeVariables...
751 }
std::set< const Alignable * > myNoHieraCollection
keeps track of created &#39;secondary&#39; steering files
Definition: PedeSteerer.h:139
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:666
const edm::ParameterSet myConfig
Definition: PedeSteerer.h:127
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::pair< unsigned int, unsigned int > fixParameters(const align::Alignables &, const std::string &file)
Definition: PedeSteerer.cc:240
unsigned int presigmas(const std::vector< edm::ParameterSet > &cffPresi, const std::string &fileName, const align::Alignables &, AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras)
interprete content of presigma VPSet &#39;cffPresi&#39; and call presigmasFile
Definition: PedeSteerer.cc:550
Alignable * theCoordMaster
Alignables deselected for hierarchy constr.
Definition: PedeSteerer.h:140
unsigned int hierarchyConstraints(const align::Alignables &, const std::string &file)
Definition: PedeSteerer.cc:448
const align::Alignables & alignables(void) const
get all alignables
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:124
Log< level::Info, false > LogInfo
const AlignmentParameterStore * myParameterStore
Definition: PedeSteerer.h:123
align::Alignables theCoordDefiners
master coordinates, must (?) be global frame
Definition: PedeSteerer.h:141
void defineCoordinates(const align::Alignables &, Alignable *aliMaster, const std::string &fileName)
Definition: PedeSteerer.cc:354
unsigned int buildNoHierarchyCollection(const align::Alignables &)
Definition: PedeSteerer.cc:169

◆ checkParameterChoices()

bool PedeSteerer::checkParameterChoices ( const align::Alignables alis) const
private

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

Definition at line 213 of file PedeSteerer.cc.

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

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

◆ cmsToPedeFactor()

double PedeSteerer::cmsToPedeFactor ( unsigned int  parNum) const

Definition at line 149 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().

149  {
150  return 1.; // mmh, otherwise would need to FIXME hierarchyConstraint...
151 
152  switch (parNum) {
155  return 1000.; // cm to mum *1/10 to get smaller values
157  return 2500.; // cm to mum *1/4
160  return 1000.; // rad to mrad (no first guess for sensitivity yet)
162  return 10000.; // rad to mrad *10 to get larger values
163  default:
164  return 1.;
165  }
166 }

◆ correctToReferenceSystem()

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 401 of file PedeSteerer.cc.

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

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

◆ createSteerFile()

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 650 of file PedeSteerer.cc.

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

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

650  {
651  const std::string realName(myNoSteerFiles ? "/dev/null" : name.c_str());
652 
653  std::ofstream *result = new std::ofstream(realName.c_str(), std::ios::out);
654  if (!result || !result->is_open()) {
655  delete result; // needed before exception in case just open failed
656  throw cms::Exception("FileOpenProblem") << "[PedeSteerer::createSteerFile]"
657  << "Could not open " << realName << " as output file.";
658  } else if (addToList) {
659  mySteeringFiles.push_back(realName); // keep track
660  }
661 
662  return result;
663 }
bool myNoSteerFiles
directory where pede is executed
Definition: PedeSteerer.h:130
std::vector< std::string > mySteeringFiles
precision for writing constraints to text file
Definition: PedeSteerer.h:137

◆ defineCoordinates()

void PedeSteerer::defineCoordinates ( const align::Alignables 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 354 of file PedeSteerer.cc.

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

Referenced by buildSubSteer().

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

◆ directory()

const std::string& PedeSteerer::directory ( ) const
inline

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

Definition at line 70 of file PedeSteerer.h.

References myDirectory.

Referenced by PedeReader::PedeReader().

70 { return myDirectory; }
std::string myDirectory
Definition: PedeSteerer.h:128

◆ fileName()

std::string PedeSteerer::fileName ( const std::string &  addendum) const
private

full name with directory and 'idenitfier'

Definition at line 666 of file PedeSteerer.cc.

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

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

666  {
668  name += myConfig.getParameter<std::string>("steerFile");
669  name += addendum;
670  name += ".txt";
671 
672  return name;
673 }
const edm::ParameterSet myConfig
Definition: PedeSteerer.h:127
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::string myDirectory
Definition: PedeSteerer.h:128

◆ fixParameter()

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 272 of file PedeSteerer.cc.

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

Referenced by fixParameters().

277  {
278  int result = 0;
279  float fixAt = 0.;
280  if (selector == 'c' || selector == 'C') {
282  throw cms::Exception("BadConfig")
283  << "PedeSteerer::fixParameter: correction (c/C) possible only for RigidBodyParameters";
284  }
285  fixAt = -this->parameterSign() * RigidBodyAlignmentParameters(ali, true).parameters()[iParam];
286  result = -1;
287  } else if (selector == 'f' || selector == 'F') {
288  result = 1;
289  }
290 
291  if (result) {
292  if (!filePtr) {
293  filePtr = this->createSteerFile(fileName, true);
294  (*filePtr) << "Parameter\n";
295  }
296  std::ofstream &file = *filePtr;
297 
298  const unsigned int aliLabel = myLabels->alignableLabelFromParamAndInstance(ali, iParam, iInstance);
299  file << myLabels->parameterLabel(aliLabel, iParam) << " " << fixAt * this->cmsToPedeFactor(iParam) << " -1.0";
300  if (myIsSteerFileDebug) { // debug
301  const GlobalPoint position(ali->globalPosition());
302  file << " * id " << ali->id() << ", eta " << position.eta() << ", z " << position.z() << ", r "
303  << position.perp() << ", phi " << position.phi();
304  }
305  file << "\n";
306  }
307 
308  return result;
309 }
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:666
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
const AlgebraicVector & parameters(void) const
Get alignment parameters.
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
std::ofstream * createSteerFile(const std::string &name, bool addToList)
create and open file with name, if (addToList) append to mySteeringFiles
Definition: PedeSteerer.cc:650
int parameterSign() const
results from pede (and start values for pede) might need a sign flip
Definition: PedeSteerer.h:68
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:124
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
virtual unsigned int alignableLabelFromParamAndInstance(const Alignable *alignable, unsigned int param, unsigned int instance) const =0
bool myIsSteerFileDebug
flag to write steering files to /dev/null
Definition: PedeSteerer.h:131
static int position[264][3]
Definition: ReadPGInfo.cc:289
double cmsToPedeFactor(unsigned int parNum) const
Definition: PedeSteerer.cc:149

◆ fixParameters()

std::pair< unsigned int, unsigned int > PedeSteerer::fixParameters ( const align::Alignables alis,
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 240 of file PedeSteerer.cc.

References fileName(), fixParameter(), SelectionUserVariables::fullSelection(), myLabels, PedeLabelerBase::numberOfParameterInstances(), and submitPVValidationJobs::params.

Referenced by buildSubSteer().

241  {
242  // return number of parameters fixed at 0. and fixed at original position
243  std::pair<unsigned int, unsigned int> numFixNumFixCor(0, 0);
244 
245  std::ofstream *filePtr = nullptr;
246 
247  for (const auto &iAli : alis) {
248  AlignmentParameters *params = iAli->alignmentParameters();
249  SelectionUserVariables *selVar = dynamic_cast<SelectionUserVariables *>(params->userVariables());
250  if (!selVar)
251  continue;
252 
253  for (unsigned int iParam = 0; static_cast<int>(iParam) < params->size(); ++iParam) {
254  const unsigned int nInstances = myLabels->numberOfParameterInstances(iAli, iParam);
255  for (unsigned int iInstance = 0; iInstance < nInstances; ++iInstance) {
256  int whichFix = this->fixParameter(iAli, iInstance, iParam, selVar->fullSelection()[iParam], filePtr, fileName);
257  if (whichFix == 1) {
258  ++(numFixNumFixCor.first);
259  } else if (whichFix == -1) {
260  ++(numFixNumFixCor.second);
261  }
262  }
263  }
264  }
265 
266  delete filePtr; // automatically flushes, no problem if NULL ptr.
267 
268  return numFixNumFixCor;
269 }
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:666
const std::vector< char > & fullSelection() const
int fixParameter(Alignable *ali, unsigned int iRunRange, unsigned int iParam, char selector, std::ofstream *&filePtr, const std::string &fileName)
Definition: PedeSteerer.cc:272
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:124
virtual unsigned int numberOfParameterInstances(Alignable *alignable, int param=-1) const =0
returns the number of instances for a given parameter

◆ hierarchyConstraint()

void PedeSteerer::hierarchyConstraint ( const Alignable ali,
const align::Alignables components,
std::ofstream &  file 
) const
private

Definition at line 482 of file PedeSteerer.cc.

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

Referenced by defineCoordinates(), and hierarchyConstraints().

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

◆ hierarchyConstraints()

unsigned int PedeSteerer::hierarchyConstraints ( const align::Alignables alis,
const std::string &  file 
)
private

Definition at line 448 of file PedeSteerer.cc.

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

Referenced by buildSubSteer().

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

◆ isCorrectToRefSystem()

bool PedeSteerer::isCorrectToRefSystem ( const align::Alignables coordDefiners) const

Definition at line 374 of file PedeSteerer.cc.

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

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

◆ isNoHiera()

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 144 of file PedeSteerer.cc.

References myNoHieraCollection.

Referenced by hierarchyConstraint().

144  {
145  return (myNoHieraCollection.find(ali) != myNoHieraCollection.end());
146 }
std::set< const Alignable * > myNoHieraCollection
keeps track of created &#39;secondary&#39; steering files
Definition: PedeSteerer.h:139

◆ parameterSign()

int PedeSteerer::parameterSign ( ) const
inline

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

Definition at line 68 of file PedeSteerer.h.

References myParameterSign.

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

68 { return myParameterSign; }
int myParameterSign
whether or not to fill pede steering files with debug info
Definition: PedeSteerer.h:132

◆ presigmas()

unsigned int PedeSteerer::presigmas ( const std::vector< edm::ParameterSet > &  cffPresi,
const std::string &  fileName,
const align::Alignables 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 alignableObjectId_, Exception, AlignableObjectId::idToString(), presigmasFile(), collectionMerger::selector, and nanoDQM_cfi::sels.

Referenced by buildSubSteer(), and presigmasFile().

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

◆ presigmasFile()

unsigned int PedeSteerer::presigmasFile ( const std::string &  fileName,
const align::Alignables alis,
const AlignablePresigmasMap aliPresisMap 
)
private

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

Definition at line 599 of file PedeSteerer.cc.

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

Referenced by presigmas().

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

◆ runPede()

int PedeSteerer::runPede ( const std::string &  masterSteer) const

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

Definition at line 795 of file PedeSteerer.cc.

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

795  {
796  if (masterSteer.empty()) {
797  edm::LogError("Alignment") << "@SUB=PedeSteerer::runPede"
798  << "Empty master steer file, stop";
799  return 0; //false;
800  }
801 
802  // Change pede command if running in different directory
804  if (myRunDirectory.empty()) {
806  (command += " ") += masterSteer;
807  } else {
808  command = "(cd " + myRunDirectory + " && ";
810  (command += " ") += "../" + masterSteer;
811  command += ")";
812  }
813 
815  if (!dump.empty()) {
816  command += " > ";
817  (command += myDirectory) += dump;
818  }
819 
820  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::runPede"
821  << "Start running " << command;
822  // FIXME: Recommended interface to system commands?
823  int shellReturn = gSystem->Exec(command.c_str());
824  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::runPede"
825  << "Command returns " << shellReturn;
826 
827  return shellReturn;
828 }
const edm::ParameterSet myConfig
Definition: PedeSteerer.h:127
std::string myDirectory
Definition: PedeSteerer.h:128
Log< level::Error, false > LogError
T getUntrackedParameter(std::string const &, T const &) const
std::string myRunDirectory
directory of all files
Definition: PedeSteerer.h:129
Log< level::Info, false > LogInfo
list command
Definition: mps_check.py:25

◆ selectCoordinateAlis()

align::Alignables PedeSteerer::selectCoordinateAlis ( const align::Alignables alis) 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 312 of file PedeSteerer.cc.

References Exception, SelectionUserVariables::fullSelection(), submitPVValidationJobs::params, and collectionMerger::selector.

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

Member Data Documentation

◆ alignableObjectId_

const AlignableObjectId PedeSteerer::alignableObjectId_
private

pointer to labeler (not the owner)

Definition at line 125 of file PedeSteerer.h.

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

◆ myConfig

const edm::ParameterSet PedeSteerer::myConfig
private

Definition at line 127 of file PedeSteerer.h.

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

◆ myDirectory

std::string PedeSteerer::myDirectory
private

Definition at line 128 of file PedeSteerer.h.

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

◆ myIsSteerFileDebug

bool PedeSteerer::myIsSteerFileDebug
private

flag to write steering files to /dev/null

Definition at line 131 of file PedeSteerer.h.

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

◆ myLabels

const PedeLabelerBase* PedeSteerer::myLabels
private

not the owner!

Definition at line 124 of file PedeSteerer.h.

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

◆ myNoHieraCollection

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

keeps track of created 'secondary' steering files

Definition at line 139 of file PedeSteerer.h.

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

◆ myNoSteerFiles

bool PedeSteerer::myNoSteerFiles
private

directory where pede is executed

Definition at line 130 of file PedeSteerer.h.

Referenced by createSteerFile().

◆ myParameterSign

int PedeSteerer::myParameterSign
private

whether or not to fill pede steering files with debug info

Definition at line 132 of file PedeSteerer.h.

Referenced by parameterSign().

◆ myParameterStore

const AlignmentParameterStore* PedeSteerer::myParameterStore
private

Definition at line 123 of file PedeSteerer.h.

Referenced by buildSubSteer(), and hierarchyConstraint().

◆ myRunDirectory

std::string PedeSteerer::myRunDirectory
private

directory of all files

Definition at line 129 of file PedeSteerer.h.

Referenced by buildMasterSteer(), and runPede().

◆ mySteeringFiles

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

precision for writing constraints to text file

Definition at line 137 of file PedeSteerer.h.

Referenced by buildMasterSteer(), and createSteerFile().

◆ theConstrPrecision

unsigned int PedeSteerer::theConstrPrecision
private

hierarchy constraints with less params are ignored

Definition at line 135 of file PedeSteerer.h.

Referenced by hierarchyConstraint().

◆ theCoordDefiners

align::Alignables PedeSteerer::theCoordDefiners
private

master coordinates, must (?) be global frame

Definition at line 141 of file PedeSteerer.h.

Referenced by buildSubSteer(), and correctToReferenceSystem().

◆ theCoordMaster

Alignable* PedeSteerer::theCoordMaster
private

Alignables deselected for hierarchy constr.

Definition at line 140 of file PedeSteerer.h.

Referenced by buildSubSteer(), and correctToReferenceSystem().

◆ theMinHieraConstrCoeff

double PedeSteerer::theMinHieraConstrCoeff
private

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

Definition at line 133 of file PedeSteerer.h.

Referenced by hierarchyConstraint().

◆ theMinHieraParPerConstr

unsigned int PedeSteerer::theMinHieraParPerConstr
private

min absolute value of coefficients in hierarchy constraints

Definition at line 134 of file PedeSteerer.h.

Referenced by hierarchyConstraint().