Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-27 00:42:22

0001 #ifndef MuonIdentification_MuonIdProducer_h
0002 #define MuonIdentification_MuonIdProducer_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    MuonIdentification
0007 // Class:      MuonIdProducer
0008 //
0009 /*
0010 
0011  Description: reco::Muon producer that can fill various information:
0012               - track-segment matching
0013               - energy deposition
0014               - muon isolation
0015               - muon hypothesis compatibility (calorimeter)
0016               Acceptable inputs:
0017               - reco::TrackCollection
0018               - reco::MuonCollection
0019               - reco::MuonTrackLinksCollection
0020 */
0021 //
0022 // Original Author:  Dmytro Kovalskyi
0023 //
0024 //
0025 
0026 // user include files
0027 #include "FWCore/Framework/interface/Frameworkfwd.h"
0028 #include "FWCore/Framework/interface/stream/EDProducer.h"
0029 
0030 #include "FWCore/Framework/interface/Event.h"
0031 #include "FWCore/Framework/interface/EventSetup.h"
0032 #include "FWCore/Framework/interface/MakerMacros.h"
0033 
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 
0036 #include "DataFormats/Common/interface/Handle.h"
0037 #include "DataFormats/TrackReco/interface/Track.h"
0038 #include "DataFormats/TrackReco/interface/TrackToTrackMap.h"
0039 #include "DataFormats/VertexReco/interface/Vertex.h"
0040 #include "DataFormats/MuonReco/interface/Muon.h"
0041 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
0042 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0043 
0044 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
0045 // #include "Utilities/Timing/interface/TimerStack.h"
0046 
0047 #include "RecoMuon/MuonIdentification/interface/MuonTimingFiller.h"
0048 #include "RecoMuon/MuonIdentification/interface/MuonCaloCompatibility.h"
0049 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractor.h"
0050 #include "RecoMuon/MuonIdentification/interface/MuonShowerDigiFiller.h"
0051 
0052 // RPC-Muon stuffs
0053 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
0054 #include "DataFormats/RPCRecHit/interface/RPCRecHit.h"
0055 #include "DataFormats/MuonReco/interface/MuonRPCHitMatch.h"
0056 
0057 #include "DataFormats/MuonReco/interface/Muon.h"
0058 #include "DataFormats/MuonReco/interface/CaloMuon.h"
0059 
0060 #include "RecoMuon/MuonIdentification/interface/MuonIdTruthInfo.h"
0061 #include "RecoMuon/MuonIdentification/interface/MuonArbitrationMethods.h"
0062 #include "DataFormats/Common/interface/ValueMap.h"
0063 
0064 class MuonMesh;
0065 class MuonKinkFinder;
0066 
0067 class MuonIdProducer : public edm::stream::EDProducer<> {
0068 public:
0069   typedef reco::Muon::MuonTrackType TrackType;
0070 
0071   explicit MuonIdProducer(const edm::ParameterSet&);
0072 
0073   ~MuonIdProducer() override;
0074 
0075   void produce(edm::Event&, const edm::EventSetup&) override;
0076   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0077 
0078   static double sectorPhi(const DetId& id);
0079 
0080   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0081 
0082 private:
0083   void fillMuonId(edm::Event&,
0084                   const edm::EventSetup&,
0085                   reco::Muon&,
0086                   TrackDetectorAssociator::Direction direction = TrackDetectorAssociator::InsideOut);
0087   void fillArbitrationInfo(reco::MuonCollection*, unsigned int muonType = reco::Muon::TrackerMuon);
0088   void arbitrateMuons(reco::MuonCollection*, reco::CaloMuonCollection*);
0089   void fillMuonIsolation(edm::Event&,
0090                          const edm::EventSetup&,
0091                          reco::Muon& aMuon,
0092                          reco::IsoDeposit& trackDep,
0093                          reco::IsoDeposit& ecalDep,
0094                          reco::IsoDeposit& hcalDep,
0095                          reco::IsoDeposit& hoDep,
0096                          reco::IsoDeposit& jetDep);
0097   void fillGlbQuality(edm::Event&, const edm::EventSetup&, reco::Muon& aMuon);
0098   void fillTrackerKink(reco::Muon& aMuon);
0099   void init(edm::Event&, const edm::EventSetup&);
0100 
0101   // make a muon based on a track ref
0102   reco::Muon makeMuon(edm::Event& iEvent, const edm::EventSetup& iSetup, const reco::TrackRef& track, TrackType type);
0103   // make a global muon based on the links object
0104   reco::Muon makeMuon(const reco::MuonTrackLinks& links);
0105 
0106   // make a muon based on track (p4)
0107   reco::Muon makeMuon(const reco::Track& track);
0108 
0109   reco::CaloMuon makeCaloMuon(const reco::Muon&);
0110 
0111   // check if a silicon track satisfies the trackerMuon requirements
0112   bool isGoodTrack(const reco::Track& track);
0113 
0114   bool isGoodTrackerMuon(const reco::Muon& muon);
0115   bool isGoodCaloMuon(const reco::CaloMuon& muon);
0116   bool isGoodRPCMuon(const reco::Muon& muon);
0117   bool isGoodGEMMuon(const reco::Muon& muon);
0118   bool isGoodME0Muon(const reco::Muon& muon);
0119 
0120   // check number of common DetIds for a given trackerMuon and a stand alone
0121   // muon track
0122   int overlap(const reco::Muon& muon, const reco::Track& track);
0123 
0124   unsigned int chamberId(const DetId&);
0125 
0126   double phiOfMuonInteractionRegion(const reco::Muon& muon) const;
0127 
0128   bool checkLinks(const reco::MuonTrackLinks*) const;
0129   inline bool approxEqual(const double a, const double b, const double tol = 1E-3) const {
0130     return std::abs(a - b) < tol;
0131   }
0132 
0133   /// get the segment matches of the appropriate type
0134   std::vector<reco::MuonSegmentMatch>* getSegmentMatches(reco::MuonChamberMatch& chamber, unsigned int muonType) const {
0135     if (muonType == reco::Muon::TrackerMuon)
0136       return &chamber.segmentMatches;
0137     else if (muonType == reco::Muon::ME0Muon)
0138       return &chamber.me0Matches;
0139     else if (muonType == reco::Muon::GEMMuon)
0140       return &chamber.gemMatches;
0141     else
0142       throw cms::Exception("getSegmentMatches called with unsupported muonType");
0143   }
0144 
0145   TrackDetectorAssociator trackAssociator_;
0146   TrackAssociatorParameters parameters_;
0147 
0148   struct ICTypes {
0149     enum ICTypeKey { INNER_TRACKS, OUTER_TRACKS, LINKS, MUONS, TEV_FIRSTHIT, TEV_PICKY, TEV_DYT, NONE };
0150 
0151     static ICTypeKey toKey(const std::string& s) {
0152       if (s == "inner tracks")
0153         return INNER_TRACKS;
0154       else if (s == "outer tracks")
0155         return OUTER_TRACKS;
0156       else if (s == "links")
0157         return LINKS;
0158       else if (s == "muons")
0159         return MUONS;
0160       else if (s == "tev firstHit")
0161         return TEV_FIRSTHIT;
0162       else if (s == "tev picky")
0163         return TEV_PICKY;
0164       else if (s == "tev dyt")
0165         return TEV_DYT;
0166 
0167       throw cms::Exception("FatalError") << "Unknown input collection type: " << s;
0168     }
0169 
0170     static std::string toStr(const ICTypeKey k) {
0171       switch (k) {
0172         case INNER_TRACKS:
0173           return "inner tracks";
0174         case OUTER_TRACKS:
0175           return "outer tracks";
0176         case LINKS:
0177           return "links";
0178         case MUONS:
0179           return "muons";
0180         case TEV_FIRSTHIT:
0181           return "tev firstHit";
0182         case TEV_PICKY:
0183           return "tev picky";
0184         case TEV_DYT:
0185           return "tev dyt";
0186         default:
0187           throw cms::Exception("FatalError") << "Unknown input collection type";
0188       }
0189       return "";
0190     }
0191   };
0192   std::vector<edm::InputTag> inputCollectionLabels_;
0193   std::vector<ICTypes::ICTypeKey> inputCollectionTypes_;
0194 
0195   std::unique_ptr<MuonTimingFiller> theTimingFiller_;
0196 
0197   std::unique_ptr<MuonShowerDigiFiller> theShowerDigiFiller_;
0198 
0199   // selections
0200   double minPt_;
0201   double minP_;
0202   double minPCaloMuon_;
0203   int minNumberOfMatches_;
0204   double maxAbsEta_;
0205   bool addExtraSoftMuons_;
0206 
0207   // matching
0208   double maxAbsDx_;
0209   double maxAbsPullX2_;
0210   double maxAbsDy_;
0211   double maxAbsPullY2_;
0212 
0213   // what information to fill
0214   bool fillCaloCompatibility_;
0215   bool fillEnergy_;
0216   bool storeCrossedHcalRecHits_;
0217   bool fillMatching_;
0218   bool fillShowerDigis_;
0219   bool fillIsolation_;
0220   bool writeIsoDeposits_;
0221   double ptThresholdToFillCandidateP4WithGlobalFit_;
0222   double sigmaThresholdToFillCandidateP4WithGlobalFit_;
0223 
0224   bool arbitrateTrackerMuons_;
0225 
0226   bool debugWithTruthMatching_;
0227 
0228   edm::Handle<reco::TrackCollection> innerTrackCollectionHandle_;
0229   edm::Handle<reco::TrackCollection> outerTrackCollectionHandle_;
0230   edm::Handle<reco::MuonCollection> muonCollectionHandle_;
0231   edm::Handle<reco::MuonTrackLinksCollection> linkCollectionHandle_;
0232   edm::Handle<reco::TrackToTrackMap> tpfmsCollectionHandle_;
0233   edm::Handle<reco::TrackToTrackMap> pickyCollectionHandle_;
0234   edm::Handle<reco::TrackToTrackMap> dytCollectionHandle_;
0235   edm::Handle<reco::VertexCollection> pvHandle_;
0236 
0237   edm::EDGetTokenT<reco::TrackCollection> innerTrackCollectionToken_;
0238   edm::EDGetTokenT<reco::TrackCollection> outerTrackCollectionToken_;
0239   edm::EDGetTokenT<reco::MuonCollection> muonCollectionToken_;
0240   edm::EDGetTokenT<reco::MuonTrackLinksCollection> linkCollectionToken_;
0241   edm::EDGetTokenT<reco::TrackToTrackMap> tpfmsCollectionToken_;
0242   edm::EDGetTokenT<reco::TrackToTrackMap> pickyCollectionToken_;
0243   edm::EDGetTokenT<reco::TrackToTrackMap> dytCollectionToken_;
0244   edm::EDGetTokenT<reco::VertexCollection> pvToken_;
0245 
0246   edm::EDGetTokenT<RPCRecHitCollection> rpcHitToken_;
0247   edm::EDGetTokenT<edm::ValueMap<reco::MuonQuality> > glbQualToken_;
0248 
0249   edm::Handle<RPCRecHitCollection> rpcHitHandle_;
0250   edm::Handle<edm::ValueMap<reco::MuonQuality> > glbQualHandle_;
0251 
0252   const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> geomTokenRun_;
0253   const edm::ESGetToken<Propagator, TrackingComponentsRecord> propagatorToken_;
0254   edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> globalGeomToken_;
0255 
0256   MuonCaloCompatibility muonCaloCompatibility_;
0257   std::unique_ptr<reco::isodeposit::IsoDepositExtractor> muIsoExtractorCalo_;
0258   std::unique_ptr<reco::isodeposit::IsoDepositExtractor> muIsoExtractorTrack_;
0259   std::unique_ptr<reco::isodeposit::IsoDepositExtractor> muIsoExtractorJet_;
0260   std::string trackDepositName_;
0261   std::string ecalDepositName_;
0262   std::string hcalDepositName_;
0263   std::string hoDepositName_;
0264   std::string jetDepositName_;
0265 
0266   bool fillGlobalTrackQuality_;
0267   bool fillGlobalTrackRefits_;
0268   edm::InputTag globalTrackQualityInputTag_;
0269 
0270   edm::InputTag pvInputTag_;
0271   bool selectHighPurity_;
0272   bool fillTrackerKink_;
0273   std::unique_ptr<MuonKinkFinder> trackerKinkFinder_;
0274 
0275   double caloCut_;
0276 
0277   bool arbClean_;
0278   std::unique_ptr<MuonMesh> meshAlgo_;
0279 };
0280 #endif