CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MillePedeAlignmentAlgorithm.h
Go to the documentation of this file.
1 #ifndef Alignment_MillePedeAlignmentAlgorithm_MillePedeAlignmentAlgorithm_h
2 #define Alignment_MillePedeAlignmentAlgorithm_MillePedeAlignmentAlgorithm_h
3 
13 
16 
19 
22 
24 
27 
30 
31 #include <vector>
32 #include <string>
33 #include <memory>
34 
35 class Alignable;
36 class AlignableTracker;
37 class AlignableMuon;
38 class AlignableExtras;
39 
41 class AlignableNavigator;
44 
46 
48 
49 class MillePedeMonitor;
50 class PedeSteerer;
51 class PedeLabelerBase;
52 class Mille;
54 
55 // already from base class - and forward declaration does not work since typedef!
56 /* class TkFittedLasBeamCollection; */
57 /* class TsosVectorCollection; */
58 
60 public:
63 
66 
68  void initialize(const edm::EventSetup &setup,
69  AlignableTracker *tracker,
71  AlignableExtras *extras,
72  AlignmentParameterStore *store) override;
73 
75  bool supportsCalibrations() override;
77  bool addCalibrations(const std::vector<IntegratedCalibrationBase *> &iCals) override;
78 
79  virtual bool storeThresholds(const int &nRecords, const AlignPCLThresholds::threshold_map &thresholdMap);
80 
82  void terminate(const edm::EventSetup &iSetup) override;
84  void terminate() override;
85 
87  bool processesEvents() override;
88 
90  bool storeAlignments() override;
91 
93  void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override;
94 
96  void beginRun(const edm::Run &run, const edm::EventSetup &setup, bool changed) override;
97 
98  // TODO: This method does NOT match endRun() in base class! Nobody is
99  // calling this?
101  virtual void endRun(const EventInfo &, const EndRunInfo &,
102  const edm::EventSetup &); //override;
103 
104  // This one will be called since it matches the interface of the base class
105  void endRun(const EndRunInfo &runInfo, const edm::EventSetup &setup) override;
106 
108  void beginLuminosityBlock(const edm::EventSetup &) override;
109 
111  void endLuminosityBlock(const edm::EventSetup &) override;
112 
113  /* virtual void beginLuminosityBlock(const edm::EventSetup &setup) {} */
114  /* virtual void endLuminosityBlock(const edm::EventSetup &setup) {} */
115 
118  bool setParametersForRunRange(const RunRange &runrange) override;
119 
120 private:
122 
124  std::pair<unsigned int, unsigned int> addReferenceTrajectory(
125  const edm::EventSetup &setup,
126  const EventInfo &eventInfo,
128 
132  int addMeasurementData(const edm::EventSetup &setup,
133  const EventInfo &eventInfo,
135  unsigned int iHit,
137 
140  int addGlobalData(const edm::EventSetup &setup,
141  const EventInfo &eventInfo,
143  unsigned int iHit,
144  gbl::GblPoint &gblPoint);
145 
150  unsigned int addHitCount(const std::vector<AlignmentParameters *> &parVec,
151  const std::vector<bool> &validHitVecY) const;
152 
154  template <typename CovarianceMatrix, typename ResidualMatrix, typename LocalDerivativeMatrix>
156  unsigned int iTrajHit,
157  Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
158  Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
159  Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM);
160 
162  void addVirtualMeas(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas);
163 
165  template <typename CovarianceMatrix, typename ResidualMatrix, typename LocalDerivativeMatrix>
167  unsigned int iVirtualMeas,
168  Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
169  Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
170  Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM);
171 
173  bool globalDerivativesHierarchy(const EventInfo &eventInfo,
174  const TrajectoryStateOnSurface &tsos,
175  Alignable *ali,
176  const AlignableDetOrUnitPtr &alidet,
177  std::vector<float> &globalDerivativesX,
178  std::vector<float> &globalDerivativesY,
179  std::vector<int> &globalLabels,
180  AlignmentParameters *&lowestParams) const;
181 
183  bool globalDerivativesHierarchy(const EventInfo &eventInfo,
184  const TrajectoryStateOnSurface &tsos,
185  Alignable *ali,
186  const AlignableDetOrUnitPtr &alidet,
187  std::vector<double> &globalDerivativesX,
188  std::vector<double> &globalDerivativesY,
189  std::vector<int> &globalLabels,
190  AlignmentParameters *&lowestParams) const;
191 
194  const TrajectoryStateOnSurface &tsos,
195  const edm::EventSetup &setup,
196  const EventInfo &eventInfo,
197  std::vector<float> &globalDerivativesX,
198  std::vector<float> &globalDerivativesY,
199  std::vector<int> &globalLabels) const;
200 
203  unsigned int iTrajHit,
204  const std::vector<int> &globalLabels,
205  const std::vector<float> &globalDerivativesX,
206  const std::vector<float> &globalDerivativesY);
207 
210  unsigned int iTrajHit,
211  const std::vector<int> &globalLabels,
212  const std::vector<float> &globalDerivativesX);
213 
218  unsigned int iTrajHit,
219  const std::vector<int> &globalLabels,
220  const std::vector<float> &globalDerivativesx,
221  const std::vector<float> &globalDerivativesy);
222 
223  template <typename CovarianceMatrix,
224  typename LocalDerivativeMatrix,
225  typename ResidualMatrix,
226  typename GlobalDerivativeMatrix>
227  void diagonalize(Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
228  Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM,
229  Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
230  Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM) const;
231 
232  // deals with the non matrix format of theFloatBufferX ...
233  template <typename GlobalDerivativeMatrix>
234  void makeGlobDerivMatrix(const std::vector<float> &globalDerivativesx,
235  const std::vector<float> &globalDerivativesy,
236  Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM);
237 
238  // void callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
239  // unsigned int iTrajHit, MeasurementDirection xOrY,
240  // const std::vector<float> &globalDerivatives, const std::vector<int> &globalLabels);
242  bool is2D(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const;
243 
245  bool readFromPede(const edm::ParameterSet &mprespset, bool setUserVars, const RunRange &runrange);
246  bool areEmptyParams(const align::Alignables &alignables) const;
247  unsigned int doIO(int loop) const;
249  void buildUserVariables(const align::Alignables &alignables) const;
250 
253  std::vector<std::string> getExistingFormattedFiles(const std::vector<std::string> &plainFiles,
254  const std::string &theDir);
255 
256  void addLaserData(const EventInfo &eventInfo,
257  const TkFittedLasBeamCollection &tkLasBeams,
258  const TsosVectorCollection &tkLasBeamTsoses);
259  void addLasBeam(const EventInfo &eventInfo,
260  const TkFittedLasBeam &lasBeam,
261  const std::vector<TrajectoryStateOnSurface> &tsoses);
262 
264  void addPxbSurvey(const edm::ParameterSet &pxbSurveyCfg);
265 
266  //
267  bool areIOVsSpecified() const;
268 
269  //--------------------------------------------------------
270  // Data members
271  //--------------------------------------------------------
272 
275 
276  enum EModeBit { myMilleBit = 1 << 0, myPedeRunBit = 1 << 1, myPedeSteerBit = 1 << 2, myPedeReadBit = 1 << 3 };
277  unsigned int decodeMode(const std::string &mode) const;
278  bool isMode(unsigned int testMode) const { return (theMode & testMode); }
279  bool addHitStatistics(int fromLoop, const std::string &outFile, const std::vector<std::string> &inFiles) const;
280  bool addHits(const align::Alignables &alis, const std::vector<AlignmentUserVariables *> &mpVars) const;
281 
283  unsigned int theMode;
287  std::unique_ptr<AlignableNavigator> theAlignableNavigator;
288  std::unique_ptr<MillePedeMonitor> theMonitor;
289  std::unique_ptr<Mille> theMille;
290  std::shared_ptr<PedeLabelerBase> thePedeLabels;
291  std::unique_ptr<PedeSteerer> thePedeSteer;
292  std::unique_ptr<TrajectoryFactoryBase> theTrajectoryFactory;
293  std::vector<IntegratedCalibrationBase *> theCalibrations;
294  std::shared_ptr<AlignPCLThresholds> theThresholds;
295  unsigned int theMinNumHits;
301  int theLastWrittenIov; // keeping track for output trees...
302  std::vector<float> theFloatBufferX;
303  std::vector<float> theFloatBufferY;
304  std::vector<int> theIntBuffer;
306  // CHK for GBL
307  std::unique_ptr<gbl::MilleBinary> theBinary;
309 
310  const bool runAtPCL_;
313 
316  std::vector<align::RunNumber> cachedRuns_;
318 };
319 
321 #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
tuple cfg
Definition: looper.py:296
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
std::map< std::string, AlignPCLThreshold > threshold_map
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:39
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
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
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
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:31
void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm on trajectories and tracks.
~MillePedeAlignmentAlgorithm() override
Destructor.
MillePedeAlignmentAlgorithm(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
Constructor.
std::vector< TkFittedLasBeam > TkFittedLasBeamCollection
const edm::ESGetToken< AlignPCLThresholds, AlignPCLThresholdsRcd > aliThrToken_
Definition: Mille.h:26
#define DEFINE_EDM_PLUGIN(factory, type, name)
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:38
Definition: Run.h:45
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:37