<chapter name="Event Analysis"> 
 
<h2>Event Analysis</h2> 
 
<h3>Introduction</h3> 
 
The routines in this section are intended to be used to analyze 
event properties. As such they are not part of the main event 
generation chain, but can be used in comparisons between Monte 
Carlo events and real data. They are rather free-standing, but 
assume that input is provided in the PYTHIA 8 
<code>Event</code> format, and use a few basic facilities such 
as four-vectors. Their ordering is mainly by history; for current 
LHC applications the final one, <code>SlowJet</code>, is of 
special interest. 
 
<p/> 
In addition to the methods presented here, there is also the 
possibility to make use of <aloc href="JetFinders">external 
jet finders </aloc>. 
 
<h3>Sphericity</h3> 
 
The standard sphericity tensor is 
<eq> 
    S^{ab} = (sum_i p_i^a p_i^b) / (sum_i p_i^2) 
</eq> 
where the <ei>sum i</ei> runs over the particles in the event, 
<ei>a, b = x, y, z,</ei> and <ei>p</ei> without such an index is 
the absolute size of the three-momentum . This tensor can be 
diagonalized to find eigenvalues and eigenvectors. 
 
<p/> 
The above tensor can be generalized by introducing a power 
<ei>r</ei>, such that 
<eq> 
    S^{ab} = (sum_i p_i^a p_i^b p_i^{r-2}) / (sum_i p_i^r) 
</eq> 
In particular, <ei>r = 1</ei> gives a linear dependence on momenta 
and thus a collinear safe definition, unlike sphericity. 
 
<p/> 
To do sphericity analyses you have to set up a <code>Sphericity</code> 
instance, and then feed in events to it, one at a time. The results 
for the latest event are available as output from a few methods. 
 
<method name="Sphericity::Sphericity(double power = 2., int select = 2)"> 
create a sphericity analysis object, where 
<argument name="power" default="2."> 
is the power <ei>r</ei> defined above, i.e. 
<argoption value="2.">gives Sphericity, and</argoption> 
<argoption value="1.">gives the linear form.</argoption> 
</argument> 
<argument name="select" default="2"> 
tells which particles are analyzed, 
<argoption value="1">all final-state particles,</argoption> 
<argoption value="2">all observable final-state particles, 
i.e. excluding neutrinos and other particles without strong or 
electromagnetic interactions (the <code>isVisible()</code> 
particle method), and 
</argoption> 
<argoption value="3">only charged final-state particles.</argoption> 
</argument> 
</method> 
 
<method name="bool Sphericity::analyze( const Event& event)"> 
perform a sphericity analysis, where 
<argument name="event">is an object of the <code>Event</code> class, 
most likely the <code>pythia.event</code> one. 
</argument> 
<br/>If the routine returns <code>false</code> the 
analysis failed, e.g. if too few particles are present to analyze. 
</method> 
 
<p/> 
After the analysis has been performed, a few methods are available 
to return the result of the analysis of the latest event: 
 
<method name="double Sphericity::sphericity()"> 
gives the sphericity (or equivalent if <ei>r</ei> is not 2), 
</method> 
 
<method name="double Sphericity::aplanarity()"> 
gives the aplanarity (with the same comment), 
</method> 
 
<method name="double Sphericity::eigenValue(int i)"> 
gives one of the three eigenvalues for <ei>i</ei> = 1, 2 or 3, in 
descending order, 
</method> 
 
<method name="Vec4 Sphericity::eventAxis(int i)"> 
gives the matching normalized eigenvector, as a <code>Vec4</code> 
with vanishing time/energy component. 
</method> 
 
<method name="void Sphericity::list()"> 
provides a listing of the above information. 
</method> 
 
<p/> 
There is also one method that returns information accumulated for all 
the events analyzed so far. 
 
<method name="int Sphericity::nError()"> 
tells the number of times <code>analyze(...)</code> failed to analyze 
events, i.e. returned <code>false</code>. 
</method> 
 
<h3>Thrust</h3> 
 
Thrust is obtained by varying the thrust axis so that the longitudinal 
momentum component projected onto it is maximized, and thrust itself is 
then defined as the sum of absolute longitudinal momenta divided by 
the sum of absolute momenta. The major axis is found correspondingly 
in the plane transverse to thrust, and the minor one is then defined 
to be transverse to both. Oblateness is the difference between the major 
and the minor values. 
 
<p/> 
The calculation of thrust is more computer-time-intensive than e.g. 
linear sphericity, introduced above, and has no specific advantages except 
historical precedent. In the PYTHIA 6 implementation the search was 
sped up at the price of then not being guaranteed to hit the absolute 
maximum. The current implementation studies all possibilities, but at 
the price of being slower, with time consumption for an event with 
<ei>n</ei> particles growing like <ei>n^3</ei>. 
 
<p/> 
To do thrust analyses you have to set up a <code>Thrust</code> 
instance, and then feed in events to it, one at a time. The results 
for the latest event are available as output from a few methods. 
 
