Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-10 06:14:15

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