101#include "Pythia8/Pythia.h"
104#if PYTHIA_VERSION_INTEGER >= 8310
108# include "Pythia8/Plugins.h"
109# undef PYTHIA8_PLUGIN_CLASS
110# undef PYTHIA8_PLUGIN_VERSIONS
111# define PYTHIA8_PLUGIN_CLASS(BASE, CLASS, PYTHIA, SETTINGS, LOGGER)
112# define PYTHIA8_PLUGIN_VERSIONS(...)
139 :
m_debug(
"Powheg:bb4l:DEBUG", false),
145 m_pTmin(
"Powheg:bb4l:pTminVeto", 0.5),
152 std::cout <<
"**********************************************************" << std::endl;
153 std::cout <<
"* *" << std::endl;
154 std::cout <<
"* Applying Powheg BB4L UserHook (PowhegBB4Ldlsl)! *" << std::endl;
155 std::cout <<
"* Must run on dedicated Powheg LHE input file *" << std::endl;
156 std::cout <<
"* (on your own responsibility) *" << std::endl;
157 std::cout <<
"* *" << std::endl;
158 std::cout <<
"**********************************************************" << std::endl;
180 ss << infoPtr->getEventComments();
183 assert (temp ==
"#rwgt");
187 if (
radtype_.radtype==2)
return false;
189 int i_top = -1, i_atop = -1, i_wp = -1, i_wm = -1;
190 for (
int i = 0; i < e.size(); i++) {
191 if (e[i].
id() == 6) i_top = i;
192 if (e[i].
id() == -6) i_atop = i;
193 if (e[i].
id() == 24) i_wp = i;
194 if (e[i].
id() == -24) i_wm = i;
223 int iRecAft = e.size() - 1;
224 int iEmt = e.size() - 2;
225 int iRadAft = e.size() - 3;
226 int iRadBef = e[iEmt].mother1();
229 int iRes = e[iRadBef].mother1();
230 while ( iRes > 0 && (std::abs(e[iRes].
id()) !=6 && std::abs(e[iRes].
id()) != 24) ) {
231 iRes = e[iRes].mother1();
234 #if PYTHIA_VERSION_INTEGER >= 8310
235 loggerPtr->ERROR_MSG(
"Warning in PowhegHooksBB4L::doVetoFSREmission: emission in resonance not from the top quark or from the W boson, not vetoing");
237 infoPtr->errorMsg(
"Warning in PowhegHooksBB4L::doVetoFSREmission: emission in resonance not from the top quark or from the W boson, not vetoing");
241 int iResId = e[iRes].id();
247 scale =
pTpythia(e, iRadAft, iEmt, iRecAft);
250 Vec4 pr(e[iRadAft].p()), pe(e[iEmt].p()), pres(e[iRes].p()), prec(e[iRecAft].p()), psystem;
255 psystem = pr+pe+prec;
260 if (e[iRadBef].
id() == 21)
263 else if (std::abs(e[iRadBef].
id()) <= 5 && ((e[iEmt].
id() == 21) && !
m_vetoQED(settingsPtr)) )
274 cout << iResId <<
": " << e[iRadBef].id() <<
" > " << e[iRadAft].id() <<
" + " << e[iEmt].id() <<
"; " << scale << endl;
277 else if (iResId == -6){
279 cout << iResId <<
": " << e[iRadBef].id() <<
" > " << e[iRadAft].id() <<
" + " << e[iEmt].id() <<
"; " << scale << endl;
282 else if (iResId == 24) {
284 cout << iResId <<
": " << e[iRadBef].id() <<
" > " << e[iRadAft].id() <<
" + " << e[iEmt].id() <<
"; " << scale << endl;
287 else if (iResId == -24){
289 cout << iResId <<
": " << e[iRadBef].id() <<
" > " << e[iRadAft].id() <<
" + " << e[iEmt].id() <<
"; " << scale << endl;
293 #if PYTHIA_VERSION_INTEGER >= 8310
294 loggerPtr->ERROR_MSG(
"Error in PowhegHooksBB4L::doVetoFSREmission: unimplemented case");
296 infoPtr->errorMsg(
"Error in PowhegHooksBB4L::doVetoFSREmission: unimplemented case");
312 if (
radtype_.radtype==2)
return false;
331 return sqrt(e[iRes].m2Calc());
333 if (e[iRes].
id() == 6)
335 else if (e[iRes].
id() == -6)
337 else if (e[iRes].
id() == 24)
339 else if (e[iRes].
id() == -24)
352 if (iRes < 0)
return 1e30;
355 int nDau =
event[iRes].daughterList().size();
368 else if (std::abs(event[iRes].
id()) == 6) {
370 int idw = -1, idb = -1, idg = -1;
371 for (
int i = 0; i < nDau; i++) {
372 int iDau =
event[iRes].daughterList()[i];
373 if (std::abs(event[iDau].
id()) == 24) idw = iDau;
374 if (std::abs(event[iDau].
id()) == 5) idb = iDau;
375 if (std::abs(event[iDau].
id()) == 21) idg = iDau;
379 Vec4 pw(event[idw].p());
380 pw.bstback(event[iRes].p());
381 Vec4 pb(event[idb].p());
382 pb.bstback(event[iRes].p());
383 Vec4 pg(event[idg].p());
384 pg.bstback(event[iRes].p());
387 return sqrt(2*pg*pb*pg.e()/pb.e());
390 else if (std::abs(event[iRes].
id()) == 24) {
392 int idq = -1, ida = -1, idg = -1;
393 for (
int i = 0; i < nDau; i++) {
394 int iDau =
event[iRes].daughterList()[i];
395 if (event[iDau].
id() == 21) idg = iDau;
396 else if (event[iDau].
id() > 0) idq = iDau;
397 else if (event[iDau].
id() < 0) ida = iDau;
399 if (idq<0 or ida <0){
400 throw std::out_of_range(
"idq or ida out of range in PowhegHooksBB4Ldlsl.cxx");
403 Vec4 pq(event[idq].p());
404 pq.bstback(event[iRes].p());
405 Vec4 pa(event[ida].p());
406 pa.bstback(event[iRes].p());
407 Vec4 pg(event[idg].p());
408 pg.bstback(event[iRes].p());
411 Vec4 pw = pq + pa + pg;
413 double csi = 2*pg.e()/sqrt(q2);
414 double yq = 1 - pg*pq/(pg.e()*pq.e());
415 double ya = 1 - pg*pa/(pg.e()*pa.e());
417 return sqrt(
min(1-yq,1-ya)*
pow2(csi)*q2/2);
428 inline bool match_decay(
int iparticle,
const Event &e,
const vector<int> &ids, vector<int> &positions, vector<Vec4> &momenta,
bool exitOnExtraLegs =
true){
430 if (e[iparticle].daughterList().size() != ids.size()) {
431 if (exitOnExtraLegs && e[iparticle].daughterList().size() > ids.size()) {
432 cout <<
"extra leg" << endl;
438 for (
long unsigned int i = 0; i < e[iparticle].daughterList().size(); i++) {
439 int di = e[iparticle].daughterList()[i];
440 if (ids[i] != 0 && e[di].
id() != ids[i])
447 for (
long unsigned int i = 0; i < e[iparticle].daughterList().size(); i++) {
448 int di = e[iparticle].daughterList()[i];
449 positions.push_back(di);
450 momenta.push_back(e[di].p());
458 return sqrt( 2*p1*p2*p2.e()/p1.e() );
464 return sqrt( 2*p1*p2*p1.e()*p2.e()/(
pow(p1.e()+p2.e(),2)) );
471 inline double pTpythia(
const Event &e,
int RadAfterBranch,
int EmtAfterBranch,
476 Vec4 radVec = e[RadAfterBranch].p();
477 Vec4 emtVec = e[EmtAfterBranch].p();
478 Vec4 recVec = e[RecAfterBranch].p();
479 int radID = e[RadAfterBranch].id();
482 Vec4 Q(radVec + emtVec);
483 double Qsq = Q.m2Calc();
486 double m2Rad = (std::abs(radID) >= 4 && std::abs(radID) < 7) ?
487 pow2(particleDataPtr->m0(radID)) : 0.;
492 Vec4 sum = radVec + recVec + emtVec;
493 double m2Dip = sum.m2Calc();
495 double x1 = 2. * (sum * radVec) / m2Dip;
496 double x3 = 2. * (sum * emtVec) / m2Dip;
498 pTnow =
z * (1. -
z);
502 pTnow *= (Qsq - m2Rad);
505 cout <<
"Warning: pTpythia was negative" << endl;
533 if (nMPI > 1)
return false;
536 bool top_exists =
false;
537 bool antitop_exists =
false;
538 for (
int i = e.size() - 1; i > 0; i--) {
539 if (e[i].isFinal()) {
542 if (e[i].
id() == 6) top_exists =
true;
543 if (e[i].
id() == -6) antitop_exists =
true;
548 int nCurrentFinal = -1;
550 if (top_exists && antitop_exists) nCurrentFinal = 2;
552 else if (top_exists || antitop_exists) nCurrentFinal = 3;
554 std::cout <<
"Error: neither top nor anti-top found - something went wrong" << std::endl;
558 if (
count != nCurrentFinal &&
count != nCurrentFinal + 1) {
559 cout <<
"Error: wrong number of final state particles in event: count " <<
count <<
" nCurrentFinal: "<< nCurrentFinal << endl;
560 for (
int i = e.size() - 1; i > 0; i--) {
561 if (e[i].isFinal()) { std:: cout <<
"FS particle " << i <<
" PID: " << e[i].id() << std::endl;
567 bool isEmt = (
count == nCurrentFinal) ?
false :
true;
568 int iEmt = (isEmt) ? e.size() - 1 : -1;
579 std::cout <<
"Error: m_pThardMode neither 1 or 2 - something went wrong" << std::endl;
struct @265362120060103244115120172162007233333034374360 radtype_
Pythia8_UserHooks::UserHooksFactory::Creator< Pythia8::PowhegBB4Ldlsl > powhegBB4LdlslCreator("PowhegBB4Ldlsl")
static const std::map< unsigned int, unsigned int > pow2
constexpr int pow(int base, int exp) noexcept
virtual bool doVetoFSREmission(int sizeOld, const Event &e, int iSys, bool inResonance) override
virtual bool canVetoProcessLevel() override
int numberVetoMPIStep() override
Pythia8_UserHooks::UserSetting< bool > m_vetoFSREmission
~PowhegBB4Ldlsl() override
bool canVetoMPIStep() override
Pythia8_UserHooks::UserSetting< int > m_vetoProduction
double findresscale(const int iRes, const Event &event)
int getNInResonanceFSRVeto()
bool doVetoMPIStep(int nMPI, const Event &e) override
virtual double scaleResonance(int iRes, const Event &e) override
Pythia8_UserHooks::UserSetting< double > m_pTmin
bool doVetoFSR(bool condition)
virtual bool initAfterBeams() override
Pythia8_UserHooks::UserSetting< bool > m_vetoQED
bool match_decay(int iparticle, const Event &e, const vector< int > &ids, vector< int > &positions, vector< Vec4 > &momenta, bool exitOnExtraLegs=true)
virtual bool canVetoFSREmission() override
Pythia8_UserHooks::UserSetting< int > m_vetoDipoleFrame
virtual bool doVetoProcessLevel(Event &e) override
Pythia8_UserHooks::UserSetting< bool > m_debug
unsigned long int m_nInResonanceFSRveto
double pTpythia(const Event &e, int RadAfterBranch, int EmtAfterBranch, int RecAfterBranch)
virtual bool canSetResonanceScale() override
Pythia8_UserHooks::UserSetting< double > m_scaleResonanceVeto
Pythia8_UserHooks::UserSetting< int > m_pTpythiaVeto
double qSplittingScale(Vec4 pt, Vec4 p1, Vec4 p2)
Pythia8_UserHooks::UserSetting< int > m_pThardMode
double gSplittingScale(Vec4 pt, Vec4 p1, Vec4 p2)
double pTcalc(const Event &e, int i, int j, int k, int r, int xSRin)
PowhegHooksSetterMethod()
void setpThard(double newPThard)
bool doVetoFSREmission(int, const Event &e, int iSys, bool)
bool doVetoMPIStep(int nMPI, const Event &e)
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Author: James Monk (jmonk@cern.ch)