Tau3MuMonitor

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMOffline/Trigger/plugins/TriggerDQMBase.h"
#include "CommonTools/Utils/interface/StringCutObjectSelector.h"
#include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
#include "DataFormats/Candidate/interface/CompositeCandidate.h"

class Tau3MuMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
public:
  typedef dqm::reco::MonitorElement MonitorElement;
  typedef dqm::reco::DQMStore DQMStore;

  Tau3MuMonitor(const edm::ParameterSet&);
  ~Tau3MuMonitor() throw() override;
  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

protected:
  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;

private:
  const std::string folderName_;

  const bool requireValidHLTPaths_;
  bool hltPathsAreValid_;

  // internally store a flag to remember whether the needed tau3mu collection is present and valid
  bool validProduct_ = true;

  edm::EDGetTokenT<reco::CompositeCandidateCollection> tauToken_;  // tau 3 mu collection

  MonitorElement* tau1DPt_;      // 1D tau pt histogram
  MonitorElement* tau1DEta_;     // 1D tau eta histogram
  MonitorElement* tau1DPhi_;     // 1D tau phi histogram
  MonitorElement* tau1DMass_;    // 1D tau mass histogram
  MonitorElement* tau2DEtaPhi_;  // 2D tau eta vs phi histogram

  MEbinning pt_binning_;    // for the 1D tau pt histogram
  MEbinning eta_binning_;   // for the 1D tau eta histogram and 2D tau eta vs phi histogram
  MEbinning phi_binning_;   // for the 1D tau phi histogram and 2D tau eta vs phi histogram
  MEbinning mass_binning_;  // for the 1D tau mass histogram

  std::unique_ptr<GenericTriggerEventFlag> genTriggerEventFlag_;
};

Tau3MuMonitor::Tau3MuMonitor(const edm::ParameterSet& iConfig)
    : folderName_(iConfig.getParameter<std::string>("FolderName")),
      requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
      hltPathsAreValid_(false),
      tauToken_(mayConsume<reco::CompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("taus"))),
      pt_binning_(
          getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("ptPSet"))),
      eta_binning_(getHistoPSet(
          iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("etaPSet"))),
      phi_binning_(getHistoPSet(
          iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("phiPSet"))),
      mass_binning_(getHistoPSet(
          iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("massPSet"))),
      genTriggerEventFlag_(new GenericTriggerEventFlag(
          iConfig.getParameter<edm::ParameterSet>("GenericTriggerEventPSet"), consumesCollector(), *this)) {}

Tau3MuMonitor::~Tau3MuMonitor() throw() {
  if (genTriggerEventFlag_) {
    genTriggerEventFlag_.reset();
  }
}

