Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-23 12:04:15

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