1 // ParticleDecays.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2012 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 multIncreaseWeak = settings.parm("ParticleDecays:multIncreaseWeak");
96 multRefMass = settings.parm("ParticleDecays:multRefMass");
97 multGoffset = settings.parm("ParticleDecays:multGoffset");
98 colRearrange = settings.parm("ParticleDecays:colRearrange");
100 // Minimum energy in system (+ m_q) from StringFragmentation.
101 stopMass = settings.parm("StringFragmentation:stopMass");
103 // Parameters for Dalitz decay virtual gamma mass spectrum.
104 sRhoDal = pow2(particleDataPtr->m0(113));
105 wRhoDal = pow2(particleDataPtr->mWidth(113));
107 // Allow showers in decays to qqbar/gg/ggg/gammagg.
108 doFSRinDecays = settings.flag("ParticleDecays:FSRinDecays");
110 // Use standard decays or dedicated tau decay package
111 sophisticatedTau = settings.mode("ParticleDecays:sophisticatedTau");
113 // Initialize the dedicated tau decay handler.
114 if (sophisticatedTau) tauDecayer.init(infoPtr, &settings,
115 particleDataPtr, rndmPtr, couplingsPtr);
119 //--------------------------------------------------------------------------
121 // Decay a particle; main method.
123 bool ParticleDecays::decay( int iDec, Event& event) {
125 // Check whether a decay is allowed, given the upcoming decay vertex.
126 Particle& decayer = event[iDec];
129 if (limitDecay && !checkVertex(decayer)) return true;
131 // Do not allow resonance decays (beyond handling capability).
132 if (decayer.isResonance()) {
133 infoPtr->errorMsg("Warning in ParticleDecays::decay: "
134 "resonance left undecayed");
138 // Fill the decaying particle in slot 0 of arrays.
139 idDec = decayer.id();
143 iProd.push_back( iDec );
144 idProd.push_back( idDec );
145 mProd.push_back( decayer.m() );
147 // Check for oscillations B0 <-> B0bar or B_s0 <-> B_s0bar.
148 bool hasOscillated = (abs(idDec) == 511 || abs(idDec) == 531)
149 ? oscillateB(decayer) : false;
150 if (hasOscillated) {idDec = - idDec; idProd[0] = idDec;}
152 // Particle data for decaying particle.
153 decDataPtr = &decayer.particleDataEntry();
155 // Optionally send on to external decay program.
156 bool doneExternally = false;
157 if (decDataPtr->doExternalDecay()) {
159 pProd.push_back(decayer.p());
160 doneExternally = decayHandlePtr->decay(idProd, mProd, pProd,
163 // If it worked, then store the decay products in the event record.
164 if (doneExternally) {
165 mult = idProd.size() - 1;
166 int status = (hasOscillated) ? 94 : 93;
167 for (int i = 1; i <= mult; ++i) {
168 int iPos = event.append( idProd[i], status, iDec, 0, 0, 0,
169 0, 0, pProd[i], mProd[i]);
170 iProd.push_back( iPos);
173 // Also mark mother decayed and store daughters.
174 event[iDec].statusNeg();
175 event[iDec].daughters( iProd[1], iProd[mult]);
179 // Check if the particle is tau and let the special tau decayer handle it.
180 if (decayer.idAbs() == 15 && !doneExternally && sophisticatedTau) {
181 doneExternally = tauDecayer.decay(iDec, event);
182 if (doneExternally) return true;
185 // Now begin normal internal decay treatment.
186 if (!doneExternally) {
188 // Allow up to ten tries to pick a channel.
189 if (!decDataPtr->preparePick(idDec, decayer.m())) return false;
190 bool foundChannel = false;
191 bool hasStored = false;
192 for (int iTryChannel = 0; iTryChannel < NTRYDECAY; ++iTryChannel) {
194 // Remove previous failed channel.
195 if (hasStored) event.popBack(mult);
198 // Pick new channel. Read out basics.
199 DecayChannel& channel = decDataPtr->pickChannel();
200 meMode = channel.meMode();
201 keepPartons = (meMode > 90 && meMode <= 100);
202 mult = channel.multiplicity();
204 // Allow up to ten tries for each channel (e.g with different masses).
205 bool foundMode = false;
206 for (int iTryMode = 0; iTryMode < NTRYDECAY; ++iTryMode) {
211 // Extract and store the decay products in local arrays.
213 for (int i = 0; i < mult; ++i) {
214 int idNow = channel.product(i);
215 int idAbs = abs(idNow);
216 if ( idAbs < 10 || idAbs == 21 || idAbs == 81 || idAbs == 82
217 || idAbs == 83 || (idAbs > 1000 && idAbs < 10000
218 && (idAbs/10)%10 == 0) ) hasPartons = true;
219 if (idDec < 0 && particleDataPtr->hasAnti(idNow)) idNow = -idNow;
220 double mNow = particleDataPtr->mass(idNow);
221 idProd.push_back( idNow);
222 mProd.push_back( mNow);
225 // Decays into partons usually translate into hadrons.
226 if (hasPartons && !keepPartons && !pickHadrons()) continue;
228 // Need to set colour flow if explicit decay to partons.
231 for (int i = 0; i <= mult; ++i) {
235 if (hasPartons && keepPartons && !setColours(event)) continue;
237 // Check that enough phase space for decay.
239 double mDiff = mProd[0];
240 for (int i = 1; i <= mult; ++i) mDiff -= mProd[i];
241 if (mDiff < mSafety) continue;
244 // End of inner trial loops. Check if succeeded or not.
248 if (!foundMode) continue;
250 // Store decay products in the event record.
251 int status = (hasOscillated) ? 92 : 91;
252 for (int i = 1; i <= mult; ++i) {
253 int iPos = event.append( idProd[i], status, iDec, 0, 0, 0,
254 cols[i], acols[i], Vec4(0., 0., 0., 0.), mProd[i], scale);
255 iProd.push_back( iPos);
259 // Pick mass of Dalitz decay. Temporarily change multiplicity.
260 if ( (meMode == 11 || meMode == 12 || meMode == 13)
261 && !dalitzMass() ) continue;
263 // Do a decay, split by multiplicity.
264 bool decayed = false;
265 if (mult == 1) decayed = oneBody(event);
266 else if (mult == 2) decayed = twoBody(event);
267 else if (mult == 3) decayed = threeBody(event);
268 else decayed = mGenerator(event);
269 if (!decayed) continue;
271 // Kinematics of gamma* -> l- l+ in Dalitz decay. Restore multiplicity.
272 if (meMode == 11 || meMode == 12 || meMode == 13)
273 dalitzKinematics(event);
275 // End of outer trial loops.
280 // If the decay worked, then mark mother decayed and store daughters.
282 event[iDec].statusNeg();
283 event[iDec].daughters( iProd[1], iProd[mult]);
285 // Else remove unused daughters and return failure.
287 if (hasStored) event.popBack(mult);
288 infoPtr->errorMsg("Error in ParticleDecays::decay: "
289 "failed to find workable decay channel");
293 // Now finished normal internal decay treatment.
296 // Set decay vertex when this is displaced.
297 if (event[iDec].hasVertex() || event[iDec].tau() > 0.) {
298 Vec4 vDec = event[iDec].vDec();
299 for (int i = 1; i <= mult; ++i) event[iProd[i]].vProd( vDec );
302 // Set lifetime of daughters.
303 for (int i = 1; i <= mult; ++i)
304 event[iProd[i]].tau( event[iProd[i]].tau0() * rndmPtr->exp() );
306 // In a decay explicitly to partons then optionally do a shower,
307 // and always flag that partonic system should be fragmented.
308 if (hasPartons && keepPartons && doFSRinDecays)
309 timesDecPtr->shower( iProd[1], iProd.back(), event, mProd[0]);
311 // For Hidden Valley particles also allow leptons to shower.
312 else if (event[iDec].idAbs() > 4900000 && event[iDec].idAbs() < 5000000
313 && doFSRinDecays && mult == 2 && event[iProd[1]].isLepton()) {
314 event[iProd[1]].scale(mProd[0]);
315 event[iProd[2]].scale(mProd[0]);
316 timesDecPtr->shower( iProd[1], iProd.back(), event, mProd[0]);
324 //--------------------------------------------------------------------------
326 // Check whether a decay is allowed, given the upcoming decay vertex.
328 bool ParticleDecays::checkVertex(Particle& decayer) {
330 // Check whether any of the conditions are not fulfilled.
331 if (limitTau0 && decayer.tau0() > tau0Max) return false;
332 if (limitTau && decayer.tau() > tauMax) return false;
333 if (limitRadius && pow2(decayer.xDec()) + pow2(decayer.yDec())
334 + pow2(decayer.zDec()) > pow2(rMax)) return false;
335 if (limitCylinder && (pow2(decayer.xDec()) + pow2(decayer.yDec())
336 > pow2(xyMax) || abs(decayer.zDec()) > zMax) ) return false;
343 //--------------------------------------------------------------------------
345 // Check for oscillations B0 <-> B0bar or B_s0 <-> B_s0bar.
347 bool ParticleDecays::oscillateB(Particle& decayer) {
349 // Extract relevant information and decide.
350 if (!mixB) return false;
351 double xBmix = (abs(decayer.id()) == 511) ? xBdMix : xBsMix;
352 double tau = decayer.tau();
353 double tau0 = decayer.tau0();
354 double probosc = pow2(sin(0.5 * xBmix * tau / tau0));
355 return (probosc > rndmPtr->flat());
359 //--------------------------------------------------------------------------
361 // Do a one-body decay. (Rare; e.g. for K0 -> K0_short.)
363 bool ParticleDecays::oneBody(Event& event) {
365 // References to the particles involved.
366 Particle& decayer = event[iProd[0]];
367 Particle& prod = event[iProd[1]];
369 // Set momentum and expand mother information.
370 prod.p( decayer.p() );
371 prod.m( decayer.m() );
372 prod.mother2( iProd[0] );
379 //--------------------------------------------------------------------------
381 // Do a two-body decay.
383 bool ParticleDecays::twoBody(Event& event) {
385 // References to the particles involved.
386 Particle& decayer = event[iProd[0]];
387 Particle& prod1 = event[iProd[1]];
388 Particle& prod2 = event[iProd[2]];
391 double m0 = mProd[0];
392 double m1 = mProd[1];
393 double m2 = mProd[2];
395 // Energies and absolute momentum in the rest frame.
396 if (m1 + m2 + mSafety > m0) return false;
397 double e1 = 0.5 * (m0*m0 + m1*m1 - m2*m2) / m0;
398 double e2 = 0.5 * (m0*m0 + m2*m2 - m1*m1) / m0;
399 double pAbs = 0.5 * sqrtpos( (m0 - m1 - m2) * (m0 + m1 + m2)
400 * (m0 + m1 - m2) * (m0 - m1 + m2) ) / m0;
402 // When meMode = 2, for V -> PS2 + PS3 (V = vector, pseudoscalar),
403 // need to check if production is PS0 -> PS1/gamma + V.
404 int iMother = event[iProd[0]].mother1();
407 if (iMother <= 0 || iMother >= iProd[0]) meMode = 0;
409 int iDaughter1 = event[iMother].daughter1();
410 int iDaughter2 = event[iMother].daughter2();
411 if (iDaughter2 != iDaughter1 + 1) meMode = 0;
413 int idMother = abs( event[iMother].id() );
414 if (idMother <= 100 || idMother%10 !=1
415 || (idMother/1000)%10 != 0) meMode = 0;
417 int iSister = (iProd[0] == iDaughter1) ? iDaughter2 : iDaughter1;
418 idSister = abs( event[iSister].id() );
419 if ( (idSister <= 100 || idSister%10 !=1
420 || (idSister/1000)%10 != 0) && idSister != 22) meMode = 0;
426 // Begin loop over matrix-element corrections.
427 double wtME, wtMEmax;
434 // Isotropic angles give three-momentum.
435 double cosTheta = 2. * rndmPtr->flat() - 1.;
436 double sinTheta = sqrt(1. - cosTheta*cosTheta);
437 double phi = 2. * M_PI * rndmPtr->flat();
438 double pX = pAbs * sinTheta * cos(phi);
439 double pY = pAbs * sinTheta * sin(phi);
440 double pZ = pAbs * cosTheta;
442 // Fill four-momenta and boost them away from mother rest frame.
443 prod1.p( pX, pY, pZ, e1);
444 prod2.p( -pX, -pY, -pZ, e2);
445 prod1.bst( decayer.p(), decayer.m() );
446 prod2.bst( decayer.p(), decayer.m() );
448 // Matrix element for PS0 -> PS1 + V1 -> PS1 + PS2 + PS3 of form
449 // cos**2(theta02) in V1 rest frame, and for PS0 -> gamma + V1
450 // -> gamma + PS2 + PS3 of form sin**2(theta02).
452 double p10 = decayer.p() * event[iMother].p();
453 double p12 = decayer.p() * prod1.p();
454 double p02 = event[iMother].p() * prod1.p();
455 double s0 = pow2(event[iMother].m());
456 double s1 = pow2(decayer.m());
457 double s2 = pow2(prod1.m());
458 if (idSister != 22) wtME = pow2(p10 * p12 - s1 * p02);
459 else wtME = s1 * (2. * p10 * p12 * p02 - s1 * p02*p02
460 - s0 * p12*p12 - s2 * p10*p10 + s1 * s0 * s2);
461 wtME = max( wtME, 1e-6 * s1*s1 * s0 * s2);
462 wtMEmax = (p10*p10 - s1 * s0) * (p12*p12 - s1 * s2);
465 // Break out of loop if no sensible ME weight.
466 if(loop > NTRYMEWT) {
467 infoPtr->errorMsg("ParticleDecays::twoBody: "
468 "caught in infinite ME weight loop");
472 // If rejected, try again with new invariant masses.
473 } while ( wtME < rndmPtr->flat() * wtMEmax );
480 //--------------------------------------------------------------------------
482 // Do a three-body decay (except Dalitz decays).
484 bool ParticleDecays::threeBody(Event& event) {
486 // References to the particles involved.
487 Particle& decayer = event[iProd[0]];
488 Particle& prod1 = event[iProd[1]];
489 Particle& prod2 = event[iProd[2]];
490 Particle& prod3 = event[iProd[3]];
492 // Mother and sum daughter masses. Fail if too close.
493 double m0 = mProd[0];
494 double m1 = mProd[1];
495 double m2 = mProd[2];
496 double m3 = mProd[3];
497 double mSum = m1 + m2 + m3;
498 double mDiff = m0 - mSum;
499 if (mDiff < mSafety) return false;
501 // Kinematical limits for 2+3 mass. Maximum phase-space weight.
502 double m23Min = m2 + m3;
503 double m23Max = m0 - m1;
504 double p1Max = 0.5 * sqrtpos( (m0 - m1 - m23Min) * (m0 + m1 + m23Min)
505 * (m0 + m1 - m23Min) * (m0 - m1 + m23Min) ) / m0;
506 double p23Max = 0.5 * sqrtpos( (m23Max - m2 - m3) * (m23Max + m2 + m3)
507 * (m23Max + m2 - m3) * (m23Max - m2 + m3) ) / m23Max;
508 double wtPSmax = 0.5 * p1Max * p23Max;
510 // Begin loop over matrix-element corrections.
511 double wtME, wtMEmax, wtPS, m23, p1Abs, p23Abs;
516 // Pick an intermediate mass m23 flat in the allowed range.
518 m23 = m23Min + rndmPtr->flat() * mDiff;
520 // Translate into relative momenta and find phase-space weight.
521 p1Abs = 0.5 * sqrtpos( (m0 - m1 - m23) * (m0 + m1 + m23)
522 * (m0 + m1 - m23) * (m0 - m1 + m23) ) / m0;
523 p23Abs = 0.5 * sqrtpos( (m23 - m2 - m3) * (m23 + m2 + m3)
524 * (m23 + m2 - m3) * (m23 - m2 + m3) ) / m23;
525 wtPS = p1Abs * p23Abs;
527 // If rejected, try again with new invariant masses.
528 } while ( wtPS < rndmPtr->flat() * wtPSmax );
530 // Set up m23 -> m2 + m3 isotropic in its rest frame.
531 double cosTheta = 2. * rndmPtr->flat() - 1.;
532 double sinTheta = sqrt(1. - cosTheta*cosTheta);
533 double phi = 2. * M_PI * rndmPtr->flat();
534 double pX = p23Abs * sinTheta * cos(phi);
535 double pY = p23Abs * sinTheta * sin(phi);
536 double pZ = p23Abs * cosTheta;
537 double e2 = sqrt( m2*m2 + p23Abs*p23Abs);
538 double e3 = sqrt( m3*m3 + p23Abs*p23Abs);
539 prod2.p( pX, pY, pZ, e2);
540 prod3.p( -pX, -pY, -pZ, e3);
542 // Set up m0 -> m1 + m23 isotropic in its rest frame.
543 cosTheta = 2. * rndmPtr->flat() - 1.;
544 sinTheta = sqrt(1. - cosTheta*cosTheta);
545 phi = 2. * M_PI * rndmPtr->flat();
546 pX = p1Abs * sinTheta * cos(phi);
547 pY = p1Abs * sinTheta * sin(phi);
548 pZ = p1Abs * cosTheta;
549 double e1 = sqrt( m1*m1 + p1Abs*p1Abs);
550 double e23 = sqrt( m23*m23 + p1Abs*p1Abs);
551 prod1.p( pX, pY, pZ, e1);
553 // Boost 2 + 3 to the 0 rest frame.
554 Vec4 p23( -pX, -pY, -pZ, e23);
555 prod2.bst( p23, m23 );
556 prod3.bst( p23, m23 );
558 // Matrix-element weight for omega/phi -> pi+ pi- pi0.
560 double p1p2 = prod1.p() * prod2.p();
561 double p1p3 = prod1.p() * prod3.p();
562 double p2p3 = prod2.p() * prod3.p();
563 wtME = pow2(m1 * m2 * m3) - pow2(m1 * p2p3) - pow2(m2 * p1p3)
564 - pow2(m3 * p1p2) + 2. * p1p2 * p1p3 * p2p3;
565 wtMEmax = pow3(m0 * m0) / 150.;
567 // Effective matrix element for nu spectrum in tau -> nu + hadrons.
568 } else if (meMode == 21) {
569 double x1 = 2. * prod1.e() / m0;
570 wtME = x1 * (3. - 2. * x1);
571 double xMax = min( 0.75, 2. * (1. - mSum / m0) );
572 wtMEmax = xMax * (3. - 2. * xMax);
574 // Matrix element for weak decay (only semileptonic for c and b).
575 } else if ((meMode == 22 || meMode == 23) && prod1.isLepton()) {
576 wtME = m0 * prod1.e() * (prod2.p() * prod3.p());
577 wtMEmax = min( pow4(m0) / 16., m0 * (m0 - m1 - m2) * (m0 - m1 - m3)
580 // Effective matrix element for weak decay to hadrons (B -> D, D -> K).
581 } else if (meMode == 22 || meMode == 23) {
582 double x1 = 2. * prod1.pAbs() / m0;
583 wtME = x1 * (3. - 2. * x1);
584 double xMax = min( 0.75, 2. * (1. - mSum / m0) );
585 wtMEmax = xMax * (3. - 2. * xMax);
587 // Effective matrix element for gamma spectrum in B -> gamma + hadrons.
588 } else if (meMode == 31) {
589 double x1 = 2. * prod1.e() / m0;
591 double x1Max = 1. - pow2(mSum / m0);
592 wtMEmax = pow3(x1Max);
594 // Matrix-element weight for "onium" -> g + g + g or gamma + g + g.
595 } else if (meMode == 92) {
596 double x1 = 2. * prod1.e() / m0;
597 double x2 = 2. * prod2.e() / m0;
598 double x3 = 2. * prod3.e() / m0;
599 wtME = pow2( (1. - x1) / (x2 * x3) ) + pow2( (1. - x2) / (x1 * x3) )
600 + pow2( (1. - x3) / (x1 * x2) );
602 // For gamma + g + g require minimum mass for g + g system.
603 if (prod1.id() == 22 && sqrt(1. - x1) * m0 < 2. * stopMass) wtME = 0.;
604 if (prod2.id() == 22 && sqrt(1. - x2) * m0 < 2. * stopMass) wtME = 0.;
605 if (prod3.id() == 22 && sqrt(1. - x3) * m0 < 2. * stopMass) wtME = 0.;
608 // If rejected, try again with new invariant masses.
609 } while ( wtME < rndmPtr->flat() * wtMEmax );
611 // Boost 1 + 2 + 3 to the current frame.
612 prod1.bst( decayer.p(), decayer.m() );
613 prod2.bst( decayer.p(), decayer.m() );
614 prod3.bst( decayer.p(), decayer.m() );
621 //--------------------------------------------------------------------------
623 // Do a multibody decay using the M-generator algorithm.
625 bool ParticleDecays::mGenerator(Event& event) {
627 // Mother and sum daughter masses. Fail if too close or inconsistent.
628 double m0 = mProd[0];
629 double mSum = mProd[1];
630 for (int i = 2; i <= mult; ++i) mSum += mProd[i];
631 double mDiff = m0 - mSum;
632 if (mDiff < mSafety) return false;
634 // Begin setup of intermediate invariant masses.
636 for (int i = 0; i <= mult; ++i) mInv.push_back( mProd[i]);
638 // Calculate the maximum weight in the decay.
639 double wtPS, wtME, wtMEmax;
640 double wtPSmax = 1. / WTCORRECTION[mult];
641 double mMax = mDiff + mProd[mult];
643 for (int i = mult - 1; i > 0; --i) {
646 double mNow = mProd[i];
647 wtPSmax *= 0.5 * sqrtpos( (mMax - mMin - mNow) * (mMax + mMin + mNow)
648 * (mMax + mMin - mNow) * (mMax - mMin + mNow) ) / mMax;
651 // Begin loop over matrix-element corrections.
656 // Begin loop to find the set of intermediate invariant masses.
660 // Find and order random numbers in descending order.
662 rndmOrd.push_back(1.);
663 for (int i = 1; i < mult - 1; ++i) {
664 double rndm = rndmPtr->flat();
665 rndmOrd.push_back(rndm);
666 for (int j = i - 1; j > 0; --j) {
667 if (rndm > rndmOrd[j]) swap( rndmOrd[j], rndmOrd[j+1] );
671 rndmOrd.push_back(0.);
673 // Translate into intermediate masses and find weight.
674 for (int i = mult - 1; i > 0; --i) {
675 mInv[i] = mInv[i+1] + mProd[i] + (rndmOrd[i-1] - rndmOrd[i]) * mDiff;
676 wtPS *= 0.5 * sqrtpos( (mInv[i] - mInv[i+1] - mProd[i])
677 * (mInv[i] + mInv[i+1] + mProd[i]) * (mInv[i] + mInv[i+1] - mProd[i])
678 * (mInv[i] - mInv[i+1] + mProd[i]) ) / mInv[i];
681 // If rejected, try again with new invariant masses.
682 } while ( wtPS < rndmPtr->flat() * wtPSmax );
684 // Perform two-particle decays in the respective rest frame.
685 pInv.resize(mult + 1);
686 for (int i = 1; i < mult; ++i) {
687 double pAbs = 0.5 * sqrtpos( (mInv[i] - mInv[i+1] - mProd[i])
688 * (mInv[i] + mInv[i+1] + mProd[i]) * (mInv[i] + mInv[i+1] - mProd[i])
689 * (mInv[i] - mInv[i+1] + mProd[i]) ) / mInv[i];
691 // Isotropic angles give three-momentum.
692 double cosTheta = 2. * rndmPtr->flat() - 1.;
693 double sinTheta = sqrt(1. - cosTheta*cosTheta);
694 double phi = 2. * M_PI * rndmPtr->flat();
695 double pX = pAbs * sinTheta * cos(phi);
696 double pY = pAbs * sinTheta * sin(phi);
697 double pZ = pAbs * cosTheta;
699 // Calculate energies, fill four-momenta.
700 double eHad = sqrt( mProd[i]*mProd[i] + pAbs*pAbs);
701 double eInv = sqrt( mInv[i+1]*mInv[i+1] + pAbs*pAbs);
702 event[iProd[i]].p( pX, pY, pZ, eHad);
703 pInv[i+1].p( -pX, -pY, -pZ, eInv);
706 // Boost decay products to the mother rest frame.
707 event[iProd[mult]].p( pInv[mult] );
708 for (int iFrame = mult - 1; iFrame > 1; --iFrame)
709 for (int i = iFrame; i <= mult; ++i)
710 event[iProd[i]].bst( pInv[iFrame], mInv[iFrame]);
712 // Effective matrix element for nu spectrum in tau -> nu + hadrons.
713 if (meMode == 21 && event[iProd[1]].isLepton()) {
714 double x1 = 2. * event[iProd[1]].e() / m0;
715 wtME = x1 * (3. - 2. * x1);
716 double xMax = min( 0.75, 2. * (1. - mSum / m0) );
717 wtMEmax = xMax * (3. - 2. * xMax);
719 // Effective matrix element for weak decay (only semileptonic for c and b).
720 // Particles 4 onwards should be made softer explicitly?
721 } else if ((meMode == 22 || meMode == 23) && event[iProd[1]].isLepton()) {
722 Vec4 pRest = event[iProd[3]].p();
723 for (int i = 4; i <= mult; ++i) pRest += event[iProd[i]].p();
724 wtME = m0 * event[iProd[1]].e() * (event[iProd[2]].p() * pRest);
725 for (int i = 4; i <= mult; ++i) wtME
726 *= exp(- event[iProd[i]].pAbs2() / pow2(sigmaSoft) );
727 wtMEmax = pow4(m0) / 16.;
729 // Effective matrix element for weak decay to hadrons (B -> D, D -> K).
730 } else if (meMode == 22 || meMode == 23) {
731 double x1 = 2. * event[iProd[1]].pAbs() / m0;
732 wtME = x1 * (3. - 2. * x1);
733 double xMax = min( 0.75, 2. * (1. - mSum / m0) );
734 wtMEmax = xMax * (3. - 2. * xMax);
736 // Effective matrix element for gamma spectrum in B -> gamma + hadrons.
737 } else if (meMode == 31) {
738 double x1 = 2. * event[iProd[1]].e() / m0;
740 double x1Max = 1. - pow2(mSum / m0);
741 wtMEmax = pow3(x1Max);
744 // If rejected, try again with new invariant masses.
745 } while ( wtME < rndmPtr->flat() * wtMEmax );
747 // Boost decay products to the current frame.
748 pInv[1].p( event[iProd[0]].p() );
749 for (int i = 1; i <= mult; ++i) event[iProd[i]].bst( pInv[1], mInv[1] );
756 //--------------------------------------------------------------------------
758 // Select mass of lepton pair in a Dalitz decay.
760 bool ParticleDecays::dalitzMass() {
762 // Mother and sum daughter masses.
764 for (int i = 1; i <= mult - 2; ++i) mSum1 += mProd[i];
765 if (meMode == 13) mSum1 *= MSAFEDALITZ;
766 double mSum2 = MSAFEDALITZ * (mProd[mult -1] + mProd[mult]);
767 double mDiff = mProd[0] - mSum1 - mSum2;
769 // Fail if too close or inconsistent.
770 if (mDiff < mSafety) return false;
771 if (idProd[mult - 1] + idProd[mult] != 0
772 || mProd[mult - 1] != mProd[mult]) {
773 infoPtr->errorMsg("Error in ParticleDecays::dalitzMass:"
774 " inconsistent flavour/mass assignments");
777 if ( meMode == 13 && (idProd[1] + idProd[2] != 0
778 || mProd[1] != mProd[2]) ) {
779 infoPtr->errorMsg("Error in ParticleDecays::dalitzMass:"
780 " inconsistent flavour/mass assignments");
784 // Case 1: one Dalitz pair.
785 if (meMode == 11 || meMode == 12) {
787 // Kinematical limits for gamma* squared mass.
788 double sGamMin = pow2(mSum2);
789 double sGamMax = pow2(mProd[0] - mSum1);
790 // Select virtual gamma squared mass. Guessed form for meMode == 12.
794 if (++loop > NTRYDALITZ) return false;
795 sGam = sGamMin * pow( sGamMax / sGamMin, rndmPtr->flat() );
796 wtGam = (1. + 0.5 * sGamMin / sGam) * sqrt(1. - sGamMin / sGam)
797 * pow3(1. - sGam / sGamMax) * sRhoDal * (sRhoDal + wRhoDal)
798 / ( pow2(sGam - sRhoDal) + sRhoDal * wRhoDal );
799 } while ( wtGam < rndmPtr->flat() );
801 // Store results in preparation for doing a one-less-body decay.
803 mProd[mult] = sqrt(sGam);
805 // Case 2: two Dalitz pairs.
808 // Kinematical limits for 1 + 2 and 3 + 4 gamma* masses.
809 double s0 = pow2(mProd[0]);
810 double s12Min = pow2(mSum1);
811 double s12Max = pow2(mProd[0] - mSum2);
812 double s34Min = pow2(mSum2);
813 double s34Max = pow2(mProd[0] - mSum1);
815 // Select virtual gamma squared masses. Guessed form for meMode == 13.
816 double s12, s34, wt12, wt34, wtPAbs, wtAll;
819 if (++loop > NTRYDALITZ) return false;
820 s12 = s12Min * pow( s12Max / s12Min, rndmPtr->flat() );
821 wt12 = (1. + 0.5 * s12Min / s12) * sqrt(1. - s12Min / s12)
822 * sRhoDal * (sRhoDal + wRhoDal)
823 / ( pow2(s12 - sRhoDal) + sRhoDal * wRhoDal );
824 s34 = s34Min * pow( s34Max / s34Min, rndmPtr->flat() );
825 wt34 = (1. + 0.5 * s34Min / s34) * sqrt(1. - s34Min / s34)
826 * sRhoDal * (sRhoDal + wRhoDal)
827 / ( pow2(s34 - sRhoDal) + sRhoDal * wRhoDal );
828 wtPAbs = sqrtpos( pow2(1. - (s12 + s34)/ s0)
829 - 4. * s12 * s34 / (s0 * s0) );
830 wtAll = wt12 * wt34 * pow3(wtPAbs);
831 if (wtAll > 1.) infoPtr->errorMsg(
832 "Error in ParticleDecays::dalitzMass: weight > 1");
833 } while (wtAll < rndmPtr->flat());
835 // Store results in preparation for doing a two-body decay.
837 mProd[1] = sqrt(s12);
838 mProd[2] = sqrt(s34);
846 //--------------------------------------------------------------------------
848 // Do kinematics of gamma* -> l- l+ in Dalitz decay.
850 bool ParticleDecays::dalitzKinematics(Event& event) {
852 // Restore multiplicity.
853 int nDal = (meMode < 13) ? 1 : 2;
856 // Loop over one or two lepton pairs.
857 for (int iDal = 0; iDal < nDal; ++iDal) {
859 // References to the particles involved.
860 Particle& decayer = event[iProd[0]];
861 Particle& prodA = (iDal == 0) ? event[iProd[mult - 1]]
863 Particle& prodB = (iDal == 0) ? event[iProd[mult]]
866 // Reconstruct required rotations and boosts backwards.
867 Vec4 pDec = decayer.p();
868 int iGam = (meMode < 13) ? mult - 1 : 2 - iDal;
869 Vec4 pGam = event[iProd[iGam]].p();
870 pGam.bstback( pDec, decayer.m() );
871 double phiGam = pGam.phi();
872 pGam.rot( 0., -phiGam);
873 double thetaGam = pGam.theta();
874 pGam.rot( -thetaGam, 0.);
876 // Masses and phase space in gamma* rest frame.
877 double mGam = (meMode < 13) ? mProd[mult - 1] : mProd[2 - iDal];
878 double mA = prodA.m();
879 double mB = prodB.m();
880 double mGamMin = MSAFEDALITZ * (mA + mB);
881 double mGamRat = pow2(mGamMin / mGam);
882 double pGamAbs = 0.5 * sqrtpos( (mGam - mA - mB) * (mGam + mA + mB) );
884 // Set up decay in gamma* rest frame, reference along +z axis.
885 double cosTheta, cos2Theta;
887 cosTheta = 2. * rndmPtr->flat() - 1.;
888 cos2Theta = cosTheta * cosTheta;
889 } while ( 1. + cos2Theta + mGamRat * (1. - cos2Theta)
890 < 2. * rndmPtr->flat() );
891 double sinTheta = sqrt(1. - cosTheta*cosTheta);
892 double phi = 2. * M_PI * rndmPtr->flat();
893 double pX = pGamAbs * sinTheta * cos(phi);
894 double pY = pGamAbs * sinTheta * sin(phi);
895 double pZ = pGamAbs * cosTheta;
896 double eA = sqrt( mA*mA + pGamAbs*pGamAbs);
897 double eB = sqrt( mB*mB + pGamAbs*pGamAbs);
898 prodA.p( pX, pY, pZ, eA);
899 prodB.p( -pX, -pY, -pZ, eB);
901 // Boost to lab frame.
902 prodA.bst( pGam, mGam);
903 prodB.bst( pGam, mGam);
904 prodA.rot( thetaGam, phiGam);
905 prodB.rot( thetaGam, phiGam);
906 prodA.bst( pDec, decayer.m() );
907 prodB.bst( pDec, decayer.m() );
915 //--------------------------------------------------------------------------
917 // Translate a partonic content into a set of actual hadrons.
919 bool ParticleDecays::pickHadrons() {
921 // Find partonic decay products. Rest are known id's, mainly hadrons,
922 // when necessary shuffled to beginning of idProd list.
926 bool closedGLoop = false;
927 for (int i = 1; i <= mult; ++i) {
928 int idAbs = abs(idProd[i]);
929 if ( idAbs < 9 || (idAbs > 1000 && idAbs < 10000 && (idAbs/10)%10 == 0)
930 || idAbs == 81 || idAbs == 82 || idAbs == 83) {
932 idPartons.push_back(idProd[i]);
933 if (idAbs == 83) closedGLoop = true;
937 idProd[nKnown] = idProd[i];
938 mProd[nKnown] = mProd[i];
943 // Replace generic spectator flavour code by the actual one.
944 for (int i = 0; i < nPartons; ++i) {
945 int idPart = idPartons[i];
948 int idAbs = abs(idDec);
949 if ( (idAbs/1000)%10 == 0 ) {
950 idNew = -(idAbs/10)%10;
951 if ((idAbs/100)%2 == 1) idNew = -idNew;
952 } else if ( (idAbs/100)%10 >= (idAbs/10)%10 )
953 idNew = 100 * ((idAbs/10)%100) + 3;
954 else idNew = 1000 * ((idAbs/10)%10) + 100 * ((idAbs/100)%10) + 1;
955 if (idDec < 0) idNew = -idNew;
957 // Replace generic random flavour by a randomly selected one.
958 } else if (idPart == 82 || idPart == 83) {
961 int idDummy = -flavSelPtr->pickLightQ();
962 FlavContainer flavDummy(idDummy, idPart - 82);
963 do idNew = flavSelPtr->pick(flavDummy).id;
965 mFlav = particleDataPtr->constituentMass(idNew);
966 } while (2. * mFlav + stopMass > mProd[0]);
967 } else if (idPart == -82 || idPart == -83) {
968 idNew = -idPartons[i-1];
970 idPartons[i] = idNew;
973 // Determine whether fixed multiplicity or to be selected at random.
974 int nMin = max( 2, nKnown + nPartons / 2);
975 if (meMode == 23) nMin = 3;
976 if (meMode > 41 && meMode <= 50) nMin = meMode - 40;
977 if (meMode > 51 && meMode <= 60) nMin = meMode - 50;
979 if (meMode == 0) nFix = nMin;
980 if (meMode == 11) nFix = 3;
981 if (meMode == 12) nFix = 4;
982 if (meMode > 61 && meMode <= 70) nFix = meMode - 60;
983 if (meMode > 71 && meMode <= 80) nFix = meMode - 70;
984 if (nFix > 0 && nKnown + nPartons/2 > nFix) return false;
986 // Initial values for loop to set new hadronic content.
987 int nFilled, nTotal, nNew, nSpec, nLeft;
990 bool diquarkClash = false;
991 bool usedChannel = false;
993 // Begin loop; interrupt if multiple tries fail.
996 if (nTry > NTRYPICK) return false;
998 // Initialize variables inside new try.
999 nFilled = nKnown + 1;
1000 idProd.resize(nFilled);
1001 mProd.resize(nFilled);
1006 for (int i = 1; i < nFilled; ++i) mDiff -= mProd[i];
1007 diquarkClash = false;
1008 usedChannel = false;
1010 // For weak decays collapse spectators to one particle.
1011 if ( (meMode == 22 || meMode == 23) && nLeft > 1) {
1012 FlavContainer flav1( idPartons[nPartons - 2] );
1013 FlavContainer flav2( idPartons[nPartons - 1] );
1015 do idHad = flavSelPtr->combine( flav1, flav2);
1017 double mHad = particleDataPtr->mass(idHad);
1019 idProd.push_back( idHad);
1020 mProd.push_back( mHad);
1026 // If there are partons left, then determine how many hadrons to pick.
1029 // For B -> gamma + X use geometrical distribution.
1031 double geom = rndmPtr->flat();
1036 } while (geom < 1. && nTotal < 10);
1038 // Calculate mass excess and from there average multiplicity.
1039 } else if (nFix == 0) {
1040 double multIncreaseNow = (meMode == 23)
1041 ? multIncreaseWeak : multIncrease;
1042 double mDiffPS = mDiff;
1043 for (int i = 0; i < nLeft; ++i)
1044 mDiffPS -= particleDataPtr->constituentMass( idPartons[i] );
1045 double average = 0.5 * (nKnown + nSpec) + 0.25 * nPartons
1046 + multIncreaseNow * log( max( 1.1, mDiffPS / multRefMass ) );
1047 if (closedGLoop) average += multGoffset;
1049 // Pick multiplicity according to Poissonian.
1052 for (int nNow = nMin + 1; nNow <= 10; ++nNow) {
1053 value *= average / nNow;
1058 sum *= rndmPtr->flat();
1062 value *= average / nTotal;
1064 } while (sum > 0. && nTotal < 10);
1066 // Alternatively predetermined multiplicity.
1070 nNew = nTotal - nKnown - nSpec;
1072 // Set up ends of fragmented system, as copy of idPartons.
1074 for (int i = 0; i < nLeft; ++i) {
1075 flavEnds.push_back( FlavContainer(idPartons[i]) );
1076 if (abs(idPartons[i]) > 100) flavSelPtr->assignPopQ( flavEnds[i] );
1079 // Fragment off at random, but save nLeft/2 for final recombination.
1080 if (nNew > nLeft/2) {
1081 FlavContainer flavNew;
1083 for (int i = 0; i < nNew - nLeft/2; ++i) {
1084 // When four quarks consider last one to be spectator.
1085 int iEnd = int( (nLeft - 1.) * rndmPtr->flat() );
1086 // Pick new flavour and form a new hadron.
1088 flavNew = flavSelPtr->pick( flavEnds[iEnd] );
1089 idHad = flavSelPtr->combine( flavEnds[iEnd], flavNew);
1090 } while (idHad == 0);
1091 // Store new hadron and endpoint flavour.
1092 idProd.push_back( idHad);
1093 flavEnds[iEnd].anti(flavNew);
1097 // When only two quarks left, combine to form final hadron.
1100 if ( abs(flavEnds[0].id) > 8 && abs(flavEnds[1].id) > 8)
1101 diquarkClash = true;
1103 do idHad = flavSelPtr->combine( flavEnds[0], flavEnds[1]);
1105 idProd.push_back( idHad);
1108 // If four quarks, decide how to pair them up.
1114 if ( rndmPtr->flat() < colRearrange) iEnd2 = 3;
1116 ( (flavEnds[iEnd1].id > 0 && flavEnds[iEnd1].id < 9)
1117 || flavEnds[iEnd1].id < -10 ) ? 1 : -1;
1118 if ( (flavEnds[iEnd2].id < 0 && flavEnds[iEnd2].id > -9)
1119 || flavEnds[iEnd2].id > 10 ) relColSign *= -1;
1120 if (relColSign == 1) iEnd2 = 2;
1121 if (iEnd2 == 2) iEnd3 = 1;
1122 if (iEnd2 == 3) iEnd4 = 1;
1124 // Then combine to get final two hadrons.
1126 if ( abs(flavEnds[iEnd1].id) > 8 && abs(flavEnds[iEnd2].id) > 8)
1127 diquarkClash = true;
1129 do idHad = flavSelPtr->combine( flavEnds[iEnd1], flavEnds[iEnd2]);
1131 idProd.push_back( idHad);
1133 if ( abs(flavEnds[iEnd3].id) > 8 && abs(flavEnds[iEnd4].id) > 8)
1134 diquarkClash = true;
1136 do idHad = flavSelPtr->combine( flavEnds[iEnd3], flavEnds[iEnd4]);
1138 idProd.push_back( idHad);
1142 // Find masses of the new hadrons.
1143 for (int i = nFilled; i < int(idProd.size()) ; ++i) {
1144 double mHad = particleDataPtr->mass(idProd[i]);
1145 mProd.push_back( mHad);
1150 // Optional: check that this decay mode is not explicitly defined.
1151 if ( (meMode > 61 && meMode <= 80) && mDiff > mSafety && !diquarkClash ) {
1152 int idMatch[10], idPNow;
1153 usedChannel = false;
1154 bool matched = false;
1155 // Loop through all channels. Done if not same multiplicity.
1156 for (int i = 0; i < decDataPtr->sizeChannels(); ++i) {
1157 DecayChannel& channel = decDataPtr->channel(i);
1158 if (channel.multiplicity() != nTotal) continue;
1159 for (int k = 0; k < nTotal; ++k) idMatch[k] = channel.product(k);
1160 // Match particles one by one until fail.
1161 // Do not distinguish K0/K0bar/K0short/K0long at this stage.
1162 for (int j = 0; j < nTotal; ++j) {
1164 idPNow = idProd[j + 1];
1165 if (idPNow == -311 || idPNow == 130 || idPNow == 310) idPNow = 311;
1166 for (int k = 0; k < nTotal - j; ++k)
1167 if (idMatch[k] == idPNow || (idMatch[k] == -311 && idPNow == 311)) {
1168 // Compress list of unmatched when matching worked.
1169 idMatch[k] = idMatch[nTotal - 1 - j];
1173 if (!matched) break;
1175 // If matching worked, then chosen channel to be rejected.
1176 if (matched) {usedChannel = true; break;}
1180 // Keep on trying until enough phase space and no clash.
1181 } while (mDiff < mSafety || diquarkClash || usedChannel);
1183 // Update particle multiplicity.
1184 mult = idProd.size() - 1;
1186 // For Dalitz decays shuffle Dalitz pair to the end of the list.
1187 if (meMode == 11 || meMode == 12) {
1190 for (int i = 1; i <= mult; ++i) {
1191 if (idProd[i] == 11 || idProd[i] == 13 || idProd[i] == 15) iL1 = i;
1192 if (idProd[i] == -11 || idProd[i] == -13 || idProd[i] == -15) iL2 = i;
1194 if (iL1 > 0 && iL2 > 0) {
1195 int idL1 = idProd[iL1];
1196 int idL2 = idProd[iL2];
1197 double mL1 = mProd[iL1];
1198 double mL2 = mProd[iL2];
1200 for (int i = 1; i <= mult; ++i) if (i != iL1 && i != iL2) {
1202 idProd[iMove] = idProd[i];
1203 mProd[iMove] = mProd[i];
1205 idProd[mult - 1] = idL1;
1206 idProd[mult] = idL2;
1207 mProd[mult - 1] = mL1;
1217 //--------------------------------------------------------------------------
1219 // Set colour flow and scale in a decay explicitly to partons.
1221 bool ParticleDecays::setColours(Event& event) {
1223 // Decay to q qbar (or qbar q).
1224 if (meMode == 91 && idProd[1] > 0 && idProd[1] < 9) {
1225 int newCol = event.nextColTag();
1228 } else if (meMode == 91 && idProd[1] < 0 && idProd[1] > -9) {
1229 int newCol = event.nextColTag();
1234 } else if (meMode == 91 && idProd[1] == 21) {
1235 int newCol1 = event.nextColTag();
1236 int newCol2 = event.nextColTag();
1243 } else if (meMode == 92 && idProd[1] == 21 && idProd[2] == 21
1244 && idProd[3] == 21) {
1245 int newCol1 = event.nextColTag();
1246 int newCol2 = event.nextColTag();
1247 int newCol3 = event.nextColTag();
1255 // Decay to g g gamma: locate which is gamma.
1256 } else if (meMode == 92) {
1257 int iGlu1 = (idProd[1] == 21) ? 1 : 3;
1258 int iGlu2 = (idProd[2] == 21) ? 2 : 3;
1259 int newCol1 = event.nextColTag();
1260 int newCol2 = event.nextColTag();
1261 cols[iGlu1] = newCol1;
1262 acols[iGlu1] = newCol2;
1263 cols[iGlu2] = newCol2;
1264 acols[iGlu2] = newCol1;
1266 // Unknown decay mode means failure.
1267 } else return false;
1269 // Set maximum scale to be mass of decaying particle.
1277 //==========================================================================
1279 } // end namespace Pythia8