Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:04

0001 #ifndef DQMOFFLINE_L1TRIGGER_L1TMUONDQMOFFLINE_H
0002 #define DQMOFFLINE_L1TRIGGER_L1TMUONDQMOFFLINE_H
0003 
0004 /**
0005  * \file L1TMuonDQMOffline.h
0006  *
0007  * \author J. Pela, C. Battilana
0008 *
0009 * Stage2 Muons implementation: Anna Stakia 
0010 *
0011  */
0012 
0013 // system include files
0014 #include <memory>
0015 
0016 // user include files
0017 #include "DataFormats/L1Trigger/interface/Muon.h"
0018 #include "DataFormats/L1Trigger/interface/BXVector.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/Framework/interface/ESHandle.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/LuminosityBlock.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/Common/interface/TriggerNames.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "DQMServices/Core/interface/DQMStore.h"
0027 #include "FWCore/ServiceRegistry/interface/Service.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 #include "DataFormats/MuonReco/interface/Muon.h"
0030 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0031 #include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h"
0032 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0033 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
0034 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
0035 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0036 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
0037 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0038 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0039 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0040 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0041 #include "DataFormats/VertexReco/interface/Vertex.h"
0042 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0043 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0044 #include "DataFormats/Math/interface/deltaR.h"
0045 #include "DataFormats/Math/interface/deltaPhi.h"
0046 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0047 #include "DataFormats/Common/interface/TriggerResults.h"
0048 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0049 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0050 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0051 
0052 #include "TRegexp.h"
0053 #include "TString.h"
0054 #include <utility>
0055 #include <vector>
0056 
0057 class MuonGmtPair;
0058 
0059 //
0060 // DQM class declaration
0061 //
0062 
0063 class L1TMuonDQMOffline : public DQMEDAnalyzer {
0064 public:
0065   enum Control {
0066     kCtrlTagPt,
0067     kCtrlTagEta,
0068     kCtrlTagPhi,
0069     kCtrlProbePt,
0070     kCtrlProbeEta,
0071     kCtrlProbePhi,
0072     kCtrlTagProbeDr,
0073     kCtrlTagHltDr,
0074     kCtrlMuonGmtDeltaR,
0075     kCtrlNTightVsAll,
0076     kCtrlNProbesVsTight
0077   };
0078   enum EffType { kEffPt, kEffPhi, kEffEta, kEffVtx };
0079   enum ResType { kResPt, kRes1OverPt, kResQOverPt, kResPhi, kResEta, kResCh };
0080   enum EtaRegion { kEtaRegionAll, kEtaRegionBmtf, kEtaRegionOmtf, kEtaRegionEmtf, kEtaRegionOut };
0081   enum QualLevel { kQualAll, kQualOpen, kQualDouble, kQualSingle };
0082 
0083   L1TMuonDQMOffline(const edm::ParameterSet& ps);
0084   ~L1TMuonDQMOffline() override;
0085 
0086 protected:
0087   void dqmBeginRun(const edm::Run& run, const edm::EventSetup& iSetup) override;
0088   virtual void bookControlHistos(DQMStore::IBooker&);
0089   virtual void bookEfficiencyHistos(DQMStore::IBooker& ibooker);
0090   virtual void bookResolutionHistos(DQMStore::IBooker& ibooker);
0091   void bookHistograms(DQMStore::IBooker& ibooker, const edm::Run& run, const edm::EventSetup& iSetup) override;
0092   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0093 
0094 private:
0095   // Helper Functions
0096   const unsigned int getNVertices(edm::Handle<reco::VertexCollection>& vertex);
0097   const reco::Vertex getPrimaryVertex(edm::Handle<reco::VertexCollection>& vertex,
0098                                       edm::Handle<reco::BeamSpot>& beamSpot);
0099   double matchHlt(edm::Handle<trigger::TriggerEvent>& triggerEvent, const reco::Muon* mu);
0100 
0101   // Cut and Matching
0102   void getMuonGmtPairs(edm::Handle<l1t::MuonBxCollection>& gmtCands, PropagateToMuon const& propagator);
0103   void getTightMuons(edm::Handle<reco::MuonCollection>& muons, const reco::Vertex& vertex);
0104   void getProbeMuons(edm::Handle<edm::TriggerResults>& trigResults, edm::Handle<trigger::TriggerEvent>& trigEvent);
0105 
0106   HLTConfigProvider m_hltConfig;
0107 
0108   PropagateToMuonSetup const m_propagatorSetup;
0109 
0110   std::vector<float> getHistBinsEff(EffType eff);
0111   std::tuple<int, double, double> getHistBinsRes(ResType res);
0112 
0113   // Keys for histogram maps
0114   typedef std::tuple<ResType, EtaRegion, QualLevel> m_histoKeyResType;  // resolution histograms
0115   typedef std::tuple<EffType, int, EtaRegion, QualLevel>
0116       m_histoKeyEffNumVarType;  // efficiency numerator histograms for all variables except eta
0117   typedef std::pair<int, QualLevel> m_histoKeyEffNumEtaType;  // efficiency numerator histograms for eta variable
0118   typedef std::tuple<EffType, int, EtaRegion>
0119       m_histoKeyEffDenVarType;  // efficiency denominator histograms for all variables except eta
0120 
0121   // Histograms and histogram containers
0122   std::map<std::tuple<EffType, int, EtaRegion, QualLevel>, MonitorElement*> m_EfficiencyNumVarHistos;
0123   std::map<std::pair<int, QualLevel>, MonitorElement*> m_EfficiencyNumEtaHistos;
0124   std::map<std::tuple<EffType, int, EtaRegion>, MonitorElement*> m_EfficiencyDenVarHistos;
0125   std::map<EtaRegion, MonitorElement*> m_EfficiencyDenPtHistos;
0126   std::map<int, MonitorElement*> m_EfficiencyDenEtaHistos;
0127   std::map<std::tuple<ResType, EtaRegion, QualLevel>, MonitorElement*> m_ResolutionHistos;
0128   std::map<Control, MonitorElement*> m_ControlHistos;
0129 
0130   // helper variables
0131   std::vector<const reco::Muon*> m_TightMuons;
0132   std::vector<const reco::Muon*> m_ProbeMuons;
0133   std::vector<MuonGmtPair> m_MuonGmtPairs;
0134 
0135   std::vector<reco::MuonCollection> m_RecoMuons;
0136   std::vector<l1t::MuonBxCollection> m_L1tMuons;
0137   std::vector<reco::Muon> m_RecoRecoMuons;
0138   BXVector<l1t::Muon> m_L1tL1tMuons;
0139 
0140   std::vector<std::pair<int, QualLevel>> m_cuts;
0141 
0142   // vectors of enum values to loop over
0143   const std::vector<EffType> m_effTypes;
0144   const std::vector<ResType> m_resTypes;
0145   const std::vector<EtaRegion> m_etaRegions;
0146   const std::vector<QualLevel> m_qualLevelsRes;
0147 
0148   // maps with histogram name bits
0149   std::map<EffType, std::string> m_effStrings;
0150   std::map<EffType, std::string> m_effLabelStrings;
0151   std::map<ResType, std::string> m_resStrings;
0152   std::map<ResType, std::string> m_resLabelStrings;
0153   std::map<EtaRegion, std::string> m_etaStrings;
0154   std::map<QualLevel, std::string> m_qualStrings;
0155 
0156   // config params
0157   bool m_verbose;
0158   std::string m_HistFolder;
0159   double m_TagPtCut;
0160   double m_recoToL1PtCutFactor;
0161   std::vector<edm::ParameterSet> m_cutsVPSet;
0162   edm::EDGetTokenT<reco::MuonCollection> m_MuonInputTag;
0163   edm::EDGetTokenT<l1t::MuonBxCollection> m_GmtInputTag;
0164   edm::EDGetTokenT<reco::VertexCollection> m_VtxInputTag;
0165   edm::EDGetTokenT<reco::BeamSpot> m_BsInputTag;
0166   edm::EDGetTokenT<trigger::TriggerEvent> m_trigInputTag;
0167   std::string m_trigProcess;
0168   edm::EDGetTokenT<edm::TriggerResults> m_trigProcess_token;
0169 
0170   std::vector<std::string> m_trigNames;
0171   std::vector<double> m_effVsPtBins;
0172   std::vector<double> m_effVsPhiBins;
0173   std::vector<double> m_effVsEtaBins;
0174   std::vector<double> m_effVsVtxBins;
0175 
0176   std::vector<int> m_trigIndices;
0177 
0178   bool m_useAtVtxCoord;
0179   float m_maxGmtMuonDR;
0180   float m_minTagProbeDR;
0181   float m_maxHltMuonDR;
0182 };
0183 
0184 //
0185 // helper class to manage GMT-Muon pairing
0186 //
0187 class MuonGmtPair {
0188 public:
0189   MuonGmtPair(const reco::Muon* muon, const l1t::Muon* regMu, const PropagateToMuon& propagator, bool useAtVtxCoord);
0190   MuonGmtPair(const MuonGmtPair& muonGmtPair);
0191   MuonGmtPair& operator=(const MuonGmtPair& muonGmtPair) = default;
0192   ~MuonGmtPair() {}
0193 
0194   double dR();
0195   double pt() const { return m_muon->pt(); };
0196   double eta() const { return m_muon->eta(); };
0197   double phi() const { return m_muon->phi(); };
0198   int charge() const { return m_muon->charge(); };
0199   double gmtPt() const { return m_regMu ? m_regMu->pt() : -1.; };
0200   double gmtEta() const { return m_regMu ? m_gmtEta : -5.; };
0201   double gmtPhi() const { return m_regMu ? m_gmtPhi : -5.; };
0202   int gmtCharge() const { return m_regMu ? m_regMu->charge() : -5; };
0203   int gmtQual() const { return m_regMu ? m_regMu->hwQual() : -1; };
0204 
0205   L1TMuonDQMOffline::EtaRegion etaRegion() const;
0206   double getDeltaVar(const L1TMuonDQMOffline::ResType) const;
0207   double getVar(const L1TMuonDQMOffline::EffType) const;
0208 
0209 private:
0210   const reco::Muon* m_muon;
0211   const l1t::Muon* m_regMu;
0212 
0213   // L1T muon eta and phi coordinates to be used
0214   // Can be the coordinates from the 2nd muon station or from the vertex
0215   double m_gmtEta;
0216   double m_gmtPhi;
0217 
0218   double m_eta;
0219   double m_phi;
0220 };
0221 
0222 #endif