CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

edm::ParameterSet myConfig
 pointer to labeler (not the owner) More...
 
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 35 of file PedeSteerer.h.

Member Typedef Documentation

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

Definition at line 69 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(), AlignableExtras::components(), correctToReferenceSystem(), Exception, Alignable::globalPosition(), Alignable::id(), align::invalid, isCorrectToRefSystem(), GloballyPositioned< T >::move(), myDirectory, myParameterSign, myParameterStore, selectCoordinateAlis(), Alignable::surface(), theCoordDefiners, theCoordMaster, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

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

128 {
129  // delete theCoordMaster; NO, see above
130 }

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

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

Referenced by MillePedeAlignmentAlgorithm::terminate().

755 {
756  const std::string nameMasterSteer(this->fileName("Master"));
757  std::ofstream *mainSteerPtr = this->createSteerFile(nameMasterSteer, false);
758  if (!mainSteerPtr) 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(),
763  addfiles.begin(),
764  addfiles.end());
765 
766  // add steering files to master steering file
767  std::ofstream &mainSteerRef = *mainSteerPtr;
768  for (unsigned int iFile = 0; iFile < mySteeringFiles.size(); ++iFile) {
769  mainSteerRef << mySteeringFiles[iFile] << "\n";
770  }
771 
772  // add binary files to master steering file
773  mainSteerRef << "\nCfiles\n";
774  for (unsigned int iFile = 0; iFile < binaryFiles.size(); ++iFile) {
775  mainSteerRef << binaryFiles[iFile] << "\n";
776  }
777 
778  // add method
779  mainSteerRef << "\nmethod " << myConfig.getParameter<std::string>("method") << "\n";
780 
781  // add further options
782  const std::vector<std::string> opt(myConfig.getParameter<std::vector<std::string> >("options"));
783  mainSteerRef << "\n* Outlier treatment and other options \n";
784  for (unsigned int i = 0; i < opt.size(); ++i) {
785  mainSteerRef << opt[i] << "\n";
786  }
787 
788  delete mainSteerPtr; // close (and flush) again
789 
790  return nameMasterSteer;
791 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::ParameterSet myConfig
pointer to labeler (not the owner)
Definition: PedeSteerer.h:118
std::ofstream * createSteerFile(const std::string &name, bool addToList)
create and open file with name, if (addToList) append to mySteeringFiles
Definition: PedeSteerer.cc:642
std::vector< std::string > mySteeringFiles
precision for writing constraints to text file
Definition: PedeSteerer.h:127
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:661
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 160 of file PedeSteerer.cc.

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

Referenced by buildSubSteer().

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

Referenced by MillePedeAlignmentAlgorithm::initialize().