void Tau3MuMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
  // Initialize the GenericTriggerEventFlag
  if (genTriggerEventFlag_ && genTriggerEventFlag_->on()) {
    genTriggerEventFlag_->initRun(iRun, iSetup);
  }

  // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
  hltPathsAreValid_ =
      (genTriggerEventFlag_ && genTriggerEventFlag_->on() && genTriggerEventFlag_->allHLTPathsAreValid());

  // if valid HLT paths are required,
  // create DQM outputs only if all paths are valid
  if (requireValidHLTPaths_ and (not hltPathsAreValid_)) {
    return;
  }

  std::string histname;

  std::string currentFolder = folderName_;
  ibooker.setCurrentFolder(currentFolder);

  // tau 3 mu 1D pt
  histname = "tau1DPt";
  tau1DPt_ = ibooker.book1D(histname, "", pt_binning_.nbins, pt_binning_.xmin, pt_binning_.xmax);
  tau1DPt_->setAxisTitle("3-#mu p_{T} [GeV]", 1);
  tau1DPt_->setAxisTitle("counts", 2);

  // tau 3 mu 1D eta
  histname = "tau1DEta";
  tau1DEta_ = ibooker.book1D(histname, "", eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
  tau1DEta_->setAxisTitle("3-#mu #eta", 1);
  tau1DEta_->setAxisTitle("counts", 2);

  // tau 3 mu 1D phi
  histname = "tau1DPhi";
  tau1DPhi_ = ibooker.book1D(histname, "", phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
  tau1DPhi_->setAxisTitle("3-#mu #phi", 1);
  tau1DPhi_->setAxisTitle("counts", 2);

  // tau 3 mu 1D mass
  histname = "tau1DMass";
  tau1DMass_ = ibooker.book1D(histname, "", mass_binning_.nbins, mass_binning_.xmin, mass_binning_.xmax);
  tau1DMass_->setAxisTitle("mass_{3#mu} [GeV]", 1);
  tau1DMass_->setAxisTitle("counts", 2);

  // tau 3 mu 2D eta vs phi
  histname = "tau2DEtaPhi";
  tau2DEtaPhi_ = ibooker.book2D(histname,
                                "",
                                eta_binning_.nbins,
                                eta_binning_.xmin,
                                eta_binning_.xmax,
                                phi_binning_.nbins,
                                phi_binning_.xmin,
                                phi_binning_.xmax);
  tau2DEtaPhi_->setAxisTitle("3-#mu #eta", 1);
  tau2DEtaPhi_->setAxisTitle("3-#mu #phi", 2);
}

void Tau3MuMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
  // if valid HLT paths are required,
  // analyze event only if all paths are valid
  if (requireValidHLTPaths_ and (not hltPathsAreValid_)) {
    return;
  }

  // require the trigger to be fired
  if (genTriggerEventFlag_->on() && !genTriggerEventFlag_->accept(iEvent, iSetup))
    return;

  // check if the previous event failed because of missing tau3mu collection.
  // Return silently, a warning must have been issued already at this point
  if (not validProduct_)
    return;

  // get ahold of the tau(3mu) collection
  edm::Handle<reco::CompositeCandidateCollection> tauHandle;
  iEvent.getByToken(tauToken_, tauHandle);

  // if the handle is not valid issue a warning (only for the forst occurrency)
  if (not tauHandle.isValid()) {
    edm::LogWarning("ProductNotValid") << "Tau3Mu trigger product not valid";
    validProduct_ = false;
    return;
  }

  // loop and fill
  for (auto const& itau : *tauHandle) {
    tau1DPt_->Fill(itau.pt());
    tau1DEta_->Fill(itau.eta());
    tau1DPhi_->Fill(itau.phi());
    tau1DMass_->Fill(itau.mass());
    tau2DEtaPhi_->Fill(itau.eta(), itau.phi());
  }
}

void Tau3MuMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
  edm::ParameterSetDescription desc;
  desc.add<std::string>("FolderName", "HLT/BPH/");
  desc.add<bool>("requireValidHLTPaths", true);

  desc.add<edm::InputTag>("taus", edm::InputTag("hltTauPt10MuPts511Mass1p2to2p3Iso", "Taus"));

  edm::ParameterSetDescription histoPSet;
  edm::ParameterSetDescription ptPSet;
  edm::ParameterSetDescription etaPSet;
  edm::ParameterSetDescription phiPSet;
  edm::ParameterSetDescription massPSet;
  fillHistoPSetDescription(ptPSet);
  fillHistoPSetDescription(etaPSet);
  fillHistoPSetDescription(phiPSet);
  fillHistoPSetDescription(massPSet);
  histoPSet.add<edm::ParameterSetDescription>("ptPSet", ptPSet);
  histoPSet.add<edm::ParameterSetDescription>("etaPSet", etaPSet);
  histoPSet.add<edm::ParameterSetDescription>("phiPSet", phiPSet);
  histoPSet.add<edm::ParameterSetDescription>("massPSet", massPSet);
  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);

  edm::ParameterSetDescription genericTriggerEventPSet;
  GenericTriggerEventFlag::fillPSetDescription(genericTriggerEventPSet);
  desc.add<edm::ParameterSetDescription>("GenericTriggerEventPSet", genericTriggerEventPSet);

  descriptions.add("tau3muMonitoring", desc);
}

DEFINE_FWK_MODULE(Tau3MuMonitor);