4 #include <cp3_llbb/Framework/interface/CandidatesProducer.h>
5 #include <cp3_llbb/Framework/interface/BTaggingScaleFactors.h>
7 #include <DataFormats/PatCandidates/interface/Jet.h>
8 #include "TMVA/Reader.h"
13 JetsProducer(
const std::string& name,
const ROOT::TreeGroup&
tree,
const edm::ParameterSet& config):
16 BTaggingScaleFactors::create_branches(config);
18 if (config.exists(
"btags")) {
19 const std::vector<std::string>& btags = config.getUntrackedParameter<std::vector<std::string>>(
"btags");
22 for (
const std::string& btag: btags) {
23 std::string branchName{btag};
24 std::replace(std::begin(branchName), std::end(branchName),
':',
'_');
28 if (config.exists(
"computeRegression")) {
29 computeRegression = config.getUntrackedParameter<
bool>(
"computeRegression");
30 if (computeRegression)
32 regressionFile = config.getUntrackedParameter<edm::FileInPath>(
"regressionFile").fullPath();
33 std::cout <<
" -> storing bjet energy regression, with xml file " << regressionFile << std::endl;
34 bjetRegressionReader.reset(
new TMVA::Reader());
35 bjetRegressionReader->AddVariable(
"Jet_pt", &Jet_pt);
36 bjetRegressionReader->AddVariable(
"nPVs", &nPVs);
37 bjetRegressionReader->AddVariable(
"Jet_eta", &Jet_eta);
38 bjetRegressionReader->AddVariable(
"Jet_mt", &Jet_mt);
39 bjetRegressionReader->AddVariable(
"Jet_leadTrackPt", &Jet_leadTrackPt);
40 bjetRegressionReader->AddVariable(
"Jet_leptonPtRel", &Jet_leptonPtRel);
41 bjetRegressionReader->AddVariable(
"Jet_leptonPt", &Jet_leptonPt);
42 bjetRegressionReader->AddVariable(
"Jet_leptonDeltaR", &Jet_leptonDeltaR);
43 bjetRegressionReader->AddVariable(
"Jet_neHEF", &Jet_neHEF);
44 bjetRegressionReader->AddVariable(
"Jet_neEmEF", &Jet_neEmEF);
45 bjetRegressionReader->AddVariable(
"Jet_vtxPt", &Jet_vtxPt);
46 bjetRegressionReader->AddVariable(
"Jet_vtxMass", &Jet_vtxMass);
47 bjetRegressionReader->AddVariable(
"Jet_vtx3dL", &Jet_vtx3dL);
48 bjetRegressionReader->AddVariable(
"Jet_vtxNtrk", &Jet_vtxNtrk);
49 bjetRegressionReader->AddVariable(
"Jet_vtx3deL", &Jet_vtx3deL);
50 bjetRegressionReader->BookMVA(
"BDT::BDTG", regressionFile.c_str());
53 computeRegression =
false;
59 virtual void doConsumes(
const edm::ParameterSet& config, edm::ConsumesCollector&& collector)
override {
60 m_jets_token = collector.consumes<std::vector<pat::Jet>>(config.getUntrackedParameter<edm::InputTag>(
"jets", edm::InputTag(
"slimmedJets")));
61 m_vertices_token = collector.consumes<std::vector<reco::Vertex>>(config.getUntrackedParameter<edm::InputTag>(
"vertices", edm::InputTag(
"offlineSlimmedPrimaryVertices")));
64 virtual void produce(edm::Event& event,
const edm::EventSetup& eventSetup)
override;
67 float getBTagDiscriminant(
size_t index,
const std::string& name)
const {
68 return m_btag_discriminators.at(name)->at(index);
71 float get_scale_factor(Algorithm algo,
const std::string& wp,
size_t index, Variation variation = Variation::Nominal);
76 edm::EDGetTokenT<std::vector<pat::Jet>> m_jets_token;
77 edm::EDGetTokenT<std::vector<reco::Vertex>> m_vertices_token;
79 std::map<std::string, std::vector<float>*> m_btag_discriminators;
81 bool computeRegression;
82 std::string regressionFile;
83 std::unique_ptr<TMVA::Reader> bjetRegressionReader;
88 float Jet_leadTrackPt;
89 float Jet_leptonPtRel;
91 float Jet_leptonDeltaR;
101 std::vector<float>& area =
tree[
"area"].write<std::vector<float>>();
102 std::vector<int8_t>& partonFlavor =
tree[
"partonFlavor"].write<std::vector<int8_t>>();
103 std::vector<int8_t>& hadronFlavor =
tree[
"hadronFlavor"].write<std::vector<int8_t>>();
106 std::vector<int8_t>& systFlavor =
tree[
"systFlavor"].write<std::vector<int8_t>>();
108 std::vector<float>& jecFactor =
tree[
"jecFactor"].write<std::vector<float>>();
109 std::vector<float>& puJetID =
tree[
"puJetID"].write<std::vector<float>>();
111 TRANSIENT_BRANCH(neutralHadronEnergyFraction, std::vector<float>);
112 TRANSIENT_BRANCH(neutralEmEnergyFraction, std::vector<float>);
113 TRANSIENT_BRANCH(vtxMass, std::vector<float>);
114 TRANSIENT_BRANCH(vtx3DVal, std::vector<float>);
115 TRANSIENT_BRANCH(vtx3DSig, std::vector<float>);
116 TRANSIENT_BRANCH(vtxPt, std::vector<float>);
117 TRANSIENT_BRANCH(vtxNtracks, std::vector<float>);
118 TRANSIENT_BRANCH(leptonPtRel, std::vector<float>);
119 TRANSIENT_BRANCH(leptonPt, std::vector<float>);
120 TRANSIENT_BRANCH(leptonDeltaR, std::vector<float>);
121 TRANSIENT_BRANCH(leadTrackPt, std::vector<float>);
122 BRANCH(regPt, std::vector<float>);
124 BRANCH(passLooseID, std::vector<bool>);
125 BRANCH(passTightID, std::vector<bool>);
126 BRANCH(passTightLeptonVetoID, std::vector<bool>);
Definition: BTaggingScaleFactors.h:36
Definition: CandidatesProducer.h:9
ROOT::TreeGroup tree
Access point to output tree.
Definition: Producer.h:132
Definition: JetsProducer.h:11
virtual void doConsumes(const edm::ParameterSet &config, edm::ConsumesCollector &&collector) override
Hook for the CMSSW consumes interface.
Definition: JetsProducer.h:59
virtual void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
Main method of the producer, called for each event.
Definition: JetsProducer.cc:5