Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-12 02:57:31

0001 #ifndef RecoTracker_CkfPattern_BaseCkfTrajectoryBuilder_h
0002 #define RecoTracker_CkfPattern_BaseCkfTrajectoryBuilder_h
0003 
0004 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
0005 #include "TrackingTools/PatternTools/interface/TrajectoryBuilder.h"
0006 #include "FWCore/Framework/interface/ConsumesCollector.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "FWCore/Utilities/interface/ESGetToken.h"
0011 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0012 
0013 #include <cassert>
0014 #include "TrackingTools/PatternTools/interface/TempTrajectory.h"
0015 
0016 class CkfDebugger;
0017 class Chi2MeasurementEstimatorBase;
0018 class DetGroup;
0019 class FreeTrajectoryState;
0020 class IntermediateTrajectoryCleaner;
0021 class LayerMeasurements;
0022 class MeasurementTracker;
0023 class MeasurementTrackerEvent;
0024 class MeasurementEstimator;
0025 class NavigationSchool;
0026 class Propagator;
0027 class TrajectoryStateUpdator;
0028 class TrajectoryMeasurement;
0029 class TrajectoryContainer;
0030 class TrajectoryStateOnSurface;
0031 class TrajectoryFitter;
0032 class TransientRecHitRecord;
0033 class TransientTrackingRecHitBuilder;
0034 class Trajectory;
0035 class TempTrajectory;
0036 class TrajectoryFilter;
0037 class TrackingRegion;
0038 class TrajectoryMeasurementGroup;
0039 class TrajectoryCleaner;
0040 class TrackingComponentsRecord;
0041 namespace edm {
0042   class ConsumesCollector;
0043 }
0044 
0045 #include "RecoTracker/CkfPattern/interface/PrintoutHelper.h"
0046 
0047 #include <string>
0048 
0049 /** The component of track reconstruction that, strating from a seed,
0050  *  reconstructs all possible trajectories.
0051  *  The resulting trajectories may be mutually exclusive and require
0052  *  cleaning by a TrajectoryCleaner.
0053  *  The Trajectories are normally not smoothed.
0054  */
0055 
0056 class BaseCkfTrajectoryBuilder : public TrajectoryBuilder {
0057 protected:
0058   // short names
0059   typedef FreeTrajectoryState FTS;
0060   typedef TrajectoryStateOnSurface TSOS;
0061   typedef TrajectoryMeasurement TM;
0062   typedef std::pair<TSOS, std::vector<const DetLayer*> > StateAndLayers;
0063 
0064 public:
0065   typedef std::vector<Trajectory> TrajectoryContainer;
0066   typedef std::vector<TempTrajectory> TempTrajectoryContainer;
0067   typedef TrajectoryContainer::iterator TrajectoryIterator;
0068 
0069   // Claims ownership of TrajectoryFilter pointers
0070   BaseCkfTrajectoryBuilder(const edm::ParameterSet& conf,
0071                            edm::ConsumesCollector iC,
0072                            std::unique_ptr<TrajectoryFilter> filter,
0073                            std::unique_ptr<TrajectoryFilter> inOutFilter = nullptr);
0074   BaseCkfTrajectoryBuilder(const BaseCkfTrajectoryBuilder&) = delete;
0075   BaseCkfTrajectoryBuilder& operator=(const BaseCkfTrajectoryBuilder&) = delete;
0076   ~BaseCkfTrajectoryBuilder() override;
0077 
0078   static void fillPSetDescription(edm::ParameterSetDescription& iDesc);
0079 
0080   // new interface returning the start Trajectory...
0081   virtual TempTrajectory buildTrajectories(const TrajectorySeed& seed,
0082                                            TrajectoryContainer& ret,
0083                                            unsigned int& nCandPerSeed,
0084                                            const TrajectoryFilter*) const {
0085     assert(0 == 1);
0086     return TempTrajectory();
0087   }
0088 
0089   virtual void rebuildTrajectories(TempTrajectory const& startingTraj,
0090                                    const TrajectorySeed& seed,
0091                                    TrajectoryContainer& result) const {
0092     assert(0 == 1);
0093   }
0094 
0095   void setNavigationSchool(NavigationSchool const* nv) { theNavigationSchool = nv; }
0096 
0097   void setEvent(const edm::Event& event) const override;
0098   void unset() const override;
0099 
0100   void setEvent(const edm::Event& iEvent, const edm::EventSetup& iSetup, const MeasurementTrackerEvent* data);
0101 
0102   virtual void setDebugger(CkfDebugger* dbg) const { ; }
0103 
0104   /** Maximum number of lost hits per trajectory candidate. */
0105   //  int       maxLostHit()        {return theMaxLostHit;}
0106 
0107   /** Maximum number of consecutive lost hits per trajectory candidate. */
0108   //  int       maxConsecLostHit()  {return theMaxConsecLostHit;}
0109 
0110   const TransientTrackingRecHitBuilder* hitBuilder() const { return theTTRHBuilder; }
0111 
0112 protected:
0113   static std::unique_ptr<TrajectoryFilter> createTrajectoryFilter(const edm::ParameterSet& pset,
0114                                                                   edm::ConsumesCollector& iC);
0115 
0116   virtual void setEvent_(const edm::Event& iEvent, const edm::EventSetup& iSetup) = 0;
0117 
0118   //methods for dubugging
0119   virtual bool analyzeMeasurementsDebugger(Trajectory& traj,
0120                                            const std::vector<TrajectoryMeasurement>& meas,
0121                                            const MeasurementTrackerEvent* theMeasurementTracker,
0122                                            const Propagator* theForwardPropagator,
0123                                            const Chi2MeasurementEstimatorBase* theEstimator,
0124                                            const TransientTrackingRecHitBuilder* theTTRHBuilder) const {
0125     return true;
0126   }
0127   virtual bool analyzeMeasurementsDebugger(TempTrajectory& traj,
0128                                            const std::vector<TrajectoryMeasurement>& meas,
0129                                            const MeasurementTrackerEvent* theMeasurementTracker,
0130                                            const Propagator* theForwardPropagator,
0131                                            const Chi2MeasurementEstimatorBase* theEstimator,
0132                                            const TransientTrackingRecHitBuilder* theTTRHBuilder) const {
0133     return true;
0134   }
0135   virtual void fillSeedHistoDebugger(std::vector<TrajectoryMeasurement>::iterator begin,
0136                                      std::vector<TrajectoryMeasurement>::iterator end) const {
0137     ;
0138   }
0139 
0140 protected:
0141   TempTrajectory createStartingTrajectory(const TrajectorySeed& seed) const;
0142 
0143   /** Called after each new hit is added to the trajectory, to see if building this track should be continued */
0144   // If inOut is true, this is being called part-way through tracking, after the in-out tracking phase is complete.
0145   // If inOut is false, it is called at the end of tracking.
0146   bool toBeContinued(TempTrajectory& traj, bool inOut = false) const;
0147 
0148   /** Called at end of track building, to see if track should be kept */
0149   bool qualityFilter(const TempTrajectory& traj, bool inOut = false) const;
0150 
0151   void addToResult(std::shared_ptr<const TrajectorySeed> const& seed,
0152                    TempTrajectory& traj,
0153                    TrajectoryContainer& result,
0154                    bool inOut = false) const;
0155   void addToResult(TempTrajectory const& traj, TempTrajectoryContainer& result, bool inOut = false) const;
0156   void moveToResult(TempTrajectory&& traj, TempTrajectoryContainer& result, bool inOut = false) const;
0157 
0158   StateAndLayers findStateAndLayers(const TrajectorySeed& seed, const TempTrajectory& traj) const;
0159 
0160 private:
0161   void seedMeasurements(const TrajectorySeed& seed, TempTrajectory& result, bool as5D) const;
0162 
0163 protected:
0164   void setData(const MeasurementTrackerEvent* data);
0165 
0166   const Propagator* forwardPropagator(const TrajectorySeed& seed) const {
0167     return seed.direction() == alongMomentum ? thePropagatorAlong : thePropagatorOpposite;
0168   }
0169   const Propagator* backwardPropagator(const TrajectorySeed& seed) const {
0170     return seed.direction() == alongMomentum ? thePropagatorOpposite : thePropagatorAlong;
0171   }
0172 
0173 protected:
0174   typedef TrackingComponentsRecord Chi2MeasurementEstimatorRecord;
0175 
0176   const TrajectoryStateUpdator* theUpdator = nullptr;
0177   const Propagator* thePropagatorAlong = nullptr;
0178   const Propagator* thePropagatorOpposite = nullptr;
0179   const Chi2MeasurementEstimatorBase* theEstimator = nullptr;
0180   const TransientTrackingRecHitBuilder* theTTRHBuilder = nullptr;
0181   const MeasurementTrackerEvent* theMeasurementTracker = nullptr;
0182   const NavigationSchool* theNavigationSchool = nullptr;
0183 
0184 private:
0185   bool theSeedAs5DHit;
0186 
0187   std::unique_ptr<TrajectoryFilter> theFilter;      /** Filter used at end of complete tracking */
0188   std::unique_ptr<TrajectoryFilter> theInOutFilter; /** Filter used at end of in-out tracking */
0189 
0190   // for EventSetup
0191   const edm::ESGetToken<TrajectoryStateUpdator, TrackingComponentsRecord> theUpdatorToken;
0192   const edm::ESGetToken<Propagator, TrackingComponentsRecord> thePropagatorAlongToken;
0193   const edm::ESGetToken<Propagator, TrackingComponentsRecord> thePropagatorOppositeToken;
0194   const edm::ESGetToken<Chi2MeasurementEstimatorBase, TrackingComponentsRecord> theEstimatorToken;
0195   const edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> theRecHitBuilderToken;
0196 };
0197 
0198 #endif