<method name="Thrust::Thrust(int select = 2)"> 
create a thrust analysis object, where 
<argument name="select" default="2"> 
tells which particles are analyzed, 
<argoption value="1">all final-state particles,</argoption> 
<argoption value="2">all observable final-state particles, 
i.e. excluding neutrinos and other particles without strong or 
electromagnetic interactions (the <code>isVisible()</code> 
particle method), and 
</argoption> 
<argoption value="3">only charged final-state particles.</argoption> 
</argument> 
</method> 
 
<method name="bool Thrust::analyze( const Event& event)"> 
perform a thrust analysis, where 
<argument name="event">is an object of the <code>Event</code> class, 
most likely the <code>pythia.event</code> one. 
</argument> 
<br/>If the routine returns <code>false</code> the 
analysis failed, e.g. if too few particles are present to analyze. 
</method> 
 
<p/> 
After the analysis has been performed, a few methods are available 
to return the result of the analysis of the latest event: 
 
<method name="double Thrust::thrust()"> 
</method> 
<methodmore name="double Thrust::tMajor()"> 
</methodmore> 
<methodmore name="double Thrust::tMinor()"> 
</methodmore> 
<methodmore name="double Thrust::oblateness()"> 
gives the thrust, major, minor and oblateness values, respectively, 
</methodmore> 
 
<method name="Vec4 Thrust::eventAxis(int i)"> 
gives the matching normalized event-axis vectors, for <ei>i</ei> = 1, 2 or 3 
corresponding to thrust, major or minor, as a <code>Vec4</code> with 
vanishing time/energy component. 
</method> 
 
<method name="void Thrust::list()"> 
provides a listing of the above information. 
</method> 
 
<p/> 
There is also one method that returns information accumulated for all 
the events analyzed so far. 
 
<method name="int Thrust::nError()"> 
tells the number of times <code>analyze(...)</code> failed to analyze 
events, i.e. returned <code>false</code>. 
</method> 
 
<h3>ClusterJet</h3> 
 
<code>ClusterJet</code> (a.k.a. <code>LUCLUS</code> and 
<code>PYCLUS</code>) is a clustering algorithm of the type used for 
analyses of <ei>e^+e^-</ei> events, see the PYTHIA 6 manual. All 
visible particles in the events are clustered into jets. A few options 
are available for some well-known distance measures. Cutoff 
distances can either be given in terms of a scaled quadratic quantity 
like <ei>y = pT^2/E^2</ei> or an unscaled linear one like <ei>pT</ei>. 
 
<p/> 
Note that we have deliberately chosen not to include the <ei>e^+e^-</ei> 
equivalents of the Cambridge/Aachen and anti-<ei>kRT</ei> algorithms. 
These tend to be good at clustering the densely populated (in angle) 
cores of jets, but less successful for the sparsely populated transverse 
regions, where many jets may come to consist of a single low-momentum 
particle. In hadron collisions such jets could easily be disregarded, 
while in <ei>e^+e^-</ei> annihilation all particles derive back from the 
hard process. 
 
<p/> 
To do jet finding analyses you have to set up a <code>ClusterJet</code> 
instance, and then feed in events to it, one at a time. The results 
for the latest event are available as output from a few methods. 
 
<method name="ClusterJet::ClusterJet(string measure = &quot;Lund&quot;, 
int select = 2, int massSet = 2, bool precluster = false, 
bool reassign = false)"> 
create a <code>ClusterJet</code> instance, where 
<argument name="measure" default="&quot;Lund&quot;">distance measure, 
to be provided as a character string (actually, only the first character 
is necessary) 
<argoption value="&quot;Lund&quot;">the Lund <ei>pT</ei> distance, 
</argoption> 
<argoption value="&quot;JADE&quot;">the JADE mass distance, and 
</argoption> 
<argoption value="&quot;Durham&quot;">the Durham <ei>kT</ei> measure. 
</argoption> 
</argument> 
<argument name="select" default="2"> 
tells which particles are analyzed, 
<argoption value="1">all final-state particles,</argoption> 
<argoption value="2">all observable final-state particles, 
i.e. excluding neutrinos and other particles without strong or 
electromagnetic interactions (the <code>isVisible()</code> particle 
method), and 
</argoption> 
<argoption value="3">only charged final-state particles.</argoption> 
</argument> 
<argument name="massSet" default="2">masses assumed for the particles 
used in the analysis 
<argoption value="0">all massless,</argoption> 
<argoption value="1">photons are massless while all others are 
assigned the <ei>pi+-</ei> mass, and 
</argoption> 
<argoption value="2">all given their correct masses.</argoption> 
</argument> 
<argument name="precluster" default="off"> 
perform or not a early preclustering step, where nearby particles 
are lumped together so as to speed up the subsequent normal clustering. 
</argument> 
<argument name="reassign" default="off"> 
reassign all particles to the nearest jet each time after two jets 
have been joined. 
</argument> 
</method> 
 
