108 cout << __func__ <<
' ' << slice <<
" start" << endl;
111 auto tIn = flow.GetInputTree(
inputs, slice);
112 auto [fOut, tOut] = flow.GetOutput(output);
115 auto isMC = metainfo.Get<
bool>(
"flags",
"isMC");
116 int R = metainfo.Get<
int>(
"flags",
"R");
118 auto gEv =
isMC ? flow.GetBranchReadOnly<GenEvent>(
"genEvent") :
nullptr;
119 auto rEv = flow.GetBranchReadOnly<RecEvent>(
"recEvent");
120 auto genJets =
isMC ? flow.GetBranchReadOnly <vector<GenJet>>(
"genJets") :
nullptr;
121 auto recJets = flow.GetBranchReadWrite<vector<RecJet>>(
"recJets");
123 JMEmatching<>::maxDR = R/10./2.;
124 cout <<
"Radius for matching: " << JMEmatching<>::maxDR << endl;
126 cout <<
"Setting variations" << endl;
129 vector<PtVariation> variations { PtVariation(
"nominal") };
131 TList * ev_wgts = metainfo.List(
"variations", RecEvent::WeightVar);
132 for (TObject * obj: *ev_wgts) {
133 auto name =
dynamic_cast<TObjString*
>(obj)->GetString();
134 static int i = 0; ++i;
135 variations.push_back( PtVariation(
name, 0, 0, 0, i) );
138 TList * JECs = metainfo.List(
"variations", RecJet::ScaleVar);
139 for (TObject * obj: *JECs) {
140 auto name =
dynamic_cast<TObjString*
>(obj)->GetString();
141 static int i = 0; ++i;
142 variations.push_back( PtVariation(
name, i, 0, 0, 0) );
146 for (
DT::Looper looper(tIn); looper(); ++looper) {
150 for (
const PtVariation& v: variations) {
154 auto evWgt = rEv->weights.at(v.iRecEvtWgt);
155 if (
isMC) evWgt *= gEv->weights.at(v.iGenEvtWgt);
158 for (
const RecJet&
recjet: *recJets) {
160 if (y >=
maxy)
continue;
162 if (pt < minpt || pt >=
maxpt)
continue;
164 auto irecbin = v.rec->FindBin(
pt);
165 if (find(binIDs.begin(), binIDs.end(), irecbin) == binIDs.end()) binIDs.push_back(irecbin);
169 v.rec->Fill(
pt, evWgt * jWgt);
170 v.tmp->Fill(
pt, evWgt * jWgt);
173 for (
auto x: binIDs)
for (
auto y: binIDs) {
174 double cCov = v.cov->GetBinContent(x,y),
175 cTmp = v.tmp->GetBinContent(x)*v.tmp->GetBinContent(y);
176 v.cov->SetBinContent(x,y,cCov+cTmp);
182 JMEmatching matching(*recJets, *genJets);
183 for (
const auto& [rec_it,gen_it]: matching.match_its) {
185 auto genpt = gen_it->p4.Pt(),
186 geny = gen_it->AbsRap();
188 bool LowGenPt = genpt <
minpt,
189 HighGenPt = genpt >=
maxpt,
190 HighGenY = geny >=
maxy;
191 bool goodGen = (!LowGenPt) && (!HighGenPt) && (!HighGenY);
193 for (
const PtVariation& v: variations) {
194 auto gEvW = gEv->weights.at(v.iGenEvtWgt),
195 gJetW = gen_it->weights.at(v.iGenJetWgt);
197 if (goodGen) v.gen->Fill(genpt, gEvW * gJetW);
199 auto rEvW = rEv->weights.at(v.iRecEvtWgt),
200 rJetW = rec_it->weights.at(v.iRecJetWgt);
202 auto recpt = rec_it->CorrPt(v.iJEC),
203 recy = abs(rec_it->Rapidity());
205 bool LowRecPt = recpt <
minpt,
206 HighRecPt = recpt >=
maxpt,
207 HighRecY = recy >=
maxy;
208 bool goodRec = (!LowRecPt) && (!HighRecPt) && (!HighRecY);
210 if ( goodRec && goodGen) { v.RM->Fill(genpt, recpt, gEvW * gJetW * rEvW * rJetW );
211 v.missNoMatch->Fill(genpt, gEvW * gJetW * (1 - rEvW * rJetW) ); }
212 else if (!goodRec && goodGen) v.missOut->Fill(genpt, gEvW * gJetW );
213 else if ( goodRec && !goodGen) v.fakeOut->Fill( recpt, gEvW * gJetW * rEvW * rJetW );
218 for (
const auto& gen_it: matching.miss_its) {
219 for (
const PtVariation& v: variations) {
221 double y = gen_it->AbsRap();
222 if (y >=
maxy)
continue;
223 double pt = gen_it->p4.Pt();
224 if (pt < minpt || pt >
maxpt)
continue;
226 auto evWgt = gEv->weights.at(v.iGenEvtWgt);
227 auto jWgt = gen_it->weights.at(v.iGenJetWgt);
229 v.gen ->Fill(
pt, evWgt * jWgt);
230 v.missNoMatch->Fill(
pt, evWgt * jWgt);
234 for (
const auto& rec_it: matching.fake_its) {
235 for (
const auto& v: variations) {
237 double y = rec_it->AbsRap();
238 if (y >=
maxy)
continue;
239 double pt = rec_it->CorrPt(v.iJEC);
240 if (pt < minpt || pt >
maxpt)
continue;
242 auto evWgt = rEv->weights.at(v.iRecEvtWgt) * gEv->weights.at(v.iGenEvtWgt);
243 auto jWgt = rec_it->weights.at(v.iRecJetWgt);
245 v.fakeNoMatch->Fill(
pt, evWgt * jWgt);
251 for (PtVariation& v: variations)
254 cout << __func__ <<
' ' << slice <<
" stop" << endl;