// main31.cc is a part of the PYTHIA event generator. // Copyright (C) 2023 Torbjorn Sjostrand. // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details. // Please respect the MCnet Guidelines, see GUIDELINES for details. // Keywords: matching; merging; powheg // Example how to perform matching with POWHEG-BOX events, // based on the code found in include/Pythia8Plugins/PowhegHooks.h. #include #include "Pythia8/Pythia.h" #include "Pythia8Plugins/PowhegHooks.h" #include "Pythia8Plugins/Pythia8Rivet.h" using namespace Pythia8; //========================================================================== int main(int argc, char** argv) { // Generator Pythia pythia; // New settings for Rivet interface. pythia.settings.addFlag("Main:Rivet", true); pythia.settings.addWord("Rivet:output","analysis.yoda"); pythia.settings.addWVec("Rivet:analyses",vector()); // Fetch command-line arguments. string runcard = ""; string lhefile = ""; string outfile = ""; int seed = -1; for(;;) { switch(getopt(argc, argv, "c:f:o:s:h")) { case 'c': runcard = string(optarg); continue; case 'f': lhefile = string(optarg); continue; case 'o': outfile = string(optarg); continue; case 's': seed = atoi(optarg); continue; case '?': case 'h': default : cout << " Usage:" << endl; cout << " ./" << argv[0] << " -c [optargs]" << endl; cout << "\n -c " << endl << "\n -f " << endl << "\n -o " << endl; break; case -1: break; } break; } // Check if we have a run card. if (runcard == "") { cerr << " Error: no run card provided\n" << endl; return EXIT_FAILURE; } // Load run card. pythia.readFile(runcard); // Read in main settings. int nEvent = pythia.settings.mode("Main:numberOfEvents"); int nError = pythia.settings.mode("Main:timesAllowErrors"); // Read in key POWHEG matching settings. int vetoMode = pythia.settings.mode("POWHEG:veto"); int MPIvetoMode = pythia.settings.mode("POWHEG:MPIveto"); bool loadHooks = (vetoMode > 0 || MPIvetoMode > 0); // Read in shower settings. int showerModel = pythia.settings.mode("PartonShowers:model"); // Read in LHE file if specified on command line. if (lhefile != "") pythia.readString("Beams:LHEF = "+lhefile); // Read name of Yoda file if specified on command line. if (outfile != "") pythia.readString("Rivet:output = "+outfile); // Set seed if specified on command line. if (seed >= 0) { pythia.readString("Random:setSeed = on"); pythia.readString("Random:seed = "+to_string(seed)); } // Add user hooks for shower vetoing. shared_ptr powhegHooks; if (loadHooks) { // Set showers to start at the kinematical limit. if (vetoMode > 0) { if (showerModel == 1 || showerModel == 3) { // Pythia and Dire have separate settings for ISR and FSR. pythia.readString("SpaceShower:pTmaxMatch = 2"); pythia.readString("TimeShower:pTmaxMatch = 2"); } else if (showerModel == 2) { // Vincia only has one common setting for both ISR and FSR. pythia.readString("Vincia:pTmaxMatch = 2"); } } // Set MPI to start at the kinematical limit. if (MPIvetoMode > 0) { pythia.readString("MultipartonInteractions:pTmaxMatch = 2"); } powhegHooks = make_shared(); pythia.setUserHooksPtr((UserHooksPtr)powhegHooks); } // Rivet interface. const bool doRivet = pythia.flag("Main:Rivet"); Pythia8Rivet rivet(pythia, pythia.word("Rivet:output")); vector analyses = pythia.settings.wvec("Rivet:analyses"); for (const string& analysis : analyses) rivet.addAnalysis(analysis); // Initialise PYTHIA. if (!pythia.init()) { cerr << " Error: PYTHIA initialisation failed" << endl; return EXIT_FAILURE; } // Event loop. int iEvent = 0, iError = 0; while (true) { // Generate the next event if (!pythia.next()) { // If failure because reached end of file then exit event loop if (pythia.info.atEndOfFile()) break; // Otherwise count event failure and continue/exit as necessary cout << "Warning: event " << iEvent << " failed" << endl; if (++iError == nError) { cout << "Error: too many event failures... exiting" << endl; break; } continue; } // Workaround for event weights which are not in "detailed" format. double wt = pythia.info.weight(); for (int iWt(1); iWtweightsLHEF.bookWeight("VAR"+to_string(iWt), pythia.info.getWeightsCompressedValue(iWt)/wt); } // Pass to RIVET. if (doRivet) rivet(); // If nEvent is set, check and exit loop if necessary ++iEvent; if (nEvent != 0 && iEvent == nEvent) break; } // Finalise analysis. if (doRivet) rivet.done(); // Statistics. pythia.stat(); // Done. return 0; }