Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-03 02:23:41

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0006 #include "DQMServices/Core/interface/DQMStore.h"
0007 #include "DQMOffline/Trigger/plugins/TriggerDQMBase.h"
0008 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0009 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
0010 #include "DataFormats/Candidate/interface/CompositeCandidate.h"
0011 
0012 class Tau3MuMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
0013 public:
0014   typedef dqm::reco::MonitorElement MonitorElement;
0015   typedef dqm::reco::DQMStore DQMStore;
0016 
0017   Tau3MuMonitor(const edm::ParameterSet&);
0018   ~Tau3MuMonitor() throw() override;
0019   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020 
0021 protected:
0022   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0023   void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0024 
0025 private:
0026   const std::string folderName_;
0027 
0028   const bool requireValidHLTPaths_;
0029   bool hltPathsAreValid_;
0030 
0031   // internally store a flag to remember whether the needed tau3mu collection is present and valid
0032   bool validProduct_ = true;
0033 
0034   edm::EDGetTokenT<reco::CompositeCandidateCollection> tauToken_;  // tau 3 mu collection
0035 
0036   MonitorElement* tau1DPt_;      // 1D tau pt histogram
0037   MonitorElement* tau1DEta_;     // 1D tau eta histogram
0038   MonitorElement* tau1DPhi_;     // 1D tau phi histogram
0039   MonitorElement* tau1DMass_;    // 1D tau mass histogram
0040   MonitorElement* tau2DEtaPhi_;  // 2D tau eta vs phi histogram
0041 
0042   MEbinning pt_binning_;    // for the 1D tau pt histogram
0043   MEbinning eta_binning_;   // for the 1D tau eta histogram and 2D tau eta vs phi histogram
0044   MEbinning phi_binning_;   // for the 1D tau phi histogram and 2D tau eta vs phi histogram
0045   MEbinning mass_binning_;  // for the 1D tau mass histogram
0046 
0047   std::unique_ptr<GenericTriggerEventFlag> genTriggerEventFlag_;
0048 };
0049 
0050 Tau3MuMonitor::Tau3MuMonitor(const edm::ParameterSet& iConfig)
0051     : folderName_(iConfig.getParameter<std::string>("FolderName")),
0052       requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
0053       hltPathsAreValid_(false),
0054       tauToken_(mayConsume<reco::CompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("taus"))),
0055       pt_binning_(
0056           getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("ptPSet"))),
0057       eta_binning_(getHistoPSet(
0058           iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("etaPSet"))),
0059       phi_binning_(getHistoPSet(
0060           iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("phiPSet"))),
0061       mass_binning_(getHistoPSet(
0062           iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("massPSet"))),
0063       genTriggerEventFlag_(new GenericTriggerEventFlag(
0064           iConfig.getParameter<edm::ParameterSet>("GenericTriggerEventPSet"), consumesCollector(), *this)) {}
0065 
0066 Tau3MuMonitor::~Tau3MuMonitor() throw() {
0067   if (genTriggerEventFlag_) {
0068     genTriggerEventFlag_.reset();
0069   }
0070 }
0071 
0072 void Tau3MuMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
0073   // Initialize the GenericTriggerEventFlag
0074   if (genTriggerEventFlag_ && genTriggerEventFlag_->on()) {
0075     genTriggerEventFlag_->initRun(iRun, iSetup);
0076   }
0077 
0078   // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
0079   hltPathsAreValid_ =
0080       (genTriggerEventFlag_ && genTriggerEventFlag_->on() && genTriggerEventFlag_->allHLTPathsAreValid());
0081 
0082   // if valid HLT paths are required,
0083   // create DQM outputs only if all paths are valid
0084   if (requireValidHLTPaths_ and (not hltPathsAreValid_)) {
0085     return;
0086   }
0087 
0088   std::string histname;
0089 
0090   std::string currentFolder = folderName_;
0091   ibooker.setCurrentFolder(currentFolder);
0092 
0093   // tau 3 mu 1D pt
0094   histname = "tau1DPt";
0095   tau1DPt_ = ibooker.book1D(histname, "", pt_binning_.nbins, pt_binning_.xmin, pt_binning_.xmax);
0096   tau1DPt_->setAxisTitle("3-#mu p_{T} [GeV]", 1);
0097   tau1DPt_->setAxisTitle("counts", 2);
0098 
0099   // tau 3 mu 1D eta
0100   histname = "tau1DEta";
0101   tau1DEta_ = ibooker.book1D(histname, "", eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
0102   tau1DEta_->setAxisTitle("3-#mu #eta", 1);
0103   tau1DEta_->setAxisTitle("counts", 2);
0104 
0105   // tau 3 mu 1D phi
0106   histname = "tau1DPhi";
0107   tau1DPhi_ = ibooker.book1D(histname, "", phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
0108   tau1DPhi_->setAxisTitle("3-#mu #phi", 1);
0109   tau1DPhi_->setAxisTitle("counts", 2);
0110 
0111   // tau 3 mu 1D mass
0112   histname = "tau1DMass";
0113   tau1DMass_ = ibooker.book1D(histname, "", mass_binning_.nbins, mass_binning_.xmin, mass_binning_.xmax);
0114   tau1DMass_->setAxisTitle("mass_{3#mu} [GeV]", 1);
0115   tau1DMass_->setAxisTitle("counts", 2);
0116 
0117   // tau 3 mu 2D eta vs phi
0118   histname = "tau2DEtaPhi";
0119   tau2DEtaPhi_ = ibooker.book2D(histname,
0120                                 "",
0121                                 eta_binning_.nbins,
0122                                 eta_binning_.xmin,
0123                                 eta_binning_.xmax,
0124                                 phi_binning_.nbins,
0125                                 phi_binning_.xmin,
0126                                 phi_binning_.xmax);
0127   tau2DEtaPhi_->setAxisTitle("3-#mu #eta", 1);
0128   tau2DEtaPhi_->setAxisTitle("3-#mu #phi", 2);
0129 }
0130 
0131 void Tau3MuMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0132   // if valid HLT paths are required,
0133   // analyze event only if all paths are valid
0134   if (requireValidHLTPaths_ and (not hltPathsAreValid_)) {
0135     return;
0136   }
0137 
0138   // require the trigger to be fired
0139   if (genTriggerEventFlag_->on() && !genTriggerEventFlag_->accept(iEvent, iSetup))
0140     return;
0141 
0142   // check if the previous event failed because of missing tau3mu collection.
0143   // Return silently, a warning must have been issued already at this point
0144   if (not validProduct_)
0145     return;
0146 
0147   // get ahold of the tau(3mu) collection
0148   edm::Handle<reco::CompositeCandidateCollection> tauHandle;
0149   iEvent.getByToken(tauToken_, tauHandle);
0150 
0151   // if the handle is not valid issue a warning (only for the forst occurrency)
0152   if (not tauHandle.isValid()) {
0153     edm::LogWarning("ProductNotValid") << "Tau3Mu trigger product not valid";
0154     validProduct_ = false;
0155     return;
0156   }
0157 
0158   // loop and fill
0159   for (auto const& itau : *tauHandle) {
0160     tau1DPt_->Fill(itau.pt());
0161     tau1DEta_->Fill(itau.eta());
0162     tau1DPhi_->Fill(itau.phi());
0163     tau1DMass_->Fill(itau.mass());
0164     tau2DEtaPhi_->Fill(itau.eta(), itau.phi());
0165   }
0166 }
0167 
0168 void Tau3MuMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0169   edm::ParameterSetDescription desc;
0170   desc.add<std::string>("FolderName", "HLT/BPH/");
0171   desc.add<bool>("requireValidHLTPaths", true);
0172 
0173   desc.add<edm::InputTag>("taus", edm::InputTag("hltTauPt10MuPts511Mass1p2to2p3Iso", "Taus"));
0174 
0175   edm::ParameterSetDescription histoPSet;
0176   edm::ParameterSetDescription ptPSet;
0177   edm::ParameterSetDescription etaPSet;
0178   edm::ParameterSetDescription phiPSet;
0179   edm::ParameterSetDescription massPSet;
0180   fillHistoPSetDescription(ptPSet);
0181   fillHistoPSetDescription(etaPSet);
0182   fillHistoPSetDescription(phiPSet);
0183   fillHistoPSetDescription(massPSet);
0184   histoPSet.add<edm::ParameterSetDescription>("ptPSet", ptPSet);
0185   histoPSet.add<edm::ParameterSetDescription>("etaPSet", etaPSet);
0186   histoPSet.add<edm::ParameterSetDescription>("phiPSet", phiPSet);
0187   histoPSet.add<edm::ParameterSetDescription>("massPSet", massPSet);
0188   desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
0189 
0190   edm::ParameterSetDescription genericTriggerEventPSet;
0191   GenericTriggerEventFlag::fillPSetDescription(genericTriggerEventPSet);
0192   desc.add<edm::ParameterSetDescription>("GenericTriggerEventPSet", genericTriggerEventPSet);
0193 
0194   descriptions.add("tau3muMonitoring", desc);
0195 }
0196 
0197 DEFINE_FWK_MODULE(Tau3MuMonitor);