PYTHIA  8.312
ColourReconnection.h
1 // ColourReconnection.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2024 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // Header file for the Colour reconnection handling.
7 // Reconnect the colours between the partons before hadronization.
8 // It Contains the following classes:
9 // ColourDipole, ColourParticle, ColourJunction, ColourReconnection.
10 
11 #ifndef Pythia8_ColourReconnection_H
12 #define Pythia8_ColourReconnection_H
13 
14 #include "Pythia8/Basics.h"
15 #include "Pythia8/BeamParticle.h"
16 #include "Pythia8/Event.h"
17 #include "Pythia8/FragmentationFlavZpT.h"
18 #include "Pythia8/Info.h"
19 #include "Pythia8/ParticleData.h"
20 #include "Pythia8/StringFragmentation.h"
21 #include "Pythia8/PartonDistributions.h"
22 #include "Pythia8/PartonSystems.h"
23 #include "Pythia8/PythiaStdlib.h"
24 #include "Pythia8/Settings.h"
25 #include "Pythia8/StringLength.h"
26 #include "Pythia8/StringInteractions.h"
27 
28 namespace Pythia8 {
29 
30 //==========================================================================
31 
32 // Contain a single colour chain. It always start from a quark and goes to
33 // an anti quark or from an anti-junction to at junction
34 // (or possible combinations).
35 
36 class ColourDipole {
37 
38 public:
39 
40  // Constructor.
41  ColourDipole( int colIn = 0, int iColIn = 0, int iAcolIn = 0,
42  int colReconnectionIn = 0, bool isJunIn = false, bool isAntiJunIn = false,
43  bool isActiveIn = true, bool isRealIn = false) : col(colIn), iCol(iColIn),
44  iAcol(iAcolIn), colReconnection(colReconnectionIn), isJun(isJunIn),
45  isAntiJun(isAntiJunIn),isActive(isActiveIn), isReal(isRealIn)
46  {iColLeg = 0; iAcolLeg = 0; printed = false; p1p2 = 0.;}
47 
48  double mDip(Event & event) {
49  if (isJun || isAntiJun) return 1E9;
50  else return m(event[iCol].p(),event[iAcol].p());
51  }
52 
53  // Members.
54  int col, iCol, iAcol, iColLeg, iAcolLeg, colReconnection;
55  bool isJun, isAntiJun, isActive, isReal, printed;
56  weak_ptr<ColourDipole> leftDip{}, rightDip{};
57  vector<weak_ptr<ColourDipole> > colDips, acolDips;
58  double p1p2;
59 
60  // Information for caching dipole momentum.
62  int ciCol{-1}, ciAcol{-1};
63  bool pCalculated{false};
64 
65  // Printing function, mainly intended for debugging.
66  void list() const;
67  long index{0};
68 
69 };
70 
71 // Comparison operator by index for two dipole pointers.
72 inline bool operator<(const ColourDipolePtr& d1, const ColourDipolePtr& d2) {
73  return ( d1 && d2 ? d1->index < d2->index : !d1 );}
74 
75 //==========================================================================
76 
77 // Junction class. In addition to the normal junction class, also contains a
78 // list of dipoles connected to it.
79 
80 class ColourJunction : public Junction {
81 
82 public:
83 
84  ColourJunction(const Junction& ju) : Junction(ju), dips(), dipsOrig() { }
85 
86  ColourJunction(const ColourJunction& ju) : Junction(Junction(ju)), dips(),
87  dipsOrig() { for(int i = 0;i < 3;++i) {
88  dips[i] = ju.dips[i]; dipsOrig[i] = ju.dipsOrig[i];}
89  }
90  ColourJunction& operator=( const ColourJunction& ju) {
91  this->Junction::operator=(ju);
92  for(int i = 0;i < 3;++i) {
93  dips[i] = ju.dips[i]; dipsOrig[i] = ju.dipsOrig[i];
94  }
95  return (*this);
96  }
97 
98  ColourDipolePtr getColDip(int i) {return dips[i];}
99  void setColDip(int i, ColourDipolePtr dip) {dips[i] = dip;}
100  ColourDipolePtr dips[3];
101  ColourDipolePtr dipsOrig[3];
102  void list() const;
103 
104 };
105 
106 //==========================================================================
107 
108 // TrialReconnection class.
109 
110 //--------------------------------------------------------------------------
111 
113 
114 public:
115 
116  TrialReconnection(ColourDipolePtr dip1In = 0, ColourDipolePtr dip2In = 0,
117  ColourDipolePtr dip3In = 0, ColourDipolePtr dip4In = 0, int modeIn = 0,
118  double lambdaDiffIn = 0) {
119  dips.push_back(dip1In); dips.push_back(dip2In);
120  dips.push_back(dip3In); dips.push_back(dip4In);
121  mode = modeIn; lambdaDiff = lambdaDiffIn;
122  }
123 
124  void list() {
125  cout << "mode: " << mode << " " << "lambdaDiff: " << lambdaDiff << endl;
126  for (int i = 0;i < int(dips.size()) && dips[i] != 0;++i) {
127  cout << " "; dips[i]->list(); }
128  }
129 
130  vector<ColourDipolePtr> dips;
131  int mode;
132  double lambdaDiff;
133 
134 };
135 
136 //==========================================================================
137 
138 // ColourParticle class.
139 
140 //--------------------------------------------------------------------------
141 
142 class ColourParticle : public Particle {
143 
144 public:
145 
146  ColourParticle(const Particle& ju) : Particle(ju), isJun(), junKind() {}
147 
148  vector<vector<ColourDipolePtr> > dips;
149  vector<bool> colEndIncluded, acolEndIncluded;
150  vector<ColourDipolePtr> activeDips;
151  bool isJun;
152  int junKind;
153 
154  // Printing functions, intended for debugging.
155  void listParticle();
156  void listActiveDips();
157  void listDips();
158 
159 };
160 
161 //==========================================================================
162 
163 // The ColourReconnection class handles the colour reconnection.
164 
165 //--------------------------------------------------------------------------
166 
168 
169 public:
170 
171  // Constructor
172  ColourReconnection() : allowJunctions(), sameNeighbourCol(),
173  singleReconOnly(), lowerLambdaOnly(), allowDiqJunCR(), nSys(),
174  nReconCols(), swap1(), swap2(), reconnectMode(), flipMode(),
175  timeDilationMode(), eCM(), sCM(), pT0(), pT20Rec(), pT0Ref(), ecmRef(),
176  ecmPow(), reconnectRange(), m0(), mPseudo(), m2Lambda(), fracGluon(),
177  dLambdaCut(), timeDilationPar(), timeDilationParGeV(), tfrag(), blowR(),
178  blowT(), rHadron(), kI(), dipMaxDist(), nColMove() {}
179 
180  // Initialization.
181  bool init();
182 
183  // New beams possible for handling of hard diffraction.
184  void reassignBeamPtrs( BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn)
185  {beamAPtr = beamAPtrIn; beamBPtr = beamBPtrIn;}
186 
187  // Do colour reconnection for current event.
188  bool next( Event & event, int oldSize);
189 
190 private:
191 
192  // Constants: could only be changed in the code itself.
193  static const double MINIMUMGAIN, MINIMUMGAINJUN, TINYP1P2;
194  static const int MAXRECONNECTIONS;
195 
196  // Variables needed.
197  bool allowJunctions, sameNeighbourCol, singleReconOnly, lowerLambdaOnly;
198  bool allowDiqJunCR;
199  int nSys, nReconCols, swap1, swap2, reconnectMode, flipMode,
200  timeDilationMode;
201  double eCM, sCM, pT0, pT20Rec, pT0Ref, ecmRef, ecmPow, reconnectRange,
202  m0, mPseudo, m2Lambda, fracGluon, dLambdaCut, timeDilationPar,
203  timeDilationParGeV, tfrag, blowR, blowT, rHadron, kI;
204  double dipMaxDist;
205 
206  // List of current dipoles.
207  vector<ColourDipolePtr> dipoles, usedDipoles;
208 
209  // Last used dipole index, used for sorting.
210  int dipoleIndex{0};
211 
212  // Add a dipole and increment index.
213  void addDipole(int colIn = 0, int iColIn = 0, int iAcolIn = 0,
214  int colReconnectionIn = 0, bool isJunIn = false, bool isAntiJunIn = false,
215  bool isActiveIn = true, bool isRealIn = false) {
216  dipoles.push_back(make_shared<ColourDipole>(colIn, iColIn, iAcolIn,
217  colReconnectionIn, isJunIn, isAntiJunIn, isActiveIn, isRealIn));
218  dipoles.back()->index = ++dipoleIndex;
219  }
220 
221  // Add a dipole and increment index.
222  void addDipole(const ColourDipole& dipole) {
223  dipoles.push_back(make_shared<ColourDipole>(dipole));
224  dipoles.back()->index = ++dipoleIndex;
225  }
226 
227  // Lists of particles, junctions and trials.
228  vector<ColourJunction> junctions;
229  vector<ColourParticle> particles;
230  vector<TrialReconnection> junTrials, dipTrials;
231  vector<vector<int> > iColJun;
232  vector<double> formationTimes;
233 
234  // This is only to access the function call junctionRestFrame.
235  StringFragmentation stringFragmentation;
236 
237  // This class is used to calculate the string length.
238  StringLength stringLength;
239 
240  // Do colour reconnection for the event using the new model.
241  bool nextNew( Event & event, int oldSize);
242 
243  // Simple test swap between two dipoles.
244  void swapDipoles(ColourDipolePtr& dip1, ColourDipolePtr& dip2,
245  bool back = false);
246 
247  // Setup the dipoles.
248  void setupDipoles( Event& event, int iFirst = 0);
249 
250  // Form pseuparticle of a given dipole (or junction system).
251  void makePseudoParticle(ColourDipolePtr& dip, int status,
252  bool setupDone = false);
253 
254  // Find the indices in the particle list of the junction and also their
255  // respectively leg numbers.
256  bool getJunctionIndices(const ColourDipolePtr& dip, int &iJun, int &i0,
257  int &i1, int &i2, int &junLeg0, int &junLeg1, int &junLeg2) const;
258 
259  // Form all possible pseudoparticles.
260  void makeAllPseudoParticles(Event & event, int iFirst = 0);
261 
262  // Update all colours in the event.
263  void updateEvent( Event& event, int iFirst = 0);
264 
265  double calculateStringLength( const ColourDipolePtr& dip,
266  vector<ColourDipolePtr> & dips);
267 
268  // Calculate the string length for two event indices.
269  double calculateStringLength( int i, int j) const;
270 
271  // Calculate the length of a single junction
272  // given the 3 entries in the particle list.
273  double calculateJunctionLength(const int i, const int j, const int k) const;
274 
275  // Calculate the length of a double junction,
276  // given the 4 entries in the particle record.
277  // First two are expected to be the quarks and second two the anti quarks.
278  double calculateDoubleJunctionLength( const int i, const int j, const int k,
279  const int l) const;
280 
281  // Find all the particles connected in the junction.
282  // If a single junction, the size of iParticles should be 3.
283  // For multiple junction structures, the size will increase.
284  bool findJunctionParticles( int iJun, vector<int>& iParticles,
285  vector<bool> &usedJuns, int &nJuns, vector<ColourDipolePtr> &dips);
286 
287  // Do a single trial reconnection.
288  void singleReconnection( ColourDipolePtr& dip1, ColourDipolePtr& dip2);
289 
290  // Do a single trial reconnection to form a junction.
291  void singleJunction(ColourDipolePtr& dip1, ColourDipolePtr& dip2);
292 
293  // Do a single trial reconnection to form a junction.
294  void singleJunction(const ColourDipolePtr& dip1, const ColourDipolePtr& dip2,
295  const ColourDipolePtr& dip3);
296 
297  // Print the chain containing the dipole.
298  void listChain(ColourDipolePtr& dip);
299 
300  // Print all the chains.
301  void listAllChains();
302 
303  // Print dipoles, intended for debuggning purposes.
304  void listDipoles( bool onlyActive = false, bool onlyReal = false) const;
305 
306  // Print particles, intended for debugging purposes.
307  void listParticles() const;
308 
309  // Print junctions, intended for debugging purposes.
310  void listJunctions() const;
311 
312  // Check that the current dipole setup is consistent. Debug purpose only.
313  void checkDipoles();
314 
315  // Check that the current dipole setup is consistent. Debug purpose only.
316  void checkRealDipoles(Event& event, int iFirst);
317 
318  // Calculate the invariant mass of a dipole.
319  double mDip(const ColourDipolePtr& dip) const;
320 
321  // Find a vertex of the (anti)-colour side of the dipole. If
322  // connected to a junction, recurse using the other junction
323  // dipoles.
324  Vec4 getVProd(const ColourDipolePtr& dip, bool anti) const;
325 
326  // Find an average vertex of the (anti)-colour sides of the dipoles
327  // connected to the given junction (not incuding the given dipole).
328  Vec4 getVProd(int iJun, const ColourDipolePtr& dip, bool anti) const;
329 
330  // Check that the distance between the impact parameter centers of
331  // the dipoles are within the allowed range of dipMaxDist.
332  bool checkDist(const ColourDipolePtr& dip1, const ColourDipolePtr& dip2)
333  const;
334 
335  // Find the neighbour to anti colour side. Return false if the dipole is
336  // connected to a junction or the new particle has a junction inside of it.
337  bool findAntiNeighbour(ColourDipolePtr& dip);
338 
339  // Find the neighbour to colour side. Return false if the dipole is
340  // connected to a junction or the new particle has a junction inside of it.
341  bool findColNeighbour(ColourDipolePtr& dip);
342 
343  // Check that trials do not contain junctions / unusable pseudoparticles.
344  bool checkJunctionTrials();
345 
346  // Store all dipoles connected to the ones used in the junction connection.
347  void storeUsedDips(TrialReconnection& trial);
348 
349  // Change colour structure to describe the reconnection in juncTrial.
350  bool doJunctionTrial(Event& event, TrialReconnection& juncTrial);
351 
352  // Change colour structure to describe the reconnection in juncTrial.
353  void doDipoleTrial(TrialReconnection& trial);
354 
355  // Change colour structure if it is three dipoles forming a junction system.
356  bool doTripleJunctionTrial(Event& event, TrialReconnection& juncTrial);
357 
358  // Calculate the difference between the old and new lambda.
359  double getLambdaDiff(const ColourDipolePtr& dip1,
360  const ColourDipolePtr& dip2, const ColourDipolePtr& dip3,
361  const ColourDipolePtr& dip4, const int mode) const;
362 
363  // Calculate the difference between the old and new lambda (dipole swap).
364  double getLambdaDiff(ColourDipolePtr& dip1, ColourDipolePtr& dip2);
365 
366  // Update the list of dipole trial swaps to account for latest swap.
367  void updateDipoleTrials();
368 
369  // Update the list of dipole trial swaps to account for latest swap.
370  void updateJunctionTrials();
371 
372  // Check whether up to four dipoles are 'causally' connected.
373  bool checkTimeDilation(const ColourDipolePtr& dip1 = 0,
374  const ColourDipolePtr& dip2 = 0, const ColourDipolePtr& dip3 = 0,
375  const ColourDipolePtr& dip4 = 0) const;
376 
377  // Check whether two four momenta are casually connected.
378  bool checkTimeDilation(const Vec4& p1, const Vec4& p2, const double t1,
379  const double t2) const;
380 
381  // Find the momentum of the dipole.
382  Vec4 getDipoleMomentum(const ColourDipolePtr& dip) const;
383 
384  // Find all particles connected to a junction system (particle list).
385  void addJunctionIndices(const int iSinglePar, set<int> &iPar,
386  set<int> &usedJuncs) const;
387 
388  // Find all the formation times.
389  void setupFormationTimes( Event & event);
390 
391  // Get the mass of all partons connected to a junction system (event list).
392  double getJunctionMass(Event & event, int col);
393 
394  // Find all particles connected to a junction system (event list).
395  void addJunctionIndices(const Event & event, const int iSinglePar,
396  set<int> &iPar, set<int> &usedJuncs) const;
397 
398  // The old MPI-based scheme.
399  bool reconnectMPIs( Event& event, int oldSize);
400 
401  // Vectors and methods needed for the new gluon-move model.
402 
403  // Array of (indices of) all final coloured particles.
404  vector<int> iReduceCol, iExpandCol;
405 
406  // Array of all lambda distances between coloured partons.
407  int nColMove;
408  vector<double> lambdaijMove;
409 
410  // Function to return lambda value from array.
411  double lambda12Move( int i, int j) {
412  int iAC = iReduceCol[i]; int jAC = iReduceCol[j];
413  return lambdaijMove[nColMove * min( iAC, jAC) + max( iAC, jAC)];
414  }
415 
416  // Function to return lambda(i,j) + lambda(i,k) - lambda(j,k).
417  double lambda123Move( int i, int j, int k) {
418  int iAC = iReduceCol[i]; int jAC = iReduceCol[j]; int kAC = iReduceCol[k];
419  return lambdaijMove[nColMove * min( iAC, jAC) + max( iAC, jAC)]
420  + lambdaijMove[nColMove * min( iAC, kAC) + max( iAC, kAC)]
421  - lambdaijMove[nColMove * min( jAC, kAC) + max( jAC, kAC)];
422  }
423 
424  // The new gluon-move scheme.
425  bool reconnectMove( Event& event, int oldSize);
426 
427  // The common part for both Type I and II reconnections in e+e..
428  bool reconnectTypeCommon( Event& event, int oldSize);
429 
430  // The e+e- type I CR model.
431  map<double,pair<int,int> > reconnectTypeI( Event& event,
432  vector<vector<ColourDipole> > &dips, Vec4 decays[2]);
433  // bool reconnectTypeI( Event& event, int oldSize);
434 
435  // The e+e- type II CR model.
436  map<double,pair<int,int> > reconnectTypeII( Event& event,
437  vector<vector<ColourDipole> > &dips, Vec4 decays[2]);
438  // bool reconnectTypeII( Event& event, int oldSize);
439 
440  // calculate the determinant of 3 * 3 matrix.
441  double determinant3(vector<vector< double> >& vec);
442 };
443 
444 //==========================================================================
445 
446 } // end namespace Pythia8
447 
448 #endif // Pythia8_ColourReconnection_H
void list() const
Printing function, mainly intended for debugging.
Definition: ColourReconnection.cc:38
Definition: ColourReconnection.h:36
TrialReconnection class.
Definition: ColourReconnection.h:112
The Event class holds all info on the generated event.
Definition: Event.h:453
Definition: BeamParticle.h:133
void reassignBeamPtrs(BeamParticle *beamAPtrIn, BeamParticle *beamBPtrIn)
New beams possible for handling of hard diffraction.
Definition: ColourReconnection.h:184
Definition: Event.h:338
Definition: StringFragmentation.h:119
int col
Members.
Definition: ColourReconnection.h:54
Definition: StringInteractions.h:78
ColourDipole(int colIn=0, int iColIn=0, int iAcolIn=0, int colReconnectionIn=0, bool isJunIn=false, bool isAntiJunIn=false, bool isActiveIn=true, bool isRealIn=false)
Constructor.
Definition: ColourReconnection.h:41
StringLength class. It is used to calculate the lambda measure.
Definition: StringLength.h:23
Pythia8::Vec4 dipoleMomentum
Information for caching dipole momentum.
Definition: ColourReconnection.h:61
ColourParticle class.
Definition: ColourReconnection.h:142
Definition: Event.h:32
Definition: ColourReconnection.h:80
The ColourReconnection class handles the colour reconnection.
Definition: ColourReconnection.h:167
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
double m(const Vec4 &v1)
Invariant mass and its square.
Definition: Basics.cc:595
Definition: Basics.h:32
bool operator<(const ColourDipolePtr &d1, const ColourDipolePtr &d2)
Comparison operator by index for two dipole pointers.
Definition: ColourReconnection.h:72
ColourReconnection()
Constructor.
Definition: ColourReconnection.h:172