StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ParticleData.cc
1 // ParticleData.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2018 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 // Function definitions (not found in the header) for the
7 // DecayChannel, ParticleDataEntry and ParticleData classes.
8 
9 #include "Pythia8/ParticleData.h"
10 #include "Pythia8/ResonanceWidths.h"
11 #include "Pythia8/StandardModel.h"
12 #include "Pythia8/SusyResonanceWidths.h"
13 #include "Pythia8/ResonanceWidthsDM.h"
14 
15 // Allow string and character manipulation.
16 #include <cctype>
17 
18 namespace Pythia8 {
19 
20 //==========================================================================
21 
22 // DecayChannel class.
23 // This class holds info on a single decay channel.
24 
25 //--------------------------------------------------------------------------
26 
27 // Check whether id1 occurs anywhere in product list.
28 
29 bool DecayChannel::contains(int id1) const {
30 
31  bool found1 = false;
32  for (int i = 0; i < nProd; ++i) if (prod[i] == id1) found1 = true;
33  return found1;
34 
35 }
36 
37 //--------------------------------------------------------------------------
38 
39 // Check whether id1 and id2 occur anywhere in product list.
40 // iF ID1 == ID2 then two copies of this particle must be present.
41 
42 bool DecayChannel::contains(int id1, int id2) const {
43 
44  bool found1 = false;
45  bool found2 = false;
46  for (int i = 0; i < nProd; ++i) {
47  if (!found1 && prod[i] == id1) {found1 = true; continue;}
48  if (!found2 && prod[i] == id2) {found2 = true; continue;}
49  }
50  return found1 && found2;
51 
52 }
53 
54 //--------------------------------------------------------------------------
55 
56 // Check whether id1, id2 and id3 occur anywhere in product list.
57 // iF ID1 == ID2 then two copies of this particle must be present, etc.
58 
59 bool DecayChannel::contains(int id1, int id2, int id3) const {
60 
61  bool found1 = false;
62  bool found2 = false;
63  bool found3 = false;
64  for (int i = 0; i < nProd; ++i) {
65  if (!found1 && prod[i] == id1) {found1 = true; continue;}
66  if (!found2 && prod[i] == id2) {found2 = true; continue;}
67  if (!found3 && prod[i] == id3) {found3 = true; continue;}
68  }
69  return found1 && found2 && found3;
70 
71 }
72 
73 //==========================================================================
74 
75 // ParticleDataEntry class.
76 // This class holds info on a single particle species.
77 
78 //--------------------------------------------------------------------------
79 
80 // Constants: could be changed here if desired, but normally should not.
81 // These are of technical nature, as described for each.
82 
83 // A particle is invisible if it has neither strong nor electric charge,
84 // and is not made up of constituents that have it. Only relevant for
85 // long-lived particles. This list may need to be extended.
86 const int ParticleDataEntry::INVISIBLENUMBER = 62;
87 const int ParticleDataEntry::INVISIBLETABLE[80] = {
88  12, 14, 16, 18, 23, 25, 32, 33,
89  35, 36, 39, 41, 45, 46, 51, 52,
90  53, 54, 55, 56, 57, 58, 59, 60,
91  1000012, 1000014, 1000016, 1000018, 1000022, 1000023, 1000025, 1000035,
92  1000045, 1000039, 2000012, 2000014, 2000016, 2000018, 4900012, 4900014,
93  4900016, 4900021, 4900022, 4900101, 4900102, 4900103, 4900104, 4900105,
94  4900106, 4900107, 4900108, 4900111, 4900113, 4900211, 4900213, 4900991,
95  5000039, 5100039, 9900012, 9900014, 9900016, 9900023, 0, 0,
96  0, 0, 0, 0, 0, 0, 0, 0,
97  0, 0, 0, 0, 0, 0, 0, 0
98 };
99 
100 // For some particles we know it is necessary to switch off width,
101 // although they do have one, so do not warn.
102 const int ParticleDataEntry::KNOWNNOWIDTH[3] = {10313, 10323, 10333};
103 
104 // Particles with a read-in tau0 (in mm/c) below this mayDecay by default.
105 const double ParticleDataEntry::MAXTAU0FORDECAY = 1000.;
106 
107 // Particles with a read-in m0 above this isResonance by default.
108 const double ParticleDataEntry::MINMASSRESONANCE = 20.;
109 
110 // Narrow states are assigned nominal mass.
111 const double ParticleDataEntry::NARROWMASS = 1e-6;
112 
113 // Constituent quark masses (d, u, s, c, b, -, -, -, g).
114 const double ParticleDataEntry::CONSTITUENTMASSTABLE[10]
115  = {0., 0.325, 0.325, 0.50, 1.60, 5.00, 0., 0., 0., 0.7};
116 
117 //--------------------------------------------------------------------------
118 
119 // Destructor: delete any ResonanceWidths object.
120 
121 ParticleDataEntry::~ParticleDataEntry() {
122  if (resonancePtr != 0) delete resonancePtr;
123 }
124 
125 //--------------------------------------------------------------------------
126 
127 // Set initial default values for some quantities.
128 
129 void ParticleDataEntry::setDefaults() {
130 
131  // A particle is a resonance if it is heavy enough.
132  isResonanceSave = (m0Save > MINMASSRESONANCE);
133 
134  // A particle may decay if it is shortlived enough.
135  mayDecaySave = (tau0Save < MAXTAU0FORDECAY);
136 
137  // A particle by default has no external decays.
138  doExternalDecaySave = false;
139 
140  // A particle is invisible if in current table of such.
141  isVisibleSave = true;
142  for (int i = 0; i < INVISIBLENUMBER; ++i)
143  if (idSave == INVISIBLETABLE[i]) isVisibleSave = false;
144 
145  // Normally a resonance should not have width forced to fixed value.
146  doForceWidthSave = false;
147 
148  // Set up constituent masses.
149  setConstituentMass();
150 
151  // No Breit-Wigner mass selection before initialized. Status tau0.
152  modeBWnow = 0;
153  modeTau0now = 0;
154 
155 }
156 
157 //--------------------------------------------------------------------------
158 
159 // Find out if a particle is a hadron.
160 // Only covers normal hadrons, not e.g. R-hadrons.
161 
162 bool ParticleDataEntry::isHadron() const {
163 
164  if (idSave <= 100 || (idSave >= 1000000 && idSave <= 9000000)
165  || idSave >= 9900000) return false;
166  if (idSave == 130 || idSave == 310) return true;
167  if (idSave%10 == 0 || (idSave/10)%10 == 0 || (idSave/100)%10 == 0)
168  return false;
169  return true;
170 
171 }
172 
173 //--------------------------------------------------------------------------
174 
175 // Find out if a particle is a meson.
176 // Only covers normal hadrons, not e.g. R-hadrons.
177 
178 bool ParticleDataEntry::isMeson() const {
179 
180  if (idSave <= 100 || (idSave >= 1000000 && idSave <= 9000000)
181  || idSave >= 9900000) return false;
182  if (idSave == 130 || idSave == 310) return true;
183  if (idSave%10 == 0 || (idSave/10)%10 == 0 || (idSave/100)%10 == 0
184  || (idSave/1000)%10 != 0) return false;
185  return true;
186 
187 }
188 
189 //--------------------------------------------------------------------------
190 
191 // Find out if a particle is a baryon.
192 // Only covers normal hadrons, not e.g. R-hadrons.
193 
194 bool ParticleDataEntry::isBaryon() const {
195 
196  if (idSave <= 1000 || (idSave >= 1000000 && idSave <= 9000000)
197  || idSave >= 9900000) return false;
198  if (idSave%10 == 0 || (idSave/10)%10 == 0 || (idSave/100)%10 == 0
199  || (idSave/1000)%10 == 0) return false;
200  return true;
201 
202 
203 }
204 
205 //--------------------------------------------------------------------------
206 
207 // Extract the heaviest (= largest id) quark in a hadron.
208 
209 int ParticleDataEntry::heaviestQuark(int idIn) const {
210 
211  if (!isHadron()) return 0;
212  int hQ = 0;
213 
214  // Meson.
215  if ( (idSave/1000)%10 == 0 ) {
216  hQ = (idSave/100)%10;
217  if (idSave == 130) hQ = 3;
218  if (hQ%2 == 1) hQ = -hQ;
219 
220  // Baryon.
221  } else hQ = (idSave/1000)%10;
222 
223  // Done.
224  return (idIn > 0) ? hQ : -hQ;
225 
226 }
227 
228 //--------------------------------------------------------------------------
229 
230 // Calculate three times baryon number, i.e. net quark - antiquark number.
231 
232 int ParticleDataEntry::baryonNumberType(int idIn) const {
233 
234  // Quarks.
235  if (isQuark()) return (idIn > 0) ? 1 : -1;
236 
237  // Diquarks
238  if (isDiquark()) return (idIn > 0) ? 2 : -2;
239 
240  // Baryons.
241  if (isBaryon()) return (idIn > 0) ? 3 : -3;
242 
243  // Done.
244  return 0;
245 
246 }
247 
248 //--------------------------------------------------------------------------
249 
250 // Find number of quarks of given kind inside quark, diquark or hadron.
251 // Note: naive answer for flavour-diagonal meson mixing.
252 
253 int ParticleDataEntry::nQuarksInCode(int idQIn) const {
254 
255  // Do not keep track of sign.
256  int idQ = abs(idQIn);
257  int idNow = abs(idSave);
258  int nQ = 0;
259 
260  // Quarks.
261  if (isQuark()) return (idQ == idNow) ? 1 : 0;
262 
263  // Diquarks.
264  if (isDiquark()) {
265  if ( (idNow/1000) % 10 == idQ) ++nQ;
266  if ( (idNow/100) % 10 == idQ) ++nQ;
267  return nQ;
268  }
269 
270  // Mesons.
271  if (isMeson()) {
272  if ( (idNow/100) % 10 == idQ) ++nQ;
273  if ( (idNow/10) % 10 == idQ) ++nQ;
274  return nQ;
275  }
276 
277  // Baryons.
278  if (isBaryon()) {
279  if ( (idNow/1000) % 10 == idQ) ++nQ;
280  if ( (idNow/100) % 10 == idQ) ++nQ;
281  if ( (idNow/10) % 10 == idQ) ++nQ;
282  return nQ;
283  }
284 
285  // Done. Room for improvements e.g. w.r.t. R-hadrons.
286  return 0;
287 
288 }
289 
290 //--------------------------------------------------------------------------
291 
292 // Prepare the Breit-Wigner mass selection by precalculating
293 // frequently-used expressions.
294 
295 void ParticleDataEntry::initBWmass() {
296 
297  // Optionally set decay vertices also for short-lived particles.
298  if (modeTau0now == 0) modeTau0now = (particleDataPtr->setRapidDecayVertex
299  && tau0Save == 0. && channels.size() > 0) ? 2 : 1;
300  if (modeTau0now == 2) tau0Save = (mWidthSave > NARROWMASS)
301  ? HBARC * FM2MM / mWidthSave : particleDataPtr->intermediateTau0;
302 
303  // Find Breit-Wigner mode for current particle.
304  modeBWnow = particleDataPtr->modeBreitWigner;
305  if ( m0Save < NARROWMASS ) mWidthSave = 0.;
306  if ( mWidthSave < NARROWMASS || (mMaxSave > mMinSave
307  && mMaxSave - mMinSave < NARROWMASS) ) modeBWnow = 0;
308  if (modeBWnow == 0) return;
309 
310  // Find atan expressions to be used in random mass selection.
311  if (modeBWnow < 3) {
312  atanLow = atan( 2. * (mMinSave - m0Save) / mWidthSave );
313  double atanHigh = (mMaxSave > mMinSave)
314  ? atan( 2. * (mMaxSave - m0Save) / mWidthSave ) : 0.5 * M_PI;
315  atanDif = atanHigh - atanLow;
316  } else {
317  atanLow = atan( (pow2(mMinSave) - pow2(m0Save))
318  / (m0Save * mWidthSave) );
319  double atanHigh = (mMaxSave > mMinSave)
320  ? atan( (pow2(mMaxSave) - pow2(m0Save)) / (m0Save * mWidthSave) )
321  : 0.5 * M_PI;
322  atanDif = atanHigh - atanLow;
323  }
324 
325  // Done if no threshold factor.
326  if (modeBWnow%2 == 1) return;
327 
328  // Find average mass threshold for threshold-factor correction.
329  double bRatSum = 0.;
330  double mThrSum = 0;
331  for (int i = 0; i < int(channels.size()); ++i)
332  if (channels[i].onMode() > 0) {
333  bRatSum += channels[i].bRatio();
334  double mChannelSum = 0.;
335  for (int j = 0; j < channels[i].multiplicity(); ++j)
336  mChannelSum += particleDataPtr->m0( channels[i].product(j) );
337  mThrSum += channels[i].bRatio() * mChannelSum;
338  }
339  mThr = (bRatSum == 0.) ? 0. : mThrSum / bRatSum;
340 
341  // Switch off Breit-Wigner if very close to threshold.
342  if (mThr + NARROWMASS > m0Save && !isResonanceSave) {
343  modeBWnow = 0;
344  bool knownProblem = false;
345  for (int i = 0; i < 3; ++i) if (idSave == KNOWNNOWIDTH[i])
346  knownProblem = true;
347  if (!knownProblem) {
348  ostringstream osWarn;
349  osWarn << "for id = " << idSave;
350  particleDataPtr->infoPtr->errorMsg("Warning in ParticleDataEntry::"
351  "initBWmass: switching off width", osWarn.str(), true);
352  }
353  }
354 
355 }
356 
357 //--------------------------------------------------------------------------
358 
359 // Function to give mass of a particle, either at the nominal value
360 // or picked according to a (linear or quadratic) Breit-Wigner.
361 
362 double ParticleDataEntry::mSel() {
363 
364  // Nominal value. (Width check should not be needed, but just in case.)
365  if (modeBWnow == 0 || mWidthSave < NARROWMASS) return m0Save;
366  double mNow, m2Now;
367 
368  // Mass according to a Breit-Wigner linear in m.
369  if (modeBWnow == 1) {
370  mNow = m0Save + 0.5 * mWidthSave
371  * tan( atanLow + atanDif * particleDataPtr->rndmPtr->flat() );
372 
373  // Ditto, but make Gamma proportional to sqrt(m^2 - m_threshold^2).
374  } else if (modeBWnow == 2) {
375  double mWidthNow, fixBW, runBW;
376  double m0ThrS = m0Save*m0Save - mThr*mThr;
377  do {
378  mNow = m0Save + 0.5 * mWidthSave
379  * tan( atanLow + atanDif * particleDataPtr->rndmPtr->flat() );
380  mWidthNow = mWidthSave * sqrtpos( (mNow*mNow - mThr*mThr) / m0ThrS );
381  fixBW = mWidthSave / (pow2(mNow - m0Save) + pow2(0.5 * mWidthSave));
382  runBW = mWidthNow / (pow2(mNow - m0Save) + pow2(0.5 * mWidthNow));
383  } while (runBW < particleDataPtr->rndmPtr->flat()
384  * particleDataPtr->maxEnhanceBW * fixBW);
385 
386  // Mass according to a Breit-Wigner quadratic in m.
387  } else if (modeBWnow == 3) {
388  m2Now = m0Save*m0Save + m0Save * mWidthSave
389  * tan( atanLow + atanDif * particleDataPtr->rndmPtr->flat() );
390  mNow = sqrtpos( m2Now);
391 
392  // Ditto, but m_0 Gamma_0 -> m Gamma(m) with threshold factor as above.
393  } else {
394  double mwNow, fixBW, runBW;
395  double m2Ref = m0Save * m0Save;
396  double mwRef = m0Save * mWidthSave;
397  double m2Thr = mThr * mThr;
398  do {
399  m2Now = m2Ref + mwRef * tan( atanLow + atanDif
400  * particleDataPtr->rndmPtr->flat() );
401  mNow = sqrtpos( m2Now);
402  mwNow = mNow * mWidthSave
403  * sqrtpos( (m2Now - m2Thr) / (m2Ref - m2Thr) );
404  fixBW = mwRef / (pow2(m2Now - m2Ref) + pow2(mwRef));
405  runBW = mwNow / (pow2(m2Now - m2Ref) + pow2(mwNow));
406  } while (runBW < particleDataPtr->rndmPtr->flat()
407  * particleDataPtr->maxEnhanceBW * fixBW);
408  }
409 
410  // Done.
411  return mNow;
412 }
413 
414 //--------------------------------------------------------------------------
415 
416 // Function to calculate running mass at given mass scale.
417 
418 double ParticleDataEntry::mRun(double mHat) {
419 
420  // Except for six quarks return nominal mass.
421  if (idSave > 6) return m0Save;
422  double mQRun = particleDataPtr->mQRun[idSave];
423  double Lam5 = particleDataPtr->Lambda5Run;
424 
425  // For d, u, s quarks start running at 2 GeV (RPP 2006 p. 505).
426  if (idSave < 4) return mQRun * pow ( log(2. / Lam5)
427  / log(max(2., mHat) / Lam5), 12./23.);
428 
429  // For c, b and t quarks start running at respective mass.
430  return mQRun * pow ( log(mQRun / Lam5)
431  / log(max(mQRun, mHat) / Lam5), 12./23.);
432 
433 }
434 
435 //--------------------------------------------------------------------------
436 
437 // Rescale all branching ratios to assure normalization to unity.
438 
439 void ParticleDataEntry::rescaleBR(double newSumBR) {
440 
441  // Sum up branching ratios. Find rescaling factor. Rescale.
442  double oldSumBR = 0.;
443  for ( int i = 0; i < int(channels.size()); ++ i)
444  oldSumBR += channels[i].bRatio();
445  double rescaleFactor = newSumBR / oldSumBR;
446  for ( int i = 0; i < int(channels.size()); ++ i)
447  channels[i].rescaleBR(rescaleFactor);
448 
449 }
450 
451 //--------------------------------------------------------------------------
452 
453 // Prepare to pick a decay channel.
454 
455 bool ParticleDataEntry::preparePick(int idSgn, double mHat, int idInFlav) {
456 
457  // Reset sum of allowed widths/branching ratios.
458  currentBRSum = 0.;
459 
460  // For resonances the widths are calculated dynamically.
461  if (isResonanceSave && resonancePtr != 0) {
462  resonancePtr->widthStore(idSgn, mHat, idInFlav);
463  for (int i = 0; i < int(channels.size()); ++i)
464  currentBRSum += channels[i].currentBR();
465 
466  // Else use normal fixed branching ratios.
467  } else {
468  int onMode;
469  double currentBRNow;
470  for (int i = 0; i < int(channels.size()); ++i) {
471  onMode = channels[i].onMode();
472  currentBRNow = 0.;
473  if ( idSgn > 0 && (onMode == 1 || onMode == 2) )
474  currentBRNow = channels[i].bRatio();
475  else if ( idSgn < 0 && (onMode == 1 || onMode == 3) )
476  currentBRNow = channels[i].bRatio();
477  channels[i].currentBR(currentBRNow);
478  currentBRSum += currentBRNow;
479  }
480  }
481 
482  // Failure if no channels found with positive branching ratios.
483  return (currentBRSum > 0.);
484 
485 }
486 
487 //--------------------------------------------------------------------------
488 
489 // Pick a decay channel according to branching ratios from preparePick.
490 
491 DecayChannel& ParticleDataEntry::pickChannel() {
492 
493  // Find channel in table.
494  int size = channels.size();
495  double rndmBR = currentBRSum * particleDataPtr->rndmPtr->flat();
496  int i = -1;
497  do rndmBR -= channels[++i].currentBR();
498  while (rndmBR > 0. && i < size);
499 
500  // Emergency if no channel found. Done.
501  if (i == size) i = 0;
502  return channels[i];
503 
504 }
505 
506 //--------------------------------------------------------------------------
507 
508 // Access methods stored in ResonanceWidths. Could have been
509 // inline in .h, except for problems with forward declarations.
510 
511 void ParticleDataEntry::setResonancePtr(
512  ResonanceWidths* resonancePtrIn) {
513  if (resonancePtr == resonancePtrIn) return;
514  if (resonancePtr != 0) delete resonancePtr;
515  resonancePtr = resonancePtrIn;
516 }
517 
518 void ParticleDataEntry::resInit(Info* infoPtrIn, Settings* settingsPtrIn,
519  ParticleData* particleDataPtrIn, Couplings* couplingsPtrIn) {
520  if (resonancePtr != 0) resonancePtr->init(infoPtrIn, settingsPtrIn,
521  particleDataPtrIn, couplingsPtrIn);
522 }
523 
524 double ParticleDataEntry::resWidth(int idSgn, double mHat, int idIn,
525  bool openOnly, bool setBR) {
526  return (resonancePtr != 0) ? resonancePtr->width( idSgn, mHat,
527  idIn, openOnly, setBR) : 0.;
528 }
529 
530 double ParticleDataEntry::resWidthOpen(int idSgn, double mHat, int idIn) {
531  return (resonancePtr != 0) ? resonancePtr->widthOpen( idSgn, mHat, idIn)
532  : 0.;
533 }
534 
535 double ParticleDataEntry::resWidthStore(int idSgn, double mHat, int idIn) {
536  return (resonancePtr != 0) ? resonancePtr->widthStore( idSgn, mHat, idIn)
537  : 0.;
538 }
539 
540 double ParticleDataEntry::resOpenFrac(int idSgn) {
541  return (resonancePtr != 0) ? resonancePtr->openFrac(idSgn) : 1.;
542 }
543 
544 double ParticleDataEntry::resWidthRescaleFactor() {
545  return (resonancePtr != 0) ? resonancePtr->widthRescaleFactor() : 1.;
546 }
547 
548 double ParticleDataEntry::resWidthChan(double mHat, int idAbs1,
549  int idAbs2) {
550  return (resonancePtr != 0) ? resonancePtr->widthChan( mHat, idAbs1,
551  idAbs2) : 0.;
552 }
553 
554 //--------------------------------------------------------------------------
555 
556 // Constituent masses for (d, u, s, c, b) quarks and diquarks.
557 // Hardcoded in CONSTITUENTMASSTABLE so that they are not overwritten
558 // by mistake, and separated from the "normal" masses.
559 // Called both by setDefaults and setM0 so kept as separate method.
560 
561 void ParticleDataEntry::setConstituentMass() {
562 
563  // Equate with the normal masses as default guess.
564  constituentMassSave = m0Save;
565 
566  // Quark masses trivial. Also gluon mass.
567  if (idSave < 6) constituentMassSave = CONSTITUENTMASSTABLE[idSave];
568  if (idSave == 21) constituentMassSave = CONSTITUENTMASSTABLE[9];
569 
570  // Diquarks as simple sum of constituent quarks.
571  if (idSave > 1000 && idSave < 10000 && (idSave/10)%10 == 0) {
572  int id1 = idSave/1000;
573  int id2 = (idSave/100)%10;
574  if (id1 <6 && id2 < 6) constituentMassSave
575  = CONSTITUENTMASSTABLE[id1] + CONSTITUENTMASSTABLE[id2];
576  }
577 
578 }
579 
580 //==========================================================================
581 
582 // ParticleData class.
583 // This class holds a map of all ParticleDataEntries,
584 // each entry containing info on a particle species.
585 
586 //--------------------------------------------------------------------------
587 
588 // Get data to be distributed among particles during setup.
589 // Note: this routine is called twice. Firstly from init(...), but
590 // the data should not be used at that point, so is likely overkill.
591 // Secondly, from initWidths, after user has had time to change.
592 
593 void ParticleData::initCommon() {
594 
595  // Mass generation: fixed mass or linear/quadratic Breit-Wigner.
596  modeBreitWigner = settingsPtr->mode("ParticleData:modeBreitWigner");
597 
598  // Maximum tail enhancement when adding threshold factor to Breit-Wigner.
599  maxEnhanceBW = settingsPtr->parm("ParticleData:maxEnhanceBW");
600 
601  // Find initial MSbar masses for five light flavours.
602  mQRun[1] = settingsPtr->parm("ParticleData:mdRun");
603  mQRun[2] = settingsPtr->parm("ParticleData:muRun");
604  mQRun[3] = settingsPtr->parm("ParticleData:msRun");
605  mQRun[4] = settingsPtr->parm("ParticleData:mcRun");
606  mQRun[5] = settingsPtr->parm("ParticleData:mbRun");
607  mQRun[6] = settingsPtr->parm("ParticleData:mtRun");
608 
609  // Find Lambda5 value to use in running of MSbar masses.
610  double alphaSvalue = settingsPtr->parm("ParticleData:alphaSvalueMRun");
611  AlphaStrong alphaS;
612  alphaS.init( alphaSvalue, 1, 5, false);
613  Lambda5Run = alphaS.Lambda5();
614 
615  // Set secondary vertices also for rapidly decaying particles.
616  setRapidDecayVertex = settingsPtr->flag("Fragmentation:setVertices")
617  && settingsPtr->flag("HadronVertex:rapidDecays");
618  intermediateTau0 = settingsPtr->parm("HadronVertex:intermediateTau0");
619 
620 }
621 
622 //--------------------------------------------------------------------------
623 
624 // Initialize pointer for particles to the full database, the Breit-Wigners
625 // of normal hadrons and the ResonanceWidths of resonances. For the latter
626 // the order of initialization is essential to get secondary widths right.
627 
628 void ParticleData::initWidths( vector<ResonanceWidths*> resonancePtrs) {
629 
630  // Initialize some common data (but preserve history of read statements).
631  initCommon();
632 
633  // Pointer to database and Breit-Wigner mass initialization for each
634  // particle.
635  ResonanceWidths* resonancePtr = 0;
636  for (map<int, ParticleDataEntry>::iterator pdtEntry = pdt.begin();
637  pdtEntry != pdt.end(); ++pdtEntry) {
638  ParticleDataEntry& pdtNow = pdtEntry->second;
639  pdtNow.initBWmass();
640 
641  // Remove any existing resonances.
642  resonancePtr = pdtNow.getResonancePtr();
643  if (resonancePtr != 0) pdtNow.setResonancePtr(0);
644  }
645 
646  // Begin set up new resonance objects.
647  // Z0, W+- and top are almost always needed.
648  resonancePtr = new ResonanceGmZ(23);
649  setResonancePtr( 23, resonancePtr);
650  resonancePtr = new ResonanceW(24);
651  setResonancePtr( 24, resonancePtr);
652  resonancePtr = new ResonanceTop(6);
653  setResonancePtr( 6, resonancePtr);
654 
655  // Higgs in SM.
656  if (!settingsPtr->flag("Higgs:useBSM")) {
657  resonancePtr = new ResonanceH(0, 25);
658  setResonancePtr( 25, resonancePtr);
659 
660  // Higgses in BSM.
661  } else {
662  resonancePtr = new ResonanceH(1, 25);
663  setResonancePtr( 25, resonancePtr);
664  resonancePtr = new ResonanceH(2, 35);
665  setResonancePtr( 35, resonancePtr);
666  resonancePtr = new ResonanceH(3, 36);
667  setResonancePtr( 36, resonancePtr);
668  resonancePtr = new ResonanceHchg(37);
669  setResonancePtr( 37, resonancePtr);
670  resonancePtr = new ResonanceH(4, 45);
671  setResonancePtr( 45, resonancePtr);
672  resonancePtr = new ResonanceH(5, 46);
673  setResonancePtr( 46, resonancePtr);
674  }
675 
676  // A fourth generation: b', t', tau', nu'_tau.
677  resonancePtr = new ResonanceFour(7);
678  setResonancePtr( 7, resonancePtr);
679  resonancePtr = new ResonanceFour(8);
680  setResonancePtr( 8, resonancePtr);
681  resonancePtr = new ResonanceFour(17);
682  setResonancePtr( 17, resonancePtr);
683  resonancePtr = new ResonanceFour(18);
684  setResonancePtr( 18, resonancePtr);
685 
686  // New gauge bosons: Z', W', R.
687  resonancePtr = new ResonanceZprime(32);
688  setResonancePtr( 32, resonancePtr);
689  resonancePtr = new ResonanceWprime(34);
690  setResonancePtr( 34, resonancePtr);
691  resonancePtr = new ResonanceRhorizontal(41);
692  setResonancePtr( 41, resonancePtr);
693 
694  // A leptoquark.
695  resonancePtr = new ResonanceLeptoquark(42);
696  setResonancePtr( 42, resonancePtr);
697 
698  // Mediators for Dark Matter.
699  resonancePtr = new ResonanceZp(55);
700  setResonancePtr( 55, resonancePtr);
701  resonancePtr = new ResonanceS(54);
702  setResonancePtr( 54, resonancePtr);
703 
704  // 93 = Z0copy and 94 = W+-copy used to pick decay channels
705  // for W/Z production in parton showers.
706  resonancePtr = new ResonanceGmZ(93);
707  setResonancePtr( 93, resonancePtr);
708  resonancePtr = new ResonanceW(94);
709  setResonancePtr( 94, resonancePtr);
710 
711  // Supersymmetry:
712  // - Squarks;
713  for(int i = 1; i < 7; i++){
714  resonancePtr = new ResonanceSquark(1000000 + i);
715  setResonancePtr( 1000000 + i, resonancePtr);
716  resonancePtr = new ResonanceSquark(2000000 + i);
717  setResonancePtr( 2000000 + i, resonancePtr);
718  }
719 
720  // - Sleptons and sneutrinos;
721  for(int i = 1; i < 7; i++){
722  resonancePtr = new ResonanceSlepton(1000010 + i);
723  setResonancePtr( 1000010 + i, resonancePtr);
724  resonancePtr = new ResonanceSlepton(2000010 + i);
725  setResonancePtr( 2000010 + i, resonancePtr);
726  }
727 
728  // - Gluino;
729  resonancePtr = new ResonanceGluino(1000021);
730  setResonancePtr( 1000021, resonancePtr);
731 
732  // - Charginos;
733  resonancePtr = new ResonanceChar(1000024);
734  setResonancePtr( 1000024, resonancePtr);
735  resonancePtr = new ResonanceChar(1000037);
736  setResonancePtr( 1000037, resonancePtr);
737 
738  // - Neutralinos.
739  if (isResonance(1000022)) {
740  resonancePtr = new ResonanceNeut(1000022);
741  setResonancePtr( 1000022, resonancePtr);
742  }
743  resonancePtr = new ResonanceNeut(1000023);
744  setResonancePtr( 1000023, resonancePtr);
745  resonancePtr = new ResonanceNeut(1000025);
746  setResonancePtr( 1000025, resonancePtr);
747  resonancePtr = new ResonanceNeut(1000035);
748  setResonancePtr( 1000035, resonancePtr);
749  resonancePtr = new ResonanceNeut(1000045);
750  setResonancePtr( 1000045, resonancePtr);
751 
752  // Excited quarks and leptons.
753  for (int i = 1; i < 7; ++i) {
754  resonancePtr = new ResonanceExcited(4000000 + i);
755  setResonancePtr( 4000000 + i, resonancePtr);
756  }
757  for (int i = 11; i < 17; ++i) {
758  resonancePtr = new ResonanceExcited(4000000 + i);
759  setResonancePtr( 4000000 + i, resonancePtr);
760  }
761 
762  // An excited graviton/gluon in extra-dimensional scenarios.
763  resonancePtr = new ResonanceGraviton(5100039);
764  setResonancePtr( 5100039, resonancePtr);
765  resonancePtr = new ResonanceKKgluon(5100021);
766  setResonancePtr( 5100021, resonancePtr);
767 
768  // A left-right-symmetric scenario with new righthanded neutrinos,
769  // righthanded gauge bosons and doubly charged Higgses.
770  resonancePtr = new ResonanceNuRight(9900012);
771  setResonancePtr( 9900012, resonancePtr);
772  resonancePtr = new ResonanceNuRight(9900014);
773  setResonancePtr( 9900014, resonancePtr);
774  resonancePtr = new ResonanceNuRight(9900016);
775  setResonancePtr( 9900016, resonancePtr);
776  resonancePtr = new ResonanceZRight(9900023);
777  setResonancePtr( 9900023, resonancePtr);
778  resonancePtr = new ResonanceWRight(9900024);
779  setResonancePtr( 9900024, resonancePtr);
780  resonancePtr = new ResonanceHchgchgLeft(9900041);
781  setResonancePtr( 9900041, resonancePtr);
782  resonancePtr = new ResonanceHchgchgRight(9900042);
783  setResonancePtr( 9900042, resonancePtr);
784 
785  // Attach user-defined external resonances and do basic initialization.
786  for (int i = 0; i < int(resonancePtrs.size()); ++i) {
787  int idNow = resonancePtrs[i]->id();
788  resonancePtrs[i]->initBasic(idNow);
789  setResonancePtr( idNow, resonancePtrs[i]);
790  }
791 
792  // Set up lists to order resonances in ascending mass.
793  vector<int> idOrdered;
794  vector<double> m0Ordered;
795 
796  // Put Z0 and W+- first, since known to be SM and often off-shell.
797  idOrdered.push_back(23);
798  m0Ordered.push_back(m0(23));
799  idOrdered.push_back(24);
800  m0Ordered.push_back(m0(24));
801 
802  // Loop through particle table to find resonances.
803  for (map<int, ParticleDataEntry>::iterator pdtEntry = pdt.begin();
804  pdtEntry != pdt.end(); ++pdtEntry) {
805  ParticleDataEntry& pdtNow = pdtEntry->second;
806  int idNow = pdtNow.id();
807 
808  // Set up a simple default object for uninitialized resonances.
809  if (pdtNow.isResonance() && pdtNow.getResonancePtr() == 0) {
810  resonancePtr = new ResonanceGeneric(idNow);
811  setResonancePtr( idNow, resonancePtr);
812  }
813 
814  // Insert resonances in ascending mass, to respect decay hierarchies.
815  if (pdtNow.getResonancePtr() != 0 && idNow != 23 && idNow != 24) {
816  double m0Now = pdtNow.m0();
817  idOrdered.push_back(idNow);
818  m0Ordered.push_back(m0Now);
819  for (int i = int(idOrdered.size()) - 2; i > 1; --i) {
820  if (m0Ordered[i] < m0Now) break;
821  swap( idOrdered[i], idOrdered[i + 1]);
822  swap( m0Ordered[i], m0Ordered[i + 1]);
823  }
824  }
825  }
826 
827  // Initialize the resonances in ascending mass order. Reset mass generation.
828  for (int i = 0; i < int(idOrdered.size()); ++i) {
829  resInit( idOrdered[i]);
830  ParticleDataEntry* pdtPtrNow = particleDataEntryPtr( idOrdered[i]);
831  pdtPtrNow->initBWmass();
832  }
833 
834 }
835 
836 //--------------------------------------------------------------------------
837 
838 // Read in database from specific XML file (which may refer to others).
839 
840 bool ParticleData::readXML(string inFile, bool reset) {
841 
842  // Load XML file into memory
843  if (!loadXML(inFile,reset)) return false;
844 
845  // Process XML file (now stored in memory)
846  if (!processXML(reset)) return false;
847 
848  // Done.
849  return true;
850 }
851 
852 //--------------------------------------------------------------------------
853 
854 // Read in database from specific XML stream (which may refer to others).
855 
856 bool ParticleData::readXML(istream &inStr, bool reset) {
857 
858  // Load XML file into memory
859  if (!loadXML(inStr,reset)) return false;
860 
861  // Process XML file (now stored in memory)
862  if (!processXML(reset)) return false;
863 
864  // Done.
865  return true;
866 }
867 
868 //--------------------------------------------------------------------------
869 
870 // Read in database from pre-initialised particleData object.
871 
872 bool ParticleData::copyXML(const ParticleData &particleDataIn) {
873 
874  // First Reset everything.
875  pdt.clear();
876  xmlFileSav.clear();
877  readStringHistory.resize(0);
878  readStringSubrun.clear();
879  isInit = false;
880  xmlFileSav=particleDataIn.xmlFileSav;
881 
882  // Process XML file (now stored in memory)
883  if (!processXML(true)) return false;
884 
885  // Done.
886  return true;
887 }
888 //--------------------------------------------------------------------------
889 
890 // Load a specific XML file into memory (which may refer to others).
891 
892 bool ParticleData::loadXML(istream& is, bool reset) {
893 
894  // Normally reset whole database before beginning.
895  if (reset) {
896  pdt.clear();
897  xmlFileSav.clear();
898  readStringHistory.resize(0);
899  readStringSubrun.clear();
900  isInit = false;
901  }
902 
903  // Check that instream is OK.
904  if (!is.good()) {
905  infoPtr->errorMsg("Error in ParticleData::readXML:"
906  " did not find data");
907  return false;
908  }
909 
910  // Read in one line at a time.
911  particlePtr = 0;
912  string line;
913  while ( getline(is, line) ) {
914 
915  // Get first word of a line.
916  istringstream getfirst(line);
917  string word1;
918  getfirst >> word1;
919 
920  // Check for occurence of a file also to be read.
921  if (word1 == "<file") {
922  string file = attributeValue(line, "name");
923  }
924 
925  // Else save line to memory.
926  else {
927  xmlFileSav.push_back(line);
928  }
929  }
930 
931  //Done.
932  return true;
933 
934 }
935 
936 
937 //--------------------------------------------------------------------------
938 
939 // Load a specific XML file into memory (which may refer to others).
940 
941 bool ParticleData::loadXML(string inFile, bool reset) {
942 
943  const char* cstring = inFile.c_str();
944  ifstream is(cstring);
945 
946  return loadXML(is, reset);
947 }
948 
949 //--------------------------------------------------------------------------
950 
951 // Process XML contents stored in memory.
952 
953 bool ParticleData::processXML(bool reset) {
954 
955  // Number of lines saved.
956  int nLines = xmlFileSav.size();
957 
958  // Process each line sequentially.
959  particlePtr = 0;
960  int i=-1;
961  while (++i < nLines) {
962 
963  // Retrieve line.
964  string line = xmlFileSav[i];
965 
966  // Get first word of a line.
967  istringstream getfirst(line);
968  string word1;
969  getfirst >> word1;
970 
971  // Check for occurence of a particle. Add any continuation lines.
972  if (word1 == "<particle") {
973  while (line.find(">") == string::npos) {
974  if (++i >= nLines) break;
975  string addLine = xmlFileSav[i];
976  line += addLine;
977  }
978 
979  // Read in particle properties.
980  int idTmp = intAttributeValue( line, "id");
981  string nameTmp = attributeValue( line, "name");
982  string antiNameTmp = attributeValue( line, "antiName");
983  if (antiNameTmp == "") antiNameTmp = "void";
984  int spinTypeTmp = intAttributeValue( line, "spinType");
985  int chargeTypeTmp = intAttributeValue( line, "chargeType");
986  int colTypeTmp = intAttributeValue( line, "colType");
987  double m0Tmp = doubleAttributeValue( line, "m0");
988  double mWidthTmp = doubleAttributeValue( line, "mWidth");
989  double mMinTmp = doubleAttributeValue( line, "mMin");
990  double mMaxTmp = doubleAttributeValue( line, "mMax");
991  double tau0Tmp = doubleAttributeValue( line, "tau0");
992 
993  // Erase if particle already exists.
994  if (isParticle(idTmp)) pdt.erase(idTmp);
995 
996  // Store new particle. Save pointer, to be used for decay channels.
997  addParticle( idTmp, nameTmp, antiNameTmp, spinTypeTmp, chargeTypeTmp,
998  colTypeTmp, m0Tmp, mWidthTmp, mMinTmp, mMaxTmp, tau0Tmp);
999  particlePtr = particleDataEntryPtr(idTmp);
1000 
1001  // Check for occurence of a decay channel. Add any continuation lines.
1002  } else if (word1 == "<channel") {
1003  while (line.find(">") == string::npos) {
1004  if (++i >= nLines) break;
1005  string addLine = xmlFileSav[i];
1006  line += addLine;
1007  }
1008 
1009  // Read in channel properties - products so far only as a string.
1010  int onMode = intAttributeValue( line, "onMode");
1011  double bRatio = doubleAttributeValue( line, "bRatio");
1012  int meMode = intAttributeValue( line, "meMode");
1013  string products = attributeValue( line, "products");
1014 
1015  // Read in decay products from stream. Must have at least one.
1016  istringstream prodStream(products);
1017  int prod0 = 0; int prod1 = 0; int prod2 = 0; int prod3 = 0;
1018  int prod4 = 0; int prod5 = 0; int prod6 = 0; int prod7 = 0;
1019  prodStream >> prod0 >> prod1 >> prod2 >> prod3 >> prod4 >> prod5
1020  >> prod6 >> prod7;
1021  if (prod0 == 0) {
1022  infoPtr->errorMsg("Error in ParticleData::readXML:"
1023  " incomplete decay channel", line);
1024  return false;
1025  }
1026 
1027  // Store new channel (if particle already known).
1028  if (particlePtr == 0) {
1029  infoPtr->errorMsg("Error in ParticleData::readXML:"
1030  " orphan decay channel", line);
1031  return false;
1032  }
1033  particlePtr->addChannel(onMode, bRatio, meMode, prod0, prod1,
1034  prod2, prod3, prod4, prod5, prod6, prod7);
1035 
1036  // End of loop over lines in input file and loop over files.
1037  };
1038  };
1039 
1040  // All particle data at this stage defines baseline original.
1041  if (reset) for (map<int, ParticleDataEntry>::iterator pdtEntry
1042  = pdt.begin(); pdtEntry != pdt.end(); ++pdtEntry) {
1043  particlePtr = &pdtEntry->second;
1044  particlePtr->setHasChanged(false);
1045  }
1046 
1047  // Done.
1048  isInit = true;
1049  return true;
1050 
1051 }
1052 
1053 //--------------------------------------------------------------------------
1054 
1055 // Print out complete database in numerical order as an XML file.
1056 
1057 void ParticleData::listXML(string outFile) {
1058 
1059  // Convert file name to ofstream.
1060  const char* cstring = outFile.c_str();
1061  ofstream os(cstring);
1062 
1063  // Iterate through the particle data table.
1064  for (map<int, ParticleDataEntry>::iterator pdtEntry
1065  = pdt.begin(); pdtEntry != pdt.end(); ++pdtEntry) {
1066  particlePtr = &pdtEntry->second;
1067 
1068  // Print particle properties.
1069  os << "<particle id=\"" << particlePtr->id() << "\""
1070  << " name=\"" << particlePtr->name() << "\"";
1071  if (particlePtr->hasAnti())
1072  os << " antiName=\"" << particlePtr->name(-1) << "\"";
1073  os << " spinType=\"" << particlePtr->spinType() << "\""
1074  << " chargeType=\"" << particlePtr->chargeType() << "\""
1075  << " colType=\"" << particlePtr->colType() << "\"\n";
1076  // Pick format for mass and width based on mass value.
1077  double m0Now = particlePtr->m0();
1078  if (m0Now == 0 || (m0Now > 0.1 && m0Now < 1000.))
1079  os << fixed << setprecision(5);
1080  else os << scientific << setprecision(3);
1081  os << " m0=\"" << m0Now << "\"";
1082  if (particlePtr->mWidth() > 0.)
1083  os << " mWidth=\"" << particlePtr->mWidth() << "\""
1084  << " mMin=\"" << particlePtr->mMin() << "\""
1085  << " mMax=\"" << particlePtr->mMax() << "\"";
1086  if (particlePtr->tau0() > 0.) os << scientific << setprecision(5)
1087  << " tau0=\"" << particlePtr->tau0() << "\"";
1088  os << ">\n";
1089 
1090  // Loop through the decay channel table for each particle.
1091  if (particlePtr->sizeChannels() > 0) {
1092  for (int i = 0; i < particlePtr->sizeChannels(); ++i) {
1093  const DecayChannel& channel = particlePtr->channel(i);
1094  int mult = channel.multiplicity();
1095 
1096  // Print decay channel properties.
1097  os << " <channel onMode=\"" << channel.onMode() << "\""
1098  << fixed << setprecision(7)
1099  << " bRatio=\"" << channel.bRatio() << "\"";
1100  if (channel.meMode() > 0)
1101  os << " meMode=\"" << channel.meMode() << "\"";
1102  os << " products=\"";
1103  for (int j = 0; j < mult; ++j) {
1104  os << channel.product(j);
1105  if (j < mult - 1) os << " ";
1106  }
1107 
1108  // Finish off line and loop over allowed decay channels.
1109  os << "\"/>\n";
1110  }
1111  }
1112 
1113  // Finish off existing particle.
1114  os << "</particle>\n\n";
1115 
1116  }
1117 
1118 }
1119 
1120 //--------------------------------------------------------------------------
1121 
1122 // Read in database from specific free format file.
1123 
1124 bool ParticleData::readFF(istream& is, bool reset) {
1125 
1126  // Normally reset whole database before beginning.
1127  if (reset) {
1128  pdt.clear();
1129  readStringHistory.resize(0);
1130  readStringSubrun.clear();
1131  isInit = false;
1132  }
1133 
1134  if (!is.good()) {
1135  infoPtr->errorMsg("Error in ParticleData::readFF:"
1136  " did not find stream");
1137  return false;
1138  }
1139 
1140  // Read in one line at a time.
1141  particlePtr = 0;
1142  string line;
1143  bool readParticle = false;
1144  while ( getline(is, line) ) {
1145 
1146  // Empty lines begins new particle.
1147  if (line.find_first_not_of(" \n\t\v\b\r\f\a") == string::npos) {
1148  readParticle = true;
1149  continue;
1150  }
1151 
1152  // Prepare to use standard read from line.
1153  istringstream readLine(line);
1154 
1155  // Read in a line with particle information.
1156  if (readParticle) {
1157 
1158  // Properties to be read.
1159  int idTmp;
1160  string nameTmp, antiNameTmp;
1161  int spinTypeTmp, chargeTypeTmp, colTypeTmp;
1162  double m0Tmp, mWidthTmp, mMinTmp, mMaxTmp, tau0Tmp;
1163  string mayTmp;
1164 
1165  // Do the reading.
1166  readLine >> idTmp >> nameTmp >> antiNameTmp >> spinTypeTmp
1167  >> chargeTypeTmp >> colTypeTmp >> m0Tmp >> mWidthTmp
1168  >> mMinTmp >> mMaxTmp >> tau0Tmp;
1169 
1170  // Error printout if something went wrong.
1171  if (!readLine) {
1172  infoPtr->errorMsg("Error in ParticleData::readFF:"
1173  " incomplete particle", line);
1174  return false;
1175  }
1176 
1177  // Erase if particle already exists.
1178  if (isParticle(idTmp)) pdt.erase(idTmp);
1179 
1180  // Store new particle. Save pointer, to be used for decay channels.
1181  addParticle( idTmp, nameTmp, antiNameTmp, spinTypeTmp, chargeTypeTmp,
1182  colTypeTmp, m0Tmp, mWidthTmp, mMinTmp, mMaxTmp, tau0Tmp);
1183  particlePtr = particleDataEntryPtr(idTmp);
1184  readParticle = false;
1185 
1186  // Read in a line with decay channel information.
1187  } else {
1188 
1189  // Properties to be read.
1190  int onMode = 0;
1191  double bRatio = 0.;
1192  int meMode = 0;
1193  int prod0 = 0; int prod1 = 0; int prod2 = 0; int prod3 = 0;
1194  int prod4 = 0; int prod5 = 0; int prod6 = 0; int prod7 = 0;
1195 
1196  // Read in data from stream. Need at least one decay product.
1197  readLine >> onMode >> bRatio >> meMode >> prod0;
1198  if (!readLine) {
1199  infoPtr->errorMsg("Error in ParticleData::readFF:"
1200  " incomplete decay channel", line);
1201  return false;
1202  }
1203  readLine >> prod1 >> prod2 >> prod3 >> prod4 >> prod5
1204  >> prod6 >> prod7;
1205 
1206  // Store new channel.
1207  if (particlePtr == 0) {
1208  infoPtr->errorMsg("Error in ParticleData::readFF:"
1209  " orphan decay channel", line);
1210  return false;
1211  }
1212  particlePtr->addChannel(onMode, bRatio, meMode, prod0, prod1,
1213  prod2, prod3, prod4, prod5, prod6, prod7);
1214 
1215  }
1216 
1217  // End of while loop over lines in the file.
1218  }
1219 
1220 
1221  // Done.
1222  isInit = true;
1223  return true;
1224 
1225 }
1226 
1227 
1228 //--------------------------------------------------------------------------
1229 
1230 // Read in database from specific free format file.
1231 
1232 bool ParticleData::readFF(string inFile, bool reset) {
1233 
1234  const char* cstring = inFile.c_str();
1235  ifstream is(cstring);
1236 
1237  return readFF(is,reset);
1238 }
1239 
1240 //--------------------------------------------------------------------------
1241 
1242 // Print out complete database in numerical order as a free format file.
1243 
1244 void ParticleData::listFF(string outFile) {
1245 
1246  // Convert file name to ofstream.
1247  const char* cstring = outFile.c_str();
1248  ofstream os(cstring);
1249 
1250  // Iterate through the particle data table.
1251  for (map<int, ParticleDataEntry>::iterator pdtEntry
1252  = pdt.begin(); pdtEntry != pdt.end(); ++pdtEntry) {
1253  particlePtr = &pdtEntry->second;
1254 
1255  // Pick format for mass and width based on mass value.
1256  double m0Now = particlePtr->m0();
1257  if (m0Now == 0 || (m0Now > 0.1 && m0Now < 1000.))
1258  os << fixed << setprecision(5);
1259  else os << scientific << setprecision(3);
1260 
1261  // Print particle properties.
1262  os << "\n" << setw(8) << particlePtr->id() << " "
1263  << left << setw(16) << particlePtr->name() << " "
1264  << setw(16) << particlePtr->name(-1) << " "
1265  << right << setw(2) << particlePtr->spinType() << " "
1266  << setw(2) << particlePtr->chargeType() << " "
1267  << setw(2) << particlePtr->colType() << " "
1268  << setw(10) << particlePtr->m0() << " "
1269  << setw(10) << particlePtr->mWidth() << " "
1270  << setw(10) << particlePtr->mMin() << " "
1271  << setw(10) << particlePtr->mMax() << " "
1272  << scientific << setprecision(5)
1273  << setw(12) << particlePtr->tau0() << "\n";
1274 
1275  // Loop through the decay channel table for each particle.
1276  if (particlePtr->sizeChannels() > 0) {
1277  for (int i = 0; i < particlePtr->sizeChannels(); ++i) {
1278  const DecayChannel& channel = particlePtr->channel(i);
1279  os << " " << setw(6) << channel.onMode()
1280  << " " << fixed << setprecision(7) << setw(10)
1281  << channel.bRatio() << " "
1282  << setw(3) << channel.meMode() << " ";
1283  for (int j = 0; j < channel.multiplicity(); ++j)
1284  os << setw(8) << channel.product(j) << " ";
1285  os << "\n";
1286  }
1287  }
1288 
1289  }
1290 
1291 }
1292 
1293 //--------------------------------------------------------------------------
1294 
1295 // Read in updates from a character string, like a line of a file.
1296 // Is used by readString (and readFile) in Pythia.
1297 
1298  bool ParticleData::readString(string lineIn, bool warn) {
1299 
1300  // If empty line then done.
1301  if (lineIn.find_first_not_of(" \n\t\v\b\r\f\a") == string::npos) return true;
1302 
1303  // Take copy that will be modified.
1304  string line = lineIn;
1305 
1306  // If first character is not a digit then taken to be a comment.
1307  int firstChar = line.find_first_not_of(" \n\t\v\b\r\f\a");
1308  if (!isdigit(line[firstChar])) return true;
1309 
1310  // Replace colons and equal signs by blanks to make parsing simpler.
1311  for ( int j = 0; j < int(line.size()); ++ j)
1312  if (line[j] == ':' || line[j] == '=') line[j] = ' ';
1313 
1314  // Get particle id and property name.
1315  int idTmp;
1316  string property;
1317  istringstream getWord(line);
1318  getWord >> idTmp >> property;
1319  toLowerRep(property);
1320 
1321  // Check that valid particle.
1322  if ( (!isParticle(idTmp) && property != "all" && property != "new")
1323  || idTmp <= 0) {
1324  if (warn) cout << "\n PYTHIA Error: input particle not found in Particle"
1325  << " Data Table:\n " << lineIn << "\n";
1326  readingFailedSave = true;
1327  return false;
1328  }
1329 
1330  // Store history of readString statements.
1331  readStringHistory.push_back(line);
1332  int subrun = max( -1, settingsPtr->mode("Main:subrun"));
1333  if (readStringSubrun.find(subrun) == readStringSubrun.end())
1334  readStringSubrun[subrun] = vector<string>();
1335  readStringSubrun[subrun].push_back(line);
1336 
1337  // Identify particle property and read + set its value, case by case.
1338  if (property == "name") {
1339  string nameTmp;
1340  getWord >> nameTmp;
1341  pdt[idTmp].setName(nameTmp);
1342  return true;
1343  }
1344  if (property == "antiname") {
1345  string antiNameTmp;
1346  getWord >> antiNameTmp;
1347  pdt[idTmp].setAntiName(antiNameTmp);
1348  return true;
1349  }
1350  if (property == "names") {
1351  string nameTmp, antiNameTmp;
1352  getWord >> nameTmp >> antiNameTmp;
1353  pdt[idTmp].setNames(nameTmp, antiNameTmp);
1354  return true;
1355  }
1356  if (property == "spintype") {
1357  int spinTypeTmp;
1358  getWord >> spinTypeTmp;
1359  pdt[idTmp].setSpinType(spinTypeTmp);
1360  return true;
1361  }
1362  if (property == "chargetype") {
1363  int chargeTypeTmp;
1364  getWord >> chargeTypeTmp;
1365  pdt[idTmp].setChargeType(chargeTypeTmp);
1366  return true;
1367  }
1368  if (property == "coltype") {
1369  int colTypeTmp;
1370  getWord >> colTypeTmp;
1371  pdt[idTmp].setColType(colTypeTmp);
1372  return true;
1373  }
1374  if (property == "m0") {
1375  double m0Tmp;
1376  getWord >> m0Tmp;
1377  pdt[idTmp].setM0(m0Tmp);
1378  return true;
1379  }
1380  if (property == "mwidth") {
1381  double mWidthTmp;
1382  getWord >> mWidthTmp;
1383  pdt[idTmp].setMWidth(mWidthTmp);
1384  return true;
1385  }
1386  if (property == "mmin") {
1387  double mMinTmp;
1388  getWord >> mMinTmp;
1389  pdt[idTmp].setMMin(mMinTmp);
1390  return true;
1391  }
1392  if (property == "mmax") {
1393  double mMaxTmp;
1394  getWord >> mMaxTmp;
1395  pdt[idTmp].setMMax(mMaxTmp);
1396  return true;
1397  }
1398  if (property == "tau0") {
1399  double tau0Tmp;
1400  getWord >> tau0Tmp;
1401  pdt[idTmp].setTau0(tau0Tmp);
1402  return true;
1403  }
1404  if (property == "isresonance") {
1405  string isresTmp;
1406  getWord >> isresTmp;
1407  bool isResonanceTmp = boolString(isresTmp);
1408  pdt[idTmp].setIsResonance(isResonanceTmp);
1409  return true;
1410  }
1411  if (property == "maydecay") {
1412  string mayTmp;
1413  getWord >> mayTmp;
1414  bool mayDecayTmp = boolString(mayTmp);
1415  pdt[idTmp].setMayDecay(mayDecayTmp);
1416  return true;
1417  }
1418  if (property == "doexternaldecay") {
1419  string extdecTmp;
1420  getWord >> extdecTmp;
1421  bool doExternalDecayTmp = boolString(extdecTmp);
1422  pdt[idTmp].setDoExternalDecay(doExternalDecayTmp);
1423  return true;
1424  }
1425  if (property == "isvisible") {
1426  string isvisTmp;
1427  getWord >> isvisTmp;
1428  bool isVisibleTmp = boolString(isvisTmp);
1429  pdt[idTmp].setIsVisible(isVisibleTmp);
1430  return true;
1431  }
1432  if (property == "doforcewidth") {
1433  string doforceTmp;
1434  getWord >> doforceTmp;
1435  bool doForceWidthTmp = boolString(doforceTmp);
1436  pdt[idTmp].setDoForceWidth(doForceWidthTmp);
1437  return true;
1438  }
1439 
1440  // Addition or complete replacement of a particle.
1441  if (property == "all" || property == "new") {
1442 
1443  // Default values for properties to be read.
1444  string nameTmp = "void";
1445  string antiNameTmp = "void";
1446  int spinTypeTmp = 0;
1447  int chargeTypeTmp = 0;
1448  int colTypeTmp = 0;
1449  double m0Tmp = 0.;
1450  double mWidthTmp = 0.;
1451  double mMinTmp = 0.;
1452  double mMaxTmp = 0.;
1453  double tau0Tmp = 0.;
1454 
1455  // Read in data from stream.
1456  getWord >> nameTmp >> antiNameTmp >> spinTypeTmp >> chargeTypeTmp
1457  >> colTypeTmp >> m0Tmp >> mWidthTmp >> mMinTmp >> mMaxTmp
1458  >> tau0Tmp;
1459 
1460  // To keep existing decay channels, only overwrite particle data.
1461  if (property == "all" && isParticle(idTmp)) {
1462  setAll( idTmp, nameTmp, antiNameTmp, spinTypeTmp, chargeTypeTmp,
1463  colTypeTmp, m0Tmp, mWidthTmp, mMinTmp, mMaxTmp, tau0Tmp);
1464 
1465  // Else start over completely from scratch.
1466  } else {
1467  if (isParticle(idTmp)) pdt.erase(idTmp);
1468  addParticle( idTmp, nameTmp, antiNameTmp, spinTypeTmp, chargeTypeTmp,
1469  colTypeTmp, m0Tmp, mWidthTmp, mMinTmp, mMaxTmp, tau0Tmp);
1470  }
1471  return true;
1472  }
1473 
1474  // Set onMode of all decay channels in one go.
1475  if (property == "onmode") {
1476  int onMode = 0;
1477  string onModeIn;
1478  getWord >> onModeIn;
1479  // For onMode allow the optional possibility of Bool input.
1480  if (isdigit(onModeIn[0])) {
1481  istringstream getOnMode(onModeIn);
1482  getOnMode >> onMode;
1483  } else onMode = (boolString(onModeIn)) ? 1 : 0;
1484  for (int i = 0; i < pdt[idTmp].sizeChannels(); ++i)
1485  pdt[idTmp].channel(i).onMode(onMode);
1486  return true;
1487  }
1488 
1489  // Selective search for matching decay channels.
1490  int matchKind = 0;
1491  if (property == "offifany" || property == "onifany" ||
1492  property == "onposifany" || property == "onnegifany") matchKind = 1;
1493  if (property == "offifall" || property == "onifall" ||
1494  property == "onposifall" || property == "onnegifall") matchKind = 2;
1495  if (property == "offifmatch" || property == "onifmatch" ||
1496  property == "onposifmatch" || property == "onnegifmatch") matchKind = 3;
1497  if (matchKind > 0) {
1498  int onMode = 0;
1499  if (property == "onifany" || property == "onifall"
1500  || property == "onifmatch") onMode = 1;
1501  if (property == "onposifany" || property == "onposifall"
1502  || property == "onposifmatch") onMode = 2;
1503  if (property == "onnegifany" || property == "onnegifall"
1504  || property == "onnegifmatch") onMode = 3;
1505 
1506  // Read in particles to match.
1507  vector<int> idToMatch;
1508  int idRead;
1509  for ( ; ; ) {
1510  getWord >> idRead;
1511  if (!getWord) break;
1512  idToMatch.push_back(abs(idRead));
1513  }
1514  int nToMatch = idToMatch.size();
1515 
1516  // Loop over all decay channels.
1517  for (int i = 0; i < pdt[idTmp].sizeChannels(); ++i) {
1518  int multi = pdt[idTmp].channel(i).multiplicity();
1519 
1520  // Look for any match at all.
1521  if (matchKind == 1) {
1522  bool foundMatch = false;
1523  for (int j = 0; j < multi; ++j) {
1524  int idNow = abs(pdt[idTmp].channel(i).product(j));
1525  for (int k = 0; k < nToMatch; ++k)
1526  if (idNow == idToMatch[k]) {foundMatch = true; break;}
1527  if (foundMatch) break;
1528  }
1529  if (foundMatch) pdt[idTmp].channel(i).onMode(onMode);
1530 
1531  // Look for match of all products provided.
1532  } else {
1533  int nUnmatched = nToMatch;
1534  if (multi < nToMatch);
1535  else if (multi > nToMatch && matchKind == 3);
1536  else {
1537  vector<int> idUnmatched;
1538  for (int k = 0; k < nToMatch; ++k)
1539  idUnmatched.push_back(idToMatch[k]);
1540  for (int j = 0; j < multi; ++j) {
1541  int idNow = abs(pdt[idTmp].channel(i).product(j));
1542  for (int k = 0; k < nUnmatched; ++k)
1543  if (idNow == idUnmatched[k]) {
1544  idUnmatched[k] = idUnmatched[--nUnmatched];
1545  break;
1546  }
1547  if (nUnmatched == 0) break;
1548  }
1549  }
1550  if (nUnmatched == 0) pdt[idTmp].channel(i).onMode(onMode);
1551  }
1552  }
1553  return true;
1554  }
1555 
1556  // Rescale all branching ratios by common factor.
1557  if (property == "rescalebr") {
1558  double factor;
1559  getWord >> factor;
1560  pdt[idTmp].rescaleBR(factor);
1561  return true;
1562  }
1563 
1564  // Reset decay table in preparation for new input.
1565  if (property == "onechannel") pdt[idTmp].clearChannels();
1566 
1567  // Add or change a decay channel: get channel number and new property.
1568  if (property == "addchannel" || property == "onechannel"
1569  || isdigit(property[0])) {
1570  int channel;
1571  if (property == "addchannel" || property == "onechannel") {
1572  pdt[idTmp].addChannel();
1573  channel = pdt[idTmp].sizeChannels() - 1;
1574  property = "all";
1575  } else{
1576  istringstream getChannel(property);
1577  getChannel >> channel;
1578  getWord >> property;
1579  toLowerRep(property);
1580  }
1581 
1582  // Check that channel exists.
1583  if (channel < 0 || channel >= pdt[idTmp].sizeChannels()) return false;
1584 
1585  // Find decay channel property and value, case by case.
1586  // At same time also do case where all should be replaced.
1587  if (property == "onmode" || property == "all") {
1588  int onMode = 0;
1589  string onModeIn;
1590  getWord >> onModeIn;
1591  // For onMode allow the optional possibility of Bool input.
1592  if (isdigit(onModeIn[0])) {
1593  istringstream getOnMode(onModeIn);
1594  getOnMode >> onMode;
1595  } else onMode = (boolString(onModeIn)) ? 1 : 0;
1596  pdt[idTmp].channel(channel).onMode(onMode);
1597  if (property == "onmode") return true;
1598  }
1599  if (property == "bratio" || property == "all") {
1600  double bRatio;
1601  getWord >> bRatio;
1602  pdt[idTmp].channel(channel).bRatio(bRatio);
1603  if (property == "bratio") return true;
1604  }
1605  if (property == "memode" || property == "all") {
1606  int meMode;
1607  getWord >> meMode;
1608  pdt[idTmp].channel(channel).meMode(meMode);
1609  if (property == "memode") return true;
1610  }
1611 
1612  // Scan for products until end of line.
1613  if (property == "products" || property == "all") {
1614  int nProd = 0;
1615  for (int iProd = 0; iProd < 8; ++iProd) {
1616  int idProd;
1617  getWord >> idProd;
1618  if (!getWord) break;
1619  pdt[idTmp].channel(channel).product(iProd, idProd);
1620  ++nProd;
1621  }
1622  for (int iProd = nProd; iProd < 8; ++iProd)
1623  pdt[idTmp].channel(channel).product(iProd, 0);
1624  pdt[idTmp].channel(channel).multiplicity(nProd);
1625  return true;
1626  }
1627 
1628  // Rescale an existing branching ratio.
1629  if (property == "rescalebr") {
1630  double factor;
1631  getWord >> factor;
1632  pdt[idTmp].channel(channel).rescaleBR(factor);
1633  return true;
1634  }
1635  }
1636 
1637  // Return false if failed to recognize property.
1638  if (warn) cout << "\n PYTHIA Error: input property not found in Particle"
1639  << " Data Table:\n " << lineIn << "\n";
1640  readingFailedSave = true;
1641  return false;
1642 
1643 }
1644 
1645 //--------------------------------------------------------------------------
1646 
1647 // Print out complete or changed table of database in numerical order.
1648 
1649 void ParticleData::list(bool changedOnly, bool changedRes) {
1650 
1651  // Table header; output for bool as off/on.
1652  if (!changedOnly) {
1653  cout << "\n -------- PYTHIA Particle Data Table (complete) --------"
1654  << "------------------------------------------------------------"
1655  << "--------------\n \n";
1656 
1657  } else {
1658  cout << "\n -------- PYTHIA Particle Data Table (changed only) ----"
1659  << "------------------------------------------------------------"
1660  << "--------------\n \n";
1661  }
1662  cout << " id name antiName spn chg col m0"
1663  << " mWidth mMin mMax tau0 res dec ext "
1664  << "vis wid\n no onMode bRatio meMode products \n";
1665 
1666  // Iterate through the particle data table. Option to skip unchanged.
1667  int nList = 0;
1668  for (map<int, ParticleDataEntry>::iterator pdtEntry
1669  = pdt.begin(); pdtEntry != pdt.end(); ++pdtEntry) {
1670  particlePtr = &pdtEntry->second;
1671  if ( !changedOnly || particlePtr->hasChanged() ||
1672  ( changedRes && particlePtr->getResonancePtr() != 0 ) ) {
1673 
1674  // Pick format for mass and width based on mass value.
1675  double m0Now = particlePtr->m0();
1676  if (m0Now == 0 || (m0Now > 0.1 && m0Now < 1000.))
1677  cout << fixed << setprecision(5);
1678  else cout << scientific << setprecision(3);
1679 
1680  // Print particle properties.
1681  ++nList;
1682  cout << "\n" << setw(8) << particlePtr->id() << " " << left;
1683  if (particlePtr->name(-1) == "void")
1684  cout << setw(33) << particlePtr->name() << " ";
1685  else cout << setw(16) << particlePtr->name() << " "
1686  << setw(16) << particlePtr->name(-1) << " ";
1687  cout << right << setw(2) << particlePtr->spinType() << " "
1688  << setw(2) << particlePtr->chargeType() << " "
1689  << setw(2) << particlePtr->colType() << " "
1690  << setw(10) << particlePtr->m0() << " "
1691  << setw(10) << particlePtr->mWidth() << " "
1692  << setw(10) << particlePtr->mMin() << " "
1693  << setw(10) << particlePtr->mMax() << " "
1694  << scientific << setprecision(5)
1695  << setw(12) << particlePtr->tau0() << " " << setw(2)
1696  << particlePtr->isResonance() << " " << setw(2)
1697  << (particlePtr->mayDecay() && particlePtr->canDecay())
1698  << " " << setw(2) << particlePtr->doExternalDecay() << " "
1699  << setw(2) << particlePtr->isVisible()<< " "
1700  << setw(2) << particlePtr->doForceWidth() << "\n";
1701 
1702  // Loop through the decay channel table for each particle.
1703  if (particlePtr->sizeChannels() > 0) {
1704  for (int i = 0; i < int(particlePtr->sizeChannels()); ++i) {
1705  const DecayChannel& channel = particlePtr->channel(i);
1706  cout << " " << setprecision(7) << setw(5) << i
1707  << setw(6) << channel.onMode() << fixed<< setw(12)
1708  << channel.bRatio() << setw(5) << channel.meMode() << " ";
1709  for (int j = 0; j < channel.multiplicity(); ++j)
1710  cout << setw(8) << channel.product(j) << " ";
1711  cout << "\n";
1712  }
1713  }
1714  }
1715 
1716  }
1717 
1718  // End of loop over database contents.
1719  if (changedOnly && nList == 0) cout << "\n no particle data has been "
1720  << "changed from its default value \n";
1721  cout << "\n -------- End PYTHIA Particle Data Table -----------------"
1722  << "--------------------------------------------------------------"
1723  << "----------\n" << endl;
1724 
1725 }
1726 
1727 //--------------------------------------------------------------------------
1728 
1729 // Print out partial table of database in input order.
1730 
1731 void ParticleData::list(vector<int> idList) {
1732 
1733  // Table header; output for bool as off/on.
1734  cout << "\n -------- PYTHIA Particle Data Table (partial) ---------"
1735  << "------------------------------------------------------------"
1736  << "--------------\n \n";
1737  cout << " id name antiName spn chg col m0"
1738  << " mWidth mMin mMax tau0 res dec ext "
1739  << "vis wid\n no onMode bRatio meMode products \n";
1740 
1741  // Iterate through the given list of input particles.
1742  for (int i = 0; i < int(idList.size()); ++i) {
1743  particlePtr = particleDataEntryPtr(idList[i]);
1744 
1745  // Pick format for mass and width based on mass value.
1746  double m0Now = particlePtr->m0();
1747  if (m0Now == 0 || (m0Now > 0.1 && m0Now < 1000.))
1748  cout << fixed << setprecision(5);
1749  else cout << scientific << setprecision(3);
1750 
1751  // Print particle properties.
1752  cout << "\n" << setw(8) << particlePtr->id() << " " << left;
1753  if (particlePtr->name(-1) == "void")
1754  cout << setw(33) << particlePtr->name() << " ";
1755  else cout << setw(16) << particlePtr->name() << " "
1756  << setw(16) << particlePtr->name(-1) << " ";
1757  cout << right << setw(2) << particlePtr->spinType() << " "
1758  << setw(2) << particlePtr->chargeType() << " "
1759  << setw(2) << particlePtr->colType() << " "
1760  << setw(10) << particlePtr->m0() << " "
1761  << setw(10) << particlePtr->mWidth() << " "
1762  << setw(10) << particlePtr->mMin() << " "
1763  << setw(10) << particlePtr->mMax() << " "
1764  << scientific << setprecision(5)
1765  << setw(12) << particlePtr->tau0() << " " << setw(2)
1766  << particlePtr->isResonance() << " " << setw(2)
1767  << (particlePtr->mayDecay() && particlePtr->canDecay())
1768  << " " << setw(2) << particlePtr->doExternalDecay() << " "
1769  << setw(2) << particlePtr->isVisible() << " "
1770  << setw(2) << particlePtr->doForceWidth() << "\n";
1771 
1772  // Loop through the decay channel table for each particle.
1773  if (particlePtr->sizeChannels() > 0) {
1774  for (int j = 0; j < int(particlePtr->sizeChannels()); ++j) {
1775  const DecayChannel& channel = particlePtr->channel(j);
1776  cout << " " << setprecision(7) << setw(5) << j
1777  << setw(6) << channel.onMode() << fixed << setw(12)
1778  << channel.bRatio() << setw(5) << channel.meMode() << " ";
1779  for (int k = 0; k < channel.multiplicity(); ++k)
1780  cout << setw(8) << channel.product(k) << " ";
1781  cout << "\n";
1782  }
1783  }
1784 
1785  }
1786 
1787  // End of loop over database contents.
1788  cout << "\n -------- End PYTHIA Particle Data Table -----------------"
1789  << "--------------------------------------------------------------"
1790  << "----------\n" << endl;
1791 
1792 }
1793 
1794 //--------------------------------------------------------------------------
1795 
1796 // Check that table makes sense: e.g. consistent names and mass ranges,
1797 // that branching ratios sum to unity, that charge is conserved and
1798 // that phase space is open in each channel.
1799 // verbosity = 0: mimimal amount of checks, e.g. that no channels open.
1800 // = 1: further warning if individual channels closed
1801 // (except for resonances).
1802 // = 2: also print branching-ratio-averaged threshold mass.
1803 // = 11, 12: as 1, 2, but include resonances in detailed checks.
1804 
1805 void ParticleData::checkTable(int verbosity) {
1806 
1807  // Header.
1808  cout << "\n -------- PYTHIA Check of Particle Data Table ------------"
1809  <<"------\n\n";
1810  int nErr = 0;
1811 
1812  // Loop through all particles.
1813  for (map<int, ParticleDataEntry>::iterator pdtEntry
1814  = pdt.begin(); pdtEntry != pdt.end(); ++pdtEntry) {
1815  particlePtr = &pdtEntry->second;
1816 
1817  // Extract some particle properties. Set some flags.
1818  int idNow = particlePtr->id();
1819  bool hasAntiNow = particlePtr->hasAnti();
1820  int spinTypeNow = particlePtr->spinType();
1821  int chargeTypeNow = particlePtr->chargeType();
1822  int baryonTypeNow = particlePtr->baryonNumberType();
1823  double m0Now = particlePtr->m0();
1824  double mMinNow = particlePtr->mMin();
1825  double mMaxNow = particlePtr->mMax();
1826  double mWidthNow = particlePtr->mWidth();
1827  double tau0Now = particlePtr->tau0();
1828  bool isResonanceNow = particlePtr->isResonance();
1829  bool hasPrinted = false;
1830  bool studyCloser = verbosity > 10 || !isResonanceNow;
1831 
1832  // Check that particle name consistent with charge information.
1833  string particleName = particlePtr->name(1);
1834  if (particleName.size() > 16) {
1835  cout << " Warning: particle " << idNow << " has name " << particleName
1836  << " of length " << particleName.size() << "\n";
1837  hasPrinted = true;
1838  ++nErr;
1839  }
1840  int nPos = 0;
1841  int nNeg = 0;
1842  for (int i = 0; i < int(particleName.size()); ++i) {
1843  if (particleName[i] == '+') ++nPos;
1844  if (particleName[i] == '-') ++nNeg;
1845  }
1846  if ( (nPos > 0 && nNeg > 0) || ( nPos + nNeg > 0
1847  && 3 * (nPos - nNeg) != chargeTypeNow )) {
1848  cout << " Warning: particle " << idNow << " has name " << particleName
1849  << " inconsistent with charge type " << chargeTypeNow << "\n";
1850  hasPrinted = true;
1851  ++nErr;
1852  }
1853 
1854  // Check that antiparticle name consistent with charge information.
1855  if (hasAntiNow) {
1856  particleName = particlePtr->name(-1);
1857  if (particleName.size() > 16) {
1858  cout << " Warning: particle " << idNow << " has name " << particleName
1859  << " of length " << particleName.size() << "\n";
1860  hasPrinted = true;
1861  ++nErr;
1862  }
1863  nPos = 0;
1864  nNeg = 0;
1865  for (int i = 0; i < int(particleName.size()); ++i) {
1866  if (particleName[i] == '+') ++nPos;
1867  if (particleName[i] == '-') ++nNeg;
1868  }
1869  if ( (nPos > 0 && nNeg > 0) || ( nPos + nNeg > 0
1870  && 3 * (nPos - nNeg) != -chargeTypeNow )) {
1871  cout << " Warning: particle " << -idNow << " has name "
1872  << particleName << " inconsistent with charge type "
1873  << -chargeTypeNow << "\n";
1874  hasPrinted = true;
1875  ++nErr;
1876  }
1877  }
1878 
1879  // Check that mass, mass range and width are consistent.
1880  if (particlePtr->useBreitWigner()) {
1881  if (mMinNow > m0Now) {
1882  cout << " Error: particle " << idNow << " has mMin "
1883  << fixed << setprecision(5) << mMinNow
1884  << " larger than m0 " << m0Now << "\n";
1885  hasPrinted = true;
1886  ++nErr;
1887  }
1888  if (mMaxNow > mMinNow && mMaxNow < m0Now) {
1889  cout << " Error: particle " << idNow << " has mMax "
1890  << fixed << setprecision(5) << mMaxNow
1891  << " smaller than m0 " << m0Now << "\n";
1892  hasPrinted = true;
1893  ++nErr;
1894  }
1895  if (mMaxNow > mMinNow && mMaxNow - mMinNow < mWidthNow) {
1896  cout << " Warning: particle " << idNow << " has mMax - mMin "
1897  << fixed << setprecision(5) << mMaxNow - mMinNow
1898  << " smaller than mWidth " << mWidthNow << "\n";
1899  hasPrinted = true;
1900  ++nErr;
1901  }
1902  }
1903 
1904  // Check that particle does not both have width and lifetime.
1905  if (mWidthNow > 0. && tau0Now > 0.) {
1906  cout << " Warning: particle " << idNow << " has both nonvanishing width "
1907  << scientific << setprecision(5) << mWidthNow << " and lifetime "
1908  << tau0Now << "\n";
1909  hasPrinted = true;
1910  ++nErr;
1911  }
1912 
1913  // Begin study decay channels.
1914  if (particlePtr->sizeChannels() > 0) {
1915 
1916  // Loop through all decay channels.
1917  double bRatioSum = 0.;
1918  double bRatioPos = 0.;
1919  double bRatioNeg = 0.;
1920  bool hasPosBR = false;
1921  bool hasNegBR = false;
1922  double threshMass = 0.;
1923  bool openChannel = false;
1924  for (int i = 0; i < particlePtr->sizeChannels(); ++i) {
1925 
1926  // Extract channel properties.
1927  int onMode = particlePtr->channel(i).onMode();
1928  double bRatio = particlePtr->channel(i).bRatio();
1929  int meMode = particlePtr->channel(i).meMode();
1930  int mult = particlePtr->channel(i).multiplicity();
1931  int prod[8];
1932  for (int j = 0; j < 8; ++j)
1933  prod[j] = particlePtr->channel(i).product(j);
1934 
1935  // Sum branching ratios. Include off-channels.
1936  if (onMode == 0 || onMode == 1) bRatioSum += bRatio;
1937  else if (onMode == 2) {bRatioPos += bRatio; hasPosBR = true;}
1938  else if (onMode == 3) {bRatioNeg += bRatio; hasNegBR = true;}
1939 
1940  // Error printout when unknown decay product code.
1941  for (int j = 0; j < 8; ++j) {
1942  if ( prod[j] != 0 && !isParticle(prod[j]) ) {
1943  cout << " Error: unknown decay product for " << idNow
1944  << " -> " << prod[j] << "\n";
1945  hasPrinted = true;
1946  ++nErr;
1947  continue;
1948  }
1949  }
1950 
1951  // Error printout when no decay products or 0 interspersed.
1952  int nLast = 0;
1953  for (int j = 0; j < 8; ++j)
1954  if (prod[j] != 0) nLast = j + 1;
1955  if (mult == 0 || mult != nLast) {
1956  cout << " Error: corrupted decay product list for "
1957  << particlePtr->id() << " -> ";
1958  for (int j = 0; j < 8; ++j) cout << prod[j] << " ";
1959  cout << "\n";
1960  hasPrinted = true;
1961  ++nErr;
1962  continue;
1963  }
1964 
1965  // Check charge conservation and open phase space in decay channel.
1966  int chargeTypeSum = -chargeTypeNow;
1967  int baryonTypeSum = -baryonTypeNow;
1968  double avgFinalMass = 0.;
1969  double minFinalMass = 0.;
1970  bool canHandle = true;
1971  for (int j = 0; j < mult; ++j) {
1972  chargeTypeSum += chargeType( prod[j] );
1973  baryonTypeSum += baryonNumberType( prod[j] );
1974  avgFinalMass += m0( prod[j] );
1975  minFinalMass += m0Min( prod[j] );
1976  if (prod[j] == 81 || prod[j] == 82 || prod[j] == 83)
1977  canHandle = false;
1978  }
1979  threshMass += bRatio * avgFinalMass;
1980 
1981  // Error printout when charge or baryon number not conserved.
1982  if (chargeTypeSum != 0 && canHandle) {
1983  cout << " Error: 3*charge changed by " << chargeTypeSum
1984  << " in " << idNow << " -> ";
1985  for (int j = 0; j < mult; ++j) cout << prod[j] << " ";
1986  cout << "\n";
1987  hasPrinted = true;
1988  ++nErr;
1989  continue;
1990  }
1991  if ( baryonTypeSum != 0 && canHandle && particlePtr->isHadron() ) {
1992  cout << " Error: 3*baryon number changed by " << baryonTypeSum
1993  << " in " << idNow << " -> ";
1994  for (int j = 0; j < mult; ++j) cout << prod[j] << " ";
1995  cout << "\n";
1996  hasPrinted = true;
1997  ++nErr;
1998  continue;
1999  }
2000 
2001  // Begin check that some matrix elements are used correctly.
2002  bool correctME = true;
2003 
2004  // Check matrix element mode 0: recommended not into partons.
2005  if (meMode == 0 && !isResonanceNow) {
2006  bool hasPartons = false;
2007  for (int j = 0; j < mult; ++j) {
2008  int idAbs = abs(prod[j]);
2009  if ( idAbs < 10 || idAbs == 21 || idAbs == 81 || idAbs == 82
2010  || idAbs == 83 || (idAbs > 1000 && idAbs < 10000
2011  && (idAbs/10)%10 == 0) ) hasPartons = true;
2012  }
2013  if (hasPartons) correctME = false;
2014  }
2015 
2016  // Check matrix element mode 1: rho/omega -> pi+ pi- pi0.
2017  bool useME1 = ( mult == 3 && spinTypeNow == 3 && idNow > 100
2018  && idNow < 1000
2019  && particlePtr->channel(i).contains(211, -211, 111) );
2020  if ( meMode == 1 && !useME1 ) correctME = false;
2021  if ( meMode != 1 && useME1 ) correctME = false;
2022 
2023  // Check matrix element mode 2: polarization in V -> PS + PS.
2024  bool useME2 = ( mult == 2 && spinTypeNow == 3 && idNow > 100
2025  && idNow < 1000 && spinType(prod[0]) == 1
2026  && spinType(prod[1]) == 1 );
2027  if ( meMode == 2 && !useME2 ) correctME = false;
2028  if ( meMode != 2 && useME2 ) correctME = false;
2029 
2030  // Check matrix element mode 11, 12 and 13: Dalitz decay with
2031  // one or more particles in addition to the lepton pair,
2032  // or double Dalitz decay.
2033  bool useME11 = ( mult == 3 && !isResonanceNow
2034  && (prod[1] == 11 || prod[1] == 13 || prod[1] == 15)
2035  && prod[2] == -prod[1] );
2036  bool useME12 = ( mult > 3 && !isResonanceNow
2037  && (prod[mult - 2] == 11 || prod[mult - 2] == 13
2038  || prod[mult - 2] == 15) && prod[mult - 1] == -prod[mult - 2] );
2039  bool useME13 = ( mult == 4 && !isResonanceNow
2040  && (prod[0] == 11 || prod[0] == 13) && prod[1] == -prod[0]
2041  && (prod[2] == 11 || prod[2] == 13) && prod[3] == -prod[2] );
2042  if (useME13) useME12 = false;
2043  if ( meMode == 11 && !useME11 ) correctME = false;
2044  if ( meMode != 11 && useME11 ) correctME = false;
2045  if ( meMode == 12 && !useME12 ) correctME = false;
2046  if ( meMode != 12 && useME12 ) correctME = false;
2047  if ( meMode == 13 && !useME13 ) correctME = false;
2048  if ( meMode != 13 && useME13 ) correctME = false;
2049 
2050  // Check matrix element mode 21: tau -> nu_tau hadrons.
2051  bool useME21 = (idNow == 15 && mult > 2 && prod[0] == 16
2052  && abs(prod[1]) > 100);
2053  if ( meMode == 21 && !useME21 ) correctME = false;
2054  if ( meMode != 21 && useME21 ) correctME = false;
2055 
2056  // Check matrix element mode 22, but only for semileptonic decay.
2057  // For a -> b c d require types u = 2, ubar = -2, d = 1, dbar = -1.
2058  if ( isLepton(prod[0]) && isLepton(prod[1]) ) {
2059  bool useME22 = false;
2060  int typeA = 0;
2061  int typeB = 0;
2062  int typeC = 0;
2063  if (particlePtr->isLepton()) {
2064  typeA = (idNow > 0) ? 1 + (idNow-1)%2 : -1 - (1-idNow)%2;
2065  } else if (particlePtr->isHadron()) {
2066  int hQ = particlePtr->heaviestQuark();
2067  // Special case: for B_c either bbar or c decays.
2068  if (idNow == 541 && heaviestQuark(prod[2]) == -5) hQ = 4;
2069  typeA = (hQ > 0) ? 1 + (hQ-1)%2 : -1 - (1-hQ)%2;
2070  }
2071  typeB = (prod[0] > 0) ? 1 + (prod[0]-1)%2 : -1 - (1-prod[0])%2;
2072  typeC = (prod[1] > 0) ? 1 + (prod[1]-1)%2 : -1 - (1-prod[1])%2;
2073  // Special cases.
2074  if ( (idNow == 130 || idNow == 310) && typeC * typeA < 0)
2075  typeA = -typeA;
2076  if (mult == 3 && idNow == 2112 && prod[2] == 2212)
2077  typeA = 3 - typeA;
2078  if (mult == 3 && idNow == 3222 && prod[2] == 3122)
2079  typeA = 3 - typeA;
2080  if (mult > 2 && typeC == typeA && typeB * typeC < 0
2081  && (typeB + typeC)%2 != 0) useME22 = true;
2082  if ( meMode == 22 && !useME22 ) correctME = false;
2083  if ( meMode != 22 && useME22 ) correctME = false;
2084  }
2085 
2086  // Check for matrix element mode 31.
2087  if (meMode == 31) {
2088  int nGamma = 0;
2089  for (int j = 0; j < mult; ++j) if (prod[j] == 22) ++nGamma;
2090  if (nGamma != 1) correctME = false;
2091  }
2092 
2093  // Check for unknown mode, or resonance-only mode.
2094  if ( !isResonanceNow && (meMode < 0 || (meMode > 2 && meMode <= 10)
2095  || (meMode > 13 && meMode <= 20) || (meMode > 23 && meMode <= 30)
2096  || (meMode > 31 && meMode <= 41) || meMode == 51 || meMode == 61
2097  || meMode == 71 || (meMode > 80 && meMode <= 90)
2098  || (!particlePtr->isOctetHadron() && meMode > 92) ) )
2099  correctME = false;
2100 
2101  // Print if incorrect matrix element mode.
2102  if ( !correctME ) {
2103  cout << " Warning: meMode " << meMode << " used for "
2104  << idNow << " -> ";
2105  for (int j = 0; j < mult; ++j) cout << prod[j] << " ";
2106  cout << "\n";
2107  hasPrinted = true;
2108  ++nErr;
2109  }
2110 
2111  // Warning printout when no phase space for decay.
2112  if ( studyCloser && verbosity > 0 && canHandle && onMode > 0
2113  && particlePtr->m0Min() - minFinalMass < 0. ) {
2114  if (particlePtr->m0Max() - minFinalMass < 0.)
2115  cout << " Error: decay never possible for ";
2116  else cout << " Warning: decay sometimes not possible for ";
2117  cout << idNow << " -> ";
2118  for (int j = 0; j < mult; ++j) cout << prod[j] << " ";
2119  cout << "\n";
2120  hasPrinted = true;
2121  ++nErr;
2122  }
2123 
2124  // End loop over decay channels.
2125  if (onMode > 0 && bRatio > 0.) openChannel = true;
2126  }
2127 
2128  // Optional printout of threshold.
2129  if (verbosity%10 > 1 && particlePtr->useBreitWigner()) {
2130  threshMass /= bRatioSum;
2131  cout << " Info: particle " << idNow << fixed << setprecision(5)
2132  << " has average mass threshold " << threshMass
2133  << " while mMin is " << mMinNow << "\n";
2134  hasPrinted = true;
2135  }
2136 
2137  // Error printout when no acceptable decay channels found.
2138  if (studyCloser && !openChannel) {
2139  cout << " Error: no acceptable decay channel found for particle "
2140  << idNow << "\n";
2141  hasPrinted = true;
2142  ++nErr;
2143  }
2144 
2145  // Warning printout when branching ratios do not sum to unity.
2146  if (studyCloser && (!hasAntiNow || (!hasPosBR && !hasNegBR))
2147  && abs(bRatioSum + bRatioPos - 1.) > 1e-8) {
2148  cout << " Warning: particle " << idNow << fixed << setprecision(8)
2149  << " has branching ratio sum " << bRatioSum << "\n";
2150  hasPrinted = true;
2151  ++nErr;
2152  } else if (studyCloser && hasAntiNow
2153  && (abs(bRatioSum + bRatioPos - 1.) > 1e-8
2154  || abs(bRatioSum + bRatioNeg - 1.) > 1e-8)) {
2155  cout << " Warning: particle " << idNow << fixed << setprecision(8)
2156  << " has branching ratio sum " << bRatioSum + bRatioPos
2157  << " while its antiparticle has " << bRatioSum + bRatioNeg
2158  << "\n";
2159  hasPrinted = true;
2160  ++nErr;
2161  }
2162 
2163  // End study of decay channels and loop over particles.
2164  }
2165  if (hasPrinted) cout << "\n";
2166  }
2167 
2168  // Final output. Done.
2169  cout << " Total number of errors and warnings is " << nErr << "\n";
2170  cout << "\n -------- End PYTHIA Check of Particle Data Table --------"
2171  << "------\n" << endl;
2172 
2173 }
2174 
2175 //--------------------------------------------------------------------------
2176 
2177 // Return the id of the sequentially next particle stored in table.
2178 
2179 int ParticleData::nextId(int idIn) {
2180 
2181  // Return 0 for negative or unknown codes. Return first for 0.
2182  if (idIn < 0 || (idIn > 0 && !isParticle(idIn))) return 0;
2183  if (idIn == 0) return pdt.begin()->first;
2184 
2185  // Find pointer to current particle and step up. Return 0 if impossible.
2186  map<int, ParticleDataEntry>::const_iterator pdtIn = pdt.find(idIn);
2187  if (pdtIn == pdt.end()) return 0;
2188  ++pdtIn;
2189  if (pdtIn == pdt.end()) return 0;
2190  return pdtIn->first;
2191 
2192 }
2193 
2194 //--------------------------------------------------------------------------
2195 
2196 // Fractional width associated with open channels of one or two resonances.
2197 
2198 double ParticleData::resOpenFrac(int id1In, int id2In, int id3In) {
2199 
2200  // Default value.
2201  double answer = 1.;
2202 
2203  // First resonance.
2204  if ( ParticleDataEntry* ptr = findParticle(id1In) )
2205  answer = ptr->resOpenFrac(id1In);
2206 
2207  // Possibly second resonance.
2208  if ( ParticleDataEntry* ptr = findParticle(id2In) )
2209  answer *= ptr->resOpenFrac(id2In);
2210 
2211  // Possibly third resonance.
2212  if ( ParticleDataEntry* ptr = findParticle(id3In) )
2213  answer *= ptr->resOpenFrac(id3In);
2214 
2215  // Done.
2216  return answer;
2217 
2218 }
2219 
2220 //--------------------------------------------------------------------------
2221 
2222 // Extract XML value string following XML attribute.
2223 
2224 string ParticleData::attributeValue(string line, string attribute) {
2225 
2226  if (line.find(attribute) == string::npos) return "";
2227  int iBegAttri = line.find(attribute);
2228  int iBegQuote = line.find("\"", iBegAttri + 1);
2229  int iEndQuote = line.find("\"", iBegQuote + 1);
2230  return line.substr(iBegQuote + 1, iEndQuote - iBegQuote - 1);
2231 
2232 }
2233 
2234 //--------------------------------------------------------------------------
2235 
2236 // Extract XML bool value following XML attribute.
2237 
2238 bool ParticleData::boolAttributeValue(string line, string attribute) {
2239 
2240  string valString = attributeValue(line, attribute);
2241  if (valString == "") return false;
2242  return boolString(valString);
2243 
2244 }
2245 
2246 //--------------------------------------------------------------------------
2247 
2248 // Extract XML int value following XML attribute.
2249 
2250 int ParticleData::intAttributeValue(string line, string attribute) {
2251  string valString = attributeValue(line, attribute);
2252  if (valString == "") return 0;
2253  istringstream valStream(valString);
2254  int intVal;
2255  valStream >> intVal;
2256  return intVal;
2257 
2258 }
2259 
2260 //--------------------------------------------------------------------------
2261 
2262 // Extract XML double value following XML attribute.
2263 
2264 double ParticleData::doubleAttributeValue(string line, string attribute) {
2265  string valString = attributeValue(line, attribute);
2266  if (valString == "") return 0.;
2267  istringstream valStream(valString);
2268  double doubleVal;
2269  valStream >> doubleVal;
2270  return doubleVal;
2271 
2272 }
2273 
2274 //==========================================================================
2275 
2276 } // end namespace Pythia8