StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VinciaISR.cc
1 // VinciaISR.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Peter Skands, 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 VinciaISR
7 // class and auxiliary classes.
8 
9 #include "Pythia8/VinciaFSR.h"
10 #include "Pythia8/VinciaISR.h"
11 
12 namespace Pythia8 {
13 
14 //==========================================================================
15 
16 // Base class for initial-state trial generators.
17 
18 //--------------------------------------------------------------------------
19 
20 // Initialize pointers.
21 
22 void TrialGeneratorISR::initPtr(Info* infoPtrIn) {
23  infoPtr = infoPtrIn;
24  rndmPtr = infoPtr->rndmPtr;
25  settingsPtr = infoPtr->settingsPtr;
26 }
27 
28 //--------------------------------------------------------------------------
29 
30 // Initialize.
31 
32 void TrialGeneratorISR::init(double mcIn, double mbIn) {
33 
34  TINYPDFtrial = pow(10,-10);
35  // TODO: this version of VINCIA uses PT evolution for all branchings.
36  useMevolSav = false;
37  // s for hadron hadron.
38  shhSav = infoPtr->s();
39  // Number of active quark flavours.
40  nGtoQISRSav = settingsPtr->mode("Vincia:nGluonToQuark");
41  // For conversion trial generators.
42  if (!settingsPtr->flag("Vincia:convertGluonToQuark")) nGtoQISRSav = 0;
43  trialFlavSav = 0;
44  // Masses.
45  mbSav = mbIn;
46  mcSav = mcIn;
47  // Saved trialPDF ratio.
48  trialPDFratioSav = 1.0;
49  verbose = settingsPtr->mode("Vincia:Verbose");
50  isInit = true;
51 
52 }
53 
54 //--------------------------------------------------------------------------
55 
56 // Trial antenna function.
57 
58 double TrialGeneratorISR::aTrial(double saj, double sjb, double sAB) {
59  if (saj < 0. || sjb < 0.) return 0.;
60  const double sab = sAB + saj + sjb;
61  const double ant = 2*pow2(sab)/saj/sjb/sAB;
62  const double xFactor = sab/sAB;
63  return xFactor * ant;
64 }
65 
66 //--------------------------------------------------------------------------
67 
68 // Generate a new Q value, with first-order running alphaS.
69 
70 double TrialGeneratorISR::genQ2run(double q2old, double sAB,
71  double zMin, double zMax, double colFac, double PDFratio,
72  double b0, double kR, double Lambda, double, double,
73  double headroomFac, double enhanceFac) {
74 
75  // Sanity checks.
76  if (!checkInit()) return 0.0;
77  if (sAB < 0. || q2old < 0.) return 0.0;
78 
79  // Enhance factors < 1: do not modify trial probability.
80  enhanceFac = max(enhanceFac,1.0);
81 
82  // Generate new trial scale.
83  double Iz = getIz(zMin,zMax);
84  double comFac = 2.0*M_PI*b0/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
85  double ran = rndmPtr->flat();
86  double facLam = pow2(Lambda/kR);
87  return exp(pow(ran,comFac) * log(q2old/facLam)) * facLam;
88 
89 }
90 
91 //--------------------------------------------------------------------------
92 
93 // Generate a new Q value, with constant trial alphaS.
94 
95 double TrialGeneratorISR::genQ2(double q2old, double sAB, double zMin,
96  double zMax, double colFac, double alphaS, double PDFratio,
97  double, double, double headroomFac, double enhanceFac) {
98 
99  // Sanity checks.
100  if (!checkInit()) return 0.0;
101  if (sAB < 0. || q2old < 0.) return 0.0;
102 
103  // Enhance factors < 1: do not modify trial probability.
104  enhanceFac = max(enhanceFac,1.0);
105 
106  // Generate new trial scale.
107  double Iz = getIz(zMin,zMax);
108  double comFac = 2.0*M_PI/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
109  double ran = rndmPtr->flat();
110  return q2old * pow(ran,comFac/alphaS);
111 
112 }
113 
114 //--------------------------------------------------------------------------
115 
116 // Generate new Q value, with running of the PDFs towards the mass
117 // threshold.
118 
119 double TrialGeneratorISR::genQ2thres(double, double, double,
120  double, double, double, double, int, int, double, double, bool, double,
121  double) {return 0.0;}
122 
123 //--------------------------------------------------------------------------
124 
125 // Generate a new zeta value in [zMin,zMax].
126 
127 double TrialGeneratorISR::genZ(double zMin, double zMax) {
128  if (zMin > zMax || zMin < 0.) return -1.;
129  double ran = rndmPtr->flat();
130  double invZ = 1.0 + (1.0-zMin)/zMin*pow(zMin*(1.0-zMax)/zMax/(1.0-zMin),ran);
131  return 1.0/invZ;
132 }
133 
134 //--------------------------------------------------------------------------
135 
136 // The zeta integral.
137 
138 double TrialGeneratorISR::getIz(double zMin, double zMax) {
139  if (zMin > zMax || zMin < 0.) return 0.0;
140  return log(zMax*(1.0-zMin)/zMin/(1.0-zMax));
141 }
142 
143 //--------------------------------------------------------------------------
144 
145 // The zeta boundaries, for a given value of the evolution variable.
146 
147 double TrialGeneratorISR::getZmin(double Qt2, double sAB, double, double) {
148  if (((shhSav-sAB)*(shhSav-sAB) - (4.0*Qt2*shhSav))
149  < TINYPDFtrial) return 0.5*(shhSav - sAB)/shhSav;
150  double sajm = 0.5*(shhSav - sAB - sqrt((shhSav - sAB)*(shhSav - sAB) -
151  (4.0*Qt2*shhSav)));
152  return sajm/shhSav;
153 }
154 
155 double TrialGeneratorISR::getZmax(double Qt2, double sAB, double, double) {
156  if (((shhSav - sAB)*(shhSav - sAB) - (4.0*Qt2*shhSav))
157  < TINYPDFtrial) return 0.5*(shhSav - sAB)/shhSav;
158  double sajp = 0.5*(shhSav - sAB + sqrt((shhSav - sAB)*(shhSav - sAB) -
159  (4.0*Qt2*shhSav)));
160  return sajp/shhSav;
161 }
162 
163 //--------------------------------------------------------------------------
164 
165 // Inverse transforms to obtain saj and sjb from Qt2 and zeta.
166 
167 double TrialGeneratorISR::getS1j(double Qt2, double zeta, double sAB) {
168 
169  // If zeta < 0, swap invariants.
170  if (zeta < 0) return getSj2(Qt2, -zeta, sAB);
171  // Sanity check.
172  if (Qt2 < 0. || zeta <= 0.) {
173  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": Unphysical input");
174  return 0.;
175  }
176  return Qt2/zeta;
177 }
178 
179 double TrialGeneratorISR::getSj2(double Qt2, double zeta, double sAB) {
180 
181  // If zeta < 0, swap invariants.
182  if (zeta < 0) return getS1j(Qt2,-zeta,sAB);
183  // Sanity check.
184  if (Qt2 < 0. || zeta <= 0.) {
185  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": Unphysical input");
186  return 0.;
187  }
188  return (Qt2 + sAB*zeta)/(1.0 - zeta);
189 }
190 
191 //--------------------------------------------------------------------------
192 
193 // Compute trial PDF ratio.
194 
195 double TrialGeneratorISR::trialPDFratio(BeamParticle*, BeamParticle*,
196  int, int, int, double, double, double, double) {
197  trialPDFratioSav = 1.0;
198  return trialPDFratioSav;
199 }
200 
201 //--------------------------------------------------------------------------
202 
203 // Check initialization.
204 
205 bool TrialGeneratorISR::checkInit() {
206  if (isInit) return true;
207  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": Not initialized");
208  return false;
209 }
210 
211 //==========================================================================
212 
213 // A collinear trial function for initial-initial.
214 
215 //--------------------------------------------------------------------------
216 
217 // Trial antenna function.
218 
219 double TrialIIGCollA::aTrial(double saj, double sjb, double sAB) {
220  if (saj < 0. || sjb < 0.) return 0.;
221  const double sab = sAB + saj + sjb;
222  const double ant = 2.0 * pow2(sab/sAB)/saj;
223  return ant;
224 }
225 
226 //--------------------------------------------------------------------------
227 
228 // Generate a new Q value, with first-order running alphaS.
229 
230 double TrialIIGCollA::genQ2run(double q2old, double sAB,
231  double zMin, double zMax, double colFac, double PDFratio,
232  double b0, double kR, double Lambda, double, double,
233  double headroomFac, double enhanceFac) {
234 
235  // Sanity checks.
236  if (!checkInit()) return 0.0;
237  if (sAB < 0. || q2old < 0.) return 0.0;
238 
239  // Enhance factors < 1: do not modify trial probability.
240  enhanceFac = max(enhanceFac, 1.0);
241 
242  // Generate new trial scale
243  double Iz = getIz(zMin, zMax);
244  double comFac = 2.0*M_PI*b0/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
245  double ran = rndmPtr->flat();
246  double facLam = pow2(Lambda/kR);
247  return exp(pow(ran, comFac) * log(q2old/facLam)) * facLam;
248 
249 }
250 
251 //--------------------------------------------------------------------------
252 
253 // Generate a new Q value, with constant trial alphaS.
254 
255 double TrialIIGCollA::genQ2(double q2old, double sAB,
256  double zMin, double zMax, double colFac, double alphaS, double PDFratio,
257  double, double, double headroomFac, double enhanceFac) {
258 
259  // Sanity checks.
260  if (!checkInit()) return 0.0;
261  if (sAB < 0. || q2old < 0.) return 0.0;
262 
263  // Enhance factors < 1: do not modify trial probability.
264  enhanceFac = max(enhanceFac, 1.0);
265 
266  // Generate new trial scale.
267  double Iz = getIz(zMin, zMax);
268  double comFac = 2.0*M_PI/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
269  double ran = rndmPtr->flat();
270  return q2old * pow(ran, comFac/alphaS);
271 
272 }
273 
274 //--------------------------------------------------------------------------
275 
276 // Generate a new zeta value in [zMin,zMax].
277 
278 double TrialIIGCollA::genZ(double zMin, double zMax) {
279  if (zMin > zMax || zMin < 0.) return -1.;
280  double ran = rndmPtr->flat();
281  double z = -1.0 + (1.0+zMin)*pow((1.0+zMax)/(1.0+zMin),ran);
282  return z;
283 }
284 
285 //--------------------------------------------------------------------------
286 
287 // The zeta integral.
288 
289 double TrialIIGCollA::getIz(double zMin, double zMax) {
290  if (zMin > zMax || zMin < 0.) return 0.0;
291  return log((1.0+zMax)/(1.0+zMin));
292 }
293 
294 //--------------------------------------------------------------------------
295 
296 // The zeta boundaries, for a given value of the evolution variable.
297 
298 double TrialIIGCollA::getZmin(double Qt2, double sAB, double, double) {
299  if (((shhSav - sAB)*(shhSav - sAB) - (4.0*Qt2*shhSav))
300  < TINYPDFtrial ) return 0.5*(shhSav - sAB)/sAB;
301  double sajm = 0.5*(shhSav - sAB - sqrt((shhSav - sAB)*(shhSav - sAB) -
302  (4.0*Qt2*shhSav)));
303  return sajm/sAB;
304 }
305 
306 double TrialIIGCollA::getZmax(double Qt2, double sAB, double, double) {
307  if (((shhSav - sAB)*(shhSav - sAB) - (4.0*Qt2*shhSav))
308  < TINYPDFtrial) return 0.5*(shhSav - sAB)/sAB;
309  double sajp = 0.5*(shhSav - sAB + sqrt((shhSav - sAB)*(shhSav - sAB) -
310  (4.0*Qt2*shhSav)));
311  return sajp/sAB;
312 }
313 
314 //--------------------------------------------------------------------------
315 
316 // Inverse transforms to obtain saj and sjb from Qt2 and zeta.
317 
318 double TrialIIGCollA::getS1j(double Qt2, double zeta, double sAB) {
319 
320  // If zeta < 0, swap invariants.
321  if (zeta < 0) return getSj2(Qt2,-zeta,sAB);
322  // Sanity check.
323  if (Qt2 < 0. || zeta <= 0.) {
324  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
325  return 0.;
326  }
327  return Qt2*(1.0+zeta)/(zeta-Qt2/sAB);
328 
329 }
330 
331 double TrialIIGCollA::getSj2(double Qt2, double zeta, double sAB) {
332 
333  // If zeta < 0, swap invariants.
334  if (zeta < 0) return getS1j(Qt2,-zeta,sAB);
335  // Sanity check.
336  if (Qt2 < 0. || zeta <= 0.) {
337  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
338  return 0.;
339  }
340  return zeta*sAB;
341 
342 }
343 
344 //==========================================================================
345 
346 // A splitting trial function for initial-initial, q -> gqbar.
347 
348 //--------------------------------------------------------------------------
349 
350 // Trial antenna function.
351 
352 double TrialIISplitA::aTrial(double saj, double sjb, double sAB) {
353  if (saj < 0. || sjb < 0.) return 0.;
354  const double sab = sAB + saj + sjb;
355  const double ant = sab/saj/sAB;
356  const double xFactor = sab/sAB;
357  return xFactor * ant;
358 }
359 
360 //--------------------------------------------------------------------------
361 
362 // Generate a new Q value, with first-order running alphaS.
363 
364 double TrialIISplitA::genQ2run(double q2old, double sAB,
365  double zMin, double zMax, double colFac, double PDFratio,
366  double b0, double kR, double Lambda, double, double,
367  double headroomFac, double enhanceFac) {
368 
369  // Sanity checks.
370  if (!checkInit()) return 0.0;
371  if (sAB < 0. || q2old < 0.) return 0.0;
372 
373  // Enhance factors < 1: do not modify trial probability.
374  enhanceFac = max(enhanceFac, 1.0);
375 
376  // Generate new trial scale
377  double Iz = getIz(zMin, zMax);
378  double comFac = 4.0*M_PI*b0/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
379  double ran = rndmPtr->flat();
380  double facLam = pow2(Lambda/kR);
381  return exp(pow(ran, comFac) * log(q2old/facLam)) * facLam;
382 
383 }
384 
385 //--------------------------------------------------------------------------
386 
387 // Generate a new Q value, with constant trial alphaS.
388 
389 double TrialIISplitA::genQ2(double q2old, double sAB,
390  double zMin, double zMax, double colFac, double alphaS, double PDFratio,
391  double, double, double headroomFac, double enhanceFac) {
392 
393  // Sanity checks.
394  if (!checkInit()) return 0.0;
395  if (sAB < 0. || q2old < 0.) return 0.0;
396 
397  // Enhance factors < 1: do not modify trial probability.
398  enhanceFac = max(enhanceFac, 1.0);
399 
400  // Generate new trial scale
401  double Iz = getIz(zMin, zMax);
402  double comFac = 4.0*M_PI/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
403  double ran = rndmPtr->flat();
404  return q2old * pow(ran, comFac/alphaS);
405 
406 }
407 
408 //--------------------------------------------------------------------------
409 
410 // Generate a new Q value, with running of the PDFs towards the mass
411 // threshold.
412 
413 double TrialIISplitA::genQ2thres(double q2old, double sAB, double zMin,
414  double zMax, double colFac, double alphaS, double PDFratio, int idA, int,
415  double, double, bool, double headroomFac, double enhanceFac) {
416 
417  // Use only if the user wants to get rid of c and b quarks and use
418  // only in the right evolution window.
419  double mQ = (abs(idA) == 4 ? mcSav : mbSav);
420 
421  // Sanity checks.
422  if (!checkInit()) return 0.0;
423  if (sAB < 0. || q2old < 0.) return 0.0;
424 
425  // Enhance factors < 1: do not modify trial probability
426  enhanceFac = max(enhanceFac, 1.0);
427 
428  // Generate new trial scale
429  double Iz = getIz(zMin, zMax);
430  double comFac = 4.0*M_PI/Iz/colFac/alphaS/PDFratio/(headroomFac*enhanceFac);
431  double ran = rndmPtr->flat();
432  return (exp(pow(ran, comFac) * log(q2old/pow2(mQ))) * pow2(mQ));
433 
434 }
435 
436 //--------------------------------------------------------------------------
437 
438 // Generate a new zeta value in [zMin,zMax].
439 
440 double TrialIISplitA::genZ(double zMin, double zMax) {
441  if (zMin > zMax || zMin < 0.) return -1.;
442  double ran = rndmPtr->flat();
443  if (useMevolSav) return zMin *pow(zMax/zMin, ran);
444  else return (-1.0 + (1.0 + zMin)*pow((1.0 + zMax)/(1.0 + zMin), ran));
445 }
446 
447 //--------------------------------------------------------------------------
448 
449 // The zeta integral (with alpha = 0).
450 
451 double TrialIISplitA::getIz(double zMin, double zMax) {
452  if (zMin > zMax || zMin < 0.) return 0.0;
453  if (useMevolSav) return log(zMax/zMin);
454  else return log((1.0 + zMax)/(1.0 + zMin));
455 }
456 
457 //--------------------------------------------------------------------------
458 
459 // The zeta boundaries, for a given value of the evolution scale.
460 
461 double TrialIISplitA::getZmin(double Qt2, double sAB, double, double) {
462  if (useMevolSav) return (Qt2+sAB)/sAB;
463  if (((shhSav - sAB)*(shhSav - sAB) - (4.0*Qt2*shhSav))
464  < TINYPDFtrial) return 0.5*(shhSav - sAB)/sAB;
465  double sajm = 0.5*(shhSav - sAB - sqrt((shhSav - sAB)*(shhSav - sAB) -
466  (4.0*Qt2*shhSav)));
467  return sajm/sAB;
468 }
469 
470 double TrialIISplitA::getZmax(double Qt2, double sAB, double, double) {
471  if (useMevolSav) return (shhSav/sAB);
472  if (((shhSav - sAB)*(shhSav - sAB) - (4.0*Qt2*shhSav))
473  < TINYPDFtrial) return 0.5*(shhSav - sAB)/sAB;
474  double sajp = 0.5*(shhSav - sAB + sqrt((shhSav - sAB)*(shhSav - sAB) -
475  (4.0*Qt2*shhSav)));
476  return sajp/sAB;
477 }
478 
479 //--------------------------------------------------------------------------
480 
481 // Inverse transforms to obtain saj and sjb from Qt2 and zeta.
482 
483 double TrialIISplitA::getS1j(double Qt2, double zeta, double sAB) {
484 
485  // If zeta < 0, swap invariants.
486  if (zeta < 0) return getSj2(Qt2, -zeta, sAB);
487  // Sanity check.
488  if (Qt2 < 0. || zeta <= 0.) {
489  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
490  return 0.;
491  }
492  double saj = Qt2*(1.0 + zeta)/(zeta - Qt2/sAB);
493  if (useMevolSav) saj = Qt2;
494  return saj;
495 
496 }
497 
498 double TrialIISplitA::getSj2(double Qt2, double zeta, double sAB) {
499  // If zeta < 0, swap invariants.
500  if (zeta < 0) return getS1j(Qt2, -zeta, sAB);
501  // Sanity check.
502  if (Qt2 < 0. || zeta <= 0.) {
503  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
504  return 0.;
505  }
506  double sjb = zeta*sAB;
507  if (useMevolSav) sjb = sAB*(zeta - 1) - Qt2;
508  return sjb;
509 
510 }
511 
512 //--------------------------------------------------------------------------
513 
514 // Trial PDF ratio.
515 
516 double TrialIISplitA::trialPDFratio(BeamParticle* beamAPtr, BeamParticle*,
517  int iSys, int idA, int, double eA, double, double Qt2A, double) {
518  double xA = eA/(sqrt(shhSav)/2.0);
519  double newPdf = max(beamAPtr->xfISR(iSys, 21, xA, Qt2A), TINYPDFtrial);
520  double oldPdf = max(beamAPtr->xfISR(iSys, idA, xA, Qt2A), TINYPDFtrial);
521  trialPDFratioSav = 1.0*newPdf/oldPdf;
522  return trialPDFratioSav;
523 }
524 
525 //==========================================================================
526 
527 // A conversion trial function for initial-initial, g -> qqbar.
528 
529 //--------------------------------------------------------------------------
530 
531 // Trial antenna function.
532 
533 double TrialIIConvA::aTrial(double saj, double sjb, double sAB) {
534  if (saj < 0. || sjb < 0.) return 0.;
535  const double sab = sAB + saj + sjb;
536  const double ant = pow2(sab/sAB)/saj;
537  return ant;
538 }
539 
540 //--------------------------------------------------------------------------
541 
542 // Generate a new Q value, with first-order running alphaS.
543 
544 double TrialIIConvA::genQ2run(double q2old, double sAB,
545  double zMin, double zMax, double colFac, double PDFratio,
546  double b0, double kR, double Lambda, double, double,
547  double headroomFac, double enhanceFac) {
548 
549  // Sanity checks.
550  if (!checkInit()) return 0.0;
551  if (sAB < 0. || q2old < 0.) return 0.0;
552 
553  // Enhance factors < 1: do not modify trial probability.
554  enhanceFac = max(enhanceFac,1.0);
555 
556  // Generate new trial scale.
557  double Iz = getIz(zMin, zMax);
558  double comFac = 4.0*M_PI*b0/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
559  double ran = rndmPtr->flat();
560  double facLam = pow2(Lambda/kR);
561  return exp(pow(ran, comFac) * log(q2old/facLam)) * facLam;
562 
563 }
564 
565 //--------------------------------------------------------------------------
566 
567 // Generate a new Q value, with constant trial alphaS.
568 
569 double TrialIIConvA::genQ2(double q2old, double sAB,
570  double zMin, double zMax, double colFac, double alphaS, double PDFratio,
571  double, double, double headroomFac, double enhanceFac) {
572 
573  // Sanity checks.
574  if (!checkInit()) return 0.0;
575  if (sAB < 0. || q2old < 0.) return 0.0;
576 
577  // Enhance factors < 1: do not modify trial probability.
578  enhanceFac = max(enhanceFac, 1.0);
579 
580  // Generate new trial scale
581  double Iz = getIz(zMin, zMax);
582  double comFac = 4.0*M_PI/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
583  double ran = rndmPtr->flat();
584  return q2old * pow(ran, comFac/alphaS);
585 
586 }
587 
588 //--------------------------------------------------------------------------
589 
590 // Generate a new zeta value in [zMin,zMax].
591 
592 double TrialIIConvA::genZ(double zMin, double zMax) {
593  if (zMin > zMax || zMin < 0.) return -1.;
594  double ran = rndmPtr->flat();
595  if (useMevolSav) return zMax*pow(zMin/zMax, ran);
596  else return (-1.0 + (1.0 + zMin)*pow((1.0 + zMax)/(1.0 + zMin), ran));
597 }
598 
599 //--------------------------------------------------------------------------
600 
601 // The zeta integral.
602 
603 double TrialIIConvA::getIz(double zMin, double zMax) {
604  if (zMin > zMax || zMin < 0.) return 0.0;
605  if (useMevolSav) return log(zMax/zMin);
606  else return log((1.0 + zMax)/(1.0 + zMin));
607 }
608 
609 //--------------------------------------------------------------------------
610 
611 // The zeta boundaries, for a given value of the evolution scale.
612 
613 double TrialIIConvA::getZmin(double Qt2, double sAB, double, double) {
614  if (useMevolSav) return ((Qt2 + sAB)/sAB);
615  if (((shhSav - sAB)*(shhSav - sAB) - (4.0*Qt2*shhSav))
616  < TINYPDFtrial) return 0.5*(shhSav - sAB)/sAB;
617  double sajm = 0.5*(shhSav - sAB - sqrt((shhSav - sAB)*(shhSav - sAB) -
618  (4.0*Qt2*shhSav)));
619  return sajm/sAB;
620 }
621 
622 double TrialIIConvA::getZmax(double Qt2, double sAB, double, double) {
623  if (useMevolSav) return (shhSav/sAB);
624  if (((shhSav - sAB)*(shhSav - sAB) - (4.0*Qt2*shhSav))
625  < TINYPDFtrial ) return 0.5*(shhSav - sAB)/sAB;
626  double sajp = 0.5*(shhSav - sAB + sqrt((shhSav - sAB)*(shhSav - sAB) -
627  (4.0*Qt2*shhSav)));
628  return sajp/sAB;
629 }
630 
631 //--------------------------------------------------------------------------
632 
633 // Inverse transforms to obtain saj and sjb from Qt2 and zeta.
634 
635 double TrialIIConvA::getS1j(double Qt2, double zeta, double sAB) {
636 
637  // If zeta < 0, swap invariants.
638  if (zeta < 0) return getSj2(Qt2, -zeta, sAB);
639  // Sanity check.
640  if (Qt2 < 0. || zeta <= 0.) {
641  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
642  return 0.;
643  }
644  double saj = Qt2*(1.0 + zeta)/(zeta - Qt2/sAB);
645  if (useMevolSav) saj = Qt2;
646  return saj;
647 
648 }
649 
650 double TrialIIConvA::getSj2(double Qt2, double zeta, double sAB) {
651 
652  // If zeta < 0, swap invariants.
653  if (zeta < 0) return getS1j(Qt2, -zeta, sAB);
654  // Sanity check.
655  if (Qt2 < 0. || zeta <= 0.) {
656  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
657  return 0.;
658  }
659  double sjb = zeta*sAB;
660  if (useMevolSav) sjb = sAB*(zeta - 1) - Qt2;
661  return sjb;
662 
663 }
664 
665 //--------------------------------------------------------------------------
666 
667 // Trial PDF ratio.
668 
669 double TrialIIConvA::trialPDFratio(BeamParticle* beamAPtr, BeamParticle*,
670  int iSys, int, int, double eA, double, double Qt2A, double) {
671 
672  double xA = eA/(sqrt(shhSav)/2.0);
673  int nQuark = nGtoQISRSav;
674  if (nQuark >= 4 && Qt2A <= 4.0*mcSav*mcSav) nQuark = 3;
675  else if (nQuark >= 5 && Qt2A <= 4.0*mbSav*mbSav) nQuark = 4;
676  double oldPdf = max(beamAPtr->xfISR(iSys, 21, xA, Qt2A),TINYPDFtrial);
677 
678  // Store trial PDF weights for later use to pick flavour.
679  map<int, double> trialPdfWeight;
680  double trialPdfWeightSum = 0.0;
681  for (int idQ = -nQuark; idQ <= nQuark; idQ++) {
682  // Skip gluon.
683  if (idQ==0) continue;
684  // PDF headroom and valence flavour enhancement.
685  double fac = 2.0 + 0.5 * beamAPtr->nValence(idQ);
686  trialPdfWeight[idQ] =
687  max(fac * beamAPtr->xfISR(iSys, idQ, xA, Qt2A),TINYPDFtrial);
688  trialPdfWeightSum += trialPdfWeight[idQ];
689  }
690  // Pick trial flavour ID and store weight for that flavour, to be
691  // used in accept probability.
692  double ranFlav = rndmPtr->flat() * trialPdfWeightSum;
693  map<int,double>::iterator it;
694  for (it = trialPdfWeight.begin(); it != trialPdfWeight.end(); ++it) {
695  double newPdf = it->second;
696  ranFlav -= newPdf;
697  if (ranFlav < 0.) {
698  trialFlavSav = it->first;
699  trialPDFratioSav = newPdf/oldPdf;
700  break;
701  }
702  }
703  // Return sum over all flavours, to be used as evolution coefficient.
704  return trialPdfWeightSum/oldPdf;
705 
706 }
707 
708 //==========================================================================
709 
710 // Soft-eikonal trial function for IF (derived base class)
711 
712 //--------------------------------------------------------------------------
713 
714 // Trial antenna function.
715 
716 double TrialIFSoft::aTrial(double saj, double sjk, double sAK) {
717  if (saj < 0. || sjk < 0.) return 0.;
718  const double ant = 2. * pow2(sAK + sjk)/saj/sjk/sAK;
719  return ant;
720 }
721 
722 //--------------------------------------------------------------------------
723 
724 // Generate a new Q value, with first-order running alphaS.
725 
726 double TrialIFSoft::genQ2run(double q2old, double sAK,
727  double zMin, double zMax, double colFac, double PDFratio,
728  double b0, double kR, double Lambda, double, double,
729  double headroomFac, double enhanceFac) {
730 
731  // Sanity checks.
732  if (!checkInit()) return 0.0;
733  if (sAK < 0. || q2old < 0.) return 0.0;
734 
735  // Enhance factors < 1: do not modify trial probability.
736  enhanceFac = max(enhanceFac, 1.0);
737 
738  // Generate new trial scale.
739  double Iz = getIz(zMin, zMax);
740  double comFac = 2.0*M_PI*b0/(Iz*colFac*PDFratio*headroomFac*enhanceFac);
741  double ran = rndmPtr->flat();
742  double facLam = pow2(Lambda/kR);
743  return exp(pow(ran, comFac) * log(q2old/facLam)) * facLam;
744 
745 }
746 
747 //--------------------------------------------------------------------------
748 
749 // Generate a new Q value, with constant trial alphaS.
750 
751 double TrialIFSoft::genQ2(double q2old, double sAK,
752  double zMin, double zMax, double colFac, double alphaS, double PDFratio,
753  double, double, double headroomFac, double enhanceFac) {
754 
755  // Sanity checks.
756  if (!checkInit()) return 0.0;
757  if (sAK < 0. || q2old < 0.) return 0.0;
758 
759  // Enhance factors < 1: do not modify trial probability.
760  enhanceFac = max(enhanceFac, 1.0);
761 
762  // Generate new trial scale.
763  double Iz = getIz(zMin, zMax);
764  double comFac = 2.0*M_PI/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
765  double ran = rndmPtr->flat();
766  return q2old * pow(ran, comFac/alphaS);
767 
768 }
769 
770 //--------------------------------------------------------------------------
771 
772 // Generate a new zeta value in [zMin,zMax].
773 
774 double TrialIFSoft::genZ(double zMin, double zMax) {
775  if (zMin > zMax || zMin < 0.) return -1.;
776  const double ran = rndmPtr->flat();
777  const double facRan = pow( zMin * (zMax-1.) / zMax / (zMin -1.), ran );
778  const double z = zMin * 1./(zMin - (zMin - 1) * facRan);
779  return z;
780 }
781 
782 //--------------------------------------------------------------------------
783 
784 // The zeta integral: dzeta/zeta/(zeta-1).
785 
786 double TrialIFSoft::getIz(double zMin, double zMax) {
787  if (zMin >= zMax || zMin <= 1.) return 0.0;
788  const double c = (zMax - 1) * zMin / ( (zMin - 1) * zMax );
789  return log(c);
790 }
791 
792 //--------------------------------------------------------------------------
793 
794 // The zeta boundaries, for a given value of the evolution scale.
795 
796 double TrialIFSoft::getZmin(double Qt2, double sAK, double, double) {
797  return (Qt2 + sAK)/sAK;
798 }
799 
800 double TrialIFSoft::getZmax(double, double, double eA, double eBeamUsed) {
801  const double xA = eA/(sqrt(shhSav)/2.0);
802  const double eAmax = ( (sqrt(shhSav)/2.0) - (eBeamUsed-eA) );
803  const double xAmax = eAmax/(sqrt(shhSav)/2.0);
804  return xAmax / xA;
805 }
806 
807 //--------------------------------------------------------------------------
808 
809 // Inverse transforms to obtain saj and sjk from Qt2 and zeta.
810 
811 double TrialIFSoft::getS1j(double Qt2, double zeta, double sAK) {
812 
813  // If zeta < 0, swap invariants.
814  if (zeta < 0) return getSj2(Qt2, -zeta, sAK);
815  // Sanity check.
816  if (Qt2 < 0. || zeta <= 0.) {
817  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
818  return 0.;
819  }
820  return Qt2*zeta/(zeta - 1.0);
821 
822 }
823 
824 double TrialIFSoft::getSj2(double Qt2, double zeta, double sAK) {
825 
826  // If zeta < 0, swap invariants.
827  if (zeta < 0) return getS1j(Qt2,-zeta,sAK);
828 
829  // Sanity check.
830  if (Qt2 < 0. || zeta <= 0.) {
831  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
832  return 0.;
833  }
834  return sAK*(zeta - 1.0);
835 
836 }
837 
838 //--------------------------------------------------------------------------
839 
840 // Trial PDF ratio.
841 
842 double TrialIFSoft::trialPDFratio(BeamParticle*, BeamParticle*,
843  int, int, int, double, double, double, double) {
844  trialPDFratioSav = 1.3;
845  return trialPDFratioSav;
846 }
847 
848 //==========================================================================
849 
850 // Specialised soft-eikonal trial function for initial-final when
851 // initial-state parton is a valence quark.
852 
853 //--------------------------------------------------------------------------
854 
855 // Trial antenna function. This trial generator uses PDF <= const as
856 // overestimate => x-factor.
857 
858 double TrialVFSoft::aTrial(double saj, double sjk, double sAK) {
859  if (saj < 0. || sjk < 0.) return 0.;
860  const double ant = 2. * pow2(sAK + sjk)/saj/sjk/sAK;
861  const double xFactor = (sAK + sjk)/sAK;
862  return xFactor * ant;
863 }
864 
865 //--------------------------------------------------------------------------
866 
867 // Generate a new zeta value in [zMin,zMax].
868 
869 double TrialVFSoft::genZ(double zMin, double zMax) {
870  if (zMin > zMax || zMin < 0.) return -1.;
871  double ran = rndmPtr->flat();
872  double z = 1 + (zMin - 1.) * pow( (zMax - 1.)/(zMin - 1.),ran);
873  return z;
874 }
875 
876 //--------------------------------------------------------------------------
877 
878 // The zeta integral: dzeta/(zeta-1).
879 
880 double TrialVFSoft::getIz(double zMin, double zMax) {
881  if (zMin >= zMax || zMin <= 1.) return 0.0;
882  const double c = (zMax - 1) / (zMin - 1);
883  return log(c);
884 }
885 
886 //==========================================================================
887 
888 // A gluon collinear trial function for initial-final.
889 
890 //--------------------------------------------------------------------------
891 
892 // Trial antenna function.
893 
894 double TrialIFGCollA::aTrial(double saj, double sjk, double sAK) {
895  if (saj < 0. || sjk < 0.) return 0.;
896  return 2.*pow2((sAK + sjk)/sAK)/saj;
897 }
898 
899 //--------------------------------------------------------------------------
900 
901 // Generate a new Q value, with first-order running alphaS.
902 
903 double TrialIFGCollA::genQ2run(double q2old, double sAK,
904  double zMin, double zMax, double colFac, double PDFratio,
905  double b0, double kR, double Lambda, double, double,
906  double headroomFac, double enhanceFac) {
907 
908  // Sanity checks.
909  if (!checkInit()) return 0.0;
910  if (sAK < 0. || q2old < 0.) return 0.0;
911 
912  // Enhance factors < 1: do not modify trial probability.
913  enhanceFac = max(enhanceFac, 1.0);
914 
915  // Generate new trial scale.
916  double Iz = getIz(zMin, zMax);
917  double comFac = 2.0*M_PI*b0/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
918  double ran = rndmPtr->flat();
919  double facLam = pow2(Lambda/kR) ;
920  return exp(pow(ran, comFac) * log(q2old/facLam)) * facLam;
921 
922 }
923 
924 //--------------------------------------------------------------------------
925 
926 // Generate a new Q value, with constant trial alphaS.
927 
928 double TrialIFGCollA::genQ2(double q2old, double sAK,
929  double zMin, double zMax, double colFac, double alphaS, double PDFratio,
930  double, double, double headroomFac, double enhanceFac) {
931 
932  // Sanity checks.
933  if (!checkInit()) return 0.0;
934  if (sAK < 0. || q2old < 0.) return 0.0;
935 
936  // Enhance factors < 1: do not modify trial probability.
937  enhanceFac = max(enhanceFac,1.0);
938 
939  // Generate new trial scale.
940  double Iz = getIz(zMin, zMax);
941  double comFac = 2.0*M_PI/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
942  double ran = rndmPtr->flat();
943  return q2old * pow(ran, comFac/alphaS);
944 }
945 
946 //--------------------------------------------------------------------------
947 
948 // Generate a new zeta value in [zMin,zMax].
949 
950 double TrialIFGCollA::genZ(double zMin, double zMax) {
951  if (zMin > zMax || zMin < 0.) return -1.;
952  double ran = rndmPtr->flat();
953  return zMax*pow(zMin/zMax,ran);
954 }
955 
956 //--------------------------------------------------------------------------
957 
958 // The zeta integral.
959 
960 double TrialIFGCollA::getIz(double zMin, double zMax) {
961  if (zMin > zMax || zMin < 0.) return 0.0;
962  return log(zMax/zMin);
963 }
964 
965 //--------------------------------------------------------------------------
966 
967 // The zeta boundaries, for a given value of the evolution scale.
968 
969 double TrialIFGCollA::getZmin(double Qt2, double sAK, double, double) {
970  return (Qt2+sAK)/sAK;
971 }
972 
973 double TrialIFGCollA::getZmax(double, double, double eA, double eBeamUsed) {
974  const double xA = eA/(sqrt(shhSav)/2.0);
975  const double eAmax = ( (sqrt(shhSav)/2.0) - (eBeamUsed - eA) );
976  const double xAmax = eAmax/(sqrt(shhSav)/2.0);
977  return xAmax/xA;
978 }
979 
980 //--------------------------------------------------------------------------
981 
982 // Inverse transforms to obtain saj and sjk from Qt2 and zeta.
983 
984 double TrialIFGCollA::getS1j(double Qt2, double zeta, double sAK) {
985 
986  // If zeta < 0, swap invariants.
987  if (zeta < 0) return getSj2(Qt2,-zeta,sAK);
988  // Sanity check.
989  if (Qt2 < 0. || zeta <= 0.) {
990  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
991  return 0.;
992  }
993  return Qt2*zeta/(zeta - 1.0);
994 
995 }
996 
997 double TrialIFGCollA::getSj2(double Qt2, double zeta, double sAK) {
998 
999  // If zeta < 0, swap invariants.
1000  if (zeta < 0) return getS1j(Qt2,-zeta,sAK);
1001  // Sanity check.
1002  if (Qt2 < 0. || zeta <= 0.) {
1003  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
1004  return 0.;
1005  }
1006  return sAK*(zeta - 1.0);
1007 
1008 }
1009 
1010 //--------------------------------------------------------------------------
1011 
1012 // Trial PDF ratio (= just a simple headroom factor).
1013 
1014 double TrialIFGCollA::trialPDFratio(BeamParticle*, BeamParticle*,
1015  int, int, int, double, double, double, double) {
1016  trialPDFratioSav = 1.3;
1017  return trialPDFratioSav;
1018 }
1019 
1020 //==========================================================================
1021 
1022 // A splitting trial function for initial-final, q -> gqbar.
1023 
1024 //--------------------------------------------------------------------------
1025 
1026 // Trial antenna function.
1027 
1028 double TrialIFSplitA::aTrial(double saj, double sjk, double sAK) {
1029  if (saj < 0. || sjk < 0.) return 0.;
1030  return 2.0/sAK*(sAK + sjk)/saj;
1031 }
1032 
1033 //--------------------------------------------------------------------------
1034 
1035 // Generate a new Q value, with first-order running alphaS.
1036 
1037 double TrialIFSplitA::genQ2run(double q2old, double sAK,
1038  double zMin, double zMax, double colFac, double PDFratio,
1039  double b0, double kR, double Lambda, double, double,
1040  double headroomFac, double enhanceFac) {
1041 
1042  // Sanity checks.
1043  if (!checkInit()) return 0.0;
1044  if (sAK < 0. || q2old < 0.) return 0.0;
1045 
1046  // Enhance factors < 1: do not modify trial probability.
1047  enhanceFac = max(enhanceFac, 1.0);
1048 
1049  // Generate new trial scale
1050  double Iz = getIz(zMin,zMax);
1051  double comFac = 2.0*M_PI*b0/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
1052  double ran = rndmPtr->flat();
1053  double facLam = pow2(Lambda/kR);
1054  return exp(pow(ran, comFac) * log(q2old/facLam)) * facLam;
1055 
1056 }
1057 
1058 //--------------------------------------------------------------------------
1059 
1060 // Generate a new Q value, with constant trial alphaS.
1061 
1062 double TrialIFSplitA::genQ2(double q2old, double sAK,
1063  double zMin, double zMax, double colFac, double alphaS, double PDFratio,
1064  double, double, double headroomFac, double enhanceFac) {
1065 
1066  // Sanity checks.
1067  if (!checkInit()) return 0.0;
1068  if (sAK < 0. || q2old < 0.) return 0.0;
1069 
1070  // Enhance factors < 1: do not modify trial probability.
1071  enhanceFac = max(enhanceFac, 1.0);
1072 
1073  // Generate new trial scale.
1074  double Iz = getIz(zMin,zMax);
1075  double comFac = 2.0*M_PI/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
1076  double ran = rndmPtr->flat();
1077  return q2old * pow(ran, comFac/alphaS);
1078 
1079 }
1080 
1081 //--------------------------------------------------------------------------
1082 
1083 // Generate a new Q value, with running of the PDFs towards the mass
1084 // threshold.
1085 
1086 double TrialIFSplitA::genQ2thres(double q2old, double sAK,
1087  double zMin, double zMax, double colFac, double alphaS, double PDFratio,
1088  int idA, int, double, double, bool,
1089  double headroomFac, double enhanceFac) {
1090 
1091  // Use only if the user wants to get rid of c and b quarks and use
1092  // only in the right evolution window.
1093  double mQ = (abs(idA) == 4 ? mcSav : mbSav);
1094 
1095  // Sanity checks.
1096  if (!checkInit()) return 0.0;
1097  if (sAK < 0. || q2old < 0.) return 0.0;
1098 
1099  // Enhance factors < 1: do not modify trial probability.
1100  enhanceFac = max(enhanceFac, 1.0);
1101 
1102  // Generate new trial scale.
1103  double Iz = getIz(zMin, zMax);
1104  double comFac = 2.0*M_PI/Iz/colFac/alphaS/PDFratio/(headroomFac*enhanceFac);
1105  double ran = rndmPtr->flat();
1106  return (exp(pow(ran, comFac) * log(q2old/pow2(mQ))) * pow2(mQ));
1107 
1108 }
1109 
1110 //--------------------------------------------------------------------------
1111 
1112 // Generate a new zeta value in [zMin,zMax].
1113 
1114 double TrialIFSplitA::genZ(double zMin, double zMax) {
1115  if (zMin > zMax || zMin < 0.) return -1.;
1116  double ran = rndmPtr->flat();
1117  return pow(ran*(1./zMax - 1./zMin) + 1./zMin, -1.0);
1118 }
1119 
1120 //--------------------------------------------------------------------------
1121 
1122 // The zeta integral.
1123 
1124 double TrialIFSplitA::getIz(double zMin, double zMax) {
1125  if (zMin > zMax || zMin < 0.) return 0.0;
1126  return (1./zMin - 1./zMax);
1127 }
1128 
1129 //--------------------------------------------------------------------------
1130 
1131 // The zeta boundaries, for a given value of the evolution scale.
1132 
1133 double TrialIFSplitA::getZmin(double Qt2, double sAK, double, double) {
1134  if (useMevolSav) return max(1.0, Qt2/sAK);
1135  else return (Qt2 + sAK)/sAK;
1136 }
1137 
1138 double TrialIFSplitA::getZmax(double, double, double eA, double eBeamUsed) {
1139  double xA = eA/(sqrt(shhSav)/2.0);
1140  double eAmax = ((sqrt(shhSav)/2.0) - (eBeamUsed - eA));
1141  double xAmax = eAmax/(sqrt(shhSav)/2.0);
1142  return xAmax/xA;
1143 }
1144 
1145 //--------------------------------------------------------------------------
1146 
1147 // Inverse transforms to obtain saj and sjk from Qt2 and zeta.
1148 
1149 double TrialIFSplitA::getS1j(double Qt2, double zeta, double sAK) {
1150 
1151  // If zeta < 0, swap invariants.
1152  if (zeta < 0) return getSj2(Qt2, -zeta, sAK);
1153  // Sanity check.
1154  if (Qt2 < 0. || zeta <= 0.) {
1155  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
1156  return 0.;
1157  }
1158  double saj = Qt2;
1159  if (!useMevolSav) saj *= zeta/(zeta - 1.0);
1160  return saj;
1161 
1162 }
1163 
1164 double TrialIFSplitA::getSj2(double Qt2, double zeta, double sAK) {
1165 
1166  // If zeta < 0, swap invariants.
1167  if (zeta < 0) return getS1j(Qt2, -zeta, sAK);
1168  // Sanity check
1169  if (Qt2 < 0. || zeta <= 0.) {
1170  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
1171  return 0.;
1172  }
1173  double sjk = sAK*(zeta - 1.0);
1174  if (useMevolSav) sjk = (zeta - 1.0)*sAK;
1175  return sjk;
1176 
1177 }
1178 
1179 //--------------------------------------------------------------------------
1180 
1181 // Trial PDF ratio.
1182 
1183 double TrialIFSplitA::trialPDFratio(BeamParticle* beamAPtr, BeamParticle*,
1184  int iSys, int idA, int, double eA, double, double Qt2A, double) {
1185  double xA = eA/(sqrt(shhSav)/2.0);
1186  double newPdf = max(beamAPtr->xfISR(iSys, 21, xA, Qt2A), TINYPDFtrial);
1187  double oldPdf = max(beamAPtr->xfISR(iSys, idA, xA, Qt2A), TINYPDFtrial);
1188  trialPDFratioSav = newPdf/oldPdf;
1189  return trialPDFratioSav;
1190 }
1191 
1192 //==========================================================================
1193 
1194 // K splitting trial function for IF (derived base class), g->qqbar
1195 
1196 //--------------------------------------------------------------------------
1197 
1198 // Trial antenna function.
1199 
1200 double TrialIFSplitK::aTrial(double saj, double sjk, double sAK) {
1201  if (saj < 0. || sjk < 0.) return 0.;
1202  return 1.0/2.0/sjk*pow2((sAK + sjk)/sAK);
1203 }
1204 
1205 //--------------------------------------------------------------------------
1206 
1207 // Generate a new Q value, with first-order running alphaS.
1208 
1209 double TrialIFSplitK::genQ2run(double q2old, double sAK,
1210  double zMin, double zMax, double colFac, double PDFratio,
1211  double b0, double kR, double Lambda, double, double,
1212  double headroomFac, double enhanceFac) {
1213 
1214  // Sanity checks.
1215  if (!checkInit()) return 0.0;
1216  if (sAK < 0. || q2old < 0.) return 0.0;
1217 
1218  // Enhance factors < 1: do not modify trial probability.
1219  enhanceFac = max(enhanceFac, 1.0);
1220 
1221  // Generate new trial scale.
1222  double Iz = getIz(zMin, zMax);
1223  double comFac = 8.0*M_PI*b0/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
1224  double ran = rndmPtr->flat();
1225  double facLam = pow2(Lambda/kR);
1226  return exp(pow(ran, comFac) * log(q2old/facLam)) * facLam;
1227 
1228 }
1229 
1230 //--------------------------------------------------------------------------
1231 
1232 // Generate a new Q value, with constant trial alphaS.
1233 
1234 double TrialIFSplitK::genQ2(double q2old, double sAK,
1235  double zMin, double zMax, double colFac, double alphaS, double PDFratio,
1236  double, double, double headroomFac, double enhanceFac) {
1237 
1238  // Sanity checks.
1239  if (!checkInit()) return 0.0;
1240  if (sAK < 0. || q2old < 0.) return 0.0;
1241 
1242  // Enhance factors < 1: do not modify trial probability.
1243  enhanceFac = max(enhanceFac, 1.0);
1244 
1245  // Generate new trial scale.
1246  double Iz = getIz(zMin, zMax);
1247  double comFac = 8.0*M_PI/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
1248  double ran = rndmPtr->flat();
1249  return q2old * pow(ran, comFac/alphaS);
1250 
1251 }
1252 
1253 //--------------------------------------------------------------------------
1254 
1255 // Generate a new zeta value in [zMin,zMax].
1256 
1257 double TrialIFSplitK::genZ(double zMin, double zMax) {
1258  if (zMin > zMax || zMin < 0.) return -1.;
1259  double ran = rndmPtr->flat();
1260  return ran*(zMin - zMax)+zMax;
1261 }
1262 
1263 //--------------------------------------------------------------------------
1264 
1265 // The zeta integral.
1266 
1267 double TrialIFSplitK::getIz(double zMin, double zMax) {
1268  if (zMin > zMax || zMin < 0.) return 0.0;
1269  return (zMax - zMin);
1270 }
1271 
1272 //--------------------------------------------------------------------------
1273 
1274 // The zeta boundaries, for a given value of the evolution scale.
1275 
1276 double TrialIFSplitK::getZmin(double Qt2, double sAK, double eA,
1277  double eBeamUsed) {
1278  if (useMevolSav) return 0.0;
1279  double xA = eA/(sqrt(shhSav)/2.0);
1280  double eAmax = ( (sqrt(shhSav)/2.0) - (eBeamUsed-eA) );
1281  double xAmax = eAmax/(sqrt(shhSav)/2.0);
1282  double sjkmax = sAK*(xAmax - xA)/xA;
1283  return Qt2/sjkmax;
1284 }
1285 
1286 double TrialIFSplitK::getZmax(double, double, double, double) {
1287  return 1.0;
1288 }
1289 
1290 //--------------------------------------------------------------------------
1291 
1292 // Inverse transforms to obtain saj and sjk from Qt2 and zeta.
1293 
1294 double TrialIFSplitK::getS1j(double Qt2, double zeta, double sAK) {
1295 
1296  // If zeta < 0, swap invariants.
1297  if (zeta < 0) return getSj2(Qt2, -zeta, sAK);
1298  // Sanity check.
1299  if (Qt2 < 0. || zeta <= 0.) {
1300  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
1301  return 0.;
1302  }
1303  double saj = Qt2+zeta*sAK;
1304  if (useMevolSav) saj = zeta*(sAK + Qt2);
1305  return saj;
1306 
1307 }
1308 
1309 double TrialIFSplitK::getSj2(double Qt2, double zeta, double sAK) {
1310 
1311  // If zeta < 0, swap invariants.
1312  if (zeta < 0) return getS1j(Qt2,-zeta,sAK);
1313  // Sanity check.
1314  if (Qt2 < 0. || zeta <= 0.) {
1315  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
1316  return 0.;
1317  }
1318  double sjk = Qt2;
1319  if (!useMevolSav) sjk /= zeta;
1320  return sjk;
1321 
1322 }
1323 
1324 //--------------------------------------------------------------------------
1325 
1326 // Trial PDF ratio.
1327 
1328 double TrialIFSplitK::trialPDFratio(BeamParticle*, BeamParticle*,
1329  int, int, int, double, double, double, double) {
1330  trialPDFratioSav = 1.0;
1331  return trialPDFratioSav;
1332 }
1333 
1334 //==========================================================================
1335 
1336 // A conversion trial function for IF (derived base class), g->qqbar
1337 
1338 //--------------------------------------------------------------------------
1339 
1340 // Trial antenna function.
1341 
1342 double TrialIFConvA::aTrial(double saj, double sjk, double sAK) {
1343  if (saj < 0. || sjk < 0. || sAK < 0.) return 0.;
1344  return 1.0/saj*pow2((sAK + sjk)/sAK);
1345 }
1346 
1347 //--------------------------------------------------------------------------
1348 
1349 // Generate a new Q value, with first-order running alphaS.
1350 
1351 double TrialIFConvA::genQ2run(double q2old, double sAK,
1352  double zMin, double zMax, double colFac, double PDFratio,
1353  double b0, double kR, double Lambda, double, double,
1354  double headroomFac, double enhanceFac) {
1355 
1356  // Sanity checks.
1357  if (!checkInit()) return 0.0;
1358  if (sAK < 0. || q2old < 0.) return 0.0;
1359 
1360  // Enhance factors < 1: do not modify trial probability.
1361  enhanceFac = max(enhanceFac,1.0);
1362 
1363  // Generate new trial scale.
1364  double Iz = getIz(zMin, zMax);
1365  double comFac = 4.0*M_PI*b0/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
1366  double ran = rndmPtr->flat();
1367  double facLam = pow2(Lambda/kR);
1368  return exp(pow(ran, comFac) * log(q2old/facLam)) * facLam;
1369 
1370 }
1371 
1372 //--------------------------------------------------------------------------
1373 
1374 // Generate a new Q value, with constant trial alphaS.
1375 
1376 double TrialIFConvA::genQ2(double q2old, double sAK,
1377  double zMin, double zMax, double colFac, double alphaS, double PDFratio,
1378  double, double, double headroomFac, double enhanceFac) {
1379 
1380  // Sanity checks.
1381  if (!checkInit()) return 0.0;
1382  if (sAK < 0. || q2old < 0.) return 0.0;
1383 
1384  // Enhance factors < 1: do not modify trial probability
1385  enhanceFac = max(enhanceFac, 1.0);
1386 
1387  // Generate new trial scale
1388  double Iz = getIz(zMin, zMax);
1389  double comFac = 4.0*M_PI/Iz/colFac/PDFratio/(headroomFac*enhanceFac);
1390  double ran = rndmPtr->flat();
1391  return q2old * pow(ran, comFac/alphaS);
1392 
1393 }
1394 
1395 //--------------------------------------------------------------------------
1396 
1397 // Generate a new zeta value in [zMin,zMax].
1398 
1399 double TrialIFConvA::genZ(double zMin, double zMax) {
1400  if (zMin > zMax || zMin < 0.) return -1.;
1401  double ran = rndmPtr->flat();
1402  return zMax*pow(zMin/zMax, ran);
1403 }
1404 
1405 //--------------------------------------------------------------------------
1406 
1407 // The zeta integral.
1408 
1409 double TrialIFConvA::getIz(double zMin, double zMax) {
1410  if (zMin > zMax || zMin < 0.) return 0.0;
1411  return log(zMax/zMin);
1412 }
1413 
1414 //--------------------------------------------------------------------------
1415 
1416 // The zeta boundaries, for a given value of the evolution scale.
1417 
1418 double TrialIFConvA::getZmin(double Qt2, double sAK, double, double) {
1419  if (useMevolSav) {
1420  if (Qt2<sAK) return 1.0;
1421  else return Qt2/sAK;
1422  }
1423  return (Qt2+sAK)/sAK;
1424 }
1425 
1426 double TrialIFConvA::getZmax(double, double sAK, double eA,
1427  double eBeamUsed) {
1428  double xA = eA/(sqrt(shhSav)/2.0);
1429  double eAmax = ((sqrt(shhSav)/2.0) - (eBeamUsed - eA));
1430  double xAmax = eAmax/(sqrt(shhSav)/2.0);
1431  double sjkmax = sAK*(xAmax - xA)/xA;
1432  return (sjkmax+sAK)/sAK;
1433 }
1434 
1435 //--------------------------------------------------------------------------
1436 
1437 // Inverse transforms to obtain saj and sjk from Qt2 and zeta.
1438 
1439 double TrialIFConvA::getS1j(double Qt2, double zeta, double sAK) {
1440 
1441  // If zeta < 0, swap invariants.
1442  if (zeta < 0) return getSj2(Qt2, -zeta, sAK);
1443  // Sanity check.
1444  if (Qt2 < 0. || zeta <= 0.) {
1445  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
1446  return 0.;
1447  }
1448  double saj = Qt2;
1449  if (!useMevolSav) saj *= zeta/(zeta - 1.0);
1450  return saj;
1451 
1452 }
1453 
1454 double TrialIFConvA::getSj2(double Qt2, double zeta, double sAK) {
1455 
1456  // If zeta < 0, swap invariants.
1457  if (zeta < 0) return getS1j(Qt2,-zeta,sAK);
1458  // Sanity check.
1459  if (Qt2 < 0. || zeta <= 0.) {
1460  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": unphysical input");
1461  return 0.;
1462  }
1463  double sjk = sAK*(zeta - 1.0);
1464  if (useMevolSav) sjk = (zeta - 1.0)*sAK;
1465  return sjk;
1466 
1467 }
1468 
1469 //--------------------------------------------------------------------------
1470 
1471 // Trial PDF ratio.
1472 
1473 double TrialIFConvA::trialPDFratio(BeamParticle* beamAPtr, BeamParticle*,
1474  int iSys, int, int, double eOldA, double, double Qt2A, double) {
1475 
1476  // Number of active flavours.
1477  double xOldA = eOldA/(sqrt(shhSav)/2.0);
1478  int nQuark = nGtoQISRSav;
1479  if (nQuark >= 4 && Qt2A <= 4.0*mcSav*mcSav) nQuark = 3;
1480  else if (nQuark >= 5 && Qt2A <= 4.0*mbSav*mbSav) nQuark = 4;
1481 
1482  // Old PDF.
1483  double oldPdf = max(beamAPtr->xfISR(iSys, 21, xOldA, Qt2A),TINYPDFtrial);
1484 
1485  // Store trial PDF weights for later use to pick flavour.
1486  map<int, double> trialPdfWeight;
1487  double trialPdfWeightSum = 0.0;
1488  for (int idQ = -nQuark; idQ <= nQuark; idQ++) {
1489  // Skip gluon.
1490  if (idQ == 0) continue;
1491  // PDF headroom and valence enhancement factor.
1492  double fac = 2.0 + 0.5 * beamAPtr->nValence(idQ);
1493  trialPdfWeight[idQ] =
1494  max(fac * beamAPtr->xfISR(iSys, idQ, xOldA, Qt2A),TINYPDFtrial);
1495  trialPdfWeightSum += trialPdfWeight[idQ];
1496  }
1497  // Pick trial flavour ID and store weight for that flavour, to be
1498  // used in accept probability.
1499  double ranFlav = rndmPtr->flat() * trialPdfWeightSum;
1500  for (map<int,double>::iterator it = trialPdfWeight.begin();
1501  it != trialPdfWeight.end(); ++it) {
1502  double newPdf = it->second;
1503  ranFlav -= newPdf;
1504  if (ranFlav < 0.) {
1505  trialFlavSav = it->first;
1506  trialPDFratioSav = newPdf/oldPdf;
1507  break;
1508  }
1509  }
1510  // Return sum over all flavours, to be used as evolution coefficient.
1511  return trialPdfWeightSum/oldPdf;
1512 
1513 }
1514 
1515 //==========================================================================
1516 
1517 // The BranchElementalISR class, container for 2 -> 3 trial branchings.
1518 
1519 //--------------------------------------------------------------------------
1520 // Initialise / reset a branchelemental. See header for further definitions.
1521 
1522 void BranchElementalISR::reset(int iSysIn, Event& event, int i1In, int i2In,
1523  int colIn, bool isVal1In, bool isVal2In) {
1524 
1525  // Save system.
1526  system = iSysIn;
1527  // Distinguish between II and IF types.
1528  isIIsav = ( !event[i1In].isFinal() && !event[i2In].isFinal() );
1529  // Make sure that for II 1 is the guy with p+ and 2 is the guy with p-.
1530  // IF 1 is the initial guy and 2 is the final guy.
1531  bool swap = false;
1532  if (isIIsav) swap = (event[i1In].pz() < 0.0);
1533  else swap = (event[i1In].isFinal());
1534  if (swap) {
1535  // Valence.
1536  isVal1sav = isVal2In;
1537  isVal2sav = (isIIsav ? isVal1In : false);
1538  // Indices of parents.
1539  i1sav = i2In;
1540  i2sav = i1In;
1541  } else {
1542  // Valence.
1543  isVal1sav = isVal1In;
1544  isVal2sav = (isIIsav ? isVal2In : false);
1545  // Indices of parents.
1546  i1sav = i1In;
1547  i2sav = i2In;
1548  }
1549  // Distinguish between IF types: I on side A or B.
1550  is1Asav = (event[i1sav].pz() > 0);
1551  id1sav = event[i1sav].id();
1552  id2sav = event[i2sav].id();
1553  colType1sav = event[i1sav].colType();
1554  colType2sav = event[i2sav].colType();
1555  colSav = colIn;
1556  h1sav = event[i1sav].pol();
1557  h2sav = event[i2sav].pol();
1558  e1sav = event[i1sav].e();
1559  e2sav = event[i2sav].e();
1560  // Compute and store antenna invariant mass.
1561  m2AntSav = m2(event[i1sav].p(),event[i2sav].p());
1562  mAntSav = m2AntSav >= 0 ? sqrt(m2AntSav) : sqrt(-m2AntSav);
1563  sAntSav = 2 * event[i1sav].p() * event[i2sav].p();
1564  // Trial Generators.
1565  clearTrialGenerators();
1566  nVeto = 0;
1567  nHull = 0;
1568  nHadr = 0;
1569  // Default antenna properties.
1570  // 41 = incoming on spacelike main branch.
1571  // Emission 43 = outgoing produced by a branching.
1572  // 44 = outgoing shifted by a branching.
1573  new1=Particle(0,-41,i1sav,i2sav,0,0,0,0,0.);
1574  new2=Particle(0,43,i1sav,i2sav,0,0,0,0,0.);
1575  new3=Particle(0,isIIsav?-41:44,i1sav,i2sav,0,0,0,0,0.);
1576  // Set pointers.
1577  new1.setEvtPtr(&event);
1578  new2.setEvtPtr(&event);
1579  new3.setEvtPtr(&event);
1580 
1581 }
1582 
1583 //--------------------------------------------------------------------------
1584 
1585 // Function to reset all trial generators for this branch elemental.
1586 
1587 void BranchElementalISR::clearTrialGenerators() {
1588  trialGenPtrsSav.resize(0);
1589  iAntPhysSav.resize(0);
1590  isSwappedSav.resize(0);
1591  hasSavedTrial.resize(0);
1592  scaleSav.resize(0);
1593  scaleOldSav.resize(0);
1594  zMinSav.resize(0);
1595  zMaxSav.resize(0);
1596  colFacSav.resize(0);
1597  alphaSav.resize(0);
1598  physPDFratioSav.resize(0);
1599  trialPDFratioSav.resize(0);
1600  trialFlavSav.resize(0);
1601  extraMassPDFfactorSav.resize(0);
1602  headroomSav.resize(0);
1603  enhanceFacSav.resize(0);
1604  nShouldRescue.resize(0);
1605  nVeto = 0;
1606  nHull = 0;
1607  nHadr = 0;
1608 }
1609 
1610 //--------------------------------------------------------------------------
1611 
1612 // Add a trial generator to this branch elemental.
1613 
1614 void BranchElementalISR::addTrialGenerator(int iAntPhysIn, bool swapIn,
1615  TrialGeneratorISR* trialGenPtrIn) {
1616  trialGenPtrsSav.push_back(trialGenPtrIn);
1617  iAntPhysSav.push_back(iAntPhysIn);
1618  isSwappedSav.push_back(swapIn);
1619  hasSavedTrial.push_back(false);
1620  scaleSav.push_back(-1.0);
1621  scaleOldSav.push_back(-1.0);
1622  zMinSav.push_back(0.0);
1623  zMaxSav.push_back(0.0);
1624  colFacSav.push_back(0.0);
1625  alphaSav.push_back(0.0);
1626  physPDFratioSav.push_back(0.0);
1627  trialPDFratioSav.push_back(0.0);
1628  trialFlavSav.push_back(0);
1629  extraMassPDFfactorSav.push_back(0.0);
1630  headroomSav.push_back(1.0);
1631  enhanceFacSav.push_back(1.0);
1632  nShouldRescue.push_back(0);
1633 }
1634 
1635 //--------------------------------------------------------------------------
1636 
1637 // Save a generated trial branching.
1638 
1639 void BranchElementalISR::saveTrial(int iTrial, double qOld, double qTrial,
1640  double zMin, double zMax, double colFac,double alphaEff, double pdfRatio,
1641  int trialFlav, double extraMpdf, double headroom, double enhanceFac) {
1642  hasSavedTrial[iTrial] = true;
1643  scaleOldSav[iTrial] = qOld;
1644  scaleSav[iTrial] = qTrial;
1645  if (qTrial <= 0.) return;
1646  zMinSav[iTrial] = zMin;
1647  zMaxSav[iTrial] = zMax;
1648  colFacSav[iTrial] = colFac;
1649  alphaSav[iTrial] = alphaEff;
1650  trialPDFratioSav[iTrial] = pdfRatio;
1651  trialFlavSav[iTrial] = trialFlav;
1652  extraMassPDFfactorSav[iTrial] = extraMpdf;
1653  headroomSav[iTrial] = headroom;
1654  enhanceFacSav[iTrial] = enhanceFac;
1655 }
1656 
1657 //--------------------------------------------------------------------------
1658 
1659 // Generate invariants for saved branching.
1660 
1661 bool BranchElementalISR::genTrialInvariants(double& s1j, double& sj2,
1662  double eBeamUsed, int iTrial) {
1663 
1664  // Automatically determine which trial function to use if -1 input.
1665  int iGen = iTrial;
1666  if (iGen == -1) iGen = getTrialIndex();
1667  if (iGen <= -1) return false;
1668  double z = trialGenPtrsSav[iGen]->genZ(zMinSav[iGen],zMaxSav[iGen]);
1669  // Check physical phase space (note, this only checks massless hull)
1670  // (Use absolute z value since negative z values are used to
1671  // indicate swapped invariants for mD ordering).
1672  double Q2E = pow2(scaleSav[iGen]);
1673  if (abs(z) < trialGenPtrsSav[iGen]->getZmin(Q2E,sAntSav,e1sav,eBeamUsed) ||
1674  abs(z) > trialGenPtrsSav[iGen]->getZmax(Q2E,sAntSav,e1sav,eBeamUsed))
1675  return false;
1676  // Convert to s1j, sj2.
1677  s1j = trialGenPtrsSav[iGen]->getS1j(Q2E,z,sAntSav);
1678  sj2 = trialGenPtrsSav[iGen]->getSj2(Q2E,z,sAntSav);
1679  return true;
1680 
1681 }
1682 
1683 //--------------------------------------------------------------------------
1684 
1685 // Get trial function index of winner.
1686 
1687 int BranchElementalISR::getTrialIndex() const {
1688  double qMax = 0.0;
1689  int iMax = -1;
1690  for (int i = 0; i < int(scaleSav.size()); ++i) {
1691  if (hasSavedTrial[i]) {
1692  double qSav = scaleSav[i];
1693  if (qSav > qMax) {
1694  qMax = qSav;
1695  iMax = i;
1696  }
1697  }
1698  }
1699  return iMax;
1700 }
1701 
1702 //--------------------------------------------------------------------------
1703 
1704 // Get scale of winner.
1705 
1706 double BranchElementalISR::getTrialScale() const {
1707  double qMax = 0.0;
1708  for (int i = 0; i < int(scaleSav.size()); ++i) {
1709  if (hasSavedTrial[i]) qMax = max(qMax,scaleSav[i]);
1710  else {
1711  printOut(__METHOD_NAME__,
1712  +"Error! not all trials have saved scales");
1713  }
1714  }
1715  return qMax;
1716 }
1717 
1718 //--------------------------------------------------------------------------
1719 
1720 // Simple print utility, showing the contents of the ISRBranchElemental.
1721 
1722 void BranchElementalISR::list(bool header, bool footer) const {
1723 
1724  if (header) {
1725  cout<< "\n -------- VINCIA ISR Dipole-Antenna Listing -------------"
1726  << "--------- (S=sea, V=val, F=final) "
1727  << "----------------------------------"
1728  << "---\n \n"
1729  << " sys type mothers colTypes col ID codes hels"
1730  << " m TrialGenerators\n";
1731  }
1732  cout << setw(5) << system << " ";
1733  // Instead of "I" for initial, print out "V" for valence, "S" for sea.
1734  if (isIIsav) cout << (isVal1sav ? "V" : "S") << (isVal2sav ? "V" : "S");
1735  else cout << (isVal1sav ? "V" : "S") << "F";
1736  cout << setw(5) << i1sav << " " << setw(5) << i2sav << " ";
1737  cout << setw(3) << colType1sav << " ";
1738  cout << setw(3) << colType2sav << " ";
1739  cout << setw(6) << colSav << " ";
1740  cout << setw(9) << id1sav;
1741  cout << setw(9) << id2sav << " ";
1742  // Helicities temporarily output as zero.
1743  cout << setw(2) << h1sav << " " << setw(2) << h2sav << " ";
1744  cout << setw(10) << mAnt() << " ";
1745  for (int j = 0; j < (int)trialGenPtrsSav.size(); j++) {
1746  string trialName = trialGenPtrsSav[j]->name();
1747  trialName.erase(0, 5);
1748  cout << " " << trialName;
1749  }
1750  cout << "\n";
1751  if (footer)
1752  cout << "\n -------- End VINCIA SpaceShower Antenna Listing --------"
1753  << "--------------"
1754  << "-----------------------------------------------------------\n";
1755 
1756 }
1757 
1758 //==========================================================================
1759 
1760 // The VinciaISR class.
1761 
1762 //--------------------------------------------------------------------------
1763 
1764 // Initialize shower.
1765 
1766 void VinciaISR::init(BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn) {
1767 
1768  // Check if already initialized.
1769  if (isInit)
1770  if (settingsPtr->word("Merging:Process").compare("void") == 0) return;
1771  if (verbose >= veryloud) printOut(__METHOD_NAME__, "begin --------------");
1772 
1773  // Event counters and debugging.
1774  nAccepted = -1;
1775  nSelected = -1;
1776  nVetoUserHooks = 0;
1777  nFailHadLevel = 0;
1778  nCallPythiaNext = 0;
1779  verbose = settingsPtr->mode("Vincia:verbose");
1780 
1781  // Main switches.
1782  doII = settingsPtr->flag("PartonLevel:ISR")
1783  && settingsPtr->flag("Vincia:doII");
1784  doIF = settingsPtr->flag("PartonLevel:ISR")
1785  && settingsPtr->flag("Vincia:doIF");
1786 
1787  // Beam parameters.
1788  beamFrameType = settingsPtr->mode("Beams:frameType");
1789 
1790  // Beam particles.
1791  beamAPtr = beamAPtrIn;
1792  beamBPtr = beamBPtrIn;
1793  if (beamAPtr->pz() < 0)
1794  infoPtr->errorMsg("Warning in "+__METHOD_NAME__+": beamA has pz < 0");
1795 
1796  // Assume all events in same run have same beam-beam energies.
1797  m2BeamsSav = m2(beamAPtr->p(), beamBPtr->p());
1798  eCMBeamsSav = sqrt(m2BeamsSav);
1799  eBeamA = beamAPtr->e();
1800  eBeamB = beamBPtr->e();
1801 
1802  // Possibility to allow user veto of emission step.
1803  hasUserHooks = (userHooksPtr != 0);
1804  canVetoEmission = (hasUserHooks && userHooksPtr->canVetoISREmission());
1805 
1806  // Number of active quark flavours.
1807  nGluonToQuarkI = settingsPtr->mode("Vincia:nGluonToQuark");
1808  nGluonToQuarkF = settingsPtr->mode("Vincia:nGluonToQuark");
1809  convGluonToQuarkI = settingsPtr->flag("Vincia:convertGluonToQuark");
1810  convQuarkToGluonI = settingsPtr->flag("Vincia:convertQuarkToGluon");
1811 
1812  // Mass corrections.
1813  nFlavZeroMass = settingsPtr->mode("Vincia:nFlavZeroMass");
1814  // Global flag for helicity dependence.
1815  helicityShower = settingsPtr->flag("Vincia:helicityShower");
1816  // Global flag for sector showers on/off.
1817  sectorShower = settingsPtr->flag("Vincia:sectorShower");
1818  // Allow to try other IF kinematics map if selected fails.
1819  kineMapIFretry = settingsPtr->flag("Vincia:kineMapIFretry");
1820 
1821  // Mass windows : specifies thresholds for each flavour.
1822  mt = vinComPtr->mt;
1823  mb = vinComPtr->mb;
1824  mc = vinComPtr->mc;
1825  ms = vinComPtr->ms;
1826  mtb = sqrt(mt*mb);
1827 
1828  // Perturbative cutoff.
1829  cutoffScaleII = settingsPtr->parm("Vincia:cutoffScaleII");
1830  cutoffScaleIF = settingsPtr->parm("Vincia:cutoffScaleIF");
1831 
1832  // Check PDF Q2min value and issue warning if above ISR cutoff scale(s)
1833  double xTest = 0.1;
1834  bool insideBounds = true;
1835  if (beamAPtr->isHadron()) {
1836  if (doII && !beamAPtr->insideBounds(xTest, pow2(cutoffScaleII)))
1837  insideBounds = false;
1838  if (doIF && !beamAPtr->insideBounds(xTest, pow2(cutoffScaleIF)))
1839  insideBounds = false;
1840  }
1841  if (beamBPtr->isHadron()) {
1842  if (doII && !beamBPtr->insideBounds(xTest, pow2(cutoffScaleII)))
1843  insideBounds = false;
1844  if (doIF && !beamBPtr->insideBounds(xTest, pow2(cutoffScaleIF)))
1845  insideBounds = false;
1846  }
1847  if (!insideBounds) {
1848  infoPtr->errorMsg("Warning in VinciaISR::init: PDF QMin scale is "
1849  "above ISR shower cutoff.","PDFs will be treated as frozen below QMin.");
1850  }
1851 
1852  // Set shower alphaS pointer.
1853  useCMW = settingsPtr->flag("Vincia:useCMW");
1854  alphaSptr = &vinComPtr->alphaStrong;
1855  if (useCMW) alphaSptr = &vinComPtr->alphaStrongCMW;
1856 
1857  // AlphaS parameters.
1858  alphaSorder = settingsPtr->mode("Vincia:alphaSorder");
1859  alphaSvalue = settingsPtr->parm("Vincia:alphaSvalue");
1860  aSkMu2EmitI = settingsPtr->parm("Vincia:renormMultFacEmitI");
1861  aSkMu2SplitI = settingsPtr->parm("Vincia:renormMultFacSplitI");
1862  aSkMu2Conv = settingsPtr->parm("Vincia:renormMultFacConvI");
1863  aSkMu2SplitF = settingsPtr->parm("Vincia:renormMultFacSplitF");
1864  alphaSmax = settingsPtr->parm("Vincia:alphaSmax");
1865  alphaSmuFreeze = settingsPtr->parm("Vincia:alphaSmuFreeze");
1866  mu2freeze = pow2(alphaSmuFreeze);
1867 
1868  // Smallest allow scale.
1869  alphaSmuMin = max(alphaSmuFreeze, 1.05 *alphaSptr->Lambda3());
1870  mu2min = pow2(alphaSmuMin);
1871 
1872  // Check largest numerical value of alphaS we can have.
1873  if (alphaSorder >= 1) alphaSmax = min(alphaSmax, alphaSptr->alphaS(mu2min));
1874 
1875  // If we want to get rid of heavy quarks we need to change the masses
1876  // to the ones in the pdfs.
1877  BeamParticle* beamUsePtr =
1878  ((abs(beamAPtr->id()) < 100) ? beamBPtr : beamAPtr);
1879  if ((abs(beamUsePtr->id()) > 100) && (nFlavZeroMass < 5)) {
1880  vector<double> masses;
1881  masses.resize(2);
1882  masses[0] = settingsPtr->parm("Vincia:ThresholdMB");
1883  masses[1] = settingsPtr->parm("Vincia:ThresholdMC");
1884  for (int i = 0; i < (5 - nFlavZeroMass); i++) {
1885  // Check if we can get mass from beams directly (LHAPDF6 only).
1886  if (beamUsePtr->mQuarkPDF(5 - i) > 0.0) {
1887  masses[i] = beamUsePtr->mQuarkPDF(5 - i);
1888  continue;
1889  }
1890  // If not attempt to find it.
1891  double startMass = masses[i];
1892  int maxTry = 500;
1893  double scale2Last = pow2(startMass);
1894  double xfLast = beamUsePtr->xf(5 - i ,0.001, scale2Last);
1895  for (int j = 1; j <= maxTry; j++) {
1896  double scale2Now = pow2( startMass + 0.005*((double)(j)) );
1897  double xfNow = beamUsePtr->xf(5 - i, 0.001 ,scale2Now);
1898  // Set x = 0.001 and check the gradient.
1899  if ((xfNow-xfLast) > TINY) {
1900  masses[i] = sqrt(scale2Last);
1901  break;
1902  }
1903  // Update
1904  scale2Last = scale2Now;
1905  xfLast = xfNow;
1906  }
1907  }
1908  for (int i = 0; i < (int)masses.size(); i++) {
1909  (i == 0 ? mb : mc) = masses[i];
1910  if (verbose >= quiteloud)
1911  printOut(__METHOD_NAME__, "Found " + num2str(masses[i]) +
1912  (i==0 ? " as b mass." : " as c mass."));
1913  }
1914  // Reset the derived scales.
1915  ms = min(mc, ms);
1916  mtb = sqrt(mt*mb);
1917  }
1918 
1919  // Evolution windows.
1920  regMinScalesMtSav.clear();
1921  regMinScalesSav.clear();
1922  regMinScalesNow.clear();
1923  // Fill constant version with masses.
1924  regMinScalesMtSav.push_back(mc/16.0);
1925  regMinScalesMtSav.push_back(mc/5.0);
1926  regMinScalesMtSav.push_back(mc);
1927  regMinScalesMtSav.push_back(mb);
1928  regMinScalesMtSav.push_back(mtb);
1929  regMinScalesMtSav.push_back(mt);
1930  // Fill the rest.
1931  regMinScalesSav = regMinScalesMtSav;
1932  double qMinNow = 2.0*mt;
1933  double multFac = 2.0;
1934  while (qMinNow < eCMBeamsSav) {
1935  int iRegNew = int(log(qMinNow/mt)/log(5) + 5);
1936  int iRegMax = int(regMinScalesSav.size()) - 1;
1937  if (iRegNew > iRegMax)
1938  regMinScalesSav.push_back(pow(5, (double)(iRegMax+1) - 5.0)*mt);
1939  qMinNow *= multFac;
1940  }
1941 
1942  // Trial generators.
1943  vector<TrialGeneratorISR*> trialGenerators;
1944  trialGenerators.push_back(&trialIISoft);
1945  trialGenerators.push_back(&trialIIGCollA);
1946  trialGenerators.push_back(&trialIIGCollB);
1947  trialGenerators.push_back(&trialIISplitA);
1948  trialGenerators.push_back(&trialIISplitB);
1949  trialGenerators.push_back(&trialIIConvA);
1950  trialGenerators.push_back(&trialIIConvB);
1951  trialGenerators.push_back(&trialIFSoft);
1952  trialGenerators.push_back(&trialVFSoft);
1953  trialGenerators.push_back(&trialIFGCollA);
1954  trialGenerators.push_back(&trialIFSplitA);
1955  trialGenerators.push_back(&trialIFSplitK);
1956  trialGenerators.push_back(&trialIFConvA);
1957  for (int indx = 0; indx < int(trialGenerators.size()); ++indx) {
1958  trialGenerators[indx]->initPtr(infoPtr);
1959  trialGenerators[indx]->init(mc, mb);
1960  }
1961 
1962  // Enhance settings.
1963  enhanceInHard = settingsPtr->flag("Vincia:enhanceInHardProcess");
1964  enhanceInMPI = settingsPtr->flag("Vincia:enhanceInMPIshowers");
1965  enhanceAll = settingsPtr->parm("Vincia:enhanceFacAll");
1966  enhanceBottom = settingsPtr->parm("Vincia:enhanceFacBottom");
1967  enhanceCharm = settingsPtr->parm("Vincia:enhanceFacCharm");
1968  enhanceCutoff = settingsPtr->parm("Vincia:enhanceCutoff");
1969 
1970  // Resize Paccept to the maximum number of elements.
1971  Paccept.resize(max(weightsPtr->nWeights(), 1));
1972 
1973  // Clear containers.
1974  clearContainers();
1975 
1976  // Statistics.
1977  nTrialsSum = 0;
1978  int nAntPhysMax = 20;
1979  nTrials.resize(nAntPhysMax + 1);
1980  nTrialsAccepted.resize(nAntPhysMax + 1);
1981  nFailedVeto.resize(nAntPhysMax + 1);
1982  rFailedVetoPDF.resize(nAntPhysMax + 1);
1983  nFailedHull.resize(nAntPhysMax + 1);
1984  nFailedKine.resize(nAntPhysMax + 1);
1985  nFailedMass.resize(nAntPhysMax + 1);
1986  nFailedCutoff.resize(nAntPhysMax + 1);
1987  nClosePSforHQ.resize(nAntPhysMax + 1);
1988  nSectorReject.resize(nAntPhysMax + 1);
1989 
1990  // Rescue levels.
1991  doRescue = true;
1992  nRescue = 100;
1993  rescueMin = 1.0e-6;
1994 
1995  // Initialize factorization scale and parameters for shower starting scale.
1996  pTmaxMatch = settingsPtr->mode("Vincia:pTmaxMatch");
1997  pTmaxFudge = settingsPtr->parm("Vincia:pTmaxFudge");
1998  pT2maxFudge = pow2(pTmaxFudge);
1999  pT2maxFudgeMPI = pow2(settingsPtr->parm("Vincia:pTmaxFudgeMPI"));
2000  TINYPDF = pow(10, -10);
2001 
2002  // Initialize the ISR antenna functions.
2003  if (verbose >= debug) cout <<" VinciaISR(): initializing antennaSet" << endl;
2004  antSetPtr->init();
2005 
2006  // Initialise the QED shower module if not done already.
2007  if (!qedShowerPtr->isInit()) {
2008  if (verbose >= debug)
2009  cout << " VinciaISR(): initializing QED shower module" << endl;
2010  qedShowerPtr->init(beamAPtrIn, beamBPtrIn);
2011  }
2012 
2013  // Print VINCIA header and list of parameters, call issued by ISR
2014  // since we are initialised last.
2015  if (verbose >= normal) fsrPtr->header();
2016  isInit = true;
2017  if (verbose >= veryloud) printOut(__METHOD_NAME__, "end --------------");
2018 
2019 }
2020 
2021 //--------------------------------------------------------------------------
2022 
2023 // Method to determine if max pT limit should be imposed on first emission.
2024 
2025 bool VinciaISR::limitPTmax(Event& event, double, double) {
2026 
2027  // Check if limiting pT of first emission.
2028  if (pTmaxMatch == 1) return true;
2029  else if (pTmaxMatch == 2) return false;
2030 
2031  // Always restrict SoftQCD processes.
2032  else if (infoPtr->isNonDiffractive() || infoPtr->isDiffractiveA() ||
2033  infoPtr->isDiffractiveB() || infoPtr->isDiffractiveC())
2034  return true;
2035 
2036  // Look if jets or photons in final state of hard system (iSys = 0).
2037  else {
2038  const int iSysHard = 0;
2039  for (int i = 0; i < partonSystemsPtr->sizeOut(iSysHard); ++i) {
2040  int idAbs = event[partonSystemsPtr->getOut(iSysHard, i)].idAbs();
2041  if (idAbs <= 5 || idAbs == 21 || idAbs == 22) return true;
2042  else if (idAbs == 6 && nGluonToQuarkF == 6) return true;
2043  }
2044  // If no QCD/QED partons detected, allow to go to phase-space maximum.
2045  return false;
2046  }
2047 
2048 }
2049 
2050 //--------------------------------------------------------------------------
2051 
2052 // Prepare system of partons for evolution; identify ME.
2053 
2054 void VinciaISR::prepare( int iSys, Event& event, bool) {
2055 
2056  isPrepared=false;
2057  if (!(doII || doIF)) return;
2058  if (infoPtr->getAbortPartonLevel()) {
2059  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": Aborting.");
2060  return;
2061  }
2062  if (verbose >= debug){
2063  printOut(__METHOD_NAME__, "begin --------------");
2064  if (verbose >= louddebug) {
2065  stringstream ss;
2066  ss << "Preparing system " << iSys;
2067  printOut(__METHOD_NAME__, ss.str());
2068  }
2069  if (verbose >= superdebug) {
2070  event.list();
2071  partonSystemsPtr->list();
2072  }
2073  }
2074  nAccepted = max(nAccepted, infoPtr->nAccepted());
2075 
2076  // First time prepare is called for an event.
2077  bool firstCallInEvent = (iSys == 0);
2078  // getCounter(3) number of times a Pythia::next() call has been begun.
2079  int nCallPythiaNextNow = infoPtr->getCounter(3);
2080  if (nCallPythiaNextNow > nCallPythiaNext) {
2081  nCallPythiaNext = nCallPythiaNextNow;
2082  nVetoUserHooks = 0;
2083  nFailHadLevel = 0;
2084  firstCallInEvent = true;
2085  }
2086  // Last event got accepted.
2087  long nSelectedNow = infoPtr->nSelected();
2088  if (nSelectedNow > nSelected) {
2089  nSelected = nSelectedNow;
2090  nVetoUserHooks = 0;
2091  nFailHadLevel = 0;
2092  firstCallInEvent = true;
2093  }
2094  // getCounter(10) number of times the selection of a new hard process has
2095  // been begun. = 1 if no user hooks veto, > 1 if user hooks veto.
2096  int nVetoUserHooksNow = (infoPtr->getCounter(10)-1);
2097  if (nVetoUserHooksNow > nVetoUserHooks) {
2098  nVetoUserHooks = nVetoUserHooksNow;
2099  firstCallInEvent = true;
2100  }
2101  // getCounter(14) number of times the loop over parton- and hadron-level
2102  // processing has begun for a hard process. = 1 if everything after user
2103  // hooks veto is succesful, > 1 eg if hadron level fails.
2104  int nFailHadLevelNow = (infoPtr->getCounter(14)-1);
2105  if (nFailHadLevelNow > nFailHadLevel) {
2106  nFailHadLevel = nFailHadLevelNow;
2107  firstCallInEvent = true;
2108  }
2109 
2110  // Resetting for first time in new event.
2111  if (firstCallInEvent) {
2112  // Reset counters.
2113  vinComPtr->resetCounters();
2114 
2115  // Reset the weights in new events.
2116  weightsPtr->resetWeights(infoPtr->nAccepted());
2117 
2118  // Reset all vectors for the first time we are called.
2119  clearContainers();
2120  eBeamAUsed = 0.0;
2121  eBeamBUsed = 0.0;
2122 
2123  // Evolution windows, add factorization scale.
2124  regMinScalesNow.clear();
2125  regMinScalesNow = regMinScalesMtSav;
2126  regMinScalesNow.push_back(sqrt(infoPtr->Q2Fac()));
2127  // Sort to put factorization scale at the right place.
2128  stable_sort(regMinScalesNow.begin(), regMinScalesNow.end());
2129  // Fill the rest.
2130  double qMinOld = regMinScalesNow[(int)regMinScalesNow.size()-1];
2131  double qMinNow = 2.0*qMinOld;
2132  double multFac = 2.0;
2133  while (qMinNow < eCMBeamsSav) {
2134  int iRegNew = int(log(qMinNow/qMinOld)/log(6) + 6);
2135  int iRegMax = int(regMinScalesNow.size()) - 1;
2136  if (iRegNew > iRegMax)
2137  regMinScalesNow.push_back(pow(6, (double)(iRegMax+1)-6.0)*qMinOld);
2138  qMinNow *= multFac;
2139  }
2140  }
2141 
2142  // Statistics (zero info on qBranch scales).
2143  if (iSys < 4)
2144  for (int j = 0; j < 11; ++j) {
2145  qBranch[iSys][j] = 0.0;
2146  pTphys[iSys][j] = 0.0;
2147  }
2148 
2149  // Sanity check: at least two particles in system.
2150  int sizeSystem = partonSystemsPtr->sizeAll(iSys);
2151  if (sizeSystem <= 1) return;
2152 
2153  // Check if this is a resonance-decay system; if so, let FSR deal with it.
2154  hasPrepared[iSys] = false;
2155  if ( !partonSystemsPtr->hasInAB(iSys) ) return;
2156 
2157  // Flag to tell FSR that ISR::prepare() has treated this system. We
2158  // assume that when both ISR::prepare() and FSR::prepare() are
2159  // called, the sequence is that ISR::prepare() is always called
2160  // first.
2161  hasPrepared[iSys] = true;
2162 
2163  // We don't have a starting scale for this system yet.
2164  Q2hat[iSys] = 0.0;
2165  // After prepare we always have zero branchings.
2166  nBranch[iSys] = 0;
2167  nBranchISR[iSys] = 0;
2168  // Initialise polarisation flag (false if any parton not polarised).
2169  bool finalOnly = false;
2170  if (helicityShower)
2171  polarisedSys[iSys] = mecsPtr->isPolarised(iSys, event, finalOnly);
2172  else polarisedSys[iSys] = false;
2173  if (verbose >= superdebug)
2174  printOut(__METHOD_NAME__, "Checking process class for MECs");
2175 
2176  // Set isHardSys and isResonance flags.
2177  int nIn = 0;
2178  if (partonSystemsPtr->hasInAB(iSys)) nIn = 2;
2179  if (nIn == 2 && iSys == 0) isHardSys[iSys] = true;
2180 
2181  // Make light quarks (and initial-state partons) explicitly massless.
2182  bool makeNewCopies = false;
2183  if (!vinComPtr->mapToMassless(iSys, event, partonSystemsPtr, makeNewCopies))
2184  return;
2185 
2186  // Update the beam pointers (incoming partons stored as 0,1 in
2187  // partonSystems). Needed in case makeNewCopies = true; also
2188  // ensures beamA == positive pZ.
2189  for (int iBeam = 0; iBeam <= 1; ++iBeam) {
2190  int iNew = (iBeam == 0) ? partonSystemsPtr->getInA(iSys) :
2191  partonSystemsPtr->getInB(iSys);
2192  if (iNew == 0) continue;
2193  BeamParticle& beamNow = (event[iNew].pz() > 0.0 ?
2194  *beamAPtr : *beamBPtr);
2195  double eBeamNow = (event[iNew].pz() > 0.0 ? eBeamA : eBeamB);
2196  beamNow[iSys].update( iNew, event[iNew].id(), event[iNew].e()/eBeamNow );
2197  }
2198 
2199  // Then see if we know how to compute MECs for this conf.
2200  doMECsSys[iSys] = mecsPtr->prepare(iSys, event);
2201 
2202  // Then see if and whether we can assign helicities.
2203  if (doMECsSys[iSys] && helicityShower)
2204  polarisedSys[iSys] = mecsPtr->polarise(iSys, event);
2205 
2206  // Decide if we should be doing ME corrections for next order.
2207  if (doMECsSys[iSys]) doMECsSys[iSys] = mecsPtr->doMEC(iSys, 1);
2208 
2209  // Communicate with FSR.
2210  fsrPtr->polarisedSys[iSys] = polarisedSys[iSys];
2211  fsrPtr->doMECsSys[iSys] = doMECsSys[iSys];
2212  fsrPtr->isHardSys[iSys] = isHardSys[iSys];
2213  fsrPtr->isResonanceSys[iSys] = false;
2214 
2215  // Then see if we should colourize this conf.
2216  colourPtr->colourise(iSys,event);
2217  if (verbose >= superdebug) {
2218  printOut(__METHOD_NAME__, "Event after colourise.");
2219  event.list();
2220  printOut(__METHOD_NAME__,"Making colour maps");
2221  }
2222 
2223  // Find and save all colors and anticolors.
2224  map<int,int> indexOfAcol;
2225  map<int,int> indexOfCol;
2226 
2227  // Loop over event record. Find indices of particles with color lines.
2228  for (int i = 0; i < sizeSystem; ++i) {
2229  int i1 = partonSystemsPtr->getAll( iSys, i);
2230  if ( i1 <= 0 ) continue;
2231  // Save to colour maps.
2232  int col = event[i1].col();
2233  int acol = event[i1].acol();
2234  // Cross colours for initial partons.
2235  if (!event[i1].isFinal()) {
2236  col = acol;
2237  acol = event[i1].col();
2238  if (event[i1].pz() > 0.0) {
2239  initialA[iSys] = event[i1];
2240  eBeamAUsed += event[i1].e();
2241  } else {
2242  initialB[iSys] = event[i1];
2243  eBeamBUsed += event[i1].e();
2244  }
2245  }
2246  if (col > 0) indexOfCol[col] = i1;
2247  else if (col < 0) indexOfAcol[-col] = i1;
2248  if (acol > 0) indexOfAcol[acol] = i1;
2249  else if (acol < 0) indexOfCol[-acol] = i1;
2250  }
2251 
2252  // Now loop over colored particles to create branch elementals (=antennae).
2253  int sizeOld = branchElementals.size();
2254  for (map<int,int>::iterator it = indexOfCol.begin();
2255  it != indexOfCol.end(); ++it) {
2256  // Colour index.
2257  int col = it->first;
2258  // i1 is the colour (or incoming anticolour) carrier.
2259  // i2 is the anticolour (or incoming colour) carrier.
2260  int i1 = it->second;
2261  int i2 = indexOfAcol[col];
2262  if (col == 0 || i1 == 0 || i2 == 0) continue;
2263  // Exclude final-final antennae.
2264  if ((event[i1].isFinal()) && (event[i2].isFinal())) continue;
2265  if (verbose >= louddebug ) {
2266  stringstream ss("Creating antenna between ");
2267  ss << i1 << " , " << i2 << " col = " << col;
2268  printOut(__METHOD_NAME__, ss.str());
2269  }
2270 
2271  // Check whether i1 is valence (if incoming).
2272  bool isVal1(false);
2273  if (!event[i1].isFinal()) {
2274  BeamParticle& beam1 = (event[i1].pz() > 0.0) ? *beamAPtr : *beamBPtr;
2275  isVal1 = beam1[iSys].isValence();
2276  }
2277  // Check whether i2 is valence (if incoming).
2278  bool isVal2(false);
2279  if (!event[i2].isFinal()) {
2280  BeamParticle& beam2 = (event[i2].pz() > 0.0) ? *beamAPtr : *beamBPtr;
2281  isVal2 = beam2[iSys].isValence();
2282  }
2283 
2284  // Store trial QCD antenna and add trial generators depending on type.
2285  BranchElementalISR trial(iSys, event, i1, i2, col, isVal1, isVal2);
2286  resetTrialGenerators(&trial);
2287  trial.renewTrial();
2288  branchElementals.push_back(trial);
2289  }
2290 
2291  // Count up number of gluons and quark pairs.
2292  nG[iSys] = 0;
2293  nQQ[iSys] = 0;
2294  for (int i = 0; i < (int)partsSav[iSys].size(); i++) {
2295  if (partsSav[iSys][i].id() == 21) nG[iSys]++;
2296  else if (abs(partsSav[iSys][i].id()) < 7) nQQ[iSys]++;
2297  }
2298  // Half the quarks to get quark pairs.
2299  nQQ[iSys] = nQQ[iSys]/2;
2300 
2301  // Sanity check.
2302  if ((int)branchElementals.size() == sizeOld) {
2303  if (verbose >= debug)
2304  printOut(__METHOD_NAME__, "did not find any antennae: exiting.");
2305  return;
2306  }
2307 
2308  // Set starting scale for this system.
2309  setStartScale(iSys,event);
2310  isPrepared=true;
2311  if (verbose >= debug) {
2312  if (verbose >= superdebug) list();
2313  printOut(__METHOD_NAME__, "end --------------");
2314  }
2315 }
2316 
2317 //--------------------------------------------------------------------------
2318 
2319 // Update dipole list after each ISR emission.
2320 
2321 void VinciaISR::update( int iSys, Event& event, bool) {
2322 
2323  // Skip if the branching system has no incoming partons.
2324  if (!(doII || doIF) || !isPrepared) return;
2325  if (!partonSystemsPtr->hasInAB(iSys)) return;
2326  if (verbose >= debug) {
2327  printOut(__METHOD_NAME__, "begin --------------");
2328  if (verbose >= superdebug) {
2329  stringstream ss;
2330  ss << "Updating iSys: " << iSys;
2331  printOut(__METHOD_NAME__, ss.str());
2332  event.list();
2333  printOut(__METHOD_NAME__, "list of ISR dipoles before update:");
2334  list();
2335  partonSystemsPtr->list();
2336  }
2337  }
2338  int inA = partonSystemsPtr->getInA(iSys);
2339  int inB = partonSystemsPtr->getInB(iSys);
2340  if (inA <= 0 || inB <= 0 ) {
2341  stringstream ss;
2342  ss << "in system " << iSys << " inA = " << inA << " inB = " << inB;
2343  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2344  +": Incoming particles nonpositive",ss.str());
2345  return;
2346  }
2347 
2348  // Count number of branches.
2349  nBranch[iSys]++;
2350 
2351  // Particles in the list are already updated by FSR.
2352  // Find and save all colors and anticolors.
2353  map<int,int> indexOfAcol;
2354  map<int,int> indexOfCol;
2355  // Also count number of gluons and quark pairs.
2356  nG[iSys] = 0;
2357  nQQ[iSys] = 0;
2358  for (int i = 0; i < partonSystemsPtr->sizeAll(iSys); ++i) {
2359  int i1 = partonSystemsPtr->getAll( iSys, i);
2360  if (i1 <= 0) continue;
2361  // Save to colour maps.
2362  if (i1 > event.size()) {
2363  event.list();
2364  cout << " iSys = " << iSys << " / nSys = " << partonSystemsPtr->sizeSys()
2365  << " i = " << i << " / n = " << partonSystemsPtr->sizeAll(iSys)
2366  << " i1 = " << i1 << " / event.size() = " << event.size() << endl;
2367  }
2368  int col = event[i1].col();
2369  int acol = event[i1].acol();
2370 
2371  // Switch colours for initial partons.
2372  if (!event[i1].isFinal()) {
2373  col = acol;
2374  acol = event[i1].col();
2375  }
2376  if (col > 0) indexOfCol[col] = i1;
2377  else if (col < 0) indexOfAcol[-col] = i1;
2378  if (acol > 0) indexOfAcol[acol] = i1;
2379  else if (acol < 0) indexOfCol[-acol] = i1;
2380 
2381  // Count number of gluons and quark pairs.
2382  if (event[i1].id() == 21) nG[iSys]++;
2383  else if (event[i1].idAbs() < 7) nQQ[iSys]++;
2384  }
2385  nQQ[iSys] = nQQ[iSys]/2;
2386 
2387 
2388  // Loop over the antennae, and look for changed ones.
2389  // Start from back so that if we remove one it won't mess up loop
2390  for (vector<BranchElementalISR>::iterator antIt = branchElementals.end() - 1;
2391  antIt != branchElementals.begin() - 1; --antIt) {
2392  // Only check antennae in same system.
2393  if (antIt->system != iSys) continue;
2394  bool doUpdate = false;
2395  bool doRemove = false;
2396  bool foundColour=true;
2397  int antCol = antIt->col();
2398  int i1 = antIt->geti1();
2399  int i2 = antIt->geti2();
2400  int i1New = i1;
2401  int i2New = i2;
2402 
2403  // Sanity check. We don't destroy colour lines.
2404  // Antenna colour should not have disappeared.
2405  if (indexOfAcol.find(antCol) == indexOfAcol.end()) {
2406  if (verbose >= normal) infoPtr->errorMsg("Warning in "+__METHOD_NAME__
2407  +": Could not find antenna colour in list of anti-colour indices.");
2408  foundColour = false;
2409  doRemove = true;
2410  }
2411  if (indexOfCol.find(antCol) == indexOfCol.end()) {
2412  if (verbose >= normal) infoPtr->errorMsg("Warning in "+__METHOD_NAME__
2413  +": Could not find antenna colour in list of colour indices.");
2414  foundColour = false;
2415  doRemove = true;
2416  }
2417  if (foundColour) {
2418  // Initial-initial antennae.
2419  if (antIt->isII()) {
2420 
2421  // Fetch up to date i1.
2422  // Check if i1 attached on colour or anticolour end of dipole.
2423  if (event[i1].col() >0 && event[i1].col() == antCol)
2424  i1New = indexOfAcol[antCol];
2425  else i1New = indexOfCol[antCol];
2426 
2427  // Fetch up to date i2.
2428  // Check if i1 attached on colour or anticolour end of dipole.
2429  if (event[i2].col() >0 && event[i2].col() == antCol)
2430  i2New = indexOfAcol[antCol];
2431  else i2New = indexOfCol[antCol]; //col because initial
2432 
2433  // Check if i1 is still the incoming particle.
2434  if (i1New != inA) {
2435  // Check if a QED backwards evolution.
2436  bool QEDbackwards=false;
2437  if (event[i1New].isFinal() && event[i1New].mother1()==inA &&
2438  event[inA].id()==22) QEDbackwards=true;
2439  // Otherwise we dont't know about this case.
2440  if (!QEDbackwards && verbose >= normal) {
2441  infoPtr->errorMsg("Warning in "+__METHOD_NAME__
2442  +": Could not find iA in II antenna! Removing.");
2443  }
2444  doRemove=true;
2445  }
2446 
2447  // First check if i2 is still the incoming particle.
2448  if (i2New != inB){
2449 
2450  // Check if a QED backwards evolution.
2451  bool QEDbackwards = false;
2452  if(event[i2New].isFinal() && event[i2New].mother1() == inB &&
2453  event[inB].id() == 22) QEDbackwards = true;
2454  // Otherwise we dont't know about this case.
2455  if (!QEDbackwards && verbose >= normal) {
2456  infoPtr->errorMsg("Warning in "+__METHOD_NAME__+
2457  ": Could not find iB in II antenna! Removing.");
2458  }
2459  doRemove=true;
2460  }
2461 
2462  // Check if need to update.
2463  if (!doRemove && (i1 != i1New || i2 != i2New)) doUpdate = true;
2464 
2465  // Initial-final antennae.
2466  } else {
2467 
2468  // Fetch up to date i1.
2469  // Ceck if i1 attached on colour or anticolour end of dipole.
2470  if (event[i1].col() >0 && event[i1].col() == antCol)
2471  i1New = indexOfAcol[antCol];
2472  else i1New = indexOfCol[antCol];
2473 
2474  // Fetch up to date i2.
2475  if(event[i2].col()>0 && event[i2].col()==antCol)
2476  i2New = indexOfCol[antCol];
2477  else i2New = indexOfAcol[antCol];
2478 
2479  //Check if i1New is still incoming.
2480  int inX = antIt->is1A() ? inA : inB;
2481  if (i1New != inX) {
2482 
2483  // Check if QED backwards evolution.
2484  bool QEDbackwards = false;
2485  if(event[i1New].isFinal() && event[i1New].mother1() == inX &&
2486  event[inX].id() == 22) QEDbackwards = true;
2487  // Otherwise we dont't know about this case.
2488  if (!QEDbackwards && verbose >= normal) {
2489  infoPtr->errorMsg("Warning in "+__METHOD_NAME__
2490  +": Could not find inA/inB in IF antenna! Removing.");
2491  }
2492  doRemove = true;
2493  }
2494 
2495  // Check if need to update.
2496  else if(i1 != i1New || i2 != i2New) doUpdate = true;
2497 
2498  }
2499 
2500  // Recompute antenna mass.
2501  if (doUpdate) {
2502  antIt->reset(iSys, event, i1New,i2New, antCol,
2503  antIt->isVal1(), antIt->isVal2());
2504  resetTrialGenerators(&(*antIt));
2505  }
2506  indexOfAcol.erase(antCol);
2507  indexOfCol.erase(antCol);
2508  }
2509 
2510  // Remove antenna either because something went wrong or QED
2511  // backwards evol.
2512  if (doRemove) branchElementals.erase(antIt);
2513 
2514  } // End loop over branchers.
2515 
2516  // Check leftover colour lines (dismiss any FF).
2517  // Can occur e.g. if photon backwards evolves into qqbar.
2518  for (map<int,int>::iterator colIt = indexOfCol.begin();
2519  colIt != indexOfCol.end(); ++colIt) {
2520  int colNow = colIt->first;
2521  int i1Now = colIt->second;
2522  if (indexOfAcol.find(colNow) == indexOfAcol.end()) {
2523  if (verbose>=normal) {
2524  stringstream ss;
2525  ss << " Colour tag = " << colNow << " event index: " << i1Now;
2526  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2527  +": Unmatched colour index. Aborting.",ss.str());
2528  infoPtr->setAbortPartonLevel(true);
2529  return;
2530  }
2531  } else {
2532  int i2Now=indexOfAcol[colNow];
2533  if (i1Now <=0 || i2Now <= 0) {
2534  if (verbose >= normal) infoPtr->errorMsg("Error in "+__METHOD_NAME__
2535  +": Colour tag attached to impossible event index!");
2536  // Exclude final-final antennae.
2537  } else if(!event[i1Now].isFinal() || !event[i2Now].isFinal()) {
2538  if (verbose >= louddebug) {
2539  stringstream ss("Creating antenna between ");
2540  ss << i1Now << " , " << i2Now <<" col = "<< colNow;
2541  printOut(__METHOD_NAME__, ss.str());
2542  }
2543  BeamParticle& beam1 = (event[i1Now].pz() > 0.0) ?
2544  *beamAPtr : *beamBPtr;
2545  BeamParticle& beam2 = (event[i2Now].pz() > 0.0) ?
2546  *beamAPtr : *beamBPtr;
2547  bool isVal1 = beam1[iSys].isValence();
2548  bool isVal2 = beam2[iSys].isValence();
2549 
2550  // Store trial QCD antenna and add trial generators depending
2551  // on type.
2552  BranchElementalISR trial(iSys, event, i1Now, i2Now, colNow, isVal1,
2553  isVal2);
2554  resetTrialGenerators(&trial);
2555  trial.renewTrial();
2556  branchElementals.push_back(trial);
2557  }
2558  indexOfAcol.erase(colNow);
2559  }
2560  }
2561 
2562  // There was an unmatched colour line.
2563  if (indexOfAcol.size() > 0) {
2564  if (verbose >= normal)
2565  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2566  +": Unmatched anticolour index!");
2567  infoPtr->setAbortPartonLevel(true);
2568  return;
2569  }
2570 
2571  // If we are going from ME-corrected to non-ME-corrected order,
2572  // renew trials.
2573  if (doMECsSys[iSys] && !mecsPtr->doMEC(iSys, nBranch[iSys])) {
2574  doMECsSys[iSys] = false;
2575  for (int i = 0; i < (int)branchElementals.size(); i++) {
2576  BranchElementalISR* trial = &branchElementals[i];
2577  if (trial->system == iSys) trial->renewTrial();
2578  }
2579  }
2580 
2581  // Sanity check.
2582  if (branchElementals.size() <= 0) {
2583  if (verbose >= debug)
2584  printOut("VinciaISR::update", "did not find any antennae: exiting.");
2585  return;
2586  }
2587  if (verbose > debug) {
2588  if (!checkAntennae(event)) {
2589  list();
2590  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2591  +": Failed checkAntennae. Aborting.");
2592  infoPtr->setAbortPartonLevel(true);
2593  return;
2594  }
2595  }
2596  if (verbose >= debug) {
2597  if (verbose >= superdebug) list();
2598  printOut(__METHOD_NAME__, "end --------------");
2599  }
2600 
2601 }
2602 
2603 //--------------------------------------------------------------------------
2604 
2605 // Select next pT in downwards evolution.
2606 
2607 double VinciaISR::pTnext( Event& event, double pTevolBegAll,
2608  double pTevolEndAll, int, bool) {
2609 
2610  // Check if we are supposed to do anything.
2611  if (infoPtr->getAbortPartonLevel() || !(doII || doIF)) return 0.;
2612  if (verbose >= debug) printOut(__METHOD_NAME__, "begin --------------");
2613  if (branchElementals.size() <= 0) return 0.0;
2614  if (verbose >= louddebug){
2615  stringstream ss("(re)starting evolution between pTevolBegAll = ");
2616  ss << num2str(pTevolBegAll) << " and pTevolEndAll = " << pTevolEndAll;
2617  printOut(__METHOD_NAME__, ss.str());
2618  }
2619 
2620  // Checks: skipped ants (q[MPI/FSR] > qISR), qEnd < all cutoffs, no ants.
2621  bool allSkipped = true;
2622  bool qEndsmallerCutoff = true;
2623 
2624  // Denote VINCIA scales by "q", PYTHIA ones by "pTevol".
2625  double qOld = pTevolBegAll;
2626  double qEndAll = pTevolEndAll;
2627 
2628  // Initialize winner scale.
2629  double qWin = 0.0;
2630  winnerPtr = nullptr;
2631  indxWin = -1;
2632  iSysWin = -1;
2633 
2634  // Loop over antennae (in all currently existing parton systems).
2635  unsigned int nAnt = branchElementals.size();
2636  if (verbose >= superdebug) {
2637  stringstream ss("Looping over ");
2638  ss << nAnt << " antennae.";
2639  printOut(__METHOD_NAME__, ss.str());
2640  }
2641  for (unsigned int iAnt = 0; iAnt < nAnt; iAnt++) {
2642 
2643  // Shorthand for this antenna.
2644  BranchElementalISR* trialPtr = &branchElementals[iAnt];
2645  int iSys = trialPtr->system;
2646  double qMax = min(qOld, sqrt(Q2hat[iSys]));
2647  double s12 = trialPtr->sAnt();
2648  int id1 = trialPtr->id1sav;
2649  int id2 = trialPtr->id2sav;
2650  double e1 = trialPtr->e1sav;
2651  double e2 = trialPtr->e2sav;
2652  bool isII = trialPtr->isII();
2653  bool is1A = trialPtr->is1A();
2654 
2655  // Check if we are skipping this kind of antenna.
2656  if (isII && !doII) continue;
2657  else if (!isII && !doIF) continue;
2658  if (verbose >= superdebug) {
2659  stringstream ss("Processing antenna ");
2660  ss << iAnt+1 << " / " << nAnt;
2661  printOut(__METHOD_NAME__, ss.str());
2662  ss.str("Sys = ");
2663  ss << iSys << " id1 = " << id1 << " id2 = " << id2 << " nTrialGens = "
2664  << trialPtr->nTrialGenerators() << " qMax = " << qMax;
2665  printOut(__METHOD_NAME__, ss.str());
2666  }
2667 
2668  // Generate new trial branchings, starting from qMax.
2669  double qBegin = qMax;
2670  // Lowest evolution boundary: impose hadronization scale.
2671  double qEnd = qEndAll;
2672  // Cutoff scale, depends on whether we are II or IF antenna.
2673  double cutoffScale = (isII ? cutoffScaleII : cutoffScaleIF);
2674  // No trial generators for this antenna
2675  if (trialPtr->nTrialGenerators() == 0) continue;
2676 
2677  // Loop over trial functions. Find and save max trial scale.
2678  double qTrialMax = 0.0;
2679  int indxMax = -1;
2680  for (int indx = 0; indx < (int)trialPtr->nTrialGenerators(); ++indx) {
2681 
2682  // Pointer to trial generator for this trial.
2683  TrialGeneratorISR* trialGenPtr = trialPtr->trialGenPtrsSav[indx];
2684  int iAntPhys = trialPtr->getPhysIndex(indx);
2685  bool swapped = trialPtr->getIsSwapped(indx);
2686  double qBeginNow = qBegin;
2687  double qEndNow = qEnd;
2688 
2689  // Phase space limit can never be exceeded.
2690  qBeginNow = min(qBeginNow, sqrt(trialGenPtr->getQ2max(s12, e1,
2691  is1A ? eBeamAUsed : eBeamBUsed)));
2692 
2693  // If restart scale < scale we already found continue.
2694  if (qBeginNow < qWin || qBeginNow < qTrialMax) continue;
2695  if (qEndAll > cutoffScale) qEndsmallerCutoff = false;
2696 
2697  // Check if any phase space still open.
2698  if ((qBeginNow <= cutoffScale) || (qBeginNow <= qEndNow)) {
2699  // Verbose output.
2700  if (verbose >= superdebug) printOut(__METHOD_NAME__,
2701  "skipping this trial since qBeginNow = " + num2str(qBeginNow) +
2702  " cutoffScale = " + num2str(cutoffScale) +
2703  " qEndNow = " + num2str(qEndNow));
2704  continue;
2705  }
2706  allSkipped = false;
2707 
2708  // Generate new q value/no saved trial.
2709  double qTrial = qBeginNow;
2710 
2711  // Impose evolution windows.
2712  bool acceptRegion = false;
2713  int iRegion = getRegion(qTrial);
2714 
2715  // Go through regions.
2716  while (!acceptRegion) {
2717 
2718  // Set overestimated Z range for trial generation.
2719  double qMinNow = max(cutoffScale, getQmin(iRegion));
2720  double q2MinNow = pow2(qMinNow);
2721  double zMinNow = trialGenPtr->getZmin(q2MinNow, s12, e1,
2722  is1A ? eBeamAUsed : eBeamBUsed);
2723  double zMaxNow = trialGenPtr->getZmax(q2MinNow, s12, e1,
2724  is1A ? eBeamAUsed : eBeamBUsed);
2725 
2726  // Set headroom factor (= constant multiplying trial probability).
2727  double headroomFac = getHeadroomFac(iSys, iAntPhys, qMinNow);
2728  if (headroomFac < 1.)
2729  cout << " headroomFac = " << headroomFac << endl;
2730 
2731  // Check for rescue mechanism in case trial gets stuck.
2732  if (doRescue && trialPtr->getNshouldRescue(indx) >= nRescue) {
2733  // Multiply headroom.
2734  double logRescue = ((double)(trialPtr->getNshouldRescue(indx))) /
2735  ((double)(nRescue));
2736  headroomFac *= pow(10.0,-logRescue);
2737  if (verbose >= verylouddebug){
2738  stringstream ss("Applying rescue mechanism, nShouldRescue = ");
2739  ss << trialPtr->getNshouldRescue(indx)
2740  << ", multiplying headroom with 10^-" << logRescue;
2741  printOut(__METHOD_NAME__, ss.str());
2742  }
2743  }
2744 
2745  // Set PDFratio. If II the first is always side A. If IF
2746  // check which side the initial guy is. For g->qq
2747  // splittings.
2748  double PDFscale = pow2(qTrial);
2749  double pdfRatio = trialGenPtr->trialPDFratio(
2750  ((isII || is1A) ? beamAPtr : beamBPtr),
2751  ((isII || is1A) ? beamBPtr : beamAPtr),
2752  iSys, id1, id2, e1, e2, PDFscale, PDFscale);
2753  // For trial branchings that have multiple flavour combinations
2754  // (gluon conversion) check which trial flavour was picked and
2755  // store PDF ratio for that flavour.
2756  int trialFlav = trialGenPtr->trialFlav();
2757  double pdfRatioFlav = trialGenPtr->getTrialPDFratio();
2758 
2759  // Set color factor for trial.
2760  double colFac = getAnt(iAntPhys)->chargeFac();
2761  int nF = getNf(iRegion);
2762  if (iAntPhys == iXGsplitIF) colFac *= min(nF,nGluonToQuarkF);
2763 
2764  // Effective renormalization-scale prefactor.
2765  double kR = aSkMu2EmitI;
2766  if (iAntPhys == iQXsplitII || iAntPhys == iQXsplitIF)
2767  kR = aSkMu2SplitI;
2768  else if (iAntPhys == iGXconvII || iAntPhys == iGXconvIF)
2769  kR = aSkMu2Conv;
2770  else if (iAntPhys == iXGsplitIF) kR = aSkMu2SplitF;
2771  kR = sqrt(kR);
2772 
2773  // Check if we should use running alphaS.
2774  bool runAlpha = (alphaSorder >= 1);
2775  // If we are close to lambdaQCD, use constant instead.
2776  if (qMinNow < 2.5*alphaSptr->Lambda3()/kR) runAlpha = false;
2777 
2778  // Check if we should try to get rid of c and b quarks,
2779  // iRegion 2 = mc to mb, iRegion 3 = mb to mtb.
2780  int idCheck = -1;
2781  // Flavours to check.
2782  for (int i = 0; i < (5 - nFlavZeroMass); i++) {
2783  if ((abs(id1) == 5 - i) && (iRegion == 3 - i)) {
2784  if ((iAntPhys == iQXsplitII && !swapped) ||
2785  (iAntPhys == iQXsplitIF) ) idCheck = 5 - i;
2786  }
2787  if (isII && (abs(id2) == 5-i) && (iRegion == 3-i)) {
2788  if (iAntPhys == iQXsplitII && swapped) idCheck = 5-i;
2789  }
2790  }
2791  bool usePDFmassThreshold = (idCheck > 0);
2792 
2793  // Enhancements (biased kernels).
2794  bool doEnhance = false;
2795  double enhanceFac = 1.0;
2796  if (qTrial > enhanceCutoff) {
2797  if (isHardSys[iSys] && enhanceInHard) doEnhance = true;
2798  else if (!isHardSys[iSys] && partonSystemsPtr->hasInAB(iSys) &&
2799  enhanceInMPI) doEnhance = true;
2800  if (doEnhance) {
2801  enhanceFac *= enhanceAll;
2802  // At the trial level, all gluon splittings and
2803  // conversions enhanced by max(enhanceCharm,
2804  // enhanceBottom).
2805  if (min(nF,nGluonToQuarkF) >= 4 && iAntPhys == iXGsplitIF)
2806  enhanceFac *= max(enhanceCharm, enhanceBottom);
2807  else if ( nGluonToQuarkI >= 4 &&
2808  (iAntPhys == iGXconvII || iAntPhys == iGXconvIF))
2809  enhanceFac *= max(enhanceCharm,enhanceBottom);
2810  }
2811  }
2812 
2813  // Sanity check for zero branching probability.
2814  if (colFac < TINY || headroomFac < TINY) {
2815  double qTmp = qTrial;
2816  qTrial = 0.0;
2817  trialPtr->saveTrial(indx,qTmp,qTrial,0.,0.,0.,0.,pdfRatioFlav,
2818  trialFlav, 0.,0.,0.);
2819  }
2820 
2821  // Mass treatment, use PDFs mass thresholds with constant alphaS.
2822  else if (usePDFmassThreshold) {
2823  double qTmp = qTrial;
2824  // Add extra headroom, should really be multiplying trial PDF
2825  // ratio.
2826  headroomFac *= (iAntPhys == iQXsplitII ? 2.0 : 1.3);
2827  // Overestimate.
2828  double mu2eff = mu2min + pow2(kR*qMinNow);
2829  // alphaS for overestimate.
2830  double facAlphaS = min(alphaSmax, alphaSptr->alphaS(mu2eff));
2831  if (alphaSorder == 0) facAlphaS = alphaSvalue;
2832  // Generate new q value, with constant alphaS.
2833  double q2trial = trialGenPtr->genQ2thres(pow2(qTrial), s12,
2834  zMinNow, zMaxNow, colFac, facAlphaS, pdfRatio, id1, id2,
2835  e1, e2, true, headroomFac, enhanceFac);
2836  qTrial = sqrt(q2trial);
2837  double massNow = (idCheck == 4 ? mc : mb);
2838  double extraMassPDFfactor = log(q2trial/pow2(massNow));
2839  // Trial information.
2840  trialPtr->saveTrial(indx, qTmp, qTrial, zMinNow, zMaxNow, colFac,
2841  facAlphaS, pdfRatioFlav, trialFlav, extraMassPDFfactor,
2842  headroomFac, enhanceFac);
2843  if (verbose >= superdebug) printOut(__METHOD_NAME__,
2844  "Using vanishing pdfs towards the mass threshold for id1 " +
2845  num2str(id1) + " and id2 " + num2str(id2));
2846 
2847  // AlphaS running inside trial integral.
2848  } else if (runAlpha) {
2849  double qTmp = qTrial;
2850  // One-loop beta function (two-loop imposed by veto, below).
2851  double b0 = (33.0 - 2.0*nF) / (12.0 * M_PI);
2852  // Use 3-flavour Lambda for overestimate.
2853  double lambdaEff = alphaSptr->Lambda3();
2854  // Generate new q value, with alphaS running inside trial integral.
2855  double q2trial = trialGenPtr->genQ2run(pow2(qTrial), s12,
2856  zMinNow, zMaxNow, colFac, pdfRatio, b0, kR, lambdaEff,
2857  e1, e2, headroomFac, enhanceFac);
2858  qTrial = sqrt(q2trial);
2859  // Save trial information.
2860  if (qTrial > cutoffScale) {
2861  double muEff = max( 1.01, kR*qTrial/lambdaEff );
2862  double alphaEff = 1.0/b0/log(pow2(muEff));
2863  trialPtr->saveTrial(indx, qTmp, qTrial, zMinNow, zMaxNow, colFac,
2864  alphaEff, pdfRatioFlav, trialFlav, 1.0, headroomFac, enhanceFac);
2865  } else {
2866  trialPtr->saveTrial(indx, qTmp, 0.);
2867  }
2868 
2869  // AlphaS outside trial integral.
2870  } else {
2871  double qTmp = qTrial;
2872  // Constant alphaS.
2873  double facAlphaS = ( (alphaSorder >= 1) ? alphaSmax
2874  : alphaSvalue );
2875  // Generate new q value, with constant alphaS.
2876  double q2trial = trialGenPtr->genQ2(pow2(qTrial), s12,
2877  zMinNow, zMaxNow, colFac, facAlphaS, pdfRatio, e1, e2,
2878  headroomFac, enhanceFac);
2879  qTrial = sqrt(q2trial);
2880  // Save trial information.
2881  trialPtr->saveTrial(indx, qTmp, qTrial, zMinNow, zMaxNow, colFac,
2882  facAlphaS,pdfRatioFlav,trialFlav,1.0,headroomFac,enhanceFac);
2883  }
2884 
2885  // Check evolution window boundaries.
2886  if (qTrial > qMinNow) acceptRegion = true;
2887  else if (qMinNow < qWin || qMinNow < qTrialMax) {
2888  if (verbose >= verylouddebug) printOut(__METHOD_NAME__,
2889  "stopping evolution, already found scale that is bigger");
2890  acceptRegion = true;
2891  trialPtr->renewTrial(indx);
2892  qTrial = 0.0;
2893  } else if (iRegion == 0 || qTrial < cutoffScale) {
2894  acceptRegion = true;
2895  qTrial = 0.0;
2896  } else {
2897  qTrial = qMinNow;
2898  iRegion--;
2899  }
2900 
2901  } // End loop over regions.
2902  if ((qTrial > qTrialMax) && (qTrial > cutoffScale)) {
2903  qTrialMax = qTrial;
2904  indxMax = indx;
2905  }
2906 
2907  // Check for rescue mechanism in case trial gets stuck.
2908  if (doRescue && abs(qBeginNow-qTrial) < rescueMin)
2909  trialPtr->addRescue(indx);
2910  } // End loop over trial generators.
2911 
2912  // Check if trial wins.
2913  if (qTrialMax >= qWin || qWin <= 0.0) {
2914  winnerPtr = trialPtr;
2915  qWin = qTrialMax;
2916  indxWin = indxMax;
2917  iSysWin = iSys;
2918  }
2919  if (verbose >= louddebug) {
2920  stringstream ss;
2921  ss << "qTrialMax = " << qTrialMax;
2922  if (indxMax >= 0)
2923  ss <<" (" << trialPtr->trialGenPtrsSav[indxMax]->name() << ")";
2924  if(iAnt + 1 == nAnt) ss << " final qWin = ";
2925  else ss << " current qWin = ";
2926  ss << qWin <<" i1 i2 = " << winnerPtr->i1sav << " " << winnerPtr->i2sav
2927  << " in system " << iSysWin;
2928  printOut(__METHOD_NAME__, ss.str());
2929  }
2930  } // End loop over antennae.
2931 
2932  // If non-zero branching scale found: continue.
2933  if ((qWin > qEndAll) && (qWin > 0.0)) {
2934  if (verbose >= louddebug) {
2935  stringstream ss("Winner at scale qWin = ");
2936  ss << qWin << " trial type "
2937  << winnerPtr->trialGenPtrsSav[indxWin]->name();
2938  printOut(__METHOD_NAME__, ss.str());
2939  if (verbose >= verylouddebug) {
2940  ss.str("pdf ratio ");
2941  ss << winnerPtr->getPDFratioTrial(indxWin)
2942  << " col1 = " << event[winnerPtr->i1sav].col()
2943  << " acol1 = " << event[winnerPtr->i1sav].acol()
2944  << " col2 = " << event[winnerPtr->i2sav].col()
2945  << " acol2 = " << event[winnerPtr->i2sav].acol()
2946  << " in System " << iSysWin;
2947  }
2948  }
2949  } else {
2950  qWin = 0.0;
2951  // Check if qEnd < all cutoffs.
2952  if (qEndsmallerCutoff) {
2953  if (verbose >= debug) {
2954  printOut(__METHOD_NAME__, "=== All trials now below cutoff "
2955  "qEndAll = " + num2str(qEndAll, 3) + ".");
2956  if (verbose >= superdebug) {
2957  printOut(__METHOD_NAME__,"Final configuration was:");
2958  event.list();
2959  }
2960  }
2961  // ISR is done (at least for this system), set the weights.
2962  weightsPtr->doWeighting();
2963  }
2964  }
2965 
2966  // Check if we have a heavy quark in the initial state left.
2967  bool forceSplitNow = false;
2968  if ((!allSkipped) && heavyQuarkLeft(max(qWin,qEndAll))) {
2969  if (verbose >= louddebug)
2970  printOut(__METHOD_NAME__,
2971  "Going to force a splitting! qWin was " + num2str(qWin) +
2972  " with id1 = " + num2str(winnerPtr->id1sav) +
2973  " with id2 = " + num2str(winnerPtr->id2sav));
2974  // Set scale to the corresponding mass.
2975  qWin = winnerPtr->scaleSav[indxWin];
2976  winnerPtr->forceSplittingSav = true;
2977  forceSplitNow = true;
2978  } else if (winnerPtr != NULL) winnerPtr->forceSplittingSav = false;
2979  if (verbose >= debug ) {
2980  if (verbose >= superdebug) list();
2981  printOut(__METHOD_NAME__, "finished --------------");
2982  }
2983 
2984  if (qWin > pTevolBegAll && !forceSplitNow) {
2985  infoPtr->errorMsg("Warning in "+__METHOD_NAME__
2986  +": Generated scale > pTevolBegAll. Returning 0.");
2987  return 0.;
2988  }
2989 
2990  // Make sure we get the next branching.
2991  if ((qWin > 0.0) && forceSplitNow) return (pTevolEndAll-TINY);
2992  return qWin;
2993 
2994 }
2995 
2996 //--------------------------------------------------------------------------
2997 
2998 // Perform a branching (as defined by current "winner").
2999 
3000 bool VinciaISR::branch(Event& event) {
3001 
3002  // System of index of the winner and extract current QE scales..
3003  if (verbose >= debug) printOut(__METHOD_NAME__, "begin --------------");
3004  int iTrial = indxWin;
3005  double qNew = winnerPtr->getTrialScale(iTrial);
3006  double q2new = pow2(qNew);
3007  int iAntPhys = winnerPtr->getPhysIndex(iTrial);
3008  bool isII = winnerPtr->isII();
3009  bool is1A = winnerPtr->is1A();
3010  bool isSwapped = (isII ? winnerPtr->getIsSwapped(iTrial) : false);
3011  // Set to false for IF because there it was always guy 1 who did
3012  // gluon splitting/conversion in the initial state.
3013 
3014  // Count up global number of attempted trials.
3015  ++nTrialsSum;
3016  nTrials[iAntPhys]++;
3017  if (verbose >= louddebug) {
3018  stringstream ss;
3019  ss << "Processing Branching at scale Q = " << qNew;
3020  printOut(__METHOD_NAME__, ss.str());
3021  }
3022 
3023  // Recoiler, allow for both II and IF to have global recoils
3024  vector<Vec4> recoilers;
3025  vector<int> iRecs;
3026  for (int j = 0; j < partonSystemsPtr->sizeOut(iSysWin); ++j) {
3027  int ip = partonSystemsPtr->getOut(iSysWin, j);
3028  if (ip != winnerPtr->i1sav && ip != winnerPtr->i2sav) {
3029  recoilers.push_back(event[ip].p());
3030  iRecs.push_back(partonSystemsPtr->getOut(iSysWin,j));
3031  }
3032  }
3033 
3034  // Check if we have to force a splitting (to get rid of heavy quarks).
3035  bool forceSplitting = false;
3036  if (winnerPtr->forceSplittingSav) {
3037  forceSplitting = true;
3038  if (verbose >= louddebug) {
3039  stringstream ss;
3040  ss << "Forcing a splitting at q = " << qNew;
3041  printOut(__METHOD_NAME__, ss.str());
3042  }
3043  // If so, try to force the splitting at the scale we'd like to.
3044  double e1 = winnerPtr->e1sav;
3045  double q2max =
3046  winnerPtr->trialGenPtrsSav[iTrial]->getQ2max(winnerPtr->sAnt(),
3047  e1, is1A ? eBeamAUsed : eBeamBUsed);
3048  if (q2max < q2new) {
3049  q2new = q2max;
3050  qNew = sqrt(q2new);
3051  winnerPtr->scaleSav[iTrial] = 0.99*qNew;
3052  if (verbose >= louddebug ){
3053  stringstream ss;
3054  ss << "adjusted scale to q = " << qNew;
3055  printOut(__METHOD_NAME__,ss.str());
3056  }
3057  }
3058  }
3059 
3060  // Generate full trial kinematics (and reject if outside phase-space).
3061  if (!generateKinematics(event, winnerPtr, recoilers)) {
3062  // Mark this trial as "used", will need to generate a new one..
3063  winnerPtr->renewTrial(iTrial);
3064  if (verbose >= louddebug)
3065  printOut(__METHOD_NAME__, "Branching outside phase space.");
3066  return false;
3067  }
3068  // If no recoilers for this branching, e.g. local IF map, zero iRecs,
3069  if (recoilers.size() <= 0) iRecs.clear();
3070 
3071  // If we have a force splitting update scale information might have
3072  // change to ensure kinematics can be generated.
3073  if (forceSplitting) {
3074  nForceSplit++;
3075  qNew = winnerPtr->getTrialScale(iTrial);
3076  q2new = pow2(qNew);
3077  }
3078 
3079  // Assign colour flow. Note, using lastColTag here, if branching
3080  // accepted we tell Pythia.
3081  bool usedColTag = assignColourFlow(event, winnerPtr);
3082 
3083  // Check phase-space closed for getting rid of heavy quarks.
3084  vector<Particle> parts = mecsPtr->makeParticleList(iSysWin, event);
3085  if (!forceSplitting)
3086  if (!checkHeavyQuarkPhaseSpace(parts,iSysWin)) {
3087  if (verbose >= louddebug) printOut(__METHOD_NAME__,
3088  "branching rejected because phase space after branching "
3089  "does not allow forced splittings");
3090  // Mark this trial as "used", will need to generate a new one.
3091  winnerPtr->renewTrial(iTrial);
3092  ++nClosePSforHQ[iAntPhys];
3093  return false;
3094  }
3095 
3096  // Check if this branching is above cutoff scale (but don't say no
3097  // to getting rid of a massive flavour).
3098  double cutoffScale = (isII ? cutoffScaleII : cutoffScaleIF);
3099  // Check only if we don't force a splitting.
3100  if (!forceSplitting && sqrt(q2new) < cutoffScale) {
3101  bool isMassiveQsplit = false;
3102  if (iAntPhys == iQXsplitIF)
3103  isMassiveQsplit = (abs(winnerPtr->id1sav) > nFlavZeroMass);
3104  else if (iAntPhys==iQXsplitII) {
3105  isMassiveQsplit = ( isSwapped
3106  ? (abs(winnerPtr->id2sav) > nFlavZeroMass)
3107  : (abs(winnerPtr->id1sav) > nFlavZeroMass) );
3108  }
3109 
3110  // Reject and mark as "used", will need to generate a new trial.
3111  if (!isMassiveQsplit) {
3112  winnerPtr->renewTrial(iTrial);
3113  ++nFailedCutoff[iAntPhys];
3114  if (verbose > superdebug)
3115  printOut(__METHOD_NAME__,"Branching is below cutoff: reject.");
3116  return false;
3117  }
3118  }
3119 
3120  // Veto step, decide whether to accept or reject branching, skip for
3121  // forced splitting.
3122  if (!forceSplitting) {
3123  if (!acceptTrial(event, winnerPtr)) {
3124  // Mark this trial as "used", will need to generate a new one.
3125  winnerPtr->renewTrial(iTrial);
3126  if (verbose > superdebug)
3127  printOut(__METHOD_NAME__,"Branching rejected.");
3128  return false;
3129  }
3130  }
3131 
3132  // Put new particles into event record, store a copy of event, to be
3133  // used if branching vetoed by userHooks.
3134  Event evtOld = event;
3135  int evtSizeOld = evtOld.size();
3136  int i1sav = winnerPtr->i1sav;
3137  int i2sav = winnerPtr->i2sav;
3138  winnerPtr->new1.scale(qNew);
3139  winnerPtr->new2.scale(qNew);
3140  winnerPtr->new3.scale(qNew);
3141  int iNew1 = event.append(winnerPtr->new1);
3142  int iNew3 = event.append(winnerPtr->new3);
3143  int iNew2 = event.append(winnerPtr->new2);
3144  // Check for recoilers from II (or IF with global recoil map) branchings.
3145  vector< pair<int,int> > iRecNew; iRecNew.clear(); iRecNew.resize(0);
3146  if (iRecs.size() >= 1)
3147  for (int j = 0; j < event.size(); ++j)
3148  if (event[j].isFinal())
3149  for (int k = 0; k < (int)iRecs.size(); k++)
3150  // Copy recoiler change momentum.
3151  if (iRecs[k] == j) {
3152  int inew = event.copy(j,44);
3153  event[inew].p(recoilers[k]);
3154  iRecNew.push_back(make_pair(iRecs[k],inew));
3155  }
3156  // Update event pointers if necessary.
3157  event.restorePtrs();
3158  // Check if we went from polarised to unpolarised state If so,
3159  // depolarise parton state. A more complete alternative here would
3160  // be to create depolarised copies of all partons and then update
3161  // everything, but deemed unnecessary for now.
3162  if ( event[i1sav].pol() != 9 && event[i2sav].pol() != 9 &&
3163  (event[iNew1].pol() == 9 || event[iNew2].pol() == 9 ||
3164  event[iNew3].pol() == 9)) {
3165  if (verbose >= louddebug)
3166  printOut(__METHOD_NAME__, "Depolarizing parton state");
3167 
3168  // Depolarise parton state (except the branching mothers, which
3169  // will be replaced by unpolarised daughters).
3170  int sizeSystem = partonSystemsPtr->sizeOut(iSysWin);
3171  for (int i = 0; i < sizeSystem; ++i) {
3172  int i1 = partonSystemsPtr->getOut( iSysWin, i);
3173  // Skip if not present in final state.
3174  if ( i1 <= 0 || !event[i1].isFinal()) continue;
3175  // Skip if mother parton to be replaced by daughter.
3176  if ( i1 == winnerPtr->i1sav || i1 == winnerPtr->i2sav) continue;
3177  // Else depolarise.
3178  if ( event[i1].pol() != 9 ) event[i1].pol(9);
3179  }
3180  // Also make sure all daughters are depolarised as well.
3181  winnerPtr->new1.pol(9);
3182  winnerPtr->new2.pol(9);
3183  winnerPtr->new3.pol(9);
3184  }
3185 
3186  // Set mothers and daughters, mark original dipole partons as branched.
3187  event[i1sav].statusNeg();
3188  event[i2sav].statusNeg();
3189  if (isII) {
3190  // New initial partons inherit mothers (beam).
3191  event[iNew1].mothers(event[i1sav].mother1(), event[i1sav].mother2());
3192  event[iNew3].mothers(event[i2sav].mother1(), event[i2sav].mother2());
3193  // Gluon emission.
3194  if (event[iNew2].id() == 21) {
3195  // iNew1 a inherits mothers of A, daughters are A and j.
3196  event[iNew1].daughters(iNew2, i1sav);
3197  // iNew3 b inherits mothers of B, daughters are B and j.
3198  event[iNew3].daughters(iNew2, i2sav);
3199  // iNew2 j gets a and b as mothers, no daughters.
3200  event[iNew2].mothers(iNew1, iNew3);
3201 
3202  // Gluon splitting or conversion in the initial state: side A.
3203  } else if (!isSwapped) {
3204  // iNew1 a inherits mothers of A, daughters are A and j.
3205  event[iNew1].daughters(iNew2, i1sav);
3206  // iNew3 b inherits mothers of B, daughter is B.
3207  event[iNew3].daughters(i2sav, 0);
3208  // iNew2 j gets a as mother, no daughters.
3209  event[iNew2].mothers(iNew1, 0);
3210 
3211  // Gluon splitting or conversion in the initial state: side B.
3212  } else {
3213  // iNew1 a inherits mothers of A, daughter is A.
3214  event[iNew1].daughters(i1sav, 0);
3215  // iNew3 b inherits mothers of B, daughters are B and j.
3216  event[iNew3].daughters(iNew2, i2sav);
3217  // iNew2 j gets b as mother, no daughters.
3218  event[iNew2].mothers(iNew3 ,0);
3219  }
3220  // i1sav A keeps its daughters, gets a as mother.
3221  event[i1sav].mothers(iNew1, 0);
3222  // i2sav B keeps its daughters, gets b as mother.
3223  event[i2sav].mothers(iNew3, 0);
3224  // iNew2 j has no daughters.
3225  event[iNew2].daughters(0, 0);
3226  // Put a and b as daughters of the beam for hard process.
3227  if (isHardSys[iSysWin]) {
3228  bool founda = false;
3229  bool foundb = false;
3230  for (int i=0; i<(int)event.size(); i++) {
3231  if (!founda)
3232  if (event[i].daughter1() == i1sav) {
3233  event[i].daughters(iNew1, 0);
3234  founda = true;
3235  }
3236  if (!foundb)
3237  if (event[i].daughter1() == i2sav) {
3238  event[i].daughters(iNew3, 0);
3239  foundb = true;
3240  }
3241  if (founda && foundb) break;
3242  }
3243  }
3244  } else {
3245  // New initial parton inherits mothers (beam).
3246  event[iNew1].mothers(event[i1sav].mother1(), event[i1sav].mother2());
3247  // Gluon emission.
3248  if (event[iNew2].id()==21) {
3249  // iNew1 a inherits mothers of A, daughters are A and j.
3250  event[iNew1].daughters(iNew2, i1sav);
3251  // i2sav K gets k and j as daughters, keeps its mothers.
3252  event[i2sav].daughters(iNew2, iNew3);
3253  // iNew3 k gets K as mother, no daughters.
3254  event[iNew3].mothers(i2sav, 0);
3255  // iNew2 j gets a and K as mothers, no daughters.
3256  event[iNew2].mothers(i2sav, iNew1);
3257 
3258  // Gluon splitting or conversion in the initial state
3259  } else if (iAntPhys==iQXsplitIF || iAntPhys==iGXconvIF) {
3260  // iNew1 a inherits mothers of A, daughters are A and j.
3261  event[iNew1].daughters(iNew2, i1sav);
3262  // i2sav K gets k as daughter, keeps its mothers.
3263  event[i2sav].daughters(iNew3, 0);
3264  // iNew3 k gets K as mother, no daughters.
3265  event[iNew3].mothers(i2sav, 0);
3266  // iNew2 j gets a as mother, no daughters.
3267  event[iNew2].mothers(iNew1, 0);
3268 
3269  // Gluon splitting in the final state
3270  } else {
3271  // iNew1 a inherits mothers of A, daughteris A.
3272  event[iNew1].daughters(i1sav, 0);
3273  // i2sav K gets k and j as daughters, keeps its mothers.
3274  event[i2sav].daughters(iNew2, iNew3);
3275  // iNew3 k gets K as mother, no daughters.
3276  event[iNew3].mothers(i2sav, 0);
3277  // iNew2 j gets K as mother, no daughters.
3278  event[iNew2].mothers(i2sav, 0);
3279  }
3280  // i1sav A keeps its daughters, gets a as mother.
3281  event[i1sav].mothers(iNew1, 0);
3282  // iNew3 5 has no daughters.
3283  event[iNew3].daughters(0, 0);
3284  // iNew2 j has no daughters.
3285  event[iNew2].daughters(0, 0);
3286  // Put a as daughter of the beam for hard process.
3287  if (isHardSys[iSysWin])
3288  for (int i = 0; i < (int)event.size(); i++)
3289  if (event[i].daughter1() == i1sav) {
3290  event[i].daughters(iNew1, 0);
3291  break;
3292  }
3293  }
3294 
3295  // Veto by userHooks, possibility to allow user veto of emission step.
3296  if (canVetoEmission)
3297  if (userHooksPtr->doVetoISREmission(evtSizeOld, event, iSysWin)) {
3298  event = evtOld;
3299  if (verbose >= superdebug)
3300  printOut(__METHOD_NAME__, "Branching vetoed by user.");
3301  return false;
3302  }
3303 
3304  // Everything accepted.
3305  if (verbose >= superdebug) {
3306  printOut(__METHOD_NAME__, "Branching accepted.");
3307  event.list();
3308  printOut(__METHOD_NAME__, "PartonSystems before update:");
3309  partonSystemsPtr->list();
3310  }
3311  // Update list of systems.
3312  partonSystemsPtr->replace(iSysWin, i1sav, iNew1);
3313  partonSystemsPtr->addOut(iSysWin, iNew2);
3314  partonSystemsPtr->replace(iSysWin, i2sav, iNew3);
3315  // Initial partons.
3316  if (isII) {
3317  partonSystemsPtr->setInA(iSysWin, iNew1);
3318  partonSystemsPtr->setInB(iSysWin, iNew3);
3319  } else if (is1A) partonSystemsPtr->setInA(iSysWin, iNew1);
3320  else partonSystemsPtr->setInB(iSysWin, iNew1);
3321  // Recoilers (if any).
3322  for (int k = 0; k < (int)iRecNew.size(); k++)
3323  partonSystemsPtr->replace(iSysWin, iRecNew[k].first, iRecNew[k].second);
3324  double shat = (event[partonSystemsPtr->getInA(iSysWin)].p() +
3325  event[partonSystemsPtr->getInB(iSysWin)].p()).m2Calc();
3326  partonSystemsPtr->setSHat(iSysWin, shat);
3327 
3328  if (verbose >= superdebug) {
3329  printOut(__METHOD_NAME__, "PartonSystems after update:");
3330  partonSystemsPtr->list();
3331  }
3332 
3333  // Update beam particles.
3334  bool isValN1 = false;
3335  bool isValN3 = false;
3336  // Update both sides.
3337  if (isII) {
3338  // Side A.
3339  BeamParticle& beam1 = *beamAPtr;
3340  beam1[iSysWin].update(iNew1, event[iNew1].id(), event[iNew1].e()/eBeamA);
3341  // Redo choice of companion kind whenever new flavour.
3342  if (event[i1sav].id() != event[iNew1].id()) {
3343  double PDFscale = q2new;
3344  beam1.xfISR(iSysWin,event[iNew1].id(),event[iNew1].e()/eBeamA,
3345  PDFscale );
3346  beam1.pickValSeaComp();
3347  }
3348  isValN1 = beam1[iSysWin].isValence();
3349  // Side B.
3350  BeamParticle& beam2 = *beamBPtr;
3351  beam2[iSysWin].update(iNew3, event[iNew3].id(), event[iNew3].e()/eBeamB);
3352  // Redo choice of companion kind whenever new flavour.
3353  if (event[i2sav].id() != event[iNew3].id()) {
3354  double PDFscale = q2new;
3355  beam2.xfISR( iSysWin, event[iNew3].id(), event[iNew3].e()/eBeamB,
3356  PDFscale );
3357  beam2.pickValSeaComp();
3358  }
3359  isValN3 = beam2[iSysWin].isValence();
3360 
3361  // Update only one side.
3362  } else {
3363  BeamParticle& beam = (is1A ? *beamAPtr : *beamBPtr);
3364  beam[iSysWin].update( iNew1, event[iNew1].id(), event[iNew1].e()
3365  /(is1A ? eBeamA : eBeamB) );
3366  // Redo choice of companion kind whenever new flavour.
3367  if (event[i1sav].id() != event[iNew1].id()) {
3368  double PDFscale = q2new;
3369  beam.xfISR( iSysWin, event[iNew1].id(), event[iNew1].e()
3370  /(is1A ? eBeamA : eBeamB), PDFscale );
3371  beam.pickValSeaComp();
3372  }
3373  isValN1 = beam[iSysWin].isValence();
3374  }
3375 
3376  // Update antennae due to recoil.
3377  if (iRecNew.size() >= 1)
3378  for (int iAnt = 0; iAnt < (int)branchElementals.size(); ++iAnt) {
3379  BranchElementalISR* antPtr = &branchElementals[iAnt];
3380  // No recoil outside system.
3381  if (antPtr->system != iSysWin) continue;
3382  int i2 = antPtr->i2sav;
3383  // Check relevant partons for recoilers.
3384  for (int k = 0; k < (int)iRecNew.size(); k++)
3385  // i1 is always initial.
3386  if (i2 == iRecNew[k].first) antPtr->i2sav = iRecNew[k].second;
3387  }
3388 
3389  // Update number of gluons and quark pairs.
3390  if (iAntPhys == iGXconvII || iAntPhys == iGXconvIF ||
3391  iAntPhys == iXGsplitIF) {
3392  nG[iSysWin] -= 1;
3393  ++nQQ[iSysWin];
3394  } else ++nG[iSysWin];
3395 
3396  // Update list of partons and parton numbers.
3397  indexSav[iSysWin].clear(); indexSav[iSysWin].resize(0);
3398  int sizeSystem = partonSystemsPtr->sizeAll(iSysWin);
3399  for (int i = 0; i < sizeSystem; ++i) {
3400  int i1 = partonSystemsPtr->getAll( iSysWin, i);
3401  if ( i1 <= 0 ) continue;
3402  indexSav[iSysWin].push_back( i1 );
3403  if (!event[i1].isFinal()) {
3404  if (event[i1].pz() > 0.0) initialA[iSysWin] = event[i1];
3405  else initialB[iSysWin] = event[i1];
3406  }
3407  }
3408  eBeamAUsed = 0.0;
3409  eBeamBUsed = 0.0;
3410  for (map<int,Particle>::iterator it = initialA.begin();
3411  it != initialA.end(); ++it) {
3412  int i = it->first;
3413  eBeamAUsed += initialA[i].e();
3414  eBeamBUsed += initialB[i].e();
3415  }
3416  if (verbose >= louddebug)
3417  printOut(__METHOD_NAME__, "Updating dipole-antenna(e)");
3418 
3419 
3420  // Updates of the branched antennae. The BranchElemental that
3421  // winnerPtr points to is no longer needed. Update it to store new
3422  // antenna, and add second new antenna if needed.
3423 
3424  // Gluon emission.
3425  if (winnerPtr->new2.id() == 21) {
3426  // II -> we created two IF antennae.
3427  // IF -> we created an IF and an FF antenna (the latter of which is up
3428  // to the FSR shower to find and handle).
3429  // Update old antenna to be iNew1-iNew2 antenna.
3430  int col = ( (event[iNew1].col() == event[iNew2].col()) ?
3431  event[iNew2].col() : event[iNew2].acol() );
3432  winnerPtr->reset(iSysWin,event,iNew1,iNew2,col,isValN1,false);
3433  resetTrialGenerators(winnerPtr);
3434  // Update colour. Second parton in new antenna is a gluon; decide whether
3435  // the new antenna corresponds to its colour or anticolour tag.
3436  // If this was an II branching -> add the other IF antenna.
3437  if (isII) {
3438  col = ((event[iNew3].col() == event[iNew2].col()) ?
3439  event[iNew2].col() : event[iNew2].acol());
3440  BranchElementalISR newTrial(iSysWin,event,iNew3,iNew2,col,isValN3,false);
3441  resetTrialGenerators(&newTrial);
3442  // Decide whether the new antenna corresponds to the colour or
3443  // anticolour tag of the newly emitted gluon. Save
3444  // branchelemental.
3445  branchElementals.push_back(newTrial);
3446  }
3447 
3448  // Gluon splitting in the initial state:
3449  } else if (iAntPhys == iQXsplitII || iAntPhys == iQXsplitIF) {
3450  // Old antenna should now and add an IF antenna. Decide whether
3451  // this antenna corresponds to gluon colour or anticolour.
3452  int col;
3453  if (winnerPtr->isII())
3454  col = ((event[iNew1].col() == event[iNew3].acol()) ?
3455  event[iNew3].acol() : event[iNew3].col() );
3456  else
3457  col = ((event[iNew1].col() == event[iNew3].col()) ?
3458  event[iNew3].col() : event[iNew3].acol() );
3459 
3460  // Update old antenna to be iNew1-iNew3 antenna.
3461  winnerPtr->reset(iSysWin,event,iNew1,iNew3,col,isValN1,isValN3);
3462  resetTrialGenerators(winnerPtr);
3463  // Add the other IF antenna.
3464  int iSplitGluon = (isSwapped ? iNew3 : iNew1);
3465  col = ((event[iSplitGluon].col() == event[iNew2].col()) ?
3466  event[iNew2].col() : event[iNew2].acol() );
3467  BranchElementalISR newTrial(iSysWin,event,iSplitGluon,iNew2,col,
3468  false,false);
3469  resetTrialGenerators(&newTrial);
3470  // Update colour, old1 is gluon, so both col and acol != 0. Save
3471  // branchelemental,
3472  branchElementals.push_back(newTrial);
3473 
3474  // Gluon conversion in the initial state.
3475  } else if (iAntPhys == iGXconvII || iAntPhys == iGXconvIF) {
3476  // Update branched antenna, check IS or FS quark carry ant colour.
3477  int iFSQ = iNew2;
3478  int colFSQ = ( event[iFSQ].id() > 0 ? event[iFSQ].col()
3479  : event[iFSQ].acol() );
3480  int iISQ = (isSwapped ? iNew3 : iNew1);
3481  int colISQ = ( event[iISQ].id() > 0 ? event[iISQ].col()
3482  : event[iISQ].acol() );
3483  int iQLeft = 0;
3484  int colQLeft = 0;
3485  bool isValQL = false;
3486  if (colFSQ == winnerPtr->col()) {
3487  // In case this is FF ant: kick out later.
3488  int iPartner = (isSwapped ? iNew1 : iNew3);
3489  bool isPval = (isSwapped ? isValN1 : isValN3);
3490  winnerPtr->reset(iSysWin,event,iPartner,iFSQ,colFSQ,isPval,false);
3491  // IS quark is left.
3492  iQLeft = iISQ;
3493  colQLeft = colISQ;
3494  isValQL = (isSwapped ? isValN3 : isValN1);
3495  } else if (colISQ == winnerPtr->col()) {
3496  // Is II or IF ant.
3497  winnerPtr->reset(iSysWin,event,iNew1,iNew3,colISQ,isValN1,isValN3);
3498  // FS quark is left.
3499  iQLeft = iFSQ;
3500  colQLeft = colFSQ;
3501  }
3502  // Update trial generators.
3503  resetTrialGenerators(winnerPtr);
3504  // Find other antenna, where converted gluon took part in, replace
3505  // gluon with left quark.
3506  int iConvGluon = (isSwapped ? i2sav : i1sav);
3507 
3508  // Can only find one ant with old gluon, as winner already updated.
3509  for (int iAnt = 0; iAnt < (int)branchElementals.size(); iAnt++) {
3510  BranchElementalISR* antPtr = &branchElementals[iAnt];
3511  // Only look inside same system.
3512  if (antPtr->system != iSysWin) continue;
3513  if (antPtr->i1sav == iConvGluon) {
3514  antPtr->reset(iSysWin,event,antPtr->i2sav,iQLeft,colQLeft,
3515  antPtr->isVal2(),isValQL);
3516  resetTrialGenerators(antPtr);
3517  } else if (antPtr->i2sav == iConvGluon) {
3518  // New antenna is IF.
3519  antPtr->reset(iSysWin,event,antPtr->i1sav,iQLeft,colQLeft,
3520  antPtr->isVal1(),isValQL);
3521  resetTrialGenerators(antPtr);
3522  }
3523  }
3524  }
3525 
3526  // Gluon splitting in the final state.
3527  else if (iAntPhys == iXGsplitIF) {
3528  // Keep the old antenna (iNew2 as emission and iNew1 as initial
3529  // partner) which is IF, no new one created. Update colour, old2
3530  // is quark so if col2 !=0 that's antenna colour
3531  int col = ( (event[iNew2].col() != 0) ?
3532  event[iNew2].col() : event[iNew2].acol() );
3533  winnerPtr->reset(iSysWin,event,iNew1,iNew2,col,isValN1,false);
3534  // Update trial generators.
3535  resetTrialGenerators(winnerPtr);
3536  // And check the other antenna i2sav was involved: has to be IF.
3537  for (int iAnt = 0; iAnt < (int)branchElementals.size(); ++iAnt) {
3538  BranchElementalISR* antPtr = &branchElementals[iAnt];
3539  // Skip antennae not in same system.
3540  if (antPtr->system != iSysWin) continue;
3541  // Map i2sav to iNew3.
3542  if (antPtr->i2sav == i2sav) {
3543  col = antPtr->col();
3544  antPtr->reset(iSysWin,event,antPtr->i1sav,iNew3,col,
3545  antPtr->isVal1(),false);
3546  resetTrialGenerators(antPtr);
3547  }
3548  }
3549  }
3550 
3551  // Updates of the other antennae.
3552  for (int iAnt = 0; iAnt < (int)branchElementals.size(); ++iAnt) {
3553  BranchElementalISR* antPtr = &branchElementals[iAnt];
3554 
3555  // Only look inside same system.
3556  if (antPtr->system != iSysWin) continue;
3557 
3558  // Update particles.
3559  int i1 = antPtr->i1sav;
3560  int i2 = antPtr->i2sav;
3561  int i1new = i1;
3562  int i2new = i2;
3563  bool isVal1new = antPtr->isVal1();
3564  bool isVal2new = antPtr->isVal2();
3565  if ((i1 == i1sav) || (i1 == i2sav) || (i2 == i1sav) || (i2 == i2sav)) {
3566  if (i1 == i1sav) {
3567  i1new = iNew1;
3568  isVal1new = isValN1;
3569  } else if (i1 == i2sav) {
3570  i1new = iNew3;
3571  isVal1new = isValN3;
3572  }
3573  if (i2 == i1sav) {
3574  i2new = iNew1;
3575  isVal2new = isValN1;
3576  } else if (i2 == i2sav) {
3577  i2new = iNew3;
3578  isVal2new = isValN3;
3579  }
3580  int col = antPtr->col();
3581  antPtr->reset(iSysWin, event, i1new, i2new, col, isVal1new, isVal2new);
3582  resetTrialGenerators(antPtr);
3583  }
3584 
3585  // Update.
3586  i1 = antPtr->i1sav;
3587  i2 = antPtr->i2sav;
3588 
3589  // Check relevant partons for recoilers.
3590  for (int k=0; k<(int)iRecNew.size(); k++)
3591  // i1 is always initial.
3592  if (i2 == iRecNew[k].first) {
3593  int i2now = iRecNew[k].second;
3594  bool isVal1 = antPtr->isVal1();
3595  bool isVal2 = antPtr->isVal2();
3596  int col = antPtr->col();
3597  antPtr->reset(iSysWin, event, i1, i2now, col, isVal1, isVal2);
3598  resetTrialGenerators(antPtr);
3599  }
3600 
3601  // Reset rescue counter
3602  antPtr->resetRescue();
3603  }
3604 
3605  // Sanity check: Kick out any FF antenna we might have created.
3606  for (int iAnt = 0; iAnt < (int)branchElementals.size(); ++iAnt) {
3607  BranchElementalISR* antPtr = &branchElementals[iAnt];
3608  if (event[antPtr->i1sav].isFinal() && event[antPtr->i2sav].isFinal())
3609  branchElementals.erase(branchElementals.begin() + iAnt);
3610  }
3611 
3612  // Renew trials in all other systems since pdfs changed.
3613  for (int iAnt = 0; iAnt < (int)branchElementals.size(); ++iAnt) {
3614  // Skip same system.
3615  if (branchElementals[iAnt].system == iSysWin) continue;
3616  // Reset rescue counter.
3617  branchElementals[iAnt].resetRescue();
3618  if (isII || (is1A && branchElementals[iAnt].is1A()) ||
3619  (!is1A && !branchElementals[iAnt].is1A()))
3620  branchElementals[iAnt].renewTrial();
3621  }
3622 
3623  // Count the number of branchings in the system.
3624  nBranch[iSysWin]++;
3625  nBranchISR[iSysWin]++;
3626 
3627  // If we are going from ME-corrected to non-ME-corrected order, renew trials.
3628  if (doMECsSys[iSysWin] && !mecsPtr->doMEC(iSysWin, nBranch[iSysWin])) {
3629  doMECsSys[iSysWin] = false;
3630  for (int i = 0; i < (int)branchElementals.size(); i++) {
3631  BranchElementalISR* trial = &branchElementals[i];
3632  if (trial->system == iSysWin) trial->renewTrial();
3633  }
3634  }
3635 
3636  if (verbose > debug && !checkAntennae(event)) {
3637  infoPtr->errorMsg("Warning in "+__METHOD_NAME__
3638  +": Failed checkAntennae. Aborting.");
3639  infoPtr->setAbortPartonLevel(true);
3640  return false;
3641  }
3642 
3643  // Let Pythia know how many color tags we used.
3644  if (usedColTag) {
3645  event.nextColTag();
3646  if (event[iNew2].id() == 21) {
3647  int lastTag = event.lastColTag();
3648  int colMax = max(event[iNew2].col(),event[iNew2].acol());
3649  while (colMax > lastTag) lastTag = event.nextColTag();
3650  }
3651  }
3652 
3653  // Check momentum conservation.
3654  if(!vinComPtr->checkCoM(iSysWin,event,partonSystemsPtr)){
3655  infoPtr->setAbortPartonLevel(true);
3656  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
3657  ": Failed momentum conservation test. Aborting.");
3658  return false;
3659  }
3660 
3661  // Check the event after each branching.
3662  if(!vinComPtr->showerChecks(event, true)){
3663  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
3664  ": Failed shower checks. Aborting.");
3665  infoPtr->setAbortPartonLevel(true);
3666  return false;
3667  }
3668 
3669  // Statistics for first 10 branchings in first 4 systems.
3670  if (iSysWin < 4 && nBranchISR[iSysWin] < 11) {
3671  qBranch[iSysWin][nBranchISR[iSysWin]] = qNew;
3672  pTphys[iSysWin][nBranchISR[iSysWin]] = event[iNew2].pT();
3673  }
3674  if (verbose >= debug) {
3675  if (verbose >= superdebug) {
3676  event.list();
3677  list();
3678  }
3679  printOut(__METHOD_NAME__, "end --------------");
3680  }
3681  nTrialsAccepted[iAntPhys]++;
3682  return true;
3683 
3684 }
3685 
3686 //--------------------------------------------------------------------------
3687 
3688 // Print a list of II and IF dipole-antennae.
3689 
3690 void VinciaISR::list() const {
3691  for (int iAnt = 0; iAnt < (int)branchElementals.size(); ++iAnt)
3692  if (branchElementals.size() == 1) branchElementals[iAnt].list(true, true);
3693  else if ( iAnt == 0 ) branchElementals[iAnt].list(true, false);
3694  else if ( iAnt == int(branchElementals.size()) - 1 )
3695  branchElementals[iAnt].list(false, true);
3696  else branchElementals[iAnt].list();
3697 }
3698 
3699 //--------------------------------------------------------------------------
3700 
3701 // Initialise pointers to Vincia objects.
3702 
3703 void VinciaISR::initVinciaPtrs(
3704  Colour* colourPtrIn, shared_ptr<VinciaFSR> fsrPtrIn,
3705  QEDShower* qedPtrIn,MECs* mecsPtrIn,Resolution* resolutionPtrIn,
3706  VinciaCommon* vinComPtrIn,VinciaWeights* vinWeightsPtrIn) {
3707  colourPtr = colourPtrIn;
3708  fsrPtr = fsrPtrIn;
3709  qedShowerPtr = qedPtrIn;
3710  mecsPtr = mecsPtrIn;
3711  resolutionPtr = resolutionPtrIn;
3712  vinComPtr = vinComPtrIn;
3713  weightsPtr = vinWeightsPtrIn;
3714 }
3715 
3716 //--------------------------------------------------------------------------
3717 
3718 // Clear all containers.
3719 
3720 void VinciaISR::clearContainers() {
3721  hasPrepared.clear();
3722  branchElementals.clear();
3723  Q2hat.clear();
3724  isHardSys.clear();
3725  isResonanceSys.clear();
3726  polarisedSys.clear();
3727  doMECsSys.clear();
3728  indexSav.clear();
3729  partsSav.clear();
3730  nBranch.clear();
3731  nBranchISR.clear();
3732  nG.clear();
3733  nQQ.clear();
3734  initialA.clear();
3735  initialB.clear();
3736 }
3737 
3738 //--------------------------------------------------------------------------
3739 
3740 // Print final statistics information.
3741 
3742 void VinciaISR::printInfo(bool pluginCall) {
3743  if (!isInit) {
3744  if (pluginCall)
3745  cout << " *-------- End VINCIA FSR and ISR Statistics -------------"
3746  << "-------------------------------------------------------*\n\n";
3747  return;
3748  }
3749 
3750  // Weight info.
3751  int nTotWeightsInt = weightsPtr->nTotWeights;
3752  int nNonunityInitialWeight = weightsPtr->nNonunityInitialWeight;
3753  int nNegativeInitialWeight = weightsPtr->nNegativeInitialWeight;
3754  int nNonunityWeight = weightsPtr->nNonunityWeight;
3755  int nNegativeWeight = weightsPtr->nNegativeWeight;
3756  double nTotWeights = max(1.0,((double)(nTotWeightsInt)));
3757  vector<double> weightSum = weightsPtr->weightSum;
3758  vector<double> weightMax = weightsPtr->weightsMax;
3759  vector<double> weightMin = weightsPtr->weightsMin;
3760  if (pluginCall)
3761  cout << " | - - - - ISR only Statistics - - - - - - - - - - - - - - - "
3762  << "- - - - - - - - - - - - - - - - - - - - - - - - - - |\n";
3763  else {
3764  cout << "\n";
3765  cout << " *-------- VINCIA ISR Statistics ----------------------------"
3766  << "----------------------------------------------------*\n";
3767  cout << " | "
3768  << " |\n";
3769  cout << " | "
3770  << " " << setw(40) << " " << " |\n";
3771  cout << " | Total Number of (accepted) events ="
3772  << " " << num2str(nTotWeightsInt,9) << setw(40) << " " << " |\n";
3773  cout << " | Number of events with nonunity initial weight ="
3774  << " " << ( (nNonunityInitialWeight <= 0) ?
3775  " none "
3776  : num2str(nNonunityInitialWeight,9)
3777  +" <-- (INITIALLY) WEIGHTED EVENTS" )
3778  << setw(8) << " " << " |\n";
3779  cout << " | Number of events with negative initial weight ="
3780  << " " << ( (nNegativeInitialWeight <= 0) ? " none"
3781  : num2str(nNegativeWeight,9))
3782  << setw(40) << " " << " |\n";
3783  cout << " | Number of events with nonunity reweight ="
3784  << " " << ( (nNonunityWeight <= 0) ? " none "
3785  : num2str(nNonunityWeight,9)+" <-- REWEIGHTED EVENTS" )
3786  << setw(18) << " " << " |\n";
3787  cout << " | Number of events with negative reweight ="
3788  << " " << ( (nNegativeWeight <= 0) ? " none"
3789  : num2str(min(nNegativeWeight,nNonunityWeight),9))
3790  << setw(40) << " " << " |\n";
3791  cout << " | "
3792  << " " << setw(40) << " " << " |\n";
3793  cout << " | weight(i) Avg Wt Avg Dev "
3794  << "rms(dev) kUnwt Expected effUnw |\n";
3795  cout << " | This run i = IsUnw <w> <w-1> "
3796  << " 1/<w> Max Wt <w>/MaxWt Min Wt |\n";
3797  cout << " |" << setw(4) << " " << "User settings 0 ";
3798  cout << ( (abs(1.0-weightSum[0]/nTotWeights) < TINY) ?
3799  " yes " : " no " );
3800  cout << num2str(weightSum[0]/nTotWeights,9) << " ";
3801  cout << num2str(weightSum[0]/nTotWeights-1.0,9) << " ";
3802  cout << setw(9) << "-" << " ";
3803  cout << ((weightSum[0] != 0.0) ? num2str(nTotWeights/weightSum[0],9) :
3804  num2str(0.0,9));
3805  cout << num2str(weightMax[0],14) << " ";
3806  cout << ((weightMax[0] != 0.0) ?
3807  num2str(weightSum[0]/nTotWeights/weightMax[0],9) :
3808  num2str(0.0,9)) << " ";
3809  cout << num2str(weightMin[0],9) << " ";
3810  cout << "|\n";
3811  }
3812  if (verbose >= normal && nTrialsSum > 0) {
3813  cout << " | ----------------"
3814  << "------ P(Reject) ---------------------------" << setw(7) << "|"
3815  << endl
3816  << " | Trial Veto Rates: nTrials nAcc eff Zeta kinMap "
3817  << "Veto (<RPDF>) Sector IR mMin HQPS" << setw(7) << "|"
3818  << endl;
3819  for (int iAntPhys=0; iAntPhys<(int)nTrials.size(); ++iAntPhys) {
3820  double nTot = nTrials[iAntPhys];
3821  if (nTot <= 0) continue;
3822  cout << " | " << setw(17);
3823  if (iAntPhys == iQQemitII) cout << "QQemitII";
3824  else if (iAntPhys == iGQemitII) cout << "GQemitII";
3825  else if (iAntPhys == iGGemitII) cout << "GGEmitII";
3826  else if (iAntPhys == iQXsplitII) cout << "QXsplitII";
3827  else if (iAntPhys == iGXconvII) cout << "GXconvII";
3828  else if (iAntPhys == iQQemitIF) cout << "QQemitIF";
3829  else if (iAntPhys == iQGemitIF) cout << "QGemitIF";
3830  else if (iAntPhys == iGQemitIF) cout << "GQemitIF";
3831  else if (iAntPhys == iGGemitIF) cout << "GGemitIF";
3832  else if (iAntPhys == iQXsplitIF) cout << "QXsplitIF";
3833  else if (iAntPhys == iGXconvIF) cout << "GXconvIF";
3834  else if (iAntPhys == iXGsplitIF) cout << "XGsplitIF";
3835  cout << fixed << setprecision(2)
3836  << " " << num2str(int(nTot+0.5),9)
3837  << " " << num2str(int(nTrialsAccepted[iAntPhys]+0.5),8)
3838  << " " << nTrialsAccepted[iAntPhys]/nTot
3839  << " " << nFailedHull[iAntPhys]*1.0/nTot;
3840  nTot -= nFailedHull[iAntPhys];
3841  cout << " " << nFailedKine[iAntPhys]*1.0/max(1.,nTot);
3842  nTot -= nFailedKine[iAntPhys];
3843  cout << " " << nFailedVeto[iAntPhys]*1.0/max(1.,nTot)
3844  << " (" << rFailedVetoPDF[iAntPhys]/max(1.,
3845  double(nFailedVeto[iAntPhys])) << ")";
3846  nTot -= nFailedVeto[iAntPhys];
3847  cout << " " << nSectorReject[iAntPhys]*1.0/max(1.,nTot);
3848  nTot -= nSectorReject[iAntPhys];
3849  cout << " " << nFailedCutoff[iAntPhys]*1.0/max(1.,nTot);
3850  nTot -= nFailedCutoff[iAntPhys];
3851  cout << " " << nFailedMass[iAntPhys]*1.0/max(1.,nTot);
3852  nTot -= nFailedMass[iAntPhys];
3853  cout << " " << nClosePSforHQ[iAntPhys]*1.0/max(1.,nTot);
3854  cout << setw(8) << "|\n";
3855  }
3856  cout << " |" << setw(113) << " " << "|\n";
3857  }
3858  if (pluginCall)
3859  cout << " *-------- End VINCIA FSR and ISR Statistics -----------------"
3860  << "---------------------------------------------------*\n\n";
3861  else
3862  cout << " *-------- End VINCIA ISR Statistics --------------------------"
3863  << "---------------------------------------------------*\n\n";
3864 }
3865 
3866 //--------------------------------------------------------------------------
3867 
3868 // Add trial functions to a BranchElemental.
3869 
3870 void VinciaISR::resetTrialGenerators(BranchElementalISR* trial) {
3871 
3872  // Reset.
3873  trial->clearTrialGenerators();
3874  // Always p+ for II. Always I for IF.
3875  int id1 = abs(trial->id1sav);
3876  // Always p- for II. Always F for IF.
3877  int id2 = abs(trial->id2sav);
3878  bool isOctetOnium2 = ( (id2>6 && id2!=21) ? true : false );
3879  bool isVal1 = trial->isVal1();
3880  bool isVal2 = trial->isVal2();
3881  bool isII = trial->isII();
3882  bool is1A = trial->is1A();
3883  int iAntPhys = -1;
3884  int colType1abs = abs(trial->colType1());
3885  int colType2abs = abs(trial->colType2());
3886 
3887  // II antennae.
3888  if (isII) {
3889  // QQbar.
3890  if ( colType1abs == 1 && colType2abs == 1 ) {
3891  iAntPhys = iQQemitII;
3892  if (getAnt(iAntPhys)->chargeFac() > 0.)
3893  trial->addTrialGenerator(iAntPhys, false, &trialIISoft);
3894  iAntPhys = iQXsplitII;
3895  if (convQuarkToGluonI && getAnt(iAntPhys)->chargeFac() > 0.) {
3896  if (!isVal1) trial->addTrialGenerator(iAntPhys, false, &trialIISplitA);
3897  if (!isVal2) trial->addTrialGenerator(iAntPhys, true, &trialIISplitB);
3898  }
3899  // GG.
3900  } else if ( colType1abs == 2 && colType2abs == 2 ) {
3901  iAntPhys = iGGemitII;
3902  if (getAnt(iAntPhys)->chargeFac() > 0.) {
3903  trial->addTrialGenerator(iAntPhys, false, &trialIISoft);
3904  trial->addTrialGenerator(iAntPhys, false, &trialIIGCollA);
3905  trial->addTrialGenerator(iAntPhys, false, &trialIIGCollB);
3906  }
3907  iAntPhys = iGXconvII;
3908  if (convGluonToQuarkI && getAnt(iAntPhys)->chargeFac() > 0.) {
3909  trial->addTrialGenerator(iAntPhys, false, &trialIIConvA);
3910  trial->addTrialGenerator(iAntPhys, true, &trialIIConvB);
3911  }
3912  // QG.
3913  } else if ( colType1abs == 1 && colType2abs == 2 ) {
3914  iAntPhys = iGQemitII;
3915  if (getAnt(iAntPhys)->chargeFac() > 0.) {
3916  trial->addTrialGenerator(iAntPhys, true, &trialIISoft);
3917  trial->addTrialGenerator(iAntPhys, true, &trialIIGCollB);
3918  }
3919  iAntPhys = iGXconvII;
3920  if (convGluonToQuarkI && getAnt(iAntPhys)->chargeFac() > 0.)
3921  trial->addTrialGenerator(iAntPhys, true, &trialIIConvB);
3922  iAntPhys = iQXsplitII;
3923  if (convQuarkToGluonI && getAnt(iAntPhys)->chargeFac() > 0.)
3924  if (!isVal1) trial->addTrialGenerator(iAntPhys, false, &trialIISplitA);
3925  // GQ.
3926  } else if ( colType1abs == 2 && colType2abs == 1 ) {
3927  iAntPhys = iGQemitII;
3928  if (getAnt(iAntPhys)->chargeFac() > 0.) {
3929  trial->addTrialGenerator(iAntPhys, false, &trialIISoft);
3930  trial->addTrialGenerator(iAntPhys, false, &trialIIGCollA);
3931  }
3932  iAntPhys = iGXconvII;
3933  if (convGluonToQuarkI && getAnt(iAntPhys)->chargeFac() > 0.)
3934  trial->addTrialGenerator(iAntPhys, false, &trialIIConvA);
3935  iAntPhys = iQXsplitII;
3936  if (convQuarkToGluonI && getAnt(iAntPhys)->chargeFac() > 0.)
3937  if (!isVal2) trial->addTrialGenerator(iAntPhys, true, &trialIISplitB);
3938  }
3939 
3940  // IF antennae.
3941  } else {
3942  // QQ.
3943  if ( colType1abs == 1 && colType2abs == 1 ) {
3944  iAntPhys = iQQemitIF;
3945  if (getAnt(iAntPhys)->chargeFac() > 0.) {
3946  // Use different trial generator for valence quarks.
3947  if (!isVal1)
3948  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFSoft);
3949  else
3950  trial->addTrialGenerator(iAntPhys, !is1A, &trialVFSoft);
3951  }
3952  iAntPhys = iQXsplitIF;
3953  if (convQuarkToGluonI && getAnt(iAntPhys)->chargeFac() > 0.)
3954  if (!isVal1) trial->addTrialGenerator(iAntPhys, !is1A, &trialIFSplitA);
3955  // GG.
3956  } else if ( colType1abs == 2 && colType2abs == 2 ) {
3957  iAntPhys = iGGemitIF;
3958  if (getAnt(iAntPhys)->chargeFac() > 0.) {
3959  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFSoft);
3960  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFGCollA);
3961  }
3962  iAntPhys = iXGsplitIF;
3963  if (id2 == 21 && nGluonToQuarkF > 0 && getAnt(iAntPhys)->chargeFac()>0.)
3964  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFSplitK);
3965  iAntPhys = iGXconvIF;
3966  if (convGluonToQuarkI && getAnt(iAntPhys)->chargeFac() > 0.)
3967  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFConvA);
3968  // GQ.
3969  } else if ( colType1abs == 2 && colType2abs == 1 ) {
3970  iAntPhys = iGQemitIF;
3971  if (getAnt(iAntPhys)->chargeFac() > 0.) {
3972  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFSoft);
3973  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFGCollA);
3974  }
3975  iAntPhys = iGXconvIF;
3976  if (convGluonToQuarkI && getAnt(iAntPhys)->chargeFac() > 0.)
3977  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFConvA);
3978  // QG.
3979  } else if ( colType1abs == 1 && colType2abs == 2 ) {
3980  iAntPhys = iQGemitIF;
3981  if (getAnt(iAntPhys)->chargeFac() > 0.) {
3982  if (!isVal1)
3983  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFSoft);
3984  else
3985  trial->addTrialGenerator(iAntPhys, !is1A, &trialVFSoft);
3986  }
3987  iAntPhys = iXGsplitIF;
3988  if (id2 == 21 && nGluonToQuarkF > 0 && getAnt(iAntPhys)->chargeFac()>0.)
3989  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFSplitK);
3990  iAntPhys = iQXsplitIF;
3991  if (convQuarkToGluonI && getAnt(iAntPhys)->chargeFac() > 0.)
3992  if (!isVal1) trial->addTrialGenerator(iAntPhys, !is1A, &trialIFSplitA);
3993  // GOctetOnium.
3994  } else if ( id1 == 21 && isOctetOnium2 ) {
3995  iAntPhys = iGXconvIF;
3996  if (convGluonToQuarkI && getAnt(iAntPhys)->chargeFac() > 0.)
3997  trial->addTrialGenerator(iAntPhys, !is1A, &trialIFConvA);
3998  // QOctetOnium.
3999  } else if ( colType1abs == 1 && isOctetOnium2 ) {
4000  iAntPhys = iQXsplitIF;
4001  if (convQuarkToGluonI && getAnt(iAntPhys)->chargeFac() > 0.)
4002  if (!isVal1) trial->addTrialGenerator(iAntPhys, !is1A, &trialIFSplitA);
4003  }
4004  }
4005 
4006 }
4007 
4008 //--------------------------------------------------------------------------
4009 
4010 // Method to check if a gluon splitting in the initial state (to get
4011 // rid of heavy quarks) is still possible after the current branching.
4012 
4013 bool VinciaISR::checkHeavyQuarkPhaseSpace(vector<Particle> parts, int) {
4014 
4015  vector<int> isToCheck; isToCheck.resize(0);
4016  for (int i = 0; i < (int)parts.size(); i++)
4017  if (!parts[i].isFinal() && parts[i].idAbs() > nFlavZeroMass &&
4018  parts[i].idAbs() < 6) isToCheck.push_back(i);
4019 
4020  // Loop over partons to check.
4021  for (int i = 0; i < (int)isToCheck.size(); i++) {
4022  Particle heavyQuark = parts[isToCheck[i]];
4023  int hQcol = ( (heavyQuark.col() == 0) ?
4024  heavyQuark.acol() : heavyQuark.col() );
4025  double mass = ((heavyQuark.idAbs() == 4) ? mc : mb);
4026  bool is1A = (heavyQuark.pz() > 0.0);
4027  // Find the colour partner.
4028  for (int j = 0; j < (int)parts.size(); j++)
4029  if (j != isToCheck[i]) {
4030  if ( (parts[j].col() != hQcol) && (parts[j].acol() != hQcol) )
4031  continue;
4032  Particle colPartner = parts[i];
4033  double sHqCp = m2(heavyQuark, colPartner);
4034  double Q2max = 0.0;
4035  if (colPartner.isFinal())
4036  Q2max = trialIFSplitA.getQ2max(sHqCp, colPartner.e(), is1A ?
4037  eBeamAUsed : eBeamBUsed);
4038  else
4039  Q2max = trialIISplitA.getQ2max(sHqCp, colPartner.e(), is1A ?
4040  eBeamAUsed : eBeamBUsed);
4041  // Phase space limit is below the mass.
4042  if (sqrt(Q2max) < mass) return false;
4043  if (colPartner.isFinal()) {
4044  // Check for energy exceeding beam energy.
4045  double eA = heavyQuark.e();
4046  double eamax = ( is1A ? (0.98*eBeamA - (eBeamAUsed-eA)) :
4047  (0.98*eBeamB - (eBeamBUsed-eA)) );
4048  // Allowed maxima.
4049  double sjkmax = sHqCp*(eamax-eA)/eA;
4050  // sajmin = mass^2.
4051  double sakmax = (sHqCp+sjkmax-(mass*mass));
4052  // Invariant > 0.5 GeV.
4053  if ( (sjkmax < 0.5) || (sakmax < 0.5) ) return false;
4054  }
4055  }
4056  }
4057  return true;
4058 
4059 }
4060 //--------------------------------------------------------------------------
4061 
4062 // Method to check if heavy quark left after passing the evolution window.
4063 
4064 bool VinciaISR::heavyQuarkLeft(double qTrial) {
4065  // We are above mb.
4066  if (qTrial > 1.02*mb) return false;
4067  bool foundQuark = false;
4068  // Loop over antennae.
4069  for (int iAnt = 0; iAnt < (int)branchElementals.size(); ++iAnt) {
4070  BranchElementalISR* trialPtr = &branchElementals[iAnt];
4071  int iSys = trialPtr->system;
4072  int id1 = abs(trialPtr->id1sav);
4073  int id2 = abs(trialPtr->id2sav);
4074  bool foundQuarkNow = false;
4075  int splitGenTndex = -1;
4076  if ( (id1 > nFlavZeroMass) && (id1 < 6) ) {
4077  double mass = ((id1 == 4) ? mc : mb);
4078  // Safety of 2%.
4079  if (qTrial < (1.02*mass)) {
4080  foundQuarkNow = true;
4081  // Find the index of the trial generator for splitting.
4082  for (int indx = 0; indx < (int)trialPtr->nTrialGenerators(); ++indx) {
4083  if ( (trialPtr->getPhysIndex(indx) == iQXsplitIF) ||
4084  (trialPtr->getPhysIndex(indx) == iQXsplitII) ) {
4085  splitGenTndex = indx;
4086  trialPtr->scaleSav[indx] = mass;
4087  }
4088  }
4089  }
4090  }
4091  // Only check parton 2 if this is an II antenna.
4092  if ( trialPtr->isII() && (id2 > nFlavZeroMass) && (id2 < 6) ) {
4093  double mass = ((id2 == 4) ? mc : mb);
4094  // Safety of 2%.
4095  if (qTrial < (1.02*mass)) {
4096  foundQuarkNow = true;
4097  // Find the index of the trial generator for splitting.
4098  for (int indx = 0; indx < (int)trialPtr->nTrialGenerators(); ++indx) {
4099  if (trialPtr->getPhysIndex(indx) == iQXsplitII) {
4100  splitGenTndex = indx;
4101  trialPtr->scaleSav[indx] = mass;
4102  }
4103  }
4104  }
4105  }
4106  if (foundQuarkNow && (splitGenTndex>=0)) {
4107  winnerPtr = trialPtr;
4108  iSysWin = iSys;
4109  indxWin = splitGenTndex;
4110  foundQuark = foundQuarkNow;
4111  } else if (foundQuarkNow) {
4112  if (verbose >= quiet ) {
4113  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4114  ": Found heavy quark but no splitting trial generator.",
4115  "Not going to force a splitting.");
4116  trialPtr->list();
4117  cout << " Current scale = " << qTrial << endl;
4118  }
4119  }
4120  }
4121  return foundQuark;
4122 
4123 }
4124 
4125 //--------------------------------------------------------------------------
4126 
4127 // Check the antennae.
4128 
4129 bool VinciaISR::checkAntennae(const Event& event){
4130 
4131  map<int,int> nIIAntInSys;
4132  map<int,int> nIFAntInSys;
4133  for (vector<BranchElementalISR >::iterator ibrancher =
4134  branchElementals.begin(); ibrancher!= branchElementals.end();
4135  ++ibrancher) {
4136  int i1 = ibrancher->geti1();
4137  int i2 = ibrancher->geti2();
4138  int iSysNow = ibrancher->getSystem();
4139  int inA = 0;
4140  int inB = 0;
4141 
4142  if (!partonSystemsPtr->hasInAB(iSysNow)) {
4143  stringstream ss;
4144  ss << "iSysNow = " << iSysNow;
4145  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4146  ": No incoming particles in system.",ss.str());
4147  return false;
4148  } else{
4149  inA = partonSystemsPtr->getInA(iSysNow);
4150  inB = partonSystemsPtr->getInB(iSysNow);
4151  }
4152  if (inA <= 0 || inB <= 0 ) {
4153  stringstream ss;
4154  ss << "iSysNow = " << iSysNow
4155  << ". inA = " << inA << " inB = " << inB;
4156  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4157  ": Non-positive incoming particles in system.", ss.str());
4158  return false;
4159  }
4160 
4161  // Initialise counters for systems we haven't seen yet.
4162  if (nIIAntInSys.find(iSysNow)==nIIAntInSys.end())
4163  nIIAntInSys[iSysNow] = 0;
4164  if(nIFAntInSys.find(iSysNow)==nIFAntInSys.end())
4165  nIFAntInSys[iSysNow] = 0;
4166  if (ibrancher->isII()) {
4167  if(i1 != inA) {
4168  stringstream ss;
4169  ss << "iSysNow = "<<iSysNow<<". i1 = " << i1;
4170  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4171  ": i1 not incoming in system.", ss.str());
4172  return false;
4173  } else if (i2 != inB) {
4174  stringstream ss;
4175  ss << "iSysNow = "<<iSysNow<<". i2 = " << i2;
4176  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4177  ": i2 not incoming in system.", ss.str());
4178  return false;
4179  }
4180  nIIAntInSys[iSysNow]++;
4181  // Otherwise IF.
4182  } else {
4183  if(!event[i2].isFinal()) {
4184  stringstream ss;
4185  ss << "iSysNow = "<<iSysNow<<". i2 = " << i2;
4186  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4187  ": i2 not outgoing in system.", ss.str());
4188  return false;
4189  }
4190  // IF with 1 = I from A.
4191  if (ibrancher->is1A() && i1 != inA) {
4192  stringstream ss;
4193  ss << "iSysNow = "<<iSysNow<<". i1 = " << i1;
4194  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4195  ": i1 not incoming from A in system.", ss.str());
4196  return false;
4197  // IF with 1 = I from B.
4198  } else if(!ibrancher->is1A() && i1 != inB) {
4199  stringstream ss;
4200  ss << "iSysNow = "<<iSysNow<<". i1 = " << i1;
4201  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4202  ": i1 not incoming from B in system.", ss.str());
4203  return false;
4204  }
4205  nIFAntInSys[iSysNow]++;
4206  }
4207  }
4208 
4209  // Check number of initial antennae in each system matches the color
4210  // type of incoming partons.
4211  for (int iSysTest = 0; iSysTest < partonSystemsPtr->sizeSys(); ++iSysTest) {
4212  if (!partonSystemsPtr->hasInAB(iSysTest)) continue;
4213  int inA = partonSystemsPtr->getInA(iSysTest);
4214  int inB = partonSystemsPtr->getInB(iSysTest);
4215  // Count number of antenna ends expected based on colour type of
4216  // incoming particles.
4217  int nEndsExpected = abs(event[inA].colType())
4218  + abs(event[inB].colType());
4219  // Count number of antennae we have.
4220  int nAntEnds = 0;
4221  // II contribute to two ends.
4222  if (nIIAntInSys.find(iSysTest)!=nIIAntInSys.end())
4223  nAntEnds += 2*nIIAntInSys[iSysTest];
4224  if (nIFAntInSys.find(iSysTest)!=nIFAntInSys.end())
4225  nAntEnds += nIFAntInSys[iSysTest];
4226  if (nAntEnds < nEndsExpected) {
4227  stringstream ss;
4228  ss << "iSys = " << iSysTest;
4229  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4230  ": Too few initial antennae in system",ss.str());
4231  cout << "colType A: " << event[inA].colType()
4232  << " colType B: " << event[inB].colType()
4233  << " nEnds: " << nAntEnds
4234  << " nEnds expected: " << nEndsExpected
4235  << " nII: " << nIIAntInSys[iSysTest]
4236  << " nIF: " << nIFAntInSys[iSysTest]
4237  << endl;
4238  return false;
4239  } else if (nAntEnds > nEndsExpected) {
4240  stringstream ss;
4241  ss << "iSys = " << iSysTest;
4242  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
4243  ": Too many initial antennae in system.",ss.str());
4244  cout << "colType A: " << event[inA].colType()
4245  << " colType B: " << event[inB].colType()
4246  << " nEnds: " << nAntEnds
4247  << " nEnds expected: " << nEndsExpected
4248  << " nII: " << nIIAntInSys[iSysTest]
4249  << " nIF: " << nIFAntInSys[iSysTest]
4250  << endl;
4251  return false;
4252  }
4253  }
4254  return true;
4255 
4256 }
4257 
4258 //--------------------------------------------------------------------------
4259 
4260 // Set starting scale of shower (power vs wimpy) for system iSys.
4261 
4262 void VinciaISR::setStartScale(int iSys, Event& event){
4263 
4264  // Resonance and hadron decay systems: no ISR.
4265  if (!partonSystemsPtr->hasInAB(iSys)) Q2hat[iSys] = 0.0;
4266 
4267  // Hard Process System.
4268  else if (isHardSys[iSys]) {
4269  // Hard system: start at phase-space maximum or factorisation scale.
4270  if (verbose >= superdebug)
4271  printOut(__METHOD_NAME__, "Setting ISR starting scale for hard system");
4272  // pTmaxMatch = 1 : always start at QF (modulo kFudge).
4273  if (pTmaxMatch == 1) Q2hat[iSys] = pT2maxFudge * infoPtr->Q2Fac();
4274  // pTmaxMatch = 2 : always start at eCM.
4275  else if (pTmaxMatch == 2) Q2hat[iSys] = m2BeamsSav;
4276  // Else check if this event has final-state jets or photons.
4277  else {
4278  bool hasRad = false;
4279  for (int i = 0; i < partonSystemsPtr->sizeOut(iSys); ++i) {
4280  int idAbs = event[partonSystemsPtr->getOut(iSys,i)].idAbs();
4281  if (idAbs <= 5 || idAbs == 21 || idAbs == 22) hasRad = true;
4282  if (idAbs == 6 && nGluonToQuarkF == 6) hasRad = true;
4283  if (hasRad) break;
4284  }
4285  // If no QCD/QED partons detected, allow to go to phase-space maximum.
4286  if (hasRad) Q2hat[iSys] = pT2maxFudge * infoPtr->Q2Fac();
4287  else Q2hat[iSys] = m2BeamsSav;
4288  }
4289  }
4290 
4291  // MPI systems.
4292  else {
4293  if (verbose >= superdebug)
4294  printOut(__METHOD_NAME__, "Setting ISR starting scale of MPI system");
4295  // Set starting scale for MPI systems: min of incoming parton scales.
4296  // Find positions of incoming colliding partons.
4297  int in1 = partonSystemsPtr->getInA(iSys);
4298  int in2 = partonSystemsPtr->getInB(iSys);
4299  Q2hat[iSys] = pT2maxFudgeMPI
4300  * pow2(min(event[in1].scale(),event[in2].scale()));
4301  if (verbose >= louddebug) printOut(__METHOD_NAME__,
4302  "Renewing all trials since we got non-hard system!");
4303  for (int iAnt = 0; iAnt < (int)branchElementals.size(); ++iAnt)
4304  if (branchElementals[iAnt].system != iSys)
4305  branchElementals[iAnt].renewTrial();
4306  }
4307 
4308 }
4309 
4310 //--------------------------------------------------------------------------
4311 
4312 // Function to return headroom factor.
4313 
4314 double VinciaISR::getHeadroomFac(int iSys, int iAntPhys, double) {
4315 
4316  // Increase headroom factor when doing ME corrections.
4317  double headroomFac = 1.0;
4318  if (doMECsSys[iSys] && mecsPtr->doMEC(iSys,nBranch[iSys] + 1)) {
4319  headroomFac = 4.;
4320  // Gluon splitting MECs may require larger overestimates.
4321  if (iAntPhys == iXGsplitIF) headroomFac *= 1.5;
4322  // Helicity-dependent MECs may require larger headroom.
4323  if (helicityShower && polarisedSys[iSys]) headroomFac *= 1.5;
4324  // Headroom factors for pure shower.
4325  }
4326 
4327  return headroomFac;
4328 
4329 }
4330 
4331 //--------------------------------------------------------------------------
4332 
4333 // Generate kinematics (II) and set flavours and masses.
4334 
4335 bool VinciaISR::generateKinematicsII(Event& event,
4336  BranchElementalISR* trialPtr, vector<Vec4>& pRec) {
4337 
4338  // Basic info about trial function and scale
4339  if (verbose >= louddebug) printOut(__METHOD_NAME__, "begin --------------");
4340  int iTrial = indxWin;
4341  if (iTrial < 0) return false;
4342  double qNew = trialPtr->getTrialScale(iTrial);
4343  double q2new = pow2(qNew);
4344  int iAntPhys = trialPtr->getPhysIndex(iTrial);
4345  bool isSwapped = trialPtr->getIsSwapped(iTrial);
4346 
4347  // Trial generator.
4348  TrialGeneratorISR* trialGenPtr = trialPtr->trialGenPtrsSav[iTrial];
4349  int idA = trialPtr->id1sav;
4350  int idB = trialPtr->id2sav;
4351 
4352  // Force a splitting, set zMin and zMax accordingly.
4353  bool forceSplitting = trialPtr->forceSplittingSav;
4354  if (forceSplitting) {
4355  trialPtr->zMinSav[iTrial] =
4356  trialPtr->trialGenPtrsSav[iTrial]->getZmin(q2new, trialPtr->sAnt(),
4357  trialPtr->e1sav, 0.0);
4358  trialPtr->zMaxSav[iTrial] =
4359  trialPtr->trialGenPtrsSav[iTrial]->getZmax(q2new, trialPtr->sAnt(),
4360  trialPtr->e1sav, 0.0);
4361  }
4362 
4363  // Generate zeta variable, work out saj, sjb and check initial energies.
4364  double saj, sjb;
4365  if (!trialPtr->genTrialInvariants(saj, sjb, 0.0, iTrial)) {
4366  if (verbose >= verylouddebug)
4367  printOut(__METHOD_NAME__, "z outside physical range, returning.");
4368  trialPtr->nHull++;
4369  ++nFailedHull[iAntPhys];
4370  return false;
4371  }
4372 
4373  // Check that sab < shh.
4374  double sAB = trialPtr->sAnt();
4375  double sab = sAB + saj + sjb;
4376  if (sab > m2BeamsSav) {
4377  if (verbose >= verylouddebug)
4378  printOut(__METHOD_NAME__, "sab > shh = " + num2str(m2BeamsSav)
4379  + ", returning.");
4380  trialPtr->nHull++;
4381  ++nFailedHull[iAntPhys];
4382  return false;
4383  }
4384 
4385  // Set flavors and masses.
4386  double mj=0.;
4387  // Flavour for gluon backwards evolving to (anti)quark.
4388  int idConv = (iAntPhys == iGXconvII) ? trialPtr->getTrialFlav() : 0;
4389 
4390  // Gluon emission: inherit parent flavors and add middle gluon.
4391  if (iAntPhys == iQQemitII || iAntPhys == iGQemitII ||
4392  iAntPhys == iGGemitII) {
4393  trialPtr->new1.id(idA);
4394  trialPtr->new2.id(21);
4395  trialPtr->new3.id(idB);
4396  trialPtr->new1.m(0.0);
4397  trialPtr->new2.m(0.0);
4398  trialPtr->new3.m(0.0);
4399 
4400  // Gluon splitting in the initial state:
4401  } else if (iAntPhys == iQXsplitII) {
4402  // Side A splitting.
4403  if (!isSwapped) {
4404  trialPtr->new1.id(21);
4405  trialPtr->new2.id(-idA);
4406  trialPtr->new3.id(idB);
4407  trialPtr->new1.m(0.0);
4408  // Final-state leg assigned on-shell mass.
4409  mj = (abs(idA) <= nFlavZeroMass) ? 0.0 :
4410  particleDataPtr->m0(abs(idA));
4411  trialPtr->new2.m(mj);
4412  trialPtr->new3.m(0.0);
4413  // Side B splitting.
4414  } else {
4415  trialPtr->new1.id(idA);
4416  trialPtr->new2.id(-idB);
4417  trialPtr->new3.id(21);
4418  trialPtr->new1.m(0.0);
4419  // Final-state leg assigned on-shell mass.
4420  mj = (abs(idB) <= nFlavZeroMass) ? 0.0 :
4421  particleDataPtr->m0(abs(idB));
4422  trialPtr->new2.m(mj);
4423  trialPtr->new3.m(0.0);
4424  }
4425 
4426  // Gluon conversion in the initial state (idConv contains flavour)
4427  } else if (iAntPhys == iGXconvII) {
4428  // Final-state leg assigned on-shell mass.
4429  mj = (abs(idConv) <= nFlavZeroMass) ? 0.0 :
4430  particleDataPtr->m0(abs(idConv));
4431  // Side A conversion.
4432  if (!isSwapped) {
4433  trialPtr->new1.id(idConv);
4434  trialPtr->new2.id(idConv);
4435  trialPtr->new3.id(idB);
4436  trialPtr->new1.m(0.0);
4437  trialPtr->new2.m(mj);
4438  trialPtr->new3.m(0.0);
4439  // Side B conversion.
4440  } else {
4441  trialPtr->new1.id(idA);
4442  trialPtr->new2.id(idConv);
4443  trialPtr->new3.id(idConv);
4444  trialPtr->new1.m(0.0);
4445  trialPtr->new2.m(mj);
4446  trialPtr->new3.m(0.0);
4447  }
4448  }
4449 
4450  // Correct sab.
4451  double m2j = mj*mj;
4452  sab = sAB + saj + sjb -m2j;
4453  if (sab <0.) return false;
4454 
4455  // Generate full kinematics for this trial branching.
4456  // Generate random (uniform) phi angle.
4457  double phi = 2 * M_PI * rndmPtr->flat();
4458  // Generate branching kinematics, starting from dipole-antenna parents.
4459  vector<Vec4> pOld, pNew;
4460  pOld.push_back(event[trialPtr->i1sav].p());
4461  pOld.push_back(event[trialPtr->i2sav].p());
4462  if (!forceSplitting &&
4463  !vinComPtr->map2to3II(pNew, pRec, pOld, sAB, saj, sjb, sab, phi, m2j)) {
4464  if (verbose >= louddebug ) printOut(__METHOD_NAME__, "Failed map2to3II.");
4465  trialPtr->nHull++;
4466  ++nFailedKine[iAntPhys];
4467  return false;
4468  }
4469  // Save momenta.
4470  trialPtr->new1.p(pNew[0]);
4471  trialPtr->new2.p(pNew[1]);
4472  trialPtr->new3.p(pNew[2]);
4473  // Set default polarizations: unpolarised (may be assigned later).
4474  trialPtr->new1.pol(9);
4475  trialPtr->new2.pol(9);
4476  trialPtr->new3.pol(9);
4477  if (verbose >= verylouddebug) {
4478  printOut(__METHOD_NAME__, "Printing pre-branching momenta");
4479  for (int i = 0; i < 2; i++) cout << " " << pOld[i];
4480  printOut(__METHOD_NAME__, "Printing post-branching momenta and recoiler");
4481  for (int i = 0; i < 3; i++) cout << " " << pNew[i];
4482  for (int i = 0; i < (int)pRec.size(); i++) cout << " " << pRec[i];
4483  }
4484 
4485  // Check the energies of the initial guys.
4486  double eOldA = trialPtr->e1sav;
4487  double eOldB = trialPtr->e2sav;
4488  double eNewA = sqrt(eOldA/eOldB*(sAB+sjb)/(sAB+saj)*sab)/2.0;
4489  double eNewB = sqrt(eOldB/eOldA*(sAB+saj)/(sAB+sjb)*sab)/2.0;
4490  double eBeamAUsedNow = eBeamAUsed - eOldA + eNewA;
4491  double eBeamBUsedNow = eBeamBUsed - eOldB + eNewB;
4492  if ( (eBeamAUsedNow>0.98*eBeamA) || (eBeamBUsedNow>0.98*eBeamB) ) {
4493  if (verbose >= verylouddebug)
4494  infoPtr->errorMsg("Warning in "+__METHOD_NAME__+": Incoming x>1.");
4495  // Lowering saj and sjb until success.
4496  if (forceSplitting) {
4497  if (verbose >= verylouddebug)
4498  printOut(__METHOD_NAME__, "Forced splitting, lowering saj and sjb.");
4499  bool take = false;
4500  double lowera = 0.01*saj;
4501  double lowerb = 0.01*sjb;
4502  do {
4503  // TODO: check these relations for massive J.
4504  saj = max(0.0,saj-lowera);
4505  sjb = max(0.0,sjb-lowerb);
4506  sab = sAB + saj + sjb;
4507  eNewA = sqrt(eOldA/eOldB*(sAB+sjb)/(sAB+saj)*sab)/2.0;
4508  eNewB = sqrt(eOldB/eOldA*(sAB+saj)/(sAB+sjb)*sab)/2.0;
4509  eBeamAUsedNow = eBeamAUsed - eOldA + eNewA;
4510  eBeamBUsedNow = eBeamBUsed - eOldB + eNewB;
4511  if ( (eBeamAUsedNow<0.98*eBeamA)
4512  && (eBeamBUsedNow<0.98*eBeamB) ) take = true;
4513  } while (!take && saj>0.0 && sjb>0.0);
4514  q2new = trialGenPtr->getQ2(saj,sjb,sAB);
4515  qNew = sqrt(q2new);
4516  trialPtr->scaleSav[iTrial] = qNew;
4517  } else {
4518  trialPtr->nHull++;
4519  ++nFailedHull[iAntPhys];
4520  return false;
4521  }
4522  } else if ( (eNewA < eOldA) || (eNewB < eOldB) ) {
4523  if (verbose >= verylouddebug)
4524  printOut(__METHOD_NAME__, "Incoming energy decreased, returning.");
4525  trialPtr->nHull++;
4526  ++nFailedHull[iAntPhys];
4527  return false;
4528  }
4529 
4530  // Compute and save physical x*PDF ratio.
4531  double PDFscale = q2new;
4532 
4533  // Side with positive z momentum.
4534  int idOldA = idA;
4535  int idNewA = trialPtr->new1.id();
4536  double xOldA = eOldA / eBeamA;
4537  double xNewA = eNewA / eBeamA;
4538  if (verbose > normal && !beamAPtr->insideBounds(xNewA, PDFscale))
4539  printf("%s::PDFratio {xa,Q2a} outside boundaries\n",
4540  trialGenPtr->name().c_str());
4541  double pdfRatioA =
4542  max(beamAPtr->xfISR(iSysWin,idNewA,xNewA,PDFscale),TINYPDF)
4543  / max(beamAPtr->xfISR(iSysWin,idOldA,xOldA,PDFscale),TINYPDF);
4544 
4545  // Side with negative z momentum.
4546  int idOldB = idB;
4547  int idNewB = trialPtr->new3.id();
4548  double xOldB = eOldB / eBeamB;
4549  double xNewB = eNewB / eBeamB;
4550  if (verbose > normal && !beamBPtr->insideBounds(xNewB, PDFscale))
4551  printf("%s::PDFratio {xb,Q2b} outside boundaries\n",
4552  trialGenPtr->name().c_str());
4553  double pdfRatioB =
4554  max(beamBPtr->xfISR(iSysWin,idNewB,xNewB,PDFscale),TINYPDF)
4555  / max(beamBPtr->xfISR(iSysWin,idOldB,xOldB,PDFscale),TINYPDF);
4556 
4557  // Save. Note: colour flow is not assigned here, since this requires
4558  // knowledge of which is the next global colour tag available in the
4559  // event.
4560  trialPtr->addPDF(iTrial, pdfRatioA*pdfRatioB);
4561  if (verbose >= louddebug) printOut(__METHOD_NAME__, "end --------------");
4562  return true;
4563 
4564 }
4565 
4566 //--------------------------------------------------------------------------
4567 
4568 // Generate kinematics (IF) and set flavours and masses.
4569 
4570 bool VinciaISR::generateKinematicsIF(Event& event,
4571  BranchElementalISR* trialPtr, vector<Vec4>& pRec) {
4572 
4573  // Basic info about trial function and scale.
4574  if (verbose >= louddebug) printOut(__METHOD_NAME__, "begin --------------");
4575  int iTrial = indxWin;
4576  if (iTrial < 0) return false;
4577  double qNew = trialPtr->getTrialScale(iTrial);
4578  double q2new = pow2(qNew);
4579  int iAntPhys = trialPtr->getPhysIndex(iTrial);
4580  bool is1A = trialPtr->is1A();
4581  double eBeamUsed = (is1A ? eBeamAUsed : eBeamBUsed);
4582 
4583  // Trial generator.
4584  TrialGeneratorISR* trialGenPtr = trialPtr->trialGenPtrsSav[iTrial];
4585  int idA = trialPtr->id1sav;
4586  int idK = trialPtr->id2sav;
4587 
4588  // Force a splitting.
4589  bool forceSplitting = trialPtr->forceSplittingSav;
4590  if (forceSplitting) {
4591  trialPtr->zMinSav[iTrial] =
4592  trialPtr->trialGenPtrsSav[iTrial]->getZmin(q2new, trialPtr->sAnt(),
4593  trialPtr->e1sav, eBeamUsed);
4594  trialPtr->zMaxSav[iTrial] =
4595  trialPtr->trialGenPtrsSav[iTrial]->getZmax(q2new, trialPtr->sAnt(),
4596  trialPtr->e1sav, eBeamUsed);
4597  if (verbose >= superdebug)
4598  printOut(__METHOD_NAME__,"Note: this is a forced splitting");
4599  }
4600 
4601  // Generate zeta variable, work out saj, sjk.
4602  double saj;
4603  double sjk;
4604  double sAK = trialPtr->sAnt();
4605  bool pass = trialPtr->genTrialInvariants(saj, sjk, eBeamUsed, iTrial);
4606  if (!pass) {
4607  if (verbose >= verylouddebug)
4608  printOut(__METHOD_NAME__, "z outside physical range, returning.");
4609  trialPtr->nHull++;
4610  ++nFailedHull[iAntPhys];
4611  return false;
4612  }
4613 
4614  // Self-consistency check.
4615  if (verbose >= normal) {
4616  double sAntSav = trialPtr->sAnt();
4617  double sCheck = 2 * event[trialPtr->i1sav].p()*event[trialPtr->i2sav].p();
4618  if (abs(sAntSav - sCheck) > TINY) {
4619  event.list();
4620  list();
4621  cout << " sAK doesn't look preserved sAnt = " << sAntSav << " sCheck = "
4622  << sCheck << endl;
4623  }
4624  }
4625 
4626  // Set flavors and masses.
4627  // Flavour for gluon backwards evolving to (anti)quark
4628  int idConv = (iAntPhys == iGXconvIF) ? trialPtr->getTrialFlav() : 0;
4629  double mj=0.;
4630  double mk=0.;
4631  double mKold= event[trialPtr->i2sav].m();
4632 
4633  // Gluon emission: inherit parent flavors and add middle gluon.
4634  if (iAntPhys == iQQemitIF || iAntPhys == iQGemitIF ||
4635  iAntPhys == iGQemitIF || iAntPhys == iGGemitIF) {
4636  // Set ID codes.
4637  trialPtr->new1.id(idA);
4638  trialPtr->new2.id(21);
4639  trialPtr->new3.id(idK);
4640  // Set masses.
4641  mk = mKold;
4642  trialPtr->new1.m(0.0);
4643  trialPtr->new2.m(0.0);
4644  trialPtr->new3.m(mk);
4645 
4646  // Gluon splitting in the initial state.
4647  } else if (iAntPhys == iQXsplitIF) {
4648  // Set ID codes.
4649  trialPtr->new1.id(21);
4650  trialPtr->new2.id(-idA);
4651  trialPtr->new3.id(idK);
4652  // Set masses.
4653  mj = (abs(idA) <= nFlavZeroMass) ? 0.0
4654  : particleDataPtr->m0(abs(idA));
4655  mk = mKold;
4656  trialPtr->new1.m(0.0);
4657  trialPtr->new2.m(mj);
4658  trialPtr->new3.m(mk);
4659 
4660  // Gluon conversion in the initial state.
4661  } else if (iAntPhys == iGXconvIF) {
4662  // Set ID codes.
4663  trialPtr->new1.id(idConv);
4664  trialPtr->new2.id(idConv);
4665  trialPtr->new3.id(idK);
4666  // Set masses.
4667  mj = (abs(idConv) <= nFlavZeroMass) ? 0.0
4668  : particleDataPtr->m0(abs(idConv));
4669  mk = mKold;
4670  trialPtr->new1.m(0.0);
4671  trialPtr->new2.m(mj);
4672  trialPtr->new3.m(mk);
4673  if (verbose == superdebug) {
4674  stringstream ss;
4675  ss << "Gluon backwards evolving to id = " << idConv
4676  << " idK = " << idK
4677  << " mK = " << trialPtr->new3.m();
4678  printOut(__METHOD_NAME__,ss.str());
4679  }
4680 
4681  // Gluon splitting in the final state.
4682  } else if (iAntPhys == iXGsplitIF) {
4683  // Set flavor of splitting.
4684  double nF = min((int)trialPtr->getColFac(iTrial),nGluonToQuarkF);
4685  int splitFlavor = int(rndmPtr->flat() * nF) + 1;
4686  // Check phase space: sQQ = q2new > 4m^2.
4687  int nFmax = (int)nF;
4688  if (q2new > 4.0*pow2(mb)) nFmax = min(nFmax,5);
4689  else if (q2new > 4.0*pow2(mc)) nFmax = min(nFmax,4);
4690  else if (q2new > 4.0*pow2(ms)) nFmax = min(nFmax,3);
4691  else nFmax = min(nFmax,2);
4692  if (nFmax < splitFlavor) return false;
4693  trialPtr->new1.id(idA);
4694  // XG->XQQbar where Q is the emission because a col line emitted.
4695  if (abs(event[trialPtr->i1sav].col()) ==
4696  abs(event[trialPtr->i2sav].col()) ) {
4697  // IF is c-c or ac-ac.
4698  trialPtr->new2.id( splitFlavor);
4699  trialPtr->new3.id(-splitFlavor);
4700  // XG->XQbarQ where Qbar is the emission because a acol line emitted.
4701  } else {
4702  trialPtr->new2.id(-splitFlavor);
4703  trialPtr->new3.id( splitFlavor);
4704  }
4705  // Set masses.
4706  mj = (abs(splitFlavor) <= nFlavZeroMass) ? 0.0
4707  : particleDataPtr->m0(abs(splitFlavor));
4708  mk = mj;
4709  trialPtr->new1.m(event[trialPtr->i1sav].m());
4710  trialPtr->new2.m(mj);
4711  trialPtr->new3.m(mk);
4712  }
4713 
4714  // Generate full kinematics for this trial branching (needed to work
4715  // out xa, required for PDF weight).
4716  // Let antenna tell us which kinematics map to use.
4717  int kineMap = getAnt(iAntPhys)->kineMap();
4718  // Generate random (uniform) phi angle.
4719  double phi = 2 * M_PI * rndmPtr->flat();
4720  // Last invariant.
4721  double m2j = mj*mj;
4722  double m2k = mk*mk;
4723  double m2Kold = mKold*mKold;
4724  double sak = sAK + sjk - saj + m2j + m2k -m2Kold;
4725 
4726  // Generate branching kinematics, starting from dipole-antenna parents.
4727  vector<Vec4> pOld, pNew;
4728  pOld.push_back(event[trialPtr->i1sav].p());
4729  pOld.push_back(event[trialPtr->i2sav].p());
4730  // Decide whether to use local map 100% of the time or allow probabilistic
4731  // selection of global map.
4732  bool useLocalMap = (kineMap == 1);
4733  if (kineMap == 2 && iAntPhys == iXGsplitIF) useLocalMap = true;
4734  if (saj >= sAK) useLocalMap = true;
4735  if (!useLocalMap) {
4736  // Make probabilistic choice between global and local maps.
4737  double probGlobal = pow2(sAK - saj) / (pow2(sAK + sjk) + pow2(sAK - saj));
4738  if (rndmPtr->flat() < probGlobal) {
4739  // Set B momentum (fixed but used for dot products by global map).
4740  int iB = partonSystemsPtr->getInB(iSysWin);
4741  if (iB == trialPtr->i1sav) iB = partonSystemsPtr->getInA(iSysWin);
4742  Vec4 pB = event[iB].p();
4743  pass = vinComPtr->map2to3IFglobal(pNew, pRec, pOld, pB,
4744  sAK, saj, sjk, sak, phi, m2Kold, m2j, m2k);
4745  // Retry with local map if global one fails.
4746  if (!pass && kineMapIFretry) useLocalMap = true;
4747  // 1 - probGlobal to select local map.
4748  } else useLocalMap = true;
4749  }
4750  if (useLocalMap) {
4751  // Local map: no recoilers outside antenna itself.
4752  pRec.resize(0);
4753  pass = vinComPtr->map2to3IFlocal(pNew, pOld, sAK, saj, sjk, sak, phi,
4754  m2Kold, m2j, m2k);
4755  }
4756  if (!pass && !forceSplitting) {
4757  if (verbose >= louddebug ) printOut(__METHOD_NAME__, "Failed map2to3IF.");
4758  trialPtr->nHull++;
4759  ++nFailedKine[iAntPhys];
4760  return false;
4761  }
4762 
4763  // Check if enough energy is available in beam.
4764  double eBeam = (is1A ? eBeamA : eBeamB);
4765  double eBeamUsedNow = eBeamUsed - pOld[0].e() + pNew[0].e();
4766  if (eBeamUsedNow > 0.98*eBeam) {
4767  trialPtr->nHull++;
4768  ++nFailedKine[iAntPhys];
4769  return false;
4770  }
4771 
4772  // Save momenta.
4773  trialPtr->new1.p(pNew[0]);
4774  trialPtr->new2.p(pNew[1]);
4775  trialPtr->new3.p(pNew[2]);
4776  // Set default polarizations: unpolarised (may be assigned later).
4777  trialPtr->new1.pol(9);
4778  trialPtr->new2.pol(9);
4779  trialPtr->new3.pol(9);
4780  if (verbose >= verylouddebug) {
4781  printOut(__METHOD_NAME__, "Printing pre-branching momenta");
4782  for (int i = 0; i < 2; i++) cout << " " << pOld[i];
4783  printOut(__METHOD_NAME__, "Printing post-branching momenta and recoiler");
4784  for (int i = 0; i < 3; i++) cout << " " << pNew[i];
4785  for (int i = 0; i < (int)pRec.size(); i++) cout << " " << pRec[i];
4786  }
4787 
4788  // PDF ratio. Note, in gluon conversion the q2trial is generated
4789  // with the sum of quark flavours but at the same time a trial
4790  // flavour is selected and the saved trial PDF ratio only contains
4791  // that flavour/glue, so we don't need to know the sum here.
4792  BeamParticle* beamPtr = is1A ? beamAPtr : beamBPtr;
4793  double PDFscale = q2new;
4794  int idOld = idA;
4795  int idNew = trialPtr->new1.id();
4796  double eOld = pOld[0].e();
4797  double xOld = eOld / eBeam;
4798  double eNew = pNew[0].e();
4799  double xNew = eNew / eBeam;
4800  if (verbose > normal && !beamPtr->insideBounds(xNew, PDFscale))
4801  printf("%s::PDFratio {x,Q2} outside boundaries\n",
4802  trialGenPtr->name().c_str());
4803  double newPDF = beamPtr->xfISR(iSysWin,idNew,xNew,PDFscale);
4804  // Check PDF > 0; otherwise reject trial.
4805  if (newPDF < 0.) {
4806  trialPtr->nHull++;
4807  ++nFailedKine[iAntPhys];
4808  return false;
4809  }
4810  double oldPDF = beamPtr->xfISR(iSysWin,idOld,xOld,PDFscale);
4811  double pdfRatio = max(newPDF,TINYPDF) / max(oldPDF,TINYPDF);
4812 
4813  // Verbose output if old PDF does not make sense.
4814  if (oldPDF <= 0.0 && verbose > normal) {
4815  cout << " PDF ratio = " << num2str(pdfRatio)
4816  << " for idOld = " << idOld << " idNew = " << idNew
4817  << " xOld = " << num2str(xOld) << " xNew = " << num2str(xNew)
4818  << " qPDF = " << num2str(sqrt(PDFscale))
4819  << endl;
4820  cout << " Numerator = "
4821  << num2str(beamPtr->xfISR(iSysWin,idNew,xNew,PDFscale))
4822  << " Denom = "
4823  << num2str(beamPtr->xfISR(iSysWin,idOld,xOld,PDFscale))
4824  << " iSys = " << iSysWin << " nSys = "
4825  << partonSystemsPtr->sizeSys() << endl;
4826  }
4827 
4828  // Save.
4829  trialPtr->addPDF(iTrial, pdfRatio);
4830 
4831  // Check the energies of the initial guy.
4832  double eAotherSys = 0.0;
4833  double eBeamNow = 0.0;
4834  // Sum up energy used by other systems.
4835  if (is1A) {
4836  for (map<int, Particle>::iterator it = initialA.begin();
4837  it != initialA.end(); it++) {
4838  int i = it->first;
4839  if (i!=iSysWin) eAotherSys+=initialA[i].e();
4840  }
4841  eBeamNow = eBeamA;
4842  // Sum up energy used by other systems.
4843  } else {
4844  for (map<int, Particle>::iterator it = initialB.begin();
4845  it != initialB.end(); it++) {
4846  int i = it->first;
4847  if (i!=iSysWin) eAotherSys+=initialB[i].e();
4848  }
4849  eBeamNow = eBeamB;
4850  }
4851  if ((eNew+eAotherSys) > 0.98*eBeamNow) {
4852  if (verbose >= verylouddebug) printOut(__METHOD_NAME__,
4853  "Energy of incoming partons exceed beam energy, returning.");
4854  // Lowering sjk (splitting orderd in saj) until success.
4855  if (forceSplitting) {
4856  if (verbose >= verylouddebug)
4857  printOut(__METHOD_NAME__, "Forced splitting, lowering sjk.");
4858  eNew = (0.98*eBeamNow - eAotherSys);
4859  sjk = sAK*(eNew-eOld)/eOld;
4860  // This should not happen.
4861  if (sjk <= 0.001) {
4862  if (sjk <= 0.0) sjk = pow(10.0,-10.0);
4863  if (verbose >= verylouddebug) printOut(__METHOD_NAME__,
4864  "Need to choose sjk = "+ num2str(sjk) + " probably due to MPI");
4865  }
4866  eNew = eOld*(sAK+sjk)/sAK;
4867  sak = sAK + sjk - saj + m2j + m2k -m2Kold;
4868  if (sak <= 0.0) {
4869  sak = 1.0;
4870  do {
4871  sak = sak/10.0;
4872  saj = sAK + sjk - sak + m2j + m2k -m2Kold;
4873  } while (saj <= sak);
4874  }
4875  q2new = trialGenPtr->getQ2(saj,sjk,sAK);
4876  qNew = sqrt(q2new);
4877  trialPtr->scaleSav[iTrial] = qNew;
4878  } else {
4879  trialPtr->nHull++;
4880  ++nFailedHull[iAntPhys];
4881  return false;
4882  }
4883  }
4884 
4885  // Check local hadronization veto(s) inside this BranchElemental.
4886  // Require all generated final-state invariants at least above
4887  // lowest physical meson mass (FF invariant is only the 23 one)
4888  // (could in principle check only colour-connected invariants but
4889  // here just check all 23 invariants regardless of colour
4890  // connection.
4891  // Only if we do not want to force a splitting.
4892  if (!forceSplitting) {
4893  double mMin23 = vinComPtr->mHadMin(trialPtr->new2.id(),
4894  trialPtr->new3.id());
4895  if (sjk < pow2(1.01*mMin23)) {
4896  if (verbose >= debug)
4897  printOut(__METHOD_NAME__, "=== Branching Vetoed. m23 < 1.01*mMes.");
4898  trialPtr->nHadr++;
4899  ++nFailedCutoff[iAntPhys];
4900  return false;
4901  }
4902  }
4903 
4904  // Note, colour flow is not assigned here, since this requires
4905  // knowledge of which is the next global colour tag available in the
4906  // event.
4907  if (verbose >= louddebug) printOut(__METHOD_NAME__, "end --------------");
4908  return true;
4909 
4910 }
4911 
4912 //--------------------------------------------------------------------------
4913 
4914 // Main method to decide whether to accept or reject a trial branching after
4915 // full branching kinematics have been constructed.
4916 
4917 bool VinciaISR::acceptTrial(const Event& event, BranchElementalISR* trialPtr) {
4918 
4919  // Basic info about trial function and scale
4920  if (verbose >= debug) printOut(__METHOD_NAME__, "begin --------------");
4921  int iTrial = indxWin;
4922  if (iTrial < 0) {
4923  if (verbose >= debug) printOut(__METHOD_NAME__, "iTrial < 0 ");
4924  return false;
4925  }
4926  double qNew = trialPtr->getTrialScale(iTrial);
4927  int iAntPhys = trialPtr->getPhysIndex(iTrial);
4928  int iSys = trialPtr->system;
4929  bool isII = trialPtr->isII();
4930  bool isSwapped = (isII ? trialPtr->getIsSwapped(iTrial) : false);
4931  // Set to false for IF because there it was always guy 1 who did
4932  // gluon splitting/conversion in the initial state.
4933 
4934  // Trial generator.
4935  TrialGeneratorISR* trialGenPtr = trialPtr->trialGenPtrsSav[iTrial];
4936 
4937  // Invariants.
4938  double S12 = trialPtr->sAnt();
4939  double s1j = trialPtr->s12();
4940  double sj2 = trialPtr->s23();
4941 
4942  // Helicity of mother partons.
4943  // First mother is always initial. Second mother is initial for II.
4944  double hA = event[trialPtr->i1sav].pol();
4945  double hB = event[trialPtr->i2sav].pol();
4946  bool isPolarised = polarisedSys[iSys] && (hA != 9 && hB != 9);
4947 
4948  // Compute spin-summed trial antenna*PDF sum including colour and
4949  // headroom factors. Sum over individual trial terms
4950  double antPDFtrialSum = 0.0;
4951  double nTrialTerms = 0;
4952  for (int iTerm = 0; iTerm < (int)trialPtr->nTrialGenerators(); ++iTerm) {
4953  // Only include terms that correspond to the current physical antenna.
4954  if (trialPtr->getPhysIndex(iTerm) != iAntPhys) continue;
4955  // Only include terms that correspond to the same side.
4956  if (isII && trialPtr->getIsSwapped(iTerm) != isSwapped) continue;
4957  antPDFtrialSum += trialPtr->headroomSav[iTerm]
4958  * trialPtr->trialGenPtrsSav[iTerm]->aTrial(s1j, sj2, S12)
4959  * trialPtr->trialPDFratioSav[iTerm]
4960  * trialPtr->getColFac(iTerm);
4961  nTrialTerms++;
4962  }
4963 
4964  // Enhanced kernels. Note, all trial functions for the same
4965  // iAntPhys must use same enhanceFac.
4966  double enhanceFac = trialPtr->getEnhanceFac(iTrial);
4967  // If enhancement was applied but branching is below enhancement
4968  // cutoff, do accept/reject here with probability
4969  // trial/enhance-trial to get back to unenhanced trial
4970  // probability. (Trials only enhanced for enhanceFac > 1.)
4971  if (enhanceFac > 1.0 && qNew <= enhanceCutoff) {
4972  if ( rndmPtr->flat() > 1./enhanceFac ) {
4973  if (verbose >= verylouddebug)
4974  printOut(__METHOD_NAME__, "Trial vetoed at enhancement stage.");
4975  return false;
4976  }
4977  enhanceFac = 1.0;
4978  }
4979 
4980  // If physical antenna function is mirror of current trial, translate to
4981  // swapped invariants for antenna-function evaluation.
4982  double hAant = hA;
4983  double hBant = hB;
4984  double s1jant = s1j;
4985  double sj2ant = sj2;
4986  double m1ant = trialPtr->new1.m();
4987  double mjant = trialPtr->new2.m();
4988  double m2ant = trialPtr->new3.m();
4989  if (isSwapped) {
4990  hAant = hB;
4991  hBant = hA;
4992  s1jant = sj2;
4993  sj2ant = s1j;
4994  m1ant = trialPtr->new3.m();
4995  m2ant = trialPtr->new1.m();
4996  }
4997  // Fill vectors to use for antenna-function evaluation.
4998  vector<double> invariants;
4999  invariants.push_back(S12);
5000  invariants.push_back(s1jant);
5001  invariants.push_back(sj2ant);
5002  invariants.push_back(trialPtr->s13());
5003  // So far ISR is massless.
5004  vector<double> mNew;
5005  mNew.push_back(m1ant);
5006  mNew.push_back(mjant);
5007  mNew.push_back(m2ant);
5008  // Parent helicities.
5009  vector<int> helBef;
5010  helBef.push_back(hAant);
5011  helBef.push_back(hBant);
5012  // Total accept is summed over daughter helicities (selection done below).
5013  vector<int> helUnpol;
5014  helUnpol.push_back(9);
5015  helUnpol.push_back(9);
5016  helUnpol.push_back(9);
5017 
5018  // Compute spin-summed physical antennae (spin selection below).
5019  // Define pointer antennae.
5020  AntennaFunctionIX* antPtr = getAnt(iAntPhys);
5021  // Compute spin-summed antenna function.
5022  if (verbose >= verylouddebug)
5023  printOut(__METHOD_NAME__, "Evaluating antenna function and PDF ratio");
5024  double helSum;
5025  // Unpolarised case: ignore parent helicities.
5026  if (!isPolarised) helSum = antPtr->antFun(invariants,mNew);
5027  // Polarised case: use parent helicities.
5028  else helSum = antPtr->antFun(invariants, mNew, helBef, helUnpol);
5029  if (helSum <0.) {
5030  if (verbose > normal) {
5031  infoPtr->errorMsg("Error in "+__METHOD_NAME__+
5032  "Negative Antenna Function.","iAnt = "+num2str(iAntPhys));
5033  }
5034  return false;
5035  }
5036  if (verbose >= verylouddebug)
5037  printOut(__METHOD_NAME__,"helSum = "+num2str(helSum));
5038 
5039  // Store (partial) helicity sum.
5040  double antPhys = helSum;
5041  // Apply color (charge) factor.
5042  antPhys *= antPtr->chargeFac();
5043  // PDF factor.
5044  double PDFphys = trialPtr->physPDFratioSav[iTrial];
5045  // Extra factor from using running of PDFs close to mass threshold.
5046  double extraMassPDFfactor = trialPtr->extraMassPDFfactorSav[iTrial];
5047  PDFphys *= extraMassPDFfactor;
5048 
5049  // Starting value for accept probability = Physical/Trial.
5050  Paccept[0] = antPhys*PDFphys/antPDFtrialSum;
5051  if (verbose >= superdebug ||
5052  (Paccept[0] > 1.02 && qNew > 1.0 && verbose >= quiteloud)) {
5053  if (nTrialTerms == 1) {
5054  printOut(__METHOD_NAME__, "Single trial:");
5055  cout << " TrialGenerator= " << trialGenPtr->name() << endl;
5056  cout << " AntTrial/s = " << setprecision(6)
5057  << trialGenPtr->aTrial(s1j, sj2, S12) << " * "
5058  << trialPtr->headroomSav[iTrial] << " (headroom)"
5059  << " s1j, s2j = " << s1j << " " << sj2 << " sOld = " << S12 << endl;
5060  cout << " AntPhys/s = " << setprecision(6)
5061  << antPhys/antPtr->chargeFac() << endl;
5062  cout << " massPDFfactor = " << setprecision(6) << extraMassPDFfactor
5063  << endl;
5064  cout << " PDFtrial = " << setprecision(6)
5065  << trialPtr->trialPDFratioSav[iTrial] << endl;
5066  cout << " PDFphys = " << setprecision(6)
5067  << PDFphys << endl;
5068  } else {
5069  printOut(__METHOD_NAME__,
5070  "Combination of seveveral trials (gluon emission):");
5071  cout << " Win Generator = " << trialGenPtr->name() << endl;
5072  cout << " AntPhys/s = " << setprecision(6) << antPhys << endl;
5073  cout << " PDFphys = " << setprecision(6) << PDFphys << endl;
5074  }
5075  if (isII) cout << " II isSwapped = " << bool2str(isSwapped) << endl;
5076  else cout << " IF is1A = " << bool2str(trialPtr->is1A()) << endl;
5077  cout << " idOld = " << trialPtr->id1sav << " "
5078  << trialPtr->id2sav;
5079  cout << " idNew = " << trialPtr->new1.id() << " "
5080  << trialPtr->new2.id() << " " << trialPtr->new3.id() << endl;
5081  cout << " xOld = " << trialPtr->e1sav/eBeamA;
5082  if (isII) cout << " " << trialPtr->e2sav/eBeamB << endl;
5083  else cout << endl;
5084  cout << " isVal = " << bool2str(trialPtr->isVal1());
5085  if (isII) cout << " " << bool2str(trialPtr->isVal2());
5086  cout << endl;
5087  cout << " Q = " << qNew << endl;
5088  cout << " AntPDFtrial = " << setprecision(6) << antPDFtrialSum
5089  << endl;
5090  cout << " AntPDFphys = " << setprecision(6) << antPhys*PDFphys
5091  << endl;
5092  cout << " Paccept = " << setprecision(6) << Paccept[0] << endl;
5093  cout << " Enhancement = " << setprecision(6) << enhanceFac << endl;
5094  }
5095 
5096  // Choose helicities for daughter particles (so far only for
5097  // massless polarised shower).
5098  double aHel = 0.0;
5099  if ( isPolarised ) {
5100  // Generate random number.
5101  double randHel = rndmPtr->flat() * helSum;
5102  // Select helicity.
5103  int hi(0), hj(0), hk(0);
5104  for (hi = hAant; abs(hi) <= 1; hi -= 2*hAant) {
5105  for (hk = hBant; abs(hk) <= 1; hk -= 2*hBant) {
5106  for (hj = hAant; abs(hj) <= 1; hj -= 2*hAant) {
5107  vector<int> helNow;
5108  helNow.push_back(hi);
5109  helNow.push_back(hj);
5110  helNow.push_back(hk);
5111  aHel = antPtr->antFun(invariants, mNew, helBef, helNow);
5112  randHel -= aHel;
5113  if (verbose >= verylouddebug){
5114  stringstream ss;
5115  ss<< "antPhys("<< hAant <<" " << hBant
5116  <<" -> "<< hi << " " << hj << " "<< hk << ") = " << aHel
5117  << " isSwapped = " << isSwapped
5118  << " sum = " << helSum;
5119  printOut(__METHOD_NAME__, ss.str());
5120  }
5121  if (randHel < 0.) break;
5122  }
5123  if (randHel < 0.) break;
5124  }
5125  if (randHel < 0.) break;
5126  }
5127  if (verbose >= louddebug)
5128  printOut(__METHOD_NAME__, "selected" + num2str(int(hAant)) +
5129  " " + num2str(int(hBant)) + " -> " + num2str(hi) + " " +
5130  num2str(hj) + " " + num2str(hk) + ", isSwapped = " +
5131  bool2str(isSwapped)+"\n");
5132  // Assign helicities (taking swapped invariants into account).
5133  if (!isSwapped) {
5134  trialPtr->new1.pol(hi);
5135  trialPtr->new2.pol(hj);
5136  trialPtr->new3.pol(hk);
5137  } else {
5138  trialPtr->new1.pol(hk);
5139  trialPtr->new2.pol(hj);
5140  trialPtr->new3.pol(hi);
5141  }
5142  // If not polarised.
5143  } else {
5144  trialPtr->new1.pol(9);
5145  trialPtr->new2.pol(9);
5146  trialPtr->new3.pol(9);
5147  polarisedSys[iSys] = false;
5148  }
5149 
5150  // AlphaS, impose default choice. Can differ slighly from trial even
5151  // when running inside trial integral, due to flavor
5152  // thresholds. Here, alphaS(mu) is returned directly, with the
5153  // number of flavors active at mu, whereas the number of flavors in
5154  // the trial integral is controlled by the value of the trial scale.
5155  double alphaTrial = trialPtr->getAlphaTrial(iTrial);
5156  if (std::isnan(alphaTrial)) cout << " alphaStrial is NAN!!!" << endl;
5157  if (alphaTrial != alphaTrial)
5158  cout << " alphaStrial is != alphaStrial" << endl;
5159  double mu2 = pow2(qNew);
5160  double kMu2Usr = aSkMu2EmitI;
5161  if (iAntPhys == iXGsplitIF) kMu2Usr = aSkMu2SplitF;
5162  else if (iAntPhys == iQXsplitIF || iAntPhys == iQXsplitII)
5163  kMu2Usr = aSkMu2SplitI;
5164  else if (iAntPhys == iGXconvIF || iAntPhys == iGXconvII)
5165  kMu2Usr = aSkMu2Conv;
5166  double mu2Usr = max(mu2min, mu2freeze + mu2*kMu2Usr);
5167  // alphaS values.
5168  double alphaSusr = min(alphaSmax, alphaSptr->alphaS(mu2Usr));
5169  if (verbose >= verylouddebug ||
5170  (verbose >= quiteloud && alphaTrial < alphaSusr)) {
5171  stringstream ss;
5172  ss << "alphaTrial = " << alphaTrial << ", alphaSusr = " << alphaSusr
5173  << " at q = " << qNew << ", Trial Generator " << trialGenPtr->name();
5174  printOut(__METHOD_NAME__, ss.str() );
5175  }
5176 
5177  // Reweight central accept probability with user choice.
5178  Paccept[0] *= alphaSusr / alphaTrial;
5179 
5180  // Matrix element corrections.
5181  // Initialise flag to decide if we want to do a MEC.
5182  bool doMEC = doMECsSys[iSys];
5183  double pMEC = 1.0;
5184  // Check if we did MEC at last order for this process.
5185  if (doMEC) doMEC = false;
5186 
5187  // Check number of partons added since Born.
5188  int branchOrder = 1;
5189  int showerOrder = branchOrder
5190  + partonSystemsPtr->sizeOut(iSys) - mecsPtr->sizeOutBorn(iSys);
5191  if (doMEC) doMEC = false;
5192  // Check if we have an ME for this post-branching process label.
5193  if (doMEC) doMEC = false;
5194 
5195  // If we want to compute a MEC, we make a temporary new event record,
5196  // and a temporary new PartonSystem, with the tentative new state.
5197  if (doMEC) {
5198  // Copy event.
5199  Event eventNew = event;
5200  int iSysNew = partonSystemsPtr->addSys();
5201 
5202  // Copy old system information to new one
5203  partonSystemsPtr->setInA(iSysNew, partonSystemsPtr->getInA(iSys));
5204  partonSystemsPtr->setInB(iSysNew, partonSystemsPtr->getInB(iSys));
5205  for (int i=0; i<partonSystemsPtr->sizeOut(iSys); ++i)
5206  partonSystemsPtr->addOut(iSysNew, partonSystemsPtr->getOut(iSys,i));
5207 
5208  // Replace pre-branching particles with post-branching ones in
5209  // eventNew. Replace pre-branching particles with post-branching
5210  // ones in partonSystem. Evaluate MEC on eventNew (for temporary
5211  // system iSysNew); Would MEC benefit from knowing iSysOld too?
5212  // Note, if doing merging, need to cluster all jets, potentially
5213  // past what we got in as the "Born" for this run
5214 
5215  // Modify accept probability.
5216  Paccept[0] *= pMEC;
5217 
5218  // Clean up after MECs: remove temporary system we added to compute MEC.
5219  partonSystemsPtr->popBack();
5220  }
5221 
5222  // Print MC violations.
5223  if (verbose >= verylouddebug)
5224  printOut(__METHOD_NAME__, " Trial Paccept = " + num2str(Paccept[0]));
5225  bool violation = (Paccept[0] > 1.0 + TINY);
5226  bool negPaccept = (Paccept[0] < 0.0);
5227  if (violation || negPaccept) {
5228  if (verbose >= quiteloud ) {
5229  stringstream ss;
5230  if(doMEC) ss << "Paccept (shower and ME, order = ";
5231  else ss << "Paccept (shower, order = ";
5232  ss << showerOrder <<" ) = " << Paccept[0] << " at q = " << qNew
5233  << " in Trial Generator " << trialGenPtr->name();
5234  printOut(__METHOD_NAME__, ss.str());
5235  if (extraMassPDFfactor != 1.0)
5236  printOut(__METHOD_NAME__, " == Note: PDFs close to mass threshold");
5237  if (verbose >= loud || Paccept[0] > 100.0) {
5238  if (doMEC) cout <<" MEC factor = " << pMEC << endl;
5239  cout << (isII ? " AB -> ajb = " : " AK -> ajk = ") << trialPtr->id1sav
5240  << " " << trialPtr->id2sav << " -> " << trialPtr->new1.id() << " "
5241  << trialPtr->new2.id() << " " << trialPtr->new3.id() << " maj = "
5242  << sqrt(m2(trialPtr->new1.p()+trialPtr->new2.p()))
5243  << (isII ? " mjb" :
5244  " mjk")<<" = "<<sqrt(m2(trialPtr->new2.p()+trialPtr->new3.p()))
5245  << (isII ? " mAB" : " mAK") << " = " << sqrt(S12)<<endl;
5246  }
5247  if (verbose >= debug) trialPtr->list();
5248  if (Paccept[0] > 100.0) {
5249  int nResc = trialPtr->getNshouldRescue(iTrial);
5250  double PDFphysTrial = trialPtr->physPDFratioSav[iTrial]/
5251  trialPtr->trialPDFratioSav[iTrial];
5252  if (nResc>0 || PDFphysTrial>100.0) {
5253  if (nResc>0) cout << " Had " << nResc << " pTnext ~ pTold,";
5254  else
5255  cout << " Headroom = " << trialPtr->headroomSav[iTrial]
5256  << ", PDFphys/ PDFtrial = " << PDFphysTrial << endl;
5257  }
5258  }
5259  }
5260  }
5261 
5262  // TODO: uncertainty bands.
5263 
5264  // Accept/Reject step.
5265  // Enhance factors < 1 (radiation inhibition) treated by modifying pAccept.
5266  if (rndmPtr->flat() > min(1.0,enhanceFac)*Paccept[0]) {
5267 
5268  // Enhancement.
5269  if (enhanceFac != 1.0)
5270  weightsPtr->scaleWeightEnhanceReject(Paccept[0],enhanceFac);
5271 
5272  // Count up number of vetoed branchings.
5273  trialPtr->nVeto++;
5274  ++nFailedVeto[iAntPhys];
5275  rFailedVetoPDF[iAntPhys] += trialPtr->physPDFratioSav[iTrial]/
5276  trialPtr->trialPDFratioSav[iTrial];
5277  if (verbose >= debug ) {
5278  printOut(__METHOD_NAME__, "Branching vetoed.");
5279  if (verbose >= verylouddebug) {
5280  stringstream ss;
5281  ss << "Paccept = " << Paccept[0] << " Enhancefac = " << enhanceFac;
5282  printOut(__METHOD_NAME__, ss.str());
5283  }
5284  }
5285  return false;
5286  }
5287 
5288  // Enhancement.
5289  if (enhanceFac != 1.0)
5290  weightsPtr->scaleWeightEnhanceAccept(enhanceFac);
5291  if (verbose >= debug) printOut(__METHOD_NAME__, "end --------------");
5292  return true;
5293 
5294 }
5295 
5296 //--------------------------------------------------------------------------
5297 
5298 // Paint a trialPtr with colour-flow information,
5299 // according to the type of branching.
5300 
5301 bool VinciaISR::assignColourFlow(Event& event, BranchElementalISR* trialPtr) {
5302 
5303  // Basic info about trial function and old partons.
5304  bool usedColTag = false;
5305  int iTrial = indxWin;
5306  int iAntPhys = trialPtr->getPhysIndex(iTrial);
5307  bool isSwapped = trialPtr->getIsSwapped(iTrial);
5308  int colOld = trialPtr->col();
5309  int col1 = event[trialPtr->i1sav].col();
5310  int acol1 = event[trialPtr->i1sav].acol();
5311  int col2 = event[trialPtr->i2sav].col();
5312  int acol2 = event[trialPtr->i2sav].acol();
5313 
5314  // Gluon emission.
5315  if (trialPtr->new2.id() == 21) {
5316  double s12 = trialPtr->new1.p()*trialPtr->new2.p();
5317  double s23 = trialPtr->new2.p()*trialPtr->new3.p();
5318  // Who inherits the colour.
5319  bool inh12 = colourPtr->inherit01(s12,s23);
5320  // Note, use lastColTag here, if branching accepted we tell Pythia
5321  // that we used one.
5322  int nTag = event.lastColTag()+1;
5323  usedColTag = true;
5324  // Check other colourtag for gluons.
5325  int colL = 0;
5326  int colR = 0;
5327  if (trialPtr->colType1sav == 2) {
5328  if (colOld == col1) colL = event[trialPtr->i1sav].acol();
5329  else colL = event[trialPtr->i1sav].col();
5330  }
5331  if (trialPtr->colType2sav == 2) {
5332  if (colOld == col2) colR = event[trialPtr->i2sav].acol();
5333  else colR = event[trialPtr->i2sav].col();
5334  }
5335  int nextTag = 10*int(nTag/10) + 10;
5336  int colNew = nextTag + int(colOld%10 + rndmPtr->flat()*8)%9 + 1;
5337  // new1 inherits colour.
5338  if (inh12) {
5339  while (colNew%10 == colR%10)
5340  colNew = nextTag + int(colOld%10 + rndmPtr->flat()*8)%9 + 1;
5341  trialPtr->new1.acol(acol1);
5342  trialPtr->new1.col(col1);
5343  trialPtr->new2.acol(colOld == col1 ? colNew : colOld);
5344  trialPtr->new2.col(colOld == col1 ? colOld : colNew);
5345  trialPtr->new3.acol(colOld == acol2 ? colNew : acol2);
5346  trialPtr->new3.col(colOld == acol2 ? col2 : colNew);
5347  // new3 inherits colour.
5348  } else {
5349  while (colNew%10 == colL%10)
5350  colNew = nextTag + int(colOld%10 + rndmPtr->flat()*8)%9 + 1;
5351  trialPtr->new1.acol(colOld == col1 ? acol1 : colNew);
5352  trialPtr->new1.col(colOld == col1 ? colNew : col1);
5353  trialPtr->new2.acol(colOld == col1 ? colOld : colNew);
5354  trialPtr->new2.col(colOld == col1 ? colNew : colOld);
5355  trialPtr->new3.acol(acol2);
5356  trialPtr->new3.col(col2);
5357  }
5358 
5359  // Gluon splitting in the initial state: side A.
5360  } else if ((iAntPhys == iQXsplitII && !isSwapped) ||
5361  iAntPhys == iQXsplitIF) {
5362  // II new1 G -> old1 Q/QB (enters hard process) + new2 QB/Q and
5363  // new3 -> old2 as recoiler
5364  // Note, use lastColTag here, if branching accepted we tell
5365  // Pythia that we used one.
5366  int nTag = event.lastColTag()+1;
5367  usedColTag = true;
5368  // Splitting quark -> antiquark in FS.
5369  if (colOld == col1) {
5370  trialPtr->new1.acol(nTag);
5371  trialPtr->new1.col(col1);
5372  trialPtr->new2.acol(nTag);
5373  trialPtr->new2.col(0);
5374  // Splitting antiquark -> quark in FS.
5375  } else {
5376  trialPtr->new1.acol(acol1);
5377  trialPtr->new1.col(nTag);
5378  trialPtr->new2.acol(0);
5379  trialPtr->new2.col(nTag);
5380  }
5381  trialPtr->new3.acol(acol2);
5382  trialPtr->new3.col(col2);
5383  }
5384 
5385  // Gluon splitting in the initial state: side B.
5386  else if (iAntPhys == iQXsplitII && isSwapped) {
5387  // II new3 G -> old2 Q/QB (enters hard process) + new2 QB/Q and
5388  // new1 -> old1 as recoiler
5389  // Note, use lastColTag here, if branching accepted we tell
5390  // Pythia that we used one.
5391  int nTag = event.lastColTag()+1;
5392  usedColTag = true;
5393  // Splitting quark -> antiquark in FS.
5394  if (colOld == col2) {
5395  trialPtr->new2.acol(nTag);
5396  trialPtr->new2.col(0);
5397  trialPtr->new3.acol(nTag);
5398  trialPtr->new3.col(col2);
5399  // Splitting antiquark -> quark in FS.
5400  } else {
5401  trialPtr->new2.acol(0);
5402  trialPtr->new2.col(nTag);
5403  trialPtr->new3.acol(acol2);
5404  trialPtr->new3.col(nTag);
5405  }
5406  trialPtr->new1.acol(acol1);
5407  trialPtr->new1.col(col1);
5408  }
5409 
5410  // Gluon convsersion in the initial state: side A.
5411  else if ((iAntPhys == iGXconvII && !isSwapped) || iAntPhys == iGXconvIF) {
5412  // II new1 Q/QB -> old1 G (enters hard process) + new2 Q/QB and
5413  // new3 -> old2 as recoiler
5414  // Quark.
5415  if (trialPtr->new2.id() > 0) {
5416  trialPtr->new1.acol(0);
5417  trialPtr->new1.col(col1);
5418  trialPtr->new2.acol(0);
5419  trialPtr->new2.col(acol1);
5420  // Antiquark.
5421  } else {
5422  trialPtr->new1.acol(acol1);
5423  trialPtr->new1.col(0);
5424  trialPtr->new2.acol(col1);
5425  trialPtr->new2.col(0);
5426  }
5427  trialPtr->new3.acol(acol2);
5428  trialPtr->new3.col(col2);
5429  }
5430 
5431  // Gluon conversion in the initial state: side B.
5432  else if (iAntPhys == iGXconvII && isSwapped) {
5433  // II new3 Q/QB -> old2 G (enters hard process) + new2 Q/QB and
5434  // new1 -> old1 as recoiler
5435  // Quark.
5436  if (trialPtr->new2.id() > 0) {
5437  trialPtr->new2.acol(0);
5438  trialPtr->new2.col(acol2);
5439  trialPtr->new3.acol(0);
5440  trialPtr->new3.col(col2);
5441  // Anitquark.
5442  } else {
5443  trialPtr->new2.acol(col2);
5444  trialPtr->new2.col(0);
5445  trialPtr->new3.acol(acol2);
5446  trialPtr->new3.col(0);
5447  }
5448  trialPtr->new1.acol(acol1);
5449  trialPtr->new1.col(col1);
5450  }
5451 
5452  // Gluon splitting in the final state.
5453  else if ( iAntPhys == iXGsplitIF) {
5454  // IF old2 G -> new3 QB/Q + new2 Q/QB and
5455  // new1 -> old1 as recoiler
5456  // Quark.
5457  if (trialPtr->new2.id() > 0) {
5458  trialPtr->new2.acol(0);
5459  trialPtr->new2.col(col2);
5460  trialPtr->new3.acol(acol2);
5461  trialPtr->new3.col(0);
5462  // Splitting acol line -> emission is antiquark.
5463  } else {
5464  trialPtr->new2.acol(acol2);
5465  trialPtr->new2.col(0);
5466  trialPtr->new3.acol(0);
5467  trialPtr->new3.col(col2);
5468  }
5469  trialPtr->new1.acol(acol1);
5470  trialPtr->new1.col(col1);
5471  }
5472  return usedColTag;
5473 
5474 }
5475 
5476 //==========================================================================
5477 
5478 } // end namespace Pythia8
Definition: beam.h:43
Definition: AgUStep.h:26