### CKKW-L Merging with kT Scale (main80.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example program demonstrates CKKW-L merging using a merging scale defined in kT. It is designed as a basic and pedagogical setup, suitable for tutorials, and relies on input from the `main80.cmnd` file and external LHE files. ```APIDOC Program: main80.cc Functionality: Performs CKKW-L merging with a kT-defined merging scale. Input: main80.cmnd file, LHE files. Purpose: Basic, pedagogical setup for tutorials. ``` -------------------------------- ### Compile Generated PYTHIA 8 Example Program Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/MadGraph5Processes.html After MadGraph5 generates the PYTHIA 8 process library and an example main program, navigate to the `examples/` directory within your PYTHIA 8 installation. Use this `make` command to compile the generated example program, linking in the new process classes. ```Shell make -f Makefile_modelname_N ``` -------------------------------- ### C++ Dependencies and Namespace Setup for PYTHIA8 and FastJet Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main82.html This snippet includes necessary header files for PYTHIA8 and FastJet libraries, and sets up the `Pythia8` namespace. These are fundamental for compiling and running the event generation and jet analysis code. ```C++ #include "Pythia8/Pythia.h" using namespace Pythia8; // Functions for histogramming #include "fastjet/PseudoJet.hh" #include "fastjet/ClusterSequence.hh" #include "fastjet/CDFMidPointPlugin.hh" #include "fastjet/CDFJetCluPlugin.hh" ``` -------------------------------- ### Generating Ridge Effects with String Shoving Hadronization (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example demonstrates the setup and usage of the string shoving mechanism, a component of the rope hadronization framework. It illustrates how this mechanism can be employed to generate ridge effects in event simulations. ```C++ Code not provided in input text, refer to examples/main101.html ``` -------------------------------- ### FastJet Integration for Jet Finding (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/SampleMainPrograms.html An example of how the FastJet jet finding package can be linked to allow an analysis of the final state, in this case for a study of W + jet production. ```C++ C++ code demonstrating FastJet integration for W + jet production analysis. ``` -------------------------------- ### Multi-Method Matching/Merging (main89.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example program allows for matching/merging according to five alternative methods: CKKW-L, FxFx, MLM, UMEPS, and UNLOPS. The desired method is selected by choosing which `.cmnd` file to read (e.g., `main89ckkwl.cmnd`). ```APIDOC Program: main89.cc Functionality: Implements matching/merging using five alternative methods (CKKW-L, FxFx, MLM, UMEPS, UNLOPS). Configuration: Method selected by reading corresponding .cmnd file (e.g., main89ckkwl.cmnd). ``` -------------------------------- ### Pythia C++ Example: Dark Matter Production with Long-Lived Signatures Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html Simple setup for Dark Matter production in several different scenarios, as specified in `main76.cmnd`, notably with long-lived particle signatures. ```C++ main76.cc ``` -------------------------------- ### Pythia8 Merging Example Main Program Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main82.html This C++ `main` function serves as an example program to illustrate event merging with Pythia8. It validates command-line arguments, expecting an input file for settings, a full path to an LHE file, and a path for output histogram files. ```C++ int main( int argc, char* argv[] ){ // Check that correct number of command-line arguments if (argc != 4) { cerr << " Unexpected number of command-line arguments. \n You are" << " expected to provide the arguments \n" << " 1. Input file for settings \n" << " 2. Full name of the input LHE file (with path) \n" << " 3. Path for output histogram files \n" } ``` -------------------------------- ### Providing External Photon Flux for Photo-production (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example illustrates how to provide an external photon flux for photo-production processes. It demonstrates the integration of external inputs for specific event generation scenarios in Pythia8. ```C++ Code not provided in input text, refer to examples/main70.html ``` -------------------------------- ### Studying Colour Reconnection Models for Top Production (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example investigates various colour reconnection models in the context of top production. It demonstrates how to set up user hooks in `include/Pythia8Plugins/ColourReconnectionHooks.h` to incorporate custom models not available in the standard PYTHIA library. ```C++ Code not provided in input text, refer to examples/main29.html ``` -------------------------------- ### Pythia8 PDF Setup and Initialization Methods Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/PartonDistributions.html Describes the `isSetup()` method, which returns the `isSet` boolean variable indicating successful PDF setup. Also notes that grid files are stored in `xmldoc` and only used PDF sets are read during initialization. ```APIDOC PDFSetupAndInitialization: isSetup(): Returns: boolean variable 'isSet'. Description: 'isSet' is initially true, set to false if PDF setup fails (e.g., unknown PDF set). GridFiles: Location: 'xmldoc' subdirectory. Loading: Only PDF sets that will be used are read during initialization. Initialization: Individual PDFs can be constructed using input streams, similar to settings and particle data. ``` -------------------------------- ### PYTHIA8 Setup for Photon-Initiated Hard Processes Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main69.html This C++ snippet demonstrates the configuration of PYTHIA8 for simulating charged hadron spectra from photon-initiated hard processes. It includes setting up beam particles for photon-proton or photon-photon collisions (from direct beams or lepton-emitted photons), applying cuts on photon virtuality and invariant mass, adjusting multiparton interaction parameters, and initializing histograms for different process contributions. ```C++ #include "Pythia8/Pythia.h" using namespace Pythia8; int main() { // Generator. Pythia pythia; // Decrease the output. pythia.readString("Init:showChangedSettings = off"); pythia.readString("Init:showChangedParticleData = off"); pythia.readString("Next:numberCount = 0"); pythia.readString("Next:numberShowInfo = 0"); pythia.readString("Next:numberShowProcess = 0"); pythia.readString("Next:numberShowEvent = 0"); // Shorthand for some public members of pythia (also static ones). Settings& settings = pythia.settings; const Info& info = pythia.info; // Photon-proton collisions. bool photonProton = false; // Generate photon-photon events in leptonic or photon beams. bool photonsFromElectrons = false; // Each contributions separately or in a one combined run. bool automaticMix = true; // Optionally use different PDFs from LHAPDF for hard process. // Requires linkin with LHAPDF5. // pythia.readString("PDF:useHard = on"); // pythia.readString("PDF:GammaHardSet = LHAPDF5:SASG.LHgrid/5"); // Beam parameters. pythia.readString("Beams:eCM = 200."); // Set up beam particles for electron -> photon + proton. if ( photonProton) { if ( photonsFromElectrons) { pythia.readString("Beams:idA = 11"); pythia.readString("Beams:idB = 2212"); pythia.readString("PDF:lepton2gamma = on"); // Set up beam particles for photon + proton. } else { pythia.readString("Beams:idA = 22"); pythia.readString("Beams:idB = 2212"); } // Set up beam particles for photon-photon in e+e-. } else if ( photonsFromElectrons) { pythia.readString("Beams:idA = -11"); pythia.readString("Beams:idB = 11"); pythia.readString("PDF:lepton2gamma = on"); // Set up beam particles for photon-photon. } else { pythia.readString("Beams:idA = 22"); pythia.readString("Beams:idB = 22"); } // Cuts on photon virtuality and invariant mass of gamma-gamma/hadron pair. if ( photonsFromElectrons) { pythia.readString("Photon:Q2max = 1.0"); pythia.readString("Photon:Wmin = 10.0"); } // For photon-proton increase pT0Ref (for better agreement with HERA data). // Photon-photon has a new default pT0 parametrization tuned to LEP data. if ( photonProton) pythia.readString("MultipartonInteractions:pT0Ref = 3.00"); // Limit partonic pThat. settings.parm("PhaseSpace:pTHatMin", 5.0); // Reset statistics after each subrun. pythia.readString("Stat:reset = on"); // Parameters for histograms. double pTmin = 0.0; double pTmax = 40.0; int nBinsPT = 40; // Initialize the histograms. Hist pTtot("Total charged hadron pT distribution", nBinsPT, pTmin, pTmax); Hist pTresres("Resolved-resolved contribution", nBinsPT, pTmin, pTmax); Hist pTresdir("Resolved-direct contribution", nBinsPT, pTmin, pTmax); Hist pTdirres("Direct-resolved contribution", nBinsPT, pTmin, pTmax); Hist pTdirdir("Direct-direct contribution", nBinsPT, pTmin, pTmax); Hist pTiRun("Contribution from Run i", nBinsPT, pTmin, pTmax); // Initialize hard QCD processes with 0, 1, or 2 initial photons. ``` -------------------------------- ### C++ Example: NNPDF 2.3 QCD+QED Comparison (main54.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example compares the internal and LHAPDF implementations of the NNPDF 2.3 QCD+QED sets. It evaluates both the physics results and the timing performance of these implementations. Proper linking to LHAPDF is required for this comparison. ```C++ Program: main54.cc Purpose: Compare internal and LHAPDF implementations of NNPDF 2.3 QCD+QED sets Evaluation Criteria: Results and timing Requirement: LHAPDF (properly linked) ``` -------------------------------- ### C++ Example: Alternative Merging Methods (main89.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This program demonstrates five alternative matching/merging methods: CKKW-L, FxFx, MLM, UMEPS, and UNLOPS. The specific method is chosen by reading the corresponding `.cmnd` file. This allows for easy comparison and testing of different merging algorithms. ```C++ Program: main89.cc Purpose: Demonstrate multiple matching/merging methods Method Selection: - CKKW-L: main89ckkwl.cmnd - FxFx: main89fxfx.cmnd - MLM: main89mlm.cmnd - UMEPS: main89umeps.cmnd - UNLOPS: main89unlops.cmnd ``` -------------------------------- ### LHAPDF PDF Comparison (main52.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example compares the charged multiplicity distribution and other minimum-bias physics aspects between the default PYTHIA PDF and an alternative PDF set. It requires that LHAPDF is properly linked. ```APIDOC Program: main52.cc Functionality: Compares charged multiplicity distribution and other minimum-bias physics aspects between default PYTHIA PDF and an alternative PDF. Dependencies: LHAPDF. ``` -------------------------------- ### Provide External Photon Flux for Photoproduction (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example demonstrates the method for providing an external photon flux, which is essential for simulating photo-production processes. It outlines the necessary steps to integrate an external flux source into Pythia8 simulations. ```C++ examples/main70.html ``` -------------------------------- ### C++ Example: Charged Particle Spectra in Photon Collisions (main69.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example demonstrates how to generate all relevant contributions for charged particle spectra in both photon-photon and photon-proton collisions. It provides a comprehensive approach to simulating these specific interaction types. ```C++ Program: main69.cc Purpose: Generate all relevant contributions for charged particle spectra Collision Types: Photon-photon collisions, Photon-proton collisions ``` -------------------------------- ### Compile PYTHIA main93 Example and Set ROOT Environment Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ROOTusage.html These commands compile the `main93` example program, which demonstrates storing partial PYTHIA events in ROOT trees. The `make` command builds the example, and the `source` command ensures that all necessary ROOT paths are correctly set in the environment for successful execution and interaction with ROOT libraries. ```bash make main93 source root-installation-directory/bin/thisroot.sh ``` -------------------------------- ### C++ Example: Charged Multiplicity Comparison with LHAPDF (main52.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example compares the charged multiplicity distribution and several other minimum-bias physics aspects between the default PYTHIA PDF and an alternative PDF. It requires that LHAPDF is properly linked to function correctly, enabling a direct comparison of different PDF sets. ```C++ Program: main52.cc Purpose: Compare charged multiplicity and minimum-bias physics aspects Comparison: Default PYTHIA PDF vs. another PDF Dependency: LHAPDF (properly linked) ``` -------------------------------- ### PYTHIA8 MLM Matching Program Initialization and Event Loop (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main32.html This C++ program demonstrates the setup and execution of an event generation loop with PYTHIA8, specifically for Alpgen- or Madgraph-style MLM matching. It initializes the generator, reads settings from a command file, sets up a CombineMatchingInput user hook for matching, and then enters a loop to generate and process events until the specified number of events or end of file is reached, handling potential errors during generation. ```C++ // main32.cc is a part of the PYTHIA event generator. // Copyright (C) 2020 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 // MLM // This is a sample program showing Alpgen- or Madgraph-style MLM matching // for Madgraph LHEF or native Alpgen format event files. // // Please see the 'Jet Matching Style' manual page for a description of the // parameters and user options. // Includes and namespace #include "Pythia8/Pythia.h" #include "Pythia8Plugins/CombineMatchingInput.h" using namespace Pythia8; //========================================================================== int main() { // Generator and read in commands. Pythia pythia; pythia.readFile("main32.cmnd"); // Extract settings to be used in the main program. int nEvent = pythia.mode("Main:numberOfEvents"); int nAbort = pythia.mode("Main:timesAllowErrors"); int nSkip = pythia.mode("Main:spareMode1"); // Create UserHooks pointer. Stop if it failed. Pass pointer to Pythia. CombineMatchingInput combined; combined.setHook(pythia); // Initialise Pythia. if (!pythia.init()) { cout << "Error: could not initialise Pythia" << endl; return 1; }; // Optionally skip ahead in LHEF. pythia.LHAeventSkip( nSkip ); // Begin event loop. Optionally quit it before end of file. int iAbort = 0; for (int iEvent = 0; ; ++iEvent) { if (nEvent > 0 && iEvent >= nEvent) break; // Generate events. Quit if at end of file or many failures. if (!pythia.next()) { if (pythia.info.atEndOfFile()) { cout << "Info: end of input file reached" << endl; break; } if (++iAbort < nAbort) continue; cout << "Abort: too many errors in generation" << endl; break; } // Event analysis goes here. // End of event loop. } // Final statistics and done. pythia.stat(); return 0; } ``` -------------------------------- ### CKKW-L Merging with kT Scale and Specific Inputs (main81.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example performs CKKW-L merging with a kT-defined merging scale, similar to main80.cc, but uses specific input files: `main81.cmnd` and the three data files `w+_production_lhc_0.lhe`, `w+_production_lhc_1.lhe`, and `w+_production_lhc_2.lhe`. ```APIDOC Program: main81.cc Functionality: Performs CKKW-L merging with a kT-defined merging scale. Input: main81.cmnd file, w+_production_lhc_0.lhe, w+_production_lhc_1.lhe, w+_production_lhc_2.lhe. Purpose: Demonstrates CKKW-L merging with specific input data. ``` -------------------------------- ### C++ Example: External Photon Flux for Photo-production (main70.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This program exemplifies the method for providing an external photon flux specifically for photo-production processes. It is crucial for simulations where the photon beam characteristics are defined externally rather than internally generated. ```C++ Program: main70.cc Purpose: Provide an external photon flux Application: Photo-production processes ``` -------------------------------- ### Modifying Flavour Production in Rope Hadronization (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example illustrates how flavour production is altered within the rope hadronization framework. It provides insights into the impact of this model on particle composition during hadronization. ```C++ Code not provided in input text, refer to examples/main102.html ``` -------------------------------- ### CKKW-L Merging with Multiplicity Cut (main83.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html Building upon `main82.cc`, this example adds an additional cut on the lowest multiplicity allowed for the reclustered state. It can use the same input files as `main82.cc`. ```APIDOC Program: main83.cc Functionality: Performs CKKW-L merging with a user-defined merging scale function and an additional cut on the lowest multiplicity for the reclustered state. Input: Same as main82.cc (main82.cmnd, w+_production_lhc_0.lhe, etc.). ``` -------------------------------- ### LHAPDF NNPDF 2.3 Comparison (main54.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example compares the internal and LHAPDF implementations of the NNPDF 2.3 QCD+QED sets, evaluating both the physics results and the timing performance. It requires proper linking to LHAPDF. ```APIDOC Program: main54.cc Functionality: Compares internal and LHAPDF implementations of NNPDF 2.3 QCD+QED sets for results and timing. Dependencies: LHAPDF. ``` -------------------------------- ### C++ Example: Backwards Evolution from Incoming Photon (main53.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This program tests the possibility of performing backwards evolution from an incoming photon at the hard interaction. It requires that you link to a LHAPDF set that specifically includes the photon PDF, demonstrating advanced PDF functionalities. ```C++ Program: main53.cc Purpose: Test backwards evolution from incoming photon Requirement: LHAPDF set including photon PDF (must be linked) ``` -------------------------------- ### Generate Charged Particle Spectra in Photon-Photon and Photon-Proton Collisions (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example demonstrates how to generate all relevant contributions for charged particle spectra in both photon-photon and photon-proton collision scenarios. It covers the necessary configurations and methods to simulate these specific collision types. ```C++ examples/main69.html ``` -------------------------------- ### Comparing Jet Properties at Parton and Hadron Levels (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example compares jet properties at both the parton and hadron levels. It illustrates methods for gaining greater control over which particles are included in jet analyses, providing flexibility for detailed studies. ```C++ Code not provided in input text, refer to examples/main73.html ``` -------------------------------- ### Direct Hadronization Input for Parton-Level Configurations (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example illustrates how to directly input single particles or various parton-level configurations for hadronization, bypassing the full process-generation machinery. This is useful for studying specific phenomena like the hadronization of junction topologies or for simulating single-resonance decays with showers. ```C++ Code not provided in input text, refer to examples/main21.html ``` -------------------------------- ### Pythia C++ Example: Dark Matter Production via S-Channel Mediator Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html Setup (in `main75.cmnd`) for Dark Matter production via an s\-channel mediator, where a mono-jet pT spectrum is found with the FastJet package. ```C++ main75.cc ``` -------------------------------- ### Main program for PYTHIA merging illustration Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main81.html This is the main entry point of the program, illustrating CKKW-L merging. It checks for the correct number of command-line arguments, expecting three: a command file, an LHE event file, and an output file. ```C++ int main( int argc, char* argv[] ){ // Check that correct number of command-line arguments if (argc != 4) { cerr << " Unexpected number of command-line arguments ("< ``` -------------------------------- ### C++ Example: Quarkonia Generation with HelacOnia (main35.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This program demonstrates the generation of quarkonia events by interfacing the external HelacOnia package with Pythia. It also allows for a direct comparison of results obtained from HelacOnia with those from Pythia's internal implementation, facilitating validation and analysis. ```C++ Program: main35.cc Purpose: Generate quarkonia events Integration: External HelacOnia package interfaced with Pythia Functionality: Compare HelacOnia results with Pythia's internal implementation ``` -------------------------------- ### Initialize Pythia Instances Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main300.html This snippet performs the initial setup for all Pythia instances. After all settings, input files, and external PDF pointers have been configured, this loop calls the 'init()' method on each Pythia object, preparing them for event generation. ```C++ for (int i = 0; i < int(pythiaPtr.size()); ++i) { if (i < int(input_file.size()) && input_file[i] != "") pythiaPtr[i]->readFile(input_file[i].c_str()); pythiaPtr[i]->init(); } ``` -------------------------------- ### Configure PYTHIA for ROOT Integration Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ROOTusage.html This command configures the PYTHIA build system to integrate with an existing ROOT installation. It specifies the path to the ROOT installation directory, enabling PYTHIA to use ROOT functionalities for histogramming or event storage. This step is a prerequisite for compiling PYTHIA examples that interact with ROOT. ```bash ./configure --with-root=root-installation-directory ``` -------------------------------- ### pp Collisions with Angantyr Model and Rivet Analysis (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example simulates simple proton-proton (pp) collisions, similar to `main01.cc`, but incorporates the Angantyr model specifically designed for Heavy Ion collisions. It also demonstrates the straightforward setup of Rivet analyses using a dedicated interface. ```C++ Code not provided in input text, refer to examples/main111.html ``` -------------------------------- ### Linking FastJet for W + Jet Production Analysis (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example demonstrates how to link the FastJet jet finding package with Pythia8 to enable analysis of the final state, specifically for studying W + jet production. It showcases the integration of external jet reconstruction tools. ```C++ Code not provided in input text, refer to examples/main71.html ``` -------------------------------- ### C++ PYTHIA8 Main Function: Setup for Onium Production and External Decay Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main17.html The main function initializes PYTHIA8 for charmonium production at LHC energies. It configures phase space, applies a SuppressSmallPT user hook for pT regularization, and registers the custom JpsiDecay handler for external J/psi decays. ```cpp int main() { // Number of events to generate and to list. Max number of errors. int nEvent = 2000; int nList = 2; int nAbort = 5; // Pythia generator. Pythia pythia; // Initialization for charmonium (singlet+octet) production at the LHC. pythia.readString("Charmonium:all = on"); pythia.readString("Beams:eCM = 7000."); // Normally cutoff at pTHat = 1, but push it lower combined with dampening. pythia.readString("PhaseSpace:pTHatMin = 0.5"); pythia.readString("PhaseSpace:pTHatMinDiverge = 0.5"); // Set up to do a user veto and send it in. // First argument: multiplies the pT0 of multiparton interactions // to define the pT dampeing scale. // Second argument: how many powers of alpha_strong to // reweight with new (larger) argument. // Third argument: choice of process scale two different ways; // probably does not make much difference. // See "User Hooks" in manual for detail on SuppressSmallPT. auto oniumUserHook = make_shared( 1., 3, false); pythia.setUserHooksPtr( oniumUserHook); // A class to do J/psi decays externally. DecayHandlerPtr handleDecays = make_shared(&pythia.particleData, &pythia.rndm); // The list of particles the class can handle. vector handledParticles; handledParticles.push_back(443); // Hand pointer and list to Pythia. pythia.setDecayPtr( handleDecays, handledParticles); ``` -------------------------------- ### API: Get Weight Value by Index Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/CrossSectionsAndWeights.html Retrieves the numerical value of a weight at a given index. All weights are synchronized in normalization. For unweighted event generation, the value is relative to the cross section. For weighted events (e.g., LHEFs with weight strategy +-4), the value incorporates the cross section prefactor. Refer to `main44.cc` for examples. ```APIDOC Info::weightValueByIndex(int i) Parameters: i: int - The index of the weight. Returns: double ``` -------------------------------- ### Improve Parton Shower Matching with POWHEG Approach (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example demonstrates an improved matching technique for parton showers with LHEF-style input, utilizing the POWHEG approach. It shows how to configure different matching options via `main31.cmnd` and select input processes like POWHEG-hvq for top pair production or QCD 2+3-jet events, referencing `powheg-hvq.lhe` and `powheg-dijets.lhe` for input samples. ```C++ examples/main31.html ``` -------------------------------- ### Legacy HepMC2 LHEF Subrun Processing (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/SampleMainPrograms.html A legacy HepMC2 example where subruns are used to process several consecutive LHEF files, with information stored, for example, in main44.cmnd. This example mainly serves as a comparison to main45.cc, which uses HepMC3. ```C++ C++ code for legacy HepMC2 LHEF subrun processing. ``` -------------------------------- ### Configure Output Formats (HepMC, Rivet, ROOT, Logging) for Pythia8 (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main93.html This snippet details the setup of various output formats for Pythia8 simulations. It includes initializing HepMC for event record output, configuring Rivet for analysis with dynamic analysis addition, conditionally enabling ROOT output based on compilation flags, and setting up a log file for console output redirection. ```C++ // Read the extra parameters. int nEvent = pythia.mode("Main:numberOfEvents");; if(nev > -1) nEvent = nev; const bool hepmc = pythia.flag("Main:writeHepMC"); const bool root = pythia.flag("Main:writeRoot"); const bool runRivet = pythia.flag("Main:runRivet"); const bool ignoreBeams = pythia.flag("Main:rivetIgnoreBeams"); const bool doLog = pythia.flag("Main:outputLog"); const string rivetrName = pythia.settings.word("Main:rivetRunName"); const vector rAnalyses = pythia.settings.wvec("Main:analyses"); const vector rPreload = pythia.settings.wvec("Main:preload"); int nError = pythia.mode("Main:timesAllowErrors"); bool countErrors = (nError > 0 ? true : false); // HepMC conversion object. HepMC::Pythia8ToHepMC ToHepMC; HepMC::IO_GenEvent* hepmcIO; if (hepmc) hepmcIO = new HepMC::IO_GenEvent((out == "" ? "pythia.hepmc" : out + ".hepmc"),ios::out); // Rivet initialization. Pythia8Rivet rivet(pythia,(out == "" ? "Rivet.yoda" : out + ".yoda")); rivet.ignoreBeams(ignoreBeams); for(int i = 0, N = rAnalyses.size(); i < N; ++i){ string analysis = rAnalyses[i]; size_t pos = analysis.find(":"); // Simple case, no analysis parameters. if(pos == string::npos) rivet.addAnalysis(analysis); else { string an = analysis.substr(0,pos); analysis.erase(0, pos + 1); pos = analysis.find(":"); string par = analysis.substr(0,pos); size_t pos2 = par.find("->"); if (pos2 == string::npos){ cout << "Error in main93: malformed parameter " << par << endl; } string pKey = par.substr(0,pos2); string pVal = par.substr(pos2+2,par.length()); rivet.addAnalysis(an+":"+pKey+"="+pVal); } } for(int i = 0, N = rPreload.size(); i < N; ++i) rivet.addPreload(rPreload[i]); rivet.addRunName(rivetrName); // Root initialization #ifdef PY8ROOT TFile* file; RootEvent* re; TTree* tree; #endif if (root) { // First test if root is available on system. #ifndef PY8ROOT cout << "Option Main::writeRoot = on requires a working,\n" "linked Root installation." << endl; return 1; #else string op = (out == "" ? "pythia.root" : out + ".root"); file = TFile::Open(op.c_str(),"recreate" ); re = new RootEvent(); tree = new TTree("t","Pythia8 event tree"); tree->Branch("events",&re); #endif } // Logfile initialization. ofstream logBuf; std::streambuf* oldCout; if(doLog) { oldCout = cout.rdbuf(logBuf.rdbuf()); logBuf.open((out == "" ? "pythia.log" : out + ".log")); } // Option to trash the splash screen. ostream cnull(NULL); if(ip.hasOption("-l")) cnull << splashBuf.str(); ``` -------------------------------- ### Configure Pythia by reading instructions from a file or stream Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ProgramFlow.html The `Pythia::readFile` method reads instructions from an entire file or an input stream, similar to `readString` but for multiple lines. It supports multiple overloads for file names, input streams, and optional subrun filtering. ```APIDOC bool Pythia::readFile(string fileName, bool warn = true, int subrun = SUBRUNDEFAULT) bool Pythia::readFile(string fileName, int subrun = SUBRUNDEFAULT) bool Pythia::readFile(istream& inStream = cin, bool warn = true, int subrun = SUBRUNDEFAULT) bool Pythia::readFile(istream& inStream = cin, int subrun = SUBRUNDEFAULT) fileName: The file from which instructions are read. inStream: An istream from which instructions are read. warn (default = on): Write a warning message or not whenever the instruction does not make sense. subrun: Allows several optional sets of commands within the same file; only matching sections are read. Returns: bool (false if it fails to make sense out of any one line) ``` -------------------------------- ### C++ Class: Custom MergingHooks for PYTHIA8 Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main82.html This class, `MyMergingHooks`, inherits from PYTHIA8's `MergingHooks` and provides custom functionality for defining the merging scale. It includes a constructor, destructor, and virtual methods for `tmsDefinition` and a helper function `myKTdurham`. The `tmsDefinition` method demonstrates how to count final state coloured particles and use in-built `MergingHooks` functions to get hard process information. ```C++ class MyMergingHooks : public MergingHooks { private: public: // Default constructor MyMergingHooks(); // Destructor ~MyMergingHooks(); // Functional definition of the merging scale virtual double tmsDefinition( const Event& event); // Helper function for tms definition double myKTdurham(const Particle& RadAfterBranch, const Particle& EmtAfterBranch, int Type, double D ); }; //-------------------------------------------------------------------------- // Constructor MyMergingHooks::MyMergingHooks() {} // Destructor MyMergingHooks::~MyMergingHooks() {} //-------------------------------------------------------------------------- // Definition of the merging scale double MyMergingHooks::tmsDefinition( const Event& event){ // Cut only on QCD partons! // Count particle types int nFinalColoured = 0; int nFinalNow =0; for( int i=0; i < event.size(); ++i) { if(event[i].isFinal()){ if(event[i].id() != 23 && abs(event[i].id()) != 24) nFinalNow++; if( event[i].colType() != 0) nFinalColoured++; } } // Use MergingHooks in-built functions to get information on the hard process int nLeptons = nHardOutLeptons(); int nQuarks = nHardOutPartons(); int nResNow = nResInCurrent(); ``` -------------------------------- ### Dynamically Link POWHEGBOX Matrix Element Programs (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example illustrates how to dynamically link POWHEGBOX matrix element programs, eliminating the need for intermediate LHE files. It highlights the use of `LHAPowheg.h` for building POWHEG plugin libraries and `PowhegProcs.h` for loading plugins, with `main33.cmnd` providing necessary run commands. ```text ``` -------------------------------- ### Main Program for PYTHIA Event Generation and Analysis Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main16.html The main entry point for the PYTHIA program. It handles command-line argument parsing for the settings file, initializes the PYTHIA generator, sets up the `MyAnalysis` class, and begins the event loop based on settings from the input file. ```C++ // You should not need to touch the main program: its actions are // determined by the .cmnd file and the rest belongs in MyAnalysis. int main(int argc, char* argv[]) { // Check that correct number of command-line arguments if (argc != 2) { cerr << " Unexpected number of command-line arguments. \n" << " You are expected to provide a file name and nothing else. \n" << " Program stopped! " << endl; return 1; } // Check that the provided file name corresponds to an existing file. ifstream is(argv[1]); if (!is) { cerr << " Command-line file " << argv[1] << " was not found. \n" << " Program stopped! " << endl; return 1; } // Confirm that external file will be used for settings.. cout << " PYTHIA settings will be read from file " << argv[1] << endl; // Declare generator. Read in commands from external file. Pythia pythia; pythia.readFile(argv[1]); // Initialization. pythia.init(); // Declare user analysis class. Do initialization part of it. MyAnalysis myAnalysis; myAnalysis.init(); // Read in number of event and maximal number of aborts. int nEvent = pythia.mode("Main:numberOfEvents"); int nAbort = pythia.mode("Main:timesAllowErrors"); bool hasPL = pythia.flag("PartonLevel:all"); // Begin event loop. ``` -------------------------------- ### C++ Example: VINCIA and Pythia Comparison with OpenMP (main201.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example facilitates a comparison between VINCIA and Pythia for inclusive jet production at the LHC. It includes an option to run both generators in parallel, leveraging OpenMP for improved performance and efficiency in simulations. ```C++ Program: main201.cc Purpose: Compare VINCIA and Pythia for inclusive jets at LHC Parallelization: Option to run generators in parallel using OpenMP ``` -------------------------------- ### Comparing SlowJet and FastJet for QCD Jet Finding (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example compares the jet finding capabilities of SlowJet and FastJet, demonstrating that both algorithms yield identical jets when executed under the same conditions, particularly for QCD jets. It highlights the consistency between different jet finding implementations. ```C++ Code not provided in input text, refer to examples/main72.html ``` -------------------------------- ### Python: Using Pythia.readFile Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ParticleDataScheme.html Example Python code demonstrating how to load configuration settings from an external file using the 'pythia.readFile' method. ```Python pythia.readFile(fileName); ``` -------------------------------- ### Main Example: Initialize and Run Pythia for Internal LO Quarkonia Production Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main35.html This section of the main function initializes the environment for the comparison. It declares the HelacOnia executable path and creates histograms to store results from both Pythia and HelacOnia simulations. It then configures Pythia to produce J/psi particles (charmonium) at leading order (LO) internally, setting the center-of-mass energy, enabling the specific charmonium production process, and applying a minimum pT cut. The 'run' helper function is called to execute this simulation. ```C++ int main() { // The name of the HelacOnia executable. // You must prepend this string with the path to the executable // on your local installation, or otherwise make it available. string exe("ho_cluster"); // Create the histograms. Hist pyPtPsi("Pythia dN/dpT J/psi", 100, 0., 20.); Hist hoPtPsi("HelacOnia dN/dpT J/psi", 100, 0., 20.); // Produce leading-order events with Pythia. Pythia* pythia = new Pythia(); pythia->readString("Beams:eCM = 13000."); pythia->readString("Charmonium:gg2ccbar(3S1)[3S1(1)]g = on,off"); pythia->readString("PhaseSpace:pTHatMin = 2"); run(pythia, pyPtPsi, 1000); delete pythia; ``` -------------------------------- ### HepMC Event Record Output (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/SampleMainPrograms.html Similar to main01, this example outputs the event record in the HepMC event record format. It requires HepMC3 to be properly linked. Note that the hepmcout41.dat output file can become quite big, so no example file is included in this distribution. ```C++ C++ code to output event record in HepMC format. ``` -------------------------------- ### Manage Multiple Pythia Instances for Pileup and Beam-Gas Events (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example shows how to use multiple Pythia instances to simulate signal events alongside a variable number of pileup and "beam-gas" events, combining them into one common event record. It also illustrates how new Pythia instances can copy existing settings and particle data. ```C++ examples/main19.html ``` -------------------------------- ### Pythia C++ Example: Kaluza-Klein Gamma/Z Production Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html Production of Kaluza-Klein gamma/Z states in TeV-sized extra dimensions. ```C++ main27.cc ``` -------------------------------- ### Performing Matching/Merging with Multiple Methods (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example demonstrates how to perform event matching and merging using five different alternative methods: CKKW-L, FxFx, MLM, UMEPS, and UNLOPS. The specific method is selected by reading the corresponding `.cmnd` file (`main89ckkwl.cmnd`, `main89fxfx.cmnd`, `main89mlm.cmnd`, `main89umeps.cmnd`, `main89unlops.cmnd`), showcasing Pythia8's flexibility in merging schemes. ```C++ Code not provided in input text, refer to examples/main89.html ``` -------------------------------- ### APIDOC: Pythia8Plugins::PowhegProcs Class Reference Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/examples/main33.html Detailed API documentation for the `Pythia8Plugins::PowhegProcs` class, covering its constructor parameters and key methods for configuring and initializing the POWHEG matrix element interface within PYTHIA. It also notes how user hooks are managed. ```APIDOC Class: Pythia8Plugins::PowhegProcs Constructor: PowhegProcs(pythia_instance: Pythia*, process_name: string, run_directory: string = "./powhegrun", pdf_filename: string = "", use_pythia_random: bool = true) pythia_instance: Pointer to the Pythia object. process_name: The name of the POWHEG process (e.g., "hvq"). run_directory: (Optional) Path to the POWHEG run directory. Defaults to "./powhegrun". pdf_filename: (Optional) Full name of the PDF file to copy to the run directory if using native PDFs (empty string for LHAPDF). use_pythia_random: (Optional) Boolean indicating whether to use Pythia's random number generator. Defaults to true. Methods: readFile(filename: string) filename: Path to the POWHEG configuration file (e.g., "main33.pwhg"). Purpose: Configures the POWHEG matrix element. Issues a warning if a setting is repeated, using the most recent value. init() Purpose: Must be called before Pythia initialization. Copies POWHEG input and PDF files to the POWHEG run directory. User Hooks: The PowhegProcs class automatically sets Pythia's user hooks to an instance of PowhegHooks. This can be overridden by a user-chosen set of hooks (or null) via `pythia->setUserHooksPtr(userHooksPtr)`. ``` -------------------------------- ### Using FastJet Add-ons for Boosted Z^0 Mass Reconstruction (Pythia8 C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This C++ example illustrates the usage of a contributed add-on to the FastJet package, specifically the modified Mass Drop Tagger. It shows how this add-on can be applied to improve the mass reconstruction of a boosted, hadronically decaying Z^0 boson. ```C++ Code not provided in input text, refer to examples/main74.html ``` -------------------------------- ### Pythia C++ Example: Supersymmetric Particle Production Test Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html Tests of internally implemented cross sections for Supersymmetric particle production, with SUSY spectrum defined in `slha2-example.spc` and settings in `main24.cmnd`. For illustration, an alternative example spectrum is also available, `sps1aWithDecays.spc`, which contains a decay table in SLHA format. ```C++ main24.cc ``` -------------------------------- ### Pythia C++ Example: Large Extra Dimensions/Unparticles Processes Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html Test program for processes in scenarios with large extra dimensions or unparticles. ```C++ main26.cc ``` -------------------------------- ### Pythia C++ Example: Generating Two Hard Interactions per Event Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html Generation of two predetermined hard interactions in each event. ```C++ main09.cc ``` -------------------------------- ### External Photon Flux for Photo-production (C++) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/SampleMainPrograms.html Exemplifies how to provide an external photon flux for photo-production processes. ```C++ C++ code for providing external photon flux for photo-production. ``` -------------------------------- ### C++ Example: Onium Cross Section Regularization and Decays (main17.cc) Source: https://github.com/alisw/pythia8/blob/master/share/Pythia8/htmldoc/ExampleKeywords.html This example showcases two key functionalities: (a) how to utilize UserHooks to regularize onium cross sections as transverse momentum (pT) approaches zero, and (b) how particle decays can be handled externally. It provides insight into advanced control over event generation. ```C++ Program: main17.cc Features: - UserHooks for onium cross section regularization (pT → 0) - External handling of particle decays ```