CMS 3D CMS Logo

MillePedeAlignmentAlgorithm.h
Go to the documentation of this file.
1 #ifndef Alignment_MillePedeAlignmentAlgorithm_MillePedeAlignmentAlgorithm_h
2 #define Alignment_MillePedeAlignmentAlgorithm_MillePedeAlignmentAlgorithm_h
3 
13 
16 
18 
21 
24 
25 #include <vector>
26 #include <string>
27 #include <memory>
28 
29 class Alignable;
30 class AlignableTracker;
31 class AlignableMuon;
32 class AlignableExtras;
33 
35 class AlignableNavigator;
38 
40 
42 
43 class MillePedeMonitor;
44 class PedeSteerer;
45 class PedeLabelerBase;
46 class Mille;
48 
49 // already from base class - and forward declaration does not work since typedef!
50 /* class TkFittedLasBeamCollection; */
51 /* class TsosVectorCollection; */
52 
54 {
55  public:
58 
61 
63  void initialize(const edm::EventSetup &setup,
65  AlignmentParameterStore *store) override;
66 
68  bool supportsCalibrations() override;
70  bool addCalibrations(const std::vector<IntegratedCalibrationBase*> &iCals) override;
71 
72  virtual bool storeThresholds(const int & nRecords,const AlignPCLThresholds::threshold_map & thresholdMap);
73 
75  void terminate(const edm::EventSetup& iSetup) override;
77  void terminate() override;
78 
80  bool processesEvents() override;
81 
83  bool storeAlignments() override;
84 
86  void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override;
87 
89  void beginRun(const edm::Run& run,
90  const edm::EventSetup& setup,
91  bool changed) override;
92 
93  // TODO: This method does NOT match endRun() in base class! Nobody is
94  // calling this?
96  virtual void endRun(const EventInfo&, const EndRunInfo&,
97  const edm::EventSetup&); //override;
98 
99  // This one will be called since it matches the interface of the base class
100  void endRun(const EndRunInfo &runInfo, const edm::EventSetup &setup) override;
101 
103  void beginLuminosityBlock(const edm::EventSetup&) override;
104 
106  void endLuminosityBlock(const edm::EventSetup&) override;
107 
108 
109 /* virtual void beginLuminosityBlock(const edm::EventSetup &setup) {} */
110 /* virtual void endLuminosityBlock(const edm::EventSetup &setup) {} */
111 
114  bool setParametersForRunRange(const RunRange &runrange) override;
115 
116  private:
118 
120  std::pair<unsigned int, unsigned int>
121  addReferenceTrajectory(const edm::EventSetup &setup, const EventInfo &eventInfo,
123 
127  int addMeasurementData(const edm::EventSetup &setup, const EventInfo &eventInfo,
129  unsigned int iHit, AlignmentParameters *&params);
130 
133  int addGlobalData(const edm::EventSetup &setup, const EventInfo &eventInfo,
135  unsigned int iHit, gbl::GblPoint &gblPoint);
136 
141  unsigned int addHitCount(const std::vector<AlignmentParameters*> &parVec,
142  const std::vector<bool> &validHitVecY) const;
143 
145  template <typename CovarianceMatrix,
146  typename ResidualMatrix,
147  typename LocalDerivativeMatrix>
149  unsigned int iTrajHit,
150  Eigen::MatrixBase<CovarianceMatrix>& aHitCovarianceM,
151  Eigen::MatrixBase<ResidualMatrix>& aHitResidualsM,
152  Eigen::MatrixBase<LocalDerivativeMatrix>& aLocalDerivativesM);
153 
156  unsigned int iVirtualMeas);
157 
159  template <typename CovarianceMatrix,
160  typename ResidualMatrix,
161  typename LocalDerivativeMatrix>
163  unsigned int iVirtualMeas,
164  Eigen::MatrixBase<CovarianceMatrix>& aHitCovarianceM,
165  Eigen::MatrixBase<ResidualMatrix>& aHitResidualsM,
166  Eigen::MatrixBase<LocalDerivativeMatrix>& aLocalDerivativesM);
167 
169  bool globalDerivativesHierarchy(const EventInfo &eventInfo,
170  const TrajectoryStateOnSurface &tsos,
171  Alignable *ali, const AlignableDetOrUnitPtr &alidet,
172  std::vector<float> &globalDerivativesX,
173  std::vector<float> &globalDerivativesY,
174  std::vector<int> &globalLabels,
175  AlignmentParameters *&lowestParams) const;
176 
178  bool globalDerivativesHierarchy(const EventInfo &eventInfo,
179  const TrajectoryStateOnSurface &tsos,
180  Alignable *ali, const AlignableDetOrUnitPtr &alidet,
181  std::vector<double> &globalDerivativesX,
182  std::vector<double> &globalDerivativesY,
183  std::vector<int> &globalLabels,
184  AlignmentParameters *&lowestParams) const;
185 
188  const TrajectoryStateOnSurface &tsos,
189  const edm::EventSetup &setup, const EventInfo &eventInfo,
190  std::vector<float> &globalDerivativesX,
191  std::vector<float> &globalDerivativesY,
192  std::vector<int> &globalLabels) const;
193 
196  unsigned int iTrajHit, const std::vector<int> &globalLabels,
197  const std::vector<float> &globalDerivativesX,
198  const std::vector<float> &globalDerivativesY);
199 
202  unsigned int iTrajHit, const std::vector<int> &globalLabels,
203  const std::vector<float> &globalDerivativesX);
204 
209  unsigned int iTrajHit, const std::vector<int> &globalLabels,
210  const std::vector<float> &globalDerivativesx,
211  const std::vector<float> &globalDerivativesy);
212 
213  template <typename CovarianceMatrix,
214  typename LocalDerivativeMatrix,
215  typename ResidualMatrix,
216  typename GlobalDerivativeMatrix>
217  void diagonalize(Eigen::MatrixBase<CovarianceMatrix>& aHitCovarianceM,
218  Eigen::MatrixBase<LocalDerivativeMatrix>& aLocalDerivativesM,
219  Eigen::MatrixBase<ResidualMatrix>& aHitResidualsM,
220  Eigen::MatrixBase<GlobalDerivativeMatrix>& aGlobalDerivativesM) const;
221 
222  // deals with the non matrix format of theFloatBufferX ...
223  template <typename GlobalDerivativeMatrix>
224  void makeGlobDerivMatrix(const std::vector<float> &globalDerivativesx,
225  const std::vector<float> &globalDerivativesy,
226  Eigen::MatrixBase<GlobalDerivativeMatrix>& aGlobalDerivativesM);
227 
228 // void callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
229 // unsigned int iTrajHit, MeasurementDirection xOrY,
230 // const std::vector<float> &globalDerivatives, const std::vector<int> &globalLabels);
232  bool is2D(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const;
233 
235  bool readFromPede(const edm::ParameterSet &mprespset, bool setUserVars,
236  const RunRange &runrange);
237  bool areEmptyParams(const align::Alignables& alignables) const;
238  unsigned int doIO(int loop) const;
240  void buildUserVariables(const align::Alignables& alignables) const;
241 
244  std::vector<std::string> getExistingFormattedFiles(const std::vector<std::string>& plainFiles, const std::string& theDir);
245 
246  void addLaserData(const EventInfo &eventInfo,
247  const TkFittedLasBeamCollection &tkLasBeams,
248  const TsosVectorCollection &tkLasBeamTsoses);
249  void addLasBeam(const EventInfo &eventInfo,
250  const TkFittedLasBeam &lasBeam,
251  const std::vector<TrajectoryStateOnSurface> &tsoses);
252 
254  void addPxbSurvey(const edm::ParameterSet &pxbSurveyCfg);
255 
256  //
257  bool areIOVsSpecified() const;
258 
259  //--------------------------------------------------------
260  // Data members
261  //--------------------------------------------------------
262  enum EModeBit {myMilleBit = 1 << 0, myPedeRunBit = 1 << 1, myPedeSteerBit = 1 << 2,
263  myPedeReadBit = 1 << 3};
264  unsigned int decodeMode(const std::string &mode) const;
265  bool isMode(unsigned int testMode) const {return (theMode & testMode);}
266  bool addHitStatistics(int fromLoop, const std::string &outFile,
267  const std::vector<std::string> &inFiles) const;
268  bool addHits(const align::Alignables& alis,
269  const std::vector<AlignmentUserVariables*> &mpVars) const;
270 
272  unsigned int theMode;
276  std::unique_ptr<AlignableNavigator> theAlignableNavigator;
277  std::unique_ptr<MillePedeMonitor> theMonitor;
278  std::unique_ptr<Mille> theMille;
279  std::shared_ptr<PedeLabelerBase> thePedeLabels;
280  std::unique_ptr<PedeSteerer> thePedeSteer;
281  std::unique_ptr<TrajectoryFactoryBase> theTrajectoryFactory;
282  std::vector<IntegratedCalibrationBase*> theCalibrations;
283  std::shared_ptr<AlignPCLThresholds> theThresholds;
284  unsigned int theMinNumHits;
290  int theLastWrittenIov; // keeping track for output trees...
291  std::vector<float> theFloatBufferX;
292  std::vector<float> theFloatBufferY;
293  std::vector<int> theIntBuffer;
295  // CHK for GBL
296  std::unique_ptr<gbl::MilleBinary> theBinary;
298 
299  const bool runAtPCL_;
302 
305  std::vector<align::RunNumber> cachedRuns_;
307 };
308 
310  MillePedeAlignmentAlgorithm, "MillePedeAlignmentAlgorithm");
311 #endif
bool processesEvents() override
Returns whether MP should process events in the current configuration.
void globalDerivativesCalibration(const TransientTrackingRecHit::ConstRecHitPointer &recHit, const TrajectoryStateOnSurface &tsos, const edm::EventSetup &setup, const EventInfo &eventInfo, std::vector< float > &globalDerivativesX, std::vector< float > &globalDerivativesY, std::vector< int > &globalLabels) const
adding derivatives from integrated calibrations
bool supportsCalibrations() override
Returns whether MP supports calibrations.
std::unique_ptr< MillePedeMonitor > theMonitor
bool setParametersForRunRange(const RunRange &runrange) override
virtual void endRun(const EventInfo &, const EndRunInfo &, const edm::EventSetup &)
Run on run products, e.g. TkLAS.
std::shared_ptr< AlignPCLThresholds > theThresholds
void diagonalize(Eigen::MatrixBase< CovarianceMatrix > &aHitCovarianceM, Eigen::MatrixBase< LocalDerivativeMatrix > &aLocalDerivativesM, Eigen::MatrixBase< ResidualMatrix > &aHitResidualsM, Eigen::MatrixBase< GlobalDerivativeMatrix > &aGlobalDerivativesM) const
bool areEmptyParams(const align::Alignables &alignables) const
void endLuminosityBlock(const edm::EventSetup &) override
called at end of luminosity block
void buildUserVariables(const align::Alignables &alignables) const
add MillePedeVariables for each AlignmentParameters (exception if no parameters...)
std::unique_ptr< TrajectoryFactoryBase > theTrajectoryFactory
std::vector< RunRange > RunRanges
Definition: Utilities.h:40
std::unique_ptr< gbl::MilleBinary > theBinary
int addGlobalData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, gbl::GblPoint &gblPoint)
bool globalDerivativesHierarchy(const EventInfo &eventInfo, const TrajectoryStateOnSurface &tsos, Alignable *ali, const AlignableDetOrUnitPtr &alidet, std::vector< float > &globalDerivativesX, std::vector< float > &globalDerivativesY, std::vector< int > &globalLabels, AlignmentParameters *&lowestParams) const
recursively adding derivatives and labels, false if problems
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
std::shared_ptr< PedeLabelerBase > thePedeLabels
std::vector< std::string > getExistingFormattedFiles(const std::vector< std::string > &plainFiles, const std::string &theDir)
unsigned int addHitCount(const std::vector< AlignmentParameters * > &parVec, const std::vector< bool > &validHitVecY) const
bool addCalibrations(const std::vector< IntegratedCalibrationBase * > &iCals) override
Pass integrated calibrations to Millepede (they are not owned by Millepede!)
int callMille2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy)
math::Error< 5 >::type CovarianceMatrix
Interface/Base class for alignment algorithms, each alignment algorithm has to be derived from this c...
void addLasBeam(const EventInfo &eventInfo, const TkFittedLasBeam &lasBeam, const std::vector< TrajectoryStateOnSurface > &tsoses)
define event information passed to algorithms
unsigned int doIO(int loop) const
int callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX, const std::vector< float > &globalDerivativesY)
calls callMille1D or callMille2D
void beginLuminosityBlock(const edm::EventSetup &) override
called at begin of luminosity block (resets Mille binary in mille mode)
std::vector< align::RunNumber > cachedRuns_
int callMille1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX)
calls Mille for 1D hits
void addLaserData(const EventInfo &eventInfo, const TkFittedLasBeamCollection &tkLasBeams, const TsosVectorCollection &tkLasBeamTsoses)
int addMeasurementData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, AlignmentParameters *&params)
bool isMode(unsigned int testMode) const
void beginRun(const edm::Run &run, const edm::EventSetup &setup, bool changed) override
called at begin of run
bool addHits(const align::Alignables &alis, const std::vector< AlignmentUserVariables * > &mpVars) const
void makeGlobDerivMatrix(const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy, Eigen::MatrixBase< GlobalDerivativeMatrix > &aGlobalDerivativesM)
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
AlignmentParameterStore * theAlignmentParameterStore
directory for all kind of files
bool is2D(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
true if hit belongs to 2D detector (currently tracker specific)
void addRefTrackVirtualMeas1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas, Eigen::MatrixBase< CovarianceMatrix > &aHitCovarianceM, Eigen::MatrixBase< ResidualMatrix > &aHitResidualsM, Eigen::MatrixBase< LocalDerivativeMatrix > &aLocalDerivativesM)
adds data for a specific virtual measurement from reference trajectory
void addRefTrackData2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, Eigen::MatrixBase< CovarianceMatrix > &aHitCovarianceM, Eigen::MatrixBase< ResidualMatrix > &aHitResidualsM, Eigen::MatrixBase< LocalDerivativeMatrix > &aLocalDerivativesM)
adds data from reference trajectory from a specific Hit
(Abstract) Base class for alignment algorithm user variables
std::unique_ptr< PedeSteerer > thePedeSteer
bool storeAlignments() override
Returns whether MP produced results to be stored.
void terminate() override
Called at end of job.
void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
Called at beginning of job.
bool addHitStatistics(int fromLoop, const std::string &outFile, const std::vector< std::string > &inFiles) const
void addVirtualMeas(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas)
adds data for virtual measurements from reference trajectory
bool readFromPede(const edm::ParameterSet &mprespset, bool setUserVars, const RunRange &runrange)
read pede input defined by &#39;psetName&#39;, flag to create/not create MillePedeVariables ...
std::pair< unsigned int, unsigned int > addReferenceTrajectory(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr)
fill mille for a trajectory, returning number of x/y hits ([0,0] if &#39;bad&#39; trajectory) ...
virtual bool storeThresholds(const int &nRecords, const AlignPCLThresholds::threshold_map &thresholdMap)
std::vector< IntegratedCalibrationBase * > theCalibrations
std::vector< Alignable * > Alignables
Definition: Utilities.h:32
std::map< std::string, AlignPCLThreshold > threshold_map
void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm on trajectories and tracks.
MillePedeAlignmentAlgorithm(const edm::ParameterSet &cfg)
Constructor.
~MillePedeAlignmentAlgorithm() override
Destructor.
std::vector< TkFittedLasBeam > TkFittedLasBeamCollection
Definition: Mille.h:26
#define DEFINE_EDM_PLUGIN(factory, type, name)
eventInfo
add run, event number and lumi section
void addPxbSurvey(const edm::ParameterSet &pxbSurveyCfg)
add measurement data from PXB survey
unsigned int decodeMode(const std::string &mode) const
std::unique_ptr< AlignableNavigator > theAlignableNavigator
std::vector< std::vector< TrajectoryStateOnSurface > > TsosVectorCollection
define run information passed to algorithms (in endRun)
Constructor of the full muon geometry.
Definition: AlignableMuon.h:37
Definition: Run.h:43
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:38