# Fastjet in root on Mac OS

**URL:** <https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569>\
**Category:** ROOT\
**Created:** [December 3, 2014, 8:53pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569 "2014-12-03T20:53:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerstein](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@gerstein](https://root-forum.cern.ch/u/gerstein)\
**Post date:** [December 3, 2014, 8:53pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/1 "2014-12-03T20:53:47Z")

</div>

Hi,

I posted that on an existing thread, but the topic does not show up as unresolved, so I am posting it separately below:

> [@How to call external libraries](https://root-forum.cern.ch/t/how-to-call-external-libraries/10845/13):
>
> [quote=“pcanal”]Hi, Something like: gSystem-\>Load("/cern/fastjet-install/lib/libfastjet.so"); gSystem-\>AddIncludePath("/cern/fastjet-install/include"); .L /cern/ana/short-example.cc+ Philippe.[/quote] Hi, I am doing this on Mac OS 10.8.5, root version 5.34/05. I make the fastjet, go into the fastjet-install/lib, make symbolic links i.e. fastjet-install/lib/libfastjet.so -\> libfastjet.0.dylib Then inside root root [0] .include /Users/gerstein/fastjet/fastjet-install/include root [1]…

Any hints / suggestions would be greatly appreciated  
Yuri

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [December 4, 2014, 9:30am UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/2 "2014-12-04T09:30:55Z")

</div>

Hi,

I think this is an example where ROOT6 shines.  
Once ROOT6 is available on your system you can do the following.

1. Get fastjet, compile it and start up root:

```auto
curl -O http://fastjet.fr/repo/fastjet-3.0.6.tar.gz
tar zxvf fastjet-3.0.6.tar.gz
cd fastjet-3.0.6/
./configure --prefix=$PWD/../fastjet-install
make -j 12
make check
make install
cd ..
ROOT_INCLUDE_PATH=fastjet-install/include/ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/fastjet-install/lib/ root -b
```

1. Take this code, copied from the fastjet main page, and copy it into the prompt:

```auto
gSystem->Load("libfastjet.so")
#include "fastjet/ClusterSequence.hh"
#include <iostream>
using namespace fastjet;
using namespace std;
 

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;
   }
}
```

You will get the desired output:

```auto
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
```

Best,  
Danilo

---

<div class="post-metadata">

**Author:** ![gerstein](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@gerstein](https://root-forum.cern.ch/u/gerstein)\
**Post date:** [December 4, 2014, 1:07pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/3 "2014-12-04T13:07:30Z")

</div>

[quote=“dpiparo”]Hi,

I think this is an example where ROOT6 shines.  
Once ROOT6 is available on your system you can do the following.  
[/quote]

I’m sure ROOT6 will also make me espresso and remind me to buy milk.

However, I’m stuck with ROOT5 for a little while. Any ideas about ROOT5?

Thanks,  
Yuri

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [December 4, 2014, 1:17pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/4 "2014-12-04T13:17:21Z")

</div>

You _might_ get some help if you post a full reproducer.

---

<div class="post-metadata">

**Author:** ![gerstein](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@gerstein](https://root-forum.cern.ch/u/gerstein)\
**Post date:** [December 4, 2014, 2:13pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/5 "2014-12-04T14:13:54Z")

</div>

> [@dpiparo](#):
>
> You _might_ get some help if you post a full reproducer.

Danilo,

I thought I did? Which information is missing from what I posted?

Thanks,  
Yuri

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [December 4, 2014, 2:54pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/6 "2014-12-04T14:54:31Z")

</div>

> [@](#):
>
> Which information is missing from what I posted?

The actual files you used with correct names ant the list of commands typed at the prompt.

D

---

<div class="post-metadata">

**Author:** ![gerstein](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@gerstein](https://root-forum.cern.ch/u/gerstein)\
**Post date:** [December 4, 2014, 3:46pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/7 "2014-12-04T15:46:53Z")

</div>

[quote=“dpiparo”][quote]  
Which information is missing from what I posted?  
[/quote]

The actual files you used with correct names ant the list of commands typed at the prompt.

D[/quote]

Files attached.  
The fastjet files are standard unmodified fastjet-3.1.0,  
built as per standard instructions.

Root command sequence  
root [0] .include /Users/gerstein/fastjet/fastjet-install/include  
root [1] int a = gSystem-\>Load(“fastjet-install/lib/libfastjet.so”); cout\<\<a\<\<"\n";  
0  
root [2] .L shortex.cc++  
[include.tar.gz](https://root-forum.cern.ch/uploads/default/original/2X/e/e52f9313d3393151b09b139a2058ee4ef7467adb.gz) (165 KB)  
[shortex.cc](https://root-forum.cern.ch/uploads/default/original/2X/5/58be965569b83d2aae03bb20f810d4d38a39bf15.cc) (1.16 KB)

---

<div class="post-metadata">

**Author:** ![gerstein](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@gerstein](https://root-forum.cern.ch/u/gerstein)\
**Post date:** [December 4, 2014, 3:50pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/8 "2014-12-04T15:50:21Z")

</div>

turns out the dylib extensions are not allowed, so I slapped a .txt on top of it.  
[libfastjet.0.dylib.txt](https://root-forum.cern.ch/uploads/default/original/2X/8/853553268026a42fae1310f36bb820826653c202.txt) (754 KB)

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [December 4, 2014, 9:22pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/9 "2014-12-04T21:22:59Z")

</div>

Hi,

Use [code]  
#ifndef **CINT**  
//----------------------------------------------------------------------  
// implementation of JetDefinition::operator() is here to avoid nasty  
// issues of order of implementations and includes  
template  
std::vector JetDefinition::operator()(const std::vector & particles) const {  
// create a new cluster sequence  
ClusterSequence \* cs = new ClusterSequence(particles, \*this);

// get the jets, and sort them according to whether the algorithm  
// is spherical or not  
std::vector jets;  
if (is\_spherical()) {  
jets = sorted\_by\_E(cs-\>inclusive\_jets());  
} else {  
jets = sorted\_by\_pt(cs-\>inclusive\_jets());  
}

// make sure the ClusterSequence gets deleted once it’s no longer  
// needed  
if (jets.size() != 0) {  
cs-\>delete\_self\_when\_unused();  
} else {  
delete cs;  
}

return jets;  
}  
#endif // **CINT** [/code]

This construct can not be parsed by CINT _and_ is not essential to dictionary generation.

Cheers,  
Philipe.

PS. Of course, a consequence is that this operator is not useable from the interpreter (for this, use ROOT v6).

---

<div class="post-metadata">

**Author:** ![gerstein](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@gerstein](https://root-forum.cern.ch/u/gerstein)\
**Post date:** [December 5, 2014, 2:54pm UTC](https://root-forum.cern.ch/t/fastjet-in-root-on-mac-os/18569/10 "2014-12-05T14:54:40Z")

</div>

[quote=“pcanal”]Hi,

This construct can not be parsed by CINT _and_ is not essential to dictionary generation.

Cheers,  
Philipe.  
[/quote]

Hi Philippe,

thanks so much!  
It works now.

regards,  
Yuri
