Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-29 23:10:45

0001 #ifndef HLTriggerOffline_Egamma_EmDQM_H
0002 #define HLTriggerOffline_Egamma_EmDQM_H
0003 
0004 // Base Class Headers
0005 #include "CommonTools/Utils/interface/PtComparator.h"
0006 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0007 #include "DQMServices/Core/interface/DQMStore.h"
0008 #include "DataFormats/Common/interface/AssociationMap.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include "DataFormats/Common/interface/RefToBase.h"
0011 #include "DataFormats/Common/interface/TriggerResults.h"
0012 #include "DataFormats/EgammaCandidates/interface/Electron.h"
0013 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
0014 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0015 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0016 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
0017 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
0018 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/Utilities/interface/Exception.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0027 #include "HepMC/GenParticle.h"
0028 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0029 
0030 #include <boost/regex.hpp>
0031 
0032 #include "TDirectory.h"
0033 #include "TFile.h"
0034 #include "TH1F.h"
0035 #include <Math/VectorUtil.h>
0036 #include <cmath>
0037 #include <iostream>
0038 #include <memory>
0039 #include <string>
0040 #include <vector>
0041 
0042 class EmDQM;
0043 
0044 template <class T>
0045 class HistoFiller {
0046 public:
0047   HistoFiller(EmDQM *d) : dqm(d){};
0048   ~HistoFiller(){};
0049 
0050   void fillHistos(edm::Handle<trigger::TriggerEventWithRefs> &,
0051                   const edm::Event &,
0052                   unsigned int,
0053                   unsigned int,
0054                   std::vector<reco::Particle> &,
0055                   bool &);
0056   // std::vector<edm::EDGetTokenT<edm::AssociationMap<edm::OneToValue< T ,
0057   // float>>>> isoNameTokens_;
0058 
0059 private:
0060   EmDQM *dqm;
0061 };
0062 
0063 class EmDQM : public DQMOneEDAnalyzer<> {
0064 public:
0065   friend class HistoFiller<reco::ElectronCollection>;
0066   friend class HistoFiller<reco::RecoEcalCandidateCollection>;
0067   friend class HistoFiller<l1extra::L1EmParticleCollection>;
0068 
0069   /// Constructor
0070   explicit EmDQM(const edm::ParameterSet &pset);
0071 
0072   /// Destructor
0073   ~EmDQM() override;
0074 
0075   // Operations
0076 
0077   void analyze(const edm::Event &event, const edm::EventSetup &) override;
0078 
0079   void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override;
0080   void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0081   void dqmEndRun(edm::Run const &, edm::EventSetup const &) override;
0082 
0083 private:
0084   // interface to DQM framework
0085   std::string dirname_;
0086 
0087   HistoFiller<reco::ElectronCollection> *histoFillerEle;
0088   HistoFiller<reco::RecoEcalCandidateCollection> *histoFillerClu;
0089   HistoFiller<l1extra::L1EmParticleCollection> *histoFillerL1NonIso;
0090   HistoFiller<reco::RecoEcalCandidateCollection> *histoFillerPho;
0091   HistoFiller<l1extra::L1EmParticleCollection> *histoFillerL1Iso;
0092 
0093   // run in automatic configuration generation mode
0094   bool autoConfMode_;
0095   // parameter set from config file
0096   const edm::ParameterSet &pset;
0097   // global parameters
0098   edm::InputTag triggerObject_;
0099   unsigned int verbosity_;
0100   double genEtaAcc_;
0101   double genEtAcc_;
0102   bool isData_;
0103   double ptMax_;
0104   double ptMin_;
0105   double etaMax_;
0106   double phiMax_;
0107   unsigned int nbins_;
0108   double eta2DMax_;
0109   double phi2DMax_;
0110   unsigned int nbins2D_;
0111   unsigned int minEtForEtaEffPlot_;
0112   bool useHumanReadableHistTitles_;
0113   bool mcMatchedOnly_;
0114   bool noPhiPlots_;
0115   bool noIsolationPlots_;
0116 
0117   /** helper to check whether there were enough generator level
0118    *  electrons/photons (MC) or enough reco level electrons/photons
0119    *  to analyze this event.
0120    *
0121    *  @return if the event has enough of these candidates.
0122    */
0123   bool checkGeneratedParticlesRequirement(const edm::Event &event);
0124 
0125   /** similar to checkGeneratedParticlesRequirement(..) but for reconstructed
0126    *  particles. For the moment, there are some additional requirements in
0127    *  the MC version so we can't use the same code for both cases.
0128    */
0129   bool checkRecoParticlesRequirement(const edm::Event &event);
0130 
0131   /// The instance of the HLTConfigProvider as a data member
0132   HLTConfigProvider hltConfig_;
0133 
0134   // routines to build validation configuration from HLTConfiguration
0135   int countSubstring(const std::string &, const std::string &);
0136   std::vector<std::vector<std::string>> findEgammaPaths();
0137   std::vector<std::string> getFilterModules(const std::string &);
0138   double getPrimaryEtCut(const std::string &);
0139   edm::ParameterSet makePSetForL1SeedFilter(const std::string &);
0140   edm::ParameterSet makePSetForL1SeedToSuperClusterMatchFilter(const std::string &);
0141   edm::ParameterSet makePSetForEtFilter(const std::string &);
0142   edm::ParameterSet makePSetForOneOEMinusOneOPFilter(const std::string &);
0143   edm::ParameterSet makePSetForPixelMatchFilter(const std::string &);
0144   edm::ParameterSet makePSetForEgammaGenericFilter(const std::string &);
0145   edm::ParameterSet makePSetForEgammaGenericQuadraticFilter(const std::string &);
0146   edm::ParameterSet makePSetForElectronGenericFilter(const std::string &);
0147   edm::ParameterSet makePSetForEgammaDoubleEtDeltaPhiFilter(const std::string &);
0148 
0149   // set validation configuration parameters for a trigger path
0150   void SetVarsFromPSet(std::vector<edm::ParameterSet>::iterator);
0151 
0152   // generated parameter set for trigger path
0153   std::vector<edm::ParameterSet> paramSets;
0154   // input from generated parameter set
0155   unsigned int pathIndex;
0156   std::vector<edm::InputTag> theHLTCollectionLabels;
0157   unsigned int numOfHLTCollectionLabels;                // Will be size of above vector
0158   std::vector<std::string> theHLTCollectionHumanNames;  // Human-readable names for the collections
0159   edm::InputTag theL1Seed;
0160   std::vector<int> theHLTOutputTypes;
0161   std::vector<bool> plotiso;
0162   std::vector<std::vector<edm::InputTag>> isoNames;  // there has to be a better solution
0163   std::vector<std::pair<double, double>> plotBounds;
0164   std::vector<unsigned int> nCandCuts;
0165   // paramters for generator study
0166   unsigned int reqNum;
0167   int pdgGen;
0168   // plotting parameters
0169   double plotEtMin;
0170   double plotPtMin;
0171   double plotPtMax;
0172 
0173   /** collection which should be used for generator particles (MC)
0174    *  or reconstructed particles (data).
0175    *
0176    *  This collection is used for matching the HLT objects against (e.g. match
0177    * the HLT object to generated particles or reconstructed electrons/photons).
0178    */
0179   edm::InputTag gencutCollection_;
0180 
0181   /** number of generator level particles (electrons/photons) required (for MC)
0182    */
0183   unsigned int gencut_;
0184 
0185   /** which hltCollectionLabels were SEEN at least once */
0186   std::vector<std::set<std::string>> hltCollectionLabelsFoundPerPath;
0187   std::set<std::string> hltCollectionLabelsFound;
0188 
0189   /** which hltCollectionLabels were MISSED at least once */
0190   std::vector<std::set<std::string>> hltCollectionLabelsMissedPerPath;
0191   std::set<std::string> hltCollectionLabelsMissed;
0192 
0193   ////////////////////////////////////////////////////////////
0194   //          Create Histogram containers
0195   ////////////////////////////////////////////////////////////
0196   // Et & eta distributions
0197   std::vector<std::vector<MonitorElement *>> etahists;
0198   std::vector<std::vector<MonitorElement *>> phihists;
0199   std::vector<std::vector<MonitorElement *>> ethists;
0200   std::vector<std::vector<MonitorElement *>> etahistmatchs;
0201   std::vector<std::vector<MonitorElement *>> phihistmatchs;
0202   std::vector<std::vector<MonitorElement *>> ethistmatchs;
0203   std::vector<std::vector<MonitorElement *>> histEtOfHltObjMatchToGens;
0204   std::vector<std::vector<MonitorElement *>> histEtaOfHltObjMatchToGens;
0205   std::vector<std::vector<MonitorElement *>> histPhiOfHltObjMatchToGens;
0206   std::vector<std::vector<MonitorElement *>> etaphihists;
0207   std::vector<std::vector<MonitorElement *>> etaphihistmatchs;
0208   std::vector<std::vector<MonitorElement *>> histEtaPhiOfHltObjMatchToGens;
0209   // Plots of efficiency per step
0210   std::vector<MonitorElement *> totals;
0211   std::vector<MonitorElement *> totalmatchs;
0212   // generator histograms
0213   std::vector<MonitorElement *> etgens;
0214   std::vector<MonitorElement *> etagens;
0215   std::vector<MonitorElement *> phigens;
0216   std::vector<MonitorElement *> etaphigens;
0217 
0218   GreaterByPt<reco::Particle> pTComparator_;
0219   GreaterByPt<reco::GenParticle> pTGenComparator_;
0220 
0221   // tokens for data access
0222   edm::EDGetTokenT<edm::View<reco::Candidate>> genParticles_token;
0223   edm::EDGetTokenT<trigger::TriggerEventWithRefs> triggerObject_token;
0224   edm::EDGetTokenT<edm::TriggerResults> hltResults_token;
0225   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidWenu_token;
0226   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidZee_token;
0227   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidTripleEle_token;
0228   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidGammaJet_token;
0229   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidDiGamma_token;
0230   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_manualConf_token;
0231 
0232   // static variables
0233   //
0234   // trigger types considered
0235   static const unsigned TYPE_SINGLE_ELE = 0;
0236   static const unsigned TYPE_DOUBLE_ELE = 1;
0237   static const unsigned TYPE_SINGLE_PHOTON = 2;
0238   static const unsigned TYPE_DOUBLE_PHOTON = 3;
0239   static const unsigned TYPE_TRIPLE_ELE = 4;
0240 
0241   // verbosity levels
0242   static const unsigned OUTPUT_SILENT = 0;
0243   static const unsigned OUTPUT_ERRORS = 1;
0244   static const unsigned OUTPUT_WARNINGS = 2;
0245   static const unsigned OUTPUT_ALL = 3;
0246 };
0247 #endif