StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TimeShower.cc
1 // TimeShower.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2014 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.
5 
6 // Function definitions (not found in the header) for the TimeShower class.
7 
8 #include "Pythia8/TimeShower.h"
9 
10 namespace Pythia8 {
11 
12 //==========================================================================
13 
14 // The TimeShower class.
15 
16 //--------------------------------------------------------------------------
17 
18 // Constants: could be changed here if desired, but normally should not.
19 // These are of technical nature, as described for each.
20 
21 // Minimal allowed c and b quark masses, for flavour thresholds.
22 const double TimeShower::MCMIN = 1.2;
23 const double TimeShower::MBMIN = 4.0;
24 
25 // For small x approximate 1 - sqrt(1 - x) by x/2.
26 const double TimeShower::SIMPLIFYROOT = 1e-8;
27 
28 // Do not allow x too close to 0 or 1 in matrix element expressions.
29 // Warning: cuts into phase space for E_CM > 2 * pTmin * sqrt(1/XMARGIN),
30 // i.e. will become problem roughly for E_CM > 10^6 GeV.
31 const double TimeShower::XMARGIN = 1e-12;
32 const double TimeShower::XMARGINCOMB = 1e-4;
33 
34 // Lower limit on PDF value in order to avoid division by zero.
35 const double TimeShower::TINYPDF = 1e-10;
36 
37 // Big starting value in search for smallest invariant-mass pair.
38 const double TimeShower::LARGEM2 = 1e20;
39 
40 // In g -> q qbar or gamma -> f fbar require m2_pair > this * m2_q/f.
41 const double TimeShower::THRESHM2 = 4.004;
42 
43 // Never pick pT so low that alphaS is evaluated too close to Lambda_3.
44 const double TimeShower::LAMBDA3MARGIN = 1.1;
45 
46 // Rescatter: rescattering + ISR + FSR + primordial kT can lead to
47 // systems not locally conserving momentum.
48 // Fix up momentum in intermediate systems with rescattering
49 const bool TimeShower::FIXRESCATTER = true;
50 // Veto negative energies when using FIXRESCATTER option.
51 const bool TimeShower::VETONEGENERGY = false;
52 // Do not allow too large time- or spacelike virtualities in fixing-up.
53 const double TimeShower::MAXVIRTUALITYFRACTION = 0.5;
54 // Do not allow too large negative spacelike energy in system rest frame.
55 const double TimeShower::MAXNEGENERGYFRACTION = 0.7;
56 
57 // Fudge extra weight for overestimation of weak shower t-channel correction.
58 const double TimeShower::WEAKPSWEIGHT = 5.;
59 
60 // Extra overestimate of g -> q qbar branching rate for DGLAP comparison.
61 const double TimeShower::WG2QEXTRA = 20.;
62 
63 //--------------------------------------------------------------------------
64 
65 // Initialize alphaStrong, alphaEM and related pTmin parameters.
66 
67 void TimeShower::init( BeamParticle* beamAPtrIn,
68  BeamParticle* beamBPtrIn) {
69 
70  // Store input pointers for future use.
71  beamAPtr = beamAPtrIn;
72  beamBPtr = beamBPtrIn;
73 
74  // Main flags.
75  doQCDshower = settingsPtr->flag("TimeShower:QCDshower");
76  doQEDshowerByQ = settingsPtr->flag("TimeShower:QEDshowerByQ");
77  doQEDshowerByL = settingsPtr->flag("TimeShower:QEDshowerByL");
78  doQEDshowerByGamma = settingsPtr->flag("TimeShower:QEDshowerByGamma");
79  doWeakShower = settingsPtr->flag("TimeShower:weakShower");
80  doMEcorrections = settingsPtr->flag("TimeShower:MEcorrections");
81  doMEafterFirst = settingsPtr->flag("TimeShower:MEafterFirst");
82  doPhiPolAsym = settingsPtr->flag("TimeShower:phiPolAsym");
83  doInterleave = settingsPtr->flag("TimeShower:interleave");
84  allowBeamRecoil = settingsPtr->flag("TimeShower:allowBeamRecoil");
85  dampenBeamRecoil = settingsPtr->flag("TimeShower:dampenBeamRecoil");
86  recoilToColoured = settingsPtr->flag("TimeShower:recoilToColoured");
87 
88  // Matching in pT of hard interaction or MPI to shower evolution.
89  pTmaxMatch = settingsPtr->mode("TimeShower:pTmaxMatch");
90  pTdampMatch = settingsPtr->mode("TimeShower:pTdampMatch");
91  pTmaxFudge = settingsPtr->parm("TimeShower:pTmaxFudge");
92  pTmaxFudgeMPI = settingsPtr->parm("TimeShower:pTmaxFudgeMPI");
93  pTdampFudge = settingsPtr->parm("TimeShower:pTdampFudge");
94 
95  // Charm and bottom mass thresholds.
96  mc = max( MCMIN, particleDataPtr->m0(4));
97  mb = max( MBMIN, particleDataPtr->m0(5));
98  m2c = mc * mc;
99  m2b = mb * mb;
100 
101  // Parameters of scale choices.
102  renormMultFac = settingsPtr->parm("TimeShower:renormMultFac");
103  factorMultFac = settingsPtr->parm("TimeShower:factorMultFac");
104  useFixedFacScale = settingsPtr->flag("TimeShower:useFixedFacScale");
105  fixedFacScale2 = pow2(settingsPtr->parm("TimeShower:fixedFacScale"));
106 
107  // Parameters of alphaStrong generation.
108  alphaSvalue = settingsPtr->parm("TimeShower:alphaSvalue");
109  alphaSorder = settingsPtr->mode("TimeShower:alphaSorder");
110  alphaSnfmax = settingsPtr->mode("StandardModel:alphaSnfmax");
111  alphaSuseCMW = settingsPtr->flag("TimeShower:alphaSuseCMW");
112  alphaS2pi = 0.5 * alphaSvalue / M_PI;
113 
114  // Initialize alphaStrong generation.
115  alphaS.init( alphaSvalue, alphaSorder, alphaSnfmax, alphaSuseCMW);
116 
117  // Lambda for 5, 4 and 3 flavours.
118  Lambda3flav = alphaS.Lambda3();
119  Lambda4flav = alphaS.Lambda4();
120  Lambda5flav = alphaS.Lambda5();
121  Lambda5flav2 = pow2(Lambda5flav);
122  Lambda4flav2 = pow2(Lambda4flav);
123  Lambda3flav2 = pow2(Lambda3flav);
124 
125  // Parameters of QCD evolution. Warn if pTmin must be raised.
126  nGluonToQuark = settingsPtr->mode("TimeShower:nGluonToQuark");
127  weightGluonToQuark = settingsPtr->mode("TimeShower:weightGluonToQuark");
128  scaleGluonToQuark = settingsPtr->parm("TimeShower:scaleGluonToQuark");
129  extraGluonToQuark = (weightGluonToQuark%4 == 3) ? WG2QEXTRA : 1.;
130  pTcolCutMin = settingsPtr->parm("TimeShower:pTmin");
131  if (pTcolCutMin > LAMBDA3MARGIN * Lambda3flav / sqrt(renormMultFac))
132  pTcolCut = pTcolCutMin;
133  else {
134  pTcolCut = LAMBDA3MARGIN * Lambda3flav / sqrt(renormMultFac);
135  ostringstream newPTcolCut;
136  newPTcolCut << fixed << setprecision(3) << pTcolCut;
137  infoPtr->errorMsg("Warning in TimeShower::init: pTmin too low",
138  ", raised to " + newPTcolCut.str() );
139  infoPtr->setTooLowPTmin(true);
140  }
141  pT2colCut = pow2(pTcolCut);
142 
143  // Parameters of alphaEM generation.
144  alphaEMorder = settingsPtr->mode("TimeShower:alphaEMorder");
145 
146  // Initialize alphaEM generation.
147  alphaEM.init( alphaEMorder, settingsPtr);
148 
149  // Parameters of QED evolution.
150  nGammaToQuark = settingsPtr->mode("TimeShower:nGammaToQuark");
151  nGammaToLepton = settingsPtr->mode("TimeShower:nGammaToLepton");
152  pTchgQCut = settingsPtr->parm("TimeShower:pTminChgQ");
153  pT2chgQCut = pow2(pTchgQCut);
154  pTchgLCut = settingsPtr->parm("TimeShower:pTminChgL");
155  pT2chgLCut = pow2(pTchgLCut);
156  mMaxGamma = settingsPtr->parm("TimeShower:mMaxGamma");
157  m2MaxGamma = pow2(mMaxGamma);
158 
159  // Parameters of weak evolution.
160  weakMode = settingsPtr->mode("TimeShower:weakShowerMode");
161  pTweakCut = settingsPtr->parm("TimeShower:pTminWeak");
162  pT2weakCut = pow2(pTweakCut);
163  weakEnhancement = settingsPtr->parm("WeakShower:enhancement");
164  singleWeakEmission = settingsPtr->flag("WeakShower:singleEmission");
165  vetoWeakJets = settingsPtr->flag("WeakShower:vetoWeakJets");
166  vetoWeakDeltaR2 = pow2(settingsPtr->parm("WeakShower:vetoWeakDeltaR"));
167 
168  // Consisteny check for gamma -> f fbar variables.
169  if (nGammaToQuark <= 0 && nGammaToLepton <= 0) doQEDshowerByGamma = false;
170 
171  // Possibility of a global recoil stategy, e.g. for MC@NLO.
172  globalRecoil = settingsPtr->flag("TimeShower:globalRecoil");
173  nMaxGlobalRecoil = settingsPtr->mode("TimeShower:nMaxGlobalRecoil");
174  // Number of splittings produced with global recoil.
175  nMaxGlobalBranch = settingsPtr->mode("TimeShower:nMaxGlobalBranch");
176  // Number of partons in Born-like events, to distinguish between S and H.
177  nFinalBorn = settingsPtr->mode("TimeShower:nPartonsInBorn");
178  // Flag to allow to start from a scale smaller than scalup.
179  globalRecoilMode = settingsPtr->mode("TimeShower:globalRecoilMode");
180  // Flag to allow to start from a scale smaller than scalup.
181  limitMUQ = settingsPtr->flag("TimeShower:limitPTmaxGlobal");
182 
183  // Fraction and colour factor of gluon emission off onium octat state.
184  octetOniumFraction = settingsPtr->parm("TimeShower:octetOniumFraction");
185  octetOniumColFac = settingsPtr->parm("TimeShower:octetOniumColFac");
186 
187  // Z0 and W+- properties needed for gamma/Z0 mixing and weak showers.
188  mZ = particleDataPtr->m0(23);
189  gammaZ = particleDataPtr->mWidth(23);
190  thetaWRat = 1. / (16. * coupSMPtr->sin2thetaW()
191  * coupSMPtr->cos2thetaW());
192  mW = particleDataPtr->m0(24);
193  gammaW = particleDataPtr->mWidth(24);
194 
195  // May have to fix up recoils related to rescattering.
196  allowRescatter = settingsPtr->flag("PartonLevel:MPI")
197  && settingsPtr->flag("MultipartonInteractions:allowRescatter");
198 
199  // Hidden Valley scenario with further shower activity.
200  doHVshower = settingsPtr->flag("HiddenValley:FSR");
201  nCHV = settingsPtr->mode("HiddenValley:Ngauge");
202  alphaHVfix = settingsPtr->parm("HiddenValley:alphaFSR");
203  pThvCut = settingsPtr->parm("HiddenValley:pTminFSR");
204  pT2hvCut = pThvCut * pThvCut;
205  CFHV = (nCHV == 1) ? 1. : (nCHV * nCHV - 1.)/(2. * nCHV);
206  idHV = (nCHV == 1) ? 4900022 : 4900021;
207  mHV = particleDataPtr->m0(idHV);
208  brokenHVsym = (nCHV == 1 && mHV > 0.);
209 
210  // Possibility of two predetermined hard emissions in event.
211  doSecondHard = settingsPtr->flag("SecondHard:generate");
212 
213  // Possibility to allow user veto of emission step.
214  canVetoEmission = (userHooksPtr != 0)
215  ? userHooksPtr->canVetoFSREmission() : false;
216 
217  // Set initial value, just in case.
218  dopTdamp = false;
219  pT2damp = 0.;
220 
221  // Default values for the weak shower.
222  hasWeaklyRadiated = false;
223 
224 }
225 
226 //--------------------------------------------------------------------------
227 
228 // Find whether to limit maximum scale of emissions.
229 // Also allow for dampening at factorization or renormalization scale.
230 
231 bool TimeShower::limitPTmax( Event& event, double Q2Fac, double Q2Ren) {
232 
233  // Find whether to limit pT. Begin by user-set cases.
234  bool dopTlimit = false;
235  dopTlimit1 = dopTlimit2 = false;
236  if (pTmaxMatch == 1) dopTlimit = dopTlimit1 = dopTlimit2 = true;
237  else if (pTmaxMatch == 2) dopTlimit = dopTlimit1 = dopTlimit2 = false;
238 
239  // Always restrict SoftQCD processes.
240  else if (infoPtr->isNonDiffractive() || infoPtr->isDiffractiveA()
241  || infoPtr->isDiffractiveB() || infoPtr->isDiffractiveC() )
242  dopTlimit = dopTlimit1 = dopTlimit2 = true;
243 
244  // Look if any quark (u, d, s, c, b), gluon or photon in final state.
245  else {
246  int n21 = 0;
247  for (int i = 5; i < event.size(); ++i) {
248  if (event[i].status() == -21) ++n21;
249  else if (n21 == 0) {
250  int idAbs = event[i].idAbs();
251  if (idAbs <= 5 || idAbs == 21 || idAbs == 22) dopTlimit1 = true;
252  } else if (n21 == 2) {
253  int idAbs = event[i].idAbs();
254  if (idAbs <= 5 || idAbs == 21 || idAbs == 22) dopTlimit2 = true;
255  }
256  }
257  dopTlimit = (doSecondHard) ? (dopTlimit1 && dopTlimit2) : dopTlimit1;
258  }
259 
260  // Dampening at factorization or renormalization scale; only for hardest.
261  dopTdamp = false;
262  pT2damp = 0.;
263  if ( !dopTlimit1 && (pTdampMatch == 1 || pTdampMatch == 2) ) {
264  dopTdamp = true;
265  pT2damp = pow2(pTdampFudge) * ((pTdampMatch == 1) ? Q2Fac : Q2Ren);
266  }
267 
268  // Done.
269  return dopTlimit;
270 
271 }
272 
273 //--------------------------------------------------------------------------
274 
275 // Top-level routine to do a full time-like shower in resonance decay.
276 
277 int TimeShower::shower( int iBeg, int iEnd, Event& event, double pTmax,
278  int nBranchMax) {
279 
280  // Add new system, automatically with two empty beam slots.
281  int iSys = partonSystemsPtr->addSys();
282 
283  // Loop over allowed range to find all final-state particles.
284  Vec4 pSum;
285  for (int i = iBeg; i <= iEnd; ++i) if (event[i].isFinal()) {
286  partonSystemsPtr->addOut( iSys, i);
287  pSum += event[i].p();
288  }
289  partonSystemsPtr->setSHat( iSys, pSum.m2Calc() );
290 
291  // Let prepare routine do the setup.
292  dopTlimit1 = true;
293  dopTlimit2 = true;
294  dopTdamp = false;
295  hasWeaklyRadiated = false;
296  prepare( iSys, event, true);
297 
298  // Begin evolution down in pT from hard pT scale.
299  int nBranch = 0;
300  pTLastBranch = 0.;
301  do {
302  double pTtimes = pTnext( event, pTmax, 0.);
303 
304  // Do a final-state emission (if allowed).
305  if (pTtimes > 0.) {
306  if (branch( event)) {
307  ++nBranch;
308  pTLastBranch = pTtimes;
309  }
310  pTmax = pTtimes;
311  }
312 
313  // Keep on evolving until nothing is left to be done.
314  else pTmax = 0.;
315  } while (pTmax > 0. && (nBranchMax <= 0 || nBranch < nBranchMax));
316 
317  // Return number of emissions that were performed.
318  return nBranch;
319 
320 }
321 
322 //--------------------------------------------------------------------------
323 
324 // Top-level routine for QED radiation in hadronic decay to two leptons.
325 // Intentionally only does photon radiation, i.e. no photon branchings.
326 
327 int TimeShower::showerQED( int i1, int i2, Event& event, double pTmax) {
328 
329  // Add new system, automatically with two empty beam slots.
330  int iSys = partonSystemsPtr->addSys();
331  partonSystemsPtr->addOut( iSys, i1);
332  partonSystemsPtr->addOut( iSys, i2);
333  partonSystemsPtr->setSHat( iSys, m2(event[i1], event[i2]) );
334 
335  // Charge type of two leptons tells whether MEtype is gamma*/Z0 or W+-.
336  int iChg1 = event[i1].chargeType();
337  int iChg2 = event[i2].chargeType();
338  int MEtype = (iChg1 + iChg2 == 0) ? 102 : 101;
339 
340  // Fill dipole-ends list.
341  dipEnd.resize(0);
342  if (iChg1 != 0) dipEnd.push_back( TimeDipoleEnd(i1, i2, pTmax,
343  0, iChg1, 0, 0, 0, iSys, MEtype, i2) );
344  if (iChg2 != 0) dipEnd.push_back( TimeDipoleEnd(i2, i1, pTmax,
345  0, iChg2, 0, 0, 0, iSys, MEtype, i1) );
346 
347  // Begin evolution down in pT from hard pT scale.
348  int nBranch = 0;
349  pTLastBranch = 0.;
350  do {
351 
352  // Begin loop over all possible radiating dipole ends.
353  dipSel = 0;
354  iDipSel = -1;
355  double pT2sel = 0.;
356  for (int iDip = 0; iDip < int(dipEnd.size()); ++iDip) {
357  TimeDipoleEnd& dip = dipEnd[iDip];
358 
359  // Dipole properties.
360  dip.mRad = event[dip.iRadiator].m();
361  dip.mRec = event[dip.iRecoiler].m();
362  dip.mDip = m( event[dip.iRadiator], event[dip.iRecoiler] );
363  dip.m2Rad = pow2(dip.mRad);
364  dip.m2Rec = pow2(dip.mRec);
365  dip.m2Dip = pow2(dip.mDip);
366 
367  // Find maximum evolution scale for dipole.
368  dip.m2DipCorr = pow2(dip.mDip - dip.mRec) - dip.m2Rad;
369  double pTbegDip = min( pTmax, dip.pTmax );
370  double pT2begDip = min( pow2(pTbegDip), 0.25 * dip.m2DipCorr);
371 
372  // Do QED evolution where relevant.
373  dip.pT2 = 0.;
374  if (pT2begDip > pT2sel) {
375  pT2nextQED( pT2begDip, pT2sel, dip, event);
376 
377  // Update if found larger pT than current maximum. End dipole loop.
378  if (dip.pT2 > pT2sel) {
379  pT2sel = dip.pT2;
380  dipSel = &dip;
381  iDipSel = iDip;
382  }
383  }
384  }
385  double pTsel = (dipSel == 0) ? 0. : sqrt(pT2sel);
386 
387  // Do a final-state emission (if allowed).
388  if (pTsel > 0.) {
389 
390  // Find initial radiator and recoiler particles in dipole branching.
391  int iRadBef = dipSel->iRadiator;
392  int iRecBef = dipSel->iRecoiler;
393  Particle& radBef = event[iRadBef];
394  Particle& recBef = event[iRecBef];
395  Vec4 pRadBef = event[iRadBef].p();
396  Vec4 pRecBef = event[iRecBef].p();
397 
398  // Construct kinematics in dipole rest frame; massless emitter.
399  double pTorig = sqrt( dipSel->pT2);
400  double eRadPlusEmt = 0.5 * (dipSel->m2Dip + dipSel->m2 - dipSel->m2Rec)
401  / dipSel->mDip;
402  double e2RadPlusEmt = pow2(eRadPlusEmt);
403  double pzRadPlusEmt = 0.5 * sqrtpos( pow2(dipSel->m2Dip - dipSel->m2
404  - dipSel->m2Rec) - 4. * dipSel->m2 * dipSel->m2Rec ) / dipSel->mDip;
405  double pT2corr = dipSel->m2 * (e2RadPlusEmt * dipSel->z
406  * (1. - dipSel->z) - 0.25 * dipSel->m2) / pow2(pzRadPlusEmt);
407  double pTcorr = sqrtpos( pT2corr );
408  double pzRad = (e2RadPlusEmt * dipSel->z - 0.5 * dipSel->m2)
409  / pzRadPlusEmt;
410  double pzEmt = (e2RadPlusEmt * (1. - dipSel->z)
411  - 0.5 * dipSel->m2) / pzRadPlusEmt;
412  double mRad = dipSel->mRad;
413  double mEmt = 0.;
414 
415  // Kinematics reduction for radiator mass.
416  double m2Ratio = dipSel->m2Rad / dipSel->m2;
417  pTorig *= 1. - m2Ratio;
418  pTcorr *= 1. - m2Ratio;
419  pzRad += pzEmt * m2Ratio;
420  pzEmt *= 1. - m2Ratio;
421 
422  // Store kinematics of branching in dipole rest frame.
423  double phi = 2. * M_PI * rndmPtr->flat();
424  Vec4 pRad = Vec4( pTcorr * cos(phi), pTcorr * sin(phi), pzRad,
425  sqrt( pow2(pTcorr) + pow2(pzRad) + pow2(mRad) ) );
426  Vec4 pEmt = Vec4( -pRad.px(), -pRad.py(), pzEmt,
427  sqrt( pow2(pTcorr) + pow2(pzEmt) + pow2(mEmt) ) );
428  Vec4 pRec = Vec4( 0., 0., -pzRadPlusEmt,
429  sqrt( pow2(pzRadPlusEmt) + dipSel->m2Rec ) );
430 
431  // Rotate and boost dipole products to the event frame.
432  RotBstMatrix M;
433  M.fromCMframe(pRadBef, pRecBef);
434  pRad.rotbst(M);
435  pEmt.rotbst(M);
436  pRec.rotbst(M);
437 
438  // Define new particles from dipole branching.
439  Particle rad = Particle(radBef.id(), 51, iRadBef, 0, 0, 0,
440  radBef.col(), radBef.acol(), pRad, mRad, pTsel);
441  Particle emt = Particle(22, 51, iRadBef, 0, 0, 0,
442  0, 0, pEmt, mEmt, pTsel);
443  Particle rec = Particle(recBef.id(), 52, iRecBef, iRecBef, 0, 0,
444  recBef.col(), recBef.acol(), pRec, dipSel->mRec, pTsel);
445 
446  // ME corrections can lead to branching being rejected.
447  if (dipSel->MEtype == 0
448  || findMEcorr( dipSel, rad, rec, emt, false) > rndmPtr->flat() ) {
449 
450  // Shower may occur at a displaced vertex, or for unstable particle.
451  if (radBef.hasVertex()) {
452  rad.vProd( radBef.vProd() );
453  emt.vProd( radBef.vProd() );
454  }
455  if (recBef.hasVertex()) rec.vProd( recBef.vProd() );
456  rad.tau( event[iRadBef].tau() );
457  rec.tau( event[iRecBef].tau() );
458 
459  // Put new particles into the event record.
460  int iRad = event.append(rad);
461  int iEmt = event.append(emt);
462  event[iRadBef].statusNeg();
463  event[iRadBef].daughters( iRad, iEmt);
464  int iRec = event.append(rec);
465  event[iRecBef].statusNeg();
466  event[iRecBef].daughters( iRec, iRec);
467 
468  // Update to new dipole ends.
469  dipSel->iRadiator = iRad;
470  dipSel->iRecoiler = iRec;
471  dipSel->pTmax = pTsel;
472 
473  // Update other dipoles that also involved the radiator or recoiler.
474  for (int i = 0; i < int(dipEnd.size()); ++i) if (i != iDipSel) {
475  if (dipEnd[i].iRadiator == iRadBef) dipEnd[i].iRadiator = iRad;
476  if (dipEnd[i].iRecoiler == iRadBef) dipEnd[i].iRecoiler = iRad;
477  if (dipEnd[i].iMEpartner == iRadBef) dipEnd[i].iMEpartner = iRad;
478  if (dipEnd[i].iRadiator == iRecBef) dipEnd[i].iRadiator = iRec;
479  if (dipEnd[i].iRecoiler == iRecBef) dipEnd[i].iRecoiler = iRec;
480  if (dipEnd[i].iMEpartner == iRecBef) dipEnd[i].iMEpartner = iRec;
481  }
482 
483  // Done with branching
484  ++nBranch;
485  pTLastBranch = pTsel;
486  }
487  pTmax = pTsel;
488  }
489 
490  // Keep on evolving until nothing is left to be done.
491  else pTmax = 0.;
492  } while (pTmax > 0.);
493 
494  // Return number of emissions that were performed.
495  return nBranch;
496 
497 }
498 
499 //--------------------------------------------------------------------------
500 
501 // Global recoil: reset counters and store locations of outgoing partons.
502 
503 void TimeShower::prepareGlobal( Event& event) {
504 
505  // Global recoils: reset some counters.
506  nGlobal = 0;
507  nHard = 0;
508  nProposed = 0;
509  hardPartons.resize(0);
510 
511  // Global recoils: store positions of hard outgoing partons.
512  // No global recoil for H events.
513  if (globalRecoil) {
514  for (int i = 0; i < event.size(); ++i)
515  if (event[i].isFinal() && event[i].colType() != 0)
516  hardPartons.push_back(i);
517  nHard = hardPartons.size();
518  if (nFinalBorn > 0 && nHard > nFinalBorn) {
519  hardPartons.resize(0);
520  nHard = 0;
521  }
522  }
523 
524 }
525 
526 //--------------------------------------------------------------------------
527 
528 // Prepare system for evolution; identify ME.
529 
530 void TimeShower::prepare( int iSys, Event& event, bool limitPTmaxIn) {
531 
532  // Reset number of proposed splittings.
533  nProposed = 0;
534 
535  // Reset W/Z radiation flag at first call for new event.
536  if (iSys == 0) hasWeaklyRadiated = false;
537 
538  // Reset dipole-ends list for first interaction and for resonance decays.
539  int iInA = partonSystemsPtr->getInA(iSys);
540  int iInB = partonSystemsPtr->getInB(iSys);
541  if (iSys == 0 || iInA == 0) dipEnd.resize(0);
542  int dipEndSizeBeg = dipEnd.size();
543 
544  // No dipoles for 2 -> 1 processes.
545  if (partonSystemsPtr->sizeOut(iSys) < 2) return;
546 
547  // In case of DPS overwrite limitPTmaxIn by saved value.
548  if (doSecondHard && iSys == 0) limitPTmaxIn = dopTlimit1;
549  if (doSecondHard && iSys == 1) limitPTmaxIn = dopTlimit2;
550 
551  // Loop through final state of system to find possible dipole ends.
552  for (int i = 0; i < partonSystemsPtr->sizeOut(iSys); ++i) {
553  int iRad = partonSystemsPtr->getOut( iSys, i);
554  if (event[iRad].isFinal() && event[iRad].scale() > 0.) {
555 
556  // Identify colour octet onium state. Check whether QCD shower allowed.
557  int idRad = event[iRad].id();
558  int idRadAbs = abs(idRad);
559  bool isOctetOnium = particleDataPtr->isOctetHadron(idRad);
560  bool doQCD = doQCDshower;
561  if (doQCD && isOctetOnium)
562  doQCD = (rndmPtr->flat() < octetOniumFraction);
563 
564  // Find dipole end formed by colour index.
565  int colTag = event[iRad].col();
566  if (doQCD && colTag > 0) setupQCDdip( iSys, i, colTag, 1, event,
567  isOctetOnium, limitPTmaxIn);
568 
569  // Find dipole end formed by anticolour index.
570  int acolTag = event[iRad].acol();
571  if (doQCD && acolTag > 0) setupQCDdip( iSys, i, acolTag, -1, event,
572  isOctetOnium, limitPTmaxIn);
573 
574  // Find "charge-dipole" and "photon-dipole" ends.
575  int chgType = event[iRad].chargeType();
576  bool doChgDip = (chgType != 0)
577  && ( ( doQEDshowerByQ && event[iRad].isQuark() )
578  || ( doQEDshowerByL && event[iRad].isLepton() ) );
579  int gamType = (idRad == 22) ? 1 : 0;
580  bool doGamDip = (gamType == 1) && doQEDshowerByGamma;
581  if (doChgDip || doGamDip) setupQEDdip( iSys, i, chgType, gamType,
582  event, limitPTmaxIn);
583 
584  // Find weak diple ends.
585  if (doWeakShower && (iSys == 0 || !partonSystemsPtr->hasInAB(iSys))
586  && (event[iRad].isQuark() || event[iRad].isLepton())) {
587  if (weakMode == 0 || weakMode == 1)
588  setupWeakdip( iSys, i, 1, event, limitPTmaxIn);
589  if (weakMode == 0 || weakMode == 2)
590  setupWeakdip( iSys, i, 2, event, limitPTmaxIn);
591  }
592 
593  // Find Hidden Valley dipole ends.
594  bool isHVrad = (idRadAbs > 4900000 && idRadAbs < 4900007)
595  || (idRadAbs > 4900010 && idRadAbs < 4900017)
596  || idRadAbs == 4900101;
597  if (doHVshower && isHVrad) setupHVdip( iSys, i, event, limitPTmaxIn);
598 
599  // End loop over system final state. Have now found the dipole ends.
600  }
601  }
602 
603  // Loop through dipole ends to find matrix element corrections.
604  for (int iDip = dipEndSizeBeg; iDip < int(dipEnd.size()); ++iDip)
605  findMEtype( event, dipEnd[iDip]);
606 
607  // Update dipole list after a multiparton interactions rescattering.
608  if (iSys > 0 && ( (iInA > 0 && event[iInA].status() == -34)
609  || (iInB > 0 && event[iInB].status() == -34) ) )
610  rescatterUpdate( iSys, event);
611 
612 }
613 
614 //--------------------------------------------------------------------------
615 
616 // Update dipole list after a multiparton interactions rescattering.
617 
618 void TimeShower::rescatterUpdate( int iSys, Event& event) {
619 
620  // Loop over two incoming partons in system; find their rescattering mother.
621  // (iOut is outgoing from old system = incoming iIn of rescattering system.)
622  for (int iResc = 0; iResc < 2; ++iResc) {
623  int iIn = (iResc == 0) ? partonSystemsPtr->getInA(iSys)
624  : partonSystemsPtr->getInB(iSys);
625  if (iIn == 0 || event[iIn].status() != -34) continue;
626  int iOut = event[iIn].mother1();
627 
628  // Loop over all dipoles.
629  int dipEndSize = dipEnd.size();
630  for (int iDip = 0; iDip < dipEndSize; ++iDip) {
631  TimeDipoleEnd& dipNow = dipEnd[iDip];
632 
633  // Kill dipoles where rescattered parton is radiator.
634  if (dipNow.iRadiator == iOut) {
635  dipNow.colType = 0;
636  dipNow.chgType = 0;
637  dipNow.gamType = 0;
638  continue;
639  }
640  // No matrix element for dipoles between scatterings.
641  if (dipNow.iMEpartner == iOut) {
642  dipNow.MEtype = 0;
643  dipNow.iMEpartner = -1;
644  }
645 
646  // Update dipoles where outgoing rescattered parton is recoiler.
647  if (dipNow.iRecoiler == iOut) {
648  int iRad = dipNow.iRadiator;
649 
650  // Colour dipole: recoil in final state, initial state or new.
651  if (dipNow.colType > 0) {
652  int colTag = event[iRad].col();
653  bool done = false;
654  for (int i = 0; i < partonSystemsPtr->sizeOut(iSys); ++i) {
655  int iRecNow = partonSystemsPtr->getOut( iSys, i);
656  if (event[iRecNow].acol() == colTag) {
657  dipNow.iRecoiler = iRecNow;
658  dipNow.systemRec = iSys;
659  dipNow.MEtype = 0;
660  done = true;
661  break;
662  }
663  }
664  if (!done) {
665  int iIn2 = (iResc == 0) ? partonSystemsPtr->getInB(iSys)
666  : partonSystemsPtr->getInA(iSys);
667  if (event[iIn2].col() == colTag) {
668  dipNow.iRecoiler = iIn2;
669  dipNow.systemRec = iSys;
670  dipNow.MEtype = 0;
671  int isrType = event[iIn2].mother1();
672  // This line in case mother is a rescattered parton.
673  while (isrType > 2 + beamOffset)
674  isrType = event[isrType].mother1();
675  if (isrType > 2) isrType -= beamOffset;
676  dipNow.isrType = isrType;
677  done = true;
678  }
679  }
680  // If above options failed, then create new dipole.
681  if (!done) {
682  int iRadNow = partonSystemsPtr->getIndexOfOut(dipNow.system, iRad);
683  if (iRadNow != -1)
684  setupQCDdip(dipNow.system, iRadNow, event[iRad].col(), 1,
685  event, dipNow.isOctetOnium, true);
686  else
687  infoPtr->errorMsg("Warning in TimeShower::rescatterUpdate: "
688  "failed to locate radiator in system");
689 
690  dipNow.colType = 0;
691  dipNow.chgType = 0;
692  dipNow.gamType = 0;
693 
694  infoPtr->errorMsg("Warning in TimeShower::rescatterUpdate: "
695  "failed to locate new recoiling colour partner");
696  }
697 
698  // Anticolour dipole: recoil in final state, initial state or new.
699  } else if (dipNow.colType < 0) {
700  int acolTag = event[iRad].acol();
701  bool done = false;
702  for (int i = 0; i < partonSystemsPtr->sizeOut(iSys); ++i) {
703  int iRecNow = partonSystemsPtr->getOut( iSys, i);
704  if (event[iRecNow].col() == acolTag) {
705  dipNow.iRecoiler = iRecNow;
706  dipNow.systemRec = iSys;
707  dipNow.MEtype = 0;
708  done = true;
709  break;
710  }
711  }
712  if (!done) {
713  int iIn2 = (iResc == 0) ? partonSystemsPtr->getInB(iSys)
714  : partonSystemsPtr->getInA(iSys);
715  if (event[iIn2].acol() == acolTag) {
716  dipNow.iRecoiler = iIn2;
717  dipNow.systemRec = iSys;
718  dipNow.MEtype = 0;
719  int isrType = event[iIn2].mother1();
720  // This line in case mother is a rescattered parton.
721  while (isrType > 2 + beamOffset)
722  isrType = event[isrType].mother1();
723  if (isrType > 2) isrType -= beamOffset;
724  dipNow.isrType = isrType;
725  done = true;
726  }
727  }
728  // If above options failed, then create new dipole.
729  if (!done) {
730  int iRadNow = partonSystemsPtr->getIndexOfOut(dipNow.system, iRad);
731  if (iRadNow != -1)
732  setupQCDdip(dipNow.system, iRadNow, event[iRad].acol(), -1,
733  event, dipNow.isOctetOnium, true);
734  else
735  infoPtr->errorMsg("Warning in TimeShower::rescatterUpdate: "
736  "failed to locate radiator in system");
737 
738  dipNow.colType = 0;
739  dipNow.chgType = 0;
740  dipNow.gamType = 0;
741 
742  infoPtr->errorMsg("Warning in TimeShower::rescatterUpdate: "
743  "failed to locate new recoiling colour partner");
744  }
745 
746  // Charge or photon dipoles: same flavour in final or initial state.
747  } else if (dipNow.chgType != 0 || dipNow.gamType != 0) {
748  int idTag = event[dipNow.iRecoiler].id();
749  bool done = false;
750  for (int i = 0; i < partonSystemsPtr->sizeOut(iSys); ++i) {
751  int iRecNow = partonSystemsPtr->getOut( iSys, i);
752  if (event[iRecNow].id() == idTag) {
753  dipNow.iRecoiler = iRecNow;
754  dipNow.systemRec = iSys;
755  dipNow.MEtype = 0;
756  done = true;
757  break;
758  }
759  }
760  if (!done) {
761  int iIn2 = (iResc == 0) ? partonSystemsPtr->getInB(iSys)
762  : partonSystemsPtr->getInA(iSys);
763  if (event[iIn2].id() == -idTag) {
764  dipNow.iRecoiler = iIn2;
765  dipNow.systemRec = iSys;
766  dipNow.MEtype = 0;
767  int isrType = event[iIn2].mother1();
768  // This line in case mother is a rescattered parton.
769  while (isrType > 2 + beamOffset)
770  isrType = event[isrType].mother1();
771  if (isrType > 2) isrType -= beamOffset;
772  dipNow.isrType = isrType;
773  done = true;
774  }
775  }
776  // If above options failed, then create new dipole
777  if (!done) {
778  int iRadNow = partonSystemsPtr->getIndexOfOut(dipNow.system, iRad);
779  if (iRadNow != -1)
780  setupQEDdip(dipNow.system, iRadNow, dipNow.chgType,
781  dipNow.gamType, event, true);
782  else
783  infoPtr->errorMsg("Warning in TimeShower::rescatterUpdate: "
784  "failed to locate radiator in system");
785 
786  dipNow.colType = 0;
787  dipNow.chgType = 0;
788  dipNow.gamType = 0;
789 
790  infoPtr->errorMsg("Warning in TimeShower::rescatterUpdate: "
791  "failed to locate new recoiling charge partner");
792  }
793  }
794  }
795 
796  // End of loop over dipoles and two incoming sides.
797  }
798  }
799 
800 }
801 
802 //--------------------------------------------------------------------------
803 
804 // Update dipole list after each ISR emission (so not used for resonances).
805 
806  void TimeShower::update( int iSys, Event& event, bool hasWeakRad) {
807 
808  // Start list of rescatterers that gave further changed systems in ISR.
809  vector<int> iRescatterer;
810 
811  // Find new and old positions of incoming partons in the system.
812  vector<int> iNew, iOld;
813  iNew.push_back( partonSystemsPtr->getInA(iSys) );
814  iOld.push_back( event[iNew[0]].daughter2() );
815  iNew.push_back( partonSystemsPtr->getInB(iSys) );
816  iOld.push_back( event[iNew[1]].daughter2() );
817 
818  // Ditto for outgoing partons, except the newly created one.
819  int sizeOut = partonSystemsPtr->sizeOut(iSys) - 1;
820  for (int i = 0; i < sizeOut; ++i) {
821  int iNow = partonSystemsPtr->getOut(iSys, i);
822  iNew.push_back( iNow );
823  iOld.push_back( event[iNow].mother1() );
824  // Add non-final to list of rescatterers.
825  if (!event[iNow].isFinal()) iRescatterer.push_back( iNow );
826  }
827  int iNewNew = partonSystemsPtr->getOut(iSys, sizeOut);
828 
829  // Swap beams to let 0 be side on which branching occured.
830  if (event[iNew[0]].status() != -41) {
831  swap( iNew[0], iNew[1]);
832  swap( iOld[0], iOld[1]);
833  }
834 
835  // Loop over all dipole ends belonging to the system
836  // or to the recoil system, if different.
837  for (int iDip = 0; iDip < int(dipEnd.size()); ++iDip)
838  if (dipEnd[iDip].system == iSys || dipEnd[iDip].systemRec == iSys) {
839  TimeDipoleEnd& dipNow = dipEnd[iDip];
840 
841  // Replace radiator (always in final state so simple).
842  for (int i = 2; i < 2 + sizeOut; ++i)
843  if (dipNow.iRadiator == iOld[i]) {
844  dipNow.iRadiator = iNew[i];
845  break;
846  }
847 
848  // Replace ME partner (always in final state, if exists, so simple).
849  for (int i = 2; i < 2 + sizeOut; ++i)
850  if (dipNow.iMEpartner == iOld[i]) {
851  dipNow.iMEpartner = iNew[i];
852  break;
853  }
854 
855  // Recoiler: by default pick old one, only moved. Note excluded beam.
856  int iRec = 0;
857  if (dipNow.systemRec == iSys) {
858  for (int i = 1; i < 2 + sizeOut; ++i)
859  if (dipNow.iRecoiler == iOld[i]) {
860  iRec = iNew[i];
861  break;
862  }
863 
864  // QCD recoiler: check if colour hooks up with new final parton.
865  if ( dipNow.colType > 0
866  && event[dipNow.iRadiator].col() == event[iNewNew].acol() ) {
867  iRec = iNewNew;
868  dipNow.isrType = 0;
869  }
870  if ( dipNow.colType < 0
871  && event[dipNow.iRadiator].acol() == event[iNewNew].col() ) {
872  iRec = iNewNew;
873  dipNow.isrType = 0;
874  }
875 
876  // QCD recoiler: check if colour hooks up with new beam parton.
877  if ( iRec == 0 && dipNow.colType > 0
878  && event[dipNow.iRadiator].col() == event[iNew[0]].col() )
879  iRec = iNew[0];
880  if ( iRec == 0 && dipNow.colType < 0
881  && event[dipNow.iRadiator].acol() == event[iNew[0]].acol() )
882  iRec = iNew[0];
883 
884  // QED/photon recoiler: either to new particle or remains to beam.
885  if ( iRec == 0 && (dipNow.chgType != 0 || dipNow.gamType != 0) ) {
886  if ( event[iNew[0]].chargeType() == 0 ) {
887  iRec = iNewNew;
888  dipNow.isrType = 0;
889  } else {
890  iRec = iNew[0];
891  }
892  }
893 
894  // Recoiler in another system: keep it as is.
895  } else iRec = dipNow.iRecoiler;
896 
897  // Done. Kill dipole if failed to find new recoiler.
898  dipNow.iRecoiler = iRec;
899  if ( iRec == 0 && (dipNow.colType != 0 || dipNow.chgType != 0
900  || dipNow.gamType != 0) ) {
901  dipNow.colType = 0;
902  dipNow.chgType = 0;
903  dipNow.gamType = 0;
904  infoPtr->errorMsg("Error in TimeShower::update: "
905  "failed to locate new recoiling partner");
906  }
907 
908  // Kill weak dipoles if ISR emitted W/Z
909  // and only a single weak emission is allowed.
910  if (hasWeakRad && singleWeakEmission && dipNow.weakType != 0)
911  dipNow.weakType = 0;
912  }
913 
914  // Set the weak radiated variable to true if already radiated.
915  if (hasWeakRad) hasWeaklyRadiated = true;
916 
917  // Find new dipole end formed by colour index.
918  int colTag = event[iNewNew].col();
919  if (doQCDshower && colTag > 0)
920  setupQCDdip( iSys, sizeOut, colTag, 1, event, false, true);
921 
922  // Find new dipole end formed by anticolour index.
923  int acolTag = event[iNewNew].acol();
924  if (doQCDshower && acolTag > 0)
925  setupQCDdip( iSys, sizeOut, acolTag, -1, event, false, true);
926 
927 
928  // Find new "charge-dipole" and "photon-dipole" ends.
929  int chgType = event[iNewNew].chargeType();
930  bool doChgDip = (chgType != 0)
931  && ( ( doQEDshowerByQ && event[iNewNew].isQuark() )
932  || ( doQEDshowerByL && event[iNewNew].isLepton() ) );
933  int gamType = (event[iNewNew].id() == 22) ? 1 : 0;
934  bool doGamDip = (gamType == 1) && doQEDshowerByGamma;
935  if (doChgDip || doGamDip)
936  setupQEDdip( iSys, sizeOut, chgType, gamType, event, true);
937 
938  // Find new weak dipole.
939  // Uses the size of dipEnd to tell whether a new dipole is added.
940  unsigned int nDips = dipEnd.size();
941  if (doWeakShower && (event[iNewNew].isQuark() || event[iNewNew].isLepton())
942  && !(hasWeaklyRadiated && singleWeakEmission)
943  && (iSys == 0 || !partonSystemsPtr->hasInAB(iSys))) {
944 
945  if (weakMode == 0 || weakMode == 1)
946  setupWeakdip( iSys, sizeOut, 1, event, true);
947  // If added new dipole update the ME correction and me partner.
948  if (nDips != dipEnd.size()) {
949  nDips = dipEnd.size();
950  dipEnd.back().MEtype = 200;
951  dipEnd.back().iMEpartner = dipEnd.back().iRecoiler;
952  }
953 
954  if (weakMode == 0 || weakMode == 2)
955  setupWeakdip( iSys, sizeOut, 2, event, true);
956  // If added new dipole, update the ME correction and me partner.
957  if (nDips != dipEnd.size()) {
958  nDips = dipEnd.size();
959  dipEnd.back().MEtype = 205;
960  dipEnd.back().iMEpartner = dipEnd.back().iRecoiler;
961  }
962  }
963 
964  // Start iterate over list of rescatterers - may be empty.
965  int iRescNow = -1;
966  while (++iRescNow < int(iRescatterer.size())) {
967 
968  // Identify systems that rescatterers belong to.
969  int iOutNew = iRescatterer[iRescNow];
970  int iInNew = event[iOutNew].daughter1();
971  int iSysResc = partonSystemsPtr->getSystemOf(iInNew, true);
972 
973  // Find new and old positions of incoming partons in the system.
974  iNew.resize(0);
975  iOld.resize(0);
976  iNew.push_back( partonSystemsPtr->getInA(iSysResc) );
977  iOld.push_back( event[iNew[0]].daughter1() );
978  iNew.push_back( partonSystemsPtr->getInB(iSysResc) );
979  iOld.push_back( event[iNew[1]].daughter1() );
980 
981  // Ditto for outgoing partons.
982  sizeOut = partonSystemsPtr->sizeOut(iSysResc);
983  for (int i = 0; i < sizeOut; ++i) {
984  int iNow = partonSystemsPtr->getOut(iSysResc, i);
985  iNew.push_back( iNow );
986  iOld.push_back( event[iNow].mother1() );
987  // Add non-final to list of rescatterers.
988  if (!event[iNow].isFinal()) iRescatterer.push_back( iNow );
989  }
990 
991  // Loop over all dipole ends belonging to the system
992  // or to the recoil system, if different.
993  for (int iDip = 0; iDip < int(dipEnd.size()); ++iDip)
994  if (dipEnd[iDip].system == iSysResc
995  || dipEnd[iDip].systemRec == iSysResc) {
996  TimeDipoleEnd& dipNow = dipEnd[iDip];
997 
998  // Replace radiator (always in final state so simple).
999  for (int i = 2; i < 2 + sizeOut; ++i)
1000  if (dipNow.iRadiator == iOld[i]) {
1001  dipNow.iRadiator = iNew[i];
1002  break;
1003  }
1004 
1005  // Replace ME partner (always in final state, if exists, so simple).
1006  for (int i = 2; i < 2 + sizeOut; ++i)
1007  if (dipNow.iMEpartner == iOld[i]) {
1008  dipNow.iMEpartner = iNew[i];
1009  break;
1010  }
1011 
1012  // Replace recoiler.
1013  for (int i = 0; i < 2 + sizeOut; ++i)
1014  if (dipNow.iRecoiler == iOld[i]) {
1015  dipNow.iRecoiler = iNew[i];
1016  break;
1017  }
1018  }
1019 
1020  // End iterate over list of rescatterers.
1021  }
1022 
1023 }
1024 
1025 //--------------------------------------------------------------------------
1026 
1027 // Setup a dipole end for a QCD colour charge.
1028 
1029 void TimeShower::setupQCDdip( int iSys, int i, int colTag, int colSign,
1030  Event& event, bool isOctetOnium, bool limitPTmaxIn) {
1031 
1032  // Initial values. Find if allowed to hook up beams.
1033  int iRad = partonSystemsPtr->getOut(iSys, i);
1034  int iRec = 0;
1035  int sizeAllA = partonSystemsPtr->sizeAll(iSys);
1036  int sizeOut = partonSystemsPtr->sizeOut(iSys);
1037  int sizeAll = ( allowBeamRecoil ) ? sizeAllA : sizeOut;
1038  int sizeIn = sizeAll - sizeOut;
1039  int sizeInA = sizeAllA - sizeIn - sizeOut;
1040  int iOffset = i + sizeAllA - sizeOut;
1041  bool otherSystemRec = false;
1042  bool allowInitial = (partonSystemsPtr->hasInAB(iSys)) ? true : false;
1043  // PS dec 2010: possibility to allow for several recoilers and each with
1044  // flexible normalization
1045  bool isFlexible = false;
1046  double flexFactor = 1.0;
1047  vector<int> iRecVec(0);
1048 
1049  // Colour: other end by same index in beam or opposite in final state.
1050  // Exclude rescattered incoming and not final outgoing.
1051  if (colSign > 0)
1052  for (int j = 0; j < sizeAll; ++j) if (j + sizeInA != iOffset) {
1053  int iRecNow = partonSystemsPtr->getAll(iSys, j + sizeInA);
1054  if ( ( j < sizeIn && event[iRecNow].col() == colTag
1055  && !event[iRecNow].isRescatteredIncoming() )
1056  || ( j >= sizeIn && event[iRecNow].acol() == colTag
1057  && event[iRecNow].isFinal() ) ) {
1058  iRec = iRecNow;
1059  break;
1060  }
1061  }
1062 
1063  // Anticolour: other end by same index in beam or opposite in final state.
1064  // Exclude rescattered incoming and not final outgoing.
1065  if (colSign < 0)
1066  for (int j = 0; j < sizeAll; ++j) if (j + sizeInA != iOffset) {
1067  int iRecNow = partonSystemsPtr->getAll(iSys, j + sizeInA);
1068  if ( ( j < sizeIn && event[iRecNow].acol() == colTag
1069  && !event[iRecNow].isRescatteredIncoming() )
1070  || ( j >= sizeIn && event[iRecNow].col() == colTag
1071  && event[iRecNow].isFinal() ) ) {
1072  iRec = iRecNow;
1073  break;
1074  }
1075  }
1076 
1077  // Resonance decays (= no instate):
1078  // other end to nearest recoiler in same system final state,
1079  // by (p_i + p_j)^2 - (m_i + m_j)^2 = 2 (p_i p_j - m_i m_j).
1080  // (junction colours more involved, so keep track if junction colour)
1081  bool hasJunction = false;
1082  if (iRec == 0 && !allowInitial) {
1083  for (int iJun = 0; iJun < event.sizeJunction(); ++ iJun) {
1084  // For types 1&2, all legs in final state
1085  // For types 3&4, two legs in final state
1086  // For types 5&6, one leg in final state
1087  int iBeg = (event.kindJunction(iJun)-1)/2;
1088  for (int iLeg = iBeg; iLeg < 3; ++iLeg)
1089  if (event.endColJunction( iJun, iLeg) == colTag) hasJunction = true;
1090  }
1091  double ppMin = LARGEM2;
1092  for (int j = 0; j < sizeOut; ++j) if (j != i) {
1093  int iRecNow = partonSystemsPtr->getOut(iSys, j);
1094  if (!event[iRecNow].isFinal()) continue;
1095  double ppNow = event[iRecNow].p() * event[iRad].p()
1096  - event[iRecNow].m() * event[iRad].m();
1097  if (ppNow < ppMin) {
1098  iRec = iRecNow;
1099  ppMin = ppNow;
1100  }
1101  }
1102  }
1103 
1104  // If no success then look for matching (anti)colour anywhere in final state.
1105  if ( iRec == 0 || (!doInterleave && !event[iRec].isFinal()) ) {
1106  iRec = 0;
1107  for (int j = 0; j < event.size(); ++j) if (event[j].isFinal())
1108  if ( (colSign > 0 && event[j].acol() == colTag)
1109  || (colSign < 0 && event[j].col() == colTag) ) {
1110  iRec = j;
1111  otherSystemRec = true;
1112  break;
1113  }
1114 
1115  // If no success then look for match to non-rescattered in initial state.
1116  if (iRec == 0 && allowInitial) {
1117  for (int iSysR = 0; iSysR < partonSystemsPtr->sizeSys(); ++iSysR)
1118  if (iSysR != iSys) {
1119  int j = partonSystemsPtr->getInA(iSysR);
1120  if (j > 0 && event[j].isRescatteredIncoming()) j = 0;
1121  if (j > 0 && ( (colSign > 0 && event[j].col() == colTag)
1122  || (colSign < 0 && event[j].acol() == colTag) ) ) {
1123  iRec = j;
1124  otherSystemRec = true;
1125  break;
1126  }
1127  j = partonSystemsPtr->getInB(iSysR);
1128  if (j > 0 && event[j].isRescatteredIncoming()) j = 0;
1129  if (j > 0 && ( (colSign > 0 && event[j].col() == colTag)
1130  || (colSign < 0 && event[j].acol() == colTag) ) ) {
1131  iRec = j;
1132  otherSystemRec = true;
1133  break;
1134  }
1135  }
1136  }
1137  }
1138 
1139  // Junctions (PS&ND dec 2010)
1140  // For types 1&2: all legs in final state
1141  // half-strength dipoles between all legs
1142  // For types 3&4, two legs in final state
1143  // full-strength dipole between final-state legs
1144  // For types 5&6, one leg in final state
1145  // no final-state dipole end
1146 
1147  if (hasJunction) {
1148  for (int iJun = 0; iJun < event.sizeJunction(); ++ iJun) {
1149  int kindJun = event.kindJunction(iJun);
1150  int iBeg = (kindJun-1)/2;
1151  for (int iLeg = iBeg; iLeg < 3; ++iLeg) {
1152  if (event.endColJunction( iJun, iLeg) == colTag) {
1153  // For types 5&6, no other leg to recoil against. Switch off if
1154  // no other particles at all, since radiation then handled by ISR.
1155  // Example: qq -> ~t* : no radiation off ~t*
1156  // Allow radiation + recoil if unconnected partners available
1157  // Example: qq -> ~t* -> tbar ~chi0 : allow radiation off tbar,
1158  // with ~chi0 as recoiler
1159  if (kindJun >= 5) {
1160  if (sizeOut == 1) return;
1161  else break;
1162  }
1163  // For junction types 3 & 4, span one full-strength dipole
1164  // (only look inside same decay system)
1165  else if (kindJun >= 3) {
1166  int iLegRec = 3-iLeg;
1167  int colTagRec = event.endColJunction( iJun, iLegRec);
1168  for (int j = 0; j < sizeOut; ++j) if (j != i) {
1169  int iRecNow = partonSystemsPtr->getOut(iSys, j);
1170  if (!event[iRecNow].isFinal()) continue;
1171  if ( (colSign > 0 && event[iRecNow].col() == colTagRec)
1172  || (colSign < 0 && event[iRecNow].acol() == colTagRec) ) {
1173  // Only accept if staying inside same system
1174  iRec = iRecNow;
1175  break;
1176  }
1177  }
1178  }
1179  // For junction types 1 & 2, span two half-strength dipoles
1180  // (only look inside same decay system)
1181  else {
1182  // Loop over two half-strength dipole connections
1183  for (int jLeg = 1; jLeg <= 2; jLeg++) {
1184  int iLegRec = (iLeg + jLeg) % 3;
1185  int colTagRec = event.endColJunction( iJun, iLegRec);
1186  for (int j = 0; j < sizeOut; ++j) if (j != i) {
1187  int iRecNow = partonSystemsPtr->getOut(iSys, j);
1188  if (!event[iRecNow].isFinal()) continue;
1189  if ( (colSign > 0 && event[iRecNow].col() == colTagRec)
1190  || (colSign < 0 && event[iRecNow].acol() == colTagRec) ) {
1191  // Store recoilers in temporary array
1192  iRecVec.push_back(iRecNow);
1193  // Set iRec != 0 for checks below
1194  iRec = iRecNow;
1195  }
1196  }
1197  }
1198 
1199  } // End if-then-else of junction kinds
1200 
1201  } // End if leg has right color tag
1202  } // End of loop over junction legs
1203  } // End loop over junctions
1204 
1205  } // End main junction if
1206 
1207  // If fail, then other end to nearest recoiler in same system final state,
1208  // by (p_i + p_j)^2 - (m_i + m_j)^2 = 2 (p_i p_j - m_i m_j).
1209  if (iRec == 0) {
1210  double ppMin = LARGEM2;
1211  for (int j = 0; j < sizeOut; ++j) if (j != i) {
1212  int iRecNow = partonSystemsPtr->getOut(iSys, j);
1213  if (!event[iRecNow].isFinal()) continue;
1214  double ppNow = event[iRecNow].p() * event[iRad].p()
1215  - event[iRecNow].m() * event[iRad].m();
1216  if (ppNow < ppMin) {
1217  iRec = iRecNow;
1218  ppMin = ppNow;
1219  }
1220  }
1221  }
1222 
1223  // If fail, then other end to nearest recoiler in any system final state,
1224  // by (p_i + p_j)^2 - (m_i + m_j)^2 = 2 (p_i p_j - m_i m_j).
1225  if (iRec == 0) {
1226  double ppMin = LARGEM2;
1227  for (int iRecNow = 0; iRecNow < event.size(); ++iRecNow)
1228  if (iRecNow != iRad && event[iRecNow].isFinal()) {
1229  double ppNow = event[iRecNow].p() * event[iRad].p()
1230  - event[iRecNow].m() * event[iRad].m();
1231  if (ppNow < ppMin) {
1232  iRec = iRecNow;
1233  otherSystemRec = true;
1234  ppMin = ppNow;
1235  }
1236  }
1237  }
1238 
1239  // PS dec 2010: make sure iRec is stored in iRecVec
1240  if (iRecVec.size() == 0 && iRec != 0) iRecVec.push_back(iRec);
1241 
1242  // Remove any zero recoilers from normalization
1243  int nRec = iRecVec.size();
1244  for (unsigned int mRec = 0; mRec < iRecVec.size(); ++mRec)
1245  if (iRecVec[mRec] <= 0) nRec--;
1246  if (nRec >= 2) {
1247  isFlexible = true;
1248  flexFactor = 1.0/nRec;
1249  }
1250 
1251  // Check for failure to locate any recoiler
1252  if ( nRec <= 0 ) {
1253  infoPtr->errorMsg("Error in TimeShower::setupQCDdip: "
1254  "failed to locate any recoiling partner");
1255  return;
1256  }
1257 
1258  // Store dipole colour end(s).
1259  for (unsigned int mRec = 0; mRec < iRecVec.size(); ++mRec) {
1260  iRec = iRecVec[mRec];
1261  if (iRec <= 0) continue;
1262  // Max scale either by parton scale or by half dipole mass.
1263  double pTmax = event[iRad].scale();
1264  if (limitPTmaxIn) {
1265  if (iSys == 0 || (iSys == 1 && doSecondHard)) pTmax *= pTmaxFudge;
1266  else if (sizeIn > 0) pTmax *= pTmaxFudgeMPI;
1267  } else pTmax = 0.5 * m( event[iRad], event[iRec]);
1268  int colType = (event[iRad].id() == 21) ? 2 * colSign : colSign;
1269  int isrType = (event[iRec].isFinal()) ? 0 : event[iRec].mother1();
1270  // This line in case mother is a rescattered parton.
1271  while (isrType > 2 + beamOffset) isrType = event[isrType].mother1();
1272  if (isrType > 2) isrType -= beamOffset;
1273  dipEnd.push_back( TimeDipoleEnd( iRad, iRec, pTmax,
1274  colType, 0, 0, 0, isrType, iSys, -1, -1, 0, isOctetOnium) );
1275 
1276  // If hooked up with other system then find which.
1277  if (otherSystemRec) {
1278  int systemRec = partonSystemsPtr->getSystemOf(iRec, true);
1279  if (systemRec >= 0) dipEnd.back().systemRec = systemRec;
1280  dipEnd.back().MEtype = 0;
1281  }
1282 
1283  // PS dec 2010
1284  // If non-unity (flexible) normalization, set normalization factor
1285  if (isFlexible) {
1286  dipEnd.back().isFlexible = true;
1287  dipEnd.back().flexFactor = flexFactor;
1288  }
1289  }
1290 
1291 }
1292 
1293 //--------------------------------------------------------------------------
1294 
1295 // Setup a dipole end for a QED colour charge or a photon.
1296 // No failsafe choice of recoiler, so gradually widen search.
1297 
1298 void TimeShower::setupQEDdip( int iSys, int i, int chgType, int gamType,
1299  Event& event, bool limitPTmaxIn) {
1300 
1301  // Initial values. Find if allowed to hook up beams.
1302  int iRad = partonSystemsPtr->getOut(iSys, i);
1303  int idRad = event[iRad].id();
1304  int iRec = 0;
1305  int sizeAllA = partonSystemsPtr->sizeAll(iSys);
1306  int sizeOut = partonSystemsPtr->sizeOut(iSys);
1307  int sizeAll = ( allowBeamRecoil ) ? sizeAllA : sizeOut;
1308  int sizeIn = sizeAll - sizeOut;
1309  int sizeInA = sizeAllA - sizeIn - sizeOut;
1310  int iOffset = i + sizeAllA - sizeOut;
1311  double ppMin = LARGEM2;
1312  bool hasRescattered = false;
1313  bool otherSystemRec = false;
1314 
1315  // Find nearest same- (opposide-) flavour recoiler in initial (final)
1316  // state of same system, excluding rescattered (in or out) partons.
1317  // Also find if system is involved in rescattering.
1318  // Note: (p_i + p_j)2 - (m_i + m_j)2 = 2 (p_i p_j - m_i m_j).
1319  for (int j = 0; j < sizeAll; ++j) if (j + sizeInA != iOffset) {
1320  int iRecNow = partonSystemsPtr->getAll(iSys, j + sizeInA);
1321  if ( (j < sizeIn && !event[iRecNow].isRescatteredIncoming())
1322  || (j >= sizeIn && event[iRecNow].isFinal()) ) {
1323  if ( (j < sizeIn && event[iRecNow].id() == idRad)
1324  || (j >= sizeIn && event[iRecNow].id() == -idRad) ) {
1325  double ppNow = event[iRecNow].p() * event[iRad].p()
1326  - event[iRecNow].m() * event[iRad].m();
1327  if (ppNow < ppMin) {
1328  iRec = iRecNow;
1329  ppMin = ppNow;
1330  }
1331  }
1332  } else hasRescattered = true;
1333  }
1334 
1335  // If rescattering then find nearest opposite-flavour recoiler
1336  // anywhere in final state.
1337  if (iRec == 0 && hasRescattered) {
1338  for (int iRecNow = 0; iRecNow < event.size(); ++iRecNow)
1339  if (event[iRecNow].id() == -idRad && event[iRecNow].isFinal()) {
1340  double ppNow = event[iRecNow].p() * event[iRad].p()
1341  - event[iRecNow].m() * event[iRad].m();
1342  if (ppNow < ppMin) {
1343  iRec = iRecNow;
1344  ppMin = ppNow;
1345  otherSystemRec = true;
1346  }
1347  }
1348  }
1349 
1350  // Find nearest recoiler in same system, charge-squared-weighted,
1351  // including initial state, but excluding rescatterer.
1352  if (iRec == 0)
1353  for (int j = 0; j < sizeAll; ++j) if (j + sizeInA != iOffset) {
1354  int iRecNow = partonSystemsPtr->getAll(iSys, j + sizeInA);
1355  int chgTypeRecNow = event[iRecNow].chargeType();
1356  if (chgTypeRecNow == 0) continue;
1357  if ( (j < sizeIn && !event[iRecNow].isRescatteredIncoming())
1358  || (j >= sizeIn && event[iRecNow].isFinal()) ) {
1359  double ppNow = (event[iRecNow].p() * event[iRad].p()
1360  - event[iRecNow].m() * event[iRad].m())
1361  / pow2(chgTypeRecNow);
1362  if (ppNow < ppMin) {
1363  iRec = iRecNow;
1364  ppMin = ppNow;
1365  }
1366  }
1367  }
1368 
1369  // If rescattering then find nearest recoiler in the final state,
1370  // charge-squared-weighted.
1371  if (iRec == 0 && hasRescattered) {
1372  for (int iRecNow = 0; iRecNow < event.size(); ++iRecNow)
1373  if (iRecNow != iRad && event[iRecNow].isFinal()) {
1374  int chgTypeRecNow = event[iRecNow].chargeType();
1375  if (chgTypeRecNow != 0 && event[iRecNow].isFinal()) {
1376  double ppNow = (event[iRecNow].p() * event[iRad].p()
1377  - event[iRecNow].m() * event[iRad].m())
1378  / pow2(chgTypeRecNow);
1379  if (ppNow < ppMin) {
1380  iRec = iRecNow;
1381  ppMin = ppNow;
1382  otherSystemRec = true;
1383  }
1384  }
1385  }
1386  }
1387 
1388  // Find any nearest recoiler in final state of same system.
1389  if (iRec == 0)
1390  for (int j = 0; j < sizeOut; ++j) if (j != i) {
1391  int iRecNow = partonSystemsPtr->getOut(iSys, j);
1392  double ppNow = event[iRecNow].p() * event[iRad].p()
1393  - event[iRecNow].m() * event[iRad].m();
1394  if (ppNow < ppMin) {
1395  iRec = iRecNow;
1396  ppMin = ppNow;
1397  }
1398  }
1399 
1400  // Find any nearest recoiler in final state.
1401  if (iRec == 0)
1402  for (int iRecNow = 0; iRecNow < event.size(); ++iRecNow)
1403  if (iRecNow != iRad && event[iRecNow].isFinal()) {
1404  double ppNow = event[iRecNow].p() * event[iRad].p()
1405  - event[iRecNow].m() * event[iRad].m();
1406  if (ppNow < ppMin) {
1407  iRec = iRecNow;
1408  ppMin = ppNow;
1409  otherSystemRec = true;
1410  }
1411  }
1412 
1413  // Fill charge-dipole or photon-dipole end.
1414  if (iRec > 0) {
1415  // Max scale either by parton scale or by half dipole mass.
1416  double pTmax = event[iRad].scale();
1417  if (limitPTmaxIn) {
1418  if (iSys == 0 || (iSys == 1 && doSecondHard)) pTmax *= pTmaxFudge;
1419  else if (sizeIn > 0) pTmax *= pTmaxFudgeMPI;
1420  } else pTmax = 0.5 * m( event[iRad], event[iRec]);
1421  int isrType = (event[iRec].isFinal()) ? 0 : event[iRec].mother1();
1422  // This line in case mother is a rescattered parton.
1423  while (isrType > 2 + beamOffset) isrType = event[isrType].mother1();
1424  if (isrType > 2) isrType -= beamOffset;
1425  dipEnd.push_back( TimeDipoleEnd(iRad, iRec, pTmax,
1426  0, chgType, gamType, 0, isrType, iSys, -1) );
1427 
1428  // If hooked up with other system then find which.
1429  if (otherSystemRec) {
1430  int systemRec = partonSystemsPtr->getSystemOf(iRec);
1431  if (systemRec >= 0) dipEnd.back().systemRec = systemRec;
1432  dipEnd.back().MEtype = 0;
1433  }
1434 
1435  // Failure to find other end of dipole.
1436  } else {
1437  infoPtr->errorMsg("Error in TimeShower::setupQEDdip: "
1438  "failed to locate any recoiling partner");
1439  }
1440 
1441 }
1442 
1443 //--------------------------------------------------------------------------
1444 
1445  // Setup a dipole end for weak W or Z emission.
1446 
1447 void TimeShower::setupWeakdip( int iSys, int i, int weakType, Event& event,
1448  bool limitPTmaxIn) {
1449 
1450  // Initial values. Find if allowed to hook up beams.
1451  int iRad = partonSystemsPtr->getOut(iSys, i);
1452  int idRad = event[iRad].id();
1453  int iRec = 0;
1454  int sizeAllA = partonSystemsPtr->sizeAll(iSys);
1455  int sizeOut = partonSystemsPtr->sizeOut(iSys);
1456  // Only allow weak dipoles to take outgoing particles as recoiler.
1457  int sizeAll = sizeOut;
1458  int sizeIn = sizeAll - sizeOut;
1459  int sizeInA = sizeAllA - sizeIn - sizeOut;
1460  int iOffset = i + sizeAllA - sizeOut;
1461  double ppMin = LARGEM2;
1462  bool hasRescattered = false;
1463  bool otherSystemRec = false;
1464 
1465  // Find nearest same- (opposide-) flavour recoiler in initial (final)
1466  // state of same system, excluding rescattered (in or out) partons.
1467  // Also find if system is involved in rescattering.
1468  // Note: (p_i + p_j)2 - (m_i + m_j)2 = 2 (p_i p_j - m_i m_j).
1469  for (int j = 0; j < sizeAll; ++j)
1470  if (j + sizeInA != iOffset) {
1471  int iRecNow = partonSystemsPtr->getAll(iSys, j + sizeInA);
1472  if ( (j < sizeIn && !event[iRecNow].isRescatteredIncoming())
1473  || (j >= sizeIn && event[iRecNow].isFinal()) ) {
1474  if ( (j < sizeIn && event[iRecNow].id() == idRad)
1475  || (j >= sizeIn && event[iRecNow].id() == -idRad) ) {
1476  double ppNow = event[iRecNow].p() * event[iRad].p()
1477  - event[iRecNow].m() * event[iRad].m();
1478  if (ppNow < ppMin) {
1479  iRec = iRecNow;
1480  ppMin = ppNow;
1481  }
1482  }
1483  } else hasRescattered = true;
1484  }
1485 
1486  // If rescattering then find nearest opposite-flavour recoiler
1487  // anywhere in final state.
1488  if (iRec == 0 && hasRescattered) {
1489  for (int iRecNow = 0; iRecNow < event.size(); ++iRecNow)
1490  if (event[iRecNow].id() == -idRad && event[iRecNow].isFinal()) {
1491  double ppNow = event[iRecNow].p() * event[iRad].p()
1492  - event[iRecNow].m() * event[iRad].m();
1493  if (ppNow < ppMin) {
1494  iRec = iRecNow;
1495  ppMin = ppNow;
1496  otherSystemRec = true;
1497  }
1498  }
1499  }
1500 
1501  // Find nearest recoiler in same system, weak-charge-squared-weighted,
1502  // including initial state, but excluding rescatterer.
1503  if (iRec == 0)
1504  for (int j = 0; j < sizeAll; ++j) if (j + sizeInA != iOffset) {
1505  int iRecNow = partonSystemsPtr->getAll(iSys, j + sizeInA);
1506  if (abs(event[iRecNow].id()) >= 20 || weakType < 1
1507  || weakType > 2) continue;
1508  double weakCoupNow = 1.;
1509  if (weakType == 2) weakCoupNow = coupSMPtr->vf2(event[iRecNow].idAbs())
1510  + coupSMPtr->af2(event[iRecNow].idAbs());
1511  if ( (j < sizeIn && !event[iRecNow].isRescatteredIncoming())
1512  || (j >= sizeIn && event[iRecNow].isFinal()) ) {
1513  double ppNow = (event[iRecNow].p() * event[iRad].p()
1514  - event[iRecNow].m() * event[iRad].m()) / weakCoupNow;
1515  if (ppNow < ppMin) {
1516  iRec = iRecNow;
1517  ppMin = ppNow;
1518  }
1519  }
1520  }
1521 
1522  // If rescattering then find nearest recoiler in the final state,
1523  // weak-charge-squared-weighted.
1524  if (iRec == 0 && hasRescattered) {
1525  for (int iRecNow = 0; iRecNow < event.size(); ++iRecNow)
1526  if (iRecNow != iRad && event[iRecNow].isFinal()) {
1527  if (abs(event[iRecNow].id()) >= 20 || weakType < 1
1528  || weakType > 2) continue;
1529  double weakCoupNow = 1.;
1530  if (weakType == 2) weakCoupNow = coupSMPtr->vf2(event[iRecNow].idAbs())
1531  + coupSMPtr->af2(event[iRecNow].idAbs());
1532  double ppNow = (event[iRecNow].p() * event[iRad].p()
1533  - event[iRecNow].m() * event[iRad].m()) / weakCoupNow;
1534  if (ppNow < ppMin) {
1535  iRec = iRecNow;
1536  ppMin = ppNow;
1537  otherSystemRec = true;
1538  }
1539  }
1540  }
1541 
1542  // Find any nearest recoiler in final state of same system.
1543  if (iRec == 0)
1544  for (int j = 0; j < sizeOut; ++j) if (j != i) {
1545  int iRecNow = partonSystemsPtr->getOut(iSys, j);
1546  double ppNow = event[iRecNow].p() * event[iRad].p()
1547  - event[iRecNow].m() * event[iRad].m();
1548  if (ppNow < ppMin) {
1549  iRec = iRecNow;
1550  ppMin = ppNow;
1551  }
1552  }
1553 
1554  // Find any nearest recoiler in final state.
1555  if (iRec == 0)
1556  for (int iRecNow = 0; iRecNow < event.size(); ++iRecNow)
1557  if (iRecNow != iRad && event[iRecNow].isFinal()) {
1558  double ppNow = event[iRecNow].p() * event[iRad].p()
1559  - event[iRecNow].m() * event[iRad].m();
1560  if (ppNow < ppMin) {
1561  iRec = iRecNow;
1562  ppMin = ppNow;
1563  otherSystemRec = true;
1564  }
1565  }
1566 
1567  // Fill in weak dipole-end.
1568  if (iRec > 0) {
1569 
1570  // Calculate 2 -> 2 kinematics, needed for finding ISR fermion line.
1571  Vec4 p3weak = event[3].p();
1572  Vec4 p4weak = event[4].p();
1573  double tHat = (event[iRad].p() - p3weak).m2Calc();
1574  double uHat = (event[iRad].p() - p4weak).m2Calc();
1575 
1576  // Find correct helicity.
1577  int weakPol = (rndmPtr->flat() > 0.5) ? -1 : 1;
1578  // Check if particle has already gotten a helicity.
1579  if (event[iRad].pol() == 1 || event[iRad].pol() == -1)
1580  weakPol = event[iRad].pol();
1581  // If particle come from ISR radiation.
1582  else if (event[iRad].statusAbs() > 40) {
1583  if (event[event[iRad].mother1()].idAbs() < 20)
1584  weakPol = event[event[iRad].mother1()].pol();
1585  else if ((int)event[iRad].sisterList(true).size() != 0)
1586  weakPol = event[event[iRad].sisterList(true)[0]].pol();
1587  }
1588  // If it is not a 2 to 2 process, always use recoiler.
1589  else if (infoPtr->nFinal() != 2) {
1590  if (event[iRec].pol() == 1 || event[iRec].pol() == -1)
1591  weakPol = event[iRec].pol();
1592  }
1593  // If s-channel, choose same spin as recoiler.
1594  else if (idRad == - event[iRec].id()) {
1595  if (event[iRec].pol() == 1 || event[iRec].pol() == -1)
1596  weakPol = event[iRec].pol();
1597  }
1598  // if W-decay, choose always left handed.
1599  else if (event[event[iRad].mother1()].idAbs() == 24) weakPol = -1;
1600  // If four particles of the same type.
1601  else if (idRad == event[iRec].id()) {
1602  if (uHat*uHat/(tHat*tHat + uHat*uHat) > 0.5) weakPol = event[3].pol();
1603  else weakPol = event[4].pol();
1604  }
1605  // For different particle types, choose correct fermion line.
1606  else if (event[3].id() == idRad) weakPol = event[3].pol();
1607  else if (event[4].id() == idRad) weakPol = event[4].pol();
1608  // If weak ISR is turned off, this would try to use polarization
1609  // that is not set as expected. In this case use random polarization.
1610  if (weakPol > 1) weakPol = (rndmPtr->flat() > 0.5) ? -1 : 1;
1611  event[iRad].pol(weakPol);
1612 
1613  // Max scale either by parton scale or by half dipole mass.
1614  double pTmax = event[iRad].scale();
1615  if (limitPTmaxIn) {
1616  if (iSys == 0) pTmax *= pTmaxFudge;
1617  if (iSys > 0 && sizeIn > 0) pTmax *= pTmaxFudgeMPI;
1618  } else pTmax = 0.5 * m( event[iRad], event[iRec]);
1619  int isrType = (event[iRec].isFinal()) ? 0 : event[iRec].mother1();
1620  // This line in case mother is a rescattered parton.
1621  while (isrType > 2 + beamOffset) isrType = event[isrType].mother1();
1622  if (isrType > 2) isrType -= beamOffset;
1623  // No right-handed W emission.
1624 
1625  if (weakType == 1 && weakPol == 1) return;
1626  dipEnd.push_back( TimeDipoleEnd(iRad, iRec, pTmax,
1627  0, 0, 0, weakType, isrType, iSys, -1, -1, weakPol) );
1628 
1629  // If hooked up with other system then find which.
1630  if (otherSystemRec) {
1631  int systemRec = partonSystemsPtr->getSystemOf(iRec);
1632  if (systemRec >= 0) dipEnd.back().systemRec = systemRec;
1633  dipEnd.back().MEtype = 0;
1634  }
1635 
1636  // Failure to find other end of dipole.
1637  } else {
1638  infoPtr->errorMsg("Error in TimeShower::setupWeakdip: "
1639  "failed to locate any recoiling partner");
1640  }
1641 }
1642 
1643 //--------------------------------------------------------------------------
1644 
1645 // Setup a dipole end for a Hidden Valley colour charge.
1646 
1647 void TimeShower::setupHVdip( int iSys, int i, Event& event,
1648  bool limitPTmaxIn) {
1649 
1650  // Initial values.
1651  int iRad = partonSystemsPtr->getOut(iSys, i);
1652  int iRec = 0;
1653  int idRad = event[iRad].id();
1654  int sizeOut = partonSystemsPtr->sizeOut(iSys);
1655 
1656  // Hidden Valley colour positive for positive id, and vice versa.
1657  // Find opposte HV colour in final state of same system.
1658  for (int j = 0; j < sizeOut; ++j) if (j != i) {
1659  int iRecNow = partonSystemsPtr->getOut(iSys, j);
1660  int idRec = event[iRecNow].id();
1661  if ( (abs(idRec) > 4900000 && abs(idRec) < 4900017)
1662  && idRad * idRec < 0) {
1663  iRec = iRecNow;
1664  break;
1665  }
1666  }
1667 
1668  // Else find heaviest other final-state in same system.
1669  // (Intended for decays; should mainly be two-body so unique.)
1670  double mMax = -sqrt(LARGEM2);
1671  if (iRec == 0)
1672  for (int j = 0; j < sizeOut; ++j) if (j != i) {
1673  int iRecNow = partonSystemsPtr->getOut(iSys, j);
1674  if (event[iRecNow].m() > mMax) {
1675  iRec = iRecNow;
1676  mMax = event[iRecNow].m();
1677  }
1678  }
1679 
1680  // Set up dipole end, or report failure.
1681  if (iRec > 0) {
1682  // Max scale either by parton scale or by half dipole mass.
1683  double pTmax = event[iRad].scale();
1684  if (limitPTmaxIn) {
1685  if (iSys == 0 || (iSys == 1 && doSecondHard)) pTmax *= pTmaxFudge;
1686  } else pTmax = 0.5 * m( event[iRad], event[iRec]);
1687  int colvType = (event[iRad].id() > 0) ? 1 : -1;
1688  dipEnd.push_back( TimeDipoleEnd( iRad, iRec, pTmax, 0, 0, 0, 0, 0,
1689  iSys, -1, -1, 0, false, true, colvType) );
1690  } else infoPtr->errorMsg("Error in TimeShower::setupHVdip: "
1691  "failed to locate any recoiling partner");
1692 
1693 }
1694 
1695 //--------------------------------------------------------------------------
1696 
1697 // Select next pT in downwards evolution of the existing dipoles.
1698 
1699 double TimeShower::pTnext( Event& event, double pTbegAll, double pTendAll,
1700  bool isFirstTrial) {
1701 
1702  // Begin loop over all possible radiating dipole ends.
1703  dipSel = 0;
1704  iDipSel = -1;
1705  double pT2sel = pTendAll * pTendAll;
1706 
1707  for (int iDip = 0; iDip < int(dipEnd.size()); ++iDip) {
1708  TimeDipoleEnd& dip = dipEnd[iDip];
1709 
1710  // Check if global recoil should be used.
1711  useLocalRecoilNow = !(globalRecoil && dip.system == 0
1712  && partonSystemsPtr->sizeOut(0) <= nMaxGlobalRecoil);
1713 
1714  // Do not use global recoil if the radiator line has already branched.
1715  if (globalRecoilMode == 1) {
1716  if (globalRecoil) useLocalRecoilNow = true;
1717  for (int iHard = 0; iHard < int(hardPartons.size()); ++iHard)
1718  if ( event[dip.iRadiator].isAncestor(hardPartons[iHard]) )
1719  useLocalRecoilNow = false;
1720  // Check if global recoil should be used.
1721  if ( !globalRecoil || nGlobal >= nMaxGlobalBranch )
1722  useLocalRecoilNow = true;
1723 
1724  // Switch off global recoil after first trial emission.
1725  } else if (globalRecoilMode == 2) {
1726  useLocalRecoilNow = !(globalRecoil && dip.system == 0
1727  && nGlobal <= nMaxGlobalBranch);
1728  int nFinal = 0;
1729  for (int k = 0; k < int(event.size()); ++k)
1730  if ( event[k].isFinal() && event[k].colType() != 0) nFinal++;
1731  bool isFirst = (nHard == nFinal);
1732  // Switch off global recoil after first emission
1733  if ( globalRecoil && doInterleave && !isFirst )
1734  useLocalRecoilNow = true;
1735  if ( globalRecoil && nProposed > 0 )
1736  useLocalRecoilNow = true;
1737  // No global recoil for H-events.
1738  if ( nFinalBorn > 0 && nHard > nFinalBorn )
1739  useLocalRecoilNow = true;
1740  }
1741 
1742  // Dipole properties; normal local recoil.
1743  dip.mRad = event[dip.iRadiator].m();
1744  if (useLocalRecoilNow) {
1745  dip.mRec = event[dip.iRecoiler].m();
1746  dip.mDip = m( event[dip.iRadiator], event[dip.iRecoiler] );
1747 
1748  // Dipole properties, alternative global recoil. Squares.
1749  } else {
1750  Vec4 pSumGlobal;
1751  for (int i = 0; i < partonSystemsPtr->sizeOut( dip.system); ++i) {
1752  int ii = partonSystemsPtr->getOut( dip.system, i);
1753  if (ii != dip.iRadiator) pSumGlobal += event[ii].p();
1754  }
1755  dip.mRec = pSumGlobal.mCalc();
1756  dip.mDip = m( event[dip.iRadiator].p(), pSumGlobal);
1757  }
1758  dip.m2Rad = pow2(dip.mRad);
1759  dip.m2Rec = pow2(dip.mRec);
1760  dip.m2Dip = pow2(dip.mDip);
1761 
1762  // Find maximum evolution scale for dipole.
1763  dip.m2DipCorr = pow2(dip.mDip - dip.mRec) - dip.m2Rad;
1764  double pTbegDip = min( pTbegAll, dip.pTmax );
1765  double pT2begDip = min( pow2(pTbegDip), 0.25 * dip.m2DipCorr);
1766 
1767  // For global recoil, always set the starting scale for first emission.
1768  bool isFirstWimpy = !useLocalRecoilNow && (pTmaxMatch == 1)
1769  && (nProposed == 0 || isFirstTrial);
1770  double muQ = (infoPtr->scalup() > 0.) ? infoPtr->scalup()
1771  : infoPtr->QFac();
1772  if (isFirstWimpy && !limitMUQ) pT2begDip = pow2(muQ);
1773  else if (isFirstWimpy && limitMUQ) {
1774  // Find mass of colour dipole.
1775  double mS = event[dip.iRecoiler].m();
1776  double mD = m( event[dip.iRadiator], event[dip.iRecoiler] );
1777  double m2DC = pow2(mD - mS) - pow2(dip.mRad);
1778  // Choose minimal scale.
1779  pT2begDip = min( pow2(muQ), min(pow2(pTbegDip), 0.25 * m2DC) );
1780  }
1781 
1782  // Do not try splitting if the corrected dipole mass is negative.
1783  dip.pT2 = 0.;
1784  if (dip.m2DipCorr < 0.) {
1785  infoPtr->errorMsg("Warning in TimeShower::pTnext: "
1786  "negative dipole mass.");
1787  continue;
1788  }
1789 
1790  // Do QCD, QED, weak or HV evolution if it makes sense.
1791  if (pT2begDip > pT2sel) {
1792  if (dip.colType != 0)
1793  pT2nextQCD(pT2begDip, pT2sel, dip, event);
1794  else if (dip.chgType != 0 || dip.gamType != 0)
1795  pT2nextQED(pT2begDip, pT2sel, dip, event);
1796  else if (dip.weakType != 0)
1797  pT2nextWeak(pT2begDip, pT2sel, dip, event);
1798  else if (dip.colvType != 0)
1799  pT2nextHV(pT2begDip, pT2sel, dip, event);
1800 
1801  // Update if found larger pT than current maximum.
1802  if (dip.pT2 > pT2sel) {
1803  pT2sel = dip.pT2;
1804  dipSel = &dip;
1805  iDipSel = iDip;
1806  }
1807  }
1808  }
1809 
1810  // Update the number of proposed timelike emissions.
1811  if (dipSel != 0) ++nProposed;
1812 
1813  // Return nonvanishing value if found pT bigger than already found.
1814  return (dipSel == 0) ? 0. : sqrt(pT2sel);
1815 
1816 }
1817 
1818 //--------------------------------------------------------------------------
1819 
1820 // Evolve a QCD dipole end.
1821 
1822 void TimeShower::pT2nextQCD(double pT2begDip, double pT2sel,
1823  TimeDipoleEnd& dip, Event& event) {
1824 
1825  // Lower cut for evolution. Return if no evolution range.
1826  double pT2endDip = max( pT2sel, pT2colCut );
1827  if (pT2begDip < pT2endDip) return;
1828 
1829  // Upper estimate for matrix element weighting and colour factor.
1830  // Special cases for triplet recoiling against gluino and octet onia.
1831  // Note that g -> g g and g -> q qbar are split on two sides.
1832  int colTypeAbs = abs(dip.colType);
1833  double wtPSglue = 2.;
1834  double colFac = (colTypeAbs == 1) ? 4./3. : 3./2.;
1835  if (dip.MEgluinoRec) colFac = 3.;
1836  if (dip.isOctetOnium) colFac *= 0.5 * octetOniumColFac;
1837  // PS dec 2010. Include possibility for flexible normalization,
1838  // e.g., for dipoles stretched to junctions or to switch off radiation.
1839  if (dip.isFlexible) colFac *= dip.flexFactor;
1840  double wtPSqqbar = (colTypeAbs == 2)
1841  ? 0.25 * nGluonToQuark * extraGluonToQuark : 0.;
1842 
1843  // Variables used inside evolution loop. (Mainly dummy start values.)
1844  dip.pT2 = pT2begDip;
1845  int nFlavour = 3;
1846  double zMinAbs = 0.5;
1847  double pT2min = pT2endDip;
1848  double b0 = 4.5;
1849  double Lambda2 = Lambda3flav2;
1850  double emitCoefGlue = 0.;
1851  double emitCoefQqbar = 0.;
1852  double emitCoefTot = 0.;
1853  double wt = 0.;
1854  bool mustFindRange = true;
1855 
1856  // Begin evolution loop towards smaller pT values.
1857  do {
1858 
1859  // Initialize evolution coefficients at the beginning and
1860  // reinitialize when crossing c and b flavour thresholds.
1861  if (mustFindRange) {
1862 
1863  // Determine overestimated z range; switch at c and b masses.
1864  if (dip.pT2 > m2b) {
1865  nFlavour = 5;
1866  pT2min = max( m2b, pT2endDip);
1867  b0 = 23./6.;
1868  Lambda2 = Lambda5flav2;
1869  } else if (dip.pT2 > m2c) {
1870  nFlavour = 4;
1871  pT2min = max( m2c, pT2endDip);
1872  b0 = 25./6.;
1873  Lambda2 = Lambda4flav2;
1874  } else {
1875  nFlavour = 3;
1876  pT2min = pT2endDip;
1877  b0 = 27./6.;
1878  Lambda2 = Lambda3flav2;
1879  }
1880  // A change of renormalization scale expressed by a change of Lambda.
1881  Lambda2 /= renormMultFac;
1882 
1883  // Calculate allowed z range; fail if it is too tiny.
1884  zMinAbs = 0.5 - sqrtpos( 0.25 - pT2min / dip.m2DipCorr );
1885  if (zMinAbs < SIMPLIFYROOT) zMinAbs = pT2min / dip.m2DipCorr;
1886  if (zMinAbs > 0.499) { dip.pT2 = 0.; return; }
1887 
1888  // Find emission coefficients for X -> X g and g -> q qbar.
1889  emitCoefGlue = wtPSglue * colFac * log(1. / zMinAbs - 1.);
1890  emitCoefTot = emitCoefGlue;
1891  if (colTypeAbs == 2 && event[dip.iRadiator].id() == 21) {
1892  emitCoefQqbar = wtPSqqbar * (1. - 2. * zMinAbs);
1893  emitCoefTot += emitCoefQqbar;
1894  }
1895 
1896  // Initialization done for current range.
1897  mustFindRange = false;
1898  }
1899 
1900  // Pick pT2 (in overestimated z range) for fixed alpha_strong.
1901  if (alphaSorder == 0) {
1902  dip.pT2 = dip.pT2 * pow( rndmPtr->flat(),
1903  1. / (alphaS2pi * emitCoefTot) );
1904 
1905  // Ditto for first-order alpha_strong.
1906  } else if (alphaSorder == 1) {
1907  dip.pT2 = Lambda2 * pow( dip.pT2 / Lambda2,
1908  pow( rndmPtr->flat(), b0 / emitCoefTot) );
1909 
1910  // For second order reject by second term in alpha_strong expression.
1911  } else {
1912  do dip.pT2 = Lambda2 * pow( dip.pT2 / Lambda2,
1913  pow( rndmPtr->flat(), b0 / emitCoefTot) );
1914  while (alphaS.alphaS2OrdCorr(renormMultFac * dip.pT2) < rndmPtr->flat()
1915  && dip.pT2 > pT2min);
1916  }
1917  wt = 0.;
1918 
1919  // If crossed c or b thresholds: continue evolution from threshold.
1920  if (nFlavour == 5 && dip.pT2 < m2b) {
1921  mustFindRange = true;
1922  dip.pT2 = m2b;
1923  } else if ( nFlavour == 4 && dip.pT2 < m2c) {
1924  mustFindRange = true;
1925  dip.pT2 = m2c;
1926 
1927  // Abort evolution if below cutoff scale, or below another branching.
1928  } else {
1929  if ( dip.pT2 < pT2endDip) { dip.pT2 = 0.; return; }
1930 
1931  // Pick kind of branching: X -> X g or g -> q qbar.
1932  dip.flavour = 21;
1933  dip.mFlavour = 0.;
1934  if (colTypeAbs == 2 && emitCoefQqbar > rndmPtr->flat()
1935  * emitCoefTot) dip.flavour = 0;
1936 
1937  // Pick z: either dz/(1-z) or flat dz.
1938  if (dip.flavour == 21) {
1939  dip.z = 1. - zMinAbs * pow( 1. / zMinAbs - 1., rndmPtr->flat() );
1940  } else {
1941  dip.z = zMinAbs + (1. - 2. * zMinAbs) * rndmPtr->flat();
1942  }
1943 
1944  // Do not accept branching if outside allowed z range.
1945  double zMin = 0.5 - sqrtpos( 0.25 - dip.pT2 / dip.m2DipCorr );
1946  if (zMin < SIMPLIFYROOT) zMin = dip.pT2 / dip.m2DipCorr;
1947  dip.m2 = dip.m2Rad + dip.pT2 / (dip.z * (1. - dip.z));
1948  if (dip.z > zMin && dip.z < 1. - zMin
1949  && dip.m2 * dip.m2Dip < dip.z * (1. - dip.z)
1950  * pow2(dip.m2Dip + dip.m2 - dip.m2Rec) ) {
1951 
1952  // Flavour choice for g -> q qbar.
1953  if (dip.flavour == 0) {
1954  dip.flavour = min(5, 1 + int(nGluonToQuark * rndmPtr->flat()));
1955  dip.mFlavour = particleDataPtr->m0(dip.flavour);
1956  }
1957 
1958  // No z weight, except threshold, if to do ME corrections later on.
1959  if (dip.MEtype > 0) {
1960  wt = 1.;
1961  if (dip.flavour < 10 && dip.m2 < THRESHM2 * pow2(dip.mFlavour))
1962  wt = 0.;
1963 
1964  // z weight for X -> X g.
1965  } else if (dip.flavour == 21
1966  && (colTypeAbs == 1 || colTypeAbs == 3) ) {
1967  wt = (1. + pow2(dip.z)) / wtPSglue;
1968  } else if (dip.flavour == 21) {
1969  wt = (1. + pow3(dip.z)) / wtPSglue;
1970 
1971  // z weight for g -> q qbar: different options.
1972  } else {
1973  double ratioQ = pow2(dip.mFlavour) / dip.m2;
1974  double betaQ = sqrtpos( 1. - 4. * ratioQ );
1975  if (weightGluonToQuark%4 == 1) {
1976  wt = betaQ * ( pow2(dip.z) + pow2(1. - dip.z) );
1977  } else if (weightGluonToQuark%4 == 2) {
1978  wt = betaQ * ( pow2(dip.z) + pow2(1. - dip.z)
1979  + 8. * ratioQ * dip.z * (1. - dip.z) );
1980  } else {
1981  double m2Rat = dip.m2 / dip.m2DipCorr;
1982  double zCosThe = ((1. + m2Rat) * dip.z - m2Rat) / (1. - m2Rat);
1983  wt = betaQ * ( pow2(zCosThe) + pow2(1. - zCosThe)
1984  + 8. * ratioQ * zCosThe * (1. - zCosThe) )
1985  * (1. + m2Rat) / ((1. - m2Rat) * extraGluonToQuark) ;
1986  if (weightGluonToQuark%4 == 0) wt *= pow3(1. - m2Rat);
1987  }
1988  if (weightGluonToQuark > 4 && alphaSorder > 0)
1989  wt *= log(dip.pT2 / Lambda2)
1990  / log(scaleGluonToQuark * dip.m2 / Lambda2);
1991  }
1992 
1993  // Suppression factors for dipole to beam remnant.
1994  if (dip.isrType != 0 && useLocalRecoilNow) {
1995  BeamParticle& beam = (dip.isrType == 1) ? *beamAPtr : *beamBPtr;
1996  int iSysRec = dip.systemRec;
1997  double xOld = beam[iSysRec].x();
1998  double xNew = xOld * (1. + (dip.m2 - dip.m2Rad) /
1999  (dip.m2Dip - dip.m2Rad));
2000  double xMaxAbs = beam.xMax(iSysRec);
2001  if (xMaxAbs < 0.) {
2002  infoPtr->errorMsg("Warning in TimeShower::pT2nextQCD: "
2003  "xMaxAbs negative");
2004  return;
2005  }
2006 
2007  // Firstly reduce by PDF ratio.
2008  if (xNew > xMaxAbs) wt = 0.;
2009  else {
2010  int idRec = event[dip.iRecoiler].id();
2011  pdfScale2 = (useFixedFacScale) ? fixedFacScale2
2012  : factorMultFac * dip.pT2;
2013  double pdfOld = max ( TINYPDF,
2014  beam.xfISR( iSysRec, idRec, xOld, pdfScale2) );
2015  double pdfNew =
2016  beam.xfISR( iSysRec, idRec, xNew, pdfScale2);
2017  wt *= min( 1., pdfNew / pdfOld);
2018  }
2019 
2020  // Secondly optionally reduce by 4 pT2_hard / (4 pT2_hard + m2).
2021  if (dampenBeamRecoil) {
2022  double pTpT = sqrt(event[dip.iRadiator].pT2() * dip.pT2);
2023  wt *= pTpT / (pTpT + dip.m2);
2024  }
2025  }
2026 
2027  // Optional dampening of large pT values in hard system.
2028  if (dopTdamp && dip.system == 0 && dip.MEtype == 0)
2029  wt *= pT2damp / (dip.pT2 + pT2damp);
2030  }
2031  }
2032 
2033  // Iterate until acceptable pT (or have fallen below pTmin).
2034  } while (wt < rndmPtr->flat());
2035 
2036 }
2037 
2038 //--------------------------------------------------------------------------
2039 
2040 // Evolve a QED dipole end, either charged or photon.
2041 
2042 void TimeShower::pT2nextQED(double pT2begDip, double pT2sel,
2043  TimeDipoleEnd& dip, Event& event) {
2044 
2045  // Lower cut for evolution. Return if no evolution range.
2046  double pT2chgCut = (dip.chgType != 0 && abs(dip.chgType) != 3)
2047  ? pT2chgQCut : pT2chgLCut;
2048  double pT2endDip = max( pT2sel, pT2chgCut );
2049  if (pT2begDip < pT2endDip) return;
2050 
2051  // Emission of photon or photon branching.
2052  bool hasCharge = (dip.chgType != 0);
2053 
2054  // Default values.
2055  double wtPSgam = 0.;
2056  double chg2Sum = 0.;
2057  double chg2SumL = 0.;
2058  double chg2SumQ = 0.;
2059  double zMinAbs = 0.;
2060  double emitCoefTot = 0.;
2061 
2062  // alpha_em at maximum scale provides upper estimate.
2063  double alphaEMmax = alphaEM.alphaEM(renormMultFac * dip.m2DipCorr);
2064  double alphaEM2pi = alphaEMmax / (2. * M_PI);
2065 
2066  // Emission: upper estimate for matrix element weighting; charge factor.
2067  if (hasCharge) {
2068  wtPSgam = 2.;
2069  double chg2 = pow2(dip.chgType / 3.);
2070 
2071  // Determine overestimated z range. Find evolution coefficient.
2072  zMinAbs = 0.5 - sqrtpos( 0.25 - pT2endDip / dip.m2DipCorr );
2073  if (zMinAbs < SIMPLIFYROOT) zMinAbs = pT2endDip / dip.m2DipCorr;
2074  emitCoefTot = alphaEM2pi * chg2 * wtPSgam * log(1. / zMinAbs - 1.);
2075 
2076  // Branching: sum of squared charge factors for lepton and quark daughters.
2077  } else {
2078  chg2SumL = max(0, min(3, nGammaToLepton));
2079  if (nGammaToQuark > 4) chg2SumQ = 11. / 9.;
2080  else if (nGammaToQuark > 3) chg2SumQ = 10. / 9.;
2081  else if (nGammaToQuark > 2) chg2SumQ = 6. / 9.;
2082  else if (nGammaToQuark > 1) chg2SumQ = 5. / 9.;
2083  else if (nGammaToQuark > 0) chg2SumQ = 1. / 9.;
2084 
2085  // Total sum of squared charge factors. Find evolution coefficient.
2086  chg2Sum = chg2SumL + 3. * chg2SumQ;
2087  emitCoefTot = alphaEM2pi * chg2Sum * extraGluonToQuark;
2088  }
2089 
2090  // Variables used inside evolution loop.
2091  dip.pT2 = pT2begDip;
2092  double wt;
2093 
2094  // Begin evolution loop towards smaller pT values.
2095  do {
2096 
2097  // Pick pT2 (in overestimated z range).
2098  dip.pT2 = dip.pT2 * pow(rndmPtr->flat(), 1. / emitCoefTot);
2099  wt = 0.;
2100 
2101  // Abort evolution if below cutoff scale, or below another branching.
2102  if ( dip.pT2 < pT2endDip) { dip.pT2 = 0.; return; }
2103 
2104  // Pick z according to dz/(1-z) or flat.
2105  if (hasCharge) dip.z = 1. - zMinAbs
2106  * pow( 1. / zMinAbs - 1., rndmPtr->flat() );
2107  else dip.z = rndmPtr->flat();
2108 
2109  // Do not accept branching if outside allowed z range.
2110  double zMin = 0.5 - sqrtpos( 0.25 - dip.pT2 / dip.m2DipCorr );
2111  if (zMin < SIMPLIFYROOT) zMin = dip.pT2 / dip.m2DipCorr;
2112  if (dip.z <= zMin || dip.z >= 1. - zMin) continue;
2113  dip.m2 = dip.m2Rad + dip.pT2 / (dip.z * (1. - dip.z));
2114  if (dip.m2 * dip.m2Dip < dip.z * (1. - dip.z)
2115  * pow2(dip.m2Dip + dip.m2 - dip.m2Rec)
2116  // For gamma -> f fbar also impose maximum mass.
2117  && (hasCharge || dip.m2 < m2MaxGamma) ) {
2118 
2119  // Photon emission: unique flavour choice.
2120  if (hasCharge) {
2121  dip.flavour = 22;
2122  dip.mFlavour = 0.;
2123 
2124  // Photon branching: either lepton or quark flavour choice.
2125  } else {
2126  if (rndmPtr->flat() * chg2Sum < chg2SumL)
2127  dip.flavour = 9 + 2 * min(3, 1 + int(chg2SumL * rndmPtr->flat()));
2128  else {
2129  double rndmQ = 9. * chg2SumQ * rndmPtr->flat();
2130  if (rndmQ < 1.) dip.flavour = 1;
2131  else if (rndmQ < 5.) dip.flavour = 2;
2132  else if (rndmQ < 6.) dip.flavour = 3;
2133  else if (rndmQ < 10.) dip.flavour = 4;
2134  else dip.flavour = 5;
2135  }
2136  dip.mFlavour = particleDataPtr->m0(dip.flavour);
2137  }
2138 
2139  // No z weight, except threshold, if to do ME corrections later on.
2140  if (dip.MEtype > 0) {
2141  wt = 1.;
2142  if (dip.flavour < 20 && dip.m2 < THRESHM2 * pow2(dip.mFlavour))
2143  wt = 0.;
2144 
2145  // z weight for X -> X gamma.
2146  } else if (hasCharge) {
2147  wt = (1. + pow2(dip.z)) / wtPSgam;
2148 
2149  // z weight for gamma -> f fbar; different options.
2150  } else {
2151  double ratioF = pow2(dip.mFlavour) / dip.m2;
2152  double betaF = sqrtpos( 1. - 4. * ratioF );
2153  if (weightGluonToQuark%4 == 1) {
2154  wt = betaF * ( pow2(dip.z) + pow2(1. - dip.z) );
2155  } else if (weightGluonToQuark%4 == 2) {
2156  wt = betaF * ( pow2(dip.z) + pow2(1. - dip.z)
2157  + 8. * ratioF * dip.z * (1. - dip.z) );
2158  } else {
2159  double m2Rat = dip.m2 / dip.m2DipCorr;
2160  double zCosThe = ((1. + m2Rat) * dip.z - m2Rat) / (1. - m2Rat);
2161  wt = betaF * ( pow2(zCosThe) + pow2(1. - zCosThe)
2162  + 8. * ratioF * zCosThe * (1. - zCosThe) )
2163  * (1. + m2Rat) / ((1. - m2Rat) * extraGluonToQuark) ;
2164  if (weightGluonToQuark%4 == 0) wt *= pow3(1. - m2Rat);
2165  }
2166  }
2167 
2168  // Correct to current value of alpha_EM.
2169  double aEMscale = dip.pT2;
2170  if (dip.flavour < 20 && weightGluonToQuark > 4)
2171  aEMscale = scaleGluonToQuark * dip.m2;
2172  double alphaEMnow = alphaEM.alphaEM(renormMultFac * aEMscale);
2173  wt *= (alphaEMnow / alphaEMmax);
2174 
2175  // Suppression factors for dipole to beam remnant.
2176  if (dip.isrType != 0 && useLocalRecoilNow) {
2177  BeamParticle& beam = (dip.isrType == 1) ? *beamAPtr : *beamBPtr;
2178  int iSys = dip.system;
2179  double xOld = beam[iSys].x();
2180  double xNew = xOld * (1. + (dip.m2 - dip.m2Rad) /
2181  (dip.m2Dip - dip.m2Rad));
2182  double xMaxAbs = beam.xMax(iSys);
2183  if (xMaxAbs < 0.) {
2184  infoPtr->errorMsg("Warning in TimeShower::pT2nextQED: "
2185  "xMaxAbs negative");
2186  return;
2187  }
2188 
2189  // Firstly reduce by PDF ratio.
2190  if (xNew > xMaxAbs) wt = 0.;
2191  else {
2192  int idRec = event[dip.iRecoiler].id();
2193  pdfScale2 = (useFixedFacScale) ? fixedFacScale2
2194  : factorMultFac * dip.pT2;
2195  double pdfOld = max ( TINYPDF,
2196  beam.xfISR( iSys, idRec, xOld, pdfScale2) );
2197  double pdfNew =
2198  beam.xfISR( iSys, idRec, xNew, pdfScale2);
2199  wt *= min( 1., pdfNew / pdfOld);
2200  }
2201 
2202  // Secondly optionally reduce by 4 pT2_hard / (4 pT2_hard + m2).
2203  if (dampenBeamRecoil) {
2204  double pT24 = 4. * event[dip.iRadiator].pT2();
2205  wt *= pT24 / (pT24 + dip.m2);
2206  }
2207  }
2208 
2209  // Optional dampening of large pT values in hard system.
2210  if (dopTdamp && dip.system == 0 && dip.MEtype == 0)
2211  wt *= pT2damp / (dip.pT2 + pT2damp);
2212  }
2213 
2214  // Iterate until acceptable pT (or have fallen below pTmin).
2215  } while (wt < rndmPtr->flat());
2216 
2217 }
2218 
2219 //--------------------------------------------------------------------------
2220 
2221 // Evolve a weak-emission dipole end.
2222 
2223 void TimeShower::pT2nextWeak(double pT2begDip, double pT2sel,
2224  TimeDipoleEnd& dip, Event& event) {
2225 
2226  // Lower cut for evolution. Return if no evolution range.
2227  double pT2endDip = max( pT2sel, pT2weakCut );
2228  if (pT2begDip < pT2endDip) return;
2229 
2230  // Default values.
2231  double wtPSgam = 0.;
2232  double zMinAbs = 0.;
2233  double emitCoefTot = 0.;
2234 
2235  // alpha_em at maximum scale provides upper estimate.
2236  double alphaEMmax = alphaEM.alphaEM(renormMultFac * pT2begDip);
2237  double alphaEM2pi = alphaEMmax / (2. * M_PI);
2238 
2239  // Emission: upper estimate for matrix element weighting; charge factor.
2240  wtPSgam = 8.;
2241 
2242  // Determine overestimated z range. Find evolution coefficient.
2243  zMinAbs = 0.5 - sqrtpos( 0.25 - pT2endDip / dip.m2DipCorr );
2244  if (zMinAbs < SIMPLIFYROOT) zMinAbs = pT2endDip / dip.m2DipCorr;
2245 
2246  // Determine weak coupling.
2247  double weakCoupling = 0.;
2248  // W-radiation, with additional factor of two, from only having
2249  // left-handed fermions.
2250  if (dip.weakType == 1)
2251  weakCoupling = 2. * alphaEM2pi / (4. * coupSMPtr->sin2thetaW());
2252  // Z-radiation, split between left and right fermions.
2253  else if (dip.weakType == 2 && dip.weakPol == -1)
2254  weakCoupling = alphaEM2pi * thetaWRat
2255  * pow2(2. * coupSMPtr->lf( event[dip.iRadiator].idAbs() ));
2256  else
2257  weakCoupling = alphaEM2pi * thetaWRat
2258  * pow2(2. * coupSMPtr->rf( event[dip.iRadiator].idAbs() ));
2259 
2260  // Variables used inside evolution loop.
2261  emitCoefTot = weakEnhancement * weakCoupling
2262  * wtPSgam * log(1. / zMinAbs - 1.);
2263  // Fudge factor to correct for weak PS not being an overestimate of ME.
2264  if ( dip.MEtype == 201 || dip.MEtype == 202 || dip.MEtype == 203
2265  || dip.MEtype == 206 || dip.MEtype == 207 || dip.MEtype == 208 )
2266  emitCoefTot *= WEAKPSWEIGHT;
2267  dip.pT2 = pT2begDip;
2268  double wt;
2269 
2270  // Begin evolution loop towards smaller pT values.
2271  do {
2272  // Pick pT2 (in overestimated z range).
2273  dip.pT2 = dip.pT2 * pow(rndmPtr->flat(), 1. / emitCoefTot);
2274  wt = 0.;
2275 
2276  // Abort evolution if below cutoff scale, or below another branching.
2277  if ( dip.pT2 < pT2endDip) {dip.pT2 = 0.; return; }
2278 
2279  // Pick z according to dz/(1-z) or flat.
2280  dip.z = 1. - zMinAbs * pow( 1. / zMinAbs - 1., rndmPtr->flat() );
2281 
2282  // Do not accept branching if outside allowed z range.
2283  double zMin = 0.5 - sqrtpos( 0.25 - dip.pT2 / dip.m2DipCorr );
2284  if (zMin < SIMPLIFYROOT) zMin = dip.pT2 / dip.m2DipCorr;
2285  dip.m2 = dip.m2Rad + dip.pT2 / (dip.z * (1. - dip.z));
2286  if (dip.z > zMin && dip.z < 1. - zMin
2287  && dip.m2 * dip.m2Dip < dip.z * (1. - dip.z)
2288  * pow2(dip.m2Dip + dip.m2 - dip.m2Rec) ) {
2289 
2290  // Check whether emission of W+ or W-, or else Z0.
2291  if (dip.weakType == 1) {
2292  dip.flavour = (event[dip.iRadiator].id() > 0) ? 24 : -24;
2293  if (event[dip.iRadiator].idAbs() % 2 == 1) dip.flavour = -dip.flavour;
2294  } else if (dip.weakType == 2) dip.flavour = 23;
2295 
2296  // Set mass of emitted particle, with Breit-Wigner distribution.
2297  dip.mFlavour = particleDataPtr->mSel( dip.flavour);
2298 
2299  // No z weight, except threshold, if to do ME corrections later on.
2300  // Here no pure shower mode exists, always needs ME corrections.
2301  if (dip.MEtype > 0) wt = 1.;
2302 
2303  // Correct to current value of alpha_EM.
2304  double alphaEMnow = alphaEM.alphaEM(renormMultFac * dip.pT2);
2305  wt *= (alphaEMnow / alphaEMmax);
2306 
2307  // Suppression factors for dipole to beam remnant.
2308  if (dip.isrType != 0 && useLocalRecoilNow) {
2309  BeamParticle& beam = (dip.isrType == 1) ? *beamAPtr : *beamBPtr;
2310  int iSys = dip.system;
2311  double xOld = beam[iSys].x();
2312  double xNew = xOld * (1. + (dip.m2 - dip.m2Rad) /
2313  (dip.m2Dip - dip.m2Rad));
2314  double xMaxAbs = beam.xMax(iSys);
2315  if (xMaxAbs < 0.) {
2316  infoPtr->errorMsg("Warning in TimeShower::pT2nextWeak: "
2317  "xMaxAbs negative");
2318  return;
2319  }
2320 
2321  // Firstly reduce by PDF ratio.
2322  if (xNew > xMaxAbs) wt = 0.;
2323  else {
2324  int idRec = event[dip.iRecoiler].id();
2325  pdfScale2 = (useFixedFacScale) ? fixedFacScale2
2326  : factorMultFac * dip.pT2;
2327  double pdfOld = max ( TINYPDF,
2328  beam.xfISR( iSys, idRec, xOld, pdfScale2) );
2329  double pdfNew =
2330  beam.xfISR( iSys, idRec, xNew, pdfScale2);
2331  wt *= min( 1., pdfNew / pdfOld);
2332  }
2333  // Secondly optionally reduce by 4 pT2_hard / (4 pT2_hard + m2).
2334  if (dampenBeamRecoil) {
2335  double pT24 = 4. * event[dip.iRadiator].pT2();
2336  wt *= pT24 / (pT24 + dip.m2);
2337  }
2338  }
2339  }
2340 
2341  // Optional dampening of large pT values in hard system.
2342  if (dopTdamp && dip.system == 0) wt *= pT2damp / (dip.pT2 + pT2damp);
2343 
2344  // Iterate until acceptable pT (or have fallen below pTmin).
2345  } while (wt < rndmPtr->flat());
2346 
2347 }
2348 
2349 //--------------------------------------------------------------------------
2350 
2351 // Evolve a Hidden Valley dipole end.
2352 
2353 void TimeShower::pT2nextHV(double pT2begDip, double pT2sel,
2354  TimeDipoleEnd& dip, Event& ) {
2355 
2356  // Lower cut for evolution. Return if no evolution range.
2357  double pT2endDip = max( pT2sel, pT2hvCut );
2358  if (pT2begDip < pT2endDip) return;
2359 
2360  // C_F * alpha_HV/2 pi.
2361  int colvTypeAbs = abs(dip.colvType);
2362  double colvFac = (colvTypeAbs == 1) ? CFHV : 0.5 * nCHV;
2363  double alphaHV2pi = colvFac * (alphaHVfix / (2. * M_PI));
2364 
2365  // Determine overestimated z range. Find evolution coefficient.
2366  double zMinAbs = 0.5 - sqrtpos( 0.25 - pT2endDip / dip.m2DipCorr );
2367  if (zMinAbs < SIMPLIFYROOT) zMinAbs = pT2endDip / dip.m2DipCorr;
2368  double emitCoefTot = alphaHV2pi * 2. * log(1. / zMinAbs - 1.);
2369 
2370  // Variables used inside evolution loop.
2371  dip.pT2 = pT2begDip;
2372  double wt;
2373 
2374  // Begin evolution loop towards smaller pT values.
2375  do {
2376 
2377  // Pick pT2 (in overestimated z range).
2378  dip.pT2 = dip.pT2 * pow(rndmPtr->flat(), 1. / emitCoefTot);
2379  wt = 0.;
2380 
2381  // Abort evolution if below cutoff scale, or below another branching.
2382  if ( dip.pT2 < pT2endDip) { dip.pT2 = 0.; return; }
2383 
2384  // Pick z according to dz/(1-z).
2385  dip.z = 1. - zMinAbs * pow( 1. / zMinAbs - 1., rndmPtr->flat() );
2386 
2387  // Do not accept branching if outside allowed z range.
2388  double zMin = 0.5 - sqrtpos( 0.25 - dip.pT2 / dip.m2DipCorr );
2389  if (zMin < SIMPLIFYROOT) zMin = dip.pT2 / dip.m2DipCorr;
2390  dip.m2 = dip.m2Rad + dip.pT2 / (dip.z * (1. - dip.z));
2391  if (dip.z > zMin && dip.z < 1. - zMin
2392  && dip.m2 * dip.m2Dip < dip.z * (1. - dip.z)
2393  * pow2(dip.m2Dip + dip.m2 - dip.m2Rec) ) {
2394 
2395  // HV gamma or gluon emission: unique flavour choice.
2396  dip.flavour = idHV;
2397  dip.mFlavour = mHV;
2398 
2399  // No z weight, except threshold, if to do ME corrections later on.
2400  if (dip.MEtype > 0) wt = 1.;
2401 
2402  // z weight for X -> X g_HV.
2403  else if (colvTypeAbs == 1) wt = (1. + pow2(dip.z)) / 2.;
2404  else wt = (1. + pow3(dip.z)) / 2.;
2405  }
2406 
2407  // Optional dampening of large pT values in hard system.
2408  if (dopTdamp && dip.system == 0 && dip.MEtype == 0)
2409  wt *= pT2damp / (dip.pT2 + pT2damp);
2410 
2411  // Iterate until acceptable pT (or have fallen below pTmin).
2412  } while (wt < rndmPtr->flat());
2413 
2414 }
2415 
2416 //--------------------------------------------------------------------------
2417 
2418 // ME corrections and kinematics that may give failure.
2419 // Notation: radBef, recBef = radiator, recoiler before emission,
2420 // rad, rec, emt = radiator, recoiler, emitted efter emission.
2421 // (rad, emt distinguished by colour flow for g -> q qbar.)
2422 
2423 bool TimeShower::branch( Event& event, bool isInterleaved) {
2424 
2425  // Check if global recoil should be used.
2426  useLocalRecoilNow = !(globalRecoil && dipSel->system == 0
2427  && partonSystemsPtr->sizeOut(0) <= nMaxGlobalRecoil);
2428 
2429  // Do not use global recoil if the radiator line has already branched.
2430  if (globalRecoilMode == 1) {
2431  if ( globalRecoil ) useLocalRecoilNow = true;
2432  for (int iHard = 0; iHard < int(hardPartons.size()); ++iHard)
2433  if ( event[dipSel->iRadiator].isAncestor(hardPartons[iHard]) )
2434  useLocalRecoilNow = false;
2435  // Check if global recoil should be used.
2436  if ( !globalRecoil || nGlobal >= nMaxGlobalBranch )
2437  useLocalRecoilNow = true;
2438 
2439  // Switch off global recoil after first trial emission
2440  } else if (globalRecoilMode == 2) {
2441  useLocalRecoilNow = !(globalRecoil && dipSel->system == 0
2442  && nGlobal <= nMaxGlobalBranch);
2443  int nFinal = 0;
2444  for (int i = 0; i < int(event.size()); ++i)
2445  if ( event[i].isFinal() && event[i].colType() != 0) nFinal++;
2446  bool isFirst = (nHard == nFinal);
2447  if ( globalRecoil && doInterleave && !isFirst )
2448  useLocalRecoilNow = true;
2449  if ( globalRecoil && nProposed > 1 )
2450  useLocalRecoilNow = true;
2451  // No global recoil for H-events.
2452  if ( nFinalBorn > 0 && nHard > nFinalBorn )
2453  useLocalRecoilNow = true;
2454  }
2455 
2456  // Check if the first emission should be studied for removal.
2457  bool canMergeFirst = (mergingHooksPtr != 0)
2458  ? mergingHooksPtr->canVetoEmission() : false;
2459 
2460  // Find initial radiator and recoiler particles in dipole branching.
2461  int iRadBef = dipSel->iRadiator;
2462  int iRecBef = dipSel->iRecoiler;
2463  Particle& radBef = event[iRadBef];
2464  Particle& recBef = event[iRecBef];
2465 
2466  // Find their momenta, with special sum for global recoil.
2467  Vec4 pRadBef = event[iRadBef].p();
2468  Vec4 pRecBef;
2469  vector<int> iGRecBef, iGRec;
2470  if (useLocalRecoilNow) pRecBef = event[iRecBef].p();
2471  else {
2472  for (int i = 0; i < partonSystemsPtr->sizeOut( dipSel->system); ++i) {
2473  int iG = partonSystemsPtr->getOut( dipSel->system, i);
2474  if (iG != dipSel->iRadiator) {
2475  iGRecBef.push_back(iG);
2476  pRecBef += event[iG].p();
2477  }
2478  }
2479  }
2480 
2481  // Find old incoming momenta for weak shower t-channel ME correction.
2482  Vec4 p3weak = event[3].p();
2483  Vec4 p4weak = event[4].p();
2484  if ( dipSel->MEtype == 201 || dipSel->MEtype == 202
2485  || dipSel->MEtype == 203 || dipSel->MEtype == 206
2486  || dipSel->MEtype == 207 || dipSel->MEtype == 208) {
2487 
2488  // Trace back to original mother. MPI not allowed to radiate weakly.
2489  int i2to2Mother = iRadBef;
2490  while (i2to2Mother != 5 && i2to2Mother != 6 && i2to2Mother != 0)
2491  i2to2Mother = event[i2to2Mother].mother1();
2492  if (i2to2Mother == 0) return false;
2493 
2494  // u d -> u d && u g -> u g.
2495  if (event[3].id() != event[4].id()) {
2496  if (event[3].id() == event[i2to2Mother].id());
2497  else if (event[4].id() == event[i2to2Mother].id()) swap(p3weak, p4weak);
2498  // In case of no match, assign random combination.
2499  else if (rndmPtr->flat() < 0.5) swap(p3weak, p4weak);
2500  }
2501  // u u -> u u, assign random combination.
2502  else if (rndmPtr->flat() < 0.5) swap(p3weak, p4weak);
2503  }
2504 
2505  // Default flavours and colour tags for new particles in dipole branching.
2506  int idRad = radBef.id();
2507  int idEmt = dipSel->flavour;
2508  int colRad = radBef.col();
2509  int acolRad = radBef.acol();
2510  int colEmt = 0;
2511  int acolEmt = 0;
2512  iSysSel = dipSel->system;
2513  int iSysSelRec = dipSel->systemRec;
2514 
2515  // Default OK for photon, photon_HV or gluon_HV emission.
2516  if (dipSel->flavour == 22 || dipSel->flavour == idHV) {
2517  // New colour tag required for gluon emission.
2518  } else if (dipSel->flavour == 21 && dipSel->colType > 0) {
2519  colEmt = colRad;
2520  colRad = event.nextColTag();
2521  acolEmt = colRad;
2522  } else if (dipSel->flavour == 21) {
2523  acolEmt = acolRad;
2524  acolRad = event.nextColTag();
2525  colEmt = acolRad;
2526  // New flavours for g -> q qbar; split colours.
2527  } else if (dipSel->colType > 0) {
2528  idEmt = dipSel->flavour ;
2529  idRad = -idEmt;
2530  colEmt = colRad;
2531  colRad = 0;
2532  } else if (dipSel->colType < 0) {
2533  idEmt = -dipSel->flavour ;
2534  idRad = -idEmt;
2535  acolEmt = acolRad;
2536  acolRad = 0;
2537  // New flavours for gamma -> f fbar, and maybe also colours.
2538  } else if (dipSel->gamType == 1 && rndmPtr->flat() > 0.5) {
2539  idEmt = -dipSel->flavour ;
2540  idRad = -idEmt;
2541  if (idRad < 10) colRad = event.nextColTag();
2542  acolEmt = colRad;
2543  } else if (dipSel->gamType == 1) {
2544  idEmt = dipSel->flavour ;
2545  idRad = -idEmt;
2546  if (idEmt < 10) colEmt = event.nextColTag();
2547  acolRad = colEmt;
2548  }
2549 
2550  // Change fermion flavour by W emissions.
2551  int idRadSv = idRad;
2552  if (abs(idEmt) == 24) {
2553  if (rndmPtr->flat() > coupSMPtr->V2CKMsum(idRad)) return false;
2554  idRad = coupSMPtr->V2CKMpick(idRad);
2555  }
2556 
2557  // Construct kinematics in dipole rest frame:
2558  // begin simple (like g -> g g).
2559  double pTorig = sqrt( dipSel->pT2);
2560  double eRadPlusEmt = 0.5 * (dipSel->m2Dip + dipSel->m2 - dipSel->m2Rec)
2561  / dipSel->mDip;
2562  double e2RadPlusEmt = pow2(eRadPlusEmt);
2563  double pzRadPlusEmt = 0.5 * sqrtpos( pow2(dipSel->m2Dip - dipSel->m2
2564  - dipSel->m2Rec) - 4. * dipSel->m2 * dipSel->m2Rec ) / dipSel->mDip;
2565  double pT2corr = dipSel->m2 * (e2RadPlusEmt * dipSel->z * (1. - dipSel->z)
2566  - 0.25 * dipSel->m2) / pow2(pzRadPlusEmt);
2567  double pTcorr = sqrtpos( pT2corr );
2568  double pzRad = (e2RadPlusEmt * dipSel->z - 0.5 * dipSel->m2)
2569  / pzRadPlusEmt;
2570  double pzEmt = (e2RadPlusEmt * (1. - dipSel->z) - 0.5 * dipSel->m2)
2571  / pzRadPlusEmt;
2572  // Radiator flavour changed if W emission, so find new mass.
2573  double mRad = (idRad == idRadSv) ? dipSel->mRad
2574  : particleDataPtr->m0(idRad);
2575  double m2Rad = pow2(mRad);
2576  double mEmt = 0.;
2577 
2578  // Kinematics reduction for f -> f W/Z when m_f > 0 (and m_W/Z > 0)
2579  // or q -> q gamma_v when m_q > 0 and m_gamma_v > 0.
2580  if ( dipSel->weakType != 0
2581  || (abs(dipSel->colvType) == 1 && dipSel->mFlavour > 0.) ) {
2582  mEmt = dipSel->mFlavour;
2583  if (pow2(mRad + mEmt) > dipSel->m2) return false;
2584  double m2Emt = pow2(mEmt);
2585  double lambda = sqrtpos( pow2(dipSel->m2 - m2Rad - m2Emt)
2586  - 4. * m2Rad * m2Emt );
2587  kRad = 0.5 * (dipSel->m2 - lambda + m2Emt - m2Rad)
2588  / dipSel->m2;
2589  kEmt = 0.5 * (dipSel->m2 - lambda + m2Rad - m2Emt)
2590  / dipSel->m2;
2591  pTorig *= 1. - kRad - kEmt;
2592  pTcorr *= 1. - kRad - kEmt;
2593  double pzMove = kRad * pzRad - kEmt * pzEmt;
2594  pzRad -= pzMove;
2595  pzEmt += pzMove;
2596 
2597  // Kinematics reduction for q -> q g/gamma/g_HV when m_q > 0.
2598  } else if (abs(dipSel->colType) == 1 || dipSel->chgType != 0
2599  || abs(dipSel->colvType) == 1) {
2600  pTorig *= 1. - dipSel->m2Rad / dipSel->m2;
2601  pTcorr *= 1. - dipSel->m2Rad / dipSel->m2;
2602  pzRad += pzEmt * dipSel->m2Rad / dipSel->m2;
2603  pzEmt *= 1. - dipSel->m2Rad / dipSel->m2;
2604 
2605  // Kinematics reduction for g -> q qbar or gamma -> f fbar when m_f > 0;
2606  } else if (abs(dipSel->flavour) < 20) {
2607  mEmt = dipSel->mFlavour;
2608  mRad = mEmt;
2609  double beta = sqrtpos( 1. - 4. * pow2(mEmt) / dipSel->m2 );
2610  pTorig *= beta;
2611  pTcorr *= beta;
2612  pzRad = 0.5 * ( (1. + beta) * pzRad + (1. - beta) * pzEmt );
2613  pzEmt = pzRadPlusEmt - pzRad;
2614  }
2615 
2616  // Reject g emission where mass effects have reduced pT below cutoff.
2617  if (idEmt == 21 && pTorig < pTcolCut) return false;
2618 
2619  // Find rest frame and angles of original dipole.
2620  RotBstMatrix M;
2621  M.fromCMframe(pRadBef, pRecBef);
2622 
2623  // Evaluate coefficient of azimuthal asymmetry from gluon polarization.
2624  findAsymPol( event, dipSel);
2625 
2626  // Begin construction of new dipole kinematics: pick azimuthal angle.
2627  Vec4 pRad, pEmt, pRec;
2628  double wtPhi = 1.;
2629  do {
2630  double phi = 2. * M_PI * rndmPtr->flat();
2631 
2632  // Define kinematics of branching in dipole rest frame.
2633  pRad = Vec4( pTcorr * cos(phi), pTcorr * sin(phi), pzRad,
2634  sqrt( pow2(pTcorr) + pow2(pzRad) + pow2(mRad) ) );
2635  pEmt = Vec4( -pRad.px(), -pRad.py(), pzEmt,
2636  sqrt( pow2(pTcorr) + pow2(pzEmt) + pow2(mEmt) ) );
2637  pRec = Vec4( 0., 0., -pzRadPlusEmt, sqrt( pow2(pzRadPlusEmt)
2638  + dipSel->m2Rec ) );
2639 
2640  // Rotate and boost dipole products to the event frame.
2641  pRad.rotbst(M);
2642  pEmt.rotbst(M);
2643  pRec.rotbst(M);
2644 
2645  // Azimuthal phi weighting: loop to new phi value if required.
2646  if (dipSel->asymPol != 0.) {
2647  Vec4 pAunt = event[dipSel->iAunt].p();
2648  double cosPhi = cosphi( pRad, pAunt, pRadBef );
2649  wtPhi = ( 1. + dipSel->asymPol * (2. * pow2(cosPhi) - 1.) )
2650  / ( 1. + abs(dipSel->asymPol) );
2651  }
2652  } while (wtPhi < rndmPtr->flat()) ;
2653 
2654  // Kinematics when recoiler is initial-state parton.
2655  int isrTypeNow = dipSel->isrType;
2656  int isrTypeSave = isrTypeNow;
2657  if (!useLocalRecoilNow) isrTypeNow = 0;
2658  if (isrTypeNow != 0) pRec = 2. * recBef.p() - pRec;
2659 
2660  // PS dec 2010: check if radiator has flexible normalization
2661  bool isFlexible = dipSel->isFlexible;
2662 
2663  // Define new particles from dipole branching.
2664  double pTsel = sqrt(dipSel->pT2);
2665  Particle rad = Particle(idRad, 51, iRadBef, 0, 0, 0,
2666  colRad, acolRad, pRad, mRad, pTsel);
2667  Particle emt = Particle(idEmt, 51, iRadBef, 0, 0, 0,
2668  colEmt, acolEmt, pEmt, mEmt, pTsel);
2669 
2670  // Recoiler either in final or in initial state
2671  Particle rec = (isrTypeNow == 0)
2672  ? Particle(recBef.id(), 52, iRecBef, iRecBef, 0, 0,
2673  recBef.col(), recBef.acol(), pRec, dipSel->mRec, pTsel)
2674  : Particle(recBef.id(), -53, 0, 0, iRecBef, iRecBef,
2675  recBef.col(), recBef.acol(), pRec, 0., 0.);
2676 
2677  // Special checks to set weak particles status equal to 56.
2678  // This is needed for decaying the particles. Also set polarisation.
2679  if (emt.idAbs() == 23 || emt.idAbs() == 24) {
2680  emt.status(56);
2681  event[iRadBef].pol( dipSel->weakPol );
2682  rad.pol( dipSel->weakPol );
2683  }
2684 
2685  // ME corrections can lead to branching being rejected.
2686  if (dipSel->MEtype > 0) {
2687  Particle& partner = (dipSel->iMEpartner == iRecBef)
2688  ? rec : event[dipSel->iMEpartner];
2689  if ( findMEcorr( dipSel, rad, partner, emt) < rndmPtr->flat() )
2690  return false;
2691  if (dipSel->MEtype >= 200 && dipSel->MEtype <= 210
2692  && findMEcorrWeak( dipSel, rad.p(), partner.p(), emt.p(), p3weak, p4weak,
2693  event[iRadBef].p(), event[iRecBef].p()) < rndmPtr->flat() )
2694  return false;
2695  }
2696 
2697  // Rescatter: if the recoiling partner is not in the same system
2698  // as the radiator, fix up intermediate systems (can lead
2699  // to emissions being vetoed)
2700  if (allowRescatter && FIXRESCATTER && isInterleaved
2701  && iSysSel != iSysSelRec) {
2702  Vec4 pNew = rad.p() + emt.p();
2703  if (!rescatterPropagateRecoil(event, pNew)) return false;
2704  }
2705 
2706  // Save properties to be restored in case of user-hook veto of emission.
2707  int eventSizeOld = event.size();
2708  int iRadStatusV = event[iRadBef].status();
2709  int iRadDau1V = event[iRadBef].daughter1();
2710  int iRadDau2V = event[iRadBef].daughter2();
2711  int iRecStatusV = event[iRecBef].status();
2712  int iRecMot1V = event[iRecBef].mother1();
2713  int iRecMot2V = event[iRecBef].mother2();
2714  int iRecDau1V = event[iRecBef].daughter1();
2715  int iRecDau2V = event[iRecBef].daughter2();
2716  int beamOff1 = 1 + beamOffset;
2717  int beamOff2 = 2 + beamOffset;
2718  int ev1Dau1V = event[beamOff1].daughter1();
2719  int ev2Dau1V = event[beamOff2].daughter1();
2720 
2721  // Shower may occur at a displaced vertex.
2722  if (radBef.hasVertex()) {
2723  rad.vProd( radBef.vProd() );
2724  emt.vProd( radBef.vProd() );
2725  }
2726  if (recBef.hasVertex()) rec.vProd( recBef.vProd() );
2727 
2728  // Put new particles into the event record.
2729  // Mark original dipole partons as branched and set daughters/mothers.
2730  int iRad = event.append(rad);
2731  int iEmt = event.append(emt);
2732  event[iRadBef].statusNeg();
2733  event[iRadBef].daughters( iRad, iEmt);
2734  int iRec = 0;
2735  if (useLocalRecoilNow) {
2736  iRec = event.append(rec);
2737  if (isrTypeNow == 0) {
2738  event[iRecBef].statusNeg();
2739  event[iRecBef].daughters( iRec, iRec);
2740  } else {
2741  event[iRecBef].mothers( iRec, iRec);
2742  event[iRec].mothers( iRecMot1V, iRecMot2V);
2743  if (iRecMot1V == beamOff1) event[beamOff1].daughter1( iRec);
2744  if (iRecMot1V == beamOff2) event[beamOff2].daughter1( iRec);
2745  }
2746 
2747  // Global recoil: need to find relevant rotation+boost for recoilers:
2748  // boost+rotate to rest frame, boost along z axis, rotate+boost back.
2749  } else {
2750  RotBstMatrix MG = M;
2751  MG.invert();
2752  double pzRecBef = -0.5 * sqrtpos( pow2(dipSel->m2Dip - dipSel->m2Rad
2753  - dipSel->m2Rec) - 4. * dipSel->m2Rad * dipSel->m2Rec ) / dipSel->mDip;
2754  double eRecBef = sqrt( pow2(pzRecBef) + dipSel->m2Rec);
2755  double pzRecAft = -pzRadPlusEmt;
2756  double eRecAft = sqrt( pow2(pzRecAft) + dipSel->m2Rec);
2757  MG.bst( Vec4(0., 0., pzRecBef, eRecBef), Vec4(0., 0., pzRecAft, eRecAft) );
2758  MG.rotbst( M);
2759 
2760  // Global recoil: copy particles, and rotate+boost momenta (not vertices).
2761  for (int iG = 0; iG < int(iGRecBef.size()); ++iG) {
2762  iRec = event.copy( iGRecBef[iG], 52);
2763  iGRec.push_back( iRec);
2764  Vec4 pGRec = event[iRec].p();
2765  pGRec.rotbst( MG);
2766  event[iRec].p( pGRec);
2767  }
2768  }
2769 
2770  // Allow veto of branching. If so restore event record to before emission.
2771  bool inResonance = (partonSystemsPtr->getInA(iSysSel) == 0) ? true : false;
2772  if ( (canVetoEmission && userHooksPtr->doVetoFSREmission( eventSizeOld,
2773  event, iSysSel, inResonance))
2774  || (canMergeFirst && mergingHooksPtr->doVetoEmission( event )) ) {
2775  event.popBack( event.size() - eventSizeOld);
2776  event[iRadBef].status( iRadStatusV);
2777  event[iRadBef].daughters( iRadDau1V, iRadDau2V);
2778  if (useLocalRecoilNow && isrTypeNow == 0) {
2779  event[iRecBef].status( iRecStatusV);
2780  event[iRecBef].daughters( iRecDau1V, iRecDau2V);
2781  } else if (useLocalRecoilNow) {
2782  event[iRecBef].mothers( iRecMot1V, iRecMot2V);
2783  if (iRecMot1V == beamOff1) event[beamOff1].daughter1( ev1Dau1V);
2784  if (iRecMot1V == beamOff2) event[beamOff2].daughter1( ev2Dau1V);
2785  } else {
2786  for (int iG = 0; iG < int(iGRecBef.size()); ++iG) {
2787  event[iGRecBef[iG]].statusPos();
2788  event[iGRecBef[iG]].daughters( 0, 0);
2789  }
2790  }
2791  return false;
2792  }
2793 
2794  // For global recoil restore the one nominal recoiler, for bookkeeping.
2795  if (!useLocalRecoilNow) {
2796  iRec = iRecBef;
2797  for (int iG = 0; iG < int(iGRecBef.size()); ++iG)
2798  if (iGRecBef[iG] == iRecBef) iRec = iGRec[iG];
2799  }
2800 
2801  // For initial-state recoiler also update beam and sHat info.
2802  if (isrTypeNow != 0) {
2803  BeamParticle& beamRec = (isrTypeNow == 1) ? *beamAPtr : *beamBPtr;
2804  double xOld = beamRec[iSysSelRec].x();
2805  double xRec = 2. * pRec.e() / (beamAPtr->e() + beamBPtr->e());
2806  beamRec[iSysSelRec].iPos( iRec);
2807  beamRec[iSysSelRec].x( xRec);
2808  partonSystemsPtr->setSHat( iSysSelRec,
2809  partonSystemsPtr->getSHat(iSysSelRec) * xRec / xOld);
2810  }
2811 
2812  // For global recoil: if everything went as expected, remove the line
2813  // from the list of "hard lines" that are allowed to use global recoil.
2814  if ( !useLocalRecoilNow || nGlobal >= nMaxGlobalBranch) {
2815  bool doRemove=true;
2816  while ( doRemove ) {
2817  bool hasRemoved = false;
2818  for (int iHard = 0; iHard < int(hardPartons.size()); ++iHard)
2819  if ( event[dipSel->iRadiator].isAncestor(hardPartons[iHard]) ) {
2820  hardPartons.erase( hardPartons.begin() + iHard );
2821  hasRemoved = true;
2822  break;
2823  }
2824  doRemove = hasRemoved;
2825  }
2826  }
2827 
2828  // Update number of splittings that have been produced with global recoil.
2829  if ( !useLocalRecoilNow ) ++nGlobal;
2830 
2831  // Photon emission: update to new dipole ends; add new photon "dipole".
2832  if (dipSel->flavour == 22) {
2833  dipSel->iRadiator = iRad;
2834  dipSel->iRecoiler = iRec;
2835  // When recoiler was uncharged particle, in resonance decays,
2836  // assign recoil to emitted photons.
2837  if (recoilToColoured && inResonance && event[iRec].chargeType() == 0)
2838  dipSel->iRecoiler = iEmt;
2839  dipSel->pTmax = pTsel;
2840  if (doQEDshowerByGamma) dipEnd.push_back( TimeDipoleEnd(iEmt, iRad,
2841  pTsel, 0, 0, 1, 0, 0, iSysSel, 0) );
2842 
2843  // Gluon emission: update both dipole ends and add two new ones.
2844  } else if (dipSel->flavour == 21) {
2845  dipSel->iRadiator = iRad;
2846  dipSel->iRecoiler = iEmt;
2847  dipSel->systemRec = iSysSel;
2848  dipSel->isrType = 0;
2849  dipSel->pTmax = pTsel;
2850  // Optionally also kill ME corrections after first emission.
2851  if (!doMEafterFirst) dipSel->MEtype = 0;
2852  // PS dec 2010: check normalization of radiating dipole
2853  // Dipole corresponding to the newly created color tag has normal strength
2854  double flexFactor = (isFlexible) ? dipSel->flexFactor : 1.0;
2855  dipSel->isFlexible = false;
2856  for (int i = 0; i < int(dipEnd.size()); ++i) {
2857  if (dipEnd[i].iRadiator == iRecBef && dipEnd[i].iRecoiler == iRadBef
2858  && dipEnd[i].colType != 0) {
2859  dipEnd[i].iRadiator = iRec;
2860  dipEnd[i].iRecoiler = iEmt;
2861  // Optionally also kill ME corrections after first emission.
2862  if (!doMEafterFirst) dipEnd[i].MEtype = 0;
2863  // Strive to match colour to anticolour inside closed system.
2864  if ( !isFlexible && dipEnd[i].colType * dipSel->colType > 0)
2865  dipEnd[i].iRecoiler = iRad;
2866  dipEnd[i].pTmax = pTsel;
2867  // PS dec 2010: if the (iRadBef,iRecBef) dipole was flexible, the
2868  // same should be true for this (opposite) end. If so, this end keeps
2869  // the modified normalization, so we shouldn't need to do anything.
2870  }
2871  // Weak shower can have gluons as recoiler. Always choose
2872  // the outgoing gluon that produces the highest invariant mass.
2873  if (event[iRadBef].id() == 21 && dipEnd[i].iRecoiler == iRadBef
2874  && dipEnd[i].weakType != 0) {
2875  double m1 = (event[iRad].p()+event[dipEnd[i].iRadiator].p()).m2Calc();
2876  double m2 = (event[iEmt].p()+event[dipEnd[i].iRadiator].p()).m2Calc();
2877  dipEnd[i].iRecoiler = (m1 > m2) ? iRad : iEmt;
2878  }
2879  }
2880  int colType = (dipSel->colType > 0) ? 2 : -2 ;
2881  // When recoiler was uncoloured particle, in resonance decays,
2882  // assign recoil to coloured particle.
2883  int iRecMod = iRec;
2884  if (recoilToColoured && inResonance && event[iRec].col() == 0
2885  && event[iRec].acol() == 0) iRecMod = iRad;
2886  dipEnd.push_back( TimeDipoleEnd(iEmt, iRecMod, pTsel,
2887  colType, 0, 0, 0, isrTypeSave, iSysSel, 0));
2888  dipEnd.back().systemRec = iSysSelRec;
2889  // PS dec 2010: the (iEmt,iRec) dipole "inherits" flexible normalization
2890  if (isFlexible) {
2891  dipEnd.back().isFlexible = true;
2892  dipEnd.back().flexFactor = flexFactor;
2893  }
2894  dipEnd.push_back( TimeDipoleEnd(iEmt, iRad, pTsel,
2895  -colType, 0, 0, 0, 0, iSysSel, 0));
2896 
2897  // Gluon branching to q qbar: update current dipole and other of gluon.
2898  } else if (dipSel->colType != 0) {
2899  for (int i = 0; i < int(dipEnd.size()); ++i) {
2900  // Strive to match colour to anticolour inside closed system.
2901  if ( !isFlexible && dipEnd[i].iRecoiler == iRadBef
2902  && dipEnd[i].colType * dipSel->colType < 0 )
2903  dipEnd[i].iRecoiler = iEmt;
2904  if (dipEnd[i].iRadiator == iRadBef && abs(dipEnd[i].colType) == 2) {
2905  dipEnd[i].colType /= 2;
2906  if (dipEnd[i].system != dipEnd[i].systemRec) continue;
2907 
2908  // Note: gluino -> quark + squark gives a deeper radiation dip than
2909  // the more obvious alternative photon decay, so is more realistic.
2910  dipEnd[i].MEtype = 66;
2911  if (&dipEnd[i] == dipSel) dipEnd[i].iMEpartner = iRad;
2912  else dipEnd[i].iMEpartner = iEmt;
2913  }
2914  // Choose recoiler to Z/W to get largest mass.
2915  if (event[iRadBef].id() == 21 && dipEnd[i].iRecoiler == iRadBef
2916  && dipEnd[i].weakType != 0) {
2917  double m1 = (event[iRad].p()+event[dipEnd[i].iRadiator].p()).m2Calc();
2918  double m2 = (event[iEmt].p()+event[dipEnd[i].iRadiator].p()).m2Calc();
2919  dipEnd[i].iRecoiler = (m1 > m2) ? iRad : iEmt;
2920  }
2921  }
2922  dipSel->iRadiator = iEmt;
2923  dipSel->iRecoiler = iRec;
2924  dipSel->pTmax = pTsel;
2925 
2926  // Gluon branching to q qbar: also add two charge dipole ends.
2927  // Note: gluino -> quark + squark gives a deeper radiation dip than
2928  // the more obvious alternative photon decay, so is more realistic.
2929  if (doQEDshowerByQ) {
2930  int chgType = event[iRad].chargeType();
2931  dipEnd.push_back( TimeDipoleEnd(iRad, iEmt, pTsel,
2932  0, chgType, 0, 0, 0, iSysSel, 66, iEmt));
2933  dipEnd.push_back( TimeDipoleEnd(iEmt, iRad, pTsel,
2934  0, -chgType, 0, 0, 0, iSysSel, 66, iRad));
2935  }
2936 
2937  // Gluon branching to q qbar: also add weak dipoles.
2938  // Randomly decided whether to use left or right quarks.
2939  if (doWeakShower && iSysSel == 0 &&
2940  !(hasWeaklyRadiated && singleWeakEmission)) {
2941  int weakPol = (rndmPtr->flat() > 0.5) ? -1 : 1;
2942  event[iRad].pol(weakPol);
2943  event[iEmt].pol(weakPol);
2944  if ((weakMode == 0 || weakMode == 1) && weakPol == -1) {
2945  dipEnd.push_back( TimeDipoleEnd(iRad, iEmt, pTsel,
2946  0, 0, 0, 1, 0, iSysSel, 200, iEmt, weakPol) );
2947  dipEnd.push_back( TimeDipoleEnd(iEmt, iRad, pTsel,
2948  0, 0, 0, 1, 0, iSysSel, 200, iRad, weakPol) );
2949  }
2950  if (weakMode == 0 || weakMode == 2) {
2951  dipEnd.push_back( TimeDipoleEnd(iRad, iEmt, pTsel,
2952  0, 0, 0, 2, 0, iSysSel, 205, iEmt, weakPol) );
2953  dipEnd.push_back( TimeDipoleEnd(iEmt, iRad, pTsel,
2954  0, 0, 0, 2, 0, iSysSel, 205, iRad, weakPol) );
2955  }
2956  }
2957 
2958  // Photon branching to f fbar: inactivate photon "dipole";
2959  // optionally add new charge and colour dipole ends.
2960  // (But not W or Z ends, since W/Z are heavier than gamma*.)
2961  } else if (dipSel->gamType != 0) {
2962  dipSel->gamType = 0;
2963  int chgType = event[iRad].chargeType();
2964  int colType = event[iRad].colType();
2965  // MEtype = 102 for charge in vector decay.
2966  if ( chgType != 0 && ( ( doQEDshowerByQ && colType != 0 )
2967  || ( doQEDshowerByL && colType == 0 ) ) ) {
2968  dipEnd.push_back( TimeDipoleEnd(iRad, iEmt, pTsel,
2969  0, chgType, 0, 0, 0, iSysSel, 102, iEmt) );
2970  dipEnd.push_back( TimeDipoleEnd(iEmt, iRad, pTsel,
2971  0, -chgType, 0, 0, 0, iSysSel, 102, iRad) );
2972  }
2973  // MEtype = 11 for colour in vector decay.
2974  if (colType != 0 && doQCDshower) {
2975  dipEnd.push_back( TimeDipoleEnd(iRad, iEmt, pTsel,
2976  colType, 0, 0, 0, 0, iSysSel, 11, iEmt) );
2977  dipEnd.push_back( TimeDipoleEnd(iEmt, iRad, pTsel,
2978  -colType, 0, 0, 0, 0, iSysSel, 11, iRad) );
2979  }
2980 
2981  // Photon_HV emission: update to new dipole ends.
2982  } else if (dipSel->flavour == 4900022) {
2983  dipSel->iRadiator = iRad;
2984  dipSel->iRecoiler = iRec;
2985  dipSel->pTmax = pTsel;
2986 
2987  // Gluon_HV emission: update to new dipole ends.
2988  } else if (dipSel->flavour == 4900021) {
2989  dipSel->iRadiator = iRad;
2990  dipSel->iRecoiler = iEmt;
2991  dipSel->pTmax = pTsel;
2992  for (int i = 0; i < int(dipEnd.size()); ++i)
2993  if (dipEnd[i].iRadiator == iRecBef && dipEnd[i].iRecoiler == iRadBef
2994  && dipEnd[i].isHiddenValley) {
2995  dipEnd[i].iRadiator = iRec;
2996  dipEnd[i].iRecoiler = iEmt;
2997  dipEnd[i].pTmax = pTsel;
2998  }
2999  int colvType = (dipSel->colvType > 0) ? 2 : -2 ;
3000  dipEnd.push_back( TimeDipoleEnd(iEmt, iRec, pTsel,
3001  0, 0, 0, 0, isrTypeSave, iSysSel, 0, -1, 0, false, true, colvType) );
3002  dipEnd.back().systemRec = iSysSelRec;
3003  dipEnd.push_back( TimeDipoleEnd(iEmt, iRad, pTsel,
3004  0, 0, 0, 0, 0, iSysSel, 0, -1, 0, false, true, -colvType) );
3005 
3006  // W/Z emission, if only a single weak emission is allowed.
3007  } else if (dipSel->weakType != 0) {
3008  hasWeaklyRadiated = true;
3009  if (singleWeakEmission)
3010  for (int i = 0; i < int(dipEnd.size()); ++i) dipEnd[i].weakType = 0;
3011  }
3012 
3013  // Copy or set lifetime for new final state.
3014  if (event[iRad].id() == event[iRadBef].id()) {
3015  event[iRad].tau( event[iRadBef].tau() );
3016  } else {
3017  event[iRad].tau( event[iRad].tau0() * rndmPtr->exp() );
3018  event[iEmt].tau( event[iEmt].tau0() * rndmPtr->exp() );
3019  }
3020  event[iRec].tau( event[iRecBef].tau() );
3021 
3022  // Now update other dipoles that also involved the radiator or recoiler.
3023  for (int i = 0; i < int(dipEnd.size()); ++i) {
3024  // PS dec 2010: if radiator was flexible and now is normal, there may
3025  // be other flexible dipoles that need updating.
3026  if (isFlexible && !dipSel->isFlexible && dipEnd[i].isFlexible) {
3027  if (dipEnd[i].iRecoiler == iRadBef) dipEnd[i].iRecoiler = iEmt;
3028  if (dipEnd[i].iRadiator == iRadBef) {
3029  dipEnd[i].iRadiator = iEmt;
3030  if (dipEnd[i].colType == 1 && dipSel->flavour == 21)
3031  dipEnd[i].colType = 2;
3032  if (dipEnd[i].colType ==-1 && dipSel->flavour == 21)
3033  dipEnd[i].colType =-2;
3034  }
3035  }
3036  if (dipEnd[i].iRadiator == iRadBef) dipEnd[i].iRadiator = iRad;
3037  if (dipEnd[i].iRecoiler == iRadBef) dipEnd[i].iRecoiler = iRad;
3038  if (dipEnd[i].iMEpartner == iRadBef) dipEnd[i].iMEpartner = iRad;
3039  if (useLocalRecoilNow) {
3040  if (dipEnd[i].iRadiator == iRecBef) dipEnd[i].iRadiator = iRec;
3041  if (dipEnd[i].iRecoiler == iRecBef) dipEnd[i].iRecoiler = iRec;
3042  if (dipEnd[i].iMEpartner == iRecBef) dipEnd[i].iMEpartner = iRec;
3043  } else {
3044  for (int iG = 0; iG < int(iGRecBef.size()); ++iG) {
3045  if (dipEnd[i].iRadiator == iGRecBef[iG])
3046  dipEnd[i].iRadiator = iGRec[iG];
3047  if (dipEnd[i].iRecoiler == iGRecBef[iG])
3048  dipEnd[i].iRecoiler = iGRec[iG];
3049  if (dipEnd[i].iMEpartner == iGRecBef[iG])
3050  dipEnd[i].iMEpartner = iGRec[iG];
3051  }
3052  }
3053  }
3054 
3055  // PS Apr 2011
3056  // Update any junctions downstream of this branching (if necessary)
3057  // (This happens, e.g., via LHEF, when adding showers to intermediate
3058  // coloured resonances whose decays involved junctions)
3059  for (int iJun = 0; iJun < event.sizeJunction(); iJun++) {
3060  // Number of incoming colour lines for this junction.
3061  int nIncoming = (event.kindJunction(iJun)-1)/2;
3062  // Check radiator colour or anticolour, depending on junction kind
3063  // (if junction, incoming = anticolours, and vice versa)
3064  int colChk = 0;
3065  colChk = ( event.kindJunction(iJun) % 2 == 0 )
3066  ? event[iRadBef].col() : event[iRadBef].acol();
3067  // Loop over incoming junction ends
3068  for (int iCol = 0; iCol < nIncoming; iCol++) {
3069  int colJun = event.colJunction( iJun, iCol);
3070  // If match, update junction end with new upstream (anti)colour
3071  if (colJun == colChk) {
3072  int colNew = 0;
3073  if ( event.kindJunction(iJun) % 2 == 0 ) colNew = colRad;
3074  else colNew = acolRad;
3075  event.colJunction( iJun, iCol, colNew );
3076  }
3077  }
3078  }
3079 
3080  // Finally update the list of all partons in all systems.
3081  partonSystemsPtr->replace(iSysSel, iRadBef, iRad);
3082  partonSystemsPtr->addOut(iSysSel, iEmt);
3083  if (useLocalRecoilNow)
3084  partonSystemsPtr->replace(iSysSelRec, iRecBef, iRec);
3085  else {
3086  for (int iG = 0; iG < int(iGRecBef.size()); ++iG)
3087  partonSystemsPtr->replace(iSysSel, iGRecBef[iG], iGRec[iG]);
3088  }
3089 
3090  // Done.
3091  return true;
3092 
3093 }
3094 
3095 //--------------------------------------------------------------------------
3096 
3097 // Rescatter: If a dipole stretches between two different systems, those
3098 // systems will no longer locally conserve momentum. These
3099 // imbalances become problematic when ISR or primordial kT
3100 // is switched on as these steps involve Lorentz boosts.
3101 //
3102 // 'rescatterPropagateRecoil' tries to fix momentum in all
3103 // systems by propogating recoil momentum through all
3104 // intermediate systems. As the momentum transfer is already
3105 // defined, this can lead to internal lines gaining a
3106 // virtuality.
3107 
3108 // Useful definitions for a pair of integers and a vector of pairs
3109 typedef pair < int, int > pairInt;
3110 typedef vector < pairInt > vectorPairInt;
3111 
3112 //--------------------------------------------------------------------------
3113 
3114 // findParentSystems
3115 // Utility routine to find all parent systems of a given system
3116 // Returns a vector of pairs of integers with:
3117 // a) The system index, including the starting system (negative
3118 // if (b) points to a parent system, positive if (b) points
3119 // to a daughter system
3120 // b) The event record index that is the path out of the system
3121 // (if forwards == false, this is an incoming parton to the
3122 // system, and is +ve if side A or -ve if side B,
3123 // if forwards == true, this is an outgoing parton from the
3124 // system).
3125 // Returns as empty vector on failure
3126 // Note: this assumes single rescattering only and therefore only
3127 // one possible parent system
3128 
3129 inline vectorPairInt findParentSystems(const int sys,
3130  Event& event, PartonSystems* partonSystemsPtr, bool forwards) {
3131 
3132  vectorPairInt parentSystems;
3133  parentSystems.reserve(10);
3134 
3135  int iSysCur = sys;
3136  while (true) {
3137  // Get two incoming partons
3138  int iInA = partonSystemsPtr->getInA(iSysCur);
3139  int iInB = partonSystemsPtr->getInB(iSysCur);
3140 
3141  // Check if either of these links to another system
3142  int iIn = 0;
3143  if (event[iInA].isRescatteredIncoming()) iIn = iInA;
3144  if (event[iInB].isRescatteredIncoming()) iIn = -iInB;
3145 
3146  // Save the current system to the vector
3147  parentSystems.push_back( pairInt(-iSysCur, iIn) );
3148  if (iIn == 0) break;
3149 
3150  int iInAbs = abs(iIn);
3151  int iMother = event[iInAbs].mother1();
3152  iSysCur = partonSystemsPtr->getSystemOf(iMother);
3153  if (iSysCur == -1) {
3154  parentSystems.clear();
3155  break;
3156  }
3157  } // while (true)
3158 
3159  // If forwards is set, change all event record indices to go to daughter
3160  // systems rather than parent systems
3161  if (forwards) {
3162  vectorPairInt::reverse_iterator rit;
3163  for (rit = parentSystems.rbegin(); rit < (parentSystems.rend() - 1);
3164  ++rit) {
3165  pairInt &cur = *rit;
3166  pairInt &next = *(rit + 1);
3167  cur.first = -cur.first;
3168  cur.second = (next.second < 0) ? -event[abs(next.second)].mother1() :
3169  event[abs(next.second)].mother1();
3170  }
3171  }
3172 
3173  return parentSystems;
3174 }
3175 
3176 //--------------------------------------------------------------------------
3177 
3178 // rescatterPropagateRecoil
3179 // Fix up momentum in all intermediate systems when radiator and recoiler
3180 // systems are different. The strategy is to look at all parent systems
3181 // from the radiator system and the recoiler system and find where they
3182 // intersect.
3183 
3184 bool TimeShower::rescatterPropagateRecoil( Event& event, Vec4& pNew) {
3185 
3186  // Some useful variables for later
3187  int iRadBef = dipSel->iRadiator;
3188  iSysSel = dipSel->system;
3189  int iSysSelRec = dipSel->systemRec;
3190  Vec4 pImbal = pNew - event[iRadBef].p();
3191 
3192  // Store changes locally at first in case we veto the branching
3193  // eventMod stores index into the event record and new 4-vector
3194  vector < pair < int, Vec4 > > eventMod;
3195  eventMod.reserve(10);
3196  // systemMod stores system index (iSys) and system-parton index (iMem)
3197  // iMem >= 0 - index into outgoing partons (iOut)
3198  // iMem == -1 - incoming A
3199  // iMem == -2 - incoming B
3200  vectorPairInt systemMod;
3201  systemMod.reserve(10);
3202 
3203  // Find all parent systems from radiating and recoiling systems
3204  vectorPairInt radParent = findParentSystems(iSysSel, event,
3205  partonSystemsPtr, false);
3206  vectorPairInt recParent = findParentSystems(iSysSelRec, event,
3207  partonSystemsPtr, true);
3208  if (radParent.size() == 0 || recParent.size() == 0) {
3209  // This should never happen
3210  infoPtr->errorMsg("Error in TimeShower::rescatterPropagateRecoil: "
3211  "couldn't find parent system; branching vetoed");
3212  return false;
3213  }
3214  // Find the system that connects radiating and recoiling system
3215  bool foundPath = false;
3216  unsigned int iRadP = 0;
3217  unsigned int iRecP = 0;
3218  for (iRadP = 0; iRadP < radParent.size(); iRadP++) {
3219  for (iRecP = 0; iRecP < recParent.size(); iRecP++)
3220  if (abs(radParent[iRadP].first) == abs(recParent[iRecP].first)) {
3221  foundPath = true;
3222  break;
3223  }
3224  if (foundPath) break;
3225  }
3226  if (!foundPath) {
3227  // Can fail e.g. for QED dipoles where there is no connection
3228  // between radiator and recoiler systems
3229  infoPtr->errorMsg("Warning in TimeShower::rescatterPropagateRecoil: "
3230  "couldn't find recoil path; branching vetoed");
3231  return false;
3232  }
3233 
3234  // Join together to form complete path from radiating system
3235  // to recoiling system
3236  vectorPairInt path;
3237  if (radParent.size() > 1)
3238  path.assign(radParent.begin(), radParent.begin() + iRadP);
3239  if (recParent.size() > 1)
3240  path.insert(path.end(), recParent.rend() - iRecP - 1,
3241  recParent.rend() - 1);
3242 
3243  // Follow the path fixing up momenta as we go
3244  for (unsigned int i = 0; i < path.size(); i++) {
3245  // Line out of the current system
3246  bool isIncoming = (path[i].first < 0) ? true : false;
3247  int iSysCur = abs(path[i].first);
3248  bool isIncomingA = (path[i].second > 0) ? true : false;
3249  int iLink = abs(path[i].second);
3250 
3251  int iMemCur;
3252  if (isIncoming) iMemCur = (isIncomingA) ? -1 : -2;
3253  else {
3254  iMemCur = -1;
3255  for (int j = 0; j < partonSystemsPtr->sizeOut(iSysCur); j++)
3256  if (partonSystemsPtr->getOut(iSysCur, j) == iLink) {
3257  iMemCur = j;
3258  break;
3259  }
3260  if (iMemCur == -1) {
3261  // This should never happen
3262  infoPtr->errorMsg("Error in TimeShower::rescatterPropagateRecoil: "
3263  "couldn't find parton system; branching vetoed");
3264  return false;
3265  }
3266  }
3267 
3268  Vec4 pMod = (isIncoming) ? event[iLink].p() + pImbal :
3269  event[iLink].p() - pImbal;
3270  eventMod.push_back(pair <int, Vec4> (iLink, pMod));
3271  systemMod.push_back(pairInt(iSysCur, iMemCur));
3272 
3273  // Calculate sHat of iSysCur
3274  int iInCurA = partonSystemsPtr->getInA(iSysCur);
3275  int iInCurB = partonSystemsPtr->getInB(iSysCur);
3276  Vec4 pTotCur = event[iInCurA].p() + event[iInCurB].p();
3277 
3278  // If iMemCur is -1 or -2, then we must have changed the sHat of iSysCur
3279  if (iMemCur < 0) pTotCur += (isIncoming) ? pImbal : -pImbal;
3280  double sHatCur = pTotCur.m2Calc();
3281 
3282  // The fixed-up incoming and outgoing partons should not have
3283  // too large a virtuality in relation to the system mass-square.
3284  if (abs(pMod.m2Calc()) > MAXVIRTUALITYFRACTION * sHatCur) {
3285  infoPtr->errorMsg("Warning in TimeShower::rescatterPropagateRecoil: "
3286  "virtuality much larger than sHat; branching vetoed");
3287  return false;
3288  }
3289 
3290  // Outgoing ones should also not have too large negative energy
3291  // in the rest frame of the system.
3292  if (!isIncoming && pMod * pTotCur < -MAXNEGENERGYFRACTION * sHatCur) {
3293  infoPtr->errorMsg("Warning in TimeShower::rescatterPropagateRecoil: "
3294  "rest frame energy too negative; branching vetoed");
3295  return false;
3296  }
3297 
3298  // Veto negative sHat.
3299  if (sHatCur < 0.0) {
3300  infoPtr->errorMsg("Warning in TimeShower::rescatterPropagateRecoil: "
3301  "sHat became negative; branching vetoed");
3302  return false;
3303  }
3304 
3305  // Line into the new current system
3306  iLink = (isIncoming) ? event[iLink].mother1() :
3307  event[iLink].daughter1();
3308  iSysCur = partonSystemsPtr->getSystemOf(iLink, true);
3309 
3310  if (!isIncoming) iMemCur = (isIncomingA) ? -1 : -2;
3311  else {
3312  iMemCur = -1;
3313  for (int j = 0; j < partonSystemsPtr->sizeOut(iSysCur); j++)
3314  if (partonSystemsPtr->getOut(iSysCur, j) == iLink) {
3315  iMemCur = j;
3316  break;
3317  }
3318  if (iMemCur == -1) {
3319  // This should never happen
3320  infoPtr->errorMsg("Error in TimeShower::rescatterPropagateRecoil: "
3321  "couldn't find parton system; branching vetoed");
3322  return false;
3323  }
3324  }
3325 
3326  pMod = (isIncoming) ? event[iLink].p() + pImbal :
3327  event[iLink].p() - pImbal;
3328  eventMod.push_back(pair <int, Vec4> (iLink, pMod));
3329  systemMod.push_back(pairInt(iSysCur, iMemCur));
3330 
3331  // Calculate sHat of iSysCur
3332  iInCurA = partonSystemsPtr->getInA(iSysCur);
3333  iInCurB = partonSystemsPtr->getInB(iSysCur);
3334  pTotCur = event[iInCurA].p() + event[iInCurB].p();
3335 
3336  // If iMemCur is -1 or -2, then we must have changed the sHat of iSysCur
3337  if (iMemCur < 0) pTotCur += (isIncoming) ? pImbal : -pImbal;
3338  sHatCur = pTotCur.m2Calc();
3339 
3340  // The fixed-up incoming and outgoing partons should not have
3341  // too large a virtuality in relation to the system mass-square.
3342  if (abs(pMod.m2Calc()) > MAXVIRTUALITYFRACTION * sHatCur) {
3343  infoPtr->errorMsg("Warning in TimeShower::rescatterPropagateRecoil: "
3344  "virtuality much larger than sHat; branching vetoed");
3345  return false;
3346  }
3347 
3348  // Outgoing ones should also not have too large negative energy
3349  // in the rest frame of the system.
3350  if (!isIncoming && pMod * pTotCur < -MAXNEGENERGYFRACTION * sHatCur) {
3351  infoPtr->errorMsg("Warning in TimeShower::rescatterPropagateRecoil: "
3352  "rest frame energy too negative; branching vetoed");
3353  return false;
3354  }
3355 
3356  // Veto negative sHat
3357  if (sHatCur < 0.0) {
3358  infoPtr->errorMsg("Warning in TimeShower::rescatterPropagateRecoil: "
3359  "sHat became negative; branching vetoed");
3360  return false;
3361  }
3362 
3363  // Do negative energy veto
3364  if (VETONEGENERGY && pMod.e() < 0.0) {
3365  infoPtr->errorMsg("Warning in TimeShower::rescatterPropagateRecoil: "
3366  "energy became negative; branching vetoed");
3367  return false;
3368  }
3369 
3370  } // for (unsigned int i = 0; i < path.size(); i++)
3371 
3372  // If no vetos by this point, apply the changes to the event record
3373  // An incoming particle with changed momentum is given status code -54,
3374  // an outgoing particle with changed momentum is given status code -55
3375  for (unsigned int i = 0; i < eventMod.size(); i++) {
3376  int idx = eventMod[i].first;
3377  Vec4 &pMod = eventMod[i].second;
3378  int iSys = systemMod[i].first;
3379  int iMem = systemMod[i].second;
3380 
3381  // If incoming to a process then set the copy to be the mother
3382  if (event[idx].isRescatteredIncoming()) {
3383  int mother1 = event[idx].mother1();
3384  idx = event.copy(idx, -54);
3385  event[mother1].daughters(idx, idx);
3386 
3387  // Update beam information if necessary
3388  double eCM = sqrt(m2( beamAPtr->p(), beamBPtr->p()));
3389  if (iMem == -1) {
3390  partonSystemsPtr->setInA(iSys, idx);
3391  (*beamAPtr)[iSys].x((pMod.e() + pMod.pz()) / eCM);
3392  (*beamAPtr)[iSys].m(pMod.mCalc());
3393  (*beamAPtr)[iSys].p(pMod);
3394  (*beamAPtr)[iSys].iPos(idx);
3395  } else if (iMem == -2) {
3396  partonSystemsPtr->setInB(iSys, idx);
3397  (*beamBPtr)[iSys].x((pMod.e() - pMod.pz()) / eCM);
3398  (*beamBPtr)[iSys].m(pMod.mCalc());
3399  (*beamBPtr)[iSys].p(pMod);
3400  (*beamBPtr)[iSys].iPos(idx);
3401  } else {
3402  // This should never happen
3403  infoPtr->errorMsg("Error in TimeShower::rescatterPropagateRecoil: "
3404  "internal bookeeping error");
3405  }
3406 
3407  // Otherwise set the new event record entry to be the daughter
3408  } else {
3409  int daughter1 = event[idx].daughter1();
3410  idx = event.copy(idx, 55);
3411  event[idx].statusNeg();
3412  event[daughter1].mothers(idx, idx);
3413 
3414  partonSystemsPtr->setOut(iSys, iMem, idx);
3415  }
3416 
3417  event[idx].p( eventMod[i].second );
3418  event[idx].m( event[idx].mCalc() );
3419  }
3420 
3421  return true;
3422 }
3423 
3424 
3425 //--------------------------------------------------------------------------
3426 
3427 // Find class of QCD ME correction.
3428 // MEtype classification follow codes in Norrbin article,
3429 // additionally -1 = try to find type, 0 = no ME corrections.
3430 // Warning: not yet tried out to do a correct assignment in
3431 // arbitrary multiparton configurations! ??
3432 
3433 void TimeShower::findMEtype( Event& event, TimeDipoleEnd& dip) {
3434 
3435  // Initial value. Mark if no ME corrections to be applied.
3436  bool setME = true;
3437  if (!doMEcorrections) setME = false;
3438  int iMother = event[dip.iRadiator].mother1();
3439  int iMother2 = event[dip.iRadiator].mother2();
3440 
3441  // Allow ME corrections for Hidden Valley pair in 2 -> 2.
3442  if (dip.isHiddenValley && event[dip.iRecoiler].id()
3443  == -event[dip.iRadiator].id());
3444 
3445  // Allow ME corrections for all weak branchings.
3446  else if (dip.weakType != 0);
3447 
3448  // Else no ME corrections in 2 -> n processes.
3449  else {
3450  if (iMother2 != iMother && iMother2 != 0) setME = false;
3451  if (event[dip.iRecoiler].mother1() != iMother) setME = false;
3452  if (event[dip.iRecoiler].mother2() != iMother2) setME = false;
3453  }
3454 
3455  // No ME corrections for recoiler in initial state.
3456  if (event[dip.iRecoiler].status() < 0) setME = false;
3457 
3458  // No ME corrections for recoiler not in same system
3459  if (dip.system != dip.systemRec) setME = false;
3460 
3461  // Done if no ME to be set.
3462  if (!setME) {
3463  dip.MEtype = 0;
3464  return;
3465  }
3466 
3467  // If no ME partner set, assume it is the recoiler.
3468  if (dip.iMEpartner < 0) dip.iMEpartner = dip.iRecoiler;
3469 
3470  // Now begin processing of colour dipole, including Hidden Valley.
3471  if (dip.colType != 0 || dip.colvType != 0) {
3472  bool isHiddenColour = (dip.colvType != 0);
3473 
3474  // Find daughter types (may or may not be used later on).
3475  int idDau1 = event[dip.iRadiator].id();
3476  int idDau2 = event[dip.iMEpartner].id();
3477  int dau1Type = findMEparticle(idDau1, isHiddenColour);
3478  int dau2Type = findMEparticle(idDau2, isHiddenColour);
3479  int minDauType = min(dau1Type, dau2Type);
3480  int maxDauType = max(dau1Type, dau2Type);
3481 
3482  // Reorder dipole ends in kinematics. Split ME expression in two sides.
3483  dip.MEorder = (dau2Type >= dau1Type);
3484  dip.MEsplit = (maxDauType <= 6);
3485  dip.MEgluinoRec = false;
3486 
3487  // If type already set (or set not to have) then done.
3488  if (minDauType == 0 && dip.MEtype < 0) dip.MEtype = 0;
3489  if (dip.MEtype >= 0) return;
3490  dip.MEtype = 0;
3491 
3492  // For H -> gg -> ggg we found that DGLAP kernels do better than eikonal.
3493  if (dau1Type == 4 && dau2Type == 4) return;
3494 
3495  // Find mother type.
3496  int idMother = 0;
3497  if ( event[dip.iRecoiler].mother1() == iMother && iMother >= 0)
3498  idMother = event[iMother].id();
3499  int motherType = (idMother != 0)
3500  ? findMEparticle(idMother, isHiddenColour) : 0;
3501 
3502  // When a mother if not known then use colour and spin content to guess.
3503  if (motherType == 0) {
3504  int col1 = event[dip.iRadiator].col();
3505  int acol1 = event[dip.iRadiator].acol();
3506  int col2 = event[dip.iMEpartner].col();
3507  int acol2 = event[dip.iMEpartner].acol();
3508  // spinT = 0/1 = integer or half-integer.
3509  int spinT = ( event[dip.iRadiator].spinType()
3510  + event[dip.iMEpartner].spinType() )%2;
3511  // Colour singlet mother.
3512  if ( col1 == acol2 && acol1 == col2 )
3513  motherType = (spinT == 0) ? 7 : 9;
3514  // Colour octet mother.
3515  else if ( (col1 == acol2 && acol1 != 0 && col2 != 0)
3516  || (acol1 == col2 && col1 != 0 && acol2 != 0) )
3517  motherType = (spinT == 0) ? 4 : 5;
3518  // Colour triplet mother.
3519  else if ( (col1 == acol2 && acol1 != col2)
3520  || (acol1 == col2 && col1 != acol2) )
3521  motherType = (spinT == 0) ? 2 : 1;
3522  // If no colours are matched then cannot have common mother, so done.
3523  else return;
3524  }
3525 
3526  // Now start from default, which is eikonal ME corrections,
3527  // and try to find matching ME cases below.
3528  int MEkind = 0;
3529  int MEcombi = 4;
3530  dip.MEmix = 0.5;
3531 
3532  // Hidden Valley with massive gamma_v covered by two special cases.
3533  if (isHiddenColour && brokenHVsym) {
3534  MEkind = (dau2Type == 0 || dau2Type > 6) ? 30 : 31;
3535  dip.MEtype = 5 * MEkind + 1;
3536  return;
3537  }
3538 
3539  // Triplet recoiling against gluino needs enhanced radiation
3540  // to match to matrix elements.
3541  dip.MEgluinoRec = (dau1Type >= 1 && dau1Type <= 3 && dau2Type == 5);
3542 
3543  // Vector/axial vector -> q + qbar.
3544  if (minDauType == 1 && maxDauType == 1 &&
3545  (motherType == 4 || motherType == 7) ) {
3546  MEkind = 2;
3547  if (idMother == 21 || idMother == 22) MEcombi = 1;
3548  else if (idMother == 23 || idDau1 + idDau2 == 0) {
3549  MEcombi = 3;
3550  dip.MEmix = gammaZmix( event, iMother, dip.iRadiator, dip.iRecoiler );
3551  }
3552  else if (idMother == 24) MEcombi = 4;
3553  }
3554  // For chi -> chi q qbar, use V/A -> q qbar as first approximation.
3555  else if (minDauType == 1 && maxDauType == 1 && motherType == 9)
3556  MEkind = 2;
3557 
3558  // q -> q + V.
3559  else if (minDauType == 1 && maxDauType == 7 && motherType == 1)
3560  MEkind = 3;
3561  if (idDau1 == 22 || idDau2 == 22) MEcombi = 1;
3562 
3563  // Scalar/pseudoscalar -> q + qbar; q -> q + S.
3564  else if (minDauType == 1 && maxDauType == 1 && motherType == 8) {
3565  MEkind = 4;
3566  if (idMother == 25 || idMother == 35 || idMother == 37) MEcombi = 1;
3567  else if (idMother == 36) MEcombi = 2;
3568  }
3569  else if (minDauType == 1 && maxDauType == 8 && motherType == 1)
3570  MEkind = 5;
3571 
3572  // V -> ~q + ~qbar; ~q -> ~q + V; S -> ~q + ~qbar; ~q -> ~q + S.
3573  else if (minDauType == 2 && maxDauType == 2 && (motherType == 4
3574  || motherType == 7) ) MEkind = 6;
3575  else if (minDauType == 2 && (maxDauType == 4 || maxDauType == 7)
3576  && motherType == 2) MEkind = 7;
3577  else if (minDauType == 2 && maxDauType == 2 && motherType == 8)
3578  MEkind = 8;
3579  else if (minDauType == 2 && maxDauType == 8 && motherType == 2)
3580  MEkind = 9;
3581 
3582  // chi -> q + ~qbar; ~q -> q + chi; q -> ~q + chi.
3583  else if (minDauType == 1 && maxDauType == 2 && motherType == 9)
3584  MEkind = 10;
3585  else if (minDauType == 1 && maxDauType == 9 && motherType == 2)
3586  MEkind = 11;
3587  else if (minDauType == 2 && maxDauType == 9 && motherType == 1)
3588  MEkind = 12;
3589 
3590  // ~g -> q + ~qbar; ~q -> q + ~g; q -> ~q + ~g.
3591  else if (minDauType == 1 && maxDauType == 2 && motherType == 5)
3592  MEkind = 13;
3593  else if (minDauType == 1 && maxDauType == 5 && motherType == 2)
3594  MEkind = 14;
3595  else if (minDauType == 2 && maxDauType == 5 && motherType == 1)
3596  MEkind = 15;
3597 
3598  // In cases where coloured spin 1 particle involved use spin 0.
3599  // V_coloured -> q + l.
3600  else if (minDauType == 1 && maxDauType == 9 && motherType == 3)
3601  MEkind = 11;
3602  // q -> V_coloured + l;
3603  else if (minDauType == 3 && maxDauType == 9 && motherType == 1)
3604  MEkind = 12;
3605 
3606  // g (+V, S) -> ~g + ~g (eikonal approximation).
3607  else if (minDauType == 5 && maxDauType == 5) MEkind = 16;
3608 
3609  // Save ME type and gamma_5 admixture.
3610  dip.MEtype = 5 * MEkind + MEcombi;
3611 
3612  // Now begin processing of charge dipole - still primitive.
3613  } else if (dip.chgType != 0) {
3614 
3615  // Set defaults for QED case; then possibly done.
3616  dip.MEorder = true;
3617  dip.MEsplit = true;
3618  if (dip.MEtype >= 0) return;
3619 
3620  // So far only ME corrections for q qbar or l lbar.
3621  int idDau1 = event[dip.iRadiator].id();
3622  int idDau2 = event[dip.iMEpartner].id();
3623  if (abs(idDau1) < 9 && abs(idDau2) < 9 && idDau1 * idDau2 < 0) ;
3624  else if (abs(idDau1) > 10 && abs(idDau1) < 19 && abs(idDau2) > 10
3625  && abs(idDau2) < 19 && idDau1 * idDau2 < 0) ;
3626  else { dip.MEtype = 0; return; }
3627 
3628  // Distinguish charge sum != 0 or = 0; in latter assume vector source.
3629  dip.MEtype = 101;
3630  if (idDau1 + idDau2 == 0) dip.MEtype = 102;
3631  dip.MEmix = 1.;
3632  }
3633 
3634  // Identify 2 -> 2 processes for weak corrections.
3635  else if (dip.weakType == 1) {
3636  if (event[dip.iRadiator].id() == -event[dip.iRecoiler].id()
3637  || event[event[dip.iRadiator].mother1()].idAbs() == 24
3638  || infoPtr->nFinal() != 2) dip.MEtype = 200;
3639  else if (event[dip.iRadiator].idAbs() == 21
3640  || event[dip.iRecoiler].idAbs() == 21) dip.MEtype = 201;
3641  else if (event[dip.iRadiator].id() == event[dip.iRecoiler].id())
3642  dip.MEtype = 202;
3643  else dip.MEtype = 203;
3644  } else if (dip.weakType == 2) {
3645  if (event[dip.iRadiator].id() == -event[dip.iRecoiler].id()
3646  || event[event[dip.iRadiator].mother1()].idAbs() == 24) dip.MEtype = 205;
3647  else if (event[dip.iRadiator].idAbs() == 21
3648  || event[dip.iRecoiler].idAbs() == 21) dip.MEtype = 206;
3649  else if (event[dip.iRadiator].id() == event[dip.iRecoiler].id())
3650  dip.MEtype = 207;
3651  else dip.MEtype = 208;
3652  }
3653 
3654 }
3655 
3656 //--------------------------------------------------------------------------
3657 
3658 // Find type of particle for ME type: 0 = unknown, 1 = quark, 2 = squark,
3659 // 3 = spare triplet, 4 = gluon, 5 = gluino, 6 = spare octet,
3660 // 7 = vector boson, 8 = colourless scalar, 9 = colourless spin 1/2.
3661 
3662 int TimeShower::findMEparticle( int id, bool isHiddenColour) {
3663 
3664  // find colour and spin of particle.
3665  int type = 0;
3666  int colType = abs(particleDataPtr->colType(id));
3667  int spinType = particleDataPtr->spinType(id);
3668 
3669  // For hidden valley particle treat HV colour as normal one.
3670  // Note: no need to assign gv/gammav since not in ME.
3671  if (isHiddenColour) {
3672  colType = 0;
3673  int idAbs = abs(id);
3674  if ( (idAbs > 4900000 && idAbs < 4900007)
3675  || (idAbs > 4900010 && idAbs < 4900017)
3676  || idAbs == 4900101) colType = 1;
3677  }
3678 
3679  // Find particle type from colour and spin.
3680  if (colType == 1 && spinType == 2) type = 1;
3681  else if (colType == 1 && spinType == 1) type = 2;
3682  else if (colType == 1) type = 3;
3683  else if (colType == 2 && spinType == 3) type = 4;
3684  else if (colType == 2 && spinType == 2) type = 5;
3685  else if (colType == 2) type = 6;
3686  else if (colType == 0 && spinType == 3) type = 7;
3687  else if (colType == 0 && spinType == 1) type = 8;
3688  else if (colType == 0 && spinType == 2) type = 9;
3689 
3690  // Done.
3691  return type;
3692 
3693 }
3694 
3695 //--------------------------------------------------------------------------
3696 
3697 // Find mixture of V and A in gamma/Z: energy- and flavour-dependent.
3698 
3699 double TimeShower::gammaZmix( Event& event, int iRes, int iDau1, int iDau2) {
3700 
3701  // Try to identify initial flavours; use e+e- as default.
3702  int idIn1 = -11;
3703  int idIn2 = 11;
3704  int iIn1 = (iRes >= 0) ? event[iRes].mother1() : -1;
3705  int iIn2 = (iRes >= 0) ? event[iRes].mother2() : -1;
3706  if (iIn1 >=0) idIn1 = event[iIn1].id();
3707  if (iIn2 >=0) idIn2 = event[iIn1].id();
3708 
3709  // In processes f + g/gamma -> f + Z only need find one fermion.
3710  if (idIn1 == 21 || idIn1 == 22) idIn1 = -idIn2;
3711  if (idIn2 == 21 || idIn2 == 22) idIn2 = -idIn1;
3712 
3713  // Initial flavours and couplings; return if don't make sense.
3714  if (idIn1 + idIn2 != 0 ) return 0.5;
3715  int idInAbs = abs(idIn1);
3716  if (idInAbs == 0 || idInAbs > 18 ) return 0.5;
3717  double ei = coupSMPtr->ef(idInAbs);
3718  double vi = coupSMPtr->vf(idInAbs);
3719  double ai = coupSMPtr->af(idInAbs);
3720 
3721  // Final flavours and couplings; return if don't make sense.
3722  if (event[iDau1].id() + event[iDau2].id() != 0) return 0.5;
3723  int idOutAbs = abs(event[iDau1].id());
3724  if (idOutAbs == 0 || idOutAbs >18 ) return 0.5;
3725  double ef = coupSMPtr->ef(idOutAbs);
3726  double vf = coupSMPtr->vf(idOutAbs);
3727  double af = coupSMPtr->af(idOutAbs);
3728 
3729  // Calculate prefactors for interference and resonance part.
3730  Vec4 psum = event[iDau1].p() + event[iDau2].p();
3731  double sH = psum.m2Calc();
3732  double intNorm = 2. * thetaWRat * sH * (sH - mZ*mZ)
3733  / ( pow2(sH - mZ*mZ) + pow2(sH * gammaZ / mZ) );
3734  double resNorm = pow2(thetaWRat * sH)
3735  / ( pow2(sH - mZ*mZ) + pow2(sH * gammaZ / mZ) );
3736 
3737  // Calculate vector and axial expressions and find mix.
3738  double vect = ei*ei * ef*ef + ei*vi * intNorm * ef*vf
3739  + (vi*vi + ai*ai) * resNorm * vf*vf;
3740  double axiv = (vi*vi + ai*ai) * resNorm * af*af;
3741  return vect / (vect + axiv);
3742 }
3743 
3744 //--------------------------------------------------------------------------
3745 
3746 // Set up to calculate QCD ME correction with calcMEcorr.
3747 // Normally for primary particles, but also from g/gamma -> f fbar.
3748 
3749 double TimeShower::findMEcorr(TimeDipoleEnd* dip, Particle& rad,
3750  Particle& partner, Particle& emt, bool cutEdge) {
3751 
3752  // Initial values and matrix element kind.
3753  double wtME = 1.;
3754  double wtPS = 1.;
3755  int MEkind = dip->MEtype / 5;
3756  int MEcombi = dip->MEtype % 5;
3757 
3758  // Construct ME variables.
3759  Vec4 sum = rad.p() + partner.p() + emt.p();
3760  double eCMME = sum.mCalc();
3761  double x1 = 2. * (sum * rad.p()) / pow2(eCMME);
3762  double x2 = 2. * (sum * partner.p()) / pow2(eCMME);
3763  double r1 = rad.m() / eCMME;
3764  double r2 = partner.m() / eCMME;
3765  double r3 = 0.;
3766 
3767  // Evaluate kinematics for Hidden Valley with massive gamma_v.
3768  double gammavCorr = 1.;
3769  if (dip->colvType != 0 && brokenHVsym) {
3770  r3 = emt.m() / eCMME;
3771  double x3Tmp = 2. - x1 - x2;
3772  gammavCorr = x3Tmp / (x3Tmp - kRad * (x1 + x3Tmp));
3773  // For Q_v Qbar_v pair correct kinematics to common average mass.
3774  if (MEkind == 31) {
3775  double m2Pair = (rad.p() + partner.p()).m2Calc();
3776  double m2Avg = 0.5 * (rad.m2() + partner.m2())
3777  - 0.25 * pow2(rad.m2() - partner.m2()) / m2Pair;
3778  r1 = sqrt(m2Avg) / eCMME;
3779  r2 = r1;
3780  double xShift = 0.5 * (x1 + x2) * (partner.m2() - rad.m2()) / m2Pair;
3781  x1 += xShift;
3782  x2 -= xShift;
3783  }
3784  }
3785 
3786  // Derived ME variables, suitably protected.
3787  double x1minus, x2minus, x3;
3788  if (cutEdge) {
3789  x1minus = max(XMARGIN, 1. + r1*r1 - r2*r2 - x1);
3790  x2minus = max(XMARGIN, 1. + r2*r2 - r1*r1 - x2) ;
3791  x3 = max(XMARGIN, 2. - x1 - x2);
3792  } else {
3793  x1minus = max(XMARGIN*XMARGIN, 1. + r1*r1 - r2*r2 - x1);
3794  x2minus = max(XMARGIN*XMARGIN, 1. + r2*r2 - r1*r1 - x2) ;
3795  x3 = max(XMARGIN*XMARGIN, 2. - x1 - x2);
3796  }
3797 
3798  // Begin processing of QCD dipoles.
3799  if (dip->colType !=0 || dip->colvType != 0) {
3800 
3801  // Evaluate normal ME, for proper order of particles.
3802  if (dip->MEorder) wtME = calcMEcorr(MEkind, MEcombi, dip->MEmix,
3803  x1, x2, r1, r2, r3, cutEdge);
3804  else wtME = calcMEcorr(MEkind, MEcombi, dip->MEmix,
3805  x2, x1, r2, r1, r3, cutEdge);
3806 
3807  // Split up total ME when two radiating particles.
3808  if (dip->MEsplit) wtME = wtME * x1minus / x3;
3809 
3810  // Evaluate shower rate to be compared with.
3811  wtPS = 2. / ( x3 * x2minus );
3812  if (dip->MEgluinoRec) wtPS *= 9./4.;
3813  if (dip->colvType != 0 && brokenHVsym) wtPS *= gammavCorr;
3814 
3815  // For generic charge combination currently only massless expression.
3816  // (Masses included only to respect phase space boundaries.)
3817  } else if (dip->chgType !=0 && dip->MEtype == 101) {
3818  double chg1 = particleDataPtr->charge(rad.id());
3819  double chg2 = particleDataPtr->charge(partner.id());
3820  wtME = (x1*x1 + x2*x2) * pow2( chg1 * x1minus / x3
3821  - chg2 * x2minus / x3 );
3822  wtPS = 2. * ( chg1*chg1 * x1minus / x3 + chg2*chg2 * x2minus / x3 );
3823 
3824  // For flavour neutral system assume vector source and include masses.
3825  } else if (dip->chgType !=0 && dip->MEtype == 102) {
3826  wtME = calcMEcorr(2, 1, dip->MEmix, x1, x2, r1, r2, 0., cutEdge)
3827  * x1minus / x3;
3828  wtPS = 2. / ( x3 * x2minus );
3829  }
3830 
3831  // Weak W and Z emissions, currently using same matrix element.
3832  // The s-channel corrections are handled with simple MEs.
3833  else if (dip->MEtype == 200 || dip->MEtype == 205) {
3834  r3 = emt.m() / eCMME;
3835  wtME = calcMEcorr(32, 1, dip->MEmix, x1, x2, r1, r2, r3, cutEdge)
3836  * x1minus / x3;
3837  wtPS = 8. / (x3 * x2minus);
3838  wtPS *= x3 / (x3 - kRad * (x1 + x3));
3839  }
3840  // The t-channel corrections are handled separately in findMEweak.
3841  else if (dip->MEtype == 201 || dip->MEtype == 202
3842  || dip->MEtype == 203 || dip->MEtype == 205
3843  || dip->MEtype == 206 || dip->MEtype == 207) return 1.;
3844 
3845  // Return ratio of actual ME to assumed PS rate of emission.
3846  if (wtME > wtPS) infoPtr->errorMsg("Warning in TimeShower::findMEcorr: "
3847  "ME weight above PS one");
3848  return wtME / wtPS;
3849 
3850 }
3851 
3852 //--------------------------------------------------------------------------
3853 
3854 // Matrix elements for gluon (or photon) emission from
3855 // a two-body state; to be used by the parton shower routine.
3856 // Here x_i = 2 E_i/E_cm, r_i = m_i/E_cm and
3857 // 1/sigma_0 d(sigma)/d(x_1)d(x_2) = (alpha-strong/2 pi) * C_F * (this),
3858 // i.e. normalization is such that one recovers the familiar
3859 // (x_1^2 + x_2^2)/((1-x_1)*(1-x_2)) for the massless case.
3860 // Coupling structure:
3861 // kind = 1 : eikonal soft-gluon expression (spin-independent)
3862 // = 2 : V -> q qbar (V = vector/axial vector colour singlet)
3863 // = 3 : q -> q V
3864 // = 4 : S -> q qbar (S = scalar/pseudoscalar colour singlet)
3865 // = 5 : q -> q S
3866 // = 6 : V -> ~q ~qbar (~q = squark)
3867 // = 7 : ~q -> ~q V
3868 // = 8 : S -> ~q ~qbar
3869 // = 9 : ~q -> ~q S
3870 // = 10 : chi -> q ~qbar (chi = neutralino/chargino)
3871 // = 11 : ~q -> q chi
3872 // = 12 : q -> ~q chi
3873 // = 13 : ~g -> q ~qbar
3874 // = 14 : ~q -> q ~g
3875 // = 15 : q -> ~q ~g
3876 // = 16 : (9/4)*(eikonal) for gg -> ~g ~g
3877 // = 30 : Dv -> d qv (Dv= hidden valley fermion, qv= valley scalar)
3878 // = 31 : S -> Dv Dvbar (S=scalar color singlet)
3879 // Note that the order of the decay products is important.
3880 // combi = 1 : pure non-gamma5, i.e. vector/scalar/...
3881 // = 2 : pure gamma5, i.e. axial vector/pseudoscalar/....
3882 // = 3 : mixture mix*(combi=1) + (1-mix)*(combi=2)
3883 // = 4 : mixture (combi=1) +- (combi=2)
3884 
3885 double TimeShower::calcMEcorr( int kind, int combiIn, double mixIn,
3886  double x1, double x2, double r1, double r2, double r3, bool cutEdge) {
3887 
3888  // Frequent variable combinations.
3889  double x3 = 2. - x1 - x2;
3890  double x1s = x1 * x1;
3891  double x2s = x2 * x2;
3892  double x3s = x3 * x3;
3893  double x1c = x1 * x1s;
3894  double x2c = x2 * x2s;
3895  double x3c = x3 * x3s;
3896  double r1s = r1 * r1;
3897  double r2s = r2 * r2;
3898  double r1c = r1 * r1s;
3899  double r2c = r2 * r2s;
3900  double r1q = r1s * r1s;
3901  double r2q = r2s * r2s;
3902  double prop1 = 1. + r1s - r2s - x1;
3903  double prop2 = 1. + r2s - r1s - x2;
3904  double prop1s = prop1 * prop1;
3905  double prop2s = prop2 * prop2;
3906  double prop12 = prop1 * prop2;
3907  double prop13 = prop1 * x3;
3908  double prop23 = prop2 * x3;
3909 
3910  // Special case: Hidden-Valley massive photon.
3911  double r3s = r3 * r3;
3912  double prop3 = r3s - x3;
3913  double prop3s = prop3 * prop3;
3914  if (kind == 30) prop13 = prop1 * prop3;
3915 
3916  // Check input values. Return zero outside allowed phase space.
3917  if (cutEdge) {
3918  if (x1 - 2.*r1 < XMARGIN || prop1 < XMARGIN) return 0.;
3919  if (x2 - 2.*r2 < XMARGIN || prop2 < XMARGIN) return 0.;
3920  // Limits not worked out for r3 > 0.
3921  if (kind != 30 && kind != 31) {
3922  if (x1 + x2 - 1. - pow2(r1+r2) < XMARGIN) return 0.;
3923  // Note: equivalent rewritten form 4. * ( (1. - x1) * (1. - x2)
3924  // * (1. - r1s - r2s - x3) + r1s * (1. - x2s - x3) + r2s
3925  // * (1. - x1s - x3) - pow2(r1s - r2s) ) gives about same result.
3926  if ( (x1s - 4.*r1s) * (x2s - 4.*r2s)
3927  - pow2( 2. * (1. - x1 - x2 + r1s + r2s) + x1*x2 )
3928  < XMARGIN * (XMARGINCOMB + r1 + r2) ) return 0.;
3929  }
3930  }
3931 
3932  // Initial values; phase space.
3933  int combi = max(1, min(4, combiIn) );
3934  double mix = max(0., min(1., mixIn) );
3935  bool isSet1 = false;
3936  bool isSet2 = false;
3937  bool isSet4 = false;
3938  double ps = sqrtpos( pow2(1. - r1*r1 - r2*r2) - pow2(2. * r1 * r2) );
3939  double rLO = 0., rFO = 0., rLO1 = 0., rFO1 = 0., rLO2 = 0.,
3940  rFO2 = 0., rLO4 = 0., rFO4 = 0.;
3941  double offset = 0;
3942 
3943  // Select which kind of ME to use.
3944  switch (kind) {
3945 
3946  // case 1 is equal to default, i.e. eikonal expression.
3947 
3948  // V -> q qbar (V = gamma*/Z0/W+-/...).
3949  case 2:
3950  if (combi == 1 || combi == 3) {
3951  rLO1 = ps*(2.-r1s-r1q+6.*r1*r2-r2s+2.*r1s*r2s-r2q)/2.;
3952  rFO1 = -(3.+6.*r1s+r1q-6.*r1*r2+6.*r1c*r2-2.*r2s-6.*r1s*r2s
3953  +6.*r1*r2c+r2q-3.*x1+6.*r1*r2*x1+2.*r2s*x1+x1s-2.*r1s*x1s
3954  +3.*r1s*x3+6.*r1*r2*x3-r2s*x3-2.*x1*x3-5.*r1s*x1*x3
3955  +r2s*x1*x3+x1s*x3-3.*x3s-3.*r1s*x3s+r2s*x3s
3956  +2.*x1*x3s+x3c-x2)
3957  /prop2s
3958  -2.*(-3.+r1s-6.*r1*r2+6.*r1c*r2+3.*r2s-4.*r1s*r2s
3959  +6.*r1*r2c+2.*x1+3.*r1s*x1+r2s*x1-x1s-r1s*x1s
3960  -r2s*x1s+4.*x3+2.*r1s*x3+3.*r1*r2*x3-r2s*x3-3.*x1*x3
3961  -2.*r1s*x1*x3+x1s*x3-x3s-r1s*x3s+r1*r2*x3s+x1*x3s)
3962  /prop12
3963  -(-1.+2.*r1s+r1q+6.*r1*r2+6.*r1c*r2-2.*r2s-6.*r1s*r2s
3964  +6.*r1*r2c+r2q-x1-2.*r1s*x1-6.*r1*r2*x1+8.*r2s*x1+x1s
3965  -2.*r2s*x1s-r1s*x3+r2s*x3-r1s*x1*x3+r2s*x1*x3+x1s*x3+x2)
3966  /prop1s;
3967  rFO1 = rFO1/2.;
3968  isSet1 = true;
3969  }
3970  if (combi == 2 || combi == 3) {
3971  rLO2 = ps*(2.-r1s-r1q-6.*r1*r2-r2s+2.*r1s*r2s-r2q)/2.;
3972  rFO2 = -(3.+6.*r1s+r1q+6.*r1*r2-6.*r1c*r2-2.*r2s-6.*r1s*r2s
3973  -6.*r1*r2c+r2q-3.*x1-6.*r1*r2*x1+2.*r2s*x1+x1s-2.*r1s*x1s
3974  +3.*r1s*x3-6.*r1*r2*x3-r2s*x3-2.*x1*x3-5.*r1s*x1*x3
3975  +r2s*x1*x3+x1s*x3-3.*x3s-3.*r1s*x3s+r2s*x3s+2.*x1*x3s+x3c-x2)
3976  /prop2s
3977  -2.*(-3+r1s+6.*r1*r2-6.*r1c*r2+3.*r2s-4.*r1s*r2s-6.*r1*r2c
3978  +2.*x1+3.*r1s*x1+r2s*x1-x1s-r1s*x1s-r2s*x1s+4.*x3+2.*r1s*x3
3979  -3.*r1*r2*x3-r2s*x3-3.*x1*x3-2.*r1s*x1*x3+x1s*x3-x3s-r1s*x3s
3980  -r1*r2*x3s+x1*x3s)
3981  /prop12
3982  -(-1.+2.*r1s+r1q-6.*r1*r2-6.*r1c*r2-2.*r2s-6.*r1s*r2s
3983  -6.*r1*r2c+r2q-x1-2.*r1s*x1+6.*r1*r2*x1+8.*r2s*x1+x1s
3984  -2.*r2s*x1s-r1s*x3+r2s*x3-r1s*x1*x3+r2s*x1*x3+x1s*x3+x2)
3985  /prop1s;
3986  rFO2 = rFO2/2.;
3987  isSet2 = true;
3988  }
3989  if (combi == 4) {
3990  rLO4 = ps*(2.-r1s-r1q-r2s+2.*r1s*r2s-r2q)/2.;
3991  rFO4 = (1.-r1q+6.*r1s*r2s-r2q+x1+3.*r1s*x1-9.*r2s*x1-3.*x1s
3992  -r1s*x1s+3.*r2s*x1s+x1c-x2-r1s*x2+r2s*x2-r1s*x1*x2+r2s*x1*x2
3993  +x1s*x2)
3994  /prop1s
3995  -2.*(1.+r1s+r2s-4.*r1s*r2s+r1s*x1+2.*r2s*x1-x1s-r2s*x1s
3996  +2.*r1s*x2+r2s*x2-3.*x1*x2+x1s*x2-x2s-r1s*x2s+x1*x2s)
3997  /prop12
3998  +(1.-r1q+6.*r1s*r2s-r2q-x1+r1s*x1-r2s*x1+x2-9.*r1s*x2
3999  +3.*r2s*x2+r1s*x1*x2-r2s*x1*x2-3.*x2s+3.*r1s*x2s-r2s*x2s
4000  +x1*x2s+x2c)
4001  /prop2s;
4002  rFO4 = rFO4/2.;
4003  isSet4 = true;
4004  }
4005  break;
4006 
4007  // q -> q V.
4008  case 3:
4009  if (combi == 1 || combi == 3) {
4010  rLO1 = ps*(1.-2.*r1s+r1q+r2s-6.*r1*r2s+r1s*r2s-2.*r2q);
4011  rFO1 = -2.*(-1.+r1-2.*r1s+2.*r1c-r1q+pow5(r1)-r2s+r1*r2s
4012  -5.*r1s*r2s+r1c*r2s-2.*r1*r2q+2.*x1-2.*r1*x1+2.*r1s*x1
4013  -2.*r1c*x1+2.*r2s*x1+5.*r1*r2s*x1+r1s*r2s*x1+2.*r2q*x1
4014  -x1s+r1*x1s-r2s*x1s+3.*x2+4.*r1s*x2+r1q*x2+2.*r2s*x2
4015  +2.*r1s*r2s*x2-4.*x1*x2-2.*r1s*x1*x2-r2s*x1*x2+x1s*x2
4016  -2.*x2s-2.*r1s*x2s+x1*x2s)
4017  /prop23
4018  +(2.*r2s+6.*r1*r2s-6.*r1s*r2s+6.*r1c*r2s+2.*r2q+6.*r1*r2q
4019  -r2s*x1+r1s*r2s*x1-r2q*x1+x2-r1q*x2-3.*r2s*x2-6.*r1*r2s*x2
4020  +9.*r1s*r2s*x2-2.*r2q*x2-x1*x2+r1s*x1*x2-x2s-3.*r1s*x2s
4021  +2.*r2s*x2s+x1*x2s)
4022  /prop2s
4023  +(-4.-8.*r1s-4.*r1q+4.*r2s-4.*r1s*r2s+8.*r2q+9.*x1+10.*r1s*x1
4024  +r1q*x1-3.*r2s*x1+6.*r1*r2s*x1+r1s*r2s*x1-2.*r2q*x1-6.*x1s-
4025  2.*r1s*x1s+x1c+7.*x2+8.*r1s*x2+r1q*x2-7.*r2s*x2+6.*r1*r2s*x2
4026  +r1s*r2s*x2-2.*r2q*x2-9.*x1*x2-3.*r1s*x1*x2+2.*r2s*x1*x2
4027  +2.*x1s*x2-3.*x2s-r1s*x2s+2.*r2s*x2s+x1*x2s)
4028  /x3s;
4029  isSet1 = true;
4030  }
4031  if (combi == 2 || combi == 3) {
4032  rLO2 = ps*(1.-2.*r1s+r1q+r2s+6.*r1*r2s+r1s*r2s-2.*r2q);
4033  rFO2 = 2*(1.+r1+2.*r1s+2.*r1c+r1q+pow5(r1)+r2s+r1*r2s
4034  +5.*r1s*r2s+r1c*r2s-2.*r1*r2q-2.*x1-2.*r1*x1-2.*r1s*x1
4035  -2.*r1c*x1-2.*r2s*x1+5.*r1*r2s*x1-r1s*r2s*x1-2.*r2q*x1+x1s
4036  +r1*x1s+r2s*x1s-3.*x2-4.*r1s*x2-r1q*x2-2.*r2s*x2
4037  -2.*r1s*r2s*x2+4.*x1*x2+2.*r1s*x1*x2+r2s*x1*x2-x1s*x2
4038  +2.*x2s+2.*r1s*x2s-x1*x2s)
4039  /prop23
4040  +(2.*r2s-6.*r1*r2s-6.*r1s*r2s-6.*r1c*r2s+2.*r2q-6.*r1*r2q
4041  -r2s*x1+r1s*r2s*x1-r2q*x1+x2-r1q*x2-3.*r2s*x2+6.*r1*r2s*x2
4042  +9.*r1s*r2s*x2-2.*r2q*x2-x1*x2+r1s*x1*x2-x2s-3.*r1s*x2s
4043  +2.*r2s*x2s+x1*x2s)
4044  /prop2s
4045  +(-4.-8.*r1s-4.*r1q+4.*r2s-4.*r1s*r2s+8.*r2q+9.*x1+10.*r1s*x1
4046  +r1q*x1-3.*r2s*x1-6.*r1*r2s*x1+r1s*r2s*x1-2.*r2q*x1-6.*x1s
4047  -2.*r1s*x1s+x1c+7.*x2+8.*r1s*x2+r1q*x2-7.*r2s*x2-6.*r1*r2s*x2
4048  +r1s*r2s*x2-2.*r2q*x2-9.*x1*x2-3.*r1s*x1*x2+2.*r2s*x1*x2
4049  +2.*x1s*x2-3.*x2s-r1s*x2s+2.*r2s*x2s+x1*x2s)
4050  /x3s;
4051  isSet2 = true;
4052  }
4053  if (combi == 4) {
4054  rLO4 = ps*(1.-2.*r1s+r1q+r2s+r1s*r2s-2.*r2q);
4055  rFO4 = 2*(1.+2.*r1s+r1q+r2s+5.*r1s*r2s-2.*x1-2.*r1s*x1
4056  -2.*r2s*x1-r1s*r2s*x1-2.*r2q*x1+x1s+r2s*x1s-3.*x2-4.*r1s*x2
4057  -r1q*x2-2.*r2s*x2-2.*r1s*r2s*x2+4.*x1*x2+2.*r1s*x1*x2+r2s*x1*x2
4058  -x1s*x2+2.*x2s+2.*r1s*x2s-x1*x2s)
4059  /prop23
4060  +(2.*r2s-6.*r1s*r2s+2.*r2q-r2s*x1+r1s*r2s*x1-r2q*x1+x2-r1q*x2
4061  -3.*r2s*x2+9.*r1s*r2s*x2-2.*r2q*x2-x1*x2+r1s*x1*x2-x2s-3.*r1s*x2s
4062  +2.*r2s*x2s+x1*x2s)
4063  /prop2s
4064  +(-4.-8.*r1s-4.*r1q+4.*r2s-4.*r1s*r2s+8.*r2q+9.*x1+10.*r1s*x1
4065  +r1q*x1-3.*r2s*x1+r1s*r2s*x1-2.*r2q*x1-6.*x1s-2.*r1s*x1s+x1c
4066  +7.*x2+8.*r1s*x2+r1q*x2-7.*r2s*x2+r1s*r2s*x2-2.*r2q*x2-9.*x1*x2
4067  -3.*r1s*x1*x2+2.*r2s*x1*x2+2.*x1s*x2-3.*x2s-r1s*x2s+2.*r2s*x2s
4068  +x1*x2s)
4069  /x3s;
4070  isSet4 = true;
4071  }
4072  break;
4073 
4074  // S -> q qbar (S = h0/H0/A0/H+-/...).
4075  case 4:
4076  if (combi == 1 || combi == 3) {
4077  rLO1 = ps*(1.-r1s-r2s-2.*r1*r2);
4078  rFO1 = -(-1.+r1q-2.*r1*r2-2.*r1c*r2-6.*r1s*r2s-2.*r1*r2c+r2q+x1
4079  -r1s*x1+2.*r1*r2*x1+3.*r2s*x1+x2+r1s*x2-r2s*x2-x1*x2)
4080  /prop1s
4081  -2.*(r1s+r1q-2.*r1c*r2+r2s-6.*r1s*r2s-2.*r1*r2c+r2q-r1s*x1
4082  +r1*r2*x1+2.*r2s*x1+2.*r1s*x2+r1*r2*x2-r2s*x2-x1*x2)
4083  /prop12
4084  -(-1.+r1q-2.*r1*r2-2.*r1c*r2-6.*r1s*r2s-2.*r1*r2c+r2q+x1-r1s*x1
4085  +r2s*x1+x2+3.*r1s*x2+2.*r1*r2*x2-r2s*x2-x1*x2)
4086  /prop2s;
4087  isSet1 = true;
4088  }
4089  if (combi == 2 || combi == 3) {
4090  rLO2 = ps*(1.-r1s-r2s+2.*r1*r2);
4091  rFO2 = -(-1.+r1q+2.*r1*r2+2.*r1c*r2-6.*r1s*r2s+2.*r1*r2c+r2q+x1
4092  -r1s*x1-2.*r1*r2*x1+3.*r2s*x1+x2+r1s*x2-r2s*x2-x1*x2)
4093  /prop1s
4094  -(-1.+r1q+2.*r1*r2+2.*r1c*r2-6.*r1s*r2s+2.*r1*r2c+r2q+x1
4095  -r1s*x1+r2s*x1+x2+3.*r1s*x2-2.*r1*r2*x2-r2s*x2-x1*x2)
4096  /prop2s
4097  +2.*(-r1s-r1q-2.*r1c*r2-r2s+6.*r1s*r2s-2.*r1*r2c-r2q+r1s*x1
4098  +r1*r2*x1-2.*r2s*x1-2.*r1s*x2+r1*r2*x2+r2s*x2+x1*x2)
4099  /prop12;
4100  isSet2 = true;
4101  }
4102  if (combi == 4) {
4103  rLO4 = ps*(1.-r1s-r2s);
4104  rFO4 = -(-1.+r1q-6.*r1s*r2s+r2q+x1-r1s*x1+3.*r2s*x1+x2
4105  +r1s*x2-r2s*x2-x1*x2)
4106  /prop1s
4107  -2.*(r1s+r1q+r2s-6.*r1s*r2s+r2q-r1s*x1
4108  +2.*r2s*x1+2.*r1s*x2-r2s*x2-x1*x2)
4109  /prop12
4110  -(-1.+r1q-6.*r1s*r2s+r2q+x1-r1s*x1+r2s*x1
4111  +x2+3.*r1s*x2-r2s*x2-x1*x2)
4112  /prop2s;
4113  isSet4 = true;
4114  }
4115  break;
4116 
4117  // q -> q S.
4118  case 5:
4119  if (combi == 1 || combi == 3) {
4120  rLO1 = ps*(1.+r1s-r2s+2.*r1);
4121  rFO1 = (4.-4.*r1s+4.*r2s-3.*x1-2.*r1*x1+r1s*x1-r2s*x1-5.*x2
4122  -2.*r1*x2+r1s*x2-r2s*x2+x1*x2+x2s)
4123  /x3s
4124  -2.*(3.-r1-5.*r1s-r1c+3.*r2s+r1*r2s-2.*x1-r1*x1
4125  +r1s*x1-4.*x2+2.*r1s*x2-r2s*x2+x1*x2+x2s)
4126  /prop23
4127  +(2.-2.*r1-6.*r1s-2.*r1c+2.*r2s-2.*r1*r2s-x1+r1s*x1
4128  -r2s*x1-3.*x2+2.*r1*x2+3.*r1s*x2-r2s*x2+x1*x2+x2s)
4129  /prop2s;
4130  isSet1 = true;
4131  }
4132  if (combi == 2 || combi == 3) {
4133  rLO2 = ps*(1.+r1s-r2s-2.*r1);
4134  rFO2 = (4.-4.*r1s+4.*r2s-3.*x1+2.*r1*x1+r1s*x1-r2s*x1-5.*x2
4135  +2.*r1*x2+r1s*x2-r2s*x2+x1*x2+x2s)
4136  /x3s
4137  -2.*(3.+r1-5.*r1s+r1c+3.*r2s-r1*r2s-2.*x1+r1*x1
4138  +r1s*x1-4.*x2+2.*r1s*x2-r2s*x2+x1*x2+x2s)
4139  /prop23
4140  +(2.+2.*r1-6.*r1s+2.*r1c+2.*r2s+2.*r1*r2s-x1+r1s*x1
4141  -r2s*x1-3.*x2-2.*r1*x2+3.*r1s*x2-r2s*x2+x1*x2+x2s)
4142  /prop2s;
4143  isSet2 = true;
4144  }
4145  if (combi == 4) {
4146  rLO4 = ps*(1.+r1s-r2s);
4147  rFO4 = (4.-4.*r1s+4.*r2s-3.*x1+r1s*x1-r2s*x1-5.*x2+r1s*x2
4148  -r2s*x2+x1*x2+x2s)
4149  /x3s
4150  -2.*(3.-5.*r1s+3.*r2s-2.*x1+r1s*x1-4.*x2+2.*r1s*x2
4151  -r2s*x2+x1*x2+x2s)
4152  /prop23
4153  +(2.-6.*r1s+2.*r2s-x1+r1s*x1-r2s*x1-3.*x2+3.*r1s*x2
4154  -r2s*x2+x1*x2+x2s)
4155  /prop2s;
4156  isSet4 = true;
4157  }
4158  break;
4159 
4160  // V -> ~q ~qbar (~q = squark).
4161  case 6:
4162  rLO1 = ps*(1.-2.*r1s+r1q-2.*r2s-2.*r1s*r2s+r2q);
4163  rFO1 = 2.*3.+(1.+r1s+r2s-x1)*(4.*r1s-x1s)
4164  /prop1s
4165  +2.*(-1.-3.*r1s-r2s+x1+x1s*0.5+x2-x1*x2*0.5)
4166  /prop1
4167  +(1.+r1s+r2s-x2)*(4.*r2s-x2s)
4168  /prop2s
4169  +2.*(-1.-r1s-3.*r2s+x1+x2-x1*x2*0.5+x2s*0.5)
4170  /prop2
4171  -(-4.*r1s-4.*r1q-4.*r2s-8.*r1s*r2s-4.*r2q+2.*x1+6.*r1s*x1
4172  +6.*r2s*x1-2.*x1s+2.*x2+6.*r1s*x2+6.*r2s*x2-4.*x1*x2
4173  -2.*r1s*x1*x2-2.*r2s*x1*x2+x1s*x2-2.*x2s+x1*x2s)
4174  /prop12;
4175  isSet1 = true;
4176  break;
4177 
4178  // ~q -> ~q V.
4179  case 7:
4180  rLO1 = ps*(1.-2.*r1s+r1q-2.*r2s-2.*r1s*r2s+r2q);
4181  rFO1 = 16.*r2s-8.*(4.*r2s+2.*r2s*x1+x2+r1s*x2+r2s*x2-x1*x2
4182  -2.*x2s)
4183  /(3.*prop2)
4184  +8.*(1.+r1s+r2s-x2)*(4.*r2s-x2s)
4185  /(3.*prop2s)
4186  +8.*(x1+x2)*(-1.-2.*r1s-r1q-2.*r2s+2.*r1s*r2s-r2q+2.*x1
4187  +2.*r1s*x1+2.*r2s*x1-x1s+2.*x2+2.*r1s*x2+2.*r2s*x2-2.*x1*x2-x2s)
4188  /(3.*x3s)
4189  +8.*(-1.-r1s+r2s-x1)*(2.*r2s*x1+x2+r1s*x2+r2s*x2-x1*x2-x2s)
4190  /(3.*prop2*x3)
4191  -8.*(1.+2.*r1s+r1q+2.*r2s-2.*r1s*r2s+r2q-2.*x1-2.*r1s*x1
4192  -4.*r2s*x1+x1s-3.*x2-3.*r1s*x2-3.*r2s*x2+3.*x1*x2+2.*x2s)
4193  /(3.*x3);
4194  rFO1 = 3.*rFO1/8.;
4195  isSet1 = true;
4196  break;
4197 
4198  // S -> ~q ~qbar.
4199  case 8:
4200  rLO1 = ps;
4201  rFO1 = (-1.-2.*r1s-r1q-2.*r2s+2.*r1s*r2s-r2q+2.*x1+2.*r1s*x1
4202  +2.*r2s*x1-x1s-r2s*x1s+2.*x2+2.*r1s*x2+2.*r2s*x2-3.*x1*x2
4203  -r1s*x1*x2-r2s*x1*x2+x1s*x2-x2s-r1s*x2s+x1*x2s)
4204  /(prop1s*prop2s);
4205  rFO1 = 2.*rFO1;
4206  isSet1 = true;
4207  break;
4208 
4209  // ~q -> ~q S.
4210  case 9:
4211  rLO1 = ps;
4212  rFO1 = (-1.-r1s-r2s+x2)
4213  /prop2s
4214  +(1.+r1s-r2s+x1)
4215  /prop23
4216  -(x1+x2)
4217  /x3s;
4218  isSet1 = true;
4219  break;
4220 
4221  // chi -> q ~qbar (chi = neutralino/chargino).
4222  case 10:
4223  if (combi == 1 || combi == 3) {
4224  rLO1 = ps*(1.+r1s-r2s+2.*r1);
4225  rFO1 = (2.*r1+x1)*(-1.-r1s-r2s+x1)
4226  /prop1s
4227  +2.*(-1.-r1s-2.*r1c-r2s-2.*r1*r2s+3.*x1*0.5+r1*x1
4228  -r1s*x1*0.5-r2s*x1*0.5+x2+r1*x2+r1s*x2-x1*x2*0.5)
4229  /prop12
4230  +(2.-2.*r1-6.*r1s-2.*r1c+2.*r2s-2.*r1*r2s-x1+r1s*x1
4231  -r2s*x1-3.*x2+2.*r1*x2+3.*r1s*x2-r2s*x2+x1*x2+x2s)
4232  /prop2s;
4233  isSet1 = true;
4234  }
4235  if (combi == 2 || combi == 3) {
4236  rLO2 = ps*(1.-2.*r1+r1s-r2s);
4237  rFO2 = (2.*r1-x1)*(1.+r1s+r2s-x1)
4238  /prop1s
4239  +2.*(-1.-r1s+2.*r1c-r2s+2.*r1*r2s+3.*x1*0.5-r1*x1
4240  -r1s*x1*0.5-r2s*x1*0.5+x2-r1*x2+r1s*x2-x1*x2*0.5)
4241  /prop12
4242  +(2.+2.*r1-6.*r1s+2.*r1c+2.*r2s+2.*r1*r2s-x1+r1s*x1
4243  -r2s*x1-3.*x2-2.*r1*x2+3.*r1s*x2-r2s*x2+x1*x2+x2s)/
4244  prop2s;
4245  isSet2 = true;
4246  }
4247  if (combi == 4) {
4248  rLO4 = ps*(1.+r1s-r2s);
4249  rFO4 = x1*(-1.-r1s-r2s+x1)
4250  /prop1s
4251  +2.*(-1.-r1s-r2s+3.*x1*0.5-r1s*x1*0.5-r2s*x1*0.5
4252  +x2+r1s*x2-x1*x2*0.5)
4253  /prop12
4254  +(2.-6.*r1s+2.*r2s-x1+r1s*x1-r2s*x1-3.*x2+3.*r1s*x2
4255  -r2s*x2+x1*x2+x2s)
4256  /prop2s;
4257  isSet4 = true;
4258  }
4259  break;
4260 
4261  // ~q -> q chi.
4262  case 11:
4263  if (combi == 1 || combi == 3) {
4264  rLO1 = ps*(1.-pow2(r1+r2));
4265  rFO1 = (1.+r1s+2.*r1*r2+r2s-x1-x2)*(x1+x2)
4266  /x3s
4267  -(-1.+r1q-2.*r1*r2-2.*r1c*r2-6.*r1s*r2s-2.*r1*r2c+r2q+x1
4268  -r1s*x1+r2s*x1+x2+3.*r1s*x2+2.*r1*r2*x2-r2s*x2-x1*x2)
4269  /prop2s
4270  +(-1.-2.*r1s-r1q-2.*r1*r2-2.*r1c*r2+2.*r1*r2c+r2q+x1+r1s*x1
4271  -2.*r1*r2*x1-3.*r2s*x1+2.*r1s*x2-2.*r2s*x2+x1*x2+x2s)
4272  /prop23;
4273  isSet1 = true;
4274  }
4275  if (combi == 2 || combi == 3) {
4276  rLO2 = ps*(1.-pow2(r1-r2));
4277  rFO2 = (1.+r1s-2.*r1*r2+r2s-x1-x2)*(x1+x2)
4278  /x3s
4279  -(-1.+r1q+2.*r1*r2+2.*r1c*r2-6.*r1s*r2s+2.*r1*r2c+r2q+x1
4280  -r1s*x1+r2s*x1+x2+3.*r1s*x2-2.*r1*r2*x2-r2s*x2-x1*x2)
4281  /prop2s
4282  +(-1.-2.*r1s-r1q+2.*r1*r2+2.*r1c*r2-2.*r1*r2c+r2q+x1+r1s*x1
4283  +2.*r1*r2*x1-3.*r2s*x1+2.*r1s*x2-2.*r2s*x2+x1*x2+x2s)
4284  /prop23;
4285  isSet2 = true;
4286  }
4287  if (combi == 4) {
4288  rLO4 = ps*(1.-r1s-r2s);
4289  rFO4 = (1.+r1s+r2s-x1-x2)*(x1+x2)
4290  /x3s
4291  -(-1.+r1q-6.*r1s*r2s+r2q+x1-r1s*x1+r2s*x1+x2
4292  +3.*r1s*x2-r2s*x2-x1*x2)
4293  /prop2s
4294  +(-1.-2.*r1s-r1q+r2q+x1+r1s*x1-3.*r2s*x1
4295  +2.*r1s*x2-2.*r2s*x2+x1*x2+x2s)
4296  /prop23;
4297  isSet4 = true;
4298  }
4299  break;
4300 
4301  // q -> ~q chi.
4302  case 12:
4303  if (combi == 1 || combi == 3) {
4304  rLO1 = ps*(1.-r1s+r2s+2.*r2);
4305  rFO1 = (2.*r2+x2)*(-1.-r1s-r2s+x2)
4306  /prop2s
4307  +(4.+4.*r1s-4.*r2s-5.*x1-r1s*x1-2.*r2*x1+r2s*x1+x1s
4308  -3.*x2-r1s*x2-2.*r2*x2+r2s*x2+x1*x2)
4309  /x3s
4310  +2.*(-1.-r1s+r2+r1s*r2-r2s-r2c+x1+r2*x1+r2s*x1+2.*x2
4311  +r1s*x2-x1*x2*0.5-x2s*0.5)
4312  /prop23;
4313  isSet1 = true;
4314  }
4315  if (combi == 2 || combi == 3) {
4316  rLO2 = ps*(1.-r1s+r2s-2.*r2);
4317  rFO2 = (2.*r2-x2)*(1.+r1s+r2s-x2)
4318  /prop2s
4319  +(4.+4.*r1s-4.*r2s-5.*x1-r1s*x1+2.*r2*x1+r2s*x1+x1s
4320  -3.*x2-r1s*x2+2.*r2*x2+r2s*x2+x1*x2)
4321  /x3s
4322  +2.*(-1.-r1s-r2-r1s*r2-r2s+r2c+x1-r2*x1+r2s*x1+2.*x2
4323  +r1s*x2-x1*x2*0.5-x2s*0.5)
4324  /prop23;
4325  isSet2 = true;
4326  }
4327  if (combi == 4) {
4328  rLO4 = ps*(1.-r1s+r2s);
4329  rFO4 = x2*(-1.-r1s-r2s+x2)
4330  /prop2s
4331  +(4.+4.*r1s-4.*r2s-5.*x1-r1s*x1+r2s*x1+x1s
4332  -3.*x2-r1s*x2+r2s*x2+x1*x2)
4333  /x3s
4334  +2.*(-1.-r1s-r2s+x1+r2s*x1+2.*x2
4335  +r1s*x2-x1*x2*0.5-x2s*0.5)
4336  /prop23;
4337  isSet4 = true;
4338  }
4339  break;
4340 
4341  // ~g -> q ~qbar.
4342  case 13:
4343  if (combi == 1 || combi == 3) {
4344  rLO1 = ps*(1.+r1s-r2s+2.*r1);
4345  rFO1 = 4.*(2.*r1+x1)*(-1.-r1s-r2s+x1)
4346  /(3.*prop1s)
4347  -(-1.-r1s-2.*r1c-r2s-2.*r1*r2s+3.*x1*0.5+r1*x1-r1s*x1*0.5
4348  -r2s*x1*0.5+x2+r1*x2+r1s*x2-x1*x2*0.5)
4349  /(3.*prop12)
4350  +3.*(-1.+r1-r1s-r1c-r2s+r1*r2s+2.*x1+r2s*x1-x1s*0.5+x2+r1*x2
4351  +r1s*x2-x1*x2*0.5)
4352  /prop13
4353  +3.*(4.-4.*r1s+4.*r2s-3.*x1-2.*r1*x1+r1s*x1-r2s*x1-5.*x2
4354  -2.*r1*x2+r1s*x2-r2s*x2+x1*x2+x2s)
4355  /x3s
4356  -3.*(3.-r1-5.*r1s-r1c+3.*r2s+r1*r2s-2.*x1-r1*x1+r1s*x1
4357  -4.*x2+2.*r1s*x2-r2s*x2+x1*x2+x2s)
4358  /prop23
4359  +4.*(2.-2.*r1-6.*r1s-2.*r1c+2.*r2s-2.*r1*r2s-x1+r1s*x1-r2s*x1
4360  -3.*x2+2.*r1*x2+3.*r1s*x2-r2s*x2+x1*x2+x2s)
4361  /(3.*prop2s);
4362  rFO1 = 3.*rFO1/4.;
4363  isSet1 = true;
4364  }
4365  if (combi == 2 || combi == 3) {
4366  rLO2 = ps*(1.+r1s-r2s-2.*r1);
4367  rFO2 = 4.*(2.*r1-x1)*(1.+r1s+r2s-x1)
4368  /(3.*prop1s)
4369  +3.*(-1.-r1-r1s+r1c-r2s-r1*r2s+2.*x1+r2s*x1-x1s*0.5
4370  +x2-r1*x2+r1s*x2-x1*x2*0.5)
4371  /prop13
4372  +(2.+2.*r1s-4.*r1c+2.*r2s-4.*r1*r2s-3.*x1+2.*r1*x1
4373  +r1s*x1+r2s*x1-2.*x2+2.*r1*x2-2.*r1s*x2+x1*x2)
4374  /(6.*prop12)
4375  +3.*(4.-4.*r1s+4.*r2s-3.*x1+2.*r1*x1+r1s*x1-r2s*x1-5.*x2
4376  +2.*r1*x2+r1s*x2-r2s*x2+x1*x2+x2s)
4377  /x3s
4378  -3.*(3.+r1-5.*r1s+r1c+3.*r2s-r1*r2s-2.*x1+r1*x1+r1s*x1-4.*x2
4379  +2.*r1s*x2-r2s*x2+x1*x2+x2s)
4380  /prop23
4381  +4.*(2.+2.*r1-6.*r1s+2.*r1c+2.*r2s+2.*r1*r2s-x1+r1s*x1-r2s*x1
4382  -3.*x2-2.*r1*x2+3.*r1s*x2-r2s*x2+x1*x2+x2s)
4383  /(3.*prop2s);
4384  rFO2 = 3.*rFO2/4.;
4385  isSet2 = true;
4386  }
4387  if (combi == 4) {
4388  rLO4 = ps*(1.+r1s-r2s);
4389  rFO4 = 8.*x1*(-1.-r1s-r2s+x1)
4390  /(3.*prop1s)
4391  +6.*(-1-r1s-r2s+2.*x1+r2s*x1-x1s*0.5+x2+r1s*x2-x1*x2*0.5)
4392  /prop13
4393  +(2.+2.*r1s+2.*r2s-3.*x1+r1s*x1+r2s*x1-2.*x2-2.*r1s*x2+x1*x2)
4394  /(3.*prop12)
4395  +6.*(4.-4.*r1s+4.*r2s-3.*x1+r1s*x1-r2s*x1-5.*x2+r1s*x2-r2s*x2
4396  +x1*x2+x2s)
4397  /x3s
4398  -6.*(3.-5.*r1s+3.*r2s-2.*x1+r1s*x1-4.*x2+2.*r1s*x2-r2s*x2+x1*x2+x2s)
4399  /prop23
4400  +8.*(2.-6.*r1s+2.*r2s-x1+r1s*x1-r2s*x1-3.*x2+3.*r1s*x2-r2s*x2
4401  +x1*x2+x2s)
4402  /(3.*prop2s);
4403  rFO4 = 3.*rFO4/8.;
4404  isSet4 = true;
4405  }
4406  break;
4407 
4408  // ~q -> q ~g.
4409  case 14:
4410  if (combi == 1 || combi == 3) {
4411  rLO1 = ps*(1.-r1s-r2s-2.*r1*r2);
4412  rFO1 = 64.*(1.+r1s+2.*r1*r2+r2s-x1-x2)*(x1+x2)
4413  /(9.*x3s)
4414  -16.*(-1.+r1q-2.*r1*r2-2.*r1c*r2-6.*r1s*r2s-2.*r1*r2c+r2q
4415  +x1-r1s*x1+2.*r1*r2*x1+3.*r2s*x1+x2+r1s*x2-r2s*x2-x1*x2)
4416  /prop1s
4417  -16.*(r1s+r1q-2.*r1c*r2+r2s-6.*r1s*r2s-2.*r1*r2c+r2q-r1s*x1
4418  +r1*r2*x1+2.*r2s*x1+2.*r1s*x2+r1*r2*x2-r2s*x2-x1*x2)
4419  /prop12
4420  -64.*(-1.+r1q-2.*r1*r2-2.*r1c*r2-6.*r1s*r2s-2.*r1*r2c+r2q+x1
4421  -r1s*x1+r2s*x1+x2+3.*r1s*x2+2.*r1*r2*x2-r2s*x2-x1*x2)
4422  /(9.*prop2s)
4423  +8.*(-1.+r1q-2.*r1*r2+2.*r1c*r2-2.*r2s-2.*r1*r2c-r2q-2.*r1s*x1
4424  +2.*r2s*x1+x1s+x2-3.*r1s*x2-2.*r1*r2*x2+r2s*x2+x1*x2)
4425  /prop13
4426  -8.*(-1.-2.*r1s-r1q-2.*r1*r2-2.*r1c*r2+2.*r1*r2c+r2q+x1+r1s*x1
4427  -2.*r1*r2*x1-3.*r2s*x1+2.*r1s*x2-2.*r2s*x2+x1*x2+x2s)
4428  /(9.*prop23);
4429  rFO1 = 9.*rFO1/64.;
4430  isSet1 = true;
4431  }
4432  if (combi == 2 || combi == 3) {
4433  rLO2 = ps*(1.-r1s-r2s+2.*r1*r2);
4434  rFO2 = 64.*(1.+r1s-2.*r1*r2+r2s-x1-x2)*(x1+x2)
4435  /(9.*x3s)
4436  -16.*(-1.+r1q+2.*r1*r2+2.*r1c*r2-6.*r1s*r2s+2.*r1*r2c+r2q+x1
4437  -r1s*x1-2.*r1*r2*x1+3.*r2s*x1+x2+r1s*x2-r2s*x2-x1*x2)
4438  /prop1s
4439  -64.*(-1.+r1q+2.*r1*r2+2.*r1c*r2-6.*r1s*r2s+2.*r1*r2c+r2q+x1
4440  -r1s*x1+r2s*x1+x2+3.*r1s*x2-2.*r1*r2*x2-r2s*x2-x1*x2)
4441  /(9.*prop2s)
4442  +16.*(-r1s-r1q-2.*r1c*r2-r2s+6.*r1s*r2s-2.*r1*r2c-r2q+r1s*x1
4443  +r1*r2*x1-2.*r2s*x1-2.*r1s*x2+r1*r2*x2+r2s*x2+x1*x2)
4444  /prop12
4445  +8.*(-1.+r1q+2.*r1*r2-2.*r1c*r2-2.*r2s+2.*r1*r2c-r2q-2.*r1s*x1
4446  +2.*r2s*x1+x1s+x2-3.*r1s*x2+2.*r1*r2*x2+r2s*x2+x1*x2)
4447  /prop13
4448  -8.*(-1.-2.*r1s-r1q+2.*r1*r2+2.*r1c*r2-2.*r1*r2c+r2q+x1+r1s*x1+
4449  2.*r1*r2*x1-3.*r2s*x1+2.*r1s*x2-2.*r2s*x2+x1*x2+x2s)
4450  /(9.*prop23);
4451  rFO2 = 9.*rFO2/64.;
4452  isSet2 = true;
4453  }
4454  if (combi == 4) {
4455  rLO4 = ps*(1.-r1s-r2s);
4456  rFO4 = 128.*(1.+r1s+r2s-x1-x2)*(x1+x2)
4457  /(9.*x3s)
4458  -32*(-1.+r1q-6.*r1s*r2s+r2q+x1-r1s*x1+3.*r2s*x1+x2
4459  +r1s*x2-r2s*x2-x1*x2)
4460  /prop1s
4461  -32.*(r1s+r1q+r2s-6.*r1s*r2s+r2q-r1s*x1+2.*r2s*x1+2.*r1s*x2
4462  -r2s*x2-x1*x2)
4463  /prop12
4464  -128.*(-1.+r1q-6.*r1s*r2s+r2q+x1-r1s*x1+r2s*x1+x2+3.*r1s*x2
4465  -r2s*x2-x1*x2)
4466  /(9.*prop2s)
4467  +16.*(-1.+r1q-2.*r2s-r2q-2.*r1s*x1+2.*r2s*x1+x1s
4468  +x2-3.*r1s*x2+r2s*x2+x1*x2)
4469  /prop13
4470  -16.*(-1.-2.*r1s-r1q+r2q+x1+r1s*x1-3.*r2s*x1
4471  +2.*r1s*x2-2.*r2s*x2+x1*x2+x2s)
4472  /(9.*prop23);
4473  rFO4 = 9.*rFO4/128.;
4474  isSet4 = true;
4475  }
4476  break;
4477 
4478  // q -> ~q ~g.
4479  case 15:
4480  if (combi == 1 || combi == 3) {
4481  rLO1 = ps*(1.-r1s+r2s+2.*r2);
4482  rFO1 = 32*(2.*r2+x2)*(-1.-r1s-r2s+x2)
4483  /(9.*prop2s)
4484  +8.*(-1.-r1s-2.*r1s*r2-r2s-2.*r2c+x1+r2*x1+r2s*x1
4485  +3.*x2*0.5-r1s*x2*0.5+r2*x2-r2s*x2*0.5-x1*x2*0.5)
4486  /prop12
4487  +8.*(2.+2.*r1s-2.*r2-2.*r1s*r2-6.*r2s-2.*r2c-3.*x1-r1s*x1
4488  +2.*r2*x1+3.*r2s*x1+x1s-x2-r1s*x2+r2s*x2+x1*x2)
4489  /prop1s
4490  +32.*(4.+4.*r1s-4.*r2s-5.*x1-r1s*x1-2.*r2*x1+r2s*x1+x1s
4491  -3.*x2-r1s*x2-2.*r2*x2+r2s*x2+x1*x2)
4492  /(9.*x3s)
4493  -8.*(3.+3.*r1s-r2+r1s*r2-5.*r2s-r2c-4.*x1-r1s*x1
4494  +2.*r2s*x1+x1s-2.*x2-r2*x2+r2s*x2+x1*x2)
4495  /prop13
4496  -8.*(-1.-r1s+r2+r1s*r2-r2s-r2c+x1+r2*x1+r2s*x1+2.*x2+r1s*x2
4497  -x1*x2*0.5-x2s*0.5)
4498  /(9.*prop23);
4499  rFO1 = 9.*rFO1/32.;
4500  isSet1 = true;
4501  }
4502  if (combi == 2 || combi == 3) {
4503  rLO2 = ps*(1.-r1s+r2s-2.*r2);
4504  rFO2 = 32*(2.*r2-x2)*(1.+r1s+r2s-x2)
4505  /(9.*prop2s)
4506  +8.*(-1.-r1s+2.*r1s*r2-r2s+2.*r2c+x1-r2*x1+r2s*x1
4507  +3.*x2*0.5-r1s*x2*0.5-r2*x2-r2s*x2*0.5-x1*x2*0.5)
4508  /prop12
4509  +8.*(2.+2.*r1s+2.*r2+2.*r1s*r2-6.*r2s+2.*r2c-3.*x1-r1s*x1
4510  -2.*r2*x1+3.*r2s*x1+x1s-x2-r1s*x2+r2s*x2+x1*x2)
4511  /prop1s
4512  -8.*(3.+3.*r1s+r2-r1s*r2-5.*r2s+r2c-4.*x1-r1s*x1+2.*r2s*x1+x1s
4513  -2.*x2+r2*x2+r2s*x2+x1*x2)
4514  /prop13
4515  +32*(4.+4.*r1s-4.*r2s-5.*x1-r1s*x1+2.*r2*x1+r2s*x1
4516  +x1s-3.*x2-r1s*x2+2.*r2*x2+r2s*x2+x1*x2)
4517  /(9.*x3s)
4518  -8.*(-1.-r1s-r2-r1s*r2-r2s+r2c+x1-r2*x1+r2s*x1+2.*x2+r1s*x2
4519  -x1*x2*0.5-x2s*0.5)
4520  /(9.*prop23);
4521  rFO2 = 9.*rFO2/32.;
4522  isSet2 = true;
4523  }
4524  if (combi == 4) {
4525  rLO4 = ps*(1.-r1s+r2s);
4526  rFO4 = 64.*x2*(-1.-r1s-r2s+x2)
4527  /(9.*prop2s)
4528  +16.*(-1.-r1s-r2s+x1+r2s*x1+3.*x2*0.5-r1s*x2*0.5
4529  -r2s*x2*0.5-x1*x2*0.5)
4530  /prop12
4531  -16.*(3.+3.*r1s-5.*r2s-4.*x1-r1s*x1+2.*r2s*x1+x1s-2.*x2+r2s*x2
4532  +x1*x2)
4533  /prop13
4534  +64.*(4.+4.*r1s-4.*r2s-5.*x1-r1s*x1+r2s*x1+x1s-3.*x2
4535  -r1s*x2+r2s*x2+x1*x2)
4536  /(9.*x3s)
4537  +16.*(2.+2.*r1s-6.*r2s-3.*x1-r1s*x1+3.*r2s*x1+x1s
4538  -x2-r1s*x2+r2s*x2+x1*x2)
4539  /prop1s
4540  -16.*(-1.-r1s-r2s+x1+r2s*x1+2.*x2+r1s*x2-x1*x2*0.5-x2s*0.5)
4541  /(9.*prop23);
4542  rFO4 = 9.*rFO4/64.;
4543  isSet4 = true;
4544  }
4545  break;
4546 
4547  // g -> ~g ~g. Use (9/4)*eikonal. May be changed in the future.
4548  case 16:
4549  rLO = ps;
4550  if (combi == 2) offset = x3s;
4551  else if (combi == 3) offset = mix * x3s;
4552  else if (combi == 4) offset = 0.5 * x3s;
4553  rFO = ps * 4.5 * ( (x1+x2-1.+offset-r1s-r2s)/prop12
4554  - r1s/prop2s - r2s/prop1s );
4555  break;
4556 
4557  // Dv -> qv d.
4558  case 30:
4559  rLO = ps*(1.-r1s+r2s+2.*r2);
4560  rFO = ( 0.5*r3s + 2.*r1q + 0.5*r2s*r3s + r2*r3s - 2.*r1s
4561  - 0.5*r1s*r3s - 2.*r1s*r2s - 4.*r1s*r2 ) / prop2s
4562  + ( -2. + 2.*r2q + 2.*r1q + 2.*r2s*r3s - 4.*r2 + 2.*r2*r3s
4563  + 4.*r2*r2s - 4.*r1s*r2s - 4.*r1s*r2 ) /prop23
4564  + ( -2. - 0.5*r3s - 2.*r2s - 4.*r2 + 2.*r1s ) / prop2
4565  + ( -2. - r3s - 2.*r2s - r2s*r3s - 4.*r2 - 2.*r2*r3s
4566  + 2.*r1s + r1s*r3s ) / prop3s
4567  + ( -1. - r3s - r2s - 4.*r2 + r1s - x2 ) / prop3
4568  + 1.;
4569  break;
4570 
4571  // S -> Dv Dvbar
4572  case 31:
4573  rLO = ps*(1.-4.*r1s);
4574  rFO = (r3s + 2.*r1s) * (-1. + 4.*r1s) * (1./prop1s + 1./prop2s)
4575  + (-1. + 8.*r1s - x2) / prop1
4576  + (-1. + 8.*r1s - x1) / prop2
4577  + 2. * (1. - 6.*r1s + 8.*r1q + 4.*r3s*r1s) / prop12
4578  + 2.;
4579  break;
4580 
4581  // q -> q~ W
4582  case 32:
4583  rLO = 1.;
4584  rFO = (2. * r3s * r3s + 2. * r3s * (x1 + x2) + x1s + x2s) / prop12
4585  - r3s / prop1s - r3s / prop2s;
4586  break;
4587 
4588  // q -> q Z
4589  case 33:
4590  rLO = 1.;
4591  rFO = (2. * r3s * r3s + 2. * r3s * (x1 + x2) + x1s + x2s) / prop12
4592  - r3s / prop1s - r3s / prop2s;
4593  break;
4594 
4595  // Eikonal expression for kind == 1; also acts as default.
4596  default:
4597  rLO = ps;
4598  if (combi == 2) offset = x3s;
4599  else if (combi == 3) offset = mix * x3s;
4600  else if (combi == 4) offset = 0.5 * x3s;
4601  rFO = ps * 2. * ( (x1+x2-1.+offset-r1s-r2s)/prop12
4602  - r1s/prop2s - r2s/prop1s );
4603  break;
4604 
4605  // End of ME cases.
4606  }
4607 
4608  // Find relevant leading and first order expressions.
4609  if (combi == 1 && isSet1) {
4610  rLO = rLO1;
4611  rFO = rFO1; }
4612  else if (combi == 2 && isSet2) {
4613  rLO = rLO2;
4614  rFO = rFO2; }
4615  else if (combi == 3 && isSet1 && isSet2) {
4616  rLO = mix * rLO1 + (1.-mix) * rLO2;
4617  rFO = mix * rFO1 + (1.-mix) * rFO2; }
4618  else if (isSet4) {
4619  rLO = rLO4;
4620  rFO = rFO4; }
4621  else if (combi == 4 && isSet1 && isSet2) {
4622  rLO = 0.5 * (rLO1 + rLO2);
4623  rFO = 0.5 * (rFO1 + rFO2); }
4624  else if (isSet1) {
4625  rLO = rLO1;
4626  rFO = rFO1; }
4627 
4628  // Return ratio of first to leading order cross section.
4629  return rFO / rLO;
4630 }
4631 
4632 //--------------------------------------------------------------------------
4633 
4634 // Return the ME corrections for weak t-channel processes.
4635 
4636 double TimeShower::findMEcorrWeak(TimeDipoleEnd* dip,Vec4 rad,
4637  Vec4 rec, Vec4 emt,Vec4 p3,Vec4 p4,Vec4 radBef, Vec4 recBef) {
4638 
4639  // Check that it is weak emission.
4640  if (dip->MEtype > 210 || dip->MEtype < 200) return 1.;
4641 
4642  // Remove double counting. Only implemented for QCD hard processes
4643  // and for the first emission.
4644  bool cut = false;
4645  if (infoPtr->nISR() + infoPtr->nFSRinProc() == 0
4646  && infoPtr->code() > 110 && infoPtr->code() < 130
4647  && vetoWeakJets) {
4648  double d = emt.pT2();
4649  if (rad.pT2() < d) {d = rad.pT2(); cut = true;}
4650  if (rec.pT2() < d) {d = rec.pT2(); cut = true;}
4651 
4652  // Always check for combination of radiator and emitted.
4653  double dij = min(rad.pT2(),emt.pT2())
4654  * pow2(RRapPhi(rad,emt)) / vetoWeakDeltaR2;
4655  if (dij < d) {
4656  d = dij;
4657  cut = false;
4658  }
4659 
4660  // Check for angle between recoiler and radiator, if quark anti-quark pair,
4661  // or if the recoiler is a gluon.
4662  if (dip->MEtype == 200 || dip->MEtype == 205 ||
4663  dip->MEtype == 201 || dip->MEtype == 206) {
4664  dij = min(rad.pT2(),rec.pT2()) * pow2(RRapPhi(rad,rec))
4665  / vetoWeakDeltaR2;
4666  if (dij < d) {
4667  d = dij;
4668  cut = true;
4669  }
4670  }
4671  // Check for angle between recoiler and emitted, if recoiler is a quark.
4672  if (dip->MEtype == 200 || dip->MEtype == 205 ||
4673  dip->MEtype == 202 || dip->MEtype == 207 ||
4674  dip->MEtype == 203 || dip->MEtype == 208) {
4675  dij = min(emt.pT2(),rec.pT2()) * pow2(RRapPhi(emt,rec))
4676  / vetoWeakDeltaR2;
4677  if (dij < d) {
4678  d = dij;
4679  cut = false;
4680  }
4681  }
4682  if (cut) return 0.;
4683  }
4684 
4685  // Check that MEtype is t-channel weak emission.
4686  if ( dip->MEtype != 201 && dip->MEtype != 202 && dip->MEtype != 203
4687  && dip->MEtype != 206 && dip->MEtype != 207 && dip->MEtype != 208)
4688  return 1;
4689 
4690  // Rescaling of incoming partons p3 and p4.
4691  double scaleFactor2 = (rad + rec + emt).m2Calc() / (p3 + p4).m2Calc();
4692  double scaleFactor = sqrt(scaleFactor2);
4693  p3 *= scaleFactor;
4694  p4 *= scaleFactor;
4695 
4696  // Longitudinal boost to rest frame of incoming partons of hard interaction.
4697  RotBstMatrix rot2to2frame;
4698  rot2to2frame.bstback(p3 + p4);
4699  p3.rotbst(rot2to2frame);
4700  p4.rotbst(rot2to2frame);
4701  rad.rotbst(rot2to2frame);
4702  emt.rotbst(rot2to2frame);
4703  rec.rotbst(rot2to2frame);
4704  recBef.rotbst(rot2to2frame);
4705  radBef.rotbst(rot2to2frame);
4706 
4707  // Further boost to rest frame of outgoing state.
4708  RotBstMatrix rot2to3frame;
4709  rot2to3frame.bstback(rad + emt + rec);
4710  rad.rotbst(rot2to3frame);
4711  emt.rotbst(rot2to3frame);
4712  rec.rotbst(rot2to3frame);
4713  recBef.rotbst(rot2to3frame);
4714  radBef.rotbst(rot2to3frame);
4715 
4716  // Kinematical quantities.
4717  double sHat = (p3 + p4).m2Calc();
4718  double tHat = (radBef - p3).m2Calc();
4719  double uHat = (recBef - p3).m2Calc();
4720  double z = dip->z;
4721  double pT2 = dip->pT2;
4722  double Q2 = pT2 / (z*(1.-z));
4723 
4724  // ME weight. Prefactor mainly from Jacobian.
4725  double wt = 2. * pT2 / z * (Q2+sHat)/sHat * (1. - kRad - kEmt) / 4.;
4726  if (dip->MEtype == 201 || dip->MEtype == 206)
4727  wt *= weakShowerMEs.getTchanneluGuGZME( p3, p4, rec, emt, rad)
4728  / weakShowerMEs.getTchanneluGuGME( sHat, tHat, uHat);
4729  else if (dip->MEtype == 202 || dip->MEtype == 207)
4730  wt *= weakShowerMEs.getTchannelududZME( p3, p4, emt, rec, rad)
4731  / weakShowerMEs.getTchanneluuuuME( sHat, tHat, uHat);
4732  else if (dip->MEtype == 203 || dip->MEtype == 208)
4733  wt *= weakShowerMEs.getTchannelududZME( p3, p4, emt, rec, rad)
4734  / weakShowerMEs.getTchannelududME( sHat, tHat, uHat);
4735 
4736  // Split of ME into an ISR part and FSR part.
4737  wt *= abs((-emt + p3).m2Calc()) / ((emt + rad).m2Calc()
4738  + abs((-p3 + emt).m2Calc()));
4739 
4740  // Correction for previous fudge-factor enhancement of weak emission rate.
4741  wt /= WEAKPSWEIGHT;
4742  if (wt > 1.) infoPtr->errorMsg("Warning in TimeShower::findMEcorrWeak: "
4743  "weight is above unity");
4744  return wt;
4745 
4746 }
4747 
4748 //--------------------------------------------------------------------------
4749 
4750 // Find coefficient of azimuthal asymmetry from gluon polarization.
4751 
4752 void TimeShower::findAsymPol( Event& event, TimeDipoleEnd* dip) {
4753 
4754  // Default is no asymmetry. Only gluons are studied.
4755  dip->asymPol = 0.;
4756  dip->iAunt = 0;
4757  int iRad = dip->iRadiator;
4758  if (!doPhiPolAsym || event[iRad].id() != 21) return;
4759 
4760  // Trace grandmother via possibly intermediate recoil copies.
4761  int iMother = event.iTopCopy(iRad);
4762  int iGrandM = event[iMother].mother1();
4763 
4764  // If grandmother in initial state of hard scattering,
4765  // then only keep gg and qq initial states.
4766  int statusGrandM = event[iGrandM].status();
4767  bool isHardProc = (statusGrandM == -21 || statusGrandM == -31);
4768  if (isHardProc) {
4769  if (event[iGrandM + 1].status() != statusGrandM) return;
4770  if (event[iGrandM].isGluon() && event[iGrandM + 1].isGluon());
4771  else if (event[iGrandM].isQuark() && event[iGrandM + 1].isQuark());
4772  else return;
4773  }
4774 
4775  // Set aunt by history or, for hard scattering, by colour flow.
4776  if (isHardProc) dip->iAunt = dip->iRecoiler;
4777  else dip->iAunt = (event[iGrandM].daughter1() == iMother)
4778  ? event[iGrandM].daughter2() : event[iGrandM].daughter1();
4779 
4780  // Coefficient from gluon production (approximate z by energy).
4781  // For hard process arbitrarily put z = 1/2.
4782  double zProd = (isHardProc) ? 0.5 : event[iRad].e()
4783  / (event[iRad].e() + event[dip->iAunt].e());
4784  if (event[iGrandM].isGluon()) dip->asymPol = pow2( (1. - zProd)
4785  / (1. - zProd * (1. - zProd) ) );
4786  else dip->asymPol = 2. * (1. - zProd) / (1. + pow2(1. - zProd) );
4787 
4788  // Coefficients from gluon decay.
4789  if (dip->flavour == 21) dip->asymPol *= pow2( (1. - dip->z)
4790  / (1. - dip->z * (1. - dip->z) ) );
4791  else dip->asymPol *= -2. * dip->z *( 1. - dip->z )
4792  / (1. - 2. * dip->z * (1. - dip->z) );
4793 
4794 }
4795 
4796 //--------------------------------------------------------------------------
4797 
4798 // Print the list of dipoles.
4799 
4800 void TimeShower::list(ostream& os) const {
4801 
4802  // Header.
4803  os << "\n -------- PYTHIA TimeShower Dipole Listing ----------------"
4804  << "------------------------------------------------------- \n \n "
4805  << " i rad rec pTmax col chg gam weak oni hv is"
4806  << "r sys sysR type MErec mix ord spl ~gR pol \n"
4807  << fixed << setprecision(3);
4808 
4809  // Loop over dipole list and print it.
4810  for (int i = 0; i < int(dipEnd.size()); ++i)
4811  os << setw(5) << i << setw(7) << dipEnd[i].iRadiator
4812  << setw(7) << dipEnd[i].iRecoiler << setw(12) << dipEnd[i].pTmax
4813  << setw(5) << dipEnd[i].colType << setw(5) << dipEnd[i].chgType
4814  << setw(5) << dipEnd[i].gamType << setw(5) << dipEnd[i].weakType
4815  << setw(5) << dipEnd[i].isOctetOnium
4816  << setw(5) << dipEnd[i].isHiddenValley << setw(5) << dipEnd[i].isrType
4817  << setw(5) << dipEnd[i].system << setw(5) << dipEnd[i].systemRec
4818  << setw(5) << dipEnd[i].MEtype << setw(7) << dipEnd[i].iMEpartner
4819  << setw(8) << dipEnd[i].MEmix << setw(5) << dipEnd[i].MEorder
4820  << setw(5) << dipEnd[i].MEsplit << setw(5) << dipEnd[i].MEgluinoRec
4821  << setw(5) << dipEnd[i].weakPol << "\n";
4822 
4823  // Done.
4824  os << "\n -------- End PYTHIA TimeShower Dipole Listing ------------"
4825  << "-------------------------------------------------------" << endl;
4826 
4827 }
4828 
4829 //==========================================================================
4830 
4831 } // end namespace Pythia8
Definition: beam.h:43
Definition: AgUStep.h:26