Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-30 02:32:58

0001 #ifndef SINGLETOPTCHANNELLEPTONDQM_MINIAOD
0002 #define SINGLETOPTCHANNELLEPTONDQM_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 "JetMETCorrections/Objects/interface/JetCorrector.h"
0015 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0016 #include "DataFormats/VertexReco/interface/Vertex.h"
0017 #include "FWCore/Framework/interface/ConsumesCollector.h"
0018 #include "FWCore/Framework/interface/EDConsumerBase.h"
0019 #include "FWCore/Utilities/interface/EDGetToken.h"
0020 
0021 #include "DataFormats/PatCandidates/interface/Muon.h"
0022 #include "DataFormats/PatCandidates/interface/Electron.h"
0023 #include "DataFormats/PatCandidates/interface/Jet.h"
0024 #include "DataFormats/PatCandidates/interface/MET.h"
0025 
0026 namespace SingleTopTChannelLepton_miniAOD {
0027   using dqm::legacy::DQMStore;
0028   using dqm::legacy::MonitorElement;
0029 
0030   class MonitorEnsemble {
0031   public:
0032     /// different verbosity levels
0033     enum Level { STANDARD, VERBOSE, DEBUG };
0034 
0035   public:
0036     /// default contructor
0037     MonitorEnsemble(const char* label, const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC);
0038     /// default destructor
0039     ~MonitorEnsemble(){};
0040 
0041     /// book histograms in subdirectory _directory_
0042     void book(DQMStore::IBooker& ibooker);
0043     /// fill monitor histograms with electronId and jetCorrections
0044     void fill(const edm::Event& event, const edm::EventSetup& setup);
0045 
0046   private:
0047     /// deduce monitorPath from label, the label is expected
0048     /// to be of type 'selectionPath:monitorPath'
0049     std::string monitorPath(const std::string& label) const { return label.substr(label.find(':') + 1); };
0050     /// deduce selectionPath from label, the label is
0051     /// expected to be of type 'selectionPath:monitorPath'
0052     std::string selectionPath(const std::string& label) const { return label.substr(0, label.find(':')); };
0053 
0054     /// set configurable labels for trigger monitoring histograms
0055     void triggerBinLabels(std::string channel, const std::vector<std::string> labels);
0056     /// fill trigger monitoring histograms
0057     void fill(const edm::Event& event,
0058               const edm::TriggerResults& triggerTable,
0059               std::string channel,
0060               const std::vector<std::string> labels) const;
0061 
0062     /// check if histogram was booked
0063     bool booked(const std::string histName) const { return hists_.find(histName) != hists_.end(); };
0064     /// fill histogram if it had been booked before
0065     void fill(const std::string histName, double value) const {
0066       if (booked(histName))
0067         hists_.find(histName)->second->Fill(value);
0068     };
0069     /// fill histogram if it had been booked before (2-dim version)
0070     void fill(const std::string histName, double xValue, double yValue) const {
0071       if (booked(histName))
0072         hists_.find(histName)->second->Fill(xValue, yValue);
0073     };
0074     /// fill histogram if it had been booked before (2-dim version)
0075     void fill(const std::string histName, double xValue, double yValue, double zValue) const {
0076       if (booked(histName))
0077         hists_.find(histName)->second->Fill(xValue, yValue, zValue);
0078     };
0079 
0080   private:
0081     /// verbosity level for booking
0082     Level verbosity_;
0083     /// instance label
0084     std::string label_;
0085     /// considers a vector of METs
0086     std::vector<edm::EDGetTokenT<edm::View<pat::MET> > > mets_;
0087     /// input sources for monitoring
0088     edm::EDGetTokenT<edm::View<pat::Jet> > jets_;
0089     edm::EDGetTokenT<edm::View<pat::Muon> > muons_;
0090     edm::EDGetTokenT<edm::View<pat::Electron> > elecs_;
0091     edm::EDGetTokenT<edm::View<reco::Vertex> > pvs_;
0092     /// trigger table
0093     edm::EDGetTokenT<edm::TriggerResults> triggerTable_;
0094     /// trigger paths for monitoring, expected
0095     /// to be of form signalPath:MonitorPath
0096     std::vector<std::string> triggerPaths_;
0097 
0098     edm::InputTag rhoTag;
0099 
0100     /// electronId label
0101     edm::EDGetTokenT<edm::ValueMap<float> > electronId_;
0102 
0103     double eidCutValue_;
0104     /// extra isolation criterion on electron
0105     std::unique_ptr<StringCutObjectSelector<pat::Electron> > elecIso_;
0106     /// extra selection on electrons
0107     std::unique_ptr<StringCutObjectSelector<pat::Electron> > elecSelect_;
0108 
0109     /// extra selection on primary vertices; meant to investigate the pile-up
0110     /// effect
0111     std::unique_ptr<StringCutObjectSelector<reco::Vertex> > pvSelect_;
0112 
0113     /// extra isolation criterion on muon
0114     std::unique_ptr<StringCutObjectSelector<pat::Muon> > muonIso_;
0115 
0116     /// extra selection on muons
0117     std::unique_ptr<StringCutObjectSelector<pat::Muon> > muonSelect_;
0118 
0119     /// jetCorrector
0120     edm::ESGetToken<JetCorrector, JetCorrectionsRecord> jetCorrector_;
0121     /// jetID as an extra selection type
0122     edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;
0123     /// extra jetID selection on calo jets
0124     std::unique_ptr<StringCutObjectSelector<reco::JetID> > jetIDSelect_;
0125     /// extra selection on jets (here given as std::string as it depends
0126     /// on the the jet type, which selections are valid and which not)
0127     std::string jetSelect_;
0128     std::unique_ptr<StringCutObjectSelector<pat::Jet> > jetSelect;
0129     /// include btag information or not
0130     /// to be determined from the cfg
0131     bool includeBTag_;
0132     /// btag discriminator labels
0133     edm::EDGetTokenT<reco::JetTagCollection> btagEff_, btagPur_, btagVtx_, btagCSV_;
0134     /// btag working points
0135     double btagEffWP_, btagPurWP_, btagVtxWP_, btagCSVWP_;
0136     /// mass window upper and lower edge
0137     double lowerEdge_, upperEdge_;
0138 
0139     /// number of logged interesting events
0140     int logged_;
0141 
0142     /// histogram container
0143     std::map<std::string, MonitorElement*> hists_;
0144     edm::EDConsumerBase tmpConsumerBase;
0145     std::string directory_;
0146   };
0147 
0148   inline void MonitorEnsemble::triggerBinLabels(std::string channel, const std::vector<std::string> labels) {
0149     for (unsigned int idx = 0; idx < labels.size(); ++idx) {
0150       hists_[channel + "Mon_"]->setBinLabel(idx + 1, "[" + monitorPath(labels[idx]) + "]", 1);
0151       hists_[channel + "Eff_"]->setBinLabel(
0152           idx + 1, "[" + selectionPath(labels[idx]) + "]|[" + monitorPath(labels[idx]) + "]", 1);
0153     }
0154   }
0155 
0156   inline void MonitorEnsemble::fill(const edm::Event& event,
0157                                     const edm::TriggerResults& triggerTable,
0158                                     std::string channel,
0159                                     const std::vector<std::string> labels) const {
0160     for (unsigned int idx = 0; idx < labels.size(); ++idx) {
0161       if (accept(event, triggerTable, monitorPath(labels[idx]))) {
0162         fill(channel + "Mon_", idx + 0.5);
0163         // take care to fill triggerMon_ before evts is being called
0164         int evts = hists_.find(channel + "Mon_")->second->getBinContent(idx + 1);
0165         double value = hists_.find(channel + "Eff_")->second->getBinContent(idx + 1);
0166         fill(
0167             channel + "Eff_", idx + 0.5, 1. / evts * (accept(event, triggerTable, selectionPath(labels[idx])) - value));
0168       }
0169     }
0170   }
0171 }  // namespace SingleTopTChannelLepton_miniAOD
0172 
0173 #include <utility>
0174 
0175 #include "DQM/Physics/interface/TopDQMHelpers.h"
0176 #include "FWCore/Framework/interface/Frameworkfwd.h"
0177 #include "FWCore/ServiceRegistry/interface/Service.h"
0178 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0179 
0180 #include "FWCore/Common/interface/TriggerNames.h"
0181 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0182 #include "DataFormats/VertexReco/interface/Vertex.h"
0183 #include "DataFormats/Common/interface/TriggerResults.h"
0184 
0185 class SingleTopTChannelLeptonDQM_miniAOD : public DQMOneEDAnalyzer<> {
0186 public:
0187   /// default constructor
0188   SingleTopTChannelLeptonDQM_miniAOD(const edm::ParameterSet& cfg);
0189   /// default destructor
0190   ~SingleTopTChannelLeptonDQM_miniAOD() override{};
0191 
0192   /// do this during the event loop
0193   void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
0194 
0195 protected:
0196   //Book histograms
0197   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0198 
0199 private:
0200   /// deduce object type from ParameterSet label, the label
0201   /// is expected to be of type 'objectType:selectionStep'
0202   std::string objectType(const std::string& label) { return label.substr(0, label.find(':')); };
0203   /// deduce selection step from ParameterSet label, the
0204   /// label is expected to be of type 'objectType:selectionStep'
0205   std::string selectionStep(const std::string& label) { return label.substr(label.find(':') + 1); };
0206 
0207 private:
0208   /// trigger table
0209   edm::EDGetTokenT<edm::TriggerResults> triggerTable__;
0210   /// trigger paths
0211   std::vector<std::string> triggerPaths_;
0212   /// string cut selector
0213   std::unique_ptr<StringCutObjectSelector<reco::Vertex> > vertexSelect_;
0214 
0215   /// beamspot
0216   edm::InputTag beamspot_;
0217   edm::EDGetTokenT<reco::BeamSpot> beamspot__;
0218   /// string cut selector
0219   std::unique_ptr<StringCutObjectSelector<reco::BeamSpot> > beamspotSelect_;
0220 
0221   /// needed to guarantee the selection order as defined by the order of
0222   /// ParameterSets in the _selection_ vector as defined in the config
0223   std::vector<std::string> selectionOrder_;
0224   /// this is the heart component of the plugin; std::string keeps a label
0225   /// the selection step for later identification, edm::ParameterSet keeps
0226   /// the configuration of the selection for the SelectionStep class,
0227   /// MonitoringEnsemble keeps an instance of the MonitorEnsemble class to
0228   /// be filled _after_ each selection step
0229   std::map<std::string, std::pair<edm::ParameterSet, std::unique_ptr<SingleTopTChannelLepton_miniAOD::MonitorEnsemble> > >
0230       selection_;
0231   std::unique_ptr<SelectionStep<pat::Muon> > MuonStep;
0232   std::unique_ptr<SelectionStep<pat::Electron> > ElectronStep;
0233   std::unique_ptr<SelectionStep<reco::Vertex> > PvStep;
0234   std::unique_ptr<SelectionStep<pat::MET> > METStep;
0235   std::vector<std::unique_ptr<SelectionStep<pat::Jet> > > JetSteps;
0236 
0237   std::vector<edm::ParameterSet> sel_;
0238   edm::ParameterSet setup_;
0239 };
0240 
0241 #endif
0242 
0243 /* Local Variables: */
0244 /* show-trailing-whitespace: t */
0245 /* truncate-lines: t */
0246 /* End: */