StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ColourReconnection.h
1 // ColourReconnection.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // Header file for the 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  {leftDip = 0; rightDip = 0; iColLeg = 0; iAcolLeg = 0; printed = false;
47  p1p2 = 0.;}
48 
49  double mDip(Event & event) {
50  if (isJun || isAntiJun) return 1E9;
51  else return m(event[iCol].p(),event[iAcol].p());
52  }
53 
54  // Members.
55  int col, iCol, iAcol, iColLeg, iAcolLeg, colReconnection;
56  bool isJun, isAntiJun, isActive, isReal, printed;
57  ColourDipole *leftDip, *rightDip;
58  vector<ColourDipole *> colDips, acolDips;
59  double p1p2;
60 
61  // Printing function, mainly intended for debugging.
62  void list();
63 
64 };
65 
66 //==========================================================================
67 
68 // Junction class. In addition to the normal junction class, also contains a
69 // list of dipoles connected to it.
70 
71 class ColourJunction : public Junction {
72 
73 public:
74 
75  ColourJunction(const Junction& ju) : Junction(ju), dips(), dipsOrig() { }
76 
77  ColourJunction(const ColourJunction& ju) : Junction(Junction(ju)), dips(),
78  dipsOrig() { for(int i = 0;i < 3;++i) {
79  dips[i] = ju.dips[i]; dipsOrig[i] = ju.dipsOrig[i];}
80  }
81  ColourJunction& operator=( const ColourJunction& ju) {
82  this->Junction::operator=(ju);
83  for(int i = 0;i < 3;++i) {
84  dips[i] = ju.dips[i]; dipsOrig[i] = ju.dipsOrig[i];
85  }
86  return (*this);
87  }
88 
89  ColourDipole * getColDip(int i) {return dips[i];}
90  void setColDip(int i, ColourDipole * dip) {dips[i] = dip;}
91  ColourDipole * dips[3];
92  ColourDipole * dipsOrig[3];
93  void list();
94 
95 };
96 
97 //==========================================================================
98 
99 // TrialReconnection class.
100 
101 //--------------------------------------------------------------------------
102 
103 class TrialReconnection {
104 
105 public:
106 
107  TrialReconnection(ColourDipole* dip1In = 0, ColourDipole* dip2In = 0,
108  ColourDipole* dip3In = 0, ColourDipole* dip4In = 0, int modeIn = 0,
109  double lambdaDiffIn = 0) {
110  dips.push_back(dip1In); dips.push_back(dip2In);
111  dips.push_back(dip3In); dips.push_back(dip4In);
112  mode = modeIn; lambdaDiff = lambdaDiffIn;
113  }
114 
115  void list() {
116  cout << "mode: " << mode << " " << "lambdaDiff: " << lambdaDiff << endl;
117  for (int i = 0;i < int(dips.size()) && dips[i] != 0;++i) {
118  cout << " "; dips[i]->list(); }
119  }
120 
121  vector<ColourDipole*> dips;
122  int mode;
123  double lambdaDiff;
124 
125 };
126 
127 //==========================================================================
128 
129 // ColourParticle class.
130 
131 //--------------------------------------------------------------------------
132 
133 class ColourParticle : public Particle {
134 
135 public:
136 
137  ColourParticle(const Particle& ju) : Particle(ju), isJun(), junKind() {}
138 
139  vector<vector<ColourDipole *> > dips;
140  vector<bool> colEndIncluded, acolEndIncluded;
141  vector<ColourDipole *> activeDips;
142  bool isJun;
143  int junKind;
144 
145  // Printing functions, intended for debugging.
146  void listParticle();
147  void listActiveDips();
148  void listDips();
149 
150 };
151 
152 //==========================================================================
153 
154 // The ColourReconnection class handles the colour reconnection.
155 
156 //--------------------------------------------------------------------------
157 
158 class ColourReconnection : public ColourReconnectionBase {
159 
160 public:
161 
162  // Constructor
163  ColourReconnection() : allowJunctions(), sameNeighbourCol(),
164  singleReconOnly(), lowerLambdaOnly(), nSys(), nReconCols(), swap1(),
165  swap2(), reconnectMode(), flipMode(), timeDilationMode(), eCM(), sCM(),
166  pT0(), pT20Rec(), pT0Ref(), ecmRef(), ecmPow(), reconnectRange(), m0(),
167  m0sqr(), m2Lambda(), fracGluon(), dLambdaCut(), timeDilationPar(),
168  timeDilationParGeV(), tfrag(), blowR(), blowT(), rHadron(), kI(),
169  nColMove() {}
170 
171  // Initialization.
172  bool init();
173 
174  // New beams possible for handling of hard diffraction.
175  void reassignBeamPtrs( BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn)
176  {beamAPtr = beamAPtrIn; beamBPtr = beamBPtrIn;}
177 
178  // Do colour reconnection for current event.
179  bool next( Event & event, int oldSize);
180 
181 private:
182 
183  // Constants: could only be changed in the code itself.
184  static const double MINIMUMGAIN, MINIMUMGAINJUN, TINYP1P2;
185  static const int MAXRECONNECTIONS;
186 
187  // Variables needed.
188  bool allowJunctions, sameNeighbourCol, singleReconOnly, lowerLambdaOnly;
189  int nSys, nReconCols, swap1, swap2, reconnectMode, flipMode,
190  timeDilationMode;
191  double eCM, sCM, pT0, pT20Rec, pT0Ref, ecmRef, ecmPow, reconnectRange,
192  m0, m0sqr, m2Lambda, fracGluon, dLambdaCut, timeDilationPar,
193  timeDilationParGeV, tfrag, blowR, blowT, rHadron, kI;
194 
195  // List of current dipoles.
196  vector<ColourDipole*> dipoles, usedDipoles;
197  vector<ColourJunction> junctions;
198  vector<ColourParticle> particles;
199  vector<TrialReconnection> junTrials, dipTrials;
200  vector<vector<int> > iColJun;
201  map<int,double> formationTimes;
202 
203  // This is only to access the function call junctionRestFrame.
204  StringFragmentation stringFragmentation;
205 
206  // This class is used to calculate the string length.
207  StringLength stringLength;
208 
209  // Do colour reconnection for the event using the new model.
210  bool nextNew( Event & event, int oldSize);
211 
212  // Simple test swap between two dipoles.
213  void swapDipoles(ColourDipole* dip1, ColourDipole* dip2, bool back = false);
214 
215  // Setup the dipoles.
216  void setupDipoles( Event& event, int iFirst = 0);
217 
218  // Form pseuparticle of a given dipole (or junction system).
219  void makePseudoParticle( ColourDipole* dip, int status,
220  bool setupDone = false);
221 
222  // Find the indices in the particle list of the junction and also their
223  // respectively leg numbers.
224  bool getJunctionIndices(ColourDipole* dip, int &iJun, int &i0, int &i1,
225  int &i2, int &junLeg0, int &junLeg1, int &junLeg2);
226 
227  // Form all possible pseudoparticles.
228  void makeAllPseudoParticles(Event & event, int iFirst = 0);
229 
230  // Update all colours in the event.
231  void updateEvent( Event& event, int iFirst = 0);
232 
233  double calculateStringLength( ColourDipole* dip,
234  vector<ColourDipole*> & dips);
235 
236  // Calculate the string length for two event indices.
237  double calculateStringLength( int i, int j);
238 
239  // Calculate the length of a single junction
240  // given the 3 entries in the particle list.
241  double calculateJunctionLength(int i, int j, int k);
242 
243  // Calculate the length of a double junction,
244  // given the 4 entries in the particle record.
245  // First two are expected to be the quarks and second two the anti quarks.
246  double calculateDoubleJunctionLength( int i, int j, int k, int l);
247 
248  // Find all the particles connected in the junction.
249  // If a single junction, the size of iParticles should be 3.
250  // For multiple junction structures, the size will increase.
251  bool findJunctionParticles( int iJun, vector<int>& iParticles,
252  vector<bool> &usedJuns, int &nJuns, vector<ColourDipole*> &dips);
253 
254  // Do a single trial reconnection.
255  void singleReconnection( ColourDipole* dip1, ColourDipole* dip2);
256 
257  // Do a single trial reconnection to form a junction.
258  void singleJunction(ColourDipole* dip1, ColourDipole* dip2);
259 
260  // Do a single trial reconnection to form a junction.
261  void singleJunction(ColourDipole* dip1, ColourDipole* dip2,
262  ColourDipole* dip3);
263 
264  // Print the chain containing the dipole.
265  void listChain(ColourDipole* dip);
266 
267  // Print all the chains.
268  void listAllChains();
269 
270  // Print dipoles, intended for debuggning purposes.
271  void listDipoles( bool onlyActive = false, bool onlyReal = false);
272 
273  // Print particles, intended for debugging purposes.
274  void listParticles();
275 
276  // Print junctions, intended for debugging purposes.
277  void listJunctions();
278 
279  // Check that the current dipole setup is consistent. Debug purpose only.
280  void checkDipoles();
281 
282  // Check that the current dipole setup is consistent. Debug purpose only.
283  void checkRealDipoles(Event& event, int iFirst);
284 
285  // Calculate the invariant mass of a dipole.
286  double mDip(ColourDipole* dip);
287 
288  // Find the neighbour to anti colour side. Return false if the dipole is
289  // connected to a junction or the new particle has a junction inside of it.
290  bool findAntiNeighbour(ColourDipole*& dip);
291 
292  // Find the neighbour to colour side. Return false if the dipole is
293  // connected to a junction or the new particle has a junction inside of it.
294  bool findColNeighbour(ColourDipole*& dip);
295 
296  // Check that trials do not contain junctions / unusable pseudoparticles.
297  bool checkJunctionTrials();
298 
299  // Store all dipoles connected to the ones used in the junction connection.
300  void storeUsedDips(TrialReconnection& trial);
301 
302  // Change colour structure to describe the reconnection in juncTrial.
303  void doJunctionTrial(Event& event, TrialReconnection& juncTrial);
304 
305  // Change colour structure to describe the reconnection in juncTrial.
306  void doDipoleTrial(TrialReconnection& trial);
307 
308  // Change colour structure if it is three dipoles forming a junction system.
309  void doTripleJunctionTrial(Event& event, TrialReconnection& juncTrial);
310 
311  // Calculate the difference between the old and new lambda.
312  double getLambdaDiff(ColourDipole* dip1,
313  ColourDipole* dip2, ColourDipole* dip3, ColourDipole* dip4, int mode);
314 
315  // Calculate the difference between the old and new lambda (dipole swap).
316  double getLambdaDiff(ColourDipole* dip1, ColourDipole* dip2);
317 
318  // Update the list of dipole trial swaps to account for latest swap.
319  void updateDipoleTrials();
320 
321  // Update the list of dipole trial swaps to account for latest swap.
322  void updateJunctionTrials();
323 
324  // Check whether up to four dipoles are 'causally' connected.
325  bool checkTimeDilation(ColourDipole* dip1 = 0, ColourDipole* dip2 = 0,
326  ColourDipole* dip3 = 0, ColourDipole* dip4 = 0);
327 
328  // Check whether two four momenta are casually connected.
329  bool checkTimeDilation(Vec4 p1, Vec4 p2, double t1, double t2);
330 
331  // Find the momentum of the dipole.
332  Vec4 getDipoleMomentum(ColourDipole* dip);
333 
334  // Find all particles connected to a junction system (particle list).
335  void addJunctionIndices(int iSinglePar, vector<int> &iPar,
336  vector<int> &usedJuncs);
337 
338  // Find all the formation times.
339  void setupFormationTimes( Event & event);
340 
341  // Get the mass of all partons connected to a junction system (event list).
342  double getJunctionMass(Event & event, int col);
343 
344  // Find all particles connected to a junction system (event list).
345  void addJunctionIndices(Event & event, int iSinglePar,
346  vector<int> &iPar, vector<int> &usedJuncs);
347 
348  // The old MPI-based scheme.
349  bool reconnectMPIs( Event& event, int oldSize);
350 
351  // Vectors and methods needed for the new gluon-move model.
352 
353  // Array of (indices of) all final coloured particles.
354  vector<int> iReduceCol, iExpandCol;
355 
356  // Array of all lambda distances between coloured partons.
357  int nColMove;
358  vector<double> lambdaijMove;
359 
360  // Function to return lambda value from array.
361  double lambda12Move( int i, int j) {
362  int iAC = iReduceCol[i]; int jAC = iReduceCol[j];
363  return lambdaijMove[nColMove * min( iAC, jAC) + max( iAC, jAC)];
364  }
365 
366  // Function to return lambda(i,j) + lambda(i,k) - lambda(j,k).
367  double lambda123Move( int i, int j, int k) {
368  int iAC = iReduceCol[i]; int jAC = iReduceCol[j]; int kAC = iReduceCol[k];
369  return lambdaijMove[nColMove * min( iAC, jAC) + max( iAC, jAC)]
370  + lambdaijMove[nColMove * min( iAC, kAC) + max( iAC, kAC)]
371  - lambdaijMove[nColMove * min( jAC, kAC) + max( jAC, kAC)];
372  }
373 
374  // The new gluon-move scheme.
375  bool reconnectMove( Event& event, int oldSize);
376 
377  // The common part for both Type I and II reconnections in e+e..
378  bool reconnectTypeCommon( Event& event, int oldSize);
379 
380  // The e+e- type I CR model.
381  map<double,pair<int,int> > reconnectTypeI( Event& event,
382  vector<vector<ColourDipole> > &dips, Vec4 decays[2]);
383  // bool reconnectTypeI( Event& event, int oldSize);
384 
385  // The e+e- type II CR model.
386  map<double,pair<int,int> > reconnectTypeII( Event& event,
387  vector<vector<ColourDipole> > &dips, Vec4 decays[2]);
388  // bool reconnectTypeII( Event& event, int oldSize);
389 
390  // calculate the determinant of 3 * 3 matrix.
391  double determinant3(vector<vector< double> >& vec);
392 };
393 
394 //==========================================================================
395 
396 } // end namespace Pythia8
397 
398 #endif // Pythia8_ColourReconnection_H
Definition: AgUStep.h:26