StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
History.cc
1 // History.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // This file is written by Stefan Prestel.
7 // Function definitions (not found in the header) for the
8 // Clustering and History classes.
9 
10 #include "Pythia8/History.h"
11 #include "Pythia8/SharedPointers.h"
12 
13 namespace Pythia8 {
14 
15 //==========================================================================
16 
17 // The Clustering class.
18 
19 //--------------------------------------------------------------------------
20 
21 // Declaration of Clustering class
22 // This class holds information about one radiator, recoiler,
23 // emitted system.
24 // This class is a container class for History class use.
25 
26 // print for debug
27 void Clustering::list() const {
28  cout << " emt " << emitted
29  << " rad " << emittor
30  << " rec " << recoiler
31  << " partner " << partner
32  << " pTscale " << pTscale << endl;
33 }
34 
35 //==========================================================================
36 
37 // The History class.
38 
39 // A History object represents an event in a given step in the CKKW-L
40 // clustering procedure. It defines a tree-like recursive structure,
41 // where the root node represents the state with n jets as given by
42 // the matrix element generator, and is characterized by the member
43 // variable mother being null. The leaves on the tree corresponds to a
44 // fully clustered paths where the original n-jets has been clustered
45 // down to the Born-level state. Also states which cannot be clustered
46 // down to the Born-level are possible - these will be called
47 // incomplete. The leaves are characterized by the vector of children
48 // being empty.
49 
50 //--------------------------------------------------------------------------
51 
52 // Number of trial emission to use for calculating the average number of
53 // emissions
54 const int History::NTRIAL = 1;
55 
56 //--------------------------------------------------------------------------
57 
58 // Declaration of History class
59 // The only constructor. Default arguments are used when creating
60 // the initial history node. The \a depth is the maximum number of
61 // clusterings requested. \a scalein is the scale at which the \a
62 // statein was clustered (should be set to the merging scale for the
63 // initial history node. \a beamAIn and beamBIn are needed to
64 // calcutate PDF ratios, \a particleDataIn to have access to the
65 // correct masses of particles. If \a isOrdered is true, the previous
66 // clusterings has been ordered. \a is the PDF ratio for this
67 // clustering (=1 for FSR clusterings). \a probin is the accumulated
68 // probabilities for the previous clusterings, and \ mothin is the
69 // previous history node (null for the initial node).
70 
71 History::History( int depthIn,
72  double scalein,
73  Event statein,
74  Clustering c,
75  MergingHooksPtr mergingHooksPtrIn,
76  BeamParticle beamAIn,
77  BeamParticle beamBIn,
78  ParticleData* particleDataPtrIn,
79  Info* infoPtrIn,
80  PartonLevel* showersIn,
81  CoupSM* coupSMPtrIn,
82  bool isOrdered = true,
83  bool isStronglyOrdered = true,
84  bool isAllowed = true,
85  bool isNextInInput = true,
86  double probin = 1.0,
87  History * mothin = 0)
88  : state(statein),
89  mother(mothin),
90  selectedChild(-1),
91  sumpath(0.0),
92  sumGoodBranches(0.0),
93  sumBadBranches(0.0),
94  foundOrderedPath(false),
95  foundStronglyOrderedPath(false),
96  foundAllowedPath(false),
97  foundCompletePath(false),
98  scale(scalein),
99  nextInInput(isNextInInput),
100  prob(probin),
101  clusterIn(c),
102  iReclusteredOld(0),
103  iReclusteredNew(),
104  doInclude(true),
105  mergingHooksPtr(mergingHooksPtrIn),
106  beamA(beamAIn),
107  beamB(beamBIn),
108  particleDataPtr(particleDataPtrIn),
109  infoPtr(infoPtrIn),
110  showers(showersIn),
111  coupSMPtr(coupSMPtrIn),
112  probMaxSave(-1.),
113  depth(depthIn),
114  minDepthSave(-1)
115  {
116 
117  // Initialise beam particles
118  setupBeams();
119 
120  // Update probability with PDF ratio
121  if (mother && mergingHooksPtr->includeRedundant()) prob *= pdfForSudakov();
122 
123  // Minimal scalar sum of pT used in Herwig to choose history
124  // Keep track of scalar PT
125  if (mother) {
126  double acoll = (mother->state[clusterIn.emittor].isFinal())
127  ? mergingHooksPtr->herwigAcollFSR()
128  : mergingHooksPtr->herwigAcollISR();
129  sumScalarPT = mother->sumScalarPT + acoll*scale;
130  } else
131  sumScalarPT = 0.0;
132 
133  // Remember reclustered radiator in lower multiplicity state
134  if ( mother ) iReclusteredOld = mother->iReclusteredNew;
135 
136  // Check if more steps should be taken.
137  int nFinalP = 0, nFinalW = 0, nFinalZ = 0;
138  int nL = 0, nA= 0, nH = 0;
139  for ( int i = 0; i < int(state.size()); ++i )
140  if ( state[i].isFinal() ) {
141  if ( state[i].colType() != 0 )
142  nFinalP++;
143  if ( state[i].idAbs() == 23 )
144  nFinalZ++;
145  if ( state[i].idAbs() == 24 )
146  nFinalW++;
147  if ( state[i].idAbs() < 20 && state[i].idAbs() > 10)
148  nL++;
149  if ( state[i].idAbs() == 22)
150  nA++;
151  if ( state[i].idAbs() == 23
152  || state[i].idAbs() == 24
153  || state[i].idAbs() == 25)
154  nH++;
155  }
156  if ( mergingHooksPtr->doWeakClustering()
157  && nFinalP == 2 && nFinalW == 0 && nFinalZ == 0) depth = 0;
158 
159  // Stop clustering at 2->1 massive.
160  // Stop clustering at 2->2 massless.
161 
162  bool qcd = ( nFinalP > mergingHooksPtr->hardProcess->nQuarksOut() );
163 
164  // If this is not the fully clustered state, try to find possible
165  // QCD clusterings.
166  vector<Clustering> clusterings;
167  if ( qcd && depth > 0 ) clusterings = getAllQCDClusterings();
168 
169  bool dow = ( mergingHooksPtr->doWeakClustering()
170  && nFinalP > 1 && nFinalW+nFinalZ > 0 );
171 
172  // If necessary, try to find possible EW clusterings.
173  vector<Clustering> clusteringsEW;
174  // if ( depth > 0 && mergingHooksPtr->doWeakClustering() )
175  if ( depth > 0 && dow )
176  clusteringsEW = getAllEWClusterings();
177  if ( !clusteringsEW.empty() ) {
178  clusterings.insert( clusterings.end(), clusteringsEW.begin(),
179  clusteringsEW.end() );
180  }
181 
182  // If necessary, try to find possible SQCD clusterings.
183  vector<Clustering> clusteringsSQCD;
184  if ( depth > 0 && mergingHooksPtr->doSQCDClustering() )
185  clusteringsSQCD = getAllSQCDClusterings();
186  if ( !clusteringsSQCD.empty() )
187  clusterings.insert( clusterings.end(), clusteringsSQCD.begin(),
188  clusteringsSQCD.end() );
189 
190  // If no clusterings were found, the recursion is done and we
191  // register this node.
192  if ( clusterings.empty() ) {
193  // Multiply with hard process matrix element.
194  prob *= hardProcessME(state);
195  if (registerPath( *this, isOrdered, isStronglyOrdered, isAllowed,
196  depth == 0 )) updateMinDepth(depth);
197  return;
198  }
199 
200  // We'll now order the clusterings in such a way that an ordered
201  // history is found more rapidly. Following the branches with small pT is
202  // a good heuristic, as is following ISR clusterings.
203  multimap<double, Clustering *> sort;
204  for (unsigned int i = 0; i < clusterings.size(); ++i) {
205  double t = clusterings[i].pT();
206  double index = t;
208  //double z = getCurrentZ(clusterings[i].emittor,
209  // clusterings[i].recoiler,
210  // clusterings[i].emitted,
211  // clusterings[i].flavRadBef);
212  //double index = t/z;
213  //if (!state[clusterings[i].emittor].isFinal())
214  // sort.insert(make_pair(-1./index, &clusterings[i]));
215  //else
216  // sort.insert(make_pair(index, &clusterings[i]));
217  sort.insert(make_pair(index, &clusterings[i]));
218  }
219 
220  for ( multimap<double, Clustering *>::iterator it = sort.begin();
221  it != sort.end(); ++it ) {
222 
223  double t = it->second->pT();
224  // If this path is not strongly ordered and we already have found an
225  // ordered path, then we don't need to continue along this path.
226  bool stronglyOrdered = isStronglyOrdered;
227  if ( mergingHooksPtr->enforceStrongOrdering()
228  && ( !stronglyOrdered
229  || ( mother && ( t <
230  mergingHooksPtr->scaleSeparationFactor()*scale ) ))) {
231  if ( onlyStronglyOrderedPaths() ) continue;
232  stronglyOrdered = false;
233  }
234 
235  // Check if reclustering follows ordered sequence.
236  bool ordered = isOrdered;
237  if ( mergingHooksPtr->orderInRapidity()
238  && mergingHooksPtr->orderHistories() ) {
239  // Get new z value
240  double z = getCurrentZ((*it->second).emittor,
241  (*it->second).recoiler,(*it->second).emitted,
242  (*it->second).flavRadBef);
243  // Get z value of splitting that produced this state
244  double zOld = (!mother) ? 0. : mother->getCurrentZ(clusterIn.emittor,
245  clusterIn.recoiler,clusterIn.emitted,
246  clusterIn.flavRadBef);
247  // If this path is not ordered in pT and y, and we already have found
248  // an ordered path, then we don't need to continue along this path.
249  if ( !ordered || ( mother && (t < scale
250  || t < pow(1. - z,2) / (z * (1. - zOld ))*scale ))) {
251  if ( onlyOrderedPaths() ) continue;
252  ordered = false;
253  }
254  } else if ( mergingHooksPtr->orderHistories() ) {
255  // If this path is not ordered in pT and we already have found an
256  // ordered path, then we don't need to continue along this path, unless
257  // we have not yet found an allowed path.
258  if ( !ordered || ( mother && (t < scale) ) ) {
259  if ( depth >= minDepth() && onlyOrderedPaths() && onlyAllowedPaths() )
260  continue;
261  ordered = false;
262  }
263  }
264 
265  // Check if reclustered state should be disallowed.
266  bool doCut = mergingHooksPtr->canCutOnRecState()
267  || mergingHooksPtr->allowCutOnRecState();
268  bool allowed = isAllowed;
269  if ( doCut
270  && mergingHooksPtr->doCutOnRecState(cluster(*it->second)) ) {
271  if ( onlyAllowedPaths() ) continue;
272  allowed = false;
273  }
274 
275  // Skip if this branch is already strongly suppressed.
276  double p = getProb(*it->second);
277  if (abs(p)*prob < 1e-10*probMax()) continue;
278  updateProbMax(abs(p)*prob,depth==0);
279 
280  // Perform the clustering and recurse and construct the next
281  // history node.
282  children.push_back(new History(depth - 1, t, cluster(*it->second),
283  *it->second, mergingHooksPtr, beamA, beamB, particleDataPtr,
284  infoPtr, showers, coupSMPtr, ordered, stronglyOrdered, allowed,
285  true, prob*p, this ));
286  }
287 
288 }
289 
290 //--------------------------------------------------------------------------
291 
292 // Function to project all possible paths onto only the desired paths.
293 
294 bool History::projectOntoDesiredHistories() {
295  // At the moment, only trim histories.
296  return trimHistories();
297 }
298 
299 //--------------------------------------------------------------------------
300 
301 // In the initial history node, select one of the paths according to
302 // the probabilities. This function should be called for the initial
303 // history node.
304 // IN trialShower* : Previously initialised trialShower object,
305 // to perform trial showering and as
306 // repository of pointers to initialise alphaS
307 // PartonSystems* : PartonSystems object needed to initialise
308 // shower objects
309 // OUT double : (Sukadov) , (alpha_S ratios) , (PDF ratios)
310 
311 vector<double> History::weightCKKWL(PartonLevel* trial, AlphaStrong * asFSR,
312  AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN) {
313 
314  if ( mergingHooksPtr->canCutOnRecState() && !foundAllowedPath ) {
315  string message="Warning in History::weightCKKWL: No allowed history";
316  message+=" found. Using disallowed history.";
317  infoPtr->errorMsg(message);
318  }
319  if ( mergingHooksPtr->orderHistories() && !foundOrderedPath ) {
320  string message="Warning in History::weightCKKWL: No ordered history";
321  message+=" found. Using unordered history.";
322  infoPtr->errorMsg(message);
323  }
324  if ( mergingHooksPtr->canCutOnRecState()
325  && mergingHooksPtr->orderHistories()
326  && !foundAllowedPath && !foundOrderedPath ) {
327  string message="Warning in History::weightCKKWL: No allowed or ordered";
328  message+=" history found.";
329  infoPtr->errorMsg(message);
330  }
331 
332  // Read alpha_S in ME calculation and maximal scale (eCM)
333  double asME = infoPtr->alphaS();
334  double aemME = infoPtr->alphaEM();
335  double maxScale = (foundCompletePath) ? infoPtr->eCM()
336  : mergingHooksPtr->muFinME();
337 
338  // Select a path of clusterings
339  History * selected = select(RN);
340 
341  // Set scales in the states to the scales pythia would have set
342  selected->setScalesInHistory();
343 
344  int nWgts = mergingHooksPtr->nWgts;
345  // Get weight.
346  vector<double> sudakov( nWgts, 1. );
347  vector<double> asWeight( nWgts, 1. );
348  vector<double> aemWeight( nWgts, 1. );
349  vector<double> pdfWeight( nWgts, 1. );
350 
351  // Do trial shower, calculation of alpha_S ratios, PDF ratios
352  sudakov = selected->weightTree( trial, asME, aemME, maxScale,
353  selected->clusterIn.pT(), asFSR, asISR, aemFSR, aemISR, asWeight,
354  aemWeight, pdfWeight );
355 
356  // MPI no-emission probability
357  int njetsMaxMPI = mergingHooksPtr->nMinMPI();
358  vector<double> mpiwt = selected->weightTreeEmissions( trial, -1, 0,
359  njetsMaxMPI, maxScale );
360 
361  // Set hard process renormalisation scale to default Pythia value.
362  bool resetScales = mergingHooksPtr->resetHardQRen();
363 
364  // For pure QCD dijet events, evaluate the coupling of the hard process at
365  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
366  // arbitrary scale.
367  if ( resetScales
368  && mergingHooksPtr->getProcessString().compare("pp>jj") == 0) {
369  // Reset to a running coupling. Here we choose FSR for simplicity.
370  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
371  double runningCoupling = (*asFSR).alphaS(newQ2Ren) / asME;
372  for (double& asW: asWeight) asW *= pow2(runningCoupling);
373  } else if (mergingHooksPtr->doWeakClustering()
374  && isQCD2to2(selected->state)) {
375  // Reset to a running coupling. Here we choose FSR for simplicity.
376  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
377  double runningCoupling = (*asFSR).alphaS(newQ2Ren) / asME;
378  for (double& asW: asWeight) asW *= pow2(runningCoupling);
379  }
380 
381  // For W clustering, correct the \alpha_em.
382  if (mergingHooksPtr->doWeakClustering() && isEW2to1(selected->state)) {
383  // Reset to a running coupling. Here we choose FSR for simplicity.
384  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
385  double runningCoupling = (*aemFSR).alphaEM(newQ2Ren) / aemME;
386  for (double& aemW: aemWeight) aemW *= runningCoupling;
387  }
388 
389  // For prompt photon events, evaluate the coupling of the hard process at
390  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
391  // arbitrary scale.
392  if ( resetScales
393  && mergingHooksPtr->getProcessString().compare("pp>aj") == 0) {
394  // Reset to a running coupling. In prompt photon always ISR.
395  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
396  double runningCoupling =
397  (*asISR).alphaS( newQ2Ren + pow(mergingHooksPtr->pT0ISR(),2) ) / asME;
398  for (double& asW: asWeight) asW *= runningCoupling;
399  }
400 
401  // Done
402  vector<double> ret;
403  for (int iVar = 0; iVar < nWgts; ++iVar)
404  ret.push_back(sudakov[iVar]*asWeight[iVar]*aemWeight[iVar]*pdfWeight[iVar]*
405  mpiwt[iVar]);
406  return ret;
407 
408 }
409 
410 //--------------------------------------------------------------------------
411 
412 // Function to return weight of virtual correction and subtractive events
413 // for NL3 merging
414 
415 vector<double> History::weightNL3Loop(PartonLevel* trial, double RN ) {
416 
417  if ( mergingHooksPtr->canCutOnRecState() && !foundAllowedPath ) {
418  string message="Warning in History::weightNL3Loop: No allowed history";
419  message+=" found. Using disallowed history.";
420  infoPtr->errorMsg(message);
421  }
422 
423  // Select a path of clusterings
424  History * selected = select(RN);
425  // Set scales in the states to the scales pythia would have set
426  selected->setScalesInHistory();
427 
428  // So far, no reweighting
429  int nWgts = mergingHooksPtr->nWgts;
430  vector<double> wt( nWgts, 1. );
431 
432  // Only reweighting with MPI no-emission probability
433  double maxScale = (foundCompletePath) ? infoPtr->eCM()
434  : mergingHooksPtr->muFinME();
435  int njetsMaxMPI = mergingHooksPtr->nMinMPI();
436  vector<double> mpiwt = selected->weightTreeEmissions( trial, -1, 0,
437  njetsMaxMPI, maxScale );
438  wt = mpiwt;
439  // Done
440  return wt;
441 }
442 
443 //--------------------------------------------------------------------------
444 
445 // Function to calculate O(\alpha_s)-term of CKKWL-weight for NLO merging
446 
447 vector<double> History::weightNL3First(PartonLevel* trial, AlphaStrong* asFSR,
448  AlphaStrong* asISR, AlphaEM* , AlphaEM* , double RN,
449  Rndm* rndmPtr ) {
450 
451  // Read alpha_S in ME calculation and maximal scale (eCM)
452  double asME = infoPtr->alphaS();
453  double muR = mergingHooksPtr->muRinME();
454  double maxScale = (foundCompletePath)
455  ? infoPtr->eCM()
456  : mergingHooksPtr->muFinME();
457 
458  // Pick path of clusterings
459  History * selected = select(RN);
460  // Set scales in the states to the scales pythia would have set
461  selected->setScalesInHistory();
462 
463  int nSteps = mergingHooksPtr->getNumberOfClusteringSteps(state);
464 
465  // Get the lowest order k-factor and add first two terms in expansion
466  double kFactor = asME * mergingHooksPtr->k1Factor(nSteps);
467 
468  // If using Bbar, which includes a tree-level part, subtract an
469  // additional one, i.e. the O(\as^0) contribution as well
470  double wt = 1. + kFactor;
471 
472  // Calculate sum of O(alpha) terms
473  double wtFirst = selected->weightFirst(trial,asME, muR, maxScale, asFSR,
474  asISR, rndmPtr );
475 
476  // Get starting scale for trial showers.
477  double startingScale = (selected->mother) ? state.scale()
478  : infoPtr->eCM();
479 
480  // Count emissions: New variant
481  // Generate true average, not only one-point
482  bool fixpdf = true;
483  bool fixas = true;
484  double nWeight1 = 0.;
485  for(int i=0; i < NTRIAL; ++i) {
486  // Get number of emissions
487  vector<double> unresolvedEmissionTerm = countEmissions( trial,
488  startingScale, mergingHooksPtr->tms(), 2, asME, asFSR, asISR, 3,
489  fixpdf, fixas );
490  nWeight1 += unresolvedEmissionTerm[1];
491  }
492 
493  wtFirst += nWeight1/double(NTRIAL);
494 
495  // Introduce vector to allow variation of coefficient
496  int nWgts = mergingHooksPtr->nWgts;
497  vector<double> wtVec({wt+wtFirst});
498 
499  // Use the varied scale in the coefficient around which we expand
500  for (int iVar = 1; iVar < nWgts; ++iVar) {
501  double asFix = asFSR->alphaS(pow2(muR*mergingHooksPtr->
502  muRVarFactors[iVar-1])) / asME;
503  wtVec.push_back( wt + asFix*wtFirst );
504  }
505 
506  // Introduce variation of stong coupling that is not done in Born input
507  for ( int iVar = 1; iVar < nWgts; ++iVar ) {
508  double corrFac = std::pow(asFSR->alphaS(pow2(muR*mergingHooksPtr->
509  muRVarFactors[iVar-1])) / asME, nSteps);
510  wtVec[iVar] *= corrFac;
511  }
512 
513  // Done
514  return wtVec;
515 
516 }
517 
518 //--------------------------------------------------------------------------
519 
520 vector<double> History::weightNL3Tree(PartonLevel* trial, AlphaStrong*
521  asFSR, AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR,
522  double RN) {
523  // No difference to CKKW-L. Recycle CKKW-L function.
524  return weightCKKWL( trial, asFSR, asISR, aemFSR, aemISR, RN);
525 }
526 
527 //--------------------------------------------------------------------------
528 
529 vector<double> History::weightUMEPSTree(PartonLevel* trial, AlphaStrong*
530  asFSR, AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR,
531  double RN) {
532  // No difference to CKKW-L. Recycle CKKW-L function.
533  return weightCKKWL( trial, asFSR, asISR, aemFSR, aemISR, RN);
534 }
535 
536 //--------------------------------------------------------------------------
537 
538 // Function to return weight of virtual correction events for NLO merging
539 
540 vector<double> History::weightUMEPSSubt(PartonLevel* trial, AlphaStrong*
541  asFSR, AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR,
542  double RN ) {
543 
544  // Read alpha_S in ME calculation and maximal scale (eCM)
545  double asME = infoPtr->alphaS();
546  double aemME = infoPtr->alphaEM();
547  double maxScale = (foundCompletePath) ? infoPtr->eCM()
548  : mergingHooksPtr->muFinME();
549  // Select a path of clusterings
550  History * selected = select(RN);
551  // Set scales in the states to the scales pythia would have set
552  selected->setScalesInHistory();
553 
554  // Get weight.
555  int nWgts = mergingHooksPtr->nWgts;
556  vector<double> sudakov( nWgts, 1.);
557  vector<double> asWeight( nWgts, 1.);
558  vector<double> aemWeight( nWgts, 1.);
559  vector<double> pdfWeight( nWgts, 1.);
560 
561  // Do trial shower, calculation of alpha_S ratios, PDF ratios
562  sudakov = selected->weightTree(trial, asME, aemME, maxScale,
563  selected->clusterIn.pT(), asFSR, asISR, aemFSR, aemISR, asWeight,
564  aemWeight, pdfWeight);
565 
566  // MPI no-emission probability.
567  int njetsMaxMPI = mergingHooksPtr->nMinMPI()+1;
568  vector<double> mpiwt = selected->weightTreeEmissions( trial, -1, 0,
569  njetsMaxMPI, maxScale );
570 
571  // Set hard process renormalisation scale to default Pythia value.
572  bool resetScales = mergingHooksPtr->resetHardQRen();
573  // For pure QCD dijet events, evaluate the coupling of the hard process at
574  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
575  // arbitrary scale.
576  if ( resetScales
577  && mergingHooksPtr->getProcessString().compare("pp>jj") == 0) {
578  // Reset to a running coupling. Here we choose FSR for simplicity.
579  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
580  double runningCoupling = (*asFSR).alphaS(newQ2Ren) / asME;
581  for (double& asW: asWeight) asW *= pow(runningCoupling,2);
582  }
583 
584  // For prompt photon events, evaluate the coupling of the hard process at
585  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
586  // arbitrary scale.
587  if ( resetScales
588  && mergingHooksPtr->getProcessString().compare("pp>aj") == 0) {
589  // Reset to a running coupling. In prompt photon always ISR.
590  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
591  double runningCoupling =
592  (*asISR).alphaS( newQ2Ren + pow(mergingHooksPtr->pT0ISR(),2) ) / asME;
593  for (double& asW: asWeight) asW *= runningCoupling;
594  }
595 
596  // Done
597  vector<double> ret;
598  for (int iVar = 0; iVar < nWgts; ++iVar)
599  ret.push_back(sudakov[iVar]*asWeight[iVar]*aemWeight[iVar]*pdfWeight[iVar]*
600  mpiwt[iVar]);
601  return ret;
602 
603 }
604 
605 //--------------------------------------------------------------------------
606 
607 vector<double> History::weightUNLOPSTree(PartonLevel* trial, AlphaStrong*
608  asFSR, AlphaStrong* asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN,
609  int depthIn) {
610 
611  if ( mergingHooksPtr->canCutOnRecState() && !foundAllowedPath ) {
612  string message="Warning in History::weightUNLOPSTree: No allowed";
613  message+=" history found. Using disallowed history.";
614  infoPtr->errorMsg(message);
615  }
616  if ( mergingHooksPtr->orderHistories() && !foundOrderedPath ) {
617  string message="Warning in History::weightUNLOPSTree: No ordered";
618  message+=" history found. Using unordered history.";
619  infoPtr->errorMsg(message);
620  }
621  if ( mergingHooksPtr->canCutOnRecState()
622  && mergingHooksPtr->orderHistories()
623  && !foundAllowedPath && !foundOrderedPath ) {
624  string message="Warning in History::weightUNLOPSTree: No allowed or";
625  message+=" ordered history found.";
626  infoPtr->errorMsg(message);
627  }
628 
629  // Read alpha_S in ME calculation and maximal scale (eCM)
630  double asME = infoPtr->alphaS();
631  double aemME = infoPtr->alphaEM();
632  double maxScale = (foundCompletePath) ? infoPtr->eCM()
633  : mergingHooksPtr->muFinME();
634  // Select a path of clusterings
635  History * selected = select(RN);
636  // Set scales in the states to the scales pythia would have set
637  selected->setScalesInHistory();
638 
639  // Get weight.
640  int nWgts = mergingHooksPtr->nWgts;
641  vector<double> asWeight( nWgts, 1. );
642  vector<double> aemWeight( nWgts, 1. );
643  vector<double> pdfWeight( nWgts, 1. );
644 
645  // Do trial shower, calculation of alpha_S ratios, PDF ratios
646  vector<double> wt( nWgts, 1.);
647  if (depthIn < 0) wt = selected->weightTree(trial, asME, aemME, maxScale,
648  selected->clusterIn.pT(), asFSR, asISR, aemFSR, aemISR, asWeight,
649  aemWeight, pdfWeight);
650  else {
651  wt = selected->weightTreeEmissions( trial, 1, 0, depthIn, maxScale );
652  if (wt[0] != 0.) {
653  asWeight = selected->weightTreeAlphaS( asME, asFSR, asISR, depthIn);
654  aemWeight = selected->weightTreeAlphaEM( aemME, aemFSR, aemISR, depthIn);
655  pdfWeight = selected->weightTreePDFs( maxScale,
656  selected->clusterIn.pT(), depthIn);
657  }
658  }
659 
660  // MPI no-emission probability.
661  int njetsMaxMPI = mergingHooksPtr->nMinMPI();
662  vector<double> mpiwt = selected->weightTreeEmissions( trial, -1, 0,
663  njetsMaxMPI, maxScale );
664 
665  // Set hard process renormalisation scale to default Pythia value.
666  bool resetScales = mergingHooksPtr->resetHardQRen();
667  // For pure QCD dijet events, evaluate the coupling of the hard process at
668  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
669  // arbitrary scale.
670  if ( resetScales
671  && mergingHooksPtr->getProcessString().compare("pp>jj") == 0) {
672  // Reset to a running coupling. Here we choose FSR for simplicity.
673  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
674  double runningCoupling = (*asFSR).alphaS(newQ2Ren) / asME;
675  for (double& asW: asWeight) asW *= pow(runningCoupling,2);
676  }
677 
678  // For prompt photon events, evaluate the coupling of the hard process at
679  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
680  // arbitrary scale.
681  if ( resetScales
682  && mergingHooksPtr->getProcessString().compare("pp>aj") == 0) {
683  // Reset to a running coupling. In prompt photon always ISR.
684  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
685  double runningCoupling =
686  (*asISR).alphaS( newQ2Ren + pow(mergingHooksPtr->pT0ISR(),2) ) / asME;
687  for (double& asW: asWeight) asW *= runningCoupling;
688  }
689 
690  // Done
691  vector<double> ret;
692  for (int iVar = 0; iVar < nWgts; ++iVar)
693  ret.push_back(wt[iVar]*asWeight[iVar]*aemWeight[iVar]*pdfWeight[iVar]*
694  mpiwt[iVar]);
695 
696  // For tree level, undo as variation applied to ME component to avoid double
697  // ratios when combining later.
698  int nSteps = mergingHooksPtr->getNumberOfClusteringSteps(state);
699  double muR = mergingHooksPtr->muRinME();
700  for (int iVar = 1; iVar < nWgts; ++iVar)
701  asWeight[iVar] *= std::pow((*asFSR).alphaS(muR*muR) /
702  (*asFSR).alphaS(pow2(muR*mergingHooksPtr->muRVarFactors[iVar-1])),
703  nSteps);
704 
705  // Save weight vectors internally for UNLOPS-P and -PC
706  mergingHooksPtr->individualWeights.wtSave = wt;
707  mergingHooksPtr->individualWeights.asWeightSave = asWeight;
708  mergingHooksPtr->individualWeights.aemWeightSave = aemWeight;
709  mergingHooksPtr->individualWeights.pdfWeightSave = pdfWeight;
710  mergingHooksPtr->individualWeights.mpiWeightSave = mpiwt;
711 
712  return ret;
713 
714 }
715 
716 //--------------------------------------------------------------------------
717 
718 vector<double> History::weightUNLOPSLoop(PartonLevel* trial, AlphaStrong*
719  asFSR, AlphaStrong* asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN,
720  int depthIn) {
721  // No difference to default NL3
722  if (depthIn < 0) return weightNL3Loop(trial, RN);
723 
724  // Read alpha_S in ME calculation and maximal scale (eCM)
725  double asME = infoPtr->alphaS();
726  double aemME = infoPtr->alphaEM();
727  double maxScale = (foundCompletePath) ? infoPtr->eCM() :
728  mergingHooksPtr->muFinME();
729 
730  // Select a path of clusterings
731  History * selected = select(RN);
732  // Set scales in the status to the scales pythia would have set
733  selected->setScalesInHistory();
734 
735  // Get weight.
736  int nWgts = mergingHooksPtr->nWgts;
737  vector<double> wt( nWgts, 1.);
738  vector<double> asWeight( nWgts, 1.);
739  vector<double> aemWeight( nWgts, 1.);
740  vector<double> pdfWeight( nWgts, 1.);
741 
742  // Do trial shower, calculation of alpha_S ratios, PDF ratios
743  if (depthIn < 0) wt = selected->weightTree(trial, asME, aemME, maxScale,
744  selected->clusterIn.pT(), asFSR, asISR, aemFSR, aemISR, asWeight,
745  aemWeight, pdfWeight);
746  else {
747  wt = selected->weightTreeEmissions( trial, 1, 0, depthIn, maxScale );
748  if (wt[0] != 0.) {
749  asWeight = selected->weightTreeAlphaS( asME, asFSR, asISR, depthIn,
750  true);
751  aemWeight = selected->weightTreeAlphaEM( aemME, aemFSR, aemISR, depthIn);
752  pdfWeight = selected->weightTreePDFs( maxScale,
753  selected->clusterIn.pT(), depthIn);
754  }
755  }
756 
757  // MPI no-emission probability.
758  int njetsMaxMPI = mergingHooksPtr->nMinMPI();
759  vector<double> mpiwt = selected->weightTreeEmissions( trial, -1, 0,
760  njetsMaxMPI, maxScale );
761 
762  // Set hard process renormalisation scale to default Pythia value.
763  bool resetScales = mergingHooksPtr->resetHardQRen();
764  // For pure QCD dijet events, evaluate the coupling of the hard process at
765  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
766  // arbitrary scale.
767  if ( resetScales
768  && mergingHooksPtr->getProcessString().compare("pp>jj") == 0) {
769  // Reset to a running coupling. Here we choose FSR for simplicity.
770  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
771  double runningCoupling = (*asFSR).alphaS(newQ2Ren) / asME;
772  for (double& asW: asWeight) asW *= pow(runningCoupling,2);
773  }
774 
775  // For prompt photon events, evaluate the coupling of the hard process at
776  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
777  // arbitrary scale.
778  if ( resetScales
779  && mergingHooksPtr->getProcessString().compare("pp>aj") == 0) {
780  // Reset to a running coupling. In prompt photon always ISR.
781  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
782  double runningCoupling =
783  (*asISR).alphaS( newQ2Ren + pow(mergingHooksPtr->pT0ISR(),2) ) / asME;
784  for (double& asW: asWeight) asW *= runningCoupling;
785  }
786 
787  // Done
788  vector<double> ret;
789  for (int iVar = 0; iVar < nWgts; ++iVar)
790  ret.push_back(wt[iVar]*asWeight[iVar]*aemWeight[iVar]*pdfWeight[iVar]*
791  mpiwt[iVar]);
792 
793  // Save weight vectors interally for UNLOPS-P and -PC
794  mergingHooksPtr->individualWeights.wtSave = wt;
795  mergingHooksPtr->individualWeights.asWeightSave = asWeight;
796  mergingHooksPtr->individualWeights.aemWeightSave = aemWeight;
797  mergingHooksPtr->individualWeights.pdfWeightSave = pdfWeight;
798  mergingHooksPtr->individualWeights.mpiWeightSave = mpiwt;
799 
800  return ret;
801 
802 }
803 
804 //--------------------------------------------------------------------------
805 
806 vector<double> History::weightUNLOPSSubt(PartonLevel* trial, AlphaStrong*
807  asFSR, AlphaStrong* asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN,
808  int depthIn) {
809 
810  // Select a path of clusterings
811  History* selected = select(RN);
812  // Set scales in the states to the scales pythia would have set
813  selected->setScalesInHistory();
814 
815  // Read alpha_S in ME calculation and maximal scale (eCM)
816  double asME = infoPtr->alphaS();
817  double aemME = infoPtr->alphaEM();
818  double maxScale = (foundCompletePath)
819  ? infoPtr->eCM()
820  : mergingHooksPtr->muFinME();
821 
822  int nWgts = mergingHooksPtr->nWgts;
823 
824  // Only allow two clusterings if all intermediate states above the
825  // merging scale.
826  int nSteps = mergingHooksPtr->getNumberOfClusteringSteps(state);
827  if ( nSteps == 2 && mergingHooksPtr->nRecluster() == 2
828  && ( !foundCompletePath
829  || !selected->allIntermediateAboveRhoMS( mergingHooksPtr->tms() )) )
830  return vector<double>( nWgts, 0. );
831 
832  // Get weights: alpha_S ratios and PDF ratios
833  vector<double> asWeight( nWgts, 1.);
834  vector<double> aemWeight( nWgts, 1.);
835  vector<double> pdfWeight( nWgts, 1.);
836  // Do trial shower, calculation of alpha_S ratios, PDF ratios
837  vector<double> wt( nWgts, 1.);
838  if (depthIn < 0)
839  wt = selected->weightTree(trial, asME, aemME, maxScale,
840  selected->clusterIn.pT(), asFSR, asISR, aemFSR, aemISR, asWeight,
841  aemWeight, pdfWeight);
842  else {
843  wt = selected->weightTreeEmissions( trial, 1, 0, depthIn, maxScale );
844  if (wt[0] > 0.) {
845  asWeight = selected->weightTreeAlphaS( asME, asFSR, asISR, depthIn);
846  aemWeight = selected->weightTreeAlphaEM( aemME, aemFSR, aemISR, depthIn);
847  pdfWeight = selected->weightTreePDFs( maxScale,
848  selected->clusterIn.pT(), depthIn);
849  }
850  }
851 
852  // MPI no-emission probability.
853  int njetsMaxMPI = mergingHooksPtr->nMinMPI()+1;
854  vector<double> mpiwt = selected->weightTreeEmissions( trial, -1, 0,
855  njetsMaxMPI, maxScale );
856 
857  // Set weight
858  vector<double> ret;
859  if (mergingHooksPtr->nRecluster() == 2 )
860  ret = wt = asWeight = aemWeight = pdfWeight = mpiwt =
861  vector<double>( nWgts, 1. );
862  else {
863  for (int iVar = 0; iVar < nWgts; ++iVar)
864  ret.push_back(asWeight[iVar]*aemWeight[iVar]*pdfWeight[iVar]*
865  wt[iVar]*mpiwt[iVar]);
866  }
867 
868  // For tree level, undo as variation applied to ME component to avoid double
869  // ratios when combining later.
870  double muR = mergingHooksPtr->muRinME();
871  for (int iVar = 1; iVar < nWgts; ++iVar)
872  asWeight[iVar] *= std::pow((*asFSR).alphaS(muR*muR) /
873  (*asFSR).alphaS(pow2(muR*mergingHooksPtr->muRVarFactors[iVar-1])),
874  nSteps);
875 
876  // Save weight vectors interally for UNLOPS-P and -PC
877  mergingHooksPtr->individualWeights.wtSave = wt;
878  mergingHooksPtr->individualWeights.asWeightSave = asWeight;
879  mergingHooksPtr->individualWeights.aemWeightSave = aemWeight;
880  mergingHooksPtr->individualWeights.pdfWeightSave = pdfWeight;
881  mergingHooksPtr->individualWeights.mpiWeightSave = mpiwt;
882 
883  // Done
884  return ret;
885 
886 }
887 
888 //--------------------------------------------------------------------------
889 
890 vector<double> History::weightUNLOPSSubtNLO(PartonLevel* trial, AlphaStrong*
891  asFSR, AlphaStrong* asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN,
892  int depthIn) {
893 
894  // So far, no reweighting
895  int nWgts = mergingHooksPtr->nWgts;
896  vector<double> wt( nWgts, 1. );
897 
898  if (depthIn < 0) {
899 
900  // Select a path of clusterings
901  History * selected = select(RN);
902  // Set scales in the states to the scales pythia would have set
903  selected->setScalesInHistory();
904  // Only reweighting with MPI no-emission probability
905  double maxScale = (foundCompletePath) ? infoPtr->eCM()
906  : mergingHooksPtr->muFinME();
907  int njetsMaxMPI = mergingHooksPtr->nMinMPI()+1;
908  vector<double> mpiwt = selected->weightTreeEmissions
909  ( trial, -1, 0, njetsMaxMPI, maxScale );
910  wt = mpiwt;
911  // Done
912  return wt;
913  }
914 
915  // Select a path of clusterings
916  History* selected = select(RN);
917  // Set scales in the states to the scales pythia would have set
918  selected->setScalesInHistory();
919 
920  // Read alpha_S in ME calculation and maximal scale (eCM)
921  double asME = infoPtr->alphaS();
922  double aemME = infoPtr->alphaEM();
923  double maxScale = (foundCompletePath)
924  ? infoPtr->eCM()
925  : mergingHooksPtr->muFinME();
926 
927  // Only allow two clusterings if all intermediate states above the
928  // merging scale.
929  double nSteps = mergingHooksPtr->getNumberOfClusteringSteps(state);
930  if ( nSteps == 2 && mergingHooksPtr->nRecluster() == 2
931  && ( !foundCompletePath
932  || !selected->allIntermediateAboveRhoMS( mergingHooksPtr->tms() )) )
933  return vector<double>( nWgts, 0. );
934 
935  // Get weights: alpha_S ratios and PDF ratios
936  vector<double> asWeight( nWgts, 1.);
937  vector<double> aemWeight( nWgts, 1.);
938  vector<double> pdfWeight( nWgts, 1.);
939  // Do trial shower, calculation of alpha_S ratios, PDF ratios
940  if (depthIn < 0)
941  wt = selected->weightTree(trial, asME, aemME, maxScale,
942  selected->clusterIn.pT(), asFSR, asISR, aemFSR, aemISR, asWeight,
943  aemWeight, pdfWeight);
944  else {
945  wt = selected->weightTreeEmissions( trial, 1, 0, depthIn, maxScale );
946  if (wt[0] > 0.) {
947  asWeight = selected->weightTreeAlphaS( asME, asFSR, asISR, depthIn,
948  true);
949  aemWeight = selected->weightTreeAlphaEM( aemME, aemFSR, aemISR, depthIn);
950  pdfWeight = selected->weightTreePDFs( maxScale,
951  selected->clusterIn.pT(), depthIn);
952  }
953  }
954 
955  // MPI no-emission probability.
956  int njetsMaxMPI = mergingHooksPtr->nMinMPI()+1;
957  vector<double> mpiwt = selected->weightTreeEmissions( trial, -1, 0,
958  njetsMaxMPI, maxScale );
959 
960  // Set weight
961  vector<double> ret;
962  if (mergingHooksPtr->nRecluster() == 2 )
963  ret = wt = asWeight = aemWeight = pdfWeight = mpiwt =
964  vector<double>( nWgts, 1. );
965  else {
966  for (int iVar = 0; iVar < nWgts; ++iVar)
967  ret.push_back(asWeight[iVar]*aemWeight[iVar]*pdfWeight[iVar]*
968  wt[iVar]*mpiwt[iVar]);
969  }
970 
971  // Save weight vectors interally for UNLOPS-P and -PC
972  mergingHooksPtr->individualWeights.wtSave = wt;
973  mergingHooksPtr->individualWeights.asWeightSave = asWeight;
974  mergingHooksPtr->individualWeights.aemWeightSave = aemWeight;
975  mergingHooksPtr->individualWeights.pdfWeightSave = pdfWeight;
976  mergingHooksPtr->individualWeights.mpiWeightSave = mpiwt;
977 
978  // Done
979  return ret;
980 }
981 
982 //--------------------------------------------------------------------------
983 
984 // Function to calculate O(\alpha_s)-term of CKKWL-weight for NLO merging
985 
986 vector<double> History::weightUNLOPSFirst( int order, PartonLevel*
987  trial, AlphaStrong* asFSR, AlphaStrong* asISR, AlphaEM*, AlphaEM*,
988  double RN, Rndm* rndmPtr ) {
989 
990  int nWgts = mergingHooksPtr->nWgts;
991 
992  // Already done if no correction should be calculated
993  if ( order < 0 ) return vector<double>( nWgts, 0. );
994 
995  // Read alpha_S in ME calculation and maximal scale (eCM)
996  double asME = infoPtr->alphaS();
997  //double aemME = infoPtr->alphaEM();
998  double muR = mergingHooksPtr->muRinME();
999  double maxScale = (foundCompletePath)
1000  ? infoPtr->eCM()
1001  : mergingHooksPtr->muFinME();
1002 
1003  // Pick path of clusterings
1004  History * selected = select(RN);
1005  // Set scales in the states to the scales pythia would have set
1006  selected->setScalesInHistory();
1007 
1008  double nSteps = mergingHooksPtr->getNumberOfClusteringSteps(state);
1009 
1010  // Get the lowest order k-factor and add first two terms in expansion
1011  double kFactor = asME * mergingHooksPtr->k1Factor(nSteps);
1012 
1013  // If using Bbar, which includes a tree-level part, subtract an
1014  // additional one, i.e. the O(\as^0) contribution as well
1015  double wt = 1;
1016  // Set up vector for order == 0 case.
1017  vector<double> wtVec(nWgts, wt);
1018 
1019  if (order > 0) {
1020  // Start by adding the O(\alpha_s^1)-term of the k-factor.
1021  if ( mergingHooksPtr->orderHistories() && foundOrderedPath )
1022  wt += kFactor;
1023 
1024  // Calculate sum of O(\alpha_s^1)-terms of the ckkw-l weight WITHOUT
1025  // the O(\alpha_s^1)-term of the last no-emission probability.
1026  // Get first term in expansion of alpha_s ratios.
1027  double wA = selected->weightFirstAlphaS( asME, muR, asFSR, asISR );
1028  // Generate true average, not only one-point.
1029  double nWeight = 0.;
1030  for ( int i=0; i < NTRIAL; ++i ) {
1031  // Get average number of emissions.
1032  double wE = selected->weightFirstEmissions(trial,asME, maxScale,
1033  asFSR, asISR, true, true );
1034  // Add average number of emissions off reconstructed states to weight.
1035  nWeight += wE;
1036  // Get first term in expansion of PDF ratios.
1037  double pscale = selected->clusterIn.pT();
1038  double wP = selected->weightFirstPDFs(asME, maxScale, pscale, rndmPtr);
1039  // Add integral of DGLAP shifted PDF ratios from \alpha_s
1040  // expansion to wt.
1041  nWeight += wP;
1042  }
1043 
1044  // Introduce vector to allow variation of coefficient
1045  wtVec = vector<double>({wt + wA + nWeight/double(NTRIAL)});
1046 
1047  // Use the varied scale in the coefficient around which we expand
1048  for (int iVar = 1; iVar < nWgts; ++iVar) {
1049  double asFix = asFSR->alphaS(pow2(muR*mergingHooksPtr->
1050  muRVarFactors[iVar-1])) / asME;
1051  wtVec.push_back( wt + asFix*(wA + nWeight / double(NTRIAL)) );
1052  }
1053  }
1054 
1055  // Introduce variation of stong coupling that is not done in Born input
1056  mergingHooksPtr->individualWeights.bornAsVarFac =
1057  vector<double>( nWgts, 1. );
1058  for ( int iVar = 1; iVar < nWgts; ++iVar ) {
1059  double corrFac = std::pow(asFSR->alphaS(pow2(muR*mergingHooksPtr->
1060  muRVarFactors[iVar-1])) / asME, nSteps);
1061  wtVec[iVar] *= corrFac;
1062  mergingHooksPtr->individualWeights.bornAsVarFac[iVar] =
1063  corrFac;
1064  }
1065 
1066  // If O(\alpha_s^1)-term + O(\alpha_s^1)-term is to be calculated, done.
1067  if ( order <= 1 ) return wtVec;
1068 
1069  // So far, no calculation of O(\alpha_s^2)-term
1070  return vector<double>( nWgts, 0. );
1071 
1072 }
1073 
1074 //--------------------------------------------------------------------------
1075 
1076 // Function to set the state with complete scales for evolution.
1077 
1078 void History::getStartingConditions( const double RN, Event& outState ) {
1079 
1080  // Select the history
1081  History * selected = select(RN);
1082 
1083  // Set scales in the states to the scales pythia would have set
1084  selected->setScalesInHistory();
1085 
1086  // Get number of clustering steps.
1087  int nSteps = mergingHooksPtr->getNumberOfClusteringSteps(state);
1088 
1089  // Update the lowest order process.
1090  if (!selected->mother) {
1091  int nFinal = 0;
1092  for(int i=0; i < int(state.size()); ++i)
1093  if ( state[i].isFinal()) nFinal++;
1094  if (nFinal <=2)
1095  state.scale(mergingHooksPtr->muF());
1096 
1097  // Save information on last splitting, to allow the next
1098  // emission in the shower to have smaller rapidity with
1099  // respect to the last ME splitting.
1100  // For hard process, use dummy values.
1101  if (mergingHooksPtr->getNumberOfClusteringSteps(state) == 0) {
1102  infoPtr->zNowISR(0.5);
1103  infoPtr->pT2NowISR(pow(state[0].e(),2));
1104  infoPtr->hasHistory(true);
1105  // For incomplete process, try to use real values.
1106  } else {
1107  infoPtr->zNowISR(selected->zISR());
1108  infoPtr->pT2NowISR(pow(selected->pTISR(),2));
1109  infoPtr->hasHistory(true);
1110  }
1111 
1112  // Set QCD 2->2 starting scale different from arbitrary scale in LHEF!
1113  // --> Set to minimal mT of partons.
1114  int nFinalCol = 0;
1115  double muf = state[0].e();
1116  for ( int i=0; i < state.size(); ++i )
1117  if ( state[i].isFinal()
1118  && ( state[i].colType() != 0 || state[i].id() == 22 ) ) {
1119  nFinalCol++;
1120  muf = min( muf, abs(state[i].mT()) );
1121  }
1122  // For pure QCD dijet events (only!), set the process scale to the
1123  // transverse momentum of the outgoing partons.
1124  if ( nSteps == 0 && nFinalCol == 2
1125  && ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
1126  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0) ) {
1127  state.scale(muf);
1128  for (int i = 3;i < state.size();++i)
1129  state[i].scale(muf);
1130  }
1131  // For weak inclusive merging, follow QCD 2->2 starting scale for dijet
1132  // events. Also, restore input input polarisations.
1133  if (nSteps == 0 && nFinalCol == 2 &&
1134  mergingHooksPtr->getProcessString().find("inc") != string::npos) {
1135  state.scale(muf);
1136  for (int i = 3;i < state.size();++i)
1137  state[i].scale(muf);
1138  for ( int i=0; i < min(state.size(),outState.size()); ++i )
1139  state[i].pol(outState[i].pol());
1140  }
1141 
1142  } else {
1143 
1144  // Save information on last splitting, to allow the next
1145  // emission in the shower to have smaller rapidity with
1146  // respect to the last ME splitting.
1147  infoPtr->zNowISR(selected->zISR());
1148  infoPtr->pT2NowISR(pow(selected->pTISR(),2));
1149  infoPtr->hasHistory(true);
1150 
1151  }
1152 
1153  // Copy the output state.
1154  outState = state;
1155 
1156  // Save MPI starting scale.
1157  if (nSteps == 0)
1158  mergingHooksPtr->muMI(infoPtr->eCM());
1159  else
1160  mergingHooksPtr->muMI(outState.scale());
1161 
1162  // Setup the weak shower if W clustering is enabled.
1163  if (mergingHooksPtr->doWeakClustering()) setupSimpleWeakShower(0);
1164 
1165  mergingHooksPtr->setShowerStoppingScale( 0.0 );
1166 }
1167 
1168 //--------------------------------------------------------------------------
1169 
1170 // Function to print the history that would be chosen from the number RN.
1171 
1172 void History::printHistory( const double RN ) {
1173  History * selected = select(RN);
1174  selected->printStates();
1175  // Done
1176 }
1177 
1178 //--------------------------------------------------------------------------
1179 
1180 // Function to print the states in a history, starting from the hard process.
1181 
1182 void History::printStates() {
1183  if ( !mother ) {
1184  cout << scientific << setprecision(6) << "Probability=" << prob << endl;
1185  state.list();
1186  return;
1187  }
1188 
1189  // Print.
1190  double p = prob/mother->prob;
1191  cout << scientific << setprecision(6) << "Probability=" << p
1192  << " scale=" << clusterIn.pT() << endl;
1193  state.list();
1194  // Recurse
1195  mother->printStates();
1196  // Done
1197  return;
1198 }
1199 
1200 //--------------------------------------------------------------------------
1201 
1202 // Function to set the state with complete scales for evolution.
1203 
1204 bool History::getClusteredEvent( const double RN, int nSteps,
1205  Event& outState) {
1206 
1207  // Select history
1208  History * selected = select(RN);
1209  // Set scales in the states to the scales pythia would have set
1210  // (Only needed if not done before in calculation of weights or
1211  // setting of starting conditions)
1212  selected->setScalesInHistory();
1213  // If the history does not allow for nSteps clusterings (e.g. because the
1214  // history is incomplete), return false
1215  if (nSteps > selected->nClusterings()) return false;
1216  // Return event with nSteps-1 additional partons (i.e. recluster the last
1217  // splitting) and copy the output state
1218  outState = selected->clusteredState(nSteps-1);
1219  // Done.
1220  return true;
1221 
1222 }
1223 
1224 //--------------------------------------------------------------------------
1225 
1226 bool History::getFirstClusteredEventAboveTMS( const double RN, int nDesired,
1227  Event& process, int& nPerformed, bool doUpdate ) {
1228 
1229  // Do reclustering (looping) steps. Remember process scale.
1230  int nTried = nDesired - 1;
1231  // Get number of clustering steps.
1232  int nSteps = select(RN)->nClusterings();
1233  // Set scales in the states to the scales pythia would have set.
1234  select(RN)->setScalesInHistory();
1235 
1236  // Recluster until reclustered event is above the merging scale.
1237  Event dummy = Event();
1238  do {
1239  // Initialise temporary output of reclustering.
1240  dummy.clear();
1241  dummy.init( "(hard process-modified)", particleDataPtr );
1242  dummy.clear();
1243  // Recluster once more.
1244  nTried++;
1245  // If reclustered event does not exist, exit.
1246  if ( !getClusteredEvent( RN, nSteps-nTried+1, dummy ) ) return false;
1247  if ( nTried >= nSteps ) break;
1248 
1249  // Continue loop if reclustered event has unresolved partons.
1250  } while ( mergingHooksPtr->getNumberOfClusteringSteps(dummy) > 0
1251  && mergingHooksPtr->tmsNow( dummy) < mergingHooksPtr->tms() );
1252 
1253  // Update the hard process.
1254  if ( doUpdate ) process = dummy;
1255 
1256  // Failed to produce output state.
1257  if ( nTried > nSteps ) return false;
1258 
1259  nPerformed = nTried;
1260  if ( doUpdate ) {
1261  // Update to the actual number of steps.
1262  mergingHooksPtr->nReclusterSave = nPerformed;
1263  // Save MPI starting scale
1264  if (mergingHooksPtr->getNumberOfClusteringSteps(state) == 0)
1265  mergingHooksPtr->muMI(infoPtr->eCM());
1266  else
1267  mergingHooksPtr->muMI(state.scale());
1268  }
1269 
1270  // Done
1271  return true;
1272 
1273 }
1274 
1275 //--------------------------------------------------------------------------
1276 
1277 // Calculate and return pdf ratio.
1278 
1279 double History::getPDFratio( int side, bool forSudakov, bool useHardPDFs,
1280  int flavNum, double xNum, double muNum,
1281  int flavDen, double xDen, double muDen) {
1282 
1283  // Do nothing for e+e- beams
1284  if ( abs(flavNum) > 10 && flavNum != 21 ) return 1.0;
1285  if ( abs(flavDen) > 10 && flavDen != 21 ) return 1.0;
1286 
1287  // Now calculate PDF ratio if necessary
1288  double pdfRatio = 1.0;
1289 
1290  // Get mother and daughter pdfs
1291  double pdfNum = 0.0;
1292  double pdfDen = 0.0;
1293 
1294  // Use hard process PDFs (i.e. PDFs NOT used in ISR, FSR or MPI).
1295  if ( useHardPDFs ) {
1296  if (side == 1) {
1297  if (forSudakov)
1298  pdfNum = mother->beamA.xfHard( flavNum, xNum, muNum*muNum);
1299  else
1300  pdfNum = beamA.xfHard( flavNum, xNum, muNum*muNum);
1301  pdfDen = max(1e-10, beamA.xfHard( flavDen, xDen, muDen*muDen));
1302  } else {
1303  if (forSudakov)
1304  pdfNum = mother->beamB.xfHard( flavNum, xNum, muNum*muNum);
1305  else
1306  pdfNum = beamB.xfHard( flavNum, xNum, muNum*muNum);
1307  pdfDen = max(1e-10,beamB.xfHard( flavDen, xDen, muDen*muDen));
1308  }
1309 
1310  // Use rescaled PDFs in the presence of multiparton interactions
1311  } else {
1312  if (side == 1) {
1313  if (forSudakov)
1314  pdfNum = mother->beamA.xfISR(0, flavNum, xNum, muNum*muNum);
1315  else
1316  pdfNum = beamA.xfISR(0, flavNum, xNum, muNum*muNum);
1317  pdfDen = max(1e-10, beamA.xfISR(0, flavDen, xDen, muDen*muDen));
1318 
1319  } else {
1320  if (forSudakov)
1321  pdfNum = mother->beamB.xfISR(0, flavNum, xNum, muNum*muNum);
1322  else
1323  pdfNum = beamB.xfISR(0, flavNum, xNum, muNum*muNum);
1324  pdfDen = max(1e-10,beamB.xfISR(0, flavDen, xDen, muDen*muDen));
1325  }
1326  }
1327 
1328  // Cut out charm threshold.
1329  if ( forSudakov && abs(flavNum) ==4 && abs(flavDen) == 4 && muDen == muNum
1330  && muNum < particleDataPtr->m0(4))
1331  pdfDen = pdfNum = 1.0;
1332 
1333  // Return ratio of pdfs
1334  if ( pdfNum > 1e-15 && pdfDen > 1e-10 ) {
1335  pdfRatio *= pdfNum / pdfDen;
1336  } else if ( pdfNum < pdfDen ) {
1337  pdfRatio = 0.;
1338  } else if ( pdfNum > pdfDen ) {
1339  pdfRatio = 1.;
1340  }
1341 
1342  // Done
1343  return pdfRatio;
1344 
1345 }
1346 
1347 //--------------------------------------------------------------------------
1348 
1349 /*--------------- METHODS USED FOR ONLY ONE PATH OF HISTORY NODES ------- */
1350 
1351 // Function to set all scales in the sequence of states. This is a
1352 // wrapper routine for setScales and setEventScales methods
1353 
1354 void History::setScalesInHistory() {
1355  // Find correct links from n+1 to n states (mother --> child), as
1356  // needed for enforcing ordered scale sequences
1357  vector<int> ident;
1358  findPath(ident);
1359 
1360  // Set production scales in the states to the scales pythia would
1361  // have set and enforce ordering
1362  setScales(ident,true);
1363 
1364  // Set the overall event scales to the scale of the last branching
1365  setEventScales();
1366 
1367 }
1368 
1369 //--------------------------------------------------------------------------
1370 
1371 // Setup function that call the real getWeakProb.
1372 
1373 double History::getWeakProb() {
1374  vector<int> modes, fermionLines;
1375  vector<Vec4> mom;
1376  return getWeakProb(modes, mom, fermionLines);
1377 }
1378 
1379 //--------------------------------------------------------------------------
1380 
1381 // Recursive function that returns the weak probability for the given path.
1382 // mode refers to which ME correction to use, 1 = sChannel, 2 = gluon channel,
1383 // 3 = double quark t-channel, 4 is double quark u-channel.
1384 
1385 double History::getWeakProb(vector<int> &mode, vector<Vec4> &mom,
1386  vector<int> fermionLines) {
1387 
1388  // If at end, return 1.
1389  if (!mother) return 1.;
1390 
1391  // Find the transfer map given the splitting.
1392  map<int,int> stateTransfer;
1393  findStateTransfer(stateTransfer);
1394 
1395  // Setup hard process.
1396  if (mode.empty()) setupWeakHard(mode,fermionLines,mom);
1397 
1398  // Update modes and fermionLines.
1399  vector<int> modeNew = updateWeakModes(mode, stateTransfer);
1400  vector<int> fermionLinesNew = updateWeakFermionLines(fermionLines,
1401  stateTransfer);
1402 
1403  // Get the probability if it is a weak emission.
1404  if (mother->state[clusterIn.emitted].idAbs() == 24 ||
1405  mother->state[clusterIn.emitted].idAbs() == 23)
1406  return getSingleWeakProb(modeNew, mom, fermionLinesNew) *
1407  mother->getWeakProb(modeNew, mom, fermionLinesNew);
1408  else return mother->getWeakProb(modeNew, mom, fermionLinesNew);
1409 }
1410 
1411 //--------------------------------------------------------------------------
1412 
1413 double History::getSingleWeakProb(vector<int> &mode, vector<Vec4> &mom,
1414  vector<int> fermionLines) {
1415 
1416  // Find the correct coupling coefficient.
1417  double weakCoupling = 0.0;
1418  if (mother->state[clusterIn.emitted].idAbs() == 24) {
1419  // No emissions from right handed particles.
1420  if (clusterIn.spinRadBef == 1) return 0.0;
1421  else if (clusterIn.spinRadBef == -1)
1422  weakCoupling = 4.*M_PI/ coupSMPtr->sin2thetaW()
1423  * coupSMPtr->V2CKMid(abs(clusterIn.flavRadBef),
1424  mother->state[clusterIn.emittor].idAbs());
1425  else {
1426  infoPtr->errorMsg("Warning in History::getSingleWeakProb: "
1427  "Spin not properly configurated. Skipping history");
1428  return 0.0;
1429  }
1430  } else if (mother->state[clusterIn.emitted].idAbs() == 23) {
1431  // No emissions from right handed particles.
1432  if (clusterIn.spinRadBef == 1)
1433  weakCoupling = 4.*M_PI*pow2(coupSMPtr->rf( abs(clusterIn.flavRadBef)))
1434  / (coupSMPtr->sin2thetaW() * coupSMPtr->cos2thetaW()) ;
1435  else if (clusterIn.spinRadBef == -1)
1436  weakCoupling = 4.*M_PI*pow2(coupSMPtr->lf( abs(clusterIn.flavRadBef)))
1437  / (coupSMPtr->sin2thetaW() * coupSMPtr->cos2thetaW()) ;
1438  else {
1439  infoPtr->errorMsg("Warning in History::getSingleWeakProb: "
1440  "Spin not properly configurated. Skipping history");
1441  return 0.0;
1442  }
1443  } else {
1444  infoPtr->errorMsg("Warning in History::getSingleWeakProb: "
1445  "Did not emit W/Z. Skipping history.");
1446  return 0.0;
1447  }
1448 
1449  // Find and store kinematics (e.g. z, pT, k1, k3).
1450 
1451  // Store momenta.
1452  Vec4 pRadAft = mother->state[clusterIn.emittor].p();
1453  Vec4 pEmtAft = mother->state[clusterIn.emitted].p();
1454  Vec4 pRecAft = mother->state[clusterIn.recoiler].p();
1455  Vec4 pSum = pRadAft + pEmtAft + pRecAft;
1456  double m2sum = pSum.m2Calc();
1457  double Qsq = (pRadAft + pEmtAft).m2Calc();
1458 
1459  double m2Rad0 = pRadAft.m2Calc();
1460  double m2Emt0 = pEmtAft.m2Calc();
1461  double lambda13 = sqrt( pow2(Qsq - m2Rad0 - m2Emt0 ) - 4. * m2Rad0*m2Emt0 );
1462  double k1 = ( Qsq - lambda13 + (m2Emt0 - m2Rad0 ) ) / ( 2. * Qsq );
1463  double k3 = ( Qsq - lambda13 - (m2Emt0 - m2Rad0 ) ) / ( 2. * Qsq );
1464 
1465  double z = mother->getCurrentZ(clusterIn.emittor, clusterIn.recoiler,
1466  clusterIn.emitted, clusterIn.flavRadBef);
1467  double pT2 = pow2(clusterIn.pTscale);
1468 
1469  double x1 = 2. * pRadAft * pSum / m2sum;
1470  double x2 = 2. * pRecAft * pSum / m2sum;
1471  double x3 = 2. * pEmtAft * pSum / m2sum;
1472 
1473  // Final state clustering.
1474  if ( state[clusterIn.radBef].status() > 0) {
1475  // s-channel
1476  if (mode[clusterIn.emittor] == 1) {
1477  // Calculate variables.
1478  double eCMME = pSum.mCalc();
1479  double r1 = mother->state[clusterIn.emittor].m() / eCMME;
1480  double r2 = mother->state[clusterIn.recoiler].m() / eCMME;
1481  double r3 = mother->state[clusterIn.emitted].m() / eCMME;
1482  double x1s = x1 * x1;
1483  double x2s = x2 * x2;
1484  double r1s = r1 * r1;
1485  double r2s = r2 * r2;
1486  double r3s = r3 * r3;
1487  double prop1 = 1. + r1s - r2s - x1;
1488  double prop2 = 1. + r2s - r1s - x2;
1489  double prop1s = prop1 * prop1;
1490  double prop2s = prop2 * prop2;
1491  double prop12 = prop1 * prop2;
1492 
1493  // Calculate Jacobian.
1494  double jac = 1./(1.-z) * 1./pT2 * (1-x2+r2-r1)*(x3 - k1*(x1+x3))
1495  * (1.-x1+r1-r2) / x3;
1496  return jac * weakCoupling * ((2. * r3s * r3s + 2. * r3s *
1497  (x1 + x2) + x1s + x2s) / prop12 - r3s / prop1s - r3s / prop2s);
1498  }
1499  // t-channel.
1500  else {
1501  // Store momentas needed.
1502  Vec4 p1 = mother->state[clusterIn.emittor].p();
1503  Vec4 p2 = mother->state[clusterIn.recoiler].p();
1504  Vec4 p3 = mother->state[clusterIn.emitted].p();
1505  Vec4 radBef = state[clusterIn.radBef].p();
1506  Vec4 recBef = state[clusterIn.recBef].p();
1507  Vec4 pIn1 = mom[0];
1508  Vec4 pIn2 = mom[1];
1509 
1510  // Check if a swap is needed.
1511  if (fermionLines[2] == clusterIn.emittor);
1512  else if (fermionLines[3] == clusterIn.emittor) swap(pIn1, pIn2);
1513 
1514  // Rescaling of incoming partons p3 and p4.
1515  double scaleFactor2 = (p1 + p2 + p3).m2Calc() / (pIn1 + pIn2).m2Calc();
1516  double scaleFactor = sqrt(scaleFactor2);
1517  pIn1 *= scaleFactor;
1518  pIn2 *= scaleFactor;
1519 
1520  // Longitudinal boost to rest frame of incoming partons of
1521  // hard interaction.
1522  RotBstMatrix rot2to2frame;
1523  rot2to2frame.bstback(pIn1 + pIn2);
1524  pIn1.rotbst(rot2to2frame);
1525  pIn2.rotbst(rot2to2frame);
1526  p1.rotbst(rot2to2frame);
1527  p2.rotbst(rot2to2frame);
1528  p3.rotbst(rot2to2frame);
1529  recBef.rotbst(rot2to2frame);
1530  radBef.rotbst(rot2to2frame);
1531 
1532  // Further boost to rest frame of outgoing state.
1533  RotBstMatrix rot2to3frame;
1534  rot2to3frame.bstback(p1 + p2 + p3);
1535  p1.rotbst(rot2to3frame);
1536  p2.rotbst(rot2to3frame);
1537  p3.rotbst(rot2to3frame);
1538  recBef.rotbst(rot2to3frame);
1539  radBef.rotbst(rot2to3frame);
1540 
1541  // Calculate variables;
1542  double sHat = (pIn1 + pIn2).m2Calc();
1543  double tHat = (radBef - pIn1).m2Calc();
1544  double uHat = (recBef - pIn1).m2Calc();
1545  double localProb = 0;
1546  double Q2 = pT2 / (z*(1.-z));
1547  double jac = 1./(4. * M_PI) * 1./( (1.-z) * z ) * sHat / (sHat - Q2)
1548  * (1. - k1 - k3);
1549 
1550  // Calculate the ME depending on the top of process.
1551  if (mode[clusterIn.emittor] == 2)
1552  localProb = simpleWeakShowerMEs.getMEqg2qgZ( pIn1, pIn2, p2, p3, p1)
1553  / simpleWeakShowerMEs.getMEqg2qg( sHat, tHat, uHat);
1554  else if (mode[clusterIn.emittor] == 3)
1555  localProb = simpleWeakShowerMEs.getMEqq2qqZ( pIn1, pIn2, p3, p2, p1)
1556  / simpleWeakShowerMEs.getMEqq2qq( sHat, tHat, uHat, false);
1557  else if (mode[clusterIn.emittor] == 4)
1558  localProb = simpleWeakShowerMEs.getMEqq2qqZ( pIn1, pIn2, p3, p2, p1)
1559  / simpleWeakShowerMEs.getMEqq2qq( sHat, tHat, uHat, true);
1560  else {
1561  string message="Warning in History::getSingleWeakProb: Wrong";
1562  message+=" mode setup. Setting probability for path to zero.";
1563  infoPtr->errorMsg(message);
1564  }
1565 
1566  // Split matrix element according to propagaters.
1567  localProb *= abs((-p3 + pIn1).m2Calc())
1568  / ((p3 + p1).m2Calc() + abs((-pIn1 + p3).m2Calc()));
1569 
1570  return jac * weakCoupling * localProb;
1571  }
1572  }
1573  // Initial clustering.
1574  else {
1575  // s-channel
1576  if (mode[clusterIn.emittor] == 1) {
1577  Vec4 pIn1 = mother->state[clusterIn.emittor].p();
1578  Vec4 pIn2 = mother->state[clusterIn.recoiler].p();
1579  Vec4 p1 = mother->state[clusterIn.emitted].p();
1580  Vec4 p2 = pIn1 + pIn2 -p1;
1581 
1582  double sH = (pIn1 + pIn2).m2Calc();
1583  double tH = (p1 - pIn1).m2Calc();
1584  double uH = (p1 - pIn2).m2Calc();
1585  double m3s = p1.m2Calc();
1586  double m4s = p2.m2Calc();
1587 
1588  double jac = 1./sH * tH*uH / ( tH * (tH + uH) );
1589  return jac * weakCoupling * ((uH*uH + tH*tH + 2 * sH * (m3s + m4s))
1590  / (uH*tH) - m3s * m4s * (1/(tH*tH) + 1/(uH*uH)));
1591  }
1592  else {
1593 
1594  // Store momenta.
1595  Vec4 pIn1 = mother->state[clusterIn.emittor].p();
1596  Vec4 pIn2 = mother->state[clusterIn.recoiler].p();
1597  Vec4 p3 = mother->state[clusterIn.emitted].p();
1598  Vec4 p1 = mom[2];
1599  Vec4 p2 = mom[3];
1600 
1601  // Check if radiator is from beam one or two.
1602  if (fermionLines[0] == clusterIn.emittor);
1603  else if (fermionLines[1] == clusterIn.emittor)
1604  swap(p1, p2);
1605 
1606 
1607  Vec4 pDaughter, pRecoiler;
1608  int signBeam = (pIn1.pz() > 0.) ? 1 : -1;
1609  double eCM = state[0].e(), phi = 0;
1610 
1611  // Undo the ISR boost.
1612  reverseBoostISR(pIn1, p3, pIn2, pDaughter, pRecoiler, signBeam,
1613  eCM, phi);
1614 
1615  // Scale outgoing vectors to conserve energy / momentum.
1616  //double scaleFactor2 = (pIn1 + pIn2 - p3).m2Calc() / (p1 + p2).m2Calc();
1617  double scaleFactor2 = (pIn1 + pIn2 - p3).m2Calc() / (p1 + p2).m2Calc();
1618  double scaleFactor = sqrt(scaleFactor2);
1619  RotBstMatrix rot2to2frame;
1620  rot2to2frame.bstback(p1 + p2);
1621  p1.rotbst(rot2to2frame);
1622  p2.rotbst(rot2to2frame);
1623  p1 *= scaleFactor;
1624  p2 *= scaleFactor;
1625 
1626  // Find 2 to 2 rest frame for incoming particles.
1627  // This is done before one of the two are made virtual (Q^2 mass).
1628  Vec4 radBef = state[clusterIn.radBef].p();
1629  Vec4 recBef = state[clusterIn.recBef].p();
1630 
1631  RotBstMatrix rot2to2frameInc;
1632  rot2to2frameInc.bstback(radBef + recBef);
1633  radBef.rotbst(rot2to2frameInc);
1634  recBef.rotbst(rot2to2frameInc);
1635  double sHat = (p1 + p2).m2Calc();
1636  double tHat = (p1 - radBef).m2Calc();
1637  double uHat = (p1 - recBef).m2Calc();
1638  double localProb = 0;
1639  p1.rot(0., -phi);
1640  p2.rot(0., -phi);
1641 
1642  // Calculating the Jacobian
1643  double jac = z / (4.*M_PI);
1644 
1645  if (mode[clusterIn.emittor] == 2)
1646  localProb = simpleWeakShowerMEs.getMEqg2qgZ(pIn1, pIn2, p2, p3, p1)
1647  / simpleWeakShowerMEs.getMEqg2qg(sHat, tHat, uHat);
1648  else if (mode[clusterIn.emittor] == 4)
1649  localProb = simpleWeakShowerMEs.getMEqq2qqZ(pIn1, pIn2, p3, p2, p1)
1650  / simpleWeakShowerMEs.getMEqq2qq(sHat, tHat, uHat, true);
1651  else if (mode[clusterIn.emittor] == 3)
1652  localProb = simpleWeakShowerMEs.getMEqq2qqZ(pIn1, pIn2, p3, p2, p1)
1653  / simpleWeakShowerMEs.getMEqq2qq(sHat, tHat, uHat, false);
1654  else {
1655  string message="Warning in History::getSingleWeakProb: Wrong";
1656  message+=" mode setup. Setting probability for path to zero.";
1657  infoPtr->errorMsg(message);
1658  }
1659 
1660  // Split of ME into an ISR part and FSR part.
1661  localProb *= (p3 + p1).m2Calc() / ( (p3 + p1).m2Calc()
1662  + abs((-pIn1 + p3).m2Calc()) );
1663 
1664  return jac * weakCoupling * localProb;
1665  }
1666  }
1667 
1668 }
1669 
1670 //--------------------------------------------------------------------------
1671 
1672 // Check if the weak recoil structure is allowed.
1673 bool History::checkWeakRecoils(map<int,int> &allowedRecoils, bool isFirst) {
1674  if (!mother) return true;
1675 
1676  // Setup if first
1677  if (isFirst) {
1678  // Drell-Yan production.
1679  if (state.size() != 8) {
1680  if (state[3].isQuark() || state[3].isLepton())
1681  allowedRecoils.insert(pair<int,int>(3,4));
1682  if (state[4].isQuark() || state[4].isLepton())
1683  allowedRecoils.insert(pair<int,int>(4,3));
1684 
1685  } else {
1686  if (state[3].isQuark() || state[3].isLepton())
1687  allowedRecoils.insert(pair<int,int>(3,4));
1688  if (state[4].isQuark() || state[4].isLepton())
1689  allowedRecoils.insert(pair<int,int>(4,3));
1690  if (state[5].isQuark() || state[5].isLepton())
1691  allowedRecoils.insert(pair<int,int>(5,6));
1692  if (state[6].isQuark() || state[6].isLepton())
1693  allowedRecoils.insert(pair<int,int>(6,5));
1694  }
1695  }
1696 
1697  // Find the transfer map.
1698  map<int,int> transfer;
1699  findStateTransfer(transfer);
1700 
1701  // Copy the new allowed recoils.
1702  map<int,int> allowedRecoilsNew;
1703  for (map<int,int>::iterator it = allowedRecoils.begin();
1704  it != allowedRecoils.end(); ++it) {
1705 
1706  // Start by considering final state splittings.
1707  if (state[clusterIn.radBef].status() > 0) {
1708  // If the dipole was not connected to current splitting.
1709  if (it->first != clusterIn.radBef &&
1710  it->second != clusterIn.radBef)
1711  allowedRecoilsNew.insert(pair<int,int>(transfer[it->first],
1712  transfer[it->second]));
1713  // If the recoiler is splitted into two.
1714  else if (it->second == clusterIn.radBef) {
1715  // Follow fermion line.
1716  if (state[clusterIn.recBef].isQuark() ||
1717  state[clusterIn.recBef].isLepton()) {
1718  if (mother->state[clusterIn.emittor].isQuark() ||
1719  mother->state[clusterIn.emittor].isLepton())
1720  allowedRecoilsNew.insert(pair<int,int>(transfer[it->first],
1721  clusterIn.emittor));
1722  else
1723  allowedRecoilsNew.insert(pair<int,int>(transfer[it->first],
1724  clusterIn.emitted));
1725  }
1726  // If no fermion line to follow, choose the largest invariant mass.
1727  else {
1728  double mEmittor = (mother->state[clusterIn.emittor].p() +
1729  mother->state[transfer[it->first]].p()).mCalc();
1730  double mEmitted = (mother->state[clusterIn.emitted].p() +
1731  mother->state[transfer[it->first]].p()).mCalc();
1732  if (mEmitted > mEmittor)
1733  allowedRecoilsNew.insert(pair<int,int>(transfer[it->first],
1734  clusterIn.emitted));
1735  else
1736  allowedRecoilsNew.insert(pair<int,int>(transfer[it->first],
1737  clusterIn.emittor));
1738  }
1739  }
1740  // If the radiator is splitted into two.
1741  if (mother->state[clusterIn.emittor].isQuark() ||
1742  mother->state[clusterIn.emittor].isLepton())
1743  allowedRecoilsNew.insert(pair<int,int>(clusterIn.emittor,
1744  transfer[it->second]));
1745  else
1746  allowedRecoilsNew.insert(pair<int,int>(clusterIn.emitted,
1747  transfer[it->second]));
1748  }
1749 
1750  // Look at initial splittings.
1751  else {
1752  // If not involved in the splitting.
1753  if (it->first != clusterIn.radBef &&
1754  it->second != clusterIn.radBef)
1755  allowedRecoilsNew.insert(pair<int,int>(transfer[it->first],
1756  transfer[it->second]));
1757 
1758  // If the recoiler is splitted, always choose the emittor.
1759  else if (it->second == clusterIn.radBef)
1760  allowedRecoilsNew.insert(pair<int,int>(transfer[it->first],
1761  clusterIn.emittor));
1762 
1763  // If the radiator splits into two.
1764  else {
1765  // If the the fermion line continues to be the beam particle.
1766  if (mother->state[clusterIn.emittor].isQuark() ||
1767  mother->state[clusterIn.emittor].isLepton())
1768  allowedRecoilsNew.insert(pair<int,int>(clusterIn.emittor,
1769  clusterIn.recoiler));
1770 
1771  // If the fermion line is emitted, find recoiler in final state.
1772  else
1773  allowedRecoilsNew.insert(pair<int,int>(clusterIn.emittor,
1774  findISRRecoiler()));
1775  }
1776  }
1777  }
1778 
1779  // If a gluon/phton is split into a quark-antiquark pair, add two new
1780  // possible configurations.
1781  if ( (state[clusterIn.radBef].idAbs() == 22 ||
1782  state[clusterIn.radBef].idAbs() == 21) &&
1783  (mother->state[clusterIn.emittor].isQuark() ||
1784  mother->state[clusterIn.emittor].isLepton() ) ) {
1785  // If it is a final splitting, just add the two.
1786  if (state[clusterIn.radBef].status() > 0) {
1787  allowedRecoilsNew.insert(pair<int,int>(clusterIn.emittor,
1788  clusterIn.emitted));
1789  allowedRecoilsNew.insert(pair<int,int>(clusterIn.emitted,
1790  clusterIn.emittor));
1791  }
1792 
1793  // If it is an initial splitting.
1794  else {
1795  allowedRecoilsNew.insert(pair<int,int>(clusterIn.emittor,
1796  clusterIn.recoiler));
1797  allowedRecoilsNew.insert(pair<int,int>(clusterIn.emitted,
1798  findISRRecoiler()));
1799  }
1800  }
1801 
1802  // allowedRecoilsNew is now properly setup, so ready to check
1803  // if recoil works.
1804 
1805  // If weak emission, do the check.
1806  if (mother->state[clusterIn.emitted].idAbs() == 24 ||
1807  mother->state[clusterIn.emitted].idAbs() == 23)
1808  if ( clusterIn.recoiler != allowedRecoilsNew[clusterIn.emittor])
1809  return false;
1810 
1811  // check the mother.
1812  return mother->checkWeakRecoils(allowedRecoilsNew);
1813 
1814 }
1815 
1816 //--------------------------------------------------------------------------
1817 
1818 // Find the recoiler for an ISR scattered weak particle.
1819 // Always use 1 as weak weight, even though the shower uses a slightly
1820 // different value for Z emissions.
1821 int History::findISRRecoiler() {
1822 
1823  int flavRad = mother->state[clusterIn.emitted].id();
1824  Vec4 pRad = mother->state[clusterIn.emitted].p();
1825  double mRad = mother->state[clusterIn.emitted].m();
1826  int iRad = clusterIn.emitted;
1827  int iRec = 0;
1828  double ppMin = 1E20;
1829  for (int i = 0;i < mother->state.size(); ++i) {
1830  if (i == iRad) continue;
1831  if (mother->state[i].isFinal() && mother->state[i].id() == - flavRad) {
1832  double ppNow = mother->state[i].p() * pRad
1833  - mother->state[i].m() - mRad;
1834  if (ppNow < ppMin) {
1835  ppMin = ppNow;
1836  iRec = i;
1837  }
1838  }
1839  }
1840  if (iRec) return iRec;
1841 
1842  // Find nearest recoiler weak-charge-squared-weighted.
1843  for (int i = 0;i < mother->state.size(); ++i) {
1844  if (i == iRad) continue;
1845  if (mother->state[i].isFinal() && mother->state[i].idAbs() < 20) {
1846  double weakCoupNow = 1.;
1847  double ppNow = (mother->state[i].p() * pRad
1848  - mother->state[i].m() - mRad) / weakCoupNow;
1849  if (ppNow < ppMin) {
1850  ppMin = ppNow;
1851  iRec = i;
1852  }
1853  }
1854  }
1855  if (iRec) return iRec;
1856 
1857  // Find nearest recoiler in final state.
1858  for (int i = 0;i < mother->state.size(); ++i) {
1859  if (i == iRad) continue;
1860  if (mother->state[i].isFinal()) {
1861  double ppNow = mother->state[i].p() * pRad
1862  - mother->state[i].m() - mRad;
1863  if (ppNow < ppMin) {
1864  ppMin = ppNow;
1865  iRec = i;
1866  }
1867  }
1868  }
1869  if (iRec) return iRec;
1870 
1871  return 0;
1872 }
1873 
1874 //--------------------------------------------------------------------------
1875 
1876 // Find map between indecies in the current state and the state after
1877 // the splitting.
1878 // NOT IMPLEMENTED FOR MULTIPLE W/Z/GAMMA (NEED TO HAVE A WAY TO IDENTIFY THEM)
1879 void History::findStateTransfer(map<int,int> &transfer) {
1880  // No need to transfer if already at highest multiplicity.
1881  if (!mother) return;
1882  transfer.clear();
1883 
1884  // Directly assign the 3 first particles (system, beam1, beam2);
1885  for(int i = 0;i < 3; ++i)
1886  transfer.insert(pair<int,int>(i,i));
1887 
1888  transfer.insert(pair<int,int>(clusterIn.radBef, clusterIn.emittor));
1889  transfer.insert(pair<int,int>(clusterIn.recBef, clusterIn.recoiler));
1890 
1891  // Handle all particles that are not part of the clustering.
1892  for (int i = 0; i < int(mother->state.size()); ++i) {
1893  if (clusterIn.emitted == i ||
1894  clusterIn.emittor == i ||
1895  clusterIn.recoiler == i)
1896  continue;
1897 
1898  for (int j = 0;j < int(state.size()); ++j) {
1899  if (mother->state[i].id() == state[j].id()
1900  && mother->state[i].colType() == state[j].colType()
1901  && mother->state[i].chargeType() == state[j].chargeType()
1902  && mother->state[i].col() == state[j].col()
1903  && mother->state[i].acol() == state[j].acol()
1904  && mother->state[i].status() == state[j].status()) {
1905  transfer.insert(pair<int,int>(j,i));
1906  break;
1907  }
1908  }
1909  }
1910 }
1911 
1912 //--------------------------------------------------------------------------
1913 
1914 // Function to find the index (in the mother histories) of the
1915 // child history, thus providing a way access the path from both
1916 // initial history (mother == 0) and final history (all children == 0)
1917 // IN vector<int> : The index of each child in the children vector
1918 // of the current history node will be saved in
1919 // this vector
1920 // NO OUTPUT
1921 
1922 void History::findPath(vector<int>& out) {
1923 
1924  // If the initial and final nodes are identical, return
1925  if (!mother && int(children.size()) < 1) return;
1926  // Find the child by checking the children vector for the perfomed
1927  // clustering
1928  int iChild=-1;
1929  if ( mother ) {
1930  int size = int(mother->children.size());
1931  // Loop through children and identify child chosen
1932  for ( int i=0; i < size; ++i) {
1933  if ( mother->children[i]->scale == scale
1934  && mother->children[i]->prob == prob
1935  && equalClustering(mother->children[i]->clusterIn,clusterIn)) {
1936  iChild = i;
1937  break;
1938  }
1939  }
1940  // Save the index of the child in the children vector and recurse
1941  if (iChild >-1)
1942  out.push_back(iChild);
1943  mother->findPath(out);
1944  }
1945 }
1946 
1947 //--------------------------------------------------------------------------
1948 
1949 // Functions to set the parton production scales and enforce
1950 // ordering on the scales of the respective clusterings stored in
1951 // the History node:
1952 // Method will start from lowest multiplicity state and move to
1953 // higher states, setting the production scales the shower would
1954 // have used.
1955 // When arriving at the highest multiplicity, the method will switch
1956 // and go back in direction of lower states to check and enforce
1957 // ordering for unordered histories.
1958 // IN vector<int> : Vector of positions of the chosen child
1959 // in the mother history to allow to move
1960 // in direction initial->final along path
1961 // bool : True: Move in direction low->high
1962 // multiplicity and set production scales
1963 // False: Move in direction high->low
1964 // multiplicity and check and enforce
1965 // ordering
1966 // NO OUTPUT
1967 
1968 void History::setScales( vector<int> index, bool forward) {
1969 
1970  // First, set the scales of the hard process to the kinematial
1971  // limit (=s)
1972  if ( children.empty() && forward ) {
1973  // New "incomplete" configurations showered from mu
1974  if (!mother) {
1975  double scaleNew = 1.;
1976  if (mergingHooksPtr->incompleteScalePrescip()==0) {
1977  scaleNew = mergingHooksPtr->muF();
1978  } else if (mergingHooksPtr->incompleteScalePrescip()==1) {
1979  Vec4 pOut;
1980  pOut.p(0.,0.,0.,0.);
1981  for(int i=0; i<int(state.size()); ++i)
1982  if (state[i].isFinal())
1983  pOut += state[i].p();
1984  scaleNew = pOut.mCalc();
1985  } else if (mergingHooksPtr->incompleteScalePrescip()==2) {
1986  scaleNew = state[0].e();
1987  }
1988 
1989  scaleNew = max( mergingHooksPtr->pTcut(), scaleNew);
1990 
1991  state.scale(scaleNew);
1992  for(int i=3; i < int(state.size());++i)
1993  if (state[i].colType() != 0)
1994  state[i].scale(scaleNew);
1995  } else {
1996  // 2->2 with non-parton particles showered from eCM
1997  state.scale( state[0].e() );
1998  // Count final partons
1999  bool isLEP = ( state[3].isLepton() && state[4].isLepton() );
2000  int nFinal = 0;
2001  int nFinalPartons = 0;
2002  int nFinalPhotons = 0;
2003  for ( int i=0; i < int(state.size()); ++i ) {
2004  if ( state[i].isFinal() ) {
2005  nFinal++;
2006  if ( state[i].colType() != 0 ) nFinalPartons++;
2007  if ( state[i].id() == 22 ) nFinalPhotons++;
2008  }
2009  }
2010  bool isQCD = ( nFinal == 2 && nFinal == nFinalPartons );
2011  bool isPPh = ( nFinal == 2 && nFinalPartons == 1 && nFinalPhotons == 1);
2012  // If 2->2, purely partonic, set event scale to kinematic pT
2013  if ( !isLEP && ( isQCD || isPPh ) ) {
2014  double scaleNew = hardFacScale(state);
2015  state.scale( scaleNew );
2016  }
2017  }
2018  }
2019  // Set all particle production scales, starting from lowest
2020  // multiplicity (final) state
2021  if (mother && forward) {
2022  // When choosing splitting scale, beware of unordered splittings:
2023  double scaleNew = 1.;
2024  if (mergingHooksPtr->unorderedScalePrescip() == 0) {
2025  // Use larger scale as common splitting scale for mother and child
2026  scaleNew = max( mergingHooksPtr->pTcut(), max(scale,mother->scale));
2027  } else if (mergingHooksPtr->unorderedScalePrescip() == 1) {
2028  // Use smaller scale as common splitting scale for mother and child
2029  if (scale < mother->scale)
2030  scaleNew *= max( mergingHooksPtr->pTcut(), min(scale,mother->scale));
2031  else
2032  scaleNew *= max( mergingHooksPtr->pTcut(), max(scale,mother->scale));
2033  }
2034 
2035  // Rescale the mother state partons to the clustering scales
2036  // that have been found along the path
2037  mother->state[clusterIn.emitted].scale(scaleNew);
2038  mother->state[clusterIn.emittor].scale(scaleNew);
2039  mother->state[clusterIn.recoiler].scale(scaleNew);
2040 
2041  // Find unchanged copies of partons in higher multiplicity states
2042  // and rescale those
2043  mother->scaleCopies(clusterIn.emitted, mother->state, scaleNew);
2044  mother->scaleCopies(clusterIn.emittor, mother->state, scaleNew);
2045  mother->scaleCopies(clusterIn.recoiler, mother->state, scaleNew);
2046 
2047  // Recurse
2048  mother->setScales(index,true);
2049  }
2050 
2051  // Now, check and correct ordering from the highest multiplicity
2052  // state backwards to all the clustered states
2053  if (!mother || !forward) {
2054  // Get index of child along the path
2055  int iChild = -1;
2056  if ( int(index.size()) > 0 ) {
2057  iChild = index.back();
2058  index.pop_back();
2059  }
2060 
2061  // Check that the reclustered scale is above the shower cut
2062  if (mother) {
2063  scale = max(mergingHooksPtr->pTcut(), scale);
2064  }
2065  // If this is NOT the 2->2 process, check and enforce ordering
2066  if (iChild != -1 && !children.empty()) {
2067  if (scale > children[iChild]->scale ) {
2068  if (mergingHooksPtr->unorderedScalePrescip() == 0) {
2069  // Use larger scale as common splitting scale for mother and child
2070  double scaleNew = max( mergingHooksPtr->pTcut(),
2071  max(scale,children[iChild]->scale));
2072  // Enforce ordering in particle production scales
2073  for( int i = 0; i < int(children[iChild]->state.size()); ++i)
2074  if (children[iChild]->state[i].scale() == children[iChild]->scale)
2075  children[iChild]->state[i].scale(scaleNew);
2076  // Enforce ordering in saved clustering scale
2077  children[iChild]->scale = scaleNew;
2078 
2079  } else if ( mergingHooksPtr->unorderedScalePrescip() == 1) {
2080  // Use smaller scale as common splitting scale for mother & child
2081  double scaleNew = max(mergingHooksPtr->pTcut(),
2082  min(scale,children[iChild]->scale));
2083  // Enforce ordering in particle production scales
2084  for( int i = 0; i < int(state.size()); ++i)
2085  if (state[i].scale() == scale)
2086  state[i].scale(scaleNew);
2087  // Enforce ordering in saved clustering scale
2088  scale = scaleNew;
2089  }
2090  // Just set the overall event scale to the minimal scale
2091  } else {
2092  double scalemin = state[0].e();
2093  for( int i = 0; i < int(state.size()); ++i)
2094  if (state[i].colType() != 0)
2095  scalemin = max(mergingHooksPtr->pTcut(),
2096  min(scalemin,state[i].scale()));
2097  state.scale(scalemin);
2098  scale = max(mergingHooksPtr->pTcut(), scale);
2099  }
2100  //Recurse
2101  children[iChild]->setScales(index, false);
2102  }
2103  }
2104 
2105 }
2106 
2107 //--------------------------------------------------------------------------
2108 
2109 // Function to find a particle in all higher multiplicity events
2110 // along the history path and set its production scale to the input
2111 // scale
2112 // IN int iPart : Parton in refEvent to be checked / rescaled
2113 // Event& refEvent : Reference event for iPart
2114 // double scale : Scale to be set as production scale for
2115 // unchanged copies of iPart in subsequent steps
2116 
2117 void History::scaleCopies(int iPart, const Event& refEvent, double rho) {
2118 
2119  // Check if any parton recently rescaled is found unchanged:
2120  // Same charge, colours in mother->state
2121  if ( mother ) {
2122  for( int i=0; i < mother->state.size(); ++i) {
2123  if ( ( mother->state[i].id() == refEvent[iPart].id()
2124  && mother->state[i].colType() == refEvent[iPart].colType()
2125  && mother->state[i].chargeType() == refEvent[iPart].chargeType()
2126  && mother->state[i].col() == refEvent[iPart].col()
2127  && mother->state[i].acol() == refEvent[iPart].acol() )
2128  ) {
2129  // Rescale the unchanged parton
2130  mother->state[i].scale(rho);
2131  // Recurse
2132  if (mother->mother)
2133  mother->scaleCopies( iPart, refEvent, rho );
2134  } // end if found unchanged parton case
2135  } // end loop over particle entries in event
2136  }
2137 }
2138 
2139 //--------------------------------------------------------------------------
2140 
2141 // Functions to set the OVERALL EVENT SCALES [=state.scale()] to
2142 // the scale of the last clustering
2143 // NO INPUT
2144 // NO OUTPUT
2145 
2146 void History::setEventScales() {
2147  // Set the event scale to the scale of the last clustering,
2148  // except for the very lowest multiplicity state
2149  if (mother) {
2150  mother->state.scale(scale);
2151  // Recurse
2152  mother->setEventScales();
2153  }
2154 }
2155 
2156 //--------------------------------------------------------------------------
2157 
2158 // Functions to return the z value of the last ISR splitting
2159 // NO INPUT
2160 // OUTPUT double : z value of last ISR splitting in history
2161 
2162 double History::zISR() {
2163 
2164  // Do nothing for ME level state
2165  if (!mother) return 0.0;
2166  // Skip FSR splitting
2167  if (mother->state[clusterIn.emittor].isFinal()) return mother->zISR();
2168  // Calculate z
2169  int rad = clusterIn.emittor;
2170  int rec = clusterIn.recoiler;
2171  int emt = clusterIn.emitted;
2172  double z = (mother->state[rad].p() + mother->state[rec].p()
2173  - mother->state[emt].p()).m2Calc()
2174  / (mother->state[rad].p() + mother->state[rec].p()).m2Calc();
2175  // Recurse
2176  double znew = mother->zISR();
2177  // Update z
2178  if (znew > 0.) z = znew;
2179 
2180  return z;
2181 }
2182 
2183 //--------------------------------------------------------------------------
2184 
2185 // Functions to return the z value of the last FSR splitting
2186 // NO INPUT
2187 // OUTPUT double : z value of last FSR splitting in history
2188 
2189 double History::zFSR() {
2190 
2191  // Do nothing for ME level state
2192  if (!mother) return 0.0;
2193  // Skip ISR splitting
2194  if (!mother->state[clusterIn.emittor].isFinal()) return mother->zFSR();
2195  // Calculate z
2196  int rad = clusterIn.emittor;
2197  int rec = clusterIn.recoiler;
2198  int emt = clusterIn.emitted;
2199  // Construct 2->3 variables for FSR
2200  Vec4 sum = mother->state[rad].p() + mother->state[rec].p()
2201  + mother->state[emt].p();
2202  double m2Dip = sum.m2Calc();
2203  double x1 = 2. * (sum * mother->state[rad].p()) / m2Dip;
2204  double x3 = 2. * (sum * mother->state[emt].p()) / m2Dip;
2205  // Calculate z of splitting for FSR
2206  double z = x1/(x1+x3);
2207  // Recurse
2208  double znew = mother->zFSR();
2209  // Update z
2210  if (znew > 0.) z = znew;
2211 
2212  return z;
2213 }
2214 
2215 //--------------------------------------------------------------------------
2216 
2217 // Functions to return the pT scale of the last FSR splitting
2218 // NO INPUT
2219 // OUTPUT double : pT scale of last FSR splitting in history
2220 
2221 double History::pTISR() {
2222  // Do nothing for ME level state
2223  if (!mother) return 0.0;
2224  // Skip FSR splitting
2225  if (mother->state[clusterIn.emittor].isFinal()) return mother->pTISR();
2226  double pT = mother->state.scale();
2227  // Recurse
2228  double pTnew = mother->pTISR();
2229  // Update pT
2230  if (pTnew > 0.) pT = pTnew;
2231 
2232  return pT;
2233 }
2234 
2235 //--------------------------------------------------------------------------
2236 
2237 // Functions to return the pT scale of the last FSR splitting
2238 // NO INPUT
2239 // OUTPUT double : pT scale of last FSR splitting in history
2240 
2241 double History::pTFSR() {
2242 
2243  // Do nothing for ME level state
2244  if (!mother) return 0.0;
2245  // Skip ISR splitting
2246  if (!mother->state[clusterIn.emittor].isFinal()) return mother->pTFSR();
2247  double pT = mother->state.scale();
2248  // Recurse
2249  double pTnew = mother->pTFSR();
2250  // Update pT
2251  if (pTnew > 0.) pT = pTnew;
2252  return pT;
2253 }
2254 
2255 //--------------------------------------------------------------------------
2256 
2257 // Function to return the depth of the history (i.e. the number of
2258 // reclustered splittings)
2259 // NO INPUT
2260 // OUTPUT int : Depth of history
2261 
2262 int History::nClusterings() {
2263  if (!mother) return 0;
2264  int w = mother->nClusterings();
2265  w += 1;
2266  return w;
2267 }
2268 
2269 //--------------------------------------------------------------------------
2270 
2271 // Functions to return the event after nSteps splittings of the 2->2 process
2272 // Example: nSteps = 1 -> return event with one additional parton
2273 // INPUT int : Number of splittings in the event,
2274 // as counted from core 2->2 process
2275 // OUTPUT Event : event with nSteps additional partons
2276 
2277 Event History::clusteredState(int nSteps) {
2278 
2279  // Save state
2280  Event outState = state;
2281  // As long as there are steps to do, recursively save state
2282  if (mother && nSteps > 0)
2283  outState = mother->clusteredState(nSteps - 1);
2284  // Done
2285  return outState;
2286 
2287 }
2288 
2289 //--------------------------------------------------------------------------
2290 
2291 // Function to choose a path from all paths in the tree
2292 // according to their splitting probabilities
2293 // IN double : Random number
2294 // OUT History* : Leaf of history path chosen
2295 
2296 History * History::select(double rnd) {
2297 
2298  // No need to choose if no paths have been constructed.
2299  if ( goodBranches.empty() && badBranches.empty() ) return this;
2300 
2301  // Choose amongst paths allowed by projections.
2302  double sum = 0.;
2303  map<double, History*> selectFrom;
2304  if ( !goodBranches.empty() ) {
2305  selectFrom = goodBranches;
2306  sum = sumGoodBranches;
2307  } else {
2308  selectFrom = badBranches;
2309  sum = sumBadBranches;
2310  }
2311 
2312  if (mergingHooksPtr->pickBySumPT()) {
2313  // Find index of history with minimal sum of scalar pT
2314  int nFinal = 0;
2315  for (int i=0; i < state.size(); ++i)
2316  if (state[i].isFinal())
2317  nFinal++;
2318  double iMin = 0.;
2319  double sumMin = (nFinal-2)*state[0].e();
2320  for ( map<double, History*>::iterator it = selectFrom.begin();
2321  it != selectFrom.end(); ++it ) {
2322 
2323  if (it->second->sumScalarPT < sumMin) {
2324  sumMin = it->second->sumScalarPT;
2325  iMin = it->first;
2326  }
2327  }
2328  // Choose history with smallest sum of scalar pT
2329  return selectFrom.lower_bound(iMin)->second;
2330  } else {
2331  // Choose history according to probability, be careful about upper bound
2332  if ( rnd != 1. ) {
2333  return selectFrom.upper_bound(sum*rnd)->second;
2334  } else {
2335  return selectFrom.lower_bound(sum*rnd)->second;
2336  }
2337  }
2338  // Done
2339 }
2340 
2341 //--------------------------------------------------------------------------
2342 
2343 // Function to project paths onto desired paths.
2344 
2345 bool History::trimHistories() {
2346  // Do nothing if no paths have been constructed.
2347  if ( paths.empty() ) return false;
2348  // Loop through all constructed paths. Check all removal conditions.
2349  for ( map<double, History*>::iterator it = paths.begin();
2350  it != paths.end(); ++it ) {
2351  // Check if history is allowed.
2352  if ( it->second->keep() && !it->second->keepHistory() )
2353  it->second->remove();
2354  }
2355  // Project onto desired / undesired branches.
2356  double sumold, sumnew, sumprob, mismatch;
2357  sumold = sumnew = sumprob = mismatch = 0.;
2358  // Loop through all constructed paths and store allowed paths.
2359  // Skip undesired paths.
2360  for ( map<double, History*>::iterator it = paths.begin();
2361  it != paths.end(); ++it ) {
2362  // Update index
2363  sumnew = it->first;
2364  if ( it->second->keep() ) {
2365  // Fill branches with allowed paths.
2366  goodBranches.insert( make_pair( sumnew - mismatch, it->second) );
2367  // Add probability of this path.
2368  sumGoodBranches = sumnew - mismatch;
2369  } else {
2370  // Update mismatch in probabilities resulting from not including this
2371  // path
2372  double mismatchOld = mismatch;
2373  mismatch += sumnew - sumold;
2374  // Fill branches with allowed paths.
2375  badBranches.insert( make_pair( mismatchOld + sumnew - sumold,
2376  it->second ) );
2377  // Add probability of this path.
2378  sumBadBranches = mismatchOld + sumnew - sumold;
2379  }
2380  // remember index of this path in order to caclulate probability of
2381  // subsequent path.
2382  sumold = it->first;
2383  }
2384 
2385  // Done
2386  return !goodBranches.empty();
2387 }
2388 
2389 //--------------------------------------------------------------------------
2390 
2391 // Function implementing checks on a paths, deciding if the path is valid.
2392 
2393 bool History::keepHistory() {
2394  bool keepPath = true;
2395 
2396  // Tag unordered paths for removal.
2397  if ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
2398  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0
2399  || isQCD2to2(state) ) {
2400  // Tag unordered paths for removal. Include scale of hard 2->2 process
2401  // into the ordering definition.
2402  double maxScale = hardFacScale(state);
2403  return keepPath = isOrderedPath( maxScale );
2404  }
2405 
2406  // Set starting scale to mass of Drell-Yan for 2->1.
2407  if (isEW2to1(state)) {
2408  Vec4 pSum(0,0,0,0);
2409  for (int i = 0;i < state.size(); ++i)
2410  if (state[i].isFinal()) pSum += state[i].p();
2411  return isOrderedPath( pSum.mCalc());
2412  }
2413 
2414  keepPath = isOrderedPath( infoPtr->eCM() );
2415 
2416  // More stringent criterion.
2417  //keepPath = allIntermediateAboveRhoMS( mergingHooksPtr->tms() );
2418 
2419  // Do not keep extremely unlikely paths.
2420  if (probMax() > 0. && abs(prob) < 1e-10*probMax()) keepPath=false;
2421 
2422 
2423  //Done
2424  return keepPath;
2425 }
2426 
2427 //--------------------------------------------------------------------------
2428 
2429 // Function to check if a path is ordered in evolution pT.
2430 
2431 bool History::isOrderedPath( double maxscale ) {
2432  double newscale = clusterIn.pT();
2433  if ( !mother ) return true;
2434  if ( mother->state[clusterIn.emittor].idAbs() == 21
2435  && mother->state[clusterIn.emitted].idAbs() == 5
2436  && !mother->state[clusterIn.emittor].isFinal())
2437  newscale=maxscale;
2438  bool ordered = mother->isOrderedPath(newscale);
2439  if ( !ordered || maxscale < newscale) return false;
2440  return ordered;
2441 }
2442 
2443 //--------------------------------------------------------------------------
2444 
2445 // Function to check if all reconstucted states in a path pass the merging
2446 // scale cut.
2447 
2448 bool History::allIntermediateAboveRhoMS( double rhoms, bool good ) {
2449  // If one state below the merging scale has already been found, no need to
2450  // check further.
2451  if ( !good ) return false;
2452  // Check merging scale for states with more than 0 jets
2453  int nFinal = 0;
2454  for ( int i = 0; i < state.size(); ++i )
2455  if ( state[i].isFinal() && state[i].colType() != 0 )
2456  nFinal++;
2457  double rhoNew = (nFinal > 0 ) ? mergingHooksPtr->tmsNow( state )
2458  : state[0].e();
2459  // Assume state from ME generator passes merging scale cut.
2460  if ( !mother ) return good;
2461  // Recurse.
2462  return mother->allIntermediateAboveRhoMS( rhoms, (rhoNew > rhoms) );
2463 }
2464 
2465 //--------------------------------------------------------------------------
2466 
2467 // Function to check if any ordered paths were found (and kept).
2468 
2469 bool History::foundAnyOrderedPaths() {
2470  //Do nothing if no paths were found
2471  if ( paths.empty() ) return false;
2472  double maxscale = infoPtr->eCM();
2473  // Loop through paths. Divide probability into ordered and unordered pieces.
2474  for ( map<double, History*>::iterator it = paths.begin();
2475  it != paths.end(); ++it )
2476  if ( it->second->isOrderedPath(maxscale) )
2477  return true;
2478  // Done
2479  return false;
2480 }
2481 
2482 //--------------------------------------------------------------------------
2483 
2484 // For a full path, find the weight calculated from the ratio of
2485 // couplings, the no-emission probabilities, and possible PDF
2486 // ratios. This function should only be called for the last history
2487 // node of a full path.
2488 // IN TimeShower : Already initialised shower object to be used as
2489 // trial shower
2490 // double : alpha_s value used in ME calculation
2491 // double : Maximal mass scale of the problem (e.g. E_CM)
2492 // AlphaStrong: Initialised shower alpha_s object for FSR
2493 // alpha_s ratio calculation
2494 // AlphaStrong: Initialised shower alpha_s object for ISR
2495 // alpha_s ratio calculation (can be different from previous)
2496 
2497 vector<double> History::weightTree(PartonLevel* trial, double as0, double aem0,
2498  double maxscale, double pdfScale, AlphaStrong * asFSR, AlphaStrong * asISR,
2499  AlphaEM * aemFSR, AlphaEM * aemISR, vector<double>& asWeight,
2500  vector<double>& aemWeight, vector<double>& pdfWeight) {
2501 
2502  // Use correct scale
2503  double newScale = scale;
2504 
2505  int nWgts = mergingHooksPtr->nWgts;
2506 
2507  // For ME state, just multiply by PDF ratios
2508  if ( !mother ) {
2509 
2510  int sideRad = (state[3].pz() > 0) ? 1 :-1;
2511  int sideRec = (state[4].pz() > 0) ? 1 :-1;
2512 
2513  // Calculate PDF first leg
2514  if (state[3].colType() != 0) {
2515  // Find x value and flavour
2516  double x = 2.*state[3].e() / state[0].e();
2517  int flav = state[3].id();
2518  // Find numerator/denominator scale
2519  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
2520  double scaleDen = mergingHooksPtr->muFinME();
2521  // For initial parton, multiply by PDF ratio
2522  double ratio = getPDFratio(sideRad, false, false, flav, x, scaleNum,
2523  flav, x, scaleDen);
2524  for (double& pdfW: pdfWeight) pdfW *= ratio;
2525  }
2526 
2527  // Calculate PDF ratio for second leg
2528  if (state[4].colType() != 0) {
2529  // Find x value and flavour
2530  double x = 2.*state[4].e() / state[0].e();
2531  int flav = state[4].id();
2532  // Find numerator/denominator scale
2533  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
2534  double scaleDen = mergingHooksPtr->muFinME();
2535  // For initial parton, multiply with PDF ratio
2536  double ratio = getPDFratio(sideRec, false, false, flav, x, scaleNum,
2537  flav, x, scaleDen);
2538  for (double& pdfW: pdfWeight) pdfW *= ratio;
2539  }
2540  return vector<double>(nWgts,1.);
2541  }
2542 
2543  // Remember new PDF scale n case true scale should be used for un-ordered
2544  // splittings.
2545  double newPDFscale = newScale;
2546  if (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2547  newPDFscale = clusterIn.pT();
2548 
2549  // Recurse
2550  vector<double> w = mother->weightTree(trial, as0, aem0, newScale,
2551  newPDFscale, asFSR, asISR, aemFSR, aemISR, asWeight, aemWeight,
2552  pdfWeight);
2553 
2554  // Do nothing for empty state
2555  if (state.size() < 3) return vector<double>(nWgts,1.);
2556  // If up to now, trial shower was not successful, return zero
2557  if ( w[0] < 1e-12 ) return vector<double>(nWgts,0.);
2558  // Do trial shower on current state, return zero if not successful
2559  vector<double> wTrial = doTrialShower(trial, 1, maxscale);
2560  for (int iVar = 0; iVar < nWgts; ++iVar)
2561  w[iVar] *= wTrial[iVar];
2562  if ( w[0] < 1e-12 ) return vector<double>( nWgts, 0. );
2563 
2564  int emtType = mother->state[clusterIn.emitted].colType();
2565  // Calculate alpha_s ratio for current state.
2566  if ( asFSR && asISR && emtType != 0) {
2567  double asScale = pow2( newScale );
2568  if (mergingHooksPtr->unorderedASscalePrescip() == 1)
2569  asScale = pow2( clusterIn.pT() );
2570 
2571  // Add regularisation scale to initial state alpha_s.
2572  bool FSR = mother->state[clusterIn.emittor].isFinal();
2573  if (!FSR) asScale += pow2(mergingHooksPtr->pT0ISR());
2574 
2575  // Directly get argument of running alpha_s from shower plugin.
2576  if (mergingHooksPtr->useShowerPlugin() )
2577  asScale = getShowerPluginScale(mother->state, clusterIn.emittor,
2578  clusterIn.emitted, clusterIn.recoiler, "scaleAS", asScale);
2579 
2580  double alphaSinPS = (FSR) ? (*asFSR).alphaS(asScale)
2581  : (*asISR).alphaS(asScale);
2582  asWeight[0] *= alphaSinPS / as0;
2583 
2584  // Scale variations
2585  for (int iVar = 1; iVar < nWgts; ++iVar) {
2586  alphaSinPS = (FSR) ?
2587  asFSR->alphaS(pow2(mergingHooksPtr->muRVarFactors[iVar-1])*asScale) :
2588  asISR->alphaS(pow2(mergingHooksPtr->muRVarFactors[iVar-1])*asScale);
2589  asWeight[iVar] *= alphaSinPS / as0;
2590  }
2591  }
2592 
2593  // Calculate alpha_em ratio for current state.
2594  if ( aemFSR && aemISR && emtType == 0 ) {
2595  double aemScale = pow2( newScale );
2596  if (mergingHooksPtr->unorderedASscalePrescip() == 1)
2597  aemScale = pow2( clusterIn.pT() );
2598 
2599  // Add regularisation scale to initial state alpha_s.
2600  bool FSR = mother->state[clusterIn.emittor].isFinal();
2601  if (!FSR) aemScale += pow2(mergingHooksPtr->pT0ISR());
2602 
2603  // Directly get argument of running alpha_em from shower plugin.
2604  if (mergingHooksPtr->useShowerPlugin() )
2605  aemScale = getShowerPluginScale(mother->state, clusterIn.emittor,
2606  clusterIn.emitted, clusterIn.recoiler, "scaleEM", aemScale);
2607 
2608  double alphaEMinPS = (FSR) ? (*aemFSR).alphaEM(aemScale)
2609  : (*aemISR).alphaEM(aemScale);
2610  for (double& aemW: aemWeight) aemW *= alphaEMinPS / aem0;
2611  }
2612 
2613  // Calculate pdf ratios: Get both sides of event
2614  int inP = 3;
2615  int inM = 4;
2616  int sideP = (mother->state[inP].pz() > 0) ? 1 :-1;
2617  int sideM = (mother->state[inM].pz() > 0) ? 1 :-1;
2618 
2619  if ( mother->state[inP].colType() != 0 ) {
2620  // Find x value and flavour
2621  double x = getCurrentX(sideP);
2622  int flav = getCurrentFlav(sideP);
2623  // Find numerator scale
2624  double scaleNum = (children.empty())
2625  ? hardFacScale(state)
2626  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2627  ? pdfScale : maxscale );
2628  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2629  ? clusterIn.pT() : newScale;
2630  // Multiply PDF ratio
2631  double ratio = getPDFratio(sideP, false, false, flav, x, scaleNum,
2632  flav, x, scaleDen);
2633  for (double& pdfW: pdfWeight) pdfW *= ratio;
2634  }
2635 
2636  if ( mother->state[inM].colType() != 0 ) {
2637  // Find x value and flavour
2638  double x = getCurrentX(sideM);
2639  int flav = getCurrentFlav(sideM);
2640  // Find numerator scale
2641  double scaleNum = (children.empty())
2642  ? hardFacScale(state)
2643  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2644  ? pdfScale : maxscale );
2645  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2646  ? clusterIn.pT() : newScale;
2647  // Multiply PDF ratio
2648  double ratio = getPDFratio(sideM, false, false, flav, x, scaleNum,
2649  flav, x, scaleDen);
2650  for (double& pdfW: pdfWeight) pdfW *= ratio;
2651  }
2652 
2653  // Done
2654  return w;
2655 }
2656 
2657 //--------------------------------------------------------------------------
2658 
2659 // Function to return the \alpha_s-ratio part of the CKKWL weight of a path.
2660 
2661 vector<double> History::weightTreeAlphaS( double as0, AlphaStrong * asFSR,
2662  AlphaStrong * asISR, int njetMax, bool asVarInME ) {
2663 
2664  int nWgts = mergingHooksPtr->nWgts;
2665 
2666  // For ME state, do nothing.
2667  if ( !mother ) return vector<double>(nWgts,1.);
2668  // Recurse
2669  vector<double> w = mother->weightTreeAlphaS( as0, asFSR, asISR, njetMax,
2670  asVarInME );
2671  // Do nothing for empty state
2672  if (state.size() < 3) return w;
2673 
2674  // If this node has too many jets, no not calculate no-emission probability.
2675  int njetNow = mergingHooksPtr->getNumberOfClusteringSteps( state) ;
2676  if (njetNow >= njetMax) return vector<double>( nWgts, 1.0 );
2677 
2678  // Store variables for easy use.
2679  bool FSR = mother->state[clusterIn.emittor].isFinal();
2680  int emtID = mother->state[clusterIn.emitted].id();
2681 
2682  // Do not correct alphaS if it is an EW emission.
2683  if (abs(emtID) == 22 || abs(emtID) == 23 || abs(emtID) == 24) return w;
2684 
2685  // Calculate alpha_s ratio for current state
2686  if ( asFSR && asISR ) {
2687  double asScale = pow2( scale );
2688  if (mergingHooksPtr->unorderedASscalePrescip() == 1)
2689  asScale = pow2( clusterIn.pT() );
2690 
2691  // Add regularisation scale to initial state alpha_s.
2692  if (!FSR) asScale += pow2(mergingHooksPtr->pT0ISR());
2693 
2694  // Directly get argument of running alpha_s from shower plugin.
2695  if (mergingHooksPtr->useShowerPlugin() )
2696  asScale = getShowerPluginScale(mother->state, clusterIn.emittor,
2697  clusterIn.emitted, clusterIn.recoiler, "scaleAS", asScale);
2698 
2699  double alphaSinPS = (FSR) ? (*asFSR).alphaS(asScale)
2700  : (*asISR).alphaS(asScale);
2701  w[0] *= alphaSinPS / as0;
2702 
2703  // Scale variations
2704  for (int iVar = 1; iVar < nWgts; ++iVar) {
2705  alphaSinPS = (FSR) ?
2706  asFSR->alphaS(pow2(mergingHooksPtr->muRVarFactors[iVar-1])*asScale) :
2707  asISR->alphaS(pow2(mergingHooksPtr->muRVarFactors[iVar-1])*asScale);
2708  // Respect variations in ME if present (NLO input)
2709  double muR2 = pow2(mergingHooksPtr->muRinMESave);
2710  double alphaSinME = (!asVarInME) ? as0 : ((FSR) ?
2711  asFSR->alphaS(muR2*pow2(mergingHooksPtr->muRVarFactors[iVar-1])) :
2712  asISR->alphaS(muR2*pow2(mergingHooksPtr->muRVarFactors[iVar-1])));
2713  w[iVar] *= alphaSinPS / alphaSinME;
2714  }
2715  }
2716 
2717  // Done
2718  return w;
2719 }
2720 
2721 //--------------------------------------------------------------------------
2722 
2723 // Function to return the \alpha_em-ratio part of the CKKWL weight of a path.
2724 
2725 vector<double> History::weightTreeAlphaEM( double aem0, AlphaEM * aemFSR,
2726  AlphaEM * aemISR, int njetMax ) {
2727 
2728  int nWgts = mergingHooksPtr->nWgts;
2729 
2730  // For ME state, do nothing.
2731  if ( !mother ) return vector<double>( nWgts, 1. );
2732  // Recurse
2733  vector<double> w = mother->weightTreeAlphaEM( aem0, aemFSR, aemISR,
2734  njetMax );
2735  // Do nothing for empty state
2736  if (state.size() < 3) return w;
2737 
2738  // If this node has too many jets, no not calculate no-emission probability.
2739  int njetNow = mergingHooksPtr->getNumberOfClusteringSteps( state) ;
2740  if (njetNow >= njetMax) return vector<double>( nWgts, 1.0 );
2741 
2742  // Store variables for easy use.
2743  bool FSR = mother->state[clusterIn.emittor].isFinal();
2744  int emtID = mother->state[clusterIn.emitted].id();
2745 
2746  // Do not correct alpha EM if it not an EW emission.
2747  if (!(abs(emtID) == 22 || abs(emtID) == 23 || abs(emtID) == 24)) return w;
2748 
2749  // Calculate alpha_s ratio for current state
2750  if ( aemFSR && aemISR ) {
2751  double aemScale = pow2( scale );
2752  if (mergingHooksPtr->unorderedASscalePrescip() == 1)
2753  aemScale = pow2( clusterIn.pT() );
2754 
2755  // Add regularisation scale to initial state alpha_em.
2756  if (!FSR) aemScale += pow2(mergingHooksPtr->pT0ISR());
2757 
2758  // Directly get argument of running alpha_em from shower plugin.
2759  if (mergingHooksPtr->useShowerPlugin() )
2760  aemScale = getShowerPluginScale(mother->state, clusterIn.emittor,
2761  clusterIn.emitted, clusterIn.recoiler, "scaleEM", aemScale);
2762 
2763  double alphaEMinPS = (FSR) ? (*aemFSR).alphaEM(aemScale)
2764  : (*aemISR).alphaEM(aemScale);
2765  for (double& wi: w) wi *= alphaEMinPS / aem0;
2766  }
2767 
2768  // Done
2769  return w;
2770 }
2771 
2772 //--------------------------------------------------------------------------
2773 
2774 // Function to return the PDF-ratio part of the CKKWL weight of a path.
2775 
2776 vector<double> History::weightTreePDFs( double maxscale, double pdfScale,
2777  int njetMax ) {
2778 
2779  // Use correct scale
2780  double newScale = scale;
2781 
2782  double nWgts = mergingHooksPtr->nWgts;
2783 
2784  // For ME state, just multiply by PDF ratios
2785  if ( !mother ) {
2786 
2787  // If this node has too many jets, do not calculate PDF ratio.
2788  int njet = mergingHooksPtr->getNumberOfClusteringSteps( state);
2789  if (njet > njetMax) return vector<double>( nWgts, 1.0 );
2790 
2791  vector<double> wt( nWgts, 1. );
2792  int sideRad = (state[3].pz() > 0) ? 1 :-1;
2793  int sideRec = (state[4].pz() > 0) ? 1 :-1;
2794 
2795  // Calculate PDF first leg
2796  if (state[3].colType() != 0) {
2797  // Find x value and flavour
2798  double x = 2.*state[3].e() / state[0].e();
2799  int flav = state[3].id();
2800  // Find numerator/denominator scale
2801  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
2802  double scaleDen = mergingHooksPtr->muFinME();
2803  // For initial parton, multiply by PDF ratio
2804  double ratio = getPDFratio(sideRad, false, false, flav, x, scaleNum,
2805  flav, x, scaleDen);
2806  for (double& w: wt) w *= ratio;
2807  }
2808 
2809  // Calculate PDF ratio for second leg
2810  if (state[4].colType() != 0) {
2811  // Find x value and flavour
2812  double x = 2.*state[4].e() / state[0].e();
2813  int flav = state[4].id();
2814  // Find numerator/denominator scale
2815  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
2816  double scaleDen = mergingHooksPtr->muFinME();
2817  // For initial parton, multiply with PDF ratio
2818  double ratio = getPDFratio(sideRec, false, false, flav, x, scaleNum,
2819  flav, x, scaleDen);
2820  for (double& w: wt) w *= ratio;
2821  }
2822 
2823  return wt;
2824  }
2825 
2826  // Remember new PDF scale n case true scale should be used for un-ordered
2827  // splittings.
2828  double newPDFscale = newScale;
2829  if ( mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2830  newPDFscale = clusterIn.pT();
2831 
2832  // Recurse
2833  vector<double> w = mother->weightTreePDFs( newScale, newPDFscale, njetMax );
2834 
2835  // Do nothing for empty state
2836  if (state.size() < 3) return w;
2837 
2838  // If this node has too many jets, do not calculate PDF ratio.
2839  int njetNow = mergingHooksPtr->getNumberOfClusteringSteps( state) ;
2840  if (njetNow >= njetMax) return vector<double>( nWgts, 1. );
2841 
2842  // Calculate pdf ratios: Get both sides of event
2843  int inP = 3;
2844  int inM = 4;
2845  int sideP = (mother->state[inP].pz() > 0) ? 1 :-1;
2846  int sideM = (mother->state[inM].pz() > 0) ? 1 :-1;
2847 
2848  if ( mother->state[inP].colType() != 0 ) {
2849  // Find x value and flavour
2850  double x = getCurrentX(sideP);
2851  int flav = getCurrentFlav(sideP);
2852  // Find numerator scale
2853  double scaleNum = (children.empty())
2854  ? hardFacScale(state)
2855  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2856  ? pdfScale : maxscale );
2857  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2858  ? clusterIn.pT() : newScale;
2859 
2860  double xDen = (njetNow == njetMax) ? mother->getCurrentX(sideP) : x;
2861  int flavDen = (njetNow == njetMax) ? mother->getCurrentFlav(sideP) : flav;
2862  double sDen = (njetNow == njetMax) ? mergingHooksPtr->muFinME() : scaleDen;
2863  double ratio = getPDFratio(sideP, false, false, flav, x, scaleNum,
2864  flavDen, xDen, sDen);
2865  for (double& wi: w) wi *= ratio;
2866  }
2867 
2868  if ( mother->state[inM].colType() != 0 ) {
2869  // Find x value and flavour
2870  double x = getCurrentX(sideM);
2871  int flav = getCurrentFlav(sideM);
2872  // Find numerator scale
2873  double scaleNum = (children.empty())
2874  ? hardFacScale(state)
2875  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2876  ? pdfScale : maxscale );
2877  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2878  ? clusterIn.pT() : newScale;
2879 
2880  double xDen = (njetNow == njetMax) ? mother->getCurrentX(sideM) : x;
2881  int flavDen = (njetNow == njetMax) ? mother->getCurrentFlav(sideM) : flav;
2882  double sDen = (njetNow == njetMax) ? mergingHooksPtr->muFinME() : scaleDen;
2883  double ratio = getPDFratio(sideM, false, false, flav, x, scaleNum,
2884  flavDen, xDen, sDen);
2885  for (double& wi: w) wi *= ratio;
2886  }
2887 
2888  // Done
2889  return w;
2890 }
2891 
2892 //--------------------------------------------------------------------------
2893 
2894 // Function to return the no-emission probability part of the CKKWL weight.
2895 
2896 vector<double> History::weightTreeEmissions( PartonLevel* trial, int type,
2897  int njetMin, int njetMax, double maxscale ) {
2898 
2899  int nWgts = mergingHooksPtr->nWgts;
2900 
2901  if (type == -1 && !mergingHooksPtr->settingsPtr->flag("PartonLevel:MPI"))
2902  return vector<double>( nWgts, 1. );
2903 
2904  // Use correct scale
2905  double newScale = scale;
2906  // For ME state, just multiply by PDF ratios
2907 
2908  if ( !mother ) return vector<double>( nWgts, 1.0 );
2909  // Recurse
2910  vector<double> w = mother->weightTreeEmissions( trial, type, njetMin,
2911  njetMax, newScale );
2912  // Do nothing for empty state
2913  if (state.size() < 3) return vector<double>( nWgts, 1.0 );
2914  // If up to now, trial shower was not successful, return zero
2915  if ( w[0] < 1e-12 ) return vector<double>( nWgts, 0.0 );
2916  // If this node has too many jets, do not calculate no-emission probability.
2917  int njetNow = mergingHooksPtr->getNumberOfClusteringSteps( state) ;
2918  if (njetNow >= njetMax) return vector<double>( nWgts, 1.0);
2919  // Do trial shower on current state, return zero if not successful
2920  else {
2921  vector<double> wTrial = doTrialShower( trial, type, maxscale );
2922  for (int iVar = 0; iVar < nWgts; ++iVar) w[iVar] *= wTrial[iVar];
2923  }
2924  if ( w[0] < 1e-12 ) return vector<double>( nWgts, 0.0 );
2925  // Done
2926  return w;
2927 
2928 }
2929 
2930 //--------------------------------------------------------------------------
2931 
2932 // Function to generate the O(\alpha_s)-term of the CKKWL-weight.
2933 
2934 double History::weightFirst(PartonLevel* trial, double as0, double muR,
2935  double maxscale, AlphaStrong * asFSR, AlphaStrong * asISR, Rndm* rndmPtr ) {
2936 
2937  // Use correct scale
2938  double newScale = scale;
2939 
2940  if ( !mother ) {
2941 
2942  double weight = 0.;
2943 
2944  // Calculate PDF first leg
2945  if (state[3].colType() != 0) {
2946  // Find x value and flavour
2947  double x = 2.*state[3].e() / state[0].e();
2948  int flav = state[3].id();
2949  // Find numerator/denominator scale
2950  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
2951  double scaleDen = mergingHooksPtr->muFinME();
2952  // Monte Carlo integrand.
2953  double intPDF4 = monteCarloPDFratios(flav, x, scaleNum, scaleDen,
2954  mergingHooksPtr->muFinME(), as0, rndmPtr);
2955  weight += intPDF4;
2956  }
2957 
2958  // Calculate PDF ratio for second leg
2959  if (state[4].colType() != 0) {
2960  // Find x value and flavour
2961  double x = 2.*state[4].e() / state[0].e();
2962  int flav = state[4].id();
2963  // Find numerator/denominator scale
2964  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
2965  double scaleDen = mergingHooksPtr->muFinME();
2966  // Monte Carlo integrand.
2967  double intPDF4 = monteCarloPDFratios(flav, x, scaleNum, scaleDen,
2968  mergingHooksPtr->muFinME(), as0, rndmPtr);
2969  weight += intPDF4;
2970  }
2971 
2972  return weight;
2973  }
2974 
2975  // Recurse
2976  double w = mother->weightFirst(trial, as0, muR, newScale, asFSR, asISR,
2977  rndmPtr );
2978 
2979  // Do nothing for empty state
2980  if (state.size() < 3) return 0.0;
2981 
2982  // Find right scale
2983  double b = 1.;
2984  double asScale2 = newScale*newScale;
2985  int showerType = (mother->state[clusterIn.emittor].isFinal() ) ? 1 : -1;
2986  if (showerType == -1) {
2987  asScale2 += pow(mergingHooksPtr->pT0ISR(),2);
2988  b = 1.;
2989  }
2990 
2991  // Directly get argument of running alpha_s from shower plugin.
2992  if (mergingHooksPtr->useShowerPlugin() ){
2993  asScale2 = getShowerPluginScale(mother->state, clusterIn.emittor,
2994  clusterIn.emitted, clusterIn.recoiler, "scaleAS", asScale2);
2995  b = 1.;
2996  }
2997 
2998  // Find summand beta_0 / 2 * ln(muR^2/t_i) due to as expansion.
2999  double NF = 4.;
3000  double BETA0 = 11. - 2./3.* NF;
3001  // For fixed \alpha_s in matrix element
3002  w += as0 / (2.*M_PI) * 0.5 * BETA0 * log( (muR*muR) / (b*asScale2) );
3003 
3004  // Count emissions: New variant
3005  // Generate true average, not only one-point.
3006  bool fixpdf = true;
3007  bool fixas = true;
3008  double nWeight1 = 0.;
3009  double nWeight2 = 0.;
3010 
3011  for(int i=0; i < NTRIAL; ++i) {
3012  // Get number of emissions
3013  vector<double> unresolvedEmissionTerm = countEmissions(trial, maxscale,
3014  newScale, 2, as0, asFSR, asISR, 3, fixpdf, fixas);
3015  nWeight1 += unresolvedEmissionTerm[1];
3016  }
3017  w += nWeight1/double(NTRIAL) + nWeight2/double(NTRIAL);
3018 
3019  // Calculate pdf ratios: Get both sides of event
3020  int inP = 3;
3021  int inM = 4;
3022  int sideP = (mother->state[inP].pz() > 0) ? 1 :-1;
3023  int sideM = (mother->state[inM].pz() > 0) ? 1 :-1;
3024 
3025  if ( mother->state[inP].colType() != 0 ) {
3026  // Find x value and flavour
3027  double x = getCurrentX(sideP);
3028  int flav = getCurrentFlav(sideP);
3029  // Find numerator scale
3030  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
3031  // Monte Carlo integrand.
3032  double intPDF4 = monteCarloPDFratios(flav, x, scaleNum, newScale,
3033  mergingHooksPtr->muFinME(), as0, rndmPtr);
3034  w += intPDF4;
3035 
3036  }
3037 
3038  if ( mother->state[inM].colType() != 0 ) {
3039  // Find x value and flavour
3040  double x = getCurrentX(sideM);
3041  int flav = getCurrentFlav(sideM);
3042  // Find numerator scale
3043  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
3044  // Monte Carlo integrand.
3045  double intPDF4 = monteCarloPDFratios(flav, x, scaleNum, newScale,
3046  mergingHooksPtr->muFinME(), as0, rndmPtr);
3047  w += intPDF4;
3048 
3049  }
3050 
3051  // Done
3052  return w;
3053 
3054 }
3055 
3056 //--------------------------------------------------------------------------
3057 
3058 // Function to generate the O(\alpha_s)-term of the \alpha_s-ratios
3059 // appearing in the CKKWL-weight.
3060 
3061 double History::weightFirstAlphaS( double as0, double muR,
3062  AlphaStrong * asFSR, AlphaStrong * asISR ) {
3063 
3064  // Use correct scale
3065  double newScale = scale;
3066  // Done
3067  if ( !mother ) return 0.;
3068  // Recurse
3069  double w = mother->weightFirstAlphaS( as0, muR, asFSR, asISR );
3070  // Find right scale
3071  int showerType = (mother->state[clusterIn.emittor].isFinal() ) ? 1 : -1;
3072  double b = 1.;
3073  double asScale = pow2( newScale );
3074  if ( mergingHooksPtr->unorderedASscalePrescip() == 1 )
3075  asScale = pow2( clusterIn.pT() );
3076  if (showerType == -1) {
3077  asScale += pow2( mergingHooksPtr->pT0ISR() );
3078  b = 1.;
3079  }
3080 
3081  // Directly get argument of running alpha_s from shower plugin.
3082  if (mergingHooksPtr->useShowerPlugin() ) {
3083  asScale = getShowerPluginScale(mother->state, clusterIn.emittor,
3084  clusterIn.emitted, clusterIn.recoiler, "scaleAS", asScale);
3085  b = 1.;
3086  }
3087 
3088  // Find summand beta_0 / 2 * ln(muR^2/t_i) due to as expansion.
3089  double NF = 4.;
3090  double BETA0 = 11. - 2./3.* NF;
3091  // For fixed \alpha_s in matrix element
3092  w += as0 / (2.*M_PI) * 0.5 * BETA0 * log( (muR*muR) / (b*asScale) );
3093 
3094  // Done
3095  return w;
3096 
3097 }
3098 
3099 //--------------------------------------------------------------------------
3100 
3101 // Function to generate the O(\alpha_s)-term of the PDF-ratios
3102 // appearing in the CKKWL-weight.
3103 
3104 double History::weightFirstPDFs( double as0, double maxscale, double pdfScale,
3105  Rndm* rndmPtr ) {
3106 
3107  // Use correct scale
3108  double newScale = scale;
3109 
3110  if ( !mother ) {
3111 
3112  double wt = 0.;
3113 
3114  // Calculate PDF first leg
3115  if (state[3].colType() != 0) {
3116  // Find x value and flavour
3117  double x = 2.*state[3].e() / state[0].e();
3118  int flav = state[3].id();
3119  // Find numerator/denominator scale
3120  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
3121  double scaleDen = mergingHooksPtr->muFinME();
3122  // Monte Carlo integrand.
3123  wt += monteCarloPDFratios(flav, x, scaleNum, scaleDen,
3124  mergingHooksPtr->muFinME(), as0, rndmPtr);
3125  }
3126  // Calculate PDF ratio for second leg
3127  if (state[4].colType() != 0) {
3128  // Find x value and flavour
3129  double x = 2.*state[4].e() / state[0].e();
3130  int flav = state[4].id();
3131  // Find numerator/denominator scale
3132  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
3133  double scaleDen = mergingHooksPtr->muFinME();
3134  // Monte Carlo integrand.
3135  wt += monteCarloPDFratios(flav, x, scaleNum, scaleDen,
3136  mergingHooksPtr->muFinME(), as0, rndmPtr);
3137  }
3138 
3139  // Done
3140  return wt;
3141  }
3142 
3143  // Remember new PDF scale n case true scale should be used for un-ordered
3144  // splittings.
3145  double newPDFscale = newScale;
3146  if (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
3147  newPDFscale = clusterIn.pT();
3148 
3149  // Recurse
3150  double w = mother->weightFirstPDFs( as0, newScale, newPDFscale, rndmPtr);
3151 
3152  // Calculate pdf ratios: Get both sides of event
3153  int inP = 3;
3154  int inM = 4;
3155  int sideP = (mother->state[inP].pz() > 0) ? 1 :-1;
3156  int sideM = (mother->state[inM].pz() > 0) ? 1 :-1;
3157 
3158  if ( mother->state[inP].colType() != 0 ) {
3159  // Find x value and flavour
3160  double x = getCurrentX(sideP);
3161  int flav = getCurrentFlav(sideP);
3162  // Find numerator / denominator scales
3163  double scaleNum = (children.empty())
3164  ? hardFacScale(state)
3165  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
3166  ? pdfScale : maxscale );
3167  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
3168  ? clusterIn.pT() : newScale;
3169  // Monte Carlo integrand.
3170  w += monteCarloPDFratios(flav, x, scaleNum, scaleDen,
3171  mergingHooksPtr->muFinME(), as0, rndmPtr);
3172  }
3173 
3174  if ( mother->state[inM].colType() != 0 ) {
3175  // Find x value and flavour
3176  double x = getCurrentX(sideM);
3177  int flav = getCurrentFlav(sideM);
3178  // Find numerator / denominator scales
3179  double scaleNum = (children.empty())
3180  ? hardFacScale(state)
3181  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
3182  ? pdfScale : maxscale );
3183  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
3184  ? clusterIn.pT() : newScale;
3185  // Monte Carlo integrand.
3186  w += monteCarloPDFratios(flav, x, scaleNum, scaleDen,
3187  mergingHooksPtr->muFinME(), as0, rndmPtr);
3188  }
3189 
3190  // Done
3191  return w;
3192 
3193 }
3194 
3195 
3196 //--------------------------------------------------------------------------
3197 
3198 // Function to generate the O(\alpha_s)-term of the no-emission
3199 // probabilities appearing in the CKKWL-weight.
3200 
3201 double History::weightFirstEmissions(PartonLevel* trial, double as0,
3202  double maxscale, AlphaStrong * asFSR, AlphaStrong * asISR,
3203  bool fixpdf, bool fixas ) {
3204 
3205  // Use correct scale
3206  double newScale = scale;
3207  if ( !mother ) return 0.0;
3208  // Recurse
3209  double w = mother->weightFirstEmissions(trial, as0, newScale, asFSR, asISR,
3210  fixpdf, fixas );
3211  // Do nothing for empty state
3212  if (state.size() < 3) return 0.0;
3213  // Generate true average.
3214  double nWeight1 = 0.;
3215  double nWeight2 = 0.;
3216  for(int i=0; i < NTRIAL; ++i) {
3217  // Get number of emissions
3218  vector<double> unresolvedEmissionTerm = countEmissions(trial, maxscale,
3219  newScale, 2, as0, asFSR, asISR, 3, fixpdf, fixas);
3220  nWeight1 += unresolvedEmissionTerm[1];
3221  }
3222 
3223  w += nWeight1/double(NTRIAL) + nWeight2/double(NTRIAL);
3224 
3225  // Done
3226  return w;
3227 
3228 }
3229 
3230 //--------------------------------------------------------------------------
3231 
3232 // Function to return the factorisation scale of the hard process in Pythia.
3233 
3234 double History::hardFacScale(const Event& event) {
3235  // Declare output scale.
3236  double hardscale = 0.;
3237  // If scale should not be reset, done.
3238  if ( !mergingHooksPtr->resetHardQFac() ) return mergingHooksPtr->muF();
3239  // For pure QCD dijet events, calculate the hadronic cross section
3240  // of the hard process at the pT of the dijet system, rather than at fixed
3241  // arbitrary scale.
3242  if ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
3243  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0
3244  || isQCD2to2(event)) {
3245  // Find the mT in the hard sub-process.
3246  vector <double> mT;
3247  for ( int i=0; i < event.size(); ++i)
3248  if ( event[i].isFinal() && event[i].colType() != 0 )
3249  mT.push_back( abs(event[i].mT2()) );
3250  if ( int(mT.size()) != 2 )
3251  hardscale = infoPtr->QFac();
3252  else
3253  hardscale = sqrt( min( mT[0], mT[1] ) );
3254  } else {
3255  hardscale = mergingHooksPtr->muF();
3256  }
3257  // Done
3258  return hardscale;
3259 }
3260 
3261 //--------------------------------------------------------------------------
3262 
3263 // Function to return the factorisation scale of the hard process in Pythia.
3264 
3265 double History::hardRenScale(const Event& event) {
3266  // Declare output scale.
3267  double hardscale = 0.;
3268  // If scale should not be reset, done.
3269  if ( !mergingHooksPtr->resetHardQRen() ) return mergingHooksPtr->muR();
3270  // For pure QCD dijet events, calculate the hadronic cross section
3271  // of the hard process at the pT of the dijet system, rather than at fixed
3272  // arbitrary scale.
3273  if ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
3274  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0
3275  || isQCD2to2(event)) {
3276  // Find the mT in the hard sub-process.
3277  vector <double> mT;
3278  for ( int i=0; i < event.size(); ++i)
3279  if ( event[i].isFinal()
3280  && ( event[i].colType() != 0 || event[i].id() == 22 ) )
3281  mT.push_back( abs(event[i].mT()) );
3282  if ( int(mT.size()) != 2 )
3283  hardscale = infoPtr->QRen();
3284  else
3285  hardscale = sqrt( mT[0]*mT[1] );
3286  } else {
3287  hardscale = mergingHooksPtr->muR();
3288  }
3289  // Done
3290  return hardscale;
3291 }
3292 
3293 //--------------------------------------------------------------------------
3294 
3295 // Perform a trial shower using the \a pythia object between
3296 // maxscale down to this scale and return the corresponding Sudakov
3297 // form factor.
3298 // IN trialShower : Shower object used as trial shower
3299 // double : Maximum scale for trial shower branching
3300 // OUT 0.0 : trial shower emission outside allowed pT range
3301 // 1.0 : trial shower successful (any emission was below
3302 // the minimal scale )
3303 
3304 vector<double> History::doTrialShower( PartonLevel* trial, int type,
3305  double maxscaleIn, double minscaleIn ) {
3306 
3307  // Copy state to local process
3308  Event process = state;
3309  // Set starting scale.
3310  double startingScale = maxscaleIn;
3311  // Careful when setting shower starting scale for pure QCD and prompt
3312  // photon case.
3313  if ( mergingHooksPtr->getNumberOfClusteringSteps(process) == 0
3314  && ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
3315  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0
3316  || isQCD2to2(state) ) )
3317  startingScale = min( startingScale, hardFacScale(process) );
3318 
3319  int nWgts = mergingHooksPtr->nWgts;
3320 
3321  // Set output.
3322  bool doVeto = false;
3323  double wt = 1.;
3324  bool canEnhanceTrial = trial->canEnhanceTrial();
3325 
3326  // Save shower weight vector before variation
3327  vector<double> showerWeightVecSave = infoPtr->
3328  weightContainerPtr->weightsPS.weightValues;
3329 
3330  while ( true ) {
3331 
3332  // Reset trialShower object
3333  trial->resetTrial();
3334  // Construct event to be showered
3335  Event event = Event();
3336  event.init("(hard process-modified)", particleDataPtr);
3337  event.clear();
3338 
3339  // Reset process scale so that shower starting scale is correctly set.
3340  process.scale(startingScale);
3341  doVeto = false;
3342 
3343  // Get pT before reclustering
3344  double minScale = (minscaleIn > 0.) ? minscaleIn : scale;
3345 
3346  // If the maximal scale and the minimal scale coincide (as would
3347  // be the case for the corrected scales of unordered histories),
3348  // do not generate Sudakov
3349  if (minScale >= startingScale) break;
3350 
3351  // Find z and pT values at which the current state was formed, to
3352  // ensure that the showers can order the next emission correctly in
3353  // rapidity, if required.
3354  // NOT CORRECTLY SET FOR HIGHEST MULTIPLICITY STATE!
3355  double z = ( mergingHooksPtr->getNumberOfClusteringSteps(state) == 0
3356  || !mother )
3357  ? 0.5
3358  : mother->getCurrentZ(clusterIn.emittor,clusterIn.recoiler,
3359  clusterIn.emitted, clusterIn.flavRadBef);
3360  // Store z and pT values at which the current state was formed.
3361  infoPtr->zNowISR(z);
3362  infoPtr->pT2NowISR(pow(startingScale,2));
3363  infoPtr->hasHistory(true);
3364 
3365  // Setup weak shower settings.
3366  if (mergingHooksPtr->doWeakClustering()) setupSimpleWeakShower(0);
3367 
3368  // Make sure trial shower stops where it should
3369  mergingHooksPtr->setShowerStoppingScale(minScale);
3370  // Perform trial shower emission
3371  trial->next(process,event);
3372  // Get trial shower pT.
3373  double pTtrial = trial->pTLastInShower();
3374  int typeTrial = trial->typeLastInShower();
3375 
3376  // Clear parton systems.
3377  trial->resetTrial();
3378 
3379  // Get enhanced trial emission weight.
3380  double pTEnhanced = trial->getEnhancedTrialPT();
3381  double wtEnhanced = trial->getEnhancedTrialWeight();
3382  if ( canEnhanceTrial && pTEnhanced > 0.) pTtrial = pTEnhanced;
3383 
3384  // Get veto (merging) scale value
3385  double vetoScale = (mother) ? 0. : mergingHooksPtr->tms();
3386  // Get merging scale in current event
3387  double tnow = mergingHooksPtr->tmsNow( event );
3388 
3389  // Done if evolution scale has fallen below minimum
3390  if ( pTtrial < minScale ) break;
3391  // Reset starting scale.
3392  startingScale = pTtrial;
3393 
3394  // Continue if this state is below the veto scale
3395  if ( tnow < vetoScale && vetoScale > 0. ) continue;
3396 
3397  // Retry if the trial emission was not allowed.
3398  if ( mergingHooksPtr->canVetoTrialEmission()
3399  && mergingHooksPtr->doVetoTrialEmission( process, event) ) continue;
3400 
3401  int iRecAft = event.size() - 1;
3402  int iEmt = event.size() - 2;
3403  int iRadAft = event.size() - 3;
3404  if ( (event[iRecAft].status() != 52 && event[iRecAft].status() != -53) ||
3405  event[iEmt].status() != 51 || event[iRadAft].status() != 51)
3406  iRecAft = iEmt = iRadAft = -1;
3407  for (int i = event.size() - 1; i > 0; i--) {
3408  if (iRadAft == -1 && event[i].status() == -41) iRadAft = i;
3409  else if (iEmt == -1 && event[i].status() == 43) iEmt = i;
3410  else if (iRecAft == -1 && event[i].status() == -42) iRecAft = i;
3411  if (iRadAft != -1 && iEmt != -1 && iRecAft != -1) break;
3412  }
3413 
3414  // Only consider allowed emissions for veto:
3415  // Only allow MPI for MPI no-emission probability.
3416  if ( type == -1 && typeTrial != 1 ) {
3417  // Restore weight vector
3418  infoPtr->weightContainerPtr->weightsPS.weightValues =
3419  showerWeightVecSave;
3420  continue;
3421  }
3422  // Only allow ISR or FSR for radiative no-emission probability.
3423  if ( type == 1 && !(typeTrial == 2 || typeTrial >= 3) ) {
3424  // Restore weight vector
3425  infoPtr->weightContainerPtr->weightsPS.weightValues =
3426  showerWeightVecSave;
3427  continue;
3428  }
3429 
3430  // Update enhanced trial shower weight.
3431  if (canEnhanceTrial && pTtrial > minScale) wt *= (1. - 1./wtEnhanced);
3432  // Done with enhanced trial showers if weight is zero.
3433  if ( canEnhanceTrial && wt == 0.) break;
3434  // Continue producing trial emissions in case of enhanced showers.
3435  if ( canEnhanceTrial && pTtrial > minScale) continue;
3436 
3437  // Continue if this state is below the veto scale
3438  // Veto event if trial pT was above the next nodal scale.
3439  if ( pTtrial > minScale ) doVeto = true;
3440 
3443  //if ( !mother && tnow > vetoScale && vetoScale > 0. ) doVeto = true;
3444 
3445  // For 2 -> 2 pure QCD state, do not allow multiparton interactions
3446  // above the kinematical pT of the 2 -> 2 state.
3447  if ( type == -1
3448  && typeTrial == 1
3449  && mergingHooksPtr->getNumberOfClusteringSteps(process) == 0
3450  && ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
3451  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0
3452  || isQCD2to2(state))
3453  && pTtrial > hardFacScale(process) )
3454  return vector<double>( nWgts, 0.0 );
3455 
3456  // If pT of trial emission was in suitable range (trial shower
3457  // successful), return false
3458  if ( pTtrial < minScale ) doVeto = false;
3459 
3460  // Done
3461  break;
3462 
3463  }
3464 
3465  // Done
3466  // Get combination of shower weights for muR variation in FSR and ISR
3467  vector<double> trialShowerWt = infoPtr->weightContainerPtr->weightsPS.
3468  getMuRWeightVector();
3469  // Insert 1. for central value
3470  trialShowerWt.insert(trialShowerWt.begin(),1.);
3471 
3472  // If MPI, no variation allowed (no-emission variations would bleed in from
3473  // shower without this catch)
3474  if (type == -1) trialShowerWt = vector<double>(trialShowerWt.size(),1.);
3475  // Reset shower weights
3476  infoPtr->weightContainerPtr->weightsPS.weightValues = showerWeightVecSave;
3477 
3478  //Apply veto or enhancement
3479  for (double& swt: trialShowerWt)
3480  swt *= (canEnhanceTrial) ? wt : ( (doVeto) ? 0. : 1. );
3481  return trialShowerWt;
3482 
3483 }
3484 
3485 //--------------------------------------------------------------------------
3486 
3487 // Assume we have a vector of i elements containing indices into
3488 // another vector with N elements. Update the indices so that all
3489 // unique combinations (starting from 0,1,2,3, ...) are
3490 // covered. Return false when all combinations have been ehausted.
3491 
3492 bool History::updateind(vector<int> & ind, int i, int N) {
3493  if ( i < 0 ) return false;
3494  if ( ++ind[i] < N ) return true;
3495  if ( !updateind(ind, i - 1, N - 1) ) return false;
3496  ind[i] = ind[i - 1] + 1;
3497  return true;
3498 }
3499 
3500 //--------------------------------------------------------------------------
3501 
3502 // Return the expansion of the no-emission probability up to the Nth
3503 // term. Optionally calculate the the terms using fixed alphaS
3504 // and/or PDF ratios.
3505 
3506 vector<double> History::countEmissions(PartonLevel* trial, double maxscale,
3507  double minscale, int showerType, double as0,
3508  AlphaStrong * asFSR, AlphaStrong * asISR, int N = 1,
3509  bool fixpdf = true, bool fixas = true) {
3510 
3511  if ( N < 0 ) return vector<double>();
3512  vector<double> result(N+1);
3513  result[0] = 1.0;
3514  if ( N < 1 ) return result;
3515 
3516  // Copy state to local process
3517  Event process = state;
3518 
3519  double startingScale = maxscale;
3520  // Careful when setting shower starting scale for pure QCD and prompt
3521  // photon case.
3522  if ( mergingHooksPtr->getNumberOfClusteringSteps(process) == 0
3523  && ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
3524  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0
3525  || isQCD2to2(state) ) )
3526  startingScale = min( startingScale, hardFacScale(process) );
3527 
3528  vector<double> wts;
3529  bool canEnhanceTrial = trial->canEnhanceTrial();
3530 
3531  // Save shower weight vector before variation
3532  vector<double> showerWeightVecSave = infoPtr->
3533  weightContainerPtr->weightsPS.weightValues;
3534 
3535  while ( true ) {
3536  // Reset trialShower object
3537  trial->resetTrial();
3538  // Construct event to be showered
3539  Event event = Event();
3540  event.init("(hard process-modified)", particleDataPtr);
3541  event.clear();
3542 
3543  // Reset process scale
3544  process.scale(startingScale);
3545 
3546  // If the maximal scale and the minimal scale coincide (as would
3547  // be the case for the corrected scales of unordered histories),
3548  // do not generate Sudakov
3549  if (minscale >= startingScale) return result;
3550 
3551  // Find z and pT values at which the current state was formed, to
3552  // ensure that the showers can order the next emission correctly in
3553  // rapidity, if required
3554  if ( mother ) {
3555  double z = ( mergingHooksPtr->getNumberOfClusteringSteps(state) == 0)
3556  ? 0.5
3557  : mother->getCurrentZ(clusterIn.emittor,clusterIn.recoiler,
3558  clusterIn.emitted);
3559  // Store z and pT values at which the current state was formed
3560  infoPtr->zNowISR(z);
3561  infoPtr->pT2NowISR(pow(startingScale,2));
3562  infoPtr->hasHistory(true);
3563  }
3564 
3565  // Setup the weak shower information.
3566  if (mergingHooksPtr->doWeakClustering()) setupSimpleWeakShower(0);
3567 
3568  // Perform trial shower emission
3569  trial->next(process,event);
3570 
3571  // Restore weight vector, since variation higher order
3572  infoPtr->weightContainerPtr->weightsPS.weightValues = showerWeightVecSave;
3573 
3574  // Get trial shower pT
3575  double pTtrial = trial->pTLastInShower();
3576  int typeTrial = trial->typeLastInShower();
3577 
3578  // Clear parton systems.
3579  trial->resetTrial();
3580 
3581  // Get enhanced trial emission weight.
3582  double pTEnhanced = trial->getEnhancedTrialPT();
3583  double wtEnhanced = trial->getEnhancedTrialWeight();
3584  if ( canEnhanceTrial && pTEnhanced > 0.) pTtrial = pTEnhanced;
3585 
3586  // Get veto (merging) scale value
3587  double vetoScale = (mother) ? 0. : mergingHooksPtr->tms();
3588  // Get merging scale in current event
3589  double tnow = mergingHooksPtr->tmsNow( event );
3590 
3591  // Save scale of current state.
3592  startingScale = pTtrial;
3593  // If the scale of the current state is below the minimal scale, exit.
3594  if ( pTtrial < minscale ) break;
3595  // If this state is below the merging scale, do not count emission.
3596  if ( tnow < vetoScale && vetoScale > 0. ) continue;
3597  // Retry if the trial emission was not allowed.
3598  if ( mergingHooksPtr->canVetoTrialEmission()
3599  && mergingHooksPtr->doVetoTrialEmission( process, event) ) continue;
3600 
3601  // Set weight of enhanced emission.
3602  double enhance = (canEnhanceTrial && pTtrial > minscale) ? wtEnhanced : 1.;
3603 
3604  // Check if a new emission should be generated, either because
3605  // the latest emission was not of the desired kind or if the
3606  // emission was above the minimal scale
3607  double alphaSinPS = as0;
3608  double pdfs = 1.0;
3609 
3610  double asScale2 = pTtrial*pTtrial;
3611  // Directly get argument of running alpha_s from shower plugin.
3612  if (mergingHooksPtr->useShowerPlugin() )
3613  asScale2 = getShowerPluginScale(mother->state, clusterIn.emittor,
3614  clusterIn.emitted, clusterIn.recoiler, "scaleAS", asScale2);
3615 
3616  // Initial state splittings.
3617  if ( (showerType == -1 || showerType == 2) && typeTrial == 2 ) {
3618  // Get weight to translate to alpha_s at fixed renormalisation scale.
3619  if ( fixas ) alphaSinPS = (*asISR).alphaS(asScale2);
3620  // Get weight to translate to PDFs at fixed factorisation scale.
3621  if ( fixpdf )
3622  pdfs = pdfFactor( event, typeTrial, pTtrial,
3623  mergingHooksPtr->muFinME() );
3624  // Final state splittings.
3625  } else if ( (showerType == 1 || showerType == 2) && typeTrial >= 3 ) {
3626  // Get weight to translate to alpha_s at fixed renormalisation scale.
3627  if ( fixas ) alphaSinPS = (*asFSR).alphaS(asScale2);
3628  // Get weight to translate to PDFs at fixed factorisation scale. Needed
3629  // for final state splittings with initial state recoiler.
3630  if ( fixpdf )
3631  pdfs = pdfFactor( event, typeTrial, pTtrial,
3632  mergingHooksPtr->muFinME() );
3633  }
3634 
3635  // Save weight correcting to emission generated with fixed scales.
3636  if ( typeTrial == 2 || typeTrial >= 3 )
3637  wts.push_back(as0/alphaSinPS * pdfs * 1./enhance);
3638 
3639  }
3640 
3641  for ( int n = 1; n <= min(N, int(wts.size())); ++n ) {
3642  vector<int> ind(N);
3643  for ( int i = 0; i < N; ++i ) ind[i] = i;
3644  do {
3645  double x = 1.0;
3646  for ( int j = 0; j < n; ++j ) x *= wts[ind[j]];
3647  result[n] += x;
3648  } while ( updateind(ind, n - 1, wts.size()) );
3649  if ( n%2 ) result[n] *= -1.0;
3650  }
3651 
3652  // Done
3653  return result;
3654 }
3655 
3656 //--------------------------------------------------------------------------
3657 
3658 // Function to integrate PDF ratios between two scales over x and t,
3659 // where the PDFs are always evaluated at the lower t-integration limit
3660 
3661 double History::monteCarloPDFratios(int flav, double x, double maxScale,
3662  double minScale, double pdfScale, double asME, Rndm* rndmPtr) {
3663 
3664  // Perform numerical integration for PDF ratios
3665  // Prefactor is as/2PI
3666  double factor = asME / (2.*M_PI);
3667  // Scale integration just produces a multiplicative logarithm
3668  factor *= log(maxScale/minScale);
3669 
3670  // For identical scales, done
3671  if (factor == 0.) return 0.;
3672 
3673  // Declare constants
3674  double CF = 4./3.;
3675  double CA = 3.;
3676  double NF = 4.;
3677  double TR = 1./2.;
3678 
3679  double integral = 0.;
3680  double RN = rndmPtr->flat();
3681 
3682  if (flav == 21) {
3683  double zTrial = pow(x,RN);
3684  integral = -log(x) * zTrial *
3685  integrand(flav, x, pdfScale, zTrial);
3686  integral += 1./6.*(11.*CA - 4.*NF*TR)
3687  + 2.*CA*log(1.-x);
3688  } else {
3689  double zTrial = x + RN*(1. - x);
3690  integral = (1.-x) *
3691  integrand(flav, x, pdfScale, zTrial);
3692  integral += 3./2.*CF
3693  + 2.*CF*log(1.-x);
3694  }
3695 
3696  // Done
3697  return (factor*integral);
3698 }
3699 
3700 /*--------------- METHODS USED FOR CONTRUCTION OF ALL HISTORIES --------- */
3701 
3702 // Check if a ordered (and complete) path has been found in the
3703 // initial node, in which case we will no longer be interested in
3704 // any unordered paths.
3705 
3706 bool History::onlyOrderedPaths() {
3707  if ( !mother || foundOrderedPath ) return foundOrderedPath;
3708  return foundOrderedPath = mother->onlyOrderedPaths();
3709 }
3710 
3711 //--------------------------------------------------------------------------
3712 
3713 // Check if a STRONGLY ordered (and complete) path has been found in the
3714 // initial node, in which case we will no longer be interested in
3715 // any unordered paths.
3716 
3717 bool History::onlyStronglyOrderedPaths() {
3718  if ( !mother || foundStronglyOrderedPath ) return foundStronglyOrderedPath;
3719  return foundStronglyOrderedPath = mother->onlyStronglyOrderedPaths();
3720 }
3721 
3722 //--------------------------------------------------------------------------
3723 
3724 // Check if an allowed (according to user-criterion) path has been found in
3725 // the initial node, in which case we will no longer be interested in
3726 // any forbidden paths.
3727 
3728 bool History::onlyAllowedPaths() {
3729  if ( !mother || foundAllowedPath ) return foundAllowedPath;
3730  return foundAllowedPath = mother->onlyAllowedPaths();
3731 }
3732 
3733 //--------------------------------------------------------------------------
3734 
3735 // When a full path has been found, register it with the initial
3736 // history node.
3737 // IN History : History to be registered as path
3738 // bool : Specifying if clusterings so far were ordered
3739 // bool : Specifying if path is complete down to 2->2 process
3740 // OUT true if History object forms a plausible path (eg prob>0 ...)
3741 
3742 bool History::registerPath(History & l, bool isOrdered,
3743  bool isStronglyOrdered, bool isAllowed, bool isComplete) {
3744 
3745  // We are not interested in improbable paths.
3746  if ( l.prob <= 0.0)
3747  return false;
3748  // We only register paths in the initial node.
3749  if ( mother ) return mother->registerPath(l, isOrdered,
3750  isStronglyOrdered, isAllowed, isComplete);
3751 
3752  // Again, we are not interested in improbable paths.
3753  if ( sumpath == sumpath + l.prob )
3754  return false;
3755  if ( mergingHooksPtr->canCutOnRecState()
3756  && foundAllowedPath && !isAllowed )
3757  return false;
3758  if ( mergingHooksPtr->enforceStrongOrdering()
3759  && foundStronglyOrderedPath && !isStronglyOrdered )
3760  return false;
3761  if ( mergingHooksPtr->orderHistories()
3762  && foundOrderedPath && !isOrdered ) {
3763  // Prefer complete or allowed paths to ordered paths.
3764  if ( (!foundCompletePath && isComplete)
3765  || (!foundAllowedPath && isAllowed) ) ;
3766  else return false;
3767  }
3768 
3769  if ( foundCompletePath && !isComplete)
3770  return false;
3771  if ( !mergingHooksPtr->canCutOnRecState()
3772  && !mergingHooksPtr->allowCutOnRecState() )
3773  foundAllowedPath = true;
3774 
3775  if ( mergingHooksPtr->canCutOnRecState() && isAllowed && isComplete) {
3776  if ( !foundAllowedPath || !foundCompletePath ) {
3777  // If this is the first complete, allowed path, discard the
3778  // old, disallowed or incomplete ones.
3779  paths.clear();
3780  sumpath = 0.0;
3781  }
3782  foundAllowedPath = true;
3783 
3784  }
3785 
3786  if ( mergingHooksPtr->enforceStrongOrdering() && isStronglyOrdered
3787  && isComplete ) {
3788  if ( !foundStronglyOrderedPath || !foundCompletePath ) {
3789  // If this is the first complete, ordered path, discard the
3790  // old, non-ordered or incomplete ones.
3791  paths.clear();
3792  sumpath = 0.0;
3793  }
3794  foundStronglyOrderedPath = true;
3795  foundCompletePath = true;
3796 
3797  }
3798 
3799  if ( mergingHooksPtr->orderHistories() && isOrdered && isComplete ) {
3800  if ( !foundOrderedPath || !foundCompletePath ) {
3801  // If this is the first complete, ordered path, discard the
3802  // old, non-ordered or incomplete ones.
3803  paths.clear();
3804  sumpath = 0.0;
3805  }
3806  foundOrderedPath = true;
3807  foundCompletePath = true;
3808 
3809  }
3810 
3811  if ( isComplete ) {
3812  if ( !foundCompletePath ) {
3813  // If this is the first complete path, discard the old,
3814  // incomplete ones.
3815  paths.clear();
3816  sumpath = 0.0;
3817  }
3818  foundCompletePath = true;
3819  }
3820 
3821  // Remember, if this path is ordered, even if no ordering is required
3822  if ( isOrdered ) {
3823  foundOrderedPath = true;
3824  }
3825 
3826  // Calculate the probability for weak emissions in the path.
3827  double weakProb = 1.;
3828  if (mergingHooksPtr->doWeakClustering())
3829  weakProb = l.getWeakProb();
3830 
3831  // Index path by probability
3832  sumpath += l.prob * weakProb;
3833  paths[sumpath] = &l;
3834 
3835  updateProbMax(l.prob * weakProb, isComplete);
3836 
3837  return true;
3838 }
3839 
3840 //--------------------------------------------------------------------------
3841 
3842 // For the history-defining state (and if necessary interfering
3843 // states), find all possible clusterings.
3844 // NO INPUT
3845 // OUT vector of all (rad,rec,emt) systems
3846 
3847 vector<Clustering> History::getAllQCDClusterings() {
3848  vector<Clustering> ret;
3849  // Initialise vectors to keep track of position of partons in the
3850  // history-defining state
3851  vector <int> posFinalPartn;
3852  vector <int> posInitPartn;
3853  vector <int> posFinalGluon;
3854  vector <int> posFinalQuark;
3855  vector <int> posFinalAntiq;
3856  vector <int> posInitGluon;
3857  vector <int> posInitQuark;
3858  vector <int> posInitAntiq;
3859 
3860  // Search event record for final state particles and store these in
3861  // quark, anti-quark and gluon vectors
3862  for ( int i=0; i < state.size(); ++i )
3863  if ( state[i].isFinal() && state[i].colType() !=0 ) {
3864  // Store final partons
3865  if ( state[i].id() == 21 ) posFinalGluon.push_back(i);
3866  else if ( state[i].idAbs() < 10 && state[i].id() > 0)
3867  posFinalQuark.push_back(i);
3868  else if ( state[i].idAbs() < 10 && state[i].id() < 0)
3869  posFinalAntiq.push_back(i);
3870  } else if (state[i].status() == -21 && state[i].colType() != 0 ) {
3871  // Store initial partons
3872  if ( state[i].id() == 21 ) posInitGluon.push_back(i);
3873  else if ( state[i].idAbs() < 10 && state[i].id() > 0)
3874  posInitQuark.push_back(i);
3875  else if ( state[i].idAbs() < 10 && state[i].id() < 0)
3876  posInitAntiq.push_back(i);
3877  }
3878 
3879  // Get all clusterings for input state
3880  vector<Clustering> systems;
3881  systems = getQCDClusterings(state);
3882  ret.insert(ret.end(), systems.begin(), systems.end());
3883  systems.resize(0);
3884 
3885  // If valid clusterings were found, return
3886  if ( !ret.empty() ) return ret;
3887  // If no clusterings have been found until now, try to find
3888  // clusterings of diagrams that interfere with the current one
3889  // (i.e. change the colours of the current event slightly and run
3890  // search again)
3891  else if ( mergingHooksPtr->allowColourShuffling() ) {
3892  Event NewState = Event(state);
3893  // Start with changing final state quark colour
3894  for(int i = 0; i < int(posFinalQuark.size()); ++i) {
3895  // Never change the hard process candidates
3896  if ( mergingHooksPtr->hardProcess->matchesAnyOutgoing(posFinalQuark[i],
3897  NewState) )
3898  continue;
3899  int col = NewState[posFinalQuark[i]].col();
3900  for(int j = 0; j < int(posInitAntiq.size()); ++j) {
3901  // Now swap colours
3902  int acl = NewState[posInitAntiq[j]].acol();
3903  if ( col == acl ) continue;
3904  NewState[posFinalQuark[i]].col(acl);
3905  NewState[posInitAntiq[j]].acol(col);
3906  systems = getQCDClusterings(NewState);
3907  if (!systems.empty()) {
3908  state = NewState;
3909  NewState.clear();
3910  ret.insert(ret.end(), systems.begin(), systems.end());
3911  systems.resize(0);
3912  return ret;
3913  }
3914  }
3915  }
3916  // Now change final state antiquark anticolour
3917  for(int i = 0; i < int(posFinalAntiq.size()); ++i) {
3918  // Never change the hard process candidates
3919  if ( mergingHooksPtr->hardProcess->matchesAnyOutgoing(posFinalAntiq[i],
3920  NewState) )
3921  continue;
3922  int acl = NewState[posFinalAntiq[i]].acol();
3923  for(int j = 0; j < int(posInitQuark.size()); ++j) {
3924  // Now swap colours
3925  int col = NewState[posInitQuark[j]].col();
3926  if ( col == acl ) continue;
3927  NewState[posFinalAntiq[i]].acol(col);
3928  NewState[posInitQuark[j]].col(acl);
3929  systems = getQCDClusterings(NewState);
3930  if (!systems.empty()) {
3931  state = NewState;
3932  NewState.clear();
3933  ret.insert(ret.end(), systems.begin(), systems.end());
3934  systems.resize(0);
3935  return ret;
3936  }
3937  }
3938  }
3939 
3940  }
3941 
3942  // Done
3943  return ret;
3944 }
3945 
3946 //--------------------------------------------------------------------------
3947 
3948 // For one given state, find all possible clusterings.
3949 // IN Event : state to be investigated
3950 // OUT vector of all (rad,rec,emt) systems in the state
3951 
3952 vector<Clustering> History::getQCDClusterings( const Event& event) {
3953  vector<Clustering> ret;
3954 
3955  // Initialise vectors to keep track of position of partons in the
3956  // input event
3957  vector <int> posFinalPartn;
3958  vector <int> posInitPartn;
3959 
3960  vector <int> posFinalGluon;
3961  vector <int> posFinalQuark;
3962  vector <int> posFinalAntiq;
3963  vector <int> posInitGluon;
3964  vector <int> posInitQuark;
3965  vector <int> posInitAntiq;
3966 
3967  // Search event record for final state particles and store these in
3968  // quark, anti-quark and gluon vectors
3969  for (int i=0; i < event.size(); ++i)
3970  if ( event[i].isFinal() && event[i].colType() !=0 ) {
3971  // Store final partons
3972  posFinalPartn.push_back(i);
3973  if ( event[i].id() == 21 ) posFinalGluon.push_back(i);
3974  else if ( event[i].idAbs() < 10 && event[i].id() > 0)
3975  posFinalQuark.push_back(i);
3976  else if ( event[i].idAbs() < 10 && event[i].id() < 0)
3977  posFinalAntiq.push_back(i);
3978  } else if ( event[i].status() == -21 && event[i].colType() != 0 ) {
3979  // Store initial partons
3980  posInitPartn.push_back(i);
3981  if ( event[i].id() == 21 ) posInitGluon.push_back(i);
3982  else if ( event[i].idAbs() < 10 && event[i].id() > 0)
3983  posInitQuark.push_back(i);
3984  else if ( event[i].idAbs() < 10 && event[i].id() < 0)
3985  posInitAntiq.push_back(i);
3986  }
3987 
3988  int nFiGluon = int(posFinalGluon.size());
3989  int nFiQuark = int(posFinalQuark.size());
3990  int nFiAntiq = int(posFinalAntiq.size());
3991  int nInGluon = int(posInitGluon.size());
3992  int nInQuark = int(posInitQuark.size());
3993  int nInAntiq = int(posInitAntiq.size());
3994 
3995  vector<Clustering> systems;
3996 
3997  // Find rad + emt + rec systems:
3998  // (1) Start from gluon and find all (rad,rec,emt=gluon) triples
3999  for (int i = 0; i < nFiGluon; ++i) {
4000  int EmtGluon = posFinalGluon[i];
4001  systems = findQCDTriple( EmtGluon, 2, event, posFinalPartn, posInitPartn);
4002  ret.insert(ret.end(), systems.begin(), systems.end());
4003  systems.resize(0);
4004  }
4005 
4006  // For more than one quark-antiquark pair in final state, check for
4007  // g -> qqbar splittings
4008  bool check_g2qq = true;
4009  if ( ( ( nInQuark + nInAntiq == 0 )
4010  && (nInGluon == 0)
4011  && (nFiQuark == 1) && (nFiAntiq == 1) )
4012  || ( ( nFiQuark + nFiAntiq == 0)
4013  && (nInQuark == 1) && (nInAntiq == 1) ) )
4014  check_g2qq = false;
4015 
4016  if ( check_g2qq ) {
4017 
4018  // (2) Start from quark and find all (rad,rec,emt=quark) triples
4019  // ( when g -> q qbar occured )
4020  for( int i=0; i < nFiQuark; ++i) {
4021  int EmtQuark = posFinalQuark[i];
4022  systems = findQCDTriple( EmtQuark,1,event, posFinalPartn, posInitPartn);
4023  ret.insert(ret.end(), systems.begin(), systems.end());
4024  systems.resize(0);
4025  }
4026 
4027  // (3) Start from anti-quark and find all (rad,rec,emt=anti-quark)
4028  // triples ( when g -> q qbar occured )
4029  for( int i=0; i < nFiAntiq; ++i) {
4030  int EmtAntiq = posFinalAntiq[i];
4031  systems = findQCDTriple( EmtAntiq,1,event, posFinalPartn, posInitPartn);
4032  ret.insert(ret.end(), systems.begin(), systems.end());
4033  systems.resize(0);
4034  }
4035  }
4036 
4037  return ret;
4038 }
4039 
4040 //--------------------------------------------------------------------------
4041 
4042 // Function to attach (spin-dependent duplicates of) a clustering.
4043 
4044 void History::attachClusterings (vector<Clustering>& clus, int iEmt, int iRad,
4045  int iRec, int iPartner, double pT, const Event& event) {
4046 
4047  if ( !mergingHooksPtr->doWeakClustering() ) {
4048 
4049  // Do nothing for kinematically forbidden state.
4050  if (pT <= 0.) return;
4051  clus.push_back( Clustering(iEmt, iRad, iRec, iPartner,
4052  pT, 0, 0, 0, 0, 9));
4053 
4054  } else {
4055 
4056  // Check if spins are already assigned.
4057  int radSpin = event[iRad].intPol();
4058  int emtSpin = event[iEmt].intPol();
4059  int recSpin = event[iRec].intPol();
4060  bool hasRadSpin = (radSpin != 9);
4061  bool hasEmtSpin = (emtSpin != 9);
4062  bool hasRecSpin = (recSpin != 9);
4063 
4064  // Check if any of the partons are quarks.
4065  bool radQuark = event[iRad].idAbs() < 10;
4066  bool emtQuark = event[iEmt].idAbs() < 10;
4067  bool recQuark = event[iRec].idAbs() < 10;
4068 
4069  // Generate the vector of all spin structures
4070  vector < vector<int> > structs;
4071  structs.resize(0);
4072  for (int i = 0; i < 3; ++i){
4073  int sRad = (i==0) ? -1 : (i==1) ? 1 : 9;
4074  for (int j = 0; j < 3; ++j){
4075  int sEmt = (j==0) ? -1 : (j==1) ? 1 : 9;
4076  for (int k = 0; k < 3; ++k){
4077  int sRec = (k==0) ? -1 : (k==1) ? 1 : 9;
4078  vector <int> s;
4079  s.push_back(sRad); s.push_back(sEmt); s.push_back(sRec);
4080  structs.push_back(s);
4081  }
4082  }
4083  }
4084 
4085  vector < vector<int> > allStructs;
4086  for (int i = 0; i< int(structs.size()); ++i) {
4087  // Only pick allowed combinations if spin is already set.
4088  if (hasRadSpin && radQuark && structs[i][0] != radSpin) continue;
4089  if (hasEmtSpin && emtQuark && structs[i][1] != emtSpin) continue;
4090  if (hasRecSpin && recQuark && structs[i][2] != recSpin) continue;
4091  // Set +-1 for previously unset quark spins.
4092  if (!hasRadSpin && radQuark && structs[i][0] == 9) continue;
4093  if (!hasEmtSpin && emtQuark && structs[i][1] == 9) continue;
4094  if (!hasRecSpin && recQuark && structs[i][2] == 9) continue;
4095  // Leave spin 9 for gluons.
4096  if (!radQuark && structs[i][0] != radSpin) continue;
4097  if (!emtQuark && structs[i][1] != emtSpin) continue;
4098  if (!recQuark && structs[i][2] != recSpin) continue;
4099  // Ensure that the quarks in the g-> q qbar splitting have equal spin.
4100  if (radQuark && emtQuark && structs[i][0] != structs[i][1]) continue;
4101  // Store spin structure.
4102  allStructs.push_back(structs[i]);
4103  }
4104 
4105  // Get flavour of radiator before the splitting.
4106  int flavRadBef = getRadBeforeFlav(iRad, iEmt, event);
4107  // Push back all spin-dependent clusterings.
4108  for (int i = 0; i< int(allStructs.size()); ++i) {
4109  // Get spin of radiator before the splitting.
4110  int spinRadBef = getRadBeforeSpin(iRad, iEmt, allStructs[i][0],
4111  allStructs[i][1], event);
4112  clus.push_back( Clustering(iEmt, iRad, iRec, iPartner, pT, flavRadBef,
4113  allStructs[i][0], allStructs[i][1], allStructs[i][2], spinRadBef) );
4114  }
4115 
4116  } // doWeakClustering
4117 
4118  return;
4119 
4120 }
4121 
4122 //--------------------------------------------------------------------------
4123 
4124 // Function to construct (rad,rec,emt) triples from the event
4125 // IN int : Position of Emitted in event record for which
4126 // dipoles should be constructed
4127 // int : Colour topogy to be tested
4128 // 1= g -> qqbar, causing 2 -> 2 dipole splitting
4129 // 2= q(bar) -> q(bar) g && g -> gg,
4130 // causing a 2 -> 3 dipole splitting
4131 // Event : event record to be checked for ptential partners
4132 // OUT vector of all allowed radiator+recoiler+emitted triples
4133 
4134 vector<Clustering> History::findQCDTriple (int EmtTagIn, int colTopIn,
4135  const Event& event,
4136  vector<int> posFinalPartn,
4137  vector <int> posInitPartn ) {
4138 
4139  // Copy input parton tag
4140  int EmtTag = EmtTagIn;
4141  // Copy input colour topology tag
4142  // (1: g --> qqbar splitting present, 2:rest)
4143  int colTop = colTopIn;
4144 
4145  // Initialise FinalSize
4146  int finalSize = int(posFinalPartn.size());
4147  int initSize = int(posInitPartn.size());
4148  int size = initSize + finalSize;
4149 
4150  vector<Clustering> clus;
4151 
4152  // Search final partons to find partons colour-connected to
4153  // event[EmtTag], choose radiator, then choose recoiler
4154  for ( int a = 0; a < size; ++a ) {
4155  int i = (a < finalSize)? a : (a - finalSize) ;
4156  int iRad = (a < finalSize)? posFinalPartn[i] : posInitPartn[i];
4157 
4158  if ( event[iRad].col() == event[EmtTag].col()
4159  && event[iRad].acol() == event[EmtTag].acol() )
4160  continue;
4161 
4162  if (iRad != EmtTag ) {
4163  int pTdef = event[iRad].isFinal() ? 1 : -1;
4164  int sign = (a < finalSize)? 1 : -1 ;
4165 
4166  // First colour topology: g --> qqbar. Here, emt & rad should
4167  // have same flavour (causes problems for gamma->qqbar).
4168  if (colTop == 1) {
4169 
4170  if ( event[iRad].id() == -sign*event[EmtTag].id() ) {
4171  int col = -1;
4172  int acl = -1;
4173 
4174  if (event[iRad].isFinal() ) {
4175  if (event[iRad].id() < 0) {
4176  col = event[EmtTag].col();
4177  acl = 0;
4178  } else {
4179  acl = event[EmtTag].acol();
4180  col = 0;
4181  }
4182  } else {
4183  if (event[iRad].id() < 0) {
4184  acl = event[EmtTag].acol();
4185  col = 0;
4186  } else {
4187  col = event[EmtTag].col();
4188  acl = 0;
4189  }
4190  }
4191 
4192  // Recoiler
4193  int iRec = 0;
4194  // Colour partner
4195  int iPartner = 0;
4196 
4197  if (col > 0) {
4198  // Find recoiler by colour
4199  iRec = FindCol(col,iRad,EmtTag,event,1,true);
4200  // In initial state splitting has final state colour partner,
4201  // Save both partner and recoiler
4202  if ( (sign < 0) && (event[iRec].isFinal()) ) {
4203  // Save colour recoiler
4204  iPartner = iRec;
4205  // Reset kinematic recoiler to initial state parton
4206  for(int l = 0; l < int(posInitPartn.size()); ++l)
4207  if (posInitPartn[l] != iRad) iRec = posInitPartn[l];
4208  // For final state splittings, colour partner and recoiler are
4209  // identical
4210  } else {
4211  iPartner = iRec;
4212  }
4213  if ( iRec != 0 && iPartner != 0
4214  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
4215  attachClusterings (clus, EmtTag, iRad, iRec, iPartner,
4216  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
4217  continue;
4218  }
4219 
4220  // Reset partner
4221  iPartner = 0;
4222  // Find recoiler by colour
4223  iRec = FindCol(col,iRad,EmtTag,event,2,true);
4224  // In initial state splitting has final state colour partner,
4225  // Save both partner and recoiler
4226  if ( (sign < 0) && (event[iRec].isFinal()) ) {
4227  // Save colour recoiler
4228  iPartner = iRec;
4229  // Reset kinematic recoiler to initial state parton
4230  for(int l = 0; l < int(posInitPartn.size()); ++l)
4231  if (posInitPartn[l] != iRad) iRec = posInitPartn[l];
4232  // For final state splittings, colour partner and recoiler are
4233  // identical
4234  } else {
4235  iPartner = iRec;
4236  }
4237  if ( iRec != 0 && iPartner != 0
4238  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
4239  attachClusterings (clus, EmtTag, iRad, iRec, iPartner,
4240  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
4241  continue;
4242  }
4243  }
4244 
4245 
4246  if (acl > 0) {
4247 
4248  // Reset partner
4249  iPartner = 0;
4250  // Find recoiler by colour
4251  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
4252  // In initial state splitting has final state colour partner,
4253  // Save both partner and recoiler
4254  if ( (sign < 0) && (event[iRec].isFinal()) ) {
4255  // Save colour recoiler
4256  iPartner = iRec;
4257  // Reset kinematic recoiler to initial state parton
4258  for(int l = 0; l < int(posInitPartn.size()); ++l)
4259  if (posInitPartn[l] != iRad) iRec = posInitPartn[l];
4260  // For final state splittings, colour partner and recoiler are
4261  // identical
4262  } else {
4263  iPartner = iRec;
4264  }
4265  if ( iRec != 0 && iPartner != 0
4266  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
4267  attachClusterings (clus, EmtTag, iRad, iRec, iPartner,
4268  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
4269  continue;
4270  }
4271 
4272  // Reset partner
4273  iPartner = 0;
4274  // Find recoiler by colour
4275  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
4276  // In initial state splitting has final state colour partner,
4277  // Save both partner and recoiler
4278  if ( (sign < 0) && (event[iRec].isFinal()) ) {
4279  // Save colour recoiler
4280  iPartner = iRec;
4281  // Reset kinematic recoiler to initial state parton
4282  for(int l = 0; l < int(posInitPartn.size()); ++l)
4283  if (posInitPartn[l] != iRad) iRec = posInitPartn[l];
4284  // For final state splittings, colour partner and recoiler are
4285  // identical
4286  } else {
4287  iPartner = iRec;
4288  }
4289  if ( iRec != 0 && iPartner != 0
4290  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
4291  attachClusterings (clus, EmtTag, iRad, iRec, iPartner,
4292  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
4293  continue;
4294  }
4295  }
4296  // Initial gluon splitting
4297  } else if ( event[iRad].id() == 21
4298  &&( event[iRad].col() == event[EmtTag].col()
4299  || event[iRad].acol() == event[EmtTag].acol() )) {
4300  // For an initial state radiator, always set recoiler
4301  // to the other initial state parton (recoil is taken
4302  // by full remaining system, so this is just a
4303  // labelling for such a process)
4304  int RecInit = 0;
4305  for(int l = 0; l < int(posInitPartn.size()); ++l)
4306  if (posInitPartn[l] != iRad) RecInit = posInitPartn[l];
4307 
4308  // Find the colour connected partner
4309  // Find colour index of radiator before splitting
4310  int col = getRadBeforeCol(iRad, EmtTag, event);
4311  int acl = getRadBeforeAcol(iRad, EmtTag, event);
4312 
4313  // Find the correct partner: If a colour line has split,
4314  // the partner is connected to the radiator before the splitting
4315  // by a colour line (same reasoning for anticolour). The colour
4316  // that split is the colour appearing twice in the
4317  // radiator + emitted pair.
4318  // Thus, if we remove a colour index with the clustering,
4319  // we should look for a colour partner, else look for
4320  // an anticolour partner
4321  int colRemove = (event[iRad].col() == event[EmtTag].col())
4322  ? event[iRad].col() : event[iRad].acol();
4323 
4324  int iPartner = 0;
4325  if (colRemove > 0 && col > 0 && col != colRemove)
4326  iPartner = FindCol(col,iRad,EmtTag,event,1,true)
4327  + FindCol(col,iRad,EmtTag,event,2,true);
4328  else if (colRemove > 0 && acl > 0 && acl != colRemove)
4329  iPartner = FindCol(acl,iRad,EmtTag,event,1,true)
4330  + FindCol(acl,iRad,EmtTag,event,2,true);
4331 
4332  if ( allowedClustering( iRad, EmtTag, RecInit, iPartner, event ) ) {
4333  attachClusterings (clus, EmtTag, iRad, RecInit, iPartner,
4334  pTLund(event, iRad, EmtTag, RecInit, pTdef), event);
4335  continue;
4336  }
4337  }
4338 
4339  // Second colour topology: Gluon emission
4340 
4341  } else {
4342  if ( (event[iRad].col() == event[EmtTag].acol())
4343  || (event[iRad].acol() == event[EmtTag].col())
4344  || (event[iRad].col() == event[EmtTag].col())
4345  || (event[iRad].acol() == event[EmtTag].acol()) ) {
4346  // For the rest, choose recoiler to have a common colour
4347  // tag with radiator, while not being the "Emitted"
4348 
4349  int col = -1;
4350  int acl = -1;
4351 
4352  if (event[iRad].isFinal() ) {
4353 
4354  if ( event[iRad].id() < 0) {
4355  acl = event[EmtTag].acol();
4356  col = event[iRad].col();
4357  } else if ( event[iRad].id() > 0 && event[iRad].id() < 10) {
4358  col = event[EmtTag].col();
4359  acl = event[iRad].acol();
4360  } else {
4361  col = event[EmtTag].col();
4362  acl = event[EmtTag].acol();
4363  }
4364 
4365  int iRec = 0;
4366  if (col > 0) {
4367  iRec = FindCol(col,iRad,EmtTag,event,1,true);
4368  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
4369  if (iRec != 0
4370  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
4371  attachClusterings (clus, EmtTag, iRad, iRec, iRec,
4372  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
4373  continue;
4374  }
4375 
4376  iRec = FindCol(col,iRad,EmtTag,event,2,true);
4377  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
4378  if (iRec != 0
4379  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
4380  attachClusterings (clus, EmtTag, iRad, iRec, iRec,
4381  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
4382  continue;
4383  }
4384  }
4385 
4386  if (acl > 0) {
4387  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
4388  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
4389  if (iRec != 0
4390  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
4391  attachClusterings (clus, EmtTag, iRad, iRec, iRec,
4392  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
4393  continue;
4394  }
4395 
4396  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
4397  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
4398  if (iRec != 0
4399  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
4400  attachClusterings (clus, EmtTag, iRad, iRec, iRec,
4401  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
4402  continue;
4403  }
4404  }
4405 
4406  } else {
4407 
4408  // For an initial state radiator, always set recoiler
4409  // to the other initial state parton (recoil is taken
4410 
4411  // by full remaining system, so this is just a
4412  // labelling for such a process)
4413  int RecInit = 0;
4414  int iPartner = 0;
4415  for(int l = 0; l < int(posInitPartn.size()); ++l)
4416  if (posInitPartn[l] != iRad) RecInit = posInitPartn[l];
4417 
4418  // Find the colour connected partner
4419  // Find colour index of radiator before splitting
4420  col = getRadBeforeCol(iRad, EmtTag, event);
4421  acl = getRadBeforeAcol(iRad, EmtTag, event);
4422 
4423  // Find the correct partner: If a colour line has split,
4424  // the partner is connected to the radiator before the splitting
4425  // by a colour line (same reasoning for anticolour). The colour
4426  // that split is the colour appearing twice in the
4427  // radiator + emitted pair.
4428  // Thus, if we remove a colour index with the clustering,
4429  // we should look for a colour partner, else look for
4430  // an anticolour partner
4431  int colRemove = (event[iRad].col() == event[EmtTag].col())
4432  ? event[iRad].col() : 0;
4433  iPartner = (colRemove > 0)
4434  ? FindCol(col,iRad,EmtTag,event,1,true)
4435  + FindCol(col,iRad,EmtTag,event,2,true)
4436  : FindCol(acl,iRad,EmtTag,event,1,true)
4437  + FindCol(acl,iRad,EmtTag,event,2,true);
4438 
4439  if ( allowedClustering( iRad, EmtTag, RecInit, iPartner, event)) {
4440  attachClusterings (clus, EmtTag, iRad, RecInit, iPartner,
4441  pTLund(event, iRad, EmtTag, RecInit, pTdef), event);
4442  continue;
4443  }
4444  }
4445  }
4446  }
4447  }
4448  }
4449 
4450  // Done
4451  return clus;
4452 }
4453 
4454 //--------------------------------------------------------------------------
4455 
4456 // For the history-defining state (and if necessary interfering
4457 // states), find all possible clusterings.
4458 // NO INPUT
4459 // OUT vector of all (rad,rec,emt) systems
4460 
4461 vector<Clustering> History::getAllEWClusterings() {
4462  vector<Clustering> ret;
4463 
4464  // Get all clusterings for input state
4465  vector<Clustering> systems;
4466  systems = getEWClusterings(state);
4467  ret.insert(ret.end(), systems.begin(), systems.end());
4468  // Done
4469  return ret;
4470 }
4471 
4472 //--------------------------------------------------------------------------
4473 
4474 // For one given state, find all possible clusterings.
4475 // IN Event : state to be investigated
4476 // OUT vector of all (rad,rec,emt) systems in the state
4477 
4478 vector<Clustering> History::getEWClusterings( const Event& event) {
4479  vector<Clustering> ret;
4480 
4481  // Initialise vectors to keep track of position of partons in the
4482  // input event
4483  vector <int> posFinalPartn;
4484  vector <int> posInitPartn;
4485  vector <int> posFinalW;
4486  vector <int> posFinalZ;
4487 
4488  // Search event record for final state particles and store these in
4489  // quark, anti-quark and gluon vectors
4490  for ( int i=3; i < event.size(); ++i )
4491  if ( event[i].isFinal() ) {
4492  // Store final partons
4493  posFinalPartn.push_back(i);
4494  } else {
4495  // Store initial partons
4496  posInitPartn.push_back(i);
4497  }
4498  // Search event record for final W.
4499  for ( int i=0; i < event.size(); ++i )
4500  if ( event[i].isFinal() && event[i].idAbs() == 24 )
4501  posFinalW.push_back( i );
4502 
4503  // Search event record for final Z.
4504  for ( int i=0; i < event.size(); ++i )
4505  if ( event[i].isFinal() && event[i].idAbs() == 23 )
4506  posFinalZ.push_back( i );
4507 
4508 
4509  vector<Clustering> systems;
4510  // Find rad + emt + rec systems:
4511  // (1) Start from W boson and find all (rad,rec,emt=W) triples
4512  for ( int i = 0; i < int(posFinalW.size()); ++i ) {
4513  int emtW = posFinalW[i];
4514  systems = findEWTripleW( emtW, event, posFinalPartn, posInitPartn);
4515  ret.insert(ret.end(), systems.begin(), systems.end());
4516  systems.resize(0);
4517  }
4518  // Find rad + emt + rec systems:
4519  // (1) Start from Z boson and find all (rad,rec,emt=W) triples
4520  for ( int i = 0; i < int(posFinalZ.size()); ++i ) {
4521  int emtZ = posFinalZ[i];
4522 
4523  systems = findEWTripleZ( emtZ, event, posFinalPartn, posInitPartn);
4524  ret.insert(ret.end(), systems.begin(), systems.end());
4525  systems.resize(0);
4526  }
4527 
4528  return ret;
4529 }
4530 
4531 //--------------------------------------------------------------------------
4532 
4533 // Function to construct (rad,rec,emt) triples from the event
4534 // IN int : Position of Emitted in event record for which
4535 // dipoles should be constructed
4536 // int : Colour topogy to be tested
4537 // 1= g -> qqbar, causing 2 -> 2 dipole splitting
4538 // 2= q(bar) -> q(bar) g && g -> gg,
4539 // causing a 2 -> 3 dipole splitting
4540 // Event : event record to be checked for ptential partners
4541 // OUT vector of all allowed radiator+recoiler+emitted triples
4542 
4543 vector<Clustering> History::findEWTripleW ( int emtTagIn, const Event& event,
4544  vector<int> posFinalPartn, vector<int> posInitPartn ) {
4545  // Copy input parton tag
4546  int emtTag = emtTagIn;
4547  int flavEmt = event[emtTag].id();
4548 
4549  // Copy input colour topology tag
4550  // (1: g --> qqbar splitting present, 2:rest)
4551 
4552  // Initialise FinalSize
4553  int finalSize = int(posFinalPartn.size());
4554  int initSize = int(posInitPartn.size());
4555 
4556  // Store flavour count to check if the new flavour configuration is valid.
4557  vector<int> flavCounts(30,0);
4558 
4559  for ( int a = 0; a < finalSize; ++a ) {
4560  if (event[posFinalPartn[a]].idAbs() < 20) {
4561  int sign = 1;
4562  if (event[posFinalPartn[a]].id() < 0)
4563  sign = -1;
4564  flavCounts[event[posFinalPartn[a]].idAbs()] += sign;
4565  }
4566  if (event[posFinalPartn[a]].idAbs() == 24)
4567  flavCounts[24]++;
4568  }
4569 
4570  for ( int a = 0; a < initSize; ++a ) {
4571  if (event[posInitPartn[a]].idAbs() < 20) {
4572  int sign = 1;
4573  if (event[posInitPartn[a]].id() < 0)
4574  sign = -1;
4575  flavCounts[event[posInitPartn[a]].idAbs()] -= sign;
4576  }
4577  }
4578 
4579  vector<Clustering> clus;
4580 
4581  // Search final partons to find partons colour-connected to
4582  // event[EmtTag], choose radiator, then choose recoiler
4583  for ( int a = 0; a < finalSize; ++a ) {
4584 
4585  int iRad = posFinalPartn[a];
4586  if (iRad != emtTag) {
4587 
4588  // Spin information.
4589  int spinRad = event[iRad].intPol();
4590  if (spinRad == -1 || spinRad == 9 || spinRad == 0) {
4591 
4592  int pTdef = 1;
4593  // Find recoiler by flavour.
4594  int flavRad = event[iRad].id();
4595  // Only allow quark and leptons to be radiators.
4596  if (event[iRad].isQuark() || event[iRad].isLepton()) {
4597 
4598  // Check if the W+- matches that of the quark/lepton.
4599  int flavExp = (flavRad > 0) ? 24 : -24;
4600  if (abs(flavRad) % 2 == 0) flavExp = -flavExp;
4601  if (flavExp == flavEmt) {
4602 
4603  // Find possible flavours that the W can change the quark to.
4604  vector<int> flavRadBefs = posFlavCKM(flavRad);
4605 
4606  // Change to anti particles if radiator is an anti particle.
4607  if (flavRad < 0)
4608  for (int i = 0;i < int(flavRadBefs.size()); ++i)
4609  flavRadBefs[i] = - flavRadBefs[i];
4610 
4611  // Loop through final partons and try to find matching flavours.
4612  for ( int i = 0; i < finalSize; ++i ) {
4613  int iRec = posFinalPartn[i];
4614 
4615  // Check for particle overlaps.
4616  if ( iRec != iRad && iRec != emtTag ) {
4617 
4618  for (int j = 0;j < int(flavRadBefs.size()); ++j) {
4619  // Check new flavour structure. If multiple Ws
4620  // are still present, do not check flavour yet.
4621  if (flavCounts[24] <= 1 && !checkFlavour(flavCounts,
4622  flavRad, flavRadBefs[j], 1))
4623  continue;
4624 
4625  clus.push_back( Clustering(emtTag, iRad, iRec, iRec,
4626  pTLund(event, iRad, emtTag, iRec, pTdef, flavRadBefs[j]),
4627  flavRadBefs[j], -1 ) );
4628  }
4629  }
4630  }
4631  }
4632  }
4633  }
4634  }
4635  }
4636 
4637  // Search for initial shower histories.
4638  for (int a = 0;a < int(posInitPartn.size()); ++a) {
4639  int iRad = posInitPartn[a];
4640  int flavRad = event[iRad].id();
4641  // Only allow quarks and leptons to radiate weak bosons.
4642  if (event[iRad].isQuark() || event[iRad].isLepton()) {
4643 
4644  // Spin information.
4645  int spinRad = event[iRad].intPol();
4646  if (spinRad == -1 || spinRad == 9 || spinRad == 0) {
4647 
4648  // Check if the W+- matches that of the quark/lepton.
4649  int flavExp = (flavRad > 0) ? 24 : -24;
4650  if (abs(flavRad) % 2 == 1) flavExp = -flavExp;
4651  if (flavExp == flavEmt) {
4652  // Find possible flavours that the W cam change the quark to.
4653  vector<int> flavRadBefs = posFlavCKM(flavRad);
4654 
4655  // Change to anti particles if radiator is an anti particle.
4656  if (flavRad < 0)
4657  for (int i = 0;i < int(flavRadBefs.size()); ++i)
4658  flavRadBefs[i] = - flavRadBefs[i];
4659 
4660  // Loop through final partons and try to find matching flavours.
4661  for ( int i = 0; i < int(posInitPartn.size()); ++i ) {
4662  int iRec = posInitPartn[i];
4663 
4664  // Check for particle overlaps.
4665  if ( i != a && iRec != emtTag) {
4666  for (int j = 0;j < int(flavRadBefs.size()); ++j) {
4667 
4668  // Check new flavour structure.
4669  // If multiple Ws are still present, do not check flavour yet.
4670  if (flavCounts[24] <= 1 && !checkFlavour(flavCounts,
4671  flavRad, flavRadBefs[j], -1))
4672  continue;
4673  clus.push_back( Clustering(emtTag, iRad, iRec, iRec,
4674  pTLund(event, iRad, emtTag, iRec, -1, flavRadBefs[j]),
4675  flavRadBefs[j], -1 ) );
4676  }
4677  }
4678  }
4679  }
4680  }
4681  }
4682  }
4683 
4684  // Done
4685  return clus;
4686 }
4687 
4688 //--------------------------------------------------------------------------
4689 
4690 // Function to construct (rad,rec,emt) triples from the event
4691 // IN int : Position of Emitted in event record for which
4692 // dipoles should be constructed
4693 // int : Colour topogy to be tested
4694 // 1= g -> qqbar, causing 2 -> 2 dipole splitting
4695 // 2= q(bar) -> q(bar) g && g -> gg,
4696 // causing a 2 -> 3 dipole splitting
4697 // Event : event record to be checked for ptential partners
4698 // OUT vector of all allowed radiator+recoiler+emitted triples
4699 
4700 vector<Clustering> History::findEWTripleZ ( int emtTagIn, const Event& event,
4701  vector<int> posFinalPartn, vector<int> posInitPartn ) {
4702  // Copy input parton tag
4703  int emtTag = emtTagIn;
4704 
4705  // Copy input colour topology tag
4706  // (1: g --> qqbar splitting present, 2:rest)
4707 
4708  // Initialise FinalSize
4709  int finalSize = int(posFinalPartn.size());
4710  int initSize = int(posInitPartn.size());
4711 
4712  // Store flavour count to check if the new flavour configuration is valid.
4713  vector<int> flavCounts(30,0);
4714 
4715  for ( int a = 0; a < finalSize; ++a ) {
4716  if (event[posFinalPartn[a]].idAbs() < 20) {
4717  int sign = 1;
4718  if (event[posFinalPartn[a]].id() < 0)
4719  sign = -1;
4720  flavCounts[event[posFinalPartn[a]].idAbs()] += sign;
4721  }
4722  if (event[posFinalPartn[a]].idAbs() == 24)
4723  flavCounts[24]++;
4724  }
4725 
4726  for ( int a = 0; a < initSize; ++a ) {
4727  if (event[posInitPartn[a]].idAbs() < 20) {
4728  int sign = 1;
4729  if (event[posInitPartn[a]].id() < 0)
4730  sign = -1;
4731  flavCounts[event[posInitPartn[a]].idAbs()] -= sign;
4732  }
4733  }
4734 
4735  vector<Clustering> clus;
4736  // Add Z reclusterings.
4737 
4738  // Search final partons to find partons colour-connected to
4739  // event[EmtTag], choose radiator, then choose recoiler
4740  for ( int a = 0; a < finalSize; ++a ) {
4741 
4742  int iRad = posFinalPartn[a];
4743  if (iRad != emtTag) {
4744  int pTdef = 1;
4745  // Find recoiler by flavour.
4746  int flavRad = event[iRad].id();
4747 
4748  // Only allow quark and leptons to be radiators.
4749  if (event[iRad].isQuark() || event[iRad].isLepton())
4750  // Loop through final partons and try to find matching flavours.
4751  for ( int i = 0; i < finalSize; ++i ) {
4752  int iRec = posFinalPartn[i];
4753 
4754  // Check for particle overlaps.
4755  if ( iRec != iRad && iRec != emtTag ) {
4756  // Check new flavour structure.
4757  // If multiple Ws are still present, do not check flavour yet.
4758  if (flavCounts[24] <= 1 && !checkFlavour(flavCounts,
4759  flavRad, flavRad, 1))
4760  continue;
4761 
4762  clus.push_back( Clustering(emtTag, iRad, iRec, iRec,
4763  pTLund(event, iRad, emtTag, iRec, pTdef, flavRad),
4764  flavRad, -1 ) );
4765  }
4766  }
4767  }
4768  }
4769 
4770  // Search for initial shower histories.
4771  for (int a = 0;a < int(posInitPartn.size()); ++a) {
4772  int iRad = posInitPartn[a];
4773  int flavRad = event[iRad].id();
4774  // Only allow quarks and leptons to radiate weak bosons.
4775  if (event[iRad].isQuark() || event[iRad].isLepton()) {
4776 
4777  // Loop through initial partons and try to find matching flavours.
4778  for ( int i = 0; i < int(posInitPartn.size()); ++i ) {
4779  int iRec = posInitPartn[i];
4780 
4781  // Check for particle overlaps.
4782  if ( i != a && iRec != emtTag) {
4783  // Check new flavour structure.
4784  // If multiple Ws are still present, do not check flavour yet.
4785  if (flavCounts[24] <= 1 && !checkFlavour(flavCounts,
4786  flavRad, flavRad, -1))
4787  continue;
4788  clus.push_back( Clustering(emtTag, iRad, iRec, iRec,
4789  pTLund(event, iRad, emtTag, iRec, -1, flavRad),
4790  flavRad, -1 ) );
4791  }
4792  }
4793  }
4794  }
4795 
4796  // Done
4797  return clus;
4798 }
4799 
4800 //--------------------------------------------------------------------------
4801 
4802 // For the history-defining state (and if necessary interfering
4803 // states), find all possible clusterings.
4804 // NO INPUT
4805 // OUT vector of all (rad,rec,emt) systems
4806 
4807 vector<Clustering> History::getAllSQCDClusterings() {
4808  vector<Clustering> ret;
4809 
4810  // Get all clusterings for input state
4811  vector<Clustering> systems;
4812  systems = getSQCDClusterings(state);
4813  ret.insert(ret.end(), systems.begin(), systems.end());
4814  // Done
4815  return ret;
4816 }
4817 
4818 //--------------------------------------------------------------------------
4819 
4820 // For one given state, find all possible clusterings.
4821 // IN Event : state to be investigated
4822 // OUT vector of all (rad,rec,emt) systems in the state
4823 
4824 vector<Clustering> History::getSQCDClusterings( const Event& event) {
4825  vector<Clustering> ret;
4826 
4827  // Initialise vectors to keep track of position of partons in the
4828  // input event
4829  vector <int> posFinalPartn;
4830  vector <int> posInitPartn;
4831 
4832  vector <int> posFinalGluon;
4833  vector <int> posFinalQuark;
4834  vector <int> posFinalAntiq;
4835  vector <int> posInitGluon;
4836  vector <int> posInitQuark;
4837  vector <int> posInitAntiq;
4838 
4839  // Search event record for final state particles and store these in
4840  // quark, anti-quark and gluon vectors
4841  for (int i=0; i < event.size(); ++i)
4842  if ( event[i].isFinal() && event[i].colType() !=0 ) {
4843  // Store final partons
4844  posFinalPartn.push_back(i);
4845  if ( event[i].id() == 21 || event[i].id() == 1000021)
4846  posFinalGluon.push_back(i);
4847  else if ( (event[i].idAbs() < 10 && event[i].id() > 0)
4848  || (event[i].idAbs() < 1000010 && event[i].idAbs() > 1000000
4849  && event[i].id() > 0)
4850  || (event[i].idAbs() < 2000010 && event[i].idAbs() > 2000000
4851  && event[i].id() > 0))
4852  posFinalQuark.push_back(i);
4853  else if ( (event[i].idAbs() < 10 && event[i].id() < 0)
4854  || (event[i].idAbs() < 1000010 && event[i].idAbs() > 1000000
4855  && event[i].id() < 0)
4856  || (event[i].idAbs() < 2000010 && event[i].idAbs() > 2000000
4857  && event[i].id() < 0))
4858  posFinalAntiq.push_back(i);
4859  } else if ( event[i].status() == -21 && event[i].colType() != 0 ) {
4860  // Store initial partons
4861  posInitPartn.push_back(i);
4862  if ( event[i].id() == 21 || event[i].id() == 1000021)
4863  posInitGluon.push_back(i);
4864  else if ( (event[i].idAbs() < 10 && event[i].id() > 0)
4865  || (event[i].idAbs() < 1000010 && event[i].idAbs() > 1000000
4866  && event[i].id() > 0)
4867  || (event[i].idAbs() < 2000010 && event[i].idAbs() > 2000000
4868  && event[i].id() > 0))
4869  posInitQuark.push_back(i);
4870  else if ( (event[i].idAbs() < 10 && event[i].id() < 0)
4871  || (event[i].idAbs() < 1000010 && event[i].idAbs() > 1000000
4872  && event[i].id() < 0)
4873  || (event[i].idAbs() < 2000010 && event[i].idAbs() > 2000000
4874  && event[i].id() < 0))
4875  posInitAntiq.push_back(i);
4876  }
4877 
4878  int nFiGluon = int(posFinalGluon.size());
4879  int nFiQuark = int(posFinalQuark.size());
4880  int nFiAntiq = int(posFinalAntiq.size());
4881  int nInGluon = int(posInitGluon.size());
4882  int nInQuark = int(posInitQuark.size());
4883  int nInAntiq = int(posInitAntiq.size());
4884  vector<Clustering> systems;
4885 
4886  // Find rad + emt + rec systems:
4887  // (1) Start from gluon and find all (rad,rec,emt=gluon) triples
4888  for (int i = 0; i < nFiGluon; ++i) {
4889  int EmtGluon = posFinalGluon[i];
4890  systems = findSQCDTriple( EmtGluon, 2, event, posFinalPartn, posInitPartn);
4891  ret.insert(ret.end(), systems.begin(), systems.end());
4892  systems.resize(0);
4893  }
4894 
4895  // For more than one quark-antiquark pair in final state, check for
4896  // g -> qqbar splittings
4897  bool check_g2qq = true;
4898  if ( ( ( nInQuark + nInAntiq == 0 )
4899  && (nInGluon == 0)
4900  && (nFiQuark == 1) && (nFiAntiq == 1) )
4901  || ( ( nFiQuark + nFiAntiq == 0)
4902  && (nInQuark == 1) && (nInAntiq == 1) ) )
4903  check_g2qq = false;
4904 
4905  if ( check_g2qq ) {
4906 
4907  // (2) Start from quark and find all (rad,rec,emt=quark) triples
4908  // ( when g -> q qbar occured )
4909  for( int i=0; i < nFiQuark; ++i) {
4910  int EmtQuark = posFinalQuark[i];
4911  systems = findSQCDTriple( EmtQuark,1,event, posFinalPartn, posInitPartn);
4912  ret.insert(ret.end(), systems.begin(), systems.end());
4913  systems.resize(0);
4914  }
4915 
4916  // (3) Start from anti-quark and find all (rad,rec,emt=anti-quark)
4917  // triples ( when g -> q qbar occured )
4918  for( int i=0; i < nFiAntiq; ++i) {
4919  int EmtAntiq = posFinalAntiq[i];
4920  systems = findSQCDTriple( EmtAntiq,1,event, posFinalPartn, posInitPartn);
4921  ret.insert(ret.end(), systems.begin(), systems.end());
4922  systems.resize(0);
4923  }
4924 
4925  }
4926 
4927  return ret;
4928 }
4929 
4930 //--------------------------------------------------------------------------
4931 
4932 // Function to construct (rad,rec,emt) triples from the event
4933 // IN int : Position of Emitted in event record for which
4934 // dipoles should be constructed
4935 // int : Colour topogy to be tested
4936 // 1= g -> qqbar, causing 2 -> 2 dipole splitting
4937 // 2= q(bar) -> q(bar) g && g -> gg,
4938 // causing a 2 -> 3 dipole splitting
4939 // Event : event record to be checked for ptential partners
4940 // OUT vector of all allowed radiator+recoiler+emitted triples
4941 
4942 vector<Clustering> History::findSQCDTriple (int EmtTagIn, int colTopIn,
4943  const Event& event,
4944  vector<int> posFinalPartn,
4945  vector <int> posInitPartn ) {
4946 
4947  // Copy input parton tag
4948  int EmtTag = EmtTagIn;
4949  // Copy input colour topology tag
4950  // (1: g --> qqbar splitting present, 2:rest)
4951  int colTop = colTopIn;
4952 
4953  // PDG numbering offset for squarks
4954  int offsetL = 1000000;
4955  int offsetR = 2000000;
4956 
4957  // Initialise FinalSize
4958  int finalSize = int(posFinalPartn.size());
4959  int initSize = int(posInitPartn.size());
4960  int size = initSize + finalSize;
4961 
4962  vector<Clustering> clus;
4963 
4964  // Search final partons to find partons colour-connected to
4965  // event[EmtTag], choose radiator, then choose recoiler
4966  for ( int a = 0; a < size; ++a ) {
4967  int i = (a < finalSize)? a : (a - finalSize) ;
4968  int iRad = (a < finalSize)? posFinalPartn[i] : posInitPartn[i];
4969 
4970  if ( event[iRad].col() == event[EmtTag].col()
4971  && event[iRad].acol() == event[EmtTag].acol() )
4972  continue;
4973 
4974  // Save radiator flavour.
4975  int radID = event[iRad].id();
4976  // Remember if radiator is BSM.
4977  bool isSQCDrad = (abs(radID) > offsetL);
4978  // Remember if emitted is BSM.
4979  bool isSQCDemt = (event[EmtTag].idAbs() > offsetL );
4980 
4981  if (iRad != EmtTag ) {
4982  int pTdef = event[iRad].isFinal() ? 1 : -1;
4983  int sign = (a < finalSize)? 1 : -1 ;
4984 
4985  // Disalllow clusterings resulting in an initial state sQCD parton!
4986  int radBefID = getRadBeforeFlav(iRad,EmtTag,event);
4987  if ( pTdef == -1 && abs(radBefID) > offsetL ) continue;
4988 
4989  // First colour topology: g --> qqbar. Here, emt & rad should
4990  // have same flavour (causes problems for gamma->qqbar).
4991  if (colTop == 1) {
4992 
4993  int radSign = (event[iRad].id() < 0) ? -1 : 1;
4994  int emtSign = (event[EmtTag].id() < 0) ? -1 : 1;
4995 
4996  // Final gluino splitting.
4997  bool finalSplitting = false;
4998  if ( abs(radID) < 10
4999  && radSign*(abs(radID)+offsetL) == -sign*event[EmtTag].id() )
5000  finalSplitting = true;
5001  if ( abs(radID) < 10
5002  && radSign*(abs(radID)+offsetR) == -sign*event[EmtTag].id() )
5003  finalSplitting = true;
5004  if ( abs(radID) > offsetL && abs(radID) < offsetL+10
5005  && radID == -sign*emtSign*( event[EmtTag].idAbs() + offsetL) )
5006  finalSplitting = true;
5007  if ( abs(radID) > offsetR && abs(radID) < offsetR+10
5008  && radID == -sign*emtSign*( event[EmtTag].idAbs() + offsetR) )
5009  finalSplitting = true;
5010 
5011  // Initial gluon splitting.
5012  bool initialSplitting = false;
5013  if ( radID == 21 && ( ( event[EmtTag].idAbs() > offsetL
5014  && event[EmtTag].idAbs() < offsetL+10)
5015  || ( event[EmtTag].idAbs() > offsetR
5016  && event[EmtTag].idAbs() < offsetR+10) )
5017  && ( event[iRad].col() == event[EmtTag].col()
5018  || event[iRad].acol() == event[EmtTag].acol() ) )
5019  initialSplitting = true;
5020 
5021  if ( finalSplitting ) {
5022 
5023  int col = -1;
5024  int acl = -1;
5025  if ( radID < 0 && event[iRad].colType() == -1) {
5026  acl = event[EmtTag].acol();
5027  col = event[iRad].acol();
5028  } else if ( event[iRad].colType() == 1 ) {
5029  col = event[EmtTag].col();
5030  acl = event[iRad].col();
5031  }
5032 
5033  // Recoiler
5034  int iRec = 0;
5035  // Colour partner
5036  int iPartner = 0;
5037 
5038  if (col > 0) {
5039  // Find recoiler by colour
5040  iRec = FindCol(col,iRad,EmtTag,event,1,true);
5041  // In initial state splitting has final state colour partner,
5042  // Save both partner and recoiler
5043  if ( (sign < 0) && (event[iRec].isFinal()) ) {
5044  // Save colour recoiler
5045  iPartner = iRec;
5046  // Reset kinematic recoiler to initial state parton
5047  for(int l = 0; l < int(posInitPartn.size()); ++l)
5048  if (posInitPartn[l] != iRad) iRec = posInitPartn[l];
5049  // For final state splittings, colour partner and recoiler are
5050  // identical
5051  } else {
5052  iPartner = iRec;
5053  }
5054 
5055  // Not interested in pure QCD triples here.
5056  if ( !isSQCDrad && !isSQCDemt
5057  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
5058  iRec = 0;
5059 
5060  if ( iRec != 0 && iPartner != 0
5061  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
5062  attachClusterings (clus, EmtTag, iRad, iRec, iPartner,
5063  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
5064  continue;
5065  }
5066 
5067  // Reset partner
5068  iPartner = 0;
5069  // Find recoiler by colour
5070  iRec = FindCol(col,iRad,EmtTag,event,2,true);
5071  // In initial state splitting has final state colour partner,
5072  // Save both partner and recoiler
5073  if ( (sign < 0) && (event[iRec].isFinal()) ) {
5074  // Save colour recoiler
5075  iPartner = iRec;
5076  // Reset kinematic recoiler to initial state parton
5077  for(int l = 0; l < int(posInitPartn.size()); ++l)
5078  if (posInitPartn[l] != iRad) iRec = posInitPartn[l];
5079  // For final state splittings, colour partner and recoiler are
5080  // identical
5081  } else {
5082  iPartner = iRec;
5083  }
5084 
5085  // Not interested in pure QCD triples here.
5086  if ( !isSQCDrad && !isSQCDemt
5087  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
5088  iRec = 0;
5089 
5090  if ( iRec != 0 && iPartner != 0
5091  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
5092  attachClusterings (clus, EmtTag, iRad, iRec, iPartner,
5093  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
5094  continue;
5095  }
5096  }
5097 
5098  if (acl > 0) {
5099 
5100  // Reset partner
5101  iPartner = 0;
5102  // Find recoiler by colour
5103  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
5104  // In initial state splitting has final state colour partner,
5105  // Save both partner and recoiler
5106  if ( (sign < 0) && (event[iRec].isFinal()) ) {
5107  // Save colour recoiler
5108  iPartner = iRec;
5109  // Reset kinematic recoiler to initial state parton
5110  for(int l = 0; l < int(posInitPartn.size()); ++l)
5111  if (posInitPartn[l] != iRad) iRec = posInitPartn[l];
5112  // For final state splittings, colour partner and recoiler are
5113  // identical
5114  } else {
5115  iPartner = iRec;
5116  }
5117 
5118  // Not interested in pure QCD triples here.
5119  if ( !isSQCDrad && !isSQCDemt
5120  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
5121  iRec = 0;
5122 
5123  if ( iRec != 0 && iPartner != 0
5124  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
5125  attachClusterings (clus, EmtTag, iRad, iRec, iPartner,
5126  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
5127  continue;
5128  }
5129 
5130  // Reset partner
5131  iPartner = 0;
5132  // Find recoiler by colour
5133  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
5134  // In initial state splitting has final state colour partner,
5135  // Save both partner and recoiler
5136  if ( (sign < 0) && (event[iRec].isFinal()) ) {
5137  // Save colour recoiler
5138  iPartner = iRec;
5139  // Reset kinematic recoiler to initial state parton
5140  for(int l = 0; l < int(posInitPartn.size()); ++l)
5141  if (posInitPartn[l] != iRad) iRec = posInitPartn[l];
5142  // For final state splittings, colour partner and recoiler are
5143  // identical
5144  } else {
5145  iPartner = iRec;
5146  }
5147 
5148  // Not interested in pure QCD triples here.
5149  if ( !isSQCDrad && !isSQCDemt
5150  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
5151  iRec = 0;
5152 
5153  if ( iRec != 0 && iPartner != 0
5154  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
5155  attachClusterings (clus, EmtTag, iRad, iRec, iPartner,
5156  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
5157  continue;
5158  }
5159  }
5160  // Initial gluon splitting
5161  } else if ( initialSplitting ) {
5162 
5163  // SM splittings already taken care of in findQCDTriple.
5164  if ( !isSQCDrad && !isSQCDemt ) continue;
5165 
5166  // For an initial state radiator, always set recoiler
5167  // to the other initial state parton (recoil is taken
5168  // by full remaining system, so this is just a
5169  // labelling for such a process)
5170  int RecInit = 0;
5171  for(int l = 0; l < int(posInitPartn.size()); ++l)
5172  if (posInitPartn[l] != iRad) RecInit = posInitPartn[l];
5173 
5174  // Find the colour connected partner
5175  // Find colour index of radiator before splitting
5176  int col = getRadBeforeCol(iRad, EmtTag, event);
5177  int acl = getRadBeforeAcol(iRad, EmtTag, event);
5178 
5179  // Find the correct partner: If a colour line has split,
5180  // the partner is connected to the radiator before the splitting
5181  // by a colour line (same reasoning for anticolour). The colour
5182  // that split is the colour appearing twice in the
5183  // radiator + emitted pair.
5184  // Thus, if we remove a colour index with the clustering,
5185  // we should look for a colour partner, else look for
5186  // an anticolour partner
5187  int colRemove = (event[iRad].col() == event[EmtTag].col())
5188  ? event[iRad].col() : 0;
5189 
5190  int iPartner = 0;
5191  if (colRemove > 0 && col > 0)
5192  iPartner = FindCol(col,iRad,EmtTag,event,1,true)
5193  + FindCol(col,iRad,EmtTag,event,2,true);
5194  else if (colRemove > 0 && acl > 0)
5195  iPartner = FindCol(acl,iRad,EmtTag,event,1,true)
5196  + FindCol(acl,iRad,EmtTag,event,2,true);
5197 
5198  if ( allowedClustering( iRad, EmtTag, RecInit, iPartner, event ) ) {
5199  attachClusterings (clus, EmtTag, iRad, RecInit, iPartner,
5200  pTLund(event, iRad, EmtTag, RecInit, pTdef), event);
5201  continue;
5202  }
5203  }
5204 
5205  // Second colour topology: Gluino emission
5206 
5207  } else {
5208 
5209  if ( (event[iRad].col() == event[EmtTag].acol())
5210  || (event[iRad].acol() == event[EmtTag].col())
5211  || (event[iRad].col() == event[EmtTag].col())
5212  || (event[iRad].acol() == event[EmtTag].acol()) ) {
5213  // For the rest, choose recoiler to have a common colour
5214  // tag with radiator, while not being the "Emitted"
5215 
5216  int col = -1;
5217  int acl = -1;
5218 
5219  if (event[iRad].isFinal() ) {
5220 
5221  if ( radID < 0 && event[iRad].colType() == -1) {
5222  acl = event[EmtTag].acol();
5223  col = event[iRad].col();
5224  } else if ( radID > 0 && event[iRad].colType() == 1 ) {
5225  col = event[EmtTag].col();
5226  acl = event[iRad].acol();
5227  } else {
5228  col = event[iRad].col();
5229  acl = event[iRad].acol();
5230  }
5231 
5232  int iRec = 0;
5233  if (col > 0) {
5234  iRec = FindCol(col,iRad,EmtTag,event,1,true);
5235  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
5236  // Not interested in pure QCD triples here.
5237  if ( !isSQCDrad && !isSQCDemt
5238  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
5239  iRec = 0;
5240  if (iRec != 0
5241  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
5242  attachClusterings (clus, EmtTag, iRad, iRec, iRec,
5243  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
5244  continue;
5245  }
5246 
5247  iRec = FindCol(col,iRad,EmtTag,event,2,true);
5248  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
5249  // Not interested in pure QCD triples here.
5250  if ( !isSQCDrad && !isSQCDemt
5251  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
5252  iRec = 0;
5253  if (iRec != 0
5254  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
5255  attachClusterings (clus, EmtTag, iRad, iRec, iRec,
5256  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
5257  continue;
5258  }
5259  }
5260 
5261  if (acl > 0) {
5262  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
5263  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
5264  // Not interested in pure QCD triples here.
5265  if ( !isSQCDrad && !isSQCDemt
5266  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
5267  iRec = 0;
5268  if (iRec != 0
5269  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
5270  attachClusterings (clus, EmtTag, iRad, iRec, iRec,
5271  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
5272  continue;
5273  }
5274 
5275  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
5276  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
5277  // Not interested in pure QCD triples here.
5278  if ( !isSQCDrad && !isSQCDemt
5279  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
5280  iRec = 0;
5281  if (iRec != 0
5282  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
5283  attachClusterings (clus, EmtTag, iRad, iRec, iRec,
5284  pTLund(event, iRad, EmtTag, iRec, pTdef), event);
5285  continue;
5286  }
5287  }
5288 
5289  } else {
5290 
5291  // SM splittings already taken care of in findQCDTriple. Since
5292  // initial state splittings will not know if the true
5293  // colour-connected recoiler is a SM particle, any ISR splitting
5294  // of a SM particle will be included by findQCDTriple. To not
5295  // include the same splitting twice, continue for SM ISR radiator
5296  if ( !isSQCDrad || !isSQCDemt ) continue;
5297 
5298  // For an initial state radiator, always set recoiler
5299  // to the other initial state parton (recoil is taken
5300  // by full remaining system, so this is just a
5301  // labelling for such a process)
5302  int RecInit = 0;
5303  int iPartner = 0;
5304  for(int l = 0; l < int(posInitPartn.size()); ++l)
5305  if (posInitPartn[l] != iRad) RecInit = posInitPartn[l];
5306 
5307  // Find the colour connected partner
5308  // Find colour index of radiator before splitting
5309  col = getRadBeforeCol(iRad, EmtTag, event);
5310  acl = getRadBeforeAcol(iRad, EmtTag, event);
5311 
5312  // Find the correct partner: If a colour line has split,
5313  // the partner is connected to the radiator before the splitting
5314  // by a colour line (same reasoning for anticolour). The colour
5315  // that split is the colour appearing twice in the
5316  // radiator + emitted pair.
5317  // Thus, if we remove a colour index with the clustering,
5318  // we should look for a colour partner, else look for
5319  // an anticolour partner
5320  int colRemove = (event[iRad].col() == event[EmtTag].col())
5321  ? event[iRad].col() : 0;
5322  iPartner = (colRemove > 0)
5323  ? FindCol(col,iRad,EmtTag,event,1,true)
5324  + FindCol(col,iRad,EmtTag,event,2,true)
5325  : FindCol(acl,iRad,EmtTag,event,1,true)
5326  + FindCol(acl,iRad,EmtTag,event,2,true);
5327 
5328  if ( allowedClustering( iRad, EmtTag, RecInit, iPartner, event)) {
5329  attachClusterings (clus, EmtTag, iRad, RecInit, iPartner,
5330  pTLund(event, iRad, EmtTag, RecInit, pTdef), event);
5331  continue;
5332  }
5333  }
5334  }
5335  }
5336  }
5337  }
5338 
5339  // Done
5340  return clus;
5341 
5342 }
5343 
5344 //--------------------------------------------------------------------------
5345 
5346 // Calculate and return the probability of a clustering.
5347 // IN Clustering : rad,rec,emt - System for which the splitting
5348 // probability should be calcuated
5349 // OUT splitting probability
5350 
5351 double History::getProb(const Clustering & SystemIn) {
5352 
5353  // Get local copies of input system
5354  int Rad = SystemIn.emittor;
5355  int Rec = SystemIn.recoiler;
5356  int Emt = SystemIn.emitted;
5357 
5358  // Initialise shower probability
5359  double showerProb = 0.0;
5360 
5361  // If the splitting resulted in disallowed evolution variable,
5362  // disallow the splitting
5363  if (SystemIn.pT() <= 0.) return 0.;
5364 
5365  // Initialise all combinatorical factors
5366  double CF = 4./3.;
5367  double CA = 3.;
5368  // Flavour is known when reclustring, thus n_f=1
5369  double TR = 1./2.;
5370 
5371  // Split up in FSR and ISR
5372  bool isFSR = (state[Rad].isFinal() && state[Rec].isFinal());
5373  bool isFSRinREC = (state[Rad].isFinal() && !state[Rec].isFinal());
5374  bool isISR = !state[Rad].isFinal();
5375 
5376  // Check if external splitting probability should be used.
5377  if ( mergingHooksPtr->useShowerPlugin() ) {
5378  int iPartner = (isISR && SystemIn.partner > 0) ? SystemIn.partner : Rec;
5379 
5380  double pr = 0.;
5381  bool isFSR2 = showers->timesPtr->isTimelike(state, Rad, Emt, iPartner, "");
5382  if (isFSR2) {
5383  string name = showers->timesPtr->getSplittingName( state, Rad, Emt,
5384  iPartner).front();
5385  pr = showers->timesPtr->getSplittingProb( state, Rad, Emt,
5386  iPartner, name);
5387  } else {
5388  string name = showers->spacePtr->getSplittingName(state, Rad, Emt,
5389  iPartner).front();
5390  pr = showers->spacePtr->getSplittingProb(state, Rad, Emt,
5391  iPartner, name);
5392  }
5393  return abs(pr);
5394  }
5395 
5396  // Check if this is the clustering 2->3 to 2->2.
5397  // If so, use weight for joined evolution
5398  int nFinal = 0;
5399  for(int i=0; i < state.size(); ++i)
5400  if (state[i].isFinal()) nFinal++;
5401  bool isLast = (nFinal == (mergingHooksPtr->hardProcess->nQuarksOut()
5402  +mergingHooksPtr->hardProcess->nLeptonOut()+1));
5403 
5404  // Do not calculate splitting functions for electroweak emissions
5405  bool isElectroWeak = (state[Emt].idAbs() == 23 || state[Emt].idAbs() == 24);
5406 
5407  if (isISR) {
5408  // Find incoming particles
5409  int inP = 0;
5410  int inM = 0;
5411  for(int i=0;i< int(state.size()); ++i) {
5412  if (state[i].mother1() == 1) inP = i;
5413  if (state[i].mother1() == 2) inM = i;
5414  }
5415  // Construct dipole mass, eCM and sHat = x1*x2*s
5416  Vec4 sum = state[Rad].p() + state[Rec].p() - state[Emt].p();
5417  double m2Dip = sum.m2Calc();
5418  double sHat = (state[inM].p() + state[inP].p()).m2Calc();
5419  // Energy fraction z=E_q1/E_qi in branch q(i)q(2) -> q(1)g(3)q(2)
5420  double z1 = m2Dip / sHat;
5421  // Virtuality of the splittings
5422  Vec4 Q1( state[Rad].p() - state[Emt].p() );
5423  Vec4 Q2( state[Rec].p() - state[Emt].p() );
5424  // Q^2 for emission off radiator line
5425  double Q1sq = -Q1.m2Calc();
5426  // pT^2 for emission off radiator line
5427  double pT1sq = pow2(pTLund(state, Rad, Emt, Rec, -1, SystemIn.flavRadBef));
5428  // Remember if massive particles involved: Mass corrections for
5429  // to g->QQ and Q->Qg splittings
5430  bool g2QQmassive = mergingHooksPtr->includeMassive()
5431  && state[Rad].id() == 21
5432  && ( (state[Emt].idAbs() >= 4 && state[Emt].idAbs() < 7)
5433  || (state[Emt].idAbs() > 1000000 && state[Emt].idAbs() < 1000010 )
5434  || (state[Emt].idAbs() > 2000000 && state[Emt].idAbs() < 2000010 ));
5435  bool Q2Qgmassive = mergingHooksPtr->includeMassive()
5436  && state[Emt].id() == 21
5437  && ( (state[Rad].idAbs() >= 4 && state[Rad].idAbs() < 7)
5438  || (state[Rad].idAbs() > 1000000 && state[Rad].idAbs() < 1000010 )
5439  || (state[Rad].idAbs() > 2000000 && state[Rad].idAbs() < 2000010 ));
5440  bool isMassive = mergingHooksPtr->includeMassive()
5441  && ( g2QQmassive || Q2Qgmassive
5442  || state[Emt].id() == 1000021);
5443  double m2Emt0 = state[Emt].p().m2Calc();
5444  double m2Rad0 = pow(particleDataPtr->m0(state[Rad].id()),2);
5445 
5446  // Correction of virtuality for massive splittings
5447  if ( g2QQmassive) Q1sq += m2Emt0;
5448  else if (Q2Qgmassive) Q1sq += m2Rad0;
5449 
5450  // pT0 dependence!!!
5451  double pT0sq = pow(mergingHooksPtr->pT0ISR(),2);
5452  double Q2sq = -Q2.m2Calc();
5453 
5454  // Correction of virtuality of other splitting
5455  bool g2QQmassiveRec = mergingHooksPtr->includeMassive()
5456  && state[Rec].id() == 21
5457  && ( state[Emt].idAbs() >= 4 && state[Emt].idAbs() < 7);
5458  bool Q2QgmassiveRec = mergingHooksPtr->includeMassive()
5459  && state[Emt].id() == 21
5460  && ( state[Rec].idAbs() >= 4 && state[Rec].idAbs() < 7);
5461  double m2Rec0 = pow(particleDataPtr->m0(state[Rec].id()),2);
5462  if ( g2QQmassiveRec) Q2sq += m2Emt0;
5463  else if (Q2QgmassiveRec) Q2sq += m2Rec0;
5464 
5465  bool hasJoinedEvol = (state[Emt].id() == 21
5466  || state[Rad].id() == state[Rec].id());
5467 
5468  // Initialise normalization factor multiplying the splitting
5469  // function numerator
5470  double fac = 1.;
5471  if ( mergingHooksPtr->pickByFull() || mergingHooksPtr->pickBySumPT()) {
5472  double facJoined = ( Q2sq + pT0sq/(1.-z1) )
5473  * 1./(Q1sq*Q2sq + pT0sq*sHat + pow(pT0sq/(1.-z1),2));
5474  double facSingle = mergingHooksPtr->nonJoinedNorm()*1./( pT1sq + pT0sq);
5475 
5476  fac = (hasJoinedEvol && isLast) ? facJoined : facSingle;
5477 
5478  } else if (mergingHooksPtr->pickByPoPT2()) {
5479  fac = 1./(pT1sq + pT0sq);
5480  } else {
5481  string message="Error in History::getProb: Scheme for calculating";
5482  message+=" shower splitting probability is undefined.";
5483  infoPtr->errorMsg(message);
5484  }
5485 
5486  // Calculate shower splitting probability:
5487  // Splitting functions*normalization*ME reweighting factors
5488 
5489  if ( isElectroWeak ) {
5490 
5491  // For electroweak splittings, the probabilities depend on the
5492  // full shower history, and can hence not be calculated correctly
5493  // here. Thus, use dummy value and "dress" with full probabilities
5494  // later, once the path is known.
5495  showerProb = 1.;
5496 
5497  // Calculate branching probability for q -> q g
5498  } else if ( state[Emt].id() == 21 && state[Rad].id() != 21) {
5499  // Find splitting kernel
5500  double num = CF*(1. + pow(z1,2)) / (1.-z1);
5501  if (isMassive) num -= CF * z1 * (1.-z1) * (m2Rad0/pT1sq);
5502 
5503  // Find ME reweighting factor
5504  double meReweighting = 1.;
5505  // Find the number of final state coloured particles, apart
5506  // from those coming from the hard process
5507  int nCol = 0;
5508  for(int i=0; i < state.size(); ++i)
5509  if (state[i].isFinal() && state[i].colType() != 0
5510  && !mergingHooksPtr->hardProcess->matchesAnyOutgoing(i,state) )
5511  nCol++;
5512  // For first splitting of single vector boson production,
5513  // apply ME corrections
5514  if (nCol == 1
5515  && int(mergingHooksPtr->hardProcess->hardIntermediate.size()) == 1) {
5516  double sH = m2Dip / z1;
5517  double tH = -Q1sq;
5518  double uH = Q1sq - m2Dip * (1. - z1) / z1;
5519  double misMatch = (uH*tH - (uH + tH)*pT0sq/(1.-z1)
5520  + pow(pT0sq/(1.-z1),2) ) / (uH*tH);
5521  meReweighting *= (tH*tH + uH*uH + 2. * m2Dip * sH)
5522  / (sH*sH + m2Dip*m2Dip);
5523  meReweighting *= misMatch;
5524  }
5525  // Multiply factors
5526  showerProb = num*fac*meReweighting;
5527 
5528  // Calculate branching probability for g -> g g
5529  } else if ( state[Emt].id() == 21 && state[Rad].id() == 21) {
5530  // Calculate splitting kernel
5531  double num = 2.*CA*pow2(1. - z1*(1.-z1)) / (z1*(1.-z1));
5532 
5533  // Include ME reweighting for higgs!!
5534  // Find ME reweighting factor
5535  double meReweighting = 1.;
5536  // Find the number of final state coloured particles, apart
5537  // from those coming from the hard process
5538  int nCol = 0;
5539  for(int i=0; i < state.size(); ++i)
5540  if (state[i].isFinal() && state[i].colType() != 0
5541  && !mergingHooksPtr->hardProcess->matchesAnyOutgoing(i,state) )
5542  nCol++;
5543  // For first splitting of single vector boson production,
5544  // apply ME corrections
5545  if ( nCol == 1
5546  && mergingHooksPtr->getProcessString().compare("pp>h") == 0
5547  && int(mergingHooksPtr->hardProcess->hardIntermediate.size()) == 1 ) {
5548  double sH = m2Dip / z1;
5549  double tH = -Q1sq;
5550  double uH = Q1sq - m2Dip * (1. - z1) / z1;
5551  meReweighting *= 0.5
5552  * (pow4(sH) + pow4(tH) + pow4(uH) + pow4(m2Dip))
5553  / pow2(sH*sH - m2Dip * (sH - m2Dip));
5554  }
5555 
5556  // Multiply factors
5557  showerProb = num*fac*meReweighting;
5558 
5559  // Calculate branching probability for q -> g q
5560  } else if ( state[Emt].id() != 21 && state[Rad].id() != 21 ) {
5561  // Calculate splitting kernel
5562  double num = CF*(1. + pow2(1.-z1)) / z1;
5563 
5564  // Include ME reweighting for higgs!!
5565  // Find ME reweighting factor
5566  double meReweighting = 1.;
5567  // Find the number of final state coloured particles, apart
5568  // from those coming from the hard process
5569  int nCol = 0;
5570  for ( int i=0; i < state.size(); ++i )
5571  if ( state[i].isFinal() && state[i].colType() != 0
5572  && !mergingHooksPtr->hardProcess->matchesAnyOutgoing(i,state) )
5573  nCol++;
5574  // For first splitting of single vector boson production,
5575  // apply ME corrections
5576  if (nCol == 1
5577  && mergingHooksPtr->getProcessString().compare("pp>h") == 0
5578  && int(mergingHooksPtr->hardProcess->hardIntermediate.size()) == 1) {
5579  double sH = m2Dip / z1;
5580  double uH = Q1sq - m2Dip * (1. - z1) / z1;
5581  meReweighting *= (sH*sH + uH*uH)
5582  / (sH*sH + pow2(sH -m2Dip));
5583  }
5584 
5585  // Multiply factors
5586  showerProb = num*fac*meReweighting;
5587 
5588  // Calculate branching probability for g -> q qbar
5589  } else if ( state[Emt].id() != 21 && state[Rad].id() == 21 ) {
5590 
5591  // Calculate splitting kernel
5592  double num = TR * ( pow(z1,2) + pow(1.-z1,2) );
5593  if (isMassive) num += TR * 2.*z1*(1.-z1)*(m2Emt0/pT1sq);
5594  // Calculate ME reweighting factor
5595  double meReweighting = 1.;
5596  // Find the number of final state coloured particles, apart
5597  // from those coming from the hard process
5598  int nCol = 0;
5599  for ( int i=0; i < state.size(); ++i )
5600  if ( state[i].isFinal() && state[i].colType() != 0
5601  && !mergingHooksPtr->hardProcess->matchesAnyOutgoing(i,state) )
5602  nCol++;
5603  // For first splitting of single vector boson production,
5604  // apply ME corrections
5605  if (nCol == 1
5606  && int(mergingHooksPtr->hardProcess->hardIntermediate.size()) == 1) {
5607  double sH = m2Dip / z1;
5608  double tH = -Q1sq;
5609  double uH = Q1sq - m2Dip * (1. - z1) / z1;
5610  swap( tH, uH);
5611  double misMatch = ( uH - pT0sq/(1.-z1) ) / uH;
5612  double me = (sH*sH + uH*uH + 2. * m2Dip * tH)
5613  / (pow2(sH - m2Dip) + m2Dip*m2Dip);
5614  // Weight with me/overestimate
5615  meReweighting *= me;
5616  meReweighting *= misMatch;
5617  }
5618  // Multiply factors
5619  showerProb = num*fac*meReweighting;
5620 
5621  // Print error if no kernel calculated
5622  } else {
5623  string message = "Error in History::getProb: Splitting kernel"
5624  " undefined in ISR in clustering.";
5625  infoPtr->errorMsg(message);
5626  }
5627 
5628  // If corrected pT below zero in ISR, put probability to zero
5629  double m2Sister = pow(state[Emt].m(),2);
5630  double pT2corr = (Q1sq - z1*(m2Dip + Q1sq)*(Q1sq + m2Sister)/m2Dip);
5631  if (pT2corr < 0.) showerProb = 0.0;
5632 
5633  // If creating heavy quark by Q -> gQ then next need g -> Q + Qbar.
5634  // So minimum total mass2 is 4 * m2Sister, but use more to be safe.
5635  if ( state[Emt].id() == state[Rad].id()
5636  && ( state[Rad].idAbs() == 4 || state[Rad].idAbs() == 5 )) {
5637  double m2QQsister = 2.*4.*m2Sister;
5638  double pT2QQcorr = Q1sq - z1*(m2Dip + Q1sq)*(Q1sq + m2QQsister)
5639  / m2Dip;
5640  if (pT2QQcorr < 0.0) showerProb = 0.0;
5641  }
5642 
5643  // Check cuts on momentum fraction.
5644  double pT2minNow
5645  = pow2(mergingHooksPtr->settingsPtr->parm("SpaceShower:pTmin"));
5646  //double pT2minNow = mergingHooksPtr->pTcut();
5647  double zMaxAbs = 1. - 0.5 * (pT2minNow / m2Dip) *
5648  ( sqrt( 1. + 4. * m2Dip / pT2minNow ) - 1. );
5649  zMaxAbs = min(1.,zMaxAbs);
5650  //double zMinAbs = max(0.,1. - zMaxAbs);
5651  double zMinAbs = 2. * state[Rad].e() / state[0].e() * z1;
5652 
5653  // Massive z limit.
5654  int radBefID = getRadBeforeFlav(Rad, Emt, state);
5655  if ( abs(radBefID) == 4 || abs(radBefID) == 5 ) {
5656  double m2Massive = pow2(particleDataPtr->m0(radBefID));
5657  double mRatio = sqrt( m2Massive / m2Dip );
5658  double zMaxMassive = (1. - mRatio) / ( 1. + mRatio * (1. - mRatio) );
5659  zMaxAbs = min(zMaxAbs, zMaxMassive);
5660  }
5661 
5662  if (z1 < zMinAbs || z1 > zMaxAbs) showerProb = 0.0;
5663 
5664  if (mergingHooksPtr->includeRedundant()) {
5665  // Initialise the spacelike shower alpha_S
5666  AlphaStrong* asISR = mergingHooksPtr->AlphaS_ISR();
5667  double as = (*asISR).alphaS(pT1sq + pT0sq) / (2.*M_PI);
5668  // Multiply with alpha_S
5669  showerProb *= as;
5670  }
5671 
5672  // Done for ISR case, begin FSR case
5673 
5674  } else if (isFSR || isFSRinREC) {
5675 
5676  // Construct dipole mass
5677  int recSign = (state[Rec].isFinal()) ? 1 : -1;
5678  Vec4 sum = state[Rad].p() + recSign*state[Rec].p() + state[Emt].p();
5679  double m2Dip = abs(sum.m2Calc());
5680 
5681  // Virtuality of the splittings
5682  Vec4 Q1( state[Rad].p() + state[Emt].p() );
5683  Vec4 Q2( state[Rec].p() + state[Emt].p() );
5684 
5685  // Get z value.
5686  double z1 = getCurrentZ( Rad, Rec, Emt, SystemIn.flavRadBef);
5687 
5688  // Q^2 for emission off radiator line
5689  double Q1sq = Q1.m2Calc();
5690  // pT^2 for emission off radiator line
5691  double pT1sq = pow(SystemIn.pT(),2);
5692  // Q^2 for emission off recoiler line
5693  double Q2sq = Q2.m2Calc();
5694 
5695  // Remember if radiator or recoiler is massive.
5696  bool isMassiveRad = ( state[Rad].idAbs() >= 4
5697  && state[Rad].id() != 21 );
5698  bool isMassiveRec = ( state[Rec].idAbs() >= 4
5699  && state[Rec].id() != 21 );
5700 
5701  // Correction of virtuality for massive splittings.
5702  double m2Rad0 = pow(particleDataPtr->m0(state[Rad].id()),2);
5703  double m2Rec0 = pow(particleDataPtr->m0(state[Rec].id()),2);
5704  if ( mergingHooksPtr->includeMassive() && isMassiveRad ) Q1sq -= m2Rad0;
5705  if ( mergingHooksPtr->includeMassive() && isMassiveRec ) Q2sq -= m2Rec0;
5706 
5707  // Initialise normalization factor multiplying the splitting
5708  // function numerator
5709  double fac = 1.;
5710  if ( mergingHooksPtr->pickByFull() || mergingHooksPtr->pickBySumPT()) {
5711  double facJoined = (1.-z1)/Q1sq * m2Dip/( Q1sq + Q2sq );
5712  double facSingle = mergingHooksPtr->fsrInRecNorm() * 1./ pT1sq;
5713  fac = (!isFSRinREC && isLast) ? facJoined : facSingle;
5714 
5715  } else if (mergingHooksPtr->pickByPoPT2()) {
5716  fac = 1. / pT1sq;
5717  } else {
5718  string message="Error in History::getProb: Scheme for calculating";
5719  message+=" shower splitting probability is undefined.";
5720  infoPtr->errorMsg(message);
5721  }
5722  // Calculate shower splitting probability:
5723  // Splitting functions*normalization*ME reweighting factors
5724 
5725  if ( isElectroWeak ) {
5726 
5727  // For electroweak splittings, the probabilities depend on the
5728  // full shower history, and can hence not be calculated correctly
5729  // here. Thus, use dummy value and "dress" with full probabilities
5730  // later, once the path is known.
5731  showerProb = 1.;
5732 
5733  // Calculate branching probability for g -> g_1 g_2
5734  } else if ( state[Emt].id() == 21 && state[Rad].colType() == 2) {
5735 
5736  // Calculate splitting kernel
5737  double num = 0.5* CA * (1. + pow3(z1)) / (1.-z1);
5738  // Multiply factors
5739  showerProb = num*fac;
5740 
5741  // Calculate branching probability for q -> q g with quark recoiler
5742  } else if ( state[Emt].id() == 21
5743  && state[Rad].colType() != 2 && state[Rec].colType() != 2) {
5744  // For a qqbar dipole in FSR, ME corrections exist and the
5745  // splitting function "z-weight" is set to 1.0 (only for 2->2 ??)
5746  double num = CF * 2./(1.-z1);
5747  // Find the number of final state coloured particles, apart
5748  // from those coming from the hard process
5749  int nCol = 0;
5750  for(int i=0; i < state.size(); ++i)
5751  if (state[i].isFinal() && state[i].colType() != 0
5752  && !mergingHooksPtr->hardProcess->matchesAnyOutgoing(i,state) )
5753  nCol++;
5754  // Calculate splitting kernel
5755  if ( nCol > 3
5756  || int(mergingHooksPtr->hardProcess->hardIntermediate.size()) > 1)
5757  num = CF * (1. + pow2(z1)) /(1.-z1);
5758  // Calculate ME reweighting factor
5759  double meReweighting = 1.;
5760  // Correct if this is the process created by the first
5761  // FSR splitting of a 2->2 process
5762  if ( nCol == 3
5763  && int(mergingHooksPtr->hardProcess->hardIntermediate.size()) == 1 ) {
5764  // Construct 2->3 variables for FSR
5765  double x1 = 2. * (sum * state[Rad].p()) / m2Dip;
5766  double x2 = 2. * (sum * state[Rec].p()) / m2Dip;
5767  double prop1 = max(1e-12, 1. - x1);
5768  double prop2 = max(1e-12, 1. - x2);
5769  double x3 = max(1e-12, 2. - x1 - x2);
5770  // Calculate the ME reweighting factor
5771  double ShowerRate1 = 2./( x3 * prop2 );
5772  double meDividingFactor1 = prop1 / x3;
5773  double me = (pow(x1,2) + pow(x2,2))/(prop1*prop2);
5774  meReweighting = meDividingFactor1 * me / ShowerRate1;
5775  }
5776  // Multiply factors
5777  showerProb = num*fac*meReweighting;
5778 
5779  // Calculate branching probability for q -> q g with gluon recoiler
5780  } else if ( state[Emt].id() == 21 && state[Rad].colType() != 2
5781  && state[Rec].colType() == 2 ) {
5782  // For qg /qbarg dipoles, the splitting function is
5783  // calculated and not weighted by a ME correction factor
5784  // Shower splitting function
5785  double num = CF * (1. + pow2(z1)) / (1.-z1);
5786  showerProb = num*fac;
5787 
5788  // Calculate branching probability for g -> q qbar
5789  } else if ( state[Emt].id() != 21 ) {
5790  // Get flavour of quark / antiquark
5791  int flavour = state[Emt].id();
5792  // Get correct masses for the quarks
5793  // (needed to calculate splitting function?)
5794  double mFlavour = particleDataPtr->m0(flavour);
5795  // Get mass of quark/antiquark pair
5796  double mDipole = m(state[Rad].p(), state[Emt].p());
5797  // Factor determining if gluon decay was allowed
5798  double beta = sqrtpos( 1. - 4.*pow2(mFlavour)/pow2(mDipole) );
5799  // Shower splitting function
5800  double num = 0.5*TR * ( z1*z1 + (1.-z1)*(1.-z1) );
5801  if (beta <= 0.) beta = 0.;
5802 
5803  showerProb = num*fac*beta;
5804 
5805  // Print error if no kernel calculated
5806  } else {
5807  string message="Error in History::getProb: Splitting kernel undefined";
5808  message+=" in FSR clustering.";
5809  infoPtr->errorMsg(message);
5810  }
5811 
5812  if (mergingHooksPtr->includeRedundant()) {
5813  // Initialise the spacelike shower alpha_S
5814  AlphaStrong* asFSR = mergingHooksPtr->AlphaS_FSR();
5815  double as = (*asFSR).alphaS(pT1sq) / (2.*M_PI);
5816  // Multiply with alpha_S
5817  showerProb *= as;
5818  }
5819 
5820  double m2DipCorr = pow2(sqrt(m2Dip) - sqrt(m2Rec0)) - m2Rad0;
5821  double zMin = 0.5 - sqrtpos( 0.25 - pT1sq / m2DipCorr );
5822  double m2 = m2Rad0 + 2. * state[Rad].p()*state[Emt].p();
5823  bool keepMassive = (z1 > zMin && z1 < 1. - zMin
5824  && m2 * m2Dip < z1 * (1. - z1) * pow2(m2Dip + m2 - m2Rec0) );
5825  // No emission probability outside disallowed z range.
5826  if (!keepMassive) showerProb *= 0.0;
5827 
5828  // Done for FSR
5829  } else {
5830  string message="Error in History::getProb: Radiation could not be";
5831  message+=" interpreted as FSR or ISR.";
5832  infoPtr->errorMsg(message);
5833  }
5834 
5835  if (mergingHooksPtr->doWeakClustering()) {
5836 
5837  // Every time we assign spin, equivalent QCD histories are counted twice,
5838  // due to distingushing between quark spins.
5839  // To remove this overcounting, multiply by QCD probabilities by 1/2,
5840  // for each quark spin that has been assigned.
5841  double factor = 1.;
5842  if (state[Rad].idAbs() < 10 && state[Rad].intPol() == 9
5843  && SystemIn.spinRad != 9) factor *= 0.5;
5844  if (state[Emt].idAbs() < 10 && state[Emt].intPol() == 9
5845  && SystemIn.spinEmt != 9) factor *= 0.5;
5846  if (state[Rec].idAbs() < 10 && state[Rec].intPol() == 9
5847  && SystemIn.spinRec != 9) factor *= 0.5;
5848  if ( state[Emt].colType() != 0 ) {
5849  showerProb *= factor;
5850  }
5851 
5852  // The g -> q qbar splitting leads to two histories, not four.
5853  // The previous clustering steps overcounted the number of histories to be
5854  // four, leading to a too small probability of a path by 1/2. Correct!
5855  if ( state[Emt].idAbs() < 10 && state[Rad].colType() != 0) {
5856  showerProb *= 2.0;
5857  }
5858 
5859  }
5860 
5861  // Done
5862  return showerProb;
5863 
5864 }
5865 
5866 //--------------------------------------------------------------------------
5867 
5868 // Set up the beams (fill the beam particles with the correct
5869 // current incoming particles) to allow calculation of splitting
5870 // probability.
5871 // For interleaved evolution, set assignments dividing PDFs into
5872 // sea and valence content. This assignment is, until a history path
5873 // is chosen and a first trial shower performed, not fully correct
5874 // (since content is chosen form too high x and too low scale). The
5875 // assignment used for reweighting will be corrected after trial
5876 // showering
5877 
5878 void History::setupBeams() {
5879 
5880  // Do nothing for empty event, possible if sequence of
5881  // clusterings was ill-advised in that it results in
5882  // colour-disconnected states
5883  if (state.size() < 4) return;
5884  // Do nothing for e+e- beams
5885  if ( state[3].colType() == 0 ) return;
5886  if ( state[4].colType() == 0 ) return;
5887 
5888  // Incoming partons to hard process are stored in slots 3 and 4.
5889  int inS = 0;
5890  int inP = 0;
5891  int inM = 0;
5892  for(int i=0;i< int(state.size()); ++i) {
5893  if (state[i].mother1() == 1) inP = i;
5894  if (state[i].mother1() == 2) inM = i;
5895  }
5896 
5897  // Save some info before clearing beams
5898  // Mothers of incoming partons companion code
5899  int motherPcompRes = -1;
5900  int motherMcompRes = -1;
5901 
5902  bool sameFlavP = false;
5903  bool sameFlavM = false;
5904 
5905  if (mother) {
5906  int inMotherP = 0;
5907  int inMotherM = 0;
5908  for(int i=0;i< int(mother->state.size()); ++i) {
5909  if (mother->state[i].mother1() == 1) inMotherP = i;
5910  if (mother->state[i].mother1() == 2) inMotherM = i;
5911  }
5912  sameFlavP = (state[inP].id() == mother->state[inMotherP].id());
5913  sameFlavM = (state[inM].id() == mother->state[inMotherM].id());
5914 
5915  motherPcompRes = (sameFlavP) ? beamA[0].companion() : -2;
5916  motherMcompRes = (sameFlavM) ? beamB[0].companion() : -2;
5917  }
5918 
5919  // Append the current incoming particles to the beam
5920  beamA.clear();
5921  beamB.clear();
5922 
5923  // Get energy of incoming particles
5924  double Ep = 2. * state[inP].e();
5925  double Em = 2. * state[inM].e();
5926 
5927  // If incoming partons are massive then recalculate to put them massless.
5928  if (state[inP].m() != 0. || state[inM].m() != 0.) {
5929  Ep = state[inP].pPos() + state[inM].pPos();
5930  Em = state[inP].pNeg() + state[inM].pNeg();
5931  }
5932 
5933  // Add incoming hard-scattering partons to list in beam remnants.
5934  double x1 = Ep / state[inS].m();
5935  beamA.append( inP, state[inP].id(), x1);
5936  double x2 = Em / state[inS].m();
5937  beamB.append( inM, state[inM].id(), x2);
5938 
5939  // Scale. For ME multiplicity history, put scale to mu_F
5940  // (since sea/valence quark content is chosen from this scale)
5941  double scalePDF = (mother) ? scale : infoPtr->QFac();
5942  // Find whether incoming partons are valence or sea. Store.
5943  // Can I do better, e.g. by setting the scale to the hard process
5944  // scale (= M_W) or by replacing one of the x values by some x/z??
5945  beamA.xfISR( 0, state[inP].id(), x1, scalePDF*scalePDF);
5946  if (!mother) {
5947  beamA.pickValSeaComp();
5948  } else {
5949  beamA[0].companion(motherPcompRes);
5950  }
5951  beamB.xfISR( 0, state[inM].id(), x2, scalePDF*scalePDF);
5952  if (!mother) {
5953  beamB.pickValSeaComp();
5954  } else {
5955  beamB[0].companion(motherMcompRes);
5956  }
5957 
5958 }
5959 
5960 //--------------------------------------------------------------------------
5961 
5962 // Calculate the PDF ratio used in the argument of the no-emission
5963 // probability
5964 
5965 double History::pdfForSudakov() {
5966 
5967  // Do nothing for e+e- beams
5968  if ( state[3].colType() == 0 ) return 1.0;
5969  if ( state[4].colType() == 0 ) return 1.0;
5970 
5971  // Check if splittings was ISR or FSR
5972  bool FSR = ( mother->state[clusterIn.emittor].isFinal()
5973  && mother->state[clusterIn.recoiler].isFinal());
5974  bool FSRinRec = ( mother->state[clusterIn.emittor].isFinal()
5975  && !mother->state[clusterIn.recoiler].isFinal());
5976 
5977  // Done for pure FSR
5978  if (FSR) return 1.0;
5979 
5980  int iInMother = (FSRinRec)? clusterIn.recoiler : clusterIn.emittor;
5981  // Find side of event that was reclustered
5982  int side = ( mother->state[iInMother].pz() > 0 ) ? 1 : -1;
5983 
5984  int inP = 0;
5985  int inM = 0;
5986  for(int i=0;i< int(state.size()); ++i) {
5987  if (state[i].mother1() == 1) inP = i;
5988  if (state[i].mother1() == 2) inM = i;
5989  }
5990 
5991  // Save mother id
5992  int idMother = mother->state[iInMother].id();
5993  // Find daughter position and id
5994  int iDau = (side == 1) ? inP : inM;
5995  int idDaughter = state[iDau].id();
5996  // Get mother x value
5997  double xMother = 2. * mother->state[iInMother].e() / mother->state[0].e();
5998  // Get daughter x value of daughter
5999  double xDaughter = 2.*state[iDau].e() / state[0].e(); // x1 before isr
6000 
6001  // Calculate pdf ratio
6002  double ratio = getPDFratio(side, true, false, idMother, xMother, scale,
6003  idDaughter, xDaughter, scale);
6004 
6005  // For FSR with incoming recoiler, maximally return 1.0, as
6006  // is done in Pythia::TimeShower.
6007  // For ISR, return ratio
6008  return ( (FSRinRec)? min(1.,ratio) : ratio);
6009 }
6010 
6011 //--------------------------------------------------------------------------
6012 
6013 // Calculate the hard process matrix element to include in the selection
6014 // probability.
6015 
6016 double History::hardProcessME( const Event& event ) {
6017 
6018  // Calculate prob for Drell-Yan process.
6019  if (isEW2to1(event)) {
6020 
6021  // qqbar -> W.
6022  if (event[5].idAbs() == 24) {
6023  int idIn1 = event[3].id();
6024  int idIn2 = event[4].id();
6025  double mW = particleDataPtr->m0(24);
6026  double gW = particleDataPtr->mWidth(24) / mW;
6027  double sH = (event[3].p()+event[4].p()).m2Calc();
6028 
6029  double thetaWRat = 1. / (12. * coupSMPtr->sin2thetaW());
6030  double ckmW = coupSMPtr->V2CKMid(abs(idIn1), abs(idIn2));
6031 
6032  double bwW = 12. * M_PI / ( pow2(sH - pow2(mW)) + pow2(sH * gW) );
6033  double preFac = thetaWRat * sqrt(sH) * particleDataPtr->mWidth(24);
6034  return ckmW * preFac * bwW;
6035  }
6036  // qqbar -> Z. No interference with gamma included.
6037  else if (event[5].idAbs() == 23) {
6038  double mZ = particleDataPtr->m0(23);
6039  double gZ = particleDataPtr->mWidth(23) / mZ;
6040  double sH = (event[3].p()+event[4].p()).m2Calc();
6041 
6042  double thetaZRat = (pow2(coupSMPtr->rf( abs(clusterIn.flavRadBef))) +
6043  pow2(coupSMPtr->lf( abs(clusterIn.flavRadBef)))) /
6044  (24. * coupSMPtr->sin2thetaW() * coupSMPtr->cos2thetaW());
6045  double bwW = 12. * M_PI / ( pow2(sH - pow2(mZ)) + pow2(sH * gZ) );
6046  double preFac = thetaZRat * sqrt(sH) * particleDataPtr->mWidth(23);
6047  return preFac * bwW;
6048  }
6049  else {
6050  string message="Warning in History::hardProcessME: Only Z/W are";
6051  message+=" supported as 2->1 processes. Skipping history.";
6052  infoPtr->errorMsg(message);
6053  return 0;
6054  }
6055  }
6056  // 2 to 2 process, assume QCD.
6057  else if (isQCD2to2(event)) {
6058  int idIn1 = event[3].id();
6059  int idIn2 = event[4].id();
6060  int idOut1 = event[5].id();
6061  int idOut2 = event[6].id();
6062 
6063  double sH = (event[3].p()+event[4].p()).m2Calc();
6064  double tH = (event[3].p()-event[5].p()).m2Calc();
6065  double uH = (event[3].p()-event[6].p()).m2Calc();
6066 
6067  // Verify that it is QCD.
6068  bool isQCD = true;
6069  if (!(abs(idIn1) < 10 || abs(idIn1) == 21) ) isQCD = false;
6070  if (!(abs(idIn2) < 10 || abs(idIn2) == 21) ) isQCD = false;
6071  if (!(abs(idOut1) < 10 || abs(idOut1) == 21) ) isQCD = false;
6072  if (!(abs(idOut2) < 10 || abs(idOut2) == 21) ) isQCD = false;
6073 
6074  // Overall phase-space constant (dsigma/dcos(theta)).
6075  double cor = M_PI / (9. * pow2(sH));
6076 
6077  // If it is QCD calculate cross section.
6078  if (isQCD) {
6079  // Find out which 2->2 process it is.
6080 
6081  // incoming gluon pair.
6082  if (abs(idIn1) == 21 && abs(idIn2) == 21) {
6083  if (abs(idOut1) == 21 && abs(idOut2) == 21)
6084  return cor * simpleWeakShowerMEs.getMEgg2gg(sH, tH, uH);
6085  else return cor * simpleWeakShowerMEs.getMEgg2qqbar(sH, tH, uH);
6086 
6087  // Incoming single gluon
6088  } else if (abs(idIn1) == 21 || abs(idIn2) == 21) {
6089  if (idIn1 != idOut1) swap(uH, tH);
6090  return cor * simpleWeakShowerMEs.getMEqg2qg(sH, tH, uH);
6091  }
6092 
6093  // Incoming quarks
6094  else {
6095  if (abs(idOut1) == 21 && abs(idOut2) == 21)
6096  return cor * simpleWeakShowerMEs.getMEqqbar2gg(sH, tH, uH);
6097  if (idIn1 == -idIn2) {
6098  if (abs(idIn1) == abs(idOut1)) {
6099  if (idIn1 != idOut1) swap(uH, tH);
6100  return cor * simpleWeakShowerMEs.getMEqqbar2qqbar(sH,tH,uH,true);
6101  }
6102  else {
6103  return cor * simpleWeakShowerMEs.getMEqqbar2qqbar(sH,tH,uH,false);
6104  }
6105  }
6106  else if (idIn1 == idIn2)
6107  return cor * simpleWeakShowerMEs.getMEqq2qq(sH, tH, uH, true);
6108  else {
6109  if (idIn1 == idOut1) swap(uH,tH);
6110  return cor * simpleWeakShowerMEs.getMEqq2qq(sH, tH, uH, false);
6111  }
6112  }
6113  }
6114  }
6115 
6116 
6117  // Get hard process.
6118  string process = mergingHooksPtr->getProcessString();
6119  double result = 1.;
6120 
6121  if ( process.compare("pp>e+ve") == 0
6122  || process.compare("pp>e-ve~") == 0
6123  || process.compare("pp>LEPTONS,NEUTRINOS") == 0 ) {
6124  // Do nothing for incomplete process.
6125  int nFinal = 0;
6126  for ( int i=0; i < int(event.size()); ++i )
6127  if ( event[i].isFinal() ) nFinal++;
6128  if ( nFinal != 2 ) return 1.;
6129  // Get W-boson mass and width.
6130  double mW = particleDataPtr->m0(24);
6131  double gW = particleDataPtr->mWidth(24) / mW;
6132  // Get incoming particles.
6133  int inP = (event[3].pz() > 0) ? 3 : 4;
6134  int inM = (event[3].pz() > 0) ? 4 : 3;
6135  // Get outgoing particles.
6136  int outP = 0;
6137  for ( int i=0; i < int(event.size()); ++i ) {
6138  if ( event[i].isFinal() && event[i].px() > 0 ) outP = i;
6139  }
6140  // Get Mandelstam variables.
6141  double sH = (event[inP].p() + event[inM].p()).m2Calc();
6142  double tH = (event[inP].p() - event[outP].p()).m2Calc();
6143  double uH = - sH - tH;
6144 
6145  // Return kinematic part of matrix element.
6146  result = ( 1. + (tH - uH)/sH ) / ( pow2(sH - mW*mW) + pow2(sH*gW) );
6147  } else
6148  result = mergingHooksPtr->hardProcessME(event);
6149 
6150  return result;
6151 
6152 }
6153 
6154 //--------------------------------------------------------------------------
6155 
6156 // Perform the clustering of the current state and return the
6157 // clustered state.
6158 // IN Clustering : rad,rec,emt triple to be clustered to two partons
6159 // OUT clustered state
6160 
6161 Event History::cluster( Clustering & inSystem ) {
6162 
6163  // Initialise tags of particles to be changed
6164  int Rad = inSystem.emittor;
6165  int Rec = inSystem.recoiler;
6166  int Emt = inSystem.emitted;
6167  // Initialise eCM,mHat
6168  double eCM = state[0].e();
6169  // Flags for type of radiation
6170  int radType = state[Rad].isFinal() ? 1 : -1;
6171  int recType = state[Rec].isFinal() ? 1 : -1;
6172 
6173  // Construct the clustered event
6174  Event NewEvent = Event();
6175  NewEvent.init("(hard process-modified)", particleDataPtr);
6176  NewEvent.clear();
6177 
6178  // Check if external clustering should be used.
6179  if ( mergingHooksPtr->useShowerPlugin() ) {
6180  int iPartner = (radType == -1 && inSystem.partner > 0)
6181  ? inSystem.partner : Rec;
6182  bool isFSR = showers->timesPtr->isTimelike(state, Rad, Emt, iPartner, "");
6183  if (isFSR) {
6184  string name = showers->timesPtr->getSplittingName(state,Rad,Emt,
6185  iPartner).front();
6186  return showers->timesPtr->clustered(state,Rad,Emt,iPartner,name);
6187  } else {
6188  string name = showers->spacePtr->getSplittingName(state,Rad,Emt,
6189  iPartner).front();
6190  return showers->spacePtr->clustered(state,Rad,Emt,iPartner,name);
6191  }
6192  }
6193 
6194  // Copy all unchanged particles to NewEvent
6195  for (int i = 0; i < state.size(); ++i)
6196  if ( i != Rad && i != Rec && i != Emt )
6197  NewEvent.append( state[i] );
6198 
6199  // Copy all the junctions one by one
6200  for (int i = 0; i < state.sizeJunction(); ++i)
6201  NewEvent.appendJunction( state.getJunction(i) );
6202  // Find an appropriate scale for the hard process
6203  double mu = choseHardScale(state);
6204  // Initialise scales for new event
6205  NewEvent.saveSize();
6206  NewEvent.saveJunctionSize();
6207  NewEvent.scale(mu);
6208  NewEvent.scaleSecond(mu);
6209 
6210  // Set properties of radiator/recoiler after the clustering
6211  // Recoiler properties will be unchanged
6212  Particle RecBefore = Particle( state[Rec] );
6213  RecBefore.setEvtPtr(&NewEvent);
6214  RecBefore.daughters(0,0);
6215  RecBefore.pol(inSystem.spinRec);
6216  // Find flavour of radiator before splitting
6217  int radID = inSystem.flavRadBef;
6218  if (radID == 0) radID = getRadBeforeFlav(Rad, Emt, state);
6219  int recID = state[Rec].id();
6220  Particle RadBefore = Particle( state[Rad] );
6221  RadBefore.setEvtPtr(&NewEvent);
6222  RadBefore.id(radID);
6223  RadBefore.pol(inSystem.spinRadBef);
6224  RadBefore.daughters(0,0);
6225  // Put dummy values for colours
6226  RadBefore.cols(RecBefore.acol(),RecBefore.col());
6227 
6228  // Reset status if the reclustered radiator is a resonance.
6229  if ( particleDataPtr->isResonance(radID) && radType == 1)
6230  RadBefore.status(state[Rad].status());
6231 
6232  // Put mass for radiator and recoiler
6233  double radMass = particleDataPtr->m0(radID);
6234  double recMass = particleDataPtr->m0(recID);
6235  if (radType == 1 ) RadBefore.m(radMass);
6236  else RadBefore.m(0.0);
6237  if (recType == 1 ) RecBefore.m(recMass);
6238  else RecBefore.m(0.0);
6239 
6240  // Construct momenta and colours of clustered particles
6241  // ISR/FSR splittings are treated differently
6242  if ( radType + recType == 2 && state[Emt].idAbs() != 23 &&
6243  state[Emt].idAbs() != 24) {
6244  // Clustering of final(rad)/final(rec) dipole splitting
6245  // Get eCM of (rad,rec,emt) triple
6246  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
6247  double eCMME = sum.mCalc();
6248 
6249  // Define radiator and recoiler back-to-back in the dipole
6250  // rest frame [=(state[rad]+state[emt])+state[rec] rest frame]
6251  Vec4 Rad4mom;
6252  Vec4 Rec4mom;
6253  double mDsq = pow2(eCMME);
6254  // If possible, keep the invariant mass of the radiator.
6255  double mRsq = (radID == state[Rad].id() )
6256  ? abs(state[Rad].p().m2Calc())
6257  : pow2(particleDataPtr->m0(radID));
6258  double mSsq = abs(state[Rec].p().m2Calc());
6259  double a = 0.5*sqrt(mDsq);
6260  double b = 0.25*(mRsq - mSsq) / a;
6261  double c = sqrt(pow2(a) + pow2(b) - 2.*a*b - mSsq);
6262 
6263  Rad4mom.p( 0., 0., c, a+b);
6264  Rec4mom.p( 0., 0.,-c, a-b);
6265 
6266  // Find boost from Rad4mom+Rec4mom rest frame to event cm frame
6267  Vec4 old1 = Vec4(state[Rad].p() + state[Emt].p());
6268  Vec4 old2 = Vec4(state[Rec].p());
6269  RotBstMatrix fromCM;
6270  fromCM.fromCMframe(old1, old2);
6271  // Transform momenta
6272  Rad4mom.rotbst(fromCM);
6273  Rec4mom.rotbst(fromCM);
6274 
6275  RadBefore.p(Rad4mom);
6276  RecBefore.p(Rec4mom);
6277  RadBefore.m(sqrt(mRsq));
6278  RecBefore.m(sqrt(mSsq));
6279 
6280  } else if ( radType + recType == 2 && (state[Emt].idAbs() == 23 ||
6281  state[Emt].idAbs() == 24) ) {
6282  // Clustering of final(rad)/final(rec) dipole splitting
6283  // Get eCM of (rad,rec,emt) triple
6284  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
6285  double eCMME = sum.mCalc();
6286 
6287  // Define radiator and recoiler back-to-back in the dipole
6288  // rest frame [=(state[rad]+state[emt])+state[rec] rest frame]
6289  Vec4 Rad4mom;
6290  Vec4 Rec4mom;
6291  double mDsq = pow2(eCMME);
6292  // If possible, keep the invariant mass of the radiator.
6293  double mRsq = (radID == state[Rad].id() )
6294  ? abs(state[Rad].p().m2Calc())
6295  : pow2(particleDataPtr->m0(radID));
6296  double mSsq = abs(state[Rec].p().m2Calc());
6297  double a = 0.5*sqrt(mDsq);
6298  double b = 0.25*(mRsq - mSsq) / a;
6299  double c = sqrt(pow2(a) + pow2(b) - 2.*a*b - mSsq);
6300 
6301  Rad4mom.p( 0., 0., c, a+b);
6302  Rec4mom.p( 0., 0.,-c, a-b);
6303 
6304  // Find boost from Rad4mom+Rec4mom rest frame to event cm frame
6305  Vec4 old1 = Vec4(state[Rad].p() + state[Emt].p());
6306  Vec4 old2 = Vec4(state[Rec].p());
6307  RotBstMatrix fromCM;
6308  fromCM.fromCMframe(old1, old2);
6309  // Transform momenta
6310  Rad4mom.rotbst(fromCM);
6311  Rec4mom.rotbst(fromCM);
6312 
6313  RadBefore.p(Rad4mom);
6314  RecBefore.p(Rec4mom);
6315  RadBefore.m(sqrt(mRsq));
6316  RecBefore.m(sqrt(mSsq));
6317 
6318  } else if ( radType + recType == 0 ) {
6319 
6320  // Clustering of final(rad)/initial(rec) dipole splitting
6321  // Get eCM of (rad,rec,emt) triple
6322  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
6323  double eCMME = sum.mCalc();
6324  // Define radiator and recoiler back-to-back in the dipole
6325  // rest frame [=(state[rad]+state[emt])+state[rec] rest frame]
6326  Vec4 Rad4mom;
6327  Vec4 Rec4mom;
6328  double mDsq = pow2(eCMME);
6329  // If possible, keep the invariant mass of the radiator.
6330  double mRsq = (radID == state[Rad].id() )
6331  ? abs(state[Rad].p().m2Calc())
6332  : pow2(particleDataPtr->m0(radID));
6333  double mSsq = abs(state[Rec].p().m2Calc());
6334  double a = 0.5*sqrt(mDsq);
6335  double b = 0.25*(mRsq - mSsq) / a;
6336  double c = sqrt(pow2(a) + pow2(b) - 2.*a*b - mSsq);
6337 
6338  Rad4mom.p( 0., 0., c, a+b);
6339  Rec4mom.p( 0., 0.,-c, a-b);
6340 
6341  // Find boost from Rad4mom+Rec4mom rest frame to event cm frame
6342  Vec4 old1 = Vec4(state[Rad].p() + state[Emt].p());
6343  Vec4 old2 = Vec4(state[Rec].p());
6344  RotBstMatrix fromCM;
6345  fromCM.fromCMframe(old1, old2);
6346  // Transform momenta
6347  Rad4mom.rotbst(fromCM);
6348  Rec4mom.rotbst(fromCM);
6349 
6350  // Rescale recoiler momentum
6351  Rec4mom = 2.*state[Rec].p() - Rec4mom;
6352 
6353  // Ensure that recoiler is massless to
6354  // very good accuracy.
6355  if ( abs(Rec4mom.mCalc()) > 1e-7 ) {
6356  double pzSign = (Rec4mom.pz() > 0.) ? 1. : -1.;
6357  double eRec = Rec4mom.e();
6358  Rec4mom.p(0., 0., pzSign*eRec, eRec);
6359  }
6360 
6361  RadBefore.p(Rad4mom);
6362  RecBefore.p(Rec4mom);
6363  RadBefore.m(sqrt(mRsq));
6364 
6365  // Set mass of initial recoiler to zero
6366  RecBefore.m( 0.0 );
6367 
6368  } else {
6369 
6370  // Clustering of initial(rad)/initial(rec) dipole splitting
6371  // We want to cluster: Meaning doing the inverse of a process
6372  // ( pDaughter + pRecoiler -> pOut )
6373  // ==> ( pMother + pPartner -> pOut' + pSister )
6374  // produced by an initial state splitting. The matrix element
6375  // provides us with pMother, pPartner, pSister and pOut'
6376  Vec4 pMother( state[Rad].p() );
6377  Vec4 pSister( state[Emt].p() );
6378  Vec4 pPartner( state[Rec].p() );
6379  Vec4 pDaughterBef( 0.,0.,0.,0. );
6380  Vec4 pRecoilerBef( 0.,0.,0.,0. );
6381  Vec4 pDaughter( 0.,0.,0.,0. );
6382  Vec4 pRecoiler( 0.,0.,0.,0. );
6383 
6384  // Find side that radiates event (mother moving in sign * p_z direction).
6385  int sign = (state[Rad].pz() > 0.) ? 1 : -1;
6386 
6387  // Find rotation by phi that would have been done for a
6388  // splitting daughter -> mother + sister
6389  double phi = pSister.phi();
6390  // Find rotation with -phi
6391  RotBstMatrix rot_by_mphi;
6392  rot_by_mphi.rot(0.,-phi);
6393  // Find rotation with +phi
6394  RotBstMatrix rot_by_pphi;
6395  rot_by_pphi.rot(0.,phi);
6396 
6397  // Get mother and partner x values
6398  // x1 after isr
6399  double x1 = 2. * pMother.e() / eCM;
6400  // x2 after isr
6401  double x2 = 2. * pPartner.e() / eCM;
6402 
6403  // Find z of the splitting
6404  Vec4 qDip( pMother - pSister);
6405  Vec4 qAfter(pMother + pPartner);
6406  Vec4 qBefore(qDip + pPartner);
6407  double z = qBefore.m2Calc() / qAfter.m2Calc();
6408 
6409  // Calculate e_CM^2 before the splitting.
6410  double x1New = z*x1; // x1 before isr
6411  double x2New = x2; // x2 before isr
6412  double sHat = x1New*x2New*eCM*eCM;
6413 
6414  // Construct daughter and recoiler momenta before the splitting.
6415  // (Note: For final result, only needs to be boosted into
6416  // frame with unchanged "recoiler" momentum)
6417  pDaughterBef.p( 0., 0., sign*0.5*sqrt(sHat), 0.5*sqrt(sHat));
6418  pRecoilerBef.p( 0., 0., -sign*0.5*sqrt(sHat), 0.5*sqrt(sHat));
6419 
6420  // Rotate momenta defined in the lab frame by phi
6421  pMother.rotbst( rot_by_mphi );
6422  pSister.rotbst( rot_by_mphi );
6423  pPartner.rotbst( rot_by_mphi );
6424  for(int i=3; i< NewEvent.size(); ++i)
6425  NewEvent[i].rotbst( rot_by_mphi );
6426 
6427  // Find boost from lab frame to rest frame of
6428  // off-shell daughter + on-shell recoiler dipole
6429  pDaughter.p( pMother - pSister);
6430  pRecoiler.p( pPartner );
6431  RotBstMatrix from_CM_to_DRoff;
6432  if (sign == 1)
6433  from_CM_to_DRoff.toCMframe(pDaughter, pRecoiler);
6434  else
6435  from_CM_to_DRoff.toCMframe(pRecoiler, pDaughter);
6436 
6437  // Rotate and boost all momenta to rest frame of off-shell daughter +
6438  // on-shell recoiler dipole
6439  pMother.rotbst( from_CM_to_DRoff );
6440  pPartner.rotbst( from_CM_to_DRoff );
6441  pSister.rotbst( from_CM_to_DRoff );
6442  for(int i=3; i< NewEvent.size(); ++i)
6443  NewEvent[i].rotbst( from_CM_to_DRoff );
6444 
6445  // Find longitudinal boost from on-shell daughter + on-shell recoiler
6446  // dipole rest frame to the frame in which the recoiler momentum (x-value)
6447  // does not change in the splitting process.
6448  RotBstMatrix from_DR_to_CM;
6449  from_DR_to_CM.bst( 0., 0., sign*( x1New - x2New ) / ( x1New + x2New ) );
6450 
6451  // Boost all momenta into the "unchanged recoiler" frame, thereby
6452  // correcting for momentum mismatch by transferring the recoil to all
6453  // final state particles.
6454  pDaughterBef.rotbst( from_DR_to_CM );
6455  pRecoilerBef.rotbst( from_DR_to_CM );
6456  for(int i=3; i< NewEvent.size(); ++i)
6457  NewEvent[i].rotbst( from_DR_to_CM );
6458 
6459  // Transform outgoing momenta
6460  for(int i=3; i< NewEvent.size(); ++i)
6461  NewEvent[i].rotbst( rot_by_pphi );
6462 
6463  // Ensure that radiator and recoiler are massless to
6464  // very good accuracy.
6465  if ( abs(pRecoilerBef.mCalc()) > 1e-7 ) {
6466  double pzSign = (pRecoilerBef.pz() > 0.) ? 1. : -1.;
6467  double eRec = pRecoilerBef.e();
6468  pRecoilerBef.p(0., 0., pzSign*eRec, eRec);
6469  }
6470  if ( abs(pDaughterBef.mCalc()) > 1e-7 ) {
6471  double pzSign = (pDaughterBef.pz() > 0.) ? 1. : -1.;
6472  double eDau = pDaughterBef.e();
6473  pDaughterBef.p(0., 0., pzSign*eDau, eDau);
6474  }
6475  // Transform pMother and outgoing momenta
6476  // Set momenta of particles to be attached to new event record
6477  RecBefore.p( pRecoilerBef );
6478  RadBefore.p( pDaughterBef );
6479  if (RecBefore.pz() > 0.) RecBefore.mother1(1);
6480  else RecBefore.mother1(2);
6481  if (RadBefore.pz() > 0.) RadBefore.mother1(1);
6482  else RadBefore.mother1(2);
6483 
6484  }
6485 
6486  // Put some dummy production scales for RecBefore, RadBefore
6487  RecBefore.scale(mu);
6488  RadBefore.scale(mu);
6489 
6490  // Append new recoiler and find new radiator colour
6491  NewEvent.append(RecBefore);
6492 
6493  // Assign the correct colour to re-clustered radiator.
6494  // Keep old radiator colours for electroweak emission.
6495  int emtID = state[Emt].id();
6496  if ( emtID == 22 || emtID == 23 || abs(emtID) == 24 )
6497  RadBefore.cols( state[Rad].col(), state[Rad].acol() );
6498  // For QCD, carefully construct colour.
6499  else if ( !connectRadiator( RadBefore, radType, RecBefore, recType,
6500  NewEvent ) ) {
6501  // Could happen if previous clustering produced several colour
6502  // singlett subsystems in the event
6503  NewEvent.reset();
6504  return NewEvent;
6505  }
6506 
6507  // Build the clustered event
6508  Event outState = Event();
6509  outState.init("(hard process-modified)", particleDataPtr);
6510  outState.clear();
6511 
6512  // Copy system and incoming beam particles to outState
6513  for (int i = 0; i < 3; ++i)
6514  outState.append( NewEvent[i] );
6515  // Copy all the junctions one by one
6516  for (int i = 0; i < state.sizeJunction(); ++i)
6517  outState.appendJunction( state.getJunction(i) );
6518  // Initialise scales for new event
6519  outState.saveSize();
6520  outState.saveJunctionSize();
6521  outState.scale(mu);
6522  outState.scaleSecond(mu);
6523  bool radAppended = false;
6524  bool recAppended = false;
6525  int size = int(outState.size());
6526  // Save position of radiator and recoiler in new event record.
6527  int radPos = 0, recPos = 0;
6528 
6529  // Append first incoming particle
6530  if ( RecBefore.mother1() == 1) {
6531  recPos = outState.append( RecBefore );
6532  recAppended = true;
6533  } else if ( RadBefore.mother1() == 1 ) {
6534  radPos = outState.append( RadBefore );
6535  radAppended = true;
6536  } else {
6537  // Find second incoming in input event
6538  int in1 = 0;
6539  for(int i=0; i < int(state.size()); ++i)
6540  if (state[i].mother1() == 1) in1 =i;
6541  outState.append( state[in1] );
6542  size++;
6543  }
6544  // Append second incoming particle
6545  if ( RecBefore.mother1() == 2) {
6546  recPos = outState.append( RecBefore );
6547  recAppended = true;
6548  } else if ( RadBefore.mother1() == 2 ) {
6549  radPos = outState.append( RadBefore );
6550  radAppended = true;
6551  } else {
6552  // Find second incoming in input event
6553  int in2 = 0;
6554  for(int i=0; i < int(state.size()); ++i)
6555  if (state[i].mother1() == 2) in2 =i;
6556 
6557  outState.append( state[in2] );
6558  size++;
6559  }
6560 
6561  // Append new recoiler if not done already
6562  if (!recAppended && !RecBefore.isFinal()) {
6563  recAppended = true;
6564  recPos = outState.append( RecBefore);
6565  }
6566  // Append new radiator if not done already
6567  if (!radAppended && !RadBefore.isFinal()) {
6568  radAppended = true;
6569  radPos = outState.append( RadBefore);
6570  }
6571 
6572  // Append intermediate particle
6573  // (careful not to append reclustered recoiler)
6574  // Append intermediate particle
6575  // (careful not to append reclustered recoiler)
6576  for (int i = 0; i < int(NewEvent.size()-1); ++i)
6577  if (NewEvent[i].status() == -22) outState.append( NewEvent[i] );
6578  // Append final state particles, resonances first
6579  for (int i = 0; i < int(NewEvent.size()-1); ++i)
6580  if (NewEvent[i].status() == 22) outState.append( NewEvent[i] );
6581  // Then start appending partons
6582  if (!radAppended && RadBefore.statusAbs() == 22)
6583  radPos = outState.append(RadBefore);
6584  if (!recAppended)
6585  recPos = outState.append(RecBefore);
6586  if (!radAppended && RadBefore.statusAbs() != 22)
6587  radPos = outState.append(RadBefore);
6588  // Then partons (not reclustered recoiler)
6589  for(int i = 0; i < int(NewEvent.size()-1); ++i)
6590  if ( NewEvent[i].status() != 22
6591  && NewEvent[i].colType() != 0
6592  && NewEvent[i].isFinal())
6593  outState.append( NewEvent[i] );
6594  // Then the rest
6595  for(int i = 0; i < int(NewEvent.size()-1); ++i)
6596  if ( NewEvent[i].status() != 22
6597  && NewEvent[i].colType() == 0
6598  && NewEvent[i].isFinal() )
6599  outState.append( NewEvent[i]);
6600 
6601  // Find intermediate and respective daughters
6602  vector<int> posIntermediate;
6603  vector<int> posDaughter1;
6604  vector<int> posDaughter2;
6605  for(int i=0; i < int(outState.size()); ++i)
6606  if (outState[i].status() == -22) {
6607  posIntermediate.push_back(i);
6608  int d1 = outState[i].daughter1();
6609  int d2 = outState[i].daughter2();
6610  // Find daughters in output state
6611  int daughter1 = FindParticle( state[d1], outState);
6612  int daughter2 = FindParticle( state[d2], outState);
6613  // If both daughters found, done
6614  // Else put first final particle as first daughter
6615  // and last final particle as second daughter
6616  if (daughter1 > 0)
6617  posDaughter1.push_back( daughter1);
6618  else {
6619  daughter1 = 0;
6620  while(!outState[daughter1].isFinal() ) daughter1++;
6621  posDaughter1.push_back( daughter1);
6622  }
6623  if (daughter2 > 0)
6624  posDaughter2.push_back( daughter2);
6625  else {
6626  daughter2 = outState.size()-1;
6627  while(!outState[daughter2].isFinal() ) daughter2--;
6628  posDaughter2.push_back( daughter2);
6629  }
6630  }
6631  // Set daughters and mothers
6632  for(int i=0; i < int(posIntermediate.size()); ++i) {
6633  outState[posIntermediate[i]].daughters(posDaughter1[i],posDaughter2[i]);
6634  outState[posDaughter1[i]].mother1(posIntermediate[i]);
6635  outState[posDaughter2[i]].mother1(posIntermediate[i]);
6636  }
6637 
6638  // Find range of final state partons
6639  int minParFinal = int(outState.size());
6640  int maxParFinal = 0;
6641  for(int i=0; i < int(outState.size()); ++i)
6642  if (outState[i].mother1() == 3 && outState[i].mother2() == 4) {
6643  minParFinal = min(i,minParFinal);
6644  maxParFinal = max(i,maxParFinal);
6645  }
6646 
6647  if (minParFinal == maxParFinal) maxParFinal = 0;
6648  outState[3].daughters(minParFinal,maxParFinal);
6649  outState[4].daughters(minParFinal,maxParFinal);
6650 
6651  // Update event properties
6652  outState.saveSize();
6653  outState.saveJunctionSize();
6654 
6655  // Store radiator and recoiler positions.
6656  inSystem.recBef = recPos;
6657  inSystem.radBef = radPos;
6658 
6659  // Almost there...
6660  // If an intermediate coloured parton exists which was directly
6661  // colour connected to the radiator before the splitting, and the
6662  // radiator before and after the splitting had only one colour, problems
6663  // will arise since the colour of the radiator will be changed, whereas
6664  // the intermediate parton still has the old colour. In effect, this
6665  // means that when setting up a event for trial showering, one colour will
6666  // be free.
6667  // Hence, check for an intermediate coloured triplet resonance has been
6668  // colour-connected to the "old" radiator.
6669  // Find resonance
6670  int iColRes = 0;
6671  if ( radType == -1 && state[Rad].colType() == 1) {
6672  // Find resonance connected to initial colour
6673  for(int i=0; i < int(state.size()); ++i)
6674  if ( i != Rad && i != Emt && i != Rec
6675  && state[i].status() == -22
6676  && state[i].col() == state[Rad].col() )
6677  iColRes = i;
6678  } else if ( radType == -1 && state[Rad].colType() == -1) {
6679  // Find resonance connected to initial anticolour
6680  for(int i=0; i < int(state.size()); ++i)
6681  if ( i != Rad && i != Emt && i != Rec
6682  && state[i].status() == -22
6683  && state[i].acol() == state[Rad].acol() )
6684  iColRes = i;
6685  } else if ( radType == 1 && state[Rad].colType() == 1) {
6686  // Find resonance connected to final state colour
6687  for(int i=0; i < int(state.size()); ++i)
6688  if ( i != Rad && i != Emt && i != Rec
6689  && state[i].status() == -22
6690  && state[i].col() == state[Rad].col() )
6691  iColRes = i;
6692  } else if ( radType == 1 && state[Rad].colType() == -1) {
6693  // Find resonance connected to final state anticolour
6694  for(int i=0; i < int(state.size()); ++i)
6695  if ( i != Rad && i != Emt && i != Rec
6696  && state[i].status() == -22
6697  && state[i].acol() == state[Rad].acol() )
6698  iColRes = i;
6699  }
6700 
6701  if (iColRes > 0) {
6702  // Now find this resonance in the reclustered state
6703  int iColResNow = FindParticle( state[iColRes], outState);
6704 
6705  // Find reclustered radiator colours
6706  int radCol = outState[radPos].col();
6707  int radAcl = outState[radPos].acol();
6708  // Find resonance radiator colours
6709  int resCol = outState[iColResNow].col();
6710  int resAcl = outState[iColResNow].acol();
6711  // Check if any of the reclustered radiators colours match the resonance
6712  bool matchesRes = (radCol > 0
6713  && ( radCol == resCol || radCol == resAcl))
6714  || (radAcl > 0
6715  && ( radAcl == resCol || radAcl == resAcl));
6716 
6717  // If a resonance has been found, but no colours match, change
6718  // the colour of the resonance
6719  if (!matchesRes && iColResNow > 0) {
6720  if ( radType == -1 && outState[radPos].colType() == 1)
6721  outState[iColResNow].col(radCol);
6722  else if ( radType ==-1 && outState[radPos].colType() ==-1)
6723  outState[iColResNow].acol(radAcl);
6724  else if ( radType == 1 && outState[radPos].colType() == 1)
6725  outState[iColResNow].col(radCol);
6726  else if ( radType == 1 && outState[radPos].colType() ==-1)
6727  outState[iColResNow].acol(radAcl);
6728  }
6729 
6730 
6731  // If a resonance has been found, but no colours match, and the position
6732  // of the resonance in the event record has been changed, update the
6733  // radiator mother
6734  if (!matchesRes && iColResNow > 0 && iColRes != iColResNow)
6735  outState[radPos].mother1(iColResNow);
6736 
6737  }
6738 
6739  // If event is not constructed properly, return false
6740  if ( !validEvent(outState) ) {
6741  // Set momenta of particles to be attached to new event record
6742  outState.reset();
6743  return outState;
6744  }
6745 
6746  // Remember position of reclustered radiator in state
6747  iReclusteredNew = radPos;
6748 
6749  // Done
6750  return outState;
6751 }
6752 
6753 //--------------------------------------------------------------------------
6754 
6755 // Function to get the flavour of the radiator before the splitting
6756 // for clustering
6757 // IN int : Flavour of the radiator after the splitting
6758 // int : Flavour of the emitted after the splitting
6759 // OUT int : Flavour of the radiator before the splitting
6760 
6761 int History::getRadBeforeFlav(const int RadAfter, const int EmtAfter,
6762  const Event& event) {
6763 
6764  int type = event[RadAfter].isFinal() ? 1 :-1;
6765  int emtID = event[EmtAfter].id();
6766  int radID = event[RadAfter].id();
6767  int emtCOL = event[EmtAfter].col();
6768  int radCOL = event[RadAfter].col();
6769  int emtACL = event[EmtAfter].acol();
6770  int radACL = event[RadAfter].acol();
6771 
6772  bool colConnected = ((type == 1) && ( (emtCOL !=0 && (emtCOL ==radACL))
6773  || (emtACL !=0 && (emtACL ==radCOL)) ))
6774  ||((type ==-1) && ( (emtCOL !=0 && (emtCOL ==radCOL))
6775  || (emtACL !=0 && (emtACL ==radACL)) ));
6776  // QCD splittings
6777  // Gluon radiation
6778  if ( emtID == 21 )
6779  return radID;
6780  // Final state gluon splitting
6781  if ( type == 1 && emtID == -radID && !colConnected )
6782  return 21;
6783  // Initial state s-channel gluon splitting
6784  if ( type ==-1 && radID == 21 )
6785  return -emtID;
6786  // Initial state t-channel gluon splitting
6787  if ( type ==-1 && !colConnected
6788  && radID != 21 && abs(emtID) < 10 && abs(radID) < 10)
6789  return 21;
6790 
6791  // SQCD splittings
6792  int radSign = (radID < 0) ? -1 : 1;
6793  int offsetL = 1000000;
6794  int offsetR = 2000000;
6795  // Gluino radiation
6796  if ( emtID == 1000021 ) {
6797  // Gluino radiation combined with quark yields squark.
6798  if (abs(radID) < 10 ) {
6799  int offset = offsetL;
6800  // Check if righthanded squark present. If so, make the reclustered
6801  // squark match. Works for squark pair production + gluino emission.
6802  for (int i=0; i < int(event.size()); ++i)
6803  if ( event[i].isFinal()
6804  && event[i].idAbs() < offsetR+10 && event[i].idAbs() > offsetR)
6805  offset = offsetR;
6806  return radSign*(abs(radID)+offset);
6807  }
6808  // Gluino radiation combined with squark yields quark.
6809  if (abs(radID) > offsetL && abs(radID) < offsetL+10 )
6810  return radSign*(abs(radID)-offsetL);
6811  if (abs(radID) > offsetR && abs(radID) < offsetR+10 )
6812  return radSign*(abs(radID)-offsetR);
6813  // Gluino radiation off gluon yields gluino.
6814  if (radID == 21 ) return emtID;
6815  }
6816 
6817  int emtSign = (emtID < 0) ? -1 : 1;
6818  // Get PDG numbering offsets.
6819  int emtOffset = 0;
6820  if ( abs(emtID) > offsetL && abs(emtID) < offsetL+10 )
6821  emtOffset = offsetL;
6822  if ( abs(emtID) > offsetR && abs(emtID) < offsetR+10 )
6823  emtOffset = offsetR;
6824  int radOffset = 0;
6825  if ( abs(radID) > offsetL && abs(radID) < offsetL+10 )
6826  radOffset = offsetL;
6827  if ( abs(radID) > offsetR && abs(radID) < offsetR+10 )
6828  radOffset = offsetR;
6829 
6830  // Final state gluino splitting
6831  if ( type == 1 && !colConnected ) {
6832  // Emitted squark, radiating quark.
6833  if ( emtOffset > 0 && radOffset == 0
6834  && emtSign*(abs(emtID) - emtOffset) == -radID )
6835  return 1000021;
6836  // Emitted quark, radiating squark.
6837  if ( emtOffset == 0 && radOffset > 0
6838  && emtID == -radSign*(abs(radID) - radOffset) )
6839  return 1000021;
6840  }
6841 
6842  // Initial state s-channel gluino splitting
6843  if ( type ==-1 && radID == 1000021 ) {
6844  // Quark entering underlying hard process.
6845  if ( emtOffset > 0 ) return -emtSign*(abs(emtID) - emtOffset);
6846  // Squark entering underlying hard process.
6847  else return -emtSign*(abs(emtID) + emtOffset);
6848  }
6849 
6850  // Initial state t-channel gluino splitting.
6851  if ( type ==-1
6852  && ( (abs(emtID) > offsetL && abs(emtID) < offsetL+10)
6853  || (abs(emtID) > offsetR && abs(emtID) < offsetR+10))
6854  && ( (abs(radID) > offsetL && abs(radID) < offsetL+10)
6855  || (abs(radID) > offsetR && abs(radID) < offsetR+10))
6856  && emtSign*(abs(emtID)+emtOffset) == radSign*(abs(radID) - radOffset)
6857  && !colConnected ) {
6858  return 1000021;
6859  }
6860 
6861  // Electroweak splittings splittings
6862  // Photon / Z radiation: Calculate invariant mass of system
6863  double m2final = (event[RadAfter].p()+ event[EmtAfter].p()).m2Calc();
6864 
6865  if ( emtID == 22 || emtID == 23 ) return radID;
6866  // Final state Photon splitting
6867  if ( type == 1 && emtID == -radID && colConnected && sqrt(m2final) <= 10. )
6868  return 22;
6869  // Final state Photon splitting
6870  if ( type == 1 && emtID == -radID && colConnected && sqrt(m2final) > 10. )
6871  return 23;
6872  // Initial state s-channel photon/ Z splitting
6873  if ( type ==-1 && (radID == 22 || radID == 23) )
6874  return -emtID;
6875  // Initial state t-channel photon / Z splitting: Always bookkeep as photon
6876  if ( type ==-1 && abs(emtID) < 10 && abs(radID) < 10 && colConnected )
6877  return 22;
6878 
6879  // W+ radiation
6880  // Final state W+ splitting
6881  if ( emtID == 24 && radID < 0 ) return radID + 1;
6882  if ( emtID == 24 && radID > 0 ) return radID + 1;
6883 
6884  // W- radiation
6885  // Final state W- splitting
6886  if ( emtID ==-24 && radID < 0 ) return radID - 1;
6887  if ( emtID ==-24 && radID > 0 ) return radID - 1;
6888 
6889  // Done.
6890  return 0;
6891 
6892 }
6893 
6894 //--------------------------------------------------------------------------
6895 
6896 // Function to get the spin of the radiator before the splitting
6897 // IN int : Spin of the radiator after the splitting
6898 // int : Spin of the emitted after the splitting
6899 // OUT int : Spin of the radiator before the splitting
6900 
6901 int History::getRadBeforeSpin(const int radAfter, const int emtAfter,
6902  const int spinRadAfter, const int spinEmtAfter,
6903  const Event& event) {
6904 
6905  // Get flavour before the splitting.
6906  int radBeforeFlav = getRadBeforeFlav(radAfter, emtAfter, event);
6907 
6908  // Gluon in final state g-> q qbar
6909  if ( event[radAfter].isFinal()
6910  && event[radAfter].id() == -event[emtAfter].id())
6911  return (spinRadAfter == 9) ? spinEmtAfter : spinRadAfter;
6912 
6913  // Quark in final state q -> q g
6914  if ( event[radAfter].isFinal() && abs(radBeforeFlav) < 10
6915  && event[radAfter].idAbs() < 10)
6916  // Special oddity: Gluon does not change spin.
6917  return spinRadAfter;
6918 
6919  // Quark in final state q -> g q
6920  if ( event[radAfter].isFinal() && abs(radBeforeFlav) < 10
6921  && event[emtAfter].idAbs() < 10)
6922  // Special oddity: Gluon does not change spin.
6923  return spinEmtAfter;
6924 
6925  // Gluon in final state g -> g g
6926  if ( event[radAfter].isFinal() && radBeforeFlav == 21
6927  && event[radAfter].id() == 21)
6928  // Special oddity: Gluon does not change spin.
6929  return (spinRadAfter == 9) ? spinEmtAfter : spinRadAfter;
6930 
6931  // Gluon in initial state g-> q qbar
6932  if ( !event[radAfter].isFinal()
6933  && radBeforeFlav == -event[emtAfter].id())
6934  return (spinRadAfter == 9) ? spinEmtAfter : spinRadAfter;
6935 
6936  // Quark in initial state q -> q g
6937  if ( !event[radAfter].isFinal() && abs(radBeforeFlav) < 10
6938  && event[radAfter].idAbs() < 10)
6939  // Special oddity: Gluon does not change spin.
6940  return spinRadAfter;
6941 
6942  // Gluon in initial state q -> g q
6943  if ( !event[radAfter].isFinal() && radBeforeFlav == 21
6944  && event[emtAfter].idAbs() < 10)
6945  // Special oddity: Gluon does not change spin.
6946  return spinEmtAfter;
6947 
6948  // Done. Return default value.
6949  return 9;
6950 
6951 }
6952 
6953 //--------------------------------------------------------------------------
6954 
6955 // Function to properly colour-connect the radiator to the rest of
6956 // the event, as needed during clustering
6957 // IN Particle& : Particle to be connected
6958 // Particle : Recoiler forming a dipole with Radiator
6959 // Event : event to which Radiator shall be appended
6960 // OUT true : Radiator could be connected to the event
6961 // false : Radiator could not be connected to the
6962 // event or the resulting event was
6963 // non-valid
6964 
6965 bool History::connectRadiator( Particle& Radiator, const int RadType,
6966  const Particle& Recoiler, const int RecType,
6967  const Event& event ) {
6968 
6969  // Start filling radiator colour indices with dummy values
6970  Radiator.cols( -1, -1 );
6971 
6972  // Radiator should always be colour-connected to recoiler.
6973  // Three cases (rad = Anti-Quark, Quark, Gluon) to be considered
6974  if ( Radiator.colType() == -1 ) {
6975  // For final state antiquark radiator, the anticolour is fixed
6976  // by the final / initial state recoiler colour / anticolour
6977  if ( RadType + RecType == 2 )
6978  Radiator.cols( 0, Recoiler.col());
6979  else if ( RadType + RecType == 0 )
6980  Radiator.cols( 0, Recoiler.acol());
6981  // For initial state antiquark radiator, the anticolour is fixed
6982  // by the colour of the emitted gluon (which will be the
6983  // leftover anticolour of a final state particle or the leftover
6984  // colour of an initial state particle ( = the recoiler))
6985  else {
6986  // Set colour of antiquark radiator to zero
6987  Radiator.col( 0 );
6988  for (int i = 0; i < event.size(); ++i) {
6989  int col = event[i].col();
6990  int acl = event[i].acol();
6991 
6992  if ( event[i].isFinal()) {
6993  // Search for leftover anticolour in final / initial state
6994  if ( acl > 0 && FindCol(acl,i,0,event,1,true) == 0
6995  && FindCol(acl,i,0,event,2,true) == 0 )
6996  Radiator.acol(event[i].acol());
6997  } else {
6998  // Search for leftover colour in initial / final state
6999  if ( col > 0 && FindCol(col,i,0,event,1,true) == 0
7000  && FindCol(col,i,0,event,2,true) == 0 )
7001  Radiator.acol(event[i].col());
7002  }
7003  } // end loop over particles in event record
7004  }
7005 
7006  } else if ( Radiator.colType() == 1 ) {
7007  // For final state quark radiator, the colour is fixed
7008  // by the final / initial state recoiler anticolour / colour
7009  if ( RadType + RecType == 2 )
7010  Radiator.cols( Recoiler.acol(), 0);
7011 
7012  else if ( RadType + RecType == 0 )
7013  Radiator.cols( Recoiler.col(), 0);
7014  // For initial state quark radiator, the colour is fixed
7015  // by the anticolour of the emitted gluon (which will be the
7016  // leftover colour of a final state particle or the leftover
7017  // anticolour of an initial state particle ( = the recoiler))
7018 
7019  else {
7020  // Set anticolour of quark radiator to zero
7021  Radiator.acol( 0 );
7022  for (int i = 0; i < event.size(); ++i) {
7023  int col = event[i].col();
7024  int acl = event[i].acol();
7025 
7026  if ( event[i].isFinal()) {
7027  // Search for leftover colour in final / initial state
7028  if ( col > 0 && FindCol(col,i,0,event,1,true) == 0
7029  && FindCol(col,i,0,event,2,true) == 0)
7030  Radiator.col(event[i].col());
7031  } else {
7032  // Search for leftover anticolour in initial / final state
7033  if ( acl > 0 && FindCol(acl,i,0,event,1,true) == 0
7034  && FindCol(acl,i,0,event,2,true) == 0)
7035  Radiator.col(event[i].acol());
7036  }
7037  } // end loop over particles in event record
7038 
7039  } // end distinction between fsr / fsr+initial recoiler / isr
7040 
7041  } else if ( Radiator.colType() == 2 ) {
7042  // For a gluon radiator, one (anticolour) colour index is defined
7043  // by the recoiler colour (anticolour).
7044  // The remaining index is chosen to match the free index in the
7045  // event
7046  // Search for leftover colour (anticolour) in the final state
7047  for (int i = 0; i < event.size(); ++i) {
7048  int col = event[i].col();
7049  int acl = event[i].acol();
7050  int iEx = i;
7051 
7052  if ( event[i].isFinal()) {
7053  if ( col > 0 && FindCol(col,iEx,0,event,1,true) == 0
7054  && FindCol(col,iEx,0,event,2,true) == 0) {
7055  if (Radiator.status() < 0 ) Radiator.col(event[i].col());
7056  else Radiator.acol(event[i].col());
7057  }
7058  if ( acl > 0 && FindCol(acl,iEx,0,event,2,true) == 0
7059  && FindCol(acl,iEx,0,event,1,true) == 0 ) {
7060  if (Radiator.status() < 0 ) Radiator.acol(event[i].acol());
7061  else Radiator.col(event[i].acol());
7062  }
7063  } else {
7064  if ( col > 0 && FindCol(col,iEx,0,event,1,true) == 0
7065  && FindCol(col,iEx,0,event,2,true) == 0) {
7066  if (Radiator.status() < 0 ) Radiator.acol(event[i].col());
7067  else Radiator.col(event[i].col());
7068  }
7069  if ( acl > 0 && (FindCol(acl,iEx,0,event,2,true) == 0
7070  && FindCol(acl,iEx,0,event,1,true) == 0)) {
7071  if (Radiator.status() < 0 ) Radiator.col(event[i].acol());
7072  else Radiator.acol(event[i].acol());
7073  }
7074  }
7075  } // end loop over particles in event record
7076  } // end cases of different radiator colour type
7077 
7078  // If either colour or anticolour has not been set, return false
7079  if (Radiator.col() < 0 || Radiator.acol() < 0) return false;
7080  // Done
7081  return true;
7082 }
7083 
7084 //--------------------------------------------------------------------------
7085 
7086 // Function to find a colour (anticolour) index in the input event
7087 // IN int col : Colour tag to be investigated
7088 // int iExclude1 : Identifier of first particle to be excluded
7089 // from search
7090 // int iExclude2 : Identifier of second particle to be excluded
7091 // from search
7092 // Event event : event to be searched for colour tag
7093 // int type : Tag to define if col should be counted as
7094 // colour (type = 1) [->find anti-colour index
7095 // contracted with col]
7096 // anticolour (type = 2) [->find colour index
7097 // contracted with col]
7098 // OUT int : Position of particle in event record
7099 // contraced with col [0 if col is free tag]
7100 
7101 int History::FindCol(int col, int iExclude1, int iExclude2,
7102  const Event& event, int type, bool isHardIn) {
7103 
7104  bool isHard = isHardIn;
7105  int index = 0;
7106 
7107  if (isHard) {
7108  // Search event record for matching colour & anticolour
7109  for(int n = 0; n < event.size(); ++n) {
7110  if ( n != iExclude1 && n != iExclude2
7111  && event[n].colType() != 0
7112  &&( event[n].status() > 0 // Check outgoing
7113  || event[n].status() == -21) ) { // Check incoming
7114  if ( event[n].acol() == col ) {
7115  index = -n;
7116  break;
7117  }
7118  if ( event[n].col() == col ) {
7119  index = n;
7120  break;
7121  }
7122  }
7123  }
7124  } else {
7125 
7126  // Search event record for matching colour & anticolour
7127  for(int n = 0; n < event.size(); ++n) {
7128  if ( n != iExclude1 && n != iExclude2
7129  && event[n].colType() != 0
7130  &&( event[n].status() == 43 // Check outgoing from ISR
7131  || event[n].status() == 51 // Check outgoing from FSR
7132  || event[n].status() == -41 // first initial
7133  || event[n].status() == -42) ) { // second initial
7134  if ( event[n].acol() == col ) {
7135  index = -n;
7136  break;
7137  }
7138  if ( event[n].col() == col ) {
7139  index = n;
7140  break;
7141  }
7142  }
7143  }
7144  }
7145  // if no matching colour / anticolour has been found, return false
7146  if ( type == 1 && index < 0) return abs(index);
7147  if ( type == 2 && index > 0) return abs(index);
7148 
7149  return 0;
7150 }
7151 
7152 //--------------------------------------------------------------------------
7153 
7154 // Function to in the input event find a particle with quantum
7155 // numbers matching those of the input particle
7156 // IN Particle : Particle to be searched for
7157 // Event : Event to be searched in
7158 // OUT int : > 0 : Position of matching particle in event
7159 // < 0 : No match in event
7160 
7161 int History::FindParticle( const Particle& particle, const Event& event,
7162  bool checkStatus ) {
7163 
7164  int index = -1;
7165 
7166  for ( int i = int(event.size()) - 1; i > 0; --i )
7167  if ( event[i].id() == particle.id()
7168  && event[i].colType() == particle.colType()
7169  && event[i].chargeType() == particle.chargeType()
7170  && event[i].col() == particle.col()
7171  && event[i].acol() == particle.acol()
7172  && event[i].charge() == particle.charge() ) {
7173  index = i;
7174  break;
7175  }
7176 
7177  if (index >= 0 && checkStatus && event[index].status() != particle.status())
7178  index = -1;
7179 
7180  return index;
7181 
7182 }
7183 
7184 //--------------------------------------------------------------------------
7185 
7186 // Function to get the colour of the radiator before the splitting
7187 // for clustering
7188 // IN int : Position of the radiator after the splitting, in the event
7189 // int : Position of the emitted after the splitting, in the event
7190 // Event : Reference event
7191 // OUT int : Colour of the radiator before the splitting
7192 
7193 int History::getRadBeforeCol(const int rad, const int emt,
7194  const Event& event) {
7195 
7196  // Save type of splitting
7197  int type = (event[rad].isFinal()) ? 1 :-1;
7198  // Get flavour of radiator after potential clustering
7199  int radBeforeFlav = getRadBeforeFlav(rad,emt,event);
7200  // Get colours of the radiator before the potential clustering
7201  int radBeforeCol = -1;
7202  // Get reconstructed gluon colours
7203  if (radBeforeFlav == 21) {
7204 
7205  // Start with quark emissions in FSR
7206  if (type == 1 && event[emt].id() != 21) {
7207  radBeforeCol = (event[rad].col() > 0)
7208  ? event[rad].col() : event[emt].col();
7209  // Quark emissions in ISR
7210  } else if (type == -1 && event[emt].id() != 21) {
7211  radBeforeCol = (event[rad].col() > 0)
7212  ? event[rad].col() : event[emt].acol();
7213  //Gluon emissions in FSR
7214  } else if (type == 1 && event[emt].id() == 21) {
7215  // If emitted is a gluon, remove the repeated index, and take
7216  // the remaining indices as colour and anticolour
7217  int colRemove = (event[rad].col() == event[emt].acol())
7218  ? event[rad].col() : event[rad].acol();
7219  radBeforeCol = (event[rad].col() == colRemove)
7220  ? event[emt].col() : event[rad].col();
7221  //Gluon emissions in ISR
7222  } else if (type == -1 && event[emt].id() == 21) {
7223  // If emitted is a gluon, remove the repeated index, and take
7224  // the remaining indices as colour and anticolour
7225  int colRemove = (event[rad].col() == event[emt].col())
7226  ? event[rad].col() : event[rad].acol();
7227  radBeforeCol = (event[rad].col() == colRemove)
7228  ? event[emt].acol() : event[rad].col();
7229  }
7230 
7231  // Get reconstructed quark colours
7232  } else if (radBeforeFlav > 0) {
7233 
7234  // Quark emission in FSR
7235  if (type == 1 && event[emt].id() != 21) {
7236  // If radiating is a quark, remove the repeated index, and take
7237  // the remaining indices as colour and anticolour
7238  int colRemove = (event[rad].col() == event[emt].acol())
7239  ? event[rad].acol() : 0;
7240  radBeforeCol = (event[rad].col() == colRemove)
7241  ? event[emt].col() : event[rad].col();
7242  //Gluon emissions in FSR
7243  } else if (type == 1 && event[emt].id() == 21) {
7244  // If emitted is a gluon, remove the repeated index, and take
7245  // the remaining indices as colour and anticolour
7246  int colRemove = (event[rad].col() == event[emt].acol())
7247  ? event[rad].col() : 0;
7248  radBeforeCol = (event[rad].col() == colRemove)
7249  ? event[emt].col() : event[rad].col();
7250  //Quark emissions in ISR
7251  } else if (type == -1 && event[emt].id() != 21) {
7252  // If emitted is a quark, remove the repeated index, and take
7253  // the remaining indices as colour and anticolour
7254  int colRemove = (event[rad].col() == event[emt].col())
7255  ? event[rad].col() : 0;
7256  radBeforeCol = (event[rad].col() == colRemove)
7257  ? event[emt].acol() : event[rad].col();
7258  //Gluon emissions in ISR
7259  } else if (type == -1 && event[emt].id() == 21) {
7260  // If emitted is a gluon, remove the repeated index, and take
7261  // the remaining indices as colour and anticolour
7262  int colRemove = (event[rad].col() == event[emt].col())
7263  ? event[rad].col() : 0;
7264  radBeforeCol = (event[rad].col() == colRemove)
7265  ? event[emt].acol() : event[rad].col();
7266  }
7267  // Other particles are assumed uncoloured
7268  } else {
7269  radBeforeCol = 0;
7270  }
7271 
7272  return radBeforeCol;
7273 
7274 }
7275 
7276 //--------------------------------------------------------------------------
7277 
7278 // Function to get the anticolour of the radiator before the splitting
7279 // for clustering
7280 // IN int : Position of the radiator after the splitting, in the event
7281 // int : Position of the emitted after the splitting, in the event
7282 // Event : Reference event
7283 // OUT int : Anticolour of the radiator before the splitting
7284 
7285 int History::getRadBeforeAcol(const int rad, const int emt,
7286  const Event& event) {
7287 
7288  // Save type of splitting
7289  int type = (event[rad].isFinal()) ? 1 :-1;
7290  // Get flavour of radiator after potential clustering
7291 
7292  int radBeforeFlav = getRadBeforeFlav(rad,emt,event);
7293  // Get colours of the radiator before the potential clustering
7294  int radBeforeAcl = -1;
7295  // Get reconstructed gluon colours
7296  if (radBeforeFlav == 21) {
7297 
7298  // Start with quark emissions in FSR
7299  if (type == 1 && event[emt].id() != 21) {
7300  radBeforeAcl = (event[rad].acol() > 0)
7301  ? event[rad].acol() : event[emt].acol();
7302  // Quark emissions in ISR
7303  } else if (type == -1 && event[emt].id() != 21) {
7304  radBeforeAcl = (event[rad].acol() > 0)
7305  ? event[rad].acol() : event[emt].col();
7306  //Gluon emissions in FSR
7307  } else if (type == 1 && event[emt].id() == 21) {
7308  // If emitted is a gluon, remove the repeated index, and take
7309  // the remaining indices as colour and anticolour
7310  int colRemove = (event[rad].col() == event[emt].acol())
7311  ? event[rad].col() : event[rad].acol();
7312  radBeforeAcl = (event[rad].acol() == colRemove)
7313  ? event[emt].acol() : event[rad].acol();
7314  //Gluon emissions in ISR
7315  } else if (type == -1 && event[emt].id() == 21) {
7316  // If emitted is a gluon, remove the repeated index, and take
7317  // the remaining indices as colour and anticolour
7318  int colRemove = (event[rad].col() == event[emt].col())
7319  ? event[rad].col() : event[rad].acol();
7320  radBeforeAcl = (event[rad].acol() == colRemove)
7321  ? event[emt].col() : event[rad].acol();
7322  }
7323 
7324  // Get reconstructed anti-quark colours
7325  } else if (radBeforeFlav < 0) {
7326 
7327  // Antiquark emission in FSR
7328  if (type == 1 && event[emt].id() != 21) {
7329  // If radiating is a antiquark, remove the repeated index, and take
7330  // the remaining indices as colour and anticolour
7331  int colRemove = (event[rad].col() == event[emt].acol())
7332  ? event[rad].acol() : 0;
7333  radBeforeAcl = (event[rad].acol() == colRemove)
7334  ? event[emt].acol() : event[rad].acol();
7335  //Gluon emissions in FSR
7336  } else if (type == 1 && event[emt].id() == 21) {
7337  // If emitted is a gluon, remove the repeated index, and take
7338  // the remaining indices as colour and anticolour
7339  int colRemove = (event[rad].acol() == event[emt].col())
7340  ? event[rad].acol() : 0;
7341  radBeforeAcl = (event[rad].acol() == colRemove)
7342  ? event[emt].acol() : event[rad].acol();
7343  //Antiquark emissions in ISR
7344  } else if (type == -1 && event[emt].id() != 21) {
7345  // If emitted is an antiquark, remove the repeated index, and take
7346  // the remaining indices as colour and anticolour
7347  int colRemove = (event[rad].acol() == event[emt].acol())
7348  ? event[rad].acol() : 0;
7349  radBeforeAcl = (event[rad].acol() == colRemove)
7350  ? event[emt].col() : event[rad].acol();
7351  //Gluon emissions in ISR
7352  } else if (type == -1 && event[emt].id() == 21) {
7353  // If emitted is a gluon, remove the repeated index, and take
7354  // the remaining indices as colour and anticolour
7355  int colRemove = (event[rad].acol() == event[emt].acol())
7356  ? event[rad].acol() : 0;
7357  radBeforeAcl = (event[rad].acol() == colRemove)
7358  ? event[emt].col() : event[rad].acol();
7359  }
7360  // Other particles are considered uncoloured
7361  } else {
7362  radBeforeAcl = 0;
7363  }
7364 
7365  return radBeforeAcl;
7366 
7367 }
7368 
7369 //--------------------------------------------------------------------------
7370 
7371  // Function to get the parton connected to in by a colour line
7372  // IN int : Position of parton for which partner should be found
7373  // Event : Reference event
7374  // OUT int : If a colour line connects the "in" parton with another
7375  // parton, return the Position of the partner, else return 0
7376 
7377 int History::getColPartner(const int in, const Event& event) {
7378 
7379  if (event[in].col() == 0) return 0;
7380 
7381  int partner = 0;
7382  // Try to find anticolour index first
7383  partner = FindCol(event[in].col(),in,0,event,1,true);
7384  // If no anticolour index has been found, try colour
7385  if (partner == 0)
7386  partner = FindCol(event[in].col(),in,0,event,2,true);
7387 
7388  return partner;
7389 
7390 }
7391 
7392 //--------------------------------------------------------------------------
7393 
7394 
7395  // Function to get the parton connected to in by an anticolour line
7396  // IN int : Position of parton for which partner should be found
7397  // Event : Reference event
7398  // OUT int : If an anticolour line connects the "in" parton with another
7399  // parton, return the Position of the partner, else return 0
7400 
7401 int History::getAcolPartner(const int in, const Event& event) {
7402 
7403  if (event[in].acol() == 0) return 0;
7404 
7405  int partner = 0;
7406  // Try to find colour index first
7407  partner = FindCol(event[in].acol(),in,0,event,2,true);
7408  // If no colour index has been found, try anticolour
7409  if (partner == 0)
7410  partner = FindCol(event[in].acol(),in,0,event,1,true);
7411 
7412  return partner;
7413 
7414 }
7415 
7416 //--------------------------------------------------------------------------
7417 
7418 // Function to get the list of partons connected to the particle
7419 // formed by reclusterinf emt and rad by colour and anticolour lines
7420 // IN int : Position of radiator in the clustering
7421 // IN int : Position of emitted in the clustering
7422 // Event : Reference event
7423 // OUT vector<int> : List of positions of all partons that are connected
7424 // to the parton that will be formed
7425 // by clustering emt and rad.
7426 
7427 vector<int> History::getReclusteredPartners(const int rad, const int emt,
7428  const Event& event) {
7429 
7430  // Save type
7431  int type = event[rad].isFinal() ? 1 : -1;
7432  // Get reclustered colours
7433  int radBeforeCol = getRadBeforeCol(rad, emt, event);
7434  int radBeforeAcl = getRadBeforeAcol(rad, emt, event);
7435  // Declare output
7436  vector<int> partners;
7437 
7438 
7439  // Start with FSR clusterings
7440  if (type == 1) {
7441 
7442  for(int i=0; i < int(event.size()); ++i) {
7443  // Check all initial state partons
7444  if ( i != emt && i != rad
7445  && event[i].status() == -21
7446  && event[i].col() > 0
7447  && event[i].col() == radBeforeCol)
7448  partners.push_back(i);
7449  // Check all final state partons
7450  if ( i != emt && i != rad
7451  && event[i].isFinal()
7452  && event[i].acol() > 0
7453  && event[i].acol() == radBeforeCol)
7454  partners.push_back(i);
7455  // Check all initial state partons
7456  if ( i != emt && i != rad
7457  && event[i].status() == -21
7458  && event[i].acol() > 0
7459  && event[i].acol() == radBeforeAcl)
7460  partners.push_back(i);
7461  // Check all final state partons
7462  if ( i != emt && i != rad
7463  && event[i].isFinal()
7464  && event[i].col() > 0
7465  && event[i].col() == radBeforeAcl)
7466  partners.push_back(i);
7467  }
7468  // Start with ISR clusterings
7469  } else {
7470 
7471  for(int i=0; i < int(event.size()); ++i) {
7472  // Check all initial state partons
7473  if ( i != emt && i != rad
7474  && event[i].status() == -21
7475  && event[i].acol() > 0
7476  && event[i].acol() == radBeforeCol)
7477  partners.push_back(i);
7478  // Check all final state partons
7479  if ( i != emt && i != rad
7480  && event[i].isFinal()
7481  && event[i].col() > 0
7482  && event[i].col() == radBeforeCol)
7483  partners.push_back(i);
7484  // Check all initial state partons
7485  if ( i != emt && i != rad
7486  && event[i].status() == -21
7487  && event[i].col() > 0
7488  && event[i].col() == radBeforeAcl)
7489  partners.push_back(i);
7490  // Check all final state partons
7491  if ( i != emt && i != rad
7492  && event[i].isFinal()
7493  && event[i].acol() > 0
7494  && event[i].acol() == radBeforeAcl)
7495  partners.push_back(i);
7496  }
7497 
7498  }
7499  // Done
7500  return partners;
7501 }
7502 
7503 //--------------------------------------------------------------------------
7504 
7505 // Function to extract a chain of colour-connected partons in
7506 // the event
7507 // IN int : Type of parton from which to start extracting a
7508 // parton chain. If the starting point is a quark
7509 // i.e. flavType = 1, a chain of partons that are
7510 // consecutively connected by colour-lines will be
7511 // extracted. If the starting point is an antiquark
7512 // i.e. flavType =-1, a chain of partons that are
7513 // consecutively connected by anticolour-lines
7514 // will be extracted.
7515 // IN int : Position of the parton from which a
7516 // colour-connected chain should be derived
7517 // IN Event : Refernence event
7518 // IN/OUT vector<int> : Partons that should be excluded from the search.
7519 // OUT vector<int> : Positions of partons along the chain
7520 // OUT bool : Found singlet / did not find singlet
7521 
7522 bool History::getColSinglet( const int flavType, const int iParton,
7523  const Event& event, vector<int>& exclude, vector<int>& colSinglet) {
7524 
7525  // If no possible flavour to start from has been found
7526  if (iParton < 0) return false;
7527 
7528  // If no further partner has been found in a previous iteration,
7529  // and the whole final state has been excluded, we're done
7530  if (iParton == 0) {
7531 
7532  // Count number of final state partons
7533  int nFinal = 0;
7534  for(int i=0; i < int(event.size()); ++i)
7535  if ( event[i].isFinal() && event[i].colType() != 0)
7536  nFinal++;
7537 
7538  // Get number of initial state partons in the list of
7539  // excluded partons
7540  int nExclude = int(exclude.size());
7541  int nInitExclude = 0;
7542  if (!event[exclude[2]].isFinal())
7543  nInitExclude++;
7544  if (!event[exclude[3]].isFinal())
7545  nInitExclude++;
7546 
7547  // If the whole final state has been considered, return
7548  if (nFinal == nExclude - nInitExclude)
7549  return true;
7550  else
7551  return false;
7552 
7553  }
7554 
7555  // Declare colour partner
7556  int colP = 0;
7557  // Save the colour partner
7558  colSinglet.push_back(iParton);
7559  // Remove the partner from the list
7560  exclude.push_back(iParton);
7561  // When starting out from a quark line, follow the colour lines
7562  if (flavType == 1)
7563  colP = getColPartner(iParton,event);
7564  // When starting out from an antiquark line, follow the anticolour lines
7565  else
7566  colP = getAcolPartner(iParton,event);
7567 
7568  // Do not count excluded partons twice
7569  for(int i = 0; i < int(exclude.size()); ++i)
7570  if (colP == exclude[i])
7571  return true;
7572 
7573  // Recurse
7574  return getColSinglet(flavType,colP,event,exclude,colSinglet);
7575 
7576 }
7577 
7578 //--------------------------------------------------------------------------
7579 
7580 // Function to check that a set of partons forms a colour singlet
7581 // IN Event : Reference event
7582 // IN vector<int> : Positions of the partons in the set
7583 // OUT bool : Is a colour singlet / is not
7584 
7585 bool History::isColSinglet( const Event& event,
7586  vector<int> system ) {
7587 
7588  // Check if system forms a colour singlet
7589  for(int i=0; i < int(system.size()); ++i ) {
7590  // Match quark and gluon colours
7591  if ( system[i] > 0
7592  && (event[system[i]].colType() == 1
7593  || event[system[i]].colType() == 2) ) {
7594  for(int j=0; j < int(system.size()); ++j)
7595  // If flavour matches, remove both partons and continue
7596  if ( system[j] > 0
7597  && event[system[i]].col() == event[system[j]].acol()) {
7598  // Remove index and break
7599  system[i] = 0;
7600  system[j] = 0;
7601  break;
7602  }
7603  }
7604  // Match antiquark and gluon anticolours
7605  if ( system[i] > 0
7606  && (event[system[i]].colType() == -1
7607  || event[system[i]].colType() == 2) ) {
7608  for(int j=0; j < int(system.size()); ++j)
7609  // If flavour matches, remove both partons and continue
7610  if ( system[j] > 0
7611  && event[system[i]].acol() == event[system[j]].col()) {
7612  // Remove index and break
7613  system[i] = 0;
7614  system[j] = 0;
7615  break;
7616  }
7617  }
7618 
7619  }
7620 
7621  // The system is a colour singlet if for all colours,
7622  // an anticolour was found
7623  bool isColSing = true;
7624  for(int i=0; i < int(system.size()); ++i)
7625  if ( system[i] != 0 )
7626  isColSing = false;
7627 
7628  // Return
7629  return isColSing;
7630 
7631 
7632 }
7633 
7634 //--------------------------------------------------------------------------
7635 
7636 // Function to check that a set of partons forms a flavour singlet
7637 // IN Event : Reference event
7638 // IN vector<int> : Positions of the partons in the set
7639 // IN int : Flavour of all the quarks in the set, if
7640 // all quarks in a set should have a fixed flavour
7641 // OUT bool : Is a flavour singlet / is not
7642 
7643 bool History::isFlavSinglet( const Event& event,
7644  vector<int> system, int flav) {
7645 
7646  // If a decoupled colour singlet has been found, check if this is also
7647  // a flavour singlet
7648  // Check that each quark matches an antiquark
7649  for(int i=0; i < int(system.size()); ++i)
7650  if ( system[i] > 0 ) {
7651  for(int j=0; j < int(system.size()); ++j) {
7652  // If flavour of outgoing partons matches,
7653  // remove both partons and continue.
7654  // Skip all bosons
7655  if ( event[i].idAbs() != 21
7656  && event[i].idAbs() != 22
7657  && event[i].idAbs() != 23
7658  && event[i].idAbs() != 24
7659  && system[j] > 0
7660  && event[system[i]].isFinal()
7661  && event[system[j]].isFinal()
7662  && event[system[i]].id() == -1*event[system[j]].id()) {
7663  // If we want to check if only one flavour of quarks
7664  // exists
7665  if (abs(flav) > 0 && event[system[i]].idAbs() != flav)
7666  return false;
7667  // Remove index and break
7668  system[i] = 0;
7669  system[j] = 0;
7670  break;
7671  }
7672  // If flavour of outgoing and incoming partons match,
7673  // remove both partons and continue.
7674  // Skip all bosons
7675  if ( event[i].idAbs() != 21
7676  && event[i].idAbs() != 22
7677  && event[i].idAbs() != 23
7678  && event[i].idAbs() != 24
7679  && system[j] > 0
7680  && event[system[i]].isFinal() != event[system[j]].isFinal()
7681  && event[system[i]].id() == event[system[j]].id()) {
7682  // If we want to check if only one flavour of quarks
7683  // exists
7684  if (abs(flav) > 0 && event[system[i]].idAbs() != flav)
7685  return false;
7686  // Remove index and break
7687  system[i] = 0;
7688  system[j] = 0;
7689  break;
7690  }
7691 
7692  }
7693  }
7694 
7695  // The colour singlet is a flavour singlet if for all quarks,
7696  // an antiquark was found
7697  bool isFlavSing = true;
7698  for(int i=0; i < int(system.size()); ++i)
7699  if ( system[i] != 0 )
7700  isFlavSing = false;
7701 
7702  // Return
7703  return isFlavSing;
7704 
7705 }
7706 
7707 //--------------------------------------------------------------------------
7708 
7709 // Function to check if rad,emt,rec triple is allowed for clustering
7710 // IN int rad,emt,rec : Positions (in event record) of the three
7711 // particles considered for clustering
7712 // Event event : Reference event
7713 
7714 bool History::allowedClustering( int rad, int emt, int rec, int partner,
7715  const Event& event ) {
7716 
7717  // Declare output
7718  bool allowed = true;
7719 
7720  // CONSTRUCT SOME PROPERTIES FOR LATER INVESTIGATION
7721 
7722  // Check if the triple forms a colour singlett
7723  bool isSing = isSinglett(rad,emt,partner,event);
7724  int type = (event[rad].isFinal()) ? 1 :-1;
7725  // Get flavour of radiator after potential clustering
7726  int radBeforeFlav = getRadBeforeFlav(rad,emt,event);
7727  // Get colours of the radiator before the potential clustering
7728  int radBeforeCol = getRadBeforeCol(rad,emt,event);
7729  int radBeforeAcl = getRadBeforeAcol(rad,emt,event);
7730  // Get colour partner of reclustered parton
7731  vector<int> radBeforeColP = getReclusteredPartners(rad, emt, event);
7732 
7733  // Count coloured partons in hard process
7734  int nPartonInHard = 0;
7735  for(int i=0; i < int(event.size()); ++i)
7736  // Check all final state partons
7737  if ( event[i].isFinal()
7738  && event[i].colType() != 0
7739  && mergingHooksPtr->hardProcess->matchesAnyOutgoing(i, event) )
7740  nPartonInHard++;
7741 
7742  // Count coloured final state partons in event, excluding
7743  // rad, rec, emt and hard process
7744  int nPartons = 0;
7745  for(int i=0; i < int(event.size()); ++i)
7746  // Check all final state partons
7747  if ( i!=emt && i!=rad && i!=rec
7748  && event[i].isFinal()
7749  && event[i].colType() != 0
7750  && !mergingHooksPtr->hardProcess->matchesAnyOutgoing(i, event) )
7751  nPartons++;
7752 
7753  // Count number of initial state partons
7754  int nInitialPartons = 0;
7755  for(int i=0; i < int(event.size()); ++i)
7756  if ( event[i].status() == -21
7757  && event[i].colType() != 0 )
7758  nInitialPartons++;
7759 
7760  // Get number of non-charged final state particles
7761  int nFinalEW = 0;
7762  for(int i=0; i < int(event.size()); ++i)
7763  if ( event[i].isFinal()
7764  &&( event[i].id() == 22
7765  || event[i].id() == 23
7766  || event[i].id() == 24
7767  ||(event[i].idAbs() > 10 && event[i].idAbs() < 20)
7768  ||(event[i].idAbs() > 1000010 && event[i].idAbs() < 1000020)
7769  ||(event[i].idAbs() > 2000010 && event[i].idAbs() < 2000020) ))
7770  nFinalEW++;
7771 
7772  // Check if event after potential clustering contains an even
7773  // number of quarks and/or antiquarks
7774  // (otherwise no electroweak vertex could be formed!)
7775  // Get number of final quarks
7776  int nFinalQuark = 0;
7777  // Get number of excluded final state quarks as well
7778  int nFinalQuarkExc = 0;
7779  for(int i=0; i < int(event.size()); ++i) {
7780  if (i !=rad && i != emt && i != rec) {
7781  if (event[i].isFinal() && abs(event[i].colType()) == 1 ) {
7782  if ( !mergingHooksPtr->hardProcess->matchesAnyOutgoing(i,event) )
7783  nFinalQuark++;
7784  else
7785  nFinalQuarkExc++;
7786  }
7787  }
7788  }
7789 
7790  // Add recoiler to number of final quarks
7791  if (event[rec].isFinal() && event[rec].isQuark()) nFinalQuark++;
7792  // Add radiator after clustering to number of final quarks
7793  if ( event[rad].isFinal()
7794  && abs(particleDataPtr->colType(radBeforeFlav)) == 1) nFinalQuark++;
7795 
7796  // Get number of initial quarks
7797  int nInitialQuark = 0;
7798  if (type == 1) {
7799  if (event[rec].isFinal()) {
7800  if (event[3].isQuark()) nInitialQuark++;
7801  if (event[4].isQuark()) nInitialQuark++;
7802  } else {
7803  int iOtherIn = (rec == 3) ? 4 : 3;
7804  if (event[rec].isQuark()) nInitialQuark++;
7805  if (event[iOtherIn].isQuark()) nInitialQuark++;
7806  }
7807  } else {
7808  // Add recoiler to number of initial quarks
7809  if (event[rec].isQuark()) nInitialQuark++;
7810  // Add radiator after clustering to number of initial quarks
7811  if (abs(radBeforeFlav) < 10) nInitialQuark++;
7812  }
7813 
7814  // BEGIN CHECKING THE CLUSTERING
7815 
7816  // Do not allow clusterings that lead to a disallowed proton content.
7817  int proton[] = {1,2,3,4,5,21,22,23,24};
7818  bool isInProton = false;
7819  for(int i=0; i < 9; ++i)
7820  if (abs(radBeforeFlav) == proton[i]) isInProton = true;
7821  if (type == -1 && !isInProton) return false;
7822 
7823  // Check if colour is conserved
7824  vector<int> unmatchedCol;
7825  vector<int> unmatchedAcl;
7826  // Check all unmatched colours
7827  for ( int i = 0; i < event.size(); ++i)
7828  if ( i != emt && i != rad
7829  && (event[i].isFinal() || event[i].status() == -21)
7830  && event[i].colType() != 0 ) {
7831 
7832  int colP = getColPartner(i,event);
7833  int aclP = getAcolPartner(i,event);
7834 
7835  if (event[i].col() > 0
7836  && (colP == emt || colP == rad || colP == 0) )
7837  unmatchedCol.push_back(i);
7838  if (event[i].acol() > 0
7839  && (aclP == emt || aclP == rad || aclP == 0) )
7840  unmatchedAcl.push_back(i);
7841 
7842  }
7843 
7844  // If more than one colour or more than one anticolour are unmatched,
7845  // there is no way to make this clustering work
7846  if (int(unmatchedCol.size()) + int(unmatchedAcl.size()) > 2)
7847  return false;
7848 
7849  // If triple forms colour singlett, check that resulting state
7850  // matches hard core process
7851  if (isSing)
7852  allowed = false;
7853  if ( isSing && event[rec].isQuark()
7854  && abs(particleDataPtr->colType(radBeforeFlav)) == 1)
7855  allowed = true;
7856 
7857  // Never recluster any outgoing partons of the core V -> qqbar' splitting!
7858  if ( mergingHooksPtr->hardProcess->matchesAnyOutgoing(emt,event) ) {
7859  // Check if any other particle could replace "emt" as part of the candidate
7860  // core process. If so, replace emt with the new candidate and allow the
7861  // clustering.
7862  bool canReplace = mergingHooksPtr->hardProcess->findOtherCandidates(emt,
7863  event, true);
7864  if (canReplace) allowed = true;
7865  else allowed = false;
7866  }
7867 
7868  // Never allow clustering of any outgoing partons of the hard process
7869  // which would change the flavour of one of the hard process partons!
7870  if ( mergingHooksPtr->hardProcess->matchesAnyOutgoing(rad,event)
7871  && event[rad].id() != radBeforeFlav )
7872  allowed = false;
7873 
7874  // If only gluons in initial state and no quarks in final state,
7875  // reject (no electroweak vertex can be formed)
7876  if (nFinalEW != 0 && nInitialQuark == 0
7877  && nFinalQuark == 0 && nFinalQuarkExc == 0)
7878  allowed = false;
7879 
7880  if ( (nInitialQuark + nFinalQuark + nFinalQuarkExc)%2 != 0 )
7881  allowed = false;
7882 
7883  // Disallow final state splittings that lead to a purely gluonic final
7884  // state, while having a completely colour-connected initial state.
7885  // This means that the clustering is discarded if it does not lead to the
7886  // t-channel gluon needed to connect the final state to a qq~ initial state.
7887  // Here, partons excluded from clustering are not counted as possible
7888  // partners to form a t-channel gluon
7889  vector<int> in;
7890  for(int i=0; i < int(event.size()); ++i)
7891  if ( i!=emt && i!=rad && i!=rec
7892  && (event[i].mother1() == 1 || event[i].mother1() == 2))
7893  in.push_back(event[i].id());
7894  if (!event[rad].isFinal()) in.push_back(radBeforeFlav);
7895  if (!event[rec].isFinal()) in.push_back(event[rec].id());
7896  vector<int> out;
7897  for(int i=0; i < int(event.size()); ++i)
7898  if ( i!=emt && i!=rad && i!=rec && event[i].isFinal())
7899  out.push_back(event[i].id());
7900  if (event[rad].isFinal()) out.push_back(radBeforeFlav);
7901  if (event[rec].isFinal()) out.push_back(event[rec].id());
7902  if (event[3].col() == event[4].acol()
7903  && event[3].acol() == event[4].col()
7904  && !mergingHooksPtr->allowEffectiveVertex( in, out)
7905  && nFinalQuark == 0){
7906  // Careful if rad and rec are the only quarks in the final state, but
7907  // were both excluded from the list of final state quarks.
7908  int nTripletts = abs(event[rec].colType())
7909  + abs(particleDataPtr->colType(radBeforeFlav));
7910  if (event[3].isGluon()) allowed = false;
7911  else if (nTripletts != 2 && nFinalQuarkExc%2 == 0) allowed = false;
7912  }
7913 
7914  // Minimal phase space checks.
7915  if ( abs((event[rad].p()+type*event[emt].p()+event[rec].p()).pz())
7916  > (event[rad].p()+type*event[emt].p()+event[rec].p()).e()
7917  || (type == -1
7918  && (event[rad].p()-event[emt].p()+event[rec].p()).m2Calc() < 0.) ){
7919  return false;
7920  }
7921 
7922  // No problems with gluon radiation
7923  if (event[emt].id() == 21) return allowed;
7924 
7925  // No problems with gluino radiation
7926  if (event[emt].id() == 1000021) return allowed;
7927 
7928  // Save all hard process candidates
7929  vector<int> outgoingParticles;
7930  int nOut1 = int(mergingHooksPtr->hardProcess->PosOutgoing1.size());
7931  for ( int i=0; i < nOut1; ++i ) {
7932  int iPos = mergingHooksPtr->hardProcess->PosOutgoing1[i];
7933  outgoingParticles.push_back(
7934  mergingHooksPtr->hardProcess->state[iPos].id() );
7935  }
7936  int nOut2 = int(mergingHooksPtr->hardProcess->PosOutgoing2.size());
7937  for ( int i=0; i < nOut2; ++i ) {
7938  int iPos = mergingHooksPtr->hardProcess->PosOutgoing2[i];
7939  outgoingParticles.push_back(
7940  mergingHooksPtr->hardProcess->state[iPos].id() );
7941  }
7942 
7943  // Start more involved checks. g -> q_1 qbar_1 splittings are
7944  // particularly problematic if more than one quark of the emitted
7945  // flavour is present.
7946  // Count number of initial quarks of radiator or emitted flavour
7947  vector<int> iInQuarkFlav;
7948  for(int i=0; i < int(event.size()); ++i)
7949  // Check all initial state partons
7950  if ( i != emt && i != rad
7951  && event[i].status() == -21
7952  && event[i].idAbs() == event[emt].idAbs() )
7953  iInQuarkFlav.push_back(i);
7954 
7955  // Count number of final quarks of radiator or emitted flavour
7956  vector<int> iOutQuarkFlav;
7957  for(int i=0; i < int(event.size()); ++i)
7958  // Check all final state partons
7959  if ( i != emt && i != rad
7960  && event[i].isFinal()
7961  && event[i].idAbs() == event[emt].idAbs() ) {
7962 
7963  // Loop through final state hard particles. If one matches, remove the
7964  // matching one, and do not count.
7965  bool matchOut = false;
7966  for (int j = 0; j < int(outgoingParticles.size()); ++j)
7967  if ( event[i].idAbs() == abs(outgoingParticles[j])) {
7968  matchOut = true;
7969  outgoingParticles[j] = 99;
7970  }
7971  if (!matchOut) iOutQuarkFlav.push_back(i);
7972 
7973  }
7974 
7975  // Save number of potentially dangerous quarks
7976  int nInQuarkFlav = int(iInQuarkFlav.size());
7977  int nOutQuarkFlav = int(iOutQuarkFlav.size());
7978 
7979  // Easiest problem 0:
7980  // Radiator before splitting exactly matches the partner
7981  // after the splitting
7982  if ( event[partner].isFinal()
7983  && event[partner].id() == 21
7984  && radBeforeFlav == 21
7985  && event[partner].col() == radBeforeCol
7986  && event[partner].acol() == radBeforeAcl)
7987  return false;
7988 
7989  // If there are no ambiguities in qqbar pairs, return
7990  if (nInQuarkFlav + nOutQuarkFlav == 0)
7991  return allowed;
7992 
7993  // Save all quarks and gluons that will not change colour
7994  vector<int> gluon;
7995  vector<int> quark;
7996  vector<int> antiq;
7997  vector<int> partons;
7998  for(int i=0; i < int(event.size()); ++i)
7999  // Check initial and final state partons
8000  if ( i!=emt && i!=rad
8001  && event[i].colType() != 0
8002  && (event[i].isFinal() || event[i].status() == -21) ) {
8003  // Save index
8004  partons.push_back(i);
8005  // Split into components
8006  if (event[i].colType() == 2)
8007  gluon.push_back(i);
8008  else if (event[i].colType() == 1)
8009  quark.push_back(i);
8010  else if (event[i].colType() == -1)
8011  antiq.push_back(i);
8012  }
8013 
8014  // We split up the test of the g->qq splitting into final state
8015  // and initial state problems
8016  bool isFSRg2qq = ((type == 1) && (event[rad].id() == -1*event[emt].id()) );
8017  bool isISRg2qq = ((type ==-1) && (event[rad].id() == event[emt].id()) );
8018 
8019  // First check general things about colour connections
8020  // Check that clustering does not produce a gluon that is exactly
8021  // matched in the final state, or does not have any colour connections
8022  if ( (isFSRg2qq || isISRg2qq)
8023  && int(quark.size()) + int(antiq.size())
8024  + int(gluon.size()) > nPartonInHard ) {
8025 
8026  vector<int> colours;
8027  vector<int> anticolours;
8028  // Add the colour and anticolour of the gluon before the emission
8029  // to the list, bookkeep initial colour as final anticolour, and
8030  // initial anticolour as final colour
8031  if (type == 1) {
8032  colours.push_back(radBeforeCol);
8033  anticolours.push_back(radBeforeAcl);
8034  } else {
8035  colours.push_back(radBeforeAcl);
8036  anticolours.push_back(radBeforeCol);
8037  }
8038  // Now store gluon colours and anticolours.
8039  for(int i=0; i < int(gluon.size()); ++i)
8040  if (event[gluon[i]].isFinal()) {
8041  colours.push_back(event[gluon[i]].col());
8042  anticolours.push_back(event[gluon[i]].acol());
8043  } else {
8044  colours.push_back(event[gluon[i]].acol());
8045  anticolours.push_back(event[gluon[i]].col());
8046  }
8047 
8048  // Loop through colours and check if any match with
8049  // anticolours. If colour matches, remove from list
8050  for(int i=0; i < int(colours.size()); ++i)
8051  for(int j=0; j < int(anticolours.size()); ++j)
8052  if (colours[i] > 0 && anticolours[j] > 0
8053  && colours[i] == anticolours[j]) {
8054  colours[i] = 0;
8055  anticolours[j] = 0;
8056  }
8057 
8058 
8059  // If all gluon anticolours and all colours matched, disallow
8060  // the clustering
8061  bool allMatched = true;
8062  for(int i=0; i < int(colours.size()); ++i)
8063  if (colours[i] != 0)
8064  allMatched = false;
8065  for(int i=0; i < int(anticolours.size()); ++i)
8066  if (anticolours[i] != 0)
8067  allMatched = false;
8068 
8069  if (allMatched)
8070  return false;
8071 
8072  // Now add the colours of the hard process, and check if all
8073  // colours match.
8074  for(int i=0; i < int(quark.size()); ++i)
8075  if ( event[quark[i]].isFinal()
8076  && mergingHooksPtr->hardProcess->matchesAnyOutgoing(quark[i], event) )
8077  colours.push_back(event[quark[i]].col());
8078 
8079  for(int i=0; i < int(antiq.size()); ++i)
8080  if ( event[antiq[i]].isFinal()
8081  && mergingHooksPtr->hardProcess->matchesAnyOutgoing(antiq[i], event) )
8082  anticolours.push_back(event[antiq[i]].acol());
8083 
8084  // Loop through colours again and check if any match with
8085  // anticolours. If colour matches, remove from list
8086  for(int i=0; i < int(colours.size()); ++i)
8087 
8088  for(int j=0; j < int(anticolours.size()); ++j)
8089  if (colours[i] > 0 && anticolours[j] > 0
8090  && colours[i] == anticolours[j]) {
8091  colours[i] = 0;
8092  anticolours[j] = 0;
8093  }
8094 
8095  // Check if clustering would produce the hard process
8096  int nNotInHard = 0;
8097  for ( int i=0; i < int(quark.size()); ++i )
8098  if ( !mergingHooksPtr->hardProcess->matchesAnyOutgoing( quark[i],
8099  event) )
8100  nNotInHard++;
8101  for ( int i=0; i < int(antiq.size()); ++i )
8102  if ( !mergingHooksPtr->hardProcess->matchesAnyOutgoing( antiq[i],
8103  event) )
8104  nNotInHard++;
8105  for(int i=0; i < int(gluon.size()); ++i)
8106  if ( event[gluon[i]].isFinal() )
8107  nNotInHard++;
8108  if ( type == 1 )
8109  nNotInHard++;
8110 
8111  // If all colours are matched now, and since we have more quarks than
8112  // present in the hard process, disallow the clustering
8113  allMatched = true;
8114  for(int i=0; i < int(colours.size()); ++i)
8115  if (colours[i] != 0)
8116  allMatched = false;
8117  for(int i=0; i < int(anticolours.size()); ++i)
8118  if (anticolours[i] != 0)
8119  allMatched = false;
8120 
8121  if (allMatched && nNotInHard > 0)
8122  return false;
8123 
8124  }
8125 
8126  // FSR PROBLEMS
8127 
8128  if (isFSRg2qq && nInQuarkFlav + nOutQuarkFlav > 0) {
8129 
8130  // Easiest problem 1:
8131  // RECLUSTERED FINAL STATE GLUON MATCHES INITIAL STATE GLUON
8132  for(int i=0; i < int(gluon.size()); ++i) {
8133  if (!event[gluon[i]].isFinal()
8134  && event[gluon[i]].col() == radBeforeCol
8135  && event[gluon[i]].acol() == radBeforeAcl)
8136  return false;
8137  }
8138 
8139  // Easiest problem 2:
8140  // RECLUSTERED FINAL STATE GLUON MATCHES FINAL STATE GLUON
8141  for(int i=0; i < int(gluon.size()); ++i) {
8142  if (event[gluon[i]].isFinal()
8143  && event[gluon[i]].col() == radBeforeAcl
8144  && event[gluon[i]].acol() == radBeforeCol)
8145  return false;
8146  }
8147 
8148  // Easiest problem 3:
8149  // RECLUSTERED FINAL STATE GLUON MATCHES FINAL STATE Q-QBAR PAIR
8150  if ( int(radBeforeColP.size()) == 2
8151  && event[radBeforeColP[0]].isFinal()
8152  && event[radBeforeColP[1]].isFinal()
8153  && event[radBeforeColP[0]].id() == -1*event[radBeforeColP[1]].id() ) {
8154 
8155  // This clustering is allowed if there is no colour in the
8156  // initial state
8157  if (nInitialPartons > 0)
8158  return false;
8159  }
8160 
8161  // Next-to-easiest problem 1:
8162  // RECLUSTERED FINAL STATE GLUON MATCHES ONE FINAL STARE Q_1
8163  // AND ONE INITIAL STATE Q_1
8164  if ( int(radBeforeColP.size()) == 2
8165  && (( event[radBeforeColP[0]].status() == -21
8166  && event[radBeforeColP[1]].isFinal())
8167  ||( event[radBeforeColP[0]].isFinal()
8168  && event[radBeforeColP[1]].status() == -21))
8169  && event[radBeforeColP[0]].id() == event[radBeforeColP[1]].id() ) {
8170 
8171  // In principle, clustering this splitting can disconnect
8172  // the colour lines of a graph. However, the colours can be connected
8173  // again if a final or initial partons of the correct flavour exists.
8174 
8175  // Check which of the partners are final / initial
8176  int incoming = (event[radBeforeColP[0]].isFinal())
8177  ? radBeforeColP[1] : radBeforeColP[0];
8178  int outgoing = (event[radBeforeColP[0]].isFinal())
8179  ? radBeforeColP[0] : radBeforeColP[1];
8180 
8181  // Loop through event to find "recovery partons"
8182  bool clusPossible = false;
8183  for(int i=0; i < int(event.size()); ++i)
8184  if ( i != emt && i != rad
8185  && i != incoming && i != outgoing
8186  && !mergingHooksPtr->hardProcess->matchesAnyOutgoing(i,event) ) {
8187  // Check if an incoming parton matches
8188  if ( event[i].status() == -21
8189  && (event[i].id() == event[outgoing].id()
8190  ||event[i].id() == -1*event[incoming].id()) )
8191  clusPossible = true;
8192  // Check if a final parton matches
8193  if ( event[i].isFinal()
8194  && (event[i].id() == -1*event[outgoing].id()
8195  ||event[i].id() == event[incoming].id()) )
8196  clusPossible = true;
8197  }
8198 
8199  // There can be a further complication: If e.g. in
8200  // t-channel photon exchange topologies, both incoming
8201  // partons are quarks, and form colour singlets with any
8202  // number of final state partons, at least try to
8203  // recluster as much as possible.
8204  // For this, check if the incoming parton
8205  // connected to the radiator is connected to a
8206  // colour and flavour singlet
8207  vector<int> excludeIn1;
8208  for(int i=0; i < 4; ++i)
8209  excludeIn1.push_back(0);
8210  vector<int> colSingletIn1;
8211  int flavIn1Type = (event[incoming].id() > 0) ? 1 : -1;
8212  // Try finding colour singlets
8213  bool isColSingIn1 = getColSinglet(flavIn1Type,incoming,event,
8214  excludeIn1,colSingletIn1);
8215  // Check if colour singlet also is a flavour singlet
8216  bool isFlavSingIn1 = isFlavSinglet(event,colSingletIn1);
8217 
8218  // Check if the incoming parton not
8219  // connected to the radiator is connected to a
8220  // colour and flavour singlet
8221  int incoming2 = (incoming == 3) ? 4 : 3;
8222  vector<int> excludeIn2;
8223  for(int i=0; i < 4; ++i)
8224  excludeIn2.push_back(0);
8225  vector<int> colSingletIn2;
8226  int flavIn2Type = (event[incoming2].id() > 0) ? 1 : -1;
8227  // Try finding colour singlets
8228  bool isColSingIn2 = getColSinglet(flavIn2Type,incoming2,event,
8229  excludeIn2,colSingletIn2);
8230  // Check if colour singlet also is a flavour singlet
8231  bool isFlavSingIn2 = isFlavSinglet(event,colSingletIn2);
8232 
8233  // If no "recovery clustering" is possible, reject clustering
8234  if (!clusPossible
8235  && (!isColSingIn1 || !isFlavSingIn1
8236  || !isColSingIn2 || !isFlavSingIn2))
8237  return false;
8238 
8239  }
8240 
8241  // Next-to-easiest problem 2:
8242  // FINAL STATE Q-QBAR CLUSTERING DISCONNECTS SINGLETT SUBSYSTEM WITH
8243  // FINAL STATE Q-QBAR PAIR FROM GRAPH
8244 
8245  // Prepare to check for colour singlet combinations of final state quarks
8246  // Start by building a list of partons to exclude when checking for
8247  // colour singlet combinations
8248  int flav = event[emt].id();
8249  vector<int> exclude;
8250  exclude.push_back(emt);
8251  exclude.push_back(rad);
8252  exclude.push_back(radBeforeColP[0]);
8253  exclude.push_back(radBeforeColP[1]);
8254  vector<int> colSinglet;
8255  // Now find parton from which to start checking colour singlets
8256  int iOther = -1;
8257  // Loop through event to find a parton of correct flavour
8258  for(int i=0; i < int(event.size()); ++i)
8259  // Check final state for parton equalling emitted flavour.
8260  // Exclude the colour system coupled to the clustering
8261  if ( i != emt
8262  && i != rad
8263  && i != radBeforeColP[0]
8264  && i != radBeforeColP[1]
8265  && event[i].isFinal() ) {
8266  // Stop if one parton of the correct flavour is found
8267  if (event[i].id() == flav) {
8268  iOther = i;
8269  break;
8270  }
8271  }
8272  // Save the type of flavour
8273  int flavType = (iOther > 0 && event[iOther].id() > 0) ? 1
8274  : (iOther > 0) ? -1 : 0;
8275  // Try finding colour singlets
8276  bool isColSing = getColSinglet(flavType,iOther,event,exclude,colSinglet);
8277  // Check if colour singlet also is a flavour singlet
8278  bool isFlavSing = isFlavSinglet(event,colSinglet);
8279 
8280  // Check if the colour singlet is precisely contained in the hard process.
8281  // If so, then we're safe to recluster.
8282  bool isHardSys = true;
8283  for(int i=0; i < int(colSinglet.size()); ++i)
8284  isHardSys = mergingHooksPtr->hardProcess->matchesAnyOutgoing(
8285  colSinglet[i], event);
8286 
8287  // Nearly there...
8288  // If the decoupled colour singlet system is NOT contained in the hard
8289  // process, we need to check the whole final state.
8290  if (isColSing && isFlavSing && !isHardSys) {
8291 
8292  // In a final check, ensure that the final state does not only
8293  // consist of colour singlets that are also flavour singlets
8294  // of the identical (!) flavours
8295  // Loop through event and save all final state partons
8296  vector<int> allFinal;
8297  for(int i=0; i < int(event.size()); ++i)
8298  if ( event[i].isFinal() )
8299  allFinal.push_back(i);
8300 
8301  // Check if all final partons form a colour singlet
8302  bool isFullColSing = isColSinglet(event,allFinal);
8303  // Check if all final partons form a flavour singlet
8304  bool isFullFlavSing = isFlavSinglet(event,allFinal,flav);
8305 
8306  // If all final quarks are of identical flavour,
8307  // no possible clustering should be discriminated.
8308  // Otherwise, disallow
8309  if (!isFullColSing || !isFullFlavSing)
8310  return false;
8311  }
8312  }
8313 
8314  // ISR PROBLEMS
8315 
8316  if (isISRg2qq && nInQuarkFlav + nOutQuarkFlav > 0) {
8317 
8318  // Easiest problem 1:
8319  // RECLUSTERED INITIAL STATE GLUON MATCHES FINAL STATE GLUON
8320  for(int i=0; i < int(gluon.size()); ++i) {
8321  if (event[gluon[i]].isFinal()
8322  && event[gluon[i]].col() == radBeforeCol
8323  && event[gluon[i]].acol() == radBeforeAcl)
8324  return false;
8325  }
8326 
8327  // Easiest problem 2:
8328  // RECLUSTERED INITIAL STATE GLUON MATCHES INITIAL STATE GLUON
8329  for(int i=0; i < int(gluon.size()); ++i) {
8330  if (event[gluon[i]].status() == -21
8331  && event[gluon[i]].acol() == radBeforeCol
8332  && event[gluon[i]].col() == radBeforeAcl)
8333  return false;
8334  }
8335 
8336  // Next-to-easiest problem 1:
8337  // RECLUSTERED INITIAL STATE GLUON MATCHES FINAL STATE Q-QBAR PAIR
8338  if ( int(radBeforeColP.size()) == 2
8339  && event[radBeforeColP[0]].isFinal()
8340  && event[radBeforeColP[1]].isFinal()
8341  && event[radBeforeColP[0]].id() == -1*event[radBeforeColP[1]].id() ) {
8342 
8343  // In principle, clustering this splitting can disconnect
8344  // the colour lines of a graph. However, the colours can be connected
8345  // again if final state partons of the correct (anti)flavour, or
8346  // initial state partons of the correct flavour exist
8347  // Loop through event to check
8348  bool clusPossible = false;
8349  for(int i=0; i < int(event.size()); ++i)
8350  if ( i != emt && i != rad
8351  && i != radBeforeColP[0]
8352  && i != radBeforeColP[1]
8353  && !mergingHooksPtr->hardProcess->matchesAnyOutgoing(i,event) ) {
8354  if (event[i].status() == -21
8355  && ( event[radBeforeColP[0]].id() == event[i].id()
8356  || event[radBeforeColP[1]].id() == event[i].id() ))
8357 
8358  clusPossible = true;
8359  if (event[i].isFinal()
8360  && ( event[radBeforeColP[0]].id() == -1*event[i].id()
8361  || event[radBeforeColP[1]].id() == -1*event[i].id() ))
8362  clusPossible = true;
8363  }
8364 
8365  // There can be a further complication: If e.g. in
8366  // t-channel photon exchange topologies, both incoming
8367  // partons are quarks, and form colour singlets with any
8368  // number of final state partons, at least try to
8369  // recluster as much as possible.
8370  // For this, check if the incoming parton
8371  // connected to the radiator is connected to a
8372  // colour and flavour singlet
8373  int incoming1 = 3;
8374  vector<int> excludeIn1;
8375  for(int i=0; i < 4; ++i)
8376  excludeIn1.push_back(0);
8377  vector<int> colSingletIn1;
8378  int flavIn1Type = (event[incoming1].id() > 0) ? 1 : -1;
8379  // Try finding colour singlets
8380  bool isColSingIn1 = getColSinglet(flavIn1Type,incoming1,event,
8381  excludeIn1,colSingletIn1);
8382  // Check if colour singlet also is a flavour singlet
8383  bool isFlavSingIn1 = isFlavSinglet(event,colSingletIn1);
8384 
8385  // Check if the incoming parton not
8386  // connected to the radiator is connected to a
8387  // colour and flavour singlet
8388  int incoming2 = 4;
8389  vector<int> excludeIn2;
8390  for(int i=0; i < 4; ++i)
8391  excludeIn2.push_back(0);
8392  vector<int> colSingletIn2;
8393  int flavIn2Type = (event[incoming2].id() > 0) ? 1 : -1;
8394  // Try finding colour singlets
8395  bool isColSingIn2 = getColSinglet(flavIn2Type,incoming2,event,
8396  excludeIn2,colSingletIn2);
8397  // Check if colour singlet also is a flavour singlet
8398  bool isFlavSingIn2 = isFlavSinglet(event,colSingletIn2);
8399 
8400  // If no "recovery clustering" is possible, reject clustering
8401  if (!clusPossible
8402  && (!isColSingIn1 || !isFlavSingIn1
8403  || !isColSingIn2 || !isFlavSingIn2))
8404  return false;
8405 
8406  }
8407 
8408  }
8409 
8410  // Done
8411  return allowed;
8412 }
8413 
8414 //--------------------------------------------------------------------------
8415 
8416 // Function to check if rad,emt,rec triple is results in
8417 // colour singlet radBefore+recBefore
8418 // IN int rad,emt,rec : Positions (in event record) of the three
8419 // particles considered for clustering
8420 // Event event : Reference event
8421 
8422 bool History::isSinglett( int rad, int emt, int rec, const Event& event ) {
8423 
8424  int radCol = event[rad].col();
8425  int emtCol = event[emt].col();
8426  int recCol = event[rec].col();
8427  int radAcl = event[rad].acol();
8428  int emtAcl = event[emt].acol();
8429  int recAcl = event[rec].acol();
8430  int recType = event[rec].isFinal() ? 1 : -1;
8431 
8432  bool isSing = false;
8433 
8434  if ( ( recType == -1
8435  && radCol + emtCol == recCol && radAcl + emtAcl == recAcl)
8436  ||( recType == 1
8437  && radCol + emtCol == recAcl && radAcl + emtAcl == recCol) )
8438  isSing = true;
8439 
8440  return isSing;
8441 
8442 }
8443 
8444 //--------------------------------------------------------------------------
8445 
8446 // Function to check if event is sensibly constructed: Meaning
8447 // that all colour indices are contracted and that the charge in
8448 // initial and final states matches
8449 // IN event : event to be checked
8450 // OUT TRUE : event is properly construced
8451 // FALSE : event not valid
8452 
8453 bool History::validEvent( const Event& event ) {
8454 
8455  // Check if event is coloured
8456  bool validColour = true;
8457  for ( int i = 0; i < event.size(); ++i)
8458  // Check colour of quarks
8459  if ( event[i].isFinal() && event[i].colType() == 1
8460  // No corresponding anticolour in final state
8461  && ( FindCol(event[i].col(),i,0,event,1,true) == 0
8462  // No corresponding colour in initial state
8463  && FindCol(event[i].col(),i,0,event,2,true) == 0 )) {
8464  validColour = false;
8465  break;
8466  // Check anticolour of antiquarks
8467  } else if ( event[i].isFinal() && event[i].colType() == -1
8468  // No corresponding colour in final state
8469  && ( FindCol(event[i].acol(),i,0,event,2,true) == 0
8470  // No corresponding anticolour in initial state
8471  && FindCol(event[i].acol(),i,0,event,1,true) == 0 )) {
8472  validColour = false;
8473  break;
8474  // No uncontracted colour (anticolour) charge of gluons
8475  } else if ( event[i].isFinal() && event[i].colType() == 2
8476  // No corresponding anticolour in final state
8477  && ( FindCol(event[i].col(),i,0,event,1,true) == 0
8478  // No corresponding colour in initial state
8479  && FindCol(event[i].col(),i,0,event,2,true) == 0 )
8480  // No corresponding colour in final state
8481  && ( FindCol(event[i].acol(),i,0,event,2,true) == 0
8482  // No corresponding anticolour in initial state
8483  && FindCol(event[i].acol(),i,0,event,1,true) == 0 )) {
8484  validColour = false;
8485  break;
8486  }
8487 
8488  // Check charge sum in initial and final state
8489  bool validCharge = true;
8490  double initCharge = event[3].charge() + event[4].charge();
8491  double finalCharge = 0.0;
8492  for(int i = 0; i < event.size(); ++i)
8493  if (event[i].isFinal()) finalCharge += event[i].charge();
8494  if (abs(initCharge-finalCharge) > 1e-12) validCharge = false;
8495 
8496  return (validColour && validCharge);
8497 
8498 }
8499 
8500 //--------------------------------------------------------------------------
8501 
8502 // Function to check whether two clusterings are identical, used
8503 // for finding the history path in the mother -> children direction
8504 
8505 bool History::equalClustering( Clustering clus1 , Clustering clus2 ) {
8506  return ( (clus1.emittor == clus2.emittor)
8507  && (clus1.emitted == clus2.emitted)
8508  && (clus1.recoiler == clus2.recoiler)
8509  && (clus1.partner == clus2.partner)
8510  && (clus1.pT() == clus2.pT())
8511  && (clus1.spinRadBef == clus2.spinRadBef)
8512  && (clus1.spinRad == clus2.spinRad)
8513  && (clus1.spinEmt == clus2.spinEmt)
8514  && (clus1.spinRec == clus2.spinRec)
8515  && (clus1.flavRadBef == clus2.flavRadBef));
8516 }
8517 
8518 //--------------------------------------------------------------------------
8519 
8520 // Chose dummy scale for event construction. By default, choose
8521 // sHat for 2->Boson(->2)+ n partons processes and
8522 // M_Boson for 2->Boson(->) processes
8523 
8524 double History::choseHardScale( const Event& event ) const {
8525 
8526  // Get sHat
8527  double mHat = (event[3].p() + event[4].p()).mCalc();
8528 
8529  // Find number of final state particles and bosons
8530  int nFinal = 0;
8531  int nFinBos= 0;
8532  int nBosons= 0;
8533  double mBos = 0.0;
8534  for(int i = 0; i < event.size(); ++i)
8535  if ( event[i].isFinal() ) {
8536  nFinal++;
8537  // Remember final state unstable bosons
8538  if ( event[i].idAbs() == 23
8539  || event[i].idAbs() == 24 ) {
8540  nFinBos++;
8541  nBosons++;
8542  mBos += event[i].m();
8543  }
8544  } else if ( abs(event[i].status()) == 22
8545  && ( event[i].idAbs() == 23
8546  || event[i].idAbs() == 24 )) {
8547  nBosons++;
8548  mBos += event[i].m(); // Real mass
8549  }
8550 
8551  // Return averaged boson masses
8552  if ( nBosons > 0 && (nFinal + nFinBos*2) <= 3)
8553  return (mBos / double(nBosons));
8554  else return
8555  mHat;
8556 }
8557 
8558 
8559 //--------------------------------------------------------------------------
8560 
8561 // If the state has an incoming hadron return the flavour of the
8562 // parton entering the hard interaction. Otherwise return 0
8563 
8564 int History::getCurrentFlav(const int side) const {
8565  int in = (side == 1) ? 3 : 4;
8566  return state[in].id();
8567 }
8568 
8569 //--------------------------------------------------------------------------
8570 
8571 double History::getCurrentX(const int side) const {
8572  int in = (side == 1) ? 3 : 4;
8573  return ( 2.*state[in].e()/state[0].e() );
8574 }
8575 
8576 //--------------------------------------------------------------------------
8577 
8578 double History::getCurrentZ(const int rad,
8579  const int rec, const int emt, int idRadBef) const {
8580 
8581  int type = state[rad].isFinal() ? 1 : -1;
8582  double z = 0.;
8583 
8584  if (type == 1) {
8585 
8586  Vec4 radAfterBranch(state[rad].p());
8587  Vec4 recAfterBranch(state[rec].p());
8588  Vec4 emtAfterBranch(state[emt].p());
8589 
8590  // Store masses both after and prior to emission.
8591  double m2RadAft = radAfterBranch.m2Calc();
8592  double m2EmtAft = emtAfterBranch.m2Calc();
8593  double m2RadBef = 0.;
8594  if ( state[rad].idAbs() != 21 && state[rad].idAbs() != 22
8595  && state[emt].idAbs() != 24 && state[rad].idAbs() != state[emt].idAbs())
8596  m2RadBef = m2RadAft;
8597  else if ( state[emt].idAbs() == 24) {
8598  if (idRadBef != 0)
8599  m2RadBef = pow2(particleDataPtr->m0(abs(idRadBef)));
8600  }
8601 
8602  double Qsq = (radAfterBranch + emtAfterBranch).m2Calc();
8603 
8604  // Calculate dipole invariant mass.
8605  double m2final
8606  = (radAfterBranch + recAfterBranch + emtAfterBranch).m2Calc();
8607  // More complicated for initial state recoiler.
8608  if ( !state[rec].isFinal() ){
8609  double mar2 = m2final - 2. * Qsq + 2. * m2RadBef;
8610  recAfterBranch *= (1. - (Qsq - m2RadBef)/(mar2 - m2RadBef))
8611  /(1. + (Qsq - m2RadBef)/(mar2 - m2RadBef));
8612  // If Qsq is larger than mar2 the event is not kinematically possible.
8613  // Just return random z, since clustering will be discarded.
8614  if (Qsq > mar2) return 0.5;
8615  }
8616 
8617  Vec4 sum = radAfterBranch + recAfterBranch + emtAfterBranch;
8618  double m2Dip = sum.m2Calc();
8619  // Construct 2->3 variables for FSR
8620  double x1 = 2. * (sum * radAfterBranch) / m2Dip;
8621  double x2 = 2. * (sum * recAfterBranch) / m2Dip;
8622 
8623  // Prepare for more complicated z definition for massive splittings.
8624  double lambda13 = sqrt( pow2(Qsq - m2RadAft - m2EmtAft )
8625  - 4.*m2RadAft*m2EmtAft);
8626  double k1 = ( Qsq - lambda13 + (m2EmtAft - m2RadAft ) ) / ( 2. * Qsq );
8627  double k3 = ( Qsq - lambda13 - (m2EmtAft - m2RadAft ) ) / ( 2. * Qsq );
8628  // Calculate z of splitting, different for FSR
8629  z = 1./ ( 1- k1 -k3) * ( x1 / (2.-x2) - k3);
8630 
8631  } else {
8632  // Construct momenta of dipole before/after splitting for ISR
8633  Vec4 qBR(state[rad].p() - state[emt].p() + state[rec].p());
8634  Vec4 qAR(state[rad].p() + state[rec].p());
8635  // Calculate z of splitting, different for ISR
8636  z = (qBR.m2Calc())/( qAR.m2Calc());
8637  }
8638 
8639  return z;
8640 
8641 }
8642 
8643 //--------------------------------------------------------------------------
8644 
8645 // Function to compute "pythia pT separation" from Particle input
8646 
8647 double History::pTLund(const Event& event, int rad, int emt, int rec,
8648  int ShowerType, int idRadBef) {
8649 
8650 
8651  Particle RadAfterBranch = event[rad];
8652  Particle EmtAfterBranch = event[emt];
8653  Particle RecAfterBranch = event[rec];
8654 
8655  // Use external shower for merging.
8656  if ( mergingHooksPtr->useShowerPlugin() ) {
8657  map<string,double> stateVars;
8658  bool isFSR = showers->timesPtr->isTimelike(event, rad, emt, rec, "");
8659  if (isFSR) {
8660  string name = showers->timesPtr->getSplittingName(event, rad, emt,
8661  rec).front();
8662  stateVars = showers->timesPtr->getStateVariables(event, rad, emt, rec,
8663  name);
8664  } else {
8665  string name = showers->spacePtr->getSplittingName(event, rad, emt,
8666  rec).front();
8667  stateVars = showers->spacePtr->getStateVariables(event, rad, emt, rec,
8668  name);
8669  }
8670 
8671  return ( (stateVars.size() > 0 && stateVars.find("t") != stateVars.end())
8672  ? sqrt(stateVars["t"]) : -1.0 );
8673  }
8674 
8675  // Save type: 1 = FSR pT definition, else ISR definition
8676  int Type = ShowerType;
8677  // Calculate virtuality of splitting
8678  int sign = (Type==1) ? 1 : -1;
8679  Vec4 Q(RadAfterBranch.p() + sign*EmtAfterBranch.p());
8680  double Qsq = sign * Q.m2Calc();
8681 
8682  // Construct 2->3 variables for FSR
8683  Vec4 radAft(RadAfterBranch.p());
8684  Vec4 recAft(RecAfterBranch.p());
8685  Vec4 emtAft(EmtAfterBranch.p());
8686 
8687  // Store masses both after and prior to emission.
8688  double m2RadAft = radAft.m2Calc();
8689  double m2EmtAft = emtAft.m2Calc();
8690 
8691  double m2RadBef = 0.;
8692  if ( RadAfterBranch.idAbs() != 21 && RadAfterBranch.idAbs() != 22
8693  && EmtAfterBranch.idAbs() != 24
8694  && RadAfterBranch.idAbs() != EmtAfterBranch.idAbs() )
8695  m2RadBef = m2RadAft;
8696  else if (EmtAfterBranch.idAbs() == 24) {
8697  if (idRadBef != 0)
8698  m2RadBef = pow2(particleDataPtr->m0(abs(idRadBef)));
8699  } else if (!RadAfterBranch.isFinal()) {
8700  if (RadAfterBranch.idAbs() == 21 && EmtAfterBranch.idAbs() != 21)
8701  m2RadBef = m2EmtAft;
8702  }
8703 
8704  // Calculate dipole invariant mass.
8705  double m2final = (radAft + recAft + emtAft).m2Calc();
8706  // More complicated for initial state recoiler.
8707  if ( !RecAfterBranch.isFinal() && RadAfterBranch.isFinal() ){
8708  double mar2 = m2final - 2. * Qsq + 2. * m2RadBef;
8709  recAft *= (1. - (Qsq - m2RadBef)/(mar2 - m2RadBef))
8710  /(1. + (Qsq - m2RadBef)/(mar2 - m2RadBef));
8711  // Reclustering not kinematically possible if Qsq is larger than mar2.
8712  if (Qsq > mar2) return 0.;
8713  }
8714 
8715  Vec4 sum = radAft + recAft + emtAft;
8716  double m2Dip = sum.m2Calc();
8717  double x1 = 2. * (sum * radAft) / m2Dip;
8718  double x2 = 2. * (sum * recAft) / m2Dip;
8719 
8720  // Construct momenta of dipole before/after splitting for ISR
8721  double q2BR = (RadAfterBranch.p() - EmtAfterBranch.p()
8722  + RecAfterBranch.p()).m2Calc();
8723  double q2AR = (RadAfterBranch.p() + RecAfterBranch.p()).m2Calc();
8724 
8725  // Prepare for more complicated z definition for massive splittings.
8726  double lambda13 = sqrt( pow2(Qsq - m2RadAft - m2EmtAft )
8727  - 4. * m2RadAft*m2EmtAft );
8728  double k1 = ( Qsq - lambda13 + (m2EmtAft - m2RadAft ) ) / ( 2. * Qsq );
8729  double k3 = ( Qsq - lambda13 - (m2EmtAft - m2RadAft ) ) / ( 2. * Qsq );
8730 
8731  // Calculate z of splitting, different for FSR and ISR
8732  double z = (Type==1) ? 1./ ( 1- k1 -k3) * ( x1 / (2.-x2) - k3)
8733  : q2BR / q2AR;
8734 
8735  // Separation of splitting, different for FSR and ISR
8736  double pTpyth = (Type==1) ? z*(1.-z) : (1.-z);
8737 
8738  // pT^2 = separation*virtuality
8739  if (Type == 1) pTpyth *= (Qsq - m2RadBef);
8740  else pTpyth *= Qsq;
8741 
8742  // Check for threshold in ISR, only relevant for c and b.
8743  // Use pT2 = (1 - z) * (Qsq + m^2).
8744  if ( Type != 1) {
8745  if ( (RadAfterBranch.idAbs() == 4 || EmtAfterBranch.idAbs() == 4)
8746  && RadAfterBranch.idAbs() != EmtAfterBranch.idAbs()) {
8747  if (pTpyth < 2 * pow2(particleDataPtr->m0(4)))
8748  pTpyth = (Qsq + pow2(particleDataPtr->m0(4)) ) * (1. - q2BR/q2AR);
8749  } else if ( (RadAfterBranch.idAbs() == 5 || EmtAfterBranch.idAbs() == 5)
8750  && RadAfterBranch.idAbs() != EmtAfterBranch.idAbs()) {
8751  if (pTpyth < 2 * pow2(particleDataPtr->m0(5)))
8752  pTpyth = (Qsq + pow2(particleDataPtr->m0(5)) ) * (1. - q2BR/q2AR);
8753  }
8754  }
8755 
8756  if ( pTpyth < 0. ) pTpyth = 0.;
8757 
8758  // Return pT
8759  return sqrt(pTpyth);
8760 
8761 }
8762 
8763 //--------------------------------------------------------------------------
8764 
8765 // Function to return the position of the initial line before (or after)
8766 // a single (!) splitting.
8767 
8768 int History::posChangedIncoming(const Event& event, bool before) {
8769 
8770  // Check for initial state splittings.
8771  // Consider a splitting to exist if both mother and sister were found.
8772  // Find sister
8773  int iSister = 0;
8774  for (int i =0; i < event.size(); ++i)
8775  if (event[i].status() == 43) {
8776  iSister = i;
8777  break;
8778  }
8779  // Find mother
8780  int iMother = 0;
8781  if (iSister > 0) iMother = event[iSister].mother1();
8782 
8783  // Initial state splitting has been found.
8784  if (iSister > 0 && iMother > 0) {
8785 
8786  // Find flavour, mother flavour
8787  int flavSister = event[iSister].id();
8788  int flavMother = event[iMother].id();
8789 
8790  // Find splitting flavour
8791  int flavDaughter = 0;
8792  if ( abs(flavMother) < 21 && flavSister == 21)
8793  flavDaughter = flavMother;
8794  else if ( flavMother == 21 && flavSister == 21)
8795  flavDaughter = flavMother;
8796  else if ( flavMother == 21 && abs(flavSister) < 21)
8797  flavDaughter = -1*flavSister;
8798  else if ( abs(flavMother) < 21 && abs(flavSister) < 21)
8799  flavDaughter = 21;
8800 
8801  // Find initial state (!) daughter
8802  int iDaughter = 0;
8803  for (int i =0; i < event.size(); ++i)
8804  if ( !event[i].isFinal()
8805  && event[i].mother1() == iMother
8806  && event[i].id() == flavDaughter )
8807  iDaughter = i;
8808 
8809  // Done for initial state splitting.
8810  if ( !before ) return iMother;
8811  else return iDaughter;
8812 
8813  }
8814 
8815  // Check for final state splittings with initial state recoiler.
8816  // Consider a splitting to exist if both mother and daughter were found.
8817  // Find new mother
8818  iMother = 0;
8819  for (int i =0; i < event.size(); ++i)
8820  if ( abs(event[i].status()) == 53 || abs(event[i].status()) == 54) {
8821  iMother = i;
8822  break;
8823  }
8824  // Find daughter
8825  int iDaughter = 0;
8826  if (iMother > 0) iDaughter = event[iMother].daughter1();
8827 
8828  // Done if final state splitting has been found.
8829  if (iDaughter > 0 && iMother > 0) {
8830 
8831  // Done for final state splitting.
8832  if ( !before ) return iMother;
8833  else return iDaughter;
8834 
8835  }
8836 
8837  // If no splitting has been found, return zero.
8838  return 0;
8839 
8840 }
8841 
8842 //--------------------------------------------------------------------------
8843 
8844 // Function to give back the ratio of PDFs and PDF * splitting kernels needed
8845 // to convert a splitting at scale pdfScale, chosen with running PDFs, to a
8846 // splitting chosen with PDFs at a fixed scale mu. As needed to properly count
8847 // emissions.
8848 
8849 double History::pdfFactor( const Event& event, const int type,
8850  double pdfScale, double mu ) {
8851 
8852  double weight = 1.;
8853 
8854  // Final state splittings
8855  if (type >= 3) {
8856 
8857  // Find new mother
8858  int iMother = 0;
8859  for (int i =0; i < event.size(); ++i)
8860  if ( abs(event[i].status()) == 53 || abs(event[i].status()) == 54) {
8861  iMother = i;
8862  break;
8863  }
8864  int flavMother = event[iMother].id();
8865 
8866  // Done if no initial state recoiler was found
8867  if ( iMother == 0 ) return 1.;
8868 
8869  // Find daughter
8870  int iDaughter = event[iMother].daughter1();
8871  int flavDaughter = event[iDaughter].id();
8872 
8873  // Find x values
8874  double xMother = 2.*event[iMother].e() / event[0].e();
8875  double xDaughter = 2.*event[iDaughter].e() / event[0].e();
8876 
8877  // Calculate PDF ratios
8878 
8879  int sideSplit = ( event[iMother].pz() > 0.) ? 1 : -1;
8880  double pdfDen1, pdfDen2, pdfNum1, pdfNum2;
8881  pdfDen1 = pdfDen2 = pdfNum1 = pdfNum2 = 1.;
8882  if ( sideSplit == 1 ) {
8883  // Find PDFs
8884  pdfDen1 = max(1e-15,beamA.xfISR(0, flavDaughter, xDaughter, pow2(mu)) );
8885  pdfNum1 = beamA.xfISR(0, flavDaughter, xDaughter, pow2(pdfScale) );
8886  pdfNum2 = beamA.xfISR(0, flavMother, xMother, pow2(mu) );
8887  pdfDen2 = max(1e-15,beamA.xfISR(0,flavMother, xMother, pow2(pdfScale)) );
8888  } else {
8889  // Find PDFs
8890  pdfDen1 = max(1e-15,beamB.xfISR(0, flavDaughter, xDaughter, pow2(mu)) );
8891  pdfNum1 = beamB.xfISR(0, flavDaughter, xDaughter, pow2(pdfScale) );
8892  pdfNum2 = beamB.xfISR(0, flavMother, xMother, pow2(mu) );
8893  pdfDen2 = max(1e-15,beamB.xfISR(0,flavMother, xMother, pow2(pdfScale)) );
8894  }
8895 
8896  // The magnitude of the PDF ratio in FSR is limited to one. If that was
8897  // the case, return one.
8898  if ( pdfDen2/pdfNum1 > 1. ) return 1.;
8899 
8900  // Calculate PDF weight to reweight emission to emission evaluated at
8901  // constant factorisation scale. No need to include the splitting kernel in
8902  // the weight, since it will drop out anyway.
8903  weight = (pdfNum1/pdfDen1) * (pdfNum2)/(pdfDen2);
8904 
8905  // Initial state splittings
8906  } else if (type == 2) {
8907 
8908  // Find sister
8909  int iSister = 0;
8910  for (int i =0; i < event.size(); ++i)
8911  if (event[i].status() == 43) {
8912  iSister = i;
8913  break;
8914  }
8915  int flavSister = event[iSister].id();
8916 
8917  // Find mother
8918  int iMother = event[iSister].mother1();
8919  int flavMother = event[iMother].id();
8920 
8921  // Find splitting flavour
8922  int flavDaughter = 0;
8923  if ( abs(flavMother) < 21 && flavSister == 21)
8924  flavDaughter = flavMother;
8925  else if ( flavMother == 21 && flavSister == 21)
8926  flavDaughter = flavMother;
8927  else if ( flavMother == 21 && abs(flavSister) < 21)
8928  flavDaughter = -1*flavSister;
8929  else if ( abs(flavMother) < 21 && abs(flavSister) < 21)
8930  flavDaughter = 21;
8931 
8932  // Find x values
8933  double xMother = 2.*event[iMother].e() / event[0].e();
8934 
8935  // Find initial state (!) daughter
8936  int iDaughter = 0;
8937  for (int i =0; i < event.size(); ++i)
8938  if ( !event[i].isFinal()
8939  && event[i].mother1() == iMother
8940  && event[i].id() == flavDaughter )
8941  iDaughter = i;
8942  double xDaughter = 2.*event[iDaughter].e() / event[0].e();
8943 
8944  // Calculate PDF weight to reweight emission to emission evaluated at
8945  // constant factorisation scale. No need to include the splitting kernel
8946  // in the weight, since it will drop out anyway.
8947  int sideSplit = ( event[iMother].pz() > 0.) ? 1 : -1;
8948  double ratio1 = getPDFratio( sideSplit, false, false, flavDaughter,
8949  xDaughter, pdfScale, flavDaughter, xDaughter, mu );
8950  double ratio2 = getPDFratio( sideSplit, false, false, flavMother,
8951  xMother, mu, flavMother, xMother, pdfScale );
8952 
8953  weight = ratio1*ratio2;
8954 
8955  // Do nothing for MPI
8956  } else {
8957  weight = 1.;
8958  }
8959 
8960  // Done
8961  return weight;
8962 }
8963 
8964 //--------------------------------------------------------------------------
8965 
8966 // Function giving the product of splitting kernels and PDFs so that the
8967 // resulting flavour is given by flav. This is used as a helper routine
8968 // to dgauss
8969 
8970 double History::integrand(int flav, double x, double scaleInt, double z) {
8971 
8972  // Declare constants
8973  double CF = 4./3.;
8974  double TR = 1./2.;
8975  double CA = 3.;
8976 
8977  double result = 0.;
8978 
8979  // Integrate NLL sudakov remainder
8980  if (flav==0) {
8981 
8982  AlphaStrong* as = mergingHooksPtr->AlphaS_ISR();
8983  double asNow = (*as).alphaS(z);
8984  result = 1./z *asNow*asNow* ( log(scaleInt/z) -3./2. );
8985 
8986  // Integrand for PDF ratios. Careful about factors if 1/z, since formulae
8987  // are expressed in terms if f(x,mu), while Pythia uses x*f(x,mu)!
8988  } else if (flav==21) {
8989 
8990  double measure1 = 1./(1. - z);
8991  double measure2 = 1.;
8992 
8993  double integrand1 =
8994  2.*CA
8995  * z * getPDFratio( 2, false, true, 21, x/z, scaleInt, 21, x, scaleInt )
8996  - 2.*CA;
8997 
8998  double integrand2 =
8999  // G -> G terms
9000  2.*CA *((1. -z)/z + z*(1.-z))
9001  * getPDFratio( 2, false, true, 21, x/z, scaleInt, 21, x, scaleInt )
9002  // G -> Q terms
9003  + CF * ((1+pow(1-z,2))/z)
9004  *( getPDFratio(2,false,true,1,x/z,scaleInt,21,x,scaleInt)
9005  + getPDFratio(2,false,true,-1,x/z,scaleInt,21,x,scaleInt)
9006  + getPDFratio(2,false,true,2,x/z,scaleInt,21,x,scaleInt)
9007  + getPDFratio(2,false,true,-2,x/z,scaleInt,21,x,scaleInt)
9008  + getPDFratio(2,false,true,3,x/z,scaleInt,21,x,scaleInt)
9009  + getPDFratio(2,false,true,-3,x/z,scaleInt,21,x,scaleInt)
9010  + getPDFratio(2,false,true,4,x/z,scaleInt,21,x,scaleInt)
9011  + getPDFratio(2,false,true,-4,x/z,scaleInt,21,x,scaleInt) );
9012 
9013  // Done
9014  result = integrand1*measure1 + integrand2*measure2;
9015 
9016  } else {
9017 
9018  double measure1 = 1./(1. -z);
9019  double measure2 = 1.;
9020 
9021  // Q -> Q terms
9022  double integrand1 =
9023  CF * (1+pow(z,2))
9024  * getPDFratio(2,false,true,flav,x/z,scaleInt,flav,x,scaleInt)
9025  - 2.*CF;
9026 
9027  // Q -> G terms
9028  double integrand2 =
9029  + TR * (pow(z,2) + pow(1-z,2))
9030  * getPDFratio(2,false,true,21,x/z,scaleInt,flav,x,scaleInt);
9031 
9032  // Done
9033  result = measure1*integrand1 + measure2*integrand2;
9034  }
9035 
9036  return result;
9037 
9038 }
9039 
9040 //--------------------------------------------------------------------------
9041 
9042 // Function providing a list of possible new flavours after a w emssion
9043 // from the input flavour.
9044 
9045 vector<int> History::posFlavCKM(int flav) {
9046 
9047  // absolute values!
9048  int flavAbs = abs(flav);
9049 
9050  vector<int> flavRadBefs;
9051  // (e,mu,tau)
9052  if (flavAbs > 10 && flavAbs % 2 == 1)
9053  flavRadBefs.push_back(flavAbs + 1);
9054  // (neutrinoes)
9055  else if (flavAbs > 10 && flavAbs % 2 == 0)
9056  flavRadBefs.push_back(flavAbs - 1);
9057  // Full CKM for quarks.
9058  else if (flavAbs < 10 && flavAbs % 2 == 1) {
9059  flavRadBefs.push_back(2);
9060  flavRadBefs.push_back(4);
9061  flavRadBefs.push_back(6);
9062  }
9063  else if (flavAbs < 10 && flavAbs % 2 == 0) {
9064  flavRadBefs.push_back(1);
9065  flavRadBefs.push_back(3);
9066  flavRadBefs.push_back(5);
9067  }
9068 
9069  // Return the possible flavours.
9070  return flavRadBefs;
9071 }
9072 
9073 //--------------------------------------------------------------------------
9074 
9075 // Check if the new flavour structure is possible.
9076 // If clusType is 1 final clustering is assumed, otherwise initial clustering
9077 // is assumed.
9078 
9079 bool History::checkFlavour(vector<int>& flavCounts, int flavRad,
9080  int flavRadBef, int clusType) {
9081 
9082  // Loop over event.
9083  for(int k = 0; k < 20; ++k) {
9084  // Find changes from this W emission.
9085  int cor = 0;
9086  if (abs(flavRad) == k) {
9087  cor = -1;
9088  if (flavRad < 0) cor = 1;
9089  }
9090 
9091  if (abs(flavRadBef) == k) {
9092  cor = 1;
9093  if (flavRadBef < 0) cor = -1;
9094  }
9095 
9096  // if flavour and flavRadBef is the same, no correction.
9097  if (flavRadBef == flavRad) cor = 0;
9098 
9099  // Check if flavour is consistent.
9100  if (clusType == 1) {
9101  if (flavCounts[k] + cor != 0) return false;
9102  }
9103  else
9104  if (flavCounts[k] - cor != 0) return false;
9105  }
9106 
9107  // No more checks.
9108  return true;
9109 
9110 }
9111 
9112 //--------------------------------------------------------------------------
9113 
9114 // Reverse the boost carried out by the ISR.
9115 // The three first momenta are given by the ME,
9116 // the last two are filled in by this function.
9117 void History::reverseBoostISR(Vec4& pMother, Vec4& pSister, Vec4& pPartner,
9118  Vec4& pDaughter, Vec4& pRecoiler, int sign, double eCM, double& phi ) {
9119 
9120  // Find rotation by phi that would have been done for a
9121  // splitting daughter -> mother + sister
9122  phi = pSister.phi();
9123  // Find rotation with -phi
9124  RotBstMatrix rot_by_mphi;
9125  rot_by_mphi.rot(0.,-phi);
9126  // Find rotation with +phi
9127  RotBstMatrix rot_by_pphi;
9128  rot_by_pphi.rot(0.,phi);
9129 
9130  // Get mother and partner x values
9131  // x1 after isr
9132  double x1 = 2. * pMother.e() / eCM;
9133  // x2 after isr
9134  double x2 = 2. * pPartner.e() / eCM;
9135 
9136  // Find z of the splitting
9137  Vec4 qDip( pMother - pSister);
9138  Vec4 qAfter(pMother + pPartner);
9139  Vec4 qBefore(qDip + pPartner);
9140  double z = qBefore.m2Calc() / qAfter.m2Calc();
9141 
9142  // Calculate e_CM^2 before the splitting.
9143  double x1New = z*x1; // x1 before isr
9144  double x2New = x2; // x2 before isr
9145  double sHat = x1New*x2New*eCM*eCM;
9146 
9147  // Construct daughter and recoiler momenta before the splitting.
9148  // (Note: For final result, only needs to be boosted into
9149  // frame with unchanged "recoiler" momentum)
9150  Vec4 pDaughterBef( 0., 0., sign*0.5*sqrt(sHat), 0.5*sqrt(sHat));
9151  Vec4 pRecoilerBef( 0., 0., -sign*0.5*sqrt(sHat), 0.5*sqrt(sHat));
9152 
9153  // Rotate momenta defined in the lab frame by phi
9154  pMother.rotbst( rot_by_mphi );
9155  pSister.rotbst( rot_by_mphi );
9156  pPartner.rotbst( rot_by_mphi );
9157 
9158  // Find boost from lab frame to rest frame of
9159  // off-shell daughter + on-shell recoiler dipole
9160  pDaughter.p( pMother - pSister);
9161  pRecoiler.p( pPartner );
9162  RotBstMatrix from_CM_to_DRoff;
9163  if (sign == 1)
9164  from_CM_to_DRoff.toCMframe(pDaughter, pRecoiler);
9165  else
9166  from_CM_to_DRoff.toCMframe(pRecoiler, pDaughter);
9167 
9168  // Rotate and boost all momenta to rest frame of off-shell daughter +
9169  // on-shell recoiler dipole
9170  pMother.rotbst( from_CM_to_DRoff );
9171  pPartner.rotbst( from_CM_to_DRoff );
9172  pSister.rotbst( from_CM_to_DRoff );
9173 
9174  // Find longitudinal boost from on-shell daughter + on-shell recoiler
9175  // dipole rest frame to the frame in which the recoiler momentum (x-value)
9176  // does not change in the splitting process.
9177  RotBstMatrix from_DR_to_CM;
9178  from_DR_to_CM.bst( 0., 0., sign*( x1New - x2New ) / ( x1New + x2New ) );
9179 
9180  // Boost all momenta into the "unchanged recoiler" frame, thereby
9181  // correcting for momentum mismatch by transferring the recoil to all
9182  // final state particles.
9183  pDaughterBef.rotbst( from_DR_to_CM );
9184  pRecoilerBef.rotbst( from_DR_to_CM );
9185 
9186  // Ensure that radiator and recoiler are massless to
9187  // very good accuracy.
9188  if ( abs(pRecoilerBef.mCalc()) > 1e-7 ) {
9189  double pzSign = (pRecoilerBef.pz() > 0.) ? 1. : -1.;
9190  double eRec = pRecoilerBef.e();
9191  pRecoilerBef.p(0., 0., pzSign*eRec, eRec);
9192  }
9193  if ( abs(pDaughterBef.mCalc()) > 1e-7 ) {
9194  double pzSign = (pDaughterBef.pz() > 0.) ? 1. : -1.;
9195  double eDau = pDaughterBef.e();
9196  pDaughterBef.p(0., 0., pzSign*eDau, eDau);
9197  }
9198 
9199  // Done.
9200  return;
9201 }
9202 
9203 
9204 //--------------------------------------------------------------------------
9205 
9206 // Check if an event reclustered into a 2 -> 2 dijet.
9207 // (Only enabled if W reclustering is used).
9208 bool History::isQCD2to2(const Event& event) {
9209 
9210  if (!mergingHooksPtr->doWeakClustering()) return false;
9211  //if (event.size() == 7) return true;
9212  //else return false;
9213  int nFinalPartons = 0, nFinal = 0;;
9214  for (int i = 0;i < event.size();++i)
9215  if (event[i].isFinal()) {
9216  nFinal++;
9217  if ( event[i].idAbs() < 10 || event[i].idAbs() == 21)
9218  nFinalPartons++;
9219  }
9220  if (nFinalPartons == 2 && nFinal == 2) return true;
9221  else return false;
9222 
9223 }
9224 
9225 //--------------------------------------------------------------------------
9226 
9227 
9228 // Check if an event reclustered into a 2 -> 1 Drell-Yan.
9229 // (Only enabled if W reclustering is used).
9230 bool History::isEW2to1(const Event& event) {
9231 
9232  if (!mergingHooksPtr->doWeakClustering()) return false;
9233 
9234  int nVector = 0;
9235  for (int i = 0;i < event.size();++i) {
9236  if (event[i].isFinal()) {
9237  if (event[i].idAbs() == 23 ||
9238  event[i].idAbs() == 24 ||
9239  event[i].idAbs() == 22) nVector++;
9240  else return false;
9241  }
9242  }
9243 
9244  // Only true if a single vector boson as outgoing process.
9245  if (nVector == 1) return true;
9246 
9247  // Done
9248  return false;
9249 
9250 }
9251 
9252 //--------------------------------------------------------------------------
9253 
9254 // Set selected child indices.
9255 void History::setSelectedChild() {
9256  if (mother == 0) return;
9257  for (int i = 0;i < int(mother->children.size());++i)
9258  if (mother->children[i] == this) mother->selectedChild = i;
9259  mother->setSelectedChild();
9260 }
9261 
9262 //--------------------------------------------------------------------------
9263 
9264 void History::setupSimpleWeakShower(int nSteps) {
9265 
9266  // Go back to original 2 to 2 process.
9267  if (selectedChild != -1) {
9268  children[selectedChild]->setupSimpleWeakShower(nSteps+1);
9269  return;
9270  }
9271 
9272  // Defining needed containers.
9273  vector<int> mode, fermionLines;
9274  vector<Vec4> mom;
9275  vector<pair<int,int> > dipoles;
9276 
9277  // Setup hard process.
9278  setupWeakHard(mode,fermionLines, mom);
9279 
9280  // Setup dipoles
9281  if (isQCD2to2(state)) {
9282  // Add dipoles.
9283  if (state[3].idAbs() < 10) dipoles.push_back(make_pair(3,4));
9284  if (state[4].idAbs() < 10) dipoles.push_back(make_pair(4,3));
9285  if (state[5].idAbs() < 10) dipoles.push_back(make_pair(5,6));
9286  if (state[6].idAbs() < 10) dipoles.push_back(make_pair(6,5));
9287  } else if (isEW2to1(state)) {
9288  if (state[3].idAbs() < 10) dipoles.push_back(make_pair(3,4));
9289  if (state[4].idAbs() < 10) dipoles.push_back(make_pair(4,3));
9290  }
9291 
9292  // Update the dipoles untill the desired number of emissions is reached.
9293  transferSimpleWeakShower(mode, mom, fermionLines, dipoles, nSteps);
9294 }
9295 
9296 //--------------------------------------------------------------------------
9297 
9298 // Update weak dipoles after an emission.
9299 void History::transferSimpleWeakShower(vector<int> &mode, vector<Vec4> &mom,
9300  vector<int> fermionLines, vector<pair<int,int> > &dipoles,
9301  int nSteps) {
9302 
9303  // store information in info pointer when reached last step.
9304  if (nSteps == 0) {
9305  infoPtr->setWeakModes(mode);
9306  infoPtr->setWeakDipoles(dipoles);
9307  infoPtr->setWeakMomenta(mom);
9308  infoPtr->setWeak2to2lines(fermionLines);
9309  return;
9310  }
9311 
9312  // Find the transfer map.
9313  map<int,int> stateTransfer;
9314  findStateTransfer(stateTransfer);
9315 
9316  // Update modes, fermion lines and dipoles.
9317  vector<int> modeNew = updateWeakModes(mode, stateTransfer);
9318  vector<int> fermionLinesNew = updateWeakFermionLines(fermionLines,
9319  stateTransfer);
9320  vector<pair<int, int> > dipolesNew = updateWeakDipoles(dipoles,
9321  stateTransfer);
9322 
9323  // Recursive call to transfer to desired final step.
9324  mother->transferSimpleWeakShower(modeNew, mom, fermionLinesNew, dipolesNew,
9325  nSteps - 1);
9326 }
9327 
9328 //--------------------------------------------------------------------------
9329 
9330 // Update the weak modes after an emission.
9331 vector<int> History::updateWeakModes(vector<int>& mode,
9332  map<int,int>& stateTransfer) {
9333 
9334  vector<int> modeNew(mode.size() + 1,0);
9335 
9336  // Update all modes not involved in emission.
9337  for (map<int,int>::iterator it = stateTransfer.begin();
9338  it != stateTransfer.end(); ++it)
9339  modeNew[it->second] = mode[it->first];
9340 
9341  modeNew[clusterIn.emitted] = mode[clusterIn.radBef];
9342 
9343  // Update splittings.
9344  // g -> q Q mark as s-channel.
9345  if (state[clusterIn.radBef].idAbs() == 21 &&
9346  mother->state[clusterIn.emittor].idAbs() != 21) {
9347  // Set FSR dipole to S-channel.
9348  if (state[clusterIn.radBef].status() > 0) modeNew[clusterIn.emittor] = 1;
9349  // Set ISR dipole depending on recoiler.
9350  else {
9351  if (modeNew[clusterIn.emittor] == 1);
9352  else if ( mother->state[clusterIn.recoiler].id() == 21)
9353  modeNew[clusterIn.emittor] = 2;
9354  else if ( mother->state[clusterIn.recoiler].id()
9355  == mother->state[clusterIn.emittor].id() )
9356  modeNew[clusterIn.emittor] = 4;
9357  else modeNew[clusterIn.emittor] = 3;
9358  }
9359  // Emitted is always FSR.
9360  modeNew[clusterIn.emitted] = 1;
9361  }
9362 
9363  // ISR q -> q g
9364  if (state[clusterIn.radBef].idAbs() < 10 &&
9365  mother->state[clusterIn.emittor].idAbs() == 21) {
9366  if (state[clusterIn.radBef].status() < 0) {
9367  modeNew[clusterIn.emitted] = 1;
9368  }
9369  }
9370 
9371  // gamma -> q Q mark as s-channel
9372  if (state[clusterIn.radBef].idAbs() == 22) {
9373  // Only FSR particles change to S-channel.
9374  if (state[clusterIn.radBef].status() > 0) modeNew[clusterIn.emittor] = 1;
9375  // Set ISR dipole depending on recoiler.
9376  else {
9377  if (modeNew[clusterIn.emittor] == 1);
9378  else if ( mother->state[clusterIn.recoiler].id() == 21)
9379  modeNew[clusterIn.emittor] = 2;
9380  else if ( mother->state[clusterIn.recoiler].id()
9381  == mother->state[clusterIn.emittor].id() )
9382  modeNew[clusterIn.emittor] = 4;
9383  else modeNew[clusterIn.emittor] = 3;
9384  }
9385  // Emitted is always FSR.
9386  modeNew[clusterIn.emitted] = 1;
9387  }
9388  return modeNew;
9389 }
9390 
9391 //--------------------------------------------------------------------------
9392 
9393 // Update the fermion lines for the 2 -> 2 process. This is needed for
9394 // the weak probabilities.
9395 vector<int> History::updateWeakFermionLines(vector<int> fermionLines,
9396  map<int,int>& stateTransfer) {
9397 
9398  // Update fermion lines to 2-to-2 process.
9399  if (!fermionLines.empty()) {
9400  // Initial state lines always goes back to radiator.
9401  fermionLines[0] = stateTransfer[fermionLines[0]];
9402  fermionLines[1] = stateTransfer[fermionLines[1]];
9403 
9404  // If not involved in splitting just update index.
9405  bool lines[2] = {false,false};
9406  if (fermionLines[2] != clusterIn.radBef)
9407  fermionLines[2] = stateTransfer[fermionLines[2]];
9408  else lines[0] = true;
9409  if (fermionLines[3] != clusterIn.radBef)
9410  fermionLines[3] = stateTransfer[fermionLines[3]];
9411  else lines[1] = true;
9412 
9413  // If involved in splitting follow the fermion line.
9414  for (int i = 0;i < 2; ++i) {
9415  if (lines[i]) {
9416  if (state[fermionLines[2 + i]].isQuark() ||
9417  state[fermionLines[2 + i]].isLepton()) {
9418  if (mother->state[clusterIn.emittor].isQuark() ||
9419  mother->state[clusterIn.emittor].isLepton())
9420  fermionLines[2 + i] = clusterIn.emittor;
9421  else fermionLines[2 + i] = clusterIn.emitted;
9422  }
9423  // Stop tracing if gluon splitting.
9424  else fermionLines[2 + i] = 0;
9425  }
9426  }
9427  }
9428  return fermionLines;
9429 }
9430 
9431 //--------------------------------------------------------------------------
9432 
9433 // Update the list of weak dipoles. This is needed to setup the PS correctly.
9434 vector<pair<int,int> > History::updateWeakDipoles(
9435  vector<pair<int,int> > &dipoles, map<int,int>& stateTransfer) {
9436 
9437  vector<pair<int,int> > dipolesNew;
9438  for (int i = 0;i < int(dipoles.size());++i) {
9439  int iRecNew = -1, iRadNew = -1;
9440 
9441  // Find new radiator.
9442  if (dipoles[i].first != clusterIn.radBef)
9443  iRadNew = stateTransfer[dipoles[i].first];
9444  // FSR emission follow the quark line.
9445  else if (state[clusterIn.radBef].status() > 0) {
9446  if (mother->state[clusterIn.emitted].id() ==
9447  state[clusterIn.radBef].id())
9448  iRadNew = clusterIn.emitted;
9449  else iRadNew = clusterIn.emittor;
9450  // OSR emission always choose the emittor.
9451  } else if (mother->state[clusterIn.emittor].idAbs() < 10)
9452  iRadNew = clusterIn.emittor;
9453 
9454  // If no radiator is found skip the dipole.
9455  if (iRadNew == -1) continue;
9456 
9457  // Find new recoiler
9458  if (dipoles[i].second != clusterIn.radBef)
9459  iRecNew = stateTransfer[dipoles[i].second];
9460  // FSR emission follow the quark line.
9461  else if (state[clusterIn.radBef].status() > 0) {
9462  // If g -> g g, choose the one with the highest invariant mass.
9463  if (mother->state[clusterIn.emitted].id() == 21 &&
9464  mother->state[clusterIn.emittor].id() == 21) {
9465  double m1 = (mother->state[clusterIn.emitted].p()
9466  + mother->state[iRadNew].p()).m2Calc();
9467  double m2 = (mother->state[clusterIn.emittor].p()
9468  + mother->state[iRadNew].p()).m2Calc();
9469  iRecNew = (m1 > m2) ? clusterIn.emitted : clusterIn.emittor;
9470  }
9471  // Otherwise choose matching flavour.
9472  else if (mother->state[clusterIn.emitted].id() ==
9473  state[clusterIn.radBef].id())
9474  iRecNew = clusterIn.emitted;
9475  else iRecNew = clusterIn.emittor;
9476  // ISR emission always choose the emittor.
9477  } else iRecNew = clusterIn.emittor;
9478 
9479  dipolesNew.push_back(make_pair(iRadNew,iRecNew));
9480  }
9481 
9482  // If g -> q qbar add new dipoles.
9483  if (state[clusterIn.radBef].idAbs() == 21 &&
9484  mother->state[clusterIn.emittor].idAbs() != 21) {
9485  // FSR.
9486  if (state[clusterIn.radBef].status() > 0) {
9487  dipolesNew.push_back(make_pair(clusterIn.emittor,clusterIn.emitted));
9488  dipolesNew.push_back(make_pair(clusterIn.emitted,clusterIn.emittor));
9489  // ISR.
9490  } else {
9491  int iRad = clusterIn.emittor;
9492  int iRec = (iRad == 3) ? 4 : 3;
9493  dipolesNew.push_back(make_pair(iRad,iRec));
9494  dipolesNew.push_back(make_pair(clusterIn.emitted,findISRRecoiler()));
9495  }
9496  }
9497 
9498  // if an ISR quark goes into a gluon.
9499  if (state[clusterIn.radBef].idAbs() < 10 &&
9500  mother->state[clusterIn.emittor].idAbs() == 21 &&
9501  state[clusterIn.radBef].status() < 0)
9502  dipolesNew.push_back(make_pair(clusterIn.emitted,findISRRecoiler()));
9503 
9504  return dipolesNew;
9505 }
9506 
9507 //--------------------------------------------------------------------------
9508 
9509 // Setup the hard process information needed for calculating weak probabilities
9510 // and setting up the shower.
9511 void History::setupWeakHard(vector<int>& mode, vector<int>& fermionLines,
9512  vector<Vec4>& mom) {
9513 
9514  if (!isQCD2to2(state)) {
9515  // Not a 2 -> 2 process, mark everything as s-channel.
9516  mode.resize(state.size(), 1);
9517  } else {
9518 
9519  // Store momenta.
9520  for (int i = 0;i < 4; ++i) {
9521  mom.push_back(state[3 + i].p());
9522  fermionLines.push_back(3 + i);
9523  }
9524  // All gluon case, everything is s-channel.
9525  if ( state[3].idAbs() == 21 && state[4].idAbs() == 21 &&
9526  state[5].idAbs() == 21 && state[6].idAbs() == 21)
9527  mode.resize(state.size(), 1);
9528 
9529  // s-channel if quark-anti quark final state or gluon final state.
9530  else if (state[5].id() == -state[6].id() ||
9531  (state[5].idAbs() == 21 && state[6].idAbs() == 21))
9532  mode.resize(state.size(), 1);
9533 
9534  // t-channel gluon.
9535  else if (state[5].idAbs() == 21 || state[6].idAbs() == 21) {
9536  mode.resize(state.size(), 2);
9537  if (state[3].id() != state[5].id()) {
9538  swap(mom[0], mom[1]);
9539  swap(mom[2], mom[3]);
9540  }
9541  }
9542 
9543  // Double (different) quark t-channel.
9544  else if (state[5].id() != state[6].id()) {
9545  mode.resize(state.size(), 3);
9546  if (state[3].id() != state[5].id()) {
9547  swap(mom[0], mom[1]);
9548  swap(mom[2], mom[3]);
9549  }
9550  }
9551 
9552  // 4 quarks of the same type.
9553  // (might need to try both combinations).
9554  else if (state[5].id() == state[6].id()) {
9555  mode.resize(state.size(), 4);
9556  }
9557  }
9558 }
9559 
9560 //--------------------------------------------------------------------------
9561 
9562 // Function to retrieve scale information from external showers.
9563 
9564 double History::getShowerPluginScale(const Event& event, int rad, int emt,
9565  int rec, string key, double scalePythia) {
9566 
9567  // Done if no shower plugin is used.
9568  if ( !mergingHooksPtr->useShowerPlugin() ) return scalePythia;
9569 
9570  // Retrieve state variables.
9571  map<string,double> stateVars;
9572  bool isFSR = showers->timesPtr->isTimelike(event, rad, emt, rec, "");
9573  if (isFSR) {
9574  string name = showers->timesPtr->getSplittingName(event, rad, emt,
9575  rec).front();
9576  stateVars = showers->timesPtr->getStateVariables(event, rad, emt, rec,
9577  name);
9578  } else {
9579  string name = showers->spacePtr->getSplittingName(event, rad, emt,
9580  rec).front();
9581  stateVars = showers->spacePtr->getStateVariables(event, rad, emt, rec,
9582  name);
9583  }
9584 
9585  return ( (stateVars.size() > 0 && stateVars.find(key) != stateVars.end())
9586  ? stateVars[key] : -1.0 );
9587 
9588 }
9589 
9590 //==========================================================================
9591 
9592 } // end namespace Pythia8
Definition: AgUStep.h:26