PYTHIA  8.311
FastJet3.h
1 // FastJet3.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2024 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // This header file written by Gavin Salam.
7 
8 #ifndef Pythia8_FastJet3_H
9 #define Pythia8_FastJet3_H
10 
11 //----------------------------------------------------------------------
12 // \file FastJet3Pythia8.hh
13 //
14 // Code providing an interface for FastJet 3 to make use of Pythia8
15 // particles and momenta. Given a
16 //
17 // \code
18 // Pythia8::Particle py8_particle;
19 // \endcode
20 //
21 // you may write
22 //
23 // \code
24 // fastjet::PseudoJet fj_particle = py8_particle;
25 // \endcode
26 //
27 // A copy of the Pythia8::Particle can then be accessed as
28 //
29 // \code
30 // fj_particle.user_info<Pythia8::Particle>()
31 // \endcode
32 //
33 // so that one can obtain information about the particle such as
34 //
35 // \code
36 // fj_particle.user_info<Pythia8::Particle>().status();
37 // fj_particle.user_info<Pythia8::Particle>().charge();
38 // \endcode
39 //
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.
44 //
45 // This file also defines a number of selectors that act on such
46 // PseudoJets, such as
47 //
48 // \code
49 // SelectorIsCharged();
50 // SelectorId(int id);
51 // \endcode
52 //
53 // so that one can for example write
54 //
55 // \code
56 // vector<PseudoJet> charged_constituents
57 // = SelectorIsCharged()(jet.constituents());
58 // \endcode
59 //
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.
64 //
65 // If you do not need the above facilities, then you may instead
66 // construct the PseudoJet from the pythia8 particle's 4-vector
67 //
68 // \code
69 // PseudoJet fj_particle = py8_particle.p();
70 // \endcode
71 //
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.
75 //
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 // ----------------------------------------------------------------------
82 
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 "Pythia8/Event.h" // this is what we need from Pythia8
87 
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 "FastJet3 is required in order to obtain the features of this interface"
92 #endif
93 
94 FASTJET_BEGIN_NAMESPACE // place the code here inside the FJ namespace
95 
96 // \class Py8Particle
97 //
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
102  public PseudoJet::UserInfoBase {
103 public:
104  Py8Particle(const Pythia8::Particle & particle) : Particle(particle),
105  mIndex(particle.index()) {}
106  virtual int index() const override {return mIndex;}
107 private:
108  int mIndex;
109 };
110 
111 // specialization of the PseudoJet constructor so that it can take a
112 // pythia8 particle (and makes a copy of it as user info);
113 template<>
114 inline PseudoJet::PseudoJet(const Pythia8::Particle & particle) {
115  reset(particle.px(),particle.py(),particle.pz(), particle.e());
116  set_user_index( particle.index() );
117  set_user_info(new Py8Particle(particle));
118 }
119 
120 // specialization of the PseudoJet constructor so that it can take a
121 // pythia8 Vec4. There is then no particular user info available.
122 template<>
123 inline PseudoJet::PseudoJet(const Pythia8::Vec4 & particle) {
124  reset(particle.px(),particle.py(),particle.pz(), particle.e());
125 }
126 
127 
128 // \class SelectorWorkerPy8
129 //
130 // A template class to help with the creation of Selectors for Pythia
131 // particle properties. It's not necessary to understand how this
132 // works in order to use the selectors. See below for the actual list
133 // of selectors.
134 //
135 // (But if you're curious, essentially it stores a pointer to a
136 // member function of Pythia8::Particle, and when called to select
137 // particles, executes it and checks the return value is equal to
138 // that requested in the constructor).
139 template<class T> class SelectorWorkerPy8 : public SelectorWorker {
140 public:
141  // the typedef helps with the notation for member function pointers
142  typedef T (Pythia8::Particle::*Py8ParticleFnPtr)() const;
143 
144  // c'tor, which takes the member fn pointer and the return value
145  // that it should be equal to
146  SelectorWorkerPy8(Py8ParticleFnPtr member_fn_ptr, T value) :
147  _member_fn_ptr(member_fn_ptr), _value(value) {};
148 
149  // the one function from SelectorWorker that must be overloaded to
150  // get functioning selection. It makes sure that the PseudoJet
151  // actually has Pythia8::Particle user info before checking
152  // its value.
153  bool pass(const PseudoJet & p) const {
154  const Pythia8::Particle * py8_particle
155  = dynamic_cast<const Pythia8::Particle *>(p.user_info_ptr());
156  if (py8_particle == 0) {
157  return false; // no info, so false
158  } else {
159  return (py8_particle->*_member_fn_ptr)() == _value;
160  }
161  }
162 private:
163  Py8ParticleFnPtr _member_fn_ptr;
164  T _value;
165 };
166 
167 // @name Boolean FJ3/PY8 Selectors
168 //
169 // A series of selectors for boolean properties of PseudoJets with
170 // Pythia8::Particle information; PseudoJets without
171 // Pythia8::Particle structure never pass these selectors.
172 //
173 //\{
174 inline Selector SelectorIsFinal () {return
175  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isFinal , true));}
176 inline Selector SelectorIsCharged () {return
177  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isCharged , true));}
178 inline Selector SelectorIsNeutral () {return
179  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isNeutral , true));}
180 inline Selector SelectorIsResonance() {return
181  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isResonance,true));}
182 inline Selector SelectorIsVisible () {return
183  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isVisible , true));}
184 inline Selector SelectorIsLepton () {return
185  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isLepton , true));}
186 inline Selector SelectorIsQuark () {return
187  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isQuark , true));}
188 inline Selector SelectorIsGluon () {return
189  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isGluon , true));}
190 inline Selector SelectorIsDiquark () {return
191  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isDiquark , true));}
192 inline Selector SelectorIsParton () {return
193  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isParton , true));}
194 inline Selector SelectorIsHadron () {return
195  Selector(new SelectorWorkerPy8<bool>(&Pythia8::Particle::isHadron , true));}
196 //\}
197 
198 // @name Integer FJ3/PY8 Selectors
199 //
200 // A series of selectors for integer properties of PseudoJets with
201 // Pythia8::Particle information; PseudoJets without
202 // Pythia8::Particle structure never pass these selectors.
203 //
204 //\{
205 inline Selector SelectorId (int i) {return
206  Selector(new SelectorWorkerPy8<int>(&Pythia8::Particle::id , i));}
207 inline Selector SelectorIdAbs (int i) {return
209 inline Selector SelectorStatus (int i) {return
210  Selector(new SelectorWorkerPy8<int>(&Pythia8::Particle::status , i));}
211 inline Selector SelectorStatusAbs(int i) {return
212  Selector(new SelectorWorkerPy8<int>(&Pythia8::Particle::statusAbs, i));}
213 //\}
214 
215 
216 FASTJET_END_NAMESPACE
217 
218 #endif // Pythia8_FastJet3_H
Definition: FastJet3.h:139
virtual int index() const override
Methods that can refer back to the event the particle belongs to.
Definition: FastJet3.h:106
bool pass(const PseudoJet &p) const
Definition: FastJet3.h:153
SelectorWorkerPy8(Py8ParticleFnPtr member_fn_ptr, T value)
Definition: FastJet3.h:146
int id() const
Member functions for output.
Definition: Event.h:127
also gives PseudoJet & JetDefinition
Definition: FastJet3.h:101
Particle()
Constructors.
Definition: Event.h:37
Definition: Event.h:32
int idAbs() const
Member functions for output; derived int and bool quantities.
Definition: Event.h:152
Definition: Basics.h:32
virtual int index() const
Methods that can refer back to the event the particle belongs to.
Definition: Event.cc:87