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