PYTHIA  8.311
Event.h
1 // Event.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 // Header file for the Particle and Event classes.
7 // Particle: information on an instance of a particle.
8 // Junction: information on a junction between three colours.
9 // Event: list of particles in the current event.
10 
11 #ifndef Pythia8_Event_H
12 #define Pythia8_Event_H
13 
14 #include "Pythia8/Basics.h"
15 #include "Pythia8/ParticleData.h"
16 #include "Pythia8/PythiaStdlib.h"
17 
18 namespace Pythia8 {
19 
20 //==========================================================================
21 
22 // Forward references to ParticleDataEntry and ResonanceWidths classes.
23 class ParticleDataEntry;
24 class ResonanceWidths;
25 class Event;
26 
27 //==========================================================================
28 
29 // Particle class.
30 // This class holds info on a particle in general.
31 
32 class Particle {
33 
34 public:
35 
36  // Constructors.
37  Particle() : idSave(0), statusSave(0), mother1Save(0), mother2Save(0),
38  daughter1Save(0), daughter2Save(0), colSave(0), acolSave(0),
39  pSave(Vec4(0.,0.,0.,0.)), mSave(0.), scaleSave(0.), polSave(9.),
40  hasVertexSave(false), vProdSave(Vec4(0.,0.,0.,0.)), tauSave(0.),
41  pdePtr(0), evtPtr(0) { }
42  Particle(int idIn, int statusIn = 0, int mother1In = 0,
43  int mother2In = 0, int daughter1In = 0, int daughter2In = 0,
44  int colIn = 0, int acolIn = 0, double pxIn = 0., double pyIn = 0.,
45  double pzIn = 0., double eIn = 0., double mIn = 0.,
46  double scaleIn = 0., double polIn = 9.)
47  : idSave(idIn), statusSave(statusIn), mother1Save(mother1In),
48  mother2Save(mother2In), daughter1Save(daughter1In),
49  daughter2Save(daughter2In), colSave(colIn), acolSave(acolIn),
50  pSave(Vec4(pxIn, pyIn, pzIn, eIn)), mSave(mIn), scaleSave(scaleIn),
51  polSave(polIn), hasVertexSave(false), vProdSave(Vec4(0.,0.,0.,0.)),
52  tauSave(0.), pdePtr(0), evtPtr(0) { }
53  Particle(int idIn, int statusIn, int mother1In, int mother2In,
54  int daughter1In, int daughter2In, int colIn, int acolIn,
55  Vec4 pIn, double mIn = 0., double scaleIn = 0., double polIn = 9.)
56  : idSave(idIn), statusSave(statusIn), mother1Save(mother1In),
57  mother2Save(mother2In), daughter1Save(daughter1In),
58  daughter2Save(daughter2In), colSave(colIn), acolSave(acolIn),
59  pSave(pIn), mSave(mIn), scaleSave(scaleIn), polSave(polIn),
60  hasVertexSave(false), vProdSave(Vec4(0.,0.,0.,0.)), tauSave(0.),
61  pdePtr(0), evtPtr(0) { }
62  Particle(const Particle& pt) : idSave(pt.idSave),
63  statusSave(pt.statusSave), mother1Save(pt.mother1Save),
64  mother2Save(pt.mother2Save), daughter1Save(pt.daughter1Save),
65  daughter2Save(pt.daughter2Save), colSave(pt.colSave),
66  acolSave(pt.acolSave), pSave(pt.pSave), mSave(pt.mSave),
67  scaleSave(pt.scaleSave), polSave(pt.polSave),
68  hasVertexSave(pt.hasVertexSave), vProdSave(pt.vProdSave),
69  tauSave(pt.tauSave), pdePtr(pt.pdePtr), evtPtr(pt.evtPtr) { }
70  Particle& operator=(const Particle& pt) {if (this != &pt) {
71  idSave = pt.idSave; statusSave = pt.statusSave;
72  mother1Save = pt.mother1Save; mother2Save = pt.mother2Save;
73  daughter1Save = pt.daughter1Save; daughter2Save = pt.daughter2Save;
74  colSave = pt.colSave; acolSave = pt.acolSave; pSave = pt.pSave;
75  mSave = pt.mSave; scaleSave = pt.scaleSave; polSave = pt.polSave;
76  hasVertexSave = pt.hasVertexSave; vProdSave = pt.vProdSave;
77  tauSave = pt.tauSave; pdePtr = pt.pdePtr; evtPtr = pt.evtPtr; }
78  return *this; }
79 
80  // Destructor.
81  virtual ~Particle() {}
82 
83  // Member functions to set the Event and ParticleDataEntry pointers.
84  void setEvtPtr(Event* evtPtrIn) { evtPtr = evtPtrIn; setPDEPtr();}
85  void setPDEPtr(ParticleDataEntryPtr pdePtrIn = nullptr);
86 
87  // Member functions for input.
88  void id(int idIn) {idSave = idIn; setPDEPtr();}
89  void status(int statusIn) {statusSave = statusIn;}
90  void statusPos() {statusSave = abs(statusSave);}
91  void statusNeg() {statusSave = -abs(statusSave);}
92  void statusCode(int statusIn) {statusSave =
93  (statusSave > 0) ? abs(statusIn) : -abs(statusIn);}
94  void mother1(int mother1In) {mother1Save = mother1In;}
95  void mother2(int mother2In) {mother2Save = mother2In;}
96  void mothers(int mother1In = 0, int mother2In = 0)
97  {mother1Save = mother1In; mother2Save = mother2In;}
98  void daughter1(int daughter1In) {daughter1Save = daughter1In;}
99  void daughter2(int daughter2In) {daughter2Save = daughter2In;}
100  void daughters(int daughter1In = 0, int daughter2In = 0)
101  {daughter1Save = daughter1In; daughter2Save = daughter2In;}
102  void col(int colIn) {colSave = colIn;}
103  void acol(int acolIn) {acolSave = acolIn;}
104  void cols(int colIn = 0,int acolIn = 0) {colSave = colIn;
105  acolSave = acolIn;}
106  void p(Vec4 pIn) {pSave = pIn;}
107  void p(double pxIn, double pyIn, double pzIn, double eIn)
108  {pSave.p(pxIn, pyIn, pzIn, eIn);}
109  void px(double pxIn) {pSave.px(pxIn);}
110  void py(double pyIn) {pSave.py(pyIn);}
111  void pz(double pzIn) {pSave.pz(pzIn);}
112  void e(double eIn) {pSave.e(eIn);}
113  void m(double mIn) {mSave = mIn;}
114  void scale(double scaleIn) {scaleSave = scaleIn;}
115  void pol(double polIn) {polSave = polIn;}
116  void vProd(Vec4 vProdIn) {vProdSave = vProdIn; hasVertexSave = true;}
117  void vProd(double xProdIn, double yProdIn, double zProdIn, double tProdIn)
118  {vProdSave.p(xProdIn, yProdIn, zProdIn, tProdIn); hasVertexSave = true;}
119  void xProd(double xProdIn) {vProdSave.px(xProdIn); hasVertexSave = true;}
120  void yProd(double yProdIn) {vProdSave.py(yProdIn); hasVertexSave = true;}
121  void zProd(double zProdIn) {vProdSave.pz(zProdIn); hasVertexSave = true;}
122  void tProd(double tProdIn) {vProdSave.e(tProdIn); hasVertexSave = true;}
123  void vProdAdd(Vec4 vProdIn) {vProdSave += vProdIn; hasVertexSave = true;}
124  void tau(double tauIn) {tauSave = tauIn;}
125 
126  // Member functions for output.
127  int id() const {return idSave;}
128  int status() const {return statusSave;}
129  int mother1() const {return mother1Save;}
130  int mother2() const {return mother2Save;}
131  int daughter1() const {return daughter1Save;}
132  int daughter2() const {return daughter2Save;}
133  int col() const {return colSave;}
134  int acol() const {return acolSave;}
135  Vec4 p() const {return pSave;}
136  double px() const {return pSave.px();}
137  double py() const {return pSave.py();}
138  double pz() const {return pSave.pz();}
139  double e() const {return pSave.e();}
140  double m() const {return mSave;}
141  double scale() const {return scaleSave;}
142  double pol() const {return polSave;}
143  bool hasVertex() const {return hasVertexSave;}
144  Vec4 vProd() const {return vProdSave;}
145  double xProd() const {return vProdSave.px();}
146  double yProd() const {return vProdSave.py();}
147  double zProd() const {return vProdSave.pz();}
148  double tProd() const {return vProdSave.e();}
149  double tau() const {return tauSave;}
150 
151  // Member functions for output; derived int and bool quantities.
152  int idAbs() const {return abs(idSave);}
153  int statusAbs() const {return abs(statusSave);}
154  bool isFinal() const {return (statusSave > 0);}
155  int intPol() const;
156  bool isRescatteredIncoming() const {return
157  (statusSave == -34 || statusSave == -45 ||
158  statusSave == -46 || statusSave == -54);}
159 
160  // Member functions for output; derived double quantities.
161  double m2() const {return (mSave >= 0.) ? mSave*mSave
162  : -mSave*mSave;}
163  double mCalc() const {return pSave.mCalc();}
164  double m2Calc() const {return pSave.m2Calc();}
165  double eCalc() const {return sqrt(abs(m2() + pSave.pAbs2()));}
166  double pT() const {return pSave.pT();}
167  double pT2() const {return pSave.pT2();}
168  double mT() const {double temp = m2() + pSave.pT2();
169  return (temp >= 0.) ? sqrt(temp) : -sqrt(-temp);}
170  double mT2() const {return m2() + pSave.pT2();}
171  double pAbs() const {return pSave.pAbs();}
172  double pAbs2() const {return pSave.pAbs2();}
173  double eT() const {return pSave.eT();}
174  double eT2() const {return pSave.eT2();}
175  double theta() const {return pSave.theta();}
176  double phi() const {return pSave.phi();}
177  double thetaXZ() const {return pSave.thetaXZ();}
178  double pPos() const {return pSave.pPos();}
179  double pNeg() const {return pSave.pNeg();}
180  double y() const;
181  double eta() const;
182  double y(double mCut) const;
183  double y(double mCut, RotBstMatrix& M) const;
184  Vec4 vDec() const {return (tauSave > 0. && mSave > 0.)
185  ? vProdSave + tauSave * pSave / mSave : vProdSave;}
186  double xDec() const {return (tauSave > 0. && mSave > 0.)
187  ? vProdSave.px() + tauSave * pSave.px() / mSave : vProdSave.px();}
188  double yDec() const {return (tauSave > 0. && mSave > 0.)
189  ? vProdSave.py() + tauSave * pSave.py() / mSave : vProdSave.py();}
190  double zDec() const {return (tauSave > 0. && mSave > 0.)
191  ? vProdSave.pz() + tauSave * pSave.pz() / mSave : vProdSave.pz();}
192  double tDec() const {return (tauSave > 0. && mSave > 0.)
193  ? vProdSave.e() + tauSave * pSave.e() / mSave : vProdSave.e();}
194 
195  // Methods that can refer back to the event the particle belongs to.
196  virtual int index() const;
197  int iTopCopy() const;
198  int iBotCopy() const;
199  int iTopCopyId(bool simplify = false) const;
200  int iBotCopyId(bool simplify = false) const;
201  vector<int> motherList() const;
202  vector<int> daughterList() const;
203  vector<int> daughterListRecursive() const;
204  vector<int> sisterList(bool traceTopBot = false) const;
205  bool isAncestor(int iAncestor) const;
206  int statusHepMC() const;
207  bool isFinalPartonLevel() const;
208  bool undoDecay();
209 
210  // Get and set Hidden Valley colours, referring back to the event.
211  int colHV() const;
212  int acolHV() const;
213  void colHV(int colHVin);
214  void acolHV(int acolHVin);
215  void colsHV(int colHVin, int acolHVin);
216 
217  // Further output, based on a pointer to a ParticleDataEntry object.
218  string name() const {
219  return (pdePtr != 0) ? pdePtr->name(idSave) : " ";}
220  string nameWithStatus(int maxLen = 20) const;
221  int spinType() const {
222  return (pdePtr != 0) ? pdePtr->spinType() : 0;}
223  int chargeType() const {
224  return (pdePtr != 0) ? pdePtr->chargeType(idSave) : 0;}
225  double charge() const {
226  return (pdePtr != 0) ? pdePtr->charge(idSave) : 0;}
227  bool isCharged() const {
228  return (pdePtr != 0) ? (pdePtr->chargeType(idSave) != 0) : false;}
229  bool isNeutral() const {
230  return (pdePtr != 0) ? (pdePtr->chargeType(idSave) == 0) : false;}
231  int colType() const {
232  return (pdePtr != 0) ? pdePtr->colType(idSave) : 0;}
233  double m0() const {
234  return (pdePtr != 0) ? pdePtr->m0() : 0.;}
235  double mWidth() const {
236  return (pdePtr != 0) ? pdePtr->mWidth() : 0.;}
237  double mMin() const {
238  return (pdePtr != 0) ? pdePtr->mMin() : 0.;}
239  double mMax() const {
240  return (pdePtr != 0) ? pdePtr->mMax() : 0.;}
241  double mSel() const {
242  return (pdePtr != 0) ? pdePtr->mSel() : 0.;}
243  double constituentMass() const {
244  return (pdePtr != 0) ? pdePtr->constituentMass() : 0.;}
245  double tau0() const {
246  return (pdePtr != 0) ? pdePtr->tau0() : 0.;}
247  bool mayDecay() const {
248  return (pdePtr != 0) ? pdePtr->mayDecay() : false;}
249  bool canDecay() const {
250  return (pdePtr != 0) ? pdePtr->canDecay() : false;}
251  bool doExternalDecay() const {
252  return (pdePtr != 0) ? pdePtr->doExternalDecay() : false;}
253  bool isResonance() const {
254  return (pdePtr != 0) ? pdePtr->isResonance() : false;}
255  bool isVisible() const {
256  return (pdePtr != 0) ? pdePtr->isVisible() : false;}
257  bool isLepton() const {
258  return (pdePtr != 0) ? pdePtr->isLepton() : false;}
259  bool isQuark() const {
260  return (pdePtr != 0) ? pdePtr->isQuark() : false;}
261  bool isGluon() const {
262  return (pdePtr != 0) ? pdePtr->isGluon() : false;}
263  bool isDiquark() const {
264  return (pdePtr != 0) ? pdePtr->isDiquark() : false;}
265  bool isParton() const {
266  return (pdePtr != 0) ? pdePtr->isParton() : false;}
267  bool isHadron() const {
268  return (pdePtr != 0) ? pdePtr->isHadron() : false;}
269  bool isExotic() const {
270  return (pdePtr != 0) ? pdePtr->isExotic() : false;}
271  ParticleDataEntry& particleDataEntry() const {return *pdePtr;}
272 
273  // Member functions that perform operations.
274  void rescale3(double fac) {pSave.rescale3(fac);}
275  void rescale4(double fac) {pSave.rescale4(fac);}
276  void rescale5(double fac) {pSave.rescale4(fac); mSave *= fac;}
277  void rot(double thetaIn, double phiIn) {pSave.rot(thetaIn, phiIn);
278  if (hasVertexSave) vProdSave.rot(thetaIn, phiIn);}
279  void bst(double betaX, double betaY, double betaZ) {
280  pSave.bst(betaX, betaY, betaZ);
281  if (hasVertexSave) vProdSave.bst(betaX, betaY, betaZ);}
282  void bst(double betaX, double betaY, double betaZ, double gamma) {
283  pSave.bst(betaX, betaY, betaZ, gamma);
284  if (hasVertexSave) vProdSave.bst(betaX, betaY, betaZ, gamma);}
285  void bst(const Vec4& pBst) {pSave.bst(pBst);
286  if (hasVertexSave) vProdSave.bst(pBst);}
287  void bst(const Vec4& pBst, double mBst) {pSave.bst(pBst, mBst);
288  if (hasVertexSave) vProdSave.bst(pBst, mBst);}
289  void bstback(const Vec4& pBst) {pSave.bstback(pBst);
290  if (hasVertexSave) vProdSave.bstback(pBst);}
291  void bstback(const Vec4& pBst, double mBst) {pSave.bstback(pBst, mBst);
292  if (hasVertexSave) vProdSave.bstback(pBst, mBst);}
293  void rotbst(const RotBstMatrix& M, bool boostVertex = true) {pSave.rotbst(M);
294  if (hasVertexSave && boostVertex) vProdSave.rotbst(M);}
295  void offsetHistory( int minMother, int addMother, int minDaughter,
296  int addDaughter);
297  void offsetCol( int addCol);
298 
299 protected:
300 
301  // Constants: could only be changed in the code itself.
302  static const double TINY;
303 
304  // Properties of the current particle.
305  int idSave, statusSave, mother1Save, mother2Save, daughter1Save,
306  daughter2Save, colSave, acolSave;
307  Vec4 pSave;
308  double mSave, scaleSave, polSave;
309  bool hasVertexSave;
310  Vec4 vProdSave;
311  double tauSave;
312 
313  // Pointer to properties of the particle species.
314  // Should no be saved in a persistent copy of the event record.
315  // The //! below is ROOT notation that this member should not be saved.
316  // Event::restorePtrs() can be called to restore the missing information.
317  ParticleDataEntryPtr pdePtr; //!
318 
319  // Pointer to the whole event record to which the particle belongs (if any).
320  // As above it should not be saved.
321  Event* evtPtr; //!
322 
323 };
324 
325 // Particles invariant mass, mass squared, and momentum dot product.
326 // (Not part of class proper, but tightly linked.)
327 double m(const Particle& pp1, const Particle& pp2);
328 double m2(const Particle& pp1, const Particle& pp2);
329 double m2(const Particle& pp1, const Particle& pp2, const Particle& pp3);
330 double dot4(const Particle& pp1, const Particle& pp2);
331 
332 //==========================================================================
333 
334 // The junction class stores what kind of junction it is, the colour indices
335 // of the legs at the junction and as far out as legs have been traced,
336 // and the status codes assigned for fragmentation of each leg.
337 
338 class Junction {
339 
340 public:
341 
342  // Constructors.
343  Junction() : remainsSave(true), kindSave(0), colSave(), endColSave(),
344  statusSave() { }
345 
346  Junction( int kindIn, int col0In, int col1In, int col2In)
347  : remainsSave(true), kindSave(kindIn), colSave(), endColSave(),
348  statusSave() {
349  colSave[0] = col0In; colSave[1] = col1In; colSave[2] = col2In;
350  for (int j = 0; j < 3; ++j) {
351  endColSave[j] = colSave[j]; } }
352  Junction(const Junction& ju) : remainsSave(ju.remainsSave),
353  kindSave(ju.kindSave), colSave(), endColSave(), statusSave() {
354  for (int j = 0; j < 3; ++j) {
355  colSave[j] = ju.colSave[j]; endColSave[j] = ju.endColSave[j];
356  statusSave[j] = ju.statusSave[j]; } }
357  Junction& operator=(const Junction& ju) {if (this != &ju) {
358  remainsSave = ju.remainsSave; kindSave = ju.kindSave;
359  for (int j = 0; j < 3; ++j) { colSave[j] = ju.colSave[j];
360  endColSave[j] = ju.endColSave[j]; statusSave[j] = ju.statusSave[j]; } }
361  return *this; }
362 
363  // Set values.
364  void remains(bool remainsIn) {remainsSave = remainsIn;}
365  void col(int j, int colIn) {colSave[j] = colIn; endColSave[j] = colIn;}
366  void cols(int j, int colIn, int endColIn) {colSave[j] = colIn;
367  endColSave[j] = endColIn;}
368  void endCol(int j, int endColIn) {endColSave[j] = endColIn;}
369  void status(int j, int statusIn) {statusSave[j] = statusIn;}
370 
371  // Read out value.
372  bool remains() const {return remainsSave;}
373  int kind() const {return kindSave;}
374  int col(int j) const {return colSave[j];}
375  int endCol(int j) const {return endColSave[j];}
376  int status(int j) const {return statusSave[j];}
377 
378 private:
379 
380  // Kind, positions of the three ends and their status codes.
381  bool remainsSave;
382  int kindSave, colSave[3], endColSave[3], statusSave[3];
383 
384 };
385 
386 //==========================================================================
387 
388 // The HVcols class stores Hidden Valley colours for HV-coloured particles.
389 
390 class HVcols {
391 
392 public:
393 
394  // Default constructor and constructor with standard input.
395  HVcols() : iHV(0), colHV(0), acolHV(0) { }
396  HVcols( int iHVin, int colHVin, int acolHVin) : iHV(iHVin),
397  colHV(colHVin), acolHV(acolHVin) {}
398 
399  // Index of HV-particle and its HV-colour and HV-anticolour.
400  int iHV, colHV, acolHV;
401 
402 };
403 
404 //==========================================================================
405 
406 // The StringBreaks class stores information about how a single string has
407 // been broken up into quark/antiquark and diquark/anti-diquark pairs.
408 
410 
411 public:
412 
413  // Set and get string end indices.
414  void setEnds(int iPosIn, int iNegIn) {iPos = iPosIn; iNeg = iNegIn;}
415  int posEnd() {return iPos;}
416  int negEnd() {return iNeg;}
417 
418  // Clear the breaks.
419  void clear() {breaks.clear();}
420 
421  // Add a string break by particle ID.
422  void add(int id) {breaks[abs(id)] += 1;}
423 
424  // Returns the number of breaks for a given particle ID, or the the sum of
425  // all, light quark, or diquark breaks.
426  const map<int, int>& nId() {return breaks;}
427  int nId(int id) const {
428  auto itr = breaks.find(abs(id));
429  return itr == breaks.end() ? 0 : itr->second;}
430  int nAll() const {int nSum = 0; for (auto &id : breaks) nSum += id.second;
431  return nSum;}
432  int nQuark() const {return nId(1) + nId(2) + nId(3) + nId(4);}
433  int nDiquark() const {int nSum = 0;
434  for (const auto &id : breaks)
435  if (id.first > 1000 && id.first < 10000 && (id.first/10)%10 == 0)
436  nSum += id.second;
437  return nSum;}
438 
439 private:
440 
441  // Index of string end partons and sums of all, quark, and diquark breaks.
442  int iPos{0}, iNeg{0};
443 
444  // Number of breaks mapped by particle ID.
445  map<int, int> breaks{};
446 
447 };
448 
449 //==========================================================================
450 
451 // The Event class holds all info on the generated event.
452 
453 class Event {
454 
455 public:
456 
457  // Constructors.
458  Event(int capacity = 100) : startColTag(100), maxColTag(100),
459  savedSize(0), savedJunctionSize(0), savedHVcolsSize(0),
460  savedPartonLevelSize(0), scaleSave(0.), scaleSecondSave(0.),
461  headerList("----------------------------------------"),
462  particleDataPtr(0) { entry.reserve(capacity); }
463  Event& operator=(const Event& oldEvent);
464  Event(const Event& oldEvent) {*this = oldEvent;}
465 
466  // Initialize header for event listing, particle data table, and colour.
467  void init( string headerIn = "", ParticleData* particleDataPtrIn = 0,
468  int startColTagIn = 100) {
469  headerList.replace(0, headerIn.length() + 2, headerIn + " ");
470  particleDataPtr = particleDataPtrIn; startColTag = startColTagIn;}
471 
472  // Clear event record.
473  void clear() {entry.resize(0); maxColTag = startColTag;
474  savedPartonLevelSize = 0; scaleSave = 0.; scaleSecondSave = 0.;
475  clearJunctions(); clearHV(); clearStringBreaks();}
476  void free() {vector<Particle>().swap(entry); maxColTag = startColTag;
477  savedPartonLevelSize = 0; scaleSave = 0.; scaleSecondSave = 0.;
478  clearJunctions(); clearHV(); clearStringBreaks();}
479 
480  // Clear event record, and set first particle empty.
481  void reset() {clear(); append(90, -11, 0, 0, 0., 0., 0., 0., 0.);}
482 
483  // Overload index operator to access element of event record.
484  Particle& operator[](int i) {return entry.at(i);}
485  const Particle& operator[](int i) const {return entry.at(i);}
486 
487  // Implement standard references to elements in the particle array.
488  Particle& front() {return entry.front();}
489  Particle& at(int i) {return entry.at(i);}
490  Particle& back() {return entry.back();}
491  const Particle& front() const {return entry.front();}
492  const Particle& at(int i) const {return entry.at(i);}
493  const Particle& back() const {return entry.back();}
494 
495  // Implement iterators for the particle array.
496  vector<Pythia8::Particle>::iterator begin() { return entry.begin(); }
497  vector<Pythia8::Particle>::iterator end() { return entry.end(); }
498  vector<Pythia8::Particle>::const_iterator begin() const
499  { return entry.begin(); }
500  vector<Pythia8::Particle>::const_iterator end() const
501  { return entry.end(); }
502 
503  // Event record size.
504  int size() const {return entry.size();}
505 
506  // Put a new particle at the end of the event record; return index.
507  int append(Particle entryIn) {
508  entry.push_back(entryIn); setEvtPtr();
509  if (entryIn.col() > maxColTag) maxColTag = entryIn.col();
510  if (entryIn.acol() > maxColTag) maxColTag = entryIn.acol();
511  return entry.size() - 1;
512  }
513  int append(int id, int status, int mother1, int mother2, int daughter1,
514  int daughter2, int col, int acol, double px, double py, double pz,
515  double e, double m = 0., double scaleIn = 0., double polIn = 9.) {
516  entry.push_back( Particle(id, status, mother1, mother2, daughter1,
517  daughter2, col, acol, px, py, pz, e, m, scaleIn, polIn) ); setEvtPtr();
518  if (col > maxColTag) maxColTag = col;
519  if (acol > maxColTag) maxColTag = acol;
520  return entry.size() - 1;
521  }
522  int append(int id, int status, int mother1, int mother2, int daughter1,
523  int daughter2, int col, int acol, Vec4 p, double m = 0.,
524  double scaleIn = 0., double polIn = 9.) {
525  entry.push_back( Particle(id, status, mother1, mother2, daughter1,
526  daughter2, col, acol, p, m, scaleIn, polIn) ); setEvtPtr();
527  if (col > maxColTag) maxColTag = col;
528  if (acol > maxColTag) maxColTag = acol;
529  return entry.size() - 1;
530  }
531 
532  // Brief versions of append: no mothers and no daughters.
533  int append(int id, int status, int col, int acol, double px, double py,
534  double pz, double e, double m = 0., double scaleIn = 0.,
535  double polIn = 9.) { entry.push_back( Particle(id, status, 0, 0, 0, 0,
536  col, acol, px, py, pz, e, m, scaleIn, polIn) ); setEvtPtr();
537  if (col > maxColTag) maxColTag = col;
538  if (acol > maxColTag) maxColTag = acol;
539  return entry.size() - 1;
540  }
541  int append(int id, int status, int col, int acol, Vec4 p, double m = 0.,
542  double scaleIn = 0., double polIn = 9.) {entry.push_back( Particle(id,
543  status, 0, 0, 0, 0, col, acol, p, m, scaleIn, polIn) ); setEvtPtr();
544  if (col > maxColTag) maxColTag = col;
545  if (acol > maxColTag) maxColTag = acol;
546  return entry.size() - 1;
547  }
548 
549  // Set pointer to the event for a particle, by default latest one.
550  void setEvtPtr(int iSet = -1) {if (iSet < 0) iSet = entry.size() - 1;
551  entry[iSet].setEvtPtr( this);}
552 
553  // Add a copy of an existing particle at the end of the event record.
554  int copy(int iCopy, int newStatus = 0);
555 
556  // List the particles in an event.
557  void list(bool showScaleAndVertex = false,
558  bool showMothersAndDaughters = false, int precision = 3) const;
559 
560  // Remove last n entries.
561  void popBack(int nRemove = 1) { if (nRemove ==1) entry.pop_back();
562  else {int newSize = max( 0, size() - nRemove);
563  entry.resize(newSize);} }
564 
565  // Remove entries from iFirst to iLast, including endpoints, and fix history.
566  // (To the extent possible; history pointers in removed range are zeroed.)
567  void remove(int iFirst, int iLast, bool shiftHistory = true);
568 
569  // Restore all ParticleDataEntryPtr pointers in the Particle vector.
570  // Useful when a persistent copy of the event record is read back in.
571  void restorePtrs() { for (int i = 0; i < size(); ++i) setEvtPtr(i); }
572 
573  // Save or restore the size of the event record (throwing at the end).
574  void saveSize() {savedSize = entry.size();}
575  void restoreSize() {entry.resize(savedSize);}
576  int savedSizeValue() {return savedSize;}
577 
578  // Initialize and access colour tag information.
579  void initColTag(int colTag = 0) {maxColTag = max( colTag,startColTag);}
580  int lastColTag() const {return maxColTag;}
581  int nextColTag() {return ++maxColTag;}
582 
583  // Access scale for which event as a whole is defined.
584  void scale( double scaleIn) {scaleSave = scaleIn;}
585  double scale() const {return scaleSave;}
586 
587  // Need a second scale if two hard interactions in event.
588  void scaleSecond( double scaleSecondIn) {scaleSecondSave = scaleSecondIn;}
589  double scaleSecond() const {return scaleSecondSave;}
590 
591  // Find complete list of daughters.
592  // Note: temporarily retained for CMS compatibility. Do not use!
593  vector<int> daughterList(int i) const {return entry[i].daughterList();}
594 
595  // Return number of final-state particles, optionally charged only.
596  int nFinal(bool chargedOnly = false) const {
597  int nFin = 0;
598  for (int i = 0; i < size(); ++i)
599  if (entry[i].isFinal() && (!chargedOnly || entry[i].isCharged()))
600  ++nFin;
601  return nFin; }
602 
603  // Find separation in y, eta, phi or R between two particles.
604  double dyAbs(int i1, int i2) const {
605  return abs( entry[i1].y() - entry[i2].y() ); }
606  double detaAbs(int i1, int i2) const {
607  return abs( entry[i1].eta() - entry[i2].eta() ); }
608  double dphiAbs(int i1, int i2) const {
609  double dPhiTmp = abs( entry[i1].phi() - entry[i2].phi() );
610  if (dPhiTmp > M_PI) dPhiTmp = 2. * M_PI - dPhiTmp;
611  return dPhiTmp; }
612  double RRapPhi(int i1, int i2) const {
613  return sqrt( pow2(dyAbs(i1, i2)) + pow2(dphiAbs(i1, i2)) ); }
614  double REtaPhi(int i1, int i2) const {
615  return sqrt( pow2(detaAbs(i1, i2)) + pow2(dphiAbs(i1, i2)) ); }
616 
617  // Member functions for rotations and boosts of an event.
618  void rot(double theta, double phi)
619  {for (int i = 0; i < size(); ++i) entry[i].rot(theta, phi);}
620  void bst(double betaX, double betaY, double betaZ)
621  {for (int i = 0; i < size(); ++i) entry[i].bst(betaX, betaY, betaZ);}
622  void bst(double betaX, double betaY, double betaZ, double gamma)
623  {for (int i = 0; i < size(); ++i) entry[i].bst(betaX, betaY, betaZ,
624  gamma);}
625  void bst(const Vec4& vec)
626  {for (int i = 0; i < size(); ++i) entry[i].bst(vec);}
627  void rotbst(const RotBstMatrix& M, bool boostVertices = true)
628  {for (int i = 0; i < size(); ++i) entry[i].rotbst(M, boostVertices);}
629 
630  // Clear the list of junctions.
631  void clearJunctions() {junction.resize(0);}
632 
633  // Add a junction to the list, study it or extra input.
634  int appendJunction( int kind, int col0, int col1, int col2)
635  { junction.push_back( Junction( kind, col0, col1, col2) );
636  return junction.size() - 1;}
637  int appendJunction(Junction junctionIn) {junction.push_back(junctionIn);
638  return junction.size() - 1;}
639  int sizeJunction() const {return junction.size();}
640  bool remainsJunction(int i) const {return junction[i].remains();}
641  void remainsJunction(int i, bool remainsIn) {junction[i].remains(remainsIn);}
642  int kindJunction(int i) const {return junction[i].kind();}
643  int colJunction( int i, int j) const {return junction[i].col(j);}
644  void colJunction( int i, int j, int colIn) {junction[i].col(j, colIn);}
645  int endColJunction( int i, int j) const {return junction[i].endCol(j);}
646  void endColJunction( int i, int j, int endColIn)
647  {junction[i].endCol(j, endColIn);}
648  int statusJunction( int i, int j) const {return junction[i].status(j);}
649  void statusJunction( int i, int j, int statusIn)
650  {junction[i].status(j, statusIn);}
651  Junction& getJunction(int i) {return junction[i];}
652  const Junction& getJunction(int i) const {return junction[i];}
653  void eraseJunction(int i);
654 
655  // Save or restore the size of the junction list (throwing at the end).
656  void saveJunctionSize() {savedJunctionSize = junction.size();}
657  void restoreJunctionSize() {junction.resize(savedJunctionSize);}
658 
659  // List any junctions in the event; for debug mainly.
660  void listJunctions() const;
661 
662  // Tell whether event has Hidden Valley colours stored.
663  bool hasHVcols() const {return (hvCols.size() > 0);}
664 
665  // List any Hidden Valley colours. Find largest HV colour.
666  void listHVcols() const;
667  int maxHVcols() const;
668 
669  // Save or restore the size of the HV-coloured list (throwing at the end).
670  void saveHVcolsSize() {savedHVcolsSize = hvCols.size();}
671  void restoreHVcolsSize() {hvCols.resize(savedHVcolsSize);}
672 
673  // Save event record size at Parton Level, i.e. before hadronization.
674  void savePartonLevelSize() {savedPartonLevelSize = entry.size();}
675 
676  // Add information about string breaks for a single string.
677  void addStringBreaks(StringBreaks& sbIn) {stringBreaks.push_back(sbIn);}
678 
679  // Clear string breaks information.
680  void clearStringBreaks() {stringBreaks.clear();}
681 
682  // Get information about all string breaks in the event.
683  const vector<StringBreaks> &getStringBreaks() const {return stringBreaks;}
684 
685  // Operator overloading allows to append one event to an existing one.
686  // Warning: particles should be OK, but some other information unreliable.
687  Event& operator+=(const Event& addEvent);
688 
689  // Direct access to the particles via constant pointer.
690  const vector<Particle>* particles() const {return &entry;}
691 
692 private:
693 
694  // The Particle class needs to access particle data.
695  friend class Particle;
696 
697  // Constants: could only be changed in the code itself.
698  static const int IPERLINE;
699 
700  // Initialization data, normally only set once.
701  int startColTag;
702 
703  // The event: a vector containing all particles (entries).
704  // The explicit use of Pythia8:: qualifier patches a limitation in ROOT.
705  vector<Pythia8::Particle> entry;
706 
707  // The list of junctions.
708  // The explicit use of Pythia8:: qualifier patches a limitation in ROOT.
709  vector<Pythia8::Junction> junction;
710 
711  // The list of Hidden-Valley-coloured partons.
712  // The explicit use of Pythia8:: qualifier patches a limitation in ROOT.
713  vector<Pythia8::HVcols> hvCols;
714 
715  // The list of string break information for each string in the event.
716  vector<Pythia8::StringBreaks> stringBreaks;
717 
718  // Find index in Hidden Valley list for a particle in the event record.
719  bool findIndexHV(int iIn) { if (iIn > 0 && iIn == iEventHV) return true;
720  for (int i = 0; i < int(hvCols.size()); ++i) if (hvCols[i].iHV == iIn)
721  {iEventHV = iIn; iIndexHV = i; return true; }
722  return false; }
723  int iEventHV, iIndexHV;
724 
725  // Clear the list of Hidden Valley colours. Reset indices.
726  void clearHV() {hvCols.resize(0); iEventHV = -1; iIndexHV = -1;}
727 
728  // The maximum colour tag of the event so far.
729  int maxColTag;
730 
731  // Saved entry and junction list sizes, for simple restoration.
732  int savedSize, savedJunctionSize, savedHVcolsSize, savedPartonLevelSize;
733 
734  // The scale of the event; linear quantity in GeV.
735  double scaleSave, scaleSecondSave;
736 
737  // Header specification in event listing (at most 40 characters wide).
738  string headerList;
739 
740  // Pointer to the particle data table.
741  // The //! below is ROOT notation that this member should not be saved.
742  ParticleData* particleDataPtr; //!
743 
744 };
745 
746 //==========================================================================
747 
748 } // end namespace Pythia8
749 
750 #endif // Pythia8_Event_H
virtual ~Particle()
Destructor.
Definition: Event.h:81
ParticleDataEntryPtr pdePtr
Definition: Event.h:317
constexpr double pow2(const double &x)
Powers of small integers - for balance speed/code clarity.
Definition: PythiaStdlib.h:182
const map< int, int > & nId()
Definition: Event.h:426
const vector< Particle > * particles() const
Direct access to the particles via constant pointer.
Definition: Event.h:690
void clear()
Clear the breaks.
Definition: Event.h:419
int append(int id, int status, int col, int acol, double px, double py, double pz, double e, double m=0., double scaleIn=0., double polIn=9.)
Brief versions of append: no mothers and no daughters.
Definition: Event.h:533
This class holds info on a single particle species.
Definition: ParticleData.h:125
void clearJunctions()
Clear the list of junctions.
Definition: Event.h:631
bool isAncestor(int iAncestor) const
Definition: Event.cc:332
void bstback(const Vec4 &pIn)
Boost given by a Vec4 p; boost in opposite direction.
Definition: Basics.cc:509
void rescale3(double fac)
Member functions that perform operations.
Definition: Basics.h:95
The HVcols class stores Hidden Valley colours for HV-coloured particles.
Definition: Event.h:390
void setEnds(int iPosIn, int iNegIn)
Set and get string end indices.
Definition: Event.h:414
The Event class holds all info on the generated event.
Definition: Event.h:453
bool isFinalPartonLevel() const
Check if particle belonged to the final state at the Parton Level.
Definition: Event.cc:411
double m2() const
Member functions for output; derived double quantities.
Definition: Event.h:161
void addStringBreaks(StringBreaks &sbIn)
Add information about string breaks for a single string.
Definition: Event.h:677
double RRapPhi(const Vec4 &v1, const Vec4 &v2)
R is distance in cylindrical (y/eta, phi) coordinates.
Definition: Basics.cc:734
int iBotCopyId(bool simplify=false) const
Definition: Event.cc:153
void setEvtPtr(int iSet=-1)
Set pointer to the event for a particle, by default latest one.
Definition: Event.h:550
Definition: Event.h:338
HVcols()
Default constructor and constructor with standard input.
Definition: Event.h:395
vector< int > sisterList(bool traceTopBot=false) const
Definition: Event.cc:301
void id(int idIn)
Member functions for input.
Definition: Event.h:88
void clear()
Clear event record.
Definition: Event.h:473
void rot(double theta, double phi)
Member functions for rotations and boosts of an event.
Definition: Event.h:618
Junction()
Constructors.
Definition: Event.h:343
void rotbst(const RotBstMatrix &M)
Arbitrary combination of rotations and boosts defined by 4 * 4 matrix.
Definition: Basics.cc:551
int colHV() const
Get and set Hidden Valley colours, referring back to the event.
Definition: Event.cc:522
void scale(double scaleIn)
Access scale for which event as a whole is defined.
Definition: Event.h:584
void remains(bool remainsIn)
Set values.
Definition: Event.h:364
static const double TINY
Constants: could only be changed in the code itself.
Definition: Event.h:302
void saveSize()
Save or restore the size of the event record (throwing at the end).
Definition: Event.h:574
vector< int > daughterListRecursive() const
Definition: Event.cc:270
const vector< StringBreaks > & getStringBreaks() const
Get information about all string breaks in the event.
Definition: Event.h:683
void reset()
Clear event record, and set first particle empty.
Definition: Event.h:481
void rot(double thetaIn, double phiIn)
Rotation (simple).
Definition: Basics.cc:368
int append(Particle entryIn)
Put a new particle at the end of the event record; return index.
Definition: Event.h:507
int statusHepMC() const
Convert internal Pythia status codes to the HepMC status conventions.
Definition: Event.cc:383
void saveHVcolsSize()
Save or restore the size of the HV-coloured list (throwing at the end).
Definition: Event.h:670
vector< int > daughterList() const
Find complete list of daughters.
Definition: Event.cc:225
void initColTag(int colTag=0)
Initialize and access colour tag information.
Definition: Event.h:579
void clearStringBreaks()
Clear string breaks information.
Definition: Event.h:680
double REtaPhi(const Vec4 &v1, const Vec4 &v2)
Distance in cylindrical (eta, phi) coordinates.
Definition: Basics.cc:745
Particle & operator[](int i)
Overload index operator to access element of event record.
Definition: Event.h:484
bool undoDecay()
Definition: Event.cc:426
int iHV
Index of HV-particle and its HV-colour and HV-anticolour.
Definition: Event.h:400
double y() const
Functions for rapidity and pseudorapidity.
Definition: Event.cc:54
int id() const
Member functions for output.
Definition: Event.h:127
Particle()
Constructors.
Definition: Event.h:37
double dyAbs(int i1, int i2) const
Find separation in y, eta, phi or R between two particles.
Definition: Event.h:604
int idSave
Properties of the current particle.
Definition: Event.h:305
int iTopCopy() const
Trace the first and last copy of one and the same particle.
Definition: Event.cc:95
int appendJunction(int kind, int col0, int col1, int col2)
Add a junction to the list, study it or extra input.
Definition: Event.h:634
void bst(double betaX, double betaY, double betaZ)
Boost (simple).
Definition: Basics.cc:434
void popBack(int nRemove=1)
Remove last n entries.
Definition: Event.h:561
int size() const
Event record size.
Definition: Event.h:504
Definition: Event.h:32
bool hasHVcols() const
Tell whether event has Hidden Valley colours stored.
Definition: Event.h:663
vector< int > motherList() const
Find complete list of mothers.
Definition: Event.cc:189
Event(int capacity=100)
Constructors.
Definition: Event.h:458
int idAbs() const
Member functions for output; derived int and bool quantities.
Definition: Event.h:152
Particle & front()
Implement standard references to elements in the particle array.
Definition: Event.h:488
Definition: Basics.h:251
vector< Pythia8::Particle >::iterator begin()
Implement iterators for the particle array.
Definition: Event.h:496
void setPDEPtr(ParticleDataEntryPtr pdePtrIn=nullptr)
Set pointer to the particle data species of the particle.
Definition: Event.cc:30
double phi(const Vec4 &v1, const Vec4 &v2)
phi is azimuthal angle between v1 and v2 around z axis.
Definition: Basics.cc:674
void scaleSecond(double scaleSecondIn)
Need a second scale if two hard interactions in event.
Definition: Event.h:588
void rescale3(double fac)
Member functions that perform operations.
Definition: Event.h:274
int nFinal(bool chargedOnly=false) const
Return number of final-state particles, optionally charged only.
Definition: Event.h:596
string name() const
Further output, based on a pointer to a ParticleDataEntry object.
Definition: Event.h:218
void setEvtPtr(Event *evtPtrIn)
Member functions to set the Event and ParticleDataEntry pointers.
Definition: Event.h:84
void add(int id)
Add a string break by particle ID.
Definition: Event.h:422
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
double m(const Vec4 &v1)
Invariant mass and its square.
Definition: Basics.cc:576
vector< int > daughterList(int i) const
Definition: Event.h:593
void saveJunctionSize()
Save or restore the size of the junction list (throwing at the end).
Definition: Event.h:656
void init(string headerIn="", ParticleData *particleDataPtrIn=0, int startColTagIn=100)
Initialize header for event listing, particle data table, and colour.
Definition: Event.h:467
void savePartonLevelSize()
Save event record size at Parton Level, i.e. before hadronization.
Definition: Event.h:674
void restorePtrs()
Definition: Event.h:571
Definition: Event.h:409
int intPol() const
Find out if polarization is (close to) an integer.
Definition: Event.cc:40
void offsetHistory(int minMother, int addMother, int minDaughter, int addDaughter)
Add offsets to mother and daughter pointers (must be non-negative).
Definition: Event.cc:575
bool remains() const
Read out value.
Definition: Event.h:372
void offsetCol(int addCol)
Add offsets to colour and anticolour (must be positive).
Definition: Event.cc:590
int iTopCopyId(bool simplify=false) const
Definition: Event.cc:121
This class holds a map of all ParticleDataEntries.
Definition: ParticleData.h:422
Definition: Basics.h:32
string nameWithStatus(int maxLen=20) const
Particle name, with status but imposed maximum length -> may truncate.
Definition: Event.cc:558
Event * evtPtr
!
Definition: Event.h:321
virtual int index() const
Methods that can refer back to the event the particle belongs to.
Definition: Event.cc:87