<method name="ClusterJet::analyze( const Event& event, double yScale, 
double pTscale, int nJetMin = 1, int nJetMax = 0)"> 
performs a jet finding analysis, where 
<argument name="event">is an object of the <code>Event</code> class, 
most likely the <code>pythia.event</code> one. 
</argument> 
<argument name="yScale"> 
is the cutoff joining scale, below which jets are joined. Is given 
in quadratic dimensionless quantities. Either <code>yScale</code> 
or <code>pTscale</code> must be set nonvanishing, and the larger of 
the two dictates the actual value. 
</argument> 
<argument name="pTscale"> 
is the cutoff joining scale, below which jets are joined. Is given 
in linear quantities, such as <ei>pT</ei> or <ei>m</ei> depending on 
the measure used, but always in units of GeV. Either <code>yScale</code> 
or <code>pTscale</code> must be set nonvanishing, and the larger of 
the two dictates the actual value. 
</argument> 
<argument name="nJetMin" default="1"> 
the minimum number of jets to be reconstructed. If used, it can override 
the <code>yScale</code> and <code>pTscale</code> values. 
</argument> 
<argument name="nJetMax" default="0"> 
the maximum number of jets to be reconstructed. Is not used if below 
<code>nJetMin</code>. If used, it can override the <code>yScale</code> 
and <code>pTscale</code> values. Thus e.g. 
<code>nJetMin = nJetMax = 3</code> can be used to reconstruct exactly 
3 jets. 
</argument> 
<br/>If the routine returns <code>false</code> the analysis failed, 
e.g. because the number of particles was smaller than the minimum number 
of jets requested. 
</method> 
 
<p/> 
After the analysis has been performed, a few <code>ClusterJet</code> 
class methods are available to return the result of the analysis: 
 
<method name="int ClusterJet::size()"> 
gives the number of jets found, with jets numbered 0 through 
<code>size() - 1</code>. 
</method> 
 
<method name="Vec4 ClusterJet::p(int i)"> 
gives a <code>Vec4</code> corresponding to the four-momentum defined by 
the sum of all the contributing particles to the <ei>i</ei>'th jet. 
</method> 
 
<method name="int ClusterJet::mult(int i)"> 
the number of particles that have been clustered into the <ei>i</ei>'th jet. 
</method> 
 
<method name="int ClusterJet::jetAssignment(int i)"> 
gives the index of the jet that the particle <ei>i</ei> of the event 
record belongs to, 
</method> 
 
<method name="void ClusterJet::list()"> 
provides a listing of the reconstructed jets. 
</method> 
 
<method name="int ClusterJet::distanceSize()"> 
the number of most recent clustering scales that have been stored 
for readout with the next method. Normally this would be five, 
but less if fewer clustering steps occurred. 
</method> 
 
<method name="double ClusterJet::distance(int i)"> 
clustering scales, with <code>distance(0)</code> being the most 
recent one, i.e. normally the highest, up to <code>distance(4)</code> 
being the fifth most recent. That is, with <ei>n</ei> being the final 
number of jets, <code>ClusterJet::size()</code>, the scales at which 
<ei>n+1</ei> jets become <ei>n</ei>, <ei>n+2</ei> become <ei>n+1</ei>, 
and so on till <ei>n+5</ei> become <ei>n+4</ei>. Nonexisting clustering 
scales are returned as zero. The physical interpretation of a scale is 
as provided by the respective distance measure (Lund, JADE, Durham). 
</method> 
 
<p/> 
There is also one method that returns information accumulated for all 
the events analyzed so far. 
 
<method name="int ClusterJet::nError()"> 
tells the number of times <code>analyze(...)</code> failed to analyze 
events, i.e. returned <code>false</code>. 
</method> 
 
<h3>CellJet</h3> 
 
<code>CellJet</code> (a.k.a. <code>PYCELL</code>) is a simple cone jet 
finder in the UA1 spirit, see the PYTHIA 6 manual. It works in an 
<ei>(eta, phi, eT)</ei> space, where <ei>eta</ei> is pseudorapidity, 
<ei>phi</ei> azimuthal angle and <ei>eT</ei> transverse energy. 
It will draw cones in <ei>R = sqrt(Delta-eta^2 + Delta-phi^2)</ei> 
around seed cells. If the total <ei>eT</ei> inside the cone exceeds 
the threshold, a jet is formed, and the cells are removed from further 
analysis. There are no split or merge procedures, so later-found jets 
may be missing some of the edge regions already used up by previous 
ones. Not all particles in the event are assigned to jets; leftovers 
may be viewed as belonging to beam remnants or the underlying event. 
It is not used by any experimental collaboration, but is closely 
related to the more recent and better theoretically motivated 
anti-<ei>kT</ei> algorithm <ref>Cac08</ref>. 
 
<p/> 
To do jet finding analyses you have to set up a <code>CellJet</code> 
instance, and then feed in events to it, one at a time. Especially note 
that, if you want to use the options where energies are smeared in 
order so emulate detector imperfections, you must hand in an external 
random number generator, preferably the one residing in the 
<code>Pythia</code> class. The results for the latest event are 
available as output from a few methods. 
 
