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