110 cout << __func__ <<
' ' << slice <<
" start" << endl;
113 auto tIn = flow.GetInputTree(slice);
114 auto [fOut, tOut] = flow.GetOutput(output);
117 auto isMC = metainfo.Get<
bool>(
"flags",
"isMC");
118 int R = metainfo.Get<
int>(
"flags",
"R");
120 auto gEv =
isMC ? flow.GetBranchReadOnly<GenEvent>(
"genEvent") :
nullptr;
121 auto rEv = flow.GetBranchReadOnly<RecEvent>(
"recEvent");
122 auto genJets =
isMC ? flow.GetBranchReadOnly <vector<GenJet>>(
"genJets") :
nullptr;
123 auto recJets = flow.GetBranchReadWrite<vector<RecJet>>(
"recJets");
125 JMEmatching<>::maxDR = R/10./2.;
126 cout <<
"Radius for matching: " << JMEmatching<>::maxDR << endl;
128 cout <<
"Setting variations" << endl;
131 vector<PtVariation> variations { PtVariation(
"nominal") };
134 auto push = [&variations](
auto...
args) {
135 variations.emplace_back(
args...);
138 auto getvars = [&push,&metainfo](
const char * category,
auto indices) {
139 TList * ev_wgts = metainfo.List(
"variations", category);
140 for (TObject * obj: *ev_wgts) {
141 auto param =
dynamic_cast<TParameter<int>*
>(obj);
142 const int val = param->GetVal();
145 for (
int j = 0; j < val; ++j, ++i) {
146 TString varname = param->GetName();
147 if (val > 1) varname += j;
148 apply(push, indices(varname, i));
153 getvars(GenEvent::WeightVar, [](
const char * v,
int i) {
return make_tuple(v, 0 , 0 , 0 , i , 0); });
154 getvars(RecEvent::WeightVar, [](
const char * v,
int i) {
return make_tuple(v, 0 , 0 , 0 , 0 , i); });
155 getvars(RecJet :: ScaleVar, [](
const char * v,
int i) {
return make_tuple(v, i , 0 , 0 , 0 , 0); });
158 for (
DT::Looper looper(tIn); looper(); ++looper) {
162 for (
const PtVariation& v: variations) {
166 auto evWgt = rEv->weights.at(v.iRecEvtWgt);
167 if (
isMC) evWgt *= gEv->weights.at(v.iGenEvtWgt);
170 for (
const RecJet&
recjet: *recJets) {
172 if (y >=
maxy)
continue;
174 if (pt < minpt || pt >=
maxpt)
continue;
176 auto irecbin = v.rec->FindBin(
pt);
177 if (find(binIDs.begin(), binIDs.end(), irecbin) == binIDs.end()) binIDs.push_back(irecbin);
181 v.rec->Fill(
pt, evWgt * jWgt);
182 v.tmp->Fill(
pt, evWgt * jWgt);
185 for (
auto x: binIDs)
for (
auto y: binIDs) {
186 double cCov = v.cov->GetBinContent(x,y),
187 cTmp = v.tmp->GetBinContent(x)*v.tmp->GetBinContent(y);
188 v.cov->SetBinContent(x,y,cCov+cTmp);
194 JMEmatching matching(*recJets, *genJets);
195 for (
const auto& [rec_it,gen_it]: matching.match_its) {
197 auto genpt = gen_it->p4.Pt(),
198 geny = gen_it->AbsRap();
200 bool LowGenPt = genpt <
minpt,
201 HighGenPt = genpt >=
maxpt,
202 HighGenY = geny >=
maxy;
203 bool goodGen = (!LowGenPt) && (!HighGenPt) && (!HighGenY);
205 for (
const PtVariation& v: variations) {
206 auto gEvW = gEv->weights.at(v.iGenEvtWgt),
207 gJetW = gen_it->weights.at(v.iGenJetWgt);
209 if (goodGen) v.gen->Fill(genpt, gEvW * gJetW);
211 auto rEvW = rEv->weights.at(v.iRecEvtWgt),
212 rJetW = rec_it->weights.at(v.iRecJetWgt);
214 auto recpt = rec_it->CorrPt(v.iJEC),
215 recy = abs(rec_it->Rapidity());
217 bool LowRecPt = recpt <
minpt,
218 HighRecPt = recpt >=
maxpt,
219 HighRecY = recy >=
maxy;
220 bool goodRec = (!LowRecPt) && (!HighRecPt) && (!HighRecY);
222 if ( goodRec && goodGen) { v.RM->Fill(genpt, recpt, gEvW * gJetW * rEvW * rJetW );
223 v.missNoMatch->Fill(genpt, gEvW * gJetW * (1 - rEvW * rJetW) ); }
224 else if (!goodRec && goodGen) v.missOut->Fill(genpt, gEvW * gJetW );
225 else if ( goodRec && !goodGen) v.fakeOut->Fill( recpt, gEvW * gJetW * rEvW * rJetW );
230 for (
const auto& gen_it: matching.miss_its) {
231 for (
const PtVariation& v: variations) {
233 double y = gen_it->AbsRap();
234 if (y >=
maxy)
continue;
235 double pt = gen_it->p4.Pt();
236 if (pt < minpt || pt >
maxpt)
continue;
238 auto evWgt = gEv->weights.at(v.iGenEvtWgt);
239 auto jWgt = gen_it->weights.at(v.iGenJetWgt);
241 v.gen ->Fill(
pt, evWgt * jWgt);
242 v.missNoMatch->Fill(
pt, evWgt * jWgt);
246 for (
const auto& rec_it: matching.fake_its) {
247 for (
const auto& v: variations) {
249 double y = rec_it->AbsRap();
250 if (y >=
maxy)
continue;
251 double pt = rec_it->CorrPt(v.iJEC);
252 if (pt < minpt || pt >
maxpt)
continue;
254 auto evWgt = rEv->weights.at(v.iRecEvtWgt) * gEv->weights.at(v.iGenEvtWgt);
255 auto jWgt = rec_it->weights.at(v.iRecJetWgt);
257 v.fakeNoMatch->Fill(
pt, evWgt * jWgt);
263 for (PtVariation& v: variations)
266 cout << __func__ <<
' ' << slice <<
" stop" << endl;