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. |
---|
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 "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 "FastJet 3 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 |
---|
101 | class Py8Particle: public Pythia8::Particle, |
---|
102 | public PseudoJet::UserInfoBase { |
---|
103 | public: |
---|
104 | Py8Particle(const Pythia8::Particle & particle) : Particle(particle) {} |
---|
105 | }; |
---|
106 | |
---|
107 | /// specialization of the PseudoJet constructor so that it can take a |
---|
108 | /// pythia8 particle (and makes a copy of it as user info); |
---|
109 | template<> |
---|
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)); |
---|
113 | } |
---|
114 | |
---|
115 | /// specialization of the PseudoJet constructor so that it can take a |
---|
116 | /// pythia8 Vec4. There is then no particular user info available. |
---|
117 | template<> |
---|
118 | inline PseudoJet::PseudoJet(const Pythia8::Vec4 & particle) { |
---|
119 | reset(particle.px(),particle.py(),particle.pz(), particle.e()); |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | /// \class SelectorWorkerPy8 |
---|
124 | /// |
---|
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 |
---|
128 | /// of selectors. |
---|
129 | /// |
---|
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 { |
---|
135 | public: |
---|
136 | /// the typedef helps with the notation for member function pointers |
---|
137 | typedef T (Pythia8::Particle::*Py8ParticleFnPtr)() const; |
---|
138 | |
---|
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) {}; |
---|
143 | |
---|
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 |
---|
147 | /// its value. |
---|
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 |
---|
153 | } else { |
---|
154 | return (py8_particle->*_member_fn_ptr)() == _value; |
---|
155 | } |
---|
156 | } |
---|
157 | private: |
---|
158 | Py8ParticleFnPtr _member_fn_ptr; |
---|
159 | T _value; |
---|
160 | }; |
---|
161 | |
---|
162 | /// @name Boolean FJ3/PY8 Selectors |
---|
163 | /// |
---|
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. |
---|
167 | /// |
---|
168 | ///\{ |
---|
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));} |
---|
191 | ///\} |
---|
192 | |
---|
193 | /// @name Integer FJ3/PY8 Selectors |
---|
194 | /// |
---|
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. |
---|
198 | /// |
---|
199 | ///\{ |
---|
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));} |
---|
208 | ///\} |
---|
209 | |
---|
210 | |
---|
211 | FASTJET_END_NAMESPACE |
---|
212 | |
---|
213 | #endif // Pythia8_FastJet3_H |
---|