## RIVET usage

RIVET is a toolkit for the validation of Monte Carlo event generators [Buc10]. It contains the results of many experimental analyses, so that generator output can easily be compared to data, as well as providing a framework to implement your own analyses. Although using PYTHIA with RIVET is not officially supported, some helpful hints are given below. The full RIVET manual is available online.

### PYTHIA with RIVET via plugin

A PYTHIA plugin is available, `RivetHooks` defined in `Pythia8Plugins/RivetHooks.h`. This plugin can be loaded, and analyses can then be easily added for processing. The plugin works with `PythiaParallel`, and RIVET analyses can be run asynchronously. For the plugin to be available, PYTHIA must be configured with the `--with-rivet` flag before being built.

      ./configure --with-rivet

If successful, the plugin library `lib/pythia8rivet.so` will be built. This requires the RIVET configuration to be available via the `rivet-config` command and is only available for RIVET 4.

There are a number of examples which show how to work with this plugin: `main144`, `main164`, `main225`, and `main421`. The general usage is as follows. First, load the plugin.

      Init:plugins = {libpythia8rivet.so::RivetHooks}

None of the options described below is available if the plugin is not successfully loaded. Once the plugin is loaded, a number of additional settings will be available. To begin, set the output YODA file name; it must end in `.yoda` (this is a RIVET requirement, not PYTHIA).

      Rivet:fileName = NAME

If directory structure is included in the YODA file name, an attempt will be made to create that directory structure.

Next, define the analyses to run. This can be done with comma separated lists, `{ANALYSIS1,ANALYSIS2,ANALYSIS3,...}`. The list of analyses can be appended with the `+=` syntax.

      Rivet:analyses  = {ANALYSIS1,ANALYSIS2}
      Rivet:analyses += {ANALYSIS3}

Parameters for each analysis can be modified using the following syntax.

      Rivet:analyses = {ANALYSIS1:PARM1=VALUE1:PARM2=VALUE2:...,ANALYSIS2}

Finally, set any additional configuration for RIVET.

      ! This is a list of YODA files which can be preloaded.
      Rivet:preloads = {YODA1,YODA2,YODA3,...}
      ! This is a temporary debugging output filename, which must end with .yoda.
      Rivet:dumpName = NAME
      ! If NUMBER > 0, dump RIVET output to Rivet:dumpName every NUMBER events.
      Rivet:dumpPeriod = NUMBER
      ! Flag to require RIVET to check the beam configuration.
      Rivet:checkBeams = off
      ! By default, zero weight events are skipped for analysis.
      Rivet:skipZeroWeights = on

### Using PYTHIA with RIVET via HEPMC

The following assumes that you already have RIVET installed. Instructions for this may be found here.
Events are passed from PYTHIA to RIVET using the HepMC format. PYTHIA must be compiled with HepMC support, using the same version of HepMC used when compiling RIVET. This is setup through the PYTHIA `configure` script e.g.

      ./configure --with-hepmc=/path/to/HepMC

The PYTHIA library itself does not need to be recompiled.
The `examples/main132.cc` sample program can then be used to generate events in HepMC format (which `examples/main133.cc` extends by allowing subruns). When in the `examples` directory, the main program can be built and used as follows

      make main132
      ./main132 main132.cmnd main132.hepmc

The first argument is the input file which provides the options for event generation, while the second is the output file where the HepMC events should be written.
This HepMC file may now be read and processed by RIVET

      rivet --analysis=ANALYSIS_NAME main132.hepmc

where `ANALYSIS_NAME` is a built-in RIVET analysis, or one you have created yourself. The output of RIVET is in the form of `.aida` files, containing the histograms for the analysis, which can be processed further with RIVET (see the RIVET documentation for more details).
The above examples requires that (potentially large) HepMC events are stored to disk before being read by RIVET. It is possible, instead, to pass the events directly to RIVET as they are produced by using a `FIFO` pipe. This is done with the `mkfifo` command

      mkfifo my_fifo
      ./main132.exe main132.cmnd my_fifo &
      rivet --analysis=ANALYSIS_NAME my_fifo

Note that `main132` is run in the background.

### Compiling PYTHIA with RIVET

It is also possible to compile a PYTHIA main program together with the RIVET library. To facilitate this, there is a header file called `Pythia8Plugins/Pythia8Rivet.h` defining a helper class called `Pythia8::Pythia8Rivet`. This header class has been deprecated in favor of the plugin structure above, and will be removed in a future version of PYTHIA. To use this class, a main program needs to be modified as follows:

      #include "Pythia8/Pythia.h"

      // Include the Pythia8Rivet header file.
      #include "Pythia8Plugins/Pythia8Rivet.h"

      int main() {

        Pythia pythia;

        // Setup the run by reading strings or a command file.

        pythia.init();

        // Create a Pythia8Rivet object and add (one or several) analyses.

        Pythia8Rivet rivet(pythia, "outputfile.yoda");
        rivet.addAnalysis("AnalysisName");
        rivet.addAnalysis("AnotherAnalysisName");

        for (int iEvent = 0; iEvent < 100; ++iEvent) {
          if (!pythia.next()) continue;

          // Push event to Rivet.
          rivet();

          // Maybe do other non-Rivet analysis.
        }

        // Tell Rivet to finalise the run.
        rivet.done();

      }

To compile the program, information about where Rivet and its dependencies are installed is needed. This information is available via the `rivet-config` script via the following.

      rivet-config --includedir --libdir --cppflags --libs