Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fastjet plugins? #77

Open
skluth opened this issue Dec 16, 2021 · 16 comments
Open

Use fastjet plugins? #77

skluth opened this issue Dec 16, 2021 · 16 comments

Comments

@skluth
Copy link

skluth commented Dec 16, 2021

For our studies we would need access to some of the fastjet algorithms available as plugins. Examples are the eesiscone, the jade and the pxcone e+e- jet algorithms.

We can of course do this directly in C++, or with a dedicated C++ wrapper which can be loaded into python via ROOT.

But it would be great if the fastjet plugins could be made available directly through python fastjet.

@aryan26roy
Copy link
Collaborator

@skluth , thank you for opening this issue. Fastjet plugins are going to be added to python fastjet in the future, although I cannot tell you when as it will require a lot of time from someone. Maybe @jpivarski knows more about it.

@jpivarski
Copy link
Member

If what you're asking about is in fj-contrib, we're waiting for fj-contrib to move from SVN to git so that we can make it a git submodule and include it in the build.

If what you're asking about is in FastJet core, the Python module is built with all plugins enabled. I think only the CGAL support was temporarily turned off because of a compilation problem, but that only affects performance at high pile-up, not capabilities. Oh! We also turned off the one and only plugin that required Fortran. Many of the plugins were different jet algorithms—are eesiscone, jade, and pxcone among that set?

These are the compilation arguments we use:

fastjet/setup.py

Lines 62 to 70 in e5aebdc

args = [
f"--prefix={OUTPUT}",
"--enable-allcxxplugins",
"--enable-cgal-header-only",
f"--with-cgaldir={cgal_dir}",
"--enable-swig",
"--enable-pyext",
"LDFLAGS=-Wl,-rpath=$$ORIGIN/_fastjet_core/lib:$$ORIGIN",
]

Instead of listing out all those plugins, we include all of the ones written in C++ (as opposed to Fortran).

@aryan26roy
Copy link
Collaborator

@jpivarski I think pxcone was the one that required Fortran.

@jpivarski
Copy link
Member

Ah, then we'd need to get Fortran into CD. Let's hear from @skluth about the exact requirements, first, though.

@skluth
Copy link
Author

skluth commented Dec 16, 2021

I think the problem for us is how to use a JetDefinition which needs a plugin even if the plugin enabled. We would like to use the various e+e- algorithms like eesiscone and JADE.

@jpivarski
Copy link
Member

For how to use a JetDefinition, is what you're looking for covered in https://fastjet.readthedocs.io/en/latest/Awkward.html?

For example,

import fastjet
jetdef = fastjet.JetDefinition(fastjet.antikt_algorithm, 0.6)

What happens if you put in ee_genkt_algorithm or ee_kt_algorithm?

I didn't see any of the others you mentioned in that list. Since this is a Python module, we'd have to have the plugins compiled-in to be able to use them.

@skluth
Copy link
Author

skluth commented Dec 16, 2021

The compiled-in algorithms work for us. The problem is creating a JetDefinition object with a plugin algo. All plugin algos have a enum fastjet::plugin_algorithm. In C++ one has to create a plugin instance of the correct type and create a JetDefinition instance with that. That probably needs dedicated code which detects that a requested algo is a plugin (i.e. not built-in), creates a C++ instance of that plugin, creates a JetDefintion object with the plugin and passes that back.

@jpivarski
Copy link
Member

@aryan26roy, is this something that can be done with the SWIG objects, or is it a C++ interface that needs to be exposed into Python?

(First question is, do you recognize the procedure @skluth is describing? I don't know how these things are done in C++ so I don't quite understand the procedure. But since you've been working on the C++ side, maybe it makes more sense to you?)

@aryan26roy
Copy link
Collaborator

@jpivarski I couldn't find any of the algorithms that @skluth mentioned in the import list from swig. While the procedure for making a JetDefinition for a plugin is the same as native algorithms, if those plugins are not exposed through the swig bindings, we couldn't support them. (I can't find the eesiscone algorithms anywhere, maybe it is a part of fj contrib.)

@skluth
Copy link
Author

skluth commented Dec 16, 2021

Here is the logic I have in a class to handle plugins:

if( ja == fastjet::plugin_algorithm ) { // ja derived from input jetalgString
    if( jetalgString == "siscone" ) {
      plugin= new fastjet::SISConePlugin( R, 0.75 );
    }
    else if( jetalgString == "eesiscone" ) {
      plugin= new fastjet::SISConeSphericalPlugin( R, 0.75 );
    }
    else if( jetalgString == "jade" ) {
      plugin= new fastjet::JadePlugin();
      recombiner= new EEE0Recombiner();
    }
    else if( jetalgString == "pxcone" ) {
      plugin= new fastjet::PxConePlugin( R, Emin, 0.75, true, 1 );
    }
    else {
      string txt= "TFastJet::TFastJet: wrong plugin: " + jetalgString;
      throw std::runtime_error( txt );
    }
    jetdef= fastjet::JetDefinition( plugin );
}

Note it also shows which plugin class is eesiscone

@aryan26roy
Copy link
Collaborator

@skluth thanks! I found all the algorithms you mentioned in the docs. All of these plugin algorithms do not seem to be binded through swig @jpivarski.

@skluth
Copy link
Author

skluth commented Dec 16, 2021

Perhaps it is enough to expose the plugin classes in the swig import list? Then one could build an instance on the python side and create e.g.

import fastjet
pluginAlg = fastjet.JadePlugin()
jetdef = fastjet.JetDefinition( pluginAlg )

The fastjet::JetDefinition class has a matching ctor for this, so we need that exposed as well.

@skluth
Copy link
Author

skluth commented Dec 17, 2021

About the Fortran-based pxcone algorithm: it is wrapped in C++ in fastjet, so I would think that all we would need for pxcone is building fastjet with pxcone (needs a Fortran compiler i.e. gfortran) and exposing the relevant plugin class fastjet::PxConePlugin( ... ) through the swig magic.

@aryan26roy
Copy link
Collaborator

@skluth yes, that should be enough. However, the swig bindings are provided by the core fastjet authors, perhaps we can ask them about it @jpivarski.

@skluth
Copy link
Author

skluth commented Dec 17, 2021

I have a fastjet-3.4.0 build. I could try to experiment with the swig bindings, but I have no experience with this so far, so I would need a little introduction into where to look in the fastjet codebase.

@jpivarski
Copy link
Member

@skluth yes, that should be enough. However, the swig bindings are provided by the core fastjet authors, perhaps we can ask them about it @jpivarski.

We can ask why this algorithm isn't configured in the same way as the others, or why it can't be done through the SWIG bindings, but if there's a way to do it in C++, then we can also expose that through pybind11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants