1 // FragmentationSystems.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2008 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
6 // Function definitions (not found in the header) for the
7 // ColConfig, StringRegion and StringSystem classes.
9 #include "FragmentationSystems.h"
13 //**************************************************************************
15 // The ColConfig class.
19 // Initialize and save pointers.
21 void ColConfig::init(StringFlav* flavSelPtrIn) {
24 flavSelPtr = flavSelPtrIn;
26 // Joining of nearby partons along the string.
27 mJoin = Settings::parm("FragmentationSystems:mJoin");
29 // For consistency ensure that mJoin is bigger than in StringRegion.
30 mJoin = max( mJoin, 2. * StringRegion::MJOIN);
32 // Simplification of q q q junction topology to quark - diquark one.
33 mJoinJunction = Settings::parm("FragmentationSystems:mJoinJunction");
34 mStringMin = Settings::parm("HadronLevel:mStringMin");
40 // Insert a new colour singlet system in ascending mass order.
41 // Calculate its properties. Join nearby partons.
43 void ColConfig::insert( vector<int>& iPartonIn, Event& event) {
45 // Find momentum and invariant mass of system, minus endpoint masses.
48 bool hasJunctionIn = false;
49 for (int i = 0; i < int(iPartonIn.size()); ++i) {
50 if (iPartonIn[i] < 0) {
54 pSumIn += event[ iPartonIn[i] ].p();
55 if (!event[ iPartonIn[i] ].isGluon())
56 mSumIn += event[ iPartonIn[i] ].constituentMass();
58 double massIn = pSumIn.mCalc();
59 double massExcessIn = massIn - mSumIn;
61 // Identify closed gluon loop. Assign "endpoint" masses as light quarks.
62 bool isClosedIn = (iPartonIn[0] >= 0 && event[ iPartonIn[0] ].isGluon());
63 if (isClosedIn) massExcessIn -= 2. * ParticleDataTable::constituentMass(1);
65 // For junction topology: join two nearby legs into a diquark.
66 if (hasJunctionIn && joinJunction( iPartonIn, event, massExcessIn))
67 hasJunctionIn = false;
69 // Loop while > 2 partons left and hope of finding joining pair.
70 bool hasJoined = true;
71 while (hasJoined && iPartonIn.size() > 2) {
73 // Look for the pair of neighbour partons (along string) with
74 // the smallest invariant mass (subtracting quark masses).
76 double mJoinMin = 2. * mJoin;
77 int nSize = iPartonIn.size();
78 int nPair = (isClosedIn) ? nSize : nSize - 1;
79 for (int i = 0; i < nPair; ++i) {
80 // Keep three legs of junction separate.
81 if (iPartonIn[i] < 0 || iPartonIn[(i + 1)%nSize] < 0) continue;
82 Particle& parton1 = event[ iPartonIn[i] ];
83 Particle& parton2 = event[ iPartonIn[(i + 1)%nSize] ];
85 pSumNow += (parton1.isGluon()) ? 0.5 * parton1.p() : parton1.p();
86 pSumNow += (parton2.isGluon()) ? 0.5 * parton2.p() : parton2.p();
87 double mJoinNow = pSumNow.mCalc();
88 if (!parton1.isGluon()) mJoinNow -= parton1.m();
89 if (!parton2.isGluon()) mJoinNow -= parton2.m();
90 if (mJoinNow < mJoinMin) { iJoinMin = i; mJoinMin = mJoinNow; }
93 // If sufficiently nearby then join into one new parton.
94 // Note: error sensitivity to mJoin indicates unstable precedure??
96 if (mJoinMin < mJoin) {
97 int iJoin1 = iPartonIn[iJoinMin];
98 int iJoin2 = iPartonIn[(iJoinMin + 1)%nSize];
99 int idNew = (event[iJoin1].isGluon()) ? event[iJoin2].id()
100 : event[iJoin1].id();
101 int colNew = event[iJoin1].col();
102 int acolNew = event[iJoin2].acol();
103 if (colNew == acolNew) {
104 colNew = event[iJoin2].col();
105 acolNew = event[iJoin1].acol();
107 Vec4 pNew = event[iJoin1].p() + event[iJoin2].p();
109 // Append joined parton to event record.
110 int iNew = event.append( idNew, 73, min(iJoin1, iJoin2),
111 max(iJoin1, iJoin2), 0, 0, colNew, acolNew, pNew, pNew.mCalc() );
113 // Mark joined partons and reduce remaining system.
114 event[iJoin1].statusNeg();
115 event[iJoin2].statusNeg();
116 event[iJoin1].daughter1(iNew);
117 event[iJoin2].daughter1(iNew);
118 if (iJoinMin == nSize - 1) iPartonIn[0] = iNew;
120 iPartonIn[iJoinMin] = iNew;
121 for (int i = iJoinMin + 1; i < nSize - 1; ++i)
122 iPartonIn[i] = iPartonIn[i + 1];
124 iPartonIn.pop_back();
126 // If joined,then loopback to look for more.
131 // Store new colour singlet system at the end.
132 singlets.push_back( ColSinglet(iPartonIn, pSumIn, massIn,
133 massExcessIn, hasJunctionIn, isClosedIn) );
135 // Now move around, so that smallest mass excesses come first.
136 int iInsert = singlets.size() - 1;
137 for (int iSub = singlets.size() - 2; iSub >= 0; --iSub) {
138 if (massExcessIn > singlets[iSub].massExcess) break;
139 singlets[iSub + 1] = singlets[iSub];
142 if (iInsert < int(singlets.size()) - 1) singlets[iInsert] =
143 ColSinglet(iPartonIn, pSumIn, massIn, massExcessIn,
144 hasJunctionIn, isClosedIn);
150 // Join two legs of junction to a diquark for small invariant masses.
151 // Note: for junction system, iPartonIn points to structure
152 // (-code0) g...g.q0 (-code1) g...g.q1 (-code2) g...g.q2
154 bool ColConfig::joinJunction( vector<int>& iPartonIn, Event& event,
155 double massExcessIn) {
157 // Find four-momentum and endpoint quarks and masses on the three legs.
162 for (int i = 0; i < int(iPartonIn.size()); ++ i) {
163 if (iPartonIn[i] < 0) ++leg;
165 pLeg[leg] += event[ iPartonIn[i] ].p();
166 mLeg[leg] = event[ iPartonIn[i] ].m();
167 idAbsLeg[leg] = event[ iPartonIn[i] ].idAbs();
171 // Calculate invariant mass of three pairs, minus endpoint masses.
172 double m01 = (pLeg[0] + pLeg[1]).mCalc() - mLeg[0] - mLeg[1];
173 double m02 = (pLeg[0] + pLeg[2]).mCalc() - mLeg[0] - mLeg[2];
174 double m12 = (pLeg[1] + pLeg[2]).mCalc() - mLeg[1] - mLeg[2];
176 // Find lowest-mass pair not involving diquark.
177 double mMin = mJoinJunction + 1.;
180 if (m01 < mMin && idAbsLeg[0] < 9 && idAbsLeg[1] < 9) {
185 if (m02 < mMin && idAbsLeg[0] < 9 && idAbsLeg[2] < 9) {
190 if (m12 < mMin && idAbsLeg[1] < 9 && idAbsLeg[2] < 9) {
195 int legC = 3 - legA - legB;
197 // Nothing to do if no two legs have small invariant mass, and
198 // system as a whole is above MiniStringFragmentation threshold.
199 if (mMin > mJoinJunction && massExcessIn > mStringMin) return false;
201 // Construct separate index arrays for the three legs.
202 vector<int> iLegA, iLegB, iLegC;
204 for (int i = 0; i < int(iPartonIn.size()); ++ i) {
205 if (iPartonIn[i] < 0) ++leg;
206 else if( leg == legA) iLegA.push_back( iPartonIn[i] );
207 else if( leg == legB) iLegB.push_back( iPartonIn[i] );
208 else if( leg == legC) iLegC.push_back( iPartonIn[i] );
211 // First step: successively combine any gluons on the two legs.
212 // (Presumably overkill; not likely to be (m)any extra gluons.)
213 // (Do as successive binary joinings, so only need two mothers.)
214 for (leg = 0; leg < 2; ++leg) {
215 vector<int>& iLegNow = (leg == 0) ? iLegA : iLegB;
216 int sizeNow = iLegNow.size();
217 for (int i = sizeNow - 2; i >= 0; --i) {
218 int iQ = iLegNow.back();
220 int colNew = (event[iQ].id() > 0) ? event[iG].col() : 0;
221 int acolNew = (event[iQ].id() < 0) ? event[iG].acol() : 0;
222 Vec4 pNew = event[iQ].p() + event[iG].p();
223 int iNew = event.append( event[iQ].id(), 74, min(iQ, iG),
224 max(iQ, iG), 0, 0, colNew, acolNew, pNew, pNew.mCalc() );
226 // Mark joined partons and update iLeg end.
227 event[iQ].statusNeg();
228 event[iG].statusNeg();
229 event[iQ].daughter1(iNew);
230 event[iG].daughter1(iNew);
231 iLegNow.back() = iNew;
235 // Second step: combine two quarks into a diquark.
236 int iQA = iLegA.back();
237 int iQB = iLegB.back();
238 int idQA = event[iQA].id();
239 int idQB = event[iQB].id();
240 int idNew = flavSelPtr->makeDiquark( idQA, idQB );
241 // Diquark colour is opposite to parton closest to junction on third leg.
242 int colNew = (idNew > 0) ? 0 : event[ iLegC[0] ].acol();
243 int acolNew = (idNew > 0) ? event[ iLegC[0] ].col() : 0;
244 Vec4 pNew = pLeg[legA] + pLeg[legB];
245 int iNew = event.append( idNew, 74, min(iQA, iQB), max( iQA, iQB),
246 0, 0, colNew, acolNew, pNew, pNew.mCalc() );
248 // Mark joined partons and reduce remaining system.
249 event[iQA].statusNeg();
250 event[iQB].statusNeg();
251 event[iQA].daughter1(iNew);
252 event[iQB].daughter1(iNew);
254 iPartonIn.push_back( iNew);
255 for (int i = 0; i < int(iLegC.size()) ; ++i)
256 iPartonIn.push_back( iLegC[i]);
258 // Remove junction from event record list, identifying by colour.
260 for (int i = 0; i < event.sizeJunction(); ++i)
261 for (int j = 0; j < 3; ++ j)
262 if ( event.colJunction(i,j) == max(colNew, acolNew) ) iJun = i;
263 if (iJun >= 0) event.eraseJunction(iJun);
265 // Done, having eliminated junction.
272 // Collect all partons of singlet to be consecutively ordered.
274 void ColConfig::collect(int iSub, Event& event) {
276 // Partons may already have been collected, e.g. at ministring collapse.
277 if (singlets[iSub].isCollected) return;
278 singlets[iSub].isCollected = true;
280 // Check if partons already "by chance" happen to be ordered.
282 for (int i = 0; i < singlets[iSub].size() - 1; ++i) {
283 int iFirst = singlets[iSub].iParton[i];
284 if (iFirst < 0) continue;
285 int iSecond = singlets[iSub].iParton[i + 1];
286 if (iSecond < 0) iSecond = singlets[iSub].iParton[i + 2];
287 if (iSecond != iFirst + 1) { inOrder = false; break;}
291 // Copy down system. Update current partons.
292 for (int i = 0; i < singlets[iSub].size(); ++i) {
293 int iOld = singlets[iSub].iParton[i];
294 if (iOld < 0) continue;
295 int iNew = event.copy(iOld, 71);
296 singlets[iSub].iParton[i] = iNew;
304 // List all currently identified singlets.
306 void ColConfig::list(ostream& os) {
308 // Header. Loop over all individual singlets.
309 os << "\n -------- Colour Singlet Systems Listing -------------------\n";
310 for (int iSub = 0; iSub < int(singlets.size()); ++iSub) {
312 // List all partons belonging to each singlet.
313 os << " singlet " << iSub << " contains " ;
314 for (int i = 0; i < singlets[iSub].size(); ++i)
315 os << singlets[iSub].iParton[i] << " ";
322 //**************************************************************************
324 // The StringRegion class.
326 // Currently a number of simplifications, in particular ??
327 // 1) No popcorn baryon production.
328 // 2) Simplified treatment of pT in stepping and joining.
332 // Constants: could be changed here if desired, but normally should not.
333 // These are of technical nature, as described for each.
335 // If a string region is smaller thsan this it is assumed empty.
336 const double StringRegion::MJOIN = 0.1;
338 // Avoid division by zero.
339 const double StringRegion::TINY = 1e-20;
343 // Set up four-vectors for longitudinal and transverse directions.
345 void StringRegion::setUp(Vec4 p1, Vec4 p2, bool isMassless) {
347 // Simple case: the two incoming four-vectors guaranteed massless.
350 // Calculate w2, minimum value. Lightcone directions = input.
352 if (w2 < MJOIN*MJOIN) {isSetUp = true; isEmpty = true; return;}
356 // Else allow possibility of masses for incoming partons (also gluons!).
359 // Generic four-momentum combinations.
360 double m1Sq = p1 * p1;
361 double m2Sq = p2 * p2;
362 double p1p2 = p1 * p2;
363 w2 = m1Sq + 2. * p1p2 + m2Sq;
364 double rootSq = pow2(p1p2) - m1Sq * m2Sq;
366 // If crazy kinematics (should not happen!) modify energies.
367 if (w2 <= 0. || rootSq <= 0.) {
368 if (m1Sq < 0.) m1Sq = 0.;
369 p1.e( sqrt(m1Sq + p1.pAbs2()) );
370 if (m2Sq < 0.) m2Sq = 0.;
371 p2.e( sqrt(m2Sq + p2.pAbs2()) );
373 w2 = m1Sq + 2. * p1p2 + m2Sq;
374 rootSq = pow2(p1p2) - m1Sq * m2Sq;
377 // If still small invariant mass then empty region (e.g. in gg system).
378 if (w2 < MJOIN*MJOIN) {isSetUp = true; isEmpty = true; return;}
380 // Find two lightconelike longitudinal four-vector directions.
381 double root = sqrt( max(TINY, rootSq) );
382 double k1 = 0.5 * ( (m2Sq + p1p2) / root - 1.);
383 double k2 = 0.5 * ( (m1Sq + p1p2) / root - 1.);
384 pPos = (1. + k1) * p1 - k2 * p2;
385 pNeg = (1. + k2) * p2 - k1 * p1;
388 // Find two spacelike transverse four-vector directions.
389 // Begin by picking two sensible trial directions.
390 Vec4 eDiff = pPos / pPos.e() - pNeg / pNeg.e();
391 double eDx = pow2( eDiff.px() );
392 double eDy = pow2( eDiff.py() );
393 double eDz = pow2( eDiff.pz() );
394 if (eDx < min(eDy, eDz)) {
395 eX = Vec4( 1., 0., 0., 0.);
396 eY = (eDy < eDz) ? Vec4( 0., 1., 0., 0.) : Vec4( 0., 0., 1., 0.);
397 } else if (eDy < eDz) {
398 eX = Vec4( 0., 1., 0., 0.);
399 eY = (eDx < eDz) ? Vec4( 1., 0., 0., 0.) : Vec4( 0., 0., 1., 0.);
401 eX = Vec4( 0., 0., 1., 0.);
402 eY = (eDx < eDy) ? Vec4( 1., 0., 0., 0.) : Vec4( 0., 1., 0., 0.);
405 // Then construct orthogonal linear combinations.
406 double pPosNeg = pPos * pNeg;
407 double kXPos = eX * pPos / pPosNeg;
408 double kXNeg = eX * pNeg / pPosNeg;
409 double kXX = 1. / sqrt( 1. + 2. * kXPos * kXNeg * pPosNeg );
410 double kYPos = eY * pPos / pPosNeg;
411 double kYNeg = eY * pNeg / pPosNeg;
412 double kYX = kXX * (kXPos * kYNeg + kXNeg * kYPos) * pPosNeg;
413 double kYY = 1. / sqrt(1. + 2. * kYPos * kYNeg * pPosNeg - pow2(kYX));
414 eX = kXX * (eX - kXNeg * pPos - kXPos * pNeg);
415 eY = kYY * (eY - kYNeg * pPos - kYPos * pNeg - kYX * eX);
425 // Project a four-momentum onto (x+, x-, px, py).
427 void StringRegion::project(Vec4 pIn) {
429 // Perform projections by four-vector multiplication.
430 xPosProj = 2. * (pIn * pNeg) / w2;
431 xNegProj = 2. * (pIn * pPos) / w2;
432 pxProj = - (pIn * eX);
433 pyProj = - (pIn * eY);
437 //**************************************************************************
439 // The StringSystem class.
443 // Set up system from parton list.
445 void StringSystem::setUp(vector<int>& iSys, Event& event) {
447 // Figure out how big the system is. (Closed gluon loops?)
448 sizePartons = iSys.size();
449 sizeStrings = sizePartons - 1;
450 sizeRegions = (sizeStrings * (sizeStrings + 1)) / 2;
451 indxReg = 2 * sizeStrings + 1;
452 iMax = sizeStrings - 1;
454 // Reserve space for the required number of regions.
456 system.resize(sizeRegions);
458 // Set up the lowest-lying regions.
459 for (int i = 0; i < sizeStrings; ++i) {
460 Vec4 p1 = event[ iSys[i] ].p();
461 if ( event[ iSys[i] ].isGluon() ) p1 *= 0.5;
462 Vec4 p2 = event[ iSys[i+1] ].p();
463 if ( event[ iSys[i+1] ].isGluon() ) p2 *= 0.5;
464 system[ iReg(i, iMax - i) ].setUp( p1, p2, false);
469 //**************************************************************************
471 } // end namespace Pythia8