Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:54

0001 #ifndef RecoMuon_GlobalTrackingTools_GlobalTrajectoryBuilderBase_H
0002 #define RecoMuon_GlobalTrackingTools_GlobalTrajectoryBuilderBase_H
0003 
0004 /** \class GlobalTrajectoryBuilderBase
0005  *
0006  *   Base class for GlobalMuonTrajectoryBuilder and L3MuonTrajectoryBuilder
0007  *   Provide common tools and interface to reconstruct muons starting
0008  *   from a muon track reconstructed
0009  *   in the standalone muon system (with DT, CSC and RPC
0010  *   information).
0011  *   It tries to reconstruct the corresponding
0012  *   track in the tracker and performs
0013  *   matching between the reconstructed tracks
0014  *   in the muon system and the tracker.
0015  *
0016  *  \author N. Neumeister    Purdue University
0017  *  \author C. Liu       Purdue University
0018  *  \author A. Everett       Purdue University
0019  */
0020 
0021 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0022 #include "RecoMuon/TrackingTools/interface/MuonTrajectoryBuilder.h"
0023 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
0024 #include "FWCore/Framework/interface/ConsumesCollector.h"
0025 
0026 #include "MagneticField/Engine/interface/MagneticField.h"
0027 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0028 #include "RecoTracker/Record/interface/TrackerMultipleScatteringRecord.h"
0029 #include "RecoTracker/TkMSParametrization/interface/MultipleScatteringParametrisationMaker.h"
0030 #include "RecoTracker/TkTrackingRegions/interface/RectangularEtaPhiTrackingRegion.h"
0031 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0032 #include "TrackingTools/TrackRefitter/interface/TrackTransformer.h"
0033 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0034 #include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h"
0035 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0036 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0037 
0038 //Forward declare classes from same package (RecoMuon)
0039 class GlobalMuonTrackMatcher;
0040 class MuonDetLayerMeasurements;
0041 class MuonServiceProxy;
0042 class MuonTrackingRegionBuilder;
0043 class GlobalMuonRefitter;
0044 class TransientRecHitRecord;
0045 
0046 class GlobalTrajectoryBuilderBase : public MuonTrajectoryBuilder {
0047 public:
0048   typedef TransientTrackingRecHit::RecHitContainer RecHitContainer;
0049   typedef TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer;
0050   typedef TransientTrackingRecHit::RecHitPointer RecHitPointer;
0051   typedef TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer;
0052   typedef MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer;
0053   typedef MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer;
0054   typedef MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer;
0055   typedef MuonTransientTrackingRecHit::ConstMuonRecHitContainer ConstMuonRecHitContainer;
0056   typedef std::vector<Trajectory> TC;
0057   typedef TC::const_iterator TI;
0058 
0059   /// constructor with Parameter Set and MuonServiceProxy
0060   GlobalTrajectoryBuilderBase(const edm::ParameterSet&, const MuonServiceProxy*, edm::ConsumesCollector&);
0061 
0062   /// destructor
0063   ~GlobalTrajectoryBuilderBase() override;
0064 
0065   /// dummy implementation, unused in this class
0066   MuonTrajectoryBuilder::TrajectoryContainer trajectories(const TrajectorySeed&) override {
0067     return MuonTrajectoryBuilder::TrajectoryContainer();
0068   }
0069 
0070   /// pass the Event to the algo at each event
0071   void setEvent(const edm::Event&) override;
0072 
0073 protected:
0074   enum RefitDirection { inToOut, outToIn, undetermined };
0075 
0076   /// build combined trajectory from sta Track and tracker RecHits
0077   MuonTrajectoryBuilder::CandidateContainer build(const TrackCand&, MuonTrajectoryBuilder::CandidateContainer&) const;
0078 
0079   /// make a TrackCand collection using tracker Track, Trajectory information
0080   virtual std::vector<TrackCand> makeTkCandCollection(const TrackCand&) = 0;
0081 
0082   /// choose tracker tracks within region of interest
0083   std::vector<TrackCand> chooseRegionalTrackerTracks(const TrackCand&, const std::vector<TrackCand>&);
0084 
0085   /// define region of interest with tracker
0086   RectangularEtaPhiTrackingRegion defineRegionOfInterest(const reco::TrackRef&) const;
0087 
0088   /// check muon RecHits, calculate chamber occupancy and select hits to be used in the final fit
0089   void checkMuonHits(const reco::Track&, ConstRecHitContainer&, ConstRecHitContainer&, std::vector<int>&) const;
0090 
0091   /// select muon hits compatible with trajectory; check hits in chambers with showers
0092   ConstRecHitContainer selectMuonHits(const Trajectory&, const std::vector<int>&) const;
0093 
0094   /// select tracker hits; exclude some tracker hits in the global trajectory
0095   ConstRecHitContainer selectTrackerHits(const ConstRecHitContainer&) const;
0096 
0097   /// rescale errors of outermost TEC RecHit
0098   void fixTEC(ConstRecHitContainer& all, double scl_x, double scl_y) const;
0099 
0100   /// choose final trajectory
0101   const Trajectory* chooseTrajectory(const std::vector<Trajectory*>&, int) const;
0102 
0103   /// calculate chi2 probability (-ln(P))
0104   double trackProbability(const Trajectory&) const;
0105 
0106   /// print all RecHits of a trajectory
0107   void printHits(const ConstRecHitContainer&) const;
0108 
0109   /// if TrackCand has only a TrackRef, attempt to add Trajectory*
0110   void addTraj(TrackCand&) {}  ///This does nothing now
0111 
0112   /// check order of RechIts on a trajectory
0113   RefitDirection checkRecHitsOrdering(const ConstRecHitContainer&) const;
0114 
0115   /// get transient RecHits of a Track
0116   TransientTrackingRecHit::ConstRecHitContainer getTransientRecHits(const reco::Track&) const;
0117 
0118   ///
0119   GlobalMuonTrackMatcher* trackMatcher() const { return theTrackMatcher; }
0120 
0121   ///
0122   const MuonServiceProxy* service() const { return theService; }
0123 
0124   struct ComparatorInOut {
0125     bool operator()(const TransientTrackingRecHit::ConstRecHitPointer& a,
0126                     const TransientTrackingRecHit::ConstRecHitPointer& b) const {
0127       bool barrel_a = (a->det()->subDetector() == GeomDetEnumerators::DT ||
0128                        a->det()->subDetector() == GeomDetEnumerators::RPCBarrel);
0129 
0130       bool barrel_b = (b->det()->subDetector() == GeomDetEnumerators::DT ||
0131                        b->det()->subDetector() == GeomDetEnumerators::RPCBarrel);
0132 
0133       if (barrel_a && barrel_b)
0134         return a->det()->surface().position().perp() < b->det()->surface().position().perp();
0135 
0136       else if (!barrel_a && !barrel_b)
0137         return fabs(a->globalPosition().z()) < fabs(b->globalPosition().z());
0138       else if (barrel_a && !barrel_b)
0139         return true;
0140       else if (!barrel_a && barrel_b)
0141         return false;
0142       //shouldn't really get here in any case (there's some sense to throw here )
0143       return false;
0144     }
0145   };
0146 
0147   std::string theCategory;
0148   float thePtCut;
0149   float thePCut;
0150 
0151 private:
0152   GlobalMuonTrackMatcher* theTrackMatcher;
0153   MuonDetLayerMeasurements* theLayerMeasurements;
0154   TrackTransformer* theTrackTransformer;
0155   MuonTrackingRegionBuilder* theRegionBuilder;
0156   const MuonServiceProxy* theService;
0157   GlobalMuonRefitter* theGlbRefitter;
0158   bool theRPCInTheFit;
0159   bool theRefitFlag;
0160   int theMuonHitsOption;
0161   float theTECxScale;
0162   float theTECyScale;
0163   std::string theTrackerPropagatorName;
0164   const edm::Event* theEvent;
0165   edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> theTrackerRecHitBuilderToken;
0166   const TransientTrackingRecHitBuilder* theTrackerRecHitBuilder;
0167   edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> theMuonRecHitBuilderToken;
0168   const TransientTrackingRecHitBuilder* theMuonRecHitBuilder;
0169   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> theTopoToken;
0170   const TrackerTopology* theTopo;
0171   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> theFieldToken;
0172   const MagneticField* theField;
0173   edm::ESGetToken<MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord> theMSMakerToken;
0174   const MultipleScatteringParametrisationMaker* theMSMaker;
0175 };
0176 #endif