StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ParticleData.h
1 // ParticleData.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 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 classes containing particle data.
7 // DecayChannel contains info on a single decay channel.
8 // ParticleDataEntry contains info on a single particle species.
9 // ParticleData collects info on all particles as a map.
10 
11 #ifndef Pythia8_ParticleData_H
12 #define Pythia8_ParticleData_H
13 
14 #include "Pythia8/Basics.h"
15 #include "Pythia8/Info.h"
16 #include "Pythia8/PythiaStdlib.h"
17 #include "Pythia8/Settings.h"
18 #include "Pythia8/StandardModel.h"
19 
20 namespace Pythia8 {
21 
22 //==========================================================================
23 
24 // Forward reference to some classes.
25 class ParticleData;
26 class ResonanceWidths;
27 class CoupSM;
28 class CoupSUSY;
29 class SUSYResonanceWidths;
30 
31 //==========================================================================
32 
33 // This class holds info on a single decay channel.
34 
35 class DecayChannel {
36 
37 public:
38 
39  // Constructor.
40  DecayChannel(int onModeIn = 0, double bRatioIn = 0., int meModeIn = 0,
41  int prod0 = 0, int prod1 = 0, int prod2 = 0, int prod3 = 0,
42  int prod4 = 0, int prod5 = 0, int prod6 = 0, int prod7 = 0)
43  : onModeSave(onModeIn), bRatioSave(bRatioIn), currentBRSave(0.),
44  onShellWidthSave(0.), openSecPos(1.), openSecNeg(1.),
45  meModeSave(meModeIn), nProd(0), prod(), hasChangedSave(true) {
46  prod[0] = prod0; prod[1] = prod1; prod[2] = prod2; prod[3] = prod3;
47  prod[4] = prod4; prod[5] = prod5; prod[6] = prod6; prod[7] = prod7;
48  for (int j = 0; j < 8; ++j) if (prod[j] != 0 && j == nProd) ++nProd; }
49 
50  // Copy constructor.
51  DecayChannel( const DecayChannel& oldDC) {
52  onModeSave = oldDC.onModeSave; bRatioSave = oldDC.bRatioSave;
53  currentBRSave = oldDC.currentBRSave;
54  onShellWidthSave = oldDC.onShellWidthSave; openSecPos = oldDC.openSecPos;
55  openSecNeg = oldDC.openSecNeg; meModeSave = oldDC.meModeSave;
56  nProd = oldDC.nProd; for (int j = 0; j < 8; ++j) prod[j] = oldDC.prod[j];
57  hasChangedSave = oldDC.hasChangedSave; }
58 
59  // Assignment operator.
60  DecayChannel& operator=( const DecayChannel& oldDC) { if (this != &oldDC) {
61  onModeSave = oldDC.onModeSave; bRatioSave = oldDC.bRatioSave;
62  currentBRSave = oldDC.currentBRSave;
63  onShellWidthSave = oldDC.onShellWidthSave; openSecPos = oldDC.openSecPos;
64  openSecNeg = oldDC.openSecNeg; meModeSave = oldDC.meModeSave;
65  nProd = oldDC.nProd; for (int j = 0; j < 8; ++j) prod[j] = oldDC.prod[j];
66  hasChangedSave = oldDC.hasChangedSave; } return *this; }
67 
68  // Member functions for input.
69  void onMode(int onModeIn) {onModeSave = onModeIn; hasChangedSave = true;}
70  void bRatio(double bRatioIn, bool countAsChanged = true) {
71  bRatioSave = bRatioIn; if (countAsChanged) hasChangedSave = true;}
72  void rescaleBR(double fac) {bRatioSave *= fac; hasChangedSave = true;}
73  void meMode(int meModeIn) {meModeSave = meModeIn; hasChangedSave = true;}
74  void multiplicity(int multIn) {nProd = multIn; hasChangedSave = true;}
75  void product(int i, int prodIn) {prod[i] = prodIn; nProd = 0;
76  for (int j = 0; j < 8; ++j) if (prod[j] != 0 && j == nProd) ++nProd;
77  hasChangedSave = true;}
78  void setHasChanged(bool hasChangedIn) {hasChangedSave = hasChangedIn;}
79 
80  // Member functions for output.
81  int onMode() const {return onModeSave;}
82  double bRatio() const {return bRatioSave;}
83  int meMode() const {return meModeSave;}
84  int multiplicity() const {return nProd;}
85  int product(int i) const {return (i >= 0 && i < nProd) ? prod[i] : 0;}
86  bool hasChanged() const { return hasChangedSave;}
87 
88  // Check for presence of particles anywhere in decay list.
89  bool contains(int id1) const;
90  bool contains(int id1, int id2) const;
91  bool contains(int id1, int id2, int id3) const;
92 
93  // Input/output for current selection of decay modes.
94  // Takes into account on/off switches and dynamic width for resonances.
95  void currentBR(double currentBRIn) {currentBRSave = currentBRIn;}
96  double currentBR() const {return currentBRSave;}
97 
98  // Input/output for nominal partial width; used by resonances.
99  void onShellWidth(double onShellWidthIn) {
100  onShellWidthSave = onShellWidthIn;}
101  double onShellWidth() const {return onShellWidthSave;}
102  void onShellWidthFactor(double factor) {onShellWidthSave *= factor;}
103 
104  // Input/output for fraction of secondary open widths; used by resonances.
105  void openSec(int idSgn, double openSecIn) {
106  if (idSgn > 0) openSecPos = openSecIn; else openSecNeg = openSecIn;}
107  double openSec(int idSgn) const {
108  return (idSgn > 0) ? openSecPos : openSecNeg;}
109 
110 private:
111 
112  // Decay channel info.
113  int onModeSave;
114  double bRatioSave, currentBRSave, onShellWidthSave, openSecPos,
115  openSecNeg;
116  int meModeSave, nProd, prod[8];
117  bool hasChangedSave;
118 
119 };
120 
121 //==========================================================================
122 
123 // This class holds info on a single particle species.
124 
125 class ParticleDataEntry {
126 
127 public:
128 
129  // Constructors: for antiparticle exists or not.
130  ParticleDataEntry(int idIn = 0, string nameIn = " ",
131  int spinTypeIn = 0, int chargeTypeIn = 0, int colTypeIn = 0,
132  double m0In = 0., double mWidthIn = 0., double mMinIn = 0.,
133  double mMaxIn = 0., double tau0In = 0., bool varWidthIn = false)
134  : idSave(abs(idIn)), nameSave(nameIn), antiNameSave("void"),
135  spinTypeSave(spinTypeIn), chargeTypeSave(chargeTypeIn),
136  colTypeSave(colTypeIn), m0Save(m0In), mWidthSave (mWidthIn),
137  mMinSave(mMinIn), mMaxSave(mMaxIn), tau0Save(tau0In),
138  constituentMassSave(), hasAntiSave(false), isResonanceSave(),
139  mayDecaySave(), tauCalcSave(true), varWidthSave(varWidthIn),
140  doExternalDecaySave(), isVisibleSave(), doForceWidthSave(),
141  hasChangedSave(true), hasChangedMMinSave(false),
142  hasChangedMMaxSave(false), modeBWnow(), modeTau0now(), atanLow(),
143  atanDif(), mThr(), currentBRSum(), resonancePtr(0), particleDataPtr() {
144  setDefaults();}
145  ParticleDataEntry(int idIn, string nameIn, string antiNameIn,
146  int spinTypeIn = 0, int chargeTypeIn = 0, int colTypeIn = 0,
147  double m0In = 0., double mWidthIn = 0., double mMinIn = 0.,
148  double mMaxIn = 0., double tau0In = 0., bool varWidthIn = false)
149  : idSave(abs(idIn)), nameSave(nameIn), antiNameSave(antiNameIn),
150  spinTypeSave(spinTypeIn), chargeTypeSave(chargeTypeIn),
151  colTypeSave(colTypeIn), m0Save(m0In), mWidthSave (mWidthIn),
152  mMinSave(mMinIn), mMaxSave(mMaxIn), tau0Save(tau0In),
153  constituentMassSave(), hasAntiSave(true), isResonanceSave(),
154  mayDecaySave(), tauCalcSave(true), varWidthSave(varWidthIn),
155  doExternalDecaySave(), isVisibleSave(), doForceWidthSave(),
156  hasChangedSave(true), hasChangedMMinSave(false),
157  hasChangedMMaxSave(false), modeBWnow(), modeTau0now(), atanLow(),
158  atanDif(), mThr(), currentBRSum(), resonancePtr(0), particleDataPtr() {
159  setDefaults(); if (toLower(antiNameIn) == "void") hasAntiSave = false;}
160 
161  // Copy constructor.
162  ParticleDataEntry( const ParticleDataEntry& oldPDE) {idSave = oldPDE.idSave;
163  nameSave = oldPDE.nameSave; antiNameSave = oldPDE.antiNameSave;
164  spinTypeSave = oldPDE.spinTypeSave; chargeTypeSave = oldPDE.chargeTypeSave;
165  colTypeSave = oldPDE.colTypeSave; m0Save = oldPDE.m0Save;
166  mWidthSave = oldPDE.mWidthSave; mMinSave = oldPDE.mMinSave;
167  mMaxSave = oldPDE.mMaxSave; tau0Save = oldPDE.tau0Save;
168  varWidthSave = oldPDE.varWidthSave;
169  constituentMassSave = oldPDE.constituentMassSave;
170  hasAntiSave = oldPDE.hasAntiSave; isResonanceSave = oldPDE.isResonanceSave;
171  mayDecaySave = oldPDE.mayDecaySave; tauCalcSave = oldPDE.tauCalcSave;
172  doExternalDecaySave = oldPDE.doExternalDecaySave; isVisibleSave
173  = oldPDE.isVisibleSave; doForceWidthSave = oldPDE.doForceWidthSave;
174  hasChangedSave = oldPDE.hasChangedSave; hasChangedMMinSave
175  = oldPDE.hasChangedMMinSave; hasChangedMMaxSave
176  = oldPDE.hasChangedMMaxSave; modeTau0now = oldPDE.modeTau0now; modeBWnow
177  = oldPDE.modeBWnow; atanLow = oldPDE.atanLow; atanDif = oldPDE.atanDif;
178  mThr = oldPDE.mThr;
179  for (int i = 0; i < int(oldPDE.channels.size()); ++i) {
180  DecayChannel oldDC = oldPDE.channels[i]; channels.push_back(oldDC); }
181  currentBRSum = oldPDE.currentBRSum; resonancePtr = oldPDE.resonancePtr;
182  particleDataPtr = oldPDE.particleDataPtr; }
183 
184  // Assignment operator.
185  ParticleDataEntry& operator=( const ParticleDataEntry& oldPDE) {
186  if (this != &oldPDE) { idSave = oldPDE.idSave;
187  nameSave = oldPDE.nameSave; antiNameSave = oldPDE.antiNameSave;
188  spinTypeSave = oldPDE.spinTypeSave; chargeTypeSave = oldPDE.chargeTypeSave;
189  colTypeSave = oldPDE.colTypeSave; m0Save = oldPDE.m0Save;
190  mWidthSave = oldPDE.mWidthSave; mMinSave = oldPDE.mMinSave;
191  mMaxSave = oldPDE.mMaxSave; tau0Save = oldPDE.tau0Save;
192  varWidthSave = oldPDE.varWidthSave;
193  constituentMassSave = oldPDE.constituentMassSave;
194  hasAntiSave = oldPDE.hasAntiSave; isResonanceSave = oldPDE.isResonanceSave;
195  mayDecaySave = oldPDE.mayDecaySave; tauCalcSave = oldPDE.tauCalcSave;
196  doExternalDecaySave = oldPDE.doExternalDecaySave; isVisibleSave
197  = oldPDE.isVisibleSave; doForceWidthSave = oldPDE.doForceWidthSave;
198  hasChangedSave = oldPDE.hasChangedSave; hasChangedMMinSave
199  = oldPDE.hasChangedMMinSave; hasChangedMMaxSave
200  = oldPDE.hasChangedMMaxSave; modeBWnow = oldPDE.modeBWnow; atanLow
201  = oldPDE.atanLow; atanDif = oldPDE.atanDif; mThr = oldPDE.mThr;
202  for (int i = 0; i < int(oldPDE.channels.size()); ++i) {
203  DecayChannel oldDC = oldPDE.channels[i]; channels.push_back(oldDC); }
204  currentBRSum = oldPDE.currentBRSum; resonancePtr = 0;
205  particleDataPtr = 0; } return *this; }
206 
207  // Destructor: delete any ResonanceWidths object.
208  ~ParticleDataEntry();
209 
210  // Initialization of some particle flags.
211  void setDefaults();
212 
213  // Store pointer to whole particle data table/database.
214  void initPtr( ParticleData* particleDataPtrIn) {
215  particleDataPtr = particleDataPtrIn;}
216 
217  // Reset all the properties of an existing particle.
218  void setAll(string nameIn, string antiNameIn, int spinTypeIn = 0,
219  int chargeTypeIn = 0, int colTypeIn = 0, double m0In = 0.,
220  double mWidthIn = 0., double mMinIn = 0., double mMaxIn = 0.,
221  double tau0In = 0., double varWidthIn = false)
222  {nameSave = nameIn; antiNameSave = antiNameIn; hasAntiSave = true;
223  if (toLower(antiNameIn) == "void") hasAntiSave = false;
224  spinTypeSave = spinTypeIn; chargeTypeSave = chargeTypeIn;
225  colTypeSave = colTypeIn; m0Save = m0In; mWidthSave = mWidthIn;
226  setMMin(mMinIn); setMMax(mMaxIn); tau0Save = tau0In;
227  varWidthSave = varWidthIn; setDefaults(); hasChangedSave = true;}
228 
229  // Change current values one at a time (or set if not set before).
230  // (Must use set here since else name+signature clash with get methods.)
231  void setName(string nameIn) {nameSave = nameIn; hasChangedSave = true;}
232  void setAntiName(string antiNameIn) {antiNameSave = antiNameIn;
233  hasAntiSave = (toLower(antiNameIn) != "void"); hasChangedSave = true;}
234  void setNames(string nameIn, string antiNameIn) {nameSave = nameIn;
235  antiNameSave = antiNameIn; hasAntiSave = (toLower(antiNameIn) != "void");
236  hasChangedSave = true;}
237  void setSpinType(int spinTypeIn) {spinTypeSave = spinTypeIn;
238  hasChangedSave = true;}
239  void setChargeType(int chargeTypeIn) {chargeTypeSave = chargeTypeIn;
240  hasChangedSave = true;}
241  void setColType(int colTypeIn) {colTypeSave = colTypeIn;
242  hasChangedSave = true;}
243  void setM0(double m0In) {m0Save = m0In; setConstituentMass();
244  hasChangedSave = true;}
245  void setMWidth(double mWidthIn, bool countAsChanged = true) {
246  mWidthSave = mWidthIn; if (countAsChanged) hasChangedSave = true;}
247  void setMMin(double mMinIn) {mMinSave = mMinIn; hasChangedSave = true;
248  hasChangedMMinSave=true;}
249  void setMMax(double mMaxIn) {mMaxSave = mMaxIn; hasChangedSave = true;
250  hasChangedMMaxSave=true;}
251  // Special options specifically when cutting wings of Breit-Wigners.
252  void setMMinNoChange(double mMinIn) {mMinSave = mMinIn;}
253  void setMMaxNoChange(double mMaxIn) {mMaxSave = mMaxIn;}
254  void setTau0(double tau0In, bool countAsChanged = true)
255  {tau0Save = tau0In; if (countAsChanged) hasChangedSave = true;}
256  void setVarWidth(bool varWidthIn) {varWidthSave = varWidthIn;}
257  void setIsResonance(bool isResonanceIn) {isResonanceSave = isResonanceIn;
258  hasChangedSave = true;}
259  void setMayDecay(bool mayDecayIn, bool countAsChanged = true) {
260  mayDecaySave = mayDecayIn; if (countAsChanged) hasChangedSave = true;}
261  void setTauCalc(bool tauCalcIn, bool countAsChanged = true) {
262  tauCalcSave = tauCalcIn; if (countAsChanged) hasChangedSave = true;}
263  void setDoExternalDecay(bool doExternalDecayIn)
264  {doExternalDecaySave = doExternalDecayIn; hasChangedSave = true;}
265  void setIsVisible(bool isVisibleIn) {isVisibleSave = isVisibleIn;
266  hasChangedSave = true;}
267  void setDoForceWidth(bool doForceWidthIn) {doForceWidthSave = doForceWidthIn;
268  hasChangedSave = true;}
269  void setHasChanged(bool hasChangedIn) {hasChangedSave = hasChangedIn;
270  for (int i = 0; i < int(channels.size()); ++i)
271  channels[i].setHasChanged(hasChangedIn);
272  if (!hasChangedIn) {hasChangedMMinSave=false; hasChangedMMaxSave=false;}}
273 
274  // Give back current values.
275  int id() const { return idSave; }
276  int antiId() const {
277  return hasAntiSave ? -idSave : idSave; }
278  bool hasAnti() const { return hasAntiSave; }
279  string name(int idIn = 1) const {
280  return (idIn > 0) ? nameSave : antiNameSave; }
281  int spinType() const {return spinTypeSave; }
282  int chargeType(int idIn = 1) const {
283  return (idIn > 0) ? chargeTypeSave : -chargeTypeSave; }
284  double charge(int idIn = 1) const {
285  return (idIn > 0) ? chargeTypeSave / 3. : -chargeTypeSave / 3.; }
286  int colType(int idIn = 1) const {
287  if (colTypeSave == 2) return colTypeSave;
288  return (idIn > 0) ? colTypeSave : -colTypeSave; }
289  double m0() const { return m0Save; }
290  double mWidth() const { return mWidthSave; }
291  double mMin() const { return mMinSave; }
292  double mMax() const { return mMaxSave; }
293  double m0Min() const {
294  return (modeBWnow == 0) ? m0Save : mMinSave; }
295  double m0Max() const {
296  return (modeBWnow == 0) ? m0Save : mMaxSave; }
297  double tau0() const { return tau0Save; }
298  bool isResonance() const { return isResonanceSave; }
299  bool varWidth() const { return varWidthSave; }
300  bool mayDecay() const { return mayDecaySave; }
301  bool tauCalc() const { return tauCalcSave; }
302  bool doExternalDecay() const { return doExternalDecaySave; }
303  bool isVisible() const { return isVisibleSave; }
304  bool doForceWidth() const { return doForceWidthSave; }
305  bool hasChanged() const { if (hasChangedSave) return true;
306  for (int i = 0; i < int(channels.size()); ++i)
307  if (channels[i].hasChanged()) return true;
308  return false;}
309  bool hasChangedMMin() const { return hasChangedMMinSave; }
310  bool hasChangedMMax() const { return hasChangedMMaxSave; }
311 
312  // Set and give back several mass-related quantities.
313  void initBWmass();
314  double constituentMass() const { return constituentMassSave; }
315  double mSel() const;
316  double mRun(double mH) const;
317 
318  // Give back other quantities.
319  bool useBreitWigner() const { return (modeBWnow > 0); }
320  bool canDecay() const { return (channels.size() > 0)
321  || varWidthSave; }
322  bool isLepton() const { return (idSave > 10 && idSave < 19);}
323  bool isQuark() const { return (idSave != 0 && idSave < 9);}
324  bool isGluon() const { return (idSave == 21);}
325  bool isDiquark() const { return (idSave > 1000 && idSave < 10000
326  && (idSave/10)%10 == 0);}
327  bool isParton() const { return ( idSave == 21
328  || (idSave != 0 && idSave < 6)
329  || (idSave > 1000 && idSave < 5510 && (idSave/10)%10 == 0) );}
330  bool isHadron() const;
331  bool isMeson() const;
332  bool isBaryon() const;
333  bool isOnium() const;
334 
335  // Intermediate octet ccbar or bbar states in colour-octet model.
336  bool isOctetHadron() const {return idSave >= 9940000
337  && idSave < 9960000; }
338  int heaviestQuark(int idIn = 1) const;
339  int baryonNumberType(int idIn = 1) const;
340  int nQuarksInCode(int idQIn) const;
341 
342  // Reset to empty decay table.
343  void clearChannels() {channels.resize(0);}
344 
345  // Add a decay channel to the decay table.
346  void addChannel(int onMode = 0, double bRatio = 0., int meMode = 0,
347  int prod0 = 0, int prod1 = 0, int prod2 = 0, int prod3 = 0,
348  int prod4 = 0, int prod5 = 0, int prod6 = 0, int prod7 = 0) {
349  channels.push_back( DecayChannel( onMode, bRatio, meMode, prod0,
350  prod1, prod2, prod3, prod4, prod5, prod6, prod7) ); }
351 
352  // Decay table size.
353  int sizeChannels() const {return channels.size();}
354 
355  // Gain access to a channel in the decay table.
356  DecayChannel& channel(int i){return channels[i];}
357  const DecayChannel& channel(int i) const {return channels[i];}
358 
359  // Rescale sum of branching ratios to unity.
360  void rescaleBR(double newSumBR = 1.);
361 
362  // Random choice of decay channel according to branching ratios.
363  bool preparePick(int idSgn, double mHat = 0., int idInFlav = 0);
364  DecayChannel& pickChannel();
365 
366  // Access methods stored in ResonanceWidths.
367  void setResonancePtr(ResonanceWidths* resonancePtrIn);
368  ResonanceWidths* getResonancePtr() {return resonancePtr;}
369  void resInit(Info* infoPtrIn);
370  double resWidth(int idSgn, double mHat, int idIn = 0,
371  bool openOnly = false, bool setBR = false);
372  double resWidthOpen(int idSgn, double mHat, int idIn = 0);
373  double resWidthStore(int idSgn, double mHat, int idIn = 0);
374  double resOpenFrac(int idSgn);
375  double resWidthRescaleFactor();
376  double resWidthChan(double mHat, int idAbs1 = 0, int idAbs2 = 0);
377 
378 private:
379 
380  // Constants: could only be changed in the code itself.
381  static const int INVISIBLENUMBER, INVISIBLETABLE[80], KNOWNNOWIDTH[3];
382  static const double MAXTAU0FORDECAY,MINMASSRESONANCE, NARROWMASS,
383  CONSTITUENTMASSTABLE[10];
384 
385  // Particle data.
386  int idSave;
387  string nameSave, antiNameSave;
388  int spinTypeSave, chargeTypeSave, colTypeSave;
389  double m0Save, mWidthSave, mMinSave, mMaxSave, tau0Save,
390  constituentMassSave;
391  bool hasAntiSave, isResonanceSave, mayDecaySave, tauCalcSave, varWidthSave,
392  doExternalDecaySave, isVisibleSave, doForceWidthSave, hasChangedSave,
393  hasChangedMMinSave, hasChangedMMaxSave;
394 
395  // Extra data for mass selection according to a Breit-Wigner and lifetime.
396  int modeBWnow, modeTau0now;
397  double atanLow, atanDif, mThr;
398 
399  // A vector containing all the decay channels of the particle.
400  vector<DecayChannel> channels;
401 
402  // Summed branching ratio of currently open channels.
403  double currentBRSum;
404 
405  // Pointer to ResonanceWidths object; only used for some particles.
406  ResonanceWidths* resonancePtr;
407 
408  // Pointer to the full particle data table.
409  ParticleData* particleDataPtr;
410 
411  // Set constituent mass.
412  void setConstituentMass();
413 
414 };
415 
416 //==========================================================================
417 
418 // This class holds a map of all ParticleDataEntries.
419 
420 class ParticleData {
421 
422 public:
423 
424  // Constructor.
425  ParticleData() : setRapidDecayVertex(), modeBreitWigner(), maxEnhanceBW(),
426  mQRun(), Lambda5Run(), intermediateTau0(), infoPtr(0), settingsPtr(0),
427  rndmPtr(0), coupSMPtr(0), particlePtr(0), isInit(false),
428  readingFailedSave(false) {}
429 
430  // Copy constructor.
431  ParticleData( const ParticleData& oldPD) {
432  modeBreitWigner = oldPD.modeBreitWigner; maxEnhanceBW = oldPD.maxEnhanceBW;
433  for (int i = 0; i < 7; ++i) mQRun[i] = oldPD.mQRun[i];
434  Lambda5Run = oldPD.Lambda5Run;
435  infoPtr = 0; settingsPtr = 0; rndmPtr = 0; coupSMPtr = 0;
436  for ( map<int, ParticleDataEntry>::const_iterator pde = oldPD.pdt.begin();
437  pde != oldPD.pdt.end(); pde++) { int idTmp = pde->first;
438  pdt[idTmp] = pde->second; pdt[idTmp].initPtr(this); }
439  particlePtr = 0; isInit = oldPD.isInit;
440  readingFailedSave = oldPD.readingFailedSave; }
441 
442  // Assignment operator.
443  ParticleData& operator=( const ParticleData& oldPD) { if (this != &oldPD) {
444  modeBreitWigner = oldPD.modeBreitWigner; maxEnhanceBW = oldPD.maxEnhanceBW;
445  for (int i = 0; i < 7; ++i) mQRun[i] = oldPD.mQRun[i];
446  Lambda5Run = oldPD.Lambda5Run;
447  infoPtr = 0; settingsPtr = 0; rndmPtr = 0; coupSMPtr = 0;
448  for ( map<int, ParticleDataEntry>::const_iterator pde = oldPD.pdt.begin();
449  pde != oldPD.pdt.end(); pde++) { int idTmp = pde->first;
450  pdt[idTmp] = pde->second; pdt[idTmp].initPtr(this); }
451  particlePtr = 0; isInit = oldPD.isInit;
452  readingFailedSave = oldPD.readingFailedSave; } return *this; }
453 
454  // Initialize pointers.
455  void initPtrs(Info* infoPtrIn) {infoPtr = infoPtrIn;
456  settingsPtr = infoPtr->settingsPtr; rndmPtr = infoPtr->rndmPtr;
457  coupSMPtr = infoPtr->coupSMPtr;}
458 
459  // Read in database from specific file.
460  bool init(string startFile = "../share/Pythia8/xmldoc/ParticleData.xml") {
461  initCommon(); return readXML(startFile);}
462 
463  // Read in database from saved file stored in memory.
464  bool init(const ParticleData& particleDataIn) {
465  initCommon(); return copyXML(particleDataIn);}
466 
467  // Read in database from an istream.
468  bool init(istream& is) { initCommon(); return readXML(is);}
469 
470  // Overwrite existing database by reading from specific file.
471  bool reInit(string startFile, bool xmlFormat = true) { initCommon();
472  return (xmlFormat) ? readXML(startFile) : readFF(startFile);}
473 
474  // Initialize pointers, normal Breit-Wigners and special resonances.
475  void initWidths(vector<ResonanceWidths*> resonancePtrs);
476 
477  // Read and process or list whole (or part of) database from/to an XML file.
478  bool readXML(string inFile, bool reset = true) ;
479  void listXML(string outFile);
480  bool readXML(istream& is, bool reset=true);
481 
482  // Copy and process XML information from another particleData object.
483  bool copyXML(const ParticleData &particleDataIn);
484 
485  // Auxiliary functions to readXML() and copyXML().
486  bool loadXML(string inFile, bool reset = true) ;
487  bool loadXML(istream& is, bool reset=true);
488  bool processXML(bool reset = true) ;
489 
490  // Read or list whole (or part of) database from/to a free format file.
491  bool readFF(string inFile, bool reset = true) ;
492  bool readFF(istream& is, bool reset = true);
493  void listFF(string outFile);
494 
495  // Read in one update from a single line.
496  bool readString(string lineIn, bool warn = true) ;
497 
498  // Keep track whether any readings have failed, invalidating run setup.
499  bool readingFailed() {return readingFailedSave;}
500 
501  // Print out table of whole database, or of only part of it.
502  void listAll(ostream& stream) {list(stream, false, true);}
503  void listAll() {listAll(cout);}
504  void listChanged(bool changedRes = false) {list(true, changedRes);}
505  void list(ostream& stream, bool chargedOnly = false, bool changedRes = true);
506  void list(bool changedOnly = false, bool changedRes = true) {
507  list(cout, changedOnly, changedRes); }
508 
509  // Print out specified particles.
510  void list(int idList) {vector<int> idListTemp;
511  idListTemp.push_back(idList); list( idListTemp);}
512  void list(vector<int> idList);
513 
514  // Retrieve readString history (e.g., for inspection). Everything
515  // (subrun=-999), up to first subrun (=-1), or subrun-specific (>=0).
516  vector<string> getReadHistory(int subrun=-999) {
517  if (subrun == -999) return readStringHistory;
518  else if (readStringSubrun.find(subrun) != readStringSubrun.end())
519  return readStringSubrun[subrun];
520  else return vector<string>();
521  }
522 
523  // Check that table makes sense, especially for decays.
524  void checkTable(int verbosity = 1) ;
525 
526  // Add new entry.
527  void addParticle(int idIn, string nameIn = " ", int spinTypeIn = 0,
528  int chargeTypeIn = 0, int colTypeIn = 0, double m0In = 0.,
529  double mWidthIn = 0., double mMinIn = 0., double mMaxIn = 0.,
530  double tau0In = 0., bool varWidthIn = false) {
531  pdt[abs(idIn)] = ParticleDataEntry(idIn, nameIn, spinTypeIn, chargeTypeIn,
532  colTypeIn, m0In, mWidthIn, mMinIn, mMaxIn, tau0In, varWidthIn);
533  pdt[abs(idIn)].initPtr(this); }
534  void addParticle(int idIn, string nameIn, string antiNameIn,
535  int spinTypeIn = 0, int chargeTypeIn = 0, int colTypeIn = 0,
536  double m0In = 0., double mWidthIn = 0., double mMinIn = 0.,
537  double mMaxIn = 0., double tau0In = 0., bool varWidthIn = false) {
538  pdt[abs(idIn)] = ParticleDataEntry(idIn, nameIn, antiNameIn, spinTypeIn,
539  chargeTypeIn, colTypeIn, m0In, mWidthIn, mMinIn, mMaxIn, tau0In,
540  varWidthIn);
541  pdt[abs(idIn)].initPtr(this); }
542 
543  // Reset all the properties of an entry in one go.
544  void setAll(int idIn, string nameIn, string antiNameIn,
545  int spinTypeIn = 0, int chargeTypeIn = 0, int colTypeIn = 0,
546  double m0In = 0., double mWidthIn = 0., double mMinIn = 0.,
547  double mMaxIn = 0.,double tau0In = 0.,bool varWidthIn = false) {
548  ParticleDataEntry* ptr = findParticle(idIn);
549  if ( ptr ) ptr->setAll( nameIn, antiNameIn, spinTypeIn, chargeTypeIn,
550  colTypeIn, m0In, mWidthIn, mMinIn, mMaxIn, tau0In, varWidthIn); }
551 
552  // Query existence of an entry.
553  bool isParticle(int idIn) const {
554  map<int,ParticleDataEntry>::const_iterator found = pdt.find( abs(idIn) );
555  if ( found == pdt.end() ) return false;
556  if ( idIn > 0 || found->second.hasAnti() ) return true;
557  return false;
558  }
559 
560  // Query existence of an entry and return an iterator.
561  ParticleDataEntry* findParticle(int idIn) {
562  map<int,ParticleDataEntry>::iterator found = pdt.find( abs(idIn) );
563  if( found == pdt.end() ) return nullptr;
564  if ( idIn > 0 || found->second.hasAnti() ) return &((*found).second);
565  return nullptr;
566  }
567 
568  // Query existence of an entry and return a const iterator.
569  const ParticleDataEntry* findParticle(int idIn) const {
570  map<int,ParticleDataEntry>::const_iterator found = pdt.find( abs(idIn) );
571  if( found == pdt.end() ) return nullptr;
572  if ( idIn > 0 || found->second.hasAnti() ) return &((*found).second);
573  return nullptr;
574  }
575 
576  // Return the id of the sequentially next particle stored in table.
577  int nextId(int idIn) const;
578 
579  // Define iterators over entries.
580  map<int, ParticleDataEntry>::iterator begin() { return pdt.begin(); }
581  map<int, ParticleDataEntry>::iterator end() { return pdt.end(); }
582 
583  // Change current values one at a time (or set if not set before).
584  void name(int idIn, string nameIn) {
585  ParticleDataEntry* ptr = findParticle(idIn);
586  if ( ptr ) ptr->setName(nameIn); }
587  void antiName(int idIn, string antiNameIn) {
588  ParticleDataEntry* ptr = findParticle(idIn);
589  if ( ptr ) ptr->setAntiName(antiNameIn); }
590  void names(int idIn, string nameIn, string antiNameIn) {
591  ParticleDataEntry* ptr = findParticle(idIn);
592  if ( ptr ) ptr->setNames(nameIn, antiNameIn); }
593  void spinType(int idIn, int spinTypeIn) {
594  ParticleDataEntry* ptr = findParticle(idIn);
595  if ( ptr ) ptr->setSpinType(spinTypeIn); }
596  void chargeType(int idIn, int chargeTypeIn) {
597  ParticleDataEntry* ptr = findParticle(idIn);
598  if ( ptr ) ptr->setChargeType(chargeTypeIn); }
599  void colType(int idIn, int colTypeIn) {
600  ParticleDataEntry* ptr = findParticle(idIn);
601  if ( ptr ) ptr->setColType(colTypeIn); }
602  void m0(int idIn, double m0In) {
603  ParticleDataEntry* ptr = findParticle(idIn);
604  if ( ptr ) ptr->setM0(m0In); }
605  void mWidth(int idIn, double mWidthIn) {
606  ParticleDataEntry* ptr = findParticle(idIn);
607  if ( ptr ) ptr->setMWidth(mWidthIn); }
608  void mMin(int idIn, double mMinIn) {
609  ParticleDataEntry* ptr = findParticle(idIn);
610  if ( ptr ) ptr->setMMin(mMinIn); }
611  void mMax(int idIn, double mMaxIn) {
612  ParticleDataEntry* ptr = findParticle(idIn);
613  if ( ptr ) ptr->setMMax(mMaxIn); }
614  void tau0(int idIn, double tau0In) {
615  ParticleDataEntry* ptr = findParticle(idIn);
616  if ( ptr ) ptr->setTau0(tau0In); }
617  void isResonance(int idIn, bool isResonanceIn) {
618  ParticleDataEntry* ptr = findParticle(idIn);
619  if ( ptr ) ptr->setIsResonance(isResonanceIn); }
620  void mayDecay(int idIn, bool mayDecayIn) {
621  ParticleDataEntry* ptr = findParticle(idIn);
622  if ( ptr ) ptr->setMayDecay(mayDecayIn); }
623  void tauCalc(int idIn, bool tauCalcIn) {
624  ParticleDataEntry* ptr = findParticle(idIn);
625  if ( ptr ) ptr->setTauCalc(tauCalcIn); }
626  void doExternalDecay(int idIn, bool doExternalDecayIn) {
627  ParticleDataEntry* ptr = findParticle(idIn);
628  if ( ptr ) ptr->setDoExternalDecay(doExternalDecayIn); }
629  void varWidth(int idIn, bool varWidthIn) {
630  ParticleDataEntry* ptr = findParticle(idIn);
631  if ( ptr ) ptr->setVarWidth(varWidthIn); }
632  void isVisible(int idIn, bool isVisibleIn) {
633  ParticleDataEntry* ptr = findParticle(idIn);
634  if ( ptr ) ptr->setIsVisible(isVisibleIn); }
635  void doForceWidth(int idIn, bool doForceWidthIn) {
636  ParticleDataEntry* ptr = findParticle(idIn);
637  if ( ptr ) ptr->setDoForceWidth(doForceWidthIn); }
638  void hasChanged(int idIn, bool hasChangedIn) {
639  ParticleDataEntry* ptr = findParticle(idIn);
640  if ( ptr ) ptr->setHasChanged(hasChangedIn); }
641 
642  // Give back current values.
643  bool hasAnti(int idIn) const {
644  const ParticleDataEntry* ptr = findParticle(idIn);
645  return ( ptr ) ? ptr->hasAnti() : false; }
646  int antiId(int idIn) const {
647  if (idIn < 0) return -idIn;
648  const ParticleDataEntry* ptr = findParticle(idIn);
649  return ( ptr ) ? ptr->antiId() : 0; }
650  string name(int idIn) const {
651  const ParticleDataEntry* ptr = findParticle(idIn);
652  return ( ptr ) ? ptr->name(idIn) : " "; }
653  int spinType(int idIn) const {
654  const ParticleDataEntry* ptr = findParticle(idIn);
655  return ( ptr ) ? ptr->spinType() : 0; }
656  int chargeType(int idIn) const {
657  const ParticleDataEntry* ptr = findParticle(idIn);
658  return ( ptr ) ? ptr->chargeType(idIn) : 0; }
659  double charge(int idIn) const {
660  const ParticleDataEntry* ptr = findParticle(idIn);
661  return ( ptr ) ? ptr->charge(idIn) : 0; }
662  int colType(int idIn) const {
663  const ParticleDataEntry* ptr = findParticle(idIn);
664  return ( ptr ) ? ptr->colType(idIn) : 0 ; }
665  double m0(int idIn) const {
666  const ParticleDataEntry* ptr = findParticle(idIn);
667  return ( ptr ) ? ptr->m0() : 0. ; }
668  double mWidth(int idIn) const {
669  const ParticleDataEntry* ptr = findParticle(idIn);
670  return ( ptr ) ? ptr->mWidth() : 0. ; }
671  double mMin(int idIn) const {
672  const ParticleDataEntry* ptr = findParticle(idIn);
673  return ( ptr ) ? ptr->mMin() : 0. ; }
674  double m0Min(int idIn) const {
675  const ParticleDataEntry* ptr = findParticle(idIn);
676  return ( ptr ) ? ptr->m0Min() : 0. ; }
677  double mMax(int idIn) const {
678  const ParticleDataEntry* ptr = findParticle(idIn);
679  return ( ptr ) ? ptr->mMax() : 0. ; }
680  double m0Max(int idIn) const {
681  const ParticleDataEntry* ptr = findParticle(idIn);
682  return ( ptr ) ? ptr->m0Max() : 0. ; }
683  double tau0(int idIn) const {
684  const ParticleDataEntry* ptr = findParticle(idIn);
685  return ( ptr ) ? ptr->tau0() : 0. ; }
686  bool isResonance(int idIn) const {
687  const ParticleDataEntry* ptr = findParticle(idIn);
688  return ( ptr ) ? ptr->isResonance() : false ; }
689  bool mayDecay(int idIn) const {
690  const ParticleDataEntry* ptr = findParticle(idIn);
691  return ( ptr ) ? ptr->mayDecay() : false ; }
692  bool tauCalc(int idIn) const {
693  const ParticleDataEntry* ptr = findParticle(idIn);
694  return ( ptr ) ? ptr->tauCalc() : false ; }
695  bool doExternalDecay(int idIn) const {
696  const ParticleDataEntry* ptr = findParticle(idIn);
697  return ( ptr ) ? ptr->doExternalDecay() : false ; }
698  bool isVisible(int idIn) const {
699  const ParticleDataEntry* ptr = findParticle(idIn);
700  return ( ptr ) ? ptr->isVisible() : false ; }
701  bool doForceWidth(int idIn) const {
702  const ParticleDataEntry* ptr = findParticle(idIn);
703  return ( ptr ) ? ptr->doForceWidth() : false ; }
704  bool hasChanged(int idIn) const {
705  const ParticleDataEntry* ptr = findParticle(idIn);
706  return ( ptr ) ? ptr->hasChanged() : false ; }
707  bool hasChangedMMin(int idIn) const {
708  const ParticleDataEntry* ptr = findParticle(idIn);
709  return ( ptr ) ? ptr->hasChangedMMin() : false ; }
710  bool hasChangedMMax(int idIn) const {
711  const ParticleDataEntry* ptr = findParticle(idIn);
712  return ( ptr ) ? ptr->hasChangedMMax() : false ; }
713 
714  // Give back special mass-related quantities.
715  bool useBreitWigner(int idIn) const {
716  const ParticleDataEntry* ptr = findParticle(idIn);
717  return ( ptr ) ? ptr->useBreitWigner() : false ; }
718  bool varWidth(int idIn) const {
719  const ParticleDataEntry* ptr = findParticle(idIn);
720  return ( ptr ) ? ptr->varWidth() : false; }
721  double constituentMass(int idIn) const {
722  const ParticleDataEntry* ptr = findParticle(idIn);
723  return ( ptr ) ? ptr->constituentMass() : 0. ; }
724  double mSel(int idIn) const {
725  const ParticleDataEntry* ptr = findParticle(idIn);
726  return ( ptr ) ? ptr->mSel() : 0. ; }
727  double mRun(int idIn, double mH) const {
728  const ParticleDataEntry* ptr = findParticle(idIn);
729  return ( ptr ) ? ptr->mRun(mH) : 0. ; }
730 
731  // Give back other quantities.
732  bool canDecay(int idIn) const {
733  const ParticleDataEntry* ptr = findParticle(idIn);
734  return ( ptr ) ? ptr->canDecay() : false ; }
735  bool isLepton(int idIn) const {
736  const ParticleDataEntry* ptr = findParticle(idIn);
737  return ( ptr ) ? ptr->isLepton() : false ; }
738  bool isQuark(int idIn) const {
739  const ParticleDataEntry* ptr = findParticle(idIn);
740  return ( ptr ) ? ptr->isQuark() : false ; }
741  bool isGluon(int idIn) const {
742  const ParticleDataEntry* ptr = findParticle(idIn);
743  return ( ptr ) ? ptr->isGluon() : false ; }
744  bool isDiquark(int idIn) const {
745  const ParticleDataEntry* ptr = findParticle(idIn);
746  return ( ptr ) ? ptr->isDiquark() : false ; }
747  bool isParton(int idIn) const {
748  const ParticleDataEntry* ptr = findParticle(idIn);
749  return ( ptr ) ? ptr->isParton() : false ; }
750  bool isHadron(int idIn) const {
751  const ParticleDataEntry* ptr = findParticle(idIn);
752  return ( ptr ) ? ptr->isHadron() : false ; }
753  bool isMeson(int idIn) const {
754  const ParticleDataEntry* ptr = findParticle(idIn);
755  return ( ptr ) ? ptr->isMeson() : false ; }
756  bool isBaryon(int idIn) const {
757  const ParticleDataEntry* ptr = findParticle(idIn);
758  return ( ptr ) ? ptr->isBaryon() : false ; }
759  bool isOnium(int idIn) const {
760  const ParticleDataEntry* ptr = findParticle(idIn);
761  return ( ptr ) ? ptr->isOnium() : false ; }
762  bool isOctetHadron(int idIn) const {
763  const ParticleDataEntry* ptr = findParticle(idIn);
764  return ( ptr ) ? ptr->isOctetHadron() : false ; }
765  int heaviestQuark(int idIn) const {
766  const ParticleDataEntry* ptr = findParticle(idIn);
767  return ( ptr ) ? ptr->heaviestQuark(idIn) : 0 ; }
768  int baryonNumberType(int idIn) const {
769  const ParticleDataEntry* ptr = findParticle(idIn);
770  return ( ptr ) ? ptr->baryonNumberType(idIn) : 0 ; }
771  int nQuarksInCode(int idIn, int idQIn) const {
772  const ParticleDataEntry* ptr = findParticle(idIn);
773  return ( ptr ) ? ptr->nQuarksInCode(idQIn) : 0 ; }
774 
775  // Change branching ratios.
776  void rescaleBR(int idIn, double newSumBR = 1.) {
777  ParticleDataEntry* ptr = findParticle(idIn);
778  if ( ptr ) ptr->rescaleBR(newSumBR); }
779 
780  // Access methods stored in ResonanceWidths.
781  void setResonancePtr(int idIn, ResonanceWidths* resonancePtrIn) {
782  ParticleDataEntry* ptr = findParticle(idIn);
783  if ( ptr ) ptr->setResonancePtr( resonancePtrIn);}
784  void resInit(int idIn) {
785  ParticleDataEntry* ptr = findParticle(idIn);
786  if ( ptr ) ptr->resInit(infoPtr);}
787  double resWidth(int idIn, double mHat, int idInFlav = 0,
788  bool openOnly = false, bool setBR = false) {
789  ParticleDataEntry* ptr = findParticle(idIn);
790  return ( ptr ) ? ptr->resWidth(idIn, mHat,
791  idInFlav, openOnly, setBR) : 0.;}
792  double resWidthOpen(int idIn, double mHat, int idInFlav = 0) {
793  ParticleDataEntry* ptr = findParticle(idIn);
794  return ( ptr ) ? ptr->resWidthOpen(idIn, mHat, idInFlav) : 0.;}
795  double resWidthStore(int idIn, double mHat, int idInFlav = 0) {
796  ParticleDataEntry* ptr = findParticle(idIn);
797  return ( ptr ) ? ptr->resWidthStore(idIn, mHat, idInFlav) : 0.;}
798  double resOpenFrac(int id1In, int id2In = 0, int id3In = 0);
799  double resWidthRescaleFactor(int idIn) {
800  ParticleDataEntry* ptr = findParticle(idIn);
801  return ( ptr ) ? ptr->resWidthRescaleFactor() : 0.;}
802  double resWidthChan(int idIn, double mHat, int idAbs1 = 0,
803  int idAbs2 = 0) {
804  ParticleDataEntry* ptr = findParticle(idIn);
805  return ( ptr ) ? ptr->resWidthChan( mHat, idAbs1, idAbs2) : 0.;}
806 
807  // Return pointer to entry.
808  ParticleDataEntry* particleDataEntryPtr(int idIn) {
809  ParticleDataEntry* ptr = findParticle(idIn);
810  return ( ptr ) ? ptr : &pdt[0]; }
811 
812  // Check initialisation status.
813  bool getIsInit() {return isInit;}
814 
815 private:
816 
817  // Common data, accessible for the individual particles.
818  bool setRapidDecayVertex;
819  int modeBreitWigner;
820  double maxEnhanceBW, mQRun[7], Lambda5Run, intermediateTau0;
821 
822  // The individual particle need access to the full database.
823  friend class ParticleDataEntry;
824 
825  // Pointer to various information on the generation.
826  Info* infoPtr;
827 
828  // Pointer to the settings database.
829  Settings* settingsPtr;
830 
831  // Pointer to the random number generator.
832  Rndm* rndmPtr;
833 
834  // Pointer to Standard Model couplings.
835  CoupSM* coupSMPtr;
836 
837  // All particle data stored in a map.
838  map<int, ParticleDataEntry> pdt;
839 
840  // Pointer to current particle (e.g. when reading decay channels).
841  ParticleDataEntry* particlePtr;
842 
843  // Flag that initialization has been performed; whether any failures.
844  bool isInit, readingFailedSave;
845 
846  // Method for common setting of particle-specific info.
847  void initCommon();
848 
849  // Useful functions for string handling.
850  bool boolString(string tag) { string tagLow = toLower(tag);
851  return ( tagLow == "true" || tagLow == "1" || tagLow == "on"
852  || tagLow == "yes" || tagLow == "ok" ); }
853 
854  // Extract XML value following XML attribute.
855  string attributeValue(string line, string attribute);
856  bool boolAttributeValue(string line, string attribute);
857  int intAttributeValue(string line, string attribute);
858  double doubleAttributeValue(string line, string attribute);
859 
860  // Vector of strings containing the readable lines of the XML file.
861  vector<string> xmlFileSav;
862 
863  // Stored history of readString statements (common and by subrun).
864  vector<string> readStringHistory;
865  map<int, vector<string> > readStringSubrun;
866 
867 };
868 
869 //==========================================================================
870 
871 } // end namespace Pythia8
872 
873 #endif // Pythia8_ParticleData_H