1 // ParticleDecays.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2010 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 // ParticleDecays class.
9 #include "ParticleDecays.h"
13 //==========================================================================
15 // The ParticleDecays class.
17 //--------------------------------------------------------------------------
19 // Constants: could be changed here if desired, but normally should not.
20 // These are of technical nature, as described for each.
22 // Number of times one tries to let decay happen (for 2 nested loops).
23 const int ParticleDecays::NTRYDECAY = 10;
25 // Number of times one tries to pick valid hadronic content in decay.
26 const int ParticleDecays::NTRYPICK = 100;
28 // Number of times one tries to pick decay topology.
29 const int ParticleDecays::NTRYMEWT = 1000;
31 // Maximal loop count in Dalitz decay treatment.
32 const int ParticleDecays::NTRYDALITZ = 1000;
34 // Minimal Dalitz pair mass this factor above threshold.
35 const double ParticleDecays::MSAFEDALITZ = 1.000001;
37 // These numbers are hardwired empirical parameters,
38 // intended to speed up the M-generator.
39 const double ParticleDecays::WTCORRECTION[11] = { 1., 1., 1.,
40 2., 5., 15., 60., 250., 1250., 7000., 50000. };
42 //--------------------------------------------------------------------------
44 // Initialize and save pointers.
46 void ParticleDecays::init(Info* infoPtrIn, Settings& settings,
47 ParticleData* particleDataPtrIn, Rndm* rndmPtrIn,
48 Couplings* couplingsPtrIn, TimeShower* timesDecPtrIn,
49 StringFlav* flavSelPtrIn, DecayHandler* decayHandlePtrIn,
50 vector<int> handledParticles) {
52 // Save pointers to error messages handling and flavour generation.
54 particleDataPtr = particleDataPtrIn;
56 couplingsPtr = couplingsPtrIn;
57 flavSelPtr = flavSelPtrIn;
59 // Save pointer to timelike shower, as needed in some few decays.
60 timesDecPtr = timesDecPtrIn;
62 // Save pointer for external handling of some decays.
63 decayHandlePtr = decayHandlePtrIn;
65 // Set which particles should be handled externally.
66 if (decayHandlePtr != 0)
67 for (int i = 0; i < int(handledParticles.size()); ++i)
68 particleDataPtr->doExternalDecay(handledParticles[i], true);
70 // Safety margin in mass to avoid troubles.
71 mSafety = settings.parm("ParticleDecays:mSafety");
73 // Lifetime and vertex rules for determining whether decay allowed.
74 limitTau0 = settings.flag("ParticleDecays:limitTau0");
75 tau0Max = settings.parm("ParticleDecays:tau0Max");
76 limitTau = settings.flag("ParticleDecays:limitTau");
77 tauMax = settings.parm("ParticleDecays:tauMax");
78 limitRadius = settings.flag("ParticleDecays:limitRadius");
79 rMax = settings.parm("ParticleDecays:rMax");
80 limitCylinder = settings.flag("ParticleDecays:limitCylinder");
81 xyMax = settings.parm("ParticleDecays:xyMax");
82 zMax = settings.parm("ParticleDecays:zMax");
83 limitDecay = limitTau0 || limitTau || limitRadius || limitCylinder;
85 // B-Bbar mixing parameters.
86 mixB = settings.flag("ParticleDecays:mixB");
87 xBdMix = settings.parm("ParticleDecays:xBdMix");
88 xBsMix = settings.parm("ParticleDecays:xBsMix");
90 // Suppression of extra-hadron momenta in semileptonic decays.
91 sigmaSoft = settings.parm("ParticleDecays:sigmaSoft");
93 // Selection of multiplicity and colours in "phase space" model.
94 multIncrease = settings.parm("ParticleDecays:multIncrease");
95 multRefMass = settings.parm("ParticleDecays:multRefMass");
96 multGoffset = settings.parm("ParticleDecays:multGoffset");
97 colRearrange = settings.parm("ParticleDecays:colRearrange");
99 // Minimum energy in system (+ m_q) from StringFragmentation.
100 stopMass = settings.parm("StringFragmentation:stopMass");
102 // Parameters for Dalitz decay virtual gamma mass spectrum.
103 sRhoDal = pow2(particleDataPtr->m0(113));
104 wRhoDal = pow2(particleDataPtr->mWidth(113));
106 // Allow showers in decays to qqbar/gg/ggg/gammagg.
107 doFSRinDecays = settings.flag("ParticleDecays:FSRinDecays");
111 //--------------------------------------------------------------------------
113 // Decay a particle; main method.
115 bool ParticleDecays::decay( int iDec, Event& event) {
117 // Check whether a decay is allowed, given the upcoming decay vertex.
118 Particle& decayer = event[iDec];
121 if (limitDecay && !checkVertex(decayer)) return true;
123 // Fill the decaying particle in slot 0 of arrays.
124 idDec = decayer.id();
128 iProd.push_back( iDec );
129 idProd.push_back( idDec );
130 mProd.push_back( decayer.m() );
132 // Check for oscillations B0 <-> B0bar or B_s0 <-> B_s0bar.
133 bool hasOscillated = (abs(idDec) == 511 || abs(idDec) == 531)
134 ? oscillateB(decayer) : false;
135 if (hasOscillated) {idDec = - idDec; idProd[0] = idDec;}
137 // Particle data for decaying particle.
138 decDataPtr = &decayer.particleDataEntry();
140 // Optionally send on to external decay program.
141 bool doneExternally = false;
142 if (decDataPtr->doExternalDecay()) {
144 pProd.push_back(decayer.p());
145 doneExternally = decayHandlePtr->decay(idProd, mProd, pProd,
148 // If it worked, then store the decay products in the event record.
149 if (doneExternally) {
150 mult = idProd.size() - 1;
151 int status = (hasOscillated) ? 94 : 93;
152 for (int i = 1; i <= mult; ++i) {
153 int iPos = event.append( idProd[i], status, iDec, 0, 0, 0,
154 0, 0, pProd[i], mProd[i]);
155 iProd.push_back( iPos);
158 // Also mark mother decayed and store daughters.
159 event[iDec].statusNeg();
160 event[iDec].daughters( iProd[1], iProd[mult]);
164 // Now begin normal internal decay treatment.
165 if (!doneExternally) {
167 // Allow up to ten tries to pick a channel.
168 if (!decDataPtr->preparePick(idDec)) return false;
169 bool foundChannel = false;
170 bool hasStored = false;
171 for (int iTryChannel = 0; iTryChannel < NTRYDECAY; ++iTryChannel) {
173 // Remove previous failed channel.
174 if (hasStored) event.popBack(mult);
177 // Pick new channel. Read out basics.
178 DecayChannel& channel = decDataPtr->pickChannel();
179 meMode = channel.meMode();
180 keepPartons = (meMode > 90 && meMode <= 100);
181 mult = channel.multiplicity();
183 // Allow up to ten tries for each channel (e.g with different masses).
184 bool foundMode = false;
185 for (int iTryMode = 0; iTryMode < NTRYDECAY; ++iTryMode) {
190 // Extract and store the decay products in local arrays.
192 for (int i = 0; i < mult; ++i) {
193 int idNow = channel.product(i);
194 int idAbs = abs(idNow);
195 if ( idAbs < 10 || idAbs == 21 || idAbs == 81 || idAbs == 82
196 || idAbs == 83 || (idAbs > 1000 && idAbs < 10000
197 && (idAbs/10)%10 == 0) ) hasPartons = true;
198 if (idDec < 0 && particleDataPtr->hasAnti(idNow)) idNow = -idNow;
199 double mNow = particleDataPtr->mass(idNow);
200 idProd.push_back( idNow);
201 mProd.push_back( mNow);
204 // Decays into partons usually translate into hadrons.
205 if (hasPartons && !keepPartons && !pickHadrons()) continue;
207 // Need to set colour flow if explicit decay to partons.
210 for (int i = 0; i <= mult; ++i) {
214 if (hasPartons && keepPartons && !setColours(event)) continue;
216 // Check that enough phase space for decay.
218 double mDiff = mProd[0];
219 for (int i = 1; i <= mult; ++i) mDiff -= mProd[i];
220 if (mDiff < mSafety) continue;
223 // End of inner trial loops. Check if succeeded or not.
227 if (!foundMode) continue;
229 // Store decay products in the event record.
230 int status = (hasOscillated) ? 92 : 91;
231 for (int i = 1; i <= mult; ++i) {
232 int iPos = event.append( idProd[i], status, iDec, 0, 0, 0,
233 cols[i], acols[i], Vec4(0., 0., 0., 0.), mProd[i], scale);
234 iProd.push_back( iPos);
238 // Pick mass of Dalitz decay. Temporarily change multiplicity.
239 if ( (meMode == 11 || meMode == 12 || meMode == 13)
240 && !dalitzMass() ) continue;
242 // Do a decay, split by multiplicity.
243 bool decayed = false;
244 if (mult == 1) decayed = oneBody(event);
245 else if (mult == 2) decayed = twoBody(event);
246 else if (mult == 3) decayed = threeBody(event);
247 else decayed = mGenerator(event);
248 if (!decayed) continue;
250 // Kinematics of gamma* -> l- l+ in Dalitz decay. Restore multiplicity.
251 if (meMode == 11 || meMode == 12 || meMode == 13)
252 dalitzKinematics(event);
254 // End of outer trial loops.
259 // If the decay worked, then mark mother decayed and store daughters.
261 event[iDec].statusNeg();
262 event[iDec].daughters( iProd[1], iProd[mult]);
264 // Else remove unused daughters and return failure.
266 if (hasStored) event.popBack(mult);
267 infoPtr->errorMsg("Error in ParticleDecays::decay: "
268 "failed to find workable decay channel");
272 // Now finished normal internal decay treatment.
275 // Set decay vertex when this is displaced.
276 if (event[iDec].hasVertex() || event[iDec].tau() > 0.) {
277 Vec4 vDec = event[iDec].vDec();
278 for (int i = 1; i <= mult; ++i) event[iProd[i]].vProd( vDec );
281 // Set lifetime of daughters.
282 for (int i = 1; i <= mult; ++i)
283 event[iProd[i]].tau( event[iProd[i]].tau0() * rndmPtr->exp() );
285 // In a decay explicitly to partons then optionally do a shower,
286 // and always flag that partonic system should be fragmented.
287 if (hasPartons && keepPartons && doFSRinDecays)
288 timesDecPtr->shower( iProd[1], iProd.back(), event, mProd[0]);
295 //--------------------------------------------------------------------------
297 // Check whether a decay is allowed, given the upcoming decay vertex.
299 bool ParticleDecays::checkVertex(Particle& decayer) {
301 // Check whether any of the conditions are not fulfilled.
302 if (limitTau0 && decayer.tau0() > tau0Max) return false;
303 if (limitTau && decayer.tau() > tauMax) return false;
304 if (limitRadius && pow2(decayer.xDec()) + pow2(decayer.yDec())
305 + pow2(decayer.zDec()) > pow2(rMax)) return false;
306 if (limitCylinder && (pow2(decayer.xDec()) + pow2(decayer.yDec())
307 > pow2(xyMax) || abs(decayer.zDec()) > zMax) ) return false;
314 //--------------------------------------------------------------------------
316 // Check for oscillations B0 <-> B0bar or B_s0 <-> B_s0bar.
318 bool ParticleDecays::oscillateB(Particle& decayer) {
320 // Extract relevant information and decide.
321 double xBmix = (abs(decayer.id()) == 511) ? xBdMix : xBsMix;
322 double tau = decayer.tau();
323 double tau0 = decayer.tau0();
324 double probosc = pow2(sin(0.5 * xBmix * tau / tau0));
325 return (probosc > rndmPtr->flat());
329 //--------------------------------------------------------------------------
331 // Do a one-body decay. (Rare; e.g. for K0 -> K0_short.)
333 bool ParticleDecays::oneBody(Event& event) {
335 // References to the particles involved.
336 Particle& decayer = event[iProd[0]];
337 Particle& prod = event[iProd[1]];
339 // Set momentum and expand mother information.
340 prod.p( decayer.p() );
341 prod.m( decayer.m() );
342 prod.mother2( iProd[0] );
349 //--------------------------------------------------------------------------
351 // Do a two-body decay.
353 bool ParticleDecays::twoBody(Event& event) {
355 // References to the particles involved.
356 Particle& decayer = event[iProd[0]];
357 Particle& prod1 = event[iProd[1]];
358 Particle& prod2 = event[iProd[2]];
361 double m0 = mProd[0];
362 double m1 = mProd[1];
363 double m2 = mProd[2];
365 // Energies and absolute momentum in the rest frame.
366 if (m1 + m2 + mSafety > m0) return false;
367 double e1 = 0.5 * (m0*m0 + m1*m1 - m2*m2) / m0;
368 double e2 = 0.5 * (m0*m0 + m2*m2 - m1*m1) / m0;
369 double pAbs = 0.5 * sqrtpos( (m0 - m1 - m2) * (m0 + m1 + m2)
370 * (m0 + m1 - m2) * (m0 - m1 + m2) ) / m0;
372 // When meMode = 2, for V -> PS2 + PS3 (V = vector, pseudoscalar),
373 // need to check if production is PS0 -> PS1/gamma + V.
374 int iMother = event[iProd[0]].mother1();
377 if (iMother <= 0 || iMother >= iProd[0]) meMode = 0;
379 int iDaughter1 = event[iMother].daughter1();
380 int iDaughter2 = event[iMother].daughter2();
381 if (iDaughter2 != iDaughter1 + 1) meMode = 0;
383 int idMother = abs( event[iMother].id() );
384 if (idMother <= 100 || idMother%10 !=1
385 || (idMother/1000)%10 != 0) meMode = 0;
387 int iSister = (iProd[0] == iDaughter1) ? iDaughter2 : iDaughter1;
388 idSister = abs( event[iSister].id() );
389 if ( (idSister <= 100 || idSister%10 !=1
390 || (idSister/1000)%10 != 0) && idSister != 22) meMode = 0;
396 // Begin loop over matrix-element corrections.
397 double wtME, wtMEmax;
404 // Isotropic angles give three-momentum.
405 double cosTheta = 2. * rndmPtr->flat() - 1.;
406 double sinTheta = sqrt(1. - cosTheta*cosTheta);
407 double phi = 2. * M_PI * rndmPtr->flat();
408 double pX = pAbs * sinTheta * cos(phi);
409 double pY = pAbs * sinTheta * sin(phi);
410 double pZ = pAbs * cosTheta;
412 // Fill four-momenta and boost them away from mother rest frame.
413 prod1.p( pX, pY, pZ, e1);
414 prod2.p( -pX, -pY, -pZ, e2);
415 prod1.bst( decayer.p(), decayer.m() );
416 prod2.bst( decayer.p(), decayer.m() );
418 // Matrix element for PS0 -> PS1 + V1 -> PS1 + PS2 + PS3 of form
419 // cos**2(theta02) in V1 rest frame, and for PS0 -> gamma + V1
420 // -> gamma + PS2 + PS3 of form sin**2(theta02).
422 double p10 = decayer.p() * event[iMother].p();
423 double p12 = decayer.p() * prod1.p();
424 double p02 = event[iMother].p() * prod1.p();
425 double s0 = pow2(event[iMother].m());
426 double s1 = pow2(decayer.m());
427 double s2 = pow2(prod1.m());
428 if (idSister != 22) wtME = pow2(p10 * p12 - s1 * p02);
429 else wtME = s1 * (2. * p10 * p12 * p02 - s1 * p02*p02
430 - s0 * p12*p12 - s2 * p10*p10 + s1 * s0 * s2);
431 wtME = max( wtME, 1e-6 * s1*s1 * s0 * s2);
432 wtMEmax = (p10*p10 - s1 * s0) * (p12*p12 - s1 * s2);
435 // Break out of loop if no sensible ME weight.
436 if(loop > NTRYMEWT) {
437 infoPtr->errorMsg("ParticleDecays::twoBody: "
438 "caught in infinite ME weight loop");
442 // If rejected, try again with new invariant masses.
443 } while ( wtME < rndmPtr->flat() * wtMEmax );
450 //--------------------------------------------------------------------------
452 // Do a three-body decay (except Dalitz decays).
454 bool ParticleDecays::threeBody(Event& event) {
456 // References to the particles involved.
457 Particle& decayer = event[iProd[0]];
458 Particle& prod1 = event[iProd[1]];
459 Particle& prod2 = event[iProd[2]];
460 Particle& prod3 = event[iProd[3]];
462 // Mother and sum daughter masses. Fail if too close.
463 double m0 = mProd[0];
464 double m1 = mProd[1];
465 double m2 = mProd[2];
466 double m3 = mProd[3];
467 double mSum = m1 + m2 + m3;
468 double mDiff = m0 - mSum;
469 if (mDiff < mSafety) return false;
471 // Kinematical limits for 2+3 mass. Maximum phase-space weight.
472 double m23Min = m2 + m3;
473 double m23Max = m0 - m1;
474 double p1Max = 0.5 * sqrtpos( (m0 - m1 - m23Min) * (m0 + m1 + m23Min)
475 * (m0 + m1 - m23Min) * (m0 - m1 + m23Min) ) / m0;
476 double p23Max = 0.5 * sqrtpos( (m23Max - m2 - m3) * (m23Max + m2 + m3)
477 * (m23Max + m2 - m3) * (m23Max - m2 + m3) ) / m23Max;
478 double wtPSmax = 0.5 * p1Max * p23Max;
480 // Begin loop over matrix-element corrections.
481 double wtME, wtMEmax, wtPS, m23, p1Abs, p23Abs;
486 // Pick an intermediate mass m23 flat in the allowed range.
488 m23 = m23Min + rndmPtr->flat() * mDiff;
490 // Translate into relative momenta and find phase-space weight.
491 p1Abs = 0.5 * sqrtpos( (m0 - m1 - m23) * (m0 + m1 + m23)
492 * (m0 + m1 - m23) * (m0 - m1 + m23) ) / m0;
493 p23Abs = 0.5 * sqrtpos( (m23 - m2 - m3) * (m23 + m2 + m3)
494 * (m23 + m2 - m3) * (m23 - m2 + m3) ) / m23;
495 wtPS = p1Abs * p23Abs;
497 // If rejected, try again with new invariant masses.
498 } while ( wtPS < rndmPtr->flat() * wtPSmax );
500 // Set up m23 -> m2 + m3 isotropic in its rest frame.
501 double cosTheta = 2. * rndmPtr->flat() - 1.;
502 double sinTheta = sqrt(1. - cosTheta*cosTheta);
503 double phi = 2. * M_PI * rndmPtr->flat();
504 double pX = p23Abs * sinTheta * cos(phi);
505 double pY = p23Abs * sinTheta * sin(phi);
506 double pZ = p23Abs * cosTheta;
507 double e2 = sqrt( m2*m2 + p23Abs*p23Abs);
508 double e3 = sqrt( m3*m3 + p23Abs*p23Abs);
509 prod2.p( pX, pY, pZ, e2);
510 prod3.p( -pX, -pY, -pZ, e3);
512 // Set up m0 -> m1 + m23 isotropic in its rest frame.
513 cosTheta = 2. * rndmPtr->flat() - 1.;
514 sinTheta = sqrt(1. - cosTheta*cosTheta);
515 phi = 2. * M_PI * rndmPtr->flat();
516 pX = p1Abs * sinTheta * cos(phi);
517 pY = p1Abs * sinTheta * sin(phi);
518 pZ = p1Abs * cosTheta;
519 double e1 = sqrt( m1*m1 + p1Abs*p1Abs);
520 double e23 = sqrt( m23*m23 + p1Abs*p1Abs);
521 prod1.p( pX, pY, pZ, e1);
523 // Boost 2 + 3 to the 0 rest frame.
524 Vec4 p23( -pX, -pY, -pZ, e23);
525 prod2.bst( p23, m23 );
526 prod3.bst( p23, m23 );
528 // Matrix-element weight for omega/phi -> pi+ pi- pi0.
530 double p1p2 = prod1.p() * prod2.p();
531 double p1p3 = prod1.p() * prod3.p();
532 double p2p3 = prod2.p() * prod3.p();
533 wtME = pow2(m1 * m2 * m3) - pow2(m1 * p2p3) - pow2(m2 * p1p3)
534 - pow2(m3 * p1p2) + 2. * p1p2 * p1p3 * p2p3;
535 wtMEmax = pow3(m0 * m0) / 150.;
537 // Effective matrix element for nu spectrum in tau -> nu + hadrons.
538 } else if (meMode == 21) {
539 double x1 = 2. * prod1.e() / m0;
540 wtME = x1 * (3. - 2. * x1);
541 double xMax = min( 0.75, 2. * (1. - mSum / m0) );
542 wtMEmax = xMax * (3. - 2. * xMax);
544 // Matrix element for weak decay (only semileptonic for c and b).
545 } else if ((meMode == 22 || meMode == 23) && prod1.isLepton()) {
546 wtME = m0 * prod1.e() * (prod2.p() * prod3.p());
547 wtMEmax = min( pow4(m0) / 16., m0 * (m0 - m1 - m2) * (m0 - m1 - m3)
550 // Effective matrix element for weak decay to hadrons (B -> D, D -> K).
551 } else if (meMode == 22 || meMode == 23) {
552 double x1 = 2. * prod1.pAbs() / m0;
553 wtME = x1 * (3. - 2. * x1);
554 double xMax = min( 0.75, 2. * (1. - mSum / m0) );
555 wtMEmax = xMax * (3. - 2. * xMax);
557 // Effective matrix element for gamma spectrum in B -> gamma + hadrons.
558 } else if (meMode == 31) {
559 double x1 = 2. * prod1.e() / m0;
561 double x1Max = 1. - pow2(mSum / m0);
562 wtMEmax = pow3(x1Max);
564 // Matrix-element weight for "onium" -> g + g + g or gamma + g + g.
565 } else if (meMode == 92) {
566 double x1 = 2. * prod1.e() / m0;
567 double x2 = 2. * prod2.e() / m0;
568 double x3 = 2. * prod3.e() / m0;
569 wtME = pow2( (1. - x1) / (x2 * x3) ) + pow2( (1. - x2) / (x1 * x3) )
570 + pow2( (1. - x3) / (x1 * x2) );
572 // For gamma + g + g require minimum mass for g + g system.
573 if (prod1.id() == 22 && sqrt(1. - x1) * m0 < 2. * stopMass) wtME = 0.;
574 if (prod2.id() == 22 && sqrt(1. - x2) * m0 < 2. * stopMass) wtME = 0.;
575 if (prod3.id() == 22 && sqrt(1. - x3) * m0 < 2. * stopMass) wtME = 0.;
578 // If rejected, try again with new invariant masses.
579 } while ( wtME < rndmPtr->flat() * wtMEmax );
581 // Boost 1 + 2 + 3 to the current frame.
582 prod1.bst( decayer.p(), decayer.m() );
583 prod2.bst( decayer.p(), decayer.m() );
584 prod3.bst( decayer.p(), decayer.m() );
591 //--------------------------------------------------------------------------
593 // Do a multibody decay using the M-generator algorithm.
595 bool ParticleDecays::mGenerator(Event& event) {
597 // Mother and sum daughter masses. Fail if too close or inconsistent.
598 double m0 = mProd[0];
599 double mSum = mProd[1];
600 for (int i = 2; i <= mult; ++i) mSum += mProd[i];
601 double mDiff = m0 - mSum;
602 if (mDiff < mSafety) return false;
604 // Begin setup of intermediate invariant masses.
606 for (int i = 0; i <= mult; ++i) mInv.push_back( mProd[i]);
608 // Calculate the maximum weight in the decay.
609 double wtPS, wtME, wtMEmax;
610 double wtPSmax = 1. / WTCORRECTION[mult];
611 double mMax = mDiff + mProd[mult];
613 for (int i = mult - 1; i > 0; --i) {
616 double mNow = mProd[i];
617 wtPSmax *= 0.5 * sqrtpos( (mMax - mMin - mNow) * (mMax + mMin + mNow)
618 * (mMax + mMin - mNow) * (mMax - mMin + mNow) ) / mMax;
621 // Begin loop over matrix-element corrections.
626 // Begin loop to find the set of intermediate invariant masses.
630 // Find and order random numbers in descending order.
632 rndmOrd.push_back(1.);
633 for (int i = 1; i < mult - 1; ++i) {
634 double rndm = rndmPtr->flat();
635 rndmOrd.push_back(rndm);
636 for (int j = i - 1; j > 0; --j) {
637 if (rndm > rndmOrd[j]) swap( rndmOrd[j], rndmOrd[j+1] );
641 rndmOrd.push_back(0.);
643 // Translate into intermediate masses and find weight.
644 for (int i = mult - 1; i > 0; --i) {
645 mInv[i] = mInv[i+1] + mProd[i] + (rndmOrd[i-1] - rndmOrd[i]) * mDiff;
646 wtPS *= 0.5 * sqrtpos( (mInv[i] - mInv[i+1] - mProd[i])
647 * (mInv[i] + mInv[i+1] + mProd[i]) * (mInv[i] + mInv[i+1] - mProd[i])
648 * (mInv[i] - mInv[i+1] + mProd[i]) ) / mInv[i];
651 // If rejected, try again with new invariant masses.
652 } while ( wtPS < rndmPtr->flat() * wtPSmax );
654 // Perform two-particle decays in the respective rest frame.
655 pInv.resize(mult + 1);
656 for (int i = 1; i < mult; ++i) {
657 double pAbs = 0.5 * sqrtpos( (mInv[i] - mInv[i+1] - mProd[i])
658 * (mInv[i] + mInv[i+1] + mProd[i]) * (mInv[i] + mInv[i+1] - mProd[i])
659 * (mInv[i] - mInv[i+1] + mProd[i]) ) / mInv[i];
661 // Isotropic angles give three-momentum.
662 double cosTheta = 2. * rndmPtr->flat() - 1.;
663 double sinTheta = sqrt(1. - cosTheta*cosTheta);
664 double phi = 2. * M_PI * rndmPtr->flat();
665 double pX = pAbs * sinTheta * cos(phi);
666 double pY = pAbs * sinTheta * sin(phi);
667 double pZ = pAbs * cosTheta;
669 // Calculate energies, fill four-momenta.
670 double eHad = sqrt( mProd[i]*mProd[i] + pAbs*pAbs);
671 double eInv = sqrt( mInv[i+1]*mInv[i+1] + pAbs*pAbs);
672 event[iProd[i]].p( pX, pY, pZ, eHad);
673 pInv[i+1].p( -pX, -pY, -pZ, eInv);
676 // Boost decay products to the mother rest frame.
677 event[iProd[mult]].p( pInv[mult] );
678 for (int iFrame = mult - 1; iFrame > 1; --iFrame)
679 for (int i = iFrame; i <= mult; ++i)
680 event[iProd[i]].bst( pInv[iFrame], mInv[iFrame]);
682 // Effective matrix element for nu spectrum in tau -> nu + hadrons.
683 if (meMode == 21 && event[iProd[1]].isLepton()) {
684 double x1 = 2. * event[iProd[1]].e() / m0;
685 wtME = x1 * (3. - 2. * x1);
686 double xMax = min( 0.75, 2. * (1. - mSum / m0) );
687 wtMEmax = xMax * (3. - 2. * xMax);
689 // Effective matrix element for weak decay (only semileptonic for c and b).
690 // Particles 4 onwards should be made softer explicitly?
691 } else if ((meMode == 22 || meMode == 23) && event[iProd[1]].isLepton()) {
692 Vec4 pRest = event[iProd[3]].p();
693 for (int i = 4; i <= mult; ++i) pRest += event[iProd[i]].p();
694 wtME = m0 * event[iProd[1]].e() * (event[iProd[2]].p() * pRest);
695 for (int i = 4; i <= mult; ++i) wtME
696 *= exp(- event[iProd[i]].pAbs2() / pow2(sigmaSoft) );
697 wtMEmax = pow4(m0) / 16.;
699 // Effective matrix element for weak decay to hadrons (B -> D, D -> K).
700 } else if (meMode == 22 || meMode == 23) {
701 double x1 = 2. * event[iProd[1]].pAbs() / m0;
702 wtME = x1 * (3. - 2. * x1);
703 double xMax = min( 0.75, 2. * (1. - mSum / m0) );
704 wtMEmax = xMax * (3. - 2. * xMax);
706 // Effective matrix element for gamma spectrum in B -> gamma + hadrons.
707 } else if (meMode == 31) {
708 double x1 = 2. * event[iProd[1]].e() / m0;
710 double x1Max = 1. - pow2(mSum / m0);
711 wtMEmax = pow3(x1Max);
714 // If rejected, try again with new invariant masses.
715 } while ( wtME < rndmPtr->flat() * wtMEmax );
717 // Boost decay products to the current frame.
718 pInv[1].p( event[iProd[0]].p() );
719 for (int i = 1; i <= mult; ++i) event[iProd[i]].bst( pInv[1], mInv[1] );
726 //--------------------------------------------------------------------------
728 // Select mass of lepton pair in a Dalitz decay.
730 bool ParticleDecays::dalitzMass() {
732 // Mother and sum daughter masses.
734 for (int i = 1; i <= mult - 2; ++i) mSum1 += mProd[i];
735 if (meMode == 13) mSum1 *= MSAFEDALITZ;
736 double mSum2 = MSAFEDALITZ * (mProd[mult -1] + mProd[mult]);
737 double mDiff = mProd[0] - mSum1 - mSum2;
739 // Fail if too close or inconsistent.
740 if (mDiff < mSafety) return false;
741 if (idProd[mult - 1] + idProd[mult] != 0
742 || mProd[mult - 1] != mProd[mult]) {
743 infoPtr->errorMsg("Error in ParticleDecays::dalitzMass:"
744 " inconsistent flavour/mass assignments");
747 if ( meMode == 13 && (idProd[1] + idProd[2] != 0
748 || mProd[1] != mProd[2]) ) {
749 infoPtr->errorMsg("Error in ParticleDecays::dalitzMass:"
750 " inconsistent flavour/mass assignments");
754 // Case 1: one Dalitz pair.
755 if (meMode == 11 || meMode == 12) {
757 // Kinematical limits for gamma* squared mass.
758 double sGamMin = pow2(mSum2);
759 double sGamMax = pow2(mProd[0] - mSum1);
760 // Select virtual gamma squared mass. Guessed form for meMode == 12.
764 if (++loop > NTRYDALITZ) return false;
765 sGam = sGamMin * pow( sGamMax / sGamMin, rndmPtr->flat() );
766 wtGam = (1. + 0.5 * sGamMin / sGam) * sqrt(1. - sGamMin / sGam)
767 * pow3(1. - sGam / sGamMax) * sRhoDal * (sRhoDal + wRhoDal)
768 / ( pow2(sGam - sRhoDal) + sRhoDal * wRhoDal );
769 } while ( wtGam < rndmPtr->flat() );
771 // Store results in preparation for doing a one-less-body decay.
773 mProd[mult] = sqrt(sGam);
775 // Case 2: two Dalitz pairs.
778 // Kinematical limits for 1 + 2 and 3 + 4 gamma* masses.
779 double s0 = pow2(mProd[0]);
780 double s12Min = pow2(mSum1);
781 double s12Max = pow2(mProd[0] - mSum2);
782 double s34Min = pow2(mSum2);
783 double s34Max = pow2(mProd[0] - mSum1);
785 // Select virtual gamma squared masses. Guessed form for meMode == 13.
786 double s12, s34, wt12, wt34, wtPAbs, wtAll;
789 if (++loop > NTRYDALITZ) return false;
790 s12 = s12Min * pow( s12Max / s12Min, rndmPtr->flat() );
791 wt12 = (1. + 0.5 * s12Min / s12) * sqrt(1. - s12Min / s12)
792 * sRhoDal * (sRhoDal + wRhoDal)
793 / ( pow2(s12 - sRhoDal) + sRhoDal * wRhoDal );
794 s34 = s34Min * pow( s34Max / s34Min, rndmPtr->flat() );
795 wt34 = (1. + 0.5 * s34Min / s34) * sqrt(1. - s34Min / s34)
796 * sRhoDal * (sRhoDal + wRhoDal)
797 / ( pow2(s34 - sRhoDal) + sRhoDal * wRhoDal );
798 wtPAbs = sqrtpos( pow2(1. - (s12 + s34)/ s0)
799 - 4. * s12 * s34 / (s0 * s0) );
800 wtAll = wt12 * wt34 * pow3(wtPAbs);
801 if (wtAll > 1.) infoPtr->errorMsg(
802 "Error in ParticleDecays::dalitzMass: weight > 1");
803 } while (wtAll < rndmPtr->flat());
805 // Store results in preparation for doing a two-body decay.
807 mProd[1] = sqrt(s12);
808 mProd[2] = sqrt(s34);
816 //--------------------------------------------------------------------------
818 // Do kinematics of gamma* -> l- l+ in Dalitz decay.
820 bool ParticleDecays::dalitzKinematics(Event& event) {
822 // Restore multiplicity.
823 int nDal = (meMode < 13) ? 1 : 2;
826 // Loop over one or two lepton pairs.
827 for (int iDal = 0; iDal < nDal; ++iDal) {
829 // References to the particles involved.
830 Particle& decayer = event[iProd[0]];
831 Particle& prodA = (iDal == 0) ? event[iProd[mult - 1]]
833 Particle& prodB = (iDal == 0) ? event[iProd[mult]]
836 // Reconstruct required rotations and boosts backwards.
837 Vec4 pDec = decayer.p();
838 int iGam = (meMode < 13) ? mult - 1 : 2 - iDal;
839 Vec4 pGam = event[iProd[iGam]].p();
840 pGam.bstback( pDec, decayer.m() );
841 double phiGam = pGam.phi();
842 pGam.rot( 0., -phiGam);
843 double thetaGam = pGam.theta();
844 pGam.rot( -thetaGam, 0.);
846 // Masses and phase space in gamma* rest frame.
847 double mGam = (meMode < 13) ? mProd[mult - 1] : mProd[2 - iDal];
848 double mA = prodA.m();
849 double mB = prodB.m();
850 double mGamMin = MSAFEDALITZ * (mA + mB);
851 double mGamRat = pow2(mGamMin / mGam);
852 double pGamAbs = 0.5 * sqrtpos( (mGam - mA - mB) * (mGam + mA + mB) );
854 // Set up decay in gamma* rest frame, reference along +z axis.
855 double cosTheta, cos2Theta;
857 cosTheta = 2. * rndmPtr->flat() - 1.;
858 cos2Theta = cosTheta * cosTheta;
859 } while ( 1. + cos2Theta + mGamRat * (1. - cos2Theta)
860 < 2. * rndmPtr->flat() );
861 double sinTheta = sqrt(1. - cosTheta*cosTheta);
862 double phi = 2. * M_PI * rndmPtr->flat();
863 double pX = pGamAbs * sinTheta * cos(phi);
864 double pY = pGamAbs * sinTheta * sin(phi);
865 double pZ = pGamAbs * cosTheta;
866 double eA = sqrt( mA*mA + pGamAbs*pGamAbs);
867 double eB = sqrt( mB*mB + pGamAbs*pGamAbs);
868 prodA.p( pX, pY, pZ, eA);
869 prodB.p( -pX, -pY, -pZ, eB);
871 // Boost to lab frame.
872 prodA.bst( pGam, mGam);
873 prodB.bst( pGam, mGam);
874 prodA.rot( thetaGam, phiGam);
875 prodB.rot( thetaGam, phiGam);
876 prodA.bst( pDec, decayer.m() );
877 prodB.bst( pDec, decayer.m() );
885 //--------------------------------------------------------------------------
887 // Translate a partonic content into a set of actual hadrons.
889 bool ParticleDecays::pickHadrons() {
891 // Find partonic decay products. Rest are known id's, mainly hadrons,
892 // when necessary shuffled to beginning of idProd list.
896 bool closedGLoop = false;
897 for (int i = 1; i <= mult; ++i) {
898 int idAbs = abs(idProd[i]);
899 if ( idAbs < 9 || (idAbs > 1000 && idAbs < 10000 && (idAbs/10)%10 == 0)
900 || idAbs == 81 || idAbs == 82 || idAbs == 83) {
902 idPartons.push_back(idProd[i]);
903 if (idAbs == 83) closedGLoop = true;
907 idProd[nKnown] = idProd[i];
908 mProd[nKnown] = mProd[i];
913 // Replace generic spectator flavour code by the actual one.
914 for (int i = 0; i < nPartons; ++i) {
915 int idPart = idPartons[i];
918 int idAbs = abs(idDec);
919 if ( (idAbs/1000)%10 == 0 ) {
920 idNew = -(idAbs/10)%10;
921 if ((idAbs/100)%2 == 1) idNew = -idNew;
922 } else if ( (idAbs/100)%10 >= (idAbs/10)%10 )
923 idNew = 100 * ((idAbs/10)%100) + 3;
924 else idNew = 1000 * ((idAbs/10)%10) + 100 * ((idAbs/100)%10) + 1;
925 if (idDec < 0) idNew = -idNew;
927 // Replace generic random flavour by a randomly selected one.
928 } else if (idPart == 82 || idPart == 83) {
931 int idDummy = -flavSelPtr->pickLightQ();
932 FlavContainer flavDummy(idDummy, idPart - 82);
933 do idNew = flavSelPtr->pick(flavDummy).id;
935 mFlav = particleDataPtr->constituentMass(idNew);
936 } while (2. * mFlav + stopMass > mProd[0]);
937 } else if (idPart == -82 || idPart == -83) {
938 idNew = -idPartons[i-1];
940 idPartons[i] = idNew;
943 // Determine whether fixed multiplicity or to be selected at random.
944 int nMin = max( 2, nKnown + nPartons / 2);
945 if (meMode == 23) nMin = 3;
946 if (meMode > 41 && meMode <= 50) nMin = meMode - 40;
947 if (meMode > 51 && meMode <= 60) nMin = meMode - 50;
949 if (meMode == 0) nFix = nMin;
950 if (meMode == 11) nFix = 3;
951 if (meMode == 12) nFix = 4;
952 if (meMode > 61 && meMode <= 70) nFix = meMode - 60;
953 if (meMode > 71 && meMode <= 80) nFix = meMode - 70;
954 if (nFix > 0 && nKnown + nPartons/2 > nFix) return false;
956 // Initial values for loop to set new hadronic content.
957 int nFilled = nKnown + 1;
958 int nTotal, nNew, nSpec, nLeft;
961 bool diquarkClash = false;
962 bool usedChannel = false;
964 // Begin loop; interrupt if multiple tries fail.
967 if (nTry > NTRYPICK) return false;
969 // Initialize variables inside new try.
970 nFilled = nKnown + 1;
971 idProd.resize(nFilled);
972 mProd.resize(nFilled);
978 for (int i = 1; i < nFilled; ++i) mDiff -= mProd[i];
979 diquarkClash = false;
982 // For weak decays collapse spectators to one particle.
983 if ( (meMode == 22 || meMode == 23) && nLeft > 1) {
984 FlavContainer flav1( idPartons[nPartons - 2] );
985 FlavContainer flav2( idPartons[nPartons - 1] );
987 do idHad = flavSelPtr->combine( flav1, flav2);
989 double mHad = particleDataPtr->mass(idHad);
991 idProd.push_back( idHad);
992 mProd.push_back( mHad);
998 // If there are partons left, then determine how many hadrons to pick.
1001 // For B -> gamma + X use geometrical distribution.
1003 double geom = rndmPtr->flat();
1008 } while (geom < 1. && nTotal < 10);
1010 // Calculate mass excess and from there average multiplicity.
1011 } else if (nFix == 0) {
1012 double mDiffPS = mDiff;
1013 for (int i = 0; i < nLeft; ++i)
1014 mDiffPS -= particleDataPtr->constituentMass( idPartons[i] );
1015 double average = 0.5 * (nKnown + nSpec) + 0.25 * nPartons
1016 + multIncrease * log( max( 1.1, mDiffPS / multRefMass ) );
1017 if (closedGLoop) average += multGoffset;
1019 // Pick multiplicity according to Poissonian.
1022 for (int nNow = nMin + 1; nNow <= 10; ++nNow) {
1023 value *= average / nNow;
1028 sum *= rndmPtr->flat();
1032 value *= average / nTotal;
1034 } while (sum > 0. && nTotal < 10);
1036 // Alternatively predetermined multiplicity.
1040 nNew = nTotal - nKnown - nSpec;
1042 // Set up ends of fragmented system, as copy of idPartons.
1044 for (int i = 0; i < nLeft; ++i) {
1045 flavEnds.push_back( FlavContainer(idPartons[i]) );
1046 if (abs(idPartons[i]) > 100) flavSelPtr->assignPopQ( flavEnds[i] );
1049 // Fragment off at random, but save nLeft/2 for final recombination.
1050 if (nNew > nLeft/2) {
1051 FlavContainer flavNew;
1053 for (int i = 0; i < nNew - nLeft/2; ++i) {
1054 // When four quarks consider last one to be spectator.
1055 int iEnd = int( (nLeft - 1.) * rndmPtr->flat() );
1056 // Pick new flavour and form a new hadron.
1058 flavNew = flavSelPtr->pick( flavEnds[iEnd] );
1059 idHad = flavSelPtr->combine( flavEnds[iEnd], flavNew);
1060 } while (idHad == 0);
1061 // Store new hadron and endpoint flavour.
1062 idProd.push_back( idHad);
1063 flavEnds[iEnd].anti(flavNew);
1067 // When only two quarks left, combine to form final hadron.
1070 if ( abs(flavEnds[0].id) > 8 && abs(flavEnds[1].id) > 8)
1071 diquarkClash = true;
1073 do idHad = flavSelPtr->combine( flavEnds[0], flavEnds[1]);
1075 idProd.push_back( idHad);
1078 // If four quarks, decide how to pair them up.
1084 if ( rndmPtr->flat() < colRearrange) iEnd2 = 3;
1086 ( (flavEnds[iEnd1].id > 0 && flavEnds[iEnd1].id < 9)
1087 || flavEnds[iEnd1].id < -10 ) ? 1 : -1;
1088 if ( (flavEnds[iEnd2].id < 0 && flavEnds[iEnd2].id > -9)
1089 || flavEnds[iEnd2].id > 10 ) relColSign *= -1;
1090 if (relColSign == 1) iEnd2 = 2;
1091 if (iEnd2 == 2) iEnd3 = 1;
1092 if (iEnd2 == 3) iEnd4 = 1;
1094 // Then combine to get final two hadrons.
1096 if ( abs(flavEnds[iEnd1].id) > 8 && abs(flavEnds[iEnd2].id) > 8)
1097 diquarkClash = true;
1099 do idHad = flavSelPtr->combine( flavEnds[iEnd1], flavEnds[iEnd2]);
1101 idProd.push_back( idHad);
1103 if ( abs(flavEnds[iEnd3].id) > 8 && abs(flavEnds[iEnd4].id) > 8)
1104 diquarkClash = true;
1106 do idHad = flavSelPtr->combine( flavEnds[iEnd3], flavEnds[iEnd4]);
1108 idProd.push_back( idHad);
1112 // Find masses of the new hadrons.
1113 for (int i = nFilled; i < int(idProd.size()) ; ++i) {
1114 double mHad = particleDataPtr->mass(idProd[i]);
1115 mProd.push_back( mHad);
1120 // Optional: check that this decay mode is not explicitly defined.
1121 if ( (meMode > 61 && meMode <= 80) && mDiff > mSafety && !diquarkClash ) {
1122 int idMatch[10], idPNow;
1123 usedChannel = false;
1124 bool matched = false;
1125 // Loop through all channels. Done if not same multiplicity.
1126 for (int i = 0; i < decDataPtr->sizeChannels(); ++i) {
1127 DecayChannel& channel = decDataPtr->channel(i);
1128 if (channel.multiplicity() != nTotal) continue;
1129 for (int k = 0; k < nTotal; ++k) idMatch[k] = channel.product(k);
1130 // Match particles one by one until fail.
1131 // Do not distinguish K0/K0bar/K0short/K0long at this stage.
1132 for (int j = 0; j < nTotal; ++j) {
1134 idPNow = idProd[j + 1];
1135 if (idPNow == -311 || idPNow == 130 || idPNow == 310) idPNow = 311;
1136 for (int k = 0; k < nTotal - j; ++k)
1137 if (idMatch[k] == idPNow || (idMatch[k] == -311 && idPNow == 311)) {
1138 // Compress list of unmatched when matching worked.
1139 idMatch[k] = idMatch[nTotal - 1 - j];
1143 if (!matched) break;
1145 // If matching worked, then chosen channel to be rejected.
1146 if (matched) {usedChannel = true; break;}
1150 // Keep on trying until enough phase space and no clash.
1151 } while (mDiff < mSafety || diquarkClash || usedChannel);
1153 // Update particle multiplicity.
1154 mult = idProd.size() - 1;
1156 // For Dalitz decays shuffle Dalitz pair to the end of the list.
1157 if (meMode == 11 || meMode == 12) {
1160 for (int i = 1; i <= mult; ++i) {
1161 if (idProd[i] == 11 || idProd[i] == 13 || idProd[i] == 15) iL1 = i;
1162 if (idProd[i] == -11 || idProd[i] == -13 || idProd[i] == -15) iL2 = i;
1164 if (iL1 > 0 && iL2 > 0) {
1165 int idL1 = idProd[iL1];
1166 int idL2 = idProd[iL2];
1167 double mL1 = mProd[iL1];
1168 double mL2 = mProd[iL2];
1170 for (int i = 1; i <= mult; ++i) if (i != iL1 && i != iL2) {
1172 idProd[iMove] = idProd[i];
1173 mProd[iMove] = mProd[i];
1175 idProd[mult - 1] = idL1;
1176 idProd[mult] = idL2;
1177 mProd[mult - 1] = mL1;
1187 //--------------------------------------------------------------------------
1189 // Set colour flow and scale in a decay explicitly to partons.
1191 bool ParticleDecays::setColours(Event& event) {
1193 // Decay to q qbar (or qbar q).
1194 if (meMode == 91 && idProd[1] > 0 && idProd[1] < 9) {
1195 int newCol = event.nextColTag();
1198 } else if (meMode == 91 && idProd[1] < 0 && idProd[1] > -9) {
1199 int newCol = event.nextColTag();
1204 } else if (meMode == 91 && idProd[1] == 21) {
1205 int newCol1 = event.nextColTag();
1206 int newCol2 = event.nextColTag();
1213 } else if (meMode == 92 && idProd[1] == 21 && idProd[2] == 21
1214 && idProd[3] == 21) {
1215 int newCol1 = event.nextColTag();
1216 int newCol2 = event.nextColTag();
1217 int newCol3 = event.nextColTag();
1225 // Decay to g g gamma: locate which is gamma.
1226 } else if (meMode == 92) {
1227 int iGlu1 = (idProd[1] == 21) ? 1 : 3;
1228 int iGlu2 = (idProd[2] == 21) ? 2 : 3;
1229 int newCol1 = event.nextColTag();
1230 int newCol2 = event.nextColTag();
1231 cols[iGlu1] = newCol1;
1232 acols[iGlu1] = newCol2;
1233 cols[iGlu2] = newCol2;
1234 acols[iGlu2] = newCol1;
1236 // Unknown decay mode means failure.
1237 } else return false;
1239 // Set maximum scale to be mass of decaying particle.
1247 //==========================================================================
1249 } // end namespace Pythia8