Skip to content

Commit

Permalink
Merge pull request #43304 from peteryouBuffalo/updatePFVal_13_3_X
Browse files Browse the repository at this point in the history
UPDATED: Adding of jet purity and efficiency plots to PFValidation package
  • Loading branch information
cmsbuild authored Nov 28, 2023
2 parents 53708a6 + 0adf85b commit 6b19bb3
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Validation/RecoParticleFlow/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ plots:
QCD_plots:
rm -Rf plots
python3 test/compare.py \
--sample FlatQCD_noPU:${TMPDIR}/QCD/${DQM_MC}.root:${TMPDIR}/QCD/${DQM_MC}.root \
--sample FlatQCD_noPU:${TMPDIR}/QCD/${DQM_MC}.root:${TMPDIR}/QCD/${DQM_MC}.root \
--doResponsePlots --doOffsetPlots --doMETPlots --doPFCandPlots

QCDPU_plots:
Expand Down
4 changes: 2 additions & 2 deletions Validation/RecoParticleFlow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ for lxplus with SLC8 (used for Run3 CMSSW releases)
~~~
ssh -X [email protected]
export SCRAM_ARCH=el8_amd64_gcc10
cmsrel CMSSW_12_5_0_pre3
cd CMSSW_12_5_0_pre3
cmsrel CMSSW_13_3_0_pre3
cd CMSSW_13_3_0_pre3
cmsenv
~~~

