Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 #ifndef Alignment_CommonAlignmentAlgorithm_AlignmentAlgorithmBase_h
0003 #define Alignment_CommonAlignmentAlgorithm_AlignmentAlgorithmBase_h
0004 
0005 /**
0006  * @package   Alignment/CommonAlignmentAlgorithm
0007  * @file      AlignmentAlgorithmBase.h
0008  *
0009  * @author    ???
0010  *
0011  * Last update:
0012  * @author    Max Stark (max.stark@cern.ch)
0013  * @date      2015/07/16
0014  *
0015  * @brief     Interface/Base class for alignment algorithms, each alignment
0016  *            algorithm has to be derived from this class
0017  */
0018 
0019 #include <vector>
0020 #include <utility>
0021 #include <memory>
0022 
0023 class AlignableTracker;
0024 class AlignableMuon;
0025 class AlignableExtras;
0026 class AlignmentParameterStore;
0027 class IntegratedCalibrationBase;
0028 class Trajectory;
0029 // These data formats cannot be forward declared since they are typedef's,
0030 // so include the headers that define the typedef's
0031 // (no need to include in dependencies in BuildFile):
0032 // class TsosVectorCollection;
0033 // class TkFittedLasBeamCollection;
0034 // class AliClusterValueMap;
0035 #include "Alignment/CommonAlignment/interface/Utilities.h"
0036 #include "Alignment/LaserAlignment/interface/TsosVectorCollection.h"
0037 #include "DataFormats/Alignment/interface/TkFittedLasBeamCollectionFwd.h"
0038 #include "DataFormats/Alignment/interface/AliClusterValueMapFwd.h"
0039 #include "FWCore/Framework/interface/Event.h"
0040 #include "FWCore/Framework/interface/ConsumesCollector.h"
0041 
0042 namespace edm {
0043   class EventSetup;
0044   class ParameterSet;
0045 }  // namespace edm
0046 namespace reco {
0047   class Track;
0048   class BeamSpot;
0049 }  // namespace reco
0050 
0051 /*** Global typedefs part I (see EOF for part II) ***/
0052 typedef std::pair<const Trajectory *, const reco::Track *> ConstTrajTrackPair;
0053 typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairs;
0054 
0055 typedef std::vector<IntegratedCalibrationBase *> Calibrations;
0056 typedef std::vector<std::unique_ptr<IntegratedCalibrationBase>> CalibrationsOwner;
0057 
0058 typedef std::vector<IntegratedCalibrationBase *> Calibrations;
0059 
0060 class AlignmentAlgorithmBase {
0061 public:
0062   // TODO: DEPRECATED: For not breaking the interface, used in serveral files.
0063   //                   If possible use the global typedefs above.
0064   // With global typedefs one does not have to typedef again like
0065   // 'typedef AlignmentAlgorithmBase::ConstTrajTrackPair ConstTrajTrackPair;'
0066   // in other files.
0067   typedef std::pair<const Trajectory *, const reco::Track *> ConstTrajTrackPair;
0068   typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
0069   using RunNumber = align::RunNumber;
0070   using RunRange = align::RunRange;
0071 
0072   /// define event information passed to algorithms
0073   class EventInfo {
0074   public:
0075     EventInfo(const edm::EventID &theEventId,
0076               const ConstTrajTrackPairCollection &theTrajTrackPairs,
0077               const reco::BeamSpot &theBeamSpot,
0078               const AliClusterValueMap *theClusterValueMap)
0079         : eventId_(theEventId),
0080           trajTrackPairs_(theTrajTrackPairs),
0081           beamSpot_(theBeamSpot),
0082           clusterValueMap_(theClusterValueMap) {}
0083 
0084     const edm::EventID eventId() const { return eventId_; }
0085     const ConstTrajTrackPairCollection &trajTrackPairs() const { return trajTrackPairs_; }
0086     const reco::BeamSpot &beamSpot() const { return beamSpot_; }
0087     const AliClusterValueMap *clusterValueMap() const { return clusterValueMap_; }  ///might be null!
0088 
0089   private:
0090     const edm::EventID eventId_;
0091     const ConstTrajTrackPairCollection &trajTrackPairs_;
0092     const reco::BeamSpot &beamSpot_;
0093     const AliClusterValueMap *clusterValueMap_;  ///might be null!
0094   };
0095 
0096   /// define run information passed to algorithms (in endRun)
0097   class EndRunInfo {
0098   public:
0099     EndRunInfo(const edm::RunID &theRunId,
0100                const TkFittedLasBeamCollection *theTkLasBeams,
0101                const TsosVectorCollection *theTkLasBeamTsoses)
0102         : runId_(theRunId), tkLasBeams_(theTkLasBeams), tkLasBeamTsoses_(theTkLasBeamTsoses) {}
0103 
0104     const edm::RunID runId() const { return runId_; }
0105     const TkFittedLasBeamCollection *tkLasBeams() const { return tkLasBeams_; }       /// might be null!
0106     const TsosVectorCollection *tkLasBeamTsoses() const { return tkLasBeamTsoses_; }  /// might be null!
0107 
0108   private:
0109     const edm::RunID runId_;
0110     const TkFittedLasBeamCollection *tkLasBeams_;  /// might be null!
0111     const TsosVectorCollection *tkLasBeamTsoses_;  /// might be null!
0112   };
0113 
0114   /// Constructor
0115   AlignmentAlgorithmBase(const edm::ParameterSet &, const edm::ConsumesCollector &){};
0116 
0117   /// Destructor
0118   virtual ~AlignmentAlgorithmBase(){};
0119 
0120   /// Call at beginning of job (must be implemented in derived class)
0121   virtual void initialize(const edm::EventSetup &setup,
0122                           AlignableTracker *tracker,
0123                           AlignableMuon *muon,
0124                           AlignableExtras *extras,
0125                           AlignmentParameterStore *store) = 0;
0126 
0127   /// Returns whether calibrations is supported by algorithm,
0128   /// default implementation returns false.
0129   virtual bool supportsCalibrations() { return false; }
0130   /// Pass integrated calibrations to algorithm, to be called after initialize()
0131   /// Calibrations' ownership is NOT passed to algorithm
0132   virtual bool addCalibrations(const Calibrations &) { return false; }
0133   // Overloading for the owning vector
0134   bool addCalibrations(const CalibrationsOwner &cals) {
0135     Calibrations tmp;
0136     tmp.reserve(cals.size());
0137     for (const auto &ptr : cals) {
0138       tmp.push_back(ptr.get());
0139     }
0140     return addCalibrations(tmp);
0141   }
0142 
0143   /// Returns whether algorithm proccesses events in current configuration
0144   virtual bool processesEvents() { return true; }
0145 
0146   /// Returns whether algorithm produced results to be stored
0147   virtual bool storeAlignments() { return true; }
0148 
0149   // TODO: DEPRECATED: Actually, there are no iterative algorithms, use
0150   //                   initialze() and terminate()
0151   /// Called at start of loop, default implementation is dummy for
0152   /// non-iterative algorithms
0153   virtual void startNewLoop() {}
0154 
0155   /// Call at end of each loop (must be implemented in derived class)
0156   virtual void terminate(const edm::EventSetup &iSetup) = 0;
0157   /// Called at end of job (must be implemented in derived class)
0158   virtual void terminate() {}
0159 
0160   /// Run the algorithm (must be implemented in derived class)
0161   virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo) = 0;
0162 
0163   /// called at begin of run
0164   virtual void beginRun(const edm::Run &, const edm::EventSetup &, bool changed){};
0165 
0166   /// called at end of run - order of arguments like in EDProducer etc.
0167   virtual void endRun(const EndRunInfo &runInfo, const edm::EventSetup &setup){};
0168 
0169   /// called at begin of luminosity block (no lumi block info passed yet)
0170   virtual void beginLuminosityBlock(const edm::EventSetup &setup){};
0171 
0172   /// called at end of luminosity block (no lumi block info passed yet)
0173   virtual void endLuminosityBlock(const edm::EventSetup &setup){};
0174 
0175   /// called in order to pass parameters to alignables for a specific run
0176   /// range in case the algorithm supports run range dependent alignment.
0177   virtual bool setParametersForRunRange(const RunRange &rr) { return false; };
0178 };
0179 
0180 /*** Global typedefs part II ***/
0181 typedef AlignmentAlgorithmBase::EventInfo EventInfo;
0182 typedef AlignmentAlgorithmBase::EndRunInfo EndRunInfo;
0183 
0184 #endif