File indexing completed on 2023-03-17 10:58:39
0001 #include <string>
0002 #include <vector>
0003
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "DQMServices/Core/interface/DQMStore.h"
0009 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0010 #include "DQMOffline/Trigger/plugins/TriggerDQMBase.h"
0011 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
0012 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0013 #include "DataFormats/JetReco/interface/PFJet.h"
0014 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0015 #include "DataFormats/JetReco/interface/CaloJet.h"
0016 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0017 #include "DataFormats/JetReco/interface/GenJetCollection.h"
0018
0019 class JetMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
0020 public:
0021 typedef dqm::reco::MonitorElement MonitorElement;
0022 typedef dqm::reco::DQMStore DQMStore;
0023
0024 JetMonitor(const edm::ParameterSet&);
0025 ~JetMonitor() throw() override;
0026
0027 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0028
0029 protected:
0030 void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0031 void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0032
0033 bool isBarrel(double eta);
0034 bool isEndCapP(double eta);
0035 bool isEndCapM(double eta);
0036 bool isForward(double eta);
0037
0038 void bookMESub(DQMStore::IBooker&,
0039 ObjME* a_me,
0040 const int len_,
0041 const std::string& h_Name,
0042 const std::string& h_Title,
0043 const std::string& h_subOptName,
0044 const std::string& h_subOptTitle,
0045 const bool doPhi = true,
0046 const bool doEta = true,
0047 const bool doEtaPhi = true,
0048 const bool doVsLS = true);
0049 void FillME(ObjME* a_me,
0050 const double pt_,
0051 const double phi_,
0052 const double eta_,
0053 const int ls_,
0054 const std::string& denu,
0055 const bool doPhi = true,
0056 const bool doEta = true,
0057 const bool doEtaPhi = true,
0058 const bool doVsLS = true);
0059
0060 private:
0061 const std::string folderName_;
0062
0063 const bool requireValidHLTPaths_;
0064 bool hltPathsAreValid_;
0065
0066 double ptcut_;
0067 bool isPFJetTrig;
0068 bool isCaloJetTrig;
0069
0070 const bool enableFullMonitoring_;
0071
0072 edm::EDGetTokenT<edm::View<reco::Jet> > jetSrc_;
0073
0074 std::unique_ptr<GenericTriggerEventFlag> num_genTriggerEventFlag_;
0075 std::unique_ptr<GenericTriggerEventFlag> den_genTriggerEventFlag_;
0076
0077 MEbinning jetpt_binning_;
0078 MEbinning jetptThr_binning_;
0079 MEbinning ls_binning_;
0080
0081 ObjME a_ME[7];
0082 ObjME a_ME_HB[7];
0083 ObjME a_ME_HE[7];
0084 ObjME a_ME_HF[7];
0085 ObjME a_ME_HE_p[7];
0086 ObjME a_ME_HE_m[7];
0087
0088 std::vector<double> v_jetpt;
0089 std::vector<double> v_jeteta;
0090 std::vector<double> v_jetphi;
0091
0092
0093 MEbinning jet_phi_binning_{64, -3.2, 3.2};
0094 MEbinning jet_eta_binning_{50, -5, 5};
0095 };
0096
0097 JetMonitor::JetMonitor(const edm::ParameterSet& iConfig)
0098 : folderName_(iConfig.getParameter<std::string>("FolderName")),
0099 requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
0100 hltPathsAreValid_(false),
0101 ptcut_(iConfig.getParameter<double>("ptcut")),
0102 isPFJetTrig(iConfig.getParameter<bool>("ispfjettrg")),
0103 isCaloJetTrig(iConfig.getParameter<bool>("iscalojettrg")),
0104 enableFullMonitoring_(iConfig.getParameter<bool>("enableFullMonitoring")),
0105 jetSrc_(mayConsume<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("jetSrc"))),
0106 num_genTriggerEventFlag_(new GenericTriggerEventFlag(
0107 iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
0108 den_genTriggerEventFlag_(new GenericTriggerEventFlag(
0109 iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
0110 jetpt_binning_(getHistoPSet(
0111 iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("jetPSet"))),
0112 jetptThr_binning_(getHistoPSet(
0113 iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("jetPtThrPSet"))),
0114 ls_binning_(getHistoPSet(
0115 iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet"))) {}
0116
0117 JetMonitor::~JetMonitor() throw() {
0118 if (num_genTriggerEventFlag_) {
0119 num_genTriggerEventFlag_.reset();
0120 }
0121 if (den_genTriggerEventFlag_) {
0122 den_genTriggerEventFlag_.reset();
0123 }
0124 }
0125
0126 void JetMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
0127
0128 if (num_genTriggerEventFlag_ && num_genTriggerEventFlag_->on()) {
0129 num_genTriggerEventFlag_->initRun(iRun, iSetup);
0130 }
0131 if (den_genTriggerEventFlag_ && den_genTriggerEventFlag_->on()) {
0132 den_genTriggerEventFlag_->initRun(iRun, iSetup);
0133 }
0134
0135
0136 hltPathsAreValid_ = (num_genTriggerEventFlag_ && den_genTriggerEventFlag_ && num_genTriggerEventFlag_->on() &&
0137 den_genTriggerEventFlag_->on() && num_genTriggerEventFlag_->allHLTPathsAreValid() &&
0138 den_genTriggerEventFlag_->allHLTPathsAreValid());
0139
0140
0141
0142 if (requireValidHLTPaths_ and (not hltPathsAreValid_)) {
0143 return;
0144 }
0145
0146 std::string histname, histtitle;
0147 std::string hist_obtag = "";
0148 std::string histtitle_obtag = "";
0149 std::string currentFolder = folderName_;
0150 ibooker.setCurrentFolder(currentFolder);
0151
0152 if (isPFJetTrig) {
0153 hist_obtag = "pfjet";
0154 histtitle_obtag = "PFJet";
0155 } else if (isCaloJetTrig) {
0156 hist_obtag = "calojet";
0157 histtitle_obtag = "CaloJet";
0158 } else {
0159 hist_obtag = "pfjet";
0160 histtitle_obtag = "PFJet";
0161 }
0162
0163 bookMESub(ibooker, a_ME, sizeof(a_ME) / sizeof(a_ME[0]), hist_obtag, histtitle_obtag, "", "");
0164 bookMESub(ibooker,
0165 a_ME_HB,
0166 sizeof(a_ME_HB) / sizeof(a_ME_HB[0]),
0167 hist_obtag,
0168 histtitle_obtag,
0169 "HB",
0170 "(HB)",
0171 true,
0172 true,
0173 true,
0174 false);
0175 bookMESub(ibooker,
0176 a_ME_HE,
0177 sizeof(a_ME_HE) / sizeof(a_ME_HE[0]),
0178 hist_obtag,
0179 histtitle_obtag,
0180 "HE",
0181 "(HE)",
0182 true,
0183 true,
0184 true,
0185 false);
0186 bookMESub(ibooker,
0187 a_ME_HF,
0188 sizeof(a_ME_HF) / sizeof(a_ME_HF[0]),
0189 hist_obtag,
0190 histtitle_obtag,
0191 "HF",
0192 "(HF)",
0193 true,
0194 true,
0195 true,
0196 false);
0197
0198
0199 if (!enableFullMonitoring_) {
0200 return;
0201 }
0202
0203 bookMESub(ibooker,
0204 a_ME_HE_p,
0205 sizeof(a_ME_HE_p) / sizeof(a_ME_HE_p[0]),
0206 hist_obtag,
0207 histtitle_obtag,
0208 "HE_p",
0209 "(HE+)",
0210 true,
0211 false,
0212 true,
0213 false);
0214 bookMESub(ibooker,
0215 a_ME_HE_m,
0216 sizeof(a_ME_HE_m) / sizeof(a_ME_HE_m[0]),
0217 hist_obtag,
0218 histtitle_obtag,
0219 "HE_m",
0220 "(HE-)",
0221 true,
0222 false,
0223 true,
0224 false);
0225 }
0226
0227 void JetMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0228
0229
0230 if (requireValidHLTPaths_ and (not hltPathsAreValid_)) {
0231 return;
0232 }
0233
0234
0235 if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup))
0236 return;
0237
0238 const int ls = iEvent.id().luminosityBlock();
0239
0240 v_jetpt.clear();
0241 v_jeteta.clear();
0242 v_jetphi.clear();
0243
0244 edm::Handle<edm::View<reco::Jet> > offjets;
0245 iEvent.getByToken(jetSrc_, offjets);
0246 if (!offjets.isValid()) {
0247 edm::LogWarning("JetMonitor") << "Jet handle not valid \n";
0248 return;
0249 }
0250 for (edm::View<reco::Jet>::const_iterator ibegin = offjets->begin(), iend = offjets->end(), ijet = ibegin;
0251 ijet != iend;
0252 ++ijet) {
0253 if (ijet->pt() < ptcut_) {
0254 continue;
0255 }
0256 v_jetpt.push_back(ijet->pt());
0257 v_jeteta.push_back(ijet->eta());
0258 v_jetphi.push_back(ijet->phi());
0259
0260 }
0261
0262 if (v_jetpt.empty())
0263 return;
0264 double jetpt_ = v_jetpt[0];
0265 double jeteta_ = v_jeteta[0];
0266 double jetphi_ = v_jetphi[0];
0267
0268 FillME(a_ME, jetpt_, jetphi_, jeteta_, ls, "denominator");
0269 if (isBarrel(jeteta_)) {
0270 FillME(a_ME_HB, jetpt_, jetphi_, jeteta_, ls, "denominator", true, true, true, false);
0271 } else if (isEndCapP(jeteta_)) {
0272 FillME(a_ME_HE, jetpt_, jetphi_, jeteta_, ls, "denominator", true, true, true, false);
0273 if (enableFullMonitoring_) {
0274 FillME(a_ME_HE_p, jetpt_, jetphi_, jeteta_, ls, "denominator", true, false, true, false);
0275 }
0276 } else if (isEndCapM(jeteta_)) {
0277 FillME(a_ME_HE, jetpt_, jetphi_, jeteta_, ls, "denominator", true, true, true, false);
0278 if (enableFullMonitoring_) {
0279 FillME(a_ME_HE_m, jetpt_, jetphi_, jeteta_, ls, "denominator", true, false, true, false);
0280 }
0281 } else if (isForward(jeteta_)) {
0282 FillME(a_ME_HF, jetpt_, jetphi_, jeteta_, ls, "denominator", true, true, true, false);
0283 }
0284
0285 if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
0286 return;
0287
0288 FillME(a_ME, jetpt_, jetphi_, jeteta_, ls, "numerator");
0289 if (isBarrel(jeteta_)) {
0290 FillME(a_ME_HB, jetpt_, jetphi_, jeteta_, ls, "numerator", true, true, true, false);
0291 } else if (isEndCapP(jeteta_)) {
0292 FillME(a_ME_HE, jetpt_, jetphi_, jeteta_, ls, "numerator", true, true, true, false);
0293 if (enableFullMonitoring_) {
0294 FillME(a_ME_HE_p, jetpt_, jetphi_, jeteta_, ls, "numerator", true, false, true, false);
0295 }
0296 } else if (isEndCapM(jeteta_)) {
0297 FillME(a_ME_HE, jetpt_, jetphi_, jeteta_, ls, "numerator", true, true, true, false);
0298 if (enableFullMonitoring_) {
0299 FillME(a_ME_HE_m, jetpt_, jetphi_, jeteta_, ls, "numerator", true, false, true, false);
0300 }
0301 } else if (isForward(jeteta_)) {
0302 FillME(a_ME_HF, jetpt_, jetphi_, jeteta_, ls, "numerator", true, true, true, false);
0303 }
0304 }
0305
0306 bool JetMonitor::isBarrel(double eta) {
0307 bool output = false;
0308 if (fabs(eta) <= 1.3)
0309 output = true;
0310 return output;
0311 }
0312
0313 bool JetMonitor::isEndCapM(double eta) {
0314 bool output = false;
0315 if (fabs(eta) <= 3.0 && fabs(eta) > 1.3 && (eta < 0))
0316 output = true;
0317 return output;
0318 }
0319
0320
0321 bool JetMonitor::isEndCapP(double eta) {
0322 bool output = false;
0323 if (fabs(eta) <= 3.0 && fabs(eta) > 1.3 && (eta > 0))
0324 output = true;
0325 return output;
0326 }
0327
0328
0329 bool JetMonitor::isForward(double eta) {
0330 bool output = false;
0331 if (fabs(eta) > 3.0)
0332 output = true;
0333 return output;
0334 }
0335
0336 void JetMonitor::FillME(ObjME* a_me,
0337 const double pt_,
0338 const double phi_,
0339 const double eta_,
0340 const int ls_,
0341 const std::string& DenoOrNume,
0342 const bool doPhi,
0343 const bool doEta,
0344 const bool doEtaPhi,
0345 const bool doVsLS) {
0346 if (DenoOrNume == "denominator") {
0347
0348
0349 a_me[0].denominator->Fill(pt_);
0350 a_me[1].denominator->Fill(pt_);
0351 if (doVsLS)
0352 a_me[2].denominator->Fill(ls_, pt_);
0353 if (doPhi)
0354 a_me[3].denominator->Fill(phi_);
0355 if (doEta)
0356 a_me[4].denominator->Fill(eta_);
0357 if (doEtaPhi)
0358 a_me[5].denominator->Fill(eta_, phi_);
0359 if (doEtaPhi)
0360 a_me[6].denominator->Fill(eta_, pt_);
0361 } else if (DenoOrNume == "numerator") {
0362 a_me[0].numerator->Fill(pt_);
0363 a_me[1].numerator->Fill(pt_);
0364 if (doVsLS)
0365 a_me[2].numerator->Fill(ls_, pt_);
0366 if (doPhi)
0367 a_me[3].numerator->Fill(phi_);
0368 if (doEta)
0369 a_me[4].numerator->Fill(eta_);
0370 if (doEtaPhi)
0371 a_me[5].numerator->Fill(eta_, phi_);
0372 if (doEtaPhi)
0373 a_me[6].numerator->Fill(eta_, pt_);
0374 } else {
0375 edm::LogWarning("JetMonitor") << "CHECK OUT denu option in FillME !!! DenoOrNume ? : " << DenoOrNume << std::endl;
0376 }
0377 }
0378
0379 void JetMonitor::bookMESub(DQMStore::IBooker& Ibooker,
0380 ObjME* a_me,
0381 const int len_,
0382 const std::string& h_Name,
0383 const std::string& h_Title,
0384 const std::string& h_subOptName,
0385 const std::string& hSubT,
0386 const bool doPhi,
0387 const bool doEta,
0388 const bool doEtaPhi,
0389 const bool doVsLS) {
0390 std::string hName = h_Name;
0391 std::string hTitle = h_Title;
0392 const std::string hSubN = h_subOptName.empty() ? "" : "_" + h_subOptName;
0393
0394 int nbin_phi = jet_phi_binning_.nbins;
0395 double maxbin_phi = jet_phi_binning_.xmax;
0396 double minbin_phi = jet_phi_binning_.xmin;
0397
0398 int nbin_eta = jet_eta_binning_.nbins;
0399 double maxbin_eta = jet_eta_binning_.xmax;
0400 double minbin_eta = jet_eta_binning_.xmin;
0401
0402 hName = h_Name + "pT" + hSubN;
0403 hTitle = h_Title + " pT " + hSubT;
0404 bookME(Ibooker, a_me[0], hName, hTitle, jetpt_binning_.nbins, jetpt_binning_.xmin, jetpt_binning_.xmax);
0405 setMETitle(a_me[0], h_Title + " pT [GeV]", "events / [GeV]");
0406
0407 hName = h_Name + "pT_pTThresh" + hSubN;
0408 hTitle = h_Title + " pT " + hSubT;
0409 bookME(Ibooker, a_me[1], hName, hTitle, jetptThr_binning_.nbins, jetptThr_binning_.xmin, jetptThr_binning_.xmax);
0410 setMETitle(a_me[1], h_Title + "pT [GeV]", "events / [GeV]");
0411
0412 if (doVsLS) {
0413 hName = h_Name + "pTVsLS" + hSubN;
0414 hTitle = h_Title + " vs LS " + hSubT;
0415 bookME(Ibooker,
0416 a_me[2],
0417 hName,
0418 hTitle,
0419 ls_binning_.nbins,
0420 ls_binning_.xmin,
0421 ls_binning_.xmax,
0422 jetpt_binning_.xmin,
0423 jetpt_binning_.xmax);
0424 setMETitle(a_me[2], "LS", h_Title + "pT [GeV]");
0425 }
0426
0427 if (doPhi) {
0428 hName = h_Name + "phi" + hSubN;
0429 hTitle = h_Title + " phi " + hSubT;
0430 bookME(Ibooker, a_me[3], hName, hTitle, nbin_phi, minbin_phi, maxbin_phi);
0431 setMETitle(a_me[3], h_Title + " #phi", "events / 0.1 rad");
0432 }
0433
0434 if (doEta) {
0435 hName = h_Name + "eta" + hSubN;
0436 hTitle = h_Title + " eta " + hSubT;
0437 bookME(Ibooker, a_me[4], hName, hTitle, nbin_eta, minbin_eta, maxbin_eta);
0438 setMETitle(a_me[4], h_Title + " #eta", "events");
0439 }
0440
0441 if (doEtaPhi) {
0442 hName = h_Name + "EtaVsPhi" + hSubN;
0443 hTitle = h_Title + " eta Vs phi " + hSubT;
0444 bookME(Ibooker, a_me[5], hName, hTitle, nbin_eta, minbin_eta, maxbin_eta, nbin_phi, minbin_phi, maxbin_phi);
0445 setMETitle(a_me[5], h_Title + " #eta", "#phi");
0446 }
0447
0448 if (doEtaPhi) {
0449 hName = h_Name + "EtaVspT" + hSubN;
0450 hTitle = h_Title + " eta Vs pT " + hSubT;
0451 bookME(Ibooker,
0452 a_me[6],
0453 hName,
0454 hTitle,
0455 nbin_eta,
0456 minbin_eta,
0457 maxbin_eta,
0458 jetpt_binning_.nbins,
0459 jetpt_binning_.xmin,
0460 jetpt_binning_.xmax);
0461 setMETitle(a_me[6], h_Title + " #eta", "Leading Jet pT [GeV]");
0462 }
0463 }
0464
0465 void JetMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0466 edm::ParameterSetDescription desc;
0467 desc.add<std::string>("FolderName", "HLT/Jet");
0468 desc.add<bool>("requireValidHLTPaths", true);
0469
0470 desc.add<edm::InputTag>("jetSrc", edm::InputTag("ak4PFJetsCHS"));
0471 desc.add<double>("ptcut", 20);
0472 desc.add<bool>("ispfjettrg", true);
0473 desc.add<bool>("iscalojettrg", false);
0474
0475 desc.add<bool>("enableFullMonitoring", true);
0476
0477 edm::ParameterSetDescription genericTriggerEventPSet;
0478 GenericTriggerEventFlag::fillPSetDescription(genericTriggerEventPSet);
0479
0480 desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
0481 desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
0482
0483 edm::ParameterSetDescription histoPSet;
0484 edm::ParameterSetDescription jetPSet;
0485 edm::ParameterSetDescription jetPtThrPSet;
0486 fillHistoPSetDescription(jetPSet);
0487 fillHistoPSetDescription(jetPtThrPSet);
0488 histoPSet.add<edm::ParameterSetDescription>("jetPSet", jetPSet);
0489 histoPSet.add<edm::ParameterSetDescription>("jetPtThrPSet", jetPtThrPSet);
0490 histoPSet.add<std::vector<double> >("jetptBinning",
0491 {0., 20., 40., 60., 80., 90., 100., 110., 120., 130., 140., 150., 160.,
0492 170., 180., 190., 200., 220., 240., 260., 280., 300., 350., 400., 450., 1000.});
0493
0494 edm::ParameterSetDescription lsPSet;
0495 fillHistoLSPSetDescription(lsPSet);
0496 histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
0497
0498 desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
0499
0500 descriptions.add("jetMonitoring", desc);
0501 }
0502
0503 DEFINE_FWK_MODULE(JetMonitor);