Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:37

0001 #ifndef PEDESTEERER_H
0002 #define PEDESTEERER_H
0003 
0004 /**
0005  * \class PedeSteerer
0006  *
0007  * provides steering for pede according to configuration
0008  *
0009  * \author    : Gero Flucke
0010  * date       : October 2006
0011  * $Date: 2013/06/18 13:31:29 $
0012  * $Revision: 1.29 $
0013  * (last update by $Author: jbehr $)
0014  */
0015 
0016 #include <vector>
0017 #include <map>
0018 #include <set>
0019 #include <string>
0020 // forward ofstream:
0021 #include <iosfwd>
0022 
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "Alignment/CommonAlignment/interface/Utilities.h"
0025 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
0026 
0027 class Alignable;
0028 class AlignableTracker;
0029 class AlignableMuon;
0030 class AlignableExtras;
0031 class AlignmentParameterStore;
0032 class PedeLabelerBase;
0033 class PedeSteererWeakModeConstraints;
0034 
0035 /***************************************
0036 ****************************************/
0037 class PedeSteerer {
0038 public:
0039   /// constructor from AlignableTracker/AlignableMuon, their AlignmentParameterStore and the labeler
0040   /// (NOTE: The latter two must live longer than the constructed PedeSteerer!)
0041   PedeSteerer(AlignableTracker *aliTracker,
0042               AlignableMuon *aliMuon,
0043               AlignableExtras *aliExtras,
0044               AlignmentParameterStore *store,
0045               const PedeLabelerBase *labels,
0046               const edm::ParameterSet &config,
0047               const std::string &defaultDir,
0048               bool noSteerFiles);
0049   /** non-virtual destructor: do not inherit from this class **/
0050   ~PedeSteerer();
0051 
0052   /// True if 'ali' was deselected from hierarchy and any ancestor (e.g. mother) has parameters.
0053   bool isNoHiera(const Alignable *ali) const;
0054 
0055   /// construct steering files about hierarchy, fixing etc. an keep track of their names
0056   void buildSubSteer(AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras);
0057   /// construct (and return name of) master steering file from config, binaryFiles etc.
0058   std::string buildMasterSteer(const std::vector<std::string> &binaryFiles);
0059   /// run pede, masterSteer should be as returned from buildMasterSteer(...)
0060   int runPede(const std::string &masterSteer) const;
0061   /// If reference alignables have been configured, shift everything such that mean
0062   /// position and orientation of dets in these alignables are zero.
0063   void correctToReferenceSystem();
0064   bool isCorrectToRefSystem(const align::Alignables &coordDefiners) const;
0065 
0066   double cmsToPedeFactor(unsigned int parNum) const;
0067   /// results from pede (and start values for pede) might need a sign flip
0068   int parameterSign() const { return myParameterSign; }
0069   /// directory from constructor input, '/' is attached if needed
0070   const std::string &directory() const { return myDirectory; }
0071 
0072 private:
0073   typedef std::map<const Alignable *, std::vector<float> > AlignablePresigmasMap;
0074 
0075   /// Checks whether SelectionUserVariables that might be attached to alis' AlignmentParameters
0076   /// (these must exist) are all known.
0077   bool checkParameterChoices(const align::Alignables &) const;
0078   /// Store Alignables that have SelectionUserVariables attached to their AlignmentParameters
0079   /// (these must exist) that indicate removal from hierarchy, i.e. make it 'top level'.
0080   unsigned int buildNoHierarchyCollection(const align::Alignables &);
0081   /// Checks whether 'alignables' have SelectionUserVariables attached to their AlignmentParameters
0082   /// (these must exist) that indicate fixation of a parameter, a steering 'file'
0083   /// is created accordingly.
0084   /// Returns number of parameters fixed at 0 and at 'nominal truth'.
0085   std::pair<unsigned int, unsigned int> fixParameters(const align::Alignables &, const std::string &file);
0086   /// If 'selector' means fixing, create corresponding steering file line in file pointed to
0087   /// by 'filePtr'. If 'filePtr == 0' create file with name 'fileName'
0088   /// (and return pointer via reference).
0089   int fixParameter(Alignable *ali,
0090                    unsigned int iRunRange,
0091                    unsigned int iParam,
0092                    char selector,
0093                    std::ofstream *&filePtr,
0094                    const std::string &fileName);
0095   /// Return 'alignables' that have SelectionUserVariables attached to their AlignmentParameters
0096   /// (these must exist) that indicate a definition of a coordinate system.
0097   /// Throws if ill defined reference objects.
0098   align::Alignables selectCoordinateAlis(const align::Alignables &) const;
0099   /// Create steering file with constraints defining coordinate system via hierarchy constraints
0100   /// between 'aliMaster' and 'alis'; 'aliMaster' must not have parameters: would not make sense!
0101   void defineCoordinates(const align::Alignables &, Alignable *aliMaster, const std::string &fileName);
0102 
0103   unsigned int hierarchyConstraints(const align::Alignables &, const std::string &file);
0104   void hierarchyConstraint(const Alignable *ali, const align::Alignables &components, std::ofstream &file) const;
0105 
0106   /// interprete content of presigma VPSet 'cffPresi' and call presigmasFile
0107   unsigned int presigmas(const std::vector<edm::ParameterSet> &cffPresi,
0108                          const std::string &fileName,
0109                          const align::Alignables &,
0110                          AlignableTracker *aliTracker,
0111                          AlignableMuon *aliMuon,
0112                          AlignableExtras *aliExtras);
0113   /// look for active 'alis' in map of presigma values and create steering file
0114   unsigned int presigmasFile(const std::string &fileName,
0115                              const align::Alignables &,
0116                              const AlignablePresigmasMap &aliPresisMap);
0117   /// full name with directory and 'idenitfier'
0118   std::string fileName(const std::string &addendum) const;
0119   /// create and open file with name, if (addToList) append to mySteeringFiles
0120   std::ofstream *createSteerFile(const std::string &name, bool addToList);
0121 
0122   // data members
0123   const AlignmentParameterStore *myParameterStore;  /// not the owner!
0124   const PedeLabelerBase *myLabels;                  /// pointer to labeler (not the owner)
0125   const AlignableObjectId alignableObjectId_;
0126 
0127   const edm::ParameterSet myConfig;
0128   std::string myDirectory;               /// directory of all files
0129   std::string myRunDirectory;            /// directory where pede is executed
0130   bool myNoSteerFiles;                   /// flag to write steering files to /dev/null
0131   bool myIsSteerFileDebug;               /// whether or not to fill pede steering files with debug info
0132   int myParameterSign;                   /// old pede versions (before May '07) need a sign flip...
0133   double theMinHieraConstrCoeff;         /// min absolute value of coefficients in hierarchy constraints
0134   unsigned int theMinHieraParPerConstr;  /// hierarchy constraints with less params are ignored
0135   unsigned int theConstrPrecision;       /// precision for writing constraints to text file
0136 
0137   std::vector<std::string> mySteeringFiles;  /// keeps track of created 'secondary' steering files
0138 
0139   std::set<const Alignable *> myNoHieraCollection;  /// Alignables deselected for hierarchy constr.
0140   Alignable *theCoordMaster;                        /// master coordinates, must (?) be global frame
0141   align::Alignables theCoordDefiners;               /// Alignables selected to define coordinates
0142 };
0143 
0144 #endif