<chapter name="Matching and Merging"> 
 
<h2>Matching and Merging</h2> 
 
This page first describes the matching and merging capabilitities of 
PYTHIA, and then, below, the use of a somewhat generic example main 
program to produce matched or merged results. 
 
Precision and a wide kinematical coverage are important ingredients 
to the applicability of Event Generators. Both can be aided by including 
higher-order corrections into the Generator. Depending on needs, the 
inclusion of higher orders (on top of a Born-level leading-order (LO) 
process) can be prioritized in different ways: 
<ul> 
<li>A formal order-by-order perturbative calculation, in each order 
higher including graphs both with one particle more in the final 
state and with one loop more in the intermediate state. This is 
accurate to the order of the calculation, and limited to a first- 
or second-order corrections. 
</li> 
<li>Multiple hard real emission corrections, but neglecting the 
virtual corrections that should accompany the corrections. 
Thereby it is possible to allow for topologies with a larger and 
varying number of partons, at the prize of not being accurate to any 
particular order. 
</li> 
<li>The parton shower provides an approximation to higher orders, 
both real and virtual contributions for the emission of arbitrarily 
many particles. 
</li> 
</ul> 
Each of these approaches have drawbacks in complementary phasespace 
regions (the first two not being suitable in soft/collinear emissions 
regions, and thus unsuitable to combine with hadronization, while the third 
fails in hard, well-separated regions), such that many schemes to combine 
the strengths of the different approaches exist. 
 
<p/> 
The common traits of all combination methods are that matrix elements 
are used to describe the production of hard and well separated 
particles, and parton showers for the production of soft or collinear 
particles. What differs between the various approaches that have been 
proposed are which matrix elements are being used, how doublecounting 
is avoided, and how the transition from the hard to the soft regime is 
handled. These combination methods are typically referred to as 
"matching" or "merging" algorithms. There is some confusion about the 
distinction between the two terms. We will use "matching" to describe 
the combination of one (NLO) calculation with the parton shower, and 
"merging" when several calculations are combined with each other (and 
the shower).  PYTHIA offers implementations of several different 
matching and merging algorithms, which hopefully suit most needs. 
 
<ul> 
<li>For many/most resonance decays the first branching in the shower 
is merged with first-order matrix elements <ref>Ben87, 
Nor01</ref>. This means that the emission rate is accurate to NLO, 
similarly to the POWHEG strategy (see below), but built into the 
<aloc href="TimelikeShowers">timelike showers</aloc>. The angular 
orientation of the event after the first emission is only handled by 
the parton shower kinematics, however. Needless to say, this formalism 
is precisely what is tested by <ei>Z^0</ei> decays at LEP1, and it is 
known to do a pretty good job there.</li> 
 
<li>Also the <aloc href="SpacelikeShowers">spacelike showers</aloc> 
contain a correction to first-order matrix elements, but only for the 
one-body-final-state processes <ei>q qbar &rarr; 
gamma^*/Z^0/W^+-/h^0/H^0/A0/Z'0/W'+-/R0</ei> <ref>Miu99</ref> and 
<ei>g g &rarr; h^0/H^0/A0</ei>, and only to leading order. That is, it 
is equivalent to the POWHEG formalism for the real emission, but the 
prefactor "cross section normalization" is LO rather than 
NLO. Therefore this framework is less relevant, and has been 
superseded the following ones.</li> 
 
<li>The POWHEG strategy <ref>Nas04</ref> provides a cross section 
accurate to NLO. The hardest emission is constructed with unit 
probability, based on the ratio of the real-emission matrix element to 
the Born-level cross section, and with a Sudakov factor derived from 
this ratio, i.e. the philosophy introduced in <ref>Ben87</ref>. 
<br/>While POWHEG is a generic strategy, the POWHEG BOX 
<ref>Ali10</ref> is an explicit framework, within which several 
processes are available. The code required for merging the PYTHIA 
showers with POWHEG input can be found in 
<code>include/Pythia8Plugins/PowHegHooks.h</code>, and is further 
described on a <aloc href="POWHEGMerging">separate page</aloc>.  A 
user example is found in <code>examples/main31</code>.</li> 
 
<li>The other traditional approach for NLO calculations is the MC@NLO 
one <ref>Fri02</ref>. In it the shower emission probability, without 
its Sudakov factor, is subtracted from the real-emission matrix 
element to regularize divergences. It therefore requires a analytic 
knowledge of the way the shower populates phase space.  The aMC@NLO 
package <ref>Fre11</ref> offers an implementation for PYTHIA 8, 
developed by Paolo Torrielli and Stefano Frixione. The global-recoil 
option of the PYTHIA final-state shower has been constructed to be 
used for the above-mentioned subtraction.</li> 
 