<method name="CellJet::CellJet(double etaMax = 5., int nEta = 50, 
int nPhi = 32, int select = 2, int smear = 0, double resolution = 0.5, 
double upperCut = 2., double threshold = 0., Rndm* rndmPtr = 0)"> 
create a <code>CellJet</code> instance, where 
<argument name="etaMax" default="5."> 
the maximum +-pseudorapidity that the detector is assumed to cover. 
</argument> 
<argument name="nEta" default="50"> 
the number of equal-sized bins that the <ei>+-etaMax</ei> range 
is assumed to be divided into. 
</argument> 
<argument name="nPhi" default="32"> 
the number of equal-sized bins that the <ei>phi</ei> range 
<ei>+-pi</ei> is assumed to be divided into. 
</argument> 
<argument name="select" default="2"> 
tells which particles are analyzed, 
<argoption value="1">all final-state particles,</argoption> 
<argoption value="2">all observable final-state particles, 
i.e. excluding neutrinos and other particles without strong or 
electromagnetic interactions (the <code>isVisible()</code> particle 
method), 
and</argoption> 
<argoption value="3">only charged final-state particles.</argoption> 
</argument> 
<argument name="smear" default="0"> 
strategy to smear the actual <ei>eT</ei> bin by bin, 
<argoption value="0">no smearing,</argoption> 
<argoption value="1">smear the <ei>eT</ei> according to a Gaussian 
with width <ei>resolution * sqrt(eT)</ei>, with the Gaussian truncated 
at 0 and <ei>upperCut * eT</ei>,</argoption> 
<argoption value="2">smear the <ei>e = eT * cosh(eta)</ei> according 
to a Gaussian with width <ei>resolution * sqrt(e)</ei>, with the 
Gaussian truncated at 0 and <ei>upperCut * e</ei>.</argoption> 
</argument> 
<argument name="resolution" default="0.5"> 
see above. 
</argument> 
<argument name="upperCut" default="2."> 
see above. 
</argument> 
<argument name="threshold" default="0 GeV"> 
completely neglect all bins with an <ei>eT &lt; threshold</ei>. 
</argument> 
<argument name="rndmPtr" default="0"> 
the random-number generator used to select the smearing described 
above. Must be handed in for smearing to be possible. If your 
<code>Pythia</code> class instance is named <code>pythia</code>, 
then <code>&pythia.rndm</code> would be the logical choice. 
</argument> 
</method> 
 
<method name="bool CellJet::analyze( const Event& event, 
double eTjetMin = 20., double coneRadius = 0.7, double eTseed = 1.5)"> 
performs a jet finding analysis, where 
<argument name="event">is an object of the <code>Event</code> class, 
most likely the <code>pythia.event</code> one. 
</argument> 
<argument name="eTjetMin" default="20. GeV"> 
is the minimum transverse energy inside a cone for this to be 
accepted as a jet. 
</argument> 
<argument name="coneRadius" default="0.7"> 
 is the size of the cone in <ei>(eta, phi)</ei> space drawn around 
the geometric center of the jet. 
</argument> 
<argument name="eTseed" default="1.5 GeV"> 
the minimum <ei>eT</ei> in a cell for this to be acceptable as 
the trial center of a jet. 
</argument> 
<br/>If the routine returns <code>false</code> the analysis failed, 
but currently this is not foreseen ever to happen. 
</method> 
 
<p/> 
After the analysis has been performed, a few <code>CellJet</code> 
class methods are available to return the result of the analysis: 
 
<method name="int CellJet::size()"> 
gives the number of jets found, with jets numbered 0 through 
<code>size() - 1</code>, 
</method> 
 
<method name="double CellJet::eT(int i)"> 
gives the <ei>eT</ei> of the <ei>i</ei>'th jet, where jets have been 
ordered with decreasing <ei>eT</ei> values, 
</method> 
 
<method name="double CellJet::etaCenter(int i)"> 
</method> 
<methodmore name="double CellJet::phiCenter(int i)"> 
gives the <ei>eta</ei> and <ei>phi</ei> coordinates of the geometrical 
center of the <ei>i</ei>'th jet, 
</methodmore> 
 
<method name="double CellJet::etaWeighted(int i)"> 
</method> 
<methodmore name="double CellJet::phiWeighted(int i)"> 
gives the <ei>eta</ei> and <ei>phi</ei> coordinates of the 
<ei>eT</ei>-weighted center of the <ei>i</ei>'th jet, 
</methodmore> 
 
<method name="int CellJet::multiplicity(int i)"> 
gives the number of particles clustered into the <ei>i</ei>'th jet, 
</method> 
 
<method name="Vec4 CellJet::pMassless(int i)"> 
gives a <code>Vec4</code> corresponding to the four-momentum defined 
by the <ei>eT</ei> and the weighted center of the <ei>i</ei>'th jet, 
</method> 
 
