Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:15

0001 // system include files
0002 #include <memory>
0003 
0004 // user include files
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 
0015 #include "RecoParticleFlow/Benchmark/interface/PFTauElecRejectionBenchmark.h"
0016 
0017 using namespace edm;
0018 using namespace reco;
0019 using namespace std;
0020 
0021 //
0022 // class declaration
0023 
0024 class PFTauElecRejectionBenchmarkAnalyzer : public edm::one::EDAnalyzer<> {
0025 public:
0026   typedef dqm::legacy::DQMStore DQMStore;
0027   typedef dqm::legacy::MonitorElement MonitorElement;
0028 
0029   explicit PFTauElecRejectionBenchmarkAnalyzer(const edm::ParameterSet &);
0030   ~PFTauElecRejectionBenchmarkAnalyzer() override;
0031 
0032 private:
0033   void beginJob() override;
0034   void analyze(const edm::Event &, const edm::EventSetup &) override;
0035   void endJob() override;
0036   // ----------member data ---------------------------
0037 
0038   string outputfile;
0039   DQMStore *db;
0040   string benchmarkLabel;
0041   double maxDeltaR;
0042   double minMCPt;
0043   double maxMCAbsEta;
0044   double minRecoPt;
0045   double maxRecoAbsEta;
0046   bool applyEcalCrackCut;
0047   string sGenMatchObjectLabel;
0048 
0049   edm::EDGetTokenT<edm::HepMCProduct> sGenParticleSource_tok_;
0050   edm::EDGetTokenT<reco::PFTauCollection> pfTauProducer_tok_;
0051   edm::EDGetTokenT<reco::PFTauDiscriminator> pfTauDiscriminatorByIsolationProducer_tok_;
0052   edm::EDGetTokenT<reco::PFTauDiscriminator> pfTauDiscriminatorAgainstElectronProducer_tok_;
0053 
0054   PFTauElecRejectionBenchmark PFTauElecRejectionBenchmark_;
0055 };
0056 /// PFTauElecRejection Benchmark
0057 
0058 //
0059 // constants, enums and typedefs
0060 //
0061 
0062 //
0063 // static data member definitions
0064 //
0065 
0066 //
0067 // constructors and destructor
0068 //
0069 PFTauElecRejectionBenchmarkAnalyzer::PFTauElecRejectionBenchmarkAnalyzer(const edm::ParameterSet &iConfig)
0070 
0071 {
0072   // now do what ever initialization is needed
0073   outputfile = iConfig.getUntrackedParameter<string>("OutputFile");
0074   benchmarkLabel = iConfig.getParameter<string>("BenchmarkLabel");
0075   sGenParticleSource_tok_ = consumes<edm::HepMCProduct>(iConfig.getParameter<InputTag>("InputTruthLabel"));
0076   maxDeltaR = iConfig.getParameter<double>("maxDeltaR");
0077   minMCPt = iConfig.getParameter<double>("minMCPt");
0078   maxMCAbsEta = iConfig.getParameter<double>("maxMCAbsEta");
0079   minRecoPt = iConfig.getParameter<double>("minRecoPt");
0080   maxRecoAbsEta = iConfig.getParameter<double>("maxRecoAbsEta");
0081   pfTauProducer_tok_ = consumes<reco::PFTauCollection>(iConfig.getParameter<InputTag>("PFTauProducer"));
0082   pfTauDiscriminatorByIsolationProducer_tok_ =
0083       consumes<reco::PFTauDiscriminator>(iConfig.getParameter<InputTag>("PFTauDiscriminatorByIsolationProducer"));
0084   pfTauDiscriminatorAgainstElectronProducer_tok_ =
0085       consumes<reco::PFTauDiscriminator>(iConfig.getParameter<InputTag>("PFTauDiscriminatorAgainstElectronProducer"));
0086   sGenMatchObjectLabel = iConfig.getParameter<string>("GenMatchObjectLabel");
0087   applyEcalCrackCut = iConfig.getParameter<bool>("ApplyEcalCrackCut");
0088 
0089   db = edm::Service<DQMStore>().operator->();
0090 
0091   PFTauElecRejectionBenchmark_.setup(outputfile,
0092                                      benchmarkLabel,
0093                                      maxDeltaR,
0094                                      minRecoPt,
0095                                      maxRecoAbsEta,
0096                                      minMCPt,
0097                                      maxMCAbsEta,
0098                                      sGenMatchObjectLabel,
0099                                      applyEcalCrackCut,
0100                                      db);
0101 }
0102 
0103 PFTauElecRejectionBenchmarkAnalyzer::~PFTauElecRejectionBenchmarkAnalyzer() {
0104   // do anything here that needs to be done at desctruction time
0105   // (e.g. close files, deallocate resources etc.)
0106 }
0107 
0108 //
0109 // member functions
0110 //
0111 
0112 // ------------ method called to for each event  ------------
0113 void PFTauElecRejectionBenchmarkAnalyzer::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0114   // get gen products
0115   Handle<HepMCProduct> mcevt;
0116   iEvent.getByToken(sGenParticleSource_tok_, mcevt);
0117 
0118   // get pftau collection
0119   Handle<PFTauCollection> thePFTau;
0120   iEvent.getByToken(pfTauProducer_tok_, thePFTau);
0121 
0122   // get iso discriminator association vector
0123   Handle<PFTauDiscriminator> thePFTauDiscriminatorByIsolation;
0124   iEvent.getByToken(pfTauDiscriminatorByIsolationProducer_tok_, thePFTauDiscriminatorByIsolation);
0125 
0126   // get anti-elec discriminator association vector
0127   Handle<PFTauDiscriminator> thePFTauDiscriminatorAgainstElectron;
0128   iEvent.getByToken(pfTauDiscriminatorAgainstElectronProducer_tok_, thePFTauDiscriminatorAgainstElectron);
0129 
0130   PFTauElecRejectionBenchmark_.process(
0131       mcevt, thePFTau, thePFTauDiscriminatorByIsolation, thePFTauDiscriminatorAgainstElectron);
0132 }
0133 
0134 // ------------ method called once each job just before starting event loop
0135 // ------------
0136 void PFTauElecRejectionBenchmarkAnalyzer::beginJob() {}
0137 
0138 // ------------ method called once each job just after ending the event loop
0139 // ------------
0140 void PFTauElecRejectionBenchmarkAnalyzer::endJob() { PFTauElecRejectionBenchmark_.write(); }
0141 
0142 // define this as a plug-in
0143 DEFINE_FWK_MODULE(PFTauElecRejectionBenchmarkAnalyzer);