Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:47

0001 #ifndef MuonReco_Muon_h
0002 #define MuonReco_Muon_h
0003 /** \class reco::Muon Muon.h DataFormats/MuonReco/interface/Muon.h
0004  *  
0005  * A reconstructed Muon.
0006  * contains reference to three fits:
0007  *  - tracker alone
0008  *  - muon detector alone
0009  *  - combined muon plus tracker
0010  *
0011  * \author Luca Lista, Claudio Campagnari, Dmytro Kovalskyi, Jake Ribnik, Riccardo Bellan, Michalis Bachtis
0012  *
0013  *
0014  */
0015 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
0016 #include "DataFormats/MuonReco/interface/MuonChamberMatch.h"
0017 #include "DataFormats/MuonReco/interface/MuonIsolation.h"
0018 #include "DataFormats/MuonReco/interface/MuonPFIsolation.h"
0019 #include "DataFormats/MuonReco/interface/MuonEnergy.h"
0020 #include "DataFormats/MuonReco/interface/MuonTime.h"
0021 #include "DataFormats/MuonReco/interface/MuonQuality.h"
0022 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0023 #include "DataFormats/TrackReco/interface/Track.h"
0024 
0025 namespace reco {
0026 
0027   class Muon : public RecoCandidate {
0028   public:
0029     Muon();
0030     /// constructor from values
0031     Muon(Charge, const LorentzVector&, const Point& = Point(0, 0, 0));
0032     /// create a clone
0033     Muon* clone() const override;
0034 
0035     /// map for Global Muon refitters
0036     enum MuonTrackType { None, InnerTrack, OuterTrack, CombinedTrack, TPFMS, Picky, DYT };
0037     typedef std::map<MuonTrackType, reco::TrackRef> MuonTrackRefMap;
0038     typedef std::pair<TrackRef, Muon::MuonTrackType> MuonTrackTypePair;
0039 
0040     ///
0041     /// ====================== TRACK BLOCK ===========================
0042     ///
0043     /// reference to Track reconstructed in the tracker only
0044     using reco::RecoCandidate::track;
0045     virtual TrackRef innerTrack() const { return innerTrack_; }
0046     TrackRef track() const override { return innerTrack(); }
0047     /// reference to Track reconstructed in the muon detector only
0048     virtual TrackRef outerTrack() const { return outerTrack_; }
0049     TrackRef standAloneMuon() const override { return outerTrack(); }
0050     /// reference to Track reconstructed in both tracked and muon detector
0051     virtual TrackRef globalTrack() const { return globalTrack_; }
0052     TrackRef combinedMuon() const override { return globalTrack(); }
0053 
0054     virtual TrackRef tpfmsTrack() const { return muonTrackFromMap(TPFMS); }
0055     virtual TrackRef pickyTrack() const { return muonTrackFromMap(Picky); }
0056     virtual TrackRef dytTrack() const { return muonTrackFromMap(DYT); }
0057 
0058     const Track* bestTrack() const override { return muonTrack(bestTrackType_).get(); }
0059     TrackBaseRef bestTrackRef() const override { return reco::TrackBaseRef(muonTrack(bestTrackType_)); }
0060     virtual TrackRef muonBestTrack() const { return muonTrack(bestTrackType_); }
0061     virtual MuonTrackType muonBestTrackType() const { return bestTrackType_; }
0062     virtual TrackRef tunePMuonBestTrack() const { return muonTrack(bestTunePTrackType_); }
0063     virtual MuonTrackType tunePMuonBestTrackType() const { return bestTunePTrackType_; }
0064 
0065     bool isAValidMuonTrack(const MuonTrackType& type) const;
0066     TrackRef muonTrack(const MuonTrackType&) const;
0067 
0068     TrackRef muonTrackFromMap(const MuonTrackType& type) const {
0069       MuonTrackRefMap::const_iterator iter = refittedTrackMap_.find(type);
0070       if (iter != refittedTrackMap_.end())
0071         return iter->second;
0072       else
0073         return TrackRef();
0074     }
0075 
0076     /// set reference to Track
0077     virtual void setInnerTrack(const TrackRef& t);
0078     virtual void setTrack(const TrackRef& t);
0079     /// set reference to Track
0080     virtual void setOuterTrack(const TrackRef& t);
0081     virtual void setStandAlone(const TrackRef& t);
0082     /// set reference to Track
0083     virtual void setGlobalTrack(const TrackRef& t);
0084     virtual void setCombined(const TrackRef& t);
0085     // set reference to the Best Track
0086     virtual void setBestTrack(MuonTrackType muonType) { bestTrackType_ = muonType; }
0087     // set reference to the Best Track by PF
0088     virtual void setTunePBestTrack(MuonTrackType muonType) { bestTunePTrackType_ = muonType; }
0089 
0090     void setMuonTrack(const MuonTrackType&, const TrackRef&);
0091 
0092     ///set reference to PFCandidate
0093     ///
0094     /// ====================== PF BLOCK ===========================
0095     ///
0096 
0097     reco::Candidate::LorentzVector pfP4() const { return pfP4_; }
0098     virtual void setPFP4(const reco::Candidate::LorentzVector& p4_);
0099 
0100     ///
0101     /// ====================== ENERGY BLOCK ===========================
0102     ///
0103     /// energy deposition
0104     bool isEnergyValid() const { return energyValid_; }
0105     /// get energy deposition information
0106     MuonEnergy calEnergy() const { return calEnergy_; }
0107     /// set energy deposition information
0108     void setCalEnergy(const MuonEnergy& calEnergy) {
0109       calEnergy_ = calEnergy;
0110       energyValid_ = true;
0111     }
0112 
0113     ///
0114     /// ====================== Quality BLOCK ===========================
0115     ///
0116     /// energy deposition
0117     bool isQualityValid() const { return qualityValid_; }
0118     /// get energy deposition information
0119     MuonQuality combinedQuality() const { return combinedQuality_; }
0120     /// set energy deposition information
0121     void setCombinedQuality(const MuonQuality& combinedQuality) {
0122       combinedQuality_ = combinedQuality;
0123       qualityValid_ = true;
0124     }
0125 
0126     ///
0127     /// ====================== TIMING BLOCK ===========================
0128     ///
0129     /// timing information
0130     bool isTimeValid() const { return (time_.nDof > 0); }
0131     /// get DT/CSC combined timing information
0132     MuonTime time() const { return time_; }
0133     /// set DT/CSC combined timing information
0134     void setTime(const MuonTime& time) { time_ = time; }
0135     /// get RPC timing information
0136     MuonTime rpcTime() const { return rpcTime_; }
0137     /// set RPC timing information
0138     void setRPCTime(const MuonTime& time) { rpcTime_ = time; }
0139 
0140     ///
0141     /// ====================== MUON MATCH BLOCK ===========================
0142     ///
0143     bool isMatchesValid() const { return matchesValid_; }
0144     /// get muon matching information
0145     std::vector<MuonChamberMatch>& matches() { return muMatches_; }
0146     const std::vector<MuonChamberMatch>& matches() const { return muMatches_; }
0147     /// set muon matching information
0148     void setMatches(const std::vector<MuonChamberMatch>& matches) {
0149       muMatches_ = matches;
0150       matchesValid_ = true;
0151     }
0152 
0153     ///
0154     /// ====================== MUON COMPATIBILITY BLOCK ===========================
0155     ///
0156     /// Relative likelihood based on ECAL, HCAL, HO energy defined as
0157     /// L_muon/(L_muon+L_not_muon)
0158     float caloCompatibility() const { return caloCompatibility_; }
0159     void setCaloCompatibility(float input) { caloCompatibility_ = input; }
0160     bool isCaloCompatibilityValid() const { return caloCompatibility_ >= 0; }
0161 
0162     ///
0163     /// ====================== ISOLATION BLOCK ===========================
0164     ///
0165     /// Summary of muon isolation information
0166     const MuonIsolation& isolationR03() const { return isolationR03_; }
0167     const MuonIsolation& isolationR05() const { return isolationR05_; }
0168 
0169     const MuonPFIsolation& pfIsolationR03() const { return pfIsolationR03_; }
0170     const MuonPFIsolation& pfMeanDRIsoProfileR03() const { return pfIsoMeanDRR03_; }
0171     const MuonPFIsolation& pfSumDRIsoProfileR03() const { return pfIsoSumDRR03_; }
0172     const MuonPFIsolation& pfIsolationR04() const { return pfIsolationR04_; }
0173     const MuonPFIsolation& pfMeanDRIsoProfileR04() const { return pfIsoMeanDRR04_; }
0174     const MuonPFIsolation& pfSumDRIsoProfileR04() const { return pfIsoSumDRR04_; }
0175 
0176     void setIsolation(const MuonIsolation& isoR03, const MuonIsolation& isoR05);
0177     bool isIsolationValid() const { return isolationValid_; }
0178     void setPFIsolation(const std::string& label, const reco::MuonPFIsolation& deposit);
0179 
0180     bool isPFIsolationValid() const { return pfIsolationValid_; }
0181 
0182     /// define arbitration schemes
0183     // WARNING: There can be not more than 7 arbritration types. If
0184     //          have more it will break the matching logic for types
0185     //          defined in MuonSegmentMatch
0186 
0187     enum ArbitrationType {
0188       NoArbitration,
0189       SegmentArbitration,
0190       SegmentAndTrackArbitration,
0191       SegmentAndTrackArbitrationCleaned,
0192       RPCHitAndTrackArbitration,
0193       GEMSegmentAndTrackArbitration,
0194       ME0SegmentAndTrackArbitration,
0195       GEMHitAndTrackArbitration
0196     };
0197 
0198     ///
0199     /// ====================== STANDARD SELECTORS ===========================
0200     ///
0201     // When adding new selectors, also update DataFormats/MuonReco/interface/MuonSelectors.h string to enum map
0202     enum Selector {
0203       CutBasedIdLoose = 0,
0204       CutBasedIdMedium = 1,
0205       CutBasedIdMediumPrompt = 2,  // medium with IP cuts
0206       CutBasedIdTight = 3,
0207       CutBasedIdGlobalHighPt = 4,  // high pt muon for Z',W' (better momentum resolution)
0208       CutBasedIdTrkHighPt = 5,     // high pt muon for boosted Z (better efficiency)
0209       PFIsoVeryLoose = 6,          // reliso<0.40
0210       PFIsoLoose = 7,              // reliso<0.25
0211       PFIsoMedium = 8,             // reliso<0.20
0212       PFIsoTight = 9,              // reliso<0.15
0213       PFIsoVeryTight = 10,         // reliso<0.10
0214       TkIsoLoose = 11,             // reliso<0.10
0215       TkIsoTight = 12,             // reliso<0.05
0216       SoftCutBasedId = 13,
0217       SoftMvaId = 14,
0218       MvaLoose = 15,
0219       MvaMedium = 16,
0220       MvaTight = 17,
0221       MiniIsoLoose = 18,      // reliso<0.40
0222       MiniIsoMedium = 19,     // reliso<0.20
0223       MiniIsoTight = 20,      // reliso<0.10
0224       MiniIsoVeryTight = 21,  // reliso<0.05
0225       TriggerIdLoose = 22,    // robust selector for HLT
0226       InTimeMuon = 23,
0227       PFIsoVeryVeryTight = 24,  // reliso<0.05
0228       MultiIsoLoose = 25,       // miniIso with ptRatio and ptRel
0229       MultiIsoMedium = 26,      // miniIso with ptRatio and ptRel
0230       PuppiIsoLoose = 27,
0231       PuppiIsoMedium = 28,
0232       PuppiIsoTight = 29,
0233       MvaVTight = 30,
0234       MvaVVTight = 31,
0235       LowPtMvaLoose = 32,
0236       LowPtMvaMedium = 33,
0237       MvaIDwpMedium = 34,
0238       MvaIDwpTight = 35,
0239     };
0240 
0241     bool passed(uint64_t selection) const { return (selectors_ & selection) == selection; }
0242     bool passed(Selector selection) const { return passed(static_cast<uint64_t>(1UL << selection)); }
0243     uint64_t selectors() const { return selectors_; }
0244     void setSelectors(uint64_t selectors) { selectors_ = selectors; }
0245     void setSelector(Selector selector, bool passed) {
0246       auto selector64 = 1UL << selector;
0247       if (passed)
0248         selectors_ |= selector64;
0249       else
0250         selectors_ &= ~selector64;
0251     }
0252 
0253     ///
0254     /// ====================== USEFUL METHODs ===========================
0255     ///
0256     /// number of chambers (MuonChamberMatches include RPC rolls, GEM and ME0 segments)
0257     int numberOfChambers() const { return muMatches_.size(); }
0258     /// number of chambers CSC or DT matches only (MuonChamberMatches include RPC rolls)
0259     int numberOfChambersCSCorDT() const;
0260     /// get number of chambers with matched segments
0261     int numberOfMatches(ArbitrationType type = SegmentAndTrackArbitration) const;
0262     /// get number of stations with matched segments
0263     /// just adds the bits returned by stationMask
0264     int numberOfMatchedStations(ArbitrationType type = SegmentAndTrackArbitration) const;
0265     /// expected number of stations with matching segments based on the absolute
0266     /// distance from the edge of a chamber
0267     unsigned int expectedNnumberOfMatchedStations(float minDistanceFromEdge = 10.0) const;
0268     /// get bit map of stations with matched segments
0269     /// bits 0-1-2-3 = DT stations 1-2-3-4
0270     /// bits 4-5-6-7 = CSC stations 1-2-3-4
0271     unsigned int stationMask(ArbitrationType type = SegmentAndTrackArbitration) const;
0272     /// get bit map of stations with tracks within
0273     /// given distance (in cm) of chamber edges
0274     /// bit assignments are same as above
0275     int numberOfMatchedRPCLayers(ArbitrationType type = RPCHitAndTrackArbitration) const;
0276     unsigned int RPClayerMask(ArbitrationType type = RPCHitAndTrackArbitration) const;
0277     unsigned int stationGapMaskDistance(float distanceCut = 10.) const;
0278     /// same as above for given number of sigmas
0279     unsigned int stationGapMaskPull(float sigmaCut = 3.) const;
0280     /// # of digis in a given station layer
0281     int nDigisInStation(int station, int muonSubdetId) const;
0282     /// tag a shower in a given station layer
0283     bool hasShowerInStation(int station, int muonSubdetId, int nDtDigisCut = 20, int nCscDigisCut = 36) const;
0284     /// count the number of showers along a muon track
0285     int numberOfShowers(int nDtDigisCut = 20, int nCscDigisCut = 36) const;
0286 
0287     /// muon type - type of the algorithm that reconstructed this muon
0288     /// multiple algorithms can reconstruct the same muon
0289     static const unsigned int GlobalMuon = 1 << 1;
0290     static const unsigned int TrackerMuon = 1 << 2;
0291     static const unsigned int StandAloneMuon = 1 << 3;
0292     static const unsigned int CaloMuon = 1 << 4;
0293     static const unsigned int PFMuon = 1 << 5;
0294     static const unsigned int RPCMuon = 1 << 6;
0295     static const unsigned int GEMMuon = 1 << 7;
0296     static const unsigned int ME0Muon = 1 << 8;
0297 
0298     void setType(unsigned int type) { type_ = type; }
0299     unsigned int type() const { return type_; }
0300 
0301     // override of method in base class reco::Candidate
0302     bool isMuon() const override { return true; }
0303     bool isGlobalMuon() const override { return type_ & GlobalMuon; }
0304     bool isTrackerMuon() const override { return type_ & TrackerMuon; }
0305     bool isStandAloneMuon() const override { return type_ & StandAloneMuon; }
0306     bool isCaloMuon() const override { return type_ & CaloMuon; }
0307     bool isPFMuon() const { return type_ & PFMuon; }  //fix me ! Has to go to type
0308     bool isRPCMuon() const { return type_ & RPCMuon; }
0309     bool isGEMMuon() const { return type_ & GEMMuon; }
0310     bool isME0Muon() const { return type_ & ME0Muon; }
0311 
0312   private:
0313     /// check overlap with another candidate
0314     bool overlap(const Candidate&) const override;
0315     /// reference to Track reconstructed in the tracker only
0316     TrackRef innerTrack_;
0317     /// reference to Track reconstructed in the muon detector only
0318     TrackRef outerTrack_;
0319     /// reference to Track reconstructed in both tracked and muon detector
0320     TrackRef globalTrack_;
0321     /// reference to the Global Track refitted with dedicated TeV reconstructors
0322     MuonTrackRefMap refittedTrackMap_;
0323     /// reference to the Track chosen to assign the momentum value to the muon
0324     MuonTrackType bestTrackType_;
0325     /// reference to the Track chosen to assign the momentum value to the muon by PF
0326     MuonTrackType bestTunePTrackType_;
0327 
0328     /// energy deposition
0329     MuonEnergy calEnergy_;
0330     /// quality block
0331     MuonQuality combinedQuality_;
0332     /// Information on matching between tracks and segments
0333     std::vector<MuonChamberMatch> muMatches_;
0334     /// timing
0335     MuonTime time_;
0336     MuonTime rpcTime_;
0337     bool energyValid_;
0338     bool matchesValid_;
0339     bool isolationValid_;
0340     bool pfIsolationValid_;
0341     bool qualityValid_;
0342     /// muon hypothesis compatibility with observer calorimeter energy
0343     float caloCompatibility_;
0344     /// Isolation information for two cones with dR=0.3 and dR=0.5
0345     MuonIsolation isolationR03_;
0346     MuonIsolation isolationR05_;
0347 
0348     /// PF Isolation information for two cones with dR=0.3 and dR=0.4
0349     MuonPFIsolation pfIsolationR03_;
0350     MuonPFIsolation pfIsoMeanDRR03_;
0351     MuonPFIsolation pfIsoSumDRR03_;
0352     MuonPFIsolation pfIsolationR04_;
0353     MuonPFIsolation pfIsoMeanDRR04_;
0354     MuonPFIsolation pfIsoSumDRR04_;
0355 
0356     /// muon type mask
0357     unsigned int type_;
0358 
0359     //PF muon p4
0360     reco::Candidate::LorentzVector pfP4_;
0361 
0362     // FixMe: Still missing trigger information
0363 
0364     /// get vector of muon chambers for given station and detector
0365     const std::vector<const MuonChamberMatch*> chambers(int station, int muonSubdetId) const;
0366     /// get pointers to best segment and corresponding chamber in vector of chambers
0367     std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> pair(
0368         const std::vector<const MuonChamberMatch*>&, ArbitrationType type = SegmentAndTrackArbitration) const;
0369     /// selector bitmap
0370     uint64_t selectors_;
0371 
0372   public:
0373     /// get number of segments
0374     int numberOfSegments(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0375     /// get deltas between (best) segment and track
0376     /// If no chamber or no segment returns 999999
0377     float dX(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0378     float dY(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0379     float dDxDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0380     float dDyDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0381     float pullX(int station,
0382                 int muonSubdetId,
0383                 ArbitrationType type = SegmentAndTrackArbitration,
0384                 bool includeSegmentError = true) const;
0385     float pullY(int station,
0386                 int muonSubdetId,
0387                 ArbitrationType type = SegmentAndTrackArbitration,
0388                 bool includeSegmentError = true) const;
0389     float pullDxDz(int station,
0390                    int muonSubdetId,
0391                    ArbitrationType type = SegmentAndTrackArbitration,
0392                    bool includeSegmentError = true) const;
0393     float pullDyDz(int station,
0394                    int muonSubdetId,
0395                    ArbitrationType type = SegmentAndTrackArbitration,
0396                    bool includeSegmentError = true) const;
0397     /// get (best) segment information
0398     /// If no segment returns 999999
0399     float segmentX(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0400     float segmentY(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0401     float segmentDxDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0402     float segmentDyDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0403     float segmentXErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0404     float segmentYErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0405     float segmentDxDzErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0406     float segmentDyDzErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0407     /// get track information in chamber that contains (best) segment
0408     /// If no segment, get track information in chamber that has the most negative distance between the track
0409     /// and the nearest chamber edge (the chamber with the deepest track)
0410     /// If no chamber returns 999999
0411     float trackEdgeX(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0412     float trackEdgeY(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0413     float trackX(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0414     float trackY(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0415     float trackDxDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0416     float trackDyDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0417     float trackXErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0418     float trackYErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0419     float trackDxDzErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0420     float trackDyDzErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0421     float trackDist(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0422     float trackDistErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0423 
0424     float t0(int n = 0) {
0425       int i = 0;
0426       for (auto& chamber : muMatches_) {
0427         int segmentMatchesSize = (int)chamber.segmentMatches.size();
0428         if (i + segmentMatchesSize < n) {
0429           i += segmentMatchesSize;
0430           continue;
0431         }
0432         return chamber.segmentMatches[n - i].t0;
0433       }
0434       return 0;
0435     }
0436   };
0437 
0438 }  // namespace reco
0439 
0440 #endif