9 #include "Pythia8/StringFragmentation.h"
22 const double StringEnd::TINY = 1e-6;
25 const double StringEnd::PT2SAME = 0.01;
31 void StringEnd::setUp(
bool fromPosIn,
int iEndIn,
int idOldIn,
int iMaxIn,
32 double pxIn,
double pyIn,
double GammaIn,
double xPosIn,
double xNegIn) {
38 flavOld = FlavContainer(idOldIn);
42 iPosOld = (fromPos) ? 0 : iMax;
43 iNegOld = (fromPos) ? iMax : 0;
53 void StringEnd::newHadron() {
57 flavNew = flavSelPtr->pick( flavOld);
58 idHad = flavSelPtr->combine( flavOld, flavNew);
62 pair<double, double> pxy = pTSelPtr->pxy();
65 pxHad = pxOld + pxNew;
66 pyHad = pyOld + pyNew;
69 mHad = particleDataPtr->mSel(idHad);
70 mT2Had = pow2(mHad) + pow2(pxHad) + pow2(pyHad);
79 Vec4 StringEnd::kinematicsHadron( StringSystem& system) {
82 zHad = zSelPtr->zFrag( flavOld.id, flavNew.id, mT2Had);
83 GammaNew = (1. - zHad) * (GammaOld + mT2Had / zHad);
87 int& iDirOld = (fromPos) ? iPosOld : iNegOld;
88 int& iInvOld = (fromPos) ? iNegOld : iPosOld;
89 int& iDirNew = (fromPos) ? iPosNew : iNegNew;
90 int& iInvNew = (fromPos) ? iNegNew : iPosNew;
91 double& xDirOld = (fromPos) ? xPosOld : xNegOld;
92 double& xInvOld = (fromPos) ? xNegOld : xPosOld;
93 double& xDirNew = (fromPos) ? xPosNew : xNegNew;
94 double& xInvNew = (fromPos) ? xNegNew : xPosNew;
95 double& xDirHad = (fromPos) ? xPosHad : xNegHad;
96 double& xInvHad = (fromPos) ? xNegHad : xPosHad;
104 for (
int iStep = 0; ; ++iStep) {
107 StringRegion& region = system.region( iPosNew, iNegNew);
110 if (iStep == 0 && iPosOld + iNegOld == iMax) {
113 if (mT2Had < zHad * xDirOld * (1. - xInvOld) * region.w2) {
116 xDirHad = zHad * xDirOld;
117 xInvHad = mT2Had / (xDirHad * region.w2);
118 xDirNew = xDirOld - xDirHad;
119 xInvNew = xInvOld + xInvHad;
122 return region.pHad( xPosHad, xNegHad, pxHad, pyHad);
128 if (iInvNew < 0)
return Vec4(0., 0., 0., -1.);
131 xInvHad = 1. - xInvOld;
133 pSoFar = region.pHad( xPosHad, xNegHad, pxOld, pyOld);
138 }
else if (iStep == 0) {
139 pSoFar = region.pHad( 0., 0., pxOld, pyOld);
140 pTNew = region.pHad( 0., 0., pxNew, pyNew);
145 if (!region.isSetUp) region.setUp(
146 system.regionLowPos(iPosNew).pPos,
147 system.regionLowNeg(iNegNew).pNeg,
true);
151 if (region.isEmpty) {
152 xDirHad = (iDirNew == iDirOld) ? xDirOld : 1.;
154 pSoFar += region.pHad( xPosHad, xNegHad, 0., 0.);
156 if (iDirNew + iInvNew > iMax)
return Vec4(0., 0., 0., -1.);
162 double pxNewTemp = -pTNew * region.eX;
163 double pyNewTemp = -pTNew * region.eY;
164 if (abs( pxNewTemp * pxNewTemp + pyNewTemp * pyNewTemp
165 - pxNew * pxNew - pyNew * pyNew) < PT2SAME) {
171 Vec4 pTemp = pSoFar + region.pHad( 0., 0., pxNew, pyNew);
175 double cM1 = pTemp.m2Calc();
176 double cM2 = 2. * (pTemp * region.pPos);
177 double cM3 = 2. * (pTemp * region.pNeg);
178 double cM4 = region.w2;
179 if (!fromPos) swap( cM2, cM3);
187 for (
int iInv = iInvNew; iInv <= iMax - iDirNew; ++iInv) {
189 if (iInv == iInvNew) xInv = (iInvNew == iInvOld) ? xInvOld : 0.;
190 for (
int iDir = iDirNew; iDir <= iMax - iInv; ++iDir) {
191 double xDir = (iDir == iDirOld) ? xDirOld : 1.;
192 int iPos = (fromPos) ? iDir : iInv;
193 int iNeg = (fromPos) ? iInv : iDir;
194 StringRegion& regionGam = system.region( iPos, iNeg);
195 if (!regionGam.isSetUp) regionGam.setUp(
196 system.regionLowPos(iPos).pPos,
197 system.regionLowNeg(iNeg).pNeg,
true);
198 double w2 = regionGam.w2;
199 cGam1 += xDir * xInv * w2;
200 if (iDir == iDirNew) cGam2 -= xInv * w2;
201 if (iInv == iInvNew) cGam3 += xDir * w2;
202 if (iDir == iDirNew && iInv == iInvNew) cGam4 -= w2;
207 double cM0 = pow2(mHad) - cM1;
208 double cGam0 = GammaNew - cGam1;
209 double r2 = cM3 * cGam4 - cM4 * cGam3;
210 double r1 = cM4 * cGam0 - cM0 * cGam4 + cM3 * cGam2 - cM2 * cGam3;
211 double r0 = cM2 * cGam0 - cM0 * cGam2;
212 double root = sqrtpos( r1*r1 - 4. * r2 * r0 );
213 if (abs(r2) < TINY || root < TINY)
return Vec4(0., 0., 0., -1.);
214 xInvHad = 0.5 * (root / abs(r2) - r1 / r2);
215 xDirHad = (cM0 - cM3 * xInvHad) / (cM2 + cM4 * xInvHad);
218 xDirNew = (iDirNew == iDirOld) ? xDirOld - xDirHad : 1. - xDirHad;
219 xInvNew = (iInvNew == iInvOld) ? xInvOld + xInvHad : xInvHad;
223 xInvHad = (iInvNew == iInvOld) ? 1. - xInvOld : 1.;
225 pSoFar += region.pHad( xPosHad, xNegHad, 0., 0.);
227 if (iInvNew < 0)
return Vec4(0., 0., 0., -1.);
231 }
else if (xDirNew < 0.) {
232 xDirHad = (iDirNew == iDirOld) ? xDirOld : 1.;
234 pSoFar += region.pHad( xPosHad, xNegHad, 0., 0.);
236 if (iDirNew + iInvNew > iMax)
return Vec4(0., 0., 0., -1.);
241 return pSoFar + region.pHad( xPosHad, xNegHad, pxNew, pyNew);
252 void StringEnd::update() {
254 flavOld.anti(flavNew);
275 const int StringFragmentation::NTRYFLAV = 10;
276 const int StringFragmentation::NTRYJOIN = 30;
279 const int StringFragmentation::NSTOPMASS = 15;
280 const double StringFragmentation::FACSTOPMASS = 1.05;
283 const double StringFragmentation::CLOSEDM2MAX = 25.;
284 const double StringFragmentation::CLOSEDM2FRAC = 0.1;
287 const double StringFragmentation::EXPMAX = 50.;
290 const double StringFragmentation::MATCHPOSNEG = 1e-6;
293 const double StringFragmentation::EJNWEIGHTMAX = 10.;
296 const double StringFragmentation::CONVJNREST = 1e-5;
297 const int StringFragmentation::NTRYJNREST = 20;
300 const int StringFragmentation::NTRYJNMATCH = 20;
301 const double StringFragmentation::EEXTRAJNMATCH = 0.5;
302 const double StringFragmentation::MDIQUARKMIN = -2.0;
305 const double StringFragmentation::M2MAXJRF = 1e-4;
308 const double StringFragmentation::CONVJRFEQ = 1e-12;
309 const int StringFragmentation::NTRYJRFEQ = 40;
315 void StringFragmentation::init(Info* infoPtrIn, Settings& settings,
316 ParticleData* particleDataPtrIn, Rndm* rndmPtrIn, StringFlav* flavSelPtrIn,
317 StringPT* pTSelPtrIn, StringZ* zSelPtrIn) {
321 particleDataPtr = particleDataPtrIn;
323 flavSelPtr = flavSelPtrIn;
324 pTSelPtr = pTSelPtrIn;
328 stopMass = zSelPtr->stopMass();
329 stopNewFlav = zSelPtr->stopNewFlav();
330 stopSmear = zSelPtr->stopSmear();
331 eNormJunction = settings.parm(
"StringFragmentation:eNormJunction");
333 = settings.parm(
"StringFragmentation:eBothLeftJunction");
335 = settings.parm(
"StringFragmentation:eMaxLeftJunction");
337 = settings.parm(
"StringFragmentation:eMinLeftJunction");
340 mJoin = settings.parm(
"FragmentationSystems:mJoin");
343 bLund = zSelPtr->bAreaLund();
346 hadrons.init(
"(string fragmentation)", particleDataPtr);
349 posEnd.init( particleDataPtr, flavSelPtr, pTSelPtr, zSelPtr);
350 negEnd.init( particleDataPtr, flavSelPtr, pTSelPtr, zSelPtr);
358 bool StringFragmentation::fragment(
int iSub, ColConfig& colConfig,
362 iParton = colConfig[iSub].iParton;
364 if (iPos < 0) iPos = iParton[1];
365 int idPos =
event[iPos].id();
366 iNeg = iParton.back();
367 int idNeg =
event[iNeg].id();
368 pSum = colConfig[iSub].pSum;
374 isClosed = colConfig[iSub].isClosed;
375 if (isClosed) iParton = findFirstRegion(iParton, event);
379 pJunctionHadrons = 0.;
380 hasJunction = colConfig[iSub].hasJunction;
381 if (hasJunction && !fragmentToJunction(event))
return false;
382 int junctionHadrons = hadrons.size();
384 idPos =
event[ iParton[0] ].id();
385 idNeg =
event.back().id();
386 pSum -= pJunctionHadrons;
390 system.setUp(iParton, event);
391 stopMassNow = stopMass;
395 for (
int iTry = 0; ; ++iTry) {
396 if (iTry > NTRYJOIN) {
397 infoPtr->errorMsg(
"Error in StringFragmentation::fragment: "
399 if (hasJunction) ++nExtraJoin;
400 if (nExtraJoin > 0)
event.popBack(nExtraJoin);
405 if (iTry == NTRYJOIN / 3) nExtraJoin = extraJoin( 2., event);
406 if (iTry == 2 * NTRYJOIN / 3) nExtraJoin += extraJoin( 4., event);
409 if (iTry > NTRYJOIN - NSTOPMASS) stopMassNow *= FACSTOPMASS;
412 setStartEnds(idPos, idNeg, system);
420 fromPos = (rndmPtr->flat() < 0.5);
421 StringEnd& nowEnd = (fromPos) ? posEnd : negEnd;
425 if ( energyUsedUp(fromPos) )
break;
428 Vec4 pHad = nowEnd.kinematicsHadron(system);
429 int statusHad = (fromPos) ? 83 : 84;
430 hadrons.append( nowEnd.idHad, statusHad, iPos, iNeg,
431 0, 0, 0, 0, pHad, nowEnd.mHad);
432 if (pHad.e() < 0.)
break;
442 if ( finalTwo(fromPos) )
break;
446 int newHadrons = hadrons.size() - junctionHadrons;
447 hadrons.popBack(newHadrons);
451 if (hasJunction) ++nExtraJoin;
452 if (nExtraJoin > 0) {
453 event.popBack(nExtraJoin);
454 iParton = colConfig[iSub].iParton;
469 vector<int> StringFragmentation::findFirstRegion(vector<int>& iPartonIn,
473 vector<double> m2Pair;
475 int size = iPartonIn.size();
476 for (
int i = 0; i < size; ++i) {
477 double m2Now = 0.5 *
event[ iPartonIn[i] ].p()
478 *
event[ iPartonIn[(i + 1)%size] ].p();
479 m2Pair.push_back(m2Now);
484 double m2Reg = m2Sum * rndmPtr->flat();
486 do m2Reg -= m2Pair[++iReg];
487 while (m2Reg > 0. && iReg < size - 1);
490 vector<int> iPartonOut;
491 for (
int i = 0; i < size + 2; ++i)
492 iPartonOut.push_back( iPartonIn[(i + iReg)%size] );
503 void StringFragmentation::setStartEnds(
int idPos,
int idNeg,
504 StringSystem systemNow) {
510 double xPosFromPos = 1.;
511 double xNegFromPos = 0.;
512 double xPosFromNeg = 0.;
513 double xNegFromNeg = 1.;
518 int idTry = flavSelPtr->pickLightQ();
519 FlavContainer flavTry(idTry, 1);
520 flavTry = flavSelPtr->pick( flavTry);
521 flavTry = flavSelPtr->pick( flavTry);
524 }
while (idPos == 0);
527 pair<double, double> pxy = pTSelPtr->pxy();
530 double m2Region = systemNow.regionLowPos(0).w2;
531 double m2Temp = min( CLOSEDM2MAX, CLOSEDM2FRAC * m2Region);
533 double zTemp = zSelPtr->zFrag( idPos, idNeg, m2Temp);
534 xPosFromPos = 1. - zTemp;
535 xNegFromPos = m2Temp / (zTemp * m2Region);
536 }
while (xNegFromPos > 1.);
537 Gamma = xPosFromPos * xNegFromPos * m2Region;
538 xPosFromNeg = xPosFromPos;
539 xNegFromNeg = xNegFromPos;
543 posEnd.setUp(
true, iPos, idPos, systemNow.iMax, px, py,
544 Gamma, xPosFromPos, xNegFromPos);
545 negEnd.setUp(
false, iNeg, idNeg, systemNow.iMax, -px, -py,
546 Gamma, xPosFromNeg, xNegFromNeg);
550 flavSelPtr->assignPopQ(posEnd.flavOld);
551 flavSelPtr->assignPopQ(negEnd.flavOld);
552 if (rndmPtr->flat() < 0.5) posEnd.flavOld.nPop = 0;
553 else negEnd.flavOld.nPop = 0;
554 posEnd.flavOld.rank = 1;
555 negEnd.flavOld.rank = 1;
566 bool StringFragmentation::energyUsedUp(
bool fromPos) {
569 if (pRem.e() < 0.)
return true;
572 double wMin = stopMassNow
573 + particleDataPtr->constituentMass(posEnd.flavOld.id)
574 + particleDataPtr->constituentMass(negEnd.flavOld.id);
575 if (fromPos) wMin += stopNewFlav
576 * particleDataPtr->constituentMass(posEnd.flavNew.id);
577 else wMin += stopNewFlav
578 * particleDataPtr->constituentMass(negEnd.flavNew.id);
579 wMin *= 1. + (2. * rndmPtr->flat() - 1.) * stopSmear;
580 w2Rem = pRem.m2Calc();
581 if (w2Rem < pow2(wMin))
return true;
592 bool StringFragmentation::finalTwo(
bool fromPos) {
595 if (pRem.e() < 0. || w2Rem < 0. || (hadrons.size() > 0
596 && hadrons.back().e() < 0.) )
return false;
597 if ( posEnd.iPosOld > negEnd.iPosOld || negEnd.iNegOld > posEnd.iNegOld)
599 if ( posEnd.iPosOld == negEnd.iPosOld && posEnd.xPosOld < negEnd.xPosOld)
601 if ( posEnd.iNegOld == negEnd.iNegOld && posEnd.xNegOld > negEnd.xNegOld)
606 FlavContainer flav1 = (fromPos) ? posEnd.flavNew.anti() : posEnd.flavOld;
607 FlavContainer flav2 = (fromPos) ? negEnd.flavOld : negEnd.flavNew.anti();
608 if (flav1.isDiquark() && flav2.isDiquark())
return false;
610 for (
int iTry = 0; iTry < NTRYFLAV; ++iTry) {
611 idHad = flavSelPtr->combine( flav1, flav2);
612 if (idHad != 0)
break;
614 if (idHad == 0)
return false;
618 negEnd.idHad = idHad;
619 negEnd.pxNew = -posEnd.pxNew;
620 negEnd.pyNew = -posEnd.pyNew;
621 negEnd.mHad = particleDataPtr->mSel(idHad);
623 posEnd.idHad = idHad;
624 posEnd.pxNew = -negEnd.pxNew;
625 posEnd.pyNew = -negEnd.pyNew;
626 posEnd.mHad = particleDataPtr->mSel(idHad);
630 StringRegion region = finalRegion();
631 if (region.isEmpty)
return false;
634 region.project( pRem);
635 double pxRem = region.px() - posEnd.pxOld - negEnd.pxOld;
636 double pyRem = region.py() - posEnd.pyOld - negEnd.pyOld;
637 double xPosRem = region.xPos();
638 double xNegRem = region.xNeg();
641 posEnd.pxOld += 0.5 * pxRem;
642 posEnd.pyOld += 0.5 * pyRem;
643 negEnd.pxOld += 0.5 * pxRem;
644 negEnd.pyOld += 0.5 * pyRem;
647 posEnd.pxHad = posEnd.pxOld + posEnd.pxNew;
648 posEnd.pyHad = posEnd.pyOld + posEnd.pyNew;
649 posEnd.mT2Had = pow2(posEnd.mHad) + pow2(posEnd.pxHad)
650 + pow2(posEnd.pyHad);
651 negEnd.pxHad = negEnd.pxOld + negEnd.pxNew;
652 negEnd.pyHad = negEnd.pyOld + negEnd.pyNew;
653 negEnd.mT2Had = pow2(negEnd.mHad) + pow2(negEnd.pxHad)
654 + pow2(negEnd.pyHad);
657 double wT2Rem = w2Rem + pow2( posEnd.pxHad + negEnd.pxHad)
658 + pow2( posEnd.pyHad + negEnd.pyHad);
661 if ( sqrt(wT2Rem) < sqrt(posEnd.mT2Had) + sqrt(negEnd.mT2Had) )
663 double lambda2 = pow2( wT2Rem - posEnd.mT2Had - negEnd.mT2Had)
664 - 4. * posEnd.mT2Had * negEnd.mT2Had;
665 if (lambda2 <= 0.)
return false;
668 double lambda = sqrt(lambda2);
669 double probReverse = 1. / (1. + exp( min( EXPMAX, bLund * lambda) ) );
670 double xpzPos = 0.5 * lambda/ wT2Rem;
671 if (probReverse > rndmPtr->flat()) xpzPos = -xpzPos;
672 double xmDiff = (posEnd.mT2Had - negEnd.mT2Had) / wT2Rem;
673 double xePos = 0.5 * (1. + xmDiff);
674 double xeNeg = 0.5 * (1. - xmDiff );
677 Vec4 pHadPos = region.pHad( (xePos + xpzPos) * xPosRem,
678 (xePos - xpzPos) * xNegRem, posEnd.pxHad, posEnd.pyHad);
679 Vec4 pHadNeg = region.pHad( (xeNeg - xpzPos) * xPosRem,
680 (xeNeg + xpzPos) * xNegRem, negEnd.pxHad, negEnd.pyHad);
683 hadrons.append( posEnd.idHad, 83, posEnd.iEnd, negEnd.iEnd,
684 0, 0, 0, 0, pHadPos, posEnd.mHad);
685 hadrons.append( negEnd.idHad, 84, posEnd.iEnd, negEnd.iEnd,
686 0, 0, 0, 0, pHadNeg, negEnd.mHad);
697 StringRegion StringFragmentation::finalRegion() {
700 if (posEnd.iPosOld == negEnd.iPosOld && posEnd.iNegOld == negEnd.iNegOld)
701 return system.region( posEnd.iPosOld, posEnd.iNegOld);
708 if ( posEnd.iPosOld == negEnd.iPosOld) {
709 double xPosJoin = posEnd.xPosOld - negEnd.xPosOld;
710 if (xPosJoin < 0.)
return region;
711 pPosJoin = system.regionLowPos(posEnd.iPosOld).pHad( xPosJoin, 0., 0., 0.);
713 for (
int iPosNow = posEnd.iPosOld; iPosNow <= negEnd.iPosOld; ++iPosNow) {
714 if (iPosNow == posEnd.iPosOld) pPosJoin
715 += system.regionLowPos(iPosNow).pHad( posEnd.xPosOld, 0., 0., 0.);
716 else if (iPosNow == negEnd.iPosOld) pPosJoin
717 += system.regionLowPos(iPosNow).pHad( 1. - negEnd.xPosOld, 0., 0., 0.);
718 else pPosJoin += system.regionLowPos(iPosNow).pHad( 1., 0., 0., 0.);
724 if ( negEnd.iNegOld == posEnd.iNegOld) {
725 double xNegJoin = negEnd.xNegOld - posEnd.xNegOld;
726 if (xNegJoin < 0.)
return region;
727 pNegJoin = system.regionLowNeg(negEnd.iNegOld).pHad( 0., xNegJoin, 0., 0.);
729 for (
int iNegNow = negEnd.iNegOld; iNegNow <= posEnd.iNegOld; ++iNegNow) {
730 if (iNegNow == negEnd.iNegOld) pNegJoin
731 += system.regionLowNeg(iNegNow).pHad( 0., negEnd.xNegOld, 0., 0.);
732 else if (iNegNow == posEnd.iNegOld) pNegJoin
733 += system.regionLowNeg(iNegNow).pHad( 0., 1. - posEnd.xNegOld, 0., 0.);
734 else pNegJoin += system.regionLowNeg(iNegNow).pHad( 0., 1., 0., 0.);
740 Vec4 pTest = pPosJoin - pNegJoin;
741 if ( abs(pTest.px()) + abs(pTest.py()) + abs(pTest.pz()) + abs(pTest.e())
742 < MATCHPOSNEG * (pPosJoin.e() + pNegJoin.e()) ) {
744 = system.regionLowPos(posEnd.iPosOld + 1).pHad( 1., 0., 0., 0.)
745 - system.regionLowNeg(negEnd.iNegOld + 1).pHad( 0., 1., 0., 0.);
751 region.setUp( pPosJoin, pNegJoin);
752 if (region.isEmpty)
return region;
755 Vec4 pTposOld = system.region( posEnd.iPosOld, posEnd.iNegOld).pHad(
756 0., 0., posEnd.pxOld, posEnd.pyOld);
757 region.project( pTposOld);
758 posEnd.pxOld = region.px();
759 posEnd.pyOld = region.py();
760 Vec4 pTnegOld = system.region( negEnd.iPosOld, negEnd.iNegOld).pHad(
761 0., 0., negEnd.pxOld, negEnd.pyOld);
762 region.project( pTnegOld);
763 negEnd.pxOld = region.px();
764 negEnd.pyOld = region.py();
775 void StringFragmentation::store(
Event& event) {
778 int iFirst =
event.size();
782 for (
int i = 0; i < hadrons.size(); ++i)
783 if (hadrons[i].status() == 85 || hadrons[i].status() == 86)
784 event.append( hadrons[i] );
788 for (
int i = 0; i < hadrons.size(); ++i)
789 if (hadrons[i].status() == 83) event.append( hadrons[i] );
792 for (
int i = hadrons.size() - 1; i >= 0 ; --i)
793 if (hadrons[i].status() == 84) event.append( hadrons[i] );
794 int iLast =
event.size() - 1;
797 if (event[posEnd.iEnd].hasVertex()) {
798 Vec4 vDec =
event[posEnd.iEnd].vDec();
799 for (
int i = iFirst; i <= iLast; ++i) event[i].vProd( vDec );
803 for (
int i = iFirst; i <= iLast; ++i)
804 event[i].tau( event[i].tau0() * rndmPtr->exp() );
807 for (
int i = 0; i < int(iParton.size()); ++i)
808 if (iParton[i] >= 0) {
809 event[ iParton[i] ].statusNeg();
810 event[ iParton[i] ].daughters(iFirst, iLast);
819 bool StringFragmentation::fragmentToJunction(
Event& event) {
824 int legBeg[3] = { 0, 0, 0};
825 int legEnd[3] = { 0, 0, 0};
828 if (iParton[0] > 0) {
829 infoPtr->errorMsg(
"Error in StringFragmentation::fragment"
830 "ToJunction: iParton[0] not a valid junctionNumber");
833 for (
int i = 0; i < int(iParton.size()); ++i) {
834 if (iParton[i] < 0) {
836 infoPtr->errorMsg(
"Error in StringFragmentation::fragment"
837 "ToJunction: unprocessed multi-junction system");
840 legBeg[++leg] = i + 1;
842 else legEnd[leg] = i;
846 RotBstMatrix MtoJRF, Mstep;
847 MtoJRF.bstback(pSum);
855 for (leg = 0; leg < 3; ++ leg) {
858 for (
int i = legBeg[leg]; i <= legEnd[leg]; ++i) {
859 Vec4 pTemp =
event[ iParton[i] ].p();
860 pTemp.rotbst(MtoJRF);
861 pWTinJRF[leg] += pTemp * exp(-eWeight);
862 eWeight += pTemp.e() / eNormJunction;
863 if (eWeight > EJNWEIGHTMAX)
break;
868 if (iter == 1) errInCM = pow2(costheta(pWTinJRF[0], pWTinJRF[1]) + 0.5)
869 + pow2(costheta(pWTinJRF[0], pWTinJRF[2]) + 0.5)
870 + pow2(costheta(pWTinJRF[1], pWTinJRF[2]) + 0.5);
873 Mstep = junctionRestFrame( pWTinJRF[0], pWTinJRF[1], pWTinJRF[2]);
876 MtoJRF.rotbst( Mstep );
877 }
while (iter < 3 || (Mstep.deviation() > CONVJNREST && iter < NTRYJNREST) );
880 double errInJRF = pow2(costheta(pWTinJRF[0], pWTinJRF[1]) + 0.5)
881 + pow2(costheta(pWTinJRF[0], pWTinJRF[2]) + 0.5)
882 + pow2(costheta(pWTinJRF[1], pWTinJRF[2]) + 0.5);
883 if (errInJRF > errInCM + CONVJNREST) {
884 infoPtr->errorMsg(
"Warning in StringFragmentation::fragmentTo"
885 "Junction: bad convergence junction rest frame");
887 MtoJRF.bstback(pSum);
891 RotBstMatrix MfromJRF = MtoJRF;
895 Vec4 pInLeg[3], pInJRF[3];
896 for (leg = 0; leg < 3; ++leg) {
898 for (
int i = legBeg[leg]; i <= legEnd[leg]; ++i)
899 pInLeg[leg] += event[ iParton[i] ].p();
900 pInJRF[leg] = pInLeg[leg];
901 pInJRF[leg].rotbst(MtoJRF);
905 int legMin = (pInJRF[0].e() < pInJRF[1].e()) ? 0 : 1;
906 int legMax = 1 - legMin;
907 if (pInJRF[2].e() < min(pInJRF[0].e(), pInJRF[1].e()) ) legMin = 2;
908 else if (pInJRF[2].e() > max(pInJRF[0].e(), pInJRF[1].e()) ) legMax = 2;
909 int legMid = 3 - legMin - legMax;
912 int iJunction = (-iParton[0]) / 10 - 1;
913 event.statusJunction( iJunction, legMin, 85);
914 event.statusJunction( iJunction, legMid, 86);
915 event.statusJunction( iJunction, legMax, 83);
919 vector<int> iPartonMin;
920 for (
int i = legEnd[legMin]; i >= legBeg[legMin]; --i) {
921 int iNew =
event.append( event[ iParton[i] ] );
922 event[iNew].rotbst(MtoJRF);
923 iPartonMin.push_back( iNew );
925 vector<int> iPartonMid;
926 for (
int i = legEnd[legMid]; i >= legBeg[legMid]; --i) {
927 int iNew =
event.append( event[ iParton[i] ] );
928 event[iNew].rotbst(MtoJRF);
929 iPartonMid.push_back( iNew );
934 pWTinJRF[legMin] = 0.;
935 for (
int i = iPartonMin.size() - 1; i >= 0; --i) {
936 pWTinJRF[legMin] +=
event[ iPartonMin[i] ].p() * exp(-eWeight);
937 eWeight +=
event[ iPartonMin[i] ].e() / eNormJunction;
938 if (eWeight > EJNWEIGHTMAX)
break;
941 pWTinJRF[legMid] = 0.;
942 for (
int i = iPartonMid.size() - 1; i >= 0; --i) {
943 pWTinJRF[legMid] +=
event[ iPartonMid[i] ].p() * exp(-eWeight);
944 eWeight +=
event[ iPartonMid[i] ].e() / eNormJunction;
945 if (eWeight > EJNWEIGHTMAX)
break;
949 Vec4 pOppose = pWTinJRF[legMin];
951 int idOppose = (rndmPtr->flat() > 0.5) ? 2 : 1;
952 if (event[ iPartonMin[0] ].col() > 0) idOppose = -idOppose;
953 int iOppose =
event.append( idOppose, 77, 0, 0, 0, 0, 0, 0,
955 iPartonMin.push_back( iOppose);
956 pOppose = pWTinJRF[legMid];
958 idOppose = (rndmPtr->flat() > 0.5) ? 2 : 1;
959 if (event[ iPartonMid[0] ].col() > 0) idOppose = -idOppose;
960 iOppose =
event.append( idOppose, 77, 0, 0, 0, 0, 0, 0,
962 iPartonMid.push_back( iOppose);
965 systemMin.setUp(iPartonMin, event);
966 systemMid.setUp(iPartonMid, event);
972 for (
int iTryOuter = 0; ; ++iTryOuter) {
975 double eLeftMin = 0.;
976 double eLeftMid = 0.;
977 for (
int iTryMiddle = 0; ; ++iTryMiddle) {
980 for (
int legLoop = 0; legLoop < 2; ++ legLoop) {
981 int legNow = (legLoop == 0) ? legMin : legMid;
984 StringSystem& systemNow = (legLoop == 0) ? systemMin : systemMid;
985 int idPos = (legLoop == 0) ? event[ iPartonMin[0] ].
id()
986 :
event[ iPartonMid[0] ].id();
987 idOppose = (legLoop == 0) ? event[ iPartonMin.back() ].id()
988 :
event[ iPartonMid.back() ].id();
989 double eInJRF = pInJRF[legNow].e();
990 int statusHad = (legLoop == 0) ? 85 : 86;
994 for (
int iTryInner = 0; ; ++iTryInner) {
995 if (iTryInner > 2 * NTRYJNMATCH) {
996 infoPtr->errorMsg(
"Error in StringFragmentation::fragment"
997 "ToJunction: caught in junction flavour loop");
998 event.popBack( iPartonMin.size() + iPartonMid.size() );
1001 bool needBaryon = (abs(idPos) > 10 && iTryInner > NTRYJNMATCH);
1002 double eExtra = (iTryInner > NTRYJNMATCH) ? EEXTRAJNMATCH : 0.;
1005 setStartEnds(idPos, idOppose, systemNow);
1009 for ( ; ; ++nHadrons) {
1013 Vec4 pHad = posEnd.kinematicsHadron(systemNow);
1016 if (pHad.e() < 0. ) { noNegE =
false;
break; }
1020 bool delayedBreak =
false;
1021 if (eUsed + pHad.e() + eExtra > eInJRF) {
1022 if (nHadrons > 0 || !needBaryon)
break;
1023 delayedBreak =
true;
1027 hadrons.append( posEnd.idHad, statusHad, iPos, iNeg,
1028 0, 0, 0, 0, pHad, posEnd.mHad);
1042 if (iTryInner > NTRYJNMATCH && !noNegE && nHadrons == 0 &&
1043 abs(idPos) < 10)
break;
1046 if ( noNegE && abs(posEnd.flavOld.id) < 10 )
break;
1047 hadrons.popBack(nHadrons);
1051 if (legNow == legMin) {
1052 idMin = posEnd.flavOld.id;
1053 eLeftMin = eInJRF - eUsed;
1055 idMid = posEnd.flavOld.id;
1056 eLeftMid = eInJRF - eUsed;
1062 double eTrial = eBothLeftJunction + rndmPtr->flat() * eMaxLeftJunction;
1063 if (iTryMiddle > NTRYJNMATCH
1064 || ( min( eLeftMin, eLeftMid) < eBothLeftJunction
1065 && max( eLeftMin, eLeftMid) < eTrial ) )
break;
1070 for (
int i = 0; i < hadrons.size(); ++i) {
1071 hadrons[i].rotbst(MfromJRF);
1074 hadrons[i].e( hadrons[i].eCalc() );
1075 pJunctionHadrons += hadrons[i].p();
1080 pDiquark = pInLeg[legMin] + pInLeg[legMid] - pJunctionHadrons;
1081 double m2Left = m2( pInLeg[legMax], pDiquark);
1082 if (iTryOuter > NTRYJNMATCH || (pDiquark.mCalc() > MDIQUARKMIN
1083 && m2Left > eMinLeftJunction * pInLeg[legMax].e()) )
break;
1085 pJunctionHadrons = 0.;
1089 event.popBack( iPartonMin.size() + iPartonMid.size() );
1093 int idDiquark = flavSelPtr->makeDiquark( idMin, idMid);
1094 double mDiquark = pDiquark.mCalc();
1095 int iDiquark =
event.append( idDiquark, 78, 0, 0, 0, 0, 0, 0,
1096 pDiquark, mDiquark);
1099 vector<int> iPartonMax;
1100 for (
int i = legEnd[legMax]; i >= legBeg[legMax]; --i)
1101 iPartonMax.push_back( iParton[i] );
1102 iPartonMax.push_back( iDiquark );
1105 int iPsize = iPartonMax.size();
1106 double m0Diquark =
event[iDiquark].m0();
1107 while (iPsize > 2) {
1108 Vec4 pGluNear =
event[ iPartonMax[iPsize - 2] ].p();
1109 if ( (pDiquark + 0.5 * pGluNear).mCalc() > m0Diquark + mJoin )
break;
1110 pDiquark += pGluNear;
1111 event[iDiquark].p( pDiquark );
1112 event[iDiquark].m( pDiquark.mCalc() );
1113 iPartonMax.pop_back();
1115 iPartonMax[iPsize - 1] = iDiquark;
1119 iParton = iPartonMax;
1130 RotBstMatrix StringFragmentation::junctionRestFrame(Vec4& p0, Vec4& p1,
1134 Vec4 pSumJun = p0 + p1 + p2;
1135 double sHat = pSumJun.m2Calc();
1137 pp[0][0] = p0.m2Calc();
1138 pp[1][1] = p1.m2Calc();
1139 pp[2][2] = p2.m2Calc();
1140 pp[0][1] = pp[1][0] = p0 * p1;
1141 pp[0][2] = pp[2][0] = p0 * p2;
1142 pp[1][2] = pp[2][1] = p1 * p2;
1146 double eMax01 = pow2(pp[0][1]) * pp[2][2];
1147 double eMax02 = pow2(pp[0][2]) * pp[1][1];
1148 double eMax12 = pow2(pp[1][2]) * pp[0][0];
1151 int i = (pp[1][1] > pp[0][0]) ? 1 : 0;
1152 if (pp[2][2] > max(pp[0][0], pp[1][1])) i = 2;
1157 for (
int iTry = 0; iTry < 3; ++iTry) {
1160 if (i == 0) j = (eMax02 < eMax01) ? 2 : 1;
1161 else if (i == 1) j = (eMax12 < eMax01) ? 2 : 0;
1162 else j = (eMax12 < eMax02) ? 1 : 0;
1166 double m2i = pp[i][i];
1167 double m2j = pp[j][j];
1168 double m2k = pp[k][k];
1169 double pipj = pp[i][j];
1170 double pipk = pp[i][k];
1171 double pjpk = pp[j][k];
1174 if (m2i < M2MAXJRF) {
1175 ei = sqrt( 2. * pipk * pipj / (3. * pjpk) );
1176 ej = sqrt( 2. * pjpk * pipj / (3. * pipk) );
1177 ek = sqrt( 2. * pipk * pjpk / (3. * pipj) );
1183 double eiMin = sqrt(m2i);
1184 double ejMin = pipj / eiMin;
1185 double ekMin = pipk / eiMin;
1186 double pjMin = sqrtpos( ejMin*ejMin - m2j );
1187 double pkMin = sqrtpos( ekMin*ekMin - m2k );
1188 double fMin = ejMin * ekMin + 0.5 * pjMin * pkMin - pjpk;
1190 double eiMax = (pipj + pipk) / sqrt(m2j + m2k + 2. * pjpk);
1191 if (m2j > M2MAXJRF) eiMax = min( eiMax, pipj / sqrt(m2j) );
1192 double piMax = sqrtpos( eiMax*eiMax - m2i );
1193 double temp = eiMax*eiMax - 0.25 *piMax*piMax;
1194 double pjMax = (eiMax * sqrtpos( pipj*pipj - m2j * temp )
1195 - 0.5 * piMax * pipj) / temp;
1196 double pkMax = (eiMax * sqrtpos( pipk*pipk - m2k * temp )
1197 - 0.5 * piMax * pipk) / temp;
1198 double ejMax = sqrt(pjMax*pjMax + m2j);
1199 double ekMax = sqrt(pkMax*pkMax + m2k);
1200 double fMax = ejMax * ekMax + 0.5 * pjMax * pkMax - pjpk;
1204 int iPrel = (i + 1)%3;
1205 if (pp[iPrel][iPrel] > M2MAXJRF) {i = iPrel;
continue;}
1208 if (iTry < 3 && pp[iPrel][iPrel] > M2MAXJRF) {i = iPrel;
continue;}
1214 double pi = 0.5 * (piMin + piMax);
1215 for (
int iter = 0; iter < NTRYJRFEQ; ++iter) {
1218 ei = sqrt(pi*pi + m2i);
1219 temp = ei*ei - 0.25 * pi*pi;
1220 double pj = (ei * sqrtpos( pipj*pipj - m2j * temp )
1221 - 0.5 * pi * pipj) / temp;
1222 double pk = (ei * sqrtpos( pipk*pipk - m2k * temp )
1223 - 0.5 * pi * pipk) / temp;
1224 ej = sqrt(pj*pj + m2j);
1225 ek = sqrt(pk*pk + m2k);
1226 double fNow = ej * ek + 0.5 * pj * pk - pjpk;
1229 if (fNow > 0.) { ++iterMin; piMin = pi; fMin = fNow;}
1230 else {++iterMax; piMax = pi; fMax = fNow;}
1233 if (2 * iter < NTRYJRFEQ
1234 && (iterMin < 2 || iterMax < 2 || 4 * iter < NTRYJRFEQ))
1235 { pi = 0.5 * (piMin + piMax);
continue;}
1236 if (fMin < 0. || fMax > 0. || abs(fNow) < CONVJRFEQ * sHat)
break;
1237 pi = piMin + (piMax - piMin) * fMin / (fMin - fMax);
1245 double eNew[3] = { 0., 0., 0.};
1255 Mmove.bstback(pSumJun);
1261 Vec4 pDir01 = p0cm / p0cm.e() - p1cm / p1cm.e();
1262 Vec4 pDir02 = p0cm / p0cm.e() - p2cm / p2cm.e();
1263 double pDiff01 = pDir01.pAbs2();
1264 double pDiff02 = pDir02.pAbs2();
1265 double pDiff0102 = dot3(pDir01, pDir02);
1266 double eDiff01 = eNew[0] / p0cm.e() - eNew[1] / p1cm.e();
1267 double eDiff02 = eNew[0] / p0cm.e() - eNew[2] / p2cm.e();
1268 double denom = pDiff01 * pDiff02 - pDiff0102*pDiff0102;
1269 double coef01 = (eDiff01 * pDiff02 - eDiff02 * pDiff0102) / denom;
1270 double coef02 = (eDiff02 * pDiff01 - eDiff01 * pDiff0102) / denom;
1271 Vec4 vJunction = coef01 * pDir01 + coef02 * pDir02;
1272 vJunction.e( sqrt(1. + vJunction.pAbs2()) );
1275 Mmove.bst(vJunction);
1285 int StringFragmentation::extraJoin(
double facExtra,
Event& event) {
1289 int iPsize = iParton.size();
1290 while (iPsize > 2) {
1295 double mJoinMin = 2. * facExtra * mJoin;
1296 for (
int i = 0; i < iPsize - 1; ++i) {
1297 Particle& parton1 =
event[ iParton[i] ];
1298 Particle& parton2 =
event[ iParton[i + 1] ];
1300 pSumNow += (parton2.isGluon()) ? 0.5 * parton1.p() : parton1.p();
1301 pSumNow += (parton2.isGluon()) ? 0.5 * parton2.p() : parton2.p();
1302 double mJoinNow = pSumNow.mCalc();
1303 if (!parton1.isGluon()) mJoinNow -= parton1.m0();
1304 if (!parton2.isGluon()) mJoinNow -= parton2.m0();
1305 if (mJoinNow < mJoinMin) { iJoinMin = i; mJoinMin = mJoinNow; }
1309 if (iJoinMin < 0 || mJoinMin > facExtra * mJoin)
return nJoin;
1313 int iJoin1 = iParton[iJoinMin];
1314 int iJoin2 = iParton[iJoinMin + 1];
1315 int idNew = (
event[iJoin1].isGluon()) ? event[iJoin2].
id()
1316 :
event[iJoin1].id();
1317 int colNew =
event[iJoin1].col();
1318 int acolNew =
event[iJoin2].acol();
1319 if (colNew == acolNew) {
1320 colNew =
event[iJoin2].col();
1321 acolNew =
event[iJoin1].acol();
1323 Vec4 pNew =
event[iJoin1].p() +
event[iJoin2].p();
1326 int iNew =
event.append( idNew, 73, min(iJoin1, iJoin2),
1327 max(iJoin1, iJoin2), 0, 0, colNew, acolNew, pNew, pNew.mCalc() );
1328 iParton[iJoinMin] = iNew;
1329 for (
int i = iJoinMin + 1; i < iPsize - 1; ++i)
1330 iParton[i] = iParton[i + 1];