CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Alignment/MillePedeAlignmentAlgorithm/interface/MillePedeAlignmentAlgorithm.h

Go to the documentation of this file.
00001 #ifndef Alignment_MillePedeAlignmentAlgorithm_MillePedeAlignmentAlgorithm_h
00002 #define Alignment_MillePedeAlignmentAlgorithm_MillePedeAlignmentAlgorithm_h
00003 
00013 
00014 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmBase.h"
00015 
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 
00018 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00019 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00020 
00021 #include "Alignment/ReferenceTrajectories/interface/ReferenceTrajectoryBase.h"
00022 
00023 #include <vector>
00024 #include <string>
00025 
00026 #include <TMatrixDSym.h>
00027 #include <TMatrixD.h>
00028 #include <TMatrixF.h>
00029 
00030 class Alignable;
00031 class AlignableTracker;
00032 class AlignableMuon;
00033 class AlignableExtras;
00034 
00035 class AlignmentParameters;
00036 class AlignableNavigator;
00037 class AlignableDetOrUnitPtr;
00038 class AlignmentUserVariables;
00039 
00040 class AlignmentParameterStore;
00041 
00042 class IntegratedCalibrationBase;
00043 
00044 class MillePedeMonitor;
00045 class PedeSteerer;
00046 class PedeLabelerBase;
00047 class Mille;
00048 class TrajectoryFactoryBase;
00049 
00050 // already from base class - and forward declaration does not work since typedef!
00051 /* class TkFittedLasBeamCollection; */
00052 /* class TsosVectorCollection; */
00053 
00054 class MillePedeAlignmentAlgorithm : public AlignmentAlgorithmBase
00055 {
00056  public:
00058   MillePedeAlignmentAlgorithm(const edm::ParameterSet &cfg);
00059 
00061   virtual ~MillePedeAlignmentAlgorithm();
00062 
00064   virtual void initialize(const edm::EventSetup &setup,
00065                           AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras,
00066                           AlignmentParameterStore *store);
00067 
00069   virtual bool addCalibrations(const std::vector<IntegratedCalibrationBase*> &iCals);
00070 
00072   virtual void terminate(const edm::EventSetup& iSetup);
00073 
00075   virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo);
00076 
00078   virtual void endRun(const EventInfo &eventInfo, const EndRunInfo &runInfo,
00079                       const edm::EventSetup &setup);
00080 
00081 /*   virtual void beginLuminosityBlock(const edm::EventSetup &setup) {} */
00082 /*   virtual void endLuminosityBlock(const edm::EventSetup &setup) {} */
00083 
00086   virtual bool setParametersForRunRange(const RunRange &runrange);
00087 
00088  private:
00089   enum MeasurementDirection {kLocalX = 0, kLocalY};
00090 
00092   std::pair<unsigned int, unsigned int>
00093     addReferenceTrajectory(const edm::EventSetup &setup, const EventInfo &eventInfo, 
00094                            const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr);
00095 
00099   int addMeasurementData(const edm::EventSetup &setup, const EventInfo &eventInfo, 
00100                          const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
00101                          unsigned int iHit, AlignmentParameters *&params);
00102 
00107   unsigned int addHitCount(const std::vector<AlignmentParameters*> &parVec,
00108                            const std::vector<bool> &validHitVecY) const;
00109 
00111   void addRefTrackData2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
00112                          unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
00113                          TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM);
00114   
00116   void addVirtualMeas(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
00117                       unsigned int iVirtualMeas);
00118                            
00120   void addRefTrackVirtualMeas1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
00121                                 unsigned int iVirtualMeas,TMatrixDSym &aHitCovarianceM,
00122                                 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM);
00123   
00125   bool globalDerivativesHierarchy(const EventInfo &eventInfo, 
00126                                   const TrajectoryStateOnSurface &tsos,
00127                                   Alignable *ali, const AlignableDetOrUnitPtr &alidet,
00128                                   std::vector<float> &globalDerivativesX,
00129                                   std::vector<float> &globalDerivativesY,
00130                                   std::vector<int> &globalLabels,
00131                                   AlignmentParameters *&lowestParams) const;
00132 
00134   void globalDerivativesCalibration(const TransientTrackingRecHit::ConstRecHitPointer &recHit,
00135                                     const TrajectoryStateOnSurface &tsos,
00136                                     const edm::EventSetup &setup, const EventInfo &eventInfo,
00137                                     std::vector<float> &globalDerivativesX,
00138                                     std::vector<float> &globalDerivativesY,
00139                                     std::vector<int> &globalLabels) const;
00140 
00142   int callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
00143                 unsigned int iTrajHit, const std::vector<int> &globalLabels,
00144                 const std::vector<float> &globalDerivativesX,
00145                 const std::vector<float> &globalDerivativesY);
00146 
00148   int callMille1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
00149                   unsigned int iTrajHit, const std::vector<int> &globalLabels,
00150                   const std::vector<float> &globalDerivativesX);
00151 
00155   int callMille2D ( const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
00156                     unsigned int iTrajHit, const std::vector<int> &globalLabels,
00157                     const std::vector<float> &globalDerivativesx,
00158                     const std::vector<float> &globalDerivativesy);
00159   void  diagonalize(TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM,
00160                     TMatrixF &aHitResidualsM,TMatrixF &theGlobalDerivativesM) const;
00161   // deals with the non matrix format of theFloatBufferX ...
00162   void makeGlobDerivMatrix(const std::vector<float> &globalDerivativesx,
00163                            const std::vector<float> &globalDerivativesy,
00164                            TMatrixF &aGlobalDerivativesM);
00165 
00166 //   void callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, 
00167 //               unsigned int iTrajHit, MeasurementDirection xOrY,
00168 //               const std::vector<float> &globalDerivatives, const std::vector<int> &globalLabels);
00170   bool is2D(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const;
00171 
00173   bool readFromPede(const edm::ParameterSet &mprespset, bool setUserVars,
00174                     const RunRange &runrange);
00175   bool areEmptyParams(const std::vector<Alignable*> &alignables) const;
00176   unsigned int doIO(int loop) const;
00178   void buildUserVariables(const std::vector<Alignable*> &alignables) const;
00179 
00180   void addLaserData(const EventInfo &eventInfo, 
00181                     const TkFittedLasBeamCollection &tkLasBeams,
00182                     const TsosVectorCollection &tkLasBeamTsoses);
00183   void addLasBeam(const EventInfo &eventInfo, 
00184                   const TkFittedLasBeam &lasBeam,
00185                   const std::vector<TrajectoryStateOnSurface> &tsoses);
00186 
00188   void addPxbSurvey(const edm::ParameterSet &pxbSurveyCfg);
00189 
00190   //--------------------------------------------------------
00191   // Data members
00192   //--------------------------------------------------------
00193   enum EModeBit {myMilleBit = 1 << 0, myPedeRunBit = 1 << 1, myPedeSteerBit = 1 << 2,
00194                  myPedeReadBit = 1 << 3};
00195   unsigned int decodeMode(const std::string &mode) const;
00196   bool isMode(unsigned int testMode) const {return (theMode & testMode);}
00197   bool addHitStatistics(int fromLoop, const std::string &outFile,
00198                         const std::vector<std::string> &inFiles) const;
00199   bool addHits(const std::vector<Alignable*> &alis,
00200                const std::vector<AlignmentUserVariables*> &mpVars) const;
00201 
00202   edm::ParameterSet         theConfig;
00203   unsigned int              theMode;
00204   std::string               theDir; 
00205   AlignmentParameterStore  *theAlignmentParameterStore;
00206   std::vector<Alignable*>   theAlignables;
00207   AlignableNavigator       *theAlignableNavigator;
00208   MillePedeMonitor         *theMonitor;
00209   Mille                    *theMille;
00210   PedeLabelerBase          *thePedeLabels;
00211   PedeSteerer              *thePedeSteer;
00212   TrajectoryFactoryBase    *theTrajectoryFactory;
00213   std::vector<IntegratedCalibrationBase*> theCalibrations;
00214   unsigned int              theMinNumHits;
00215   double                    theMaximalCor2D; 
00216 
00217   int                       theLastWrittenIov; // keeping track for output trees...
00218   std::vector<float>        theFloatBufferX;
00219   std::vector<float>        theFloatBufferY;
00220   std::vector<int>          theIntBuffer;
00221   bool                      theDoSurveyPixelBarrel;
00222 };
00223 
00224 #endif