Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef SINGLETOPTCHANNELLEPTONDQM
0002 #define SINGLETOPTCHANNELLEPTONDQM
0003 
0004 #include <string>
0005 #include <vector>
0006 
0007 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0008 
0009 #include "DataFormats/JetReco/interface/Jet.h"
0010 #include "DQM/Physics/interface/TopDQMHelpers.h"
0011 #include "DataFormats/MuonReco/interface/Muon.h"
0012 #include "DataFormats/Common/interface/ValueMap.h"
0013 #include "DataFormats/METReco/interface/CaloMET.h"
0014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0015 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
0016 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0017 #include "DataFormats/VertexReco/interface/Vertex.h"
0018 #include "FWCore/Framework/interface/ConsumesCollector.h"
0019 #include "FWCore/Framework/interface/EDConsumerBase.h"
0020 #include "FWCore/Utilities/interface/EDGetToken.h"
0021 #include "JetMETCorrections/JetCorrector/interface/JetCorrector.h"
0022 
0023 /**
0024    \class   MonitorEnsemble TopDQMHelpers.h
0025    "DQM/Physics/interface/TopDQMHelpers.h"
0026 
0027    \brief   Helper class to define histograms for monitoring of
0028    muon/electron/jet/met quantities.
0029 
0030    Helper class to contain histograms for the monitoring of
0031    muon/electron/jet/met quantities.
0032    This class can be instantiated several times after several event selection
0033    steps. It can
0034    be used to fill histograms in three different granularity levels according to
0035    STANDARD
0036    (<10 histograms), VERBOSE(<20 histograms), DEBUG(<30 histgorams). Note that
0037    for the sake
0038    of simplicity and to force the analyst to keep the number of histograms to be
0039    monitored
0040    small the MonitorEnsemble class contains the histograms for all objects at
0041    once. It should
0042    not contain much more than 10 histograms though in the STANDARD
0043    configuration, as these
0044    histograms will be monitored at each SelectionStep. Monitoring of histograms
0045    after selec-
0046    tion steps within the same object collection needs to be implemented within
0047    the Monitor-
0048    Ensemble. It will not be covered by the SelectionStep class.
0049 */
0050 
0051 namespace SingleTopTChannelLepton {
0052   using dqm::legacy::DQMStore;
0053   using dqm::legacy::MonitorElement;
0054 
0055   class MonitorEnsemble {
0056   public:
0057     /// different verbosity levels
0058     enum Level { STANDARD, VERBOSE, DEBUG };
0059 
0060   public:
0061     /// default contructor
0062     MonitorEnsemble(const char* label,
0063                     const edm::ParameterSet& cfg,
0064                     const edm::VParameterSet& vcfg,
0065                     edm::ConsumesCollector&& iC);
0066     /// default destructor
0067     ~MonitorEnsemble() {}
0068 
0069     /// book histograms in subdirectory _directory_
0070     void book(DQMStore::IBooker& ibooker);
0071     /// fill monitor histograms with electronId and jetCorrections
0072     void fill(const edm::Event& event, const edm::EventSetup& setup);
0073 
0074   private:
0075     /// deduce monitorPath from label, the label is expected
0076     /// to be of type 'selectionPath:monitorPath'
0077     std::string monitorPath(const std::string& label) const { return label.substr(label.find(':') + 1); };
0078     /// deduce selectionPath from label, the label is
0079     /// expected to be of type 'selectionPath:monitorPath'
0080     std::string selectionPath(const std::string& label) const { return label.substr(0, label.find(':')); };
0081 
0082     /// set configurable labels for trigger monitoring histograms
0083     void triggerBinLabels(std::string channel, const std::vector<std::string> labels);
0084     /// fill trigger monitoring histograms
0085     void fill(const edm::Event& event,
0086               const edm::TriggerResults& triggerTable,
0087               std::string channel,
0088               const std::vector<std::string> labels) const;
0089 
0090     /// check if histogram was booked
0091     bool booked(const std::string histName) const { return hists_.find(histName) != hists_.end(); };
0092     /// fill histogram if it had been booked before
0093     void fill(const std::string histName, double value) const {
0094       if (booked(histName))
0095         hists_.find(histName)->second->Fill(value);
0096     };
0097     /// fill histogram if it had been booked before (2-dim version)
0098     void fill(const std::string histName, double xValue, double yValue) const {
0099       if (booked(histName))
0100         hists_.find(histName)->second->Fill(xValue, yValue);
0101     };
0102     /// fill histogram if it had been booked before (2-dim version)
0103     void fill(const std::string histName, double xValue, double yValue, double zValue) const {
0104       if (booked(histName))
0105         hists_.find(histName)->second->Fill(xValue, yValue, zValue);
0106     };
0107 
0108   private:
0109     /// verbosity level for booking
0110     Level verbosity_;
0111     /// instance label
0112     std::string label_;
0113     /// considers a vector of METs
0114     std::vector<edm::EDGetTokenT<edm::View<reco::MET> > > mets_;
0115     //    std::vector<edm::InputTag> mets_;
0116     /// input sources for monitoring
0117     edm::EDGetTokenT<edm::View<reco::Jet> > jets_;
0118     edm::EDGetTokenT<edm::View<reco::PFCandidate> > muons_;
0119     edm::EDGetTokenT<edm::View<reco::GsfElectron> > elecs_gsf_;
0120     edm::EDGetTokenT<edm::View<reco::PFCandidate> > elecs_;
0121     edm::EDGetTokenT<edm::View<reco::Vertex> > pvs_;
0122 
0123     //    edm::InputTag elecs_, elecs_gsf_, muons_, muons_reco_, jets_, pvs_;
0124 
0125     /// trigger table
0126     //    edm::InputTag triggerTable_;
0127     edm::EDGetTokenT<edm::TriggerResults> triggerTable_;
0128 
0129     /// trigger paths for monitoring, expected
0130     /// to be of form signalPath:MonitorPath
0131     std::vector<std::string> triggerPaths_;
0132 
0133     /// electronId label
0134     //    edm::InputTag electronId_;
0135     edm::EDGetTokenT<edm::ValueMap<float> > electronId_;
0136     /// electronId pattern we expect the following pattern:
0137     ///  0: fails
0138     ///  1: passes electron ID only
0139     ///  2: passes electron Isolation only
0140     ///  3: passes electron ID and Isolation only
0141     ///  4: passes conversion rejection
0142     ///  5: passes conversion rejection and ID
0143     ///  6: passes conversion rejection and Isolation
0144     ///  7: passes the whole selection
0145     /// As described on
0146     /// https://twiki.cern.ch/twiki/bin/view/CMS/SimpleCutBasedEleID
0147     // int eidPattern_;
0148     // the cut for the MVA Id
0149     double eidCutValue_;
0150     /// extra isolation criterion on electron
0151     std::string elecIso_;
0152     /// extra selection on electrons
0153     std::unique_ptr<StringCutObjectSelector<reco::PFCandidate> > elecSelect_;
0154     edm::InputTag rhoTag;
0155 
0156     /// extra selection on primary vertices; meant to investigate the pile-up
0157     /// effect
0158     std::unique_ptr<StringCutObjectSelector<reco::Vertex> > pvSelect_;
0159 
0160     /// extra isolation criterion on muon
0161     std::unique_ptr<StringCutObjectSelector<reco::PFCandidate> > muonIso_;
0162 
0163     /// extra selection on muons
0164     std::unique_ptr<StringCutObjectSelector<reco::PFCandidate> > muonSelect_;
0165     /// jetCorrector
0166     edm::ESGetToken<JetCorrector, JetCorrectionsRecord> jetCorrector_;
0167     /// jetID as an extra selection type
0168     edm::EDGetTokenT<reco::JetIDValueMap> jetIDLabel_;
0169 
0170     /// extra jetID selection on calo jets
0171     std::unique_ptr<StringCutObjectSelector<reco::JetID> > jetIDSelect_;
0172     std::unique_ptr<StringCutObjectSelector<reco::PFJet> > jetlooseSelection_;
0173     std::unique_ptr<StringCutObjectSelector<reco::PFJet> > jetSelection_;
0174     /// extra selection on jets (here given as std::string as it depends
0175     /// on the the jet type, which selections are valid and which not)
0176     std::string jetSelect_;
0177     /// include btag information or not
0178     /// to be determined from the cfg
0179     bool includeBTag_;
0180     /// btag discriminator labels
0181     //    edm::InputTag btagEff_, btagPur_, btagVtx_, btagCombVtx_;
0182     edm::EDGetTokenT<reco::JetTagCollection> btagEff_, btagPur_, btagVtx_, btagCSV_, btagCombVtx_;
0183 
0184     /// btag working points
0185     double btagEffWP_, btagPurWP_, btagVtxWP_, btagCSVWP_, btagCombVtxWP_;
0186     /// mass window upper and lower edge
0187     double lowerEdge_, upperEdge_;
0188 
0189     /// number of logged interesting events
0190     int logged_;
0191     /// storage manager
0192     /// histogram container
0193     std::map<std::string, MonitorElement*> hists_;
0194     edm::EDConsumerBase tmpConsumerBase;
0195 
0196     std::string directory_;
0197 
0198     std::unique_ptr<StringCutObjectSelector<reco::PFCandidate, true> > muonSelect;
0199     std::unique_ptr<StringCutObjectSelector<reco::PFCandidate, true> > muonIso;
0200 
0201     std::unique_ptr<StringCutObjectSelector<reco::PFCandidate, true> > elecSelect;
0202     std::unique_ptr<StringCutObjectSelector<reco::PFCandidate, true> > elecIso;
0203   };
0204 
0205   inline void MonitorEnsemble::triggerBinLabels(std::string channel, const std::vector<std::string> labels) {
0206     for (unsigned int idx = 0; idx < labels.size(); ++idx) {
0207       hists_[channel + "Mon_"]->setBinLabel(idx + 1, "[" + monitorPath(labels[idx]) + "]", 1);
0208       hists_[channel + "Eff_"]->setBinLabel(
0209           idx + 1, "[" + selectionPath(labels[idx]) + "]|[" + monitorPath(labels[idx]) + "]", 1);
0210     }
0211   }
0212 
0213   inline void MonitorEnsemble::fill(const edm::Event& event,
0214                                     const edm::TriggerResults& triggerTable,
0215                                     std::string channel,
0216                                     const std::vector<std::string> labels) const {
0217     for (unsigned int idx = 0; idx < labels.size(); ++idx) {
0218       if (accept(event, triggerTable, monitorPath(labels[idx]))) {
0219         fill(channel + "Mon_", idx + 0.5);
0220         // take care to fill triggerMon_ before evts is being called
0221         int evts = hists_.find(channel + "Mon_")->second->getBinContent(idx + 1);
0222         double value = hists_.find(channel + "Eff_")->second->getBinContent(idx + 1);
0223         fill(
0224             channel + "Eff_", idx + 0.5, 1. / evts * (accept(event, triggerTable, selectionPath(labels[idx])) - value));
0225       }
0226     }
0227   }
0228 }  // namespace SingleTopTChannelLepton
0229 
0230 #include <utility>
0231 
0232 #include "DQM/Physics/interface/TopDQMHelpers.h"
0233 #include "FWCore/Framework/interface/Frameworkfwd.h"
0234 #include "FWCore/ServiceRegistry/interface/Service.h"
0235 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0236 
0237 #include "FWCore/Common/interface/TriggerNames.h"
0238 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0239 #include "DataFormats/VertexReco/interface/Vertex.h"
0240 #include "DataFormats/Common/interface/TriggerResults.h"
0241 
0242 /**
0243    \class   SingleTopTChannelLeptonDQM SingleTopTChannelLeptonDQM.h
0244    "DQM/Physics/plugins/SingleTopTChannelLeptonDQM.h"
0245 
0246    \brief   Module to apply a monitored selection of top like events in the
0247    semi-leptonic channel
0248 
0249    Plugin to apply a monitored selection of top like events with some minimal
0250    flexibility in the number and definition of the selection steps. To achieve
0251    this flexibility it employes the SelectionStep class. The MonitorEnsemble
0252    class is used to provide a well defined set of histograms to be monitored
0253    after each selection step. The SelectionStep class provides a flexible and
0254    intuitive selection via the StringCutParser.  SelectionStep and
0255    MonitorEnsemble classes are interleaved. The monitoring starts after a
0256    preselection step (which is not monitored in the context of this module) with
0257    an instance of the MonitorEnsemble class. The following objects are supported
0258    for selection:
0259 
0260     - jets  : of type reco::Jet (jets), reco::CaloJet (jets/calo) or reco::PFJet
0261    (jets/pflow)
0262     - elecs : of type reco::GsfElectron
0263     - muons : of type reco::Muon
0264     - met   : of type reco::MET
0265 
0266    These types have to be present as prefix of the selection step paramter
0267    _label_ separated from the rest of the label by a ':' (e.g. in the form
0268    "jets:step0"). The class expects selection labels of this type. They will be
0269    disentangled by the private helper functions _objectType_ and _seletionStep_
0270    as declared below.
0271 */
0272 
0273 /// define MonitorEnsembple to be used
0274 // using SingleTopTChannelLepton::MonitorEnsemble;
0275 
0276 class SingleTopTChannelLeptonDQM : public DQMOneEDAnalyzer<> {
0277 public:
0278   /// default constructor
0279   SingleTopTChannelLeptonDQM(const edm::ParameterSet& cfg);
0280   /// default destructor
0281   ~SingleTopTChannelLeptonDQM() override{};
0282 
0283   /// do this during the event loop
0284   void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
0285 
0286 protected:
0287   //Book histograms
0288   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0289 
0290 private:
0291   /// deduce object type from ParameterSet label, the label
0292   /// is expected to be of type 'objectType:selectionStep'
0293   std::string objectType(const std::string& label) { return label.substr(0, label.find(':')); };
0294   /// deduce selection step from ParameterSet label, the
0295   /// label is expected to be of type 'objectType:selectionStep'
0296   std::string selectionStep(const std::string& label) { return label.substr(label.find(':') + 1); };
0297 
0298 private:
0299   /// trigger table
0300   edm::EDGetTokenT<edm::TriggerResults> triggerTable__;
0301 
0302   /// trigger paths
0303   std::vector<std::string> triggerPaths_;
0304   /// primary vertex
0305   edm::InputTag vertex_;
0306   edm::EDGetTokenT<reco::Vertex> vertex__;
0307   /// string cut selector
0308   std::unique_ptr<StringCutObjectSelector<reco::Vertex> > vertexSelect_;
0309 
0310   /// beamspot
0311   edm::InputTag beamspot_;
0312   edm::EDGetTokenT<reco::BeamSpot> beamspot__;
0313   /// string cut selector
0314   std::unique_ptr<StringCutObjectSelector<reco::BeamSpot> > beamspotSelect_;
0315 
0316   /// needed to guarantee the selection order as defined by the order of
0317   /// ParameterSets in the _selection_ vector as defined in the config
0318   std::vector<std::string> selectionOrder_;
0319   /// this is the heart component of the plugin; std::string keeps a label
0320   /// the selection step for later identification, edm::ParameterSet keeps
0321   /// the configuration of the selection for the SelectionStep class,
0322   /// MonitoringEnsemble keeps an instance of the MonitorEnsemble class to
0323   /// be filled _after_ each selection step
0324   std::map<std::string, std::pair<edm::ParameterSet, std::unique_ptr<SingleTopTChannelLepton::MonitorEnsemble> > >
0325       selection_;
0326 
0327   std::unique_ptr<SelectionStep<reco::Muon> > MuonStep;
0328   std::unique_ptr<SelectionStep<reco::PFCandidate> > PFMuonStep;
0329   std::unique_ptr<SelectionStep<reco::GsfElectron> > ElectronStep;
0330   std::unique_ptr<SelectionStep<reco::PFCandidate> > PFElectronStep;
0331   std::unique_ptr<SelectionStep<reco::Vertex> > PvStep;
0332 
0333   std::vector<std::unique_ptr<SelectionStep<reco::Jet> > > JetSteps;
0334   std::vector<std::unique_ptr<SelectionStep<reco::CaloJet> > > CaloJetSteps;
0335   std::vector<std::unique_ptr<SelectionStep<reco::PFJet> > > PFJetSteps;
0336 
0337   std::unique_ptr<SelectionStep<reco::MET> > METStep;
0338   std::vector<edm::ParameterSet> sel;
0339 };
0340 
0341 #endif