Remove PU staub (i.e. high-weight events due to PU sampling)
75 cout << __func__ <<
' ' << slice <<
" start" << endl;
78 auto tIn = flow.GetInputTree(
inputs, slice);
79 auto [fOut, tOut] = flow.GetOutput(output);
83 auto isMC = metainfo.Get<
bool>(
"flags",
"isMC");
84 if (!
isMC) BOOST_THROW_EXCEPTION(
DE::BadInput(
"Only MC may be used as input.",
85 make_unique<TFile>(
inputs.front().c_str() )) );
86 auto R = metainfo.Get<
int>(
"flags",
"R");
87 const auto maxDR = R/10.;
89 auto fMBmaxgenpt =
config.get<fs::path>(
"corrections.PUcleaning.MBmaxgenpt");
91 metainfo.Set<fs::path>(
"corrections",
"PUcleaning",
"MBmaxgenpt", fMBmaxgenpt);
94 auto genEvt = flow.GetBranchReadOnly<GenEvent>(
"genEvent");
95 auto recEvt = flow.GetBranchReadWrite<RecEvent>(
"recEvent");
96 auto pileup = flow.GetBranchReadWrite<PileUp>(
"pileup");
97 auto genJets = flow.GetBranchReadOnly <vector<GenJet>>(
"genJets");
98 auto recJets = flow.GetBranchReadWrite<vector<RecJet>>(
"recJets");
100 auto pt_logw = make_unique<TH2F>(
"pt_logw",
";Jet p_{T}^{rec} [GeV];log(w);N_{eff}^{j}",
nPtBins,
pt_edges.data(), 400, -30, 20),
101 mjj_logw = make_unique<TH2F>(
"mjj_logw",
";m_{jj}^{rec} [GeV];log(w);N_{eff}^{jj}",
nMjjBins,
Mjj_edges.data(), 400, -30, 20);
104 ControlPlots raw(
"raw"),
106 corrected(
"corrected");
108 Plots PUbefore(
"PUbefore"),
110 PUgenveto(
"PUgenveto");
112 for (
DT::Looper looper(tIn); looper(); ++looper) {
116 raw(*genJets, genEvt->weights.front());
117 raw(*recJets, genEvt->weights.front() * recEvt->weights.front());
118 PUbefore(*genJets, *recJets, *genEvt, *recEvt, *
pileup);
122 const float maxpthatPU = pthats_it !=
pileup->
pthats.end() ? *pthats_it : 0.;
123 bool bad_rec = (maxpthatPU > genEvt->hard_scale);
130 auto it = maxgenpts.find(evtID);
131 if (it == maxgenpts.end())
continue;
132 bad_rec |= it->second > genJets->front().p4.Pt();
133 cout << recEvt->evtNo <<
' ' << evtID <<
' ' << it->second << endl;
138 if (recJets->size() > 0) {
139 const auto&
recjet = recJets->begin();
140 bool matched =
false;
141 for (
const auto&
genjet: *genJets)
143 float maxgenpt = genJets->size() > 0 ? genJets->front().p4.Pt()
144 : genEvt->hard_scale;
145 static const float m = 156;
146 if (
recjet->
p4.Pt() > max(2*maxgenpt, m))
153 recEvt->weights *= 0;
154 genveto(*genJets, genEvt->weights.front());
155 genveto(*recJets, genEvt->weights.front() * recEvt->weights.front());
156 PUgenveto(*genJets, *recJets, *genEvt, *recEvt, *
pileup);
161 corrected(*genJets, genEvt->weights.front());
162 corrected(*recJets, genEvt->weights.front() * recEvt->weights.front());
163 PUafter(*genJets, *recJets, *genEvt, *recEvt, *
pileup);
165 if (steering &
DT::fill) tOut->Fill();
168 metainfo.Set<
bool>(
"git",
"complete",
true);
172 corrected.Write(fOut);
173 PUbefore.Write(fOut);
174 PUgenveto.Write(fOut);
177 cout << __func__ <<
' ' << slice <<
" stop" << endl;