Download the code and then unpack it (on some systems you may need to
replace "curl -O" with "wget"):
curl -O https://fastjet.fr/repo/fastjet-3.4.3.tar.gz
tar zxvf fastjet-3.4.3.tar.gz
cd fastjet-3.4.3/
Compile and install (you can also choose your own preferred prefix), and when you're done go back to the original directory
./configure --prefix=$PWD/../fastjet-install
make
make check
make install
cd ..
Now paste the following piece of code into a file called
short-example.cc
#include "fastjet/ClusterSequence.hh"
#include <iostream>
using namespace fastjet;
using namespace std;
int main () {
vector<PseudoJet> particles;
// an event with three particles: px py pz E
particles.push_back( PseudoJet( 99.0, 0.1, 0, 100.0) );
particles.push_back( PseudoJet( 4.0, -0.1, 0, 5.0) );
particles.push_back( PseudoJet( -99.0, 0, 0, 99.0) );
// choose a jet definition
double R = 0.7;
JetDefinition jet_def(antikt_algorithm, R);
// run the clustering, extract the jets
ClusterSequence cs(particles, jet_def);
vector<PseudoJet> jets = sorted_by_pt(cs.inclusive_jets());
// print out some infos
cout << "Clustering with " << jet_def.description() << endl;
// print the jets
cout << " pt y phi" << endl;
for (unsigned i = 0; i < jets.size(); i++) {
cout << "jet " << i << ": "<< jets[i].pt() << " "
<< jets[i].rap() << " " << jets[i].phi() << endl;
vector<PseudoJet> constituents = jets[i].constituents();
for (unsigned j = 0; j < constituents.size(); j++) {
cout << " constituent " << j << "'s pt: " << constituents[j].pt()
<< endl;
}
}
}
Then compile and run it with
g++ short-example.cc -o short-example \
`fastjet-install/bin/fastjet-config --cxxflags --libs --plugins`
./short-example
The output will consist of a banner, followed by the lines
Clustering with Longitudinally invariant anti-kt algorithm with R = 0.7
and E scheme recombination
pt y phi
jet 0: 103 0 0
constituent 0's pt: 99.0001
constituent 1's pt: 4.00125
jet 1: 99 0 3.14159
constituent 0's pt: 99