PYTHIA  8.315
FragmentationFlavZpT.h
1 // FragmentationFlavZpT.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2025 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 helper classes for fragmentation.
7 // StringFlav is used to select quark and hadron flavours.
8 // StringPT is used to select transverse momenta.
9 // StringZ is used to sample the fragmentation function f(z).
10 
11 #ifndef Pythia8_FragmentationFlavZpT_H
12 #define Pythia8_FragmentationFlavZpT_H
13 
14 #include "Pythia8/Basics.h"
15 #include "Pythia8/MathTools.h"
16 #include "Pythia8/ParticleData.h"
17 #include "Pythia8/PhysicsBase.h"
18 #include "Pythia8/PythiaStdlib.h"
19 #include "Pythia8/Settings.h"
20 
21 namespace Pythia8 {
22 
23 //==========================================================================
24 
25 // The FlavContainer class is a simple container for flavour,
26 // including the extra properties needed for popcorn baryon handling.
27 // id = current flavour.
28 // rank = current rank; 0 for endpoint flavour and then increase by 1.
29 // nPop = number of popcorn mesons yet to be produced (1 or 0).
30 // idPop = (absolute sign of) popcorn quark, shared between B and Bbar.
31 // idVtx = (absolute sign of) vertex (= non-shared) quark in diquark.
32 
34 
35 public:
36 
37  // Constructor.
38  FlavContainer(int idIn = 0, int rankIn = 0, int nPopIn = 0,
39  int idPopIn = 0, int idVtxIn = 0) : id(idIn), rank(rankIn),
40  nPop(nPopIn), idPop(idPopIn), idVtx(idVtxIn) {}
41 
42  // Copy constructor.
44  id = flav.id; rank = flav.rank; nPop = flav.nPop; idPop = flav.idPop;
45  idVtx = flav.idVtx;}
46 
47  // Overloaded equal operator.
48  FlavContainer& operator=(const FlavContainer& flav) { if (this != &flav) {
49  id = flav.id; rank = flav.rank; nPop = flav.nPop; idPop = flav.idPop;
50  idVtx = flav.idVtx; } return *this; }
51 
52  // Invert flavour.
53  FlavContainer& anti() {id = -id; return *this;}
54 
55  // Read in a container into another, without/with id sign flip.
56  FlavContainer& copy(const FlavContainer& flav) { if (this != &flav) {
57  id = flav.id; rank = flav.rank; nPop = flav.nPop; idPop = flav.idPop;
58  idVtx = flav.idVtx; } return *this; }
59  FlavContainer& anti(const FlavContainer& flav) { if (this != &flav) {
60  id = -flav.id; rank = flav.rank; nPop = flav.nPop; idPop = flav.idPop;
61  idVtx = flav.idVtx; } return *this; }
62 
63  // Check whether is diquark.
64  bool isDiquark() {int idAbs = abs(id);
65  return (idAbs > 1000 && idAbs < 10000 && (idAbs/10)%10 == 0);}
66 
67  // Stored properties.
68  int id, rank, nPop, idPop, idVtx;
69 
70 };
71 
72 //==========================================================================
73 
74 // The StringFlav class is used to select quark and hadron flavours.
75 
76 class StringFlav : public PhysicsBase {
77 
78 public:
79 
80  // Constructor.
82  suppressLeadingB(),
83  mT2suppression(), useWidthPre(), probQQtoQ(), probStoUD(), probSQtoQQ(),
84  probQQ1toQQ0(), probQandQQ(), probQandS(), probQandSinQQ(), probQQ1corr(),
85  probQQ1corrInv(), probQQ1norm(), probQQ1join(), mesonRate(),
86  mesonRateSum(), mesonMix1(), mesonMix2(), etaSup(), etaPrimeSup(),
87  decupletSup(), baryonCGSum(), baryonCGMax(), popcornRate(), popcornSpair(),
88  popcornSmeson(), barCGMax(), scbBM(), popFrac(), popS(), dWT(),
89  lightLeadingBSup(), heavyLeadingBSup(), probStoUDSav(), probQQtoQSav(),
90  probSQtoQQSav(), probQQ1toQQ0Sav(), alphaQQSav(), sigmaHad(),
91  widthPreStrange(), widthPreDiquark(), thermalModel(), mesonNonetL1(),
92  temperature(), tempPreFactor(), nNewQuark(), mesMixRate1(), mesMixRate2(),
93  mesMixRate3(), baryonOctWeight(), baryonDecWeight(), closePacking(),
94  doEnhanceDiquark(), enhanceStrange(), enhancePT(), enhanceDiquark(),
95  exponentMPI(), exponentNSP(), hadronIDwin(0), idNewWin(0),
96  hadronMassWin(-1.0) {}
97 
98  // Destructor.
99  virtual ~StringFlav() {}
100 
101  // Initialize data members.
102  virtual void init();
103 
104  // Initialise parameters when using close packing.
105  virtual void init(double kappaModifier, double strangeJunc,
106  double probQQmod);
107 
108  // Pick a light d, u or s quark according to fixed ratios.
109  int pickLightQ() { double rndmFlav = probQandS * rndmPtr->flat();
110  if (rndmFlav < 1.) return 1;
111  if (rndmFlav < 2.) return 2;
112  return 3; }
113 
114  // Pick a new flavour (including diquarks) given an incoming one,
115  // either by old standard Gaussian or new alternative exponential.
116  virtual FlavContainer pick(FlavContainer& flavOld, double pT = -1.0,
117  double kappaModifier = -1.0, bool allowPop = true) {
118  hadronIDwin = 0; idNewWin = 0; hadronMassWin = -1.0;
119  if ( (thermalModel || mT2suppression) && (pT >= 0.0) )
120  return pickThermal(flavOld, pT, kappaModifier);
121  return pickGauss(flavOld, allowPop); }
122  virtual FlavContainer pickGauss(FlavContainer& flavOld,
123  bool allowPop = true);
124  virtual FlavContainer pickThermal(FlavContainer& flavOld,
125  double pT, double kappaModifier);
126 
127  // Combine two flavours (including diquarks) to produce a hadron.
128  virtual int combine(FlavContainer& flav1, FlavContainer& flav2);
129 
130  // Ditto, simplified input argument for simple configurations.
131  virtual int combineId( int id1, int id2, bool keepTrying = true) {
132  FlavContainer flag1(id1); FlavContainer flag2(id2);
133  for (int i = 0; i < 100; ++i) { int idNew = combine( flag1, flag2);
134  if (idNew != 0 || !keepTrying) return idNew;} return 0;}
135 
136  // Combine three (di-) quark flavours into two hadrons.
137  virtual pair<int,int> combineDiquarkJunction(int id1, int id2, int id3);
138 
139  // Combine two flavours to produce a hadron with lowest possible mass.
140  virtual int combineToLightest( int id1, int id2);
141 
142  // Lightest flavour-neutral meson.
143  virtual int idLightestNeutralMeson() { return 111; }
144 
145  // Return chosen hadron in case of thermal model.
146  virtual int getHadronIDwin() { return hadronIDwin; }
147 
148  // Combine two flavours into hadron for last two remaining flavours
149  // for thermal model.
150  virtual int combineLastThermal(FlavContainer& flav1, FlavContainer& flav2,
151  double pT, double kappaModifier);
152 
153  // General function, decides whether to just return the hadron id
154  // if thermal model was use or whether to combine the two flavours.
155  virtual int getHadronID(FlavContainer& flav1, FlavContainer& flav2,
156  double pT = -1.0, double kappaModifier = -1.0, bool finalTwo = false) {
157  if (finalTwo) return ((thermalModel || mT2suppression) ?
158  combineLastThermal(flav1, flav2, pT, kappaModifier)
159  : combine(flav1, flav2));
160  if ((thermalModel || mT2suppression)&& (hadronIDwin != 0)
161  && (idNewWin != 0)) return getHadronIDwin();
162  return combine(flav1, flav2); }
163 
164  // Return hadron mass. Used one if present, pick otherwise.
165  virtual double getHadronMassWin(int idHad) { return
166  ((hadronMassWin < 0.0) ? particleDataPtr->mSel(idHad) : hadronMassWin); }
167 
168  // Assign popcorn quark inside an original (= rank 0) diquark.
169  void assignPopQ(FlavContainer& flav);
170 
171  // Combine two quarks to produce a diquark.
172  int makeDiquark(int id1, int id2, int idHad = 0);
173 
174  // Check if quark-diquark combination should be added. If so add.
175  void addQuarkDiquark(vector< pair<int,int> >& quarkCombis,
176  int qID, int diqID, int hadronID) {
177  bool allowed = true;
178  for (int iCombi = 0; iCombi < int(quarkCombis.size()); iCombi++)
179  if ( (qID == quarkCombis[iCombi].first ) &&
180  (diqID == quarkCombis[iCombi].second) ) allowed = false;
181  if (allowed) quarkCombis.push_back( (hadronID > 0) ?
182  make_pair( qID, diqID) : make_pair(-qID, -diqID) ); }
183 
184  // Get spin counter for mesons.
185  int getMesonSpinCounter(int hadronID) { hadronID = abs(hadronID);
186  int j = (hadronID % 10);
187  if (hadronID < 1000) return ((j==1) ? 0 : ( (j==3) ? 1 : 5 ));
188  if (hadronID < 20000) return ((j==1) ? 3 : 2);
189  if (hadronID > 20000) return 4;
190  return -1; }
191 
192  // Get the flavour and spin ratios calculated from the diquark weights.
193  // i: (0) q -> B B, (1) q -> B M B, (2) qq -> M B
194  // j: (0) s/u popcorn ratio, (1/2) s/u ratio for vertex quark if popcorn
195  // quark is u/d or s, (3) q/q' vertex quark ratio if popcorn quark is
196  // light and = q, (4/5/6) (spin 1)/(spin 0) ratio for su, us and ud
197  double getFlavourSpinRatios(int i, int j) {
198  return (i < 3 && j < 7) ? dWT[i][j] : -1.0;}
199 
200 protected:
201 
202  // Initialise derived parameters.
203  virtual void initDerived();
204 
205  // Constants: could only be changed in the code itself.
206  static const int mesonMultipletCode[6];
207  static const double baryonCGOct[6], baryonCGDec[6];
208 
209  // Settings for Gaussian model.
210  bool suppressLeadingB, mT2suppression, useWidthPre;
211  double probQQtoQ, probStoUD, probSQtoQQ, probQQ1toQQ0, probQandQQ,
212  probQandS, probQandSinQQ, probQQ1corr, probQQ1corrInv, probQQ1norm,
213  probQQ1join[4], mesonRate[4][6], mesonRateSum[4], mesonMix1[2][6],
214  mesonMix2[2][6], etaSup, etaPrimeSup, decupletSup, baryonCGSum[6],
215  baryonCGMax[6], popcornRate, popcornSpair, popcornSmeson, barCGMax[8],
216  scbBM[3], popFrac, popS[3], dWT[3][7], lightLeadingBSup,
217  heavyLeadingBSup;
218  bool qqKappa;
219  double probStoUDSav, probQQtoQSav, probSQtoQQSav, probQQ1toQQ0Sav,
220  alphaQQSav, sigmaHad, widthPreStrange, widthPreDiquark;
221 
222  // Settings for thermal model.
223  bool thermalModel, mesonNonetL1;
224  double temperature, tempPreFactor;
225  int nNewQuark;
226  double mesMixRate1[2][6], mesMixRate2[2][6], mesMixRate3[2][6];
227  double baryonOctWeight[6][6][6][2], baryonDecWeight[6][6][6][2];
228 
229  // Settings used by both models.
230  bool closePacking, doEnhanceDiquark;
231  double enhanceStrange, enhancePT, enhanceDiquark, exponentMPI, exponentNSP;
232 
233  // Key = hadron id, value = list of constituent ids.
234  map< int, vector< pair<int,int> > > hadronConstIDs;
235  // Key = initial (di)quark id, value = list of possible hadron ids
236  // + nr in hadronConstIDs.
237  map< int, vector< pair<int,int> > > possibleHadrons;
238  // Key = initial (di)quark id, value = prefactor to multiply rate.
239  map< int, vector<double> > possibleRatePrefacs;
240  // Similar, but for combining the last two (di)quarks. Key = (di)quark pair.
241  map< pair<int,int>, vector< pair<int,int> > > possibleHadronsLast;
242  map< pair<int,int>, vector<double> > possibleRatePrefacsLast;
243 
244  // Selection in thermal model.
245  int hadronIDwin, idNewWin;
246  double hadronMassWin;
247 
248  // Fragmentation weights container.
250 
251 };
252 
253 //==========================================================================
254 
255 // Functions for unnormalised, <z>, and RMSD(z) of Lund FF. The two latter
256 // return negative values in case of failure.
257 
258 double LundFFRaw(double z, double a, double b, double c, double mT2);
259 
260 double LundFFAvg(double a, double b, double mT2, double tol);
261 
262 double LundFFRms(double a, double b, double mT2, double tol);
263 
264 //==========================================================================
265 
266 // The StringZ class is used to sample the fragmentation function f(z).
267 
268 class StringZ : public PhysicsBase {
269 
270 public:
271 
272  // Constructor.
273  StringZ() : useNonStandC(), useNonStandB(), useNonStandH(), usePetersonC(),
274  usePetersonB(), usePetersonH(), useOldAExtra(), mc2(), mb2(),
275  aLund(), bLund(), aExtraSQuark(), aExtraDiquark(), rFactC(),
276  rFactB(), rFactH(), aNonC(), aNonB(), aNonH(), bNonC(), bNonB(),
277  bNonH(), epsilonC(), epsilonB(), epsilonH(), stopM(), stopNF(),
278  stopS() {}
279 
280  // Destructor.
281  virtual ~StringZ() {}
282 
283  // Initialize data members.
284  virtual bool init();
285 
286  // Fragmentation function: top-level to determine parameters.
287  virtual double zFrag( int idOld, int idNew = 0, double mT2 = 1.);
288 
289  // Fragmentation function: select z according to provided parameters.
290  virtual double zLund( double a, double b, double c = 1.,
291  double head = 1., double bNow = 0., int idFrag = 0,
292  bool isOldSQuark = false, bool isNewSQuark = false,
293  bool isOldDiquark = false, bool isNewDiquark = false);
294  virtual double zPeterson( double epsilon);
295  virtual double zLundMax( double a, double b, double c = 1.);
296 
297  // Parameters for stopping in the middle; overloaded for Hidden Valley.
298  virtual double stopMass() {return stopM;}
299  virtual double stopNewFlav() {return stopNF;}
300  virtual double stopSmear() {return stopS;}
301 
302  // a and b fragmentation parameters needed in some operations.
303  virtual double aAreaLund() {return aLund;}
304  virtual double bAreaLund() {return bLund;}
305 
306  // Method to derive both a and b parameters (from <z> and RMSD(z)).
307  bool deriveABLund( bool derivaA = false, bool deriveAExtraDiquark = false,
308  bool deriveAExtraSQuark = false);
309  // Method to derive bLund from <z> (for fixed a and reference mT2).
310  double deriveBLund( double avgZ, double a, double mT2ref);
311 
312  protected:
313 
314  // Constants: could only be changed in the code itself.
315  static const double CFROMUNITY, AFROMZERO, AFROMC, EXPMAX;
316 
317  // Initialization data, to be read from Settings.
318  bool useNonStandC, useNonStandB, useNonStandH,
319  usePetersonC, usePetersonB, usePetersonH, useOldAExtra;
320  double mc2, mb2, aLund, bLund, aExtraSQuark, aExtraDiquark, rFactC,
321  rFactB, rFactH, aNonC, aNonB, aNonH, bNonC, bNonB, bNonH,
322  epsilonC, epsilonB, epsilonH, stopM, stopNF, stopS;
323 
324  // Fragmentation weights container.
326 
327 };
328 
329 //==========================================================================
330 
331 // The StringPT class is used to select select transverse momenta.
332 
333 class StringPT : public PhysicsBase {
334 
335 public:
336 
337  // Constructor.
338  StringPT() : useWidthPre(), sigmaQ(), enhancedFraction(), enhancedWidth(),
339  sigma2Had(), widthPreStrange(), widthPreDiquark(),
340  thermalModel(), temperature(), tempPreFactor(), fracSmallX(),
341  closePacking(), enhancePT(), exponentMPI(), exponentNSP() {}
342 
343  // Destructor.
344  virtual ~StringPT() {}
345 
346  // Initialize data members.
347  virtual void init();
348 
349  // General function, return px and py as a pair in the same call
350  // in either model.
351  pair<double, double> pxy(int idIn, double kappaModifier = -1.0) {
352  return (thermalModel ? pxyThermal(idIn, kappaModifier) :
353  pxyGauss(idIn, kappaModifier)); }
354  pair<double, double> pxyGauss(int idIn = 0, double kappaModifier = -1.0);
355  pair<double, double> pxyThermal(int idIn, double kappaModifier = -1.0);
356 
357  // Gaussian suppression of given pT2; used in MiniStringFragmentation.
358  double suppressPT2(double pT2) { return (thermalModel ?
359  exp(-sqrt(pT2)/temperature) : exp(-pT2/sigma2Had)); }
360 
361 protected:
362 
363  // Constants: could only be changed in the code itself.
364  static const double SIGMAMIN;
365 
366  // Initialization data, to be read from Settings.
367  // Gaussian model.
369  double sigmaQ, enhancedFraction, enhancedWidth, sigma2Had,
370  widthPreStrange, widthPreDiquark;
371  // Thermal model.
373  double temperature, tempPreFactor, fracSmallX;
374  // Both.
376  double enhancePT, exponentMPI, exponentNSP;
377 
378 private:
379 
380  // Evaluate Bessel function K_{1/4}(x).
381  double BesselK14(double x);
382 
383  // Fragmentation weights container.
384  WeightsFragmentation* wgtsPtr{};
385 
386 };
387 
388 //==========================================================================
389 
390 } // end namespace Pythia8
391 
392 #endif // Pythia8_FragmentationFlavZpT_H
int hadronIDwin
Selection in thermal model.
Definition: FragmentationFlavZpT.h:245
pair< double, double > pxy(int idIn, double kappaModifier=-1.0)
Definition: FragmentationFlavZpT.h:351
double LundFFRms(double a, double b, double mT2, double tol)
Definition: FragmentationFlavZpT.cc:1491
FlavContainer & operator=(const FlavContainer &flav)
Overloaded equal operator.
Definition: FragmentationFlavZpT.h:48
virtual double aAreaLund()
a and b fragmentation parameters needed in some operations.
Definition: FragmentationFlavZpT.h:303
Definition: PhysicsBase.h:23
virtual double getHadronMassWin(int idHad)
Return hadron mass. Used one if present, pick otherwise.
Definition: FragmentationFlavZpT.h:165
int getMesonSpinCounter(int hadronID)
Get spin counter for mesons.
Definition: FragmentationFlavZpT.h:185
map< int, vector< pair< int, int > > > possibleHadrons
Definition: FragmentationFlavZpT.h:237
static const double SIGMAMIN
Constants: could only be changed in the code itself.
Definition: FragmentationFlavZpT.h:364
bool thermalModel
Settings for thermal model.
Definition: FragmentationFlavZpT.h:223
The StringPT class is used to select select transverse momenta.
Definition: FragmentationFlavZpT.h:333
virtual ~StringPT()
Destructor.
Definition: FragmentationFlavZpT.h:344
double LundFFAvg(double a, double b, double mT2, double tol)
Definition: FragmentationFlavZpT.cc:1457
bool thermalModel
Thermal model.
Definition: FragmentationFlavZpT.h:372
bool isDiquark()
Check whether is diquark.
Definition: FragmentationFlavZpT.h:64
Wave4 epsilon(Wave4 w1, Wave4 w2, Wave4 w3)
Permutation operator.
Definition: HelicityBasics.cc:56
virtual ~StringZ()
Destructor.
Definition: FragmentationFlavZpT.h:281
virtual ~StringFlav()
Destructor.
Definition: FragmentationFlavZpT.h:99
void addQuarkDiquark(vector< pair< int, int > > &quarkCombis, int qID, int diqID, int hadronID)
Check if quark-diquark combination should be added. If so add.
Definition: FragmentationFlavZpT.h:175
virtual int getHadronID(FlavContainer &flav1, FlavContainer &flav2, double pT=-1.0, double kappaModifier=-1.0, bool finalTwo=false)
Definition: FragmentationFlavZpT.h:155
The StringZ class is used to sample the fragmentation function f(z).
Definition: FragmentationFlavZpT.h:268
FlavContainer & anti()
Invert flavour.
Definition: FragmentationFlavZpT.h:53
FlavContainer(int idIn=0, int rankIn=0, int nPopIn=0, int idPopIn=0, int idVtxIn=0)
Constructor.
Definition: FragmentationFlavZpT.h:38
int id
Stored properties.
Definition: FragmentationFlavZpT.h:68
double getFlavourSpinRatios(int i, int j)
Definition: FragmentationFlavZpT.h:197
bool suppressLeadingB
Settings for Gaussian model.
Definition: FragmentationFlavZpT.h:210
bool useWidthPre
Definition: FragmentationFlavZpT.h:368
virtual int combineId(int id1, int id2, bool keepTrying=true)
Ditto, simplified input argument for simple configurations.
Definition: FragmentationFlavZpT.h:131
double suppressPT2(double pT2)
Gaussian suppression of given pT2; used in MiniStringFragmentation.
Definition: FragmentationFlavZpT.h:358
FlavContainer & copy(const FlavContainer &flav)
Read in a container into another, without/with id sign flip.
Definition: FragmentationFlavZpT.h:56
virtual int idLightestNeutralMeson()
Lightest flavour-neutral meson.
Definition: FragmentationFlavZpT.h:143
FlavContainer(const FlavContainer &flav)
Copy constructor.
Definition: FragmentationFlavZpT.h:43
double LundFFRaw(double z, double a, double b, double c, double mT2)
Functions for the Lund symmetric FF: unnormalised, average, and RMSD.
Definition: FragmentationFlavZpT.cc:1442
StringZ()
Constructor.
Definition: FragmentationFlavZpT.h:273
map< int, vector< pair< int, int > > > hadronConstIDs
Key = hadron id, value = list of constituent ids.
Definition: FragmentationFlavZpT.h:234
virtual double stopMass()
Parameters for stopping in the middle; overloaded for Hidden Valley.
Definition: FragmentationFlavZpT.h:298
Definition: FragmentationFlavZpT.h:33
Definition: Weights.h:354
map< pair< int, int >, vector< pair< int, int > > > possibleHadronsLast
Similar, but for combining the last two (di)quarks. Key = (di)quark pair.
Definition: FragmentationFlavZpT.h:241
static const double EXPMAX
Do not take exponent of too large or small number.
Definition: FragmentationFlavZpT.h:315
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
bool closePacking
Both.
Definition: FragmentationFlavZpT.h:375
The StringFlav class is used to select quark and hadron flavours.
Definition: FragmentationFlavZpT.h:76
virtual FlavContainer pick(FlavContainer &flavOld, double pT=-1.0, double kappaModifier=-1.0, bool allowPop=true)
Definition: FragmentationFlavZpT.h:116
bool closePacking
Settings used by both models.
Definition: FragmentationFlavZpT.h:230
bool useNonStandC
Initialization data, to be read from Settings.
Definition: FragmentationFlavZpT.h:318
int pickLightQ()
Pick a light d, u or s quark according to fixed ratios.
Definition: FragmentationFlavZpT.h:109
StringPT()
Constructor.
Definition: FragmentationFlavZpT.h:338
StringFlav()
Constructor.
Definition: FragmentationFlavZpT.h:81
map< int, vector< double > > possibleRatePrefacs
Key = initial (di)quark id, value = prefactor to multiply rate.
Definition: FragmentationFlavZpT.h:239
virtual int getHadronIDwin()
Return chosen hadron in case of thermal model.
Definition: FragmentationFlavZpT.h:146