Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-30 01:54:36

0001 #ifndef DQMOFFLINE_L1TRIGGER_L1TPHASE2MUONOFFLINE_H
0002 #define DQMOFFLINE_L1TRIGGER_L1TPHASE2MUONOFFLINE_H
0003 
0004 /**
0005  * \file L1TPhase2MuonOffline.h
0006  *
0007  * \author S. Folgueras
0008 *
0009  */
0010 
0011 // DataFormats
0012 #include "DataFormats/L1Trigger/interface/Muon.h"
0013 #include "DataFormats/L1TMuonPhase2/interface/SAMuon.h"
0014 #include "DataFormats/L1TMuonPhase2/interface/TrackerMuon.h"
0015 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0016 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
0017 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
0018 #include "DataFormats/Math/interface/deltaPhi.h"
0019 
0020 // FWCore
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ServiceRegistry/interface/Service.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 
0028 // DQMServices
0029 #include "DQMServices/Core/interface/DQMStore.h"
0030 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0031 
0032 #include <memory>
0033 #include "TRegexp.h"
0034 #include <utility>
0035 #include <vector>
0036 
0037 class GenMuonGMTPair;
0038 
0039 //
0040 // DQM class declaration
0041 //
0042 
0043 class L1TPhase2MuonOffline : public DQMEDAnalyzer {
0044 public:
0045   L1TPhase2MuonOffline(const edm::ParameterSet& ps);
0046   ~L1TPhase2MuonOffline() override = default;
0047 
0048   enum MuType { kSAMuon, kTkMuon, kNMuTypes };
0049   enum VarType { kPt, kEta, kPhi, kIso, kQual, kZ0, kD0, kNVarTypes };
0050   enum EffType { kEffPt, kEffPhi, kEffEta, kEffTypes };
0051   enum ResType { kResPt, kRes1OverPt, kResQOverPt, kResPhi, kResEta, kResCh, kNResTypes };
0052   enum EtaRegion { kEtaRegionAll, kEtaRegionBmtf, kEtaRegionOmtf, kEtaRegionEmtf, kNEtaRegions };
0053   enum QualLevel { kQualOpen, kQualDouble, kQualSingle, kNQualLevels };
0054 
0055 protected:
0056   void dqmBeginRun(const edm::Run& run, const edm::EventSetup& iSetup) override;
0057   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0058 
0059   void bookControlHistos(DQMStore::IBooker&, MuType type);
0060   void bookEfficiencyHistos(DQMStore::IBooker& ibooker, MuType type);
0061   void bookResolutionHistos(DQMStore::IBooker& ibooker, MuType type);
0062   void bookHistograms(DQMStore::IBooker& ibooker, const edm::Run& run, const edm::EventSetup& iSetup) override;
0063 
0064   //Fill Histos
0065   void fillControlHistos();
0066   void fillEfficiencyHistos();
0067   void fillResolutionHistos();
0068 
0069 private:
0070   // Cut and Matching
0071   void getMuonGmtPairs(edm::Handle<l1t::MuonBxCollection>& gmtCands);
0072 
0073   // Handles and Tokens
0074   edm::EDGetTokenT<l1t::SAMuonCollection> gmtMuonToken_;
0075   edm::EDGetTokenT<l1t::TrackerMuonCollection> gmtTkMuonToken_;
0076   edm::EDGetTokenT<std::vector<reco::GenParticle>> genParticleToken_;
0077 
0078   edm::Handle<l1t::SAMuonCollection> gmtSAMuon_;
0079   edm::Handle<l1t::TrackerMuonCollection> gmtTkMuon_;
0080   edm::Handle<std::vector<reco::GenParticle>> genparticles_;
0081 
0082   //  PropagateToMuon muonpropagator_;
0083 
0084   // vectors of enum values to loop over (and store quantities)
0085   const std::vector<MuType> muonTypes_;
0086   const std::vector<EffType> effTypes_;
0087   const std::vector<ResType> resTypes_;
0088   //  const std::vector<VarType> varTypes_;
0089   const std::vector<EtaRegion> etaRegions_;
0090   const std::vector<QualLevel> qualLevels_;
0091 
0092   // maps with histogram name bits
0093   //  std::map<EffType, std::string> effNames_;
0094   //  std::map<EffType, std::string> effLabels_;
0095   std::map<ResType, std::string> resNames_;
0096   std::map<ResType, std::string> resLabels_;
0097   std::map<EtaRegion, std::string> etaNames_;
0098   std::map<QualLevel, std::string> qualNames_;
0099   std::map<MuType, std::string> muonNames_;
0100 
0101   // config params
0102   const std::string histFolder_;
0103   const std::vector<edm::ParameterSet> cutsVPSet_;
0104 
0105   const std::vector<double> effVsPtBins_;
0106   const std::vector<double> effVsPhiBins_;
0107   const std::vector<double> effVsEtaBins_;
0108 
0109   const double maxGmtMuonDR_;
0110 
0111   // Helper methods
0112   void matchMuonsToGen(std::vector<const reco::GenParticle*> genmus);
0113   std::vector<float> getHistBinsEff(EffType eff);
0114   std::tuple<int, double, double> getHistBinsRes(ResType res);
0115 
0116   MonitorElement* efficiencyNum_[kNMuTypes][kNEtaRegions][kNQualLevels][kEffTypes];
0117   MonitorElement* efficiencyDen_[kNMuTypes][kNEtaRegions][kNQualLevels][kEffTypes];
0118   MonitorElement* resolutionHistos_[kNMuTypes][kNEtaRegions][kNQualLevels][kNResTypes];
0119   MonitorElement* controlHistos_[kNMuTypes][kNVarTypes];
0120 
0121   // helper variables
0122   std::vector<GenMuonGMTPair> gmtSAMuonPairs_;
0123   std::vector<GenMuonGMTPair> gmtTkMuonPairs_;
0124   std::vector<std::pair<int, QualLevel>> cuts_;
0125 
0126   const float lsb_pt = Phase2L1GMT::LSBpt;
0127   const float lsb_phi = Phase2L1GMT::LSBphi;
0128   const float lsb_eta = Phase2L1GMT::LSBeta;
0129   const float lsb_z0 = Phase2L1GMT::LSBSAz0;
0130   const float lsb_d0 = Phase2L1GMT::LSBSAd0;
0131 };
0132 
0133 //
0134 // helper class to manage GMT-GenMuon pairing
0135 //
0136 class GenMuonGMTPair {
0137 public:
0138   GenMuonGMTPair(const reco::GenParticle* mu, const l1t::L1Candidate* gmtmu);
0139   GenMuonGMTPair(const GenMuonGMTPair& muongmtPair);
0140   GenMuonGMTPair& operator=(const GenMuonGMTPair& muongmtPair) = default;
0141   ~GenMuonGMTPair(){};
0142 
0143   float dR2();
0144   float pt() const { return mu_->pt(); };
0145   float eta() const { return mu_->eta(); };
0146   float phi() const { return mu_->phi(); };
0147   int charge() const { return mu_->charge(); };
0148 
0149   // Now properties of the L1 candidate:
0150   float gmtPt() const { return gmtmu_ ? gmtmu_->pt() : -1.; };
0151   float gmtEta() const { return gmtmu_ ? gmtEta_ : -5.; };
0152   float gmtPhi() const { return gmtmu_ ? gmtPhi_ : -5.; };
0153   int gmtCharge() const { return gmtmu_ ? gmtmu_->charge() : -5; };
0154   int gmtQual() const { return gmtmu_ ? gmtmu_->hwQual() : -1; };
0155 
0156   L1TPhase2MuonOffline::EtaRegion etaRegion() const;
0157   double getDeltaVar(const L1TPhase2MuonOffline::ResType) const;
0158   double getVar(const L1TPhase2MuonOffline::EffType) const;
0159 
0160 private:
0161   const reco::GenParticle* mu_;
0162   const l1t::L1Candidate* gmtmu_;
0163 
0164   // L1T muon eta and phi coordinates to be used
0165   // Can be the coordinates from the 2nd muon station or from the vertex
0166   float gmtEta_;
0167   float gmtPhi_;
0168 
0169   float muEta_;
0170   float muPhi_;
0171 };
0172 
0173 #endif