Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-11 04:33:06

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   // global parameters
0096   edm::InputTag triggerObject_;
0097   unsigned int verbosity_;
0098   double genEtaAcc_;
0099   double genEtAcc_;
0100   bool isData_;
0101   double ptMax_;
0102   double ptMin_;
0103   double etaMax_;
0104   double phiMax_;
0105   unsigned int nbins_;
0106   double eta2DMax_;
0107   double phi2DMax_;
0108   unsigned int nbins2D_;
0109   unsigned int minEtForEtaEffPlot_;
0110   bool useHumanReadableHistTitles_;
0111   bool mcMatchedOnly_;
0112   bool noPhiPlots_;
0113   bool noIsolationPlots_;
0114 
0115   /** helper to check whether there were enough generator level
0116    *  electrons/photons (MC) or enough reco level electrons/photons
0117    *  to analyze this event.
0118    *
0119    *  @return if the event has enough of these candidates.
0120    */
0121   bool checkGeneratedParticlesRequirement(const edm::Event &event);
0122 
0123   /** similar to checkGeneratedParticlesRequirement(..) but for reconstructed
0124    *  particles. For the moment, there are some additional requirements in
0125    *  the MC version so we can't use the same code for both cases.
0126    */
0127   bool checkRecoParticlesRequirement(const edm::Event &event);
0128 
0129   /// The instance of the HLTConfigProvider as a data member
0130   HLTConfigProvider hltConfig_;
0131 
0132   // routines to build validation configuration from HLTConfiguration
0133   int countSubstring(const std::string &, const std::string &);
0134   std::vector<std::vector<std::string>> findEgammaPaths();
0135   std::vector<std::string> getFilterModules(const std::string &);
0136   double getPrimaryEtCut(const std::string &);
0137   edm::ParameterSet makePSetForL1SeedFilter(const std::string &);
0138   edm::ParameterSet makePSetForL1SeedToSuperClusterMatchFilter(const std::string &);
0139   edm::ParameterSet makePSetForEtFilter(const std::string &);
0140   edm::ParameterSet makePSetForOneOEMinusOneOPFilter(const std::string &);
0141   edm::ParameterSet makePSetForPixelMatchFilter(const std::string &);
0142   edm::ParameterSet makePSetForEgammaGenericFilter(const std::string &);
0143   edm::ParameterSet makePSetForEgammaGenericQuadraticFilter(const std::string &);
0144   edm::ParameterSet makePSetForElectronGenericFilter(const std::string &);
0145   edm::ParameterSet makePSetForEgammaDoubleEtDeltaPhiFilter(const std::string &);
0146 
0147   // set validation configuration parameters for a trigger path
0148   void SetVarsFromPSet(std::vector<edm::ParameterSet>::iterator);
0149 
0150   // generated parameter set for trigger path
0151   std::vector<edm::ParameterSet> paramSets;
0152   // input from generated parameter set
0153   unsigned int pathIndex;
0154   std::vector<edm::InputTag> theHLTCollectionLabels;
0155   unsigned int numOfHLTCollectionLabels;                // Will be size of above vector
0156   std::vector<std::string> theHLTCollectionHumanNames;  // Human-readable names for the collections
0157   edm::InputTag theL1Seed;
0158   std::vector<int> theHLTOutputTypes;
0159   std::vector<bool> plotiso;
0160   std::vector<std::vector<edm::InputTag>> isoNames;  // there has to be a better solution
0161   std::vector<std::pair<double, double>> plotBounds;
0162   std::vector<unsigned int> nCandCuts;
0163   // paramters for generator study
0164   unsigned int reqNum;
0165   int pdgGen;
0166   // plotting parameters
0167   double plotEtMin;
0168   double plotPtMin;
0169   double plotPtMax;
0170 
0171   /** collection which should be used for generator particles (MC)
0172    *  or reconstructed particles (data).
0173    *
0174    *  This collection is used for matching the HLT objects against (e.g. match
0175    * the HLT object to generated particles or reconstructed electrons/photons).
0176    */
0177   edm::InputTag gencutCollection_;
0178 
0179   /** number of generator level particles (electrons/photons) required (for MC)
0180    */
0181   unsigned int gencut_;
0182 
0183   /** which hltCollectionLabels were SEEN at least once */
0184   std::vector<std::set<std::string>> hltCollectionLabelsFoundPerPath;
0185   std::set<std::string> hltCollectionLabelsFound;
0186 
0187   /** which hltCollectionLabels were MISSED at least once */
0188   std::vector<std::set<std::string>> hltCollectionLabelsMissedPerPath;
0189   std::set<std::string> hltCollectionLabelsMissed;
0190 
0191   ////////////////////////////////////////////////////////////
0192   //          Create Histogram containers
0193   ////////////////////////////////////////////////////////////
0194   // Et & eta distributions
0195   std::vector<std::vector<MonitorElement *>> etahists;
0196   std::vector<std::vector<MonitorElement *>> phihists;
0197   std::vector<std::vector<MonitorElement *>> ethists;
0198   std::vector<std::vector<MonitorElement *>> etahistmatchs;
0199   std::vector<std::vector<MonitorElement *>> phihistmatchs;
0200   std::vector<std::vector<MonitorElement *>> ethistmatchs;
0201   std::vector<std::vector<MonitorElement *>> histEtOfHltObjMatchToGens;
0202   std::vector<std::vector<MonitorElement *>> histEtaOfHltObjMatchToGens;
0203   std::vector<std::vector<MonitorElement *>> histPhiOfHltObjMatchToGens;
0204   std::vector<std::vector<MonitorElement *>> etaphihists;
0205   std::vector<std::vector<MonitorElement *>> etaphihistmatchs;
0206   std::vector<std::vector<MonitorElement *>> histEtaPhiOfHltObjMatchToGens;
0207   // Plots of efficiency per step
0208   std::vector<MonitorElement *> totals;
0209   std::vector<MonitorElement *> totalmatchs;
0210   // generator histograms
0211   std::vector<MonitorElement *> etgens;
0212   std::vector<MonitorElement *> etagens;
0213   std::vector<MonitorElement *> phigens;
0214   std::vector<MonitorElement *> etaphigens;
0215 
0216   GreaterByPt<reco::Particle> pTComparator_;
0217   GreaterByPt<reco::GenParticle> pTGenComparator_;
0218 
0219   // tokens for data access
0220   edm::EDGetTokenT<edm::View<reco::Candidate>> genParticles_token;
0221   edm::EDGetTokenT<trigger::TriggerEventWithRefs> triggerObject_token;
0222   edm::EDGetTokenT<edm::TriggerResults> hltResults_token;
0223   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidWenu_token;
0224   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidZee_token;
0225   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidTripleEle_token;
0226   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidGammaJet_token;
0227   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_fidDiGamma_token;
0228   edm::EDGetTokenT<edm::View<reco::Candidate>> gencutColl_manualConf_token;
0229 
0230   // static variables
0231   //
0232   // trigger types considered
0233   static const unsigned TYPE_SINGLE_ELE = 0;
0234   static const unsigned TYPE_DOUBLE_ELE = 1;
0235   static const unsigned TYPE_SINGLE_PHOTON = 2;
0236   static const unsigned TYPE_DOUBLE_PHOTON = 3;
0237   static const unsigned TYPE_TRIPLE_ELE = 4;
0238 
0239   // verbosity levels
0240   static const unsigned OUTPUT_SILENT = 0;
0241   static const unsigned OUTPUT_ERRORS = 1;
0242   static const unsigned OUTPUT_WARNINGS = 2;
0243   static const unsigned OUTPUT_ALL = 3;
0244 };
0245 #endif