File indexing completed on 2024-04-06 12:33:14
0001
0002
0003
0004
0005
0006
0007 #include "DQMServices/Core/interface/DQMStore.h"
0008 #include "DataFormats/Candidate/interface/Candidate.h"
0009 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0010 #include "DataFormats/Common/interface/Handle.h"
0011 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0012 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0013 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0014 #include "FWCore/Framework/interface/ESHandle.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/ServiceRegistry/interface/Service.h"
0019 #include "FWCore/Utilities/interface/EDGetToken.h"
0020 #include "FWCore/Utilities/interface/InputTag.h"
0021 #include "RecoParticleFlow/Benchmark/interface/GenericBenchmark.h"
0022
0023 #include <algorithm>
0024 #include <cmath>
0025 #include <fstream>
0026 #include <iostream>
0027 #include <map>
0028 #include <memory>
0029 #include <ostream>
0030 #include <vector>
0031
0032 class GenericBenchmarkAnalyzer : public edm::one::EDAnalyzer<>, public GenericBenchmark {
0033 public:
0034 explicit GenericBenchmarkAnalyzer(const edm::ParameterSet &);
0035 ~GenericBenchmarkAnalyzer() override;
0036
0037 void analyze(const edm::Event &, const edm::EventSetup &) override;
0038 void beginJob() override;
0039 void endJob() override;
0040
0041 private:
0042
0043 std::string outputFile_;
0044 edm::EDGetTokenT<edm::View<reco::Candidate>> myTruth_;
0045 edm::EDGetTokenT<edm::View<reco::Candidate>> myReco_;
0046 edm::InputTag inputTruthLabel_;
0047 edm::InputTag inputRecoLabel_;
0048 std::string benchmarkLabel_;
0049 bool startFromGen_;
0050 bool plotAgainstRecoQuantities_;
0051 bool onlyTwoJets_;
0052 double recPt_cut;
0053 double minEta_cut;
0054 double maxEta_cut;
0055 double deltaR_cut;
0056 float minDeltaEt_;
0057 float maxDeltaEt_;
0058 float minDeltaPhi_;
0059 float maxDeltaPhi_;
0060 bool doMetPlots_;
0061 };
0062
0063 #include "FWCore/Framework/interface/MakerMacros.h"
0064 DEFINE_FWK_MODULE(GenericBenchmarkAnalyzer);
0065
0066 using namespace reco;
0067 using namespace edm;
0068 using namespace std;
0069
0070 GenericBenchmarkAnalyzer::GenericBenchmarkAnalyzer(const edm::ParameterSet &iConfig) {
0071 inputTruthLabel_ = iConfig.getParameter<edm::InputTag>("InputTruthLabel");
0072 inputRecoLabel_ = iConfig.getParameter<edm::InputTag>("InputRecoLabel");
0073 outputFile_ = iConfig.getUntrackedParameter<std::string>("OutputFile");
0074 benchmarkLabel_ = iConfig.getParameter<std::string>("BenchmarkLabel");
0075 startFromGen_ = iConfig.getParameter<bool>("StartFromGen");
0076 plotAgainstRecoQuantities_ = iConfig.getParameter<bool>("PlotAgainstRecoQuantities");
0077 onlyTwoJets_ = iConfig.getParameter<bool>("OnlyTwoJets");
0078 recPt_cut = iConfig.getParameter<double>("recPt");
0079 minEta_cut = iConfig.getParameter<double>("minEta");
0080 maxEta_cut = iConfig.getParameter<double>("maxEta");
0081 deltaR_cut = iConfig.getParameter<double>("deltaRMax");
0082
0083 minDeltaEt_ = iConfig.getParameter<double>("minDeltaEt");
0084 maxDeltaEt_ = iConfig.getParameter<double>("maxDeltaEt");
0085 minDeltaPhi_ = iConfig.getParameter<double>("minDeltaPhi");
0086 maxDeltaPhi_ = iConfig.getParameter<double>("maxDeltaPhi");
0087 doMetPlots_ = iConfig.getParameter<bool>("doMetPlots");
0088
0089 if (!outputFile_.empty())
0090 edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str() << "'";
0091 else
0092 edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
0093
0094 myTruth_ = consumes<edm::View<reco::Candidate>>(inputTruthLabel_);
0095 myReco_ = consumes<edm::View<reco::Candidate>>(inputRecoLabel_);
0096 }
0097
0098 GenericBenchmarkAnalyzer::~GenericBenchmarkAnalyzer() {}
0099
0100 void GenericBenchmarkAnalyzer::beginJob() {
0101
0102 dbe_ = edm::Service<DQMStore>().operator->();
0103
0104 if (dbe_) {
0105
0106
0107 std::string path = "ParticleFlow/" + benchmarkLabel_ + "/";
0108 if (plotAgainstRecoQuantities_)
0109 path += "Reco";
0110 else
0111 path += "Gen";
0112 dbe_->setCurrentFolder(path);
0113 setup(dbe_, plotAgainstRecoQuantities_, minDeltaEt_, maxDeltaEt_, minDeltaPhi_, maxDeltaPhi_, doMetPlots_);
0114 }
0115 }
0116
0117 void GenericBenchmarkAnalyzer::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0118
0119 typedef edm::View<reco::Candidate> candidateCollection;
0120 typedef edm::View<reco::Candidate> candidateCollection;
0121
0122 const candidateCollection *truth_candidates;
0123 const candidateCollection *reco_candidates;
0124
0125
0126
0127
0128
0129 {
0130
0131 Handle<candidateCollection> truth_hnd;
0132 bool isGen = iEvent.getByToken(myTruth_, truth_hnd);
0133
0134 if (!isGen) {
0135 std::cout << "Warning : no Gen jets in input !" << std::endl;
0136 return;
0137 }
0138
0139 truth_candidates = truth_hnd.product();
0140
0141
0142 Handle<candidateCollection> reco_hnd;
0143 bool isReco = iEvent.getByToken(myReco_, reco_hnd);
0144 if (!isReco) {
0145 std::cout << "Warning : no Reco jets in input !" << std::endl;
0146 return;
0147 }
0148 reco_candidates = reco_hnd.product();
0149
0150
0151
0152
0153
0154
0155 }
0156 if (!truth_candidates || !reco_candidates) {
0157 edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
0158 edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
0159 return;
0160 }
0161
0162
0163
0164
0165
0166 fill(reco_candidates,
0167 truth_candidates,
0168 startFromGen_,
0169 plotAgainstRecoQuantities_,
0170 onlyTwoJets_,
0171 recPt_cut,
0172 minEta_cut,
0173 maxEta_cut,
0174 deltaR_cut);
0175 }
0176
0177 void GenericBenchmarkAnalyzer::endJob() {
0178
0179 if (!outputFile_.empty())
0180 dbe_->save(outputFile_);
0181 }