StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VinciaFSR.cc
1 // VinciaFSR.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 VinciaFSR class
7 // and auxiliary classes.
8 
9 #include "Pythia8/VinciaFSR.h"
10 
11 namespace Pythia8 {
12 
13 //==========================================================================
14 
15 // The Brancher class, base class containing a generic set of "parent
16 // partons" as well as virtual methods for generating trial
17 // branchings.
18 
19 //--------------------------------------------------------------------------
20 
21 // Reset.
22 
23 void Brancher::reset(int iSysIn, Event& event, vector<int> iIn) {
24 
25  // Save info on parents and resize vectors.
26  iSav = iIn;
27  hasTrialSav = false;
28  systemSav = iSysIn;
29  Vec4 pSum;
30  int nMassive = 0;
31  idSav.resize(iIn.size());
32  hSav.resize(iIn.size());
33  colTypeSav.resize(iIn.size());
34  colSav.resize(iIn.size());
35  acolSav.resize(iIn.size());
36  mSav.resize(iIn.size());
37  for (unsigned int i = 0; i < iIn.size(); ++i) {
38  idSav[i] = event[iIn[i]].id();
39  hSav[i] = event[iIn[i]].pol();
40  colTypeSav[i] = event[iIn[i]].colType();
41  colSav[i] = event[iIn[i]].col();
42  acolSav[i] = event[iIn[i]].acol();
43  mSav[i] = event[iIn[i]].m();
44  if (mSav[i] != 0.0) nMassive += 1;
45  // Compute and store antenna invariant mass.
46  pSum += event[iIn[i]].p();
47  }
48  m2AntSav = pSum.m2Calc();
49  mAntSav = (m2AntSav >= 0) ? sqrt(m2AntSav) : -sqrt(-m2AntSav);
50  // Massless parents: sIK = m2IK and kallenFac = 1.0.
51  sAntSav = m2AntSav;
52  kallenFacSav = 1.0;
53  // Mass corrections to sAnt and kallenFac.
54  if (nMassive != 0) {
55  // sIK = m2IK - m2I - m2K.
56  for (unsigned int i = 0; i < iIn.size(); ++i) sAntSav -= pow2(mSav[i]);
57  // Phase-space correction non-unity if both parents massive.
58  // Note, so far only defined for 2-parton systems.
59  if (nMassive == 2 && iIn.size() == 2)
60  kallenFacSav = sAntSav/sqrt(pow2(sAntSav) - 4*pow2(mSav[0]*mSav[1]));
61  }
62  // Call method to initialise variables in derived classes.
63  init();
64 
65 }
66 
67 //--------------------------------------------------------------------------
68 
69 // Compute pT scale of trial branching.
70 double Brancher::getpTscale() {
71 
72  if (invariantsSav.size() == 3) {
73  double sIK = invariantsSav[0];
74  double y12 = invariantsSav[1] / sIK;
75  double y23 = invariantsSav[2] / sIK;
76  return sIK * y12 * y23;
77  } else return 0.;
78 
79 }
80 
81 //--------------------------------------------------------------------------
82 
83 // Return Xj.
84 double Brancher::getXj() {
85 
86  if (invariantsSav.size() == 3) {
87  double sIK = invariantsSav[0];
88  double y12 = invariantsSav[1] / sIK;
89  double y23 = invariantsSav[2] / sIK;
90  return y12 + y23;
91  } else return 1.0;
92 
93 }
94 
95 //--------------------------------------------------------------------------
96 
97 // Simple print utility, showing the contents of the Brancher.
98 
99 void Brancher::list(string header) const {
100 
101  // Check if we are asked to output a header.
102  if (header != "none")
103  cout << " -------- " << std::left << setw(30) << header
104  << " ----------------"
105  << "--------------------------------------------- \n"
106  << " sys type mothers colTypes ID codes "
107  << " hels m qNewSav \n"
108  << fixed << std::right << setprecision(3);
109  cout << setw(5) << system() << " ";
110  string type = "FF";
111  if (iSav.size() == 3) type = "FFF";
112  else if (iSav.size() >= 4) type="FS";
113  cout << setw(4) << type << " "
114  << setw(5) << i0() << " " << setw(5) << i1() << " "
115  << setw(5) << (i2() > 0 ? num2str(i2(), 5) : " ") << " "
116  << setw(3) << colType0() << " " << setw(3) << colType1() << " "
117  << setw(3) << (i2() > 0 ? num2str(colType2(), 3) : " ") << " "
118  << setw(9) << id0() << setw(9) << id1()
119  << setw(9) << (i2() > 0 ? num2str(id2(), 9) : " ") << " "
120  << setw(2) << h0() << " " << setw(2) << h1() << " "
121  << setw(2) << (i2() > 0 ? num2str(h2(), 2) : " ") << " "
122  << num2str(mAnt(), 10);
123  if (hasTrial()) {
124  if (q2NewSav > 0.) cout << " " << num2str(sqrt(q2NewSav), 10);
125  else cout << " " << num2str(0.0, 10);
126  }
127  else cout << " " << setw(10) << "-";
128  cout << endl;
129 
130 }
131 
132 //--------------------------------------------------------------------------
133 
134 // Set post-branching IDs and masses. Base class is for gluon emission.
135 
136 void Brancher::setidPost() {
137  idPostSav.clear();
138  idPostSav.push_back(id0());
139  idPostSav.push_back(21);
140  idPostSav.push_back(id1());
141 }
142 
143 vector<double> Brancher::setmPostVec() {
144  mPostSav.clear();
145  mPostSav.push_back(mSav[0]); // mi
146  mPostSav.push_back(0.0); // mj
147  mPostSav.push_back(mSav[1]); // mk
148  return mPostSav;
149 }
150 
151 void Brancher::setStatPost() {
152  statPostSav.resize(iSav.size() + 1, 51);}
153 
154 void Brancher::setMaps(int){
155  mothers2daughters.clear(); daughters2mothers.clear();}
156 
157 //--------------------------------------------------------------------------
158 
159 // Return index of new particle (slightly arbitrary choice for splittings).
160 
161 int Brancher::iNew(){
162 
163  if (i0() > 0) {
164  if(mothers2daughters.find(i0()) != mothers2daughters.end())
165  return mothers2daughters[i0()].second;
166  else return 0;
167  }
168  else return 0;
169 
170 }
171 
172 
173 //==========================================================================
174 
175 // Class BrancherEmitFF, branch elemental for 2->3 gluon emissions.
176 
177 //--------------------------------------------------------------------------
178 
179 // Method to initialise members specific to BrancherEmitFF.
180 
181 void BrancherEmitFF::init() {
182 
183  branchType = 1;
184  if (colType0() == 2 && colType1() == 2) iAntSav = iGGemitFF;
185  else if (colType1() == 2) iAntSav = iQGemitFF;
186  else if (colType0() == 2) iAntSav = iGQemitFF;
187  else iAntSav = iQQemitFF;
188 
189 }
190 
191 //--------------------------------------------------------------------------
192 
193 // Generate a new Q2 value, soft-eikonal 2/yij/yjk implementation.
194 
195 double BrancherEmitFF::genQ2(int evTypeIn, double q2BegIn, Rndm* rndmPtr,
196  const EvolutionWindow* evWindowIn, double colFacIn,
197  vector<double> headroomIn, vector<double> enhanceIn,
198  int) {
199 
200  // Initialise output value and save input parameters.
201  q2NewSav = 0.;
202  evTypeSav = evTypeIn;
203  evWindowSav = evWindowIn;
204  colFacSav = colFacIn;
205  q2BegSav = q2BegIn;
206  headroomSav = (headroomIn.size() >=1) ? headroomIn[0] : 1.0 ;
207  enhanceSav = (enhanceIn.size() >=1) ? enhanceIn[0] : 1.0 ;
208  // Set flag that this call will produce a saved trial.
209  hasTrialSav = true;
210  // Overall normalisation factor (independent of evType).
211  double normFac = colFacSav * kallenFac() * headroomSav * enhanceSav;
212  // pT evolution.
213  if (evTypeSav == 1) {
214  // Constant trial alphaS.
215  if (evWindowSav->runMode <= 0) {
216  double coeff = normFac * evWindowSav->alphaSmax / 4. / M_PI;
217  double lnR = log(rndmPtr->flat());
218  double xT1 = q2BegSav / sAnt();
219  double ln2xT2 = pow2(log(xT1)) - lnR / coeff;
220  double xT2 = exp(-sqrt(ln2xT2));
221  q2NewSav = xT2 * sAnt();
222 
223  // Running trial alphaS
224  } else {
225  double q2Min = pow2(evWindowSav->qMin);
226  double d = sqrt(1 - 4 * q2Min/sAnt());
227  double deltaY = log( (1.+d)/(1.-d) );
228  double coeff = normFac * deltaY / 2. / M_PI;
229  double b0 = evWindowSav->b0;
230  double powR = pow(rndmPtr->flat(),b0/coeff);
231  double facLam = evWindowSav->lambda2 / evWindowSav->kMu2;
232  q2NewSav = facLam * pow(q2BegSav/facLam,powR);
233  }
234  }
235  if (q2NewSav > q2BegIn) {
236  string errorMsg = "Error in "+__METHOD_NAME__
237  +": Generated q2New > q2BegIn."+" Returning 0.";
238  cout<<errorMsg<<endl;
239  q2NewSav = 0.;
240  }
241  return q2NewSav;
242 
243 }
244 
245 //--------------------------------------------------------------------------
246 
247 // Generate invariants.
248 
249 bool BrancherEmitFF::genInvariants(vector<double>& invariants,
250  Rndm* rndmPtr, int){
251 
252  // Clear output vector, check if we have a sensible q2New scale.
253  invariants.clear();
254  if (q2NewSav <= 0.) return false;
255 
256  // pT evolution.
257  if (evTypeSav == 1) {
258  double xT = q2NewSav / sAnt();
259  if (xT > 0.25) return false;
260  // Rapidity boundaries for constant trial alphaS.
261  double yMinTrial, yMaxTrial;
262  if (evWindowSav->runMode <= 0) {
263  yMinTrial = log(xT)/2.;
264  yMaxTrial = -yMinTrial;
265 
266  // Rapidity boundaries for running trial alphaS
267  } else {
268  double q2MinNow = pow2(evWindowSav->qMin);
269  double xTMinNow = q2MinNow/sAnt();
270  double dTrial = sqrt(1. - 4*xTMinNow);
271  yMaxTrial = 0.5 * log( (1.+dTrial)/(1.-dTrial ) );
272  yMinTrial = -yMaxTrial;
273  }
274  double yTrial = yMinTrial + rndmPtr->flat()*(yMaxTrial - yMinTrial);
275  double dPhys = sqrt(1. - 4*xT);
276  double yMaxPhys = 0.5 * log((1. + dPhys)/(1. - dPhys));
277  double yMinPhys = -yMaxPhys;
278  if (yTrial < yMinPhys || yTrial > yMaxPhys) return false;
279  double r = exp(yTrial);
280  double rootXT = sqrt(xT);
281  double yij = rootXT / r;
282  double yjk = rootXT * r;
283  double yik = 1.0 - yij - yjk;
284  if (yij < 0. || yjk < 0. || yik < 0.) {
285  cout << " Problem in genInvariants yij = " << yij << " yjk = "
286  << yjk << endl;
287  return false;
288  }
289  double sij = sAnt() * yij;
290  double sjk = sAnt() * yjk;
291  double sik = sAnt() * yik;
292 
293  // Element 0 is the antenna sAnt.
294  invariants.push_back(sAnt());
295  invariants.push_back(sij);
296  invariants.push_back(sjk);
297  invariants.push_back(sik);
298 
299  // Save the generated invariants (for future query and use by pAccept).
300  invariantsSav = invariants;
301  setmPostVec();
302 
303  // Veto if the point outside the available phase space.
304  double det = gramDet(sij,sjk,sik,mPostSav[0],mPostSav[1],mPostSav[2]);
305  if (det > 0.) return true;
306  else return false;
307  }
308  else return false;
309 
310 }
311 
312 //--------------------------------------------------------------------------
313 
314 // Compute antPhys / antTrial for gluon emissions, given antPhys.
315 
316 double BrancherEmitFF::pAccept(const double antPhys, int) {
317 
318  // Evaluate trial function taking headroom factor into account.
319  if (invariantsSav.size() <= 2) return 0.;
320  double antTrial = headroomSav
321  *2.*invariantsSav[0]/invariantsSav[1]/invariantsSav[2];
322  // pT evolution.
323  if (evTypeSav == 1) {
324  // Constant trial alphaS.
325  if (evWindowSav->runMode <= 0)
326  antTrial *= colFacSav * evWindowSav->alphaSmax;
327  // Running trial alphaS: pars = colFac, b0, facLam = Lambda^2/kMuR^2.
328  else {
329  double b0 = evWindowSav->b0;
330  double facLam = evWindowSav->lambda2/evWindowSav->kMu2;
331  double lnx = log(q2NewSav/facLam);
332  double alphaTrial = 1./b0/lnx;
333  antTrial *= colFacSav * alphaTrial;
334  }
335  }
336  return antPhys/antTrial;
337 
338 }
339 
340 //--------------------------------------------------------------------------
341 
342 // Return the maximum Q2.
343 
344 double BrancherEmitFF::getQ2Max(int evType) {
345 
346  if (evType == 1) return sAntSav/4.;
347  else if (evType == 2) return sAntSav/9.;
348  else if (evType == 3) return sAntSav/2.;
349  else return 0.;
350 
351 }
352 
353 //--------------------------------------------------------------------------
354 
355 // Method to make mothers2daughters and daughters2mothers pairs.
356 
357 void BrancherEmitFF::setMaps(int sizeOld) {
358 
359  mothers2daughters.clear();
360  daughters2mothers.clear();
361 
362  //For updating the children of existing parents.
363  mothers2daughters[i0()] = make_pair(sizeOld, sizeOld + 1);
364  mothers2daughters[i1()] = make_pair(sizeOld + 1, sizeOld + 2);
365 
366  //For adding mothers of new children.
367  daughters2mothers[sizeOld] = make_pair(i0(), 0);
368  daughters2mothers[sizeOld+1] = make_pair(i0(), i1());
369  daughters2mothers[sizeOld+2] = make_pair(i1(), 0);
370 
371 }
372 
373 //--------------------------------------------------------------------------
374 
375 // Generic getter method. Assumes setter methods called earlier.
376 
377 bool BrancherEmitFF::getNewParticles(Event& event, vector<Vec4> momIn,
378  vector<int> hIn, vector<Particle> &pNew, Rndm* rndmPtr, Colour* colourPtr) {
379 
380  // Initialize.
381  unsigned int nPost = iSav.size() + 1;
382  pNew.clear();
383  pNew.resize(nPost);
384  setidPost();
385  setStatPost();
386  double scaleNew = sqrt(q2NewSav);
387  setMaps(event.size());
388 
389  // Check everything set.
390  if (momIn.size() != nPost || hIn.size() != nPost ||
391  mPostSav.size() != nPost || idPostSav.size() != nPost ||
392  statPostSav.size() != nPost || invariantsSav.size() < 3) return false;
393 
394  // Who inherits the colour?
395  double sij = invariantsSav[1];
396  double sjk = invariantsSav[2];
397  bool inh01 = colourPtr->inherit01(sij,sjk);
398  int lastTag = event.lastColTag();
399  vector<int> col(nPost, 0);
400  vector<int> acol(nPost, 0);
401  acol[0] = event[i0()].acol();
402  col[0] = event[i0()].col();
403  acol[2] = event[i1()].acol();
404  col[2] = event[i1()].col();
405 
406  // Generate a new colour tag.
407  int colNew = lastTag + 1 + rndmPtr->flat()*10;
408  // 0 keeps colour.
409  if (inh01) {
410  while (colNew%10 == col[2]%10 || colNew%10 == 0)
411  colNew = lastTag + 1 + rndmPtr->flat()*10;
412  acol[1]=col[0];
413  col[1]=colNew;
414  acol[2]=colNew;
415  // 2 keeps colour.
416  } else {
417  while (colNew%10 == acol[0]%10 || colNew%10 == 0)
418  colNew = lastTag + 1 + rndmPtr->flat()*10;
419  col[0]=colNew;
420  acol[1]=colNew;
421  col[1]=acol[2];
422  }
423 
424  // Now populate particle vector.
425  for (unsigned int ipart = 0; ipart < nPost; ++ipart) {
426  pNew[ipart].status(statPostSav[ipart]);
427  pNew[ipart].id(idPostSav[ipart]);
428  pNew[ipart].pol(hIn[ipart]);
429  pNew[ipart].p(momIn[ipart]);
430  pNew[ipart].m(mPostSav[ipart]);
431  pNew[ipart].setEvtPtr(&event);
432  pNew[ipart].scale(scaleNew);
433  pNew[ipart].daughters(0,0);
434  pNew[ipart].col(col[ipart]);
435  pNew[ipart].acol(acol[ipart]);
436  }
437  colTagSav = colNew;
438  return true;
439 
440 }
441 
442 //==========================================================================
443 
444 // Class BrancherSplitFF, branch elemental for 2->3 gluon splittings.
445 
446 //--------------------------------------------------------------------------
447 
448 // Method to initialise data members specific to BrancherSplitFF.
449 
450 void BrancherSplitFF::init() {
451  branchType = 2; iAntSav = iGXsplitFF; swapped = false;}
452 
453 //--------------------------------------------------------------------------
454 
455 // Generate a new Q2 value .
456 
457 double BrancherSplitFF::genQ2(int evTypeIn, double q2BegIn,
458  Rndm* rndmPtr, const EvolutionWindow* evWindowIn,
459  double, vector<double> headroomFlav,
460  vector<double> enhanceFlav, int verboseIn) {
461 
462  // Initialise output value and save input parameters.
463  q2NewSav = 0.;
464  evTypeSav = evTypeIn;
465  q2BegSav = q2BegIn;
466  evWindowSav = evWindowIn;
467 
468  // Total splitting weight summed over flavours
469  double wtSum = 0.0;
470  vector<double> wtFlav;
471  unsigned int nFlav = headroomFlav.size();
472  if (nFlav != enhanceFlav.size()) {
473  if (verboseIn >=normal) {
474  string errorMsg = "Error in "+__METHOD_NAME__
475  +": inconsistent size of headroom and enhancement vectors.";
476  cout<<errorMsg<<endl;
477  }
478  return 0.;
479  }
480 
481  // First check if there is any phase space open for this flavour
482  for (unsigned int iFlav = 0; iFlav < nFlav; ++iFlav) {
483  double mFlav = evWindowSav->mass.at(iFlav+1);
484  if (mAnt() - m0() - m1() < 2.*mFlav) {
485  wtFlav.push_back(0.); continue;
486  } else {
487  double wt = headroomFlav[iFlav] * enhanceFlav[iFlav];
488  wtFlav.push_back(wt);
489  wtSum += wt;
490  }
491  }
492 
493  // Set flag that this call will produce a saved trial.
494  hasTrialSav = true;
495  // Overall normalisation factor common to all trial integrals.
496  double normFac = kallenFac() * wtSum;
497  // pT evolution.
498  if (evTypeSav == 1) {
499  double deltaZeta = 1.0;
500  double coeff = normFac * deltaZeta / 8. / M_PI;
501  double xT1 = q2BegSav / sAnt();
502  // Constant trial alphaS.
503  if (evWindowSav->runMode <= 0) {
504  double aStrial = evWindowSav->alphaSmax;
505  double xT2 = xT1 * pow(rndmPtr->flat(), 1./aStrial/coeff);
506  q2NewSav = xT2 * sAnt();
507 
508  // Running trial alphaS.
509  } else {
510  double b0 = evWindowSav->b0;
511  double facLam = evWindowSav->lambda2/evWindowSav->kMu2;
512  double powR = pow(rndmPtr->flat(),b0/coeff);
513  q2NewSav = facLam * pow(q2BegSav/facLam,powR);
514  }
515  }
516 
517  // Select flavour.
518  double ranFlav = rndmPtr->flat() * wtSum;
519  for (int iFlav = nFlav - 1; iFlav >= 0; --iFlav) {
520  ranFlav -= wtFlav[iFlav];
521  if (ranFlav < 0) {
522  idFlavSav = iFlav+1;
523  // Set quark masses.
524  mFlavSav = evWindowSav->mass.at(idFlavSav);
525  // Save corresponding headroom and enhancement factors.
526  enhanceSav = enhanceFlav[iFlav];
527  headroomSav = headroomFlav[iFlav];
528  break;
529  }
530  }
531  if (q2NewSav > q2BegIn) {
532  string errorMsg = "Error in "+__METHOD_NAME__
533  +": Generated q2New > q2Beg."+" Returning 0.";
534  cout<<errorMsg<<endl;
535  q2NewSav = 0.;
536  }
537  return q2NewSav;
538 
539 }
540 
541 //--------------------------------------------------------------------------
542 
543 // Generate complementary invariant(s) for saved trial scale
544 // for gluon splitting. Return false if no physical kinematics possible.
545 
546 bool BrancherSplitFF::genInvariants(vector<double>& invariants,
547  Rndm* rndmPtr, int) {
548 
549  // Clear output vector, and check if we have a sensible q2New scale.
550  invariants.clear();
551  if (q2NewSav <= 0.) return false;
552 
553  // pT evolution.
554  double m2j = pow2(mFlavSav);
555  if (evTypeSav == 1) {
556  // Zeta is uniform in [0,1].
557  double zetaTrial = rndmPtr->flat();
558  double m2qq = q2NewSav / zetaTrial;
559  double sij = m2qq - 2*m2j;
560  if (sij < 0.) return false;
561 
562  // Here i=q, j=qbar is always the case, but change def for sjk,
563  // sik depending on who is colour connected to the recoiler. G
564  // anticolour side (XG antenna): pT = pT(qbar) = pTj; zeta = yjk +
565  // mu2q.
566  double sjk, sik;
567  if (isXGsav) {
568  sjk = sAnt()*zetaTrial - m2j;
569  sik = sAnt() - m2qq - sjk;
570 
571  // G colour side (GX antenna): pT = pT(q) = pTi; zeta = yik + mu2q.
572  } else {
573  sik = sAnt()*zetaTrial - m2j;
574  sjk = sAnt() - m2qq - sik;
575  }
576  if (sjk < 0.) return false;
577 
578  // Element 0 is the antenna sAnt.
579  invariants.push_back(sAnt());
580  invariants.push_back(sij);
581  invariants.push_back(sjk);
582  invariants.push_back(sik);
583 
584  // Save the generated invariants (for future query and use by pAccept).
585  invariantsSav = invariants;
586  setmPostVec();
587 
588  // Veto if point outside the available phase space.
589  double det = gramDet(sij,sjk,sik,mPostSav[0],mPostSav[1],mPostSav[2]);
590  if (det > 0.) return true;
591  else return false;
592  }
593  else return false;
594 
595 }
596 
597 //--------------------------------------------------------------------------
598 
599 // Compute antPhys/antTrial for gluon splittings, given antPhys.
600 // Note, antPhys should be normalised to include charge and coupling
601 // factors.
602 
603 double BrancherSplitFF::pAccept(const double antPhys, int) {
604 
605  // Evaluate trial function with headroom factor.
606  if (invariantsSav.size() <= 2) return 0.;
607  double antTrial = headroomSav/(2.*(invariantsSav[1] + 2*pow2(mFlavSav)));
608 
609  // pT evolution (note evType =1 for pTj, evType -1 for pTi).
610  if (evTypeSav == 1) {
611  double alphaTrial = evWindowSav->alphaSmax;
612  if (evWindowSav->runMode >= 1) {
613  double b0 = evWindowSav->b0;
614  double facLam = evWindowSav->lambda2/evWindowSav->kMu2;
615  double lnx = log(q2NewSav/facLam);
616  alphaTrial = 1./b0/lnx;
617  }
618  antTrial *= alphaTrial;
619  }
620  return antPhys/antTrial;
621 
622 }
623 
624 //--------------------------------------------------------------------------
625 
626 // Getter and setter methods.
627 
628 double BrancherSplitFF::getQ2Max(int evType) {
629 
630  if (evType == 1) return sAntSav/4.;
631  else if (evType == 2) return sAntSav;
632  else if (evType == 3) return sAntSav;
633  else return 0.;
634 
635 }
636 
637 vector<double> BrancherSplitFF::setmPostVec() {
638 
639  mPostSav.clear();
640  mPostSav.push_back(mFlavSav); // mi
641  mPostSav.push_back(mFlavSav); // mj
642  mPostSav.push_back(mSav[1]); // mk
643  return mPostSav;
644 
645 }
646 
647 void BrancherSplitFF::setidPost() {
648 
649  idPostSav.clear();
650  idPostSav.push_back(idFlavSav);
651  idPostSav.push_back(-idFlavSav);
652  idPostSav.push_back(id1());
653 
654 }
655 
656 void BrancherSplitFF::setStatPost() {
657 
658  statPostSav.resize(iSav.size() + 1, 51);
659  statPostSav[2] = 52;
660 
661 }
662 
663 void BrancherSplitFF::setMaps(int sizeOld) {
664 
665  // For updating the children of existing parents.
666  mothers2daughters.clear();
667  daughters2mothers.clear();
668  mothers2daughters[i0()] = make_pair(sizeOld, sizeOld+1);
669  mothers2daughters[i1()] = make_pair(sizeOld+2,sizeOld+2);
670 
671  // For adding mothers of new children.
672  daughters2mothers[sizeOld] = make_pair(i0(),0);
673  daughters2mothers[sizeOld+1] = make_pair(i0(),0);
674  daughters2mothers[sizeOld+2] = make_pair(i1(),i1());
675 
676 }
677 
678 //--------------------------------------------------------------------------
679 
680 // Generic getter method. Assumes setter methods called earlier.
681 
682 bool BrancherSplitFF::getNewParticles(Event& event, vector<Vec4> momIn,
683  vector<int> hIn, vector<Particle> &pNew, Rndm*, Colour*) {
684 
685  // Initialize.
686  unsigned int nPost = iSav.size() + 1;
687  pNew.clear();
688  pNew.resize(nPost);
689  setidPost();
690  setStatPost();
691  double scaleNew = sqrt(q2NewSav);
692  setMaps(event.size());
693 
694  // Check everything set.
695  if (momIn.size()!=nPost || hIn.size()!=nPost ||
696  mPostSav.size() !=nPost || idPostSav.size() != nPost ||
697  statPostSav.size() != nPost || invariantsSav.size() < 3) return false;
698  vector<int> col(nPost,0);
699  vector<int> acol(nPost,0);
700  acol[0] = 0;
701  col[0] = event[i0()].col();
702  acol[1] = event[i0()].acol();
703  col[1] = 0;
704  acol[2] = event[i1()].acol();
705  col[2] = event[i1()].col();
706 
707  // Now populate particle vector.
708  for (unsigned int ipart = 0; ipart < nPost; ++ipart) {
709  pNew[ipart].status(statPostSav[ipart]);
710  pNew[ipart].id(idPostSav[ipart]);
711  pNew[ipart].pol(hIn[ipart]);
712  pNew[ipart].p(momIn[ipart]);
713  pNew[ipart].m(mPostSav[ipart]);
714  pNew[ipart].setEvtPtr(&event);
715  pNew[ipart].scale(scaleNew);
716  pNew[ipart].daughters(0,0);
717  pNew[ipart].col(col[ipart]);
718  pNew[ipart].acol(acol[ipart]);
719  }
720  colTagSav = 0;
721  return true;
722 
723 }
724 
725 //==========================================================================
726 
727 // BrancherEmitRF class for storing information on antennae between a
728 // coloured resonance and final state parton, and generating a new
729 // emission.
730 
731 //--------------------------------------------------------------------------
732 
733 // Method to initialise data members specific to BrancherEmitRF.
734 
735 void BrancherEmitRF::init(Event& event, vector<int> allIn,
736  unsigned int posResIn, unsigned int posFIn, double Q2cut) {
737 
738  // Get Pythia indices of res and final.
739  posRes = posResIn;
740  posFinal = posFIn;
741  int iRes = allIn.at(posRes);
742  int iFinal = allIn.at(posFinal);
743  colFlowRtoF = event[iRes].col() == event[iFinal].col() && event[iRes].col()
744  != 0;
745 
746  // Extract the momenta of the rest.
747  Vec4 recoilVec(0., 0., 0., 0.);
748  for (vector<int>::iterator pos = allIn.begin(); pos != allIn.end(); ++pos) {
749  if ((*pos == iRes) || (*pos == iFinal)) continue;
750  recoilVec += event[*pos].p();
751  }
752 
753  // This is not necesssarily p(res). In the case where one particle
754  // always recieves the recoil e.g. W in t->bWX it is p_t -p_X.
755  Vec4 resVec = recoilVec + event[iFinal].p();
756 
757  //Calculate the masses.
758  mRes = resVec.mCalc();
759  mFinal = event[iFinal].mCalc();
760  mRecoilers = recoilVec.mCalc();
761  sAK = getsAK(mRes, mFinal, mRecoilers);
762 
763  // Calculate common prefactor to trial integral.
764  kallenFacSav = (2.0*sAK/(4.0*M_PI));
765  kallenFacSav /= sqrt(KallenFunction(mRes*mRes, mFinal*mFinal,
766  mRecoilers*mRecoilers));
767 
768  // Calculate zeta limits.
769  zetaMin= zetaMinCalc(mRes, mFinal, mRecoilers, Q2cut);
770  zetaMax = zetaMaxCalc(mRes, mFinal, mRecoilers);
771  // Phase space is closed.
772  if (zetaMax < zetaMin) zetaIntSave = 0.;
773  // Calculate zeta integral (full phase space).
774  else zetaIntSave = zetaIntegral(zetaMin, zetaMax);
775 
776  // Calculate Q2max.
777  Q2MaxSav = calcQ2Max(mRes, mRecoilers, mFinal);
778  branchType = 5;
779  // TODO: swapped should be redundant since save posRes, posFinal.
780  // R = Q.
781  if (abs(colTypeSav[posRes]) == 1) {
782  // F = Q.
783  if (abs(colTypeSav[posFinal]) == 1) {
784  iAntSav = iQQemitRF;
785  swapped = false;
786  // F = g.
787  } else if (colTypeSav[posFinal] == 2) {
788  iAntSav = iQGemitRF;
789  swapped = posRes != 0;
790  // Some other final state - don't know what to do with this yet!
791  } else {
792  iAntSav = -1;
793  swapped = false;
794  }
795  // Some other resonance. Don't know what to do with this yet!
796  } else {
797  iAntSav = -1;
798  swapped = false;
799  }
800 
801 }
802 
803 //--------------------------------------------------------------------------
804 
805 // Setter methods.
806 
807 vector<double> BrancherEmitRF::setmPostVec() {
808  mPostSav.clear();
809  mPostSav.push_back(mRes); // ma
810  mPostSav.push_back(0.0); // mj
811  mPostSav.push_back(mFinal); // mk
812  mPostSav.push_back(mRecoilers); // mAK
813  return mPostSav;
814 }
815 
816 void BrancherEmitRF::setidPost() {
817  idPostSav.clear();
818  idPostSav = idSav;
819  // Insert gluon in second position.
820  idPostSav.insert(idPostSav.begin() + 1, 21);
821 }
822 
823 void BrancherEmitRF::setStatPost() {
824  statPostSav.resize(iSav.size() + 1, 52);
825  statPostSav[posFinal] = 51;
826  statPostSav[posFinal+1] = 51;
827 }
828 
829 int BrancherEmitRF::iNew() {
830  if (posFinal > 0 && iSav[posFinal] > 0
831  && mothers2daughters.find(iSav[posFinal]) != mothers2daughters.end())
832  return mothers2daughters[iSav[posFinal]].second;
833  return 0;
834 }
835 
836 void BrancherEmitRF::setMaps(int sizeOld) {
837  mothers2daughters.clear();
838  daughters2mothers.clear();
839  posNewtoOld.clear();
840 
841  // For updating the children of existing parents. Save children of
842  // F (treat like 1->2 splitting).
843  mothers2daughters[iSav[posFinal]] = make_pair(sizeOld, sizeOld + 1);
844  daughters2mothers[sizeOld] = make_pair(iSav[posFinal], 0);
845  daughters2mothers[sizeOld+1] = make_pair(iSav[posFinal], 0);
846 
847  //Save recoilers and insert the new emission at position 1.
848  int iInsert = sizeOld + 2;
849  unsigned int posNewEmit = 1;
850  for (unsigned int pos = 0; pos < iSav.size(); pos++) {
851  if (pos >= posNewEmit) posNewtoOld[pos + 1] = pos;
852  else posNewtoOld[pos] = pos;
853  if (pos == posRes || pos == posFinal) continue;
854  else {
855  mothers2daughters[iSav[pos]] = make_pair(iInsert, iInsert);
856  daughters2mothers[iInsert] = make_pair(iSav[pos], iSav[pos]);
857  iInsert++;
858  }
859  }
860 }
861 
862 //--------------------------------------------------------------------------
863 
864 // Generic method, assumes setter methods called earlier.
865 
866 bool BrancherEmitRF::getNewParticles(Event& event, vector<Vec4> momIn,
867  vector<int> hIn, vector<Particle> &pNew, Rndm* rndmPtr, Colour*) {
868 
869  // Initialize.
870  unsigned int nPost = iSav.size() + 1;
871  pNew.clear();
872  setidPost();
873  setStatPost();
874  double scaleNew = sqrt(q2NewSav);
875  setMaps(event.size());
876 
877  // Check everything set.
878  if(momIn.size() != nPost || hIn.size() != nPost ||
879  idPostSav.size() != nPost || statPostSav.size() != nPost) return false;
880 
881  // Generate new colour tag.
882  int lastTag = event.lastColTag();
883  int resTag = 0;
884  int newTag = 0;
885  if (colFlowRtoF) resTag = event[iSav[posRes]].col();
886  else resTag = event[iSav[posRes]].acol();
887  // New tag can't be same colour as neighbour.
888  while (newTag%10 == resTag%10 || newTag%10 == 0)
889  newTag = lastTag + 1 + rndmPtr->flat()*10;
890 
891  // Now populate particle vector.
892  for (unsigned int ipart = 0; ipart < nPost; ++ipart) {
893  Particle newPart;
894  // Set mass and colours (we have repurposed mPost for antenna
895  // function mass scales). This is new emission.
896  if (posNewtoOld.find(ipart) == posNewtoOld.end()) {
897  newPart.m(0.0);
898  if (colFlowRtoF) newPart.cols(resTag, newTag);
899  else newPart.cols(newTag, resTag);
900  // Skip the resonance.
901  } else if (posNewtoOld[ipart] == posRes) continue;
902  else {
903  newPart.m(mSav[posNewtoOld[ipart]]);
904  int colNow = event[iSav[posNewtoOld[ipart]]].col();
905  int acolNow = event[iSav[posNewtoOld[ipart]]].acol();
906  if (posNewtoOld[ipart] == posFinal) {
907  if (colFlowRtoF) colNow = newTag;
908  else acolNow = newTag;
909  }
910  newPart.cols(colNow,acolNow);
911  }
912 
913  // Set other pre-determined particle properties.
914  newPart.status(statPostSav[ipart]);
915  newPart.id(idPostSav[ipart]);
916  newPart.pol(hIn[ipart]);
917  newPart.p(momIn[ipart]);
918  newPart.setEvtPtr(&event);
919  newPart.scale(scaleNew);
920  newPart.daughters(0,0);
921  if (abs(newPart.m() - newPart.mCalc()) > 0.001) return false;
922  pNew.push_back(newPart);
923  }
924  colTagSav=newTag;
925  return true;
926 
927 }
928 
929 //--------------------------------------------------------------------------
930 
931 // Generate a new Q2 scale.
932 
933 double BrancherEmitRF::genQ2(int evTypeIn, double Q2MaxNow, Rndm* rndmPtr,
934  const EvolutionWindow* evWindowPtrIn, double colFac,
935  vector<double> headroomIn, vector<double> enhanceIn,
936  int verboseIn) {
937 
938  // Save headroom and enhancement factors.
939  headroomSav = (headroomIn.size() >= 1) ? headroomIn[0] : 1.0;
940  enhanceSav = (enhanceIn.size() >= 1) ? enhanceIn[0] : 1.0;
941  if (zetaIntSave <= 0.) {
942  hasTrialSav = true;
943  q2NewSav = 0.;
944  return q2NewSav;
945  }
946 
947  // pT evolution.
948  if (evTypeIn == 1) {
949 
950  // Get multiplicative factors.
951  double prefactor = kallenFacSav;
952  prefactor *= colFac;
953  prefactor *= headroomSav * enhanceSav;
954 
955  // Save info for later (to be used in pAccept).
956  evTypeSav = evTypeIn;
957  q2BegSav = Q2MaxNow;
958  evWindowSav = evWindowPtrIn;
959  colFacSav = colFac;
960 
961  // Fixed alphaS.
962  double logR = log(rndmPtr->flat());
963  if (evWindowPtrIn->runMode <= 0){
964  // Use max possible value for alphaS.
965  prefactor *= evWindowPtrIn->alphaSmax;
966  // Inverse of Q2 integral for fixed alphaS.
967  q2NewSav = Q2MaxNow*exp(logR/(prefactor*zetaIntSave));
968  // Running alphaS.
969  } else{
970  prefactor /= evWindowPtrIn->b0;
971  double muRScaleMod = evWindowPtrIn->kMu2/evWindowPtrIn->lambda2;
972  double logQ2Ratio = exp(logR/(prefactor*zetaIntSave));
973  double logQ2maxFactor = log(Q2MaxNow*muRScaleMod);
974  q2NewSav = exp(logQ2maxFactor*logQ2Ratio)/muRScaleMod;
975  }
976  if (q2NewSav > Q2MaxNow) {
977  if (verboseIn >= superdebug)
978  cout << "evolution mode = " << evWindowPtrIn->runMode << endl
979  << "prefactor = " << prefactor << " zetaIntSave = " << zetaIntSave
980  << " logR = " << logR << endl
981  << " kmu2 = " << evWindowPtrIn->kMu2
982  << " lambda2 = " << evWindowPtrIn->lambda2 << endl;
983  string errorMsg = "Error in "+__METHOD_NAME__
984  +": Generated q2New > q2Max"+" Returning -1.";
985  cout<<errorMsg<<endl;
986  q2NewSav = -1.;
987  }
988  } else {
989  if (verboseIn >= normal) {
990  stringstream ss;
991  ss << "evTypeIn = " << evTypeIn;
992  string errorMsg = "Error in "+__METHOD_NAME__
993  +": Unsupported Evolution Type."+" "+ss.str();
994  cout<<errorMsg<<endl;
995  }
996  return 0.;
997  }
998 
999  // Set flag that this call produces a saved trial.
1000  hasTrialSav = true;
1001  return q2NewSav;
1002 
1003 }
1004 
1005 //--------------------------------------------------------------------------
1006 
1007 // Generate complementary invariant(s) for saved trial scale. Return
1008 // false if no physical kinematics possible.
1009 
1010 bool BrancherEmitRF::genInvariants(vector<double>& invariants,Rndm* rndmPtr,
1011  int verboseIn) {
1012 
1013  // Initialise and check we have a generated q2.
1014  invariants.clear();
1015  invariantsSav.clear();
1016  setmPostVec();
1017  if (q2NewSav <= 0.) return false;
1018 
1019  // Calculate invariants from zeta, q2.
1020  double zetaNext = getZetaNext(rndmPtr);
1021  double sjk = sAK*(zetaNext - 1.0);
1022  double saj = q2NewSav*(1.0 + sAK/sjk);
1023  double sak = sAK + sjk - saj;
1024  if (verboseIn >= louddebug) {
1025  stringstream ss;
1026  ss << "Phase space point: Q2next = " << q2NewSav << " zeta = " << zetaNext;
1027  printOut(__METHOD_NAME__, ss.str());
1028  ss.str("Scaled invariants: yaj = ");
1029  ss << saj/(sjk+sAK) << " yjk = " << sjk/(sjk+sAK);
1030  printOut(__METHOD_NAME__, ss.str());
1031  }
1032 
1033  //Save regardless.
1034  invariantsSav.push_back(sAK);
1035  invariantsSav.push_back(saj);
1036  invariantsSav.push_back(sjk);
1037  invariantsSav.push_back(sak);
1038 
1039  // Veto if the point is outside the available phase space.
1040  if (vetoPhSpPoint(saj, sjk, sak, verboseIn)) return false;
1041  else {invariants = invariantsSav; return true;}
1042 
1043 }
1044 
1045 //--------------------------------------------------------------------------
1046 
1047 // Compute antPhys/antTrial, given antPhys.
1048 
1049 double BrancherEmitRF::pAccept(const double antPhys, int verboseIn) {
1050 
1051  // Check q2.
1052  if (q2NewSav <= 0.) {
1053  if (verboseIn >= normal) {
1054  string errorMsg = "Error in "+__METHOD_NAME__+": q2NewSav not set."+
1055  " Returning 0.";
1056  cout<<errorMsg<<endl;
1057  }
1058  return 0.;
1059  }
1060 
1061  // Reduced trial antenna.
1062  double antTrial = 2.0/q2NewSav;
1063 
1064  // Multiply by headroom factor.
1065  antTrial *= headroomSav;
1066 
1067  // Multiply by col factor.
1068  antTrial *= colFacSav;
1069 
1070  //Multiply by alphaS, default is fixed alphaS.
1071  double alphaSTrial = evWindowSav->alphaSmax;
1072  if (evWindowSav->runMode >= 1) {
1073  double mu2 = q2NewSav;
1074  mu2 *= (evWindowSav->kMu2/evWindowSav->lambda2);
1075  alphaSTrial = 1.0/log(mu2)/evWindowSav->b0;
1076  }
1077  antTrial *= alphaSTrial;
1078  return antPhys/antTrial;
1079 
1080 }
1081 
1082 //--------------------------------------------------------------------------
1083 
1084 // Protected helper methods for internal class use.
1085 
1086 double BrancherEmitRF::KallenFunction(double x, double y, double z) {
1087  return x*x + y*y + z*z - 2.*(x*y + x*z + y*z);}
1088 
1089 double BrancherEmitRF::zetaIntSingleLim(double zetaLim) {
1090  double x = zetaLim-1; return x + log(x);}
1091 
1092 double BrancherEmitRF::zetaIntegral(double zLow, double zHigh) {
1093  return zetaIntSingleLim(zHigh) - zetaIntSingleLim(zLow);}
1094 
1095 double BrancherEmitRF::getsAK(double mA, double mK, double mAK) {
1096  return mA*mA +mK*mK - mAK*mAK;}
1097 
1098 double BrancherEmitRF::zetaMinCalc(double mA, double mK, double mAK,
1099  double Q2cut) {
1100  return 1.0/(1.0 - Q2cut/(mA*mA -(mAK + mK)*(mAK + mK)));}
1101 
1102 double BrancherEmitRF::zetaMaxCalc(double mA, double mK, double mAK) {
1103  return 1.0 + ((mA-mAK)*(mA-mAK) - mK*mK)/getsAK(mA, mK, mAK);}
1104 
1105 double BrancherEmitRF::getZetaNext(Rndm* rndmPtr) {
1106  // Returns the solution for zeta to R =
1107  // I(zeta,zetamin)/I(zetamax,zetamin).
1108  double R = rndmPtr->flat();
1109  // I(zetamax,zetamin).
1110  double intZrange = zetaIntegral(zetaMin, zetaMax);
1111  double intZMin = zetaIntSingleLim(zetaMin);
1112  // exp(I(zeta)).
1113  double expIntZeta = exp(intZrange*R + intZMin);
1114  double lambWFact = LambertW(expIntZeta);
1115  // Now invert to get zeta.
1116  return 1. + lambWFact;
1117 }
1118 
1119 double BrancherEmitRF::calcQ2Max(double mA, double mAK, double mK){
1120  double aM2 = (mA-mAK)*(mA-mAK) - mK*mK;
1121  double bM2 = mAK*(mA-mAK) + mK*mK;
1122  double cM = mA-mAK;
1123  return aM2*aM2*mA/(2.0*cM*bM2);
1124 }
1125 
1126 //--------------------------------------------------------------------------
1127 
1128 // Veto point if outside available phase space.
1129 
1130 bool BrancherEmitRF::vetoPhSpPoint(double saj, double sjk, double sak,
1131  int verboseIn) {
1132 
1133  // Make copies of masses (just for compactness of notation).
1134  double mAK = mRecoilers;
1135  double ma = mPostSav[0];
1136  double mj = mPostSav[1];
1137  double mk = mPostSav[2];
1138 
1139  // Common sense: saj, sjk > 0. Not an error for splitters - mass
1140  // effects can make negative and push outside generated phase space.
1141  if (saj<0. || sjk<0.) {
1142  if (verboseIn >= louddebug) {
1143  stringstream ss;
1144  ss << "Negative invariants. saj = " << saj << " sjk = " << sjk;
1145  printOut(__METHOD_NAME__, ss.str());
1146  }
1147  return true;
1148  }
1149 
1150  // On-shell X condition.
1151  double invDiff = ma*ma + mj*mj + mk*mk - saj - sak + sjk - mAK*mAK;
1152  if (invDiff > 0.001) {
1153  if (verboseIn >= louddebug)
1154  printOut(__METHOD_NAME__, "Failed on-shell AK condition.");
1155  return true;
1156  }
1157 
1158  // On-shell j,k conditions.
1159  double Ek = sak/(2.0*ma);
1160  if (Ek*Ek < mk*mk) {
1161  if (verboseIn >= louddebug)
1162  printOut(__METHOD_NAME__, "Failed on-shell k condition.");
1163  return true;
1164  }
1165  double Ej = saj/(2.0*ma);
1166  if(Ej*Ej < mj*mj) {
1167  if (verboseIn >= louddebug)
1168  printOut(__METHOD_NAME__, "Failed on-shell j condition.");
1169  return true;
1170  }
1171 
1172  // When |cosTheta| < 1.
1173  double cosTheta = getCosTheta(Ej,Ek,mj,mk,sjk);
1174  if (abs(cosTheta) > 1.0) {
1175  if (verboseIn >= louddebug)
1176  printOut(__METHOD_NAME__, "Failed cos theta condition.");
1177  return true;
1178  }
1179 
1180  // This condition may be sufficient to remove above conditions.
1181  double det = saj*sjk*sak - saj*saj*mk*mk - sjk*sjk*ma*ma - sak*sak*mj*mj
1182  + 4.0*ma*ma*mj*mj*mk*mk;
1183  if (det <= 0.) {
1184  if (verboseIn >= louddebug)
1185  printOut(__METHOD_NAME__, "Gram det < 0 : Outside phase space");
1186  }
1187  return false;
1188 
1189 }
1190 
1191 //--------------------------------------------------------------------------
1192 
1193 // Calculate maximum gluon energy in the centre of mass frame of res
1194 // given cos theta.
1195 
1196 double BrancherEmitRF::getEjMax(double cosTheta, double mA, double mAK,
1197  double mK) {
1198 
1199  double cos2Theta(cosTheta*cosTheta), sin2Theta(1. - cos2Theta),
1200  mA2(mA*mA), mK2(mK*mK), mAK2(mAK*mAK),
1201  tmp0(sqrt(sin2Theta*KallenFunction(mA2, mK2, mAK2) + 4.0*mAK2*mA2)),
1202  tmp1(mK/mA*tmp0), tmp2(cos2Theta*mK2 + mAK2), tmp3(mA2 - sin2Theta*mK2),
1203  tmp4((tmp2 + tmp1)/tmp3);
1204  double Emax = mA*(1 - tmp4)/2.0;
1205  double EabsoluteMax = mA/2.0 - (mK+mAK)*(mK+mAK)/(2.0*mA);
1206  return min(Emax,EabsoluteMax);
1207 
1208 }
1209 
1210 //==========================================================================
1211 
1212 // BrancherSplitRF class for storing information on antennae between a
1213 // coloured resonance and final state parton, and generating a new
1214 // emission.
1215 
1216 //--------------------------------------------------------------------------
1217 
1218 void BrancherSplitRF::init(Event& event, vector<int> allIn,
1219  unsigned int posResIn, unsigned int posFIn, double Q2cut) {
1220 
1221  // Get Pythia indices of res and final.
1222  posRes = posResIn;
1223  posFinal = posFIn;
1224  int iRes = allIn.at(posRes);
1225  int iFinal = allIn.at(posFinal);
1226  colFlowRtoF = event[iRes].col() == event[iFinal].col()
1227  && event[iRes].col() != 0;
1228 
1229  // Extract the momenta of the rest.
1230  Vec4 recoilVec(0., 0., 0., 0.);
1231  for (vector<int>::iterator pos=allIn.begin(); pos!=allIn.end(); ++pos) {
1232  if ((*pos == iRes) || (*pos == iFinal)) continue;
1233  recoilVec += event[*pos].p();
1234  }
1235 
1236  // This is not necesssarily p(res). In the case where one particle
1237  // always recieves the recoil, e.g. W in t->bWX it is p_t - p_X,
1238  Vec4 resVec = recoilVec + event[iFinal].p();
1239  mRes = resVec.mCalc();
1240  mFinal = 0.;
1241  mRecoilers = recoilVec.mCalc();
1242  sAK = getsAK(mRes, mFinal, mRecoilers);
1243 
1244  //Calculate common prefactor to trial integral.
1245  kallenFacSav = (0.5*sAK/(4.0*M_PI));
1246  kallenFacSav /= sqrt(KallenFunction(mRes*mRes, mFinal*mFinal,
1247  mRecoilers*mRecoilers));
1248 
1249  // Calculate zeta limits.
1250  zetaMin = zetaMinCalc(mRes, mFinal, mRecoilers,Q2cut);
1251  zetaMax = 1.0;
1252 
1253  // Calculate zeta integral (full phase space), for splitters is just flat.
1254  zetaIntSave= zetaMax-zetaMin;
1255 
1256  // Calculate Q2max.
1257  Q2MaxSav = calcQ2Max(mRes, mRecoilers,mFinal);
1258  branchType = 6;
1259  swapped = false;
1260  iAntSav = iXGsplitRF;
1261 
1262 }
1263 
1264 //--------------------------------------------------------------------------
1265 
1266 // Setter methods.
1267 
1268 vector<double> BrancherSplitRF::setmPostVec() {
1269  mPostSav.clear();
1270  mPostSav.push_back(mRes);
1271  mPostSav.push_back(mFlavSav);
1272  mPostSav.push_back(mFlavSav);
1273  mPostSav.push_back(mRecoilers);
1274  return mPostSav;
1275 }
1276 
1277 void BrancherSplitRF::setidPost(){
1278  idPostSav.clear();
1279  idPostSav = idSav;
1280  // Modify the splitting gluon to antiquark, insert quark in second position.
1281  if (colFlowRtoF) {
1282  idPostSav[posFinal] = -idFlavSav;
1283  idPostSav.insert(idPostSav.begin() + 1, idFlavSav);
1284  } else {
1285  idPostSav[posFinal] = idFlavSav;
1286  idPostSav.insert(idPostSav.begin() + 1, -idFlavSav);
1287  }
1288 }
1289 
1290 void BrancherSplitRF::setStatPost() {
1291  statPostSav.resize(iSav.size() + 1, 52);
1292  statPostSav[1] = 51;
1293  statPostSav[posFinal+1] = 51;
1294 }
1295 
1296 //--------------------------------------------------------------------------
1297 
1298 // Generic method, assumes setter methods called earlier.
1299 
1300 bool BrancherSplitRF::getNewParticles(Event& event, vector<Vec4> momIn,
1301  vector<int> hIn, vector<Particle>& pNew, Rndm*, Colour*){
1302 
1303  // Initialize.
1304  unsigned int nPost = iSav.size() + 1;
1305  pNew.clear();
1306  setidPost();
1307  setStatPost();
1308  double scaleNew = sqrt(q2NewSav);
1309  setMaps(event.size());
1310  if (momIn.size() != nPost || hIn.size() != nPost ||
1311  idPostSav.size() != nPost || statPostSav.size() != nPost ) return false;
1312  int resTag = 0;
1313  if (colFlowRtoF) resTag = event[iSav[posRes]].col();
1314  else resTag = event[iSav[posRes]].acol();
1315 
1316  // Now populate particle vector.
1317  for (unsigned int ipart = 0; ipart < nPost; ++ipart) {
1318  Particle newPart;
1319  // Set mass and colours, (we have repurposed mPost for antenna
1320  // function mass scales). This is new emission.
1321  if (posNewtoOld.find(ipart) == posNewtoOld.end()) {
1322  newPart.m(mFlavSav);
1323  if (colFlowRtoF) newPart.cols(resTag, 0);
1324  else newPart.cols(0, resTag);
1325  } else if (posNewtoOld[ipart] == posRes) {continue;
1326  } else {
1327  int colNow = event[iSav[posNewtoOld[ipart]]].col();
1328  int acolNow = event[iSav[posNewtoOld[ipart]]].acol();
1329  if (posNewtoOld[ipart] == posFinal) {
1330  if (colFlowRtoF) colNow = 0;
1331  else acolNow = 0;
1332  newPart.m(mFlavSav);
1333  } else newPart.m(mSav[posNewtoOld[ipart]]);
1334  newPart.cols(colNow,acolNow);
1335  }
1336 
1337  //Set other pre-determined particle properties.
1338  newPart.status(statPostSav[ipart]);
1339  newPart.id(idPostSav[ipart]);
1340  newPart.pol(hIn[ipart]);
1341  newPart.p(momIn[ipart]);
1342  newPart.setEvtPtr(&event);
1343  newPart.scale(scaleNew);
1344  newPart.daughters(0,0);
1345  pNew.push_back(newPart);
1346  }
1347  colTagSav = 0;
1348  return true;
1349 
1350 }
1351 
1352 //--------------------------------------------------------------------------
1353 
1354 // Generate a new Q2 scale.
1355 
1356 double BrancherSplitRF::genQ2(int evTypeIn, double Q2MaxNow, Rndm* rndmPtr,
1357  const EvolutionWindow* evWindowPtrIn, double colFac,
1358  vector<double> headroomIn, vector<double> enhanceIn, int verboseIn) {
1359 
1360  if (zetaIntSave <= 0.) {
1361  hasTrialSav = true;
1362  q2NewSav = 0.;
1363  return q2NewSav;
1364  }
1365 
1366  // Total splitting weight summed over flavours
1367  double wtSum = 0.0;
1368  vector<double> wtFlav;
1369  unsigned int nFlav = headroomIn.size();
1370  if (nFlav != enhanceIn.size()) {
1371  if (verboseIn >= normal) {
1372  string errorMsg = "Error in "+__METHOD_NAME__
1373  +": Headroom and enhancement vectors have different sizes.";
1374  cout<<errorMsg<<endl;
1375  }
1376  return 0.;
1377  }
1378  for (unsigned int iFlav = 0; iFlav < nFlav; ++iFlav) {
1379  double wt = headroomIn[iFlav] * enhanceIn[iFlav];
1380  wtFlav.push_back(wt);
1381  wtSum += wt;
1382  }
1383 
1384  // pT evolution.
1385  if (evTypeIn == 1) {
1386 
1387  // Get multiplicative factors (sAK/(2*4pi*lambda^1/2)).
1388  double prefactor = kallenFacSav;
1389  prefactor *= colFac;
1390  prefactor *= wtSum;
1391  evTypeSav = evTypeIn;
1392  q2BegSav = Q2MaxNow;
1393  evWindowSav = evWindowPtrIn;
1394  colFacSav = colFac;
1395  double logR = log(rndmPtr->flat());
1396 
1397  // Fixed alphaS.
1398  if (evWindowPtrIn->runMode <= 0) {
1399  // Use max possible value for alphaS.
1400  prefactor*= evWindowPtrIn->alphaSmax;
1401  // Inverse of Q2 integral for fixed alphaS.
1402  q2NewSav = Q2MaxNow*exp(logR/(prefactor*zetaIntSave));
1403  // Running alphaS.
1404  } else {
1405  prefactor /= evWindowPtrIn->b0;
1406  double muRScaleMod = evWindowPtrIn->kMu2/evWindowPtrIn->lambda2;
1407  double logQ2Ratio = exp(logR/(prefactor*zetaIntSave));
1408  double logQ2maxFactor = log(Q2MaxNow*muRScaleMod);
1409  q2NewSav = exp(logQ2maxFactor*logQ2Ratio)/muRScaleMod;
1410  }
1411  } else {
1412  if (verboseIn >= normal) {
1413  stringstream ss;
1414  ss << "evTypeIn = " << evTypeIn;
1415  string errorMsg = "Error in "+__METHOD_NAME__
1416  +": Unsupported Evolution Type."+" "+ss.str();
1417  cout<<errorMsg<<endl;
1418  }
1419  return 0.;
1420  }
1421 
1422  // Select flavour.
1423  double ranFlav = rndmPtr->flat() * wtSum;
1424  for (int iFlav = nFlav - 1; iFlav >= 0; --iFlav) {
1425  ranFlav -= wtFlav[iFlav];
1426  if (ranFlav < 0) {
1427  idFlavSav = iFlav+1;
1428  mFlavSav = evWindowSav->mass.at(idFlavSav);
1429  enhanceSav = enhanceIn[iFlav];
1430  headroomSav = headroomIn[iFlav];
1431  break;
1432  }
1433  }
1434 
1435  // Debugging.
1436  if (verboseIn >= superdebug) {
1437  stringstream ss;
1438  ss << "Selected splitting flavour: " << idFlavSav;
1439  printOut(__METHOD_NAME__, ss.str());
1440  }
1441  if (q2NewSav > Q2MaxNow) {
1442  string errorMsg = "Error in "+__METHOD_NAME__
1443  +": Generated qq2New > q2Max"+" Returning -1.";
1444  cout<<errorMsg<<endl;
1445  q2NewSav = -1.;
1446  }
1447  hasTrialSav = true;
1448  return q2NewSav;
1449 
1450 }
1451 
1452 //--------------------------------------------------------------------------
1453 
1454 // Generate complementary invariant(s) for saved trial scale. Return
1455 // false if no physical kinematics possible.
1456 
1457 bool BrancherSplitRF::genInvariants(vector<double>& invariants,Rndm* rndmPtr,
1458  int verboseIn) {
1459 
1460  //Initialize and check we have a generated q2.
1461  invariants.clear();
1462  invariantsSav.clear();
1463  if (q2NewSav <= 0.) return false;
1464  setmPostVec();
1465 
1466  // Get zeta.
1467  double zetaNext = getZetaNext(rndmPtr);
1468  if (zetaNext < 0.) cout << zetaMin<< " " << zetaMax << endl;
1469  double m2q = mFlavSav*mFlavSav;
1470  double sak = zetaNext*sAK;
1471  double tmp1 = q2NewSav - (1.-zetaNext)*sAK + m2q;
1472  double tmp2 = sqrt(1.0 +4.0*sAK*q2NewSav/(tmp1*tmp1));
1473  double sjk = tmp1*(1-tmp2)/2.0 -2.0*m2q ;
1474  double saj = (1.0-zetaNext)*sAK + 2.0*m2q +sjk;
1475  if (verboseIn >= louddebug) {
1476  stringstream ss;
1477  ss << "Phase space point: Q2next = " << q2NewSav <<" zeta = " << zetaNext;
1478  printOut(__METHOD_NAME__, ss.str());
1479  ss.str("Scaled invariants: yaj = ");
1480  ss << saj/(sjk+sAK) << " yjk = " << sjk/(sjk+sAK);
1481  printOut(__METHOD_NAME__, ss.str());
1482  }
1483 
1484  //Save regardless.
1485  invariantsSav.push_back(sAK);
1486  invariantsSav.push_back(saj);
1487  invariantsSav.push_back(sjk);
1488  invariantsSav.push_back(sak);
1489 
1490  // Veto if the point is outside the available phase space.
1491  if (vetoPhSpPoint(saj, sjk, sak, verboseIn)) return false;
1492  else {invariants = invariantsSav; return true;}
1493 
1494 }
1495 
1496 //--------------------------------------------------------------------------
1497 
1498 // Compute antPhys/antTrial, given antPhys. Note, antPhys should be
1499 // normalised to include charge and coupling factors.
1500 
1501 double BrancherSplitRF::pAccept(const double antPhys, int verboseIn) {
1502 
1503  if (q2NewSav <= 0.) {
1504  if (verboseIn >= normal) {
1505  string errorMsg = "Error in "+__METHOD_NAME__+": q2NewSav not set";
1506  cout<<errorMsg<<endl;
1507  }
1508  return 0.;
1509  } else if (invariantsSav.size() != 4) {
1510  if (verboseIn >= normal) {
1511  string errorMsg = "Error in "+__METHOD_NAME__+": invariants not set";
1512  cout<<errorMsg<<endl;
1513  }
1514  return 0.;
1515  }
1516  double saj = invariantsSav[1];
1517  double sjk = invariantsSav[2];
1518  double sak = invariantsSav[3];
1519  double m2q = mFlavSav*mFlavSav;
1520  double antTrial = 0.5/(sjk + 2.0*m2q);
1521  double norm = 1.0 + (sjk + 2.0*m2q)/(sAK+sjk+2.0*m2q)*(sak+m2q)/(saj-m2q);
1522  antTrial*=norm;
1523 
1524  // Multiply by headroom factor.
1525  antTrial *= headroomSav;
1526 
1527  // Multiply by col factor.
1528  antTrial *= colFacSav;
1529 
1530  // Multiply by alphaS, default is fixed alphaS.
1531  double alphaSTrial = evWindowSav->alphaSmax;
1532 
1533  // Running alphaS.
1534  if (evWindowSav->runMode >= 1) {
1535  double mu2 = q2NewSav;
1536  mu2 *= (evWindowSav->kMu2/evWindowSav->lambda2);
1537  alphaSTrial = 1.0/log(mu2)/evWindowSav->b0;
1538  }
1539  antTrial *= alphaSTrial;
1540  return antPhys/antTrial;
1541 
1542 }
1543 
1544 //==========================================================================
1545 
1546 // The VinciaFSR class for resonant decays.
1547 
1548 //--------------------------------------------------------------------------
1549 
1550 // Initialize alphaStrong and related pTmin parameters (TimeShower).
1551 
1552 void VinciaFSR::init( BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn) {
1553 
1554  // Check if already initialized.
1555  if (isInit && settingsPtr->word("Merging:Process").compare("void") == 0)
1556  return;
1557  verbose = settingsPtr->mode("Vincia:verbose");
1558  if (verbose >= veryloud) printOut(__METHOD_NAME__, "begin --------------");
1559  allowforceQuit = false;
1560  forceQuit = false;
1561  nBranchQuit = -1;
1562 
1563  // Event counters and debugging. Set nAccepted to -1, so prepare
1564  // works properly.
1565  nAccepted = -1;
1566  nSelected = -1;
1567  nVetoUserHooks = 0;
1568  nFailHadLevel = 0;
1569  nCallPythiaNext = 0;
1570 
1571  // Showers on/off.
1572  doFF = settingsPtr->flag("Vincia:doFF");
1573  doRF = settingsPtr->flag("Vincia:doRF");
1574  doII = settingsPtr->flag("Vincia:doII");
1575  doIF = settingsPtr->flag("Vincia:doIF");
1576  doQED = settingsPtr->flag("Vincia:doQED");
1577 
1578  // TODO: everything is evolved in PT in this version of VINCIA.
1579  evTypeEmit = 1;
1580  evTypeSplit = 1;
1581 
1582  // Store input pointers for future use.
1583  beamAPtr = beamAPtrIn;
1584  beamBPtr = beamBPtrIn;
1585 
1586  // Assume all events in same run have same beam-beam ECM.
1587  m2BeamsSav = m2(beamAPtr->p(), beamBPtr->p());
1588  eCMBeamsSav = sqrt(m2BeamsSav);
1589 
1590  // Possibility to allow user veto of emission step.
1591  hasUserHooks = (userHooksPtr != 0);
1592  canVetoEmission = (hasUserHooks && userHooksPtr->canVetoFSREmission());
1593 
1594  // Number of active quark flavours
1595  nGluonToQuark = settingsPtr->mode("Vincia:nGluonToQuark");
1596 
1597  // Number of flavours to be treated as massless (can be made
1598  // user-specifiable in future if desired).
1599  nFlavZeroMass = settingsPtr->mode("Vincia:nFlavZeroMass");
1600 
1601  // Global flag for helicity dependence.
1602  helicityShower = settingsPtr->flag("Vincia:helicityShower");
1603 
1604  // Global flag for sector showers on/off.
1605  sectorShower = settingsPtr->flag("Vincia:sectorShower");
1606 
1607  // Perturbative cutoff. Since emissions and splittings can have
1608  // different evolution measures, in principle allow for different
1609  // cutoff scales, for now forced same.
1610  q2CutoffEmit = pow2(settingsPtr->parm("Vincia:cutoffScaleFF"));
1611  // Allow perturbative g->qq splittings to lower scales.
1612  q2CutoffSplit = pow2(settingsPtr->parm("Vincia:cutoffScaleFF"));
1613 
1614  // Set shower alphaS pointer.
1615  useCMW = settingsPtr->flag("Vincia:useCMW");
1616  aSemitPtr = &vinComPtr->alphaStrong;
1617  aSsplitPtr = &vinComPtr->alphaStrong;
1618  // Currently, CMW is applied to both emissions and splittings.
1619  if (useCMW) {
1620  aSemitPtr = &vinComPtr->alphaStrongCMW;
1621  aSsplitPtr = &vinComPtr->alphaStrongCMW;
1622  }
1623 
1624  // AlphaS parameters.
1625  alphaSvalue = settingsPtr->parm("Vincia:alphaSvalue");
1626  alphaSorder = settingsPtr->mode("Vincia:alphaSorder");
1627  aSkMu2Emit = settingsPtr->parm("Vincia:renormMultFacEmitF");
1628  aSkMu2Split = settingsPtr->parm("Vincia:renormMultFacSplitF");
1629  alphaSmax = settingsPtr->parm("Vincia:alphaSmax");
1630  alphaSmuFreeze = settingsPtr->parm("Vincia:alphaSmuFreeze");
1631  mu2freeze = pow2(alphaSmuFreeze);
1632 
1633  // Smallest allowed scale for running alphaS.
1634  alphaSmuMin = 1.05 * max(aSemitPtr->Lambda3(), aSsplitPtr->Lambda3());
1635  mu2min = pow2(alphaSmuMin);
1636 
1637  // For constant alphaS, set max = value (for efficiency).
1638  if (alphaSorder == 0) alphaSmax = alphaSvalue;
1639  initEvolutionWindows();
1640 
1641  // Settings for enhanced (biased) kernels.
1642  enhanceInHard = settingsPtr->flag("Vincia:enhanceInHardProcess");
1643  enhanceInResDec = settingsPtr->flag("Vincia:enhanceInResonanceDecays");
1644  enhanceInMPI = settingsPtr->flag("Vincia:enhanceInMPIshowers");
1645  enhanceAll = settingsPtr->parm("Vincia:enhanceFacAll");
1646  // Explicitly allow heavy-quark enhancements only, not suppression
1647  enhanceBottom = max(1., settingsPtr->parm("Vincia:enhanceFacBottom"));
1648  enhanceCharm = max(1., settingsPtr->parm("Vincia:enhanceFacCharm"));
1649  enhanceCutoff = settingsPtr->parm("Vincia:enhanceCutoff");
1650 
1651  // Resize pAccept to the maximum number of elements.
1652  pAccept.resize(max(weightsPtr->nWeights(), 1));
1653 
1654  // Statistics.
1655  nTrialsSum = 0;
1656  int nAntPhysMax = 20;
1657  nTrials.resize(nAntPhysMax + 1);
1658  nTrialsAccepted.resize(nAntPhysMax + 1);
1659  nFailedVeto.resize(nAntPhysMax + 1);
1660  nFailedHull.resize(nAntPhysMax + 1);
1661  nFailedKine.resize(nAntPhysMax + 1);
1662  nFailedMass.resize(nAntPhysMax + 1);
1663  nFailedCutoff.resize(nAntPhysMax + 1);
1664  nClosePSforHQ.resize(nAntPhysMax + 1);
1665  nSectorReject.resize(nAntPhysMax + 1);
1666 
1667  // Initialize parameters for shower starting scale.
1668  pTmaxMatch = settingsPtr->mode("Vincia:pTmaxMatch");
1669  pTmaxFudge = settingsPtr->parm("Vincia:pTmaxFudge");
1670  pT2maxFudge = pow2(pTmaxFudge);
1671  pT2maxFudgeMPI = pow2(settingsPtr->parm("Vincia:pTmaxFudgeMPI"));
1672 
1673  // Initialize the FSR antenna functions.
1674  if (verbose >= veryloud)
1675  printOut(__METHOD_NAME__, "initializing antennaSet");
1676  antSetPtr->init();
1677  kMapResEmit = settingsPtr->mode("Vincia:kineMapRFemit");
1678  kMapResSplit = settingsPtr->mode("Vincia:kineMapRFsplit");
1679 
1680  // Initialise the QED shower module if not done already.
1681  if (!qedShowerPtr->isInit()) {
1682  if (verbose >= debug)
1683  printOut(__METHOD_NAME__, "initializing QED shower module");
1684  qedShowerPtr->init(beamAPtrIn, beamBPtrIn);
1685  }
1686 
1687  // Diagnostics.
1688  setDiagnostics(dynamic_pointer_cast<VinciaDiagnostics>(userHooksPtr));
1689 
1690  isInit=true;
1691  if (verbose >= veryloud) printOut(__METHOD_NAME__, "end --------------");
1692 
1693 }
1694 
1695 //--------------------------------------------------------------------------
1696 
1697 // Possible limitation of first emission (TimeShower).
1698 
1699 bool VinciaFSR::limitPTmax(Event& event, double, double) {
1700 
1701  // Check if limiting pT of first emission.
1702  if (pTmaxMatch == 1) return true;
1703  else if (pTmaxMatch == 2) return false;
1704 
1705  // Always restrict SoftQCD processes.
1706  else if (infoPtr->isNonDiffractive() || infoPtr->isDiffractiveA() ||
1707  infoPtr->isDiffractiveB() || infoPtr->isDiffractiveC())
1708  return true;
1709 
1710  // Look if jets or photons in final state of hard system (iSys = 0).
1711  else {
1712  const int iSysHard = 0;
1713  for (int i = 0; i < partonSystemsPtr->sizeOut(iSysHard); ++i) {
1714  int idAbs = event[partonSystemsPtr->getOut(iSysHard,i)].idAbs();
1715  if (idAbs <= 5 || idAbs == 21 || idAbs == 22) return true;
1716  else if (idAbs == 6 && nGluonToQuark == 6) return true;
1717  }
1718  // If no QCD/QED partons detected, allow to go to phase-space maximum
1719  return false;
1720  }
1721 
1722 }
1723 
1724 //--------------------------------------------------------------------------
1725 
1726 // Top-level routine to do a full time-like shower in resonance decay
1727 // (TimeShower).
1728 
1729 int VinciaFSR::shower(int iBeg, int iEnd, Event& event, double pTmax,
1730  int nBranchMax) {
1731 
1732  // Verbose output.
1733  if (verbose >= debug) printOut("VinciaFSR::shower", "begin --------------");
1734 
1735  // Add new system, automatically with two empty beam slots.
1736  int iSys = partonSystemsPtr->addSys();
1737 
1738  // Verbose output.
1739  if (verbose >= 8) printOut("VinciaFSR::shower",
1740  "preparing to shower. System no. " + num2str(iSys));
1741 
1742  // Loop over allowed range to find all final-state particles.
1743  Vec4 pSum;
1744  for (int i = iBeg; i <= iEnd; ++i)
1745  if (event[i].isFinal()) {
1746  partonSystemsPtr->addOut( iSys, i);
1747  pSum += event[i].p();
1748  }
1749  partonSystemsPtr->setSHat( iSys, pSum.m2Calc() );
1750 
1751  // Now need to clear all systems of antennae. Should be fine
1752  // because shower() is only called in two cases: (1) showering off
1753  // hadronic resonances as they decay (e.g. upsilon) (2) by user, in
1754  // which case there should not be pre-existing systems.
1755  resEmitters.clear();
1756  resSplitters.clear();
1757  emitters.clear();
1758  splitters.clear();
1759  lookupBrancherRF.clear();
1760  lookupSplitterRF.clear();
1761  lookupBrancherFF.clear();
1762  lookupSplitter.clear();
1763  qedShowerPtr->iSystems.clear();
1764  qedShowerPtr->emitSystems.clear();
1765  qedShowerPtr->splitSystems.clear();
1766  qedShowerPtr->convSystems.clear();
1767 
1768  // Let prepare routine do the setup.
1769  prepare(iSys, event, false);
1770 
1771  // Begin evolution down in pT from hard pT scale.
1772  int nBranchNow = 0;
1773  do {
1774  // Do a final-state emission (if allowed).
1775  double pTtimes = pTnext(event, pTmax, 0.);
1776  if (pTtimes > 0.) {
1777  if (branch(event)) ++nBranchNow;
1778  pTmax = pTtimes;
1779  }
1780 
1781  // Keep on evolving until nothing is left to be done.
1782  else pTmax = 0.;
1783  } while (pTmax > 0. && (nBranchMax <= 0 || nBranchNow < nBranchMax));
1784 
1785  // Return number of emissions that were performed.
1786  return nBranchNow;
1787 
1788 }
1789 
1790 //--------------------------------------------------------------------------
1791 
1792 // Method to add QED showers in hadron decays (TimeShower).
1793 
1794 int VinciaFSR::showerQED(int iBeg, int iEnd, Event& event, double pTmax) {
1795 
1796  // Verbose output
1797  if(verbose >= debug) printOut(__METHOD_NAME__, "begin --------------");
1798 
1799  // Construct a little QED system out of the given particles.
1800  partonSystemsPtr->addSys();
1801  int iSys = partonSystemsPtr->sizeSys()-1;
1802  // We could check if they all have the same mother and treat as
1803  // resonance decay, but currently do not.
1804  if (iBeg > iEnd) {
1805  partonSystemsPtr->addOut(iSys,iBeg);
1806  partonSystemsPtr->addOut(iSys,iEnd);
1807  } else {
1808  for (int i=iBeg; i<iEnd; ++i) partonSystemsPtr->addOut(iSys,i);
1809  }
1810  qedShowerPtr->prepare( iSys, event, true);
1811  double q2 = pow2(pTmax);
1812  double q2min = qedShowerPtr->q2min();
1813  int nBranchNow = 0;
1814  while(true) {
1815  q2 = qedShowerPtr->generateTrialScale(event, q2);
1816  if (q2 < q2min) break;
1817  if (qedShowerPtr->checkVeto(event)) {
1818  qedShowerPtr->update(event, iSys);
1819  ++nBranchNow;
1820  }
1821  }
1822  return nBranchNow;
1823 
1824 }
1825 
1826 //--------------------------------------------------------------------------
1827 
1828 // Method to add QED showers to partons below colour resolution scale
1829 // (TimeShower).
1830 
1831 int VinciaFSR::showerQEDafterRemnants(Event& event) {
1832 
1833  // Check if we are supposed to do anything.
1834  if (!doQED || infoPtr->getAbortPartonLevel()) return 0;
1835  if (verbose >= debug) printOut(__METHOD_NAME__, "begin --------------");
1836 
1837  // Prepare for showering below hadronisation scale. Include partons
1838  // from all current systems (pass iSys = -1).
1839  qedShowerPtr->prepare( -1, event, true);
1840  // Retrieve actual iSys.
1841  int iSys = partonSystemsPtr->sizeSys()-1;
1842  double q2 = qedShowerPtr->q2minColoured();
1843  double q2min = max(qedShowerPtr->q2min(),1.e-13);
1844  int nBranchNow = 0;
1845  while(true) {
1846  q2 = qedShowerPtr->generateTrialScale(event, q2);
1847  if (q2 < q2min) break;
1848  if (qedShowerPtr->checkVeto(event)) {
1849  qedShowerPtr->update(event, iSys);
1850  ++nBranchNow;
1851  }
1852  }
1853  if (verbose >= debug) printOut(__METHOD_NAME__, "end --------------");
1854  return nBranchNow;
1855 
1856 }
1857 
1858 //--------------------------------------------------------------------------
1859 
1860 // Prepare system for evolution (TimeShower).
1861 
1862 void VinciaFSR::prepare( int iSys, Event& event, bool){
1863 
1864  // Set isPrepared to false every time prepare is called.
1865  // Only reset back to true if method executes successfully.
1866  isPrepared = false;
1867  if (!isInit) return;
1868 
1869  // Check if we are supposed to do anything
1870  if (!(doFF || doRF)) return;
1871  if (infoPtr->getAbortPartonLevel()) {
1872  infoPtr->errorMsg("Error in "+__METHOD_NAME__
1873  +": Received abort from PartonLevel().","Aborting.");
1874  return;
1875  }
1876 
1877  // Last chance to print header if not done already.
1878  if (!headerIsPrinted && verbose >= normal) header();
1879  if (verbose >= debug) {
1880  printOut(__METHOD_NAME__, "begin --------------");
1881  if (verbose >= louddebug) {
1882  stringstream ss;
1883  ss << "Preparing system " << iSys;
1884  printOut(__METHOD_NAME__, ss.str());
1885  }
1886  if (verbose >= superdebug) {
1887  event.list();
1888  partonSystemsPtr->list();
1889  }
1890  }
1891 
1892  // Statistics (zero info on qBranch scales).
1893  if (iSys < 4)
1894  for (int j = 0; j < 11; ++j) {
1895  qBranch[iSys][j] = 0.0;
1896  pTphys[iSys][j] = 0.0;
1897  }
1898 
1899  // Counter for accepted events.
1900  nAccepted = max(nAccepted, infoPtr->nAccepted());
1901 
1902  // First time prepare is called for an event.
1903  bool firstCallInEvent = false;
1904  // getCounter(3), number of times a Pythia::next() call has been begun.
1905  int nCallPythiaNextNow = infoPtr->getCounter(3);
1906  if (nCallPythiaNextNow > nCallPythiaNext) {
1907  nCallPythiaNext = nCallPythiaNextNow;
1908  nVetoUserHooks = 0;
1909  nFailHadLevel = 0;
1910  firstCallInEvent = true;
1911  }
1912  // Last event got accepted.
1913  long nSelectedNow = infoPtr->nSelected();
1914  if (nSelectedNow > nSelected) {
1915  nSelected = nSelectedNow;
1916  nVetoUserHooks = 0;
1917  nFailHadLevel = 0;
1918  firstCallInEvent = true;
1919  }
1920  // getCounter(10), number of times the selection of a new hard
1921  // process has been begun. = 1 if no user hooks veto, > 1 if user
1922  // hooks veto.
1923  int nVetoUserHooksNow = (infoPtr->getCounter(10)-1);
1924  if (nVetoUserHooksNow > nVetoUserHooks) {
1925  nVetoUserHooks = nVetoUserHooksNow;
1926  firstCallInEvent = true;
1927  }
1928  // getCounter(14), number of times loop over parton- and
1929  // hadron-level processing has begun for a hard process. = 1 if
1930  // everything after user hooks veto is succesful, > 1 eg if hadron
1931  // level fails.
1932  int nFailHadLevelNow = (infoPtr->getCounter(14) - 1);
1933  if (nFailHadLevelNow > nFailHadLevel) {
1934  nFailHadLevel = nFailHadLevelNow;
1935  firstCallInEvent = true;
1936  }
1937 
1938  // Resetting for first time in new event.
1939  if (firstCallInEvent) {
1940  forceQuit = false;
1941 
1942  // Reset counters, weights in new events, and clear system information.
1943  vinComPtr->resetCounters();
1944  weightsPtr->resetWeights(infoPtr->nAccepted());
1945  clearContainers();
1946  }
1947 
1948  // Allow to quit after a certain number of emissions per event (just
1949  // for testing).
1950  if (forceQuit){
1951  if (verbose >= debug) printOut(__METHOD_NAME__, "User forced quit early.");
1952  return;
1953  }
1954 
1955  // Sanity check: at least two particles in system.
1956  int sizeSystem = partonSystemsPtr->sizeAll(iSys);
1957  if (sizeSystem <= 1) return;
1958 
1959  // Reset antenna list for first interaction and for resonance
1960  // decays. We don't have a starting scale for this system yet.
1961  Q2hat[iSys] = 0.0;
1962  // After prepare we always have zero branchings.
1963  nBranch[iSys] = 0;
1964  nBranchFSR[iSys] = 0;
1965  if (doDiagnostics) diagnosticsPtr->setnBranchSys(iSys,nBranch[iSys]);
1966 
1967  // Initialize polarisation flag (only consider final-state partons).
1968  bool checkIncoming = false;
1969  if (helicityShower)
1970  polarisedSys[iSys] = mecsPtr->isPolarised(iSys, event, checkIncoming);
1971  else polarisedSys[iSys] = false;
1972  stateChangeSys[iSys] = true;
1973  stateChangeLast = true;
1974  iSysWin = iSys;
1975  iNewSav = 0;
1976 
1977  // Note that we have not yet binned the first branching scale.
1978  if (iSys == 0) firstQBranchBinned = false;
1979 
1980  // We are not creating new copies of the particles. Colour and
1981  // polarization information may be changed or added, respectively,
1982  // and masses may be set to zero for partons VINCIA wants to treat
1983  // as massless.
1984  bool makeNewCopies = false;
1985 
1986  // Note, for 2->2 systems, ISR::prepare() is called before
1987  // FRS::prepare() (if doISR) so ISR may already have done
1988  // everything.
1989  if ((doIF || doII) && isrPtr->prepared(iSys)) {
1990  makeNewCopies = false;
1991 
1992  // Ensure consistency between ISR + FSR lists.
1993  isHardSys[iSys] = isrPtr->isHardSys[iSys];
1994  isResonanceSys[iSys] = false;
1995  doMECsSys[iSys] = isrPtr->doMECsSys[iSys];
1996  polarisedSys[iSys] = isrPtr->polarisedSys[iSys];
1997 
1998  // If ISR::prepare() not called for this system, prepare it now.
1999  } else {
2000 
2001  // Since ISR::prepare() not called, this will normally be a resonance
2002  // decay system, but still no harm in checking explicitly.
2003  if (partonSystemsPtr->hasInAB(iSys)) {
2004  isHardSys[iSys] = ( iSys == 0 );
2005  isResonanceSys[iSys] = false;
2006  } else {
2007  isHardSys[iSys] = false;
2008  isResonanceSys[iSys] = partonSystemsPtr->hasInRes(iSys);
2009  int iAncestor = event[partonSystemsPtr->getOut(iSys,0)].mother1();
2010  // Make sure iAncestor is recorded as iInA in the parton system
2011  // (not standard usage in PYTHIA but useful in VINCIA).
2012  partonSystemsPtr->setInA(iSys, iAncestor);
2013  }
2014 
2015  // Make light quarks (and initial-state partons) explicitly massless.
2016  if (!vinComPtr->mapToMassless(iSys, event, partonSystemsPtr,
2017  makeNewCopies)) return;
2018  // Then see if we know how to compute matrix elements for this conf.
2019  doMECsSys[iSys] = mecsPtr->prepare(iSys, event);
2020  // Then see if and whether we can assign helicities.
2021  if (doMECsSys[iSys] && helicityShower)
2022  polarisedSys[iSys] = mecsPtr->polarise(iSys, event);
2023  // Decide if we should be doing ME corrections for next order.
2024  if (doMECsSys[iSys]) doMECsSys[iSys] = mecsPtr->doMEC(iSys, 1);
2025  // Then see if we should colourise this conf.
2026  colourPtr->colourise(iSys, event);
2027  }
2028 
2029  // Find antennae.
2030  if (verbose >= superdebug) printOut(__METHOD_NAME__, "Finding antennae....");
2031  if(!getAntennae(iSys, event)) return;
2032 
2033  // Set starting scale for this system.
2034  setStartScale(iSys, event);
2035 
2036  // Let others know we got to the end.
2037  isPrepared = true;
2038  if (verbose >= debug) {
2039  if (verbose >= superdebug) list();
2040  printOut(__METHOD_NAME__, "end --------------");
2041  }
2042 
2043 }
2044 
2045 //--------------------------------------------------------------------------
2046 
2047 // Update antenna list after each ISR emission (TimeShower).
2048 
2049 void VinciaFSR::update( int iSys, Event& event, bool) {
2050 
2051  // Do nothing if not prepared for FSR.
2052  if (!isPrepared) return;
2053  if (verbose >= debug) {
2054  printOut(__METHOD_NAME__, "begin --------------");
2055  if (verbose >= louddebug) event.list();
2056  }
2057 
2058  // Update QED system.
2059  qedShowerPtr->update(event, iSys);
2060  if (isResonanceSys[iSys]) {
2061  if (verbose >=normal) infoPtr->errorMsg("Error in "+__METHOD_NAME__
2062  +": Update called unexpectedly in resonance shower.","Exiting.");
2063  return;
2064  }
2065 
2066  // Count number of branches.
2067  nBranch[iSys]++;
2068 
2069  // Particles in the list are already updated by ISR. Find and save
2070  // all colours and anticolours; find all FF antennae.
2071  map<int,int> indexOfAcol;
2072  map<int,int> indexOfCol;
2073  vector< pair<int,int> > antFF;
2074  const bool findFF = true;
2075  const bool findIX = false;
2076  colourPtr->makeColourMaps(iSys, event, indexOfAcol, indexOfCol,
2077  antFF, findFF, findIX);
2078 
2079  // In principle, the colour maps could here be used to look for any
2080  // unmatched tags -> junctions.
2081 
2082  // Sanity check: can only shower QCD systems with more than 1 FF
2083  // connection.
2084  if (antFF.size() <= 0) return;
2085 
2086  // Update any final-state antennae with partons changed by ISR
2087  // branching.
2088  for (int i = 0; i < (int)emitters.size(); i++) {
2089  Brancher* brancherPtr = &emitters[i];
2090  // Update any antennae with legs that were modified by the ISR
2091  // branching, i.e. whose current legs have been marked with status
2092  // < 0.
2093  int i0Old = brancherPtr->i0();
2094  int i1Old = brancherPtr->i1();
2095  int i0New = i0Old;
2096  int i1New = i1Old;
2097 
2098  if (event[i0Old].status() < 0 || event[i1Old].status() < 0) {
2099  // Get new positions from indexOfCol, indexOfAcol (could also
2100  // use daughter information from old i0, i1).
2101  i0New = indexOfCol[event[i0Old].col()];
2102  i1New = indexOfAcol[event[i1Old].acol()];
2103  // Update emitter.
2104  brancherPtr->reset(brancherPtr->system(), event, i0New, i1New);
2105 
2106  // Update lookup map and erase old keys.
2107  pair<int,bool> key = make_pair(i0Old, true);
2108  if (lookupBrancherFF.find(key)!=lookupBrancherFF.end())
2109  lookupBrancherFF.erase(key);
2110  key = make_pair(i1Old, false);
2111  if (lookupBrancherFF.find(key)!=lookupBrancherFF.end())
2112  lookupBrancherFF.erase(key);
2113  // Add new keys.
2114  key = make_pair(i0New,true);
2115  lookupBrancherFF[key] = i;
2116  key = make_pair(i1New,false);
2117  lookupBrancherFF[key] = i;
2118 
2119  // Update splitters.
2120  if (event[i0Old].isGluon()) {
2121  if (event[i0New].isGluon())
2122  updateSplitter(event,i0Old,i1Old,i0New,i1New,true);
2123  else removeSplitter(i0Old);
2124  }
2125  if (event[i1Old].isGluon()) {
2126  if (event[i1New].isGluon())
2127  updateSplitter(event,i1Old,i0Old,i1New,i0New,false);
2128  else removeSplitter(i1Old);
2129  }
2130  }
2131 
2132  // Remove the antennae out of the list. This way we can check
2133  // later if ISR added a new FF antenna i0/i1 is colour/anticolour.
2134  pair<int,int> pairNow = make_pair(i0New,i1New);
2135  vector< pair<int,int> >::iterator iter;
2136  iter = find (antFF.begin(), antFF.end(), pairNow);
2137  if (iter != antFF.end()) antFF.erase(iter);
2138  }
2139 
2140 
2141  // Is there a FF connection left?
2142  for (int i = 0; i < (int)antFF.size(); i++) {
2143  int i0 = antFF[i].first; // i0/iNew[0] is colour.
2144  int i1 = antFF[i].second; // i1/iNew[2] is anticolour.
2145  // Don't include II or IF antennae.
2146  if (!event[i0].isFinal() || !event[i1].isFinal()) continue;
2147  if (verbose >= superdebug) {
2148  stringstream ss;
2149  ss << "Creating antenna between " << i0 << " , " << i1
2150  << " col = " << event[i0].col();
2151  printOut(__METHOD_NAME__, ss.str());
2152  }
2153  // Store new trial QCD gluon emission antenna.
2154  saveEmitter(iSys, event, i0, i1);
2155  // Store new trial QCD gluon splitting antenna(e).
2156  if (event[i0].isGluon()) saveSplitter(iSys, event, i0, i1, true);
2157  if (event[i1].isGluon()) saveSplitter(iSys, event, i1, i0, false);
2158  }
2159 
2160  // Sanity check.
2161  if (emitters.size() + splitters.size() <= 0) {
2162  if (verbose >= quiteloud)
2163  printOut(__METHOD_NAME__, "WARNING: Did not find any QCD antennae.");
2164  return;
2165  }
2166  if (!check(event)) {
2167  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2168  +": failed update antennae.");
2169  list();
2170  if (verbose >= superdebug) printLookup();
2171  infoPtr->setAbortPartonLevel(true);
2172  return;
2173  }
2174  if (verbose >=debug) {
2175  if (verbose >= louddebug) list();
2176  if (verbose >= superdebug) printLookup();
2177  printOut(__METHOD_NAME__, "end --------------");
2178  }
2179 
2180 }
2181 
2182 //--------------------------------------------------------------------------
2183 
2184 // Select next pT in downwards evolution (TimeShower).
2185 
2186 double VinciaFSR::pTnext(Event& event, double pTevolBegAll,
2187  double pTevolEndAll, bool, bool) {
2188 
2189  // Check if we are supposed to do anything.
2190  if (infoPtr->getAbortPartonLevel() || !isPrepared) return 0.;
2191  if (forceQuit) {
2192  if (verbose >= debug) printOut(__METHOD_NAME__, "User forced quit early.");
2193  return 0.;
2194  }
2195  if (verbose >= debug) printOut(__METHOD_NAME__, "begin --------------");
2196 
2197  // Denote VINCIA scales by "q", PYTHIA ones by "pTevol".
2198  double q2Begin = pow2(pTevolBegAll);
2199  double q2EndAll = pow2(pTevolEndAll);
2200 
2201  // Initialize.
2202  q2WinSav = 0.;
2203  winnerQED = false;
2204  winnerPtr = 0;
2205 
2206  // Generate next gluon-emission trial scale (above qEndAll).
2207  if (doFF && emitters.size() > 0) {
2208  if ( !q2NextEmit(q2Begin, q2EndAll) ) return 0.;
2209  }
2210 
2211  // Generate next gluon-splitting trial scale and compare to current qWin.
2212  if (doFF && splitters.size() > 0) {
2213  if ( !q2NextSplit(q2Begin, q2EndAll) ) return 0.;
2214  }
2215 
2216  // Generate next resonance gluon-emission trial and compare to current qWin.
2217  if (doRF && resEmitters.size() > 0) {
2218  if ( !q2NextResEmit(q2Begin, q2EndAll) ) return 0.;
2219  }
2220 
2221  // Generate nex resonance gluon-splitting trial and compare to current qWin.
2222  if (doRF && resSplitters.size() > 0) {
2223  if ( !q2NextResSplit(q2Begin, q2EndAll) ) return 0.;
2224  }
2225 
2226  // Generate next QED trial scale and compare to current qWin.
2227  if (doQED) {
2228  double q2QED = qedShowerPtr->generateTrialScale(event, q2Begin);
2229  if (q2QED >q2Begin) {
2230  stringstream ss;
2231  ss << "q2Begin = "<<q2Begin<<" q2QED = " << q2QED;
2232  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2233  +": Genereated q2QED > q2Begin.",ss.str());
2234  return 0.;
2235  }
2236  // Check for winning condition.
2237  if (q2QED > q2WinSav && q2QED > q2EndAll) {
2238  q2WinSav = q2QED;
2239  winnerQED = true;
2240  winnerPtr = NULL;
2241  }
2242  }
2243 
2244  // If non-zero branching scale found: continue.
2245  if (q2WinSav > q2EndAll) {
2246  if (verbose >= debug) {
2247  stringstream ss;
2248  if (winnerPtr != 0)
2249  ss << " QCD Winner at scale qWinNow = "
2250  << sqrt(q2WinSav)
2251  << " col = " << event[winnerPtr->i0()].col()
2252  << " in System " << winnerPtr->system()
2253  << " qbegin = "<< pTevolBegAll;
2254  else
2255  ss << "=== QED Winner at scale qWinNow = "
2256  << sqrt(q2WinSav);
2257  printOut(__METHOD_NAME__, ss.str());
2258  }
2259  if (verbose >= superdebug) list();
2260 
2261  // No more branchings. Finalize.
2262  } else {
2263  q2WinSav = 0.0;
2264  if (verbose>=superdebug) event.list();
2265 
2266  // TODO: add back.
2267  // Need to make sure this is only done once per event.
2268  // FSR is done; set the weights.
2269  // weightsPtr->doWeighting();
2270 
2271  // If we have not yet binned a branching scale, bin 0 as the first
2272  // branching scale.
2273  if (verbose >= normal && !firstQBranchBinned) {
2274  if (vinciaHistos.find("1stBranchingQE/eCM") != vinciaHistos.end())
2275  vinciaHistos["1stBranchingQE/eCM"].fill(0);
2276  firstQBranchBinned = true;
2277  }
2278  }
2279  if (verbose >= debug) printOut(__METHOD_NAME__, "end --------------");
2280  return sqrt(q2WinSav);
2281 
2282 }
2283 
2284 //--------------------------------------------------------------------------
2285 
2286 // Branch event, including accept/reject veto (TimeShower).
2287 
2288 bool VinciaFSR::branch(Event& event, bool ){
2289 
2290  // Verbose output.
2291  if (verbose >= debug) printOut(__METHOD_NAME__, "begin --------------");
2292 
2293  // Hand off QED branchings to QED brancher.
2294  if (winnerQED) return branchQED(event);
2295 
2296  // Now handle QCD branchings.
2297  iSysWin = winnerPtr->system();
2298  stateChangeLast = false;
2299  stateChangeSys[iSysWin] = false;
2300  iNewSav = 0;
2301 
2302  // Mark this trial as used so we do not risk reusing it.
2303  winnerPtr->needsNewTrial();
2304  // Find out which branching type we are doing.
2305  iAntWin = winnerPtr->iAntPhys();
2306 
2307  // Count up global number of attempted trials.
2308  ++nTrialsSum;
2309  nTrials[iAntWin]++;
2310 
2311  // Decide whether to accept the trial. Store new particles in pNew
2312  // if keeping.
2313  if (!acceptTrial(event)) {
2314  if (verbose >= debug)
2315  printOut(__METHOD_NAME__, "Trial rejected (failed acceptTrial)");
2316  return false;
2317  }
2318 
2319  // Update event record, add new daughters. Make a copy of the event
2320  // to update (may want to veto)! Make a copy of junction info.
2321  Event newevent = event;
2322  resJunctionInfo junctionInfoCopy;
2323  if (hasResJunction[iSysWin]) junctionInfoCopy=junctionInfo[iSysWin];
2324  if (!updateEvent(newevent,junctionInfoCopy)) {
2325  if (verbose >= loud)
2326  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2327  +": Failed to update event.");
2328  return false;
2329  }
2330 
2331  // Possibility to allow user veto of emission step.
2332  if (canVetoEmission) {
2333  if (userHooksPtr->doVetoFSREmission(event.size(), newevent,
2334  iSysWin,isResonanceSys[iSysWin])) {
2335  if (verbose >= debug) printOut(__METHOD_NAME__, "Trial rejected "
2336  "(failed UserHooks::doVetoFSREmission)");
2337  return false;
2338  }
2339  }
2340  if (doDiagnostics) diagnosticsPtr->checkEvent(iSysWin,newevent,event.size());
2341 
2342  // Everything accepted -> overwrite original event.
2343  event = newevent;
2344  if (hasResJunction[iSysWin]) junctionInfo[iSysWin] = junctionInfoCopy;
2345 
2346  // Update partonSystems.
2347  updatePartonSystems();
2348 
2349  // Check momentum conservation.
2350  if (!vinComPtr->checkCoM(iSysWin,event,partonSystemsPtr)) {
2351  infoPtr->setAbortPartonLevel(true);
2352  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2353  +": Failed momentum conservation test.");
2354  return false;
2355  }
2356 
2357  // Update antennae.
2358  if(!updateAntennae(event)) {
2359  if (verbose >= loud)
2360  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2361  +": Failed to update antennae");
2362  infoPtr->setAbortPartonLevel(true);
2363  return false;
2364  }
2365 
2366  // If diagnostic histograms are on, write in the branching scale.
2367  if (verbose >= normal && !firstQBranchBinned) {
2368  if (vinciaHistos.find("1stBranchingQE/eCM") != vinciaHistos.end())
2369  vinciaHistos["1stBranchingQE/eCM"].fill(sqrt(q2WinSav)/event[0].e());
2370  firstQBranchBinned = true;
2371  }
2372 
2373  // Count the number of branchings in the system.
2374  nBranch[iSysWin]++;
2375  nBranchFSR[iSysWin]++;
2376 
2377  // Do user-defined diagnostics.
2378  if(doDiagnostics) diagnosticsPtr->setnBranchSys(iSysWin,nBranch[iSysWin]);
2379 
2380  // Check the event after each branching.
2381  if (!vinComPtr->showerChecks(event, false)) {
2382  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": Failed shower checks.");
2383  infoPtr->setAbortPartonLevel(true);
2384  return false;
2385  }
2386 
2387  // Statistics for first 10 branchings in first 4 systems
2388  if (iSysWin < 4 && nBranchFSR[iSysWin] < 11 && nBranchFSR[iSysWin]>0) {
2389  qBranch[iSysWin][nBranchFSR[iSysWin]]=sqrt(q2WinSav);
2390  if(iNewSav>0){
2391  pTphys[iSysWin][nBranchFSR[iSysWin]]=event[iNewSav].pT();
2392  }
2393  }
2394 
2395  // Force stop by user (debugging only).
2396  if (allowforceQuit) {
2397  if (nBranchFSR[iSysWin] >= nBranchQuit && nBranchQuit > 0) {
2398  forceQuit = true;
2399  if (verbose >= debug) {
2400  stringstream ss;
2401  ss << "User forced quit after " << nBranchQuit << " emissions.";
2402  printOut(__METHOD_NAME__, ss.str());
2403  }
2404  }
2405  }
2406 
2407  // Done
2408  nTrialsAccepted[iAntWin]++;
2409  stateChangeSys[iSysWin] = true;
2410  stateChangeLast = true;
2411  pTLastAcceptedSav = sqrt(q2WinSav);
2412  if (verbose >= debug) printOut(__METHOD_NAME__, "end --------------");
2413  return true;
2414 
2415 }
2416 
2417 //--------------------------------------------------------------------------
2418 
2419 // Utility to print antenna list; for debug mainly (TimeShower).
2420 
2421 void VinciaFSR::list() const {
2422  // Loop over antenna list and print it.
2423  if (resEmitters.size() + resSplitters.size() +
2424  emitters.size() + splitters.size() == 0) {
2425  cout << " -------- The list of FF antennae is empty -------------------"
2426  "------------------------------------------\n";
2427  return;
2428  }
2429  cout << endl << endl;
2430  for (unsigned int i = 0; i < resEmitters.size(); ++i) {
2431  if (i == 0) resEmitters[i].list("Gluon Resonance Emission Antennae");
2432  else resEmitters[i].list();
2433  }
2434  for (unsigned int i = 0; i < resSplitters.size(); ++i) {
2435  if (i == 0) resSplitters[i].list("Gluon Resonance Splitting Antennae");
2436  else resSplitters[i].list();
2437  }
2438  for (int i = 0; i < (int)emitters.size(); ++i) {
2439  if (i == 0) emitters[i].list("Gluon Emission Antennae");
2440  else emitters[i].list();
2441  }
2442  for (int i = 0; i < (int)splitters.size(); ++i) {
2443  if (i == 0) splitters[i].list("Gluon Splitting Antennae");
2444  else splitters[i].list();
2445  }
2446  cout << " -------- End VINCIA FF Antenna Listing ------------------------"
2447  "----------------------------------\n";
2448 
2449 }
2450 
2451 //--------------------------------------------------------------------------
2452 
2453 // Initialise pointers to Vincia objects.
2454 
2455 void VinciaFSR::initVinciaPtrs(Colour* colourPtrIn,
2456  shared_ptr<VinciaISR> isrPtrIn, QEDShower* qedPtrIn,MECs* mecsPtrIn,
2457  Resolution* resolutionPtrIn, VinciaCommon* vinComPtrIn,
2458  VinciaWeights* vinWeightsPtrIn) {
2459  colourPtr = colourPtrIn;
2460  isrPtr = isrPtrIn;
2461  qedShowerPtr = qedPtrIn;
2462  mecsPtr = mecsPtrIn;
2463  resolutionPtr = resolutionPtrIn;
2464  vinComPtr = vinComPtrIn;
2465  weightsPtr = vinWeightsPtrIn;
2466 }
2467 
2468 //--------------------------------------------------------------------------
2469 
2470 // Print header information (version, settings, parameters, etc.).
2471 
2472 void VinciaFSR::header() {
2473 
2474  // Must be initialised before printing header.
2475  if (!isInit) return;
2476 
2477  // Avoid printing header several times.
2478  if (headerIsPrinted) return;
2479  headerIsPrinted = true;
2480 
2481  cout <<setprecision(3);
2482  cout.setf(ios::left);
2483  cout << "\n";
2484  cout << " *------- VINCIA Global Initialization ------"
2485  << "-------------------------------------------------*\n";
2486 
2487  // Print header information about shower.
2488  cout << " |\n";
2489  cout << " | QCD Shower: doII,doIF,doFF,doRF = "
2490  << bool2str(doII,3) <<","<<bool2str(doIF,3)
2491  <<","<<bool2str(doFF,3)<<","<<bool2str(doRF,3)
2492  <<"\n";
2493  cout << " | nGluonToQuark (FSR) = "
2494  << num2str(settingsPtr->mode("Vincia:nGluonToQuark"),9)<<"\n";
2495  cout << " | convertGluonToQuark (ISR) = "
2496  << bool2str(settingsPtr->flag("Vincia:convertGluonToQuark"),9)<<"\n";
2497  cout << " | convertQuarkToGluon (ISR) = "
2498  << bool2str(settingsPtr->flag("Vincia:convertQuarkToGluon"),9)<<"\n";
2499  cout << " | helicityShower = "
2500  << bool2str(settingsPtr->flag("Vincia:helicityShower"),9)<<"\n";
2501  cout << " | sectorShower = "
2502  << bool2str(settingsPtr->flag("Vincia:sectorShower"),9)<<"\n";
2503 
2504  // Print header information about alphaS
2505  cout << " |\n"
2506  << " | Alpha_s: alphaS(mZ)|MSbar = "
2507  << num2str(alphaSvalue,9)<<"\n"
2508  << " | order = "
2509  << num2str(alphaSorder,9)<<"\n";
2510  if (alphaSorder >= 1) {
2511  if (useCMW) {
2512  cout << " | LambdaQCD[nF]|MSbar = "
2513  << num2str(vinComPtr->alphaStrong.Lambda3(),9)<<"[3] "
2514  << num2str(vinComPtr->alphaStrong.Lambda4(),7)<<"[4] "
2515  << num2str(vinComPtr->alphaStrong.Lambda5(),7)<<"[5] "
2516  << num2str(vinComPtr->alphaStrong.Lambda6(),7)<<"[6]\n";
2517  cout << " | LambdaQCD[nF]|CMW = "
2518  << num2str(vinComPtr->alphaStrongCMW.Lambda3(),9)<<"[3] "
2519  << num2str(vinComPtr->alphaStrongCMW.Lambda4(),7)<<"[4] "
2520  << num2str(vinComPtr->alphaStrongCMW.Lambda5(),7)<<"[5] "
2521  << num2str(vinComPtr->alphaStrongCMW.Lambda6(),7)<<"[6]\n";
2522  } else {
2523  cout << " | LambdaQCD[nF] = "
2524  << num2str(vinComPtr->alphaStrong.Lambda3(),9)<<"[3] "
2525  << num2str(vinComPtr->alphaStrong.Lambda4(),7)<<"[4] "
2526  << num2str(vinComPtr->alphaStrong.Lambda5(),7)<<"[5] "
2527  << num2str(vinComPtr->alphaStrong.Lambda6(),7)<<"[6]\n";
2528  }
2529  cout << " | useCMW = "
2530  << bool2str(settingsPtr->flag("Vincia:useCMW"),9)<<"\n";
2531  cout << " | renormMultFacEmitF = "
2532  << num2str(settingsPtr->parm("Vincia:renormMultFacEmitF"),9)
2533  <<" (muR prefactor for FSR emissions)\n";
2534  cout << " | renormMultFacSplitF = "
2535  << num2str(settingsPtr->parm("Vincia:renormMultFacSplitF"),9)
2536  <<" (muR prefactor for FSR splittings)\n";
2537  cout << " | renormMultFacEmitI = "
2538  << num2str(settingsPtr->parm("Vincia:renormMultFacEmitI"),9)
2539  <<" (muR prefactor for ISR emissions)\n";
2540  cout << " | renormMultFacSplitI = "
2541  << num2str(settingsPtr->parm("Vincia:renormMultFacSplitI"),9)
2542  <<" (muR prefactor for ISR splittings)\n";
2543  cout << " | renormMultFacConvI = "
2544  << num2str(settingsPtr->parm("Vincia:renormMultFacConvI"),9)
2545  <<" (muR prefactor for ISR conversions)\n";
2546 
2547  cout << " | alphaSmuFreeze = "
2548  << num2str(alphaSmuFreeze,9)<<"\n";
2549  cout << " | alphaSmax = "
2550  << num2str(alphaSmax,9)<<"\n";
2551  }
2552 
2553  // Print header information about IR regularization.
2554  cout << " |\n"
2555  << " | IR Reg.: cutoffScaleEmitFF = "
2556  << num2str(sqrt(q2CutoffEmit),9)<<"\n"
2557  << " | cutoffScaleSplitFF = "
2558  << num2str(sqrt(q2CutoffSplit),9)<<"\n"
2559  << " | cutoffScaleII = "
2560  << num2str(settingsPtr->parm("Vincia:cutoffScaleII"),9)<<"\n"
2561  << " | cutoffScaleIF = "
2562  << num2str(settingsPtr->parm("Vincia:cutoffScaleIF"),9)<<"\n";
2563 
2564  // Information about QED shower, so far main switches only.
2565  cout << " |\n"
2566  << " | QED Shower: doQED = "
2567  << bool2str(doQED,9)<<endl;
2568  if (doQED) {
2569  cout << " | nGammaToQuark = "
2570  <<num2str(settingsPtr->mode("Vincia:nGammaToQuark"),9)<<"\n"
2571  << " | nGammaToLepton = "
2572  <<num2str(settingsPtr->mode("Vincia:nGammaToLepton"),9)<<"\n"
2573  << " | convertGammaToQuark = "
2574  <<bool2str(settingsPtr->flag("Vincia:convertGammaToQuark"),9)<<"\n"
2575  << " | convertQuarkToGamma = "
2576  <<bool2str(settingsPtr->flag("Vincia:convertQuarkToGamma"),9)<<"\n";
2577  }
2578 
2579  // Print header information about antenna functions.
2580  if (verbose >= 2) {
2581  cout<<" |\n"
2582  <<" | AntennaFunctions: "
2583  <<" chargeFactor kineMap"<<endl;
2584  vector<int> iAnt = antSetPtr->getIant();
2585  int modeSLC = settingsPtr->mode("Vincia:modeSLC");
2586 
2587  // FF and RF antennae.
2588  for (int i=0;i<(int)iAnt.size();++i) {
2589  int iAntPhys = iAnt[i];
2590  AntennaFunction* antPtr = antSetPtr->getAnt(iAntPhys);
2591  if (antPtr == nullptr) continue;
2592  // Print antenna name.
2593  cout.setf(ios::left);
2594  cout << setprecision(2);
2595  string antName = antPtr->vinciaName()+" ["+antPtr->humanName()+"]";
2596  cout << " | " << left << setw(32) << antName << " ";
2597  // Print colour/charge factor.
2598  double chargeFac = antPtr->chargeFac();
2599  cout<<fixed<<setw(6)<<chargeFac;
2600  // Put asterisk next to QG colour factor if using -1/NC2 correction.
2601  if (modeSLC == 2) {
2602  if (antPtr->vinciaName() == "Vincia:QGEmitFF" ||
2603  antPtr->vinciaName() == "Vincia:GQEmitFF" ||
2604  antPtr->vinciaName() == "Vincia:QGEmitRF" ||
2605  antPtr->vinciaName() == "Vincia:GQEmitRF") cout << "*";
2606  else cout << " ";
2607  } else cout << " ";
2608  int kineMap = antPtr->kineMap();
2609  cout << " " << right << setw(5) << kineMap << left << "\n";
2610  }
2611 
2612  // II and IF antennae.
2613  AntennaSetISR* antSetISRPtr = isrPtr->antSetPtr;
2614  if (antSetISRPtr != nullptr) {
2615  vector<int> iAntISR = antSetISRPtr->getIant();
2616  for (int i = 0; i < (int)iAntISR.size(); ++i) {
2617  int iAntPhys = iAntISR[i];
2618  AntennaFunctionIX* antPtr = antSetISRPtr->getAnt(iAntPhys);
2619  if (antPtr == nullptr) continue;
2620  // Print antenna name.
2621  cout.setf(ios::left);
2622  cout << setprecision(2) << " | " << left << setw(32)
2623  << antPtr->vinciaName() + " [" + antPtr->humanName() + "]"
2624  << " ";
2625  // Print colour/charge factor.
2626  double chargeFac = antPtr->chargeFac();
2627  cout << fixed << setw(6) << chargeFac;
2628  if (modeSLC == 2) {
2629  if (antPtr->vinciaName() == "Vincia:QGEmitII" ||
2630  antPtr->vinciaName() == "Vincia:GQEmitII" ||
2631  antPtr->vinciaName() == "Vincia:QGEmitIF" ||
2632  antPtr->vinciaName() == "Vincia:GQEmitIF") cout<<"*";
2633  else cout << " ";
2634  } else cout << " ";
2635  int kineMap = antPtr->kineMap();
2636  cout << " " << right << setw(5) << kineMap << left << "\n";
2637  }
2638  if (modeSLC == 2)
2639  cout << " | *: GQ antennae interpolate between "
2640  << "CA and 2CF (modeSLC = 2)" << endl;
2641  }
2642  }
2643  // Print header information about matrix-element Corrections.
2644  mecsPtr->header();
2645 
2646  // Print references.
2647  cout << " |\n";
2648  cout << " |-------------------------------------------"
2649  << "------------------------------------------\n |\n";
2650  cout << " | References :"<<endl;
2651  cout << " | VINCIA : Fischer, Prestel, Ritzmann, Skands, "
2652  << "EPJC76(2016)589, arXiv:1605.06142" << endl;
2653  cout << " | PYTHIA 8 : Sjostrand et al., CPC191(2015)159, "
2654  << "arXiv:1410.3012" << endl;
2655  cout << " |\n *------- End VINCIA Initialization "
2656  << "----------------------------------------------------*\n\n";
2657  cout.setf(ios::right);
2658 
2659 }
2660 
2661 //--------------------------------------------------------------------------
2662 
2663 // Print final statistics information.
2664 
2665 void VinciaFSR::printInfo(bool pluginCall) {
2666 
2667  // Weight info.
2668  if (!isInit) return;
2669  int nTotWeightsInt = weightsPtr->nTotWeights;
2670  int nNonunityInitialWeight = weightsPtr->nNonunityInitialWeight;
2671  int nNegativeInitialWeight = weightsPtr->nNegativeInitialWeight;
2672  int nNonunityWeight = weightsPtr->nNonunityWeight;
2673  int nNegativeWeight = weightsPtr->nNegativeWeight;
2674  double nTotWeights = max(1.0,((double)(nTotWeightsInt)));
2675  vector<double> weightSum = weightsPtr->weightSum;
2676  vector<double> weightMax = weightsPtr->weightsMax;
2677  vector<double> weightMin = weightsPtr->weightsMin;
2678 
2679  cout << "\n";
2680  if (pluginCall)
2681  cout << " *-------- VINCIA FSR and ISR Statistics ----------------"
2682  <<"--------------------------------------------------------*\n";
2683  else
2684  cout << " *-------- VINCIA FSR Statistics ------------------------"
2685  <<"--------------------------------------------------------*\n";
2686  cout << " | "
2687  <<" |\n";
2688  cout << " | "
2689  <<" " << setw(40) << " " << " |\n";
2690  cout << " | Total Number of (accepted) events = "
2691  << num2str(nTotWeightsInt, 9) << setw(40) << " " << " |\n";
2692  cout << " | Number of events with nonunity initial weight = "
2693  << ((nNonunityInitialWeight <= 0) ?
2694  " none " :
2695  num2str(nNonunityInitialWeight, 9)
2696  + " <-- (INITIALLY) WEIGHTED EVENTS")
2697  << setw(8) << " " << " |\n";
2698  cout << " | Number of events with negative initial weight = "
2699  << ((nNegativeInitialWeight <= 0) ? " none"
2700  : num2str(nNegativeWeight, 9))
2701  << setw(40) << " " << " |\n";
2702  cout << " | Number of events with nonunity reweight = "
2703  << ((nNonunityWeight <= 0) ? " none "
2704  : num2str(nNonunityWeight, 9)+" <-- REWEIGHTED EVENTS" )
2705  << setw(18) << " " << " |\n";
2706  cout << " | Number of events with negative reweight = "
2707  << ((nNegativeWeight <= 0) ? " none"
2708  : num2str(min(nNegativeWeight,nNonunityWeight), 9))
2709  << setw(40) << " " << " |\n";
2710  cout << " | "
2711  << " " << setw(40) << " " << " |\n";
2712  cout << " | weight(i) Avg Wt Avg Dev"
2713  << " rms(dev) kUnwt Expected effUnw |\n";
2714  cout << " | This run i = IsUnw <w> <w-1> "
2715  << " 1/<w> Max Wt <w>/MaxWt Min Wt |\n";
2716  cout << " |"<<setw(4)<<" "<<"User settings 0 ";
2717  cout << ((abs(1.0-weightSum[0]/nTotWeights) < TINY) ?
2718  " yes " : " no " );
2719  cout << num2str(weightSum[0]/nTotWeights,9) << " ";
2720  cout << num2str(weightSum[0]/nTotWeights-1.0,9) << " ";
2721  cout << setw(9) << "-" << " ";
2722  cout << ((weightSum[0] != 0.0) ?
2723  num2str(nTotWeights/weightSum[0], 9) : num2str(0.0, 9));
2724  cout << num2str(weightMax[0],14)<<" ";
2725  cout << ((weightMax[0] != 0.0) ? num2str(weightSum[0]/nTotWeights/
2726  weightMax[0],9) : num2str(0.0,9)) << " ";
2727  cout << num2str(weightMin[0],9) << " ";
2728  cout << "|\n";
2729  if (pluginCall) {
2730  cout << " | - - - - FSR only Statistics - - - - - - - - - - - - "
2731  << "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - |\n";
2732  cout << " | "
2733  << " " << setw(40) << " " << " |\n";
2734  }
2735  if (verbose >= 2 && nTrialsSum > 0) {
2736  cout << " | ----------"
2737  << "----------- P(Reject) --------------------"
2738  << setw(15) << "|" << endl;
2739  cout << " | Trial Veto Rates: nTrials nAcc eff Zeta kinMap"
2740  << " Veto Sector IR mMin HQPS"
2741  << setw(15) << "|" << endl;
2742  for (int iAntPhys = 0; iAntPhys < (int)nTrials.size(); ++iAntPhys) {
2743  double nTot = nTrials[iAntPhys];
2744  if (nTot <= 0) continue;
2745  cout << " | " << setw(17);
2746  if (iAntPhys == iQQemitFF) cout << "QQemitFF";
2747  else if (iAntPhys == iQGemitFF) cout << "QGemitFF";
2748  else if (iAntPhys == iGQemitFF) cout << "GQemitFF";
2749  else if (iAntPhys == iGGemitFF) cout << "GGemitFF";
2750  else if (iAntPhys == iGXsplitFF) cout << "GXsplitFF";
2751  else if (iAntPhys == iQQemitRF) cout << "QQemitRF";
2752  else if (iAntPhys == iQGemitRF) cout << "QGemitRF";
2753  else if (iAntPhys == iXGsplitRF) cout << "XGsplitRF";
2754  cout << fixed<<setprecision(2)
2755  << " "<< num2str(int(nTot+0.5), 9)
2756  << " "<< num2str(int(nTrialsAccepted[iAntPhys]+0.5), 8)
2757  << " " << nTrialsAccepted[iAntPhys]/nTot
2758  << " " << nFailedHull[iAntPhys]*1.0/max(1., nTot);
2759  nTot -= nFailedHull[iAntPhys];
2760  cout << " " << nFailedKine[iAntPhys]*1.0/max(1., nTot);
2761  nTot -= nFailedKine[iAntPhys];
2762  cout << " " << nFailedVeto[iAntPhys]*1.0/max(1., nTot);
2763  nTot -= nFailedVeto[iAntPhys];
2764  cout << " " << nSectorReject[iAntPhys]*1.0/max(1., nTot);
2765  nTot -= nSectorReject[iAntPhys];
2766  cout << " " << nFailedCutoff[iAntPhys]*1.0/max(1., nTot);
2767  nTot -= nFailedCutoff[iAntPhys];
2768  cout << " " << nFailedMass[iAntPhys]*1.0/max(1., nTot);
2769  nTot -= nFailedMass[iAntPhys];
2770  cout << " " << nClosePSforHQ[iAntPhys]*1.0/max(1., nTot);
2771  cout << setw(16) << "|\n";
2772  }
2773  cout << " |" << setw(113) << " " << "|\n";
2774  }
2775  if (!pluginCall)
2776  cout << " *-------- End VINCIA FSR Statistics --------------------"
2777  << "---------------------------------------------------------*\n\n";
2778 
2779 }
2780 
2781 //--------------------------------------------------------------------------
2782 
2783 // Print internal and diagnostic histrograms.
2784 
2785 void VinciaFSR::printHistos() {
2786  for (map<string,Hist>::iterator iH = vinciaHistos.begin();
2787  iH != vinciaHistos.end(); ++iH) {
2788  string Hname=iH->first;
2789  if (vinciaHistos[Hname].getEntries() >= 1)
2790  cout << Hname << vinciaHistos[Hname] << endl;
2791  }
2792 }
2793 
2794 //--------------------------------------------------------------------------
2795 
2796 // Write internal and diagnostic histrograms to file.
2797 
2798 void VinciaFSR::writeHistos(string fileName, string suffix) {
2799  for (map<string,Hist>::const_iterator iH = vinciaHistos.begin();
2800  iH != vinciaHistos.end(); ++iH) {
2801  string Hname=iH->first;
2802  if (vinciaHistos[Hname].getEntries() >= 1) {
2803  string file = sanitizeFileName(
2804  fileName + "-Hist-" + Hname + "." + suffix);
2805  cout << "Writing " << file << endl;
2806  iH->second.table(file);
2807  }
2808  }
2809 }
2810 
2811 //--------------------------------------------------------------------------
2812 
2813 // Get number of branchings in a system (return -1 if no such
2814 // system). If iSys < 0, sum over all.
2815 
2816 int VinciaFSR::getNbranch(int iSys) {
2817  int n = 0;
2818  if (iSys < 0)
2819  for (int i = 0; i < (int)nBranchFSR.size(); ++i) n += nBranchFSR[i];
2820  else if (iSys < (int)nBranchFSR.size()) n = nBranchFSR[iSys];
2821  else n = -1;
2822  return n;
2823 }
2824 
2825 //--------------------------------------------------------------------------
2826 
2827 // Check event.
2828 
2829 bool VinciaFSR::check(Event &event) {
2830  stringstream ss;
2831  for (int i = 0; i < (int)emitters.size(); ++i) {
2832  if (!event[emitters[i].i0()].isFinal()) {
2833  if (verbose > normal){
2834  ss << "Emitter " << i
2835  << " i0 = " << emitters[i].i0() << " not final.";
2836  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2837  +": Failed to update emitter (not final).", ss.str());
2838  }
2839  return false;
2840  } else if (!event[emitters[i].i1()].isFinal()) {
2841  if (verbose > normal) {
2842  ss << "Emitter " << i
2843  << " i1 = " << emitters[i].i1() << " not final.";
2844  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2845  +": Failed to update emitter (not final).", ss.str());
2846  }
2847  return false;
2848  }
2849  }
2850  for (int i = 0; i < (int)splitters.size(); ++i) {
2851  if(!event[splitters[i].i0()].isFinal()){
2852  if (verbose > normal) {
2853  ss << "Splitter " << i
2854  << " i0 = " << splitters[i].i0() << " not final.";
2855  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2856  +": Failed to update splitter (not final).", ss.str());
2857  }
2858  return false;
2859  } else if (!event[splitters[i].i1()].isFinal()) {
2860  if (verbose > normal) {
2861  ss << "Splitter " << i
2862  << " i1 = " << splitters[i].i1() << " not final.";
2863  infoPtr->errorMsg("Error in "+__METHOD_NAME__
2864  +": Failed to update splitter (not final).", ss.str());
2865  }
2866  return false;
2867  }
2868  }
2869  if (verbose > superdebug)
2870  printOut(__METHOD_NAME__, "Passed all checks on antennae.");
2871  return true;
2872 
2873 }
2874 
2875 //--------------------------------------------------------------------------
2876 
2877 // Initialize evolution windows.
2878 
2879 void VinciaFSR::initEvolutionWindows(void){
2880 
2881  evWindowsEmit.clear();
2882  evWindowsSplit.clear();
2883  EvolutionWindow window;
2884  window.alphaSmax = alphaSmax;
2885  window.mass[1] = 0.;
2886  window.mass[2] = 0.;
2887  window.mass[3] = 0.;
2888  window.mass[4] = (nFlavZeroMass >= 4) ? 0.0 : particleDataPtr->m0(4);
2889  window.mass[5] = (nFlavZeroMass >= 5) ? 0.0 : particleDataPtr->m0(5);
2890  window.mass[6] = (nFlavZeroMass >= 6) ? 0.0 : particleDataPtr->m0(6);
2891 
2892  for(int iWindow = 0; iWindow < 4; iWindow++) {
2893  //Get minimum boundaries of window.
2894  double qMinNowEmit=getQ2Window(iWindow, q2CutoffEmit);
2895  double qMinNowSplit=getQ2Window(iWindow ,q2CutoffSplit);
2896 
2897  // Lowest window, use constant trial alphaS for scales below charm mass.
2898  if (iWindow == 0) {
2899  window.b0 = 0.;
2900  window.lambda2 = 0.;
2901  window.kMu2 = 1.;
2902  window.runMode = 0 ;
2903  window.qMin = qMinNowEmit;
2904  evWindowsEmit[qMinNowEmit] = window;
2905  window.qMin = qMinNowSplit;
2906  evWindowsSplit[qMinNowSplit] = window;
2907  } else {
2908  // Emissions.
2909  window.runMode = alphaSorder;
2910  int nFnow = 5;
2911  if (qMinNowEmit < particleDataPtr->m0(4)) nFnow = 3;
2912  else if (qMinNowEmit < particleDataPtr->m0(5)) nFnow = 4;
2913  else if (qMinNowEmit >= particleDataPtr->m0(6)) nFnow = 6;
2914  window.b0 = (33.0 - 2.0*nFnow) / (12.0 * M_PI);
2915  double lambdaNow = getLambda(nFnow,aSemitPtr);
2916  window.lambda2 = (lambdaNow*lambdaNow);
2917  window.kMu2 = aSkMu2Emit;
2918  window.qMin = qMinNowEmit;
2919  evWindowsEmit[qMinNowEmit]=window;
2920  // Splittings.
2921  nFnow = 5;
2922  if (qMinNowSplit < particleDataPtr->m0(4)) nFnow = 3;
2923  else if (qMinNowSplit < particleDataPtr->m0(5)) nFnow = 4;
2924  else if (qMinNowSplit >= particleDataPtr->m0(6)) nFnow = 6;
2925  window.b0 = (33.0 - 2.0*nFnow) / (12.0 * M_PI);
2926  lambdaNow = getLambda(nFnow,aSsplitPtr);
2927  window.lambda2 = (lambdaNow*lambdaNow);
2928  window.kMu2 = aSkMu2Split;
2929  window.qMin = qMinNowSplit;
2930  evWindowsSplit[qMinNowSplit]=window;
2931  }
2932  }
2933 
2934 }
2935 
2936 //--------------------------------------------------------------------------
2937 
2938 // Return window Q2.
2939 
2940 double VinciaFSR::getQ2Window(int iWindow, double q2cutoff){
2941  double qMinNow = 0.;
2942  switch (iWindow) {
2943  case 0:
2944  // [cutoff, mc]
2945  qMinNow = min(sqrt(q2cutoff),particleDataPtr->m0(4));
2946  break;
2947  case 1:
2948  // [mc, mb] with 4-flavour running trial alphaS.
2949  qMinNow = max(1.0,particleDataPtr->m0(4));
2950  break;
2951  case 2:
2952  // [mb, mt] with 5-flavour running trial alphaS.
2953  qMinNow = max(3.0,particleDataPtr->m0(5));
2954  break;
2955  default:
2956  // [>mt] with 6-flavour running trial alphaS.
2957  qMinNow = max(100.0,particleDataPtr->m0(6));
2958  break;
2959  }
2960  return qMinNow;
2961 }
2962 
2963 //--------------------------------------------------------------------------
2964 
2965 // Return Lambda value.
2966 
2967 double VinciaFSR::getLambda(int nFin, AlphaStrong* aSptr) {
2968  if (nFin <= 3) return 0.;
2969  else if (nFin == 4) return aSptr->Lambda4();
2970  else if (nFin == 5) return aSptr->Lambda5();
2971  else return aSptr->Lambda6();
2972 }
2973 
2974 //--------------------------------------------------------------------------
2975 
2976 // Method to return renormalisation-scale prefactor.
2977 
2978 double VinciaFSR::getkMu2(bool isEmit){
2979  double kMu2 = 1.;
2980  if (isEmit) {
2981  kMu2 = aSkMu2Emit;
2982  bool muSoftCorr = false;
2983  if (useCMW && muSoftCorr) {
2984  // TODO: generalize.
2985  double xj = winnerPtr->getXj();
2986  double muSoftInvPow = 4;
2987  double a = 1./muSoftInvPow;
2988  kMu2 = pow(xj,a) * kMu2 + (1.-pow(xj,a));
2989  }
2990  } else kMu2 = aSkMu2Split;
2991  return kMu2;
2992 }
2993 
2994 //--------------------------------------------------------------------------
2995 
2996 // Method to return renormalisation scale. Default scale is kMu *
2997 // evolution scale.
2998 
2999 double VinciaFSR::getMu2(bool isEmit) {
3000  double mu2 = winnerPtr->q2Trial();
3001  double kMu2 = getkMu2(isEmit);
3002  mu2 = max(mu2min, mu2freeze + mu2*kMu2);
3003  return mu2;
3004 }
3005 
3006 //--------------------------------------------------------------------------
3007 
3008 // Reset (or clear) sizes of all containers.
3009 
3010 void VinciaFSR::clearContainers() {
3011  headroomSav.clear();
3012  enhanceSav.clear();
3013  Q2hat.clear();
3014  isHardSys.clear();
3015  isResonanceSys.clear();
3016  doMECsSys.clear();
3017  polarisedSys.clear();
3018  stateChangeSys.clear();
3019  nBranch.clear();
3020  nBranchFSR.clear();
3021  mSystem.clear();
3022  nG.clear();
3023  nQ.clear();
3024  nLep.clear();
3025  nGam.clear();
3026 }
3027 
3028 //--------------------------------------------------------------------------
3029 
3030 // Method to set up antennae, called in prepare.
3031 
3032 bool VinciaFSR::getAntennae(int iSys, Event& event){
3033 
3034  // Sanity check.
3035  if (partonSystemsPtr == nullptr) {
3036  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3037  +": partonSystems pointer is NULL!");
3038  return false;
3039  }
3040  // Reset antenna list for first interaction and for resonance decays
3041  // (don't do this if this is a new system due to MPI).
3042  if (iSys == 0 || partonSystemsPtr->hasInRes(iSys) ||
3043  !partonSystemsPtr->hasInAB(iSys)) {
3044  resEmitters.clear();
3045  resSplitters.clear();
3046  emitters.clear();
3047  splitters.clear();
3048  lookupBrancherRF.clear();
3049  lookupSplitterRF.clear();
3050  lookupBrancherFF.clear();
3051  lookupSplitter.clear();
3052  }
3053  // Check that iSys is a valid value.
3054  if (iSys > partonSystemsPtr->sizeSys()) return false;
3055  // Check that system contains some final state partons.
3056  if (partonSystemsPtr->sizeOut(iSys) == 0) return false;
3057 
3058  // Fetch index of resonance if any.
3059  int iMother = -1;
3060  // Colour information of resonance (will remain negative if no resonance).
3061  int resCol = -1;
3062  int resACol = -1;
3063  int colPartner = -1;
3064  int acolPartner = -1;
3065  if (partonSystemsPtr->hasInRes(iSys)) {
3066  iMother = partonSystemsPtr->getInRes(iSys);
3067  //Check that mother no longer is in system.
3068  if (event[iMother].status() > 0) return false;
3069  resCol = event[iMother].col();
3070  resACol = event[iMother].acol();
3071  }
3072 
3073  // Map of colour index to decay product (Pythia index).
3074  map<int, int> coltoDecID;
3075  // Map of anticolour index to decay product (Pythia index).
3076  map<int, int> aColtoDecID;
3077  // List of all decay products.
3078  vector<int> daughters;
3079 
3080  //Loop over members of current system and get colour information.
3081  Vec4 pSum;
3082  for (int iPart = 0; iPart < partonSystemsPtr->sizeOut(iSys); iPart++) {
3083 
3084  // Sum total FS momentum.
3085  int iOut = partonSystemsPtr->getOut(iSys, iPart);
3086  pSum += event[iOut].p();
3087  // Require final state.
3088  if (!event[iOut].isFinal()) return false;
3089  // Check colour.
3090  if (event[iOut].col() !=0 ) {
3091  // Check if colour partner of a resonance.
3092  if (event[iOut].col() == resCol) colPartner = iOut;
3093  // Otherwise save.
3094  else coltoDecID[event[iOut].col()] = iOut;
3095  }
3096  if (event[iOut].acol() !=0 ) {
3097  // Check if colour partner of a resonance.
3098  if (event[iOut].acol()==resACol) acolPartner = iOut;
3099  // Otherwise save.
3100  else aColtoDecID[event[iOut].acol()] = iOut;
3101  }
3102  // Save all.
3103  if (iOut != colPartner && iOut != acolPartner) daughters.push_back(iOut);
3104  }
3105  double mSys = m(pSum);
3106 
3107  // Check momentum conservation.
3108  Vec4 total(0., 0., 0., 0.);
3109  if (!isResonanceSys[iSys]) {
3110  if (partonSystemsPtr->getInA(iSys) > 0)
3111  total += event[partonSystemsPtr->getInA(iSys)].p();
3112  if (partonSystemsPtr->getInB(iSys) > 0)
3113  total += event[partonSystemsPtr->getInB(iSys)].p();
3114  } else total += event[partonSystemsPtr->getInRes(iSys)].p();
3115  total -= pSum;
3116  total /= mSys;
3117  if (abs(total.e()) > SMALL || abs(total.px()) > SMALL ||
3118  abs(total.py()) > SMALL || abs(total.pz()) > SMALL) {
3119  event.list();
3120  cout << "total = " << setprecision(10) << total.e() << " "
3121  << total.px() << " " << total.py() << " " <<total.pz() << endl;
3122  stringstream ss;
3123  ss << "iSys = " << iSys;
3124  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3125  +": Failed momentum conservation test.", ss.str());
3126  infoPtr->setAbortPartonLevel(true);
3127  return false;
3128  }
3129 
3130  // Store total invariant mass of the final state.
3131  mSystem[iSys] = mSys;
3132 
3133  // Prepare QED shower (above colour resolution scale).
3134  if (doQED) qedShowerPtr->prepare(iSys, event, false);
3135 
3136  // Find any resonance antennae.
3137  if (colPartner > 0) {
3138  // Get a copy of daughters.
3139  vector<int> resSysAll = daughters;
3140  if (acolPartner != colPartner && acolPartner > 0)
3141  resSysAll.push_back(acolPartner);
3142 
3143  // Insert col partner and res at front (just convention).
3144  resSysAll.insert(resSysAll.begin(), colPartner);
3145  resSysAll.insert(resSysAll.begin(), iMother);
3146  unsigned int posRes(0), posPartner(1);
3147  saveResEmitter(iSys, event, resSysAll, posRes, posPartner, true);
3148  if (event[colPartner].isGluon())
3149  saveResSplitter(iSys, event, resSysAll, posRes, posPartner, true);
3150  }
3151  if (acolPartner > 0) {
3152  // Get a copy of daughters.
3153  vector<int> resSysAll = daughters;
3154  if (acolPartner != colPartner && colPartner > 0)
3155  resSysAll.push_back(colPartner);
3156 
3157  // Insert col partner and res at front (just convention).
3158  resSysAll.insert(resSysAll.begin(), acolPartner);
3159  resSysAll.insert(resSysAll.begin(), iMother);
3160  unsigned int posRes(0), posPartner(1);
3161  saveResEmitter(iSys, event, resSysAll, posRes, posPartner, false);
3162  if (event[acolPartner].isGluon())
3163  saveResSplitter(iSys, event, resSysAll, posRes, posPartner, false);
3164  }
3165 
3166  // Find any f-f that are colour connected, but not directly to a
3167  // resonance create normal branchers for these.
3168  for (map<int,int>::iterator it = coltoDecID.begin(); it != coltoDecID.end();
3169  ++it) {
3170  int col = it->first;
3171  int i0 = it->second;
3172  int i1 = aColtoDecID[col];
3173 
3174  // Exclude antennae that are not FF.
3175  if (!event[i0].isFinal() || !event[i1].isFinal()) continue;
3176 
3177  // Add to list of QCD gluon emission trial antennae.
3178  saveEmitter(iSys, event, i0, i1);
3179 
3180  // Add gluon-splitting antennae. Default, same 2->3 antenna
3181  // structure as for gluon emissions.
3182  if (event[i0].isGluon()) saveSplitter(iSys, event, i0, i1, true);
3183  if (event[i1].isGluon()) saveSplitter(iSys, event, i1, i0, false);
3184  }
3185 
3186 
3187  // Deal with any resonance junctions, n.b. assumes that these are
3188  // colour junctions not anticolour.
3189  hasResJunction[iSys] = false;
3190  if (isResonanceSys[iSys] && resCol > 0 && colPartner >0) {
3191  // Loop over junctions.
3192  for (int iJun = 0; iJun < event.sizeJunction(); ++iJun) {
3193  // Loop over ends.
3194  for (int iLeg = 0; iLeg < 3; ++iLeg) {
3195  if (event.endColJunction(iJun, iLeg) == resCol) {
3196  // Found a resonance junction.
3197  hasResJunction[iSys] = true;
3198  junctionInfo[iSys].iJunction=iJun;
3199  junctionInfo[iSys].iEndCol=iLeg;
3200  junctionInfo[iSys].iEndColTag=resCol;
3201  junctionInfo[iSys].iEndQuark=colPartner;
3202  junctionInfo[iSys].colours.clear();
3203  junctionInfo[iSys].colours.push_back(resCol);
3204 
3205  // In context of matching might have many partons in systems
3206  // already.
3207  while (!event[junctionInfo[iSys].iEndQuark].isQuark()) {
3208  int colNow = event[junctionInfo[iSys].iEndQuark].acol();
3209  if (aColtoDecID.find(colNow) != aColtoDecID.end()) {
3210  int newPart = coltoDecID[colNow];
3211  junctionInfo[iSys].colours.push_back(colNow);
3212  junctionInfo[iSys].iEndQuark=newPart;
3213  junctionInfo[iSys].iEndColTag=colNow;
3214  } else {
3215  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3216  +": Resonance involved in junction that cannot be traced.");
3217  hasResJunction[iSys] = false;
3218  break;
3219  }
3220  }
3221  if (event[junctionInfo[iSys].iEndQuark].col() == 0 ||
3222  !event[junctionInfo[iSys].iEndQuark].isFinal()) {
3223  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3224  +": Failed to find end quark in resonance junction.");
3225  hasResJunction[iSys] = false;
3226  break;
3227  }
3228  }
3229  }
3230  }
3231  }
3232 
3233  // Count up number of gluons, quarks, and photons.
3234  nG[iSys] = 0;
3235  nQ[iSys] = 0;
3236  nGam[iSys] = 0;
3237  nLep[iSys] = 0;
3238  for (int i = 0; i < partonSystemsPtr->sizeAll(iSys); ++i) {
3239  Particle* partonPtr = &event[partonSystemsPtr->getAll(iSys, i)];
3240  if (partonPtr->id()==21) nG[iSys]++;
3241  else if (abs(partonPtr->id()) < 7) nQ[iSys]++;
3242  else if (abs(partonPtr->id()) == 22) nGam[iSys]++;
3243  else if (partonPtr->isLepton()) nLep[iSys]++;
3244  }
3245 
3246  // Sanity checks.
3247  if (verbose >= debug) {
3248  if (resEmitters.size() + resSplitters.size() +
3249  emitters.size() + splitters.size() <= 0)
3250  printOut(__METHOD_NAME__, "did not find any QCD antennae.");
3251  else if (verbose >= louddebug) {
3252  list();
3253  if (verbose >= superdebug) printLookup();
3254  }
3255  }
3256  return true;
3257 
3258 }
3259 
3260 //--------------------------------------------------------------------------
3261 
3262 // Set starting scale of shower (power vs wimpy) for system iSys.
3263 
3264 void VinciaFSR::setStartScale(int iSys, Event& event){
3265 
3266  // Set nIn: 1->n or 2->n.
3267  int nIn = 0;
3268  if (isResonanceSys[iSys]) nIn = 1;
3269  else if (partonSystemsPtr->hasInAB(iSys)) nIn = 2;
3270 
3271  // Set FSR starting scale of this system (can be different from qFac).
3272  // Resonance decay systems always start at Q2 = m2..
3273  if (isResonanceSys[iSys]) {
3274  Q2hat[iSys] = pow2(mSystem[iSys]);
3275  return;
3276 
3277  // Hard system: start at phase-space maximum or factorisation scale.
3278  } else if (isHardSys[iSys]) {
3279  if (verbose >= superdebug)
3280  printOut(__METHOD_NAME__, "Setting FSR starting scale for hard system");
3281  // pTmaxMatch = 1 : always start at QF (modulo kFudge).
3282  if (pTmaxMatch == 1) Q2hat[iSys] = pT2maxFudge * infoPtr->Q2Fac();
3283  // pTmaxMatch = 2 : always start at eCM.
3284  else if (pTmaxMatch == 2) Q2hat[iSys] = m2BeamsSav;
3285  // Else check if this event has final-state jets or photons.
3286  else {
3287  bool hasRad = false;
3288  for (int i = 0; i < partonSystemsPtr->sizeOut(iSys); ++i) {
3289  int idAbs = event[partonSystemsPtr->getOut(iSys, i)].idAbs();
3290  if (idAbs <= 5 || idAbs == 21 || idAbs == 22) hasRad = true;
3291  if (idAbs == 6 && nGluonToQuark == 6) hasRad = true;
3292  if (hasRad) break;
3293  }
3294  // If no QCD/QED partons detected, allow to go to phase-space maximum.
3295  if (hasRad) Q2hat[iSys] = pT2maxFudge * infoPtr->Q2Fac();
3296  else Q2hat[iSys] = m2BeamsSav;
3297  }
3298  } else if (nIn == 2) {
3299  if (verbose >= superdebug)
3300  printOut(__METHOD_NAME__, "Setting FSR starting scale of MPI system");
3301  // Set starting scale for MPI systems: min of incoming parton
3302  // scales. Find positions of incoming colliding partons.
3303  int in1 = partonSystemsPtr->getInA(iSys);
3304  int in2 = partonSystemsPtr->getInB(iSys);
3305  Q2hat[iSys] = pT2maxFudgeMPI
3306  * pow2(min(event[in1].scale(),event[in2].scale()));
3307  } else {
3308  // Assume hadron -> partons decay. Starting scale = mSystem.
3309  Q2hat[iSys] = pow2(mSystem[iSys]);
3310  }
3311 
3312 }
3313 
3314 //--------------------------------------------------------------------------
3315 
3316 // Auxiliary methods to generate trial scales for various shower
3317 // components.
3318 
3319 bool VinciaFSR::q2NextResEmit(const double q2Begin, const double q2End) {
3320  if (verbose >= verylouddebug)
3321  printOut(__METHOD_NAME__, "begin --------------");
3322  double q2EndNow = max(q2End, q2CutoffEmit);
3323  bool gen = q2NextBranch<BrancherEmitRF>(resEmitters, evWindowsEmit,
3324  evTypeEmit, q2Begin, q2EndNow, true);
3325  if (verbose >= verylouddebug)
3326  printOut(__METHOD_NAME__, "end --------------");
3327  return gen;
3328 }
3329 
3330 bool VinciaFSR::q2NextResSplit(const double q2Begin, const double q2End) {
3331  if (verbose >= verylouddebug)
3332  printOut(__METHOD_NAME__, "begin --------------");
3333  double q2EndNow = max(q2End, q2CutoffSplit);
3334  bool gen = q2NextBranch<BrancherSplitRF>(resSplitters, evWindowsSplit,
3335  evTypeSplit, q2Begin, q2EndNow, false);
3336  if (verbose >= verylouddebug)
3337  printOut(__METHOD_NAME__,"end --------------");
3338  return gen;
3339 }
3340 
3341 bool VinciaFSR::q2NextEmit(const double q2Begin, const double q2End) {
3342  if (verbose >= verylouddebug)
3343  printOut(__METHOD_NAME__, "begin --------------");
3344  double q2EndNow = max(q2End, q2CutoffEmit);
3345  bool gen = q2NextBranch<BrancherEmitFF>(emitters, evWindowsEmit, evTypeEmit,
3346  q2Begin, q2EndNow, true);
3347  if (verbose >= verylouddebug)
3348  printOut(__METHOD_NAME__,"end --------------");
3349  return gen;
3350 }
3351 
3352 bool VinciaFSR::q2NextSplit(const double q2Begin, const double q2End) {
3353  if (verbose >= verylouddebug)
3354  printOut(__METHOD_NAME__,"begin --------------");
3355  double q2EndNow = max(q2End, q2CutoffSplit);
3356  bool gen = q2NextBranch<BrancherSplitFF>(splitters, evWindowsSplit,
3357  evTypeSplit, q2Begin, q2EndNow, false);
3358  if (verbose >= verylouddebug)
3359  printOut(__METHOD_NAME__,"end --------------");
3360  return gen;
3361 }
3362 
3363 //--------------------------------------------------------------------------
3364 
3365 // Return the Q2 for the next branching.
3366 
3367 template <class Brancher> bool VinciaFSR::q2NextBranch(
3368  vector<Brancher>& brancherVec, const map<double, EvolutionWindow> &evWindows,
3369  const int evType, const double q2Begin, const double q2End, bool isEmit) {
3370 
3371 
3372  // Sanity check
3373  if (verbose >= superdebug) {
3374  stringstream ss;
3375  ss << "qBegin = " << sqrt(q2Begin);
3376  printOut(__METHOD_NAME__, ss.str());
3377  }
3378  if (q2Begin <= q2End) {
3379  if (verbose >= louddebug)
3380  printOut(__METHOD_NAME__, "q2Begin below cutoff. Nothing to do.");
3381  return true;
3382  } else if (!isEmit && nGluonToQuark == 0) return true;
3383 
3384  // Loop over resonance antennae.
3385  unsigned int numAnt = brancherVec.size();
3386  if (verbose >= superdebug) {
3387  stringstream ss;
3388  ss << "Looping over " << numAnt << " antennae.";
3389  printOut(__METHOD_NAME__, ss.str());
3390  }
3391  unsigned int iAnt = 0;
3392  for (typename vector<Brancher>::iterator ibrancher = brancherVec.begin();
3393  ibrancher!=brancherVec.end(); ++ibrancher) {
3394  iAnt++;
3395  if (verbose >= superdebug) {
3396  stringstream ss;
3397  ss << "Antenna " << iAnt <<" / " << numAnt;
3398  printOut(__METHOD_NAME__,ss.str());
3399  }
3400 
3401  //Check if there is any phase space left for current antenna.
3402  double Q2MaxNow = min(q2Begin, ibrancher->getQ2Max(evType));
3403  if (Q2MaxNow < q2End) {
3404  if (verbose >= louddebug) printOut(__METHOD_NAME__,
3405  "No phase space left for current antenna, continuing.");
3406  continue;
3407  }
3408 
3409  // Check if a saved trial exists for this brancher.
3410  double q2Next = 0.;
3411  if (ibrancher->hasTrial()) {
3412  q2Next = ibrancher->q2Trial();
3413  if (verbose >= louddebug) {
3414  stringstream ss;
3415  ss << "Retrieving saved trial Q=" << sqrt(q2Next);
3416  printOut(__METHOD_NAME__, ss.str());
3417  }
3418  // Else generate new trial scale.
3419  } else {
3420  if (verbose >= superdebug)
3421  printOut(__METHOD_NAME__, "Generating new trial");
3422 
3423  // Fetch system and colour factor for current brancher.
3424  int iSys = ibrancher->system();
3425  double colFac = getAnt(ibrancher->iAntPhys())->chargeFac();
3426  if (verbose >= louddebug) {
3427  stringstream ss;
3428  ss << "Starting shower for current brancher at Q=" << sqrt(Q2MaxNow);
3429  printOut(__METHOD_NAME__, ss.str());
3430  }
3431 
3432  // Impose evolution windows (for alphaS running); fetch the
3433  // current window.
3434  map<double, EvolutionWindow>::const_iterator
3435  it = evWindows.lower_bound(sqrt(Q2MaxNow));
3436  // Cast as a reverse iterator to go downwards in q2.
3437  map<double, EvolutionWindow>::const_reverse_iterator itWindowNow(it);
3438 
3439  // Go through regions.
3440  if (verbose >= superdebug)
3441  printOut(__METHOD_NAME__, "Looping over Q2 windows...");
3442  while(itWindowNow != evWindows.rend()) {
3443 
3444  // Bottom of current window.
3445  double Q2MinWindow = pow2(itWindowNow->first);
3446  const EvolutionWindow* windowPtr = &(itWindowNow->second);
3447 
3448  // Set headroom and enhancement factors.
3449  vector<double> headroomVec = getHeadroom(iSys, isEmit, Q2MaxNow);
3450  // For sector showers, use more headroom.
3451  if (sectorShower && isEmit) {
3452  if (ibrancher->colType0() == 2) headroomVec[0] *= 5;
3453  if (ibrancher->colType1() == 2) headroomVec[0] *= 5;
3454  }
3455  vector<double> enhanceVec = getEnhance(iSys, isEmit, Q2MaxNow);
3456  double Q2NextWindow = ibrancher->genQ2(evType, Q2MaxNow, rndmPtr,
3457  windowPtr, colFac, headroomVec, enhanceVec, verbose);
3458  if (Q2NextWindow < 0.) {
3459  infoPtr->setAbortPartonLevel(true);
3460  return false;
3461  }
3462  if (verbose >= superdebug) {
3463  stringstream ss;
3464  ss << "Generated QNextWindow = " << sqrt(Q2NextWindow)
3465  << " (QMinWindow = " << itWindowNow->first << " )";
3466  printOut(__METHOD_NAME__, ss.str());
3467  }
3468 
3469  // Check if Q2next is in the current window.
3470  if (Q2NextWindow > Q2MinWindow || Q2NextWindow <= 0.) {
3471  q2Next=Q2NextWindow;
3472  break;
3473  } else {
3474  if (verbose >= superdebug) printOut(__METHOD_NAME__,
3475  "QNext below window threshold. Continuing to next window.");
3476  }
3477  // Else go straight to next window.
3478  Q2MaxNow = Q2MinWindow;
3479  // Increment reverse iterator (go down in scale).
3480  itWindowNow++;
3481  } // End loop over evolution windows.
3482  if (verbose >= superdebug && itWindowNow == evWindows.rend())
3483  printOut(__METHOD_NAME__, "Out of windows. Continuing to "
3484  "next antenna.");
3485  } // End generate new trial for this antenna.
3486 
3487  // Check for winning condition.
3488  if (q2Next > q2WinSav && q2Next > q2End) {
3489  q2WinSav = q2Next;
3490  winnerPtr = &(*ibrancher);
3491  }
3492  } // End loop over QCD antennae.
3493  return true;
3494 
3495 }
3496 
3497 //--------------------------------------------------------------------------
3498 
3499 // Perform a QED branching.
3500 
3501 bool VinciaFSR::branchQED(Event& event) {
3502 
3503  // QED trial accept.
3504  if (verbose >= debug) printOut(__METHOD_NAME__, "begin --------------");
3505  int sizeOld = event.size();
3506  bool updated = false;
3507  if (qedShowerPtr->checkVeto(event)) {
3508  if (verbose >= debug)
3509  printOut(__METHOD_NAME__, "QED trial accepted. About to update.");
3510  qedShowerPtr->update(event, qedShowerPtr->sysWin());
3511 
3512  // Check momentum conservation.
3513  if (!vinComPtr->checkCoM(qedShowerPtr->sysWin(),event,partonSystemsPtr)) {
3514  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3515  +": Failed (E,p) conservation check.");
3516  infoPtr->setAbortPartonLevel(true);
3517  return false;
3518  }
3519 
3520  // Update QCD branchers after QED emissions.
3521  updated = updateAfterQED(event, sizeOld);
3522 
3523  // Check PartonSystems in debug mode.
3524  if (verbose > quiteloud) {
3525  if (partonSystemsPtr->hasInAB(iSysWin)) {
3526  int inA = partonSystemsPtr->getInA(iSysWin);
3527  int inB = partonSystemsPtr->getInB(iSysWin);
3528  if (inA <= 0 || inB <= 0 ) {
3529  stringstream ss;
3530  ss << "iSysWin = "<<iSysWin << " non-positive. inA = "<< inA
3531  << " inB = " << inB;
3532  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3533  +": Non-positive incoming parton.", ss.str());
3534  infoPtr->setAbortPartonLevel(true);
3535  return false;
3536  } else if (event[inA].mother1() > 2 || event[inB].mother1() > 2) {
3537  stringstream ss;
3538  ss << "iSysWin = "<<iSysWin;
3539  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3540  +": Failed to update incoming particles after QED branching.",
3541  ss.str());
3542  infoPtr->setAbortPartonLevel(true);
3543  return false;
3544  }
3545  }
3546  }
3547 
3548  // Else QED trial failed.
3549  } else {
3550  if (verbose >= debug) printOut(__METHOD_NAME__, "QED trial failed.");
3551  return false;
3552  }
3553 
3554  // Update saved scale of last branching.
3555  pTLastAcceptedSav = sqrt(qedShowerPtr->q2Trial);
3556  if (verbose >= debug) printOut(__METHOD_NAME__, "end --------------");
3557  return updated;
3558 
3559 }
3560 
3561 //--------------------------------------------------------------------------
3562 
3563 // Perform an early antenna rejection.
3564 
3565 bool VinciaFSR::rejectEarly(AntennaFunction* &antFunPtr, bool doMEC) {
3566 
3567  bool reject = true;
3568  if (winnerPtr->getBranchType() < 0) {
3569  if (verbose >= veryloud)
3570  printOut(__METHOD_NAME__, "WARNING: could not identify branching type.");
3571  return reject;
3572  }
3573 
3574  if (doDiagnostics) diagnosticsPtr->setBranchType(winnerPtr->getBranchType());
3575 
3576  // If enhancement was applied to the trial function but branching is
3577  // below enhancement cutoff, we do an early accept/reject here with
3578  // probability trial/enhanced-trial to get back to unenhanced trial
3579  // probability.
3580 
3581  // Trials only enhanced for enhanceFac > 1.
3582  if (winnerPtr->enhanceFac() > 1.0 &&
3583  winnerPtr->q2Trial() <= pow2(enhanceCutoff)) {
3584  if (rndmPtr->flat() > 1./winnerPtr->enhanceFac()) {
3585  if (verbose >= debug) printOut(__METHOD_NAME__,
3586  "Trial rejected (enhance applied below enhanceCutoff)");
3587  return reject;
3588  }
3589  // If passed, save that enhancement factor has now been canceled.
3590  winnerPtr->resetEnhanceFac(1.0);
3591  }
3592 
3593  // Generate post-branching invariants. Can check some vetos already
3594  // at this level, without full kinematics.
3595  vector<double> invariants;
3596  if (!winnerPtr->genInvariants(invariants, rndmPtr, verbose)) {
3597  if (verbose >= debug)
3598  printOut(__METHOD_NAME__, "Trial rejected (failed genInvariants)");
3599  if (doDiagnostics) diagnosticsPtr->checkInvariants(
3600  iSysWin,winnerPtr->iAntPhys(), winnerPtr->getInvariants(),false);
3601  ++nFailedHull[iAntWin];
3602  return reject;
3603  } else {
3604  if (doDiagnostics) diagnosticsPtr->checkInvariants(iSysWin,
3605  winnerPtr->iAntPhys(), invariants, true);
3606  }
3607 
3608  // Impose g->QQ mass thresholds for flavours treated as massless.
3609  if (iAntWin == iGXsplitFF && winnerPtr->idNew() <= nFlavZeroMass) {
3610  // m2(qq) > 4m2q => s(qq) > 2m2q, but allow for larger factor.
3611  // Factor 4 roughly matches n(g->bb) for massive b quarks.
3612  double facM = 4;
3613  if (invariants[1] < facM*pow2(particleDataPtr->m0(winnerPtr->idNew()))) {
3614  ++nFailedMass[iAntWin];
3615  return reject;
3616  }
3617  }
3618 
3619  // Compute physical antenna function (summed over possible helicities).
3620  double antPhys = getAntPhys(antFunPtr);
3621  // Get accept probability.
3622  pAccept[0]=pAcceptCalc(antPhys);
3623  // Do user diagnostics.
3624  if (doDiagnostics) diagnosticsPtr->checkpAccept(iSysWin, pAccept[0]);
3625 
3626  // If doing ME corrections, don't allow to reject yet.
3627  if (!doMEC) {
3628  // Check if rejecting the trial.
3629  double R = rndmPtr->flat();
3630  if (R > pAccept[0]) {
3631  // TODO: Note, here we want to put a call to something which computes
3632  // uncertainty variations for pure-shower branchings. We also
3633  // may want to take into account if there was a enhancement
3634  // applied to this branching.
3635  if (verbose >= debug)
3636  printOut(__METHOD_NAME__, "Trial rejected (failed R<pAccept)");
3637  ++nFailedVeto[iAntWin];
3638  return reject;
3639  }
3640 
3641  // Set accept probability to 1, so no later opportunity to reject
3642  // unles we apply an enhancement factor.
3643  pAccept[0] = 1.;
3644  }
3645 
3646  //Trial accepted so far, n.b. proper acccept/reject condition later.
3647  return false;
3648 
3649 }
3650 
3651 //--------------------------------------------------------------------------
3652 
3653 // Compute physica antenna function.
3654 double VinciaFSR::getAntPhys(AntennaFunction* &antFunPtr) {
3655 
3656  // Set antenna function pointer and check if this antenna is "on".
3657  antFunPtr= getAnt(iAntWin);
3658  if (antFunPtr->chargeFac() <= 0.) {
3659  if (verbose >= veryloud)
3660  printOut(__METHOD_NAME__, "Trial rejected (chargeFac <= 0)");
3661  return 0.;
3662  }
3663  bool isEmit = (iAntWin == iQQemitFF || iAntWin == iQGemitFF ||
3664  iAntWin == iGQemitFF || iAntWin == iGGemitFF ||
3665  iAntWin == iQQemitRF || iAntWin == iQGemitRF);
3666 
3667  // AlphaS, impose default choice. Can differ slighly from trial even
3668  // when running inside trial integral, due to flavor
3669  // thresholds. Here, alphaS(mu) is returned directly, with the
3670  // number of flavors active at mu, whereas the number of flavors in
3671  // the trial integral is controlled by the value of the trial scale.
3672  double alphaSNow = alphaSmax;
3673  if (alphaSorder >= 1) {
3674  double mu2 = getMu2(isEmit);
3675  AlphaStrong * alphaSptr = aSemitPtr;
3676  if(!isEmit) alphaSptr = aSsplitPtr;
3677  alphaSNow = min(alphaSmax, alphaSptr->alphaS(mu2));
3678  }
3679 
3680  // Compute physical antenna function (summed over final state
3681  // helicities). Note, physical antenna function can have swapped
3682  // labels (eg GQ -> GGQ).
3683  vector<double> mPost = winnerPtr->getmPostVec();
3684  vector<double> invariants = winnerPtr->getInvariants();
3685  unsigned int nPre = winnerPtr->iVec().size();
3686  vector<int> hPre = ( helicityShower && polarisedSys[iSysWin] ) ?
3687  winnerPtr->hVec() : vector<int>(nPre, 9);
3688  vector<int> hPost(nPre+1,9);
3689  double antPhys = antFunPtr->antFun(invariants, mPost, hPre, hPost);
3690  if (antPhys < 0.) {
3691  if (verbose > normal) infoPtr->errorMsg("Error in "+__METHOD_NAME__
3692  +": Negative Antenna Function.", num2str(iAntWin));
3693  return 0.;
3694  }
3695  antPhys *= antFunPtr->chargeFac();
3696 
3697  // Check antenna function before multiplying by alphaS.
3698  if (doDiagnostics) diagnosticsPtr->checkAnt(iSysWin, antPhys);
3699  antPhys*=alphaSNow;
3700  return antPhys;
3701 
3702 }
3703 
3704 //--------------------------------------------------------------------------
3705 
3706 // Calculate acceptance probability.
3707 
3708 double VinciaFSR::pAcceptCalc(double antPhys) {
3709  double prob = winnerPtr->pAccept(antPhys,verbose);
3710  if (verbose >= louddebug)
3711  printOut(__METHOD_NAME__,"Shower pAccept = " + num2str(prob));
3712  return prob;
3713 }
3714 
3715 //--------------------------------------------------------------------------
3716 
3717 // Generate the full kinematics.
3718 
3719 bool VinciaFSR::genFullKinematics(int kineMap, Event event,
3720  vector<Vec4> &pPost) {
3721 
3722  // Generate branching kinematics, starting from antenna parents.
3723  vector<Vec4> pPre;
3724  vector<int> iPre = winnerPtr->iVec();
3725  int nPre = iPre.size();
3726  int nPost = winnerPtr->iVec().size() + 1;
3727  vector<double> invariants = winnerPtr->getInvariants();
3728  vector<double> mPost = winnerPtr->getmPostVec();
3729  int branchType = winnerPtr->getBranchType();
3730  double phi = 2 * M_PI * rndmPtr->flat();
3731  for (int i = 0; i < nPre; ++i) pPre.push_back(event[iPre[i]].p());
3732 
3733  // Special case for resonance decay.
3734  if (branchType == 5 || branchType == 6) {
3735  if (!vinComPtr->map2toNRFmassive(pPost, pPre, winnerPtr->posR(),
3736  winnerPtr->posF(), invariants,phi,mPost)) {
3737  if (verbose >= debug)
3738  printOut(__METHOD_NAME__, "Trial rejected (failed map2toNRF)");
3739  ++nFailedKine[iAntWin];
3740  return false;
3741  }
3742  } else {
3743  // 2->3 kinematics.
3744  if (nPre == 2 && nPost == 3) {
3745  if (!vinComPtr->map2to3FF(pPost, pPre, kineMap, invariants, phi,
3746  mPost)) {
3747  if (verbose >= debug)
3748  printOut(__METHOD_NAME__, "Trial rejected (failed map2to3)");
3749  ++nFailedKine[iAntWin];
3750  return false;
3751  }
3752  // 2->4 kinematics
3753  } else if (nPre == 2 && nPost == 4) {
3754  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3755  +": 2->4 kinematics map not implemented yet.");
3756  return false;
3757  // 3->4 kinematics
3758  } else if (nPre == 3 && nPost == 4) {
3759  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3760  +": 3->4 kinematics map not implemented yet.");
3761  return false;
3762  }
3763  }
3764  return true;
3765 
3766 }
3767 
3768 //--------------------------------------------------------------------------
3769 
3770 // Check if a trial is accepted.
3771 
3772 bool VinciaFSR::acceptTrial(Event& event) {
3773  bool accept = false;
3774  bool doMEC = doMECsSys[iSysWin];
3775  AntennaFunction* antFunPtr;
3776 
3777  // Check to see if we veto early before generating full kinematics,
3778  // i.e. just based on invariants.
3779  if (rejectEarly(antFunPtr,doMEC)) return accept;
3780  if (!getNewParticles(event,antFunPtr,pNew)) return accept;
3781 
3782  // Check sector veto.
3783  if (sectorShower) {
3784  vector<Particle> stateNew;
3785  stateNew = mecsPtr->makeParticleList(iSysWin,event,pNew,winnerPtr->iVec());
3786  double q2sector = resolutionPtr->q2sector2to3(&pNew[0],&pNew[2],&pNew[1]);
3787  vector<int> iSctDum;
3788  if (q2sector > resolutionPtr->findSector(iSctDum, stateNew)) {
3789  ++nSectorReject[iAntWin];
3790  return accept;
3791  }
3792  }
3793 
3794  // Check if phase space is closed for getting rid of heavy quarks.
3795  vector<Particle> stateOld;
3796  if (!isrPtr->checkHeavyQuarkPhaseSpace(stateOld,iSysWin)) {
3797  stateOld = mecsPtr->makeParticleList(iSysWin, event);
3798  if (verbose >= debug) printOut(__METHOD_NAME__, "Trial rejected (failed "
3799  "checkHeavyQuarkPhaseSpace)");
3800  // Mark this trial as "used", will need to generate a new one.
3801  ++nClosePSforHQ[iAntWin];
3802  return accept;
3803  }
3804 
3805  // TODO: matrix element corrections. If we want to compute a MEC,
3806  // we make a temporary new event record, and a temporary new
3807  // PartonSystem, with the tentative new state.
3808  double pMEC = 1.0;
3809  if (doMEC) pAccept[0] *= pMEC;
3810 
3811  // Count number of shower-type partons (for diagnostics and headroom
3812  // factors).
3813  int nQbef(0), nGbef(0), nBbef(0);
3814  for (int i = 0; i < partonSystemsPtr->sizeOut(iSysWin); ++i) {
3815  if (event[partonSystemsPtr->getOut(iSysWin,i)].id() == 21) ++nGbef;
3816  else if (event[partonSystemsPtr->getOut(iSysWin,i)].idAbs() <= 4) ++nQbef;
3817  else if (event[partonSystemsPtr->getOut(iSysWin,i)].idAbs() == 5) ++nBbef;
3818  }
3819 
3820  // Fill diagnostics histograms.
3821  if (verbose >= quiteloud || (verbose >= normal && doMEC)) {
3822  string state;
3823  if (nQbef >= 1) state += num2str(nQbef,1) + "q";
3824  if (nBbef >= 1) state += num2str(nBbef,1) + "b";
3825  if (nGbef >= 1) state += num2str(nBbef,1) + "g";
3826  if (pNew[1].colType() == 2) state += "Emit";
3827  else if (pNew[1].colType() == -1) state += "SplitA";
3828  else if (pNew[1].colType() == 1) state += "SplitB";
3829  string HPacc = "Log10(ME/AntTrial):" + state;
3830  if (vinciaHistos.find(HPacc) != vinciaHistos.end())
3831  vinciaHistos[HPacc].fill(log10(max(TINY,pAccept[0])));
3832  string HqTrial = "Ln(q2trial/sSystem):" + state;
3833  if (vinciaHistos.find(HqTrial) != vinciaHistos.end())
3834  vinciaHistos[HqTrial].fill(
3835  log(max(TINY, q2WinSav/pow2(mSystem[iSysWin]))));
3836  }
3837 
3838  // Print MC violations.
3839  if (doMEC && verbose >= verylouddebug) {
3840  stringstream ss;
3841  ss << " MEC pAccept = " << pAccept[0];
3842  printOut(__METHOD_NAME__, ss.str());
3843  }
3844  if (verbose >= loud ) {
3845  bool violation = (pAccept[0] > 1.0 + TINY);
3846  bool negPaccept = (pAccept[0] < 0.0);
3847  if (violation) infoPtr->errorMsg("Error in "+__METHOD_NAME__
3848  +": pAccept > 1");
3849  if (negPaccept) infoPtr->errorMsg("Error in "+__METHOD_NAME__
3850  +": pAccept < 0");
3851  //Print more info for bad cases.
3852  if ((violation || negPaccept) && verbose > debug) winnerPtr->list();
3853  }
3854 
3855  // TODO: MC reweighting and uncertainty bands.
3856 
3857  // Enhance factors < 1 (radiation inhibition) treated by modifying pAccept.
3858  const double enhanceFac = winnerPtr->enhanceFac();
3859  if (rndmPtr->flat() > min(1.0,enhanceFac)*pAccept[0]) {
3860  if (verbose >= debug) printOut(__METHOD_NAME__ , "Trial rejected at veto "
3861  "step. wPhys/wTrial = " + num2str(pAccept[0])
3862  + " * enhanceFac = "+num2str(enhanceFac));
3863 
3864  // Reweighting to account for enhancement factor (reject).
3865  if (enhanceFac != 1.0)
3866  weightsPtr->scaleWeightEnhanceReject(pAccept[0],enhanceFac);
3867 
3868  // Count up number of vetoed branchings
3869  ++nFailedVeto[iAntWin];
3870  } else {
3871  if (verbose >= louddebug) printOut(__METHOD_NAME__, "Trial accepted.");
3872 
3873  // Reweighting to account for enhancement factor (accept).
3874  if (enhanceFac != 1.0) weightsPtr->scaleWeightEnhanceAccept(enhanceFac);
3875 
3876  // Fill diagnostics histos.
3877  if (verbose >= 3 || (verbose >= 2 && doMEC)) {
3878  string state;
3879  if (nQbef >= 1) state += num2str(nQbef,1) + "q";
3880  if (nBbef >= 1) state += num2str(nBbef,1) + "b";
3881  if (nGbef >= 1) state += num2str(nBbef,1) + "g";
3882  if (pNew[1].colType() == 2) state += "Emit";
3883  else if (pNew[1].colType() == -1) state += "SplitA";
3884  else if (pNew[1].colType() == 1) state += "SplitB";
3885  string HqPhys = "Ln(q2/sSystem):" + state;
3886  if (vinciaHistos.find(HqPhys) != vinciaHistos.end())
3887  vinciaHistos[HqPhys].fill(
3888  log(max(TINY, q2WinSav/pow2(mSystem[iSysWin]))));
3889  string HalphaS = "alphaS:" + state;
3890  string HalphaSratio = "alphaSratio:" + state;
3891  if (doMEC) {
3892  string HPacc = "Log10(ME/AntPhys):" + state;
3893  if (vinciaHistos.find(HPacc) != vinciaHistos.end()) {
3894  vinciaHistos[HPacc].fill(log10(max(TINY,pMEC)));
3895  }
3896  }
3897  }
3898  accept = true;
3899  }
3900  return accept;
3901 
3902 }
3903 
3904 //--------------------------------------------------------------------------
3905 
3906 // Generate new particles for the antenna.
3907 
3908 bool VinciaFSR::getNewParticles(Event& event, AntennaFunction* antFunPtr,
3909  vector<Particle>& newParts) {
3910 
3911  // Generate full kinematics.
3912  if (antFunPtr == nullptr) {
3913  if (verbose >= normal)
3914  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3915  +": antFunPtr is NULL pointer.");
3916  return false;
3917  }
3918  newParts.clear();
3919  vector<Vec4> pPost;
3920  int maptype = antFunPtr->kineMap();
3921  if (!genFullKinematics(maptype, event, pPost)) {
3922  if (verbose >= debug)
3923  printOut(__METHOD_NAME__, "Failed to generate kinematics");
3924  return false;
3925  }
3926 
3927  // Generate new helicities.
3928  vector<int> hPost = genHelicities(antFunPtr);
3929  if (pPost.size() != hPost.size()) {
3930  if (verbose >= normal) {
3931  stringstream ss;
3932  ss << " pPost.size() = "
3933  << pPost.size() <<" hPost.size() = " << hPost.size();
3934  infoPtr->errorMsg("Error in "+__METHOD_NAME__
3935  +": Wrong size containers.", ss.str());
3936  }
3937  return false;
3938  } else if (!winnerPtr->getNewParticles(event, pPost, hPost, newParts,
3939  rndmPtr, colourPtr)) {
3940  if (verbose >= debug)
3941  printOut(__METHOD_NAME__, "Failed to generate new particles");
3942  return false;
3943  } else return true;
3944 
3945 }
3946 
3947 //--------------------------------------------------------------------------
3948 
3949 // Generate new helicities for the antenna.
3950 
3951 vector<int> VinciaFSR::genHelicities(AntennaFunction* antFunPtr) {
3952 
3953  vector<int> hPre = winnerPtr->hVec();
3954  vector<int> hPost = hPre;
3955  hPost.insert(hPost.begin() + 1, 9);
3956  if (hPost.size() >=3) {
3957  if (helicityShower && polarisedSys[iSysWin]) {
3958  vector<double> mPost = winnerPtr->getmPostVec();
3959  vector<double> invariants = winnerPtr->getInvariants();
3960  double helSum = antFunPtr->antFun(invariants, mPost, hPre, hPost);
3961  double randHel = rndmPtr->flat() * helSum;
3962  double aHel = 0.0;
3963  // Select helicity, n.b. positions hard-coded. hPost may be
3964  // larger than 3 in case of resonance decays but meaning of
3965  // first 3 positions is same (rest are unchanged).
3966  for(int iHel = 0; iHel < 8; ++iHel) {
3967  hPost[0] = ( (iHel%2) )*2 -1;
3968  hPost[1] = ( (iHel/2)%2 )*2 -1;
3969  hPost[2] = ( (iHel/4)%2 )*2 -1;
3970  aHel = antFunPtr->antFun(invariants, mPost, hPre, hPost);
3971  randHel -= aHel;
3972  if (verbose >= verylouddebug) printOut(__METHOD_NAME__, "antPhys(" +
3973  num2str(int(hPre[0])) + " " + num2str(int(hPre[1])) + " -> " +
3974  num2str(hPost[0]) + " " + num2str(hPost[1]) + " " +
3975  num2str(hPost[2]) + ") = " + num2str(aHel) + ", m(IK,ij,jk) = " +
3976  num2str(sqrt(invariants[0])) + ", " +
3977  num2str(sqrt(invariants[1])) + ", " +
3978  num2str(sqrt(invariants[2])) + "; sum = "+num2str(helSum));
3979  if (randHel < 0.) break;
3980  }
3981  if (doDiagnostics)
3982  diagnosticsPtr->checkAntHel(iSysWin, aHel, hPre, hPost);
3983  }
3984  if (verbose >= louddebug)
3985  printOut(__METHOD_NAME__, "selected"+num2str((int)(hPre[0]))
3986  + " " + num2str(int(hPre[1])) + " -> " + num2str(hPost[0]) + " "
3987  + num2str(hPost[1]) + " " + num2str(hPost[2]) + "\n");
3988  }
3989  return hPost;
3990 
3991 }
3992 
3993 //--------------------------------------------------------------------------
3994 
3995 // Update the event.
3996 
3997 bool VinciaFSR::updateEvent(Event& event, resJunctionInfo& junctionInfoIn) {
3998 
3999  for (unsigned int i = 0; i < pNew.size(); ++i) event.append(pNew[i]);
4000  map<int, pair<int,int> >::iterator it;
4001  for (it = winnerPtr->mothers2daughters.begin();
4002  it != winnerPtr->mothers2daughters.end(); ++it) {
4003  int mother = it->first;
4004  int daughter1 = (it->second).first;
4005  int daughter2 = (it->second).second;
4006  if (mother<event.size() && mother > 0) {
4007  event[mother].daughters(daughter1,daughter2);
4008  event[mother].statusNeg();
4009  } else return false;
4010  }
4011 
4012  // Add mothers to new daughters.
4013  for(it = winnerPtr->daughters2mothers.begin();
4014  it != winnerPtr->daughters2mothers.end(); ++it) {
4015  int daughter = it->first;
4016  int mother1 = (it->second).first;
4017  int mother2 = (it->second).second;
4018  if (daughter<event.size() && daughter > 0)
4019  event[daughter].mothers(mother1, mother2);
4020  else return false;
4021  }
4022 
4023  // Tell Pythia if we used a colour tag.
4024  if (winnerPtr->colTag() != 0) {
4025  int lastTag = event.nextColTag();
4026  int colMax = winnerPtr->colTag();
4027  while (colMax > lastTag) lastTag = event.nextColTag();
4028  }
4029  iNewSav = winnerPtr->iNew();
4030 
4031  // Deal with any resonance junctions.
4032  if (hasResJunction[iSysWin]) {
4033  vector<int>* colours = &junctionInfoIn.colours;
4034  if (!event[junctionInfoIn.iEndQuark].isQuark()) {
4035  infoPtr->errorMsg("Error in "+__METHOD_NAME__
4036  +": Can't update junction. iEndQuark is not a quark!");
4037  hasResJunction[iSysWin]=false;
4038  return false;
4039  }
4040 
4041  // Check if resonance splitting.
4042  int branchType = winnerPtr->getBranchType();
4043  if (branchType == 2 || branchType == 6) {
4044  int splitter = winnerPtr->i0();
4045  if(branchType == 6) splitter = winnerPtr->iVec().at(winnerPtr->posF());
4046  // First update list of colours.
4047  int colLeft = event[splitter].col();
4048  // Find position col index.
4049  vector<int>::iterator pos = find(colours->begin(), colours->end(),
4050  colLeft);
4051  // Check if emission in string.
4052  if (pos != colours->end()) {
4053  // Remove part of string that has split off.
4054  colours->erase(pos + 1, colours->end());
4055  // Now update the junction info.
4056  int d1 = event[splitter].daughter1();
4057  int d2 = event[splitter].daughter2();
4058  if (event[d1].isQuark() && event[d1].col() > 0) {
4059  junctionInfoIn.iEndQuark = d1;
4060  junctionInfoIn.iEndColTag = event[d1].col();
4061  } else if(event[d2].isQuark() && event[d2].col() > 0) {
4062  junctionInfoIn.iEndQuark = d2;
4063  junctionInfoIn.iEndColTag = event[d2].col();
4064  }
4065  // Update junction.
4066  event.endColJunction(junctionInfoIn.iJunction, junctionInfoIn.iEndCol,
4067  junctionInfoIn.iEndColTag);
4068  }
4069  } else if (branchType == 1 || branchType == 5){
4070  //First update list of colours.
4071  int iNew = winnerPtr->iNew();
4072 
4073  // Find radiator (parton whose colours changed).
4074  int iRad = event[iNew].mother1();
4075  if(branchType == 1) {
4076  // Need to test both mothers.
4077  int m2 = event[iNew].mother2();
4078  if (m2 !=0) {
4079  // Get daughter that isn't iNew.
4080  int m2after=event[m2].daughter1();
4081  if (m2after==iNew) m2after = event[m2].daughter2();
4082  //Check, did this mother change colours or was it the
4083  // recoiler?
4084  int colBef = event[m2].col();
4085  int acolBef = event[m2].acol();
4086  int colAfter = event[m2after].col();
4087  int acolAfter = event[m2after].acol();
4088  if(colBef != colAfter || acolBef != acolAfter) iRad = m2;
4089  }
4090  }
4091 
4092  //Find new colour to insert and old colour.
4093  int colNew = 0;
4094  int colLeft = event[iRad].col();
4095  if (event[iNew].col() == colLeft) colNew = event[iNew].acol();
4096  else colNew = event[iNew].col();
4097  if (colNew == 0) {
4098  infoPtr->errorMsg("Error in "+__METHOD_NAME__
4099  +": Couldn't find colour for updating junction info.");
4100  return false;
4101  }
4102 
4103  // Find position of radiator col index.
4104  vector<int>::iterator pos = find(colours->begin(), colours->end(),
4105  colLeft);
4106  if (pos!=colours->end()) colours->insert(pos+1,colNew);
4107 
4108  // Now check if end quark has changed colour.
4109  int iEndQuark = junctionInfoIn.iEndQuark;
4110  if (!event[iEndQuark].isFinal()) {
4111  int d1 = event[iEndQuark].daughter1();
4112  int d2 = event[iEndQuark].daughter2();
4113  if (event[d1].isQuark() && event[d1].col() > 0) {
4114  junctionInfoIn.iEndQuark = d1;
4115  junctionInfoIn.iEndColTag = event[d1].col();
4116  } else if (event[d2].isQuark() && event[d2].col() > 0) {
4117  junctionInfoIn.iEndQuark = d2;
4118  junctionInfoIn.iEndColTag = event[d2].col();
4119  } else {
4120  infoPtr->errorMsg("Error in "+__METHOD_NAME__
4121  +": Couldn't update junction.");
4122  return false;
4123  }
4124  //Update junction.
4125  event.endColJunction(junctionInfoIn.iJunction,
4126  junctionInfoIn.iEndCol, junctionInfoIn.iEndColTag);
4127  }
4128  }
4129  }
4130  if (verbose >= louddebug) {
4131  printOut(__METHOD_NAME__, "Succesfully updated event after emission.");
4132  event.list();
4133  }
4134  return true;
4135 
4136 }
4137 
4138 //--------------------------------------------------------------------------
4139 
4140 // Update the parton systems.
4141 
4142 void VinciaFSR::updatePartonSystems() {
4143 
4144  // List parton systems.
4145  if (verbose >= verylouddebug) {
4146  printOut(__METHOD_NAME__, "Parton systems before update: ");
4147  partonSystemsPtr->list();
4148  }
4149 
4150  // Loop over mothers.
4151  vector<int> newpartons;
4152  for (map<int, pair<int,int> >::iterator it =
4153  winnerPtr->mothers2daughters.begin();
4154  it != winnerPtr->mothers2daughters.end(); ++it) {
4155  int mother = it->first;
4156  int daughter1 = (it->second).first;
4157  int daughter2 = (it->second).second;
4158  // Two identical non-zero daughters -> recoilers, just update.
4159  if (daughter1 == daughter2 && daughter1 != 0 && daughter2 != 0) {
4160  partonSystemsPtr->replace(iSysWin, mother, daughter1);
4161  newpartons.push_back(daughter1);
4162  }
4163  // Two non-identical daughters -> brancher.
4164  else if (daughter1 != daughter2 && daughter1 != 0 && daughter2 != 0) {
4165  // Check if we have already added either daughter.
4166  bool found1 = false;
4167  bool found2 = false;
4168  vector<int>::iterator findit = find(newpartons.begin(), newpartons.end(),
4169  daughter1);
4170  if (findit != newpartons.end()) found1 = true;
4171  findit = find(newpartons.begin(), newpartons.end(), daughter2);
4172  if (findit != newpartons.end()) found2=true;
4173  // Both added already. Just continue.
4174  if (found1 && found2) continue;
4175  // 1 in record already - just update mother with 2.
4176  else if (found1 && !found2) {
4177  partonSystemsPtr->replace(iSysWin, mother, daughter2);
4178  newpartons.push_back(daughter2);
4179  // 2 in record already - just update mother with 1
4180  } else if (!found1 && found2) {
4181  partonSystemsPtr->replace(iSysWin, mother, daughter1);
4182  newpartons.push_back(daughter1);
4183  }
4184  // Neither in record, update mother with 1, add 2.
4185  else {
4186  partonSystemsPtr->replace(iSysWin, mother, daughter1);
4187  partonSystemsPtr->addOut(iSysWin, daughter2);
4188  newpartons.push_back(daughter1);
4189  newpartons.push_back(daughter2);
4190  }
4191  }
4192  }
4193  if (verbose >= verylouddebug) {
4194  printOut(__METHOD_NAME__, "Parton systems after update: ");
4195  partonSystemsPtr->list();
4196  }
4197 
4198 }
4199 
4200 //--------------------------------------------------------------------------
4201 
4202 // Create a new emission brancher.
4203 
4204 void VinciaFSR::saveEmitter(int iSysIn, Event& event, int i0, int i1) {
4205  if (event[i0].col() == event[i1].acol()) {
4206  emitters.push_back(BrancherEmitFF(iSysIn,event,i0,i1));
4207  lookupBrancherFF[make_pair(i0,true)]=(emitters.size()-1);
4208  lookupBrancherFF[make_pair(i1,false)]=(emitters.size()-1);
4209  }
4210 }
4211 
4212 //--------------------------------------------------------------------------
4213 
4214 // Create a new resonance emission brancher.
4215 
4216 void VinciaFSR::saveResEmitter(int iSysIn, Event& event, vector<int> allIn,
4217  unsigned int posResIn, unsigned int posFIn, bool colMode) {
4218 
4219  int iRes = allIn[posResIn];
4220  if (kMapResEmit == 2 && allIn.size() > 3) {
4221  // Save radiator.
4222  allIn.clear();
4223  int iRad = allIn[posFIn];
4224  int iRec = 0;
4225  int d1 = event[iRes].daughter1();
4226  int d2 = event[iRes].daughter2();
4227 
4228  // Find original colour connected.
4229  if (colMode) {
4230  // d2 was original recoiler.
4231  if (event[d1].col() > 0 && event[iRes].col() == event[d1].col())
4232  iRec = event[d2].iBotCopy();
4233  // d1 was original recoiler.
4234  else iRec = event[d1].iBotCopy();
4235  } else {
4236  // d2 was original recoiler.
4237  if(event[d1].acol() > 0 && event[iRes].acol() == event[d1].acol() )
4238  iRec = event[d2].iBotCopy();
4239  // d1 was original recoiler.
4240  else iRec = event[d1].iBotCopy();
4241  }
4242  allIn.push_back(iRes);
4243  allIn.push_back(iRad);
4244  allIn.push_back(iRec);
4245  posResIn=0;
4246  posFIn=1;
4247  }
4248 
4249  // Discriminate between colour and anticolour res antennae to avoid
4250  // degeneracy in lookupBrancherRF0 if res is colour octet.
4251  if (!colMode) iRes *= -1;
4252 
4253  // TODO: how to set zeta cut?
4254  BrancherEmitRF temp(iSysIn,event,allIn,posResIn,posFIn,q2CutoffEmit);
4255  resEmitters.push_back(temp);
4256  lookupBrancherRF[make_pair(iRes,true)]=(resEmitters.size() - 1);
4257  lookupBrancherRF[make_pair(allIn[posFIn],false)]=(resEmitters.size() - 1);
4258 
4259 }
4260 
4261 //--------------------------------------------------------------------------
4262 
4263 // Create a new resonance splitter.
4264 
4265 void VinciaFSR::saveResSplitter(int iSysIn, Event& event, vector<int> allIn,
4266  unsigned int posResIn, unsigned int posFIn,bool colMode) {
4267 
4268  int iRes = allIn[posResIn];
4269  if (kMapResSplit == 2 && allIn.size() > 3) {
4270  // Save radiator.
4271  allIn.clear();
4272  int iRad = allIn[posFIn];
4273  int iRec = 0;
4274  int d1 = event[iRes].daughter1();
4275  int d2 = event[iRes].daughter2();
4276 
4277  // Find original colour connected.
4278  if (colMode) {
4279  // d2 was original recoiler.
4280  if(event[d1].col() > 0 && event[iRes].col() == event[d1].col())
4281  iRec = event[d2].iBotCopy();
4282  // d1 was original recoiler.
4283  else iRec = event[d1].iBotCopy();
4284  } else {
4285  // d2 was original recoiler.
4286  if(event[d1].acol() > 0 && event[iRes].acol() == event[d1].acol())
4287  iRec = event[d2].iBotCopy();
4288  // d1 was original recoiler.
4289  else iRec = event[d1].iBotCopy();
4290  }
4291  allIn.push_back(iRes);
4292  allIn.push_back(iRad);
4293  allIn.push_back(iRec);
4294  posResIn=0;
4295  posFIn=1;
4296  }
4297 
4298  // Discriminate between colour and anticolour res antennae to avoid
4299  // degeneracy in lookupBrancherRF0 if res is colour octet.
4300  if (!colMode) iRes*=-1;
4301  BrancherSplitRF temp(iSysIn,event,allIn,posResIn,posFIn,q2CutoffSplit);
4302  resSplitters.push_back(temp);
4303  lookupSplitterRF[make_pair(iRes,true)]=(resSplitters.size() -1);
4304  lookupSplitterRF[make_pair(allIn[posFIn],false)]=(resSplitters.size() -1);
4305 
4306 }
4307 
4308 //--------------------------------------------------------------------------
4309 
4310 // Create a new splitter brancher.
4311 
4312 void VinciaFSR::saveSplitter(int iSysIn, Event& event, int i0, int i1,
4313  bool col2acol) {
4314  BrancherSplitFF temp(iSysIn, event, i0, i1, col2acol);
4315  splitters.push_back(temp);
4316  if (event[i0].isGluon()) {
4317  // Colour to anti-colour.
4318  if (col2acol) {
4319  lookupSplitter[make_pair(i0,true)]=(splitters.size()-1);
4320  lookupSplitter[make_pair(i1,false)]=(splitters.size()-1);
4321  // Anti-colour to colour.
4322  } else {
4323  lookupSplitter[make_pair(-i0,true)]=(splitters.size()-1);
4324  lookupSplitter[make_pair(-i1,false)]=(splitters.size()-1);
4325  }
4326  }
4327 }
4328 
4329 //--------------------------------------------------------------------------
4330 
4331 // Update the branchers.
4332 
4333 template <class Brancher> void VinciaFSR::updateBranchers(
4334  vector<Brancher>& brancherVec, map<pair<int, bool>,
4335  unsigned int>& lookupBrancher, Event& event, int iOld, int iNew) {
4336 
4337  pair<int,bool> key = make_pair(iOld, true);
4338  if (lookupBrancher.find(key) != lookupBrancher.end()) {
4339  unsigned int pos = lookupBrancher[key];
4340  int iRec = brancherVec[pos].i1();
4341  int iSysNow = brancherVec[pos].system();
4342  brancherVec[pos].reset(iSysNow, event, abs(iNew), iRec);
4343  lookupBrancher.erase(key);
4344  lookupBrancher[make_pair(iNew,true)] = pos;
4345  }
4346  key = make_pair(iOld, false);
4347  if (lookupBrancher.find(key) != lookupBrancher.end()) {
4348  unsigned int pos = lookupBrancher[key];
4349  int iEmit = brancherVec[pos].i0();
4350  int iSysNow = brancherVec[pos].system();
4351  brancherVec[pos].reset(iSysNow, event, iEmit, abs(iNew));
4352  lookupBrancher.erase(key);
4353  lookupBrancher[make_pair(iNew,false)]=pos;
4354  }
4355 
4356 }
4357 
4358 //--------------------------------------------------------------------------
4359 
4360 // Update a single brancher.
4361 
4362 template <class Brancher> void VinciaFSR::updateBrancher(
4363  vector<Brancher>& brancherVec, map<pair<int, bool>,
4364  unsigned int>& lookupBrancher, Event& event, int iOld1, int iOld2,
4365  int iNew1, int iNew2) {
4366 
4367  pair<int,bool> key1 = make_pair(iOld1,true);
4368  pair<int,bool> key2 = make_pair(iOld2,false);
4369  if (lookupBrancher.find(key1) != lookupBrancher.end()) {
4370  unsigned int pos = lookupBrancher[key1];
4371  if (lookupBrancher.find(key2) != lookupBrancher.end()) {
4372  unsigned int pos2=lookupBrancher[key2];
4373  if (pos == pos2) {
4374  lookupBrancher.erase(key1);
4375  lookupBrancher.erase(key2);
4376  int iSysNow = brancherVec[pos].system();
4377  brancherVec[pos].reset(iSysNow, event, abs(iNew1), abs(iNew2));
4378  lookupBrancher[make_pair(iNew1,true)]=pos;
4379  lookupBrancher[make_pair(iNew2,false)]=pos;
4380  }
4381  }
4382  }
4383 
4384 }
4385 
4386 //--------------------------------------------------------------------------
4387 
4388 // Update emission branchers due to a recoiled parton.
4389 
4390 void VinciaFSR::updateEmitters(Event& event, int iOld, int iNew){
4391  updateBranchers<BrancherEmitFF>(emitters,lookupBrancherFF,event,iOld,iNew);
4392 }
4393 
4394 //--------------------------------------------------------------------------
4395 
4396 // Update emission brancher due to an emission.
4397 
4398 void VinciaFSR::updateEmitter(Event& event,int iOld1, int iOld2,
4399  int iNew1, int iNew2) {
4400  updateBrancher<BrancherEmitFF>(emitters, lookupBrancherFF, event,
4401  iOld1, iOld2, iNew1, iNew2);
4402 }
4403 
4404 //--------------------------------------------------------------------------
4405 
4406 // Update splitter branchers due to a recoiled parton.
4407 
4408 void VinciaFSR::updateSplitters(Event& event, int iOld, int iNew) {
4409  updateBranchers<BrancherSplitFF>(splitters, lookupSplitter, event,
4410  iOld, iNew);
4411  updateBranchers<BrancherSplitFF>(splitters, lookupSplitter, event,
4412  -iOld, -iNew);
4413 }
4414 
4415 //--------------------------------------------------------------------------
4416 
4417 // Update splitter brancher due to an emission.
4418 
4419 void VinciaFSR::updateSplitter(Event& event,int iOld1, int iOld2, int iNew1,
4420  int iNew2, bool col2acol) {
4421  if (col2acol) updateBrancher<BrancherSplitFF>(splitters, lookupSplitter,
4422  event, iOld1, iOld2, iNew1, iNew2);
4423  else updateBrancher<BrancherSplitFF>(splitters, lookupSplitter, event,
4424  -iOld1, -iOld2, -iNew1, -iNew2);
4425 }
4426 
4427 //--------------------------------------------------------------------------
4428 
4429 // Remove a splitter due to a gluon that has branched.
4430 
4431 void VinciaFSR::removeSplitter(int iRemove) {
4432 
4433  for (int isign = 0; isign < 2; isign++) {
4434  int sign = 1 - 2*isign;
4435  pair<int,bool> key = make_pair(sign*iRemove, true);
4436 
4437  // Update map.
4438  if (lookupSplitter.find(key) != lookupSplitter.end()) {
4439  unsigned int pos = lookupSplitter[key];
4440  lookupSplitter.erase(key);
4441  int iRec = splitters[pos].i1();
4442  pair<int,bool> recoilkey = make_pair(sign*iRec, false);
4443  if (lookupSplitter.find(recoilkey) != lookupSplitter.end())
4444  lookupSplitter.erase(recoilkey);
4445  if (pos < splitters.size()) {
4446  splitters.erase(splitters.begin()+pos);
4447 
4448  // Update map with modified positions.
4449  for(; pos < splitters.size(); pos++) {
4450  //Get brancher at current pos.
4451  BrancherSplitFF splitter = splitters.at(pos);
4452  // Find indices.
4453  int i0(splitter.i0()), i1(splitter.i1());
4454  // Update lookup map to new pos.
4455  if (!splitter.isXG()){
4456  lookupSplitter[make_pair(i0,true)]=pos;
4457  lookupSplitter[make_pair(i1,false)]=pos;
4458  } else{
4459  lookupSplitter[make_pair(-i0,true)]=pos;
4460  lookupSplitter[make_pair(-i1,false)]=pos;
4461  }
4462  } // End loop over splitters.
4463  }
4464  }
4465  } // End loop over signs.
4466 
4467 }
4468 
4469 //--------------------------------------------------------------------------
4470 
4471 // Update resonance emitter due to changed downstream decay products.
4472 
4473 bool VinciaFSR::updateResBranchers(int iSysRes, Event& event, int iRes) {
4474 
4475  if (verbose >= verylouddebug)
4476  printOut(__METHOD_NAME__, "begin --------------");
4477 
4478  // Look up decay products using partonSystems, assumed to be updated
4479  // already. Colour information of resonance.
4480  int resCol = event[iRes].col();
4481  int resACol = event[iRes].acol();
4482  int colPartner = -1;
4483  int acolPartner = -1;
4484  vector<int> daughters;
4485 
4486  // Loop over members of current decay system and get colour information.
4487  int sizeOut = partonSystemsPtr->sizeOut(iSysRes);
4488  for (int iDecPart = 0; iDecPart < sizeOut; iDecPart++) {
4489  int iOut = partonSystemsPtr->getOut(iSysRes,iDecPart);
4490 
4491  // Check if colouredm partner of the resonance.
4492  if (event[iOut].col() != 0 && event[iOut].col() == resCol)
4493  colPartner = iOut;
4494  if (event[iOut].acol() != 0 && event[iOut].acol() == resACol)
4495  acolPartner = iOut;
4496  if (iOut != colPartner && iOut != acolPartner)
4497  daughters.push_back(iOut);
4498  }
4499  if (verbose >= verylouddebug) {
4500  stringstream ss;
4501  ss << "col partner = " << colPartner << " acol partner = " << acolPartner;
4502  printOut(__METHOD_NAME__,ss.str());
4503  }
4504 
4505  if (colPartner > 0) {
4506  // Get a copy of daughters.
4507  vector<int> resSysAll = daughters;
4508  if (acolPartner != colPartner && acolPartner > 0)
4509  resSysAll.push_back(acolPartner);
4510  // Insert col partner and res at front (just convention).
4511  resSysAll.insert(resSysAll.begin(),colPartner);
4512  resSysAll.insert(resSysAll.begin(),iRes);
4513  unsigned int posRes(0), posPartner(1);
4514  updateResBranchers(iSysRes,event,resSysAll,posRes,posPartner,true);
4515  }
4516  if (acolPartner > 0) {
4517  // Get a copy of daughters.
4518  vector<int> resSysAll = daughters;
4519  if (acolPartner != colPartner && colPartner > 0)
4520  resSysAll.push_back(colPartner);
4521  // Insert col partner and res at front (just convention).
4522  resSysAll.insert(resSysAll.begin(),acolPartner);
4523  resSysAll.insert(resSysAll.begin(),iRes);
4524  unsigned int posRes(0), posPartner(1);
4525  updateResBranchers(iSysRes,event,resSysAll,posRes,posPartner,false);
4526  }
4527  if (verbose >= verylouddebug)
4528  printOut(__METHOD_NAME__, "end --------------");
4529 
4530  return true;
4531 
4532 }
4533 
4534 //--------------------------------------------------------------------------
4535 
4536 // Update resonance emitter due to changed downstream decay products.
4537 
4538 void VinciaFSR::updateResBranchers(int iSysRes, Event& event,
4539  vector<int> resSysAll, unsigned int posRes, unsigned int posPartner,
4540  bool isCol) {
4541 
4542  if (posRes >= resSysAll.size() || posPartner >= resSysAll.size()) {
4543  infoPtr->errorMsg("Error in "+__METHOD_NAME__+": Invalid positions.");
4544  infoPtr->setAbortPartonLevel(true);
4545  return;
4546  }
4547  int iRes = resSysAll[posRes];
4548  int iPartner = resSysAll[posPartner];
4549  int posREmit = posRes;
4550  int posFEmit = posPartner;
4551  int posRSplit = posRes;
4552  int posFSplit = posPartner;
4553  vector<int> resSysAllEmit;
4554  vector<int> resSysAllSplit;
4555 
4556  // If "bad" recoil map need to update recoiler system resSysAll.
4557  if (kMapResEmit == 2 && resSysAll.size() > 3) {
4558  // Fetch daughters of res.
4559  int iRec = 0;
4560  int d1 = event[iRes].daughter1();
4561  int d2 = event[iRes].daughter2();
4562 
4563  // Find original colour connected.
4564  if (isCol) {
4565  // d2 was original recoiler.
4566  if (event[d1].col() > 0 && event[iRes].col() == event[d1].col())
4567  iRec = event[d2].iBotCopy();
4568  // d1 was original recoiler.
4569  else iRec = event[d1].iBotCopy();
4570  } else {
4571  // d2 was original recoiler.
4572  if (event[d1].acol() > 0 && event[iRes].acol() == event[d1].acol())
4573  iRec = event[d2].iBotCopy();
4574  // d1 was original recoiler.
4575  else iRec = event[d1].iBotCopy();
4576  }
4577  resSysAllEmit.push_back(iRes);
4578  resSysAllEmit.push_back(iPartner);
4579  resSysAllEmit.push_back(iRec);
4580  posREmit=0;
4581  posFEmit=1;
4582  } else resSysAllEmit = resSysAll;
4583  if (kMapResSplit == 2) {
4584  resSysAllSplit = resSysAllEmit;
4585  posRSplit=0;
4586  posFSplit=1;
4587  } else resSysAllSplit = resSysAll;
4588  if (!isCol) iRes*=-1;
4589 
4590  // First update emission brancher -> always need to update because
4591  // downstream recoilers will have changed.
4592  pair<int,bool> branchkey = make_pair(iRes, true);
4593  if (lookupBrancherRF.find(branchkey) != lookupBrancherRF.end()) {
4594  unsigned int pos =lookupBrancherRF[branchkey];
4595  int iRec = (resEmitters[pos].iVec())[resEmitters[pos].posF()];
4596  pair<int,bool> recoilkey=make_pair(iRec,false);
4597  // Delete map to recoiler.
4598  if (lookupBrancherRF.find(recoilkey) != lookupBrancherRF.end())
4599  lookupBrancherRF.erase(recoilkey);
4600  // Reset brancher.
4601  resEmitters[pos].resetResBrancher(iSysRes, event, resSysAllEmit, posREmit,
4602  posFEmit,q2CutoffEmit);
4603  // Add new map.
4604  recoilkey = make_pair(iPartner,false);
4605  lookupBrancherRF[recoilkey] = pos;
4606  }
4607 
4608  // Splitters - treatement depends on latest emission.
4609  if (lookupSplitterRF.find(branchkey) != lookupSplitterRF.end()){
4610  unsigned int pos = lookupSplitterRF[branchkey];
4611  int iSplit = (resSplitters[pos].iVec())[resSplitters[pos].posF()];
4612  pair<int,bool> splitkey=make_pair(iSplit,false);
4613 
4614  // Delete map to recoiler.
4615  if (lookupSplitterRF.find(splitkey) != lookupSplitterRF.end())
4616  lookupSplitterRF.erase(splitkey);
4617 
4618  //Do we need to remove this splitter, is the splitter still a gluon?
4619  if (!event[iPartner].isGluon()) {
4620  lookupSplitterRF.erase(branchkey);
4621  resSplitters.erase(resSplitters.begin()+pos);
4622  // Update any other splitters' positions in lookup map.
4623  for (unsigned int ipos = pos; ipos < resSplitters.size(); ipos++) {
4624  BrancherSplitRF splitter = resSplitters.at(ipos);
4625  int itmpSplit = (resSplitters[ipos].iVec())[resSplitters[ipos].posF()];
4626  // Update lookup map to new pos.
4627  lookupSplitterRF[make_pair(iRes,true)] = ipos;
4628  lookupSplitterRF[make_pair(itmpSplit,false)] = ipos;
4629  }
4630  // Otherwise just update.
4631  } else {
4632  resSplitters[pos].resetResBrancher(iSysRes, event, resSysAllSplit,
4633  posRSplit, posFSplit, q2CutoffSplit);
4634  // Add new map.
4635  splitkey = make_pair(iPartner,false);
4636  lookupSplitterRF[splitkey]=pos;
4637  }
4638  // Else if last branch type was res branch add new res splitter.
4639  } else if (winnerPtr!= nullptr) {
4640  if (winnerPtr->getBranchType()==5 && event[iPartner].isGluon())
4641  saveResSplitter(iSysRes,event,resSysAllSplit,posRSplit,posFSplit,isCol);
4642  }
4643 
4644 }
4645 
4646 //--------------------------------------------------------------------------
4647 
4648 // Update the antennae.
4649 
4650 bool VinciaFSR::updateAntennae(Event& event) {
4651 
4652  if (verbose >= debug) {
4653  printOut(__METHOD_NAME__, "begin --------------");
4654  if (verbose >= superdebug) printLookup();
4655  }
4656  if (winnerPtr == nullptr) {
4657  if (verbose >= normal) infoPtr->errorMsg("Error in "+__METHOD_NAME__
4658  +": winnerPtr is NULL");
4659  return false;
4660  }
4661 
4662  // Update QED system(s), then QCD.
4663  if (doQED) qedShowerPtr->update(event, iSysWin);
4664 
4665  // Was this g->ffbar?
4666  int branchType = winnerPtr->getBranchType();
4667  if (branchType == 2) {
4668  // Remove old splitters where g = i0 and update splitters where g is rec.
4669  int splitOld = winnerPtr->i0();
4670  int recOld = winnerPtr->i1();
4671  removeSplitter(splitOld);
4672 
4673  // Get daughters.
4674  int iColSplit = event[splitOld].daughter1();
4675  int iaColSplit = event[splitOld].daughter2();
4676  if(event[iColSplit].col() == 0 && event[iaColSplit].acol() == 0 &&
4677  event[iColSplit].acol() != 0 && event[iaColSplit].col() != 0) {
4678  iColSplit = event[splitOld].daughter2();
4679  iaColSplit = event[splitOld].daughter1();
4680  }
4681 
4682  //Find colour connected partner.
4683  int iColPartner = 0;
4684  int iaColPartner = 0;
4685  pair<int,bool> testkey = make_pair(splitOld,true);
4686  if (lookupBrancherFF.find(testkey) != lookupBrancherFF.end()) {
4687  int iTest = emitters[lookupBrancherFF[testkey]].i1();
4688  if(event[iTest].acol() == event[splitOld].col()) iaColPartner = iTest;
4689  }
4690  testkey = make_pair(splitOld,false);
4691  if (lookupBrancherFF.find(testkey) != lookupBrancherFF.end()) {
4692  int iTest = emitters[lookupBrancherFF[testkey]].i0();
4693  if (event[iTest].col() == event[splitOld].acol()) iColPartner = iTest;
4694  }
4695 
4696  //Update splitters where g is (anti-)colour-connected recoiler/emitter.
4697  updateSplitter(event,iaColPartner,splitOld,iaColPartner,iColSplit,false);
4698  updateSplitter(event,iColPartner,splitOld,iColPartner,iaColSplit,true);
4699  updateEmitter(event,iColPartner,splitOld,iColPartner,iaColSplit);
4700  updateEmitter(event,splitOld,iaColPartner,iColSplit,iaColPartner);
4701 
4702  // Update recoiler.
4703  int recNew = event[recOld].daughter1();
4704  updateSplitters(event,recOld,recNew);
4705  updateEmitters(event,recOld,recNew);
4706  }
4707 
4708  // Emission.
4709  else if (branchType == 1) {
4710  // Update old splitters.
4711  int iOld1 = winnerPtr->i0();
4712  int iOld2 = winnerPtr->i1();
4713  int iNew1 = event[iOld1].daughter1();
4714  int iNew2 = event[iOld1].daughter2();
4715  int iNew3 = event[iOld2].daughter1();
4716 
4717  // Switch 1<->2 so that 2 is repeated daughter.
4718  if (iNew3 == iNew1) {
4719  iNew1=iNew2;
4720  iNew2=iNew3;
4721  iNew3=event[iOld2].daughter2();
4722  } else if (iNew3 == iNew2) iNew3=event[iOld2].daughter2();
4723 
4724  // Update emitters, determine antenna to preserve.
4725  // ab->12.
4726  if (event[iOld1].col() == event[iNew1].col()) {
4727  updateEmitter(event,iOld1,iOld2,iNew1,iNew2);
4728  if(event[iNew2].col() == event[iNew3].acol())
4729  saveEmitter(iSysWin,event,iNew2,iNew3);
4730  // ab->23.
4731  } else {
4732  updateEmitter(event,iOld1,iOld2,iNew2,iNew3);
4733  if(event[iNew1].col()==event[iNew2].acol())
4734  saveEmitter(iSysWin,event,iNew1,iNew2);
4735  }
4736  if (event[iNew1].isGluon())
4737  updateSplitter(event,iOld1,iOld2,iNew1,iNew2,true);
4738  if (event[iNew3].isGluon())
4739  updateSplitter(event,iOld2,iOld1,iNew3,iNew2,false);
4740 
4741  // New splitters.
4742  if (event[iNew2].isGluon()) {
4743  saveSplitter(iSysWin,event,iNew2,iNew3,true);
4744  saveSplitter(iSysWin,event,iNew2,iNew1,false);
4745  }
4746 
4747  // Update other connected-connected antenna, excluding antenna
4748  // which branched.
4749  updateEmitters(event,iOld1,iNew1);
4750  updateEmitters(event,iOld2,iNew3);
4751  updateSplitters(event,iOld1,iNew1);
4752  updateSplitters(event,iOld2,iNew3);
4753 
4754  // Resonance emission.
4755  } else if (branchType == 5 || branchType == 6) {
4756  // Update emitters and splitters.
4757  for (map<int, pair<int, int> >::iterator it =
4758  winnerPtr->mothers2daughters.begin();
4759  it!= winnerPtr->mothers2daughters.end(); ++it){
4760  int mother = it->first;
4761  int daughter1 = (it->second).first;
4762  int daughter2 = (it->second).second;
4763  // Recoiler -> just update.
4764  if (daughter1 == daughter2) {
4765  updateEmitters(event,mother,daughter1);
4766  updateSplitters(event,mother,daughter1);
4767  // Resonance emitter.
4768  } else {
4769  // Convention of res emission: daughter1 is new emission but
4770  // check anyway.
4771  if (branchType == 5 && event[daughter1].isGluon()) {
4772  if (event[daughter1].col()==event[daughter2].acol())
4773  saveEmitter(iSysWin,event,daughter1,daughter2);
4774  else if(event[daughter1].acol()==event[daughter2].col())
4775  saveEmitter(iSysWin,event,daughter2,daughter1);
4776  // TODO: check colour condition here.
4777  bool col2acol = false;
4778  if (event[daughter1].col() == event[daughter2].acol())
4779  col2acol = true;
4780  saveSplitter(iSysWin,event,daughter1,daughter2,col2acol);
4781  updateEmitters(event,mother,daughter2);
4782  updateSplitters(event,mother,daughter2);
4783  // Resonant splitter.
4784  } else if (branchType == 6 && event[mother].isGluon()
4785  && !event[daughter1].isGluon() && !event[daughter2].isGluon()) {
4786  removeSplitter(mother);
4787  int iColSplit = daughter1;
4788  int iaColSplit = daughter2;
4789  if(event[mother].col() != event[daughter1].col()) {
4790  iColSplit = daughter2;
4791  iaColSplit = daughter1;
4792  }
4793 
4794  // Find colour connected partner.
4795  int iColPartner(0), iaColPartner(0);
4796  pair<int,bool> testkey = make_pair(mother,true);
4797  if (lookupBrancherFF.find(testkey) != lookupBrancherFF.end()) {
4798  int iTest = emitters[lookupBrancherFF[testkey]].i1();
4799  if (event[iTest].acol() == event[mother].col())
4800  iaColPartner=iTest;
4801  }
4802  testkey = make_pair(mother,false);
4803  if (lookupBrancherFF.find(testkey) != lookupBrancherFF.end()) {
4804  int iTest = emitters[lookupBrancherFF[testkey]].i0();
4805  if (event[iTest].col() == event[mother].acol())
4806  iColPartner=iTest;
4807  }
4808 
4809  // Update splitters where mother was a
4810  // (anti)colour-connected recoiler/emitter.
4811  updateSplitter(event, iaColPartner, mother, iaColPartner, iColSplit,
4812  false);
4813  updateSplitter(event, iColPartner, mother, iColPartner, iaColSplit,
4814  true);
4815  updateEmitter(event, iColPartner, mother, iColPartner, iaColSplit);
4816  updateEmitter(event, mother, iaColPartner, iColSplit, iaColPartner);
4817 
4818  }
4819  } // End found branching in mothers2daughters.
4820  } // End for loop over mothers2daughters.
4821  } // End resonance brancher case.
4822 
4823  // If system containing resonance has branched, must always update
4824  // (because must update downstream recoilers regardless of if last
4825  // branch was res emission).
4826  if (isResonanceSys[iSysWin]) {
4827  if (!updateResBranchers(iSysWin, event,
4828  partonSystemsPtr->getInRes(iSysWin))){
4829  if (verbose >= normal)
4830  infoPtr->errorMsg("Error in "+__METHOD_NAME__
4831  +": Failed updateResEmitters.");
4832  return false;
4833  }
4834  }
4835  if (verbose >= debug) {
4836  if (verbose >= louddebug) list();
4837  if (verbose >= superdebug) {
4838  printLookup();
4839  if (!check(event)) {
4840  infoPtr->errorMsg("Error in "+__METHOD_NAME__
4841  +": Failed update antennae.");
4842  return false;
4843  }
4844  }
4845  printOut(__METHOD_NAME__, "end --------------");
4846  }
4847  return true;
4848 
4849 }
4850 
4851 //--------------------------------------------------------------------------
4852 
4853 // Update systems of QCD antennae after a QED branching.
4854 
4855 bool VinciaFSR::updateAfterQED(Event& event, int sizeOld) {
4856 
4857  if (verbose >= verylouddebug)
4858  printOut(__METHOD_NAME__, "begin --------------");
4859  bool updated = false;
4860  iSysWin = qedShowerPtr->sysWin();
4861 
4862  // Create colour-anticolour map for post-branching partons.
4863  map<int,int> iOfCol, iOfAcol;
4864  // Also check for coloured partons that were created in the
4865  // splitting, i.e. with status 51, used to create new emission
4866  // antennae below.
4867  vector<int> status51coloured;
4868  vector<pair<int,int> > colouredrecoilers;
4869  for (int i = sizeOld; i < event.size(); ++i) {
4870  int col = event[i].col();
4871  int acol = event[i].acol();
4872  if (col != 0) iOfCol[col] = i;
4873  if (acol != 0) iOfAcol[acol] = i;
4874  // Check which were "created" (as opposed to recoiling) - to see
4875  // if we need to create splitter.
4876  if (event[i].colType() != 0 && event[i].status() == 51)
4877  status51coloured.push_back(i);
4878  else if (event[i].colType() != 0 &&
4879  (event[i].status() == 52 || event[i].status() == 43 ||
4880  event[i].status() == 44)) {
4881  int moth = event[i].mother1();
4882  if (moth > 0) colouredrecoilers.push_back(make_pair(moth, i ));
4883  }
4884  }
4885 
4886  if (status51coloured.size() == 2) {
4887  int i1 = status51coloured[0];
4888  int i2 = status51coloured[1];
4889  int iCol = event[i1].colType() > 0 ? i1 : i2;
4890  int iAcol = event[i1].colType() > 0 ? i2 : i1;
4891  // If this was a splitting to coloured partons, create new
4892  // emission antenna. Create a QCD emission antenna between the two
4893  // status-51 partons.
4894  if (qedShowerPtr->isTrialSplit) saveEmitter(iSysWin,event,iCol,iAcol);
4895  // Need to update existing QCD antennae.
4896  else {
4897  int moth1 = event[i1].mother1();
4898  colouredrecoilers.push_back(make_pair(moth1, i1));
4899  int moth2 = event[i2].mother1();
4900  colouredrecoilers.push_back(make_pair(moth2, i2));
4901  if(event[moth1].col() == event[moth2].acol())
4902  updateEmitter(event,moth1,moth2,i1,i2);
4903  }
4904  } else if (status51coloured.size() == 1) {
4905  int i1 = status51coloured[0];
4906  int moth1 = event[i1].mother1();
4907  colouredrecoilers.push_back(make_pair(moth1, i1));
4908  } else if (status51coloured.size() > 2){
4909  infoPtr->errorMsg("Error in "+__METHOD_NAME__
4910  +": Too many status 51 particles");
4911  infoPtr->setAbortPartonLevel(true);
4912  return false;
4913  }
4914 
4915  // Reset any emission antennae involving quarks that have recoiled.
4916  for(vector<pair<int,int> >::iterator it = colouredrecoilers.begin();
4917  it!= colouredrecoilers.end(); ++it) {
4918  int recOld = it->first;
4919  int recNew = it->second;
4920  updateEmitters(event,recOld,recNew);
4921  updateSplitters(event,recOld,recNew);
4922  }
4923 
4924  // Update resonance antennae.
4925  if (isResonanceSys[iSysWin]){
4926  if (!updateResBranchers(iSysWin, event,
4927  partonSystemsPtr->getInRes(iSysWin))) {
4928  if (verbose >= normal)
4929  infoPtr->errorMsg("Error in "+__METHOD_NAME__
4930  +": Failed updateResEmitters.");
4931  return updated;
4932  }
4933  }
4934 
4935  // Check the event.
4936  if (!check(event)) {
4937  infoPtr->errorMsg("Error in "+__METHOD_NAME__
4938  +": Failed update antennae.");
4939  list();
4940  if (verbose >= superdebug) printLookup();
4941  infoPtr->setAbortPartonLevel(true);
4942  return false;
4943  }
4944 
4945  // Now check if end quark has changed.
4946  if (hasResJunction[iSysWin]) {
4947  int iEndQuark = junctionInfo[iSysWin].iEndQuark;
4948  if (!event[iEndQuark].isFinal()) {
4949  int d1 = event[iEndQuark].daughter1();
4950  int d2 = event[iEndQuark].daughter2();
4951  if (event[d1].isQuark() && event[d1].col() > 0)
4952  junctionInfo[iSysWin].iEndQuark = d1;
4953  else if(event[d2].isQuark() && event[d2].col() > 0)
4954  junctionInfo[iSysWin].iEndQuark = d2;
4955  else {
4956  infoPtr->errorMsg("Error in "+__METHOD_NAME__
4957  +": Couldn't update junction information");
4958  return false;
4959  }
4960  }
4961  }
4962  if (verbose >= verylouddebug)
4963  printOut(__METHOD_NAME__, "end --------------");
4964 
4965  return true;
4966 
4967 }
4968 
4969 //--------------------------------------------------------------------------
4970 
4971 // Print a brancher lookup.
4972 
4973 void VinciaFSR::printLookup(map< pair<int, bool>, unsigned int>
4974  lookupBrancher, string name) {
4975  for (map< pair<int, bool>, unsigned int >::iterator ilook =
4976  lookupBrancher.begin(); ilook != lookupBrancher.end(); ++ilook)
4977  cout << " lookup" << name << "[" << (ilook->first).first
4978  << "," << (ilook->first).second << "] = " << ilook->second << endl;
4979 }
4980 
4981 //--------------------------------------------------------------------------
4982 
4983 // Print the brancher lookup maps.
4984 
4985 void VinciaFSR::printLookup() {
4986  cout << endl << " --------" << " Brancher lookup maps"
4987  << " -------------------------------------------------------------"
4988  << endl;
4989  printLookup(lookupBrancherRF,"BrancherRF");
4990  printLookup(lookupSplitterRF,"SplitterRF");
4991  printLookup(lookupBrancherFF,"BrancherFF");
4992  printLookup(lookupSplitter,"SplitterFF");
4993  cout << " --------" << " End lookup "
4994  <<" -------------------------------------------------------------"
4995  << endl << endl;
4996 }
4997 
4998 //--------------------------------------------------------------------------
4999 
5000 // Calculate the headroom factor.
5001 
5002 vector<double> VinciaFSR::getHeadroom(int iSys, bool isEmit, double) {
5003 
5004  // TODO: ensure a decent number of failed trials if doing uncertainties.
5005  bool doUncert = false;
5006 
5007  // Check if we have we encountered this headroom criterion before.
5008  pair<int, pair<bool,bool> > headroomKey =
5009  make_pair(iSys,make_pair(isEmit,doUncert));
5010  if (headroomSav.find(headroomKey) != headroomSav.end())
5011  return headroomSav[headroomKey];
5012  // Otherwise calculate, and save for next time we need it.
5013  else {
5014  // Emissions.
5015  vector<double> headroomVec;
5016  if (isEmit) {
5017  double headroomFac = 1.0;
5018  // Increased headroom factor if doing MECs and/or uncertainties.
5019  if (doMECsSys[iSys] && mecsPtr->doMEC(iSys,nBranch[iSys]+1)) {
5020  headroomFac = 1.5;
5021  // More headroom for 2->2 than for resonance decays.
5022  if (!isResonanceSys[iSys]) headroomFac *= 2.;
5023  // More headroom for helicity dependence.
5024  if (helicityShower && polarisedSys[iSys]) headroomFac *= 1.5;
5025  }
5026  if (doUncert) headroomFac *= 1.33;
5027  headroomVec.push_back(headroomFac);
5028 
5029  // Other.
5030  } else {
5031  for (int iFlav = 1; iFlav <= nGluonToQuark; ++iFlav) {
5032  double headroomFac = 1.0;
5033  // For sector showers, trial probability should be twice as large.
5034  if (sectorShower) headroomFac *= 2;
5035  // Heavy flavours get 50% larger trial (since mass correction > 0).
5036  if (iFlav > nFlavZeroMass) headroomFac *= 1.5;
5037  // MECs also get increased headroom.
5038  if (doMECsSys[iSys] && mecsPtr->doMEC(iSys,nBranch[iSys]+1)) {
5039  headroomFac *= 2.;
5040  // More headroom for 2->2 than for resonance decays.
5041  if (!isResonanceSys[iSys]) headroomFac *= 2.;
5042  // More headroom for helicity dependence.
5043  if (helicityShower && polarisedSys[iSys]) headroomFac *= 2.;
5044  }
5045  headroomVec.push_back(headroomFac);
5046  }
5047  }
5048  headroomSav[headroomKey] = headroomVec;
5049  return headroomVec;
5050  }
5051 
5052 }
5053 
5054 //--------------------------------------------------------------------------
5055 
5056 // Calculate the enhancement factor.
5057 
5058 vector<double> VinciaFSR::getEnhance(int iSys, bool isEmit, double q2In) {
5059 
5060  bool doEnhance = false;
5061  if (q2In > pow2(enhanceCutoff)) {
5062  if (isHardSys[iSys] && enhanceInHard) doEnhance = true;
5063  else if (isResonanceSys[iSys] && enhanceInResDec) doEnhance = true;
5064  else if (!isHardSys[iSys] && !isResonanceSys[iSys] &&
5065  partonSystemsPtr->hasInAB(iSys) && enhanceInMPI) doEnhance = true;
5066  }
5067 
5068  // Check if we have encountered this enhancement criterion before.
5069  pair<int,pair<bool,bool> > enhanceKey =
5070  make_pair(iSys,make_pair(isEmit,doEnhance));
5071  vector<double> enhanceVec;
5072  if (enhanceSav.find(enhanceKey) != enhanceSav.end())
5073  enhanceVec = enhanceSav[enhanceKey];
5074  else {
5075  double enhanceFac = 1.0;
5076  // Emissions.
5077  if (isEmit) {
5078  if (doEnhance) enhanceFac *= enhanceAll;
5079  enhanceVec.push_back(enhanceFac);
5080  // Other.
5081  } else {
5082  for (int iFlav = 1; iFlav <= nGluonToQuark; ++iFlav) {
5083  if (doEnhance) {
5084  enhanceFac = enhanceAll;
5085  // Optional extra enhancement for g->cc, g->bb.
5086  if (iFlav == 4) enhanceFac *= enhanceCharm;
5087  else if (iFlav == 5) enhanceFac *= enhanceBottom;
5088  }
5089  enhanceVec.push_back(enhanceFac);
5090  }
5091  }
5092  enhanceSav[enhanceKey] = enhanceVec;
5093  }
5094  return enhanceVec;
5095 }
5096 
5097 //==========================================================================
5098 
5099 } // end namespace Pythia8
Definition: AgUStep.h:26