Expand Down
1 change: 1 addition & 0 deletions Validation/RecoParticleFlow/plugins/OffsetAnalyzerDQM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ void OffsetAnalyzerDQM::analyze(const edm::Event& iEvent, const edm::EventSetup&
int npv = 0;
for (unsigned int i = 0; i < nPVall; i++) {
const auto& pv = vertexHandle->at(i);
th1dPlots["pv_z"].fill(pv.z());

if (!pv.isFake() && pv.ndof() >= 4 && fabs(pv.z()) <= 24.0 && fabs(pv.position().rho()) <= 2.0) {
npv++;
Expand Down
201 changes: 199 additions & 2 deletions Validation/RecoParticleFlow/plugins/PFJetAnalyzerDQM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,17 @@ class PFJetAnalyzerDQM : public DQMEDAnalyzer {
std::vector<Plot1DInBin> jetResponsePlots;
std::vector<Plot1DInBin> jetResponsePlots_noJEC;
std::vector<Plot1DInBinVariable> genJetPlots;

std::vector<Plot1DInBinVariable> genJetPlots_matched;
std::vector<Plot1DInBinVariable> genJetPlots_unmatched;
std::vector<Plot1DInBinVariable> recoJetPlots;
std::vector<Plot1DInBinVariable> recoJetPlots_matched;
std::vector<Plot1DInBinVariable> recoJetPlots_unmatched;
// Is this data or MC?
bool isMC;

float jetDeltaR;

bool genJetsOn;
bool genJetsOn, recoJetsOn;

std::string jetCollectionName;

Expand All @@ -133,6 +137,11 @@ class PFJetAnalyzerDQM : public DQMEDAnalyzer {
void fillJetResponse(edm::View<pat::Jet>& recoJetCollection, edm::View<reco::Jet>& genJetCollection);
void prepareJetResponsePlots(const std::vector<edm::ParameterSet>& genjet_plots_pset);
void prepareGenJetPlots(const std::vector<edm::ParameterSet>& genjet_plots_pset);
void prepareGenJetMatchedPlots(const std::vector<edm::ParameterSet>& genjet_plots_pset);
void prepareGenJetUnmatchedPlots(const std::vector<edm::ParameterSet>& genjet_plots_pset);
void prepareRecoJetPlots(const std::vector<edm::ParameterSet>& recojet_plots_pset);
void prepareRecoJetMatchedPlots(const std::vector<edm::ParameterSet>& recojet_plots_pset);
void prepareRecoJetUnmatchedPlots(const std::vector<edm::ParameterSet>& recojet_plots_pset);
};

void PFJetAnalyzerDQM::prepareJetResponsePlots(const std::vector<edm::ParameterSet>& response_plots) {
Expand Down Expand Up @@ -188,6 +197,121 @@ void PFJetAnalyzerDQM::prepareGenJetPlots(const std::vector<edm::ParameterSet>&
}
}

void PFJetAnalyzerDQM::prepareGenJetMatchedPlots(const std::vector<edm::ParameterSet>& genjet_plots_pset) {
for (auto& pset : genjet_plots_pset) {
const auto name = pset.getParameter<std::string>("name") + "_matched";
const auto title = "Matched " + pset.getParameter<std::string>("title");

//Low and high edges of the eta bins for jets to pass to be filled into this histogram
const auto ptbins_d = pset.getParameter<std::vector<double>>("ptBins");
std::vector<float> ptbins(ptbins_d.begin(), ptbins_d.end());

const auto etabin_low = pset.getParameter<double>("etaBinLow");
const auto etabin_high = pset.getParameter<double>("etaBinHigh");

genJetPlots_matched.push_back(Plot1DInBinVariable(
name,
title,
std::make_unique<TH1F>(name.c_str(), title.c_str(), static_cast<int>(ptbins.size()) - 1, ptbins.data()),
0.0,
0.0,
etabin_low,
etabin_high));
}
}

void PFJetAnalyzerDQM::prepareGenJetUnmatchedPlots(const std::vector<edm::ParameterSet>& genjet_plots_pset) {
for (auto& pset : genjet_plots_pset) {
const auto name = pset.getParameter<std::string>("name") + "_unmatched";
const auto title = "Unmatched " + pset.getParameter<std::string>("title");

//Low and high edges of the eta bins for jets to pass to be filled into this histogram
const auto ptbins_d = pset.getParameter<std::vector<double>>("ptBins");
std::vector<float> ptbins(ptbins_d.begin(), ptbins_d.end());

const auto etabin_low = pset.getParameter<double>("etaBinLow");
const auto etabin_high = pset.getParameter<double>("etaBinHigh");

genJetPlots_unmatched.push_back(Plot1DInBinVariable(
name,
title,
std::make_unique<TH1F>(name.c_str(), title.c_str(), static_cast<int>(ptbins.size()) - 1, ptbins.data()),
0.0,
0.0,
etabin_low,
etabin_high));
}
}

void PFJetAnalyzerDQM::prepareRecoJetPlots(const std::vector<edm::ParameterSet>& recojet_plots_pset) {
for (auto& pset : recojet_plots_pset) {
const auto name = pset.getParameter<std::string>("name");
const auto title = pset.getParameter<std::string>("title");

//Low and high edges of the eta bins for jets to pass to be filled into this histogram
const auto ptbins_d = pset.getParameter<std::vector<double>>("ptBins");
std::vector<float> ptbins(ptbins_d.begin(), ptbins_d.end());

const auto etabin_low = pset.getParameter<double>("etaBinLow");
const auto etabin_high = pset.getParameter<double>("etaBinHigh");

recoJetPlots.push_back(Plot1DInBinVariable(
name,
title,
std::make_unique<TH1F>(name.c_str(), title.c_str(), static_cast<int>(ptbins.size()) - 1, ptbins.data()),
0.0,
0.0,
etabin_low,
etabin_high));
}
}

void PFJetAnalyzerDQM::prepareRecoJetMatchedPlots(const std::vector<edm::ParameterSet>& recojet_plots_pset) {
for (auto& pset : recojet_plots_pset) {
const auto name = pset.getParameter<std::string>("name") + "_matched";
const auto title = "Matched " + pset.getParameter<std::string>("title");

//Low and high edges of the eta bins for jets to pass to be filled into this histogram
const auto ptbins_d = pset.getParameter<std::vector<double>>("ptBins");
std::vector<float> ptbins(ptbins_d.begin(), ptbins_d.end());

const auto etabin_low = pset.getParameter<double>("etaBinLow");
const auto etabin_high = pset.getParameter<double>("etaBinHigh");

recoJetPlots_matched.push_back(Plot1DInBinVariable(
name,
title,
std::make_unique<TH1F>(name.c_str(), title.c_str(), static_cast<int>(ptbins.size()) - 1, ptbins.data()),
0.0,
0.0,
etabin_low,
etabin_high));
}
}

void PFJetAnalyzerDQM::prepareRecoJetUnmatchedPlots(const std::vector<edm::ParameterSet>& recojet_plots_pset) {
for (auto& pset : recojet_plots_pset) {
const auto name = pset.getParameter<std::string>("name") + "_unmatched";
const auto title = "Unmatched " + pset.getParameter<std::string>("title");

//Low and high edges of the eta bins for jets to pass to be filled into this histogram
const auto ptbins_d = pset.getParameter<std::vector<double>>("ptBins");
std::vector<float> ptbins(ptbins_d.begin(), ptbins_d.end());

const auto etabin_low = pset.getParameter<double>("etaBinLow");
const auto etabin_high = pset.getParameter<double>("etaBinHigh");

recoJetPlots_unmatched.push_back(Plot1DInBinVariable(
name,
title,
std::make_unique<TH1F>(name.c_str(), title.c_str(), static_cast<int>(ptbins.size()) - 1, ptbins.data()),
0.0,
0.0,
etabin_low,
etabin_high));
}
}

PFJetAnalyzerDQM::PFJetAnalyzerDQM(const edm::ParameterSet& iConfig) {
recoJetsLabel = iConfig.getParameter<edm::InputTag>("recoJetCollection");
genJetsLabel = iConfig.getParameter<edm::InputTag>("genJetCollection");
Expand All @@ -200,13 +324,21 @@ PFJetAnalyzerDQM::PFJetAnalyzerDQM(const edm::ParameterSet& iConfig) {

//for turn genJet on/off
genJetsOn = iConfig.getParameter<bool>("genJetsOn");
recoJetsOn = iConfig.getParameter<bool>("recoJetsOn");

//Create all jet response plots in bins of genjet pt and eta
const auto& response_plots = iConfig.getParameter<std::vector<edm::ParameterSet>>("responsePlots");
prepareJetResponsePlots(response_plots);

const auto& genjet_plots = iConfig.getParameter<std::vector<edm::ParameterSet>>("genJetPlots");
prepareGenJetPlots(genjet_plots);
prepareGenJetMatchedPlots(genjet_plots);
prepareGenJetUnmatchedPlots(genjet_plots);

const auto& recojet_plots = iConfig.getParameter<std::vector<edm::ParameterSet>>("recoJetPlots");
prepareRecoJetPlots(recojet_plots);
prepareRecoJetMatchedPlots(recojet_plots);
prepareRecoJetUnmatchedPlots(recojet_plots);

recoJetsToken = consumes<edm::View<pat::Jet>>(recoJetsLabel);
genJetsToken = consumes<edm::View<reco::Jet>>(genJetsLabel);
Expand All @@ -215,7 +347,37 @@ PFJetAnalyzerDQM::PFJetAnalyzerDQM(const edm::ParameterSet& iConfig) {
void PFJetAnalyzerDQM::fillJetResponse(edm::View<pat::Jet>& recoJetCollection, edm::View<reco::Jet>& genJetCollection) {
//match gen jets to reco jets, require minimum jetDeltaR, choose closest, do not try to match charge
std::vector<int> matchIndices;
std::vector<int> matchIndicesReco;
PFB::match(genJetCollection, recoJetCollection, matchIndices, false, jetDeltaR);
PFB::match(recoJetCollection, genJetCollection, matchIndicesReco, false, jetDeltaR);

//Fill recojet pt if recoJetOn
for (unsigned int i = 0; i < recoJetCollection.size(); i++) {
const auto& recoJet = recoJetCollection.at(i);
const auto pt_reco = recoJet.pt();
const auto eta_reco = abs(recoJet.eta());
const int iMatch_reco = matchIndicesReco[i];
if (recoJetsOn) {
for (auto& plot : recoJetPlots) {
if (plot.isInEtaBin(eta_reco)) {
plot.fill(pt_reco);
}
}
if (iMatch_reco != -1) {
for (auto& plot : recoJetPlots_matched) {
if (plot.isInEtaBin(eta_reco)) {
plot.fill(pt_reco);
}
}
} else {
for (auto& plot : recoJetPlots_unmatched) {
if (plot.isInEtaBin(eta_reco)) {
plot.fill(pt_reco);
}
}
}
}
}

for (unsigned int i = 0; i < genJetCollection.size(); i++) {
const auto& genJet = genJetCollection.at(i);
Expand All @@ -231,6 +393,21 @@ void PFJetAnalyzerDQM::fillJetResponse(edm::View<pat::Jet>& recoJetCollection, e
}
}
}
if (recoJetsOn) {
if (iMatch != -1) {
for (auto& plot : genJetPlots_matched) {
if (plot.isInEtaBin(eta_gen)) {
plot.fill(pt_gen);
}
}
} else {
for (auto& plot : genJetPlots_unmatched) {
if (plot.isInEtaBin(eta_gen)) {
plot.fill(pt_gen);
}
}
}
}

//If gen jet had a matched reco jet
if (iMatch != -1) {
Expand Down Expand Up @@ -269,6 +446,26 @@ void PFJetAnalyzerDQM::bookHistograms(DQMStore::IBooker& booker, edm::Run const&
plot.book(booker);
}

if (recoJetsOn) {
booker.setCurrentFolder("ParticleFlow/JetResponse/" + jetCollectionName + "/noJEC/");
for (auto& plot : genJetPlots_matched) {
plot.book(booker);
}
for (auto& plot : genJetPlots_unmatched) {
plot.book(booker);
}
booker.setCurrentFolder("ParticleFlow/JetResponse/" + jetCollectionName + "/JEC/");
for (auto& plot : recoJetPlots) {
plot.book(booker);
}
for (auto& plot : recoJetPlots_matched) {
plot.book(booker);
}
for (auto& plot : recoJetPlots_unmatched) {
plot.book(booker);
}
}

//Book plots for gen-jet pt spectra
if (genJetsOn) {
booker.setCurrentFolder("ParticleFlow/GenJets/");
Expand Down
Loading

0 comments on commit 6b19bb3

Please sign in to comment.