Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:55:49

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