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