Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-16 06:12:37

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     };
0196 
0197     ///
0198     /// ====================== STANDARD SELECTORS ===========================
0199     ///
0200     // When adding new selectors, also update DataFormats/MuonReco/interface/MuonSelectors.h string to enum map
0201     enum Selector {
0202       CutBasedIdLoose = 1UL << 0,
0203       CutBasedIdMedium = 1UL << 1,
0204       CutBasedIdMediumPrompt = 1UL << 2,  // medium with IP cuts
0205       CutBasedIdTight = 1UL << 3,
0206       CutBasedIdGlobalHighPt = 1UL << 4,  // high pt muon for Z',W' (better momentum resolution)
0207       CutBasedIdTrkHighPt = 1UL << 5,     // high pt muon for boosted Z (better efficiency)
0208       PFIsoVeryLoose = 1UL << 6,          // reliso<0.40
0209       PFIsoLoose = 1UL << 7,              // reliso<0.25
0210       PFIsoMedium = 1UL << 8,             // reliso<0.20
0211       PFIsoTight = 1UL << 9,              // reliso<0.15
0212       PFIsoVeryTight = 1UL << 10,         // reliso<0.10
0213       TkIsoLoose = 1UL << 11,             // reliso<0.10
0214       TkIsoTight = 1UL << 12,             // reliso<0.05
0215       SoftCutBasedId = 1UL << 13,
0216       SoftMvaId = 1UL << 14,
0217       MvaLoose = 1UL << 15,
0218       MvaMedium = 1UL << 16,
0219       MvaTight = 1UL << 17,
0220       MiniIsoLoose = 1UL << 18,      // reliso<0.40
0221       MiniIsoMedium = 1UL << 19,     // reliso<0.20
0222       MiniIsoTight = 1UL << 20,      // reliso<0.10
0223       MiniIsoVeryTight = 1UL << 21,  // reliso<0.05
0224       TriggerIdLoose = 1UL << 22,    // robust selector for HLT
0225       InTimeMuon = 1UL << 23,
0226       PFIsoVeryVeryTight = 1UL << 24,  // reliso<0.05
0227       MultiIsoLoose = 1UL << 25,       // miniIso with ptRatio and ptRel
0228       MultiIsoMedium = 1UL << 26,      // miniIso with ptRatio and ptRel
0229       PuppiIsoLoose = 1UL << 27,
0230       PuppiIsoMedium = 1UL << 28,
0231       PuppiIsoTight = 1UL << 29,
0232       MvaVTight = 1UL << 30,
0233       MvaVVTight = 1UL << 31,
0234       LowPtMvaLoose = 1UL << 32,
0235       LowPtMvaMedium = 1UL << 33,
0236       MvaIDwpMedium = 1UL << 34,
0237       MvaIDwpTight = 1UL << 35,
0238     };
0239 
0240     bool passed(uint64_t selection) const { return (selectors_ & selection) == selection; }
0241     bool passed(Selector selection) const { return passed(static_cast<uint64_t>(selection)); }
0242     uint64_t selectors() const { return selectors_; }
0243     void setSelectors(uint64_t selectors) { selectors_ = selectors; }
0244     void setSelector(Selector selector, bool passed) {
0245       if (passed)
0246         selectors_ |= selector;
0247       else
0248         selectors_ &= ~selector;
0249     }
0250 
0251     ///
0252     /// ====================== USEFUL METHODs ===========================
0253     ///
0254     /// number of chambers (MuonChamberMatches include RPC rolls, GEM and ME0 segments)
0255     int numberOfChambers() const { return muMatches_.size(); }
0256     /// number of chambers CSC or DT matches only (MuonChamberMatches include RPC rolls)
0257     int numberOfChambersCSCorDT() const;
0258     /// get number of chambers with matched segments
0259     int numberOfMatches(ArbitrationType type = SegmentAndTrackArbitration) const;
0260     /// get number of stations with matched segments
0261     /// just adds the bits returned by stationMask
0262     int numberOfMatchedStations(ArbitrationType type = SegmentAndTrackArbitration) const;
0263     /// expected number of stations with matching segments based on the absolute
0264     /// distance from the edge of a chamber
0265     unsigned int expectedNnumberOfMatchedStations(float minDistanceFromEdge = 10.0) const;
0266     /// get bit map of stations with matched segments
0267     /// bits 0-1-2-3 = DT stations 1-2-3-4
0268     /// bits 4-5-6-7 = CSC stations 1-2-3-4
0269     unsigned int stationMask(ArbitrationType type = SegmentAndTrackArbitration) const;
0270     /// get bit map of stations with tracks within
0271     /// given distance (in cm) of chamber edges
0272     /// bit assignments are same as above
0273     int numberOfMatchedRPCLayers(ArbitrationType type = RPCHitAndTrackArbitration) const;
0274     unsigned int RPClayerMask(ArbitrationType type = RPCHitAndTrackArbitration) const;
0275     unsigned int stationGapMaskDistance(float distanceCut = 10.) const;
0276     /// same as above for given number of sigmas
0277     unsigned int stationGapMaskPull(float sigmaCut = 3.) const;
0278     /// # of digis in a given station layer
0279     int nDigisInStation(int station, int muonSubdetId) const;
0280     /// tag a shower in a given station layer
0281     bool hasShowerInStation(int station, int muonSubdetId, int nDtDigisCut = 20, int nCscDigisCut = 36) const;
0282     /// count the number of showers along a muon track
0283     int numberOfShowers(int nDtDigisCut = 20, int nCscDigisCut = 36) const;
0284 
0285     /// muon type - type of the algorithm that reconstructed this muon
0286     /// multiple algorithms can reconstruct the same muon
0287     static const unsigned int GlobalMuon = 1 << 1;
0288     static const unsigned int TrackerMuon = 1 << 2;
0289     static const unsigned int StandAloneMuon = 1 << 3;
0290     static const unsigned int CaloMuon = 1 << 4;
0291     static const unsigned int PFMuon = 1 << 5;
0292     static const unsigned int RPCMuon = 1 << 6;
0293     static const unsigned int GEMMuon = 1 << 7;
0294     static const unsigned int ME0Muon = 1 << 8;
0295 
0296     void setType(unsigned int type) { type_ = type; }
0297     unsigned int type() const { return type_; }
0298 
0299     // override of method in base class reco::Candidate
0300     bool isMuon() const override { return true; }
0301     bool isGlobalMuon() const override { return type_ & GlobalMuon; }
0302     bool isTrackerMuon() const override { return type_ & TrackerMuon; }
0303     bool isStandAloneMuon() const override { return type_ & StandAloneMuon; }
0304     bool isCaloMuon() const override { return type_ & CaloMuon; }
0305     bool isPFMuon() const { return type_ & PFMuon; }  //fix me ! Has to go to type
0306     bool isRPCMuon() const { return type_ & RPCMuon; }
0307     bool isGEMMuon() const { return type_ & GEMMuon; }
0308     bool isME0Muon() const { return type_ & ME0Muon; }
0309 
0310   private:
0311     /// check overlap with another candidate
0312     bool overlap(const Candidate&) const override;
0313     /// reference to Track reconstructed in the tracker only
0314     TrackRef innerTrack_;
0315     /// reference to Track reconstructed in the muon detector only
0316     TrackRef outerTrack_;
0317     /// reference to Track reconstructed in both tracked and muon detector
0318     TrackRef globalTrack_;
0319     /// reference to the Global Track refitted with dedicated TeV reconstructors
0320     MuonTrackRefMap refittedTrackMap_;
0321     /// reference to the Track chosen to assign the momentum value to the muon
0322     MuonTrackType bestTrackType_;
0323     /// reference to the Track chosen to assign the momentum value to the muon by PF
0324     MuonTrackType bestTunePTrackType_;
0325 
0326     /// energy deposition
0327     MuonEnergy calEnergy_;
0328     /// quality block
0329     MuonQuality combinedQuality_;
0330     /// Information on matching between tracks and segments
0331     std::vector<MuonChamberMatch> muMatches_;
0332     /// timing
0333     MuonTime time_;
0334     MuonTime rpcTime_;
0335     bool energyValid_;
0336     bool matchesValid_;
0337     bool isolationValid_;
0338     bool pfIsolationValid_;
0339     bool qualityValid_;
0340     /// muon hypothesis compatibility with observer calorimeter energy
0341     float caloCompatibility_;
0342     /// Isolation information for two cones with dR=0.3 and dR=0.5
0343     MuonIsolation isolationR03_;
0344     MuonIsolation isolationR05_;
0345 
0346     /// PF Isolation information for two cones with dR=0.3 and dR=0.4
0347     MuonPFIsolation pfIsolationR03_;
0348     MuonPFIsolation pfIsoMeanDRR03_;
0349     MuonPFIsolation pfIsoSumDRR03_;
0350     MuonPFIsolation pfIsolationR04_;
0351     MuonPFIsolation pfIsoMeanDRR04_;
0352     MuonPFIsolation pfIsoSumDRR04_;
0353 
0354     /// muon type mask
0355     unsigned int type_;
0356 
0357     //PF muon p4
0358     reco::Candidate::LorentzVector pfP4_;
0359 
0360     // FixMe: Still missing trigger information
0361 
0362     /// get vector of muon chambers for given station and detector
0363     const std::vector<const MuonChamberMatch*> chambers(int station, int muonSubdetId) const;
0364     /// get pointers to best segment and corresponding chamber in vector of chambers
0365     std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> pair(
0366         const std::vector<const MuonChamberMatch*>&, ArbitrationType type = SegmentAndTrackArbitration) const;
0367     /// selector bitmap
0368     uint64_t selectors_;
0369 
0370   public:
0371     /// get number of segments
0372     int numberOfSegments(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0373     /// get deltas between (best) segment and track
0374     /// If no chamber or no segment returns 999999
0375     float dX(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0376     float dY(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0377     float dDxDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0378     float dDyDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0379     float pullX(int station,
0380                 int muonSubdetId,
0381                 ArbitrationType type = SegmentAndTrackArbitration,
0382                 bool includeSegmentError = true) const;
0383     float pullY(int station,
0384                 int muonSubdetId,
0385                 ArbitrationType type = SegmentAndTrackArbitration,
0386                 bool includeSegmentError = true) const;
0387     float pullDxDz(int station,
0388                    int muonSubdetId,
0389                    ArbitrationType type = SegmentAndTrackArbitration,
0390                    bool includeSegmentError = true) const;
0391     float pullDyDz(int station,
0392                    int muonSubdetId,
0393                    ArbitrationType type = SegmentAndTrackArbitration,
0394                    bool includeSegmentError = true) const;
0395     /// get (best) segment information
0396     /// If no segment returns 999999
0397     float segmentX(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0398     float segmentY(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0399     float segmentDxDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0400     float segmentDyDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0401     float segmentXErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0402     float segmentYErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0403     float segmentDxDzErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0404     float segmentDyDzErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0405     /// get track information in chamber that contains (best) segment
0406     /// If no segment, get track information in chamber that has the most negative distance between the track
0407     /// and the nearest chamber edge (the chamber with the deepest track)
0408     /// If no chamber returns 999999
0409     float trackEdgeX(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0410     float trackEdgeY(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0411     float trackX(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0412     float trackY(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0413     float trackDxDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0414     float trackDyDz(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0415     float trackXErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0416     float trackYErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0417     float trackDxDzErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0418     float trackDyDzErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0419     float trackDist(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0420     float trackDistErr(int station, int muonSubdetId, ArbitrationType type = SegmentAndTrackArbitration) const;
0421 
0422     float t0(int n = 0) {
0423       int i = 0;
0424       for (auto& chamber : muMatches_) {
0425         int segmentMatchesSize = (int)chamber.segmentMatches.size();
0426         if (i + segmentMatchesSize < n) {
0427           i += segmentMatchesSize;
0428           continue;
0429         }
0430         return chamber.segmentMatches[n - i].t0;
0431       }
0432       return 0;
0433     }
0434   };
0435 
0436 }  // namespace reco
0437 
0438 #endif