Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:10

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     /// different verbosity levels
0032     enum Level { STANDARD, VERBOSE, DEBUG };
0033 
0034   public:
0035     /// default contructor
0036     MonitorEnsemble(const char* label, const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC);
0037     /// default destructor
0038     ~MonitorEnsemble(){};
0039 
0040     /// book histograms in subdirectory _directory_
0041     void book(DQMStore::IBooker& ibooker);
0042     /// fill monitor histograms with electronId and jetCorrections
0043     void fill(const edm::Event& event, const edm::EventSetup& setup);
0044 
0045   private:
0046     /// deduce monitorPath from label, the label is expected
0047     /// to be of type 'selectionPath:monitorPath'
0048     std::string monitorPath(const std::string& label) const { return label.substr(label.find(':') + 1); };
0049     /// deduce selectionPath from label, the label is
0050     /// expected to be of type 'selectionPath:monitorPath'
0051     std::string selectionPath(const std::string& label) const { return label.substr(0, label.find(':')); };
0052 
0053     /// set configurable labels for trigger monitoring histograms
0054     void triggerBinLabels(std::string channel, const std::vector<std::string> labels);
0055     /// fill trigger monitoring histograms
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     /// check if histogram was booked
0062     bool booked(const std::string histName) const { return hists_.find(histName) != hists_.end(); };
0063     /// fill histogram if it had been booked before
0064     void fill(const std::string histName, double value) const {
0065       if (booked(histName))
0066         hists_.find(histName)->second->Fill(value);
0067     };
0068     /// fill histogram if it had been booked before (2-dim version)
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     /// fill histogram if it had been booked before (2-dim version)
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     /// verbosity level for booking
0081     Level verbosity_;
0082     /// instance label
0083     std::string label_;
0084     /// considers a vector of METs
0085     std::vector<edm::EDGetTokenT<edm::View<pat::MET> > > mets_;
0086     /// input sources for monitoring
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     /// trigger table
0092     edm::EDGetTokenT<edm::TriggerResults> triggerTable_;
0093     /// trigger paths for monitoring, expected
0094     /// to be of form signalPath:MonitorPath
0095     std::vector<std::string> triggerPaths_;
0096 
0097     edm::InputTag rhoTag;
0098 
0099     /// electronId label
0100     edm::EDGetTokenT<edm::ValueMap<float> > electronId_;
0101 
0102     double eidCutValue_;
0103     /// extra isolation criterion on electron
0104     std::unique_ptr<StringCutObjectSelector<pat::Electron> > elecIso_;
0105     /// extra selection on electrons
0106     std::unique_ptr<StringCutObjectSelector<pat::Electron> > elecSelect_;
0107 
0108     /// extra selection on primary vertices; meant to investigate the pile-up
0109     /// effect
0110     std::unique_ptr<StringCutObjectSelector<reco::Vertex> > pvSelect_;
0111 
0112     /// extra isolation criterion on muon
0113     std::unique_ptr<StringCutObjectSelector<pat::Muon> > muonIso_;
0114 
0115     /// extra selection on muons
0116     std::unique_ptr<StringCutObjectSelector<pat::Muon> > muonSelect_;
0117 
0118     /// jetID as an extra selection type
0119     edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;
0120     /// extra jetID selection on calo jets
0121     std::unique_ptr<StringCutObjectSelector<reco::JetID> > jetIDSelect_;
0122     /// extra selection on jets (here given as std::string as it depends
0123     /// on the the jet type, which selections are valid and which not)
0124     std::string jetSelect_;
0125     std::unique_ptr<StringCutObjectSelector<pat::Jet> > jetSelect;
0126     /// include btag information or not
0127     /// to be determined from the cfg
0128     bool includeBTag_;
0129     /// btag discriminator labels
0130     edm::EDGetTokenT<reco::JetTagCollection> btagEff_, btagPur_, btagVtx_, btagCSV_;
0131     /// btag working points
0132     double btagEffWP_, btagPurWP_, btagVtxWP_, btagCSVWP_;
0133     /// mass window upper and lower edge
0134     double lowerEdge_, upperEdge_;
0135 
0136     /// number of logged interesting events
0137     int logged_;
0138 
0139     /// histogram container
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         // take care to fill triggerMon_ before evts is being called
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 }  // namespace TopSingleLepton_miniAOD
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   /// default constructor
0185   TopSingleLeptonDQM_miniAOD(const edm::ParameterSet& cfg);
0186   /// default destructor
0187   ~TopSingleLeptonDQM_miniAOD() override{};
0188 
0189   /// do this during the event loop
0190   void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
0191 
0192 protected:
0193   //Book histograms
0194   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0195 
0196 private:
0197   /// deduce object type from ParameterSet label, the label
0198   /// is expected to be of type 'objectType:selectionStep'
0199   std::string objectType(const std::string& label) { return label.substr(0, label.find(':')); };
0200   /// deduce selection step from ParameterSet label, the
0201   /// label is expected to be of type 'objectType:selectionStep'
0202   std::string selectionStep(const std::string& label) { return label.substr(label.find(':') + 1); };
0203 
0204 private:
0205   /// trigger table
0206   edm::EDGetTokenT<edm::TriggerResults> triggerTable__;
0207   /// trigger paths
0208   std::vector<std::string> triggerPaths_;
0209   /// string cut selector
0210   std::unique_ptr<StringCutObjectSelector<reco::Vertex> > vertexSelect_;
0211 
0212   /// beamspot
0213   edm::InputTag beamspot_;
0214   edm::EDGetTokenT<reco::BeamSpot> beamspot__;
0215   /// string cut selector
0216   std::unique_ptr<StringCutObjectSelector<reco::BeamSpot> > beamspotSelect_;
0217 
0218   /// needed to guarantee the selection order as defined by the order of
0219   /// ParameterSets in the _selection_ vector as defined in the config
0220   std::vector<std::string> selectionOrder_;
0221   /// this is the heart component of the plugin; std::string keeps a label
0222   /// the selection step for later identification, edm::ParameterSet keeps
0223   /// the configuration of the selection for the SelectionStep class,
0224   /// MonitoringEnsemble keeps an instance of the MonitorEnsemble class to
0225   /// be filled _after_ each selection step
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 /* Local Variables: */
0241 /* show-trailing-whitespace: t */
0242 /* truncate-lines: t */
0243 /* End: */