1 // HadronLevel.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 HadronLevel class.
8 #include "HadronLevel.h"
12 //**************************************************************************
14 // The HadronLevel class.
18 // Constants: could be changed here if desired, but normally should not.
19 // These are of technical nature, as described for each.
21 // For breaking J-J string, pick a Gamma by taking a step with fictitious mass.
22 const double HadronLevel::JJSTRINGM2MAX = 25.;
23 const double HadronLevel::JJSTRINGM2FRAC = 0.1;
25 // Iterate junction rest frame boost until convergence or too many tries.
26 const double HadronLevel::CONVJNREST = 1e-5;
27 const int HadronLevel::NTRYJNREST = 20;
29 // Typical average transvere primary hadron mass <mThad>.
30 const double HadronLevel::MTHAD = 0.9;
34 // Find settings. Initialize HadronLevel classes as required.
36 bool HadronLevel::init(Info* infoPtrIn, TimeShower* timesDecPtr,
37 DecayHandler* decayHandlePtr, vector<int> handledParticles) {
43 doHadronize = Settings::flag("HadronLevel:Hadronize");
44 doDecay = Settings::flag("HadronLevel:Decay");
45 doBoseEinstein = Settings::flag("HadronLevel:BoseEinstein");
47 // Boundary mass between string and ministring handling.
48 mStringMin = Settings::parm("HadronLevel:mStringMin");
50 // For junction processing.
51 eNormJunction = Settings::parm("StringFragmentation:eNormJunction");
53 // Particles that should decay or not before Bose-Einstein stage.
54 widthSepBE = Settings::parm("BoseEinstein:widthSep");
56 // Initialize string and ministring fragmentation.
57 stringFrag.init(infoPtr, &flavSel, &pTSel, &zSel);
58 ministringFrag.init(infoPtr, &flavSel);
60 // Initialize particle decays.
61 decays.init(infoPtr, timesDecPtr, &flavSel, decayHandlePtr,
64 // Initialize BoseEinstein.
65 boseEinstein.init(infoPtr);
67 // Initialize auxiliary administrative classes.
68 colConfig.init( &flavSel);
70 // Initialize auxiliary fragmentation classes.
82 // Hadronize and decay the next parton-level.
84 bool HadronLevel::next( Event& event) {
86 // Colour-octet onia states must be decayed to singlet + gluon.
87 if (!decayOctetOnia(event)) return false;
89 // Possibility of hadronization inside decay, but then no BE second time.
91 bool doBoseEinsteinNow = doBoseEinstein;
95 // First part: string fragmentation.
98 // Find the complete colour singlet configuration of the event.
99 if (!findSinglets( event)) return false;
101 // Process all colour singlet (sub)system
102 for (int iSub = 0; iSub < colConfig.size(); ++iSub) {
104 // Collect sequentially all partons in a colour singlet subsystem.
105 colConfig.collect(iSub, event);
107 // String fragmentation of each colour singlet (sub)system.
108 if ( colConfig[iSub].massExcess > mStringMin ) {
109 if (!stringFrag.fragment( iSub, colConfig, event)) return false;
111 // Low-mass string treated separately. Tell if diffractive system.
113 bool isDiff = infoPtr->isDiffractiveA()
114 || infoPtr->isDiffractiveB();
115 if (!ministringFrag.fragment( iSub, colConfig, event, isDiff))
121 // Second part: sequential decays of short-lived particles (incl. K0).
124 // Loop through all entries to find those that should decay.
127 if ( event[iDec].isFinal() && event[iDec].canDecay()
128 && event[iDec].mayDecay() && (event[iDec].idAbs() == 311
129 || event[iDec].mWidth() > widthSepBE) ) {
130 decays.decay( iDec, event);
131 if (decays.moreToDo()) moreToDo = true;
133 } while (++iDec < event.size());
136 // Third part: include Bose-Einstein effects among current particles.
137 if (doBoseEinsteinNow) {
138 if (!boseEinstein.shiftEvent(event)) return false;
139 doBoseEinsteinNow = false;
142 // Fourth part: sequential decays also of long-lived particles.
145 // Loop through all entries to find those that should decay.
148 if ( event[iDec].isFinal() && event[iDec].canDecay()
149 && event[iDec].mayDecay() ) {
150 decays.decay( iDec, event);
151 if (decays.moreToDo()) moreToDo = true;
153 } while (++iDec < event.size());
157 // Normally done first time around, but sometimes not (e.g. Upsilon).
167 // Allow more decays if on/off switches changed.
168 // Note: does not do sequential hadronization, e.g. for Upsilon.
170 bool HadronLevel::moreDecays( Event& event) {
172 // Colour-octet onia states must be decayed to singlet + gluon.
173 if (!decayOctetOnia(event)) return false;
175 // Loop through all entries to find those that should decay.
178 if ( event[iDec].isFinal() && event[iDec].canDecay()
179 && event[iDec].mayDecay() ) decays.decay( iDec, event);
180 } while (++iDec < event.size());
189 // Decay colour-octet onium states.
191 bool HadronLevel::decayOctetOnia(Event& event) {
193 // Onium states to be decayed.
194 int idOnium[6] = { 9900443, 9900441, 9910441,
195 9900553, 9900551, 9910551 };
197 // Loop over particles and identify onia.
198 for (int iDec = 0; iDec < event.size(); ++iDec)
199 if (event[iDec].isFinal()) {
200 int id = event[iDec].id();
201 bool isOnium = false;
202 for (int j = 0; j < 6; ++j) if (id == idOnium[j]) isOnium = true;
204 // Decay any onia encountered.
206 if (!decays.decay( iDec, event)) return false;
208 // Set colour flow by hand: gluon inherits octet-onium state.
209 int iGlu = event.size() - 1;
210 event[iGlu].cols( event[iDec].col(), event[iDec].acol() );
221 // Trace colour flow in the event to form colour singlet subsystems.
223 bool HadronLevel::findSinglets(Event& event) {
225 // Find a list of final partons and of all colour ends and gluons.
228 iColAndAcol.resize(0);
229 for (int i = 0; i < event.size(); ++ i) if (event[i].isFinal()) {
230 if (event[i].col() > 0 && event[i].acol() > 0) iColAndAcol.push_back(i);
231 else if (event[i].col() > 0) iColEnd.push_back(i);
232 else if (event[i].acol() > 0) iAcolEnd.push_back(i);
235 // Begin arrange the partons into separate colour singlets.
237 iPartonJun.resize(0);
238 iPartonAntiJun.resize(0);
240 // Junctions: loop over them, and identify kind.
241 for (int iJun = 0; iJun < event.sizeJunction(); ++iJun)
242 if (event.remainsJunction(iJun)) {
243 event.remainsJunction(iJun, false);
244 int kindJun = event.kindJunction(iJun);
247 // First kind: three (anti)colours out from junction.
248 if (kindJun == 1 || kindJun == 2) {
249 for (int iCol = 0; iCol < 3; ++iCol) {
250 int indxCol = event.colJunction(iJun, iCol);
251 iParton.push_back( -(10 + 10 * iJun + iCol) );
252 if (kindJun == 1 && !traceFromAcol(indxCol, event, iJun, iCol))
254 if (kindJun == 2 && !traceFromCol(indxCol, event, iJun, iCol))
259 // Keep in memory a junction hooked up with an antijunction,
260 // else store found single-junction system.
262 for (int i = 0; i < int(iParton.size()); ++i) if (iParton[i] < 0)
264 if (nNeg > 3 && kindJun == 1) {
265 for (int i = 0; i < int(iParton.size()); ++i)
266 iPartonJun.push_back(iParton[i]);
267 } else if (nNeg > 3 && kindJun == 2) {
268 for (int i = 0; i < int(iParton.size()); ++i)
269 iPartonAntiJun.push_back(iParton[i]);
271 // A junction may be eliminated by insert if two quarks are nearby.
272 int nJunOld = event.sizeJunction();
273 colConfig.insert(iParton, event);
274 if (event.sizeJunction() < nJunOld) --iJun;
278 // Split junction-antijunction system into two, and store those.
279 // (Only one system in extreme cases, and then second empty.)
280 if (iPartonJun.size() > 0 && iPartonAntiJun.size() > 0) {
281 if (!splitJunctionPair(event)) return false;
282 colConfig.insert(iPartonJun, event);
283 if (iPartonAntiJun.size() > 0)
284 colConfig.insert(iPartonAntiJun, event);
285 // Error if only one of junction and antijuction left here.
286 } else if (iPartonJun.size() > 0 || iPartonAntiJun.size() > 0) {
287 infoPtr->errorMsg("Error in HadronLevel::findSinglets: "
288 "unmatched (anti)junction");
292 // Open strings: pick up each colour end and trace to its anticolor end.
293 for (int iEnd = 0; iEnd < int(iColEnd.size()); ++iEnd) {
295 iParton.push_back( iColEnd[iEnd] );
296 int indxCol = event[ iColEnd[iEnd] ].col();
297 if (!traceFromCol(indxCol, event)) return false;
299 // Store found open string system. Analyze its properties.
300 colConfig.insert(iParton, event);
303 // Closed strings : begin at any gluon and trace until back at it.
304 while (iColAndAcol.size() > 0) {
306 iParton.push_back( iColAndAcol[0] );
307 int indxCol = event[ iColAndAcol[0] ].col();
308 int indxAcol = event[ iColAndAcol[0] ].acol();
309 iColAndAcol[0] = iColAndAcol.back();
310 iColAndAcol.pop_back();
311 if (!traceInLoop(indxCol, indxAcol, event)) return false;
313 // Store found closed string system. Analyze its properties.
314 colConfig.insert(iParton, event);
324 // Trace a colour line, from a colour to an anticolour.
326 bool HadronLevel::traceFromCol(int indxCol, Event& event, int iJun,
329 // Junction kind, if any.
330 int kindJun = (iJun >= 0) ? event.kindJunction(iJun) : 0;
332 // Begin to look for a matching anticolour.
334 int loopMax = iColAndAcol.size() + 2;
335 bool hasFound = false;
340 // First check list of matching anticolour ends.
341 for (int i = 0; i < int(iAcolEnd.size()); ++i)
342 if (event[ iAcolEnd[i] ].acol() == indxCol) {
343 iParton.push_back( iAcolEnd[i] );
345 iAcolEnd[i] = iAcolEnd.back();
351 // Then check list of intermediate gluons.
353 for (int i = 0; i < int(iColAndAcol.size()); ++i)
354 if (event[ iColAndAcol[i] ].acol() == indxCol) {
355 iParton.push_back( iColAndAcol[i] );
357 // Update to new colour. Remove gluon.
358 indxCol = event[ iColAndAcol[i] ].col();
359 if (kindJun > 0) event.endColJunction(iJun, iCol, indxCol);
360 iColAndAcol[i] = iColAndAcol.back();
361 iColAndAcol.pop_back();
366 // In a pinch, check list of end colours on other (anti)junction.
367 if (!hasFound && kindJun == 2 && event.sizeJunction() > 1)
368 for (int iAntiJun = 0; iAntiJun < event.sizeJunction(); ++iAntiJun)
369 if (iAntiJun != iJun && event.kindJunction(iAntiJun) == 1)
370 for (int iColAnti = 0; iColAnti < 3; ++iColAnti)
371 if (event.endColJunction(iAntiJun, iColAnti) == indxCol) {
372 iParton.push_back( -(10 + 10 * iAntiJun + iColAnti) );
378 // Keep on tracing via gluons until reached end of leg.
379 } while (hasFound && indxCol > 0 && loop < loopMax);
381 // Something went wrong in colour tracing.
382 if (!hasFound || loop == loopMax) {
383 infoPtr->errorMsg("Error in HadronLevel::traceFromCol: "
384 "colour tracing failed");
395 // Trace a colour line, from an anticolour to a colour.
397 bool HadronLevel::traceFromAcol(int indxCol, Event& event, int iJun,
400 // Junction kind, if any.
401 int kindJun = (iJun >= 0) ? event.kindJunction(iJun) : 0;
403 // Begin to look for a matching colour.
405 int loopMax = iColAndAcol.size() + 2;
406 bool hasFound = false;
411 // First check list of matching colour ends.
412 for (int i = 0; i < int(iColEnd.size()); ++i)
413 if (event[ iColEnd[i] ].col() == indxCol) {
414 iParton.push_back( iColEnd[i] );
416 iColEnd[i] = iColEnd.back();
422 // Then check list of intermediate gluons.
424 for (int i = 0; i < int(iColAndAcol.size()); ++i)
425 if (event[ iColAndAcol[i] ].col() == indxCol) {
426 iParton.push_back( iColAndAcol[i] );
428 // Update to new colour. Remove gluon.
429 indxCol = event[ iColAndAcol[i] ].acol();
430 if (kindJun > 0) event.endColJunction(iJun, iCol, indxCol);
431 iColAndAcol[i] = iColAndAcol.back();
432 iColAndAcol.pop_back();
437 // In a pinch, check list of colours on other (anti)junction.
438 if (!hasFound && kindJun == 1 && event.sizeJunction() > 1)
439 for (int iAntiJun = 0; iAntiJun < event.sizeJunction(); ++iAntiJun)
440 if (iAntiJun != iJun && event.kindJunction(iAntiJun) == 2)
441 for (int iColAnti = 0; iColAnti < 3; ++iColAnti)
442 if (event.endColJunction(iAntiJun, iColAnti) == indxCol) {
443 iParton.push_back( -(10 + 10 * iAntiJun + iColAnti) );
449 // Keep on tracing via gluons until reached end of leg.
450 } while (hasFound && indxCol > 0 && loop < loopMax);
452 // Something went wrong in colour tracing.
453 if (!hasFound || loop == loopMax) {
454 infoPtr->errorMsg("Error in HadronLevel::traceFromAcol: "
455 "colour tracing failed");
466 // Trace a colour loop, from a colour back to the anticolour of the same.
468 bool HadronLevel::traceInLoop(int indxCol, int indxAcol, Event& event) {
470 // Move around until back where begun.
472 int loopMax = iColAndAcol.size() + 2;
473 bool hasFound = false;
478 // Check list of gluons.
479 for (int i = 0; i < int(iColAndAcol.size()); ++i)
480 if (event[ iColAndAcol[i] ].acol() == indxCol) {
481 iParton.push_back( iColAndAcol[i] );
482 indxCol = event[ iColAndAcol[i] ].col();
483 iColAndAcol[i] = iColAndAcol.back();
484 iColAndAcol.pop_back();
488 } while (hasFound && indxCol != indxAcol && loop < loopMax);
490 // Something went wrong in colour tracing.
491 if (!hasFound || loop == loopMax) {
492 infoPtr->errorMsg("Error in HadronLevel::traceInLoop: "
493 "colour tracing failed");
504 // Split junction-antijunction system into two, or simplify other way.
506 bool HadronLevel::splitJunctionPair(Event& event) {
508 // Construct separate index arrays for the three junction legs.
509 int identJun = (-iPartonJun[0])/10;
514 for (int i = 0; i < int(iPartonJun.size()); ++ i) {
515 if ( (-iPartonJun[i])/10 == identJun) ++leg;
516 if (leg == 0) iJunLegA.push_back( iPartonJun[i] );
517 else if (leg == 1) iJunLegB.push_back( iPartonJun[i] );
518 else iJunLegC.push_back( iPartonJun[i] );
521 // Construct separate index arrays for the three antijunction legs.
522 int identAnti = (-iPartonAntiJun[0])/10;
527 for (int i = 0; i < int(iPartonAntiJun.size()); ++ i) {
528 if ( (-iPartonAntiJun[i])/10 == identAnti) ++leg;
529 if (leg == 0) iAntiLegA.push_back( iPartonAntiJun[i] );
530 else if (leg == 1) iAntiLegB.push_back( iPartonAntiJun[i] );
531 else iAntiLegC.push_back( iPartonAntiJun[i] );
534 // Find interjunction legs, i.e. between junction and antijunction.
536 int legJun[3], legAnti[3], nGluLeg[3];
537 if (iJunLegA.back() < 0) { legJun[nMatch] = 0;
538 legAnti[nMatch] = (-iJunLegA.back())%10; ++nMatch;}
539 if (iJunLegB.back() < 0) { legJun[nMatch] = 1;
540 legAnti[nMatch] = (-iJunLegB.back())%10; ++nMatch;}
541 if (iJunLegC.back() < 0) { legJun[nMatch] = 2;
542 legAnti[nMatch] = (-iJunLegC.back())%10; ++nMatch;}
544 // Loop over interjunction legs.
545 for (int iMatch = 0; iMatch < nMatch; ++iMatch) {
546 vector<int>& iJunLeg = (legJun[iMatch] == 0) ? iJunLegA
547 : ( (legJun[iMatch] == 1) ? iJunLegB : iJunLegC );
548 vector<int>& iAntiLeg = (legAnti[iMatch] == 0) ? iAntiLegA
549 : ( (legAnti[iMatch] == 1) ? iAntiLegB : iAntiLegC );
551 // Find number of gluons on each. Do nothing for now if none.
552 nGluLeg[iMatch] = iJunLeg.size() + iAntiLeg.size() - 4;
553 if (nGluLeg[iMatch] == 0) continue;
555 // Else pick up the gluons on the interjunction leg in order.
557 for (int i = 1; i < int(iJunLeg.size()) - 1; ++i)
558 iGluLeg.push_back( iJunLeg[i] );
559 for (int i = int(iAntiLeg.size()) - 2; i > 0; --i)
560 iGluLeg.push_back( iAntiLeg[i] );
562 // Remove those gluons from the junction/antijunction leg lists.
566 // Pick a new quark at random; for simplicity no diquarks.
567 int idQ = flavSel.pickLightQ();
570 // If one gluon on leg, split it into a collinear q-qbar pair.
571 if (iGluLeg.size() == 1) {
573 // Store the new q qbar pair, sharing gluon colour and momentum.
574 colQ = event[ iGluLeg[0] ].col();
575 acolQ = event[ iGluLeg[0] ].acol();
576 Vec4 pQ = 0.5 * event[ iGluLeg[0] ].p();
577 double mQ = 0.5 * event[ iGluLeg[0] ].m();
578 int iQ = event.append( idQ, 75, iGluLeg[0], 0, 0, 0, colQ, 0, pQ, mQ );
579 int iQbar = event.append( -idQ, 75, iGluLeg[0], 0, 0, 0, 0, acolQ,
582 // Mark split gluon and update junction and antijunction legs.
583 event[ iGluLeg[0] ].statusNeg();
584 event[ iGluLeg[0] ].daughters( iQ, iQbar);
585 iJunLeg.push_back(iQ);
586 iAntiLeg.push_back(iQbar);
588 // If several gluons on the string, decide which g-g region to split up.
591 // Evaluate mass-squared for all adjacent gluon pairs.
594 for (int i = 0; i < int(iGluLeg.size()) - 1; ++i) {
595 double m2Now = 0.5 * event[ iGluLeg[i] ].p()
596 * event[ iGluLeg[i + 1] ].p();
597 m2Pair.push_back(m2Now);
601 // Pick breakup region with probability proportional to mass-squared.
602 double m2Reg = m2Sum * Rndm::flat();
604 do m2Reg -= m2Pair[++iReg];
605 while (m2Reg > 0. && iReg < int(iGluLeg.size()) - 1);
606 m2Reg = m2Pair[iReg];
608 // Pick breaking point of string in chosen region (symmetrically).
609 double m2Temp = min( JJSTRINGM2MAX, JJSTRINGM2FRAC * m2Reg);
613 double zTemp = zSel.zFrag( idQ, 0, m2Temp);
615 xNeg = m2Temp / (zTemp * m2Reg);
617 if (Rndm::flat() > 0.5) swap(xPos, xNeg);
619 // Pick up two "mother" gluons of breakup. Mark them decayed.
620 Particle& gJun = event[ iGluLeg[iReg] ];
621 Particle& gAnti = event[ iGluLeg[iReg + 1] ];
624 int dau1 = event.size();
625 gJun.daughters(dau1, dau1 + 3);
626 gAnti.daughters(dau1, dau1 + 3);
627 int mother1 = min( iGluLeg[iReg], iGluLeg[iReg + 1]);
628 int mother2 = max( iGluLeg[iReg], iGluLeg[iReg + 1]);
630 // Can keep one of old colours but need one new so unambiguous.
632 acolQ = event.nextColTag();
634 // Store copied gluons with reduced momenta.
635 int iGjun = event.append( 21, 75, mother1, mother2, 0, 0,
636 gJun.col(), gJun.acol(), (1. - 0.5 * xPos) * gJun.p(),
637 (1. - 0.5 * xPos) * gJun.m());
638 int iGanti = event.append( 21, 75, mother1, mother2, 0, 0,
639 acolQ, gAnti.acol(), (1. - 0.5 * xNeg) * gAnti.p(),
640 (1. - 0.5 * xNeg) * gAnti.m());
642 // Store the new q qbar pair with remaining momenta.
643 int iQ = event.append( idQ, 75, mother1, mother2, 0, 0,
644 colQ, 0, 0.5 * xNeg * gAnti.p(), 0.5 * xNeg * gAnti.m() );
645 int iQbar = event.append( -idQ, 75, mother1, mother2, 0, 0,
646 0, acolQ, 0.5 * xPos * gJun.p(), 0.5 * xPos * gJun.m() );
648 // Update junction and antijunction legs with gluons and quarks.
649 for (int i = 0; i < iReg; ++i)
650 iJunLeg.push_back( iGluLeg[i] );
651 iJunLeg.push_back(iGjun);
652 iJunLeg.push_back(iQ);
653 for (int i = int(iGluLeg.size()) - 1; i > iReg + 1; --i)
654 iAntiLeg.push_back( iGluLeg[i] );
655 iAntiLeg.push_back(iGanti);
656 iAntiLeg.push_back(iQbar);
659 // Update end colours for both g -> q qbar and g g -> g g q qbar.
660 event.endColJunction(identJun - 1, legJun[iMatch], colQ);
661 event.endColJunction(identAnti - 1, legAnti[iMatch], acolQ);
664 // Update list of interjunction legs after splittings above.
666 while (iMatchUp < nMatch) {
667 if (nGluLeg[iMatchUp] > 0) {
668 for (int i = iMatchUp; i < nMatch - 1; ++i) {
669 legJun[i] = legJun[i + 1];
670 legAnti[i] = legAnti[i + 1];
671 nGluLeg[i] = nGluLeg[i + 1];
676 // Should not ever have three empty interjunction legs.
678 infoPtr->errorMsg("Error in HadronLevel::splitJunctionPair: "
679 "three empty junction-junction legs");
683 // If two legs are empty, then collapse system to a single string.
685 int legJunLeft = 3 - legJun[0] - legJun[1];
686 int legAntiLeft = 3 - legAnti[0] - legAnti[1];
687 vector<int>& iJunLeg = (legJunLeft == 0) ? iJunLegA
688 : ( (legJunLeft == 1) ? iJunLegB : iJunLegC );
689 vector<int>& iAntiLeg = (legAntiLeft == 0) ? iAntiLegA
690 : ( (legAntiLeft == 1) ? iAntiLegB : iAntiLegC );
691 iPartonJun.resize(0);
692 for (int i = int(iJunLeg.size()) - 1; i > 0; --i)
693 iPartonJun.push_back( iJunLeg[i] );
694 for (int i = 1; i < int(iAntiLeg.size()); ++i)
695 iPartonJun.push_back( iAntiLeg[i] );
697 // Other string system empty. Remove junctions from their list. Done.
698 iPartonAntiJun.resize(0);
699 event.eraseJunction( max(identJun, identAnti) - 1);
700 event.eraseJunction( min(identJun, identAnti) - 1);
704 // If one leg is empty then, depending on string length, either
705 // (a) annihilate junction and antijunction into two simple strings, or
706 // (b) split the empty leg by borrowing energy from nearby legs.
709 // Identify the two external legs of either junction.
710 vector<int>& iJunLeg0 = (legJun[0] == 0) ? iJunLegB : iJunLegA;
711 vector<int>& iJunLeg1 = (legJun[0] == 2) ? iJunLegB : iJunLegC;
712 vector<int>& iAntiLeg0 = (legAnti[0] == 0) ? iAntiLegB : iAntiLegA;
713 vector<int>& iAntiLeg1 = (legAnti[0] == 2) ? iAntiLegB : iAntiLegC;
715 // Simplified procedure: mainly study first parton on each leg.
716 Vec4 pJunLeg0 = event[ iJunLeg0[1] ].p();
717 Vec4 pJunLeg1 = event[ iJunLeg1[1] ].p();
718 Vec4 pAntiLeg0 = event[ iAntiLeg0[1] ].p();
719 Vec4 pAntiLeg1 = event[ iAntiLeg1[1] ].p();
721 // Starting frame hopefully intermediate to two junction directions.
722 Vec4 pStart = pJunLeg0 / pJunLeg0.e() + pJunLeg1 / pJunLeg1.e()
723 + pAntiLeg0 / pAntiLeg0.e() + pAntiLeg1 / pAntiLeg1.e();
725 // Loop over iteration to junction/antijunction rest frames (JRF/ARF).
726 RotBstMatrix MtoJRF, MtoARF;
727 Vec4 pInJRF[3], pInARF[3];
728 for (int iJun = 0; iJun < 2; ++iJun) {
729 int offset = (iJun == 0) ? 0 : 2;
731 // Iterate from system rest frame towards the junction rest frame.
732 RotBstMatrix MtoRF, Mstep;
733 MtoRF.bstback(pStart);
739 // Find rest-frame momenta on the three sides of the junction.
740 // Only consider first parton on each leg, for simplicity.
741 pInRF[0 + offset] = pJunLeg0;
742 pInRF[1 + offset] = pJunLeg1;
743 pInRF[2 - offset] = pAntiLeg0;
744 pInRF[3 - offset] = pAntiLeg1;
745 for (int i = 0; i < 4; ++i) pInRF[i].rotbst(MtoRF);
747 // For third side add both legs beyond other junction, weighted.
748 double wt2 = 1. - exp( -pInRF[2].e() / eNormJunction);
749 double wt3 = 1. - exp( -pInRF[3].e() / eNormJunction);
750 pInRF[2] = wt2 * pInRF[2] + wt3 * pInRF[3];
752 // Find new junction rest frame from the set of momenta.
753 Mstep = stringFrag.junctionRestFrame( pInRF[0], pInRF[1], pInRF[2]);
754 MtoRF.rotbst( Mstep );
755 } while (iter < 3 || (Mstep.deviation() > CONVJNREST
756 && iter < NTRYJNREST) );
758 // Store final boost and rest-frame (weighted) momenta.
761 for (int i = 0; i < 3; ++i) pInJRF[i] = pInRF[i];
764 for (int i = 0; i < 3; ++i) pInARF[i] = pInRF[i];
768 // Opposite operations: boost from JRF/ARF to original system.
769 RotBstMatrix MfromJRF = MtoJRF;
771 RotBstMatrix MfromARF = MtoARF;
774 // Velocity vectors of junctions and momentum of legs in lab frame.
775 Vec4 vJun(0., 0., 0., 1.);
776 vJun.rotbst(MfromJRF);
777 Vec4 vAnti(0., 0., 0., 1.);
778 vAnti.rotbst(MfromARF);
779 Vec4 pLabJ[3], pLabA[3];
780 for (int i = 0; i < 3; ++i) {
781 pLabJ[i] = pInJRF[i];
782 pLabJ[i].rotbst(MfromJRF);
783 pLabA[i] = pInARF[i];
784 pLabA[i].rotbst(MfromARF);
787 // Calculate Lambda-measure length of three possible topologies.
788 double vJvA = vJun * vAnti;
789 double vJvAe2y = vJvA + sqrt(vJvA*vJvA - 1.);
790 double LambdaJA = (2. * pInJRF[0].e()) * (2. * pInJRF[1].e())
791 * (2. * pInARF[0].e()) * (2. * pInARF[1].e()) * vJvAe2y;
792 double Lambda00 = (2. * pLabJ[0] * pLabA[0])
793 * (2. * pLabJ[1] * pLabA[1]);
794 double Lambda01 = (2. * pLabJ[0] * pLabA[1])
795 * (2. * pLabJ[1] * pLabA[0]);
797 // Case when either topology without junctions is the shorter one.
798 if (LambdaJA > min( Lambda00, Lambda01)) {
799 vector<int>& iAntiMatch0 = (Lambda00 < Lambda01)
800 ? iAntiLeg0 : iAntiLeg1;
801 vector<int>& iAntiMatch1 = (Lambda00 < Lambda01)
802 ? iAntiLeg1 : iAntiLeg0;
804 // Define two quark-antiquark strings.
805 iPartonJun.resize(0);
806 for (int i = int(iJunLeg0.size()) - 1; i > 0; --i)
807 iPartonJun.push_back( iJunLeg0[i] );
808 for (int i = 1; i < int(iAntiMatch0.size()); ++i)
809 iPartonJun.push_back( iAntiMatch0[i] );
810 iPartonAntiJun.resize(0);
811 for (int i = int(iJunLeg1.size()) - 1; i > 0; --i)
812 iPartonAntiJun.push_back( iJunLeg1[i] );
813 for (int i = 1; i < int(iAntiMatch1.size()); ++i)
814 iPartonAntiJun.push_back( iAntiMatch1[i] );
816 // Remove junctions from their list. Done.
817 event.eraseJunction( max(identJun, identAnti) - 1);
818 event.eraseJunction( min(identJun, identAnti) - 1);
822 // Case where junction and antijunction to be separated.
823 // Shuffle (p+/p-) momentum of order <mThad> between systems,
824 // times 2/3 for 120 degree in JRF, times 1/2 for two legs,
825 // but not more than half of what nearest parton carries.
826 double eShift = MTHAD / (3. * sqrt(vJvAe2y));
827 double fracJ0 = min(0.5, eShift / pInJRF[0].e());
828 double fracJ1 = min(0.5, eShift / pInJRF[0].e());
829 Vec4 pFromJun = fracJ0 * pJunLeg0 + fracJ1 * pJunLeg1;
830 double fracA0 = min(0.5, eShift / pInARF[0].e());
831 double fracA1 = min(0.5, eShift / pInARF[0].e());
832 Vec4 pFromAnti = fracA0 * pAntiLeg0 + fracA1 * pAntiLeg1;
834 // Copy partons with scaled-down momenta and update legs.
835 int iNew = event.copy(iJunLeg0[1], 76);
836 event[iNew].rescale5(1. - fracJ0);
838 iNew = event.copy(iJunLeg1[1], 76);
839 event[iNew].rescale5(1. - fracJ1);
841 iNew = event.copy(iAntiLeg0[1], 76);
842 event[iNew].rescale5(1. - fracA0);
844 iNew = event.copy(iAntiLeg1[1], 76);
845 event[iNew].rescale5(1. - fracA1);
848 // Pick a new quark at random; for simplicity no diquarks.
849 int idQ = flavSel.pickLightQ();
851 // Update junction colours for new quark and antiquark.
852 int colQ = event.nextColTag();
853 int acolQ = event.nextColTag();
854 event.endColJunction(identJun - 1, legJun[0], colQ);
855 event.endColJunction(identAnti - 1, legAnti[0], acolQ);
857 // Store new quark and antiquark with momentum from other junction.
858 int mother1 = min(iJunLeg0[1], iJunLeg1[1]);
859 int mother2 = max(iJunLeg0[1], iJunLeg1[1]);
860 int iNewJ = event.append( idQ, 76, mother1, mother2, 0, 0,
861 colQ, 0, pFromAnti, pFromAnti.mCalc() );
862 mother1 = min(iAntiLeg0[1], iAntiLeg1[1]);
863 mother2 = max(iAntiLeg0[1], iAntiLeg1[1]);
864 int iNewA = event.append( -idQ, 76, mother1, mother2, 0, 0,
865 0, acolQ, pFromJun, pFromJun.mCalc() );
867 // Bookkeep new quark and antiquark on third legs.
868 if (legJun[0] == 0) iJunLegA[1] = iNewJ;
869 else if (legJun[0] == 1) iJunLegB[1] = iNewJ;
870 else iJunLegC[1] = iNewJ;
871 if (legAnti[0] == 0) iAntiLegA[1] = iNewA;
872 else if (legAnti[0] == 1) iAntiLegB[1] = iNewA;
873 else iAntiLegC[1] = iNewA;
875 // Done with splitting junction from antijunction.
878 // Put together new junction parton list.
879 iPartonJun.resize(0);
880 for (int i = 0; i < int(iJunLegA.size()); ++i)
881 iPartonJun.push_back( iJunLegA[i] );
882 for (int i = 0; i < int(iJunLegB.size()); ++i)
883 iPartonJun.push_back( iJunLegB[i] );
884 for (int i = 0; i < int(iJunLegC.size()); ++i)
885 iPartonJun.push_back( iJunLegC[i] );
887 // Put together new antijunction parton list.
888 iPartonAntiJun.resize(0);
889 for (int i = 0; i < int(iAntiLegA.size()); ++i)
890 iPartonAntiJun.push_back( iAntiLegA[i] );
891 for (int i = 0; i < int(iAntiLegB.size()); ++i)
892 iPartonAntiJun.push_back( iAntiLegB[i] );
893 for (int i = 0; i < int(iAntiLegC.size()); ++i)
894 iPartonAntiJun.push_back( iAntiLegC[i] );
896 // Now the two junction systems are separated and can be stored.
901 //**************************************************************************
903 } // end namespace Pythia8