<method name="Vec4 CellJet::pMassive(int i)"> 
gives a <code>Vec4</code> corresponding to the four-momentum defined by 
the sum of all the contributing cells to the <ei>i</ei>'th jet, where 
each cell contributes a four-momentum as if all the <ei>eT</ei> is 
deposited in the center of the cell, 
</method> 
 
<method name="double CellJet::m(int i)"> 
gives the invariant mass of the <ei>i</ei>'th jet, defined by the 
<code>pMassive</code> above, 
</method> 
 
<method name="void CellJet::list()"> 
provides a listing of the above information (except <code>pMassless</code>, 
for reasons of space). 
</method> 
 
<p/> 
There is also one method that returns information accumulated for all 
the events analyzed so far. 
<method name="int CellJet::nError()"> 
tells the number of times <code>analyze(...)</code> failed to analyze 
events, i.e. returned <code>false</code>. 
</method> 
 
<h3>SlowJet</h3> 
 
<code>SlowJet</code> is a simple program for doing jet finding according 
to either of the <ei>kT</ei>, anti-<ei>kT</ei>, and Cambridge/Aachen 
algorithms, in a cylindrical coordinate frame. The name is obviously 
an homage to the <code>FastJet</code> program <ref>Cac06, Cac12</ref>. 
That package contains many more algorithms, with many more options, 
and, above all, is <i>much</i> faster. Therefore <code>SlowJet</code> 
is not so much intended for massive processing of data or Monte Carlo 
files as for simple first tests. Nevertheless, within the advertised 
capabilities of <code>SlowJet</code>, it has been checked to find 
identically the same jets as <code>FastJet</code>. The time consumption 
typically is around or below that to generate an LHC <ei>pp</ei> event 
in the first place, so is not prohibitive. But the time rises rapidly 
for large multiplicities, so obviously <code>SlowJet</code> can not 
be used for tricks like distributing a dense grid of pseudoparticles 
to be able to define jet areas, like <code>FastJet</code> can, and also 
not for events with much pileup or other noise. 
 
<p/> 
The recent introduction of <code>fjcore</code>, containing the core 
functionality of <code>FastJet</code> in a very much smaller package, 
has changed the conditions. It now is possible (even encouraged by the 
authors) to distribute the two <code>fjcore</code> files as part of the 
PYTHIA package. Therefore the <code>SlowJet</code> class doubles as a 
convenient front end to <code>fjcore</code>, managing the conversion 
back and forth between PYTHIA and <code>FastJet</code> variables. Some 
applications may still benefit from using the native codes, but the default 
now is to let <code>SlowJet</code> call on <code>fjcore</code> for the 
jet finding. 
 
<p/> 
The first step is to decide which particles should be included in the 
analysis, and with what four-momenta. The <code>SlowJet</code> constructor 
allows to pick a maximum pseudorapidity defined by the extent of the 
assumed detector, to pick among some standard options of which particles 
to analyze, and to allow for some standard mass assumptions, like that 
all charged particles have the pion mass. Obviously this is only a 
restricted set of possibilities. 
 
<p/> 
Full flexibility can be obtained by deriving from the base class 
<code>SlowJetHook</code> to write your own <code>include</code> method. 
This will be presented with one final-state particle at a time, and 
should return <code>true</code> for those particles that should be 
analyzed. It is also possible to return modified four-momenta and masses, 
to take into account detector smearing effects or particle identity 
misassignments, but you must respect <ei>E^2 - p^2 = m^2</ei>. 
 
<p/> 
Alternatively you can modify the event record itself, or a copy of it 
(if you want to keep the original intact). For instance, only final 
particles are considered in the analysis, i.e. particles with positive 
status code, so negative status code should then be assigned to those 
particles that you do not want to see analyzed. Again four-momenta and 
masses can be modified, subject to <ei>E^2 - p^2 = m^2</ei>. 
 
<p/> 
The jet reconstructions is then based on sequential recombination with 
progressive removal, using the <ei>E</ei> recombination scheme. To be 
more specific, the algorithm works as follows. 
<ol> 
<li>Each particle to be analyzed defines an original cluster. It has a 
well-defined four-momentum and mass at input. From this information the 
triplet <ei>(pT, y, phi)</ei> is calculated, i.e. the transverse momentum, 
rapidity and azimuthal angle of the cluster.</li> 
<li>Define distance measures of all clusters <ei>i</ei> to the beam 
<eq>d_iB = pT_i^2p</eq> 
and of all pairs <ei>(i,j)</ei> relative to each other 
<eq>d_ij = min( pT_i^2p, pT_j^2p) DeltaR_ij^2 / R^2 </eq> 
where 
<eq>DeltaR_ij^2 = (y_i - y_j)^2 + (phi_i - phi_j)^2.</eq> 
The jet algorithm is determined by the user-selected <ei>p</ei> value, 
where <ei>p = -1</ei> corresponds to the anti-<ei>kT</ei> one, 
<ei>p = 0</ei> to the Cambridge/Aachen one and <ei>p = 1</ei> to the 
<ei>kT</ei> one. Also <ei>R</ei> is chosen by the user, to give an 
approximate measure of the size of jets. However, note that jets need 
not have a circular shape in <ei>(y, phi)</ei> space, so <ei>R</ei> 
can not straight off be interpreted as a jet radius.</li> 
<li>Find the smallest of all <ei>d_iB</ei> and <ei>d_ij</ei>.</li> 
<li>If this is a <ei>d_iB</ei> then cluster <ei>i</ei> is removed from 
the clusters list and instead added to the jets list. 
Optionally, a <ei>pTjetMin</ei> requirement is imposed, where only 
clusters with <ei>pT > pTjetMin</ei> are added to the jets list. 
If so, some of the analyzed particles will not be part of any final 
jet.</li> 
<li>If instead the smallest measure is a <ei>d_ij</ei> then the 
four-momenta of the <ei>i</ei> and <ei>j</ei> clusters are added 
to define a single new cluster. Convert this four-momentum to a new 
<ei>(pT, y, phi)</ei> triplet and update the list of <ei>d_iB</ei> 
and <ei>d_ij</ei>.</li> 
<li>Return to step 3 until no clusters remain.</li> 
</ol> 
 