<li>Multi-jet merging in the CKKW-L approach <ref>Lon01</ref> is 
directly available. Its implementation, relevant parameters and test 
programs are documented on a 
<aloc href="CKKWLMerging">separate page</aloc>.</li> 
 
<li>Multi-jet matching in the MLM approach <ref>Man02, Man07</ref> is 
also available, either based on the ALPGEN or on the Madgraph variant, 
and with input events either from ALPGEN or from Madgraph. For details 
see <aloc href="JetMatching">separate page</aloc>.</li> 
 
<li>Unitarised matrix element + parton shower merging (UMEPS) is 
directly available. Its implementation, relevant parameters and test 
programs are documented on a 
<aloc href="UMEPSMerging">separate page</aloc>.</li> 
 
<li>Next-to-leading order multi-jet merging (in the NL3 and UNLOPS 
approaches) is directly available. Its implementation, relevant 
parameters and test programs are documented on a 
<aloc href="NLOMerging">separate page</aloc>.</li> 
 
<li>Next-to-leading order jet matching in the FxFx approach is also 
available. For details see 
<aloc href="JetMatching">the jet matching page</aloc>.</li> 
</ul> 
 
<p/> 
For quick-and-dirty studies, note that the field is 
open-ended, however: any external program can feed in 
<aloc href="LHEF">Les Houches events</aloc> that 
PYTHIA subsequently processes. In this case, the maximum <ei>pT</ei> of the 
shower evolution is set by the Les Houches <code>scale</code>, on the one 
hand, and by the values of the <code>SpaceShower:pTmaxMatch</code>, 
<code>TimeShower:pTmaxMatch</code> and other parton-shower settings, 
on the other. It is typically not possible to achieve perfect 
matching this simplistic way, given that the PYTHIA <ei>pT</ei> evolution 
variables are not likely to agree with the variables used for cuts 
in the external program. Often one can get close enough with simple 
means but, for an improved matching, 
<aloc href="UserHooks">User Hooks</aloc> may be inserted to control 
the steps taken on the way, e.g. to veto those parton shower 
branchings that would doublecount emissions included in the matrix 
elements. 
 
<br/><hr/> 
<h3>main89.cc: A generic interface for matching and merging</h3> 
 
A common Pythia main program for MC@NLO NLO+PS matching, MLM jet merging, 
FxFx (NLO) jet merging, CKKW-L merging, UMEPS merging and UNLOPS (NLO) 
merging is available through <code>main89.cc</code>, together with the input 
files <code>main89mlm.cmnd</code>, <code>main89fxfx.cmnd</code>, 
<code>main89ckkwl.cmnd</code>, <code>main89umeps.cmnd</code> and 
<code>main89unlops.cmnd</code>. The interface to MLM jet matching relies 
on MadGraph, while all other options of <code>main89.cc</code> use aMC@NLO 
input. 
 
<code>main89.cc</code> produces HepMC events <ref>Dob01</ref>, that can be 
histogrammed (e.g. using RIVET <ref>Buc10</ref>), or used as input for a 
detector simulation. If the user is not familiar with HepMC analysis tools, it 
is possible to instead use Pythia's histogramming routines. For this, remove 
the lines referring to HepMC, and histogram events as illustrated (for CKKW-L) 
for the histogram <ei>histPTFirstSum</ei> in <code>main84.cc</code>, i.e. 
using <ei>weight*normhepmc</ei> as weight. 
 
<p/> 
All settings can be transferred to <code>main89.cc</code> through an input 
file. The input file is part of the command line input of 
<code>main89.cc</code>, i.e. you can execute <code>main89</code> with the 
command 
<p/> 
<code>./main89 myInputFile.cmnd myhepmc.hepmc</code> 
<p/> 
 
to read the input <code>myInputFile.cmnd</code> and produce the output file 
<code>myhepmc.hepmc</code> . Since <code>main89.cc</code> is currently a 
"front-end" for different types of matching/merging, we will briefly discuss 
the inputs for this sample program in the following. 
 
<h4>Inputs</h4> 
 
In its current form, <code>main89.cc</code> uses LHEF input to transfer 
(weighted) phase space points to Pythia. It is possible to include all 
parton multiplicities in one LHEF sample. If e.g. UMEPS merging for 
W-boson + up to two additional partons is to be performed, one LHE file 
containing W+zero, W+one and W+two parton events is required. 
 
<p/> 
All input settings are handed to <code>main89.cc</code> in the form of an 
input file. We have included the input settings files 
<p/> 
 &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; <code>main89mlm.cmnd</code>, which 
