17 processSubsetSave.init(
"(eventProcess)", particleDataPtr);
18 workEventJetSave.init(
"(workEventJet)", particleDataPtr);
21 bool setMad = settingsPtr->flag(
"JetMatching:setMad");
26 string parStr = infoPtr->header(
"MGRunCard");
27 if (!parStr.empty()) {
34 if (par.haveParam(
"xqcut") && par.haveParam(
"maxjetflavor") && par.haveParam(
"alpsfact") &&
35 par.haveParam(
"ickkw")) {
36 settingsPtr->flag(
"JetMatching:merge", par.getParam(
"ickkw"));
37 settingsPtr->parm(
"JetMatching:qCut", par.getParam(
"xqcut"));
38 settingsPtr->mode(
"JetMatching:nQmatch", par.getParamAsInt(
"maxjetflavor"));
39 settingsPtr->parm(
"JetMatching:clFact", clFact = par.getParam(
"alpsfact"));
40 if (par.getParamAsInt(
"ickkw") == 0)
42 "Error in JetMatchingMadgraph:init: " 43 "Madgraph file parameters are not set for merging");
48 "Warning in JetMatchingMadgraph:init: " 49 "Madgraph merging parameters not found");
50 if (!par.haveParam(
"xqcut"))
53 "JetMatchingMadgraph:init: No xqcut");
54 if (!par.haveParam(
"ickkw"))
57 "JetMatchingMadgraph:init: No ickkw");
58 if (!par.haveParam(
"maxjetflavor"))
61 "JetMatchingMadgraph:init: No maxjetflavor");
62 if (!par.haveParam(
"alpsfact"))
65 "JetMatchingMadgraph:init: No alpsfact");
70 doFxFx = settingsPtr->flag(
"JetMatching:doFxFx");
71 nPartonsNow = settingsPtr->mode(
"JetMatching:nPartonsNow");
72 qCutME = settingsPtr->parm(
"JetMatching:qCutME");
73 qCutMESq =
pow(qCutME, 2);
76 doMerge = settingsPtr->flag(
"JetMatching:merge");
77 doShowerKt = settingsPtr->flag(
"JetMatching:doShowerKt");
78 qCut = settingsPtr->parm(
"JetMatching:qCut");
79 nQmatch = settingsPtr->mode(
"JetMatching:nQmatch");
80 clFact = settingsPtr->parm(
"JetMatching:clFact");
83 jetAlgorithm = settingsPtr->mode(
"JetMatching:jetAlgorithm");
84 nJetMax = settingsPtr->mode(
"JetMatching:nJetMax");
85 eTjetMin = settingsPtr->parm(
"JetMatching:eTjetMin");
86 coneRadius = settingsPtr->parm(
"JetMatching:coneRadius");
87 etaJetMax = settingsPtr->parm(
"JetMatching:etaJetMax");
88 slowJetPower = settingsPtr->mode(
"JetMatching:slowJetPower");
91 jetAllow = settingsPtr->mode(
"JetMatching:jetAllow");
92 exclusiveMode = settingsPtr->mode(
"JetMatching:exclusive");
93 qCutSq =
pow(qCut, 2);
94 etaJetMaxAlgo = etaJetMax;
102 if (exclusiveMode == 2) {
106 "Warning in JetMatchingMadgraph:init: " 107 "missing jet multiplicity information; running in exclusive mode");
117 slowJet =
new SlowJet(slowJetPower, coneRadius, eTjetMin, etaJetMaxAlgo, 2, 2,
nullptr,
false);
120 slowJetHard =
new SlowJet(slowJetPower, coneRadius, qCutME, etaJetMaxAlgo, 2, 2,
nullptr,
false);
123 slowJetDJR =
new SlowJet(slowJetPower, coneRadius, qCutME, etaJetMaxAlgo, 2, 2,
nullptr,
false);
126 hjSlowJet =
new HJSlowJet(slowJetPower, coneRadius, 0.0, 100.0, 1, 2,
nullptr,
false,
true);
129 eventProcessOrig.init(
"(eventProcessOrig)", particleDataPtr);
130 eventProcess.init(
"(eventProcess)", particleDataPtr);
131 workEventJet.init(
"(workEventJet)", particleDataPtr);
136 : (slowJetPower == -1) ?
"anti-kT" 137 : (slowJetPower == 0) ?
"C/A" 138 : (slowJetPower == 1) ?
"kT" 140 string modeStr = (exclusiveMode) ?
"exclusive" :
"inclusive";
142 <<
" *----- Madgraph matching parameters -----*" << endl
143 <<
" | qCut | " << setw(14) << qCut <<
" |" << endl
144 <<
" | nQmatch | " << setw(14) << nQmatch <<
" |" << endl
145 <<
" | clFact | " << setw(14) << clFact <<
" |" << endl
146 <<
" | Jet algorithm | " << setw(14) << jetStr <<
" |" << endl
147 <<
" | eTjetMin | " << setw(14) << eTjetMin <<
" |" << endl
148 <<
" | etaJetMax | " << setw(14) << etaJetMax <<
" |" << endl
149 <<
" | jetAllow | " << setw(14) << jetAllow <<
" |" << endl
150 <<
" | Mode | " << setw(14) << modeStr <<
" |" << endl
151 <<
" *-----------------------------------------*" << endl;
158 sortIncomingProcess(
event);
168 cout << endl <<
"-------- Begin Madgraph Debug --------" << endl;
170 cout << endl <<
"Original incoming process:";
171 eventProcessOrig.list();
173 cout << endl <<
"Final-state incoming process:";
176 for (
size_t i = 0;
i < typeIdx[0].size();
i++)
177 cout << ((
i == 0) ?
"Light jets: " :
", ") << setw(3) << typeIdx[0][
i];
178 if (typeIdx[0].
empty())
179 cout <<
"Light jets: None";
181 for (
size_t i = 0;
i < typeIdx[1].size();
i++)
182 cout << ((
i == 0) ?
"\nHeavy jets: " :
", ") << setw(3) << typeIdx[1][
i];
183 for (
size_t i = 0;
i < typeIdx[2].size();
i++)
184 cout << ((
i == 0) ?
"\nOther: " :
", ") << setw(3) << typeIdx[2][
i];
186 cout << endl << endl <<
"Event:";
189 cout << endl <<
"Work event:";
194 int iTypeEnd = (typeIdx[2].empty()) ? 2 : 3;
195 for (
int iType = 0; iType < iTypeEnd; iType++) {
198 jetAlgorithmInput(
event, iType);
203 cout << endl <<
"Jet algorithm event (iType = " << iType <<
"):";
212 if (matchPartonsToJets(iType) ==
true) {
217 <<
"---------- End MLM Debug ----------" << endl;
227 <<
"---------- End MLM Debug ----------" << endl;
234 omitResonanceDecays(eventProcessOrig,
true);
239 eventProcess = workEvent;
241 for (
int i = 0;
i < 3;
i++) {
244 origTypeIdx[
i].clear();
247 for (
int i = 0;
i < eventProcess.size();
i++) {
249 if (!eventProcess[
i].isFinal())
255 if (eventProcess[
i].isGluon() || (eventProcess[
i].idAbs() <= nQmatch)) {
260 idx = (
trunc(1000. * eventProcess[
i].
scale()) ==
trunc(1000. * infoPtr->scalup())) ? 0 : 2;
264 idx = (eventProcess[
i].scale() < 1.999 *
sqrt(infoPtr->eA() * infoPtr->eB())) ? 0 : 2;
269 else if (eventProcess[
i].idAbs() > nQmatch && eventProcess[
i].idAbs() <= ID_TOP) {
273 }
else if (eventProcess[
i].colType() != 0 && eventProcess[
i].idAbs() > ID_TOP) {
280 typeIdx[
idx].push_back(
i);
281 typeSet[
idx].insert(eventProcess[
i].daughter1());
282 origTypeIdx[orig_idx].push_back(
i);
285 if (exclusiveMode == 2) {
287 int nParton = origTypeIdx[0].size();
288 exclusive = (nParton == nJetMax) ?
false :
true;
292 exclusive = (exclusiveMode == 0) ?
false :
true;
300 int nParton = typeIdx[0].size();
301 processSubsetSave.clear();
302 for (
int i = 0;
i < nParton; ++
i)
303 processSubsetSave.append(eventProcess[typeIdx[0][
i]]);
317 if (!doFxFx &&
int(typeIdx[0].
size()) > nJetMax)
319 if (doFxFx && npNLO() < nJetMax &&
int(typeIdx[0].
size()) > nJetMax)
328 workEventJet = workEvent;
331 for (
int i = 0;
i < workEventJet.size(); ++
i) {
332 if (!workEventJet[
i].isFinal())
338 if (workEventJet[
i].colType() == 0) {
339 workEventJet[
i].statusNeg();
344 int idx = workEventJet[
i].daughter1();
351 if (typeSet[1].
find(
idx) != typeSet[1].end() || typeSet[2].
find(
idx) != typeSet[2].end()) {
352 workEventJet[
i].statusNeg();
360 idx =
event[
idx].mother1();
363 }
else if (iType == 1) {
365 if (typeSet[1].
find(
idx) != typeSet[1].end())
371 workEventJet[
i].statusNeg();
376 idx =
event[
idx].mother1();
379 }
else if (iType == 2) {
381 if (typeSet[2].
find(
idx) != typeSet[2].end())
387 workEventJet[
i].statusNeg();
392 idx =
event[
idx].mother1();
415 sortIncomingProcess(
event);
421 vector<int> weakBosons;
422 for (
int i = 0;
i <
event.size();
i++) {
423 if (
event[
i].
id() == 22 &&
event[
i].id() == 23 &&
event[
i].idAbs() == 24)
424 weakBosons.push_back(
i);
427 for (
int i = workEvent.size() - 1;
i > 0; --
i) {
428 if (workEvent[
i].isFinal() && workEvent[
i].colType() != 0 &&
429 (workEvent[
i].statusAbs() == 43 || workEvent[
i].statusAbs() == 51)) {
433 bool QCDemission =
true;
436 int iPosOld = workEvent[
i].daughter1();
437 for (
int j = 0;
i <
int(weakBosons.size()); ++
i)
444 pTfirst = workEvent[
i].pT();
451 pTfirstSave = pTfirst;
456 if (doShowerKtVeto(pTfirst))
469 if (!slowJetDJR->setup(
event)) {
471 "Warning in JetMatchingMadgraph:setDJR" 472 ": the SlowJet algorithm failed on setup");
477 while (slowJetDJR->sizeAll() - slowJetDJR->sizeJet() > 0) {
481 slowJetDJR->doStep();
485 for (
int i =
int(
result.size()) - 1;
i >= 0; --
i)
495 setDJR(workEventJet);
496 set_nMEpartons(origTypeIdx[0].
size(), typeIdx[0].
size());
498 return (matchPartonsToJetsLight() > 0);
499 }
else if (iType == 1) {
500 return (matchPartonsToJetsHeavy() > 0);
502 return (matchPartonsToJetsOther() > 0);
508 workEventJetSave = workEventJet;
513 int nParton = typeIdx[0].size();
516 if (!slowJet->setup(workEventJet)) {
518 "Warning in JetMatchingMadgraph:matchPartonsToJets" 519 "Light: the SlowJet algorithm failed on setup");
522 double localQcutSq = qCutSq;
525 while (slowJet->sizeAll() - slowJet->sizeJet() > 0) {
526 if (slowJet->dNext() > localQcutSq)
528 dOld = slowJet->dNext();
531 int nJets = slowJet->sizeJet();
532 int nClus = slowJet->sizeAll();
539 int nCLjets = nClus -
nJets;
545 int nRequested = (doFxFx && !(npNLO() == nJetMax && npNLO() == (
int)(typeIdx[2].
size() - 1)))
546 ? npNLO() - typeIdx[2].size()
552 if (doFxFx && npNLO() < nJetMax && !typeIdx[2].
empty() && npNLO() == (
int)(typeIdx[2].
size() - 1)) {
574 if (nCLjets < nRequested)
579 if (nCLjets > nRequested)
589 if (doFxFx && npNLO() < nJetMax && nCLjets > nRequested)
596 if (!slowJet->setup(workEventJet)) {
598 "Warning in JetMatchingMadgraph:matchPartonsToJets" 599 "Light: the SlowJet algorithm failed on setup");
606 while (slowJet->sizeAll() - slowJet->sizeJet() > 0) {
607 if (slowJet->dNext() > localQcutSq)
614 while (slowJet->sizeAll() - slowJet->sizeJet() > nParton)
621 if (clFact >= 0. && nParton > 0) {
624 for (
int i = 0;
i < nParton; ++
i)
625 partonPt.push_back(eventProcess[typeIdx[0][
i]].pT2());
629 nJets = slowJet->sizeJet();
630 nClus = slowJet->sizeAll();
634 localQcutSq *=
pow2(clFact);
637 tempEvent.init(
"(tempEvent)", particleDataPtr);
639 double pTminEstimate = -1.;
643 for (
int i =
nJets;
i < nClus; ++
i) {
645 ID_GLUON, 98, 0, 0, 0, 0, 0, 0, slowJet->p(
i).px(), slowJet->p(
i).py(), slowJet->p(
i).pz(), slowJet->p(
i).e());
647 pTminEstimate =
max(pTminEstimate, slowJet->pT(
i));
648 if (
nPass == nRequested)
652 int tempSize = tempEvent.size();
654 vector<bool> jetAssigned;
655 jetAssigned.assign(tempSize,
false);
659 vector<vector<bool> > partonMatchesJet;
660 partonMatchesJet.reserve(nParton);
661 for (
int i = 0;
i < nParton; ++
i)
662 partonMatchesJet.push_back(vector<bool>(tempEvent.size(),
false));
679 while (doFxFx && iNow < tempSize) {
682 tempEventJet.init(
"(tempEventJet)", particleDataPtr);
683 for (
int i = 0;
i < nParton; ++
i) {
689 tempEventJet.clear();
690 tempEventJet.append(ID_GLUON,
698 tempEvent[iNow].
px(),
699 tempEvent[iNow].
py(),
700 tempEvent[iNow].pz(),
701 tempEvent[iNow].
e());
703 Vec4 pIn = eventProcess[typeIdx[0][
i]].p();
704 tempEventJet.append(ID_GLUON, 99, 0, 0, 0, 0, 0, 0, pIn.px(), pIn.py(), pIn.pz(), pIn.e());
707 if (!slowJet->setup(tempEventJet)) {
709 "Warning in JetMatchingMadgraph:matchPartonsToJets" 710 "Light: the SlowJet algorithm failed on setup");
715 if (slowJet->iNext() == tempEventJet.size() - 1 && slowJet->jNext() > -1 && slowJet->dNext() < localQcutSq) {
716 jetAssigned[iNow] =
true;
717 partonMatchesJet[
i][iNow] =
true;
722 if (jetAssigned[iNow])
737 if (npNLO() < nJetMax && nMatched != nRequested)
738 return UNMATCHED_PARTON;
739 if (npNLO() == nJetMax && nMatched < nRequested)
740 return UNMATCHED_PARTON;
750 while (!doFxFx && iNow < nParton) {
752 tempEventJet.init(
"(tempEventJet)", particleDataPtr);
753 for (
int i = 0;
i < tempSize; ++
i) {
756 Vec4 pIn = tempEvent[
i].p();
758 tempEventJet.append(ID_GLUON, 98, 0, 0, 0, 0, 0, 0, pIn.px(), pIn.py(), pIn.pz(), pIn.e());
761 Vec4 pIn = eventProcess[typeIdx[0][iNow]].p();
763 tempEventJet.append(ID_GLUON, 99, 0, 0, 0, 0, 0, 0, pIn.px(), pIn.py(), pIn.pz(), pIn.e());
764 if (!slowJet->setup(tempEventJet)) {
766 "Warning in JetMatchingMadgraph:matchPartonsToJets" 767 "Light: the SlowJet algorithm failed on setup");
772 if (slowJet->iNext() == tempEventJet.size() - 1 && slowJet->jNext() > -1 && slowJet->dNext() < localQcutSq) {
774 for (
int i = 0;
i != tempSize; ++
i) {
779 if (iKnt == slowJet->jNext())
780 jetAssigned[
i] =
true;
783 return UNMATCHED_PARTON;
790 if (nParton > 0 && pTminEstimate > 0)
791 eTpTlightMin = pTminEstimate;
796 setDJR(workEventJet);
813 int nParton = typeIdx[1].size();
815 Event tempEventJet(workEventJet);
821 for (
int i = 0;
i < nParton; ++
i) {
822 scaleF = eventProcessOrig[0].e() / workEventJet[typeIdx[1][
i]].pT();
823 tempEventJet[typeIdx[1][
i]].rescale5(scaleF);
826 if (!hjSlowJet->setup(tempEventJet)) {
828 "Warning in JetMatchingMadgraph:matchPartonsToJets" 829 "Heavy: the SlowJet algorithm failed on setup");
833 while (hjSlowJet->sizeAll() - hjSlowJet->sizeJet() > 0) {
834 if (hjSlowJet->dNext() > qCutSq)
842 for (
int idx = 0;
idx < hjSlowJet->sizeAll(); ++
idx) {
843 if (hjSlowJet->pT(
idx) > qCut)
849 hjSlowJet->list(
true);
854 int nRequested = nParton;
857 if (nCLjets < nRequested) {
859 cout <<
"veto : hvy LESS_JETS " << endl;
861 cout <<
"nCLjets = " << nCLjets <<
"; nRequest = " << nRequested << endl;
867 if (nCLjets > nRequested) {
869 cout <<
"veto : excl hvy MORE_JETS " << endl;
889 int nParton = typeIdx[2].size();
891 Event tempEventJet(workEventJet);
897 for (
int i = 0;
i < nParton; ++
i) {
898 scaleF = eventProcessOrig[0].e() / workEventJet[typeIdx[2][
i]].pT();
899 tempEventJet[typeIdx[2][
i]].rescale5(scaleF);
902 if (!hjSlowJet->setup(tempEventJet)) {
904 "Warning in JetMatchingMadgraph:matchPartonsToJets" 905 "Heavy: the SlowJet algorithm failed on setup");
909 while (hjSlowJet->sizeAll() - hjSlowJet->sizeJet() > 0) {
910 if (hjSlowJet->dNext() > qCutSq)
918 for (
int idx = 0;
idx < hjSlowJet->sizeAll(); ++
idx) {
919 if (hjSlowJet->pT(
idx) > qCut)
925 hjSlowJet->list(
true);
930 int nRequested = nParton;
933 if (nCLjets < nRequested) {
935 cout <<
"veto : other LESS_JETS " << endl;
937 cout <<
"nCLjets = " << nCLjets <<
"; nRequest = " << nRequested << endl;
943 if (nCLjets > nRequested) {
945 cout <<
"veto : excl other MORE_JETS" << endl;
964 int nParton = typeIdx[0].size();
965 double pTminME = 1e10;
966 for (
int i = 0;
i < nParton; ++
i)
967 pTminME =
min(pTminME, eventProcess[typeIdx[0][
i]].
pT());
970 if (nParton > 0 &&
pow(pTminME, 2) < qCutSq)
979 }
else if (!
exclusive && nParton > 0 && pTfirst > pTminME) {
991 string npIn = infoPtr->getEventAttribute(
"npNLO",
true);
992 int np = !npIn.empty() ? std::atoi(npIn.c_str()) : -1;
bool matchPartonsToJets(int) override
void jetAlgorithmInput(const Pythia8::Event &, int) override
bool doVetoPartonLevelEarly(const Pythia8::Event &event) override
int matchPartonsToJetsLight() override
bool doVetoStep(int, int, int, const Pythia8::Event &) override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
constexpr int pow2(int x)
bool isAncestor(ProcessHistory const &a, ProcessHistory const &b)
int matchPartonsToJetsHeavy() override
void runJetAlgorithm() override
bool doShowerKtVeto(double pTfirst)
void sortIncomingProcess(const Pythia8::Event &) override
bool initAfterBeams() override
void setDJR(const Pythia8::Event &event)
JetMatchingEWKFxFx(const edm::ParameterSet &iConfig)
int matchPartonsToJetsOther()
Power< A, B >::type pow(const A &a, const B &b)
bool doVetoProcessLevel(Pythia8::Event &event) override