<p/> 
To do jet finding analyses you first have to set up a <code>SlowJet</code> 
instance, where the arguments of the constructor specifies the details 
of the subsequent analyses. Thereafter you can feed in events to it, 
one at a time, and have them analyzed by the <code>analyze</code> method. 
Information on the resulting jets can be extracted by a few different methods. 
The minimal procedure only requires one call per event to do the analysis. 
We will begin by presenting it, and only afterwards some extensions. 
 
<method name="SlowJet::SlowJet(int power, double R, double pTjetMin = 0., 
double etaMax = 25., int select = 2, int massSet = 2, 
SlowJetHook* sjHookPtr = 0, bool useFJcore = true, bool useStandardR = true)"> 
create a <code>SlowJet</code> instance, where 
<argument name="power"> 
tells (half) the power of the transverse-momentum dependence of the 
distance measure, 
<argoption value="-1">the anti-<ei>kT</ei> algorithm,</argoption> 
<argoption value="0">the Cambridge/Aachen algorithm, and</argoption> 
<argoption value="1">the <ei>kT</ei> algorithm.</argoption> 
</argument> 
<argument name="R"> 
the <ei>R</ei> size parameter, which is crudely related to the radius of 
the jet cone in <ei>(y, phi)</ei> space around the center of the jet. 
</argument> 
<argument name="pTjetMin" default="0.0 GeV"> 
the minimum transverse momentum required for a cluster 
to become a jet. By default all clusters become jets, and therefore 
all analyzed particles are assigned to a jet. 
For comparisons with perturbative QCD, however, it is only meaningful 
to consider jets with a significant <ei>pT</ei>. 
</argument> 
<argument name="etaMax" default="25."> 
the maximum +-pseudorapidity that the detector is assumed to cover. 
If you pick a value above 20 there is assumed to be full coverage 
(obviously only meaningful for theoretical studies). 
</argument> 
<argument name="select" default="2"> 
tells which particles are analyzed, 
<argoption value="1">all final-state particles,</argoption> 
<argoption value="2">all observable final-state particles, 
i.e. excluding neutrinos and other particles without strong or 
electromagnetic interactions (the <code>isVisible()</code> particle 
method), 
and</argoption> 
<argoption value="3">only charged final-state particles.</argoption> 
</argument> 
<argument name="massSet" default="2">masses assumed for the particles 
used in the analysis 
<argoption value="0">all massless,</argoption> 
<argoption value="1">photons are massless while all others are 
assigned the <ei>pi+-</ei> mass, and 
</argoption> 
<argoption value="2">all given their correct masses.</argoption> 
</argument> 
<argument name="sjHookPtr" default="0"> 
gives the possibility to send in your own selection routine for which 
particles should be part of the analysis; see further below on the 
<code>SlowJetHook</code> class. If this pointer is sent in nonzero, 
<code>etaMax</code> and <code>massSet</code> are disregarded, 
and <code>select</code> only gives the basic selection, to which 
the user can add further requirements. 
</argument> 
<argument name="useFJcore" default="on">choice of code used for finding 
the jets. Does not affect the outcome of the analysis, but only the speed, 
and some more specialized options. 
<argoption value="on">use the <code>fjcore</code> package of 
<code>FastJet 3.0.5</code>. 
</argoption> 
<argoption value="off">use the native <code>SlowJet</code> implementation, 
which gives a slower jet finding, but allows some extra options of 
step-by-step jet joining. 
</argoption> 
</argument> 
<argument name="useStandardR" default="on">definition of <ei>R</ei> 
distance between two jets. This switch is only meaningful for 
<code>useFJcore = false</code>; within the <code>fjcore</code> package 
the standard option below is always used. 
<argoption value="on">standard, as described above, 
<ei>DeltaR_ij^2 = (y_i - y_j)^2 + (phi_i - phi_j)^2.</ei> 
</argoption> 
<argoption value="off">alternative, 
<ei>DeltaR_ij^2 = 2 (cosh(y_i - y_j) - cos(phi_i - phi_j))</ei>, 
which corresponds to the rim of the "deformed cone" giving a constant 
invariant mass between the two partons considered (for fixed 
masses and transverse momenta). 
</argoption> 
</argument> 
</method> 
 
