File indexing completed on 2024-04-06 12:18:55
0001 #ifndef HLTriggerOffline_Muon_HLTMuonPlotter_h
0002 #define HLTriggerOffline_Muon_HLTMuonPlotter_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "FWCore/Framework/interface/ConsumesCollector.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016
0017 #include "DataFormats/Candidate/interface/Candidate.h"
0018 #include "DataFormats/Candidate/interface/Particle.h"
0019 #include "DataFormats/Common/interface/RefToBase.h"
0020 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0021 #include "DataFormats/L1Trigger/interface/Muon.h"
0022 #include "DataFormats/TrackReco/interface/Track.h"
0023
0024 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0025 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
0026 #include "DataFormats/MuonReco/interface/Muon.h"
0027 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0028 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0029 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0030
0031 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0032
0033 #include "MuonAnalysis/MuonAssociators/interface/L1MuonMatcherAlgo.h"
0034
0035 #include "DQMServices/Core/interface/DQMStore.h"
0036
0037 #include <sstream>
0038 #include <string>
0039 #include <vector>
0040 #include <unordered_map>
0041
0042 #include "TPRegexp.h"
0043
0044 class HLTMuonPlotter {
0045 public:
0046 typedef dqm::legacy::DQMStore DQMStore;
0047 typedef dqm::legacy::MonitorElement MonitorElement;
0048 typedef L1MuonMatcherAlgoT<edm::Transition::BeginRun> L1MuonMatcherAlgoForDQM;
0049
0050 HLTMuonPlotter(const edm::ParameterSet &,
0051 const std::string &,
0052 const std::vector<std::string> &,
0053 const std::vector<std::string> &,
0054 const edm::EDGetTokenT<trigger::TriggerEventWithRefs> &,
0055 const edm::EDGetTokenT<reco::GenParticleCollection> &,
0056 const edm::EDGetTokenT<reco::MuonCollection> &,
0057 const L1MuonMatcherAlgoForDQM &);
0058
0059 ~HLTMuonPlotter() = default;
0060
0061 void beginRun(DQMStore::IBooker &, const edm::Run &, const edm::EventSetup &);
0062 void analyze(const edm::Event &, const edm::EventSetup &);
0063
0064 private:
0065 struct MatchStruct {
0066 const reco::Candidate *candBase;
0067 const l1t::Muon *candL1;
0068 std::vector<const reco::RecoChargedCandidate *> candHlt;
0069 MatchStruct() {
0070 candBase = nullptr;
0071 candL1 = nullptr;
0072 }
0073 MatchStruct(const reco::Candidate *cand) {
0074 candBase = cand;
0075 candL1 = nullptr;
0076 }
0077 bool operator<(MatchStruct match) { return candBase->pt() < match.candBase->pt(); }
0078 bool operator>(MatchStruct match) { return candBase->pt() > match.candBase->pt(); }
0079 };
0080 struct matchesByDescendingPt {
0081 bool operator()(MatchStruct a, MatchStruct b) { return a.candBase->pt() > b.candBase->pt(); }
0082 };
0083
0084 void findMatches(std::vector<MatchStruct> &,
0085 const l1t::MuonVectorRef &candsL1,
0086 const std::vector<std::vector<const reco::RecoChargedCandidate *>> &);
0087
0088 void bookHist(DQMStore::IBooker &, const std::string &, const std::string &, const std::string &, const std::string &);
0089
0090 template <typename T>
0091 std::string vector_to_string(std::vector<T> const &vec, std::string const &delimiter = " ") const;
0092
0093 std::string const hltPath_;
0094 std::string const hltProcessName_;
0095
0096 std::vector<std::string> const moduleLabels_;
0097 std::vector<std::string> const stepLabels_;
0098
0099 edm::EDGetTokenT<trigger::TriggerEventWithRefs> const triggerEventWithRefsToken_;
0100 edm::EDGetTokenT<reco::GenParticleCollection> const genParticleToken_;
0101 edm::EDGetTokenT<reco::MuonCollection> const recMuonToken_;
0102
0103 StringCutObjectSelector<reco::GenParticle> const genMuonSelector_;
0104 StringCutObjectSelector<reco::Muon> const recMuonSelector_;
0105 std::vector<double> const cutsDr_;
0106
0107 std::vector<double> const parametersEta_;
0108 std::vector<double> const parametersPhi_;
0109 std::vector<double> const parametersTurnOn_;
0110
0111 L1MuonMatcherAlgoForDQM l1Matcher_;
0112
0113 bool isInvalid_;
0114
0115 double cutMinPt_;
0116 double cutMaxEta_;
0117
0118 std::unordered_map<std::string, MonitorElement *> elements_;
0119 };
0120
0121 template <typename T>
0122 std::string HLTMuonPlotter::vector_to_string(std::vector<T> const &vec, std::string const &delimiter) const {
0123 if (vec.empty())
0124 return "";
0125 std::stringstream sstr;
0126 for (auto const &foo : vec)
0127 sstr << delimiter << foo;
0128 auto ret = sstr.str();
0129 ret.erase(0, delimiter.size());
0130 return ret;
0131 }
0132
0133 #endif