File indexing completed on 2024-09-11 04:32:34
0001 #ifndef TOPDILEPTONOFFLINEDQM
0002 #define TOPDILEPTONOFFLINEDQM
0003
0004 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0005
0006 #include <string>
0007 #include <vector>
0008
0009 #include "DataFormats/Math/interface/deltaR.h"
0010 #include "DataFormats/JetReco/interface/Jet.h"
0011 #include "DQM/Physics/interface/TopDQMHelpers.h"
0012 #include "DataFormats/Common/interface/ValueMap.h"
0013 #include "DataFormats/METReco/interface/CaloMET.h"
0014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0015 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0016 #include "FWCore/Utilities/interface/EDGetToken.h"
0017 #include "FWCore/Framework/interface/EDConsumerBase.h"
0018 #include "FWCore/Framework/interface/ConsumesCollector.h"
0019 #include "JetMETCorrections/JetCorrector/interface/JetCorrector.h"
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 namespace TopDiLeptonOffline {
0049 using dqm::legacy::DQMStore;
0050 using dqm::legacy::MonitorElement;
0051
0052 class MonitorEnsemble {
0053 public:
0054
0055 enum Level { STANDARD, VERBOSE, DEBUG };
0056
0057
0058 typedef reco::LeafCandidate::LorentzVector LorentzVector;
0059
0060 enum DecayChannel { NONE, DIMUON, DIELEC, ELECMU };
0061
0062 public:
0063
0064
0065 MonitorEnsemble(const char* label, const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC);
0066
0067 ~MonitorEnsemble() {}
0068
0069
0070 void book(DQMStore::IBooker& ibooker);
0071
0072 void fill(const edm::Event& event, const edm::EventSetup& setup);
0073
0074 private:
0075
0076
0077 std::string monitorPath(const std::string& label) const { return label.substr(label.find(':') + 1); };
0078
0079
0080 std::string selectionPath(const std::string& label) const { return label.substr(0, label.find(':')); };
0081
0082 DecayChannel decayChannel(const std::vector<const reco::PFCandidate*>& muons,
0083 const std::vector<const reco::PFCandidate*>& elecs) const;
0084
0085
0086 void loggerBinLabels(std::string hist);
0087
0088 void triggerBinLabels(std::string channel, const std::vector<std::string> labels);
0089
0090 void fill(const edm::Event& event,
0091 const edm::TriggerResults& triggerTable,
0092 std::string channel,
0093 const std::vector<std::string> labels) const;
0094
0095
0096 bool booked(const std::string histName) const { return hists_.find(histName) != hists_.end(); };
0097
0098 void fill(const std::string histName, double value) const {
0099 if (booked(histName))
0100 hists_.find(histName)->second->Fill(value);
0101 };
0102
0103 void fill(const std::string histName, double xValue, double yValue) const {
0104 if (booked(histName))
0105 hists_.find(histName)->second->Fill(xValue, yValue);
0106 };
0107
0108 void fill(const std::string histName, double xValue, double yValue, double zValue) const {
0109 if (booked(histName))
0110 hists_.find(histName)->second->Fill(xValue, yValue, zValue);
0111 };
0112
0113 private:
0114
0115 Level verbosity_;
0116
0117 std::string label_;
0118
0119 edm::EDGetTokenT<edm::View<reco::Jet> > jets_;
0120 edm::EDGetTokenT<edm::View<reco::PFCandidate> > muons_;
0121 edm::EDGetTokenT<edm::View<reco::PFCandidate> > elecs_;
0122
0123
0124 std::vector<edm::EDGetTokenT<edm::View<reco::MET> > > mets_;
0125
0126
0127 edm::EDGetTokenT<edm::TriggerResults> triggerTable_;
0128
0129
0130 std::vector<std::string> elecMuPaths_;
0131
0132 std::vector<std::string> diMuonPaths_;
0133
0134
0135 edm::EDGetTokenT<edm::ValueMap<float> > electronId_;
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 double eidCutValue_;
0150
0151 std::unique_ptr<StringCutObjectSelector<reco::PFCandidate> > elecIso_;
0152
0153 std::unique_ptr<StringCutObjectSelector<reco::PFCandidate> > elecSelect_;
0154
0155
0156 std::unique_ptr<StringCutObjectSelector<reco::PFCandidate, true> > muonIso_;
0157
0158
0159 std::unique_ptr<StringCutObjectSelector<reco::PFCandidate, true> > muonSelect_;
0160
0161
0162 edm::EDGetTokenT<reco::JetCorrector> jetCorrector_;
0163
0164 edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;
0165
0166 std::unique_ptr<StringCutObjectSelector<reco::JetID> > jetIDSelect_;
0167
0168
0169 std::string jetSelect_;
0170
0171 double lowerEdge_, upperEdge_;
0172
0173
0174 int elecMuLogged_, diMuonLogged_, diElecLogged_;
0175
0176
0177 std::map<std::string, MonitorElement*> hists_;
0178
0179 std::string directory_;
0180 };
0181
0182 inline void MonitorEnsemble::loggerBinLabels(std::string hist) {
0183
0184 hists_[hist]->getTH1()->SetOption("TEXT");
0185 hists_[hist]->setBinLabel(1, "Run", 1);
0186 hists_[hist]->setBinLabel(2, "Block", 1);
0187 hists_[hist]->setBinLabel(3, "Event", 1);
0188 hists_[hist]->setBinLabel(6, "pt_{L2L3}(jet1)", 1);
0189 hists_[hist]->setBinLabel(7, "pt_{L2L3}(jet2)", 1);
0190 hists_[hist]->setBinLabel(8, "MET_{Calo}", 1);
0191 hists_[hist]->setAxisTitle("logged evts", 2);
0192
0193 if (hist == "diMuonLogger_") {
0194 hists_[hist]->setBinLabel(4, "pt(muon)", 1);
0195 hists_[hist]->setBinLabel(5, "pt(muon)", 1);
0196 }
0197 if (hist == "diElecLogger_") {
0198 hists_[hist]->setBinLabel(4, "pt(elec)", 1);
0199 hists_[hist]->setBinLabel(5, "pt(elec)", 1);
0200 }
0201 if (hist == "elecMuLogger_") {
0202 hists_[hist]->setBinLabel(4, "pt(elec)", 1);
0203 hists_[hist]->setBinLabel(5, "pt(muon)", 1);
0204 }
0205 }
0206
0207 inline void MonitorEnsemble::triggerBinLabels(std::string channel, const std::vector<std::string> labels) {
0208 for (unsigned int idx = 0; idx < labels.size(); ++idx) {
0209 hists_[channel + "Mon_"]->setBinLabel(idx + 1, "[" + monitorPath(labels[idx]) + "]", 1);
0210 hists_[channel + "Eff_"]->setBinLabel(
0211 idx + 1, "[" + selectionPath(labels[idx]) + "]|[" + monitorPath(labels[idx]) + "]", 1);
0212 }
0213 }
0214
0215 inline void MonitorEnsemble::fill(const edm::Event& event,
0216 const edm::TriggerResults& triggerTable,
0217 std::string channel,
0218 const std::vector<std::string> labels) const {
0219 for (unsigned int idx = 0; idx < labels.size(); ++idx) {
0220 if (accept(event, triggerTable, monitorPath(labels[idx]))) {
0221 fill(channel + "Mon_", idx + 0.5);
0222
0223 int evts = hists_.find(channel + "Mon_")->second->getBinContent(idx + 1);
0224 double value = hists_.find(channel + "Eff_")->second->getBinContent(idx + 1);
0225 fill(
0226 channel + "Eff_", idx + 0.5, 1. / evts * (accept(event, triggerTable, selectionPath(labels[idx])) - value));
0227 }
0228 }
0229 }
0230
0231 inline MonitorEnsemble::DecayChannel MonitorEnsemble::decayChannel(
0232 const std::vector<const reco::PFCandidate*>& muons, const std::vector<const reco::PFCandidate*>& elecs) const {
0233 DecayChannel type = NONE;
0234 if (muons.size() > 1) {
0235 type = DIMUON;
0236 } else if (elecs.size() > 1) {
0237 type = DIELEC;
0238 } else if (!elecs.empty() && !muons.empty()) {
0239 type = ELECMU;
0240 }
0241 return type;
0242 }
0243 }
0244
0245 #include <utility>
0246
0247 #include "FWCore/Framework/interface/Frameworkfwd.h"
0248 #include "FWCore/ServiceRegistry/interface/Service.h"
0249 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0250
0251 #include "FWCore/Common/interface/TriggerNames.h"
0252 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0253 #include "DataFormats/VertexReco/interface/Vertex.h"
0254 #include "DataFormats/Common/interface/TriggerResults.h"
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296 class TopDiLeptonOfflineDQM : public DQMOneEDAnalyzer<> {
0297 public:
0298
0299 TopDiLeptonOfflineDQM(const edm::ParameterSet& cfg);
0300
0301 ~TopDiLeptonOfflineDQM() override {}
0302
0303
0304 void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
0305
0306 protected:
0307
0308 void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0309
0310 private:
0311
0312
0313 std::string objectType(const std::string& label) { return label.substr(0, label.find(':')); };
0314
0315
0316 std::string selectionStep(const std::string& label) { return label.substr(label.find(':') + 1); };
0317
0318 private:
0319
0320 edm::EDGetTokenT<edm::TriggerResults> triggerTable_;
0321
0322 std::vector<std::string> triggerPaths_;
0323
0324 edm::EDGetTokenT<std::vector<reco::Vertex> > vertex_;
0325
0326 std::unique_ptr<StringCutObjectSelector<reco::Vertex> > vertexSelect_;
0327
0328 edm::EDGetTokenT<reco::BeamSpot> beamspot_;
0329
0330 std::unique_ptr<StringCutObjectSelector<reco::BeamSpot> > beamspotSelect_;
0331
0332
0333
0334 std::vector<std::string> selectionOrder_;
0335
0336
0337
0338
0339
0340 std::map<std::string, std::pair<edm::ParameterSet, std::unique_ptr<TopDiLeptonOffline::MonitorEnsemble> > > selection_;
0341 std::unique_ptr<SelectionStep<reco::PFCandidate> > MuonStep;
0342 std::unique_ptr<SelectionStep<reco::PFCandidate> > ElectronStep;
0343 std::unique_ptr<SelectionStep<reco::Vertex> > PvStep;
0344 std::unique_ptr<SelectionStep<reco::MET> > METStep;
0345 std::vector<std::unique_ptr<SelectionStep<reco::Jet> > > JetSteps;
0346 std::vector<std::unique_ptr<SelectionStep<reco::CaloJet> > > CaloJetSteps;
0347 std::vector<std::unique_ptr<SelectionStep<reco::PFJet> > > PFJetSteps;
0348
0349 std::vector<edm::ParameterSet> sel_;
0350 edm::ParameterSet setup_;
0351 };
0352
0353 #endif