Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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