674 {
675  const std::vector<Alignable*> &alis = myParameterStore->alignables();
676 
677  if (theCoordMaster && !theCoordDefiners.empty()) {
678  const std::string nameCoordFile(this->fileName("Coord"));
679  this->defineCoordinates(theCoordDefiners, theCoordMaster, nameCoordFile);
680  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
681  << theCoordDefiners.size() << " highest level objects define the "
682  << "coordinate system, steering file " << nameCoordFile << ".";
683  }
684 
685  const std::string nameFixFile(this->fileName("FixPara"));
686  const std::pair<unsigned int, unsigned int> nFixFixCor(this->fixParameters(alis, nameFixFile));
687  if (nFixFixCor.first != 0 || nFixFixCor.second != 0) {
688  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
689  << nFixFixCor.first << " parameters fixed at 0. and "
690  << nFixFixCor.second << " at 'original' position, "
691  << "steering file " << nameFixFile << ".";
692  }
693 
694  if (this->buildNoHierarchyCollection(alis)) { // before hierarchyConstraints(..)
695  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
696  << myNoHieraCollection.size()<<" alignables taken out of hierarchy.";
697  }
698 
699  const std::string nameHierarchyFile(this->fileName("Hierarchy"));
700  unsigned int nConstraint = this->hierarchyConstraints(alis, nameHierarchyFile);
701  if (nConstraint) {
702  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
703  << "Hierarchy constraints for " << nConstraint << " alignables, "
704  << "steering file " << nameHierarchyFile << ".";
705  }
706 
707  //construct the systematic geometry deformations
708  if((myConfig.getParameter<std::vector<edm::ParameterSet> >("constraints")).size() > 0) {
709  PedeSteererWeakModeConstraints GeometryConstraints(aliTracker,
710  myLabels,
711  myConfig.getParameter<std::vector<edm::ParameterSet> >("constraints"),
712  myConfig.getParameter<std::string>("steerFile"));
713 
714  //prepare the output files
715  //Get the data structure in which the configuration data are stored.
716  //The relation between the ostream* and the corresponding file name needs to be filled
717  std::list<GeometryConstraintConfigData>* ConstraintsConfigContainer = GeometryConstraints.getConfigData();
718 
719  //loop over all configured constraints
720  for(std::list<GeometryConstraintConfigData>::iterator it = ConstraintsConfigContainer->begin();
721  it != ConstraintsConfigContainer->end(); it++) {
722  //each level has its own constraint which means the output is stored in a separate file
723  for(std::vector<std::pair<Alignable*, std::string> >::const_iterator ilevelsFilename = it->levelsFilenames_.begin();
724  ilevelsFilename != it->levelsFilenames_.end(); ilevelsFilename++) {
725  it->mapFileName_.insert(
726  std::pair<std::string, std::ofstream*>
727  (ilevelsFilename->second,this->createSteerFile(ilevelsFilename->second,true))
728  );
729 
730  }
731  }
732 
733  unsigned int nGeometryConstraint = GeometryConstraints.constructConstraints(alis);
734  if (nGeometryConstraint) {
735  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::buildSubSteer"
736  << "Geometry constraints for " << nGeometryConstraint << " alignables.";
737  }
738  }
739 
740  const std::string namePresigmaFile(this->fileName("Presigma"));
741  unsigned int nPresigma =
742  this->presigmas(myConfig.getParameter<std::vector<edm::ParameterSet> >("Presigmas"),
743  namePresigmaFile, alis, aliTracker, aliMuon, 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 }
T getParameter(std::string const &) const
std::vector< Alignable * > theCoordDefiners
master coordinates, must (?) be global frame
Definition: PedeSteerer.h:131
Alignable * theCoordMaster
Alignables deselected for hierarchy constr.
Definition: PedeSteerer.h:130
std::set< const Alignable * > myNoHieraCollection
keeps track of created &#39;secondary&#39; steering files
Definition: PedeSteerer.h:129
edm::ParameterSet myConfig
pointer to labeler (not the owner)
Definition: PedeSteerer.h:118
unsigned int hierarchyConstraints(const std::vector< Alignable * > &alis, const std::string &file)
Definition: PedeSteerer.cc:442
const PedeLabelerBase * myLabels
not the owner!
Definition: PedeSteerer.h:116
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:548
const AlignmentParameterStore * myParameterStore
Definition: PedeSteerer.h:115
std::pair< unsigned int, unsigned int > fixParameters(const std::vector< Alignable * > &alignables, const std::string &file)
Definition: PedeSteerer.cc:230
std::string fileName(const std::string &addendum) const
full name with directory and &#39;idenitfier&#39;
Definition: PedeSteerer.cc:661
unsigned int buildNoHierarchyCollection(const std::vector< Alignable * > &alis)
Definition: PedeSteerer.cc:160
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:346
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 202 of file PedeSteerer.cc.

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

Referenced by PedeSteerer().

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

140 {
141  return 1.; // mmh, otherwise would need to FIXME hierarchyConstraint...
142 
143  switch (parNum) {
146  return 1000.; // cm to mum *1/10 to get smaller values
148  return 2500.; // cm to mum *1/4
151  return 1000.; // rad to mrad (no first guess for sensitivity yet)
153  return 10000.; // rad to mrad *10 to get larger values
154  default:
155  return 1.;
156  }
157 }
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 394 of file PedeSteerer.cc.

References AlCaHLTBitMon_QueryRunRegistry::comp, alignCSCRings::e, Alignable::move(), Alignable::rotateInGlobalFrame(), theCoordDefiners, theCoordMaster, and align::toMatrix().

Referenced by PedeSteerer().

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

References Exception, myNoSteerFiles, mySteeringFiles, dbtoconf::out, query::result, and AlCaHLTBitMon_QueryRunRegistry::string.

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

643 {
644  const std::string realName(myNoSteerFiles ? "/dev/null" : name.c_str());
645 
646  std::ofstream *result = new std::ofstream(realName.c_str(), std::ios::out);
647  if (!result || !result->is_open()) {
648  delete result; // needed before exception in case just open failed
649  throw cms::Exception("FileOpenProblem") << "[PedeSteerer::createSteerFile]"
650  << "Could not open " << realName
651  << " as output file.";
652  } else if (addToList) {
653  mySteeringFiles.push_back(realName); // keep track
654  }
655 
656  return result;
657 }
tuple result
Definition: query.py:137
tuple out
Definition: dbtoconf.py:99
bool myNoSteerFiles
directory of all files
Definition: PedeSteerer.h:120
std::vector< std::string > mySteeringFiles
precision for writing constraints to text file
Definition: PedeSteerer.h:127
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 346 of file PedeSteerer.cc.

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

Referenced by buildSubSteer().

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

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

Definition at line 66 of file PedeSteerer.h.

References myDirectory.

Referenced by PedeReader::PedeReader().

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

full name with directory and 'idenitfier'

Definition at line 661 of file PedeSteerer.cc.

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

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

662 {
663 
665  name += myConfig.getParameter<std::string>("steerFile");
666  name += addendum;
667  name += ".txt";
668 
669  return name;
670 }
T getParameter(std::string const &) const
std::string myDirectory
Definition: PedeSteerer.h:119
edm::ParameterSet myConfig
pointer to labeler (not the owner)
Definition: PedeSteerer.h:118
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 264 of file PedeSteerer.cc.

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

Referenced by fixParameters().

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

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

Referenced by buildSubSteer().

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

Definition at line 478 of file PedeSteerer.cc.

References PedeLabelerBase::alignableLabel(), Alignable::alignableObjectId(), plotBeamSpotDB::first, 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().

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

Definition at line 442 of file PedeSteerer.cc.

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

Referenced by buildSubSteer().

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

Definition at line 368 of file PedeSteerer.cc.

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

Referenced by PedeSteerer().

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

References myNoHieraCollection.

Referenced by hierarchyConstraint().

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

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

Definition at line 64 of file PedeSteerer.h.

References myParameterSign.

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

64 { return myParameterSign; }
int myParameterSign
whether or not to fill pede steering files with debug info
Definition: PedeSteerer.h:122
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 548 of file PedeSteerer.cc.

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

Referenced by buildSubSteer(), and presigmasFile().

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

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

Referenced by presigmas().

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

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

Definition at line 794 of file PedeSteerer.cc.

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

Referenced by MillePedeAlignmentAlgorithm::terminate().

795 {
796  if (masterSteer.empty()) {
797  edm::LogError("Alignment") << "@SUB=PedeSteerer::runPede" << "Empty master steer file, stop";
798  return 0; //false;
799  }
800 
802  (command += " ") += masterSteer;
804  if (!dump.empty()) {
805  command += " > ";
806  (command += myDirectory) += dump;
807  }
808 
809  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::runPede" << "Start running " << command;
810  // FIXME: Recommended interface to system commands?
811  int shellReturn = gSystem->Exec(command.c_str());
812  edm::LogInfo("Alignment") << "@SUB=PedeSteerer::runPede" << "Command returns " << shellReturn;
813 
814  return shellReturn;
815 }
T getUntrackedParameter(std::string const &, T const &) const
std::string myDirectory
Definition: PedeSteerer.h:119
edm::ParameterSet myConfig
pointer to labeler (not the owner)
Definition: PedeSteerer.h:118
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 303 of file PedeSteerer.cc.

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

Referenced by PedeSteerer().

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

Member Data Documentation

edm::ParameterSet PedeSteerer::myConfig
private

pointer to labeler (not the owner)

Definition at line 118 of file PedeSteerer.h.

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

std::string PedeSteerer::myDirectory
private

Definition at line 119 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 121 of file PedeSteerer.h.

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

const PedeLabelerBase* PedeSteerer::myLabels
private

not the owner!

Definition at line 116 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 129 of file PedeSteerer.h.

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

bool PedeSteerer::myNoSteerFiles
private

directory of all files

Definition at line 120 of file PedeSteerer.h.

Referenced by createSteerFile().

int PedeSteerer::myParameterSign
private

whether or not to fill pede steering files with debug info

Definition at line 122 of file PedeSteerer.h.

Referenced by parameterSign(), and PedeSteerer().

const AlignmentParameterStore* PedeSteerer::myParameterStore
private

Definition at line 115 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 127 of file PedeSteerer.h.

Referenced by buildMasterSteer(), and createSteerFile().

unsigned int PedeSteerer::theConstrPrecision
private

hierarchy constraints with less params are ignored

Definition at line 125 of file PedeSteerer.h.

Referenced by hierarchyConstraint().

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

master coordinates, must (?) be global frame

Definition at line 131 of file PedeSteerer.h.

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

Alignable* PedeSteerer::theCoordMaster
private

Alignables deselected for hierarchy constr.

Definition at line 130 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 123 of file PedeSteerer.h.

Referenced by hierarchyConstraint().

unsigned int PedeSteerer::theMinHieraParPerConstr
private

min absolute value of coefficients in hierarchy constraints

Definition at line 124 of file PedeSteerer.h.

Referenced by hierarchyConstraint().