1
// FastJet3.h is a part of the PYTHIA event generator.
2
// Copyright (C) 2012 Torbjorn Sjostrand.
3
// PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
4
// Please respect the MCnet Guidelines, see GUIDELINES for details.
6
// This header file written by Gavin Salam.
8
#ifndef Pythia8_FastJet3_H
9
#define Pythia8_FastJet3_H
11
//----------------------------------------------------------------------
12
/// \file FastJet3Pythia8.hh
14
/// Code providing an interface for FastJet 3 to make use of Pythia8
15
/// particles and momenta. Given a
18
/// Pythia8::Particle py8_particle;
24
/// fastjet::PseudoJet fj_particle = py8_particle;
27
/// A copy of the Pythia8::Particle can then be accessed as
30
/// fj_particle.user_info<Pythia8::Particle>()
33
/// so that one can obtain information about the particle such as
36
/// fj_particle.user_info<Pythia8::Particle>().status();
37
/// fj_particle.user_info<Pythia8::Particle>().charge();
40
/// etc. Note that because the construction of a PseudoJet from the
41
/// Pythia8 particle involves taking a copy of the whole particle
42
/// (which has a number of member variables), there will be a small
43
/// time penalty at that point.
45
/// This file also defines a number of selectors that act on such
46
/// PseudoJets, such as
49
/// SelectorIsCharged();
50
/// SelectorId(int id);
53
/// so that one can for example write
56
/// vector<PseudoJet> charged_constituents
57
/// = SelectorIsCharged()(jet.constituents());
60
/// The full list of Pythia8-specific selectors is to be found at the
61
/// end of this file. They can be combined with each other and with
62
/// FastJet selectors using standard boolean operators. They are all
63
/// in the fastjet namespace.
65
/// If you do not need the above facilities, then you may instead
66
/// construct the PseudoJet from the pythia8 particle's 4-vector
69
/// PseudoJet fj_particle = py8_particle.p();
72
/// NB: this code is entirely given as an include file. If compilation
73
/// time is critical for your application, you may wish to split it
74
/// into separate .cc and .hh files.
76
// ----------------------------------------------------------------------
77
// Copyright 2011 by Matteo Cacciari, Gavin Salam and Gregory
78
// Soyez. Permission is granted to redistribute this file and modify
79
// it, as long as this notice is retained and any changes are clearly
80
// marked. No warranties are provided!
81
// ----------------------------------------------------------------------
83
#include "fastjet/config.h" // will allow a test for FJ3
84
#include "fastjet/ClusterSequence.hh" // also gives PseudoJet & JetDefinition
85
#include "fastjet/Selector.hh"
86
#include "Event.h" // this is what we need from Pythia8
88
// FASTJET_VERSION is only defined from version 3 onwards so we can
89
// use it to test that we have a sufficiently recent version
90
#ifndef FASTJET_VERSION
91
#error "FastJet 3 is required in order to obtain the features of this interface"
94
FASTJET_BEGIN_NAMESPACE // place the code here inside the FJ namespace
96
/// \class Py8Particle
98
/// A class derived from a pythia 8 particle and that also derives
99
/// from PseudoJet::UserInfoBase, so that it can be used as UserInfo
100
/// inside PseudoJets, but also be cast back to the Pythia8 particle
101
class Py8Particle: public Pythia8::Particle,
102
public PseudoJet::UserInfoBase {
104
Py8Particle(const Pythia8::Particle & particle) : Particle(particle) {}
107
/// specialization of the PseudoJet constructor so that it can take a
108
/// pythia8 particle (and makes a copy of it as user info);
110
inline PseudoJet::PseudoJet(const Pythia8::Particle & particle) {
111
reset(particle.px(),particle.py(),particle.pz(), particle.e());
112
set_user_info(new Py8Particle(particle));
115
/// specialization of the PseudoJet constructor so that it can take a
116
/// pythia8 Vec4. There is then no particular user info available.
118
inline PseudoJet::PseudoJet(const Pythia8::Vec4 & particle) {
119
reset(particle.px(),particle.py(),particle.pz(), particle.e());
123
/// \class SelectorWorkerPy8
125
/// A template class to help with the creation of Selectors for Pythia
126
/// particle properties. It's not necessary to understand how this
127
/// works in order to use the selectors. See below for the actual list
130
/// (But if you're curious, essentially it stores a pointer to a
131
/// member function of Pythia8::Particle, and when called to select
132
/// particles, executes it and checks the return value is equal to
133
/// that requested in the constructor).
134
template<class T> class SelectorWorkerPy8 : public SelectorWorker {
136
/// the typedef helps with the notation for member function pointers
137
typedef T (Pythia8::Particle::*Py8ParticleFnPtr)() const;
139
/// c'tor, which takes the member fn pointer and the return value
140
/// that it should be equal to
141
SelectorWorkerPy8(Py8ParticleFnPtr member_fn_ptr, T value) :
142
_member_fn_ptr(member_fn_ptr), _value(value) {};
144
/// the one function from SelectorWorker that must be overloaded to
145
/// get functioning selection. It makes sure that the PseudoJet
146
/// actually has Pythia8::Particle user info before checking
148
bool pass(const PseudoJet & p) const {
149
const Pythia8::Particle * py8_particle
150
= dynamic_cast<const Pythia8::Particle *>(p.user_info_ptr());
151
if (py8_particle == 0) {
152
return false; // no info, so false
154
return (py8_particle->*_member_fn_ptr)() == _value;
158
Py8ParticleFnPtr _member_fn_ptr;
162
/// @name Boolean FJ3/PY8 Selectors
164
/// A series of selectors for boolean properties of PseudoJets with
165
/// Pythia8::Particle information; PseudoJets without
166
/// Pythia8::Particle structure never pass these selectors.
169
inline Selector SelectorIsFinal () {return
170
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isFinal , true));}
171
inline Selector SelectorIsCharged () {return
172
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isCharged , true));}
173
inline Selector SelectorIsNeutral () {return
174
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isNeutral , true));}
175
inline Selector SelectorIsResonance() {return
176
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isResonance, true));}
177
inline Selector SelectorIsVisible () {return
178
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isVisible , true));}
179
inline Selector SelectorIsLepton () {return
180
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isLepton , true));}
181
inline Selector SelectorIsQuark () {return
182
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isQuark , true));}
183
inline Selector SelectorIsGluon () {return
184
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isGluon , true));}
185
inline Selector SelectorIsDiquark () {return
186
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isDiquark , true));}
187
inline Selector SelectorIsParton () {return
188
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isParton , true));}
189
inline Selector SelectorIsHadron () {return
190
Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isHadron , true));}
193
/// @name Integer FJ3/PY8 Selectors
195
/// A series of selectors for integer properties of PseudoJets with
196
/// Pythia8::Particle information; PseudoJets without
197
/// Pythia8::Particle structure never pass these selectors.
200
inline Selector SelectorId (int i) {return
201
Selector(new SelectorWorkerPy8<int>(&Pythia8::Particle::id , i));}
202
inline Selector SelectorIdAbs (int i) {return
203
Selector(new SelectorWorkerPy8<int>(&Pythia8::Particle::idAbs , i));}
204
inline Selector SelectorStatus (int i) {return
205
Selector(new SelectorWorkerPy8<int>(&Pythia8::Particle::status , i));}
206
inline Selector SelectorStatusAbs(int i) {return
207
Selector(new SelectorWorkerPy8<int>(&Pythia8::Particle::statusAbs, i));}
211
FASTJET_END_NAMESPACE
213
#endif // Pythia8_FastJet3_H