File indexing completed on 2024-09-11 04:32:34
0001 #ifndef TOPSINGLELEPTONDQM_MINIAOD
0002 #define TOPSINGLELEPTONDQM_MINIAOD
0003
0004 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0005 #include <string>
0006 #include <vector>
0007 #include "FWCore/Utilities/interface/EDGetToken.h"
0008
0009 #include "DataFormats/JetReco/interface/Jet.h"
0010 #include "DQM/Physics/interface/TopDQMHelpers.h"
0011 #include "DataFormats/Common/interface/ValueMap.h"
0012 #include "DataFormats/METReco/interface/CaloMET.h"
0013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0014 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0015 #include "DataFormats/VertexReco/interface/Vertex.h"
0016 #include "FWCore/Framework/interface/ConsumesCollector.h"
0017 #include "FWCore/Framework/interface/EDConsumerBase.h"
0018 #include "FWCore/Utilities/interface/EDGetToken.h"
0019
0020 #include "DataFormats/PatCandidates/interface/Muon.h"
0021 #include "DataFormats/PatCandidates/interface/Electron.h"
0022 #include "DataFormats/PatCandidates/interface/Jet.h"
0023 #include "DataFormats/PatCandidates/interface/MET.h"
0024
0025 namespace TopSingleLepton_miniAOD {
0026 using dqm::legacy::DQMStore;
0027 using dqm::legacy::MonitorElement;
0028
0029 class MonitorEnsemble {
0030 public:
0031
0032 enum Level { STANDARD, VERBOSE, DEBUG };
0033
0034 public:
0035
0036 MonitorEnsemble(const char* label, const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC);
0037
0038 ~MonitorEnsemble() {}
0039
0040
0041 void book(DQMStore::IBooker& ibooker);
0042
0043 void fill(const edm::Event& event, const edm::EventSetup& setup);
0044
0045 private:
0046
0047
0048 std::string monitorPath(const std::string& label) const { return label.substr(label.find(':') + 1); };
0049
0050
0051 std::string selectionPath(const std::string& label) const { return label.substr(0, label.find(':')); };
0052
0053
0054 void triggerBinLabels(std::string channel, const std::vector<std::string> labels);
0055
0056 void fill(const edm::Event& event,
0057 const edm::TriggerResults& triggerTable,
0058 std::string channel,
0059 const std::vector<std::string> labels) const;
0060
0061
0062 bool booked(const std::string histName) const { return hists_.find(histName) != hists_.end(); };
0063
0064 void fill(const std::string histName, double value) const {
0065 if (booked(histName))
0066 hists_.find(histName)->second->Fill(value);
0067 };
0068
0069 void fill(const std::string histName, double xValue, double yValue) const {
0070 if (booked(histName))
0071 hists_.find(histName)->second->Fill(xValue, yValue);
0072 };
0073
0074 void fill(const std::string histName, double xValue, double yValue, double zValue) const {
0075 if (booked(histName))
0076 hists_.find(histName)->second->Fill(xValue, yValue, zValue);
0077 };
0078
0079 private:
0080
0081 Level verbosity_;
0082
0083 std::string label_;
0084
0085 std::vector<edm::EDGetTokenT<edm::View<pat::MET> > > mets_;
0086
0087 edm::EDGetTokenT<edm::View<pat::Jet> > jets_;
0088 edm::EDGetTokenT<edm::View<pat::Muon> > muons_;
0089 edm::EDGetTokenT<edm::View<pat::Electron> > elecs_;
0090 edm::EDGetTokenT<edm::View<reco::Vertex> > pvs_;
0091
0092 edm::EDGetTokenT<edm::TriggerResults> triggerTable_;
0093
0094
0095 std::vector<std::string> triggerPaths_;
0096
0097 edm::InputTag rhoTag;
0098
0099
0100 edm::EDGetTokenT<edm::ValueMap<float> > electronId_;
0101
0102 double eidCutValue_;
0103
0104 std::unique_ptr<StringCutObjectSelector<pat::Electron> > elecIso_;
0105
0106 std::unique_ptr<StringCutObjectSelector<pat::Electron> > elecSelect_;
0107
0108
0109
0110 std::unique_ptr<StringCutObjectSelector<reco::Vertex> > pvSelect_;
0111
0112
0113 std::unique_ptr<StringCutObjectSelector<pat::Muon> > muonIso_;
0114
0115
0116 std::unique_ptr<StringCutObjectSelector<pat::Muon> > muonSelect_;
0117
0118
0119 edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;
0120
0121 std::unique_ptr<StringCutObjectSelector<reco::JetID> > jetIDSelect_;
0122
0123
0124 std::string jetSelect_;
0125 std::unique_ptr<StringCutObjectSelector<pat::Jet> > jetSelect;
0126
0127
0128 bool includeBTag_;
0129
0130 edm::EDGetTokenT<reco::JetTagCollection> btagEff_, btagPur_, btagVtx_, btagCSV_;
0131
0132 double btagEffWP_, btagPurWP_, btagVtxWP_, btagCSVWP_;
0133
0134 double lowerEdge_, upperEdge_;
0135
0136
0137 int logged_;
0138
0139
0140 std::map<std::string, MonitorElement*> hists_;
0141 edm::EDConsumerBase tmpConsumerBase;
0142 std::string directory_;
0143 };
0144
0145 inline void MonitorEnsemble::triggerBinLabels(std::string channel, const std::vector<std::string> labels) {
0146 for (unsigned int idx = 0; idx < labels.size(); ++idx) {
0147 hists_[channel + "Mon_"]->setBinLabel(idx + 1, "[" + monitorPath(labels[idx]) + "]", 1);
0148 hists_[channel + "Eff_"]->setBinLabel(
0149 idx + 1, "[" + selectionPath(labels[idx]) + "]|[" + monitorPath(labels[idx]) + "]", 1);
0150 }
0151 }
0152
0153 inline void MonitorEnsemble::fill(const edm::Event& event,
0154 const edm::TriggerResults& triggerTable,
0155 std::string channel,
0156 const std::vector<std::string> labels) const {
0157 for (unsigned int idx = 0; idx < labels.size(); ++idx) {
0158 if (accept(event, triggerTable, monitorPath(labels[idx]))) {
0159 fill(channel + "Mon_", idx + 0.5);
0160
0161 int evts = hists_.find(channel + "Mon_")->second->getBinContent(idx + 1);
0162 double value = hists_.find(channel + "Eff_")->second->getBinContent(idx + 1);
0163 fill(
0164 channel + "Eff_", idx + 0.5, 1. / evts * (accept(event, triggerTable, selectionPath(labels[idx])) - value));
0165 }
0166 }
0167 }
0168 }
0169
0170 #include <utility>
0171
0172 #include "DQM/Physics/interface/TopDQMHelpers.h"
0173 #include "FWCore/Framework/interface/Frameworkfwd.h"
0174 #include "FWCore/ServiceRegistry/interface/Service.h"
0175 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0176
0177 #include "FWCore/Common/interface/TriggerNames.h"
0178 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0179 #include "DataFormats/VertexReco/interface/Vertex.h"
0180 #include "DataFormats/Common/interface/TriggerResults.h"
0181
0182 class TopSingleLeptonDQM_miniAOD : public DQMOneEDAnalyzer<> {
0183 public:
0184
0185 TopSingleLeptonDQM_miniAOD(const edm::ParameterSet& cfg);
0186
0187 ~TopSingleLeptonDQM_miniAOD() override {}
0188
0189
0190 void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
0191
0192 protected:
0193
0194 void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0195
0196 private:
0197
0198
0199 std::string objectType(const std::string& label) { return label.substr(0, label.find(':')); };
0200
0201
0202 std::string selectionStep(const std::string& label) { return label.substr(label.find(':') + 1); };
0203
0204 private:
0205
0206 edm::EDGetTokenT<edm::TriggerResults> triggerTable__;
0207
0208 std::vector<std::string> triggerPaths_;
0209
0210 std::unique_ptr<StringCutObjectSelector<reco::Vertex> > vertexSelect_;
0211
0212
0213 edm::InputTag beamspot_;
0214 edm::EDGetTokenT<reco::BeamSpot> beamspot__;
0215
0216 std::unique_ptr<StringCutObjectSelector<reco::BeamSpot> > beamspotSelect_;
0217
0218
0219
0220 std::vector<std::string> selectionOrder_;
0221
0222
0223
0224
0225
0226 std::map<std::string, std::pair<edm::ParameterSet, std::unique_ptr<TopSingleLepton_miniAOD::MonitorEnsemble> > >
0227 selection_;
0228 std::unique_ptr<SelectionStep<pat::Muon> > MuonStep;
0229 std::unique_ptr<SelectionStep<pat::Electron> > ElectronStep;
0230 std::unique_ptr<SelectionStep<reco::Vertex> > PvStep;
0231 std::unique_ptr<SelectionStep<pat::MET> > METStep;
0232 std::vector<std::unique_ptr<SelectionStep<pat::Jet> > > JetSteps;
0233
0234 std::vector<edm::ParameterSet> sel_;
0235 edm::ParameterSet setup_;
0236 };
0237
0238 #endif
0239
0240
0241
0242
0243