illustrates the MLM jet matching interface, 
<p/> 
 &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; <code>main89ckkwl.cmnd</code>, which 
illustrates the CKKW-L multi-jet merging interface, 
<p/> 
 &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;  <code>main89umeps.cmnd</code>, which 
illustrates the UMEPS multi-jet merging interface, and 
 <p/> 
 &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; <code>main89fxfx.cmnd</code>, which 
illustrates the FxFx NLO jet matching interface, 
<p/> 
 &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;  <code>main89unlops.cmnd</code>, which 
illustrates the UNLOPS multi-jet NLO merging interface. 
<p/> 
Other settings (e.g. using <code>main89.cc</code> as simple LO+PS or as MC@NLO 
interface) are of course possible. In the following, we will briefly explain 
how input for the five choices above are generated and handled. 
 
<h4>MLM jet matching with main89.cc</h4> 
 
For MLM jet matching, <code>main89.cc</code> currently relies on LHEF input 
from MadGraph. Due to the particular unweighting strategy performed in the 
generation of these inputs, the sample program starts by estimating the 
cross section. After this estimate, MLM jet matching within the Madgraph 
approach is performed in a second Pythia run. Example MLM settings can be 
found in <code>main89mlm.cmnd</code>. Please consult 
<aloc href="JetMatching">Jet Matching</aloc> for more details. 
 
<h4>CKKW-L merging with main89.cc</h4> 
 
For CKKW-L merging, <code>main89.cc</code> currently relies on LHEF inputs 
generated with the leading-order mode of aMC@NLO (i.e. events should 
be generated with <code>./bin/generate_events aMC@LO</code>). 
No run to estimate the cross section estimate is needed. Example CKKW-L 
settings can be found in <code>main89ckkwl.cmnd</code>. Please consult 
<aloc href="CKKWLMerging">CKKW-L merging</aloc> for more details. 
 
<h4>UMEPS merging with main89.cc</h4> 
 
For UMEPS merging, <code>main89.cc</code> currently relies on LHEF inputs 
generated with the leading-order mode of aMC@NLO as well (see above). 
<code>main89.cc</code> automatically assigns if an event will be used as 
"standard" event or as "subtractive" contribution. Example UMEPS 
settings can be found in <code>main89umeps.cmnd</code>. Please 
consult <aloc href="UMEPSMerging">UMEPS merging</aloc> and 
<aloc href="CKKWLMerging">CKKW-L merging</aloc> for more details. 
 
<h4>FxFx (NLO) jet matching with main89.cc</h4> 
 
For FxFx jet matching, <code>main89.cc</code> relies on MC@NLO input LHE 
files generated with aMC@NLO. To produce FxFx outputs in aMC@NLO, the settings 
<code>PYTHIA8  = parton_shower</code>, <code>3 = ickkw</code> and 
<code>x = ptj</code> are necessary in your aMC@NLO run card. Here, 
<code>x</code> is the value of the matching scale in FxFx, i.e. has be 
identical to <code>JetMatching:qCutME</code> in the Pythia inputs. 
Example FxFx settings for Pythia can be found in <code>main89fxfx.cmnd</code>. 
Please consult <aloc href="JetMatching">Jet Matching</aloc> and 
<aloc href="aMCatNLOMatching">aMC@NLO matching</aloc> for more details. 
 
 
<h4>UNLOPS (NLO) merging with main89.cc</h4> 
 
For UNLOPS merging, <code>main89.cc</code> currently relies on LHEF inputs 
generated with the aMC@NLO. The UNLOPS interface in <code>main89.cc</code> 
requires a) leading-order inputs generated with the leading-order mode of 
aMC@NLO, using the UNLOPS prescription, and b) next-to-leading-order inputs 
generated with the NLO mode of aMC@NLO, using the UNLOPS prescription. 
To produce UNLOPS outputs in aMC@NLO, the settings 
<code>PYTHIA8  = parton_shower</code>, <code>4 = ickkw</code> and 
<code>x = ptj</code> are necessary in your aMC@NLO run card. Here, 
<code>x</code> is the value of the merging scale in UNLOPS, i.e. 
has be identical to <code>Merging:TMS</code> in the Pythia inputs. 
<code>main89.cc</code> will then process NLO inputs and LO inputs 
consecutively, and will automatically assign if an event will be used as 
"standard" event or as "subtractive" contribution. Example UNLOPS 
settings can be found in <code>main89umeps.cmnd</code>. Please 
consult <aloc href="UNLOPSMerging">UMEPS merging</aloc> and 
<aloc href="CKKWLMerging">CKKW-L merging</aloc> for more details. 
 
</chapter> 
 
<!-- Copyright (C) 2020 Torbjorn Sjostrand --> 
