StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VinciaCommon.h
1 // VinciaCommon.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Peter Skands, Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // This file contains global constants for the Vincia antenna shower as
7 // well as various auxiliary classes used by the Vincia shower model.
8 
9 #ifndef Pythia8_VinciaCommon_H
10 #define Pythia8_VinciaCommon_H
11 
12 // Maths headers.
13 #include <limits>
14 
15 // Include Pythia 8 headers.
16 #include "Pythia8/Event.h"
17 #include "Pythia8/Info.h"
18 #include "Pythia8/ParticleData.h"
19 #include "Pythia8/PartonSystems.h"
20 #include "Pythia8/PythiaStdlib.h"
21 #include "Pythia8/StandardModel.h"
22 
23 //==========================================================================
24 
25 // Global Vincia constants, defined to live in a Vincia-specific
26 // namespace to avoid clashes.
27 namespace Vincia {
28 
29 // Global numerical precision target (should be kept within a
30 // reasonable margin of machine precision). Large values may result
31 // in strange results due to non-zero terms being artificially forced
32 // to zero.
33 const double TINY = 1.0e-9;
34 const double TINYMASS = 1.0e-6;
35 const double SMALL = 1.0e-3;
36 
37 // Color factors in Vincia normalization.
38 const double CA = 3.0;
39 const double CF = 8.0/3.0;
40 const double TR = 1.0;
41 const double NC = 3.0;
42 
43 // Indices of FF antenna functions.
44 const int iQQemitFF = 0;
45 const int iQGemitFF = 1;
46 const int iGQemitFF = 2;
47 const int iGGemitFF = 3;
48 const int iGXsplitFF = 4;
49 
50 // Indices of RF antenna functions.
51 const int iQQemitRF = 5;
52 const int iQGemitRF = 6;
53 const int iXGsplitRF = 7;
54 
55 // Indices of II antenna functions.
56 const int iQQemitII = 0;
57 const int iGQemitII = 1;
58 const int iGGemitII = 2;
59 const int iQXsplitII = 3;
60 const int iGXconvII = 4;
61 
62 // Indices of IF antenna functions.
63 const int iQQemitIF = 5;
64 const int iQGemitIF = 6;
65 const int iGQemitIF = 7;
66 const int iGGemitIF = 8;
67 const int iQXsplitIF = 9;
68 const int iGXconvIF = 10;
69 const int iXGsplitIF = 11;
70 
71 // Mathematical constants (Euler–Mascheroni constant).
72 const double gammaE = 0.577215664901532860606512090082402431042;
73 
74 // Verbosity levels.
75 // Suppressed verbosity.
76 const int silent = 0;
77 const int quiet = 1;
78 // Normal verbosity for warnings.
79 const int normal = 2;
80 // Extra verbosity for warnings.
81 const int quiteloud = 3;
82 const int loud = 4;
83 const int veryloud = 5;
84 // Debug verbosity levels.
85 const int debug = 6;
86 const int louddebug = 7;
87 const int verylouddebug = 8;
88 const int superdebug = 9;
89 
90 }
91 
92 // Everything else lives in the Pythia 8 namespace.
93 
94 namespace Pythia8 {
95 
96 // Include namespace with global Vincia constants.
97 using namespace Vincia;
98 
99 //==========================================================================
100 
101 // Convenient typedef for unsigned integers.
102 
103 typedef unsigned int uint;
104 
105 //==========================================================================
106 
107 // Print a method name using the appropritae pre-processor macro.
108 
109 // The following method was modified from
110 // boost/current_function.hpp - BOOST_CURRENT_FUNCTION
111 //
112 // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
113 //
114 // Distributed under the Boost Software License, Version 1.0.
115 // Boost Software License - Version 1.0 - August 17th, 2003
116 //
117 // Permission is hereby granted, free of charge, to any person or
118 // organization obtaining a copy of the software and accompanying
119 // documentation covered by this license (the "Software") to use,
120 // reproduce, display, distribute, execute, and transmit the
121 // Software, and to prepare derivative works of the Software, and to
122 // permit third-parties to whom the Software is furnished to do so,
123 // all subject to the following:
124 //
125 // The copyright notices in the Software and this entire statement,
126 // including the above license grant, this restriction and the
127 // following disclaimer, must be included in all copies of the
128 // Software, in whole or in part, and all derivative works of the
129 // Software, unless such copies or derivative works are solely in the
130 // form of machine-executable object code generated by a source
131 // language processor.
132 //
133 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
134 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
135 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
136 // NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
137 // ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR
138 // OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING
139 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
140 // OTHER DEALINGS IN THE SOFTWARE.
141 //
142 // http://www.boost.org/libs/utility/current_function.html
143 //
144 // Note that Boost Software License - Version 1.0 is fully compatible
145 // with GPLV2
146 // For more information see https://www.gnu.org/licenses/license-list.en.html
147 
148 #ifndef __METHOD_NAME__
149 
150 #ifndef VINCIA_FUNCTION
151 #if ( defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) \
152 || (defined(__ICC) && (__ICC >= 600)) )
153 # define VINCIA_FUNCTION __PRETTY_FUNCTION__
154 #elif defined(__DMC__) && (__DMC__ >= 0x810)
155 # define VINCIA_FUNCTION __PRETTY_FUNCTION__
156 #elif defined(__FUNCSIG__)
157 # define VINCIA_FUNCTION __FUNCSIG__
158 #elif ( (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) \
159 || (defined(__IBMCPP__) && (__IBMCPP__ >= 500)) )
160 # define VINCIA_FUNCTION __FUNCTION__
161 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
162 # define VINCIA_FUNCTION __FUNC__
163 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
164 # define VINCIA_FUNCTION __func__
165 #else
166 # define VINCIA_FUNCTION "unknown"
167 #endif
168 #endif // end VINCIA_FUNCTION
169 
170 inline std::string methodName(const std::string& prettyFunction) {
171  size_t colons = prettyFunction.find("::");
172  size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
173  size_t end = prettyFunction.rfind("(") - begin;
174  return prettyFunction.substr(begin,end) + "()";
175 
176 }
177 
178 #define __METHOD_NAME__ methodName(VINCIA_FUNCTION)
179 #endif // end __METHOD_NAME__
180 
181 //==========================================================================
182 
183 // Functors are required to use zbrent for the rescaling variable
184 // needed in the massive Rambo version.
185 
186 // Pure virtual function overloading operator().
187 class TFunctor {
188 
189 public:
190  virtual double operator()(double) = 0;
191  virtual ~TFunctor() {}
192 
193 };
194 
195 // Functor for xi-solution in Rambo.
196 class TXiFunctor : public TFunctor {
197 
198 public:
199 
200  // Constructor takes a vector with the masses and one with the energies.
201  TXiFunctor(vector<double> mIn, vector<double> energiesIn);
202  double operator() (double);
203 
204 private:
205  vector<double> m;
206  vector<double> energies;
207 
208 };
209 
210 // Derive a class which can wrap function pointers.
211 class TPtrFunctor : public TFunctor {
212 
213 public:
214  TPtrFunctor(double (*fPtrIn)(double) ){ fPtr = fPtrIn; };
215  double operator() (double arg) { return fPtr(arg); };
216 
217 private:
218 
219  // Pointer to a function taking one double and returning one double.
220  double (*fPtr)(double);
221 
222 };
223 
224 //==========================================================================
225 
226 // Global functions accessible in the Vincia namespace.
227 
228 // Utilities for printing out VINCIA Messages.
229 void printOut(string,string);
230 
231 // String utilities.
232 string num2str(int,int width=4) ;
233 string num2str(double,int width=9) ;
234 string bool2str(bool, int width=3) ;
235 
236 // Search and replace a string.
237 inline string replaceString(string subject, const string& search,
238  const string& replace) {
239  string::size_type pos = 0;
240  while ((pos = subject.find(search, pos)) != string::npos) {
241  subject.replace(pos, search.length(), replace);
242  pos += replace.length();
243  }
244  return subject;
245 
246 }
247 
248 // Remove ":" and "/" from a file name.
249 inline string sanitizeFileName(string fileName) {
250  map<string, string> rep;
251  rep["/"] = "_div_";
252  rep[":"] = "_colon_";
253  string retVal = fileName;
254  for (map<string, string>::const_iterator it = rep.begin(); it != rep.end();
255  ++it) {
256  retVal = replaceString(retVal, it->first, it->second);
257  }
258  return retVal;
259 
260 }
261 
262 // Utility for checking if a file exists.
263 inline bool fileExists(const std::string& name) {
264  if (FILE *file = fopen(name.c_str(), "r")) {
265  fclose(file);
266  return true;
267  } else {
268  return false;
269  }
270 
271 }
272 
273 // A few useful auxiliary functions like extra invariants and dot products.
274 double m (const Vec4&);
275 double m2 (const Vec4&);
276 double m2 (const Vec4&, const Vec4&, const Vec4&);
277 double m2 (const Vec4&, const Vec4&, const Vec4&, const Vec4&);
278 double m2 (const Particle&, const Particle&, const Particle&);
279 double dot4 (const Particle&, const Particle&);
280 double getCosTheta(double E1, double E2, double m1, double m2, double s12);
281 
282 // Gram determinant, invariants used in the argument = 2*pi*pj.
283 double gramDet(double s01tilde, double s12tilde, double s02tilde,
284  double m0, double m1, double m2);
285 double gramDet(Vec4 p0, Vec4 p1, Vec4 p2);
286 
287 // Math support functions.
288 double Li2 (const double,const double kmax = 100.0,
289  const double xerr = Vincia::TINY);
290 double factorial(const int);
291 int binomial (const int,int);
292 double LambertW (const double x);
293 
294 // Zero-finder zbrent with Functor (used by massive Rambo). Note,
295 // does not work if the reference to TFunctor is declared const.
296 double zbrent(TFunctor&, double, double, double, double);
297 
298 //==========================================================================
299 
300 // Rambo flat phase-space generator.
301 
302 // This is an implementation of the Rambo phase-space generator as
303 // presented in A New Monte Carlo Treatment Of Multiparticle Phase
304 // Space At High-Energies, R. Kleiss, W.J. Stirling, S.D. Ellis, CPC40
305 // (1986) 359.
306 
307 class Rambo {
308 
309  public:
310 
311  // Deafult constructor.
312  Rambo() { rndmPtr=nullptr; isInitPtr=false;}
313 
314  // Initializing constructor.
315  Rambo(Rndm* rndmPtrIn) { initPtr(rndmPtrIn); }
316 
317  // Destructor.
318  virtual ~Rambo() {}
319 
320  // Initialize pointers.
321  void initPtr(Rndm* rndmPtrIn) {rndmPtr = rndmPtrIn; isInitPtr = true;}
322 
323  // Rambo phase space generator. Generates nOut uniformly distributed
324  // massless 4-vectors with sqrt(s) = eCM. Output in pOut.
325  double genPoint(double eCM,int nOut,vector<Vec4>& pOut);
326 
327  // Massive generalisation, weights NOT 1 anymore - literal implementation
328  // of original RAMBO paper by Ellis, Kleiss and Stirling. Number of particles
329  // determined from size of mIn vector.
330  double genPoint(double eCM,vector<double> mIn,vector<Vec4>& pOut);
331 
332  private:
333 
334  // Is initialized.
335  bool isInitPtr;
336 
337  // Pointer to the random number generator.
338  Rndm* rndmPtr;
339 
340 };
341 
342 //==========================================================================
343 
344 // A class to store and process colour information, e.g. colour maps,
345 // reconnections, etc.
346 
347 class Colour {
348 
349 public:
350 
351  // Constructor.
352 
353  Colour() {isInitPtr=false; isInit=false;}
354 
355  // Destructor.
356  ~Colour() {}
357 
358  // Initialize pointers (must be done before init).
359  void initPtr(Info* infoPtrIn) {
360  infoPtr = infoPtrIn;
361  particleDataPtr = infoPtr->particleDataPtr;
362  settingsPtr = infoPtr->settingsPtr;
363  partonSystemsPtr = infoPtr->partonSystemsPtr;
364  rndmPtr = infoPtr->rndmPtr;
365  isInitPtr=true;
366  }
367 
368  // Initialize.
369  bool init();
370 
371  // Get translation map from ordinary Les Houches tags to antenna
372  // indices (tags always ending on [1-9] with gluons having
373  // non-identical colour and anticolour indices).
374  bool colourise(int iSys, Event& event);
375 
376  // Method to sort list of partons in Vincia colour order. Returns
377  // vector<int> with indices in following order:
378  // (1) colourless incoming particles
379  // (2) triplet-ngluon-antitriplet contractions
380  // (3) ngluon rings
381  // (4) colourless outgoing particles
382  // No specific order is imposed on the relative ordering inside each
383  // of the four classes.
384  vector<int> colourSort(vector<Particle*>);
385 
386  // Method to create LC colour map and list of LC antennae.
387  void makeColourMaps(const int iSysIn, const Event& event,
388  map<int,int>& indexOfAcol, map<int,int>& indexOfCol,
389  vector< pair<int,int> >& antLC, const bool findFF, const bool findIX);
390 
391  // Determine whether 01 or 12 inherit the colour tag from a parent.
392  bool inherit01(double s01, double s12);
393 
394  // Set verbose level.
395  void setVerbose(int verboseIn) {verbose = verboseIn;};
396 
397 private:
398 
399  // Internal parameters.
400  int inheritMode;
401 
402  // Is initialized.
403  bool isInitPtr, isInit;
404 
405  // Pointers to PYTHIA 8 objects.
406  Info* infoPtr;
407  ParticleData* particleDataPtr;
408  Settings* settingsPtr;
409  PartonSystems* partonSystemsPtr;
410  Rndm* rndmPtr;
411 
412  // Verbose level.
413  int verbose;
414 
415 };
416 
417 //==========================================================================
418 
419 // A simple class for containing evolution variable definitions.
420 
421 class Resolution {
422 
423 public:
424 
425  // Constructor.
426  Resolution() = default;
427 
428  // Destructor.
429  virtual ~Resolution() {};
430 
431  // Initialize pointers (must be done before init).
432  void initPtr(Settings* settingsPtrIn) {
433  settingsPtr = settingsPtrIn;
434  isInitPtr = true;
435  }
436 
437  // Initialize.
438  bool init();
439 
440  // Sector resolution functions.
441  double q2sector2to3(const Particle* a, const Particle* b, const Particle* j,
442  bool = false);
443 
444  // Sector resolution function for 3->4 branchings (currently only
445  // used for gluon splitting, with m2qq as the measure).
446  double q2sector3to4(const Particle*, const Particle*,
447  const Particle* j1, const Particle* j2);
448 
449  // Sector resolution function for 2->4 branchings (double emission).
450  // Assume j1 and j2 are colour connected, with a and b hard
451  // recoilers.
452  double q2sector2to4(const Particle* a, const Particle* b,
453  const Particle* j1, const Particle* j2);
454 
455  // Sector resolution function for 3->5 branchings (emission +
456  // splitting).
457  double q2sector3to5(Particle* a, Particle* b,
458  Particle* j1, Particle* j2, Particle* j3);
459 
460  // Sector accept function. Optionally prevent g->qq clusterings if
461  // that would reduce the number of fermion lines below some minimum
462  // (cheap way to indicate that Z->qq/ll always has at least one
463  // fermion pair).
464  double findSector(vector<int>& iSec, vector<Particle> state, int nFmin = 1);
465 
466  // Set verbosity level.
467  void setVerbose(int verboseIn) {verbose = verboseIn;}
468 
469 private:
470 
471  // Initialized.
472  bool isInitPtr{false}, isInit{false};
473 
474  // Pointer to PYTHIA 8 settings database.
475  Settings* settingsPtr{};
476 
477  // Number of flavours to be treated as massless.
478  int nFlavZeroMassSav{};
479 
480  // Verbosity level.
481  int verbose{};
482 
483 };
484 
485 //==========================================================================
486 
487 // Class which contains functions and variables shared by the
488 // VinciaShower and VinciaMatching classes.
489 
491 
492 public:
493 
494  // Constructor.
495  VinciaCommon() {isInitPtr = false; isInit = false;}
496 
497  // Destructor.
498  virtual ~VinciaCommon() {}
499 
500  // Initialize pointers.
501  bool initPtr(Info* infoPtrIn) {
502  infoPtr = infoPtrIn;
503  particleDataPtr = infoPtr->particleDataPtr;
504  settingsPtr = infoPtr->settingsPtr;
505  rndmPtr = infoPtr->rndmPtr;
506  isInitPtr = true;
507  return true;
508  }
509 
510  // Initialize data members.
511  bool init();
512 
513  // Function to check for the hadronization cutoff for a colour
514  // connected parton pair.
515  double mHadMin(const int id1, const int id2);
516 
517  // Function to check the event after each branching. Added by NF to
518  // see if certain Pythia warnings/error are caused by the shower.
519  bool showerChecks(Event& event, bool ISR);
520 
521  // More lightweight function to check conservation of momentum.
522  bool checkCoM(int iSys, Event& event,PartonSystems* partonSystemsPtr);
523 
524  // Function to reset counters (print once every event for now).
525  void resetCounters() {
526  nUnkownPDG = 0;
527  nIncorrectCol = 0;
528  nNAN = 0;
529  nVertex = 0;
530  nChargeCons = 0;
531  nMotDau = 0;
532  for (int i=0; i<2; i++) {
533  nUnmatchedMass[i] = 0;
534  nEPcons[i] = 0;
535  }
536  }
537 
538  // Get number of active flavors at a given Q scale.
539  int getNf(double q) {
540  if (q <= mc) return 3;
541  else if (q <= mb) return 4;
542  else if (q <= mt) return 5;
543  else return 6;
544  }
545 
546  // Get the shower starting scale.
547  double getShowerStartingScale(int iSys, PartonSystems* partonSystemsPtr,
548  const Event& event, double sbbSav);
549 
550  // 3->2 clustering maps.
551  bool map3to2FFmassive(vector<Vec4>& pClu, vector<Vec4> pIn,
552  int kMapType, int a=0, int r=1, int b=2, double mI=0.0, double mK=0.0);
553  bool map3to2FFmassless(vector<Vec4>& pClu, vector<Vec4> pIn,
554  int kMapType, int a=0, int r=1, int b=2);
555  bool map3to2IFmassive(vector<Vec4>& pClu, vector<Vec4>& pIn,
556  double saj, double sjk, double sak);
557  bool map3to2IImassive(vector<Vec4>& pClu, vector<Vec4>& pIn,
558  vector<Vec4>& pRec, double saj, double sjb, double sab, bool doBoost);
559 
560  // 2->3 kinematics maps for FF branchings. Original implementations;
561  // massless by Skands, massive by Ritzmann.
562  bool map2to3FF(vector<Vec4>& pNew, const vector<Vec4>& pOld, int kMapType,
563  const vector<double>& invariants, double phi, vector<double> masses) {
564  if ( masses.size() <= 2 || ( masses[0] == 0.0 && masses[1] == 0.0
565  && masses[2] == 0.0 )) {
566  return map2to3FFmassless(pNew, pOld, kMapType, invariants, phi);
567  } else {
568  return map2to3FFmassive(pNew, pOld, kMapType, invariants, phi, masses);
569  }
570  }
571  bool map2to3FFmassive(vector<Vec4>& pNew, const vector<Vec4>& pOld,
572  int kMapType, const vector<double>& invariants, double phi,
573  vector<double> masses);
574  bool map2to3FFmassless(vector<Vec4>& pNew, const vector<Vec4>& pOld,
575  int kMapType, const vector<double>& invariants, double phi);
576 
577  // 2->3 kinematics maps for II branchings. Original implementations:
578  // massless by Fischer, massive by Verheyen.
579  bool map2to3II(vector<Vec4>& pNew, vector<Vec4>& pRec,
580  vector<Vec4>& pOld, double sAB, double saj, double sjb, double sab,
581  double phi, double m2j = 0.0);
582  bool map2to3IImassless(vector<Vec4>& pNew, vector<Vec4>& pRec,
583  vector<Vec4>& pOld, double sAB, double saj, double sjb, double sab,
584  double phi);
585 
586  // 2->3 kinematics maps for IF branchings. General massive case
587  // implemented by Verheyen.
588  bool map2to3IFlocal(vector<Vec4>& pNew, vector<Vec4>& pOld,
589  double sOldAK, double saj, double sjk, double sak, double phi,
590  double m2oldK, double m2j, double m2k);
591  bool map2to3IFglobal(vector<Vec4>& pNew, vector<Vec4>& pRec,
592  vector<Vec4>& pOld, Vec4 &pB,
593  double sAK, double saj, double sjk, double sak, double phi,
594  double mK2, double mj2, double mk2);
595 
596  // Resonance decay kinematic maps.
597  bool map2to3RFmassive(vector<Vec4>& pThree, vector<Vec4> pTwo,
598  vector<double> invariants,double phi,
599  vector<double> masses);
600  bool map2toNRFmassive(vector<Vec4>& pAfter, vector<Vec4> pBefore,
601  unsigned int posR, unsigned int posF,
602  vector<double> invariants,double phi,
603  vector<double> masses);
604 
605  // 2->3 kinematics map for RF branchings. Original implementation by Brooks.
606  bool map2to3RFmassive(vector<Vec4>& pNew, vector<Vec4>& pRec,
607  vector<Vec4> pOld, double saj, double sjk, double phi,
608  double m2oldA, double m2j, double m2oldK);
609 
610  // Check if 2-particle system is on-shell and rescale if not.
611  bool onShellCM(Vec4& p1, Vec4& p2, double m1, double m2, double tol = 1e-6);
612 
613  // Force initial-state and light-flavour partons to be massless.
614  bool mapToMassless(int iSys, Event& event, PartonSystems* partonSystemsPtr,
615  bool makeNewCopies);
616 
617  // Map a massless antenna to equivalent massive one. Boolean
618  // returns true if a modification was made.
619  bool mapToMassive(Vec4& p1, Vec4& p2, double m1, double m2) {
620  return (!onShellCM(p1,p2,m1,m2,1e-9));
621  }
622 
623  // Get/set verbose parameter.
624  int getVerbose() {return verbose; };
625  void setVerbose(int verboseIn) { verbose = verboseIn;};
626 
627  // Public data members: strong coupling in MSbar and CMW schemes,
628  // user and default choices,
629  AlphaStrong alphaStrong, alphaStrongCMW, alphaStrongDef, alphaStrongDefCMW;
630 
631  // Couplings for use in merging.
632  AlphaStrong alphaS;
633  AlphaEM alphaEM;
634  double mu2freeze, mu2min, alphaSmax;
635 
636  // Quark masses.
637  double ms, mc, mb, mt;
638  int nFlavZeroMass;
639 
640  // Checks.
641  double epTolErr, epTolWarn, mTolErr, mTolWarn;
642 
643 private:
644 
645  // Pointers.
646  Info* infoPtr;
647  Settings* settingsPtr;
648  ParticleData* particleDataPtr;
649  Rndm* rndmPtr;
650 
651  // Counter for output control.
652  int nUnkownPDG, nIncorrectCol, nNAN, nVertex, nChargeCons, nMotDau;
653  vector<int> nUnmatchedMass, nEPcons;
654 
655  // Internal flags and settings.
656  bool isInitPtr, isInit;
657  int verbose;
658 
659 };
660 
661 //==========================================================================
662 
663 } // end namespace Pythia8
664 
665 #endif // Pythia8_VinciaCommon_H