Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:58

0001 #ifndef TrackProducerAlgorithm_h
0002 #define TrackProducerAlgorithm_h
0003 
0004 /** \class TrackProducerAlgorithm
0005  *  This class calls the Final Fit and builds the Tracks then produced by the TrackProducer or by the TrackRefitter
0006  *
0007  *  \author cerati
0008  */
0009 
0010 #include "AlgoProductTraits.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
0015 #include "DataFormats/TrackReco/interface/Track.h"
0016 #include "DataFormats/TrackReco/interface/TrackExtra.h"
0017 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0018 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
0019 #include "TrackingTools/PatternTools/interface/TrackConstraintAssociation.h"
0020 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0021 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
0022 #include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h"
0023 
0024 class MagneticField;
0025 class TrackingGeometry;
0026 class Propagator;
0027 class Trajectory;
0028 class TrajectoryStateOnSurface;
0029 
0030 struct FitterCloner {
0031   std::unique_ptr<TrajectoryFitter> fitter;
0032   TkClonerImpl hitCloner;
0033 
0034   FitterCloner(const TrajectoryFitter *theFitter, const TransientTrackingRecHitBuilder *builder)
0035       : fitter(theFitter->clone()),
0036         hitCloner(static_cast<TkTransientTrackingRecHitBuilder const *>(builder)->cloner()) {
0037     fitter->setHitCloner(&hitCloner);
0038   }
0039 };
0040 
0041 template <class T>
0042 class TrackProducerAlgorithm : public AlgoProductTraits<T> {
0043 public:
0044   using Base = AlgoProductTraits<T>;
0045   using TrackCollection = typename Base::TrackCollection;
0046   using TrackView = typename Base::TrackView;
0047   using AlgoProductCollection = typename Base::AlgoProductCollection;
0048 
0049   using SeedRef = edm::RefToBase<TrajectorySeed>;
0050   using VtxConstraintAssociationCollection =
0051       edm::AssociationMap<edm::OneToOne<std::vector<T>, std::vector<VertexConstraint> > >;
0052 
0053 public:
0054   /// Constructor
0055   TrackProducerAlgorithm(const edm::ParameterSet &conf)
0056       : algo_(reco::TrackBase::algoByName(conf.getParameter<std::string>("AlgorithmName"))),
0057         originalAlgo_(reco::TrackBase::undefAlgorithm),
0058         stopReason_(0),
0059         reMatchSplitHits_(false),
0060         usePropagatorForPCA_(false) {
0061     geometricInnerState_ = (conf.exists("GeometricInnerState") ? conf.getParameter<bool>("GeometricInnerState") : true);
0062     if (conf.exists("reMatchSplitHits"))
0063       reMatchSplitHits_ = conf.getParameter<bool>("reMatchSplitHits");
0064     if (conf.exists("usePropagatorForPCA"))
0065       usePropagatorForPCA_ = conf.getParameter<bool>("usePropagatorForPCA");
0066   }
0067 
0068   /// Destructor
0069   ~TrackProducerAlgorithm() {}
0070 
0071   /// Run the Final Fit taking TrackCandidates as input
0072   void runWithCandidate(const TrackingGeometry *,
0073                         const MagneticField *,
0074                         const TrackCandidateCollection &,
0075                         const TrajectoryFitter *,
0076                         const Propagator *,
0077                         const TransientTrackingRecHitBuilder *,
0078                         const reco::BeamSpot &,
0079                         AlgoProductCollection &);
0080 
0081   /// Run the Final Fit taking Tracks as input (for Refitter)
0082   void runWithTrack(const TrackingGeometry *,
0083                     const MagneticField *,
0084                     const TrackView &,
0085                     const TrajectoryFitter *,
0086                     const Propagator *,
0087                     const TransientTrackingRecHitBuilder *,
0088                     const reco::BeamSpot &,
0089                     AlgoProductCollection &);
0090 
0091   /// Run the Final Fit taking TrackMomConstraintAssociation as input (Refitter with momentum constraint)
0092   void runWithMomentum(const TrackingGeometry *,
0093                        const MagneticField *,
0094                        const TrackMomConstraintAssociationCollection &,
0095                        const TrajectoryFitter *,
0096                        const Propagator *,
0097                        const TransientTrackingRecHitBuilder *,
0098                        const reco::BeamSpot &,
0099                        AlgoProductCollection &);
0100 
0101   /// Run the Final Fit taking TrackVtxConstraintAssociation as input (Refitter with vertex constraint)
0102   ///   currently hit sorting is disabled - will work (only) with standard tracks
0103   void runWithVertex(const TrackingGeometry *,
0104                      const MagneticField *,
0105                      const VtxConstraintAssociationCollection &,
0106                      const TrajectoryFitter *,
0107                      const Propagator *,
0108                      const TransientTrackingRecHitBuilder *,
0109                      const reco::BeamSpot &,
0110                      AlgoProductCollection &);
0111 
0112   /// Run the Final Fit taking TrackParamConstraintAssociation as input (Refitter with complete track parameters constraint)
0113   ///   currently hit sorting is disabled - will work (only) with standard tracks
0114   void runWithTrackParameters(const TrackingGeometry *,
0115                               const MagneticField *,
0116                               const TrackParamConstraintAssociationCollection &,
0117                               const TrajectoryFitter *,
0118                               const Propagator *,
0119                               const TransientTrackingRecHitBuilder *,
0120                               const reco::BeamSpot &,
0121                               AlgoProductCollection &);
0122 
0123   /// Construct Tracks to be put in the event
0124   bool buildTrack(const TrajectoryFitter *,
0125                   const Propagator *,
0126                   AlgoProductCollection &,
0127                   TransientTrackingRecHit::RecHitContainer &,
0128                   TrajectoryStateOnSurface &,
0129                   const TrajectorySeed &,
0130                   float,
0131                   const reco::BeamSpot &,
0132                   SeedRef seedRef = SeedRef(),
0133                   int qualityMask = 0,
0134                   signed char nLoops = 0);
0135 
0136 private:
0137   reco::TrackBase::TrackAlgorithm algo_;
0138   reco::TrackBase::TrackAlgorithm originalAlgo_;
0139   reco::TrackBase::AlgoMask algoMask_;
0140   uint8_t stopReason_;
0141 
0142   bool reMatchSplitHits_;
0143   bool geometricInnerState_;
0144   bool usePropagatorForPCA_;
0145 
0146   TrajectoryStateOnSurface getInitialState(const T *theT,
0147                                            TransientTrackingRecHit::RecHitContainer &hits,
0148                                            const TrackingGeometry *theG,
0149                                            const MagneticField *theMF);
0150 };
0151 
0152 #include "RecoTracker/TrackProducer/interface/TrackProducerAlgorithm.icc"
0153 
0154 template <>
0155 bool TrackProducerAlgorithm<reco::Track>::buildTrack(const TrajectoryFitter *,
0156                                                      const Propagator *,
0157                                                      AlgoProductCollection &,
0158                                                      TransientTrackingRecHit::RecHitContainer &,
0159                                                      TrajectoryStateOnSurface &,
0160                                                      const TrajectorySeed &,
0161                                                      float,
0162                                                      const reco::BeamSpot &,
0163                                                      SeedRef seedRef,
0164                                                      int qualityMask,
0165                                                      signed char nLoops);
0166 
0167 template <>
0168 bool TrackProducerAlgorithm<reco::GsfTrack>::buildTrack(const TrajectoryFitter *,
0169                                                         const Propagator *,
0170                                                         AlgoProductCollection &,
0171                                                         TransientTrackingRecHit::RecHitContainer &,
0172                                                         TrajectoryStateOnSurface &,
0173                                                         const TrajectorySeed &,
0174                                                         float,
0175                                                         const reco::BeamSpot &,
0176                                                         SeedRef seedRef,
0177                                                         int qualityMask,
0178                                                         signed char nLoops);
0179 
0180 #endif