143 cout << __func__ <<
' ' << slice <<
" start" << endl;
147 auto tIn1 = flow1.GetInputTree(slice);
148 auto tIn2 = flow2.GetInputTree(slice);
149 auto tOut2 = flow2.GetOutputTree(output);
150 auto tOut1 = flow1.GetOutputTree(output);
157 auto isMC = metainfo1.Get<
bool>(
"flags",
"isMC");
158 auto minpt = metainfo1.Get<
float>(
"skims",
"jets",
"minpt");
159 auto R = metainfo1.Get<
int>(
"flags",
"R");
163 auto recEvent1 = flow1.GetBranchReadWrite<RecEvent>(
"recEvent");
164 auto recEvent2 = flow2.GetBranchReadOnly <RecEvent>(
"recEvent");
165 auto genEvent1 =
isMC ? flow1.GetBranchReadWrite<GenEvent>(
"genEvent") :
nullptr;
166 auto genEvent2 =
isMC ? flow2.GetBranchReadOnly <GenEvent>(
"genEvent") :
nullptr;
167 auto recJets1 = flow1.GetBranchReadWrite<vector<RecJet>>(
"recJets");
168 auto recJets2 = flow2.GetBranchReadOnly <vector<RecJet>>(
"recJets");
169 auto genJets1 =
isMC ? flow1.GetBranchReadWrite<vector<GenJet>>(
"genJets") :
nullptr;
170 auto genJets2 =
isMC ? flow2.GetBranchReadOnly <vector<GenJet>>(
"genJets") :
nullptr;
171 auto recPVs1 = flow1.GetBranchReadOnly<vector<PrimaryVertex>>(
"recPVs");
172 auto recPVs2 = flow2.GetBranchReadOnly<vector<PrimaryVertex>>(
"recPVs");
173 auto genPVs1 =
isMC ? flow1.GetBranchReadOnly<vector<PrimaryVertex>>(
"genPVs") :
nullptr;
174 auto genPVs2 =
isMC ? flow2.GetBranchReadOnly<vector<PrimaryVertex>>(
"genPVs") :
nullptr;
176 const auto strategyStr =
config.get<
string>(
"corrections.event_mixing.overlap");
181 map<Long64_t, size_t> lastUsedIndex;
183 Long64_t matchedEvents = 0;
185 for (
DT::Looper looper(tIn1); looper(); ++looper) {
189 int run1 = recEvent1->runNo;
191 if (runToEntries.find(run1) == runToEntries.end())
194 const auto& matchingEntries = runToEntries[run1];
195 size_t currentIndex = lastUsedIndex[run1];
196 if (currentIndex >= matchingEntries.size())
continue;
197 Long64_t entry2 = matchingEntries[currentIndex];
198 tIn2->GetEntry(entry2);
199 lastUsedIndex[run1] = currentIndex + 1;
202 if (recEvent1->runNo != recEvent2->runNo)
203 cerr <<
orange <<
"Run number mismatch: " << recEvent1->runNo <<
" != " << recEvent2->runNo <<
def << endl;
204 if (recPVs1->front().z != recPVs2->front().z)
205 cerr <<
orange <<
"Unmatched rec-level primary vertex: " << recPVs1->front().z <<
" != " << recPVs2->front().z <<
def << endl;
207 if (recJets1 && recJets2) {
209 recJets1->insert(recJets1->end(), recJets2->begin(), recJets2->end());
210 recEvent1->weights.front() *= recEvent2->weights.front();
212 sort(recJets1->begin(), recJets1->end(),
pt_sort);
215 case RemovalStrategy::DeltaR:
218 case RemovalStrategy::AntikT:{
220 vector<fjcore::PseudoJet> inclusive_recJets =
cluster(*recJets1, R/10.0);
225 if (nJets1 != nJets2) {
226 cout <<
"Jet multiplicity changed: " << nJets1 <<
" -> " << nJets2 << endl;
228 for (
const auto& jet : *recJets1) cout << jet.CorrPt() <<
" ";
229 cout <<
"\nAnti-kT: ";
230 for (
const auto& jet : inclusive_recJets) cout << jet.pt() <<
" ";
239 if (
isMC && genJets1 && genJets2) {
241 if (genPVs1->front().z != genPVs2->front().z)
242 BOOST_THROW_EXCEPTION(
DE::BadInput((
"Unmatched gen-level primary vertex: " + to_string(genPVs1->front().z) +
" != " + to_string(genPVs2->front().z)).c_str(), tIn1));
244 genJets1->insert(genJets1->end(), genJets2->begin(), genJets2->end());
245 genEvent1->weights.front() *= genEvent2->weights.front();
247 sort(genJets1->begin(), genJets1->end(),
pt_sort);
250 case RemovalStrategy::DeltaR:
253 case RemovalStrategy::AntikT:{
255 vector<fjcore::PseudoJet> inclusive_genJets =
cluster(*genJets1, R/10.0);
260 if (nJets1 != nJets2) {
261 cout <<
"Jet multiplicity changed: " << nJets1 <<
" -> " << nJets2 << endl;
263 for (
const auto& jet : *genJets1) cout << jet.CorrPt() <<
" ";
264 cout <<
"\nAnti-kT: ";
265 for (
const auto& jet : inclusive_genJets) cout << jet.pt() <<
" ";
275 if (steering &
DT::fill) tOut1->Fill();
279 cout <<
"Processed " << tIn1->GetEntries() <<
" events, matched " << matchedEvents <<
" events ("
280 << fixed << setprecision(2) << matchedEvents * 100.0 / min(tIn1->GetEntries(), tIn2->GetEntries()) <<
"%)." << endl;
282 metainfo1.Set<
bool>(
"git",
"complete",
true);
283 cout << __func__ <<
' ' << slice <<
" stop" << endl;