StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SimpleSpaceShower.cc
1 // SimpleSpaceShower.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // Function definitions (not found in the header) for the
7 // SimpleSpaceShower class.
8 
9 #include "Pythia8/SimpleSpaceShower.h"
10 
11 namespace Pythia8 {
12 
13 //==========================================================================
14 
15 // The SimpleSpaceShower class.
16 
17 //--------------------------------------------------------------------------
18 
19 // Constants: could be changed here if desired, but normally should not.
20 // These are of technical nature, as described for each.
21 
22 // Leftover companion can give PDF > 0 at small Q2 where other PDF's = 0,
23 // and then one can end in infinite loop of impossible kinematics.
24 const int SimpleSpaceShower::MAXLOOPTINYPDF = 10;
25 
26 // Minimal allowed c and b quark masses, for flavour thresholds.
27 const double SimpleSpaceShower::MCMIN = 1.2;
28 const double SimpleSpaceShower::MBMIN = 4.0;
29 
30 // Switch to alternative (but equivalent) backwards evolution for
31 // g -> Q Qbar (Q = c or b) when below QTHRESHOLD * mQ2.
32 const double SimpleSpaceShower::CTHRESHOLD = 2.0;
33 const double SimpleSpaceShower::BTHRESHOLD = 2.0;
34 
35 // Renew evaluation of PDF's when the pT2 step is bigger than this
36 // (in addition to initial scale and c and b thresholds.)
37 const double SimpleSpaceShower::EVALPDFSTEP = 0.1;
38 
39 // Lower limit on PDF value in order to avoid division by zero.
40 const double SimpleSpaceShower::TINYPDF = 1e-10;
41 
42 // Lower limit on estimated evolution rate, below which stop.
43 const double SimpleSpaceShower::TINYKERNELPDF = 1e-6;
44 
45 // Lower limit on pT2, below which branching is rejected.
46 const double SimpleSpaceShower::TINYPT2 = 0.25e-6;
47 
48 // No attempt to do backwards evolution of a heavy (c or b) quark
49 // if evolution starts at a scale pT2 < HEAVYPT2EVOL * mQ2.
50 const double SimpleSpaceShower::HEAVYPT2EVOL = 1.1;
51 
52 // No attempt to do backwards evolution of a heavy (c or b) quark
53 // if evolution starts at a x > HEAVYXEVOL * x_max, where
54 // x_max is the largest possible x value for a g -> Q Qbar branching.
55 const double SimpleSpaceShower::HEAVYXEVOL = 0.9;
56 
57 // When backwards evolution Q -> g + Q creates a heavy quark Q,
58 // an earlier branching g -> Q + Qbar will restrict kinematics
59 // to M_{Q Qbar}^2 > EXTRASPACEQ * 4 m_Q^2. (Smarter to be found??)
60 const double SimpleSpaceShower::EXTRASPACEQ = 2.0;
61 
62 // Never pick pT so low that alphaS is evaluated too close to Lambda_3.
63 const double SimpleSpaceShower::LAMBDA3MARGIN = 1.1;
64 
65 // Do not warn for large PDF ratios at small pT2 scales.
66 const double SimpleSpaceShower::PT2MINWARN = 1.;
67 
68 // Cutoff for f_e^e at x < 1 - 10^{-10} to be used in z selection.
69 // Note: the x_min quantity come from 1 - x_max.
70 const double SimpleSpaceShower::LEPTONXMIN = 1e-10;
71 const double SimpleSpaceShower::LEPTONXMAX = 1. - 1e-10;
72 
73 // Stop l -> l gamma evolution slightly above m2l.
74 const double SimpleSpaceShower::LEPTONPT2MIN = 1.2;
75 
76 // Enhancement of l -> l gamma trial rate to compensate imperfect modelling.
77 const double SimpleSpaceShower::LEPTONFUDGE = 10.;
78 
79 // Overestimation extra factor for t-channel weak ME corrections.
80 const double SimpleSpaceShower::WEAKPSWEIGHT = 5.;
81 
82 // Overestimation extra factors by branching type
83 const double SimpleSpaceShower::HEADROOMQ2G = 1.35;
84 const double SimpleSpaceShower::HEADROOMQ2Q = 1.15;
85 const double SimpleSpaceShower::HEADROOMG2Q = 1.35;
86 const double SimpleSpaceShower::HEADROOMG2G = 1.35;
87 const double SimpleSpaceShower::HEADROOMHQG = 1.35;
88 
89 // Limit on size of number of rejections for uncertainty variations.
90 const double SimpleSpaceShower::REJECTFACTOR = 0.1;
91 
92 // Limit on probability for uncertainty variations.
93 const double SimpleSpaceShower::PROBLIMIT = 0.99;
94 
95 //--------------------------------------------------------------------------
96 
97 // Initialize alphaStrong, alphaEM and related pTmin parameters.
98 
99 void SimpleSpaceShower::init( BeamParticle* beamAPtrIn,
100  BeamParticle* beamBPtrIn) {
101 
102  // Store input pointers for future use.
103  beamAPtr = beamAPtrIn;
104  beamBPtr = beamBPtrIn;
105 
106  // Main flags to switch on and off branchings.
107  doQCDshower = flag("SpaceShower:QCDshower");
108  doQEDshowerByQ = flag("SpaceShower:QEDshowerByQ");
109  doQEDshowerByL = flag("SpaceShower:QEDshowerByL");
110  doWeakShower = flag("SpaceShower:WeakShower");
111 
112  // Matching in pT of hard interaction to shower evolution.
113  pTmaxMatch = mode("SpaceShower:pTmaxMatch");
114  pTdampMatch = mode("SpaceShower:pTdampMatch");
115  pTmaxFudge = parm("SpaceShower:pTmaxFudge");
116  pTmaxFudgeMPI = parm("SpaceShower:pTmaxFudgeMPI");
117  pTdampFudge = parm("SpaceShower:pTdampFudge");
118 
119  // Optionally force emissions to be ordered in rapidity/angle.
120  doRapidityOrder = flag("SpaceShower:rapidityOrder");
121  doRapidityOrderMPI = flag("SpaceShower:rapidityOrderMPI");
122 
123  // Charm, bottom and lepton mass thresholds.
124  mc = max( MCMIN, particleDataPtr->m0(4));
125  mb = max( MBMIN, particleDataPtr->m0(5));
126  m2c = pow2(mc);
127  m2b = pow2(mb);
128 
129  // Parameters of scale choices.
130  renormMultFac = parm("SpaceShower:renormMultFac");
131  factorMultFac = parm("SpaceShower:factorMultFac");
132  useFixedFacScale = flag("SpaceShower:useFixedFacScale");
133  fixedFacScale2 = pow2(parm("SpaceShower:fixedFacScale"));
134 
135  // Parameters of alphaStrong generation.
136  alphaSvalue = parm("SpaceShower:alphaSvalue");
137  alphaSorder = mode("SpaceShower:alphaSorder");
138  alphaSnfmax = mode("StandardModel:alphaSnfmax");
139  alphaSuseCMW = flag("SpaceShower:alphaSuseCMW");
140  alphaS2pi = 0.5 * alphaSvalue / M_PI;
141 
142  // Initialize alpha_strong generation.
143  alphaS.init( alphaSvalue, alphaSorder, alphaSnfmax, alphaSuseCMW);
144 
145  // Lambda for 5, 4 and 3 flavours.
146  Lambda5flav = alphaS.Lambda5();
147  Lambda4flav = alphaS.Lambda4();
148  Lambda3flav = alphaS.Lambda3();
149  Lambda5flav2 = pow2(Lambda5flav);
150  Lambda4flav2 = pow2(Lambda4flav);
151  Lambda3flav2 = pow2(Lambda3flav);
152 
153  // Regularization of QCD evolution for pT -> 0. Can be taken
154  // same as for multiparton interactions, or be set separately.
155  useSamePTasMPI = flag("SpaceShower:samePTasMPI");
156  if (useSamePTasMPI) {
157 
158  // Different parametrization for photon-photon collisions.
159  if (beamAPtr->isGamma() && beamBPtr->isGamma()) {
160  pT0paramMode = mode("PhotonPhoton:pT0parametrization");
161  pT0Ref = parm("PhotonPhoton:pT0Ref");
162  ecmRef = parm("PhotonPhoton:ecmRef");
163  ecmPow = parm("PhotonPhoton:ecmPow");
164  pTmin = parm("PhotonPhoton:pTmin");
165  } else {
166  pT0paramMode
167  = mode("MultipartonInteractions:pT0parametrization");
168  pT0Ref = parm("MultipartonInteractions:pT0Ref");
169  ecmRef = parm("MultipartonInteractions:ecmRef");
170  ecmPow = parm("MultipartonInteractions:ecmPow");
171  pTmin = parm("MultipartonInteractions:pTmin");
172  }
173 
174  } else {
175  pT0paramMode = mode("SpaceShower:pT0parametrization");
176  pT0Ref = parm("SpaceShower:pT0Ref");
177  ecmRef = parm("SpaceShower:ecmRef");
178  ecmPow = parm("SpaceShower:ecmPow");
179  pTmin = parm("SpaceShower:pTmin");
180  }
181 
182  // Calculate nominal invariant mass of events.
183  sCM = m2( beamAPtr->p(), beamBPtr->p());
184  eCM = sqrt(sCM);
185 
186  // Set current pT0 scale according to the chosen parametrization.
187  if (pT0paramMode == 0) pT0 = pT0Ref * pow(eCM / ecmRef, ecmPow);
188  else pT0 = pT0Ref + ecmPow * log (eCM / ecmRef);
189 
190  // Restrict pTmin to ensure that alpha_s(pTmin^2 + pT_0^2) does not blow up.
191  double pTminAbs = sqrtpos(pow2(LAMBDA3MARGIN) * Lambda3flav2 / renormMultFac
192  - pT0*pT0);
193  if (pTmin < pTminAbs) {
194  pTmin = pTminAbs;
195  ostringstream newPTmin;
196  newPTmin << fixed << setprecision(3) << pTmin;
197  infoPtr->errorMsg("Warning in SpaceShower::init: pTmin too low",
198  ", raised to " + newPTmin.str() );
199  infoPtr->setTooLowPTmin(true);
200  }
201 
202  // Parameters of alphaEM generation.
203  alphaEMorder = mode("SpaceShower:alphaEMorder");
204 
205  // Initialize alphaEM generation.
206  alphaEM.init( alphaEMorder, settingsPtr);
207 
208  // Parameters of QED evolution.
209  pTminChgQ = parm("SpaceShower:pTminchgQ");
210  pTminChgL = parm("SpaceShower:pTminchgL");
211 
212  // Derived parameters of QCD evolution.
213  pT20 = pow2(pT0);
214  pT2min = pow2(pTmin);
215  pT2minChgQ = pow2(pTminChgQ);
216  pT2minChgL = pow2(pTminChgL);
217 
218  // Parameters of weak evolution.
219  weakMode = mode("SpaceShower:weakShowerMode");
220  pTweakCut = parm("SpaceShower:pTminWeak");
221  pT2weakCut = pow2(pTweakCut);
222  weakEnhancement = parm("WeakShower:enhancement");
223  singleWeakEmission = flag("WeakShower:singleEmission");
224  vetoWeakJets = flag("WeakShower:vetoWeakJets");
225  vetoWeakDeltaR2 = pow2(parm("weakShower:vetoWeakDeltaR"));
226  weakExternal = flag("WeakShower:externalSetup");
227 
228  // Various other parameters.
229  doMEcorrections = flag("SpaceShower:MEcorrections");
230  doMEafterFirst = flag("SpaceShower:MEafterFirst");
231  doPhiPolAsym = flag("SpaceShower:phiPolAsym");
232  doPhiPolAsymHard = flag("SpaceShower:phiPolAsymHard");
233  doPhiIntAsym = flag("SpaceShower:phiIntAsym");
234  strengthIntAsym = parm("SpaceShower:strengthIntAsym");
235  nQuarkIn = mode("SpaceShower:nQuarkIn");
236 
237  // Do not do phiIntAsym if dipoleRecoil is on, to avoid doublecounting.
238  doDipoleRecoil = flag("SpaceShower:dipoleRecoil");
239  if (doDipoleRecoil) doPhiIntAsym = false;
240 
241  // Z0 and W+- properties needed for weak showers.
242  mZ = particleDataPtr->m0(23);
243  gammaZ = particleDataPtr->mWidth(23);
244  thetaWRat = 1. / (16. * coupSMPtr->sin2thetaW()
245  * coupSMPtr->cos2thetaW());
246  mW = particleDataPtr->m0(24);
247  gammaW = particleDataPtr->mWidth(24);
248 
249  // Possibility of two predetermined hard emissions in event.
250  doSecondHard = flag("SecondHard:generate");
251  twoHard = doSecondHard;
252 
253  // gamma->qqbar splittings handled differently with and without MPIs.
254  doMPI = flag("PartonLevel:MPI");
255  gamma2qqbar = false;
256 
257  // Optional dampening at small pT's when large multiplicities.
258  enhanceScreening
259  = mode("MultipartonInteractions:enhanceScreening");
260  if (!useSamePTasMPI) enhanceScreening = 0;
261 
262  // Possibility to allow user veto of emission step.
263  hasUserHooks = (userHooksPtr != 0);
264  canVetoEmission = hasUserHooks && userHooksPtr->canVetoISREmission();
265 
266  // Default values for the weak shower.
267  hasWeaklyRadiated = false;
268  weakMaxWt = 1.;
269 
270  // Disallow simultaneous splitting and trial emission enhancements.
271  canEnhanceEmission = hasUserHooks && userHooksPtr->canEnhanceEmission();
272  canEnhanceTrial = hasUserHooks && userHooksPtr->canEnhanceTrial();
273  if (canEnhanceEmission && canEnhanceTrial) {
274  infoPtr->errorMsg("Error in SimpleSpaceShower::init: Enhance for both "
275  "actual and trial emissions not possible. Both switched off.");
276  canEnhanceEmission = false;
277  canEnhanceTrial = false;
278  }
279 
280  // Properties for enhanced emissions.
281  splittingNameSel = "";
282  splittingNameNow = "";
283  enhanceFactors.clear();
284 
285  // Enable automated uncertainty variations.
286  nVarQCD = 0;
287  doUncertainties = flag("UncertaintyBands:doVariations")
288  && initUncertainties();
289  doUncertaintiesNow = doUncertainties;
290  uVarNflavQ = mode("UncertaintyBands:nFlavQ");
291  uVarMPIshowers = flag("UncertaintyBands:MPIshowers");
292  cNSpTmin = parm("UncertaintyBands:cNSpTmin");
293  uVarpTmin2 = pow2(pT0Ref);
294  uVarpTmin2 *= parm("UncertaintyBands:ISRpTmin2Fac");
295  overFactor = parm("UncertaintyBands:overSampleISR");
296 
297  // Possibility to set parton vertex information.
298  doPartonVertex = flag("PartonVertex:setVertex")
299  && (partonVertexPtr != 0);
300 
301 }
302 
303 //--------------------------------------------------------------------------
304 
305 // Find whether to limit maximum scale of emissions.
306 // Also allow for dampening at factorization or renormalization scale.
307 
308 bool SimpleSpaceShower::limitPTmax( Event& event, double Q2Fac, double Q2Ren) {
309 
310  // Find whether to limit pT. Begin by user-set cases.
311  twoHard = doSecondHard;
312  bool dopTlimit = false;
313  dopTlimit1 = dopTlimit2 = false;
314  int nHeavyCol = 0;
315  if (pTmaxMatch == 1) dopTlimit = dopTlimit1 = dopTlimit2 = true;
316  else if (pTmaxMatch == 2) dopTlimit = dopTlimit1 = dopTlimit2 = false;
317 
318  // Always restrict SoftQCD processes.
319  else if (infoPtr->isNonDiffractive() || infoPtr->isDiffractiveA()
320  || infoPtr->isDiffractiveB() || infoPtr->isDiffractiveC() )
321  dopTlimit = dopTlimit1 = dopTlimit2 = true;
322 
323  // Look if any quark (u, d, s, c, b), gluon or photon in final state.
324  // Also count number of heavy coloured particles, like top.
325  else {
326  int n21 = 0;
327  int iBegin = 5 + beamOffset;
328  for (int i = iBegin; i < event.size(); ++i) {
329  if (event[i].status() == -21) ++n21;
330  else if (n21 == 0) {
331  int idAbs = event[i].idAbs();
332  if (idAbs <= 5 || idAbs == 21 || idAbs == 22) dopTlimit1 = true;
333  if ( (event[i].col() != 0 || event[i].acol() != 0)
334  && idAbs > 5 && idAbs != 21 ) ++nHeavyCol;
335  } else if (n21 == 2) {
336  int idAbs = event[i].idAbs();
337  if (idAbs <= 5 || idAbs == 21 || idAbs == 22) dopTlimit2 = true;
338  }
339  }
340  twoHard = (n21 == 2);
341  dopTlimit = (twoHard) ? (dopTlimit1 && dopTlimit2) : dopTlimit1;
342  }
343 
344  // Dampening at factorization or renormalization scale; only for hardest.
345  dopTdamp = false;
346  pT2damp = 0.;
347  if (!dopTlimit1 && (pTdampMatch == 1 || pTdampMatch == 2)) {
348  dopTdamp = true;
349  pT2damp = pow2(pTdampFudge) * ((pTdampMatch == 1) ? Q2Fac : Q2Ren);
350  }
351  if (!dopTlimit1 && nHeavyCol > 1 && (pTdampMatch == 3 || pTdampMatch == 4)) {
352  dopTdamp = true;
353  pT2damp = pow2(pTdampFudge) * ((pTdampMatch == 3) ? Q2Fac : Q2Ren);
354  }
355 
356  // Done.
357  return dopTlimit;
358 
359 }
360 
361 //--------------------------------------------------------------------------
362 
363 // Prepare system for evolution; identify ME.
364 // Routine may be called after multiparton interactions, for a new subystem.
365 
366 void SimpleSpaceShower::prepare( int iSys, Event& event, bool limitPTmaxIn) {
367 
368  // Reset W/Z radiation flag and counters at first call for new event.
369  if (iSys == 0) {
370  nRadA.clear();
371  nRadB.clear();
372  hasWeaklyRadiated = false;
373  }
374 
375  // Find positions of incoming colliding partons.
376  int in1 = partonSystemsPtr->getInA(iSys);
377  int in2 = partonSystemsPtr->getInB(iSys);
378 
379  // Rescattered partons cannot radiate.
380  bool canRadiate1 = !(event[in1].isRescatteredIncoming());
381  bool canRadiate2 = !(event[in2].isRescatteredIncoming());
382 
383  // Reset dipole-ends list for first interaction. Also resonances.
384  if (iSys == 0) {dipEnd.resize(0); idResFirst = 0;}
385  if (iSys == 1) idResSecond = 0;
386 
387  // Find matrix element corrections for system.
388  int MEtype = findMEtype( iSys, event, false);
389 
390  // In case of DPS overwrite limitPTmaxIn by saved value.
391  if (twoHard && iSys == 0) limitPTmaxIn = dopTlimit1;
392  if (twoHard && iSys == 1) limitPTmaxIn = dopTlimit2;
393 
394  // Maximum pT scale for dipole ends.
395  double pTmax1 = (limitPTmaxIn) ? event[in1].scale() : eCM;
396  double pTmax2 = (limitPTmaxIn) ? event[in2].scale() : eCM;
397  if ( limitPTmaxIn && (iSys == 0 || (iSys == 1 && twoHard)) ) {
398  pTmax1 *= pTmaxFudge;
399  pTmax2 *= pTmaxFudge;
400  } else if (limitPTmaxIn && iSys > 0) {
401  pTmax1 *= pTmaxFudgeMPI;
402  pTmax2 *= pTmaxFudgeMPI;
403  }
404 
405  // Find dipole ends for QCD radiation.
406  // Note: colour type can change during evolution, so book also if zero.
407  if (doQCDshower) {
408  int colType1 = event[in1].colType();
409  if (canRadiate1) {
410  // Look if there is an IF dipole in case of dipole recoil.
411  int iColPartner = (doDipoleRecoil)
412  ? findColPartner(event, in1, in2, iSys) : 0;
413  int idColPartner = (iColPartner != 0) ? event[iColPartner].id() : 0;
414  dipEnd.push_back( SpaceDipoleEnd( iSys, 1, in1, in2, pTmax1,
415  colType1, 0, 0, MEtype, canRadiate2, 0, iColPartner, idColPartner) );
416  }
417  int colType2 = event[in2].colType();
418  if (canRadiate2) {
419  // Look if there is an IF dipole in case of dipole recoil.
420  int iColPartner = (doDipoleRecoil)
421  ? findColPartner(event, in2, in1, iSys) : 0;
422  int idColPartner = (iColPartner != 0) ? event[iColPartner].id() : 0;
423  dipEnd.push_back( SpaceDipoleEnd( iSys, 2, in2, in1, pTmax2,
424  colType2, 0, 0, MEtype, canRadiate1, 0, iColPartner, idColPartner) );
425  }
426  }
427 
428  // Find dipole ends for QED radiation.
429  // Note: charge type can change during evolution, so book also if zero.
430  if (doQEDshowerByQ || doQEDshowerByL) {
431  int chgType1 = ( (event[in1].isQuark() && doQEDshowerByQ)
432  || (event[in1].isLepton() && doQEDshowerByL) )
433  ? event[in1].chargeType() : 0;
434  // Special: photons have charge zero, but can evolve (only off Q for now)
435  if (event[in1].id() == 22 && doQEDshowerByQ) chgType1 = 22 ;
436  if (canRadiate1) dipEnd.push_back( SpaceDipoleEnd( iSys, -1,
437  in1, in2, pTmax1, 0, chgType1, 0, MEtype, canRadiate2) );
438  int chgType2 = ( (event[in2].isQuark() && doQEDshowerByQ)
439  || (event[in2].isLepton() && doQEDshowerByL) )
440  ? event[in2].chargeType() : 0;
441  // Special: photons have charge zero, but can evolve (only off Q for now)
442  if (event[in2].id() == 22 && doQEDshowerByQ) chgType2 = 22 ;
443  if (canRadiate2) dipEnd.push_back( SpaceDipoleEnd( iSys, -2,
444  in2, in1, pTmax2, 0, chgType2, 0, MEtype, canRadiate1) );
445  }
446 
447  // Find dipole ends for weak radiation. No right-handed W emission.
448  // Currently leptons are not allow to emit W bosons and only
449  // emissions from the hard process are included.
450  if (doWeakShower && iSys == 0) {
451  // Normal internal setup.
452  if (!weakExternal) {
453  // Determine what type of 2 -> 2 process it is.
454  int MEtypeWeak = findMEtype( iSys, event, true);
455  if (MEtypeWeak == 201 || MEtypeWeak == 202 || MEtypeWeak == 203 ||
456  MEtypeWeak == 206 || MEtypeWeak == 207 || MEtypeWeak == 208) {
457 
458  // Nonidentical incoming flavours.
459  if (event[in1].id() != event[in2].id()) {
460  if (event[in1].id() == event[in1 + 2].id()) tChannel = true;
461  else if (event[in2].id() == event[in1 + 2].id()) tChannel = false;
462  // No quark matches the outgoing, choose randomly.
463  else tChannel = (rndmPtr->flat() < 0.5);
464  // In case of same quark flavours, choose randomly.
465  } else tChannel = (rndmPtr->flat() < 0.5);
466  }
467 
468  // Set up weak dipole ends for first incoming parton.
469  int weakPol = (rndmPtr->flat() > 0.5) ? -1 : 1;
470  if (event[in1].idAbs() < 20) event[in1].pol(weakPol);
471  if (canRadiate1) {
472  if ( (weakMode == 0 || weakMode == 1) && weakPol == -1
473  && event[in1].isQuark() )
474  dipEnd.push_back( SpaceDipoleEnd( iSys, 1, in1, in2, pTmax1,
475  0, 0, 1, MEtypeWeak, canRadiate2, weakPol) );
476  if ( (weakMode == 0 || weakMode == 2)
477  && (event[in1].isQuark() || event[in1].isLepton()) )
478  dipEnd.push_back( SpaceDipoleEnd( iSys, 1, in1, in2, pTmax1,
479  0, 0, 2, MEtypeWeak + 5, canRadiate2, weakPol) );
480  }
481 
482  // Set up weak dipole ends for second incoming parton.
483  if (event[in1].id() != - event[in2].id())
484  weakPol = (rndmPtr->flat() > 0.5) ? -1 : 1;
485  if (event[in2].idAbs() < 20) event[in2].pol(weakPol);
486  if (canRadiate2) {
487  if ( (weakMode == 0 || weakMode == 1) && weakPol == -1
488  && event[in2].isQuark())
489  dipEnd.push_back( SpaceDipoleEnd( iSys, 2, in2, in1, pTmax2,
490  0, 0, 1, MEtypeWeak, canRadiate1, weakPol) );
491  if ( (weakMode == 0 || weakMode == 2) &&
492  (event[in2].isQuark() || event[in2].isLepton()) )
493  dipEnd.push_back( SpaceDipoleEnd( iSys, 2, in2, in1, pTmax2,
494  0, 0, 2, MEtypeWeak + 5, canRadiate1, weakPol) );
495  }
496  // External setup from infoPtr.
497  } else {
498  // Get information.
499  vector<pair<int,int> > weakDipoles = infoPtr->getWeakDipoles();
500  vector<int> weakModes = infoPtr->getWeakModes();
501  weakMomenta = infoPtr->getWeakMomenta();
502  tChannel = true;
503  // Loop over dipoles.
504  for (int i = 0; i < int(weakDipoles.size()); ++i) {
505  // Only consider ISR dipoles.
506 
507  if (event[weakDipoles[i].first].status() < 0) {
508  // Find ME.
509  int iRadLocal = weakDipoles[i].first;
510  int iRecLocal = weakDipoles[i].second;
511  int side = (iRadLocal == 3) ? 1 : 2;
512  double pTmax = (side == 1) ? pTmax1 : pTmax2;
513 
514  // Find MEtype.
515  int MEtypeWeak = 0;
516  if (weakModes[weakDipoles[i].first] == 1) MEtypeWeak = 200;
517  else if (weakModes[weakDipoles[i].first] == 2) MEtypeWeak = 201;
518  else if (weakModes[weakDipoles[i].first] == 3) MEtypeWeak = 202;
519  else MEtypeWeak = 203;
520 
521  // Find correct polarization, if it is already set use it.
522  // Otherwise pick randomly.
523  int weakPol = (rndmPtr->flat() > 0.5) ? -1 : 1;
524  if (event[weakDipoles[i].first].intPol() != 9)
525  weakPol = event[weakDipoles[i].first].intPol();
526  event[weakDipoles[i].first].pol(weakPol);
527 
528  // Add the dipoles.
529  if ( (weakMode == 0 || weakMode == 1) && weakPol == -1)
530  dipEnd.push_back( SpaceDipoleEnd( iSys, side, iRadLocal, iRecLocal,
531  pTmax, 0, 0, 1, MEtypeWeak, true, weakPol) );
532  if (weakMode == 0 || weakMode == 2)
533  dipEnd.push_back( SpaceDipoleEnd( iSys, side, iRadLocal, iRecLocal,
534  pTmax, 0, 0, 2, MEtypeWeak + 5, true, weakPol) );
535  }
536  }
537  }
538  }
539 
540  // Store the z and pT2 values of the last previous splitting
541  // when an event history has already been constructed.
542  if (iSys == 0 && infoPtr->hasHistory()) {
543  double zNow = infoPtr->zNowISR();
544  double pT2Now = infoPtr->pT2NowISR();
545  for (int iDipEnd = 0; iDipEnd < int(dipEnd.size()); ++iDipEnd) {
546  dipEnd[iDipEnd].zOld = zNow;
547  dipEnd[iDipEnd].pT2Old = pT2Now;
548  ++dipEnd[iDipEnd].nBranch;
549  }
550  }
551 
552 }
553 
554 //--------------------------------------------------------------------------
555 
556 // Select next pT in downwards evolution of the existing dipoles.
557 
558 double SimpleSpaceShower::pTnext( Event& event, double pTbegAll,
559  double pTendAll, int nRadIn, bool doTrialIn) {
560 
561  // Current cm energy, in case it varies between events.
562  sCM = m2( beamAPtr->p(), beamBPtr->p());
563  eCM = sqrt(sCM);
564  pTbegRef = pTbegAll;
565 
566  // Starting values: no radiating dipole found.
567  nRad = nRadIn;
568  double pT2sel = pow2(pTendAll);
569  iDipSel = 0;
570  iSysSel = 0;
571  dipEndSel = 0;
572 
573  // Check if enhanced emissions should be applied.
574  doTrialNow = doTrialIn;
575  canEnhanceET = (!doTrialNow && canEnhanceEmission)
576  || ( doTrialNow && canEnhanceTrial);
577 
578  // Starting values for enhanced emissions.
579  splittingNameSel = "";
580  splittingNameNow = "";
581  enhanceFactors.clear();
582  if (hasUserHooks) userHooksPtr->setEnhancedTrial(0., 1.);
583 
584  // Loop over all possible dipole ends.
585  for (int iDipEnd = 0; iDipEnd < int(dipEnd.size()); ++iDipEnd) {
586  iDipNow = iDipEnd;
587  dipEndNow = &dipEnd[iDipEnd];
588  iSysNow = dipEndNow->system;
589  dipEndNow->pT2 = 0.;
590  dipEndNow->pAccept = 1.0;
591  double pTbegDip = min( pTbegAll, dipEndNow->pTmax );
592 
593  // Check whether dipole end should be allowed to shower.
594  double pT2begDip = pow2(pTbegDip);
595  if (pT2begDip > pT2sel && ( dipEndNow->colType != 0
596  || dipEndNow->chgType != 0 || dipEndNow->weakType != 0) ) {
597  double pT2endDip = 0.;
598 
599  // Determine lower cut for evolution, for QCD or QED (q or l).
600  if (dipEndNow->colType != 0)
601  pT2endDip = max( pT2sel, pT2min );
602  else if (abs(dipEndNow->weakType) != 0)
603  pT2endDip = max( pT2sel, pT2weakCut);
604  else if (abs(dipEndNow->chgType) != 3 && dipEndNow->chgType != 0)
605  pT2endDip = max( pT2sel, pT2minChgQ );
606  else
607  pT2endDip = max( pT2sel, pT2minChgL );
608 
609  // Find properties of dipole and radiating dipole end.
610  sideA = ( abs(dipEndNow->side) == 1 );
611  BeamParticle& beamNow = (sideA) ? *beamAPtr : *beamBPtr;
612  BeamParticle& beamRec = (sideA) ? *beamBPtr : *beamAPtr;
613  iNow = beamNow[iSysNow].iPos();
614  iRec = beamRec[iSysNow].iPos();
615  idDaughter = beamNow[iSysNow].id();
616  xDaughter = beamNow[iSysNow].x();
617  x1Now = (sideA) ? xDaughter : beamRec[iSysNow].x();
618  x2Now = (sideA) ? beamRec[iSysNow].x() : xDaughter;
619 
620  // If reconstructed back to the beam photon, no further ISR emissions.
621  if ( beamNow.isGamma() && !(beamNow.resolvedGamma()) ) continue;
622 
623  // Note dipole mass correction when recoiler is a rescatter.
624  m2Rec = (dipEndNow->normalRecoil) ? 0. : event[iRec].m2();
625  m2Dip = x1Now * x2Now * sCM + m2Rec;
626 
627  // Prepare kinematics for final-state dipole recoil.
628  m2ColPair = (dipEndNow->iColPartner == 0) ? 0.
629  : m2( event[iNow].p(), event[dipEndNow->iColPartner].p() );
630  mColPartner = (dipEndNow->iColPartner == 0) ? 0.
631  : event[dipEndNow->iColPartner].m();
632  m2ColPartner = pow2(mColPartner);
633 
634  // Stop if m2ColPair is negative.
635  if (m2ColPair < 0.) return 0.;
636 
637  // Now do evolution in pT2, for QCD, QED or weak.
638  if (pT2begDip > pT2endDip) {
639  if (dipEndNow->colType != 0) pT2nextQCD( pT2begDip, pT2endDip);
640  else if (dipEndNow->chgType != 0 || idDaughter == 22)
641  pT2nextQED( pT2begDip, pT2endDip);
642  else if (dipEndNow->weakType != 0) pT2nextWeak( pT2begDip, pT2endDip);
643 
644  // Update if found larger pT than current maximum.
645  if (dipEndNow->pT2 > pT2sel) {
646  pT2sel = dipEndNow->pT2;
647  iDipSel = iDipNow;
648  iSysSel = iSysNow;
649  dipEndSel = dipEndNow;
650  splittingNameSel = splittingNameNow;
651  }
652  }
653  }
654  // End loop over dipole ends.
655  }
656 
657  // Return nonvanishing value if found pT is bigger than already found.
658  return (dipEndSel == 0) ? 0. : sqrt(pT2sel);
659 }
660 
661 //--------------------------------------------------------------------------
662 
663 // Evolve a QCD dipole end.
664 
665 void SimpleSpaceShower::pT2nextQCD( double pT2begDip, double pT2endDip) {
666 
667  // Some properties and kinematical starting values.
668  BeamParticle& beam = (sideA) ? *beamAPtr : *beamBPtr;
669  bool isGluon = (idDaughter == 21);
670  bool isValence = beam[iSysNow].isValence();
671  int MEtype = dipEndNow->MEtype;
672  int iColPartner = dipEndNow->iColPartner;
673  int idColPartner = dipEndNow->idColPartner;
674  double pT2 = pT2begDip;
675  double xMaxAbs = beam.xMax(iSysNow);
676  double zMinAbs = xDaughter / xMaxAbs;
677  if (xMaxAbs < 0.) {
678  infoPtr->errorMsg("Warning in SimpleSpaceShower::pT2nextQCD: "
679  "xMaxAbs negative");
680  return;
681  }
682 
683  // Starting values for handling of massive quarks (c/b), if any.
684  double idMassive = 0;
685  if ( abs(idDaughter) == 4 ) idMassive = 4;
686  if ( abs(idDaughter) == 5 ) idMassive = 5;
687  bool isMassive = (idMassive > 0);
688  double m2Massive = 0.;
689  double mRatio = 0.;
690  double zMaxMassive = 1.;
691  double m2Threshold = pT2;
692 
693  // Evolution below scale of massive quark or at large x is impossible.
694  if (isMassive) {
695  m2Massive = (idMassive == 4) ? m2c : m2b;
696  if (pT2 < HEAVYPT2EVOL * m2Massive) return;
697  if (iColPartner == 0) {
698  mRatio = sqrt( m2Massive / m2Dip );
699  zMaxMassive = (1. - mRatio) / ( 1. + mRatio * (1. - mRatio) );
700  } else {
701  double m2Red = m2ColPair - m2ColPartner;
702  zMaxMassive = m2Red / (m2Red + m2Massive);
703  }
704  if (xDaughter > HEAVYXEVOL * zMaxMassive * xMaxAbs) return;
705 
706  // Find threshold scale below which only g -> Q + Qbar will be allowed.
707  m2Threshold = (idMassive == 4) ? min( pT2, CTHRESHOLD * m2c)
708  : min( pT2, BTHRESHOLD * m2b);
709  }
710 
711  // Variables used inside evolution loop. (Mainly dummy starting values.)
712  int nFlavour = 3;
713  double b0 = 4.5;
714  double Lambda2 = Lambda3flav2;
715  double pT2minNow = pT2endDip;
716  int idMother = 0;
717  int idSister = 0;
718  double z = 0.;
719  double zMaxAbs = 0.;
720  double zRootMax = 0.;
721  double zRootMin = 0.;
722  double g2gInt = 0.;
723  double q2gInt = 0.;
724  double q2qInt = 0.;
725  double g2qInt = 0.;
726  double g2Qenhance = 0.;
727  double xPDFdaughter = 0.;
728  double xPDFmother[21] = {0.};
729  double xPDFgMother = 0.;
730  double xPDFmotherSum = 0.;
731  double kernelPDF = 0.;
732  double xMother = 0.;
733  double wt = 0.;
734  double Q2 = 0.;
735  double mSister = 0.;
736  double m2Sister = 0.;
737  double pT2corr = 0.;
738  double pT2PDF = pT2;
739  bool needNewPDF = true;
740 
741  // Add more headroom if doing uncertainty variations
742  // (to ensure at least a minimal number of failed branchings).
743  doUncertaintiesNow = doUncertainties;
744  if (!uVarMPIshowers && iSysNow != 0) doUncertaintiesNow = false;
745  double overFac = doUncertaintiesNow ? overFactor : 1.0;
746 
747  // For dipole recoil: other-end colour factor correction in q-g dipole.
748  double coefColRec = (iColPartner != 0 && idColPartner == 21) ? 9./8. : 1.;
749 
750  // Set default values for enhanced emissions.
751  bool isEnhancedQ2QG, isEnhancedG2QQ, isEnhancedQ2GQ, isEnhancedG2GG;
752  isEnhancedQ2QG = isEnhancedG2QQ = isEnhancedQ2GQ = isEnhancedG2GG = false;
753  double enhanceNow = 1.;
754  string nameNow = "";
755 
756  // Begin evolution loop towards smaller pT values.
757  int loopTinyPDFdau = 0;
758  bool hasTinyPDFdau = false;
759  do {
760 
761  // Default values for current tentative emission.
762  wt = 0.;
763  isEnhancedQ2QG = isEnhancedG2QQ = isEnhancedQ2GQ = isEnhancedG2GG = false;
764  enhanceNow = 1.;
765  nameNow = "";
766 
767  // Bad sign if repeated looping with small daughter PDF, so fail.
768  // (Example: if all PDF's = 0 below Q_0, except for c/b companion.)
769  if (hasTinyPDFdau) ++loopTinyPDFdau;
770  if (loopTinyPDFdau > MAXLOOPTINYPDF) {
771  infoPtr->errorMsg("Warning in SimpleSpaceShower::pT2nextQCD: "
772  "small daughter PDF");
773  return;
774  }
775 
776  // Initialize integrals of splitting kernels and evaluate parton
777  // densities at the beginning. Reinitialize after long evolution
778  // in pT2 or when crossing c and b flavour thresholds.
779  if (needNewPDF || pT2 < EVALPDFSTEP * pT2PDF) {
780  pT2PDF = pT2;
781  hasTinyPDFdau = false;
782 
783  // Determine overestimated z range; switch at c and b masses.
784  if (pT2 > m2b) {
785  nFlavour = 5;
786  pT2minNow = max( m2b, pT2endDip);
787  b0 = 23./6.;
788  Lambda2 = Lambda5flav2;
789  } else if (pT2 > m2c) {
790  nFlavour = 4;
791  pT2minNow = max( m2c, pT2endDip);
792  b0 = 25./6.;
793  Lambda2 = Lambda4flav2;
794  } else {
795  nFlavour = 3;
796  pT2minNow = pT2endDip;
797  b0 = 27./6.;
798  Lambda2 = Lambda3flav2;
799  }
800 
801  // A change of renormalization scale expressed by a change of Lambda.
802  Lambda2 /= renormMultFac;
803 
804  // Upper limit on z range: global or local recoil.
805  if (iColPartner == 0) zMaxAbs = 1. - 0.5 * (pT2minNow / m2Dip)
806  * ( sqrt( 1. + 4. * m2Dip / pT2minNow ) - 1. );
807  else {
808  double m2Red = m2ColPair - m2ColPartner;
809  double pT2Ext = sqrt(pT2minNow * (pT2minNow + 4. * m2ColPartner));
810  zMaxAbs = (m2Red + 0.5 * (pT2minNow - pT2Ext))
811  / (m2Red + pT2minNow * (1. - m2ColPartner / m2Red));
812  }
813  if (isMassive) zMaxAbs = min( zMaxAbs, zMaxMassive);
814 
815  // Go to another z range with lower mass scale if current is closed.
816  if (zMinAbs > zMaxAbs) {
817  if (nFlavour == 3 || (idMassive == 4 && nFlavour == 4)
818  || idMassive == 5) return;
819  pT2 = (nFlavour == 4) ? m2c : m2b;
820  continue;
821  }
822 
823  // Parton density of daughter at current scale.
824  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2;
825  xfModPrepData xfData = beam.xfModPrep(iSysNow, pdfScale2);
826  xPDFdaughter = beam.xfISR(iSysNow, idDaughter, xDaughter, pdfScale2,
827  xfData);
828  if (xPDFdaughter < TINYPDF) {
829  xPDFdaughter = TINYPDF;
830  hasTinyPDFdau = true;
831  }
832 
833  // Integrals of splitting kernels for gluons: g -> g, q -> g.
834  if (isGluon) {
835  g2gInt = overFac * HEADROOMG2G * 6.
836  * log(zMaxAbs * (1.-zMinAbs) / (zMinAbs * (1.-zMaxAbs)));
837  if (doMEcorrections) g2gInt *= calcMEmax(MEtype, 21, 21);
838  // Optionally enhanced branching rate.
839  if (canEnhanceET) g2gInt *= userHooksPtr->enhanceFactor("isr:G2GG");
840  q2gInt = overFac * HEADROOMQ2G * (16./3.)
841  * (1./sqrt(zMinAbs) - 1./sqrt(zMaxAbs));
842  if (doMEcorrections) q2gInt *= calcMEmax(MEtype, 1, 21);
843  // Optionally enhanced branching rate.
844  if (canEnhanceET) q2gInt *= userHooksPtr->enhanceFactor("isr:Q2GQ");
845 
846  // Parton density of potential quark mothers to a g.
847  xPDFmotherSum = 0.;
848  xPDFmother[10] = 0.;
849  for (int i = -nQuarkIn; i <= nQuarkIn; ++i) {
850  if (i == 0) continue;
851  xPDFmother[i+10] = beam.xfISR(iSysNow, i, xDaughter, pdfScale2,
852  xfData);
853  xPDFmotherSum += xPDFmother[i+10];
854  }
855 
856  // Total QCD evolution coefficient for a gluon.
857  kernelPDF = g2gInt + q2gInt * xPDFmotherSum / xPDFdaughter;
858 
859  // For valence quark only need consider q -> q g branchings.
860  // Introduce an extra factor sqrt(z) to smooth bumps.
861  } else if (isValence) {
862  zRootMin = (1. + sqrt(zMinAbs)) / (1. - sqrt(zMinAbs));
863  zRootMax = (1. + sqrt(zMaxAbs)) / (1. - sqrt(zMaxAbs));
864  q2qInt = coefColRec * overFac * (8./3.) * log( zRootMax / zRootMin );
865  if (doMEcorrections) q2qInt *= calcMEmax(MEtype, 1, 1);
866  // Optionally enhanced branching rate.
867  if (canEnhanceET) q2qInt *= userHooksPtr->enhanceFactor("isr:Q2QG");
868  kernelPDF = q2qInt;
869 
870  // Integrals of splitting kernels for quarks: q -> q, g -> q.
871  } else {
872  q2qInt = coefColRec * overFac * HEADROOMQ2Q * (8./3.)
873  * log( (1. - zMinAbs) / (1. - zMaxAbs) );
874  if (doMEcorrections) q2qInt *= calcMEmax(MEtype, 1, 1);
875  // Optionally enhanced branching rate.
876  if (canEnhanceET) q2qInt *= userHooksPtr->enhanceFactor("isr:Q2QG");
877  g2qInt = overFac * HEADROOMG2Q * 0.5 * (zMaxAbs - zMinAbs);
878  if (doMEcorrections) g2qInt *= calcMEmax(MEtype, 21, 1);
879  // Optionally enhanced branching rate.
880  if (canEnhanceET) g2qInt *= userHooksPtr->enhanceFactor("isr:G2QQ");
881 
882  // Increase the upper weight for heavy quarks in photon beam
883  // due to different behavior of the PDFs.
884  if (beam.isGamma() && isMassive) q2qInt *= HEADROOMHQG;
885 
886  // Increase estimated upper weight for g -> Q + Qbar.
887  if (isMassive) {
888  if (alphaSorder == 0) g2Qenhance = log(pT2/m2Massive)
889  / log(m2Threshold/m2Massive);
890  else {
891  double m2log = log( m2Massive / Lambda2);
892  g2Qenhance = log( log(pT2/Lambda2) / m2log )
893  / log( log(m2Threshold/Lambda2) / m2log );
894  }
895  g2qInt *= g2Qenhance;
896  }
897 
898  // Parton density of a potential gluon mother to a q.
899  xPDFgMother = beam.xfISR(iSysNow, 21, xDaughter, pdfScale2, xfData);
900 
901  // Total QCD evolution coefficient for a quark.
902  kernelPDF = q2qInt + g2qInt * xPDFgMother / xPDFdaughter;
903  }
904 
905  // End evaluation of splitting kernels and parton densities.
906  needNewPDF = false;
907  }
908  if (kernelPDF < TINYKERNELPDF) return;
909 
910  // Pick pT2 (in overestimated z range), for one of three different cases.
911  // Assume form alphas(pT0^2 + pT^2) * dpT^2/(pT0^2 + pT^2).
912  double Q2alphaS;
913 
914  // Fixed alpha_strong.
915  if (alphaSorder == 0) {
916  pT2 = (pT2 + pT20) * pow( rndmPtr->flat(),
917  1. / (alphaS2pi * kernelPDF)) - pT20;
918 
919  // First-order alpha_strong.
920  } else if (alphaSorder == 1) {
921  pT2 = Lambda2 * pow( (pT2 + pT20) / Lambda2,
922  pow(rndmPtr->flat(), b0 / kernelPDF) ) - pT20;
923 
924  // For second order reject by second term in alpha_strong expression.
925  } else {
926  do {
927  pT2 = Lambda2 * pow( (pT2 + pT20) / Lambda2,
928  pow(rndmPtr->flat(), b0 / kernelPDF) ) - pT20;
929  Q2alphaS = renormMultFac * max( pT2 + pT20,
930  pow2(LAMBDA3MARGIN) * Lambda3flav2);
931  } while (alphaS.alphaS2OrdCorr(Q2alphaS) < rndmPtr->flat()
932  && pT2 > pT2minNow);
933  }
934 
935  // Check for pT2 values that prompt special action.
936 
937  // If fallen into b threshold region, force g -> b + bbar.
938  if (idMassive == 5 && pT2 < m2Threshold) {
939  pT2nearThreshold( beam, m2Massive, m2Threshold, xMaxAbs,
940  zMinAbs, zMaxMassive, iColPartner );
941  return;
942 
943  // If crossed b threshold, continue evolution from this threshold.
944  } else if (nFlavour == 5 && pT2 < m2b) {
945  needNewPDF = true;
946  pT2 = m2b;
947  continue;
948 
949  // If fallen into c threshold region, force g -> c + cbar.
950  } else if (idMassive == 4 && pT2 < m2Threshold) {
951  pT2nearThreshold( beam, m2Massive, m2Threshold, xMaxAbs,
952  zMinAbs, zMaxMassive, iColPartner );
953  return;
954 
955  // If crossed c threshold, continue evolution from this threshold.
956  } else if (nFlavour == 4 && pT2 < m2c) {
957  needNewPDF = true;
958  pT2 = m2c;
959  continue;
960 
961  // Abort evolution if below cutoff scale, or below another branching.
962  } else if (pT2 < pT2endDip) return;
963 
964  // Select z value of branching to g, and corrective weight.
965  if (isGluon) {
966 
967  // g -> g (+ g).
968  if (rndmPtr->flat() * kernelPDF < g2gInt) {
969  idMother = 21;
970  idSister = 21;
971  z = 1. / ( 1. + ((1. - zMinAbs) / zMinAbs) * pow( (zMinAbs *
972  (1. - zMaxAbs)) / (zMaxAbs * (1. - zMinAbs)), rndmPtr->flat() ) );
973  wt = pow2( 1. - z * (1. - z));
974  // For dipole recoil: other-end colour factor correction in g-q dipole.
975  if (iColPartner != 0 && idColPartner != 21)
976  wt *= (m2ColPair * pow2(1. - z) + z * pT2 * 8./9.)
977  / (m2ColPair * pow2(1. - z) + z * pT2);
978  // Account for headroom factor used to enhance trial probability
979  wt /= HEADROOMG2G;
980  // Optionally enhanced branching rate.
981  nameNow = "isr:G2GG";
982  if (canEnhanceET) {
983  double enhance = userHooksPtr->enhanceFactor(nameNow);
984  if (enhance != 1.) {
985  enhanceNow = enhance;
986  isEnhancedG2GG = true;
987  }
988  }
989 
990  // q -> g (+ q): also select flavour.
991  } else {
992  double temp = xPDFmotherSum * rndmPtr->flat();
993  idMother = -nQuarkIn - 1;
994  do { temp -= xPDFmother[(++idMother) + 10]; }
995  while (temp > 0. && idMother < nQuarkIn);
996  idSister = idMother;
997  z = (zMinAbs * zMaxAbs) / pow2( sqrt(zMinAbs) + rndmPtr->flat()
998  * ( sqrt(zMaxAbs)- sqrt(zMinAbs) ));
999  wt = 0.5 * (1. + pow2(1. - z)) * sqrt(z)
1000  * xPDFdaughter / xPDFmother[idMother + 10];
1001  // Account for headroom factor used to enhance trial probability
1002  wt /= HEADROOMQ2G;
1003  // Optionally enhanced branching rate.
1004  nameNow = "isr:Q2GQ";
1005  if (canEnhanceET) {
1006  double enhance = userHooksPtr->enhanceFactor(nameNow);
1007  if (enhance != 1.) {
1008  enhanceNow = enhance;
1009  isEnhancedQ2GQ = true;
1010  }
1011  }
1012  }
1013 
1014  // Select z value of branching to q, and corrective weight.
1015  // Include massive kernel corrections for c and b quarks.
1016  } else {
1017 
1018  // q -> q (+ g).
1019  if (isValence || rndmPtr->flat() * kernelPDF < q2qInt) {
1020  idMother = idDaughter;
1021  idSister = 21;
1022  // Valence more peaked at large z.
1023  if (isValence) {
1024  double zTmp = zRootMin * pow(zRootMax / zRootMin, rndmPtr->flat() );
1025  z = pow2( (1. - zTmp) / (1. + zTmp) );
1026  } else {
1027  z = 1. - (1. - zMinAbs) * pow( (1. - zMaxAbs) / (1. - zMinAbs),
1028  rndmPtr->flat() );
1029  }
1030  if (!isMassive) {
1031  wt = 0.5 * (1. + pow2(z));
1032  } else {
1033  wt = 0.5 * (1. + pow2(z)) - z * pow2(1.-z) * m2Massive / pT2;
1034  }
1035  if (isValence) wt *= sqrt(z);
1036  // Account for headroom factor for sea quarks
1037  else wt /= HEADROOMQ2Q;
1038  // Account for headroom factor for heavy quarks in photon beam.
1039  if (beam.isGamma() && isMassive) wt /= HEADROOMHQG;
1040  // For dipole recoil: other-end colour factor correction in q-g dipole.
1041  if (iColPartner != 0 && idColPartner == 21)
1042  wt *= (m2ColPair * pow2(1. - z) + z * pT2 * 9./8.)
1043  / ((m2ColPair * pow2(1. - z) + z * pT2) * coefColRec);
1044  // Optionally enhanced branching rate.
1045  nameNow = "isr:Q2QG";
1046  if (canEnhanceET) {
1047  double enhance = userHooksPtr->enhanceFactor(nameNow);
1048  if (enhance != 1.) {
1049  enhanceNow = enhance;
1050  isEnhancedQ2QG = true;
1051  }
1052  }
1053 
1054  // g -> q (+ qbar).
1055  } else {
1056  idMother = 21;
1057  idSister = - idDaughter;
1058  z = zMinAbs + rndmPtr->flat() * (zMaxAbs - zMinAbs);
1059  if (!isMassive) {
1060  wt = (pow2(z) + pow2(1.-z)) * xPDFdaughter / xPDFgMother;
1061  } else {
1062  wt = (pow2(z) + pow2(1.-z) + 2. * z * (1.-z) * m2Massive / pT2)
1063  * xPDFdaughter / (xPDFgMother * g2Qenhance) ;
1064  }
1065  // Account for headroom factor for gluons
1066  wt /= HEADROOMG2Q;
1067  // Optionally enhanced branching rate.
1068  if (abs(idSister) < 4) nameNow = "isr:G2QQ";
1069  else if (abs(idSister) == 4) nameNow = "isr:G2QQ:cc";
1070  else nameNow = "isr:G2QQ:bb";
1071  if (canEnhanceET) {
1072  double enhance = userHooksPtr->enhanceFactor(nameNow);
1073  if (enhance != 1.) {
1074  enhanceNow = enhance;
1075  isEnhancedG2QQ = true;
1076  }
1077  }
1078  }
1079  }
1080 
1081  // Cancel out uncertainty-band extra headroom factors.
1082  wt /= overFac;
1083 
1084  // Derive Q2 and x of mother from pT2 and z.
1085  Q2 = pT2 / (1. - z);
1086  xMother = xDaughter / z;
1087 
1088  // Correction to x for massive recoiler from rescattering.
1089  if (!dipEndNow->normalRecoil) {
1090  if (sideA) xMother += (m2Rec / (x2Now * sCM)) * (1. / z - 1.);
1091  else xMother += (m2Rec / (x1Now * sCM)) * (1. / z - 1.);
1092  }
1093  if (xMother > xMaxAbs) { wt = 0.; continue; }
1094 
1095  // Forbidden emission if outside allowed z range for given pT2.
1096  mSister = particleDataPtr->m0(idSister);
1097  m2Sister = pow2(mSister);
1098  if (iColPartner == 0) {
1099  pT2corr = Q2 - z * (m2Dip + Q2) * (Q2 + m2Sister) / m2Dip;
1100  } else {
1101  double tmpRat = z * (Q2 + m2Sister) / (m2ColPair - m2ColPartner);
1102  pT2corr = ((1. - z) * Q2 - z * m2Sister) * (1. - tmpRat)
1103  - m2ColPartner * pow2(tmpRat);
1104  }
1105  if (pT2corr < TINYPT2) { wt = 0.; continue; }
1106 
1107  // For emissions in the hard scattering system, optionally veto
1108  // emissions not ordered in rapidity (= angle).
1109  if ( iSysNow == 0 && doRapidityOrder && dipEndNow->nBranch > 0
1110  && pT2 > pow2( (1. - z) / (z * (1. - dipEndNow->zOld)) )
1111  * dipEndNow->pT2Old ) { wt = 0.; continue; }
1112 
1113  // For emissions in any secondary scattering system, optionally veto
1114  // emissions not ordered in rapidity (= angle).
1115  if ( iSysNow != 0 && doRapidityOrderMPI && dipEndNow->nBranch > 0
1116  && pT2 > pow2( (1. - z) / (z * (1. - dipEndNow->zOld)) )
1117  * dipEndNow->pT2Old ) { wt = 0.; continue; }
1118 
1119  // If creating heavy quark by Q -> g + Q then next need g -> Q + Qbar.
1120  // So minimum total mass2 is 4 * m2Sister, but use more to be safe.
1121  if ( isGluon && ( abs(idMother) == 4 || abs(idMother) == 5 )) {
1122  double m2QQsister = EXTRASPACEQ * 4. * m2Sister;
1123  double pT2QQcorr = 0.;
1124  if (iColPartner == 0) {
1125  pT2QQcorr = Q2 - z * (m2Dip + Q2) * (Q2 + m2QQsister) / m2Dip;
1126  } else {
1127  double tmpRat = z * (Q2 + m2QQsister) / (m2ColPair - m2ColPartner);
1128  pT2QQcorr = ((1. - z) * Q2 - z * m2QQsister) * (1. - tmpRat)
1129  - m2ColPartner * pow2(tmpRat);
1130  }
1131  if (pT2QQcorr < TINYPT2) { wt = 0.; continue; }
1132  }
1133 
1134  // Check that room left for beam remnants with photon beam.
1135  if ( beam.isGamma() ) {
1136  BeamParticle& beamOther = (sideA) ? *beamBPtr : *beamAPtr;
1137  if ( !beamOther.resolvedGamma() ) {
1138  // Check that room left for 1 beam remnant if other fixed
1139  if ( !beam.roomFor1Remnant( idMother, xMother, eCM) ) {
1140  wt = 0.;
1141  continue;
1142  }
1143  // Otherwise check that room left for 2 beam remnants.
1144  } else {
1145  if ( !beamOther.roomFor2Remnants( idMother, xMother, eCM ) ) {
1146  wt = 0.;
1147  continue;
1148  }
1149  }
1150  }
1151 
1152  // Evaluation of ME correction.
1153  if (doMEcorrections) wt *= calcMEcorr(MEtype, idMother, idDaughter,
1154  m2Dip, z, Q2, m2Sister) / calcMEmax(MEtype, idMother, idDaughter);
1155 
1156  // Optional dampening of large pT values in first radiation.
1157  if (dopTdamp && iSysNow == 0 && MEtype == 0 && nRad == 0)
1158  wt *= pT2damp / (pT2 + pT2damp);
1159 
1160  // Idea suggested by Gosta Gustafson: increased screening in events
1161  // with large activity can be simulated by pT0_eff = sqrt(n) * pT0.
1162  if (enhanceScreening == 2) {
1163  int nSysNow = infoPtr->nMPI() + infoPtr->nISR() + 1;
1164  double WTscreen = pow2( (pT2 + pT20) / (pT2 + nSysNow * pT20) );
1165  wt *= WTscreen;
1166  }
1167 
1168  // Evaluation of new daughter and mother PDF's.
1169  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2;
1170  xfModPrepData xfData2 = beam.xfModPrep(iSysNow, pdfScale2);
1171  double xPDFdaughterNew = max ( TINYPDF,
1172  beam.xfISR(iSysNow, idDaughter, xDaughter, pdfScale2, xfData2) );
1173  double xPDFmotherNew =
1174  beam.xfISR(iSysNow, idMother, xMother, pdfScale2, xfData2);
1175  wt *= xPDFmotherNew / xPDFdaughterNew;
1176 
1177  // If doing uncertainty variations, postpone accept/reject to branch()
1178  if (wt > 0. && pT2 > pT2min && doUncertaintiesNow ) {
1179  dipEndNow->pAccept = wt;
1180  wt = 1.0;
1181  }
1182 
1183  // Check that valence step does not cause problem.
1184  if (wt > 1. && pT2 > PT2MINWARN) infoPtr->errorMsg("Warning in "
1185  "SimpleSpaceShower::pT2nextQCD: weight above unity");
1186 
1187  // Iterate until acceptable pT (or have fallen below pTmin).
1188  } while (wt < rndmPtr->flat()) ;
1189 
1190  // Store outcome of enhanced branching rate analysis.
1191  splittingNameNow = nameNow;
1192  if (canEnhanceET) {
1193  if (isEnhancedQ2QG) storeEnhanceFactor(pT2,"isr:Q2QG", enhanceNow);
1194  if (isEnhancedG2QQ) storeEnhanceFactor(pT2,"isr:G2QQ", enhanceNow);
1195  if (isEnhancedQ2GQ) storeEnhanceFactor(pT2,"isr:Q2GQ", enhanceNow);
1196  if (isEnhancedG2GG) storeEnhanceFactor(pT2,"isr:G2GG", enhanceNow);
1197  }
1198 
1199  // Save values for (so far) acceptable branching.
1200  dipEndNow->store( idDaughter,idMother, idSister, x1Now, x2Now, m2Dip,
1201  pT2, z, xMother, Q2, mSister, m2Sister, pT2corr, iColPartner, m2ColPair,
1202  mColPartner);
1203 
1204 }
1205 
1206 //--------------------------------------------------------------------------
1207 
1208 // Evolve a QCD dipole end near threshold, with g -> Q + Qbar enforced.
1209 // Note: No explicit Sudakov factor formalism here. Instead use that
1210 // df_Q(x, pT2) = (alpha_s/2pi) * (dT2/pT2) * ((gluon) * (splitting)).
1211 // This implies that effects of Q -> Q + g are neglected in this range.
1212 // Now includes also threshold behaviour with photon beams.
1213 
1214 void SimpleSpaceShower::pT2nearThreshold( BeamParticle& beam,
1215  double m2Massive, double m2Threshold, double xMaxAbs,
1216  double zMinAbs, double zMaxMassive, int iColPartner) {
1217 
1218  // Initial values, to be used in kinematics and weighting.
1219  double Lambda2 = (abs(idDaughter) == 4) ? Lambda4flav2 : Lambda5flav2;
1220  Lambda2 /= renormMultFac;
1221  double logM2Lambda2 = (alphaSorder > 0) ? log( m2Massive / Lambda2 ) : 1.;
1222  pdfScale2 = (useFixedFacScale) ? fixedFacScale2
1223  : factorMultFac * m2Threshold;
1224  double xPDFmotherOld = beam.xfISR(iSysNow, 21, xDaughter, pdfScale2);
1225  // Check that xPDF is not vanishing.
1226  if ( xPDFmotherOld < TINYPDF ) {
1227  infoPtr->errorMsg("Error in SimpleSpaceShower::pT2nearThreshold: "
1228  "xPDF = 0");
1229  return;
1230  }
1231 
1232  // Variables used inside evolution loop. (Mainly dummy start values.)
1233  int loop = 0;
1234  double wt = 0.;
1235  double pT2 = 0.;
1236  double z = 0.;
1237  double Q2 = 0.;
1238  double pT2corr = 0.;
1239  double xMother = 0.;
1240 
1241  // Check if photon beam is being evolved.
1242  bool isGammaBeam = beam.isGamma();
1243  if( isGammaBeam ){
1244  BeamParticle& beamOther = (sideA) ? *beamBPtr : *beamAPtr;
1245  // Allow splitting only if room for remnants in the other side.
1246  if ( !beamOther.roomFor1Remnant(eCM) ) return;
1247  }
1248 
1249  // Begin loop over tries to find acceptable g -> Q + Qbar branching.
1250  do {
1251  wt = 0.;
1252 
1253  // Check that not caught in infinite loop with impossible kinematics.
1254  if (++loop > 100) {
1255  infoPtr->errorMsg("Error in SimpleSpaceShower::pT2nearThreshold: "
1256  "stuck in loop");
1257  return;
1258  }
1259 
1260  // Pick dpT2/pT2 in range [m2Massive,thresholdRatio * m2Massive].
1261  pT2 = m2Massive * pow( m2Threshold / m2Massive, rndmPtr->flat() );
1262 
1263  // For photon beams kinematics are fixed.
1264  if (isGammaBeam) {
1265  xMother = 1.0;
1266  z = xDaughter/xMother;
1267  // Pick z flat in allowed range.
1268  } else {
1269  z = zMinAbs + rndmPtr->flat() * (zMaxMassive - zMinAbs);
1270  }
1271 
1272  // Check that kinematically possible choice.
1273  Q2 = pT2 / (1.-z) - m2Massive;
1274  if (iColPartner == 0) {
1275  pT2corr = Q2 - z * (m2Dip + Q2) * (Q2 + m2Massive) / m2Dip;
1276  } else {
1277  double tmpRat = z * (Q2 + m2Massive) / (m2ColPair - m2ColPartner);
1278  pT2corr = ((1. - z) * Q2 - z * m2Massive) * (1. - tmpRat)
1279  - m2ColPartner * pow2(tmpRat);
1280  }
1281  if (pT2corr < TINYPT2) continue;
1282 
1283  // Correction factor for splitting kernel.
1284  wt = pow2(z) + pow2(1.-z) + 2. * z * (1.-z) * m2Massive / pT2;
1285 
1286  // Sample the kinematics for hadron beams.
1287  if (!isGammaBeam) {
1288 
1289  // Correction factor for running alpha_s. (Only first order for now.)
1290  wt *= (alphaSorder > 0) ? logM2Lambda2 / log( pT2 / Lambda2 ) : 1.;
1291 
1292  // x, including correction for massive recoiler from rescattering.
1293  xMother = xDaughter / z;
1294  if (!dipEndNow->normalRecoil) {
1295  if (sideA) xMother += (m2Rec / (x2Now * sCM)) * (1. / z - 1.);
1296  else xMother += (m2Rec / (x1Now * sCM)) * (1. / z - 1.);
1297  }
1298  if (xMother > xMaxAbs) { wt = 0.; continue; }
1299 
1300  // Correction factor for gluon density.
1301  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2;
1302  double xPDFmotherNew = beam.xfISR(iSysNow, 21, xMother, pdfScale2);
1303  wt *= xPDFmotherNew / xPDFmotherOld;
1304 
1305  }
1306 
1307  // If doing uncertainty variations, postpone accept/reject to branch().
1308  if (wt > 0. && pT2 > pT2min && doUncertaintiesNow ) {
1309  dipEndNow->pAccept = wt;
1310  wt = 1.0;
1311  }
1312 
1313  // Iterate until acceptable pT and z.
1314  } while (wt < rndmPtr->flat()) ;
1315 
1316  // Select correct mother for the splitting.
1317  int idMother = isGammaBeam ? 22 : 21;
1318 
1319  // Save values for (so far) acceptable branching.
1320  double mSister = (abs(idDaughter) == 4) ? mc : mb;
1321 
1322  if ( isGammaBeam ) splittingNameNow = "isr:A2QQ";
1323  else splittingNameNow = "isr:G2QQ";
1324  dipEndNow->store( idDaughter, idMother, -idDaughter, x1Now, x2Now, m2Dip,
1325  pT2, z, xMother, Q2, mSister, pow2(mSister), pT2corr, iColPartner,
1326  m2ColPair, mColPartner);
1327 
1328 }
1329 
1330 //--------------------------------------------------------------------------
1331 
1332 // Evolve a QED dipole end.
1333 
1334 void SimpleSpaceShower::pT2nextQED( double pT2begDip, double pT2endDip) {
1335 
1336  // Type of dipole and starting values.
1337  BeamParticle& beam = (sideA) ? *beamAPtr : *beamBPtr;
1338  bool isLeptonBeam = beam.isLepton();
1339  bool isGammaBeam = beam.isGamma();
1340  int MEtype = dipEndNow->MEtype;
1341  bool isPhoton = (idDaughter == 22);
1342  double pT2 = pT2begDip;
1343  double m2Lepton = (isLeptonBeam) ? pow2(beam.m()) : 0.;
1344  if (isLeptonBeam && pT2begDip < m2Lepton) return;
1345 
1346  // Currently no f -> gamma branching implemented for lepton or photon beams.
1347  if (isPhoton && (isLeptonBeam || isGammaBeam) ) return;
1348 
1349  // alpha_em at maximum scale provides upper estimate.
1350  double alphaEMmax = alphaEM.alphaEM(renormMultFac * pT2begDip);
1351  double alphaEM2pi = alphaEMmax / (2. * M_PI);
1352 
1353  // Maximum x of mother implies minimum z = xDaughter / xMother.
1354  double xMaxAbs = (isLeptonBeam) ? LEPTONXMAX : beam.xMax(iSysNow);
1355  double zMinAbs = xDaughter / xMaxAbs;
1356  if (xMaxAbs < 0.) {
1357  infoPtr->errorMsg("Warning in SimpleSpaceShower::pT2nextQED: "
1358  "xMaxAbs negative");
1359  return;
1360  }
1361 
1362  // Maximum z from minimum pT and, for lepton, from minimum x_gamma.
1363  double zMaxAbs = 1. - 0.5 * (pT2endDip / m2Dip) *
1364  ( sqrt( 1. + 4. * m2Dip / pT2endDip ) - 1. );
1365  if (isLeptonBeam) {
1366  double zMaxLepton = xDaughter / (xDaughter + LEPTONXMIN);
1367  if (zMaxLepton < zMaxAbs) zMaxAbs = zMaxLepton;
1368  }
1369  if (zMaxAbs < zMinAbs) return;
1370 
1371  // Similar threshold behaviour as in QCD evolution for photon beams.
1372  double idMassive = 0;
1373  if ( isGammaBeam && abs(idDaughter) == 4 ) idMassive = 4;
1374  if ( isGammaBeam && abs(idDaughter) == 5 ) idMassive = 5;
1375  bool isMassive = (idMassive > 0);
1376  double m2Massive = 0.;
1377  double mRatio = 0.;
1378  double zMaxMassive = 1.;
1379  double m2Threshold = pT2;
1380 
1381  // Evolution below scale of massive quark or at large x is impossible.
1382  if (isMassive) {
1383  m2Massive = (idMassive == 4) ? m2c : m2b;
1384  if (pT2 < HEAVYPT2EVOL * m2Massive) return;
1385  mRatio = sqrt( m2Massive / m2Dip );
1386  zMaxMassive = (1. - mRatio) / ( 1. + mRatio * (1. - mRatio) );
1387  if (xDaughter > HEAVYXEVOL * zMaxMassive * xMaxAbs) return;
1388 
1389  // Find threshold scale below which only gamma -> Q + Qbar will be allowed.
1390  m2Threshold = (idMassive == 4) ? min( pT2, CTHRESHOLD * m2c)
1391  : min( pT2, BTHRESHOLD * m2b);
1392  }
1393 
1394  // Variables used inside evolution loop. (Mainly dummy start values.)
1395  int idMother = 0;
1396  int idSister = 22;
1397  double z = 0.;
1398  double xMother = 0.;
1399  double wt = 0.;
1400  double Q2 = 0.;
1401  double mSister = 0.;
1402  double m2Sister = 0.;
1403  double pT2corr = 0.;
1404 
1405  // Set default values for enhanced emissions.
1406  bool isEnhancedQ2QA, isEnhancedQ2AQ, isEnhancedA2QQ;
1407  isEnhancedQ2QA = isEnhancedQ2AQ = isEnhancedA2QQ = false;
1408  double enhanceNow = 1.;
1409  string nameNow = "";
1410 
1411  // QED evolution of fermions
1412  if (!isPhoton) {
1413 
1414  // Integrals of splitting kernels for fermions: f -> f. Use 1 + z^2 < 2.
1415  // Ansatz f(z) = 2 / (1 - z), with + 2 / (z - xDaughter) for lepton.
1416  double f2fInt = 0.;
1417  double f2fIntA = 2. * log( (1. - zMinAbs) / (1. - zMaxAbs) );
1418  double f2fIntB = 0.;
1419  if (isLeptonBeam) {
1420  f2fIntB = 2. * log( (zMaxAbs - xDaughter) / (zMinAbs - xDaughter) );
1421  f2fInt = f2fIntA + f2fIntB;
1422  } else f2fInt = pow2(dipEndNow->chgType / 3.) * f2fIntA;
1423 
1424  // gamma -> q qbar splitting where gamma is the original beam particle.
1425  // P(z) = 3e_q^2(z^2 + (1-z)^2)
1426  // Correct for the weight function (currently constant*log(pT2/pT2ref)).
1427  double gamma2f = 0;
1428  double pT2ref = 0;
1429  double xfApprox = 0;
1430  if (isGammaBeam) {
1431 
1432  // For photon beams approximate PDFs to estimate the splitting
1433  // probability.
1434  pT2ref = beam.gammaPDFRefScale(idDaughter);
1435  xfApprox = beam.gammaPDFxDependence(idDaughter, xDaughter);
1436 
1437  // Allow splitting only if room for remnants at the other side.
1438  BeamParticle& beamOther = (sideA) ? *beamBPtr : *beamAPtr;
1439  if ( beamOther.roomFor1Remnant(eCM) ) {
1440  gamma2f = alphaEM2pi * pow2(double(dipEndNow->chgType) / 3.)* 3.
1441  * (pow2(xDaughter) + pow2(1. - xDaughter))/xfApprox;
1442  }
1443  }
1444 
1445  // Upper estimate for evolution equation, including fudge factor.
1446  if (doMEcorrections) f2fInt *= calcMEmax(MEtype, 1, 1);
1447  double kernelPDF = alphaEM2pi * f2fInt;
1448  double fudge = (isLeptonBeam) ? LEPTONFUDGE * log(m2Dip/m2Lepton) : 1.;
1449  kernelPDF *= fudge;
1450  // Check the kernelPDF value before possible enhancement but do not
1451  // enhance gamma -> q qbar splittings.
1452  if ( (kernelPDF + gamma2f) < TINYKERNELPDF ) return;
1453 
1454  // Optionally enhanced branching rate.
1455  if (canEnhanceET) kernelPDF *= userHooksPtr->enhanceFactor("isr:Q2QA");
1456 
1457  // Optionally enhanced branching rate.
1458  if (canEnhanceET) gamma2f *= userHooksPtr->enhanceFactor("isr:A2QQ");
1459 
1460  // Add gamma -> q qbar splittings to kernelPDF for photon beam.
1461  kernelPDF += gamma2f;
1462 
1463  // Begin evolution loop towards smaller pT values.
1464  do {
1465 
1466  // Default values for current tentative emission.
1467  isEnhancedQ2QA = isEnhancedA2QQ = false;
1468  enhanceNow = 1.;
1469  nameNow = "";
1470 
1471  // gamma -> f fbar splitting with photon beam.
1472  if( (rndmPtr->flat() * kernelPDF) < gamma2f ){
1473 
1474  // Sample pT2 using pT2ref.
1475  pT2 = pT2ref*pow(pT2/pT2ref, pow(rndmPtr->flat(), 1. / kernelPDF));
1476 
1477  // If fallen into b or c threshold region, force gamma -> q + qbar.
1478  if ( isMassive && (pT2 < m2Threshold ) ) {
1479  pT2nearThreshold( beam, m2Massive, m2Threshold, xMaxAbs,
1480  zMinAbs, zMaxMassive, 0 );
1481  return;
1482  } else if (pT2 < pT2endDip) return;
1483 
1484  // Fix the flavors and masses for the partons.
1485  idMother = 22;
1486  xMother = 1.0;
1487  z = xDaughter/xMother;
1488  idSister = -idDaughter;
1489  mSister = particleDataPtr->m0(idSister);
1490  m2Sister = pow2(mSister);
1491 
1492  // Derive Q2 from pT2 and z.
1493  Q2 = pT2 / (1. - z);
1494 
1495  // Forbidden emission if outside allowed z range for given pT2.
1496  pT2corr = Q2 - z * (m2Dip + Q2) * (Q2 + m2Sister) / m2Dip;
1497  if (pT2corr < TINYPT2) { wt = 0.; continue; }
1498 
1499  // Weight with the x*log(pT2/pT2ref)/(x*pdf).
1500  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2;
1501  double daughterPDF = max ( TINYPDF,
1502  beam.xfISR(iSysNow, idDaughter, xDaughter, pdfScale2) );
1503  wt = xDaughter*log(pT2/pT2ref)/daughterPDF;
1504 
1505  // Correct for the x-dependence of PDFs
1506  // (Currently only constant depending on the quark flavor).
1507  wt *= xfApprox;
1508 
1509  // Correct to current value of alpha_EM.
1510  double alphaEMnow = alphaEM.alphaEM(renormMultFac * pT2);
1511  wt *= (alphaEMnow / alphaEMmax);
1512 
1513  // Optionally enhanced branching rate.
1514  nameNow = "isr:A2QQ";
1515  if (canEnhanceET) {
1516  double enhance = userHooksPtr->enhanceFactor(nameNow);
1517  if (enhance != 1.) {
1518  enhanceNow = enhance;
1519  isEnhancedA2QQ = true;
1520  }
1521  }
1522 
1523  // Check that gamma -> q qbar step does not cause problem.
1524  if (wt > 1. && pT2 > PT2MINWARN){
1525  infoPtr->errorMsg("Warning in SimpleSpaceShower::pT2nextQED: "
1526  "weight above unity");
1527  }
1528 
1529  // f -> f gamma splittings
1530  } else {
1531 
1532  // Pick pT2 (in overestimated z range).
1533  // For l -> l gamma include extrafactor 1 / ln(pT2/m2l) in evolution.
1534  double shift = pow(rndmPtr->flat(), 1. / kernelPDF);
1535  if (isLeptonBeam) pT2 = m2Lepton * pow( pT2 / m2Lepton, shift);
1536  else pT2 = pT2 * shift;
1537 
1538  // If fallen into b or c threshold region, force gamma -> Q + Qbar.
1539  if ( isGammaBeam && isMassive && (pT2 < m2Threshold ) ) {
1540  pT2nearThreshold( beam, m2Massive, m2Threshold, xMaxAbs,
1541  zMinAbs, zMaxMassive, 0 );
1542  return;
1543  }
1544 
1545  // Abort evolution if below cutoff scale, or below another branching.
1546  if (pT2 < pT2endDip) return;
1547  if (isLeptonBeam && pT2 < LEPTONPT2MIN * m2Lepton) return;
1548 
1549  // Set the IDs for f -> f + gamma splittings.
1550  idSister = 22;
1551  idMother = idDaughter;
1552 
1553  // Select z value of branching f -> f + gamma, and corrective weight.
1554  wt = 1.;
1555  if (isLeptonBeam) {
1556  if (f2fIntA > rndmPtr->flat() * (f2fIntA + f2fIntB)) {
1557  z = 1. - (1. - zMinAbs)
1558  * pow( (1. - zMaxAbs) / (1. - zMinAbs), rndmPtr->flat() );
1559  } else {
1560  z = xDaughter + (zMinAbs - xDaughter)
1561  * pow( (zMaxAbs - xDaughter) / (zMinAbs - xDaughter),
1562  rndmPtr->flat() );
1563  }
1564  wt *= (z - xDaughter) / (1. - xDaughter);
1565  } else {
1566  z = 1. - (1. - zMinAbs)
1567  * pow( (1. - zMaxAbs) / (1. - zMinAbs), rndmPtr->flat() );
1568  }
1569 
1570  // The same mass corrections as for QCD q -> q g
1571  if (!isMassive) {
1572  wt *= 0.5 * (1. + pow2(z));
1573  } else {
1574  wt *= 0.5 * (1. + pow2(z)) - z * pow2(1.-z) * m2Massive / pT2;
1575  }
1576 
1577  // Optionally enhanced branching rate.
1578  nameNow = "isr:Q2QA";
1579  if (canEnhanceET) {
1580  double enhance = userHooksPtr->enhanceFactor(nameNow);
1581  if (enhance != 1.) {
1582  enhanceNow = enhance;
1583  isEnhancedQ2QA = true;
1584  }
1585  }
1586 
1587  // Derive Q2 and x of mother from pT2 and z.
1588  Q2 = pT2 / (1. - z);
1589  xMother = xDaughter / z;
1590  // Correction to x for massive recoiler from rescattering.
1591  if (!dipEndNow->normalRecoil) {
1592  if (sideA) xMother += (m2Rec / (x2Now * sCM)) * (1. / z - 1.);
1593  else xMother += (m2Rec / (x1Now * sCM)) * (1. / z - 1.);
1594  }
1595  if (xMother > xMaxAbs) { wt = 0.; continue; }
1596 
1597  // Forbidden emission if outside allowed z range for given pT2.
1598  mSister = 0.;
1599  m2Sister = 0.;
1600  pT2corr = Q2 - z * (m2Dip + Q2) * (Q2 + m2Sister) / m2Dip;
1601  if (pT2corr < TINYPT2) { wt = 0.; continue; }
1602 
1603  // Check that room left for beam remnants with photon beams.
1604  if ( beam.isGamma() ) {
1605  BeamParticle& beamOther = (sideA) ? *beamBPtr : *beamAPtr;
1606  // Room for one remnant, other already fixed by ISR.
1607  if( !beamOther.resolvedGamma() ){
1608  if ( !beam.roomFor1Remnant( idMother, xMother, eCM) ) {
1609  wt = 0.;
1610  continue;
1611  }
1612  // Room left for two beam remnants.
1613  } else {
1614  if( !beamOther.roomFor2Remnants( idMother, xMother, eCM ) ) {
1615  wt = 0.;
1616  continue;
1617  }
1618  }
1619  }
1620 
1621  // Correct by ln(pT2 / m2l) and fudge factor.
1622  if (isLeptonBeam) wt *= log(pT2 / m2Lepton) / fudge;
1623 
1624  // Evaluation of ME correction.
1625  if (doMEcorrections) wt *= calcMEcorr(MEtype, idMother, idDaughter,
1626  m2Dip, z, Q2, m2Sister) / calcMEmax(MEtype, idMother, idDaughter);
1627 
1628  // Extra QED correction for f fbar -> W+- gamma. Debug??
1629  if (doMEcorrections && MEtype == 1 && idDaughter == idMother
1630  && ( (iSysNow == 0 && idResFirst == 24)
1631  || (iSysNow == 1 && idResSecond == 24) ) ) {
1632  double tHe = -Q2;
1633  double uHe = Q2 - m2Dip * (1. - z) / z;
1634  double chg1 = abs(dipEndNow->chgType / 3.);
1635  double chg2 = 1. - chg1;
1636  wt *= pow2(chg1 * uHe - chg2 * tHe)
1637  / ( (tHe + uHe) * (pow2(chg1) * uHe + pow2(chg2) * tHe) );
1638  }
1639 
1640  // Optional dampening of large pT values in first radiation.
1641  if (dopTdamp && iSysNow == 0 && MEtype == 0 && nRad == 0)
1642  wt *= pT2damp / (pT2 + pT2damp);
1643 
1644  // Correct to current value of alpha_EM.
1645  double alphaEMnow = alphaEM.alphaEM(renormMultFac * pT2);
1646  wt *= (alphaEMnow / alphaEMmax);
1647 
1648  // Evaluation of new daughter and mother PDF's.
1649  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2;
1650  xfModPrepData xfData = beam.xfModPrep(iSysNow, pdfScale2);
1651  double xPDFdaughterNew = max ( TINYPDF,
1652  beam.xfISR(iSysNow, idDaughter, xDaughter, pdfScale2, xfData) );
1653  double xPDFmotherNew =
1654  beam.xfISR(iSysNow, idMother, xMother, pdfScale2, xfData);
1655  wt *= xPDFmotherNew / xPDFdaughterNew;
1656  }
1657 
1658  // Iterate until acceptable pT (or have fallen below pTmin).
1659  } while (wt < rndmPtr->flat()) ;
1660 
1661  }
1662 
1663  // QED evolution of photons (so far only for hadron beams).
1664  else {
1665 
1666  // Initial values
1667  int nFlavour = 3;
1668  double kernelPDF = 0.0;
1669  double xPDFdaughter = 0.;
1670  double xPDFmother[21] = {0.};
1671  double xPDFmotherSum = 0.0;
1672  double pT2PDF = pT2;
1673  double pT2minNow = pT2endDip;
1674  bool needNewPDF = true;
1675 
1676  // Begin evolution loop towards smaller pT values.
1677  int loopTinyPDFdau = 0;
1678  bool hasTinyPDFdau = false;
1679  do {
1680 
1681  // Default values for current tentative emission.
1682  wt = 0.;
1683  isEnhancedQ2AQ = false;
1684  enhanceNow = 1.;
1685  nameNow = "";
1686 
1687  // Bad sign if repeated looping with small daughter PDF, so fail.
1688  if (hasTinyPDFdau) ++loopTinyPDFdau;
1689  if (loopTinyPDFdau > MAXLOOPTINYPDF) {
1690  infoPtr->errorMsg("Warning in SimpleSpaceShower::pT2nextQED: "
1691  "small daughter PDF");
1692  return;
1693  }
1694 
1695  // Initialize integrals of splitting kernels and evaluate parton
1696  // densities at the beginning. Reinitialize after long evolution
1697  // in pT2 or when crossing c and b flavour thresholds.
1698  if (needNewPDF || pT2 < EVALPDFSTEP * pT2PDF) {
1699 
1700  pT2PDF = pT2;
1701  hasTinyPDFdau = false;
1702 
1703  // Determine overestimated z range; switch at c and b masses.
1704  if (pT2 > m2b && nQuarkIn >= 5) {
1705  nFlavour = 5;
1706  pT2minNow = max( m2b, pT2endDip);
1707  } else if (pT2 > m2c && nQuarkIn >= 4) {
1708  nFlavour = 4;
1709  pT2minNow = max( m2c, pT2endDip);
1710  } else {
1711  nFlavour = 3;
1712  pT2minNow = pT2endDip;
1713  }
1714 
1715  // Compute upper z limit
1716  zMaxAbs = 1. - 0.5 * (pT2minNow / m2Dip) *
1717  ( sqrt( 1. + 4. * m2Dip / pT2minNow ) - 1. );
1718 
1719  // Parton density of daughter at current scale.
1720  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2;
1721  xPDFdaughter = beam.xfISR(iSysNow, idDaughter, xDaughter, pdfScale2);
1722  if (xPDFdaughter < TINYPDF) {
1723  xPDFdaughter = TINYPDF;
1724  hasTinyPDFdau = true;
1725  }
1726 
1727  // Integral over f -> gamma f splitting kernel.
1728  // Normalized so: 4/3 aS/2pi P(z) -> eq^2 * aEM/2pi P(z).
1729  // (Charge-weighting happens below.)
1730  double q2gInt = 4. * (1./sqrt(zMinAbs) - 1./sqrt(zMaxAbs));
1731  // Optionally enhanced branching rate.
1732  if (canEnhanceET) q2gInt *= userHooksPtr->enhanceFactor("isr:Q2QA");
1733 
1734  // Charge-weighted parton density of potential quark mothers.
1735  xPDFmotherSum = 0.;
1736  xPDFmother[10] = 0.;
1737  xfModPrepData xfData2 = beam.xfModPrep(iSysNow, pdfScale2);
1738  for (int i = -nFlavour; i <= nFlavour; ++i) {
1739  if (i == 0) continue;
1740  xPDFmother[i+10] = pow2((abs(i+1) % 2 + 1)/3.0)
1741  * beam.xfISR(iSysNow, i, xDaughter, pdfScale2, xfData2);
1742  xPDFmotherSum += xPDFmother[i+10];
1743  }
1744 
1745  // Total QED evolution coefficient for a photon.
1746  kernelPDF = q2gInt * xPDFmotherSum / xPDFdaughter;
1747 
1748  // End evaluation of splitting kernels and parton densities.
1749  needNewPDF = false;
1750  }
1751  if (kernelPDF < TINYKERNELPDF) return;
1752 
1753  // Select pT2 for next trial branching
1754  pT2 *= pow( rndmPtr->flat(), 1. / (alphaEM2pi * kernelPDF));
1755 
1756  // If crossed b threshold, continue evolution from this threshold.
1757  if (nFlavour == 5 && pT2 < m2b) {
1758  needNewPDF = true;
1759  pT2 = m2b;
1760  continue;
1761  }
1762 
1763  // If crossed c threshold, continue evolution from this threshold.
1764  else if (nFlavour == 4 && pT2 < m2c) {
1765  needNewPDF = true;
1766  pT2 = m2c;
1767  continue;
1768  }
1769 
1770  // Abort evolution if below cutoff scale, or below another branching.
1771  else if (pT2 < pT2endDip) return;
1772 
1773  // Select flavour for trial branching
1774  double temp = xPDFmotherSum * rndmPtr->flat();
1775  idMother = -nQuarkIn - 1;
1776  do {
1777  temp -= xPDFmother[(++idMother) + 10];
1778  } while (temp > 0. && idMother < nQuarkIn);
1779 
1780  // Sister is same as mother, but can have m2 > 0
1781  idSister = idMother;
1782  mSister = particleDataPtr->m0(idSister);
1783  m2Sister = pow2(mSister);
1784 
1785  // Select z for trial branching
1786  z = (zMinAbs * zMaxAbs) / pow2( sqrt(zMinAbs) + rndmPtr->flat()
1787  * ( sqrt(zMaxAbs)- sqrt(zMinAbs) ));
1788 
1789  // Trial weight: splitting kernel
1790  wt = 0.5 * (1. + pow2(1. - z)) * sqrt(z);
1791 
1792  // Trial weight: running alpha_EM
1793  double alphaEMnow = alphaEM.alphaEM(renormMultFac * pT2);
1794  wt *= (alphaEMnow / alphaEMmax);
1795 
1796  // Optionally enhanced branching rate.
1797  nameNow = "isr:Q2AQ";
1798  if (canEnhanceET) {
1799  double enhance = userHooksPtr->enhanceFactor(nameNow);
1800  if (enhance != 1.) {
1801  enhanceNow = enhance;
1802  isEnhancedQ2AQ = true;
1803  }
1804  }
1805 
1806  // Derive Q2 and x of mother from pT2 and z
1807  Q2 = pT2 / (1. - z);
1808  xMother = xDaughter / z;
1809  // Correction to x for massive recoiler from rescattering.
1810  if (!dipEndNow->normalRecoil) {
1811  if (sideA) xMother += (m2Rec / (x2Now * sCM)) * (1. / z - 1.);
1812  else xMother += (m2Rec / (x1Now * sCM)) * (1. / z - 1.);
1813  }
1814 
1815  // Compute pT2corr
1816  pT2corr = Q2 - z * (m2Dip + Q2) * (Q2 + m2Sister) / m2Dip;
1817  if (pT2corr < TINYPT2) { wt = 0.; continue; }
1818 
1819  // If creating heavy quark by Q -> gamma + Q then next g -> Q + Qbar.
1820  // So minimum total mass2 is 4 * m2Sister, but use more to be safe.
1821  if ( abs(idMother) == 4 || abs(idMother) == 5 ) {
1822  double m2QQsister = EXTRASPACEQ * 4. * m2Sister;
1823  double pT2QQcorr = Q2 - z * (m2Dip + Q2) * (Q2 + m2QQsister) / m2Dip;
1824  if (pT2QQcorr < TINYPT2) { wt = 0.; continue; }
1825  }
1826 
1827  // Optional dampening of large pT values in first radiation.
1828  if (dopTdamp && iSysNow == 0 && MEtype == 0 && nRad == 0)
1829  wt *= pT2damp / (pT2 + pT2damp);
1830 
1831  // Evaluation of new daughter PDF
1832  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2;
1833  double xPDFdaughterNew = beam.xfISR(iSysNow, idDaughter, xDaughter,
1834  pdfScale2);
1835  if (xPDFdaughterNew < TINYPDF) {
1836  xPDFdaughterNew = TINYPDF;
1837  }
1838 
1839  // Evaluation of new charge-weighted mother PDF
1840  double xPDFmotherNew = pow2( (abs(idMother+1) % 2 + 1)/3.0 )
1841  * beam.xfISR(iSysNow, idMother, xMother, pdfScale2);
1842 
1843  // Trial weight: divide out old pdf ratio
1844  wt *= xPDFdaughter / xPDFmother[idMother + 10];
1845 
1846  // Trial weight: new pdf ratio
1847  wt *= xPDFmotherNew / xPDFdaughterNew;
1848 
1849  // Iterate until acceptable pT (or have fallen below pTmin).
1850  } while (wt < rndmPtr->flat()) ;
1851  }
1852 
1853  // Store outcome of enhanced branching rate analysis.
1854  splittingNameNow = nameNow;
1855  if (canEnhanceET) {
1856  if (isEnhancedQ2QA) storeEnhanceFactor(pT2,"isr:Q2QA", enhanceNow);
1857  if (isEnhancedQ2AQ) storeEnhanceFactor(pT2,"isr:Q2AQ", enhanceNow);
1858  if (isEnhancedA2QQ) storeEnhanceFactor(pT2,"isr:A2QQ", enhanceNow);
1859  }
1860 
1861  // Save values for (so far) acceptable branching.
1862  dipEndNow->store( idDaughter, idMother, idSister, x1Now, x2Now, m2Dip,
1863  pT2, z, xMother, Q2, mSister, m2Sister, pT2corr, 0, m2ColPair,
1864  mColPartner);
1865 
1866 }
1867 
1868 //--------------------------------------------------------------------------
1869 
1870 void SimpleSpaceShower::pT2nextWeak( double pT2begDip, double pT2endDip) {
1871 
1872  // Type of dipole and starting values.
1873  BeamParticle& beam = (sideA) ? *beamAPtr : *beamBPtr;
1874  bool isLeptonBeam = beam.isLepton();
1875  bool isValence = beam[iSysNow].isValence();
1876  int MEtype = dipEndNow->MEtype;
1877  double pT2 = pT2begDip;
1878  double m2Lepton = (isLeptonBeam) ? pow2(beam.m()) : 0.;
1879  if (isLeptonBeam && pT2begDip < m2Lepton) return;
1880 
1881  // alpha_em at maximum scale provides upper estimate.
1882  double alphaEMmax = alphaEM.alphaEM(pT2begDip);
1883  double alphaEM2pi = alphaEMmax / (2. * M_PI);
1884 
1885  // Maximum x of mother implies minimum z = xDaughter / xMother.
1886  double xMaxAbs = (isLeptonBeam) ? LEPTONXMAX : beam.xMax(iSysNow);
1887  double zMinAbs = xDaughter / xMaxAbs;
1888  if (xMaxAbs < 0.) {
1889  infoPtr->errorMsg("Warning in SimpleSpaceShower::pT2nextWeak: "
1890  "xMaxAbs negative");
1891  return;
1892  }
1893 
1894  // Maximum z from minimum pT and, for lepton, from minimum x_gamma.
1895  double zMaxAbs = 1. - 0.5 * (pT2endDip / m2Dip) *
1896  ( sqrt( 1. + 4. * m2Dip / pT2endDip ) - 1. );
1897  if (isLeptonBeam) {
1898  double zMaxLepton = xDaughter / (xDaughter + LEPTONXMIN);
1899  if (zMaxLepton < zMaxAbs) zMaxAbs = zMaxLepton;
1900  }
1901  if (zMaxAbs < zMinAbs) return;
1902 
1903  // Variables used inside evolution loop. (Mainly dummy start values.)
1904  int idMother = 0;
1905  int idSister = 0;
1906  // Check whether emission of W+, W- or Z0.
1907  if (dipEndNow->weakType == 1) {
1908  idSister = (idDaughter > 0) ? -24 : 24;
1909  if (abs(idDaughter) % 2 == 1) idSister = -idSister;
1910  } else if (dipEndNow->weakType == 2) idSister = 23;
1911  double z = 0.;
1912  double xMother = 0.;
1913  double wt = 0.;
1914  double Q2 = 0.;
1915  double mSister = particleDataPtr->mSel(idSister);
1916  double m2Sister = pow2(mSister);
1917  double pT2corr = 0.;
1918 
1919  // Find maximum z due to massive sister.
1920  // Still need to prove that this actually is an overestimate.
1921  double mRatio = mSister/ sqrt(m2Dip);
1922  double m2R1 = 1. + pow2(mRatio);
1923  double zMaxMassive = 1. / (m2R1 + pT2endDip/m2Dip);
1924  if (zMaxMassive < zMaxAbs) zMaxAbs = zMaxMassive;
1925  if (zMaxAbs < zMinAbs) return;
1926 
1927  // Set default values for enhanced emissions.
1928  bool isEnhancedQ2QW;
1929  isEnhancedQ2QW = false;
1930  double enhanceNow = 1.;
1931  string nameNow = "";
1932 
1933  // Weak evolution of fermions.
1934  // Integrals of splitting kernels for fermions: f -> f.
1935  // Old ansatz f(z) = 2 / (1 - z), with + 2 / (z - xDaughter) for lepton.
1936  // New Ansatz f(z) = (1 + (1+r^2)^2) / (1 - z * (1 + r^2)).
1937  // This should always be an overestimate for massive emissions.
1938  // Not yet implemented correctly for lepton beam.
1939  double f2fInt = 0.;
1940  double f2fIntA = (1. + pow2(zMaxAbs * m2R1)) / m2R1
1941  * log( (1. - m2R1 * zMinAbs) / (1. - m2R1 * zMaxAbs) );
1942  double f2fIntB = 0.;
1943  double zRootMin = (1. + sqrt(m2R1 * zMinAbs)) / (1. - sqrt(m2R1 * zMinAbs));
1944  double zRootMax = (1. + sqrt(m2R1 * zMaxAbs)) / (1. - sqrt(m2R1 * zMaxAbs));
1945  if (isLeptonBeam) {
1946  f2fIntB = 2. * log( (zMaxAbs - xDaughter) / (zMinAbs - xDaughter) );
1947  f2fInt = f2fIntA + f2fIntB;
1948  } else if (isValence)
1949  f2fInt = (1. + pow2(zMaxAbs) * pow2(m2R1))/ sqrt(m2R1)
1950  * log( zRootMax / zRootMin );
1951  else
1952  f2fInt = f2fIntA;
1953 
1954  // Calculate the weak coupling: separate for left- and right-handed fermions.
1955  double weakCoupling = 0;
1956  if (dipEndNow->weakType == 1)
1957  weakCoupling = 2. * alphaEM2pi / (4. * coupSMPtr->sin2thetaW());
1958  else if (dipEndNow->weakType == 2 && dipEndNow->weakPol == -1)
1959  weakCoupling = alphaEM2pi * thetaWRat
1960  * pow2(2. * coupSMPtr->lf( abs(idDaughter) ));
1961  else
1962  weakCoupling = alphaEM2pi * thetaWRat
1963  * pow2(2. * coupSMPtr->rf(abs(idDaughter) ));
1964 
1965  // Find the possible mothers for a W emission. So far quarks only.
1966  vector<int> possibleMothers;
1967  if (abs(idDaughter) % 2 == 0) {
1968  possibleMothers.push_back(1);
1969  possibleMothers.push_back(3);
1970  possibleMothers.push_back(5);
1971  } else {
1972  possibleMothers.push_back(2);
1973  possibleMothers.push_back(4);
1974  }
1975  if (idDaughter < 0)
1976  for (unsigned int i = 0;i < possibleMothers.size();i++)
1977  possibleMothers[i] = - possibleMothers[i];
1978 
1979  // Check if daughter estimate is 0, return in that case.
1980  // Only write warning if u, d or g is the daughter.
1981  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2begDip;
1982  double xPDFdaughter = beam.xfISR(iSysNow, idDaughter, xDaughter, pdfScale2);
1983  if (xPDFdaughter < TINYPDF) {
1984  if (abs(idDaughter) == 1 || abs(idDaughter) == 2 || abs(idDaughter) == 21)
1985  infoPtr->errorMsg("Warning in SimpleSpaceShower::pT2nextWeak: "
1986  "very small PDF");
1987  return;
1988  }
1989 
1990  // PDF and CKM upper estimate needed for W emission.
1991  double overEstimatePDFCKM = 0.;
1992  if (dipEndNow->weakType == 1) {
1993  xfModPrepData xfData = beam.xfModPrep(iSysNow, pdfScale2);
1994  for (unsigned int i = 0; i < possibleMothers.size(); i++)
1995  overEstimatePDFCKM += coupSMPtr->V2CKMid(idDaughter, possibleMothers[i])
1996  * beam.xfISR(iSysNow, possibleMothers[i], xDaughter, pdfScale2, xfData)
1997  / xPDFdaughter;
1998  }
1999  if (dipEndNow->weakType == 2) overEstimatePDFCKM = 1.;
2000 
2001  // Upper estimate for evolution equation, including fudge factor.
2002  if (doMEcorrections) f2fInt *= calcMEmax(MEtype, 1, 1);
2003  double kernelPDF = weakCoupling * f2fInt * weakEnhancement;
2004 
2005  // PDF and CKM overestimate.
2006  kernelPDF *= overEstimatePDFCKM;
2007  double fudge = (isLeptonBeam) ? LEPTONFUDGE * log(m2Dip/m2Lepton) : 1.;
2008  kernelPDF *= fudge;
2009  if (kernelPDF < TINYKERNELPDF) return;
2010  // Optionally enhanced branching rate.
2011  if (canEnhanceET) kernelPDF *= userHooksPtr->enhanceFactor("isr:Q2QW");
2012 
2013  // Begin evolution loop towards smaller pT values.
2014  do {
2015 
2016  // Default values for current tentative emission.
2017  isEnhancedQ2QW = false;
2018  enhanceNow = 1.;
2019  nameNow = "";
2020 
2021  // Pick pT2 (in overestimated z range).
2022  // For l -> l gamma include extrafactor 1 / ln(pT2 / m2l) in evolution.
2023  double shift = pow(rndmPtr->flat(), 1. / kernelPDF);
2024  if (isLeptonBeam) pT2 = m2Lepton * pow( pT2 / m2Lepton, shift);
2025  else pT2 = pT2 * shift;
2026 
2027  // Abort evolution if below cutoff scale, or below another branching.
2028  if (pT2 < pT2endDip) return;
2029  if (isLeptonBeam && pT2 < LEPTONPT2MIN * m2Lepton) return;
2030 
2031  // Abort evolution if below mass treshold.
2032  if (pT2 < HEAVYPT2EVOL * pow2(particleDataPtr->m0(idDaughter))) return;
2033 
2034  // Set the id for the mother particle to be equal to the daughter
2035  // particle. This is correct for Z, and it will later be changed for W.
2036  idMother = idDaughter;
2037 
2038  // Select z value of branching f -> f + Z/W, and corrective weight.
2039  wt = 1.0;
2040  if (isLeptonBeam) {
2041  if (f2fIntA > rndmPtr->flat() * (f2fIntA + f2fIntB)) {
2042  z = 1. - (1. - zMinAbs)
2043  * pow( (1. - zMaxAbs) / (1. - zMinAbs), rndmPtr->flat() );
2044  } else {
2045  z = xDaughter + (zMinAbs - xDaughter)
2046  * pow( (zMaxAbs - xDaughter) / (zMinAbs - xDaughter),
2047  rndmPtr->flat() );
2048  }
2049  wt *= (z - xDaughter) / (1. - xDaughter);
2050  } else if (isValence) {
2051  // Valence more peaked at large z.
2052  double zTmp = zRootMin * pow(zRootMax / zRootMin, rndmPtr->flat() );
2053  z = pow2( (1. - zTmp) / (1. + zTmp) ) / m2R1;
2054  wt *= sqrt(z);
2055  } else {
2056  z = (1. - (1. - zMinAbs * m2R1) * pow( (1. - zMaxAbs * m2R1)
2057  / (1. - zMinAbs * m2R1), rndmPtr->flat() ) ) / m2R1;
2058  }
2059  wt *= (1. + pow2(z * m2R1)) / (1. + pow2(zMaxAbs * m2R1));
2060 
2061  // Optionally enhanced branching rate.
2062  nameNow = "isr:Q2QW";
2063  if (canEnhanceET) {
2064  double enhance = userHooksPtr->enhanceFactor(nameNow);
2065  if (enhance != 1.) {
2066  enhanceNow = enhance;
2067  isEnhancedQ2QW = true;
2068  }
2069  }
2070 
2071  // Derive Q2 and x of mother from pT2 and z.
2072  Q2 = pT2 / (1. - z);
2073  xMother = xDaughter / z;
2074 
2075  // Correction to x for massive recoiler from rescattering.
2076  if (!dipEndNow->normalRecoil) {
2077  if (sideA) xMother += (m2Rec / (x2Now * sCM)) * (1. / z - 1.);
2078  else xMother += (m2Rec / (x1Now * sCM)) * (1. / z - 1.);
2079  }
2080  if (xMother > xMaxAbs) { wt = 0.; continue; }
2081 
2082  // Forbidden emission if outside allowed z range for given pT2.
2083  pT2corr = Q2 - z * (m2Dip + Q2) * (Q2 + m2Sister) / m2Dip;
2084  if (pT2corr < TINYPT2) { wt = 0.; continue; }
2085 
2086  // Correct by ln(pT2 / m2l) and fudge factor.
2087  if (isLeptonBeam) wt *= log(pT2 / m2Lepton) / fudge;
2088 
2089  // Evaluation of ME correction.
2090  if (doMEcorrections) wt *= calcMEcorr(MEtype, idMother, idDaughter,
2091  m2Dip, z, Q2, m2Sister) / calcMEmax(MEtype, idMother, idDaughter);
2092 
2093  // Optional dampening of large pT values in first radiation.
2094  // Allow damping also for corrected matrix elements
2095  if (dopTdamp && iSysNow == 0 && nRad == 0)
2096  wt *= pT2damp / (pT2 + pT2damp);
2097 
2098  // Correct to current value of alpha_EM.
2099  double alphaEMnow = alphaEM.alphaEM(pT2);
2100  wt *= (alphaEMnow / alphaEMmax);
2101 
2102  // Evaluation of new daughter and mother PDF's for Z.
2103  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2;
2104  xfModPrepData xfData2 = beam.xfModPrep(iSysNow, pdfScale2);
2105  double xPDFdaughterNew = max ( TINYPDF,
2106  beam.xfISR(iSysNow, idDaughter, xDaughter, pdfScale2, xfData2) );
2107  if (dipEndNow->weakType == 2) {
2108  double xPDFmotherNew
2109  = beam.xfISR(iSysNow, idMother, xMother, pdfScale2, xfData2);
2110  wt *= xPDFmotherNew / xPDFdaughterNew;
2111  }
2112 
2113  // Evaluation of daughter and mother PDF's for W.
2114  if (dipEndNow->weakType == 1) {
2115  double valPDFCKM[3] = {0.};
2116  double sumPDFCKM = 0.;
2117  for (unsigned int i = 0; i < possibleMothers.size(); i++) {
2118  valPDFCKM[i] = coupSMPtr->V2CKMid(idDaughter,possibleMothers[i])
2119  * beam.xfISR(iSysNow, possibleMothers[i], xMother, pdfScale2,
2120  xfData2) / xPDFdaughterNew;
2121  sumPDFCKM += valPDFCKM[i];
2122  }
2123  wt *= sumPDFCKM / overEstimatePDFCKM;
2124 
2125  // Choose id for mother in case of W.
2126  double pickId = sumPDFCKM * rndmPtr->flat();
2127  int iId = -1;
2128  int pmSize = possibleMothers.size();
2129  do pickId -= valPDFCKM[++iId];
2130  while (pickId > 0. && iId < pmSize);
2131  idMother = possibleMothers[iId];
2132  }
2133 
2134  // Warn if too big weight.
2135  if (wt > 1.) infoPtr->errorMsg("Warning in SimpleSpaceShower::pT2next"
2136  "Weak: weight is above unity.");
2137 
2138  // Iterate until acceptable pT (or have fallen below pTmin).
2139  } while (wt < rndmPtr->flat()) ;
2140 
2141  // Store outcome of enhanced branching rate analysis.
2142  splittingNameNow = nameNow;
2143  if (canEnhanceET && isEnhancedQ2QW)
2144  storeEnhanceFactor(pT2,"isr:Q2QW", enhanceNow);
2145 
2146  // Save values for (so far) acceptable branching.
2147  dipEndNow->store( idDaughter, idMother, idSister, x1Now, x2Now, m2Dip,
2148  pT2, z, xMother, Q2, mSister, m2Sister, pT2corr, 0, m2ColPair,
2149  mColPartner);
2150 
2151 }
2152 
2153 //--------------------------------------------------------------------------
2154 
2155 // Kinematics of branching.
2156 // Construct mother -> daughter + sister, with recoiler on other side.
2157 
2158 bool SimpleSpaceShower::branch( Event& event) {
2159 
2160  // Side on which branching occured.
2161  int side = abs(dipEndSel->side);
2162  double sideSign = (side == 1) ? 1. : -1.;
2163 
2164  // Read in flavour and colour variables.
2165  int iDaughter = partonSystemsPtr->getInA(iSysSel);
2166  int iRecoiler = partonSystemsPtr->getInB(iSysSel);
2167  if (side == 2) swap(iDaughter, iRecoiler);
2168  int idDaughterNow = dipEndSel->idDaughter;
2169  int idMother = dipEndSel->idMother;
2170  int idSister = dipEndSel->idSister;
2171  int idRecoiler = event[iRecoiler].id();
2172  int colDaughter = event[iDaughter].col();
2173  int acolDaughter = event[iDaughter].acol();
2174  int iColPartner = dipEndSel->iColPartner;
2175 
2176  // Recoil parton may be rescatterer, requiring special processing.
2177  bool normalRecoil = dipEndSel->normalRecoil;
2178  int iRecoilMother = event[iRecoiler].mother1();
2179 
2180  // Read in kinematical variables.
2181  double x1 = dipEndSel->x1;
2182  double x2 = dipEndSel->x2;
2183  double xMo = dipEndSel->xMo;
2184  double m2II = dipEndSel->m2Dip;
2185  double mII = sqrt(m2II);
2186  double pT2 = dipEndSel->pT2;
2187  double z = dipEndSel->z;
2188  double Q2 = dipEndSel->Q2;
2189  double mSister = dipEndSel->mSister;
2190  double m2Sister = dipEndSel->m2Sister;
2191  double pT2corr = dipEndSel->pT2corr;
2192  double x1New = (side == 1) ? xMo : x1;
2193  double x2New = (side == 2) ? xMo : x2;
2194 
2195  // Flag for gamma -> q qbar splittings.
2196  gamma2qqbar = false;
2197 
2198  // Current beam particle.
2199  BeamParticle& beamNow = (side == 1) ? *beamAPtr : *beamBPtr;
2200 
2201  // If gamma -> q qbar splitting and nMPI > 1 then only save pT2 value
2202  // and construct the kinematics in beamRemnants.
2203  if ( beamNow.isGamma() && idMother == 22 && infoPtr->nMPI() > 1 ) {
2204  gamma2qqbar = true;
2205  beamNow.resolvedGamma(false);
2206  beamNow.pT2gamma2qqbar(pT2corr);
2207  beamNow.gamVal(iSysSel);
2208  return true;
2209  }
2210 
2211  // Read in MEtype. Four-vectors to reconstruct.
2212  int MEtype = dipEndSel->MEtype;
2213  Vec4 pMother, pSister, pNewRec, pNewColPartner;
2214 
2215  // Rescatter: kinematics may fail; use the rescatterFail flag to tell
2216  // parton level to try again.
2217  rescatterFail = false;
2218 
2219  // Kinematics for II dipole.
2220  // Construct kinematics of mother, sister and recoiler in old rest frame.
2221  // Normally both mother and recoiler are taken massless.
2222  if (iColPartner == 0) {
2223  double eNewRec, pzNewRec, pTbranch, pzMother;
2224  if (normalRecoil) {
2225  eNewRec = 0.5 * (m2II + Q2) / mII;
2226  pzNewRec = -sideSign * eNewRec;
2227  pTbranch = sqrt(pT2corr) * m2II / ( z * (m2II + Q2) );
2228  pzMother = sideSign * 0.5 * mII * ( (m2II - Q2)
2229  / ( z * (m2II + Q2) ) + (Q2 + m2Sister) / m2II );
2230  // More complicated kinematics when recoiler not massless. May fail.
2231  } else {
2232  m2Rec = event[iRecoiler].m2();
2233  double s1Tmp = m2II + Q2 - m2Rec;
2234  double s3Tmp = m2II / z - m2Rec;
2235  double r1Tmp = sqrt(s1Tmp * s1Tmp + 4. * Q2 * m2Rec);
2236  eNewRec = 0.5 * (m2II + m2Rec + Q2) / mII;
2237  pzNewRec = -sideSign * 0.5 * r1Tmp / mII;
2238  double pT2br = Q2 * s3Tmp * (m2II / z - m2II - Q2)
2239  - m2Sister * s1Tmp * s3Tmp - m2Rec * pow2(Q2 + m2Sister);
2240  if (pT2br <= 0.) return false;
2241  pTbranch = sqrt(pT2br) / r1Tmp;
2242  pzMother = sideSign * (mII * s3Tmp
2243  - eNewRec * (m2II / z - Q2 - m2Rec - m2Sister)) / r1Tmp;
2244  }
2245  // Common final kinematics steps for both normal and rescattering.
2246  double eMother = sqrt( pow2(pTbranch) + pow2(pzMother) );
2247  double pzSister = pzMother + pzNewRec;
2248  double eSister = sqrt( pow2(pTbranch) + pow2(pzSister) + m2Sister );
2249  pMother.p( pTbranch, 0., pzMother, eMother );
2250  pSister.p( pTbranch, 0., pzSister, eSister );
2251  pNewRec.p( 0., 0., pzNewRec, eNewRec );
2252 
2253  // Kinematics of IF dipole.
2254  // Construct kinematics in old rest frame of daughter + colour partner.
2255  // Mother and recoiler massless but massive colour partner.
2256  } else {
2257  double m2IF = dipEndSel->m2IF;
2258  double mIF = sqrt(m2IF);
2259  m2ColPartner = pow2( dipEndSel->mColPartner );
2260 
2261  // Construct kinematics.
2262  double m2IFred = m2IF - m2ColPartner;
2263  pMother.p( 0., 0., 0.5 * m2IFred / (z * mIF), 0.5 * m2IFred / (z * mIF) );
2264  Vec4 pShift( 0., 0.,
2265  -0.5 * Q2 / mIF - z * (Q2 + m2Sister) * m2ColPartner / (mIF * m2IFred),
2266  -0.5 * Q2 / mIF + z * (Q2 + m2Sister) / mIF );
2267  pSister = (1. - z) * pMother + pShift;
2268  pNewColPartner = Vec4( 0., 0., -0.5 * m2IFred /mIF,
2269  0.5 * (m2IF + m2ColPartner) / mIF ) - pShift;
2270  // Do not change the momentum of the recoiler (in event frame).
2271  pNewRec.p( event[iRecoiler].p() );
2272 
2273  // Flat azimuthal angle.
2274  double phi = 2. * M_PI * rndmPtr->flat();
2275 
2276  // Evaluate coefficient of azimuthal asymmetry from gluon polarization.
2277  findAsymPol( event, dipEndSel);
2278  int iFinPol = dipEndSel->iFinPol;
2279  double cPol = dipEndSel->asymPol;
2280  double phiPol = (iFinPol == 0) ? 0. : event[iFinPol].phi();
2281 
2282  // Bias phi distribution for polarization.
2283  if (iFinPol != 0) {
2284  double cPhiPol, weight;
2285  // Boost back to the rest frame of daughter + recoiler.
2286  RotBstMatrix M;
2287  M.fromCMframe( event[iDaughter].p(), event[iColPartner].p() );
2288  double pTcorr = sqrt(pT2corr);
2289  do {
2290  phi = 2. * M_PI * rndmPtr->flat();
2291  weight = 1.;
2292  Vec4 pSisTmp = pSister + pTcorr * Vec4( cos(phi), sin(phi), 0., 0.);
2293  pSisTmp.rotbst(M);
2294  cPhiPol = cos(pSisTmp.phi() - phiPol);
2295  weight *= ( 1. + cPol * (2. * pow2(cPhiPol) - 1.) )
2296  / ( 1. + abs(cPol) );
2297  } while (weight < rndmPtr->flat());
2298  }
2299 
2300  // Add azimuthal part to the kinematics.
2301  pSister.px( sqrt(pT2corr) * cos(phi) );
2302  pSister.py( sqrt(pT2corr) * sin(phi) );
2303  pNewColPartner.px( - pSister.px() );
2304  pNewColPartner.py( - pSister.py() );
2305  }
2306 
2307  // Current event and subsystem size.
2308  int eventSizeOld = event.size();
2309  int systemSizeOld = partonSystemsPtr->sizeAll(iSysSel);
2310 
2311  // Save properties to be restored in case of user-hook veto of emission.
2312  int beamOff1 = 1 + beamOffset;
2313  int beamOff2 = 2 + beamOffset;
2314  int ev1Dau1V = event[beamOff1].daughter1();
2315  int ev2Dau1V = event[beamOff2].daughter1();
2316  vector<int> statusV, mother1V, mother2V, daughter1V, daughter2V;
2317 
2318  // Check if the first emission should be checked for removal.
2319  bool canMergeFirst = (mergingHooksPtr != 0)
2320  ? mergingHooksPtr->canVetoEmission() : false;
2321 
2322  // Check if doing uncertainty variations
2323  doUncertaintiesNow = doUncertainties;
2324  if (!uVarMPIshowers && iSysSel != 0) doUncertaintiesNow = false;
2325  if (pT2 < uVarpTmin2) doUncertaintiesNow = false;
2326 
2327  // Save further properties to be restored.
2328  if (canVetoEmission || canMergeFirst || canEnhanceET || doWeakShower
2329  || doUncertainties) {
2330  for ( int iCopy = 0; iCopy < systemSizeOld; ++iCopy) {
2331  int iOldCopy = partonSystemsPtr->getAll(iSysSel, iCopy);
2332  statusV.push_back( event[iOldCopy].status());
2333  mother1V.push_back( event[iOldCopy].mother1());
2334  mother2V.push_back( event[iOldCopy].mother2());
2335  daughter1V.push_back( event[iOldCopy].daughter1());
2336  daughter2V.push_back( event[iOldCopy].daughter2());
2337  }
2338  }
2339 
2340  // Take copy of existing system, to be given modified kinematics.
2341  // Incoming negative status. Rescattered also negative, but after copy.
2342  int iNewColPartner = 0;
2343  for ( int iCopy = 0; iCopy < systemSizeOld; ++iCopy) {
2344  int iOldCopy = partonSystemsPtr->getAll(iSysSel, iCopy);
2345  int statusOld = event[iOldCopy].status();
2346  int statusNew = (iOldCopy == iDaughter
2347  || iOldCopy == iRecoiler) ? statusOld : 44;
2348  int iNewCopy = event.copy(iOldCopy, statusNew);
2349  if (statusOld < 0) event[iNewCopy].statusNeg();
2350  if (iOldCopy == iColPartner) iNewColPartner = iNewCopy;
2351  }
2352 
2353  // Define colour flow in branching.
2354  // Default corresponds to f -> f + gamma.
2355  int colMother = colDaughter;
2356  int acolMother = acolDaughter;
2357  int colSister = 0;
2358  int acolSister = 0;
2359  if (idSister == 22 || idSister == 23 || abs(idSister) == 24) ;
2360  // q -> q + g and 50% of g -> g + g; need new colour.
2361  else if (idSister == 21 && ( (idMother > 0 && idMother < 9)
2362  || (idMother == 21 && rndmPtr->flat() < 0.5) ) ) {
2363  colMother = event.nextColTag();
2364  colSister = colMother;
2365  acolSister = colDaughter;
2366  // qbar -> qbar + g and other 50% of g -> g + g; need new colour.
2367  } else if (idSister == 21) {
2368  acolMother = event.nextColTag();
2369  acolSister = acolMother;
2370  colSister = acolDaughter;
2371  // q -> g + q.
2372  } else if (idDaughterNow == 21 && idMother > 0) {
2373  colMother = colDaughter;
2374  acolMother = 0;
2375  colSister = acolDaughter;
2376  // qbar -> g + qbar
2377  } else if (idDaughterNow == 21) {
2378  acolMother = acolDaughter;
2379  colMother = 0;
2380  acolSister = colDaughter;
2381  // g -> q + qbar but not gamma -> q + qbar.
2382  } else if ( (idDaughterNow > 0 && idDaughterNow < 9) && idMother != 22) {
2383  acolMother = event.nextColTag();
2384  acolSister = acolMother;
2385  // g -> qbar + q but not gamma -> qbar + q.
2386  } else if ( (idDaughterNow < 0 && idDaughterNow > -9) && idMother != 22) {
2387  colMother = event.nextColTag();
2388  colSister = colMother;
2389  // q -> gamma + q.
2390  } else if (idDaughterNow == 22 && idMother > 0) {
2391  colMother = event.nextColTag();
2392  colSister = colMother;
2393  // qbar -> gamma + qbar.
2394  } else if (idDaughterNow == 22) {
2395  acolMother = event.nextColTag();
2396  acolSister = acolMother;
2397  // gamma -> q + qbar.
2398  } else if ( (idDaughterNow > 0 && idDaughterNow < 9) && idMother == 22) {
2399  colMother = 0;
2400  acolMother = 0;
2401  acolSister = colDaughter;
2402  gamma2qqbar = true;
2403  // gamma -> qbar + q.
2404  } else if ( (idDaughterNow < 0 && idDaughterNow > -9) && idMother == 22) {
2405  colMother = 0;
2406  acolMother = 0;
2407  colSister = acolDaughter;
2408  gamma2qqbar = true;
2409  }
2410 
2411  // Indices of partons involved. Add new sister.
2412  int iMother = eventSizeOld + side - 1;
2413  int iNewRec = eventSizeOld + 2 - side;
2414  int iSister = event.append( idSister, 43, iMother, 0, 0, 0,
2415  colSister, acolSister, pSister, mSister, sqrt(pT2) );
2416 
2417  // References to the partons involved.
2418  Particle& daughter = event[iDaughter];
2419  Particle& mother = event[iMother];
2420  Particle& newRecoiler = event[iNewRec];
2421  Particle& sister = event.back();
2422 
2423  // Allow setting of vertex for daughter parton, recoiler and sister.
2424  if (doPartonVertex) {
2425  if (!daughter.hasVertex()) partonVertexPtr->vertexISR( iDaughter, event);
2426  if (!newRecoiler.hasVertex()) partonVertexPtr->vertexISR( iNewRec, event);
2427  if (!sister.hasVertex()) partonVertexPtr->vertexISR( iSister, event);
2428  }
2429 
2430  // Replace old by new mother; update new recoiler.
2431  mother.id( idMother );
2432  mother.status( -41);
2433  mother.cols( colMother, acolMother);
2434  mother.p( pMother);
2435  if (mother.idAbs() == 21 || mother.idAbs() == 22) mother.pol(9);
2436  newRecoiler.status( (normalRecoil) ? -42 : -46 );
2437  newRecoiler.p( pNewRec);
2438  if (!normalRecoil) newRecoiler.m( event[iRecoiler].m() );
2439  // Update the colour partner in case of dipole recoil.
2440  if (iNewColPartner != 0) event[iNewColPartner].p( pNewColPartner );
2441 
2442  // Update mother and daughter pointers; also for beams.
2443  daughter.mothers( iMother, 0);
2444  mother.daughters( iSister, iDaughter);
2445  if (iSysSel == 0) {
2446  event[beamOff1].daughter1( (side == 1) ? iMother : iNewRec );
2447  event[beamOff2].daughter1( (side == 2) ? iMother : iNewRec );
2448  }
2449 
2450  // Special checks to set weak particles status equal to 47.
2451  if (sister.idAbs() == 23 || sister.idAbs() == 24) sister.status(47);
2452 
2453  // Normal azimuth and boost procedure for II dipole.
2454  if (iNewColPartner == 0) {
2455 
2456  // Find boost to old rest frame.
2457  RotBstMatrix Mtot;
2458  if (normalRecoil) Mtot.bst(0., 0., (x2 - x1) / (x1 + x2) );
2459  else if (side == 1)
2460  Mtot.toCMframe( event[iDaughter].p(), event[iRecoiler].p() );
2461  else Mtot.toCMframe( event[iRecoiler].p(), event[iDaughter].p() );
2462 
2463  // Initially select phi angle of branching at random.
2464  double phi = 2. * M_PI * rndmPtr->flat();
2465 
2466  // Evaluate coefficient of azimuthal asymmetry from gluon polarization.
2467  findAsymPol( event, dipEndSel);
2468  int iFinPol = dipEndSel->iFinPol;
2469  double cPol = dipEndSel->asymPol;
2470  double phiPol = (iFinPol == 0) ? 0. : event[iFinPol].phi();
2471 
2472  // If interference: try to match sister (anti)colour to final state.
2473  int iFinInt = 0;
2474  double cInt = 0.;
2475  double phiInt = 0.;
2476  if (doPhiIntAsym) {
2477  for (int i = 0; i < partonSystemsPtr->sizeOut(iSysSel); ++ i) {
2478  int iOut = partonSystemsPtr->getOut(iSysSel, i);
2479  if ( (acolSister != 0 && event[iOut].col() == acolSister)
2480  || (colSister != 0 && event[iOut].acol() == colSister) )
2481  iFinInt = iOut;
2482  }
2483  if (iFinInt != 0) {
2484  // Boost final-state parton to current frame of new kinematics.
2485  Vec4 pFinTmp = event[iFinInt].p();
2486  pFinTmp.rotbst(Mtot);
2487  double theFin = pFinTmp.theta();
2488  if (side == 2) theFin = M_PI - theFin;
2489  double theSis = pSister.theta();
2490  if (side == 2) theSis = M_PI - theSis;
2491  cInt = strengthIntAsym * 2. * theSis * theFin
2492  / (pow2(theSis) + pow2(theFin));
2493  phiInt = event[iFinInt].phi();
2494  }
2495  }
2496 
2497  // Bias phi distribution for polarization and interference.
2498  if (iFinPol != 0 || iFinInt != 0) {
2499  double cPhiPol, cPhiInt, weight;
2500  do {
2501  phi = 2. * M_PI * rndmPtr->flat();
2502  weight = 1.;
2503  if (iFinPol !=0 ) {
2504  cPhiPol = cos(phi - phiPol);
2505  weight *= ( 1. + cPol * (2. * pow2(cPhiPol) - 1.) )
2506  / ( 1. + abs(cPol) );
2507  }
2508  if (iFinInt !=0 ) {
2509  cPhiInt = cos(phi - phiInt);
2510  weight *= (1. - cInt) * (1. - cInt * cPhiInt)
2511  / (1. + pow2(cInt) - 2. * cInt * cPhiInt);
2512  }
2513  } while (weight < rndmPtr->flat());
2514  }
2515 
2516  // Include rotation -phi on boost to old rest frame.
2517  Mtot.rot(0., -phi);
2518 
2519  // Find boost from old rest frame to event cm frame.
2520  RotBstMatrix MfromRest;
2521  // The boost to the new rest frame.
2522  Vec4 sumNew = pMother + pNewRec;
2523  double betaX = sumNew.px() / sumNew.e();
2524  double betaZ = sumNew.pz() / sumNew.e();
2525  MfromRest.bst( -betaX, 0., -betaZ);
2526  // Alignment of radiator + recoiler to +- z axis, and rotation +phi.
2527  // Note: with spacelike (E < 0) recoiler p'_x_mother < 0 can happen!
2528  pMother.rotbst(MfromRest);
2529  double theta = pMother.theta();
2530  if (pMother.px() < 0.) theta = -theta;
2531  if (side == 2) theta += M_PI;
2532  MfromRest.rot(-theta, phi);
2533  // Boost to radiator + recoiler in event cm frame.
2534  if (normalRecoil) {
2535  MfromRest.bst( 0., 0., (x1New - x2New) / (x1New + x2New) );
2536  } else if (side == 1) {
2537  Vec4 pMotherWanted( 0., 0., 0.5 * eCM * x1New, 0.5 * eCM * x1New);
2538  MfromRest.fromCMframe( pMotherWanted, event[iRecoiler].p() );
2539  } else {
2540  Vec4 pMotherWanted( 0., 0., -0.5 * eCM * x2New, 0.5 * eCM * x2New);
2541  MfromRest.fromCMframe( event[iRecoiler].p(), pMotherWanted );
2542  }
2543  Mtot.rotbst(MfromRest);
2544 
2545  // ME correction for weak emissions in the t-channel.
2546  double wt;
2547  if (MEtype == 201 || MEtype == 202 || MEtype == 203 ||
2548  MEtype == 206 || MEtype == 207 || MEtype == 208) {
2549 
2550  // Start by finding the correct outgoing particles for the ME correction.
2551  Vec4 pA0 = mother.p();
2552  Vec4 pB = newRecoiler.p();
2553  bool sideRad = (abs(side) == 1);
2554  Vec4 p1,p2;
2555  if (weakExternal) {
2556  p1 = weakMomenta[2];
2557  p2 = weakMomenta[3];
2558  } else {
2559  p1 = event[5].p();
2560  p2 = event[6].p();
2561  }
2562  if (!tChannel) swap(p1,p2);
2563  if (!sideRad) swap(p1,p2);
2564 
2565  // Rotate with -phi to keep correct for the later +phi rotation.
2566  p1.rot(0., -phi);
2567  p2.rot(0., -phi);
2568 
2569  // Calculate the actual weight.
2570  wt = calcMEcorrWeak(MEtype, m2II, z, pT2, pA0, pB,
2571  event[iDaughter].p(), event[iRecoiler].p(), p1, p2, sister.p());
2572  if (wt > weakMaxWt) {
2573  weakMaxWt = wt;
2574  infoPtr->errorMsg("Warning in SimpleSpaceShower::Branch: "
2575  "weight is above unity for weak emission.");
2576  }
2577 
2578  // If weighting fails then restore event record to state before emission.
2579  if (wt < rndmPtr->flat()) {
2580  event.popBack( event.size() - eventSizeOld);
2581  event[beamOff1].daughter1( ev1Dau1V);
2582  event[beamOff2].daughter1( ev2Dau1V);
2583  for ( int iCopy = 0; iCopy < systemSizeOld; ++iCopy) {
2584  int iOldCopy = partonSystemsPtr->getAll(iSysSel, iCopy);
2585  event[iOldCopy].status( statusV[iCopy]);
2586  event[iOldCopy].mothers( mother1V[iCopy], mother2V[iCopy]);
2587  event[iOldCopy].daughters( daughter1V[iCopy], daughter2V[iCopy]);
2588  }
2589  return false;
2590  }
2591  }
2592 
2593  // Perform cumulative rotation/boost operation.
2594  // Mother, recoiler and sister from old rest frame to event cm frame.
2595  mother.rotbst(MfromRest, false);
2596  newRecoiler.rotbst(MfromRest, false);
2597  sister.rotbst(MfromRest, false);
2598  // The rest from (and to) event cm frame.
2599  for ( int i = eventSizeOld + 2; i < eventSizeOld + systemSizeOld; ++i)
2600  event[i].rotbst(Mtot, false);
2601 
2602  // Simpler special boost procedure for IF dipole.
2603  } else {
2604 
2605  // Find boost from daughter + colour partner rest frame to the event frame.
2606  RotBstMatrix MfromRest;
2607  MfromRest.fromCMframe( event[iDaughter].p(), event[iColPartner].p() );
2608  // Boost mother, sister and new colour partner (recoiler already fine).
2609  mother.rotbst(MfromRest, false);
2610  sister.rotbst(MfromRest, false);
2611  event[iNewColPartner].rotbst(MfromRest, false);
2612  }
2613 
2614  // Remove double counting. Only implemented for QCD hard processes
2615  // and for the first emission.
2616  if (infoPtr->nISR() + infoPtr->nFSRinProc() == 0
2617  && infoPtr->code() > 110 && infoPtr->code() < 130
2618  && MEtype >= 200 && MEtype < 210 && vetoWeakJets) {
2619 
2620  // Find outgoing particles.
2621  int iP1 = event[5].daughter1();
2622  int iP2 = event[6].daughter1();
2623  Vec4 pP1 = event[iP1].p();
2624  Vec4 pP2 = event[iP2].p();
2625 
2626  // Set start pT2 as pT2 of emitted particle and therefore no cut.
2627  double d = sister.pT2();
2628  bool cut = false;
2629 
2630  if (pP1.pT2() < d) {d = pP1.pT2(); cut = true;}
2631  if (pP2.pT2() < d) {d = pP2.pT2(); cut = true;}
2632 
2633  // Check for angle between weak boson and quarks
2634  // (require final state particle to be a fermion).
2635  if (event[iP1].idAbs() < 20) {
2636  double dij = min(pP1.pT2(),sister.pT2())
2637  * pow2(RRapPhi(pP1,sister.p()))/vetoWeakDeltaR2;
2638  if (dij < d) {
2639  d = dij;
2640  cut = false;
2641  }
2642  }
2643 
2644  if (event[iP2].idAbs() < 20) {
2645  double dij = min(pP2.pT2(),sister.pT2())
2646  * pow2(RRapPhi(pP2,sister.p()))/vetoWeakDeltaR2;
2647  if (dij < d) {
2648  d = dij;
2649  cut = false;
2650  }
2651  }
2652 
2653  // Check for angle between recoiler and radiator, if quark anti-quark pair,
2654  // or if the recoiler is a gluon.
2655  if (event[iP1].idAbs() == 21 || event[iP2].idAbs() == 21 ||
2656  event[iP1].id() == - event[iP2].id()) {
2657  double dij = min(pP1.pT2(),pP2.pT2())
2658  * pow2(RRapPhi(pP1,pP2))/vetoWeakDeltaR2;
2659  if (dij < d) {
2660  d = dij;
2661  cut = true;
2662  }
2663  }
2664 
2665  // Clean up event if the emission should be removed.
2666  if (cut) {
2667  event.popBack( event.size() - eventSizeOld);
2668  event[beamOff1].daughter1( ev1Dau1V);
2669  event[beamOff2].daughter1( ev2Dau1V);
2670  for ( int iCopy = 0; iCopy < systemSizeOld; ++iCopy) {
2671  int iOldCopy = partonSystemsPtr->getAll(iSysSel, iCopy);
2672  event[iOldCopy].status( statusV[iCopy]);
2673  event[iOldCopy].mothers( mother1V[iCopy], mother2V[iCopy]);
2674  event[iOldCopy].daughters( daughter1V[iCopy], daughter2V[iCopy]);
2675  }
2676  return false;
2677  }
2678  }
2679 
2680  // Allow veto of branching. If so restore event record to before emission.
2681  if ( (canVetoEmission
2682  && userHooksPtr->doVetoISREmission(eventSizeOld, event, iSysSel))
2683  || (canMergeFirst
2684  && mergingHooksPtr->doVetoEmission( event )) ) {
2685  event.popBack( event.size() - eventSizeOld);
2686  event[beamOff1].daughter1( ev1Dau1V);
2687  event[beamOff2].daughter1( ev2Dau1V);
2688  for ( int iCopy = 0; iCopy < systemSizeOld; ++iCopy) {
2689  int iOldCopy = partonSystemsPtr->getAll(iSysSel, iCopy);
2690  event[iOldCopy].status( statusV[iCopy]);
2691  event[iOldCopy].mothers( mother1V[iCopy], mother2V[iCopy]);
2692  event[iOldCopy].daughters( daughter1V[iCopy], daughter2V[iCopy]);
2693  }
2694  return false;
2695  }
2696 
2697  // Recover delayed shower-accept probability for uncertainty variations.
2698  // This should occur after ISR emission veto, because that is a
2699  // phase space restriction.
2700  double pAccept = dipEndSel->pAccept;
2701 
2702  // Decide if we are going to accept or reject this branching.
2703  // (Without wasting time generating random numbers if pAccept = 1.)
2704  bool acceptEvent = true;
2705  if (pAccept < 1.0) acceptEvent = (rndmPtr->flat() < pAccept);
2706 
2707  // Default values for uncertainty calculations
2708  double weight = 1.;
2709  double vp = 0.;
2710  bool vetoedEnhancedEmission = false;
2711 
2712  // Calculate event weight for enhanced emission rate.
2713  if (canEnhanceET) {
2714  // Check if emission weight was enhanced. Get enhance weight factor.
2715  bool foundEnhance = false;
2716  // Move backwards as last elements have highest pT, thus are chosen
2717  // splittings.
2718  for ( map<double,pair<string,double> >::reverse_iterator
2719  it = enhanceFactors.rbegin();
2720  it != enhanceFactors.rend(); ++it ){
2721  if (splittingNameSel.find(it->second.first) != string::npos
2722  && abs(it->second.second-1.0) > 1e-9) {
2723  foundEnhance = true;
2724  weight = it->second.second;
2725  vp = userHooksPtr->vetoProbability(splittingNameSel);
2726  break;
2727  }
2728  }
2729 
2730  // Check emission veto.
2731  if (foundEnhance && rndmPtr->flat() < vp ) vetoedEnhancedEmission = true;
2732  // Calculate new event weight.
2733  double rwgt = 1.;
2734  if (foundEnhance && vetoedEnhancedEmission) rwgt *= (1.-1./weight)/vp;
2735  else if (foundEnhance) rwgt *= 1./((1.-vp)*weight);
2736 
2737  // Reset enhance factors after usage.
2738  enhanceFactors.clear();
2739 
2740  // Set events weights, so that these could be used externally.
2741  double wtOld = userHooksPtr->getEnhancedEventWeight();
2742  if (!doTrialNow && canEnhanceEmission && !doUncertaintiesNow)
2743  userHooksPtr->setEnhancedEventWeight(wtOld*rwgt);
2744  if ( doTrialNow && canEnhanceTrial)
2745  userHooksPtr->setEnhancedTrial(sqrt(pT2), weight);
2746  // Increment counter of rejected splittings.
2747  if (vetoedEnhancedEmission && canEnhanceEmission)
2748  infoPtr->addCounter(40);
2749  }
2750 
2751  if (vetoedEnhancedEmission) acceptEvent = false;
2752 
2753  // If doing uncertainty variations, calculate accept/reject reweightings.
2754  if (doUncertaintiesNow) calcUncertainties( acceptEvent, pAccept, pT20,
2755  weight, vp, dipEndSel, &mother, &sister);
2756 
2757  // Veto if necessary.
2758  // Return false if we decided to reject this branching.
2759  if ( (doUncertainties && !acceptEvent)
2760  || (vetoedEnhancedEmission && canEnhanceEmission) ) {
2761  // Restore kinematics before returning.
2762  event.popBack( event.size() - eventSizeOld);
2763  event[beamOff1].daughter1( ev1Dau1V);
2764  event[beamOff2].daughter1( ev2Dau1V);
2765  for ( int iCopy = 0; iCopy < systemSizeOld; ++iCopy) {
2766  int iOldCopy = partonSystemsPtr->getAll(iSysSel, iCopy);
2767  event[iOldCopy].status( statusV[iCopy]);
2768  event[iOldCopy].mothers( mother1V[iCopy], mother2V[iCopy]);
2769  event[iOldCopy].daughters( daughter1V[iCopy], daughter2V[iCopy]);
2770  }
2771  return false;
2772  }
2773 
2774  // Update list of partons in system; adding newly produced one.
2775  partonSystemsPtr->setInA(iSysSel, eventSizeOld);
2776  partonSystemsPtr->setInB(iSysSel, eventSizeOld + 1);
2777  for (int iCopy = 2; iCopy < systemSizeOld; ++iCopy)
2778  partonSystemsPtr->setOut(iSysSel, iCopy - 2, eventSizeOld + iCopy);
2779  partonSystemsPtr->addOut(iSysSel, eventSizeOld + systemSizeOld);
2780  partonSystemsPtr->setSHat(iSysSel, m2II / z);
2781 
2782  // Add dipoles for q -> g q, where the daughter is the gluon.
2783  if (idDaughter == 21 && idMother != 21) {
2784  if (doQEDshowerByQ) {
2785  dipEnd.push_back( SpaceDipoleEnd( iSysSel, side, iMother,
2786  iNewRec, pT2, 0, mother.chargeType(), 0, 0, normalRecoil) );
2787  }
2788  if (doWeakShower && iSysSel == 0) {
2789  int MEtypeNew = 203;
2790  if (idRecoiler == 21) MEtypeNew = 201;
2791  if (idRecoiler == idMother) MEtypeNew = 202;
2792  // If original was a Drell-Yan, keep as Drell-Yan.
2793  if( event[3].id() == - event[4].id()) MEtypeNew = 200;
2794  int weakPol = (rndmPtr->flat() > 0.5) ? -1 : 1;
2795  event[iMother].pol(weakPol);
2796  if ((weakMode == 0 || weakMode == 1) && weakPol == -1)
2797  dipEnd.push_back( SpaceDipoleEnd( iSysSel, side, iMother,
2798  iNewRec, pT2, 0, 0, 1, MEtypeNew, normalRecoil, weakPol) );
2799  if (weakMode == 0 || weakMode == 2)
2800  dipEnd.push_back( SpaceDipoleEnd( iSysSel, side, iMother,
2801  iNewRec, pT2, 0, 0, 2, MEtypeNew + 5, normalRecoil, weakPol) );
2802  }
2803  }
2804 
2805  // Add dipoles for q -> q gamma, where the daughter is the gamma.
2806  if (idDaughter == 22 && idMother != 22) {
2807  if (doQCDshower && mother.colType() != 0) {
2808  dipEnd.push_back( SpaceDipoleEnd( iSysSel, side, iMother,
2809  iNewRec, pT2, mother.colType(), 0, 0, 0, normalRecoil) );
2810  }
2811  if (doQEDshowerByQ && mother.chargeType() != 3) {
2812  dipEnd.push_back( SpaceDipoleEnd( iSysSel, side, iMother,
2813  iNewRec, pT2, 0, mother.chargeType(), 0, 0, normalRecoil) );
2814  }
2815  if (doQEDshowerByL && mother.chargeType() == 3) {
2816  dipEnd.push_back( SpaceDipoleEnd( iSysSel, side, iMother,
2817  iNewRec, pT2, 0, mother.chargeType(), 0, 0, normalRecoil) );
2818  }
2819  if (doWeakShower && iSysSel == 0) {
2820  int MEtypeNew = 203;
2821  if (idRecoiler == 21) MEtypeNew = 201;
2822  if (idRecoiler == idMother) MEtypeNew = 202;
2823  // If original was a Drell-Yan, keep as Drell-Yan.
2824  if( event[3].id() == - event[4].id()) MEtypeNew = 200;
2825  int weakPol = (rndmPtr->flat() > 0.5) ? -1 : 1;
2826  event[iMother].pol(weakPol);
2827  if ((weakMode == 0 || weakMode == 1) && weakPol == -1)
2828  dipEnd.push_back( SpaceDipoleEnd( iSysSel, side, iMother,
2829  iNewRec, pT2, 0, 0, 1, MEtypeNew, normalRecoil, weakPol) );
2830  if (weakMode == 0 || weakMode == 2)
2831  dipEnd.push_back( SpaceDipoleEnd( iSysSel, side, iMother,
2832  iNewRec, pT2, 0, 0, 2, MEtypeNew + 5, normalRecoil, weakPol) );
2833  }
2834  }
2835 
2836  // dipEnd array may have expanded and been moved, so regenerate dipEndSel.
2837  dipEndSel = &dipEnd[iDipSel];
2838 
2839  // Set flag to tell that a weak emission has happened.
2840  if (dipEndSel->weakType != 0) hasWeaklyRadiated = true;
2841 
2842  // Update list of QCD emissions in side A and B in given iSysSel
2843  // This is used to veto jets in W/z events.
2844  while (iSysSel >= int(nRadA.size()) || iSysSel >= int(nRadB.size())) {
2845  nRadA.push_back(0);
2846  nRadB.push_back(0);
2847  }
2848  if (dipEndSel->colType != 0 && side == 1) ++nRadA[iSysSel];
2849  else if (dipEndSel->colType != 0) ++nRadB[iSysSel];
2850 
2851  // Update info on radiating dipole ends (QCD, QED or weak).
2852  for (int iDip = 0; iDip < int(dipEnd.size()); ++iDip)
2853  if ( dipEnd[iDip].system == iSysSel) {
2854  if (abs(dipEnd[iDip].side) == side) {
2855  dipEnd[iDip].iRadiator = iMother;
2856  dipEnd[iDip].iRecoiler = iNewRec;
2857  // Look if there is a IF dipole in case of dipole recoil.
2858  dipEnd[iDip].iColPartner = (doDipoleRecoil) ? findColPartner( event,
2859  dipEnd[iDip].iRadiator, dipEnd[iDip].iRecoiler, iSysSel) : 0;
2860  dipEnd[iDip].idColPartner = (dipEnd[iDip].iColPartner != 0)
2861  ? event[dipEnd[iDip].iColPartner].id() : 0;
2862  if (dipEnd[iDip].colType != 0)
2863  dipEnd[iDip].colType = mother.colType();
2864  else if (dipEnd[iDip].chgType != 0) {
2865  dipEnd[iDip].chgType = 0;
2866  if ( (mother.isQuark() && doQEDshowerByQ)
2867  || (mother.isLepton() && doQEDshowerByL) )
2868  dipEnd[iDip].chgType = mother.chargeType();
2869  }
2870  else if (dipEnd[iDip].weakType != 0) {
2871  // Kill weak dipole if mother becomes gluon / photon.
2872  if (!(mother.isLepton() || mother.isQuark()))
2873  dipEnd[iDip].weakType = 0;
2874  if (singleWeakEmission && hasWeaklyRadiated)
2875  dipEnd[iDip].weakType = 0;
2876  }
2877 
2878  // Kill ME corrections after first emission for everything
2879  // but weak showers.
2880  if (dipEnd[iDip].weakType == 0) dipEnd[iDip].MEtype = 0;
2881 
2882  // Update info on recoiling dipole ends (QCD or QED).
2883  } else {
2884  dipEnd[iDip].iRadiator = iNewRec;
2885  dipEnd[iDip].iRecoiler = iMother;
2886  // Look if there is an IF dipole in case of dipole recoil.
2887  dipEnd[iDip].iColPartner = (doDipoleRecoil) ? findColPartner( event,
2888  dipEnd[iDip].iRadiator, dipEnd[iDip].iRecoiler, iSysSel) : 0;
2889  dipEnd[iDip].idColPartner = (dipEnd[iDip].iColPartner != 0)
2890  ? event[dipEnd[iDip].iColPartner].id() : 0;
2891  // Optionally also kill recoiler ME corrections after first emission.
2892  if (!doMEafterFirst && dipEnd[iDip].weakType == 0)
2893  dipEnd[iDip].MEtype = 0;
2894  // Remove weak dipoles if we only want a single emission.
2895  if (dipEnd[iDip].weakType != 0 && singleWeakEmission
2896  && hasWeaklyRadiated) dipEnd[iDip].weakType = 0;
2897  }
2898  }
2899 
2900  // Set polarisation of mother for weak emissions.
2901  if (dipEndSel->weakType != 0) mother.pol(dipEndSel->weakPol);
2902 
2903  // Update info on beam remnants.
2904  double xNew = (side == 1) ? x1New : x2New;
2905  beamNow[iSysSel].update( iMother, idMother, xNew);
2906  // Redo choice of companion kind whenever new flavour.
2907  if (idMother != idDaughterNow) {
2908  pdfScale2 = (useFixedFacScale) ? fixedFacScale2 : factorMultFac * pT2;
2909  beamNow.xfISR( iSysSel, idMother, xNew, pdfScale2);
2910  beamNow.pickValSeaComp();
2911  }
2912  BeamParticle& beamRec = (side == 1) ? *beamBPtr : *beamAPtr;
2913  beamRec[iSysSel].iPos( iNewRec);
2914 
2915  // Store branching values of current dipole. (For rapidity ordering.)
2916  ++dipEndSel->nBranch;
2917  dipEndSel->pT2Old = pT2;
2918  dipEndSel->zOld = z;
2919 
2920  // Update history if recoiler rescatters.
2921  if (!normalRecoil)
2922  event[iRecoilMother].daughters( iNewRec, iNewRec);
2923 
2924  // Start list of rescatterers that force changed kinematics.
2925  vector<int> iRescatterer;
2926  for ( int i = 0; i < systemSizeOld - 2; ++i) {
2927  int iOutNew = partonSystemsPtr->getOut( iSysSel, i);
2928  if (!event[iOutNew].isFinal()) iRescatterer.push_back(iOutNew);
2929  }
2930 
2931  // Start iterate over list of such rescatterers.
2932  int iRescNow = -1;
2933  while (++iRescNow < int(iRescatterer.size())) {
2934 
2935  // Identify partons that induce or are affected by rescatter shift.
2936  // In following Old is before change of kinematics, New after,
2937  // Out scatterer in outstate and In in instate of another system.
2938  // Daughter sequence is (iOutOld ->) iOutNew -> iInNew -> iInOld.
2939  int iOutNew = iRescatterer[iRescNow];
2940  int iInOld = event[iOutNew].daughter1();
2941  int iSysResc = partonSystemsPtr->getSystemOf(iInOld, true);
2942 
2943  // Copy incoming partons of rescattered system and hook them up.
2944  int iOldA = partonSystemsPtr->getInA(iSysResc);
2945  int iOldB = partonSystemsPtr->getInB(iSysResc);
2946  bool rescSideA = event[iOldA].isRescatteredIncoming();
2947  int statusNewA = (rescSideA) ? -45 : -42;
2948  int statusNewB = (rescSideA) ? -42 : -45;
2949  int iNewA = event.copy(iOldA, statusNewA);
2950  int iNewB = event.copy(iOldB, statusNewB);
2951 
2952  // Copy outgoing partons of rescattered system and hook them up.
2953  int eventSize = event.size();
2954  int sizeOutAB = partonSystemsPtr->sizeOut(iSysResc);
2955  int iOldAB, statusOldAB, iNewAB;
2956  for (int iOutAB = 0; iOutAB < sizeOutAB; ++iOutAB) {
2957  iOldAB = partonSystemsPtr->getOut(iSysResc, iOutAB);
2958  statusOldAB = event[iOldAB].status();
2959  iNewAB = event.copy(iOldAB, 44);
2960  // Status could be negative for parton that rescatters in its turn.
2961  if (statusOldAB < 0) {
2962  event[iNewAB].statusNeg();
2963  iRescatterer.push_back(iNewAB);
2964  }
2965  }
2966 
2967  // Hook up new outgoing with new incoming parton.
2968  int iInNew = (rescSideA) ? iNewA : iNewB;
2969  event[iOutNew].daughters( iInNew, iInNew);
2970  event[iInNew].mothers( iOutNew, iOutNew);
2971 
2972  // Rescale recoiling incoming parton for correct invariant mass.
2973  event[iInNew].p( event[iOutNew].p() );
2974  double momFac = (rescSideA)
2975  ? event[iInOld].pPos() / event[iInNew].pPos()
2976  : event[iInOld].pNeg() / event[iInNew].pNeg();
2977  int iInRec = (rescSideA) ? iNewB : iNewA;
2978 
2979  // Rescatter: A previous boost may cause the light cone momentum of a
2980  // rescattered parton to change sign. If this happens, tell
2981  // parton level to try again.
2982  if (momFac < 0.0) {
2983  infoPtr->errorMsg("Warning in SimpleSpaceShower::branch: "
2984  "change in lightcone momentum sign; retrying parton level");
2985  rescatterFail = true;
2986  return false;
2987  }
2988  event[iInRec].rescale4( momFac);
2989 
2990  // Boost outgoing partons to new frame of incoming.
2991  RotBstMatrix MmodResc;
2992  MmodResc.toCMframe( event[iOldA].p(), event[iOldB].p());
2993  MmodResc.fromCMframe(event[iNewA].p(), event[iNewB].p());
2994  for (int iOutAB = 0; iOutAB < sizeOutAB; ++iOutAB)
2995  event[eventSize + iOutAB].rotbst(MmodResc, false);
2996 
2997  // Update list of partons in system.
2998  partonSystemsPtr->setInA(iSysResc, iNewA);
2999  partonSystemsPtr->setInB(iSysResc, iNewB);
3000  for (int iCopy = 0; iCopy < sizeOutAB; ++iCopy)
3001  partonSystemsPtr->setOut(iSysResc, iCopy, eventSize + iCopy);
3002 
3003  // Update info on radiating dipole ends (QCD or QED).
3004  for (int iDip = 0; iDip < int(dipEnd.size()); ++iDip)
3005  if ( dipEnd[iDip].system == iSysResc) {
3006  bool sideAnow = (abs(dipEnd[iDip].side) == 1);
3007  dipEnd[iDip].iRadiator = (sideAnow) ? iNewA : iNewB;
3008  dipEnd[iDip].iRecoiler = (sideAnow) ? iNewB : iNewA;
3009  }
3010 
3011  // Update info on beam remnants.
3012  BeamParticle& beamResc = (rescSideA) ? *beamAPtr : *beamBPtr;
3013  beamResc[iSysResc].iPos( iInNew);
3014  beamResc[iSysResc].p( event[iInNew].p() );
3015  beamResc[iSysResc].scaleX( 1. / momFac );
3016  BeamParticle& beamReco = (rescSideA) ? *beamBPtr : *beamAPtr;
3017  beamReco[iSysResc].iPos( iInRec);
3018  beamReco[iSysResc].scaleX( momFac);
3019 
3020  // End iterate over list of rescatterers.
3021  }
3022 
3023  // Check that beam momentum not used up by rescattered-system boosts.
3024  if ( ( beamAPtr->xMax(-1) < 0.0 && !(beamAPtr->isUnresolved()) )
3025  || ( beamBPtr->xMax(-1) < 0.0 && !(beamBPtr->isUnresolved()) ) ) {
3026  infoPtr->errorMsg("Warning in SimpleSpaceShower::branch: "
3027  "used up beam momentum; retrying parton level");
3028  rescatterFail = true;
3029  return false;
3030  }
3031 
3032  // If gamma -> q qbar valid with photon beam no need for remnants.
3033  if ( beamNow.isGamma() && beamNow.resolvedGamma() && gamma2qqbar)
3034  beamNow.resolvedGamma(false);
3035 
3036  // Done without any errors.
3037  return true;
3038 
3039 }
3040 
3041 //--------------------------------------------------------------------------
3042 
3043 // Initialize the choices of uncertainty variations of the shower.
3044 
3045 bool SimpleSpaceShower::initUncertainties() {
3046 
3047  // Only initialize once
3048  if( nUncertaintyVariations ) return(nUncertaintyVariations);
3049 
3050  // Populate lists of uncertainty variations for SimpleSpaceShower,
3051  // by keyword.
3052  uVarMuSoftCorr = flag("UncertaintyBands:muSoftCorr");
3053  dASmax = parm("UncertaintyBands:deltaAlphaSmax");
3054 
3055  // Reset uncertainty variation maps.
3056  varG2GGmuRfac.clear(); varG2GGcNS.clear();
3057  varQ2QGmuRfac.clear(); varQ2QGcNS.clear();
3058  varQ2GQmuRfac.clear(); varQ2GQcNS.clear();
3059  varX2XGmuRfac.clear(); varX2XGcNS.clear();
3060  varG2QQmuRfac.clear(); varG2QQcNS.clear();
3061  // Maps that must be known by TimeShower
3062  varPDFplus = &weightContainerPtr->weightsPS.varPDFplus;
3063  varPDFminus = &weightContainerPtr->weightsPS.varPDFminus;
3064  varPDFmember = &weightContainerPtr->weightsPS.varPDFmember;
3065  varPDFplus->clear();
3066  varPDFminus->clear();
3067  varPDFmember->clear();
3068 
3069  vector<string> keys;
3070  // List of keywords recognised by SimpleSpaceShower.
3071  keys.push_back("isr:murfac");
3072  keys.push_back("isr:g2gg:murfac");
3073  keys.push_back("isr:q2qg:murfac");
3074  keys.push_back("isr:q2gq:murfac");
3075  keys.push_back("isr:x2xg:murfac");
3076  keys.push_back("isr:g2qq:murfac");
3077  keys.push_back("isr:cns");
3078  keys.push_back("isr:g2gg:cns");
3079  keys.push_back("isr:q2qg:cns");
3080  keys.push_back("isr:q2gq:cns");
3081  keys.push_back("isr:x2xg:cns");
3082  keys.push_back("isr:g2qq:cns");
3083  keys.push_back("isr:pdf:plus");
3084  keys.push_back("isr:pdf:minus");
3085  keys.push_back("isr:pdf:member");
3086 
3087  // Store number of QCD variations (as separator to QED ones).
3088  int nKeysQCD=keys.size();
3089 
3090  // Get atomized variation strings, not necessarily all relevant for FSR
3091  vector<string> uniqueVarsIn = weightContainerPtr->weightsPS.
3092  getUniqueShowerVars();
3093  size_t varSize = uniqueVarsIn.size();
3094  if (varSize == 0) {
3095  nUncertaintyVariations = varSize;
3096  return false;
3097  }
3098  vector<string> uniqueVars;
3099 
3100  // Expand uVars if PDFmembers has been chosen
3101  string tmpKey("isr:pdf:family");
3102  // Parse each string in uniqueVarsIn to look for recognized keywords.
3103  for (string uVarString: uniqueVarsIn) {
3104  int firstEqual = uVarString.find_first_of("=");
3105  string testString = uVarString.substr(0, firstEqual);
3106  // does the key match an fsr one?
3107  if( find(keys.begin(), keys.end(), testString) != keys.end() ) {
3108  if( uniqueVars.size() == 0 ) {
3109  uniqueVars.push_back(uVarString);
3110  } else if ( find(uniqueVars.begin(), uniqueVars.end(), uVarString)
3111  == uniqueVars.end() ) {
3112  uniqueVars.push_back(uVarString);
3113  }
3114  } else if ( testString == tmpKey ) {
3115  int nMembers(0);
3116  BeamParticle& beam = *beamAPtr;
3117  nMembers = beam.nMembers();
3118  for(int iMem=1; iMem<nMembers; ++iMem) {
3119  ostringstream iss;
3120  iss << iMem;
3121  string tmpString("isr:pdf:member="+iss.str());
3122  if (find(uniqueVars.begin(), uniqueVars.end(), tmpString)
3123  == uniqueVars.end() ) {
3124  uniqueVars.push_back(tmpString);
3125  }
3126  }
3127  }
3128  }
3129 
3130  nUncertaintyVariations = int(uniqueVars.size());
3131 
3132  if ( nUncertaintyVariations > 0 ) {
3133  int nWeights = weightContainerPtr->weightsPS.getWeightsSize();
3134  int newSize = nWeights + nUncertaintyVariations;
3135  for(int iWeight = nWeights; iWeight < newSize; ++iWeight) {
3136  string uVarString = uniqueVars[iWeight - nWeights];
3137  weightContainerPtr->weightsPS.bookWeight(uVarString);
3138  // Parse each string in uVars to look for recognised keywords.
3139  // Convert to lowercase (to be case-insensitive). Also remove "=" signs
3140  // and extra spaces, so "key=value", "key = value" mapped to "key value"
3141 
3142  while (uVarString.find("=") != string::npos) {
3143  int firstEqual = uVarString.find_first_of("=");
3144  uVarString.replace(firstEqual, 1, " ");
3145  }
3146  while (uVarString.find(" ") != string::npos)
3147  uVarString.erase( uVarString.find(" "), 1);
3148  if (uVarString == "" || uVarString == " ") continue;
3149 
3150  // Loop over all keywords.
3151  int nRecognizedQCD = 0;
3152  for (int iWord = 0; iWord < int(keys.size()); ++iWord) {
3153  // Transform string to lowercase to avoid case-dependence.
3154  string key = toLower(keys[iWord]);
3155  // Extract variation value/factor.
3156  int iKey = uVarString.find(key);
3157  int iBeg = uVarString.find(" ", iKey) + 1;
3158  int iEnd = uVarString.find(" ", iBeg);
3159  string valueString = uVarString.substr(iBeg, iEnd - iBeg);
3160  stringstream ss(valueString);
3161  double value;
3162  ss >> value;
3163  if (!ss) continue;
3164 
3165  // Store (iWeight,value) pairs
3166  // RECALL: use lowercase for all keys here (since converted above).
3167  if (key == "isr:murfac" || key == "isr:g2gg:murfac")
3168  varG2GGmuRfac[iWeight] = value;
3169  if (key == "isr:murfac" || key == "isr:q2qg:murfac")
3170  varQ2QGmuRfac[iWeight] = value;
3171  if (key == "isr:murfac" || key == "isr:q2gq:murfac")
3172  varQ2GQmuRfac[iWeight] = value;
3173  if (key == "isr:murfac" || key == "isr:x2xg:murfac")
3174  varX2XGmuRfac[iWeight] = value;
3175  if (key == "isr:murfac" || key == "isr:g2qq:murfac")
3176  varG2QQmuRfac[iWeight] = value;
3177  if (key == "isr:cns" || key == "isr:g2gg:cns")
3178  varG2GGcNS[iWeight] = value;
3179  if (key == "isr:cns" || key == "isr:q2qg:cns")
3180  varQ2QGcNS[iWeight] = value;
3181  if (key == "isr:cns" || key == "isr:q2gq:cns")
3182  varQ2GQcNS[iWeight] = value;
3183  if (key == "isr:cns" || key == "isr:x2xg:cns")
3184  varX2XGcNS[iWeight] = value;
3185  if (key == "isr:cns" || key == "isr:g2qq:cns")
3186  varG2QQcNS[iWeight] = value;
3187  if (key == "isr:pdf:plus") varPDFplus->operator[](iWeight) = 1;
3188  if (key == "isr:pdf:minus") varPDFminus->operator[](iWeight) = 1;
3189  if (key == "isr:pdf:member")
3190  varPDFmember->operator[](iWeight) = int(value);
3191  // Tell that we found at least one recognized and parseable keyword.
3192  if (iWord < nKeysQCD) nRecognizedQCD++;
3193  } // End loop over QCD keywords
3194 
3195  // Tell whether this uncertainty variation contained >= 1 QCD variation.
3196  if (nRecognizedQCD > 0) ++nVarQCD;
3197  } // End loop over UVars.
3198  }
3199 
3200  // Let the calling function know if we found anything.
3201  return (nVarQCD > 0);
3202 }
3203 
3204 //--------------------------------------------------------------------------
3205 
3206 // Calculate uncertainties for the current event.
3207 
3208 void SimpleSpaceShower::calcUncertainties(bool accept, double pAccept,
3209  double pT20in, double enhance, double vp, SpaceDipoleEnd* dip,
3210  Particle* motPtr, Particle* sisPtr) {
3211 
3212  // Sanity check.
3213  if (!doUncertainties || !doUncertaintiesNow || nUncertaintyVariations <= 0)
3214  return;
3215 
3216  // Define pointer and iterator to loop over the contents of each
3217  // (iWeight,value) map.
3218  map<int,double>* varPtr=0;
3219  map<int,double>::iterator itVar;
3220  // Make sure we have a dummy to point to if no map to be used.
3221  map<int,double> dummy; dummy.clear();
3222 
3223  int numWeights = weightContainerPtr->weightsPS.getWeightsSize();
3224  // Store uncertainty variation factors, initialised to unity.
3225  // Make vector sizes + 1 since 0 = default and variations start at 1.
3226  vector<double> uVarFac(numWeights, 1.0);
3227  vector<bool> doVar(numWeights, false);
3228  // When performing biasing, the nominal weight need not be unity.
3229  doVar[0] = true;
3230  uVarFac[0] = 1.0;
3231 
3232  // Extract IDs, with standard ISR nomenclature: mot -> dau(Q2) + sis
3233  int idSis = sisPtr->id();
3234  int idMot = motPtr->id();
3235 
3236  // PDF variations
3237  if ( !varPDFplus->empty() || !varPDFminus->empty() || !varPDFmember->empty()
3238  ) {
3239  // Evaluation of new daughter and mother PDF's.
3240  double scale2 = (useFixedFacScale) ? fixedFacScale2
3241  : factorMultFac * dip->pT2;
3242  double xMother = dip->xMo;
3243  double xDau = dip->z * xMother;
3244  BeamParticle& beam = (abs(dip->side) == 1) ? *beamAPtr : *beamBPtr;
3245  int valSea = (beam[iSysSel].isValence()) ? 1 : 0;
3246  if( beam[iSysSel].isUnmatched() ) valSea = 2;
3247  beam.calcPDFEnvelope( make_pair(dip->idMother,dip->idDaughter),
3248  make_pair(xMother,xDau), scale2, valSea);
3249  PDF::PDFEnvelope ratioPDFEnv = beam.getPDFEnvelope( );
3250  //
3251  varPtr = varPDFplus;
3252  for (itVar = varPtr->begin(); itVar != varPtr->end(); ++itVar) {
3253  int iWeight = itVar->first;
3254  uVarFac[iWeight] *= 1.0 + min(ratioPDFEnv.errplusPDF
3255  / ratioPDFEnv.centralPDF, 0.5);
3256  doVar[iWeight] = true;
3257  }
3258  //
3259  varPtr = varPDFminus;
3260  for (itVar = varPtr->begin(); itVar != varPtr->end(); ++itVar) {
3261  int iWeight = itVar->first;
3262  uVarFac[iWeight] *= max(.01,1.0 - min(ratioPDFEnv.errminusPDF
3263  / ratioPDFEnv.centralPDF, 0.5));
3264  doVar[iWeight] = true;
3265  }
3266  varPtr = varPDFmember;
3267  for (itVar = varPtr->begin(); itVar != varPtr->end(); ++itVar) {
3268  int iWeight = itVar->first;
3269  int member = int( itVar->second );
3270  uVarFac[iWeight] *= max(.01,ratioPDFEnv.pdfMemberVars[member]
3271  / ratioPDFEnv.centralPDF);
3272  doVar[iWeight] = true;
3273  }
3274  }
3275 
3276  // QCD variations.
3277  if (dip->colType != 0) {
3278 
3279  // QCD renormalization-scale variations.
3280  if (alphaSorder == 0) varPtr = &dummy;
3281  else if (idMot == 21 && idSis == 21) varPtr = &varG2GGmuRfac;
3282  else if (idMot == 21 && abs(idSis) <= nQuarkIn) varPtr = &varG2QQmuRfac;
3283  else if (abs(idMot) <= nQuarkIn) {
3284  if (abs(idMot) <= uVarNflavQ) varPtr = &varQ2QGmuRfac;
3285  else varPtr = &varX2XGmuRfac;
3286  }
3287  else varPtr = &dummy;
3288  double Q2 = dip->pT2;
3289  double muR2 = renormMultFac * (Q2 + pT20in);
3290  double alphaSbaseline = alphaS.alphaS(muR2);
3291  for (itVar = varPtr->begin(); itVar != varPtr->end(); ++itVar) {
3292  int iWeight = itVar->first;
3293  double valFac = itVar->second;
3294  // Correction-factor alphaS.
3295  double muR2var = max(1.1 * Lambda3flav2, pow2(valFac) * muR2);
3296  double alphaSratio = alphaS.alphaS(muR2var) / alphaSbaseline;
3297  // Apply soft correction factor only for (on-shell) gluon emission
3298  double facCorr = 1.;
3299  if (idSis == 21 && uVarMuSoftCorr) {
3300  // Use smallest alphaS and b0, to make the compensation conservative.
3301  int nf = 5;
3302  if (dip->pT2 < pow2(mc)) nf = 3;
3303  else if (dip->pT2 < pow2(mb)) nf = 4;
3304  double alphaScorr = alphaS.alphaS(dip->m2Dip);
3305  double facSoft = alphaScorr * (33. - 2. * nf) / (6. * M_PI);
3306  // Zeta is energy fraction of emitted (on-shell) gluon = 1 - z.
3307  double zeta = 1. - dip->z;
3308  facCorr = 1. + (1. - zeta) * facSoft * log(valFac);
3309  }
3310  // Apply correction factor here for emission processes.
3311  double alphaSfac = alphaSratio * facCorr;
3312  // Limit absolute variation to +/- deltaAlphaSmax
3313  if (alphaSfac > 1.)
3314  alphaSfac = min(alphaSfac, (alphaSbaseline + dASmax) / alphaSbaseline);
3315  else if (alphaSbaseline > dASmax)
3316  alphaSfac = max(alphaSfac, (alphaSbaseline - dASmax) / alphaSbaseline);
3317  uVarFac[iWeight] *= alphaSfac;
3318  doVar[iWeight] = true;
3319  }
3320 
3321  // QCD finite-term variations (only when no MECs and above pT threshold).
3322  if (dip->MEtype != 0 || dip->pT2 < pow2(cNSpTmin) ) varPtr = &dummy;
3323  else if (idMot == 21 && idSis == 21) varPtr = &varG2GGcNS;
3324  else if (idMot == 21 && abs(idSis) <= nQuarkIn) varPtr = &varG2QQcNS;
3325  else if (abs(idMot) <= nQuarkIn) {
3326  if (abs(idMot) <= uVarNflavQ) varPtr = &varQ2QGcNS;
3327  else varPtr = &varX2XGcNS;
3328  }
3329  else varPtr = &dummy;
3330  double z = dip->z;
3331  for (itVar = varPtr->begin(); itVar != varPtr->end(); ++itVar) {
3332  int iWeight = itVar->first;
3333  double valFac = itVar->second;
3334  // Correction-factor alphaS.
3335  // Virtuality for off-shell massive quarks.
3336  if (idMot == 21 && abs(idSis) >= 4 && idSis != 21)
3337  Q2 = max(1., Q2+pow2(sisPtr->m0()));
3338  else if (idSis == 21 && abs(idMot) >= 4 && idMot != 21)
3339  Q2 = max(1., Q2+pow2(motPtr->m0()));
3340  double yQ = Q2 / dip->m2Dip;
3341  double num = yQ * valFac;
3342  double denom = 1.;
3343  // G->GG.
3344  if (idSis == 21 && idMot == 21)
3345  denom = pow2(1. - z * (1.-z)) / (z*(1.-z));
3346  // Q->QG.
3347  else if (idSis == 21)
3348  denom = (1. + pow2(z)) / (1. - z);
3349  // Q->GQ.
3350  else if (idMot == idSis)
3351  denom = (1. + pow2(1. - z)) / z;
3352  // G->QQ.
3353  else
3354  denom = pow2(z) + pow2(1. - z);
3355  // Compute reweight ratio.
3356  double minReWeight = max( 1. + num / denom, REJECTFACTOR );
3357  uVarFac[iWeight] *= minReWeight;
3358  doVar[iWeight] = true;
3359  }
3360  }
3361 
3362  // Ensure 0 < PacceptPrime < 1 (with small margins).
3363  // Skip the central weight, so as to avoid confusion
3364  for (int iWeight = 1; iWeight<numWeights; ++iWeight) {
3365  if (!doVar[iWeight]) continue;
3366  double pAcceptPrime = pAccept * uVarFac[iWeight];
3367  if (pAcceptPrime > PROBLIMIT && dip->colType != 0) {
3368  uVarFac[iWeight] *= PROBLIMIT / pAcceptPrime;
3369  }
3370  }
3371 
3372  // Apply reject or accept reweighting factors according to input decision.
3373  for (int iWeight = 0; iWeight < numWeights; ++iWeight) {
3374  if (!doVar[iWeight]) continue;
3375  // If trial accepted: apply ratio of accept probabilities.
3376  if (accept) {
3377 
3378  weightContainerPtr->weightsPS.reweightValueByIndex(iWeight,
3379  uVarFac[iWeight] / ((1.0 - vp) * enhance) );
3380 
3381  // If trial rejected : apply Sudakov reweightings.
3382  } else {
3383  // Check for near-singular denominators (indicates too few failures,
3384  // and hence would need to increase headroom).
3385  double denom = 1. - pAccept * (1.0 - vp);
3386  if (denom < REJECTFACTOR) {
3387  stringstream message;
3388  message << iWeight;
3389  infoPtr->errorMsg("Warning in SimpleSpaceShower: reject denom for"
3390  " iWeight = ", message.str());
3391  }
3392  // Force reweighting factor > 0.
3393  double reWtFail = max(0.01, (1. - uVarFac[iWeight] * pAccept / enhance )
3394  / denom);
3395  weightContainerPtr->weightsPS.reweightValueByIndex(iWeight,
3396  reWtFail);
3397  }
3398  }
3399 }
3400 
3401 //--------------------------------------------------------------------------
3402 
3403 // Find class of ME correction.
3404 
3405  int SimpleSpaceShower::findMEtype( int iSys, Event& event,
3406  bool weakRadiation) {
3407 
3408  // Default values and no action.
3409  int MEtype = 0;
3410  if (!doMEcorrections) return MEtype;
3411 
3412  // Identify systems producing a single resonance.
3413  if (partonSystemsPtr->sizeOut( iSys) == 1 && !weakRadiation) {
3414  int idIn1 = event[partonSystemsPtr->getInA(iSys)].id();
3415  int idIn2 = event[partonSystemsPtr->getInA(iSys)].id();
3416  int idRes = event[partonSystemsPtr->getOut(iSys, 0)].id();
3417  if (iSys == 0) idResFirst = abs(idRes);
3418  if (iSys == 1) idResSecond = abs(idRes);
3419 
3420  // f + fbar -> vector boson.
3421  if ( (idRes == 23 || abs(idRes) == 24 || idRes == 32
3422  || idRes == 33 || abs(idRes) == 34 || abs(idRes) == 41)
3423  && abs(idIn1) < 20 && abs(idIn2) < 20 ) MEtype = 1;
3424 
3425  // g + g, gamma + gamma -> Higgs boson.
3426  if ( (idRes == 25 || idRes == 35 || idRes == 36)
3427  && ( ( idIn1 == 21 && idIn2 == 21 )
3428  || ( idIn1 == 22 && idIn2 == 22 ) ) ) MEtype = 2;
3429 
3430  // f + fbar -> Higgs boson.
3431  if ( (idRes == 25 || idRes == 35 || idRes == 36)
3432  && abs(idIn1) < 20 && abs(idIn2) < 20 ) MEtype = 3;
3433  }
3434 
3435  // Weak ME corrections.
3436  if (weakRadiation) {
3437  if (event[3].id() == -event[4].id()
3438  || event[event[3].daughter1()].idAbs() == 24 || infoPtr->nFinal() != 2)
3439  MEtype = 200;
3440  else if (event[3].idAbs() == 21 || event[4].idAbs() == 21) MEtype = 201;
3441  else if (event[3].id() == event[4].id()) MEtype = 202;
3442  else MEtype = 203;
3443  }
3444 
3445  // Done.
3446  return MEtype;
3447 
3448 }
3449 
3450 //--------------------------------------------------------------------------
3451 
3452 // Provide maximum of expected ME weight; for preweighting of evolution.
3453 
3454 double SimpleSpaceShower::calcMEmax( int MEtype, int idMother,
3455  int idDaughterIn) {
3456 
3457  // Main non-unity case: g(gamma) f -> V f'.
3458  if (MEtype == 1 && idMother > 20 && idDaughterIn < 20) return 3.;
3459 
3460  // Added a case for t-channel W/Z exchange, since the PS is not an
3461  // overestimate. This does not help fully, but it should only be small
3462  // pT quarks / gluons that break the overscattering.
3463  if ( MEtype == 201 || MEtype == 202 || MEtype == 203
3464  || MEtype == 206 || MEtype == 207 || MEtype == 208) return WEAKPSWEIGHT;
3465 
3466  // Default.
3467  return 1.;
3468 
3469 }
3470 
3471 //--------------------------------------------------------------------------
3472 
3473 // Provide actual ME weight for current branching.
3474 // Note: currently ME corrections are only allowed for first branching
3475 // on each side, so idDaughter is essentially known and checks overkill.
3476 
3477 double SimpleSpaceShower::calcMEcorr(int MEtype, int idMother,
3478  int idDaughterIn, double M2, double z, double Q2, double m2Sister) {
3479 
3480  // Convert to Mandelstam variables. Sometimes may need to swap later.
3481  double sH = M2 / z;
3482  double tH = -Q2;
3483  double uH = Q2 - M2 * (1. - z) / z;
3484  int idMabs = abs(idMother);
3485  int idDabs = abs(idDaughterIn);
3486 
3487  // Corrections for f + fbar -> s-channel vector boson.
3488  if (MEtype == 1) {
3489  if (idMabs < 20 && idDabs < 20) {
3490  return (tH*tH + uH*uH + 2. * M2 * sH) / (sH*sH + M2*M2);
3491  } else if (idDabs < 20) {
3492  // g(gamma) f -> V f': -Q2 = (p_g - p_f')^2 in PS while
3493  // tHat = (p_f - p_f')^2 in ME so need to swap tHat <-> uHat.
3494  swap( tH, uH);
3495  return (sH*sH + uH*uH + 2. * M2 * tH) / (pow2(sH - M2) + M2*M2);
3496  }
3497 
3498  // Corrections for g + g -> Higgs boson.
3499  } else if (MEtype == 2) {
3500  if (idMabs < 20 && idDabs > 20) {
3501  return (sH*sH + uH*uH) / (sH*sH + pow2(sH - M2));
3502  } else if (idDabs > 20) {
3503  return 0.5 * (pow4(sH) + pow4(tH) + pow4(uH) + pow4(M2))
3504  / pow2(sH*sH - M2 * (sH - M2));
3505  }
3506 
3507  // Corrections for f + fbar -> Higgs boson (f = b mainly).
3508  } else if (MEtype == 3) {
3509  if (idMabs < 20 && idDabs < 20) {
3510  // The PS and ME answers agree for f fbar -> H g/gamma.
3511  return 1.;
3512  } else if (idDabs < 20) {
3513  // Need to swap tHat <-> uHat, cf. vector-boson production above.
3514  swap( tH, uH);
3515  return (sH*sH + uH*uH + 2. * (M2 - uH) * (M2 - sH))
3516  / (pow2(sH - M2) + M2*M2);
3517  }
3518 
3519  // Corrections for f -> f' + W/Z (s-channel).
3520  } else if (MEtype == 200 || MEtype == 205) {
3521  // Need to redo calculations of uH since we now emit a massive particle.
3522  uH += m2Sister;
3523  double wtME = (uH*uH + tH*tH + 2 * sH * (m2Sister + M2)) / (uH*tH)
3524  - M2 * m2Sister * (1/(tH*tH) + 1/(uH*uH));
3525  double wtPS = (sH*sH + pow2(M2 + m2Sister)) / (tH*uH);
3526  return wtME / wtPS;
3527  } else if (MEtype == 201 || MEtype == 202 || MEtype == 203 ||
3528  MEtype == 206 || MEtype == 207 || MEtype == 208)
3529  return calcMEmax(MEtype, 0, 0);
3530 
3531  // Default.
3532  return 1.;
3533 
3534 }
3535 
3536 //--------------------------------------------------------------------------
3537 
3538 // Provide actual ME weight for current branching for weak t-channel emissions.
3539 
3540 double SimpleSpaceShower::calcMEcorrWeak(int MEtype, double m2, double z,
3541  double pT2, Vec4 pMother, Vec4 pB, Vec4 pDaughter,
3542  Vec4 pB0, Vec4 p1, Vec4 p2, Vec4 pSister) {
3543 
3544  // Find daughter four-momentum in current frame.
3545  Vec4 pA = pMother - pSister;
3546 
3547  // Scale outgoing vectors to conserve energy / momentum.
3548  double scaleFactor2 = (pA + pB).m2Calc() / (p1 + p2).m2Calc();
3549  double scaleFactor = sqrt(scaleFactor2);
3550  RotBstMatrix rot2to2frame;
3551  rot2to2frame.bstback(p1 + p2);
3552  p1.rotbst(rot2to2frame);
3553  p2.rotbst(rot2to2frame);
3554  p1 *= scaleFactor;
3555  p2 *= scaleFactor;
3556 
3557  // Find 2 to 2 rest frame for incoming particles.
3558  // This is done before one of the two are made virtual (Q^2 mass).
3559  RotBstMatrix rot2to2frameInc;
3560  rot2to2frameInc.bstback(pDaughter + pB0);
3561  pDaughter.rotbst(rot2to2frameInc);
3562  pB0.rotbst(rot2to2frameInc);
3563  double sHat = (p1 + p2).m2Calc();
3564  double tHat = (p1 - pDaughter).m2Calc();
3565  double uHat = (p1 - pB0).m2Calc();
3566 
3567  // Calculate the weak t-channel correction.
3568  double m2R1 = 1. + pSister.m2Calc() / m2;
3569  double wt = 4. * sHat / (pMother + pB).m2Calc() * pT2 * ( 1. - z * m2R1)
3570  / (1. + pow2(z * m2R1)) / (1.-z);
3571  if (MEtype == 201 || MEtype == 206)
3572  wt *= simpleWeakShowerMEs.getMEqg2qgZ(pMother, pB, p2, pSister, p1)
3573  / simpleWeakShowerMEs.getMEqg2qg(sHat, tHat, uHat);
3574  else if (MEtype == 202 || MEtype == 207)
3575  wt *= simpleWeakShowerMEs.getMEqq2qqZ(pMother, pB, pSister, p2, p1)
3576  / simpleWeakShowerMEs.getMEqq2qq(sHat, tHat, uHat, true);
3577  else if (MEtype == 203 || MEtype == 208)
3578  wt *= simpleWeakShowerMEs.getMEqq2qqZ(pMother, pB, pSister, p2, p1)
3579  / simpleWeakShowerMEs.getMEqq2qq(sHat, tHat, uHat, false);
3580 
3581  // Split of ME into an ISR part and FSR part.
3582  wt *= (pSister + p1).m2Calc() / ( (pSister + p1).m2Calc()
3583  + abs((-pMother + pSister).m2Calc()) );
3584 
3585  // Remove the addition weight that was used to get an overestimate.
3586  wt /= calcMEmax(MEtype, 0, 0);
3587 
3588  return wt;
3589 }
3590 
3591 //--------------------------------------------------------------------------
3592 
3593 // Find coefficient of azimuthal asymmetry from gluon polarization.
3594 
3595 void SimpleSpaceShower::findAsymPol( Event& event, SpaceDipoleEnd* dip) {
3596 
3597  // Default is no asymmetry. Only gluons are studied.
3598  dip->iFinPol = 0;
3599  dip->asymPol = 0.;
3600  int iRad = dip->iRadiator;
3601  if (!doPhiPolAsym || dip->idDaughter != 21) return;
3602 
3603  // At least two particles in final state, whereof at least one coloured.
3604  int systemSizeOut = partonSystemsPtr->sizeOut( iSysSel);
3605  if (systemSizeOut < 2) return;
3606  bool foundColOut = false;
3607  for (int ii = 0; ii < systemSizeOut; ++ii) {
3608  int i = partonSystemsPtr->getOut( iSysSel, ii);
3609  if (event[i].col() != 0 || event[i].acol() != 0) foundColOut = true;
3610  }
3611  if (!foundColOut) return;
3612 
3613  // Check if granddaughter in final state of hard scattering.
3614  // (May need to trace across carbon copies to find granddaughters.)
3615  // If so, at most accept 2 -> 2 scatterings with gg or qq in final state.
3616  int iGrandD1 = event[iRad].daughter1();
3617  int iGrandD2 = event[iRad].daughter2();
3618  bool traceCopy = false;
3619  do {
3620  traceCopy = false;
3621  if (iGrandD1 > 0 && iGrandD2 == iGrandD1) {
3622  iGrandD1 = event[iGrandD2].daughter1();
3623  iGrandD2 = event[iGrandD2].daughter2();
3624  traceCopy = true;
3625  }
3626  } while (traceCopy);
3627  int statusGrandD1 = event[ iGrandD1 ].statusAbs();
3628  bool isHardProc = (statusGrandD1 == 23 || statusGrandD1 == 33);
3629  if (isHardProc) {
3630  if (!doPhiPolAsymHard) return;
3631  if (iGrandD2 != iGrandD1 + 1) return;
3632  if (event[iGrandD1].isGluon() && event[iGrandD2].isGluon());
3633  else if (event[iGrandD1].isQuark() && event[iGrandD2].isQuark());
3634  else return;
3635  }
3636  dip->iFinPol = iGrandD1;
3637 
3638  // Coefficient from gluon production.
3639  if (dip->idMother == 21) dip->asymPol = pow2( (1. - dip->z)
3640  / (1. - dip->z * (1. - dip->z) ) );
3641  else dip->asymPol = 2. * (1. - dip->z) / (1. + pow2(1. - dip->z) );
3642 
3643  // Coefficients from gluon decay. Put z = 1/2 for hard process.
3644  double zDau = (isHardProc) ? 0.5 : dip->zOld;
3645  if (event[iGrandD1].isGluon()) dip->asymPol *= pow2( zDau * (1. - zDau)
3646  / (1. - zDau * (1. - zDau) ) );
3647  else dip->asymPol *= -2. * zDau *( 1. - zDau )
3648  / (1. - 2. * zDau * (1. - zDau) );
3649 
3650 }
3651 
3652 //--------------------------------------------------------------------------
3653 
3654 // Find a possible colour partner in the case of dipole recoil.
3655 
3656 int SimpleSpaceShower::findColPartner(Event& event, int iSideA, int iSideB,
3657  int iSystem) {
3658 
3659  int iColPartner = 0;
3660  int colSideA = event[iSideA].col();
3661  int acolSideA = event[iSideA].acol();
3662 
3663  // Check if the parton on the other side is a colour partner.
3664  if ( (colSideA != 0 && event[iSideB].acol() == colSideA)
3665  || (acolSideA != 0 && event[iSideB].col() == acolSideA) ) {
3666 
3667  // Another possible colour partner among the outgoing partons
3668  // in the case of a gluon.
3669  if (event[iSideA].id() == 21)
3670  for (int i = 0; i < partonSystemsPtr->sizeOut(iSystem); ++i) {
3671  int iOut = partonSystemsPtr->getOut(iSystem, i);
3672  if ( event[iOut].col() == colSideA
3673  || event[iOut].acol() == acolSideA )
3674  // 50% for II and 50% for IF.
3675  if (rndmPtr->flat() < 0.5) iColPartner = iOut;
3676  }
3677 
3678  // Otherwise, check within the set of outgoing partons.
3679  } else if (colSideA != 0 || acolSideA != 0) {
3680  for (int i = 0; i < partonSystemsPtr->sizeOut(iSystem); ++ i) {
3681  int iOut = partonSystemsPtr->getOut(iSystem, i);
3682  if ( (colSideA != 0 && event[iOut].col() == colSideA)
3683  || (acolSideA != 0 && event[iOut].acol() == acolSideA) ) {
3684  if (iColPartner == 0) iColPartner = iOut;
3685  // 50% for each IF in the case of a gluon.
3686  else if (rndmPtr->flat() < 0.5) iColPartner = iOut;
3687  }
3688  }
3689  }
3690  return iColPartner;
3691 
3692 }
3693 
3694 //--------------------------------------------------------------------------
3695 
3696 // Remove weak dipoles if FSR already emitted a W/Z
3697 // and only a single weak emission is permited.
3698 // Update colour partner in case of dipole recoil.
3699 
3700 void SimpleSpaceShower::update(int iSys, Event& event, bool hasWeakRad) {
3701 
3702  if (hasWeakRad && singleWeakEmission)
3703  for (int i = 0; i < int(dipEnd.size()); i++)
3704  if (dipEnd[i].weakType != 0) dipEnd[i].weakType = 0;
3705  if (hasWeakRad) hasWeaklyRadiated = true;
3706 
3707  // Update colour partner in case of dipole recoil.
3708  if (doDipoleRecoil)
3709  for (int i = 0; i < int(dipEnd.size()); i++)
3710  if (dipEnd[i].system == iSys) {
3711  dipEnd[i].iColPartner = findColPartner(event, dipEnd[i].iRadiator,
3712  dipEnd[i].iRecoiler, iSys);
3713  dipEnd[i].idColPartner = (dipEnd[i].iColPartner != 0)
3714  ? event[dipEnd[i].iColPartner].id() : 0;
3715  }
3716 
3717 }
3718 
3719 //-------------------------------------------------------------------------
3720 
3721 // Print the list of dipoles.
3722 
3723 void SimpleSpaceShower::list() const {
3724 
3725  // Header.
3726  cout << "\n -------- PYTHIA SimpleSpaceShower Dipole Listing --------- \n"
3727  << "\n i syst side rad rec pTmax col chg ME rec \n"
3728  << fixed << setprecision(3);
3729 
3730  // Loop over dipole list and print it.
3731  for (int i = 0; i < int(dipEnd.size()); ++i)
3732  cout << setw(5) << i << setw(6) << dipEnd[i].system
3733  << setw(6) << dipEnd[i].side << setw(6) << dipEnd[i].iRadiator
3734  << setw(6) << dipEnd[i].iRecoiler << setw(12) << dipEnd[i].pTmax
3735  << setw(5) << dipEnd[i].colType << setw(5) << dipEnd[i].chgType
3736  << setw(5) << dipEnd[i].MEtype << setw(4)
3737  << dipEnd[i].normalRecoil << "\n";
3738 
3739  // Done.
3740  cout << "\n -------- End PYTHIA SimpleSpaceShower Dipole Listing -----"
3741  << endl;
3742 
3743 }
3744 
3745 //==========================================================================
3746 
3747 } // end namespace Pythia8
Definition: beam.h:43
Definition: AgUStep.h:26