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 
19 
22 
24 
27 
31 
34 
37 
38 #include <vector>
39 #include <string>
40 #include <memory>
41 
42 class Alignable;
43 class AlignableTracker;
44 class AlignableMuon;
45 class AlignableExtras;
46 
48 class AlignableNavigator;
51 
53 
55 
56 class MillePedeMonitor;
57 class PedeSteerer;
58 class PedeLabelerBase;
59 class Mille;
61 
62 // already from base class - and forward declaration does not work since typedef!
63 /* class TkFittedLasBeamCollection; */
64 /* class TsosVectorCollection; */
65 
67 public:
70 
73 
75  void initialize(const edm::EventSetup &setup,
78  AlignableExtras *extras,
79  AlignmentParameterStore *store) override;
80 
82  bool supportsCalibrations() override;
84  bool addCalibrations(const std::vector<IntegratedCalibrationBase *> &iCals) override;
85 
86  virtual bool storeThresholds(const int &nRecords,
87  const AlignPCLThresholdsHG::threshold_map &thresholdMap,
88  const AlignPCLThresholdsHG::param_map &floatMap);
89 
91  void terminate(const edm::EventSetup &iSetup) override;
93  void terminate() override;
94 
96  bool processesEvents() override;
97 
99  bool storeAlignments() override;
100 
102  void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override;
103 
105  void beginRun(const edm::Run &run, const edm::EventSetup &setup, bool changed) override;
106 
107  // TODO: This method does NOT match endRun() in base class! Nobody is
108  // calling this?
110  virtual void endRun(const EventInfo &, const EndRunInfo &,
111  const edm::EventSetup &); //override;
112 
113  // This one will be called since it matches the interface of the base class
114  void endRun(const EndRunInfo &runInfo, const edm::EventSetup &setup) override;
115 
117  void beginLuminosityBlock(const edm::EventSetup &) override;
118 
120  void endLuminosityBlock(const edm::EventSetup &) override;
121 
124  bool setParametersForRunRange(const RunRange &runrange) override;
125 
126 private:
128 
130  std::pair<unsigned int, unsigned int> addReferenceTrajectory(
131  const edm::EventSetup &setup,
132  const EventInfo &eventInfo,
134 
139  const EventInfo &eventInfo,
141  unsigned int iHit,
143 
147  const EventInfo &eventInfo,
149  unsigned int iHit,
150  gbl::GblPoint &gblPoint);
151 
156  unsigned int addHitCount(const std::vector<AlignmentParameters *> &parVec,
157  const std::vector<bool> &validHitVecY) const;
158 
160  template <typename CovarianceMatrix, typename ResidualMatrix, typename LocalDerivativeMatrix>
162  unsigned int iTrajHit,
163  Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
164  Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
165  Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM);
166 
168  void addVirtualMeas(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas);
169 
171  template <typename CovarianceMatrix, typename ResidualMatrix, typename LocalDerivativeMatrix>
173  unsigned int iVirtualMeas,
174  Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
175  Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
176  Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM);
177 
180  const TrajectoryStateOnSurface &tsos,
181  Alignable *ali,
182  const AlignableDetOrUnitPtr &alidet,
183  std::vector<float> &globalDerivativesX,
184  std::vector<float> &globalDerivativesY,
185  std::vector<int> &globalLabels,
186  AlignmentParameters *&lowestParams) const;
187 
190  const TrajectoryStateOnSurface &tsos,
191  Alignable *ali,
192  const AlignableDetOrUnitPtr &alidet,
193  std::vector<double> &globalDerivativesX,
194  std::vector<double> &globalDerivativesY,
195  std::vector<int> &globalLabels,
196  AlignmentParameters *&lowestParams) const;
197 
200  const TrajectoryStateOnSurface &tsos,
201  const edm::EventSetup &setup,
202  const EventInfo &eventInfo,
203  std::vector<float> &globalDerivativesX,
204  std::vector<float> &globalDerivativesY,
205  std::vector<int> &globalLabels) const;
206 
209  unsigned int iTrajHit,
210  const std::vector<int> &globalLabels,
211  const std::vector<float> &globalDerivativesX,
212  const std::vector<float> &globalDerivativesY);
213 
216  unsigned int iTrajHit,
217  const std::vector<int> &globalLabels,
218  const std::vector<float> &globalDerivativesX);
219 
224  unsigned int iTrajHit,
225  const std::vector<int> &globalLabels,
226  const std::vector<float> &globalDerivativesx,
227  const std::vector<float> &globalDerivativesy);
228 
229  template <typename CovarianceMatrix,
230  typename LocalDerivativeMatrix,
231  typename ResidualMatrix,
232  typename GlobalDerivativeMatrix>
233  void diagonalize(Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
234  Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM,
235  Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
236  Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM) const;
237 
238  // deals with the non matrix format of theFloatBufferX ...
239  template <typename GlobalDerivativeMatrix>
240  void makeGlobDerivMatrix(const std::vector<float> &globalDerivativesx,
241  const std::vector<float> &globalDerivativesy,
242  Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM);
243 
244  // void callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
245  // unsigned int iTrajHit, MeasurementDirection xOrY,
246  // const std::vector<float> &globalDerivatives, const std::vector<int> &globalLabels);
249 
251  bool readFromPede(const edm::ParameterSet &mprespset, bool setUserVars, const RunRange &runrange);
252  bool areEmptyParams(const align::Alignables &alignables) const;
253  unsigned int doIO(int loop) const;
255  void buildUserVariables(const align::Alignables &alignables) const;
256 
259  std::vector<std::string> getExistingFormattedFiles(const std::vector<std::string> &plainFiles,
260  const std::string &theDir);
261 
262  void addLaserData(const EventInfo &eventInfo,
263  const TkFittedLasBeamCollection &tkLasBeams,
264  const TsosVectorCollection &tkLasBeamTsoses);
265  void addLasBeam(const EventInfo &eventInfo,
266  const TkFittedLasBeam &lasBeam,
267  const std::vector<TrajectoryStateOnSurface> &tsoses);
268 
270  void addPxbSurvey(const edm::ParameterSet &pxbSurveyCfg);
271 
272  //
273  bool areIOVsSpecified() const;
274 
275  //--------------------------------------------------------
276  // Data members
277  //--------------------------------------------------------
278 
283 
284  enum EModeBit { myMilleBit = 1 << 0, myPedeRunBit = 1 << 1, myPedeSteerBit = 1 << 2, myPedeReadBit = 1 << 3 };
285  unsigned int decodeMode(const std::string &mode) const;
286  bool isMode(unsigned int testMode) const { return (theMode & testMode); }
287  bool addHitStatistics(int fromLoop, const std::string &outFile, const std::vector<std::string> &inFiles) const;
288  bool addHits(const align::Alignables &alis, const std::vector<AlignmentUserVariables *> &mpVars) const;
289 
291  unsigned int theMode;
295  std::unique_ptr<AlignableNavigator> theAlignableNavigator;
296  std::unique_ptr<MillePedeMonitor> theMonitor;
297  std::unique_ptr<Mille> theMille;
298  std::shared_ptr<PedeLabelerBase> thePedeLabels;
299  std::unique_ptr<PedeSteerer> thePedeSteer;
300  std::unique_ptr<TrajectoryFactoryBase> theTrajectoryFactory;
301  std::vector<IntegratedCalibrationBase *> theCalibrations;
302  std::shared_ptr<AlignPCLThresholdsHG> theThresholds;
303  std::shared_ptr<PixelTopologyMap> pixelTopologyMap;
304  std::shared_ptr<SiPixelQuality> pixelQuality;
305  unsigned int theMinNumHits;
311  int theLastWrittenIov; // keeping track for output trees...
312  std::vector<float> theFloatBufferX;
313  std::vector<float> theFloatBufferY;
314  std::vector<int> theIntBuffer;
316  // CHK for GBL
317  std::unique_ptr<gbl::MilleBinary> theBinary;
319 
320  const bool runAtPCL_;
323 
326  std::vector<align::RunNumber> cachedRuns_;
328 };
329 
331 #endif
bool processesEvents() override
Returns whether MP should process events in the current configuration.
std::shared_ptr< AlignPCLThresholdsHG > theThresholds
bool supportsCalibrations() override
Returns whether MP supports calibrations.
std::unordered_map< std::string, std::vector< float > > param_map
std::unique_ptr< MillePedeMonitor > theMonitor
bool setParametersForRunRange(const RunRange &runrange) override
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 addCalibrations(const std::vector< IntegratedCalibrationBase *> &iCals) override
Pass integrated calibrations to Millepede (they are not owned by Millepede!)
virtual void endRun(const EventInfo &, const EndRunInfo &, const edm::EventSetup &)
Run on run products, e.g. TkLAS.
std::map< std::string, AlignPCLThreshold > threshold_map
void endLuminosityBlock(const edm::EventSetup &) override
called at end of luminosity block
const edm::ESGetToken< SiPixelQuality, SiPixelQualityFromDbRcd > siPixelQualityToken_
std::unique_ptr< TrajectoryFactoryBase > theTrajectoryFactory
std::vector< RunRange > RunRanges
Definition: Utilities.h:39
bool areEmptyParams(const align::Alignables &alignables) const
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)
std::shared_ptr< PedeLabelerBase > thePedeLabels
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::vector< std::string > getExistingFormattedFiles(const std::vector< std::string > &plainFiles, const std::string &theDir)
bool isMode(unsigned int testMode) const
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
int callMille2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy)
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
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)
virtual bool storeThresholds(const int &nRecords, const AlignPCLThresholdsHG::threshold_map &thresholdMap, const AlignPCLThresholdsHG::param_map &floatMap)
void beginRun(const edm::Run &run, const edm::EventSetup &setup, bool changed) override
called at begin of run
bool is2D(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
true if hit belongs to 2D detector (currently tracker specific)
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_
std::shared_ptr< PixelTopologyMap > pixelTopologyMap
const edm::ESGetToken< AlignPCLThresholdsHG, AlignPCLThresholdsHGRcd > aliThrToken_
AlignmentParameterStore * theAlignmentParameterStore
directory for all kind of files
bool addHitStatistics(int fromLoop, const std::string &outFile, const std::vector< std::string > &inFiles) const
void diagonalize(Eigen::MatrixBase< CovarianceMatrix > &aHitCovarianceM, Eigen::MatrixBase< LocalDerivativeMatrix > &aLocalDerivativesM, Eigen::MatrixBase< ResidualMatrix > &aHitResidualsM, Eigen::MatrixBase< GlobalDerivativeMatrix > &aGlobalDerivativesM) const
bool addHits(const align::Alignables &alis, const std::vector< AlignmentUserVariables *> &mpVars) const
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
unsigned int decodeMode(const std::string &mode) const
(Abstract) Base class for alignment algorithm user variables
unsigned int addHitCount(const std::vector< AlignmentParameters *> &parVec, const std::vector< bool > &validHitVecY) const
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.
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) ...
void buildUserVariables(const align::Alignables &alignables) const
add MillePedeVariables for each AlignmentParameters (exception if no parameters...)
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
Eigen::Matrix< float, EcalPulseShape::TEMPLATESAMPLES, EcalPulseShape::TEMPLATESAMPLES > CovarianceMatrix
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
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
std::shared_ptr< SiPixelQuality > pixelQuality
Definition: Run.h:45
cond::RealTimeType< cond::runnumber >::type RunNumber
Definition: Utilities.h:37