<method name="bool SlowJet::analyze( const Event& event)"> 
performs a jet finding analysis, where 
<argument name="event">is an object of the <code>Event</code> class, 
most likely the <code>pythia.event</code> one. 
</argument> 
<br/>If the routine returns <code>false</code> the analysis failed, 
but currently this is not foreseen ever to happen. 
</method> 
 
<p/> 
After the analysis has been performed, a few <code>SlowJet</code> 
class methods are available to return the result of the analysis: 
 
<method name="int SlowJet::sizeOrig()"> 
gives the original number of particles (and thus clusters) that the 
analysis starts with. 
</method> 
 
<method name="int SlowJet::sizeJet()"> 
gives the number of jets found, with jets numbered 0 through 
<code>sizeJet() - 1</code>, and ordered in terms of decreasing 
transverse momentum values w.r.t. the beam axis, 
</method> 
 
<method name="double SlowJet::pT(int i)"> 
gives the transverse momentum <ei>pT</ei> of the <ei>i</ei>'th jet, 
</method> 
 
<method name="double SlowJet::y(int i)"> 
</method> 
<methodmore name="double SlowJet::phi(int i)"> 
gives the rapidity <ei>y</ei> and azimuthal angle <ei>phi</ei> 
of the center of the <ei>i</ei>'th jet (defined by the vector sum 
of constituent four-momenta), 
</methodmore> 
 
<method name="Vec4 SlowJet::p(int i)"> 
</method> 
<methodmore name="double SlowJet::m(int i)"> 
gives a <code>Vec4</code> corresponding to the four-momentum 
sum of the particles assigned to the <ei>i</ei>'th jet, and 
the invariant mass of this four-vector, 
</methodmore> 
 
<method name="int SlowJet::multiplicity(int i)"> 
gives the number of particles clustered into the <ei>i</ei>'th jet, 
</method> 
 
<method name="vector&lt;int&gt; SlowJet::constituents(int i)"> 
gives a list of the indices of the particles that have been 
clustered into the <ei>i</ei>'th jet, 
</method> 
 
<method name="vector&lt;int&gt; SlowJet::clusConstituents(int i)"> 
gives a list of the indices of the particles that have been 
clustered into the <ei>i</ei>'th cluster, at the current stage of 
the clustering process, 
</method> 
 
<method name="int SlowJet::jetAssignment(int i)"> 
gives the index of the jet that the particle <ei>i</ei> of the event 
record belongs to, or -1 if there is no jet containing particle 
<ei>i</ei>, 
</method> 
 
<method name="void SlowJet::removeJet(int i)"> 
removes the <ei>i</ei>'th jet, 
</method> 
 
<method name="void SlowJet::list()"> 
provides a listing of the basic jet information from above. 
</method> 
 
<p/> 
These are the basic methods. For more sophisticated usage 
it is possible to trace the clustering, one step at a time. 
It requires the native jet finding code, <code>useFJcore = false</code> 
in the constructor. If so, the <code>setup</code> method should be used 
to read in the event and find the initial smallest distance. Each subsequent 
<code>doStep</code> will then do one cluster joining and find the new 
smallest distance. You can therefore interrogate which clusters will be 
joined next before the joining actually is performed. Alternatively you 
can take several steps in one go, or take steps down to a predetermined 
number of jets plus remaining clusters. 
 
<method name="bool SlowJet::setup( const Event& event)"> 
selects the particles to be analyzed, calculates initial distances, 
and finds the initial smallest distance. 
<argument name="event">is an object of the <code>Event</code> class, 
most likely the <code>pythia.event</code> one. 
</argument> 
<br/>If the routine returns <code>false</code> the setup failed, 
but currently this is not foreseen ever to happen. 
</method> 
 
<method name="bool SlowJet::doStep()"> 
do the next step of the clustering. This can either be that two 
clusters are joined to one, or that a cluster is promoted to a jet 
(which is discarded if its <ei>pT</ei> value is below 
<code>pTjetMin</code>). 
<br/>The routine will only return <code>false</code> if there are no 
clusters left, or if <code>useFJcore = true</code>. 
</method> 
 
<method name="bool SlowJet::doNSteps(int nStep)"> 
calls the <code>doStep()</code> method <code>nStep</code> times, 
if possible. Will return <code>false</code> if the list of clusters 
is emptied before then. The stored jet information is still perfectly 
fine; it is only the number of steps that is wrong. Will also return 
<code>false</code> if <code>useFJcore = true</code>. 
</method> 
 
