Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:52

0001 #ifndef HLTriggerOffline_Exotica_HLTExoticaSubAnalysis_H
0002 #define HLTriggerOffline_Exotica_HLTExoticaSubAnalysis_H
0003 
0004 /** \class HLTExoticaSubAnalysis
0005  *  Generate histograms for trigger efficiencies Exotica related
0006  *  Documentation available on the CMS TWiki:
0007  *  https://twiki.cern.ch/twiki/bin/view/CMS/EXOTICATriggerValidation
0008  *
0009  *  \author  Thiago R. Fernandez Perez Tomei
0010  *           Based and adapted from:
0011  *           J. Duarte Campderros code from HLTriggerOffline/Higgs
0012  *           J. Klukas, M. Vander Donckt and J. Alcaraz code
0013  *           from the HLTriggerOffline/Muon package.
0014  */
0015 
0016 #include "FWCore/Framework/interface/ConsumesCollector.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/Utilities/interface/InputTag.h"
0022 
0023 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0024 #include "DQMServices/Core/interface/DQMStore.h"
0025 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0026 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0027 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0028 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0029 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0030 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
0031 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0032 #include "DataFormats/JetReco/interface/CaloJet.h"
0033 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0034 #include "DataFormats/JetReco/interface/PFJet.h"
0035 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0036 #include "DataFormats/METReco/interface/CaloMET.h"
0037 #include "DataFormats/METReco/interface/CaloMETCollection.h"
0038 #include "DataFormats/METReco/interface/GenMET.h"
0039 #include "DataFormats/METReco/interface/GenMETCollection.h"
0040 #include "DataFormats/METReco/interface/PFMET.h"
0041 #include "DataFormats/METReco/interface/PFMETCollection.h"
0042 #include "DataFormats/MuonReco/interface/Muon.h"
0043 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0044 #include "DataFormats/TauReco/interface/PFTau.h"
0045 #include "DataFormats/TauReco/interface/PFTauFwd.h"
0046 #include "DataFormats/TrackReco/interface/Track.h"
0047 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0048 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0049 
0050 #include "HLTriggerOffline/Exotica/interface/HLTExoticaPlotter.h"
0051 
0052 #include <cstring>
0053 #include <map>
0054 #include <set>
0055 #include <vector>
0056 
0057 /// Class to manage all object collections from a centralized place.
0058 struct EVTColContainer;
0059 
0060 /// This class is the main workhorse of the package.
0061 /// It makes the histograms for one given analysis, taking care
0062 /// of all HLT paths related to that analysis.
0063 class HLTExoticaSubAnalysis {
0064 public:
0065   typedef dqm::legacy::DQMStore DQMStore;
0066   typedef dqm::legacy::MonitorElement MonitorElement;
0067 
0068   enum class Level { GEN = 98, RECO = 99 };
0069 
0070   HLTExoticaSubAnalysis(const edm::ParameterSet &pset,
0071                         const std::string &analysisname,
0072                         edm::ConsumesCollector &&consCollector);
0073   ~HLTExoticaSubAnalysis();
0074   void beginJob();
0075   void beginRun(const edm::Run &iRun, const edm::EventSetup &iEventSetup);
0076   void endRun();
0077 
0078   /// Method to book all relevant histograms in the DQMStore.
0079   /// Uses the IBooker interface for thread safety.
0080   /// Intended to be called from master object.
0081   void subAnalysisBookHistos(DQMStore::IBooker &iBooker, const edm::Run &iRun, const edm::EventSetup &iSetup);
0082 
0083   /// Method to fill all relevant histograms.
0084   /// Notice that we update the EVTColContaner to point to the collections we
0085   /// want.
0086   void analyze(const edm::Event &iEvent, const edm::EventSetup &iEventSetup, EVTColContainer *cols);
0087 
0088 private:
0089   /// Return the objects (muons,electrons,photons,...) needed by a HLT path.
0090   /// Will in general return: 0 for muon, 1 for electron, 2 for photon,
0091   /// 3 for PFMET, 4 for PFTau, 5 for Jet.
0092   /// Notice that this function is really based on a parsing of the name of
0093   /// the path; any incongruences there may lead to problems.
0094   const std::vector<unsigned int> getObjectsType(const std::string &hltpath) const;
0095 
0096   /// Creates the maps that map  which collection should come from which label
0097   void getNamesOfObjects(const edm::ParameterSet &anpset);
0098   /// Registers consumption of objects
0099   void registerConsumes(edm::ConsumesCollector &consCollector);
0100   /// Gets the collections themselves
0101   void getHandlesToObjects(const edm::Event &iEvent, EVTColContainer *col);
0102   /// Initializes the selectors of the objects based on which object it is
0103   void initSelector(const unsigned int &objtype);
0104   /// This function applies the selectors initialized previously to the objects,
0105   /// and matches the passing objects to HLT objects.
0106   void insertCandidates(const unsigned int &objtype,
0107                         const EVTColContainer *col,
0108                         std::vector<reco::LeafCandidate> *matches,
0109                         std::map<int, double> &theSumEt,
0110                         std::map<int, std::vector<const reco::Track *>> &trkObjs);
0111 
0112   /// The internal functions to book and fill histograms
0113   void bookHist(DQMStore::IBooker &iBooker,
0114                 const std::string &source,
0115                 const std::string &objType,
0116                 const std::string &variable);
0117   void fillHist(const std::string &source, const std::string &objType, const std::string &variable, const float &value);
0118 
0119   /// Internal, working copy of the PSet passed from above.
0120   edm::ParameterSet _pset;
0121 
0122   /// The name of this sub-analysis
0123   std::string _analysisname;
0124 
0125   /// The minimum number of reco/gen candidates needed by the analysis
0126   unsigned int _minCandidates;
0127 
0128   /// The hlt paths to check for.
0129   std::vector<std::string> _hltPathsToCheck;
0130   /// The hlt paths found in the hltConfig
0131   std::set<std::string> _hltPaths;
0132   /// Relation between the short and long versions of the path
0133   std::map<std::string, std::string> _shortpath2long;
0134 
0135   /// The labels of the object collections to be used in this analysis.
0136   std::string _hltProcessName;
0137   edm::InputTag _genParticleLabel;
0138   edm::InputTag _trigResultsLabel;
0139   edm::InputTag _beamSpotLabel;
0140   std::map<unsigned int, edm::InputTag> _recLabels;
0141   /// And also the tokens to get the object collections
0142   edm::EDGetTokenT<reco::GenParticleCollection> _genParticleToken;
0143   edm::EDGetTokenT<edm::TriggerResults> _trigResultsToken;
0144   edm::EDGetTokenT<reco::BeamSpot> _bsToken;
0145   std::map<unsigned int, edm::EDGetToken> _tokens;
0146 
0147   /// Some kinematical parameters
0148   std::vector<double> _parametersEta;
0149   std::vector<double> _parametersPhi;
0150   std::vector<double> _parametersTurnOn;
0151   std::vector<double> _parametersTurnOnSumEt;
0152   std::vector<double> _parametersDxy;
0153 
0154   // flag to switch off
0155   bool _drop_pt2;
0156   bool _drop_pt3;
0157 
0158   /// gen/rec objects cuts
0159   std::map<unsigned int, std::string> _genCut;
0160   std::map<unsigned int, std::string> _recCut;
0161   /// gen/rec pt-leading objects cuts
0162   std::map<unsigned int, std::string> _genCut_leading;
0163   std::map<unsigned int, std::string> _recCut_leading;
0164 
0165   /// The concrete String selectors (use the string cuts introduced
0166   /// via the config python)
0167   std::map<unsigned int, StringCutObjectSelector<reco::GenParticle> *> _genSelectorMap;
0168   StringCutObjectSelector<reco::Muon> *_recMuonSelector;
0169   StringCutObjectSelector<reco::Track> *_recMuonTrkSelector;
0170   StringCutObjectSelector<reco::Track> *_recTrackSelector;
0171   StringCutObjectSelector<reco::GsfElectron> *_recElecSelector;
0172   StringCutObjectSelector<reco::MET> *_recMETSelector;
0173   StringCutObjectSelector<reco::PFMET> *_recPFMETSelector;
0174   StringCutObjectSelector<reco::PFMET> *_recPFMHTSelector;
0175   StringCutObjectSelector<reco::GenMET> *_genMETSelector;
0176   StringCutObjectSelector<reco::CaloMET> *_recCaloMETSelector;
0177   StringCutObjectSelector<reco::CaloMET> *_recCaloMHTSelector;
0178   StringCutObjectSelector<reco::PFTau> *_recPFTauSelector;
0179   StringCutObjectSelector<reco::Photon> *_recPhotonSelector;
0180   StringCutObjectSelector<reco::PFJet> *_recPFJetSelector;
0181   StringCutObjectSelector<reco::CaloJet> *_recCaloJetSelector;
0182 
0183   /// The plotters: managers of each hlt path where the plots are done
0184   std::vector<HLTExoticaPlotter> _plotters;
0185 
0186   /// counting HLT passed events
0187   std::map<std::string, int> _triggerCounter;
0188 
0189   /// Interface to the HLT information
0190   HLTConfigProvider _hltConfig;
0191 
0192   /// Structure of the MonitorElements
0193   std::map<std::string, MonitorElement *> _elements;
0194 };
0195 
0196 #endif