<method name="bool SlowJet::stopAtN(int nStop)"> 
calls the <code>doStep()</code> method until a total of <code>nStop</code> 
jet and cluster objects remain. Will return <code>false</code> if this 
is not possible, specifically if the number of objects already is smaller 
than <code>nStop</code> when the method is called. The stored jet and 
cluster information is still perfectly fine; it only does not have the 
expected multiplicity. Will also return <code>false</code> if 
<code>useFJcore = true</code>. 
</method> 
 
<method name="int SlowJet::sizeAll()"> 
gives the total current number of jets and clusters. The jets are 
numbered 0 through <code>sizeJet() - 1</code>, while the clusters 
are numbered <code>sizeJet()</code> through <code>sizeAll() - 1</code>. 
(Internally jets and clusters are represented by two separate arrays, 
but are here presented in one flat range.) Note that the jets are ordered 
in decreasing <ei>pT</ei>, while the clusters are not ordered. 
When <code>useFJcore = true</code> there are no intermediate steps, and 
thus the number of clusters is zero (after jet finding). 
</method> 
 
<p/> 
With this extension, the methods <code>double pT(int i)</code>, 
<code>double y(int i)</code>, <code>double phi(int i)</code>, 
<code>Vec4 p(int i)</code>, <code>double m(int i)</code> and 
<code>int multiplicity(int i)</code> can be used as before. 
Furthermore, <code>list()</code> generalizes 
 
<method name="void SlowJet::list(bool listAll = false)"> 
provides a listing of the above information. 
<argument name="listAll"> lists both jets and clusters if <code>true</code>, 
else only jets. 
</argument> 
</method> 
 
<p/> 
Three further methods can be used to check what will happen next. 
 
<method name="int SlowJet::iNext()"> 
</method> 
<methodmore name="int SlowJet::jNext()"> 
</methodmore> 
<methodmore name="double SlowJet::dNext()"> 
if the next step is to join two clusters, then the methods give 
the <ei>(i,j, d_ij)</ei> values, if instead to promote 
a cluster to a jet then <ei>(i, -1, d_iB)</ei>. 
If no clusters remain then <ei>(-1, -1, 0.)</ei>. Note that 
the cluster numbers are offset as described above, i.e. they begin at 
<code>sizeJet()</code>, which of course easily could be subtracted off. 
Also note that the jet and cluster lists are (moderately) reshuffled 
in each new step. When <code>useFJcore = true</code> there are no 
intermediate steps, and thus these methods do not return meaningul 
information. 
</methodmore> 
 
<p/> 
Finally, and separately, the <code>SlowJetHook</code> class can be used 
for a more smart selection of which particles to include in the analysis. 
For instance, isolated and/or high-<ei>pT</ei> muons, electrons and 
photons should presumably be identified separately at an early stage, 
and then not clustered to jets. 
 
<p/> 
Technically, it works like with <aloc href="UserHooks">User Hooks</aloc>. 
That is, PYTHIA contains the base class. You write a derived class. 
In the main program you create an instance of this class, and hand it 
in to <code>SlowJet</code>; in this case already as part of the 
constructor. 
 
<p/> 
The following methods should be defined in your derived class. 
 
<method name="SlowJetHook::SlowJetHook()"> 
</method> 
<methodmore name="virtual SlowJetHook::~SlowJetHook()"> 
the constructor and destructor need not do anything, and if so you 
need not write your own destructor. 
</methodmore> 
 
<method name="virtual bool SlowJetHook::include(int iSel, 
const Event& event, Vec4& pSel, double& mSel)"> 
is the main method that you will need to write. It will be called 
once for each final-state particle in an event, subject to the 
value of the <code>select</code> switch in the <code>SlowJet</code> 
constructor. The value <code>select = 2</code> may be convenient 
since then you do not need to remove e.g. neutrinos yourself, but 
use <code>select = 1</code> for full control. The method should then 
return <code>true</code> if you want to see particle included in the 
jet clustering, and <code>false</code> if not. 
<argument name="iSel">is the index in the event record of the 
currently studied particle. 
</argument> 
<argument name="event">is an object of the <code>Event</code> class, 
most likely the <code>pythia.event</code> one, where the currently 
studied particle is found. 
</argument> 
<argument name="pSel"> is at input the four-momentum of the 
currently studied particle. You can change the values, e.g. to take 
into account energy smearing in the detector, to define the initial 
cluster value, without corrupting the event record itself. 
</argument> 
<argument name="mSel"> is at input the mass of the currently studied 
particle. You can change the value, e.g. to take into account 
particle misidentification, to define the initial cluster value, 
without corrupting the event record itself. Note that the changes of 
<code>pSel</code> and <code>mSel</code> must be coordinated such that 
<ei>E^2 - p^2 = m^2</ei> holds. 
</argument> 
</method> 
 
<p/> 
It is also possible to define further methods of your own. 
One such could e.g. be called directly in the main program before the 
<code>analyze</code> method is called, to identify and bookkeep 
some event properties you may not want to reanalyze for each 
individual particle. 
 
</chapter> 
 
<!-- Copyright (C) 2026 Torbjorn Sjostrand --> 
