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) 2014 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL version 2, 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 
12 namespace Pythia8 {
13 
14 //==========================================================================
15 
16 // The Clustering class.
17 
18 //--------------------------------------------------------------------------
19 
20 // Declaration of Clustering class
21 // This class holds information about one radiator, recoiler,
22 // emitted system.
23 // This class is a container class for History class use.
24 
25 // print for debug
26 void Clustering::list() const {
27  cout << " emt " << emitted
28  << " rad " << emittor
29  << " rec " << recoiler
30  << " partner " << partner
31  << " pTscale " << pTscale << endl;
32 }
33 
34 //==========================================================================
35 
36 // The History class.
37 
38 // A History object represents an event in a given step in the CKKW-L
39 // clustering procedure. It defines a tree-like recursive structure,
40 // where the root node represents the state with n jets as given by
41 // the matrix element generator, and is characterized by the member
42 // variable mother being null. The leaves on the tree corresponds to a
43 // fully clustered paths where the original n-jets has been clustered
44 // down to the Born-level state. Also states which cannot be clustered
45 // down to the Born-level are possible - these will be called
46 // incomplete. The leaves are characterized by the vector of children
47 // being empty.
48 
49 //--------------------------------------------------------------------------
50 
51 // Number of trial emission to use for calculating the average number of
52 // emissions
53 const int History::NTRIAL = 1;
54 
55 //--------------------------------------------------------------------------
56 
57 // Declaration of History class
58 // The only constructor. Default arguments are used when creating
59 // the initial history node. The \a depth is the maximum number of
60 // clusterings requested. \a scalein is the scale at which the \a
61 // statein was clustered (should be set to the merging scale for the
62 // initial history node. \a beamAIn and beamBIn are needed to
63 // calcutate PDF ratios, \a particleDataIn to have access to the
64 // correct masses of particles. If \a isOrdered is true, the previous
65 // clusterings has been ordered. \a is the PDF ratio for this
66 // clustering (=1 for FSR clusterings). \a probin is the accumulated
67 // probabilities for the previous clusterings, and \ mothin is the
68 // previous history node (null for the initial node).
69 
70 History::History( int depth,
71  double scalein,
72  Event statein,
73  Clustering c,
74  MergingHooks* mergingHooksPtrIn,
75  BeamParticle beamAIn,
76  BeamParticle beamBIn,
77  ParticleData* particleDataPtrIn,
78  Info* infoPtrIn,
79  bool isOrdered = true,
80  bool isStronglyOrdered = true,
81  bool isAllowed = true,
82  bool isNextInInput = true,
83  double probin = 1.0,
84  History * mothin = 0)
85  : state(statein),
86  mother(mothin),
87  sumpath(0.0),
88  sumGoodBranches(0.0),
89  sumBadBranches(0.0),
90  foundOrderedPath(false),
91  foundStronglyOrderedPath(false),
92  foundAllowedPath(false),
93  foundCompletePath(false),
94  scale(scalein),
95  nextInInput(isNextInInput),
96  prob(probin),
97  clusterIn(c),
98  iReclusteredOld(0),
99  doInclude(true),
100  mergingHooksPtr(mergingHooksPtrIn),
101  beamA(beamAIn),
102  beamB(beamBIn),
103  particleDataPtr(particleDataPtrIn),
104  infoPtr(infoPtrIn)
105  {
106 
107  // Initialise beam particles
108  setupBeams();
109  // Update probability with PDF ratio
110  if (mother && mergingHooksPtr->includeRedundant()) prob *= pdfForSudakov();
111 
112  // Minimal scalar sum of pT used in Herwig to choose history
113  // Keep track of scalar PT
114  if (mother) {
115  double acoll = (mother->state[clusterIn.emittor].isFinal())
116  ? mergingHooksPtr->herwigAcollFSR()
117  : mergingHooksPtr->herwigAcollISR();
118  sumScalarPT = mother->sumScalarPT + acoll*scale;
119  } else
120  sumScalarPT = 0.0;
121 
122  // Remember reclustered radiator in lower multiplicity state
123  if ( mother ) iReclusteredOld = mother->iReclusteredNew;
124 
125  // Check if more steps should be taken.
126  int nFinalP = 0;
127  int nFinalW = 0;
128  for ( int i = 0; i < int(state.size()); ++i )
129  if ( state[i].isFinal() ) {
130  if ( state[i].colType() != 0 )
131  nFinalP++;
132  if ( state[i].idAbs() == 24 )
133  nFinalW++;
134  }
135  if ( mergingHooksPtr->doWClustering()
136  && nFinalP == 2 && nFinalW == 0 ) depth = 0;
137 
138  // If this is not the fully clustered state, try to find possible
139  // QCD clusterings.
140  vector<Clustering> clusterings;
141  if ( depth > 0 ) clusterings = getAllQCDClusterings();
142 
143  // If necessary, try to find possible EW clusterings.
144  vector<Clustering> clusteringsEW;
145  if ( depth > 0 && mergingHooksPtr->doWClustering() )
146  clusteringsEW = getAllEWClusterings();
147  if ( !clusteringsEW.empty() ) {
148  clusterings.resize(0);
149  clusterings.insert( clusterings.end(), clusteringsEW.begin(),
150  clusteringsEW.end() );
151  }
152 
153  // If necessary, try to find possible SQCD clusterings.
154  vector<Clustering> clusteringsSQCD;
155  if ( depth > 0 && mergingHooksPtr->doSQCDClustering() )
156  clusteringsSQCD = getAllSQCDClusterings();
157  if ( !clusteringsSQCD.empty() )
158  clusterings.insert( clusterings.end(), clusteringsSQCD.begin(),
159  clusteringsSQCD.end() );
160 
161  // If no clusterings were found, the recursion is done and we
162  // register this node.
163  if ( clusterings.empty() ) {
164  // Multiply with hard process matrix element.
165  prob *= hardProcessME(state);
166  registerPath( *this, isOrdered, isStronglyOrdered, isAllowed, depth == 0 );
167  return;
168  }
169 
170  // Now we sort the possible clusterings so that we try the
171  // smallest scale first.
172  multimap<double, Clustering *> sorted;
173  for ( int i = 0, N = clusterings.size(); i < N; ++i ) {
174  sorted.insert(make_pair(clusterings[i].pT(), &clusterings[i]));
175  }
176 
177  for ( multimap<double, Clustering *>::iterator it = sorted.begin();
178  it != sorted.end(); ++it ) {
179 
180  // If this path is not strongly ordered and we already have found an
181  // ordered path, then we don't need to continue along this path.
182  bool stronglyOrdered = isStronglyOrdered;
183  if ( mergingHooksPtr->enforceStrongOrdering()
184  && ( !stronglyOrdered
185  || ( mother && ( it->first <
186  mergingHooksPtr->scaleSeparationFactor()*scale ) ))) {
187  if ( onlyStronglyOrderedPaths() ) continue;
188  stronglyOrdered = false;
189  }
190 
191  // Check if reclustering follows ordered sequence.
192  bool ordered = isOrdered;
193  if ( mergingHooksPtr->orderInRapidity()
194  && mergingHooksPtr->orderHistories() ) {
195  // Get new z value
196  double z = getCurrentZ((*it->second).emittor,
197  (*it->second).recoiler,(*it->second).emitted);
198  // Get z value of splitting that produced this state
199  double zOld = (!mother) ? 0. : mother->getCurrentZ(clusterIn.emittor,
200  clusterIn.recoiler,clusterIn.emitted);
201  // If this path is not ordered in pT and y, and we already have found
202  // an ordered path, then we don't need to continue along this path.
203  if ( !ordered || ( mother && (it->first < scale
204  || it->first < pow(1. - z,2) / (z * (1. - zOld ))*scale ))) {
205  if ( onlyOrderedPaths() ) continue;
206  ordered = false;
207  }
208 
209  } else if ( mergingHooksPtr->orderHistories() ) {
210  // If this path is not ordered in pT and we already have found an
211  // ordered path, then we don't need to continue along this path, unless
212  // we have not yet found an allowed path.
213  if ( !ordered || ( mother && (it->first < scale) ) ) {
214  if ( onlyOrderedPaths() && onlyAllowedPaths() ) continue;
215  ordered = false;
216  }
217  }
218 
219  // Check if reclustered state should be disallowed.
220  bool doCut = mergingHooksPtr->canCutOnRecState()
221  || mergingHooksPtr->allowCutOnRecState();
222  bool allowed = isAllowed;
223  if ( doCut
224  && mergingHooksPtr->doCutOnRecState(cluster(*it->second)) ) {
225  if ( onlyAllowedPaths() ) continue;
226  allowed = false;
227  }
228 
229  // Perform the clustering and recurse and construct the next
230  // history node.
231  children.push_back(new History(depth - 1,it->first,cluster(*it->second),
232  *it->second, mergingHooksPtr, beamA, beamB, particleDataPtr,
233  infoPtr, ordered, stronglyOrdered, allowed, true,
234  prob*getProb(*it->second), this ));
235  }
236 }
237 
238 //--------------------------------------------------------------------------
239 
240 // Function to project all possible paths onto only the desired paths.
241 
242 bool History::projectOntoDesiredHistories() {
243  // At the moment, only trim histories.
244  return trimHistories();
245 }
246 
247 //--------------------------------------------------------------------------
248 
249 // In the initial history node, select one of the paths according to
250 // the probabilities. This function should be called for the initial
251 // history node.
252 // IN trialShower* : Previously initialised trialShower object,
253 // to perform trial showering and as
254 // repository of pointers to initialise alphaS
255 // PartonSystems* : PartonSystems object needed to initialise
256 // shower objects
257 // OUT double : (Sukadov) , (alpha_S ratios) , (PDF ratios)
258 
259 double History::weightTREE(PartonLevel* trial, AlphaStrong * asFSR,
260  AlphaStrong * asISR, double RN) {
261 
262  if ( mergingHooksPtr->canCutOnRecState() && !foundAllowedPath ) {
263  string message="Warning in History::weightTREE: No allowed history";
264  message+=" found. Using disallowed history.";
265  infoPtr->errorMsg(message);
266  }
267  if ( mergingHooksPtr->orderHistories() && !foundOrderedPath ) {
268  string message="Warning in History::weightTREE: No ordered history";
269  message+=" found. Using unordered history.";
270  infoPtr->errorMsg(message);
271  }
272  if ( mergingHooksPtr->canCutOnRecState()
273  && mergingHooksPtr->orderHistories()
274  && !foundAllowedPath && !foundOrderedPath ) {
275  string message="Warning in History::weightTREE: No allowed or ordered";
276  message+=" history found.";
277  infoPtr->errorMsg(message);
278  }
279 
280  // Read alpha_S in ME calculation and maximal scale (eCM)
281  double asME = infoPtr->alphaS();
282  double maxScale = (foundCompletePath) ? infoPtr->eCM()
283  : mergingHooksPtr->muFinME();
284  // Select a path of clusterings
285  History * selected = select(RN);
286  // Set scales in the states to the scales pythia would have set
287  selected->setScalesInHistory();
288 
289  // Get weight.
290  double asWeight = 1.;
291  double pdfWeight = 1.;
292 
293  // Do trial shower, calculation of alpha_S ratios, PDF ratios
294  double wt = selected->weightTree( trial, asME, maxScale,
295  selected->clusterIn.pT(), asFSR, asISR, asWeight,
296  pdfWeight );
297 
298  // MPI no-emission probability
299  int njetsMaxMPI = mergingHooksPtr->nMinMPI();
300  double mpiwt = selected->weightTreeEmissions( trial, -1, njetsMaxMPI,
301  maxScale );
302 
303  // Set hard process renormalisation scale to default Pythia value.
304  bool resetScales = mergingHooksPtr->resetHardQRen();
305  // For pure QCD dijet events, evaluate the coupling of the hard process at
306  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
307  // arbitrary scale.
308  if ( resetScales
309  && mergingHooksPtr->getProcessString().compare("pp>jj") == 0) {
310  // Reset to a running coupling. Here we choose FSR for simplicity.
311  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
312  double runningCoupling = (*asFSR).alphaS(newQ2Ren) / asME;
313  asWeight *= pow2(runningCoupling);
314  }
315 
316  // For prompt photon events, evaluate the coupling of the hard process at
317  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
318  // arbitrary scale.
319  if ( resetScales
320  && mergingHooksPtr->getProcessString().compare("pp>aj") == 0) {
321  // Reset to a running coupling. In prompt photon always ISR.
322  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
323  double runningCoupling =
324  (*asISR).alphaS( newQ2Ren + pow(mergingHooksPtr->pT0ISR(),2) ) / asME;
325  asWeight *= runningCoupling;
326  }
327 
328  // Done
329  return (wt*asWeight*pdfWeight*mpiwt);
330 
331 }
332 
333 //--------------------------------------------------------------------------
334 
335 // Function to return weight of virtual correction and subtractive events
336 // for NL3 merging
337 
338 double History::weightLOOP(PartonLevel* trial, double RN ) {
339 
340  if ( mergingHooksPtr->canCutOnRecState() && !foundAllowedPath ) {
341  string message="Warning in History::weightLOOP: No allowed history";
342  message+=" found. Using disallowed history.";
343  infoPtr->errorMsg(message);
344  }
345 
346  // Select a path of clusterings
347  History * selected = select(RN);
348  // Set scales in the states to the scales pythia would have set
349  selected->setScalesInHistory();
350 
351  // So far, no reweighting
352  double wt = 1.;
353 
354  // Only reweighting with MPI no-emission probability
355  double maxScale = (foundCompletePath) ? infoPtr->eCM()
356  : mergingHooksPtr->muFinME();
357  int njetsMaxMPI = mergingHooksPtr->nMinMPI();
358  double mpiwt = selected->weightTreeEmissions( trial, -1, njetsMaxMPI,
359  maxScale );
360  wt = mpiwt;
361  // Done
362  return wt;
363 }
364 
365 //--------------------------------------------------------------------------
366 
367 // Function to calculate O(\alpha_s)-term of CKKWL-weight for NLO merging
368 
369 double History::weightFIRST(PartonLevel* trial, AlphaStrong* asFSR,
370  AlphaStrong* asISR, double RN, Rndm* rndmPtr ) {
371 
372  // Read alpha_S in ME calculation and maximal scale (eCM)
373  double asME = infoPtr->alphaS();
374  double muR = mergingHooksPtr->muRinME();
375  double maxScale = (foundCompletePath)
376  ? infoPtr->eCM()
377  : mergingHooksPtr->muFinME();
378 
379  // Pick path of clusterings
380  History * selected = select(RN);
381  // Set scales in the states to the scales pythia would have set
382  selected->setScalesInHistory();
383 
384  double nSteps = mergingHooksPtr->getNumberOfClusteringSteps(state);
385 
386  // Get the lowest order k-factor and add first two terms in expansion
387  double kFactor = asME * mergingHooksPtr->k1Factor(nSteps);
388 
389  // If using Bbar, which includes a tree-level part, subtract an
390  // additional one, i.e. the O(\as^0) contribution as well
391  double wt = 1. + kFactor;
392 
393  // Calculate sum of O(alpha) terms
394  wt += selected->weightFirst(trial,asME, muR, maxScale, asFSR, asISR,
395  rndmPtr );
396 
397  // Get starting scale for trial showers.
398  double startingScale = (selected->mother) ? state.scale() : infoPtr->eCM();
399 
400  // Count emissions: New variant
401  // Generate true average, not only one-point
402  bool fixpdf = true;
403  bool fixas = true;
404  double nWeight1 = 0.;
405  for(int i=0; i < NTRIAL; ++i) {
406  // Get number of emissions
407  vector<double> unresolvedEmissionTerm = countEmissions( trial,
408  startingScale, mergingHooksPtr->tms(), 2, asME, asFSR, asISR, 3,
409  fixpdf, fixas );
410  nWeight1 += unresolvedEmissionTerm[1];
411  }
412 
413  wt += nWeight1/double(NTRIAL);
414 
415  // Done
416  return wt;
417 
418 }
419 
420 //--------------------------------------------------------------------------
421 
422 double History::weight_UMEPS_TREE(PartonLevel* trial, AlphaStrong * asFSR,
423  AlphaStrong * asISR, double RN) {
424  // No difference to CKKW-L. Recycle CKKW-L function.
425  return weightTREE( trial, asFSR, asISR, RN);
426 }
427 
428 //--------------------------------------------------------------------------
429 
430 // Function to return weight of virtual correction events for NLO merging
431 
432 double History::weight_UMEPS_SUBT(PartonLevel* trial, AlphaStrong * asFSR,
433  AlphaStrong * asISR, double RN ) {
434 
435  // Read alpha_S in ME calculation and maximal scale (eCM)
436  double asME = infoPtr->alphaS();
437  double maxScale = (foundCompletePath) ? infoPtr->eCM()
438  : mergingHooksPtr->muFinME();
439  // Select a path of clusterings
440  History * selected = select(RN);
441  // Set scales in the states to the scales pythia would have set
442  selected->setScalesInHistory();
443 
444  // Get weight.
445  double asWeight = 1.;
446  double pdfWeight = 1.;
447 
448  // Do trial shower, calculation of alpha_S ratios, PDF ratios
449  double sudakov = selected->weightTree(trial, asME, maxScale,
450  selected->clusterIn.pT(), asFSR, asISR,
451  asWeight, pdfWeight);
452 
453  // MPI no-emission probability.
454  int njetsMaxMPI = mergingHooksPtr->nMinMPI()+1;
455  double mpiwt = selected->weightTreeEmissions( trial, -1, njetsMaxMPI,
456  maxScale );
457 
458  // Set hard process renormalisation scale to default Pythia value.
459  bool resetScales = mergingHooksPtr->resetHardQRen();
460  // For pure QCD dijet events, evaluate the coupling of the hard process at
461  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
462  // arbitrary scale.
463  if ( resetScales
464  && mergingHooksPtr->getProcessString().compare("pp>jj") == 0) {
465  // Reset to a running coupling. Here we choose FSR for simplicity.
466  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
467  double runningCoupling = (*asFSR).alphaS(newQ2Ren) / asME;
468  asWeight *= pow(runningCoupling,2);
469  }
470 
471  // For prompt photon events, evaluate the coupling of the hard process at
472  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
473  // arbitrary scale.
474  if ( resetScales
475  && mergingHooksPtr->getProcessString().compare("pp>aj") == 0) {
476  // Reset to a running coupling. In prompt photon always ISR.
477  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
478  double runningCoupling =
479  (*asISR).alphaS( newQ2Ren + pow(mergingHooksPtr->pT0ISR(),2) ) / asME;
480  asWeight *= runningCoupling;
481  }
482 
483  // Done
484  return (asWeight*pdfWeight*sudakov*mpiwt);
485 
486 }
487 
488 //--------------------------------------------------------------------------
489 
490 double History::weight_UNLOPS_TREE(PartonLevel* trial, AlphaStrong * asFSR,
491  AlphaStrong * asISR, double RN) {
492 
493  // Read alpha_S in ME calculation and maximal scale (eCM)
494  double asME = infoPtr->alphaS();
495  double maxScale = (foundCompletePath) ? infoPtr->eCM()
496  : mergingHooksPtr->muFinME();
497  // Select a path of clusterings
498  History * selected = select(RN);
499  // Set scales in the states to the scales pythia would have set
500  selected->setScalesInHistory();
501 
502  // Get weight.
503  double asWeight = 1.;
504  double pdfWeight = 1.;
505 
506  // Do trial shower, calculation of alpha_S ratios, PDF ratios
507  double wt = selected->weightTree(trial, asME, maxScale,
508  selected->clusterIn.pT(), asFSR, asISR, asWeight, pdfWeight);
509  // MPI no-emission probability.
510  int njetsMaxMPI = mergingHooksPtr->nMinMPI();
511  double mpiwt = selected->weightTreeEmissions( trial, -1, njetsMaxMPI,
512  maxScale );
513 
514  // Set hard process renormalisation scale to default Pythia value.
515  bool resetScales = mergingHooksPtr->resetHardQRen();
516  // For pure QCD dijet events, evaluate the coupling of the hard process at
517  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
518  // arbitrary scale.
519  if ( resetScales
520  && mergingHooksPtr->getProcessString().compare("pp>jj") == 0) {
521  // Reset to a running coupling. Here we choose FSR for simplicity.
522  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
523  double runningCoupling = (*asFSR).alphaS(newQ2Ren) / asME;
524  asWeight *= pow(runningCoupling,2);
525  }
526 
527  // For prompt photon events, evaluate the coupling of the hard process at
528  // a more reasonable pT, rather than evaluation \alpha_s at a fixed
529  // arbitrary scale.
530  if ( resetScales
531  && mergingHooksPtr->getProcessString().compare("pp>aj") == 0) {
532  // Reset to a running coupling. In prompt photon always ISR.
533  double newQ2Ren = pow2( selected->hardRenScale(selected->state) );
534  double runningCoupling =
535  (*asISR).alphaS( newQ2Ren + pow(mergingHooksPtr->pT0ISR(),2) ) / asME;
536  asWeight *= runningCoupling;
537  }
538 
539  // Done
540  return (wt*asWeight*pdfWeight*mpiwt);
541 
542 }
543 
544 //--------------------------------------------------------------------------
545 
546 double History::weight_UNLOPS_LOOP(PartonLevel* trial, double RN ) {
547  // No difference to default NL3
548  return weightLOOP(trial, RN );
549 }
550 
551 //--------------------------------------------------------------------------
552 
553 double History::weight_UNLOPS_SUBT(PartonLevel* trial, AlphaStrong * asFSR,
554  AlphaStrong * asISR, double RN ) {
555 
556  // Select a path of clusterings
557  History * selected = select(RN);
558  // Set scales in the states to the scales pythia would have set
559  selected->setScalesInHistory();
560  // So far, no reweighting
561  double wt = 1.;
562 
563  // Read alpha_S in ME calculation and maximal scale (eCM)
564  double asME = infoPtr->alphaS();
565  double maxScale = (foundCompletePath)
566  ? infoPtr->eCM()
567  : mergingHooksPtr->muFinME();
568 
569  // Only allow two clusterings if all intermediate states above the
570  // merging scale.
571  double nSteps = mergingHooksPtr->getNumberOfClusteringSteps(state);
572  if ( nSteps == 2 && mergingHooksPtr->nRecluster() == 2
573  && ( !foundCompletePath
574  || !selected->allIntermediateAboveRhoMS( mergingHooksPtr->tms() )) ) {
575  return 0.;
576  }
577 
578  // Get weights: alpha_S ratios and PDF ratios
579  double asWeight = 1.;
580  double pdfWeight = 1.;
581  // Do trial shower, calculation of alpha_S ratios, PDF ratios
582  double sudakov = selected->weightTree(trial, asME, maxScale,
583  selected->clusterIn.pT(), asFSR, asISR,
584  asWeight, pdfWeight);
585  // MPI no-emission probability.
586  int njetsMaxMPI = mergingHooksPtr->nMinMPI()+1;
587  double mpiwt = selected->weightTreeEmissions( trial, -1, njetsMaxMPI,
588  maxScale );
589 
590  // Set weight
591  wt = ( mergingHooksPtr->nRecluster() == 2 ) ? 1.
592  : asWeight*pdfWeight*sudakov*mpiwt;
593 
594  // Done
595  return wt;
596 
597 }
598 
599 //--------------------------------------------------------------------------
600 
601 double History::weight_UNLOPS_SUBTNLO(PartonLevel* trial, double RN ) {
602 
603  // Select a path of clusterings
604  History * selected = select(RN);
605  // Set scales in the states to the scales pythia would have set
606  selected->setScalesInHistory();
607  // So far, no reweighting
608  double wt = 1.;
609  // Only reweighting with MPI no-emission probability
610  double maxScale = (foundCompletePath) ? infoPtr->eCM()
611  : mergingHooksPtr->muFinME();
612  int njetsMaxMPI = mergingHooksPtr->nMinMPI()+1;
613  double mpiwt = selected->weightTreeEmissions( trial, -1, njetsMaxMPI,
614  maxScale );
615  wt = mpiwt;
616  // Done
617  return wt;
618 
619 }
620 
621 //--------------------------------------------------------------------------
622 
623 // Function to calculate O(\alpha_s)-term of CKKWL-weight for NLO merging
624 
625 double History::weight_UNLOPS_CORRECTION( int order, PartonLevel* trial,
626  AlphaStrong* asFSR, AlphaStrong* asISR,
627  double RN, Rndm* rndmPtr ) {
628 
629  // Already done if no correction should be calculated
630  if ( order < 0 ) return 0.;
631 
632  // Read alpha_S in ME calculation and maximal scale (eCM)
633  double asME = infoPtr->alphaS();
634  double muR = mergingHooksPtr->muRinME();
635  double maxScale = (foundCompletePath)
636  ? infoPtr->eCM()
637  : mergingHooksPtr->muFinME();
638 
639  // Pick path of clusterings
640  History * selected = select(RN);
641  // Set scales in the states to the scales pythia would have set
642  selected->setScalesInHistory();
643 
644  double nSteps = mergingHooksPtr->getNumberOfClusteringSteps(state);
645 
646  // Get the lowest order k-factor and add first two terms in expansion
647  double kFactor = asME * mergingHooksPtr->k1Factor(nSteps);
648 
649  // If using Bbar, which includes a tree-level part, subtract an
650  // additional one, i.e. the O(\as^0) contribution as well
651  double wt = 1.;
652 
653  // If only O(\alpha_s^0)-term is to be calculated, done already.
654  if ( order == 0 ) return wt;
655 
656  // Start by adding the O(\alpha_s^1)-term of the k-factor.
657  wt += kFactor;
658 
659  // Calculate sum of O(\alpha_s^1)-terms of the ckkw-l weight WITHOUT
660  // the O(\alpha_s^1)-term of the last no-emission probability.
661  bool fixpdf = true;
662  bool fixas = true;
663  // Get first term in expansion of alpha_s ratios.
664  double wA = selected->weightFirstALPHAS( asME, muR, asFSR, asISR );
665  // Add logarithm from \alpha_s expansion to weight.
666  wt += (fixas) ? wA : 0.;
667  // Generate true average, not only one-point.
668  double nWeight = 0.;
669  for ( int i=0; i < NTRIAL; ++i ) {
670  // Get average number of emissions.
671  double wE = selected->weightFirstEmissions(trial,asME, maxScale,
672  asFSR, asISR, fixpdf, fixas );
673  // Add average number of emissions off reconstructed states to weight.
674  nWeight += wE;
675  // Get first term in expansion of PDF ratios.
676  double pscale = selected->clusterIn.pT();
677  double wP = selected->weightFirstPDFs(asME, maxScale, pscale, rndmPtr);
678  // Add integral of DGLAP shifted PDF ratios from \alpha_s expansion to wt.
679  nWeight += (fixpdf) ? wP : 0.;
680  }
681  wt += nWeight/double(NTRIAL);
682 
683  // If O(\alpha_s^1)-term + O(\alpha_s^1)-term is to be calculated, done.
684  if ( order == 1 ) return wt;
685 
686  // So far, no calculation of O(\alpha_s^2)-term
687  return 0.;
688 
689 }
690 
691 //--------------------------------------------------------------------------
692 
693 // Function to set the state with complete scales for evolution.
694 
695 void History::getStartingConditions( const double RN, Event& outState ) {
696 
697  // Select the history
698  History * selected = select(RN);
699 
700  // Set scales in the states to the scales pythia would have set
701  selected->setScalesInHistory();
702 
703  // Copy the output state
704  outState = state;
705 
706  // Set the scale of the lowest order process
707  if (!selected->mother) {
708  int nFinal = 0;
709  for(int i=0; i < int(outState.size()); ++i)
710  if (outState[i].isFinal()) nFinal++;
711  if (nFinal <=2)
712  outState.scale(mergingHooksPtr->muF());
713 
714  // Save information on last splitting, to allow the next
715  // emission in the shower to have smaller rapidity with
716  // respect to the last ME splitting
717  // For hard process, use dummy values
718  if (mergingHooksPtr->getNumberOfClusteringSteps(state) == 0) {
719  infoPtr->zNowISR(0.5);
720  infoPtr->pT2NowISR(pow(state[0].e(),2));
721  infoPtr->hasHistory(true);
722  // For incomplete process, try to use real values
723  } else {
724  infoPtr->zNowISR(selected->zISR());
725  infoPtr->pT2NowISR(pow(selected->pTISR(),2));
726  infoPtr->hasHistory(true);
727  }
728 
729  } else {
730 
731  // Save information on last splitting, to allow the next
732  // emission in the shower to have smaller rapidity with
733  // respect to the last ME splitting
734  infoPtr->zNowISR(selected->zISR());
735  infoPtr->pT2NowISR(pow(selected->pTISR(),2));
736  infoPtr->hasHistory(true);
737 
738  }
739 
740  // Save MPI starting scale
741  if (mergingHooksPtr->getNumberOfClusteringSteps(state) == 0)
742  mergingHooksPtr->muMI(infoPtr->eCM());
743  else
744  mergingHooksPtr->muMI(outState.scale());
745 
746 }
747 
748 //--------------------------------------------------------------------------
749 
750 // Function to print the history that would be chosen from the number RN.
751 
752 void History::printHistory( const double RN ) {
753  History * selected = select(RN);
754  selected->printStates();
755  // Done
756 }
757 
758 //--------------------------------------------------------------------------
759 
760 // Function to print the states in a history, starting from the hard process.
761 
762 void History::printStates() {
763  if ( !mother ) {
764  state.list();
765  return;
766  }
767  // Print.
768  state.list();
769  // Recurse
770  mother->printStates();
771  // Done
772  return;
773 }
774 
775 //--------------------------------------------------------------------------
776 
777 // Function to set the state with complete scales for evolution.
778 
779 bool History::getClusteredEvent( const double RN, int nSteps,
780  Event& outState) {
781 
782  // Select history
783  History * selected = select(RN);
784  // Set scales in the states to the scales pythia would have set
785  // (Only needed if not done before in calculation of weights or
786  // setting of starting conditions)
787  selected->setScalesInHistory();
788  // If the history does not allow for nSteps clusterings (e.g. because the
789  // history is incomplete), return false
790  if (nSteps > selected->nClusterings()) return false;
791  // Return event with nSteps-1 additional partons (i.e. recluster the last
792  // splitting) and copy the output state
793  outState = selected->clusteredState(nSteps-1);
794  // Done.
795  return true;
796 
797 }
798 
799 //--------------------------------------------------------------------------
800 
801 bool History::getFirstClusteredEventAboveTMS( const double RN, int nDesired,
802  Event& process, int& nPerformed, bool doUpdate ) {
803 
804  // Do reclustering (looping) steps. Remember process scale.
805  int nTried = nDesired - 1;
806  // Get number of clustering steps.
807  int nSteps = select(RN)->nClusterings();
808  // Set scales in the states to the scales pythia would have set.
809  select(RN)->setScalesInHistory();
810 
811  // Recluster until reclustered event is above the merging scale.
812  Event dummy = Event();
813  do {
814  // Initialise temporary output of reclustering.
815  dummy.clear();
816  dummy.init( "(hard process-modified)", particleDataPtr );
817  dummy.clear();
818  // Recluster once more.
819  nTried++;
820  // If reclustered event does not exist, exit.
821  if ( !getClusteredEvent( RN, nSteps-nTried+1, dummy ) ) return false;
822  if ( nTried >= nSteps ) break;
823  // Continue loop if reclustered event has unresolved partons.
824  } while ( mergingHooksPtr->rhoms( dummy, false) < mergingHooksPtr->tms() );
825 
826  // Update the hard process.
827  if ( doUpdate ) process = dummy;
828 
829  // Failed to produce output state.
830  if ( nTried > nSteps ) return false;
831 
832  nPerformed = nTried;
833  if ( doUpdate ) {
834  // Update to the actual number of steps.
835  mergingHooksPtr->nReclusterSave = nPerformed;
836  // Save MPI starting scale
837  if (mergingHooksPtr->getNumberOfClusteringSteps(state) == 0)
838  mergingHooksPtr->muMI(infoPtr->eCM());
839  else
840  mergingHooksPtr->muMI(state.scale());
841  }
842 
843  // Done
844  return true;
845 
846 }
847 
848 //--------------------------------------------------------------------------
849 
850 // Calculate and return pdf ratio.
851 
852 double History::getPDFratio( int side, bool forSudakov, bool useHardPDFs,
853  int flavNum, double xNum, double muNum,
854  int flavDen, double xDen, double muDen) {
855 
856  // Do nothing for e+e- beams
857  if ( abs(flavNum) > 10 && flavNum != 21 ) return 1.0;
858  if ( abs(flavDen) > 10 && flavDen != 21 ) return 1.0;
859 
860  // Now calculate PDF ratio if necessary
861  double pdfRatio = 1.0;
862 
863  // Get mother and daughter pdfs
864  double pdfNum = 0.0;
865  double pdfDen = 0.0;
866 
867  // Use hard process PDFs (i.e. PDFs NOT used in ISR, FSR or MPI).
868  if ( useHardPDFs ) {
869  if (side == 1) {
870  if (forSudakov)
871  pdfNum = mother->beamA.xfHard( flavNum, xNum, muNum*muNum);
872  else
873  pdfNum = beamA.xfHard( flavNum, xNum, muNum*muNum);
874  if (forSudakov)
875  pdfDen = max(1e-10, beamA.xfHard( flavDen, xDen, muDen*muDen));
876  else
877  pdfDen = max(1e-10, beamA.xfHard( flavDen, xDen, muDen*muDen));
878  } else {
879  if (forSudakov)
880  pdfNum = mother->beamB.xfHard( flavNum, xNum, muNum*muNum);
881  else
882  pdfNum = beamB.xfHard( flavNum, xNum, muNum*muNum);
883 
884  if (forSudakov)
885  pdfDen = max(1e-10,beamB.xfHard( flavDen, xDen, muDen*muDen));
886  else
887  pdfDen = max(1e-10,beamB.xfHard( flavDen, xDen, muDen*muDen));
888  }
889 
890  // Use rescaled PDFs in the presence of multiparton interactions
891  } else {
892  if (side == 1) {
893  if (forSudakov)
894  pdfNum = mother->beamA.xfISR(0, flavNum, xNum, muNum*muNum);
895  else
896  pdfNum = beamA.xfISR(0, flavNum, xNum, muNum*muNum);
897  if (forSudakov)
898  pdfDen = max(1e-10, beamA.xfISR(0, flavDen, xDen, muDen*muDen));
899  else
900  pdfDen = max(1e-10, beamA.xfISR(0, flavDen, xDen, muDen*muDen));
901 
902  } else {
903  if (forSudakov)
904  pdfNum = mother->beamB.xfISR(0, flavNum, xNum, muNum*muNum);
905  else
906  pdfNum = beamB.xfISR(0, flavNum, xNum, muNum*muNum);
907 
908  if (forSudakov)
909  pdfDen = max(1e-10,beamB.xfISR(0, flavDen, xDen, muDen*muDen));
910  else
911  pdfDen = max(1e-10,beamB.xfISR(0, flavDen, xDen, muDen*muDen));
912  }
913  }
914 
915  // Return ratio of pdfs
916  if ( pdfNum > 1e-15 && pdfDen > 1e-10 ) {
917  pdfRatio *= pdfNum / pdfDen;
918  } else if ( pdfNum < pdfDen ) {
919  pdfRatio = 0.;
920  } else if ( pdfNum > pdfDen ) {
921  pdfRatio = 1.;
922  }
923 
924  // Done
925  return pdfRatio;
926 
927 }
928 
929 //--------------------------------------------------------------------------
930 
931 /*--------------- METHODS USED FOR ONLY ONE PATH OF HISTORY NODES ------- */
932 
933 // Function to set all scales in the sequence of states. This is a
934 // wrapper routine for setScales and setEventScales methods
935 
936 void History::setScalesInHistory() {
937  // Find correct links from n+1 to n states (mother --> child), as
938  // needed for enforcing ordered scale sequences
939  vector<int> ident;
940  findPath(ident);
941  // Set production scales in the states to the scales pythia would
942  // have set and enforce ordering
943  setScales(ident,true);
944  // Set the overall event scales to the scale of the last branching
945  setEventScales();
946 }
947 
948 //--------------------------------------------------------------------------
949 
950 // Function to find the index (in the mother histories) of the
951 // child history, thus providing a way access the path from both
952 // initial history (mother == 0) and final history (all children == 0)
953 // IN vector<int> : The index of each child in the children vector
954 // of the current history node will be saved in
955 // this vector
956 // NO OUTPUT
957 
958 void History::findPath(vector<int>& out) {
959 
960  // If the initial and final nodes are identical, return
961  if (!mother && int(children.size()) < 1) return;
962  // Find the child by checking the children vector for the perfomed
963  // clustering
964  int iChild=-1;
965  if ( mother ) {
966  int size = int(mother->children.size());
967  // Loop through children and identify child chosen
968  for ( int i=0; i < size; ++i) {
969  if ( mother->children[i]->scale == scale
970  && mother->children[i]->prob == prob
971  && equalClustering(mother->children[i]->clusterIn,clusterIn)) {
972  iChild = i;
973  break;
974  }
975  }
976  // Save the index of the child in the children vector and recurse
977  if (iChild >-1)
978  out.push_back(iChild);
979  mother->findPath(out);
980  }
981 }
982 
983 //--------------------------------------------------------------------------
984 
985 // Functions to set the parton production scales and enforce
986 // ordering on the scales of the respective clusterings stored in
987 // the History node:
988 // Method will start from lowest multiplicity state and move to
989 // higher states, setting the production scales the shower would
990 // have used.
991 // When arriving at the highest multiplicity, the method will switch
992 // and go back in direction of lower states to check and enforce
993 // ordering for unordered histories.
994 // IN vector<int> : Vector of positions of the chosen child
995 // in the mother history to allow to move
996 // in direction initial->final along path
997 // bool : True: Move in direction low->high
998 // multiplicity and set production scales
999 // False: Move in direction high->low
1000 // multiplicity and check and enforce
1001 // ordering
1002 // NO OUTPUT
1003 
1004 void History::setScales( vector<int> index, bool forward) {
1005 
1006  // First, set the scales of the hard process to the kinematial
1007  // limit (=s)
1008  if ( children.empty() && forward ) {
1009  // New "incomplete" configurations showered from mu
1010  if (!mother) {
1011  double scaleNew = 1.;
1012 
1013  if (mergingHooksPtr->incompleteScalePrescip()==0) {
1014  scaleNew = mergingHooksPtr->muF();
1015  } else if (mergingHooksPtr->incompleteScalePrescip()==1) {
1016  Vec4 pOut;
1017  pOut.p(0.,0.,0.,0.);
1018  for(int i=0; i<int(state.size()); ++i)
1019  if (state[i].isFinal())
1020  pOut += state[i].p();
1021  scaleNew = pOut.mCalc();
1022  } else if (mergingHooksPtr->incompleteScalePrescip()==2) {
1023  scaleNew = state[0].e();
1024  }
1025 
1026  scaleNew = max( mergingHooksPtr->pTcut(), scaleNew);
1027 
1028  state.scale(scaleNew);
1029  for(int i=3; i < int(state.size());++i)
1030  if (state[i].colType() != 0)
1031  state[i].scale(scaleNew);
1032  } else {
1033  // 2->2 with non-parton particles showered from eCM
1034  state.scale( state[0].e() );
1035  // Count final partons
1036  bool isLEP = ( state[3].isLepton() && state[4].isLepton() );
1037  int nFinal = 0;
1038  int nFinalPartons = 0;
1039  int nFinalPhotons = 0;
1040  for ( int i=0; i < int(state.size()); ++i ) {
1041  if ( state[i].isFinal() ) {
1042  nFinal++;
1043  if ( state[i].colType() != 0 ) nFinalPartons++;
1044  if ( state[i].id() == 22 ) nFinalPhotons++;
1045  }
1046  }
1047  bool isQCD = ( nFinal == 2 && nFinal == nFinalPartons );
1048  bool isPPh = ( nFinal == 2 && nFinalPartons == 1 && nFinalPhotons == 1);
1049  // If 2->2, purely partonic, set event scale to kinematic pT
1050  if ( !isLEP && ( isQCD || isPPh ) )
1051  state.scale( hardFacScale(state) );
1052 
1053  }
1054  }
1055  // Set all particle production scales, starting from lowest
1056  // multiplicity (final) state
1057  if (mother && forward) {
1058  // When choosing splitting scale, beware of unordered splittings:
1059  double scaleNew = 1.;
1060  if (mergingHooksPtr->unorderedScalePrescip() == 0) {
1061  // Use larger scale as common splitting scale for mother and child
1062  scaleNew = max( mergingHooksPtr->pTcut(), max(scale,mother->scale));
1063  } else if (mergingHooksPtr->unorderedScalePrescip() == 1) {
1064  // Use smaller scale as common splitting scale for mother and child
1065  if (scale < mother->scale)
1066  scaleNew *= max( mergingHooksPtr->pTcut(), min(scale,mother->scale));
1067  else
1068  scaleNew *= max( mergingHooksPtr->pTcut(), max(scale,mother->scale));
1069  }
1070 
1071  // Rescale the mother state partons to the clustering scales
1072  // that have been found along the path
1073  mother->state[clusterIn.emitted].scale(scaleNew);
1074  mother->state[clusterIn.emittor].scale(scaleNew);
1075  mother->state[clusterIn.recoiler].scale(scaleNew);
1076 
1077  // Find unchanged copies of partons in higher multiplicity states
1078  // and rescale those
1079  mother->scaleCopies(clusterIn.emitted, mother->state, scaleNew);
1080  mother->scaleCopies(clusterIn.emittor, mother->state, scaleNew);
1081  mother->scaleCopies(clusterIn.recoiler, mother->state, scaleNew);
1082 
1083  // Recurse
1084  mother->setScales(index,true);
1085  }
1086 
1087  // Now, check and correct ordering from the highest multiplicity
1088  // state backwards to all the clustered states
1089  if (!mother || !forward) {
1090  // Get index of child along the path
1091  int iChild = -1;
1092  if ( int(index.size()) > 0 ) {
1093  iChild = index.back();
1094  index.pop_back();
1095  }
1096 
1097  // Check that the reclustered scale is above the shower cut
1098  if (mother) {
1099  scale = max(mergingHooksPtr->pTcut(), scale);
1100  }
1101  // If this is NOT the 2->2 process, check and enforce ordering
1102  if (iChild != -1 && !children.empty()) {
1103 
1104  if (scale > children[iChild]->scale ) {
1105  if (mergingHooksPtr->unorderedScalePrescip() == 0) {
1106  // Use larger scale as common splitting scale for mother and child
1107  double scaleNew = max( mergingHooksPtr->pTcut(),
1108  max(scale,children[iChild]->scale));
1109  // Enforce ordering in particle production scales
1110  for( int i = 0; i < int(children[iChild]->state.size()); ++i)
1111  if (children[iChild]->state[i].scale() == children[iChild]->scale)
1112  children[iChild]->state[i].scale(scaleNew);
1113  // Enforce ordering in saved clustering scale
1114  children[iChild]->scale = scaleNew;
1115 
1116  } else if ( mergingHooksPtr->unorderedScalePrescip() == 1) {
1117  // Use smaller scale as common splitting scale for mother & child
1118  double scaleNew = max(mergingHooksPtr->pTcut(),
1119  min(scale,children[iChild]->scale));
1120  // Enforce ordering in particle production scales
1121  for( int i = 0; i < int(state.size()); ++i)
1122  if (state[i].scale() == scale)
1123  state[i].scale(scaleNew);
1124  // Enforce ordering in saved clustering scale
1125  scale = scaleNew;
1126  }
1127  // Just set the overall event scale to the minimal scale
1128  } else {
1129  double scalemin = state[0].e();
1130  for( int i = 0; i < int(state.size()); ++i)
1131  if (state[i].colType() != 0)
1132  scalemin = max(mergingHooksPtr->pTcut(),
1133  min(scalemin,state[i].scale()));
1134  state.scale(scalemin);
1135  scale = max(mergingHooksPtr->pTcut(), scale);
1136  }
1137  //Recurse
1138  children[iChild]->setScales(index, false);
1139  }
1140  }
1141 
1142 }
1143 
1144 //--------------------------------------------------------------------------
1145 
1146 // Function to find a particle in all higher multiplicity events
1147 // along the history path and set its production scale to the input
1148 // scale
1149 // IN int iPart : Parton in refEvent to be checked / rescaled
1150 // Event& refEvent : Reference event for iPart
1151 // double scale : Scale to be set as production scale for
1152 // unchanged copies of iPart in subsequent steps
1153 
1154 void History::scaleCopies(int iPart, const Event& refEvent, double rho) {
1155 
1156  // Check if any parton recently rescaled is found unchanged:
1157  // Same charge, colours in mother->state
1158  if ( mother ) {
1159  for( int i=0; i < mother->state.size(); ++i) {
1160  if ( ( mother->state[i].id() == refEvent[iPart].id()
1161  && mother->state[i].colType() == refEvent[iPart].colType()
1162  && mother->state[i].chargeType() == refEvent[iPart].chargeType()
1163  && mother->state[i].col() == refEvent[iPart].col()
1164  && mother->state[i].acol() == refEvent[iPart].acol() )
1165  ) {
1166  // Rescale the unchanged parton
1167  mother->state[i].scale(rho);
1168  // Recurse
1169  if (mother->mother)
1170  mother->scaleCopies( iPart, refEvent, rho );
1171  } // end if found unchanged parton case
1172  } // end loop over particle entries in event
1173  }
1174 }
1175 
1176 //--------------------------------------------------------------------------
1177 
1178 // Functions to set the OVERALL EVENT SCALES [=state.scale()] to
1179 // the scale of the last clustering
1180 // NO INPUT
1181 // NO OUTPUT
1182 
1183 void History::setEventScales() {
1184  // Set the event scale to the scale of the last clustering,
1185  // except for the very lowest multiplicity state
1186  if (mother) {
1187  mother->state.scale(scale);
1188  // Recurse
1189  mother->setEventScales();
1190  }
1191 }
1192 
1193 //--------------------------------------------------------------------------
1194 
1195 // Functions to return the z value of the last ISR splitting
1196 // NO INPUT
1197 // OUTPUT double : z value of last ISR splitting in history
1198 
1199 double History::zISR() {
1200 
1201  // Do nothing for ME level state
1202  if (!mother) return 0.0;
1203  // Skip FSR splitting
1204  if (mother->state[clusterIn.emittor].isFinal()) return mother->zISR();
1205  // Calculate z
1206  int rad = clusterIn.emittor;
1207  int rec = clusterIn.recoiler;
1208  int emt = clusterIn.emitted;
1209  double z = (mother->state[rad].p() + mother->state[rec].p()
1210  - mother->state[emt].p()).m2Calc()
1211  / (mother->state[rad].p() + mother->state[rec].p()).m2Calc();
1212  // Recurse
1213  double znew = mother->zISR();
1214  // Update z
1215  if (znew > 0.) z = znew;
1216 
1217  return z;
1218 }
1219 
1220 //--------------------------------------------------------------------------
1221 
1222 // Functions to return the z value of the last FSR splitting
1223 // NO INPUT
1224 // OUTPUT double : z value of last FSR splitting in history
1225 
1226 double History::zFSR() {
1227 
1228  // Do nothing for ME level state
1229  if (!mother) return 0.0;
1230  // Skip ISR splitting
1231  if (!mother->state[clusterIn.emittor].isFinal()) return mother->zFSR();
1232  // Calculate z
1233  int rad = clusterIn.emittor;
1234  int rec = clusterIn.recoiler;
1235  int emt = clusterIn.emitted;
1236  // Construct 2->3 variables for FSR
1237  Vec4 sum = mother->state[rad].p() + mother->state[rec].p()
1238  + mother->state[emt].p();
1239  double m2Dip = sum.m2Calc();
1240  double x1 = 2. * (sum * mother->state[rad].p()) / m2Dip;
1241  double x3 = 2. * (sum * mother->state[emt].p()) / m2Dip;
1242  // Calculate z of splitting for FSR
1243  double z = x1/(x1+x3);
1244  // Recurse
1245  double znew = mother->zFSR();
1246  // Update z
1247  if (znew > 0.) z = znew;
1248 
1249  return z;
1250 }
1251 
1252 //--------------------------------------------------------------------------
1253 
1254 // Functions to return the pT scale of the last FSR splitting
1255 // NO INPUT
1256 // OUTPUT double : pT scale of last FSR splitting in history
1257 
1258 double History::pTISR() {
1259  // Do nothing for ME level state
1260  if (!mother) return 0.0;
1261  // Skip FSR splitting
1262  if (mother->state[clusterIn.emittor].isFinal()) return mother->pTISR();
1263  double pT = mother->state.scale();
1264  // Recurse
1265  double pTnew = mother->pTISR();
1266  // Update pT
1267  if (pTnew > 0.) pT = pTnew;
1268 
1269  return pT;
1270 }
1271 
1272 //--------------------------------------------------------------------------
1273 
1274 // Functions to return the pT scale of the last FSR splitting
1275 // NO INPUT
1276 // OUTPUT double : pT scale of last FSR splitting in history
1277 
1278 double History::pTFSR() {
1279 
1280  // Do nothing for ME level state
1281  if (!mother) return 0.0;
1282  // Skip ISR splitting
1283  if (!mother->state[clusterIn.emittor].isFinal()) return mother->pTFSR();
1284  double pT = mother->state.scale();
1285  // Recurse
1286  double pTnew = mother->pTFSR();
1287  // Update pT
1288  if (pTnew > 0.) pT = pTnew;
1289  return pT;
1290 }
1291 
1292 //--------------------------------------------------------------------------
1293 
1294 // Function to return the depth of the history (i.e. the number of
1295 // reclustered splittings)
1296 // NO INPUT
1297 // OUTPUT int : Depth of history
1298 
1299 int History::nClusterings() {
1300  if (!mother) return 0;
1301  int w = mother->nClusterings();
1302  w += 1;
1303  return w;
1304 }
1305 
1306 //--------------------------------------------------------------------------
1307 
1308 // Functions to return the event after nSteps splittings of the 2->2 process
1309 // Example: nSteps = 1 -> return event with one additional parton
1310 // INPUT int : Number of splittings in the event,
1311 // as counted from core 2->2 process
1312 // OUTPUT Event : event with nSteps additional partons
1313 
1314 Event History::clusteredState(int nSteps) {
1315 
1316  // Save state
1317  Event outState = state;
1318  // As long as there are steps to do, recursively save state
1319  if (mother && nSteps > 0)
1320  outState = mother->clusteredState(nSteps - 1);
1321  // Done
1322  return outState;
1323 
1324 }
1325 
1326 //--------------------------------------------------------------------------
1327 
1328 // Function to choose a path from all paths in the tree
1329 // according to their splitting probabilities
1330 // IN double : Random number
1331 // OUT History* : Leaf of history path chosen
1332 
1333 History * History::select(double rnd) {
1334 
1335  // No need to choose if no paths have been constructed.
1336  if ( goodBranches.empty() && badBranches.empty() ) return this;
1337 
1338  // Choose amongst paths allowed by projections.
1339  double sum = 0.;
1340  map<double, History*> selectFrom;
1341  if ( !goodBranches.empty() ) {
1342  selectFrom = goodBranches;
1343  sum = sumGoodBranches;
1344  } else {
1345  selectFrom = badBranches;
1346  sum = sumBadBranches;
1347  }
1348 
1349  if (mergingHooksPtr->pickBySumPT()) {
1350  // Find index of history with minimal sum of scalar pT
1351  int nFinal = 0;
1352  for (int i=0; i < state.size(); ++i)
1353  if (state[i].isFinal())
1354  nFinal++;
1355  double iMin = 0.;
1356  double sumMin = (nFinal-2)*state[0].e();
1357  for ( map<double, History*>::iterator it = selectFrom.begin();
1358  it != selectFrom.end(); ++it ) {
1359 
1360  if (it->second->sumScalarPT < sumMin) {
1361  sumMin = it->second->sumScalarPT;
1362  iMin = it->first;
1363  }
1364  }
1365  // Choose history with smallest sum of scalar pT
1366  return selectFrom.lower_bound(iMin)->second;
1367  } else {
1368  // Choose history according to probability, be careful about upper bound
1369  if ( rnd != 1. ) {
1370  return selectFrom.upper_bound(sum*rnd)->second;
1371  } else {
1372  return selectFrom.lower_bound(sum*rnd)->second;
1373  }
1374  }
1375  // Done
1376 }
1377 
1378 //--------------------------------------------------------------------------
1379 
1380 // Function to project paths onto desired paths.
1381 
1382 bool History::trimHistories() {
1383  // Do nothing if no paths have been constructed.
1384  if ( paths.empty() ) return false;
1385  // Loop through all constructed paths. Check all removal conditions.
1386  for ( map<double, History*>::iterator it = paths.begin();
1387  it != paths.end(); ++it ) {
1388  // Check if history is allowed.
1389  if ( it->second->keep() && !it->second->keepHistory() )
1390  it->second->remove();
1391  }
1392  // Project onto desired / undesired branches.
1393  double sumold, sumnew, sumprob, mismatch;
1394  sumold = sumnew = sumprob = mismatch = 0.;
1395  // Loop through all constructed paths and store allowed paths.
1396  // Skip undesired paths.
1397  for ( map<double, History*>::iterator it = paths.begin();
1398  it != paths.end(); ++it ) {
1399  // Update index
1400  sumnew = it->first;
1401  if ( it->second->keep() ) {
1402  // Fill branches with allowed paths.
1403  goodBranches.insert( make_pair( sumnew - mismatch, it->second) );
1404  // Add probability of this path.
1405  sumGoodBranches = sumnew - mismatch;
1406  } else {
1407  // Update mismatch in probabilities resulting from not including this
1408  // path
1409  double mismatchOld = mismatch;
1410  mismatch += sumnew - sumold;
1411  // Fill branches with allowed paths.
1412  badBranches.insert( make_pair( mismatchOld + sumnew - sumold,
1413  it->second ) );
1414  // Add probability of this path.
1415  sumBadBranches = mismatchOld + sumnew - sumold;
1416  }
1417  // remember index of this path in order to caclulate probability of
1418  // subsequent path.
1419  sumold = it->first;
1420  }
1421  // Done
1422  return !goodBranches.empty();
1423 }
1424 
1425 //--------------------------------------------------------------------------
1426 
1427 // Function implementing checks on a paths, deciding if the path is valid.
1428 
1429 bool History::keepHistory() {
1430  bool keepPath = true;
1431  // Tag unordered paths for removal.
1432  if ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
1433  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0 ) {
1434  // Tag unordered paths for removal. Include scale of hard 2->2 process
1435  // into the ordering definition.
1436  double maxScale = hardFacScale(state);
1437  keepPath = isOrderedPath( maxScale );
1438  }
1439 
1440  //Done
1441  return keepPath;
1442 }
1443 
1444 //--------------------------------------------------------------------------
1445 
1446 // Function to check if a path is ordered in evolution pT.
1447 
1448 bool History::isOrderedPath( double maxscale ) {
1449  double newscale = clusterIn.pT();
1450  if ( !mother ) return true;
1451  bool ordered = mother->isOrderedPath(newscale);
1452  if ( !ordered || maxscale < newscale) return false;
1453  return ordered;
1454 }
1455 
1456 //--------------------------------------------------------------------------
1457 
1458 // Function to check if all reconstucted states in a path pass the merging
1459 // scale cut.
1460 
1461 bool History::allIntermediateAboveRhoMS( double rhoms, bool good ) {
1462  // If one state below the merging scale has already been found, no need to
1463  // check further.
1464  if ( !good ) return false;
1465  // Check merging scale for states with more than 0 jets
1466  int nFinal = 0;
1467  for ( int i = 0; i < state.size(); ++i )
1468  if ( state[i].isFinal() && state[i].colType() != 0 )
1469  nFinal++;
1470  double rhoNew = (nFinal > 0 ) ? mergingHooksPtr->rhoms( state, false )
1471  : state[0].e();
1472  // Assume state from ME generator passes merging scale cut.
1473  if ( !mother ) return good;
1474  // Recurse.
1475  return good && mother->allIntermediateAboveRhoMS( rhoms, (rhoNew > rhoms) );
1476 }
1477 
1478 //--------------------------------------------------------------------------
1479 
1480 // Function to check if any ordered paths were found (and kept).
1481 
1482 bool History::foundAnyOrderedPaths() {
1483  //Do nothing if no paths were found
1484  if ( paths.empty() ) return false;
1485  double maxscale = infoPtr->eCM();
1486  // Loop through paths. Divide probability into ordered and unordered pieces.
1487  for ( map<double, History*>::iterator it = paths.begin();
1488  it != paths.end(); ++it )
1489  if ( it->second->isOrderedPath(maxscale) )
1490  return true;
1491  // Done
1492  return false;
1493 }
1494 
1495 //--------------------------------------------------------------------------
1496 
1497 // For a full path, find the weight calculated from the ratio of
1498 // couplings, the no-emission probabilities, and possible PDF
1499 // ratios. This function should only be called for the last history
1500 // node of a full path.
1501 // IN TimeShower : Already initialised shower object to be used as
1502 // trial shower
1503 // double : alpha_s value used in ME calculation
1504 // double : Maximal mass scale of the problem (e.g. E_CM)
1505 // AlphaStrong: Initialised shower alpha_s object for FSR
1506 // alpha_s ratio calculation
1507 // AlphaStrong: Initialised shower alpha_s object for ISR
1508 // alpha_s ratio calculation (can be different from previous)
1509 
1510 double History::weightTree(PartonLevel* trial, double as0, double maxscale,
1511  double pdfScale, AlphaStrong * asFSR, AlphaStrong * asISR,
1512  double& asWeight, double& pdfWeight) {
1513 
1514  // Use correct scale
1515  double newScale = scale;
1516 
1517  // For ME state, just multiply by PDF ratios
1518  if ( !mother ) {
1519 
1520  int sideRad = (state[3].pz() > 0) ? 1 :-1;
1521  int sideRec = (state[4].pz() > 0) ? 1 :-1;
1522  // Calculate PDF first leg
1523  if (state[3].colType() != 0) {
1524  // Find x value and flavour
1525  double x = 2.*state[3].e() / state[0].e();
1526  int flav = state[3].id();
1527 
1528  // Find numerator/denominator scale
1529  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1530  double scaleDen = mergingHooksPtr->muFinME();
1531  // For initial parton, multiply by PDF ratio
1532  double ratio = getPDFratio(sideRad, false, false, flav, x, scaleNum,
1533  flav, x, scaleDen);
1534  pdfWeight *= ratio;
1535  }
1536 
1537  // Calculate PDF ratio for second leg
1538  if (state[4].colType() != 0) {
1539  // Find x value and flavour
1540  double x = 2.*state[4].e() / state[0].e();
1541  int flav = state[4].id();
1542  // Find numerator/denominator scale
1543  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1544  double scaleDen = mergingHooksPtr->muFinME();
1545  // For initial parton, multiply with PDF ratio
1546  double ratio = getPDFratio(sideRec, false, false, flav, x, scaleNum,
1547  flav, x, scaleDen);
1548  pdfWeight *= ratio;
1549  }
1550 
1551  return 1.0;
1552  }
1553 
1554  // Remember new PDF scale n case true sclae should be used for un-ordered
1555  // splittings.
1556  double newPDFscale = newScale;
1557  if (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1558  newPDFscale = clusterIn.pT();
1559 
1560  // Recurse
1561  double w = mother->weightTree(trial, as0, newScale, newPDFscale,
1562  asFSR, asISR, asWeight, pdfWeight);
1563 
1564  // Do nothing for empty state
1565  if (state.size() < 3) return 1.0;
1566  // If up to now, trial shower was not successful, return zero
1567  if ( w < 1e-12 ) return 0.0;
1568  // Do trial shower on current state, return zero if not successful
1569  w *= doTrialShower(trial, 1, maxscale);
1570  if ( w < 1e-12 ) return 0.0;
1571 
1572  // Calculate alpha_s ratio for current state
1573  if ( asFSR && asISR ) {
1574  double asScale = pow2( newScale );
1575  if (mergingHooksPtr->unorderedASscalePrescip() == 1)
1576  asScale = pow2( clusterIn.pT() );
1577  bool FSR = mother->state[clusterIn.emittor].isFinal();
1578  double alphaSinPS = (FSR) ? (*asFSR).alphaS(asScale)
1579  : (*asISR).alphaS(asScale
1580  + pow2(mergingHooksPtr->pT0ISR()) );
1581  asWeight *= alphaSinPS / as0;
1582  }
1583 
1584  // Calculate pdf ratios: Get both sides of event
1585  int inP = 3;
1586  int inM = 4;
1587  int sideP = (mother->state[inP].pz() > 0) ? 1 :-1;
1588  int sideM = (mother->state[inM].pz() > 0) ? 1 :-1;
1589 
1590  if ( mother->state[inP].colType() != 0 ) {
1591  // Find x value and flavour
1592  double x = getCurrentX(sideP);
1593  int flav = getCurrentFlav(sideP);
1594  // Find numerator scale
1595  double scaleNum = (children.empty())
1596  ? hardFacScale(state)
1597  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1598  ? pdfScale : maxscale );
1599  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1600  ? clusterIn.pT() : newScale;
1601  // Multiply PDF ratio
1602  double ratio = getPDFratio(sideP, false, false, flav, x, scaleNum,
1603  flav, x, scaleDen);
1604  pdfWeight *= ratio;
1605  }
1606 
1607  if ( mother->state[inM].colType() != 0 ) {
1608  // Find x value and flavour
1609  double x = getCurrentX(sideM);
1610  int flav = getCurrentFlav(sideM);
1611  // Find numerator scale
1612  double scaleNum = (children.empty())
1613  ? hardFacScale(state)
1614  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1615  ? pdfScale : maxscale );
1616  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1617  ? clusterIn.pT() : newScale;
1618  // Multiply PDF ratio
1619  double ratio = getPDFratio(sideM, false, false, flav, x, scaleNum,
1620  flav, x, scaleDen);
1621  pdfWeight *= ratio;
1622  }
1623 
1624  // Done
1625  return w;
1626 }
1627 
1628 //--------------------------------------------------------------------------
1629 
1630 // Function to return the \alpha_s-ratio part of the CKKWL weight of a path.
1631 
1632 double History::weightTreeALPHAS( double as0, AlphaStrong * asFSR,
1633  AlphaStrong * asISR ) {
1634 
1635  // For ME state, do nothing.
1636  if ( !mother ) return 1.;
1637  // Recurse
1638  double w = mother->weightTreeALPHAS( as0, asFSR, asISR );
1639  // Do nothing for empty state
1640  if (state.size() < 3) return w;
1641 
1642  // Calculate alpha_s ratio for current state
1643  if ( asFSR && asISR ) {
1644  double asScale = pow2( scale );
1645  if (mergingHooksPtr->unorderedASscalePrescip() == 1)
1646  asScale = pow2( clusterIn.pT() );
1647  bool FSR = mother->state[clusterIn.emittor].isFinal();
1648  double alphaSinPS = (FSR)
1649  ? (*asFSR).alphaS(asScale)
1650  : (*asISR).alphaS(asScale + pow2(mergingHooksPtr->pT0ISR()) );
1651  w *= alphaSinPS / as0;
1652  }
1653 
1654  // Done
1655  return w;
1656 }
1657 
1658 //--------------------------------------------------------------------------
1659 
1660 // Function to return the PDF-ratio part of the CKKWL weight of a path.
1661 
1662 double History::weightTreePDFs( double maxscale, double pdfScale ) {
1663 
1664  // Use correct scale
1665  double newScale = scale;
1666 
1667  // For ME state, just multiply by PDF ratios
1668  if ( !mother ) {
1669 
1670  double wt = 1.;
1671  int sideRad = (state[3].pz() > 0) ? 1 :-1;
1672  int sideRec = (state[4].pz() > 0) ? 1 :-1;
1673 
1674  // Calculate PDF first leg
1675  if (state[3].colType() != 0) {
1676  // Find x value and flavour
1677  double x = 2.*state[3].e() / state[0].e();
1678  int flav = state[3].id();
1679  // Find numerator/denominator scale
1680  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1681  double scaleDen = mergingHooksPtr->muFinME();
1682  // For initial parton, multiply by PDF ratio
1683  wt *= getPDFratio(sideRad, false, false, flav, x, scaleNum, flav, x,
1684  scaleDen);
1685  }
1686 
1687  // Calculate PDF ratio for second leg
1688  if (state[4].colType() != 0) {
1689  // Find x value and flavour
1690  double x = 2.*state[4].e() / state[0].e();
1691  int flav = state[4].id();
1692  // Find numerator/denominator scale
1693  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1694  double scaleDen = mergingHooksPtr->muFinME();
1695  // For initial parton, multiply with PDF ratio
1696  wt *= getPDFratio(sideRec, false, false, flav, x, scaleNum, flav, x,
1697  scaleDen);
1698  }
1699 
1700  return wt;
1701  }
1702 
1703  // Remember new PDF scale n case true sclae should be used for un-ordered
1704  // splittings.
1705  double newPDFscale = newScale;
1706  if ( mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1707  newPDFscale = clusterIn.pT();
1708 
1709  // Recurse
1710  double w = mother->weightTreePDFs( newScale, newPDFscale );
1711 
1712  // Do nothing for empty state
1713  if (state.size() < 3) return w;
1714 
1715  // Calculate pdf ratios: Get both sides of event
1716  int inP = 3;
1717  int inM = 4;
1718  int sideP = (mother->state[inP].pz() > 0) ? 1 :-1;
1719  int sideM = (mother->state[inM].pz() > 0) ? 1 :-1;
1720 
1721  if ( mother->state[inP].colType() != 0 ) {
1722  // Find x value and flavour
1723  double x = getCurrentX(sideP);
1724  int flav = getCurrentFlav(sideP);
1725  // Find numerator scale
1726  double scaleNum = (children.empty())
1727  ? hardFacScale(state)
1728  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1729  ? pdfScale : maxscale );
1730  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1731  ? clusterIn.pT() : newScale;
1732  // Multiply PDF ratio
1733  double ratio = getPDFratio(sideP, false, false, flav, x, scaleNum,
1734  flav, x, scaleDen);
1735  w *= ratio;
1736  }
1737 
1738  if ( mother->state[inM].colType() != 0 ) {
1739  // Find x value and flavour
1740  double x = getCurrentX(sideM);
1741  int flav = getCurrentFlav(sideM);
1742  // Find numerator scale
1743  double scaleNum = (children.empty())
1744  ? hardFacScale(state)
1745  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1746  ? pdfScale : maxscale );
1747  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1748  ? clusterIn.pT() : newScale;
1749  // Multiply PDF ratio
1750  double ratio = getPDFratio(sideM, false, false, flav, x, scaleNum,
1751  flav, x, scaleDen);
1752  w *= ratio;
1753  }
1754 
1755  // Done
1756  return w;
1757 }
1758 
1759 //--------------------------------------------------------------------------
1760 
1761 // Function to return the no-emission probability part of the CKKWL weight.
1762 
1763 double History::weightTreeEmissions( PartonLevel* trial, int type,
1764  int njetMax, double maxscale ) {
1765 
1766  // Use correct scale
1767  double newScale = scale;
1768  // For ME state, just multiply by PDF ratios
1769  if ( !mother ) return 1.0;
1770  // Recurse
1771  double w = mother->weightTreeEmissions( trial, type, njetMax, newScale );
1772  // Do nothing for empty state
1773  if (state.size() < 3) return 1.0;
1774  // If up to now, trial shower was not successful, return zero
1775  if ( w < 1e-12 ) return 0.0;
1776  // If this node has too many jets, no not calculate no-emission probability.
1777  int njetNow = mergingHooksPtr->getNumberOfClusteringSteps( state) ;
1778  if (njetNow >= njetMax) return 1.0;
1779  // Do trial shower on current state, return zero if not successful
1780  w *= doTrialShower(trial, type, maxscale);
1781  if ( w < 1e-12 ) return 0.0;
1782  // Done
1783  return w;
1784 
1785 }
1786 
1787 //--------------------------------------------------------------------------
1788 
1789 // Function to generate the O(\alpha_s)-term of the CKKWL-weight.
1790 
1791 double History::weightFirst(PartonLevel* trial, double as0, double muR,
1792  double maxscale, AlphaStrong * asFSR, AlphaStrong * asISR, Rndm* rndmPtr ) {
1793 
1794  // Use correct scale
1795  double newScale = scale;
1796 
1797  if ( !mother ) {
1798 
1799  double weight = 0.;
1800 
1801  // Calculate PDF first leg
1802  if (state[3].colType() != 0) {
1803  // Find x value and flavour
1804  double x = 2.*state[3].e() / state[0].e();
1805  int flav = state[3].id();
1806  // Find numerator/denominator scale
1807  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1808  double scaleDen = mergingHooksPtr->muFinME();
1809  // Monte Carlo integrand.
1810  double intPDF4 = monteCarloPDFratios(flav, x, scaleNum, scaleDen,
1811  mergingHooksPtr->muFinME(), as0, rndmPtr);
1812  weight += intPDF4;
1813  }
1814 
1815  // Calculate PDF ratio for second leg
1816  if (state[4].colType() != 0) {
1817  // Find x value and flavour
1818  double x = 2.*state[4].e() / state[0].e();
1819  int flav = state[4].id();
1820  // Find numerator/denominator scale
1821  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1822  double scaleDen = mergingHooksPtr->muFinME();
1823  // Monte Carlo integrand.
1824  double intPDF4 = monteCarloPDFratios(flav, x, scaleNum, scaleDen,
1825  mergingHooksPtr->muFinME(), as0, rndmPtr);
1826  weight += intPDF4;
1827  }
1828 
1829  return weight;
1830  }
1831 
1832  // Recurse
1833  double w = mother->weightFirst(trial, as0, muR, newScale, asFSR, asISR,
1834  rndmPtr );
1835 
1836  // Do nothing for empty state
1837  if (state.size() < 3) return 0.0;
1838 
1839  // Find right scale
1840  double b = 1.;
1841  double asScale2 = newScale*newScale;
1842  int showerType = (mother->state[clusterIn.emittor].isFinal() ) ? 1 : -1;
1843  if (showerType == -1) {
1844  asScale2 += pow(mergingHooksPtr->pT0ISR(),2);
1845  b = 1.;
1846  }
1847  // Find summand beta_0 / 2 * ln(muR^2/t_i) due to as expansion.
1848  double NF = 4.;
1849  double BETA0 = 11. - 2./3.* NF;
1850  // For fixed \alpha_s in matrix element
1851  w += as0 / (2.*M_PI) * 0.5 * BETA0 * log( (muR*muR) / (b*asScale2) );
1852 
1853  // Count emissions: New variant
1854  // Generate true average, not only one-point.
1855  bool fixpdf = true;
1856  bool fixas = true;
1857  double nWeight1 = 0.;
1858  double nWeight2 = 0.;
1859 
1860  for(int i=0; i < NTRIAL; ++i) {
1861  // Get number of emissions
1862  vector<double> unresolvedEmissionTerm = countEmissions(trial, maxscale,
1863  newScale, 2, as0, asFSR, asISR, 3, fixpdf, fixas);
1864  nWeight1 += unresolvedEmissionTerm[1];
1865  }
1866  w += nWeight1/double(NTRIAL) + nWeight2/double(NTRIAL);
1867 
1868  // Calculate pdf ratios: Get both sides of event
1869  int inP = 3;
1870  int inM = 4;
1871  int sideP = (mother->state[inP].pz() > 0) ? 1 :-1;
1872  int sideM = (mother->state[inM].pz() > 0) ? 1 :-1;
1873 
1874  if ( mother->state[inP].colType() != 0 ) {
1875  // Find x value and flavour
1876  double x = getCurrentX(sideP);
1877  int flav = getCurrentFlav(sideP);
1878  // Find numerator scale
1879  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1880  // Monte Carlo integrand.
1881  double intPDF4 = monteCarloPDFratios(flav, x, scaleNum, newScale,
1882  mergingHooksPtr->muFinME(), as0, rndmPtr);
1883  w += intPDF4;
1884 
1885  }
1886 
1887  if ( mother->state[inM].colType() != 0 ) {
1888  // Find x value and flavour
1889  double x = getCurrentX(sideM);
1890  int flav = getCurrentFlav(sideM);
1891  // Find numerator scale
1892  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1893  // Monte Carlo integrand.
1894  double intPDF4 = monteCarloPDFratios(flav, x, scaleNum, newScale,
1895  mergingHooksPtr->muFinME(), as0, rndmPtr);
1896  w += intPDF4;
1897 
1898  }
1899 
1900  // Done
1901  return w;
1902 
1903 }
1904 
1905 //--------------------------------------------------------------------------
1906 
1907 // Function to generate the O(\alpha_s)-term of the \alpha_s-ratios
1908 // appearing in the CKKWL-weight.
1909 
1910 double History::weightFirstALPHAS( double as0, double muR,
1911  AlphaStrong * asFSR, AlphaStrong * asISR ) {
1912 
1913  // Use correct scale
1914  double newScale = scale;
1915  // Done
1916  if ( !mother ) return 0.;
1917  // Recurse
1918  double w = mother->weightFirstALPHAS( as0, muR, asFSR, asISR );
1919  // Find right scale
1920  int showerType = (mother->state[clusterIn.emittor].isFinal() ) ? 1 : -1;
1921  double b = 1.;
1922  double asScale = pow2( newScale );
1923  if ( mergingHooksPtr->unorderedASscalePrescip() == 1 )
1924  asScale = pow2( clusterIn.pT() );
1925  if (showerType == -1) {
1926  asScale += pow2( mergingHooksPtr->pT0ISR() );
1927  b = 1.;
1928  }
1929  // Find summand beta_0 / 2 * ln(muR^2/t_i) due to as expansion.
1930  double NF = 4.;
1931  double BETA0 = 11. - 2./3.* NF;
1932  // For fixed \alpha_s in matrix element
1933  w += as0 / (2.*M_PI) * 0.5 * BETA0 * log( (muR*muR) / (b*asScale) );
1934  // Done
1935  return w;
1936 
1937 }
1938 
1939 //--------------------------------------------------------------------------
1940 
1941 // Function to generate the O(\alpha_s)-term of the PDF-ratios
1942 // appearing in the CKKWL-weight.
1943 
1944 double History::weightFirstPDFs( double as0, double maxscale, double pdfScale,
1945  Rndm* rndmPtr ) {
1946 
1947  // Use correct scale
1948  double newScale = scale;
1949 
1950  if ( !mother ) {
1951 
1952  double wt = 0.;
1953 
1954  // Calculate PDF first leg
1955  if (state[3].colType() != 0) {
1956  // Find x value and flavour
1957  double x = 2.*state[3].e() / state[0].e();
1958  int flav = state[3].id();
1959  // Find numerator/denominator scale
1960  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1961  double scaleDen = mergingHooksPtr->muFinME();
1962  // Monte Carlo integrand.
1963  wt += monteCarloPDFratios(flav, x, scaleNum, scaleDen,
1964  mergingHooksPtr->muFinME(), as0, rndmPtr);
1965  }
1966  // Calculate PDF ratio for second leg
1967  if (state[4].colType() != 0) {
1968  // Find x value and flavour
1969  double x = 2.*state[4].e() / state[0].e();
1970  int flav = state[4].id();
1971  // Find numerator/denominator scale
1972  double scaleNum = (children.empty()) ? hardFacScale(state) : maxscale;
1973  double scaleDen = mergingHooksPtr->muFinME();
1974  // Monte Carlo integrand.
1975  wt += monteCarloPDFratios(flav, x, scaleNum, scaleDen,
1976  mergingHooksPtr->muFinME(), as0, rndmPtr);
1977  }
1978 
1979  // Done
1980  return wt;
1981  }
1982 
1983  // Remember new PDF scale n case true sclae should be used for un-ordered
1984  // splittings.
1985  double newPDFscale = newScale;
1986  if (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
1987  newPDFscale = clusterIn.pT();
1988 
1989  // Recurse
1990  double w = mother->weightFirstPDFs( as0, newScale, newPDFscale, rndmPtr);
1991 
1992  // Calculate pdf ratios: Get both sides of event
1993  int inP = 3;
1994  int inM = 4;
1995  int sideP = (mother->state[inP].pz() > 0) ? 1 :-1;
1996  int sideM = (mother->state[inM].pz() > 0) ? 1 :-1;
1997 
1998  if ( mother->state[inP].colType() != 0 ) {
1999  // Find x value and flavour
2000  double x = getCurrentX(sideP);
2001  int flav = getCurrentFlav(sideP);
2002  // Find numerator / denominator scales
2003  double scaleNum = (children.empty())
2004  ? hardFacScale(state)
2005  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2006  ? pdfScale : maxscale );
2007  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2008  ? clusterIn.pT() : newScale;
2009  // Monte Carlo integrand.
2010  w += monteCarloPDFratios(flav, x, scaleNum, scaleDen,
2011  mergingHooksPtr->muFinME(), as0, rndmPtr);
2012  }
2013 
2014  if ( mother->state[inM].colType() != 0 ) {
2015  // Find x value and flavour
2016  double x = getCurrentX(sideM);
2017  int flav = getCurrentFlav(sideM);
2018  // Find numerator / denominator scales
2019  double scaleNum = (children.empty())
2020  ? hardFacScale(state)
2021  : ( (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2022  ? pdfScale : maxscale );
2023  double scaleDen = (mergingHooksPtr->unorderedPDFscalePrescip() == 1)
2024  ? clusterIn.pT() : newScale;
2025  // Monte Carlo integrand.
2026  w += monteCarloPDFratios(flav, x, scaleNum, scaleDen,
2027  mergingHooksPtr->muFinME(), as0, rndmPtr);
2028  }
2029 
2030  // Done
2031  return w;
2032 
2033 }
2034 
2035 
2036 //--------------------------------------------------------------------------
2037 
2038 // Function to generate the O(\alpha_s)-term of the no-emission
2039 // probabilities appearing in the CKKWL-weight.
2040 
2041 double History::weightFirstEmissions(PartonLevel* trial, double as0,
2042  double maxscale, AlphaStrong * asFSR, AlphaStrong * asISR,
2043  bool fixpdf, bool fixas ) {
2044 
2045  // Use correct scale
2046  double newScale = scale;
2047  if ( !mother ) return 0.0;
2048  // Recurse
2049  double w = mother->weightFirstEmissions(trial, as0, newScale, asFSR, asISR,
2050  fixpdf, fixas );
2051  // Do nothing for empty state
2052  if (state.size() < 3) return 0.0;
2053  // Generate true average.
2054  double nWeight1 = 0.;
2055  double nWeight2 = 0.;
2056  for(int i=0; i < NTRIAL; ++i) {
2057  // Get number of emissions
2058  vector<double> unresolvedEmissionTerm = countEmissions(trial, maxscale,
2059  newScale, 2, as0, asFSR, asISR, 3, fixpdf, fixas);
2060  nWeight1 += unresolvedEmissionTerm[1];
2061  }
2062 
2063  w += nWeight1/double(NTRIAL) + nWeight2/double(NTRIAL);
2064 
2065  // Done
2066  return w;
2067 
2068 }
2069 
2070 //--------------------------------------------------------------------------
2071 
2072 // Function to return the factorisation scale of the hard process in Pythia.
2073 
2074 double History::hardFacScale(const Event& event) {
2075  // Declare output scale.
2076  double hardscale = 0.;
2077  // If scale should not be reset, done.
2078  if ( !mergingHooksPtr->resetHardQFac() ) return mergingHooksPtr->muF();
2079  // For pure QCD dijet events, calculate the hadronic cross section
2080  // of the hard process at the pT of the dijet system, rather than at fixed
2081  // arbitrary scale.
2082  if ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
2083  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0 ) {
2084  // Find the mT in the hard sub-process.
2085  vector <double> mT;
2086  for ( int i=0; i < event.size(); ++i)
2087  if ( event[i].isFinal() && event[i].colType() != 0 )
2088  mT.push_back( abs(event[i].mT2()) );
2089  if ( int(mT.size()) != 2 )
2090  hardscale = infoPtr->QFac();
2091  else
2092  hardscale = sqrt( min( mT[0], mT[1] ) );
2093  } else {
2094  hardscale = infoPtr->QFac();
2095  }
2096  // Done
2097  return hardscale;
2098 }
2099 
2100 //--------------------------------------------------------------------------
2101 
2102 // Function to return the factorisation scale of the hard process in Pythia.
2103 
2104 double History::hardRenScale(const Event& event) {
2105  // Declare output scale.
2106  double hardscale = 0.;
2107  // If scale should not be reset, done.
2108  if ( !mergingHooksPtr->resetHardQRen() ) return mergingHooksPtr->muR();
2109  // For pure QCD dijet events, calculate the hadronic cross section
2110  // of the hard process at the pT of the dijet system, rather than at fixed
2111  // arbitrary scale.
2112  if ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
2113  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0 ) {
2114  // Find the mT in the hard sub-process.
2115  vector <double> mT;
2116  for ( int i=0; i < event.size(); ++i)
2117  if ( event[i].isFinal()
2118  && ( event[i].colType() != 0 || event[i].id() == 22 ) )
2119  mT.push_back( abs(event[i].mT()) );
2120  if ( int(mT.size()) != 2 )
2121  hardscale = infoPtr->QRen();
2122  else
2123  hardscale = sqrt( mT[0]*mT[1] );
2124  } else {
2125  hardscale = infoPtr->QRen();
2126  }
2127  // Done
2128  return hardscale;
2129 }
2130 
2131 //--------------------------------------------------------------------------
2132 
2133 // Perform a trial shower using the \a pythia object between
2134 // maxscale down to this scale and return the corresponding Sudakov
2135 // form factor.
2136 // IN trialShower : Shower object used as trial shower
2137 // double : Maximum scale for trial shower branching
2138 // OUT 0.0 : trial shower emission outside allowed pT range
2139 // 1.0 : trial shower successful (any emission was below
2140 // the minimal scale )
2141 
2142 double History::doTrialShower( PartonLevel* trial, int type,
2143  double maxscaleIn, double minscaleIn ) {
2144 
2145  // Copy state to local process
2146  Event process = state;
2147  // Set starting scale.
2148  double startingScale = maxscaleIn;
2149  // Careful when setting shower starting scale for pure QCD and prompt
2150  // photon case.
2151  if ( mergingHooksPtr->getNumberOfClusteringSteps(process) == 0
2152  && ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
2153  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0 ) )
2154  startingScale = min( startingScale, hardFacScale(process) );
2155 
2156  // Set output.
2157  bool doVeto = false;
2158 
2159  while ( true ) {
2160 
2161  // Reset trialShower object
2162  trial->resetTrial();
2163  // Construct event to be showered
2164  Event event = Event();
2165  event.init("(hard process-modified)", particleDataPtr);
2166  event.clear();
2167 
2168  // Reset process scale so that shower starting scale is correctly set.
2169  process.scale(startingScale);
2170  doVeto = false;
2171 
2172  // Get pT before reclustering
2173  double minScale = (minscaleIn > 0.) ? minscaleIn : scale;
2174 
2175  // If the maximal scale and the minimal scale coincide (as would
2176  // be the case for the corrected scales of unordered histories),
2177  // do not generate Sudakov
2178  if (minScale >= startingScale) break;
2179 
2180  // Find z and pT values at which the current state was formed, to
2181  // ensure that the showers can order the next emission correctly in
2182  // rapidity, if required.
2183  // NOT CORRECTLY SET FOR HIGHEST MULTIPLICITY STATE!
2184  double z = ( mergingHooksPtr->getNumberOfClusteringSteps(state) == 0
2185  || !mother )
2186  ? 0.5
2187  : mother->getCurrentZ(clusterIn.emittor,clusterIn.recoiler,
2188  clusterIn.emitted);
2189  // Store z and pT values at which the current state was formed
2190  infoPtr->zNowISR(z);
2191  infoPtr->pT2NowISR(pow(startingScale,2));
2192  infoPtr->hasHistory(true);
2193 
2194  // Perform trial shower emission
2195  trial->next(process,event);
2196  // Get trial shower pT.
2197  double pTtrial = trial->pTLastInShower();
2198  int typeTrial = trial->typeLastInShower();
2199 
2200  // Clear parton systems.
2201  trial->resetTrial();
2202 
2203  // Get veto (merging) scale value
2204  double vetoScale = (mother) ? 0. : mergingHooksPtr->tms();
2205  // Get merging scale in current event
2206  double tnow = mergingHooksPtr->tmsNow( event );
2207 
2208  // Done if evolution scale has fallen below minimum
2209  if ( pTtrial < minScale ) break;
2210  // Reset starting scale.
2211  startingScale = pTtrial;
2212 
2213  // Continue if this state is below the veto scale
2214  if ( tnow < vetoScale && vetoScale > 0. ) continue;
2215 
2216  // Retry if the trial emission was not allowed.
2217  if ( mergingHooksPtr->canVetoTrialEmission()
2218  && mergingHooksPtr->doVetoTrialEmission( process, event) ) continue;
2219 
2220  // Only consider allowed emissions for veto:
2221  // Only allow MPI for MPI no-emission probability.
2222  if ( type == -1 && typeTrial != 1 ) continue;
2223  // Only allow ISR or FSR for radiative no-emission probability.
2224  if ( type == 1 && !(typeTrial == 2 || typeTrial >= 3) ) continue;
2225 
2226  // Veto event if trial pT was above the next nodal scale.
2227  if ( pTtrial > minScale ) doVeto = true;
2228 
2231  //if ( !mother && tnow > vetoScale && vetoScale > 0. ) doVeto = true;
2232 
2233  // For 2 -> 2 pure QCD state, do not allow multiparton interactions
2234  // above the kinematical pT of the 2 -> 2 state.
2235  if ( type == -1
2236  && typeTrial == 1
2237  && mergingHooksPtr->getNumberOfClusteringSteps(process) == 0
2238  && ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
2239  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0 )
2240  && pTtrial > hardFacScale(process) )
2241  return 0.0;
2242 
2243  // If pT of trial emission was in suitable range (trial shower
2244  // successful), return false
2245  if ( pTtrial < minScale ) doVeto = false;
2246 
2247  // Done
2248  break;
2249 
2250  }
2251 
2252  // Done
2253  return ( (doVeto) ? 0. : 1. );
2254 }
2255 
2256 //--------------------------------------------------------------------------
2257 
2258 // Assume we have a vector of i elements containing indices into
2259 // another vector with N elements. Update the indices so that all
2260 // unique combinations (starting from 0,1,2,3, ...) are
2261 // covered. Return false when all combinations have been ehausted.
2262 
2263 bool History::updateind(vector<int> & ind, int i, int N) {
2264  if ( i < 0 ) return false;
2265  if ( ++ind[i] < N ) return true;
2266  if ( !updateind(ind, i - 1, N - 1) ) return false;
2267  ind[i] = ind[i - 1] + 1;
2268  return true;
2269 }
2270 
2271 //--------------------------------------------------------------------------
2272 
2273 // Return the expansion of the no-emission probability up to the Nth
2274 // term. Optionally calculate the the terms using fixed alphaS
2275 // and/or PDF ratios.
2276 
2277 vector<double>
2278 History::countEmissions(PartonLevel* trial, double maxscale,
2279  double minscale, int showerType, double as0,
2280  AlphaStrong * asFSR, AlphaStrong * asISR, int N = 1,
2281  bool fixpdf = true, bool fixas = true) {
2282 
2283  if ( N < 0 ) return vector<double>();
2284  vector<double> result(N+1);
2285  result[0] = 1.0;
2286  if ( N < 1 ) return result;
2287 
2288  // Copy state to local process
2289  Event process = state;
2290 
2291  double startingScale = maxscale;
2292  // Careful when setting shower starting scale for pure QCD and prompt
2293  // photon case.
2294  if ( mergingHooksPtr->getNumberOfClusteringSteps(process) == 0
2295  && ( mergingHooksPtr->getProcessString().compare("pp>jj") == 0
2296  || mergingHooksPtr->getProcessString().compare("pp>aj") == 0 ) )
2297  startingScale = min( startingScale, hardFacScale(process) );
2298 
2299  vector<double> wts;
2300 
2301  while ( true ) {
2302  // Reset trialShower object
2303  trial->resetTrial();
2304  // Construct event to be showered
2305  Event event = Event();
2306  event.init("(hard process-modified)", particleDataPtr);
2307  event.clear();
2308 
2309  // Reset process scale
2310  process.scale(startingScale);
2311 
2312  // If the maximal scale and the minimal scale coincide (as would
2313  // be the case for the corrected scales of unordered histories),
2314  // do not generate Sudakov
2315  if (minscale >= startingScale) return result;
2316 
2317  // Find z and pT values at which the current state was formed, to
2318  // ensure that the showers can order the next emission correctly in
2319  // rapidity, if required
2320  if ( mother ) {
2321  double z = ( mergingHooksPtr->getNumberOfClusteringSteps(state) == 0)
2322  ? 0.5
2323  : mother->getCurrentZ(clusterIn.emittor,clusterIn.recoiler,
2324  clusterIn.emitted);
2325  // Store z and pT values at which the current state was formed
2326  infoPtr->zNowISR(z);
2327  infoPtr->pT2NowISR(pow(startingScale,2));
2328  infoPtr->hasHistory(true);
2329  }
2330 
2331  // Perform trial shower emission
2332  trial->next(process,event);
2333 
2334  // Get trial shower pT
2335  double pTtrial = trial->pTLastInShower();
2336  int typeTrial = trial->typeLastInShower();
2337 
2338  // Clear parton systems.
2339  trial->resetTrial();
2340 
2341  // Get veto (merging) scale value
2342  double vetoScale = (mother) ? 0. : mergingHooksPtr->tms();
2343  // Get merging scale in current event
2344  double tnow = mergingHooksPtr->tmsNow( event );
2345 
2346  // Save scale of current state.
2347  startingScale = pTtrial;
2348  // If the scale of the current state is below the minimal scale, exit.
2349  if ( pTtrial < minscale ) break;
2350  // If this state is below the merging scale, do not count emission.
2351  if ( tnow < vetoScale && vetoScale > 0. ) continue;
2352  // Retry if the trial emission was not allowed.
2353  if ( mergingHooksPtr->canVetoTrialEmission()
2354  && mergingHooksPtr->doVetoTrialEmission( process, event) ) continue;
2355 
2356  // Check if a new emission should be generated, either because
2357  // the latest emission was not of the desired kind or if the
2358  // emission was above the minimal scale
2359  double alphaSinPS = as0;
2360  double pdfs = 1.0;
2361  // Initial state splittings.
2362  if ( (showerType == -1 || showerType == 2) && typeTrial == 2 ) {
2363  // Get weight to translate to alpha_s at fixed renormalisation scale.
2364  if ( fixas ) alphaSinPS = (*asISR).alphaS(pTtrial*pTtrial);
2365  // Get weight to translate to PDFs at fixed factorisation scale.
2366  if ( fixpdf )
2367  pdfs = pdfFactor( event, typeTrial, pTtrial,
2368  mergingHooksPtr->muFinME() );
2369  // Final state splittings.
2370  } else if ( (showerType == 1 || showerType == 2) && typeTrial >= 3 ) {
2371  // Get weight to translate to alpha_s at fixed renormalisation scale.
2372  if ( fixas ) alphaSinPS = (*asFSR).alphaS(pTtrial*pTtrial);
2373  // Get weight to translate to PDFs at fixed factorisation scale. Needed
2374  // for final state splittings with initial state recoiler.
2375  if ( fixpdf )
2376  pdfs = pdfFactor( event, typeTrial, pTtrial,
2377  mergingHooksPtr->muFinME() );
2378  }
2379 
2380  // Save weight correcting to emission generated with fixed scales.
2381  if ( typeTrial == 2 || typeTrial >= 3 )
2382  wts.push_back(as0/alphaSinPS*pdfs);
2383 
2384  }
2385 
2386  for ( int n = 1; n <= min(N, int(wts.size())); ++n ) {
2387  vector<int> ind(N);
2388  for ( int i = 0; i < N; ++i ) ind[i] = i;
2389  do {
2390  double x = 1.0;
2391  for ( int j = 0; j < n; ++j ) x *= wts[ind[j]];
2392  result[n] += x;
2393  } while ( updateind(ind, n - 1, wts.size()) );
2394  if ( n%2 ) result[n] *= -1.0;
2395  }
2396 
2397  // Done
2398  return result;
2399 }
2400 
2401 //--------------------------------------------------------------------------
2402 
2403 // Function to integrate PDF ratios between two scales over x and t,
2404 // where the PDFs are always evaluated at the lower t-integration limit
2405 
2406 double History::monteCarloPDFratios(int flav, double x, double maxScale,
2407  double minScale, double pdfScale, double asME, Rndm* rndmPtr) {
2408 
2409  // Perform numerical integration for PDF ratios
2410  // Prefactor is as/2PI
2411  double factor = asME / (2.*M_PI);
2412  // Scale integration just produces a multiplicative logarithm
2413  factor *= log(maxScale/minScale);
2414 
2415  // For identical scales, done
2416  if (factor == 0.) return 0.;
2417 
2418  // Declare constants
2419  double CF = 4./3.;
2420  double CA = 3.;
2421  double NF = 4.;
2422  double TR = 1./2.;
2423 
2424  double integral = 0.;
2425  double RN = rndmPtr->flat();
2426 
2427  if (flav == 21) {
2428  double zTrial = pow(x,RN);
2429  integral = -log(x) * zTrial *
2430  integrand(flav, x, pdfScale, zTrial);
2431  integral += 1./6.*(11.*CA - 4.*NF*TR)
2432  + 2.*CA*log(1.-x);
2433  } else {
2434  double zTrial = x + RN*(1. - x);
2435  integral = (1.-x) *
2436  integrand(flav, x, pdfScale, zTrial);
2437  integral += 3./2.*CF
2438  + 2.*CF*log(1.-x);
2439  }
2440 
2441  // Done
2442  return (factor*integral);
2443 }
2444 
2445 /*--------------- METHODS USED FOR CONTRUCTION OF ALL HISTORIES --------- */
2446 
2447 // Check if a ordered (and complete) path has been found in the
2448 // initial node, in which case we will no longer be interested in
2449 // any unordered paths.
2450 
2451 bool History::onlyOrderedPaths() {
2452  if ( !mother || foundOrderedPath ) return foundOrderedPath;
2453  return foundOrderedPath = mother->onlyOrderedPaths();
2454 }
2455 
2456 //--------------------------------------------------------------------------
2457 
2458 // Check if a STRONGLY ordered (and complete) path has been found in the
2459 // initial node, in which case we will no longer be interested in
2460 // any unordered paths.
2461 
2462 bool History::onlyStronglyOrderedPaths() {
2463  if ( !mother || foundStronglyOrderedPath ) return foundStronglyOrderedPath;
2464  return foundStronglyOrderedPath = mother->onlyStronglyOrderedPaths();
2465 }
2466 
2467 //--------------------------------------------------------------------------
2468 
2469 // Check if an allowed (according to user-criterion) path has been found in
2470 // the initial node, in which case we will no longer be interested in
2471 // any forbidden paths.
2472 
2473 bool History::onlyAllowedPaths() {
2474  if ( !mother || foundAllowedPath ) return foundAllowedPath;
2475  return foundAllowedPath = mother->onlyAllowedPaths();
2476 }
2477 
2478 //--------------------------------------------------------------------------
2479 
2480 // When a full path has been found, register it with the initial
2481 // history node.
2482 // IN History : History to be registered as path
2483 // bool : Specifying if clusterings so far were ordered
2484 // bool : Specifying if path is complete down to 2->2 process
2485 // OUT true if History object forms a plausible path (eg prob>0 ...)
2486 
2487 bool History::registerPath(History & l, bool isOrdered,
2488  bool isStronglyOrdered, bool isAllowed, bool isComplete) {
2489 
2490  // We are not interested in improbable paths.
2491  if ( l.prob <= 0.0)
2492  return false;
2493  // We only register paths in the initial node.
2494  if ( mother ) return mother->registerPath(l, isOrdered,
2495  isStronglyOrdered, isAllowed, isComplete);
2496 
2497  // Again, we are not interested in improbable paths.
2498  if ( sumpath == sumpath + l.prob )
2499  return false;
2500  if ( mergingHooksPtr->canCutOnRecState()
2501  && foundAllowedPath && !isAllowed )
2502  return false;
2503  if ( mergingHooksPtr->enforceStrongOrdering()
2504  && foundStronglyOrderedPath && !isStronglyOrdered )
2505  return false;
2506  if ( mergingHooksPtr->orderHistories()
2507  && foundOrderedPath && !isOrdered ) {
2508  // Prefer complete or allowed paths to ordered paths.
2509  if ( (!foundCompletePath && isComplete)
2510  || (!foundAllowedPath && isAllowed) ) ;
2511  else return false;
2512  }
2513 
2514  if ( foundCompletePath && !isComplete )
2515  return false;
2516  if ( !mergingHooksPtr->canCutOnRecState()
2517  && !mergingHooksPtr->allowCutOnRecState() )
2518  foundAllowedPath = true;
2519 
2520  if ( mergingHooksPtr->canCutOnRecState() && isAllowed && isComplete) {
2521  if ( !foundAllowedPath || !foundCompletePath ) {
2522  // If this is the first complete, allowed path, discard the
2523  // old, disallowed or incomplete ones.
2524  paths.clear();
2525  sumpath = 0.0;
2526  }
2527  foundAllowedPath = true;
2528 
2529  }
2530 
2531  if ( mergingHooksPtr->enforceStrongOrdering() && isStronglyOrdered
2532  && isComplete ) {
2533  if ( !foundStronglyOrderedPath || !foundCompletePath ) {
2534  // If this is the first complete, ordered path, discard the
2535  // old, non-ordered or incomplete ones.
2536  paths.clear();
2537  sumpath = 0.0;
2538  }
2539  foundStronglyOrderedPath = true;
2540  foundCompletePath = true;
2541 
2542  }
2543 
2544  if ( mergingHooksPtr->orderHistories() && isOrdered && isComplete ) {
2545  if ( !foundOrderedPath || !foundCompletePath ) {
2546  // If this is the first complete, ordered path, discard the
2547  // old, non-ordered or incomplete ones.
2548  paths.clear();
2549  sumpath = 0.0;
2550  }
2551  foundOrderedPath = true;
2552  foundCompletePath = true;
2553 
2554  }
2555 
2556  if ( isComplete ) {
2557  if ( !foundCompletePath ) {
2558  // If this is the first complete path, discard the old,
2559  // incomplete ones.
2560  paths.clear();
2561  sumpath = 0.0;
2562  }
2563  foundCompletePath = true;
2564  }
2565 
2566  // Remember, if this path is ordered, even if no ordering is required
2567  if ( isOrdered ) {
2568  foundOrderedPath = true;
2569  }
2570 
2571  // Index path by probability
2572  sumpath += l.prob;
2573  paths[sumpath] = &l;
2574 
2575  return true;
2576 }
2577 
2578 //--------------------------------------------------------------------------
2579 
2580 // For the history-defining state (and if necessary interfering
2581 // states), find all possible clusterings.
2582 // NO INPUT
2583 // OUT vector of all (rad,rec,emt) systems
2584 
2585 vector<Clustering> History::getAllQCDClusterings() {
2586  vector<Clustering> ret;
2587  // Initialise vectors to keep track of position of partons in the
2588  // history-defining state
2589  vector <int> PosFinalPartn;
2590  vector <int> PosInitPartn;
2591  vector <int> PosFinalGluon;
2592  vector <int> PosFinalQuark;
2593  vector <int> PosFinalAntiq;
2594  vector <int> PosInitGluon;
2595  vector <int> PosInitQuark;
2596  vector <int> PosInitAntiq;
2597 
2598  // Search event record for final state particles and store these in
2599  // quark, anti-quark and gluon vectors
2600  for ( int i=0; i < state.size(); ++i )
2601  if ( state[i].isFinal() && state[i].colType() !=0 ) {
2602  // Store final partons
2603  if ( state[i].id() == 21 ) PosFinalGluon.push_back(i);
2604  else if ( state[i].idAbs() < 10 && state[i].id() > 0)
2605  PosFinalQuark.push_back(i);
2606  else if ( state[i].idAbs() < 10 && state[i].id() < 0)
2607  PosFinalAntiq.push_back(i);
2608  } else if (state[i].status() == -21 && state[i].colType() != 0 ) {
2609  // Store initial partons
2610  if ( state[i].id() == 21 ) PosInitGluon.push_back(i);
2611  else if ( state[i].idAbs() < 10 && state[i].id() > 0)
2612  PosInitQuark.push_back(i);
2613  else if ( state[i].idAbs() < 10 && state[i].id() < 0)
2614  PosInitAntiq.push_back(i);
2615  }
2616 
2617  // Get all clusterings for input state
2618  vector<Clustering> systems;
2619  systems = getQCDClusterings(state);
2620  ret.insert(ret.end(), systems.begin(), systems.end());
2621  systems.resize(0);
2622 
2623  // If valid clusterings were found, return
2624  if ( !ret.empty() ) return ret;
2625  // If no clusterings have been found until now, try to find
2626  // clusterings of diagrams that interfere with the current one
2627  // (i.e. change the colours of the current event slightly and run
2628  // search again)
2629  else if ( ret.empty()
2630  && mergingHooksPtr->allowColourShuffling() ) {
2631  Event NewState = Event(state);
2632  // Start with changing final state quark colour
2633  for(int i = 0; i < int(PosFinalQuark.size()); ++i) {
2634  // Never change the hard process candidates
2635  if ( mergingHooksPtr->hardProcess.matchesAnyOutgoing(PosFinalQuark[i],
2636  NewState) )
2637  continue;
2638  int col = NewState[PosFinalQuark[i]].col();
2639  for(int j = 0; j < int(PosInitAntiq.size()); ++j) {
2640  // Now swap colours
2641  int acl = NewState[PosInitAntiq[j]].acol();
2642  if ( col == acl ) continue;
2643  NewState[PosFinalQuark[i]].col(acl);
2644  NewState[PosInitAntiq[j]].acol(col);
2645  systems = getQCDClusterings(NewState);
2646  if (!systems.empty()) {
2647  state = NewState;
2648  NewState.clear();
2649  ret.insert(ret.end(), systems.begin(), systems.end());
2650  systems.resize(0);
2651  return ret;
2652  }
2653  }
2654  }
2655  // Now change final state antiquark anticolour
2656  for(int i = 0; i < int(PosFinalAntiq.size()); ++i) {
2657  // Never change the hard process candidates
2658  if ( mergingHooksPtr->hardProcess.matchesAnyOutgoing(PosFinalAntiq[i],
2659  NewState) )
2660  continue;
2661  int acl = NewState[PosFinalAntiq[i]].acol();
2662  for(int j = 0; j < int(PosInitQuark.size()); ++j) {
2663  // Now swap colours
2664  int col = NewState[PosInitQuark[j]].col();
2665  if ( col == acl ) continue;
2666  NewState[PosFinalAntiq[i]].acol(col);
2667  NewState[PosInitQuark[j]].col(acl);
2668  systems = getQCDClusterings(NewState);
2669  if (!systems.empty()) {
2670  state = NewState;
2671  NewState.clear();
2672  ret.insert(ret.end(), systems.begin(), systems.end());
2673  systems.resize(0);
2674  return ret;
2675  }
2676  }
2677  }
2678 
2679  if ( !ret.empty() ) {
2680  string message="Warning in History::getAllQCDClusterings: Changed";
2681  message+=" colour structure to allow at least one clustering.";
2682  infoPtr->errorMsg(message);
2683  }
2684 
2685  }
2686 
2687  // Done
2688  return ret;
2689 }
2690 
2691 //--------------------------------------------------------------------------
2692 
2693 // For one given state, find all possible clusterings.
2694 // IN Event : state to be investigated
2695 // OUT vector of all (rad,rec,emt) systems in the state
2696 
2697 vector<Clustering> History::getQCDClusterings( const Event& event) {
2698  vector<Clustering> ret;
2699 
2700  // Initialise vectors to keep track of position of partons in the
2701  // input event
2702  vector <int> PosFinalPartn;
2703  vector <int> PosInitPartn;
2704 
2705  vector <int> PosFinalGluon;
2706  vector <int> PosFinalQuark;
2707  vector <int> PosFinalAntiq;
2708  vector <int> PosInitGluon;
2709  vector <int> PosInitQuark;
2710  vector <int> PosInitAntiq;
2711 
2712  // Search event record for final state particles and store these in
2713  // quark, anti-quark and gluon vectors
2714  for (int i=0; i < event.size(); ++i)
2715  if ( event[i].isFinal() && event[i].colType() !=0 ) {
2716  // Store final partons
2717  PosFinalPartn.push_back(i);
2718  if ( event[i].id() == 21 ) PosFinalGluon.push_back(i);
2719  else if ( event[i].idAbs() < 10 && event[i].id() > 0)
2720  PosFinalQuark.push_back(i);
2721  else if ( event[i].idAbs() < 10 && event[i].id() < 0)
2722  PosFinalAntiq.push_back(i);
2723  } else if ( event[i].status() == -21 && event[i].colType() != 0 ) {
2724  // Store initial partons
2725  PosInitPartn.push_back(i);
2726  if ( event[i].id() == 21 ) PosInitGluon.push_back(i);
2727  else if ( event[i].idAbs() < 10 && event[i].id() > 0)
2728  PosInitQuark.push_back(i);
2729  else if ( event[i].idAbs() < 10 && event[i].id() < 0)
2730  PosInitAntiq.push_back(i);
2731  }
2732 
2733  int nFiGluon = int(PosFinalGluon.size());
2734  int nFiQuark = int(PosFinalQuark.size());
2735  int nFiAntiq = int(PosFinalAntiq.size());
2736  int nInGluon = int(PosInitGluon.size());
2737  int nInQuark = int(PosInitQuark.size());
2738  int nInAntiq = int(PosInitAntiq.size());
2739 
2740  vector<Clustering> systems;
2741 
2742  // Find rad + emt + rec systems:
2743  // (1) Start from gluon and find all (rad,rec,emt=gluon) triples
2744  for (int i = 0; i < nFiGluon; ++i) {
2745  int EmtGluon = PosFinalGluon[i];
2746  systems = findQCDTriple( EmtGluon, 2, event, PosFinalPartn, PosInitPartn);
2747  ret.insert(ret.end(), systems.begin(), systems.end());
2748  systems.resize(0);
2749  }
2750 
2751  // For more than one quark-antiquark pair in final state, check for
2752  // g -> qqbar splittings
2753  bool check_g2qq = true;
2754  if ( ( ( nInQuark + nInAntiq == 0 )
2755  && (nInGluon == 0)
2756  && (nFiQuark == 1) && (nFiAntiq == 1) )
2757  || ( ( nFiQuark + nFiAntiq == 0)
2758  && (nInQuark == 1) && (nInAntiq == 1) ) )
2759  check_g2qq = false;
2760 
2761  if ( check_g2qq ) {
2762 
2763  // (2) Start from quark and find all (rad,rec,emt=quark) triples
2764  // ( when g -> q qbar occured )
2765  for( int i=0; i < nFiQuark; ++i) {
2766  int EmtQuark = PosFinalQuark[i];
2767  systems = findQCDTriple( EmtQuark,1,event, PosFinalPartn, PosInitPartn);
2768  ret.insert(ret.end(), systems.begin(), systems.end());
2769  systems.resize(0);
2770  }
2771 
2772  // (3) Start from anti-quark and find all (rad,rec,emt=anti-quark)
2773  // triples ( when g -> q qbar occured )
2774  for( int i=0; i < nFiAntiq; ++i) {
2775  int EmtAntiq = PosFinalAntiq[i];
2776  systems = findQCDTriple( EmtAntiq,1,event, PosFinalPartn, PosInitPartn);
2777  ret.insert(ret.end(), systems.begin(), systems.end());
2778  systems.resize(0);
2779  }
2780  }
2781 
2782  return ret;
2783 }
2784 
2785 //--------------------------------------------------------------------------
2786 
2787 // Function to construct (rad,rec,emt) triples from the event
2788 // IN int : Position of Emitted in event record for which
2789 // dipoles should be constructed
2790 // int : Colour topogy to be tested
2791 // 1= g -> qqbar, causing 2 -> 2 dipole splitting
2792 // 2= q(bar) -> q(bar) g && g -> gg,
2793 // causing a 2 -> 3 dipole splitting
2794 // Event : event record to be checked for ptential partners
2795 // OUT vector of all allowed radiator+recoiler+emitted triples
2796 
2797 vector<Clustering> History::findQCDTriple (int EmtTagIn, int colTopIn,
2798  const Event& event,
2799  vector<int> PosFinalPartn,
2800  vector <int> PosInitPartn ) {
2801 
2802  // Copy input parton tag
2803  int EmtTag = EmtTagIn;
2804  // Copy input colour topology tag
2805  // (1: g --> qqbar splitting present, 2:rest)
2806  int colTop = colTopIn;
2807 
2808  // Initialise FinalSize
2809  int FinalSize = int(PosFinalPartn.size());
2810  int InitSize = int(PosInitPartn.size());
2811  int Size = InitSize + FinalSize;
2812 
2813  vector<Clustering> clus;
2814 
2815  // Search final partons to find partons colour-connected to
2816  // event[EmtTag], choose radiator, then choose recoiler
2817  for ( int a = 0; a < Size; ++a ) {
2818  int i = (a < FinalSize)? a : (a - FinalSize) ;
2819  int iRad = (a < FinalSize)? PosFinalPartn[i] : PosInitPartn[i];
2820 
2821  if ( event[iRad].col() == event[EmtTag].col()
2822  && event[iRad].acol() == event[EmtTag].acol() )
2823  continue;
2824 
2825  if (iRad != EmtTag ) {
2826  int pTdef = event[iRad].isFinal() ? 1 : -1;
2827  int sign = (a < FinalSize)? 1 : -1 ;
2828 
2829  // First colour topology: g --> qqbar. Here, emt & rad should
2830  // have same flavour (causes problems for gamma->qqbar).
2831  if (colTop == 1) {
2832 
2833  if ( event[iRad].id() == -sign*event[EmtTag].id() ) {
2834  int col = -1;
2835  int acl = -1;
2836  if (event[iRad].id() < 0) {
2837  col = event[EmtTag].acol();
2838  acl = event[iRad].acol();
2839  } else {
2840  col = event[EmtTag].col();
2841  acl = event[iRad].col();
2842  }
2843  // Recoiler
2844  int iRec = 0;
2845  // Colour partner
2846  int iPartner = 0;
2847 
2848  if (col > 0) {
2849  // Find recoiler by colour
2850  iRec = FindCol(col,iRad,EmtTag,event,1,true);
2851  // In initial state splitting has final state colour partner,
2852  // Save both partner and recoiler
2853  if ( (sign < 0) && (event[iRec].isFinal()) ) {
2854  // Save colour recoiler
2855  iPartner = iRec;
2856  // Reset kinematic recoiler to initial state parton
2857  for(int l = 0; l < int(PosInitPartn.size()); ++l)
2858  if (PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
2859  // For final state splittings, colour partner and recoiler are
2860  // identical
2861  } else {
2862  iPartner = iRec;
2863  }
2864  if ( iRec != 0 && iPartner != 0
2865  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
2866  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
2867  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
2868  continue;
2869  }
2870 
2871  // Reset partner
2872  iPartner = 0;
2873  // Find recoiler by colour
2874  iRec = FindCol(col,iRad,EmtTag,event,2,true);
2875  // In initial state splitting has final state colour partner,
2876  // Save both partner and recoiler
2877  if ( (sign < 0) && (event[iRec].isFinal()) ) {
2878  // Save colour recoiler
2879  iPartner = iRec;
2880  // Reset kinematic recoiler to initial state parton
2881  for(int l = 0; l < int(PosInitPartn.size()); ++l)
2882  if (PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
2883  // For final state splittings, colour partner and recoiler are
2884  // identical
2885  } else {
2886  iPartner = iRec;
2887  }
2888  if ( iRec != 0 && iPartner != 0
2889  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
2890  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
2891  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
2892  continue;
2893  }
2894  }
2895 
2896 
2897  if (acl > 0) {
2898 
2899  // Reset partner
2900  iPartner = 0;
2901  // Find recoiler by colour
2902  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
2903  // In initial state splitting has final state colour partner,
2904  // Save both partner and recoiler
2905  if ( (sign < 0) && (event[iRec].isFinal()) ) {
2906  // Save colour recoiler
2907  iPartner = iRec;
2908  // Reset kinematic recoiler to initial state parton
2909  for(int l = 0; l < int(PosInitPartn.size()); ++l)
2910  if (PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
2911  // For final state splittings, colour partner and recoiler are
2912  // identical
2913  } else {
2914  iPartner = iRec;
2915  }
2916  if ( iRec != 0 && iPartner != 0
2917  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
2918  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
2919  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
2920  continue;
2921  }
2922 
2923  // Reset partner
2924  iPartner = 0;
2925  // Find recoiler by colour
2926  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
2927  // In initial state splitting has final state colour partner,
2928  // Save both partner and recoiler
2929  if ( (sign < 0) && (event[iRec].isFinal()) ) {
2930  // Save colour recoiler
2931  iPartner = iRec;
2932  // Reset kinematic recoiler to initial state parton
2933  for(int l = 0; l < int(PosInitPartn.size()); ++l)
2934  if (PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
2935  // For final state splittings, colour partner and recoiler are
2936  // identical
2937  } else {
2938  iPartner = iRec;
2939  }
2940  if ( iRec != 0 && iPartner != 0
2941  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
2942  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
2943  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
2944  continue;
2945  }
2946  }
2947  // Initial gluon splitting
2948  } else if ( event[iRad].id() == 21
2949  &&( event[iRad].col() == event[EmtTag].col()
2950  || event[iRad].acol() == event[EmtTag].acol() )) {
2951  // For an initial state radiator, always set recoiler
2952  // to the other initial state parton (recoil is taken
2953  // by full remaining system, so this is just a
2954  // labelling for such a process)
2955  int RecInit = 0;
2956  for(int l = 0; l < int(PosInitPartn.size()); ++l)
2957  if (PosInitPartn[l] != iRad) RecInit = PosInitPartn[l];
2958 
2959  // Find the colour connected partner
2960  // Find colour index of radiator before splitting
2961  int col = getRadBeforeCol(iRad, EmtTag, event);
2962  int acl = getRadBeforeAcol(iRad, EmtTag, event);
2963 
2964  // Find the correct partner: If a colour line has split,
2965  // the partner is connected to the radiator before the splitting
2966  // by a colour line (same reasoning for anticolour). The colour
2967  // that split is the colour appearing twice in the
2968  // radiator + emitted pair.
2969  // Thus, if we remove a colour index with the clustering,
2970  // we should look for a colour partner, else look for
2971  // an anticolour partner
2972  int colRemove = (event[iRad].col() == event[EmtTag].col())
2973  ? event[iRad].col() : 0;
2974 
2975  int iPartner = 0;
2976  if (colRemove > 0 && col > 0)
2977  iPartner = FindCol(col,iRad,EmtTag,event,1,true)
2978  + FindCol(col,iRad,EmtTag,event,2,true);
2979  else if (colRemove > 0 && acl > 0)
2980  iPartner = FindCol(acl,iRad,EmtTag,event,1,true)
2981  + FindCol(acl,iRad,EmtTag,event,2,true);
2982 
2983  if ( allowedClustering( iRad, EmtTag, RecInit, iPartner, event ) ) {
2984  clus.push_back( Clustering(EmtTag, iRad, RecInit, iPartner,
2985  pTLund(event[iRad],event[EmtTag],event[RecInit], pTdef) ));
2986  continue;
2987  }
2988  }
2989 
2990  // Second colour topology: Gluon emission
2991 
2992  } else {
2993  if ( (event[iRad].col() == event[EmtTag].acol())
2994  || (event[iRad].acol() == event[EmtTag].col())
2995  || (event[iRad].col() == event[EmtTag].col())
2996  || (event[iRad].acol() == event[EmtTag].acol()) ) {
2997  // For the rest, choose recoiler to have a common colour
2998  // tag with radiator, while not being the "Emitted"
2999 
3000  int col = -1;
3001  int acl = -1;
3002 
3003  if (event[iRad].isFinal() ) {
3004 
3005  if ( event[iRad].id() < 0) {
3006  acl = event[EmtTag].acol();
3007  col = event[iRad].col();
3008  } else if ( event[iRad].id() > 0 && event[iRad].id() < 10) {
3009  col = event[EmtTag].col();
3010  acl = event[iRad].acol();
3011  } else {
3012  col = event[iRad].col();
3013  acl = event[iRad].acol();
3014  }
3015 
3016  int iRec = 0;
3017  if (col > 0) {
3018  iRec = FindCol(col,iRad,EmtTag,event,1,true);
3019  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
3020  if (iRec != 0
3021  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
3022  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
3023  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
3024  continue;
3025  }
3026 
3027  iRec = FindCol(col,iRad,EmtTag,event,2,true);
3028  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
3029  if (iRec != 0
3030  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
3031  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
3032  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
3033  continue;
3034  }
3035  }
3036 
3037 
3038  if (acl > 0) {
3039  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
3040  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
3041  if (iRec != 0
3042  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
3043  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
3044  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
3045  continue;
3046  }
3047 
3048  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
3049  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
3050  if (iRec != 0
3051  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
3052  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
3053  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
3054  continue;
3055  }
3056  }
3057 
3058  } else {
3059 
3060  // For an initial state radiator, always set recoiler
3061  // to the other initial state parton (recoil is taken
3062 
3063  // by full remaining system, so this is just a
3064  // labelling for such a process)
3065  int RecInit = 0;
3066  int iPartner = 0;
3067  for(int l = 0; l < int(PosInitPartn.size()); ++l)
3068  if (PosInitPartn[l] != iRad) RecInit = PosInitPartn[l];
3069 
3070  // Find the colour connected partner
3071  // Find colour index of radiator before splitting
3072  col = getRadBeforeCol(iRad, EmtTag, event);
3073  acl = getRadBeforeAcol(iRad, EmtTag, event);
3074 
3075  // Find the correct partner: If a colour line has split,
3076  // the partner is connected to the radiator before the splitting
3077  // by a colour line (same reasoning for anticolour). The colour
3078  // that split is the colour appearing twice in the
3079  // radiator + emitted pair.
3080  // Thus, if we remove a colour index with the clustering,
3081  // we should look for a colour partner, else look for
3082  // an anticolour partner
3083  int colRemove = (event[iRad].col() == event[EmtTag].col())
3084  ? event[iRad].col() : 0;
3085  iPartner = (colRemove > 0)
3086  ? FindCol(col,iRad,EmtTag,event,1,true)
3087  + FindCol(col,iRad,EmtTag,event,2,true)
3088  : FindCol(acl,iRad,EmtTag,event,1,true)
3089  + FindCol(acl,iRad,EmtTag,event,2,true);
3090 
3091  if ( allowedClustering( iRad, EmtTag, RecInit, iPartner, event)) {
3092  clus.push_back( Clustering(EmtTag, iRad, RecInit, iPartner,
3093  pTLund(event[iRad],event[EmtTag],event[RecInit], pTdef)));
3094 
3095  continue;
3096  }
3097  }
3098  }
3099  }
3100  }
3101  }
3102 
3103  // Done
3104  return clus;
3105 }
3106 
3107 //--------------------------------------------------------------------------
3108 
3109 // For the history-defining state (and if necessary interfering
3110 // states), find all possible clusterings.
3111 // NO INPUT
3112 // OUT vector of all (rad,rec,emt) systems
3113 
3114 vector<Clustering> History::getAllEWClusterings() {
3115  vector<Clustering> ret;
3116 
3117  // Get all clusterings for input state
3118  vector<Clustering> systems;
3119  systems = getEWClusterings(state);
3120  ret.insert(ret.end(), systems.begin(), systems.end());
3121  // Done
3122  return ret;
3123 }
3124 
3125 //--------------------------------------------------------------------------
3126 
3127 // For one given state, find all possible clusterings.
3128 // IN Event : state to be investigated
3129 // OUT vector of all (rad,rec,emt) systems in the state
3130 
3131 vector<Clustering> History::getEWClusterings( const Event& event) {
3132  vector<Clustering> ret;
3133 
3134  // Initialise vectors to keep track of position of partons in the
3135  // input event
3136  vector <int> PosFinalPartn;
3137  vector <int> PosInitPartn;
3138  vector <int> PosFinalW;
3139 
3140  // Search event record for final state particles and store these in
3141  // quark, anti-quark and gluon vectors
3142  for ( int i=0; i < event.size(); ++i )
3143  if ( event[i].isFinal() && abs(event[i].colType()) == 1 ) {
3144  // Store final partons
3145  PosFinalPartn.push_back(i);
3146  } else if ( event[i].status() == -21 && abs(event[i].colType()) == 1 ) {
3147  // Store initial partons
3148  PosInitPartn.push_back(i);
3149  }
3150  // Search event record for final W
3151  for ( int i=0; i < event.size(); ++i )
3152  if ( event[i].isFinal() && event[i].idAbs() == 24 )
3153  PosFinalW.push_back( i );
3154 
3155  vector<Clustering> systems;
3156  // Find rad + emt + rec systems:
3157  // (1) Start from W boson and find all (rad,rec,emt=W) triples
3158  for ( int i = 0; i < int(PosFinalW.size()); ++i ) {
3159  int EmtW = PosFinalW[i];
3160  systems = findEWTriple( EmtW, event, PosFinalPartn);
3161  ret.insert(ret.end(), systems.begin(), systems.end());
3162  systems.resize(0);
3163  }
3164 
3165  return ret;
3166 }
3167 
3168 //--------------------------------------------------------------------------
3169 
3170 // Function to construct (rad,rec,emt) triples from the event
3171 // IN int : Position of Emitted in event record for which
3172 // dipoles should be constructed
3173 // int : Colour topogy to be tested
3174 // 1= g -> qqbar, causing 2 -> 2 dipole splitting
3175 // 2= q(bar) -> q(bar) g && g -> gg,
3176 // causing a 2 -> 3 dipole splitting
3177 // Event : event record to be checked for ptential partners
3178 // OUT vector of all allowed radiator+recoiler+emitted triples
3179 
3180 vector<Clustering> History::findEWTriple ( int EmtTagIn, const Event& event,
3181  vector<int> PosFinalPartn ) {
3182  // Copy input parton tag
3183  int EmtTag = EmtTagIn;
3184  // Copy input colour topology tag
3185  // (1: g --> qqbar splitting present, 2:rest)
3186 
3187  // Initialise FinalSize
3188  int FinalSize = int(PosFinalPartn.size());
3189 
3190  vector<Clustering> clus;
3191 
3192  // Search final partons to find partons colour-connected to
3193  // event[EmtTag], choose radiator, then choose recoiler
3194  for ( int a = 0; a < FinalSize; ++a ) {
3195 
3196  int iRad = PosFinalPartn[a];
3197  if (iRad != EmtTag ) {
3198  int pTdef = 1;
3199  // Find recoiler by flavour.
3200  int flavRad = event[iRad].id();
3201  int flavEmt = event[EmtTag].id();
3202 
3203  // Loop through final partons and try to find matching flavours.
3204  for ( int i = 0; i < FinalSize; ++i ) {
3205  int iRec = PosFinalPartn[i];
3206  if ( i != a && flavEmt > 0
3207  && event[iRec].id() == -flavRad - 1 )
3208  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
3209  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ) );
3210  }
3211  }
3212  }
3213 
3214  // Done
3215  return clus;
3216 }
3217 
3218 //--------------------------------------------------------------------------
3219 
3220 // For the history-defining state (and if necessary interfering
3221 // states), find all possible clusterings.
3222 // NO INPUT
3223 // OUT vector of all (rad,rec,emt) systems
3224 
3225 vector<Clustering> History::getAllSQCDClusterings() {
3226  vector<Clustering> ret;
3227 
3228  // Get all clusterings for input state
3229  vector<Clustering> systems;
3230  systems = getSQCDClusterings(state);
3231  ret.insert(ret.end(), systems.begin(), systems.end());
3232  // Done
3233  return ret;
3234 }
3235 
3236 //--------------------------------------------------------------------------
3237 
3238 // For one given state, find all possible clusterings.
3239 // IN Event : state to be investigated
3240 // OUT vector of all (rad,rec,emt) systems in the state
3241 
3242 vector<Clustering> History::getSQCDClusterings( const Event& event) {
3243  vector<Clustering> ret;
3244 
3245  // Initialise vectors to keep track of position of partons in the
3246  // input event
3247  vector <int> PosFinalPartn;
3248  vector <int> PosInitPartn;
3249 
3250  vector <int> PosFinalGluon;
3251  vector <int> PosFinalQuark;
3252  vector <int> PosFinalAntiq;
3253  vector <int> PosInitGluon;
3254  vector <int> PosInitQuark;
3255  vector <int> PosInitAntiq;
3256 
3257  // Search event record for final state particles and store these in
3258  // quark, anti-quark and gluon vectors
3259  for (int i=0; i < event.size(); ++i)
3260  if ( event[i].isFinal() && event[i].colType() !=0 ) {
3261  // Store final partons
3262  PosFinalPartn.push_back(i);
3263  if ( event[i].id() == 21 || event[i].id() == 1000021)
3264  PosFinalGluon.push_back(i);
3265  else if ( (event[i].idAbs() < 10 && event[i].id() > 0)
3266  || (event[i].idAbs() < 1000010 && event[i].idAbs() > 1000000
3267  && event[i].id() > 0)
3268  || (event[i].idAbs() < 2000010 && event[i].idAbs() > 2000000
3269  && event[i].id() > 0))
3270  PosFinalQuark.push_back(i);
3271  else if ( (event[i].idAbs() < 10 && event[i].id() < 0)
3272  || (event[i].idAbs() < 1000010 && event[i].idAbs() > 1000000
3273  && event[i].id() < 0)
3274  || (event[i].idAbs() < 2000010 && event[i].idAbs() > 2000000
3275  && event[i].id() < 0))
3276  PosFinalAntiq.push_back(i);
3277  } else if ( event[i].status() == -21 && event[i].colType() != 0 ) {
3278  // Store initial partons
3279  PosInitPartn.push_back(i);
3280  if ( event[i].id() == 21 || event[i].id() == 1000021)
3281  PosInitGluon.push_back(i);
3282  else if ( (event[i].idAbs() < 10 && event[i].id() > 0)
3283  || (event[i].idAbs() < 1000010 && event[i].idAbs() > 1000000
3284  && event[i].id() > 0)
3285  || (event[i].idAbs() < 2000010 && event[i].idAbs() > 2000000
3286  && event[i].id() > 0))
3287  PosInitQuark.push_back(i);
3288  else if ( (event[i].idAbs() < 10 && event[i].id() < 0)
3289  || (event[i].idAbs() < 1000010 && event[i].idAbs() > 1000000
3290  && event[i].id() < 0)
3291  || (event[i].idAbs() < 2000010 && event[i].idAbs() > 2000000
3292  && event[i].id() < 0))
3293  PosInitAntiq.push_back(i);
3294  }
3295 
3296  int nFiGluon = int(PosFinalGluon.size());
3297  int nFiQuark = int(PosFinalQuark.size());
3298  int nFiAntiq = int(PosFinalAntiq.size());
3299  int nInGluon = int(PosInitGluon.size());
3300  int nInQuark = int(PosInitQuark.size());
3301  int nInAntiq = int(PosInitAntiq.size());
3302 
3303  vector<Clustering> systems;
3304 
3305  // Find rad + emt + rec systems:
3306  // (1) Start from gluon and find all (rad,rec,emt=gluon) triples
3307  for (int i = 0; i < nFiGluon; ++i) {
3308  int EmtGluon = PosFinalGluon[i];
3309  systems = findSQCDTriple( EmtGluon, 2, event, PosFinalPartn, PosInitPartn);
3310  ret.insert(ret.end(), systems.begin(), systems.end());
3311  systems.resize(0);
3312  }
3313 
3314  // For more than one quark-antiquark pair in final state, check for
3315  // g -> qqbar splittings
3316  bool check_g2qq = true;
3317  if ( ( ( nInQuark + nInAntiq == 0 )
3318  && (nInGluon == 0)
3319  && (nFiQuark == 1) && (nFiAntiq == 1) )
3320  || ( ( nFiQuark + nFiAntiq == 0)
3321  && (nInQuark == 1) && (nInAntiq == 1) ) )
3322  check_g2qq = false;
3323 
3324  if ( check_g2qq ) {
3325 
3326  // (2) Start from quark and find all (rad,rec,emt=quark) triples
3327  // ( when g -> q qbar occured )
3328  for( int i=0; i < nFiQuark; ++i) {
3329  int EmtQuark = PosFinalQuark[i];
3330  systems = findSQCDTriple( EmtQuark,1,event, PosFinalPartn, PosInitPartn);
3331  ret.insert(ret.end(), systems.begin(), systems.end());
3332  systems.resize(0);
3333  }
3334 
3335  // (3) Start from anti-quark and find all (rad,rec,emt=anti-quark)
3336  // triples ( when g -> q qbar occured )
3337  for( int i=0; i < nFiAntiq; ++i) {
3338  int EmtAntiq = PosFinalAntiq[i];
3339  systems = findSQCDTriple( EmtAntiq,1,event, PosFinalPartn, PosInitPartn);
3340  ret.insert(ret.end(), systems.begin(), systems.end());
3341  systems.resize(0);
3342  }
3343  }
3344 
3345  return ret;
3346 }
3347 
3348 //--------------------------------------------------------------------------
3349 
3350 // Function to construct (rad,rec,emt) triples from the event
3351 // IN int : Position of Emitted in event record for which
3352 // dipoles should be constructed
3353 // int : Colour topogy to be tested
3354 // 1= g -> qqbar, causing 2 -> 2 dipole splitting
3355 // 2= q(bar) -> q(bar) g && g -> gg,
3356 // causing a 2 -> 3 dipole splitting
3357 // Event : event record to be checked for ptential partners
3358 // OUT vector of all allowed radiator+recoiler+emitted triples
3359 
3360 vector<Clustering> History::findSQCDTriple (int EmtTagIn, int colTopIn,
3361  const Event& event,
3362  vector<int> PosFinalPartn,
3363  vector <int> PosInitPartn ) {
3364 
3365  // Copy input parton tag
3366  int EmtTag = EmtTagIn;
3367  // Copy input colour topology tag
3368  // (1: g --> qqbar splitting present, 2:rest)
3369  int colTop = colTopIn;
3370 
3371  // PDG numbering offset for squarks
3372  int offsetL = 1000000;
3373  int offsetR = 2000000;
3374 
3375  // Initialise FinalSize
3376  int FinalSize = int(PosFinalPartn.size());
3377  int InitSize = int(PosInitPartn.size());
3378  int Size = InitSize + FinalSize;
3379 
3380  vector<Clustering> clus;
3381 
3382  // Search final partons to find partons colour-connected to
3383  // event[EmtTag], choose radiator, then choose recoiler
3384  for ( int a = 0; a < Size; ++a ) {
3385  int i = (a < FinalSize)? a : (a - FinalSize) ;
3386  int iRad = (a < FinalSize)? PosFinalPartn[i] : PosInitPartn[i];
3387 
3388  if ( event[iRad].col() == event[EmtTag].col()
3389  && event[iRad].acol() == event[EmtTag].acol() )
3390  continue;
3391 
3392  // Save radiator flavour.
3393  int radID = event[iRad].id();
3394  // Remember if radiator is BSM.
3395  bool isSQCDrad = (abs(radID) > offsetL);
3396  // Remember if emitted is BSM.
3397  bool isSQCDemt = (event[EmtTag].idAbs() > offsetL );
3398 
3399  if (iRad != EmtTag ) {
3400  int pTdef = event[iRad].isFinal() ? 1 : -1;
3401  int sign = (a < FinalSize)? 1 : -1 ;
3402 
3403  // Disalllow clusterings resulting in an initial state sQCD parton!
3404  int radBefID = getRadBeforeFlav(iRad,EmtTag,event);
3405  if ( pTdef == -1 && abs(radBefID) > offsetL ) continue;
3406 
3407  // First colour topology: g --> qqbar. Here, emt & rad should
3408  // have same flavour (causes problems for gamma->qqbar).
3409  if (colTop == 1) {
3410 
3411  int emtSign = (event[EmtTag].id() < 0) ? -1 : 1;
3412 
3413  // Final gluino splitting.
3414  bool finalSplitting = false;
3415  if ( abs(radID) < 10
3416  && radID == -sign*emtSign*(offsetL + event[EmtTag].idAbs()) )
3417  finalSplitting = true;
3418  if ( abs(radID) < 10
3419  && radID == -sign*emtSign*(offsetR + event[EmtTag].idAbs()) )
3420  finalSplitting = true;
3421  if ( abs(radID) > offsetL && abs(radID) < offsetL+10
3422  && radID == -sign*emtSign*( event[EmtTag].idAbs() - offsetL) )
3423  finalSplitting = true;
3424  if ( abs(radID) > offsetR && abs(radID) < offsetR+10
3425  && radID == -sign*emtSign*( event[EmtTag].idAbs() - offsetR) )
3426  finalSplitting = true;
3427 
3428  // Initial gluon splitting.
3429  bool initialSplitting = false;
3430  if ( radID == 21 && ( ( event[EmtTag].idAbs() > offsetL
3431  && event[EmtTag].idAbs() < offsetL+10)
3432  || ( event[EmtTag].idAbs() > offsetR
3433  && event[EmtTag].idAbs() < offsetR+10) )
3434  && ( event[iRad].col() == event[EmtTag].col()
3435  || event[iRad].acol() == event[EmtTag].acol() ) )
3436  initialSplitting = true;
3437 
3438  if ( finalSplitting ) {
3439 
3440  int col = -1;
3441  int acl = -1;
3442  if ( radID < 0 && event[iRad].colType() == -1) {
3443  acl = event[EmtTag].acol();
3444  col = event[iRad].acol();
3445  } else if ( event[iRad].colType() == 1 ) {
3446  col = event[EmtTag].col();
3447  acl = event[iRad].col();
3448  }
3449 
3450  // Recoiler
3451  int iRec = 0;
3452  // Colour partner
3453  int iPartner = 0;
3454 
3455  if (col > 0) {
3456  // Find recoiler by colour
3457  iRec = FindCol(col,iRad,EmtTag,event,1,true);
3458  // In initial state splitting has final state colour partner,
3459  // Save both partner and recoiler
3460  if ( (sign < 0) && (event[iRec].isFinal()) ) {
3461  // Save colour recoiler
3462  iPartner = iRec;
3463  // Reset kinematic recoiler to initial state parton
3464  for(int l = 0; l < int(PosInitPartn.size()); ++l)
3465  if (PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
3466  // For final state splittings, colour partner and recoiler are
3467  // identical
3468  } else {
3469  iPartner = iRec;
3470  }
3471 
3472  // Not interested in pure QCD triples here.
3473  if ( !isSQCDrad && !isSQCDemt
3474  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
3475  iRec = 0;
3476 
3477  if ( iRec != 0 && iPartner != 0
3478  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
3479  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
3480  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
3481  continue;
3482  }
3483 
3484  // Reset partner
3485  iPartner = 0;
3486  // Find recoiler by colour
3487  iRec = FindCol(col,iRad,EmtTag,event,2,true);
3488  // In initial state splitting has final state colour partner,
3489  // Save both partner and recoiler
3490  if ( (sign < 0) && (event[iRec].isFinal()) ) {
3491  // Save colour recoiler
3492  iPartner = iRec;
3493  // Reset kinematic recoiler to initial state parton
3494  for(int l = 0; l < int(PosInitPartn.size()); ++l)
3495  if (PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
3496  // For final state splittings, colour partner and recoiler are
3497  // identical
3498  } else {
3499  iPartner = iRec;
3500  }
3501 
3502  // Not interested in pure QCD triples here.
3503  if ( !isSQCDrad && !isSQCDemt
3504  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
3505  iRec = 0;
3506 
3507  if ( iRec != 0 && iPartner != 0
3508  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
3509  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
3510  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
3511  continue;
3512  }
3513  }
3514 
3515  if (acl > 0) {
3516 
3517  // Reset partner
3518  iPartner = 0;
3519  // Find recoiler by colour
3520  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
3521  // In initial state splitting has final state colour partner,
3522  // Save both partner and recoiler
3523  if ( (sign < 0) && (event[iRec].isFinal()) ) {
3524  // Save colour recoiler
3525  iPartner = iRec;
3526  // Reset kinematic recoiler to initial state parton
3527  for(int l = 0; l < int(PosInitPartn.size()); ++l)
3528  if (PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
3529  // For final state splittings, colour partner and recoiler are
3530  // identical
3531  } else {
3532  iPartner = iRec;
3533  }
3534 
3535  // Not interested in pure QCD triples here.
3536  if ( !isSQCDrad && !isSQCDemt
3537  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
3538  iRec = 0;
3539 
3540  if ( iRec != 0 && iPartner != 0
3541  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
3542  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
3543  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
3544  continue;
3545  }
3546 
3547  // Reset partner
3548  iPartner = 0;
3549  // Find recoiler by colour
3550  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
3551  // In initial state splitting has final state colour partner,
3552  // Save both partner and recoiler
3553  if ( (sign < 0) && (event[iRec].isFinal()) ) {
3554  // Save colour recoiler
3555  iPartner = iRec;
3556  // Reset kinematic recoiler to initial state parton
3557  for(int l = 0; l < int(PosInitPartn.size()); ++l)
3558  if (PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
3559  // For final state splittings, colour partner and recoiler are
3560  // identical
3561  } else {
3562  iPartner = iRec;
3563  }
3564 
3565  // Not interested in pure QCD triples here.
3566  if ( !isSQCDrad && !isSQCDemt
3567  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
3568  iRec = 0;
3569 
3570  if ( iRec != 0 && iPartner != 0
3571  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ) {
3572  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
3573  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
3574  continue;
3575  }
3576  }
3577  // Initial gluon splitting
3578  } else if ( initialSplitting ) {
3579 
3580  // SM splittings already taken care of in findQCDTriple.
3581  if ( !isSQCDrad && !isSQCDemt ) continue;
3582 
3583  // For an initial state radiator, always set recoiler
3584  // to the other initial state parton (recoil is taken
3585  // by full remaining system, so this is just a
3586  // labelling for such a process)
3587  int RecInit = 0;
3588  for(int l = 0; l < int(PosInitPartn.size()); ++l)
3589  if (PosInitPartn[l] != iRad) RecInit = PosInitPartn[l];
3590 
3591  // Find the colour connected partner
3592  // Find colour index of radiator before splitting
3593  int col = getRadBeforeCol(iRad, EmtTag, event);
3594  int acl = getRadBeforeAcol(iRad, EmtTag, event);
3595 
3596  // Find the correct partner: If a colour line has split,
3597  // the partner is connected to the radiator before the splitting
3598  // by a colour line (same reasoning for anticolour). The colour
3599  // that split is the colour appearing twice in the
3600  // radiator + emitted pair.
3601  // Thus, if we remove a colour index with the clustering,
3602  // we should look for a colour partner, else look for
3603  // an anticolour partner
3604  int colRemove = (event[iRad].col() == event[EmtTag].col())
3605  ? event[iRad].col() : 0;
3606 
3607  int iPartner = 0;
3608  if (colRemove > 0 && col > 0)
3609  iPartner = FindCol(col,iRad,EmtTag,event,1,true)
3610  + FindCol(col,iRad,EmtTag,event,2,true);
3611  else if (colRemove > 0 && acl > 0)
3612  iPartner = FindCol(acl,iRad,EmtTag,event,1,true)
3613  + FindCol(acl,iRad,EmtTag,event,2,true);
3614 
3615  if ( allowedClustering( iRad, EmtTag, RecInit, iPartner, event ) ) {
3616  clus.push_back( Clustering(EmtTag, iRad, RecInit, iPartner,
3617  pTLund(event[iRad],event[EmtTag],event[RecInit], pTdef) ));
3618  continue;
3619  }
3620  }
3621 
3622  // Second colour topology: Gluino emission
3623 
3624  } else {
3625 
3626  if ( (event[iRad].col() == event[EmtTag].acol())
3627  || (event[iRad].acol() == event[EmtTag].col())
3628  || (event[iRad].col() == event[EmtTag].col())
3629  || (event[iRad].acol() == event[EmtTag].acol()) ) {
3630  // For the rest, choose recoiler to have a common colour
3631  // tag with radiator, while not being the "Emitted"
3632 
3633  int col = -1;
3634  int acl = -1;
3635 
3636  if (event[iRad].isFinal() ) {
3637 
3638  if ( radID < 0 && event[iRad].colType() == -1) {
3639  acl = event[EmtTag].acol();
3640  col = event[iRad].col();
3641  } else if ( radID > 0 && event[iRad].colType() == 1 ) {
3642  col = event[EmtTag].col();
3643  acl = event[iRad].acol();
3644  } else {
3645  col = event[iRad].col();
3646  acl = event[iRad].acol();
3647  }
3648 
3649  int iRec = 0;
3650  if (col > 0) {
3651  iRec = FindCol(col,iRad,EmtTag,event,1,true);
3652  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
3653  // Not interested in pure QCD triples here.
3654  if ( !isSQCDrad && !isSQCDemt
3655  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
3656  iRec = 0;
3657  if (iRec != 0
3658  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
3659  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
3660  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
3661  continue;
3662  }
3663 
3664  iRec = FindCol(col,iRad,EmtTag,event,2,true);
3665  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
3666  // Not interested in pure QCD triples here.
3667  if ( !isSQCDrad && !isSQCDemt
3668  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
3669  iRec = 0;
3670  if (iRec != 0
3671  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
3672  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
3673  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
3674  continue;
3675  }
3676  }
3677 
3678  if (acl > 0) {
3679  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
3680  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
3681  // Not interested in pure QCD triples here.
3682  if ( !isSQCDrad && !isSQCDemt
3683  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
3684  iRec = 0;
3685  if (iRec != 0
3686  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
3687  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
3688  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
3689  continue;
3690  }
3691 
3692  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
3693  if ( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
3694  // Not interested in pure QCD triples here.
3695  if ( !isSQCDrad && !isSQCDemt
3696  && (event[iRec].idAbs() < 10 || event[iRec].id() == 21) )
3697  iRec = 0;
3698  if (iRec != 0
3699  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ) {
3700  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
3701  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
3702  continue;
3703  }
3704  }
3705 
3706  } else {
3707 
3708  // SM splittings already taken care of in findQCDTriple. Since
3709  // initial state splittings will not know if the true
3710  // colour-connected recoiler is a SM particle, any ISR splitting
3711  // of a SM particle will be included by findQCDTriple. To not
3712  // include the same splitting twice, continue for SM ISR radiator
3713  if ( !isSQCDrad || !isSQCDemt ) continue;
3714 
3715  // For an initial state radiator, always set recoiler
3716  // to the other initial state parton (recoil is taken
3717  // by full remaining system, so this is just a
3718  // labelling for such a process)
3719  int RecInit = 0;
3720  int iPartner = 0;
3721  for(int l = 0; l < int(PosInitPartn.size()); ++l)
3722  if (PosInitPartn[l] != iRad) RecInit = PosInitPartn[l];
3723 
3724  // Find the colour connected partner
3725  // Find colour index of radiator before splitting
3726  col = getRadBeforeCol(iRad, EmtTag, event);
3727  acl = getRadBeforeAcol(iRad, EmtTag, event);
3728 
3729  // Find the correct partner: If a colour line has split,
3730  // the partner is connected to the radiator before the splitting
3731  // by a colour line (same reasoning for anticolour). The colour
3732  // that split is the colour appearing twice in the
3733  // radiator + emitted pair.
3734  // Thus, if we remove a colour index with the clustering,
3735  // we should look for a colour partner, else look for
3736  // an anticolour partner
3737  int colRemove = (event[iRad].col() == event[EmtTag].col())
3738  ? event[iRad].col() : 0;
3739  iPartner = (colRemove > 0)
3740  ? FindCol(col,iRad,EmtTag,event,1,true)
3741  + FindCol(col,iRad,EmtTag,event,2,true)
3742  : FindCol(acl,iRad,EmtTag,event,1,true)
3743  + FindCol(acl,iRad,EmtTag,event,2,true);
3744 
3745  if ( allowedClustering( iRad, EmtTag, RecInit, iPartner, event)) {
3746  clus.push_back( Clustering(EmtTag, iRad, RecInit, iPartner,
3747  pTLund(event[iRad],event[EmtTag],event[RecInit], pTdef)));
3748 
3749  continue;
3750  }
3751  }
3752  }
3753  }
3754  }
3755  }
3756 
3757  // Done
3758  return clus;
3759 
3760 }
3761 
3762 //--------------------------------------------------------------------------
3763 
3764 // Calculate and return the probability of a clustering.
3765 // IN Clustering : rad,rec,emt - System for which the splitting
3766 // probability should be calcuated
3767 // OUT splitting probability
3768 
3769 double History::getProb(const Clustering & SystemIn) {
3770 
3771  // Get local copies of input system
3772  int Rad = SystemIn.emittor;
3773  int Rec = SystemIn.recoiler;
3774  int Emt = SystemIn.emitted;
3775 
3776  // Initialise shower probability
3777  double showerProb = 0.0;
3778 
3779  // If the splitting resulted in disallowed evolution variable,
3780  // disallow the splitting
3781  if (SystemIn.pT() <= 0.) return 0.;
3782 
3783  // Initialise all combinatorical factors
3784  double CF = 4./3.;
3785  double NC = 3.;
3786  // Flavour is known when reclustring, thus n_f=1
3787  double TR = 1./2.;
3788 
3789  // Split up in FSR and ISR
3790  bool isFSR = (state[Rad].isFinal() && state[Rec].isFinal());
3791  bool isFSRinREC = (state[Rad].isFinal() && !state[Rec].isFinal());
3792  bool isISR = !state[Rad].isFinal();
3793 
3794  // Check if this is the clustering 2->3 to 2->2.
3795  // If so, use weight for joined evolution
3796  int nFinal = 0;
3797  for(int i=0; i < state.size(); ++i)
3798  if (state[i].isFinal()) nFinal++;
3799  bool isLast = (nFinal == (mergingHooksPtr->hardProcess.nQuarksOut()
3800  +mergingHooksPtr->hardProcess.nLeptonOut()+1));
3801 
3802  if (isISR) {
3803  // Find incoming particles
3804 
3805  int inP = 0;
3806  int inM = 0;
3807  for(int i=0;i< int(state.size()); ++i) {
3808  if (state[i].mother1() == 1) inP = i;
3809  if (state[i].mother1() == 2) inM = i;
3810  }
3811  // Construct dipole mass, eCM and sHat = x1*x2*s
3812  Vec4 sum = state[Rad].p() + state[Rec].p() - state[Emt].p();
3813  double m2Dip = sum.m2Calc();
3814  double sHat = (state[inM].p() + state[inP].p()).m2Calc();
3815  // Energy fraction z=E_q1/E_qi in branch q(i)q(2) -> q(1)g(3)q(2)
3816  double z1 = m2Dip / sHat;
3817  // Virtuality of the splittings
3818  Vec4 Q1( state[Rad].p() - state[Emt].p() );
3819  Vec4 Q2( state[Rec].p() - state[Emt].p() );
3820  // Q^2 for emission off radiator line
3821  double Q1sq = -Q1.m2Calc();
3822  // pT^2 for emission off radiator line
3823  double pT1sq = pow(SystemIn.pT(),2);
3824  // Remember if massive particles involved: Mass corrections for
3825  // to g->QQ and Q->Qg splittings
3826  bool g2QQmassive = mergingHooksPtr->includeMassive()
3827  && state[Rad].id() == 21
3828  && ( (state[Emt].idAbs() >= 4 && state[Emt].idAbs() < 7)
3829  || (state[Emt].idAbs() > 1000000 && state[Emt].idAbs() < 1000010 )
3830  || (state[Emt].idAbs() > 2000000 && state[Emt].idAbs() < 2000010 ));
3831  bool Q2Qgmassive = mergingHooksPtr->includeMassive()
3832  && state[Emt].id() == 21
3833  && ( (state[Rad].idAbs() >= 4 && state[Rad].idAbs() < 7)
3834  || (state[Rad].idAbs() > 1000000 && state[Rad].idAbs() < 1000010 )
3835  || (state[Rad].idAbs() > 2000000 && state[Rad].idAbs() < 2000010 ));
3836  bool isMassive = mergingHooksPtr->includeMassive()
3837  && ( g2QQmassive || Q2Qgmassive
3838  || state[Emt].id() == 1000021);
3839  double m2Emt0 = pow(particleDataPtr->m0(state[Emt].id()),2);
3840  double m2Rad0 = pow(particleDataPtr->m0(state[Rad].id()),2);
3841 
3842  // Correction of virtuality for massive splittings
3843  if ( g2QQmassive) Q1sq += m2Emt0;
3844  else if (Q2Qgmassive) Q1sq += m2Rad0;
3845 
3846  // pT0 dependence!!!
3847  double pT0sq = pow(mergingHooksPtr->pT0ISR(),2);
3848  double Q2sq = -Q2.m2Calc();
3849 
3850  // Correction of virtuality of other splitting
3851  bool g2QQmassiveRec = mergingHooksPtr->includeMassive()
3852  && state[Rec].id() == 21
3853  && ( state[Emt].idAbs() >= 4 && state[Emt].idAbs() < 7);
3854  bool Q2QgmassiveRec = mergingHooksPtr->includeMassive()
3855  && state[Emt].id() == 21
3856  && ( state[Rec].idAbs() >= 4 && state[Rec].idAbs() < 7);
3857  double m2Rec0 = pow(particleDataPtr->m0(state[Rad].id()),2);
3858  if ( g2QQmassiveRec) Q2sq += m2Emt0;
3859  else if (Q2QgmassiveRec) Q2sq += m2Rec0;
3860 
3861  bool hasJoinedEvol = (state[Emt].id() == 21
3862  || state[Rad].id() == state[Rec].id());
3863 
3864  // Initialise normalization factor multiplying the splitting
3865  // function numerator
3866  double fac = 1.;
3867  if ( mergingHooksPtr->pickByFull() || mergingHooksPtr->pickBySumPT()) {
3868  double facJoined = ( Q2sq + pT0sq/(1.-z1) )
3869  * 1./(Q1sq*Q2sq + pT0sq*sHat + pow(pT0sq/(1.-z1),2));
3870  double facSingle = mergingHooksPtr->nonJoinedNorm()*1./( pT1sq + pT0sq);
3871 
3872  fac = (hasJoinedEvol && isLast) ? facJoined : facSingle;
3873 
3874  } else if (mergingHooksPtr->pickByPoPT2()) {
3875  fac = 1./(pT1sq + pT0sq);
3876  } else {
3877  string message="Error in History::getProb: Scheme for calculating";
3878  message+=" shower splitting probability is undefined.";
3879  infoPtr->errorMsg(message);
3880  }
3881 
3882  // Calculate shower splitting probability:
3883  // Splitting functions*normalization*ME reweighting factors
3884 
3885  // Calculate branching probability for q -> q g
3886  if ( state[Emt].id() == 21 && state[Rad].id() != 21) {
3887  // Find splitting kernel
3888  double num = CF*(1. + pow(z1,2)) / (1.-z1);
3889  if (isMassive) num -= CF * z1 * (1.-z1) * (m2Rad0/pT1sq);
3890 
3891  // Find ME reweighting factor
3892  double meReweighting = 1.;
3893  // Find the number of final state coloured particles, apart
3894  // from those coming from the hard process
3895  int nCol = 0;
3896  for(int i=0; i < state.size(); ++i)
3897  if (state[i].isFinal() && state[i].colType() != 0
3898  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,state) )
3899  nCol++;
3900  // For first splitting of single vector boson production,
3901  // apply ME corrections
3902  if (nCol == 1
3903  && int(mergingHooksPtr->hardProcess.hardIntermediate.size()) == 1) {
3904  double sH = m2Dip / z1;
3905  double tH = -Q1sq;
3906  double uH = Q1sq - m2Dip * (1. - z1) / z1;
3907  double misMatch = (uH*tH - (uH + tH)*pT0sq/(1.-z1)
3908  + pow(pT0sq/(1.-z1),2) ) / (uH*tH);
3909  meReweighting *= (tH*tH + uH*uH + 2. * m2Dip * sH)
3910  / (sH*sH + m2Dip*m2Dip);
3911  meReweighting *= misMatch;
3912  }
3913  // Multiply factors
3914  showerProb = num*fac*meReweighting;
3915 
3916  // Calculate branching probability for g -> g g
3917  } else if ( state[Emt].id() == 21 && state[Rad].id() == 21) {
3918  // Calculate splitting kernel
3919  double num = 2.*NC*pow2(1. - z1*(1.-z1)) / (z1*(1.-z1));
3920 
3921  // Include ME reweighting for higgs!!
3922  // Find ME reweighting factor
3923  double meReweighting = 1.;
3924  // Find the number of final state coloured particles, apart
3925  // from those coming from the hard process
3926  int nCol = 0;
3927  for(int i=0; i < state.size(); ++i)
3928  if (state[i].isFinal() && state[i].colType() != 0
3929  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,state) )
3930  nCol++;
3931  // For first splitting of single vector boson production,
3932  // apply ME corrections
3933  if ( nCol == 1
3934  && mergingHooksPtr->getProcessString().compare("pp>h") == 0
3935  && int(mergingHooksPtr->hardProcess.hardIntermediate.size()) == 1 ) {
3936  double sH = m2Dip / z1;
3937  double tH = -Q1sq;
3938  double uH = Q1sq - m2Dip * (1. - z1) / z1;
3939  meReweighting *= 0.5
3940  * (pow4(sH) + pow4(tH) + pow4(uH) + pow4(m2Dip))
3941  / pow2(sH*sH - m2Dip * (sH - m2Dip));
3942  }
3943 
3944  // Multiply factors
3945  showerProb = num*fac*meReweighting;
3946 
3947  // Calculate branching probability for q -> g q
3948  } else if ( state[Emt].id() != 21 && state[Rad].id() != 21 ) {
3949  // Calculate splitting kernel
3950  double num = CF*(1. + pow2(1.-z1)) / z1;
3951 
3952  // Include ME reweighting for higgs!!
3953  // Find ME reweighting factor
3954  double meReweighting = 1.;
3955  // Find the number of final state coloured particles, apart
3956  // from those coming from the hard process
3957  int nCol = 0;
3958  for ( int i=0; i < state.size(); ++i )
3959  if ( state[i].isFinal() && state[i].colType() != 0
3960  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,state) )
3961  nCol++;
3962  // For first splitting of single vector boson production,
3963  // apply ME corrections
3964  if (nCol == 1
3965  && mergingHooksPtr->getProcessString().compare("pp>h") == 0
3966  && int(mergingHooksPtr->hardProcess.hardIntermediate.size()) == 1) {
3967  double sH = m2Dip / z1;
3968  double uH = Q1sq - m2Dip * (1. - z1) / z1;
3969  meReweighting *= (sH*sH + uH*uH)
3970  / (sH*sH + pow2(sH -m2Dip));
3971  }
3972 
3973  // Multiply factors
3974  showerProb = num*fac*meReweighting;
3975 
3976  // Calculate branching probability for g -> q qbar
3977  } else if ( state[Emt].id() != 21 && state[Rad].id() == 21 ) {
3978  // Calculate splitting kernel
3979  double num = TR * ( pow(z1,2) + pow(1.-z1,2) );
3980  if (isMassive) num += TR * 2.*z1*(1.-z1)*(m2Emt0/pT1sq);
3981  // Calculate ME reweighting factor
3982  double meReweighting = 1.;
3983  // Find the number of final state coloured particles, apart
3984  // from those coming from the hard process
3985  int nCol = 0;
3986  for ( int i=0; i < state.size(); ++i )
3987  if ( state[i].isFinal() && state[i].colType() != 0
3988  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,state) )
3989  nCol++;
3990  // For first splitting of single vector boson production,
3991  // apply ME corrections
3992  if (nCol == 1
3993  && int(mergingHooksPtr->hardProcess.hardIntermediate.size()) == 1) {
3994  double sH = m2Dip / z1;
3995  double tH = -Q1sq;
3996  double uH = Q1sq - m2Dip * (1. - z1) / z1;
3997  swap( tH, uH);
3998  double misMatch = ( uH - pT0sq/(1.-z1) ) / uH;
3999  double me = (sH*sH + uH*uH + 2. * m2Dip * tH)
4000  / (pow2(sH - m2Dip) + m2Dip*m2Dip);
4001  // Weight with me/overestimate
4002  meReweighting *= me;
4003  meReweighting *= misMatch;
4004  }
4005  // Multiply factors
4006  showerProb = num*fac*meReweighting;
4007 
4008  // Print error if no kernel calculated
4009  } else {
4010  string message = "Error in History::getProb: Splitting kernel"
4011  " undefined in ISR in clustering.";
4012  infoPtr->errorMsg(message);
4013  }
4014 
4015  // If corrected pT below zero in ISR, put probability to zero
4016  double m2Sister0 = pow(state[Emt].m0(),2);
4017  double pT2corr = (Q1sq - z1*(m2Dip + Q1sq)*(Q1sq + m2Sister0)/m2Dip);
4018  if (pT2corr < 0.) showerProb *= 1e-9;
4019 
4020  // If creating heavy quark by Q -> gQ then next need g -> Q + Qbar.
4021  // So minimum total mass2 is 4 * m2Sister, but use more to be safe.
4022  if ( state[Emt].id() == state[Rad].id()
4023  && ( state[Rad].idAbs() == 4 || state[Rad].idAbs() == 5 )) {
4024  double m2QQsister = 2.*4.*m2Sister0;
4025  double pT2QQcorr = Q1sq - z1*(m2Dip + Q1sq)*(Q1sq + m2QQsister)
4026  / m2Dip;
4027  if (pT2QQcorr < 0.0) showerProb *= 1e-9;
4028  }
4029 
4030  if (mergingHooksPtr->includeRedundant()) {
4031  // Initialise the spacelike shower alpha_S
4032  AlphaStrong* asISR = mergingHooksPtr->AlphaS_ISR();
4033  double as = (*asISR).alphaS(pT1sq + pT0sq) / (2.*M_PI);
4034  // Multiply with alpha_S
4035  showerProb *= as;
4036  }
4037 
4038  // Done for ISR case, begin FSR case
4039 
4040  } else if (isFSR || isFSRinREC) {
4041 
4042  // Construct dipole mass
4043  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
4044  double m2Dip = sum.m2Calc();
4045  // Construct 2->3 variables for FSR
4046  double x1 = 2. * (sum * state[Rad].p()) / m2Dip;
4047  double x2 = 2. * (sum * state[Rec].p()) / m2Dip;
4048  double prop1 = max(1e-12, 1. - x1);
4049  double prop2 = max(1e-12, 1. - x2);
4050  double x3 = max(1e-12, 2. - x1 - x2);
4051  // Energy fraction z=E_q1/E_qi in branch q(i)q(2) -> q(1)g(3)q(2)
4052  double z1 = x1/(x1 + x3);
4053 
4054  // Virtuality of the splittings
4055  Vec4 Q1( state[Rad].p() + state[Emt].p() );
4056  Vec4 Q2( state[Rec].p() + state[Emt].p() );
4057 
4058  // Q^2 for emission off radiator line
4059  double Q1sq = Q1.m2Calc();
4060  // pT^2 for emission off radiator line
4061  double pT1sq = pow(SystemIn.pT(),2);
4062  // Q^2 for emission off recoiler line
4063  double Q2sq = Q2.m2Calc();
4064 
4065  // Remember if radiator or recoiler is massive.
4066  bool isMassiveRad = ( state[Rad].idAbs() >= 4
4067  && state[Rad].id() != 21 );
4068  bool isMassiveRec = ( state[Rec].idAbs() >= 4
4069  && state[Rec].id() != 21 );
4070  // Correction of virtuality for massive splittings.
4071  double m2Rad0 = pow(particleDataPtr->m0(state[Rad].id()),2);
4072  double m2Rec0 = pow(particleDataPtr->m0(state[Rad].id()),2);
4073  if ( mergingHooksPtr->includeMassive() && isMassiveRad ) Q1sq -= m2Rad0;
4074  if ( mergingHooksPtr->includeMassive() && isMassiveRec ) Q2sq -= m2Rec0;
4075 
4076  // Initialise normalization factor multiplying the splitting
4077  // function numerator
4078  double fac = 1.;
4079  if ( mergingHooksPtr->pickByFull() || mergingHooksPtr->pickBySumPT()) {
4080  double facJoined = (1.-z1)/Q1sq * m2Dip/( Q1sq + Q2sq );
4081  double facSingle = mergingHooksPtr->fsrInRecNorm() * 1./ pT1sq;
4082  fac = (!isFSRinREC && isLast) ? facJoined : facSingle;
4083  } else if (mergingHooksPtr->pickByPoPT2()) {
4084  fac = 1. / pT1sq;
4085  } else {
4086  string message="Error in History::getProb: Scheme for calculating";
4087  message+=" shower splitting probability is undefined.";
4088  infoPtr->errorMsg(message);
4089  }
4090  // Calculate shower splitting probability:
4091  // Splitting functions*normalization*ME reweighting factors
4092 
4093  // Calculate branching probability for g -> g_1 g_2
4094  if ( state[Emt].id() == 21 && state[Rad].id() == 21) {
4095  // Calculate splitting kernel
4096  double num = 0.5* NC * (1. + pow3(z1)) / (1.-z1);
4097  // Multiply factors
4098  showerProb = num*fac;
4099 
4100  // Calculate branching probability for q -> q g with quark recoiler
4101  } else if ( state[Emt].id() == 21
4102  && state[Rad].id() != 21 && state[Rec].id() != 21) {
4103  // For a qqbar dipole in FSR, ME corrections exist and the
4104  // splitting function "z-weight" is set to 1.0 (only for 2->2 ??)
4105  double num = CF * 2./(1.-z1);
4106  // Find the number of final state coloured particles, apart
4107  // from those coming from the hard process
4108  int nCol = 0;
4109  for(int i=0; i < state.size(); ++i)
4110  if (state[i].isFinal() && state[i].colType() != 0
4111  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,state) )
4112  nCol++;
4113  // Calculate splitting kernel
4114  if ( nCol > 3
4115  || int(mergingHooksPtr->hardProcess.hardIntermediate.size()) > 1)
4116  num = CF * (1. + pow2(z1)) /(1.-z1);
4117  // Calculate ME reweighting factor
4118  double meReweighting = 1.;
4119  // Correct if this is the process created by the first
4120  // FSR splitting of a 2->2 process
4121  if ( nCol == 3
4122  && int(mergingHooksPtr->hardProcess.hardIntermediate.size()) == 1 ) {
4123  // Calculate the ME reweighting factor
4124  double ShowerRate1 = 2./( x3 * prop2 );
4125  double meDividingFactor1 = prop1 / x3;
4126  double me = (pow(x1,2) + pow(x2,2))/(prop1*prop2);
4127  meReweighting = meDividingFactor1 * me / ShowerRate1;
4128  }
4129  // Multiply factors
4130  showerProb = num*fac*meReweighting;
4131 
4132  // Calculate branching probability for q1 -> q2 w+- with quark recoiler
4133  } else if ( state[Emt].idAbs() == 24
4134  && state[Rad].id() != 21 && state[Rec].id() != 21 ) {
4135  double m2W = state[Emt].p().m2Calc();
4136  double num = ( 3.*pow2(m2W / m2Dip)
4137  + 2.* (m2W/m2Dip)*(x1 + x2)
4138  + pow2(x1) + pow2(x2) ) / ( prop1*prop2 )
4139  - (m2W/m2Dip) / pow2(prop1)
4140  - (m2W/m2Dip) / pow2(prop2);
4141  // Multiply factors
4142  showerProb = num*fac;
4143 
4144  // Calculate branching probability for q -> q g with gluon recoiler
4145  } else if ( state[Emt].id() == 21 && state[Rad].id() != 21
4146  && state[Rec].id() == 21 ) {
4147  // For qg /qbarg dipoles, the splitting function is
4148  // calculated and not weighted by a ME correction factor
4149  // Shower splitting function
4150  double num = CF * (1. + pow2(z1)) / (1.-z1);
4151  showerProb = num*fac;
4152 
4153  // Calculate branching probability for g -> q qbar
4154  } else if ( state[Emt].id() != 21 ) {
4155  // Get flavour of quark / antiquark
4156  int flavour = state[Emt].id();
4157  // Get correct masses for the quarks
4158  // (needed to calculate splitting function?)
4159  double mFlavour = particleDataPtr->m0(flavour);
4160  // Get mass of quark/antiquark pair
4161  double mDipole = m(state[Rad].p(), state[Emt].p());
4162  // Factor determining if gluon decay was allowed
4163  double beta = sqrtpos( 1. - 4.*pow2(mFlavour)/pow2(mDipole) );
4164  // Shower splitting function
4165  double num = 0.5*TR * ( z1*z1 + (1.-z1)*(1.-z1) );
4166  if (beta <= 0.) beta = 0.;
4167 
4168  showerProb = num*fac*beta;
4169 
4170  // Print error if no kernel calculated
4171  } else {
4172  string message="Error in History::getProb: Splitting kernel undefined";
4173  message+=" in FSR clustering.";
4174  infoPtr->errorMsg(message);
4175  }
4176 
4177  if (mergingHooksPtr->includeRedundant()) {
4178  // Initialise the spacelike shower alpha_S
4179  AlphaStrong* asFSR = mergingHooksPtr->AlphaS_FSR();
4180  double as = (*asFSR).alphaS(pT1sq) / (2.*M_PI);
4181  // Multiply with alpha_S
4182  showerProb *= as;
4183  }
4184 
4185  // Done for FSR
4186  } else {
4187  string message="Error in History::getProb: Radiation could not be";
4188  message+=" interpreted as FSR or ISR.";
4189  infoPtr->errorMsg(message);
4190  }
4191 
4192  if (showerProb <= 0.) showerProb = 0.;
4193 
4194 // // Different coupling constants for qcd and ew splittings
4195 // if ( state[Emt].colType() != 0 ) {
4196 // AlphaStrong* asFSR = mergingHooksPtr->AlphaS_FSR();
4197 // double as = (*asFSR).alphaS(91.188*91.188) / (2.*M_PI);
4198 // showerProb *= as;
4199 // } else {
4200 // AlphaEM* aEMFSR = mergingHooksPtr->AlphaEM_FSR();
4201 // double aEM = (*aEMFSR).alphaEM(91.188*91.188) / (2.*M_PI);
4202 // showerProb *= aEM;
4203 // }
4204 
4205  // Done
4206  return showerProb;
4207 }
4208 
4209 
4210 //--------------------------------------------------------------------------
4211 
4212 // Set up the beams (fill the beam particles with the correct
4213 // current incoming particles) to allow calculation of splitting
4214 // probability.
4215 // For interleaved evolution, set assignments dividing PDFs into
4216 // sea and valence content. This assignment is, until a history path
4217 // is chosen and a first trial shower performed, not fully correct
4218 // (since content is chosen form too high x and too low scale). The
4219 // assignment used for reweighting will be corrected after trial
4220 // showering
4221 
4222 void History::setupBeams() {
4223 
4224  // Do nothing for empty event, possible if sequence of
4225  // clusterings was ill-advised in that it results in
4226  // colour-disconnected states
4227  if (state.size() < 4) return;
4228  // Do nothing for e+e- beams
4229  if ( state[3].colType() == 0 ) return;
4230  if ( state[4].colType() == 0 ) return;
4231 
4232  // Incoming partons to hard process are stored in slots 3 and 4.
4233  int inS = 0;
4234  int inP = 0;
4235  int inM = 0;
4236  for(int i=0;i< int(state.size()); ++i) {
4237  if (state[i].mother1() == 1) inP = i;
4238  if (state[i].mother1() == 2) inM = i;
4239  }
4240 
4241  // Save some info before clearing beams
4242  // Mothers of incoming partons companion code
4243  int motherPcompRes = -1;
4244  int motherMcompRes = -1;
4245 
4246  bool sameFlavP = false;
4247  bool sameFlavM = false;
4248 
4249  if (mother) {
4250  int inMotherP = 0;
4251  int inMotherM = 0;
4252  for(int i=0;i< int(mother->state.size()); ++i) {
4253  if (mother->state[i].mother1() == 1) inMotherP = i;
4254  if (mother->state[i].mother1() == 2) inMotherM = i;
4255  }
4256  sameFlavP = (state[inP].id() == mother->state[inMotherP].id());
4257  sameFlavM = (state[inM].id() == mother->state[inMotherM].id());
4258 
4259  motherPcompRes = (sameFlavP) ? beamA[0].companion() : -2;
4260  motherMcompRes = (sameFlavM) ? beamB[0].companion() : -2;
4261  }
4262 
4263  // Append the current incoming particles to the beam
4264  beamA.clear();
4265  beamB.clear();
4266 
4267  // Get energy of incoming particles
4268  double Ep = 2. * state[inP].e();
4269  double Em = 2. * state[inM].e();
4270 
4271  // If incoming partons are massive then recalculate to put them massless.
4272  if (state[inP].m() != 0. || state[inM].m() != 0.) {
4273  Ep = state[inP].pPos() + state[inM].pPos();
4274  Em = state[inP].pNeg() + state[inM].pNeg();
4275  }
4276 
4277  // Add incoming hard-scattering partons to list in beam remnants.
4278  double x1 = Ep / state[inS].m();
4279  beamA.append( inP, state[inP].id(), x1);
4280  double x2 = Em / state[inS].m();
4281  beamB.append( inM, state[inM].id(), x2);
4282 
4283  // Scale. For ME multiplicity history, put scale to mu_F
4284  // (since sea/valence quark content is chosen from this scale)
4285  double scalePDF = (mother) ? scale : infoPtr->QFac();
4286  // Find whether incoming partons are valence or sea. Store.
4287  // Can I do better, e.g. by setting the scale to the hard process
4288  // scale (= M_W) or by replacing one of the x values by some x/z??
4289  beamA.xfISR( 0, state[inP].id(), x1, scalePDF*scalePDF);
4290  if (!mother) {
4291  beamA.pickValSeaComp();
4292  } else {
4293  beamA[0].companion(motherPcompRes);
4294  }
4295  beamB.xfISR( 0, state[inM].id(), x2, scalePDF*scalePDF);
4296  if (!mother) {
4297  beamB.pickValSeaComp();
4298  } else {
4299  beamB[0].companion(motherMcompRes);
4300  }
4301 
4302 }
4303 
4304 //--------------------------------------------------------------------------
4305 
4306 // Calculate the PDF ratio used in the argument of the no-emission
4307 // probability
4308 
4309 double History::pdfForSudakov() {
4310 
4311  // Do nothing for e+e- beams
4312  if ( state[3].colType() == 0 ) return 1.0;
4313  if ( state[4].colType() == 0 ) return 1.0;
4314 
4315  // Check if splittings was ISR or FSR
4316  bool FSR = ( mother->state[clusterIn.emittor].isFinal()
4317  && mother->state[clusterIn.recoiler].isFinal());
4318  bool FSRinRec = ( mother->state[clusterIn.emittor].isFinal()
4319  && !mother->state[clusterIn.recoiler].isFinal());
4320 
4321  // Done for pure FSR
4322  if (FSR) return 1.0;
4323 
4324  int iInMother = (FSRinRec)? clusterIn.recoiler : clusterIn.emittor;
4325  // Find side of event that was reclustered
4326  int side = ( mother->state[iInMother].pz() > 0 ) ? 1 : -1;
4327 
4328  int inP = 0;
4329  int inM = 0;
4330  for(int i=0;i< int(state.size()); ++i) {
4331  if (state[i].mother1() == 1) inP = i;
4332  if (state[i].mother1() == 2) inM = i;
4333  }
4334 
4335  // Save mother id
4336  int idMother = mother->state[iInMother].id();
4337  // Find daughter position and id
4338  int iDau = (side == 1) ? inP : inM;
4339  int idDaughter = state[iDau].id();
4340  // Get mother x value
4341  double xMother = 2. * mother->state[iInMother].e() / mother->state[0].e();
4342  // Get daughter x value of daughter
4343  double xDaughter = 2.*state[iDau].e() / state[0].e(); // x1 before isr
4344 
4345  // Calculate pdf ratio
4346  double ratio = getPDFratio(side, true, false, idMother, xMother, scale,
4347  idDaughter, xDaughter, scale);
4348 
4349  // For FSR with incoming recoiler, maximally return 1.0, as
4350  // is done in Pythia::TimeShower.
4351  // For ISR, return ratio
4352  return ( (FSRinRec)? min(1.,ratio) : ratio);
4353 }
4354 
4355 //--------------------------------------------------------------------------
4356 
4357 // Calculate the hard process matrix element to include in the selection
4358 // probability.
4359 
4360 double History::hardProcessME( const Event& event ) {
4361 
4362  // Get hard process.
4363  string process = mergingHooksPtr->getProcessString();
4364  double result = 1.;
4365 
4366  if ( process.compare("pp>e+ve") == 0
4367  || process.compare("pp>e-ve~") == 0
4368  || process.compare("pp>LEPTONS,NEUTRINOS") == 0 ) {
4369  // Do nothing for incomplete process.
4370  int nFinal = 0;
4371  for ( int i=0; i < int(event.size()); ++i )
4372  if ( event[i].isFinal() ) nFinal++;
4373  if ( nFinal != 2 ) return 1.;
4374  // Get W-boson mass and width.
4375  double mW = particleDataPtr->m0(24);
4376  double gW = particleDataPtr->mWidth(24) / mW;
4377  // Get incoming particles.
4378  int inP = (event[3].pz() > 0) ? 3 : 4;
4379  int inM = (event[3].pz() > 0) ? 4 : 3;
4380  // Get outgoing particles.
4381  int outP = 0;
4382  for ( int i=0; i < int(event.size()); ++i ) {
4383  if ( event[i].isFinal() && event[i].px() > 0 ) outP = i;
4384  }
4385  // Get Mandelstam variables.
4386  double sH = (event[inP].p() + event[inM].p()).m2Calc();
4387  double tH = (event[inP].p() - event[outP].p()).m2Calc();
4388  double uH = - sH - tH;
4389 
4390  // Return kinematic part of matrix element.
4391  result = ( 1. + (tH - uH)/sH ) / ( pow2(sH - mW*mW) + pow2(sH*gW) );
4392  } else
4393  result = mergingHooksPtr->hardProcessME(event);
4394 
4395  return result;
4396 
4397 }
4398 
4399 //--------------------------------------------------------------------------
4400 
4401 // Perform the clustering of the current state and return the
4402 // clustered state.
4403 // IN Clustering : rad,rec,emt triple to be clustered to two partons
4404 // OUT clustered state
4405 
4406 Event History::cluster( const Clustering & inSystem ) {
4407 
4408  // Initialise tags of particles to be changed
4409  int Rad = inSystem.emittor;
4410  int Rec = inSystem.recoiler;
4411  int Emt = inSystem.emitted;
4412  // Initialise eCM,mHat
4413  double eCM = state[0].e();
4414  // Flags for type of radiation
4415  int radType = state[Rad].isFinal() ? 1 : -1;
4416  int recType = state[Rec].isFinal() ? 1 : -1;
4417 
4418  // Construct the clustered event
4419  Event NewEvent = Event();
4420  NewEvent.init("(hard process-modified)", particleDataPtr);
4421  NewEvent.clear();
4422  // Copy all unchanged particles to NewEvent
4423  for (int i = 0; i < state.size(); ++i)
4424  if ( i != Rad && i != Rec && i != Emt )
4425  NewEvent.append( state[i] );
4426 
4427  // Copy all the junctions one by one
4428  for (int i = 0; i < state.sizeJunction(); ++i)
4429  NewEvent.appendJunction( state.getJunction(i) );
4430  // Find an appropriate scale for the hard process
4431  double mu = choseHardScale(state);
4432  // Initialise scales for new event
4433  NewEvent.saveSize();
4434  NewEvent.saveJunctionSize();
4435  NewEvent.scale(mu);
4436  NewEvent.scaleSecond(mu);
4437 
4438  // Set properties of radiator/recoiler after the clustering
4439  // Recoiler properties will be unchanged
4440  Particle RecBefore = Particle( state[Rec] );
4441  RecBefore.setEvtPtr(&NewEvent);
4442  RecBefore.daughters(0,0);
4443  // Find flavour of radiator before splitting
4444  int radID = getRadBeforeFlav(Rad, Emt, state);
4445  int recID = state[Rec].id();
4446  Particle RadBefore = Particle( state[Rad] );
4447  RadBefore.setEvtPtr(&NewEvent);
4448  RadBefore.id(radID);
4449  RadBefore.daughters(0,0);
4450  // Put dummy values for colours
4451  RadBefore.cols(RecBefore.acol(),RecBefore.col());
4452 
4453  // Reset status if the reclustered radiator is a resonance.
4454  if ( particleDataPtr->isResonance(radID) && radType == 1)
4455  RadBefore.status(state[Rad].status());
4456 
4457  // Put mass for radiator and recoiler
4458  double radMass = particleDataPtr->m0(radID);
4459  double recMass = particleDataPtr->m0(recID);
4460  if (radType == 1 ) RadBefore.m(radMass);
4461  else RadBefore.m(0.0);
4462  if (recType == 1 ) RecBefore.m(recMass);
4463  else RecBefore.m(0.0);
4464 
4465  // Construct momenta and colours of clustered particles
4466  // ISR/FSR splittings are treated differently
4467  if ( radType + recType == 2 && state[Emt].idAbs() != 24 ) {
4468  // Clustering of final(rad)/final(rec) dipole splitting
4469  // Get eCM of (rad,rec,emt) triple
4470  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
4471  double eCMME = sum.mCalc();
4472 
4473  // Define radiator and recoiler back-to-back in the dipole
4474  // rest frame [=(state[rad]+state[emt])+state[rec] rest frame]
4475  Vec4 Rad4mom;
4476  Vec4 Rec4mom;
4477  double mDsq = pow2(eCMME);
4478  // If possible, keep the invariant mass of the radiator.
4479  double mRsq = (radID == state[Rad].id() )
4480  ? abs(state[Rad].p().m2Calc())
4481  : pow2(particleDataPtr->m0(radID));
4482  double mSsq = abs(state[Rec].p().m2Calc());
4483  double a = 0.5*sqrt(mDsq);
4484  double b = 0.25*(mRsq - mSsq) / a;
4485  double c = sqrt(pow2(a) + pow2(b) - 2.*a*b - mSsq);
4486 
4487  Rad4mom.p( 0., 0., c, a+b);
4488  Rec4mom.p( 0., 0.,-c, a-b);
4489 
4490  // Find boost from Rad4mom+Rec4mom rest frame to event cm frame
4491  Vec4 old1 = Vec4(state[Rad].p() + state[Emt].p());
4492  Vec4 old2 = Vec4(state[Rec].p());
4493  RotBstMatrix fromCM;
4494  fromCM.fromCMframe(old1, old2);
4495  // Transform momenta
4496  Rad4mom.rotbst(fromCM);
4497  Rec4mom.rotbst(fromCM);
4498 
4499  RadBefore.p(Rad4mom);
4500  RecBefore.p(Rec4mom);
4501  RadBefore.m(sqrt(mRsq));
4502  RecBefore.m(sqrt(mSsq));
4503 
4504  } else if ( radType + recType == 2 && state[Emt].idAbs() == 24 ) {
4505  // Clustering of final(rad)/final(rec) dipole splitting
4506  // Get eCM of (rad,rec,emt) triple
4507  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
4508  double eCMME = sum.mCalc();
4509 
4510  // Define radiator and recoiler back-to-back in the dipole
4511  // rest frame [=(state[rad]+state[emt])+state[rec] rest frame]
4512  Vec4 Rad4mom;
4513  Vec4 Rec4mom;
4514  double mDsq = pow2(eCMME);
4515  // If possible, keep the invariant mass of the radiator.
4516  double mRsq = (radID == state[Rad].id() )
4517  ? abs(state[Rad].p().m2Calc())
4518  : pow2(particleDataPtr->m0(radID));
4519  double mSsq = abs(state[Rec].p().m2Calc());
4520  double a = 0.5*sqrt(mDsq);
4521  double b = 0.25*(mRsq - mSsq) / a;
4522  double c = sqrt(pow2(a) + pow2(b) - 2.*a*b - mSsq);
4523 
4524  Rad4mom.p( 0., 0., c, a+b);
4525  Rec4mom.p( 0., 0.,-c, a-b);
4526 
4527  // Find boost from Rad4mom+Rec4mom rest frame to event cm frame
4528  Vec4 old1 = Vec4(state[Rad].p() + state[Emt].p());
4529  Vec4 old2 = Vec4(state[Rec].p());
4530  RotBstMatrix fromCM;
4531  fromCM.fromCMframe(old1, old2);
4532  // Transform momenta
4533  Rad4mom.rotbst(fromCM);
4534  Rec4mom.rotbst(fromCM);
4535 
4536  RadBefore.p(Rad4mom);
4537  RecBefore.p(Rec4mom);
4538  RadBefore.m(sqrt(mRsq));
4539  RecBefore.m(sqrt(mSsq));
4540 
4541  } else if ( radType + recType == 0 ) {
4542  // Clustering of final(rad)/initial(rec) dipole splitting
4543  // Get eCM of (rad,rec,emt) triple
4544  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
4545  double eCMME = sum.mCalc();
4546  // Define radiator and recoiler back-to-back in the dipole
4547  // rest frame [=(state[rad]+state[emt])+state[rec] rest frame]
4548  Vec4 Rad4mom;
4549  Vec4 Rec4mom;
4550  double mDsq = pow2(eCMME);
4551  // If possible, keep the invariant mass of the radiator.
4552  double mRsq = (radID == state[Rad].id() )
4553  ? abs(state[Rad].p().m2Calc())
4554  : pow2(particleDataPtr->m0(radID));
4555  double mSsq = abs(state[Rec].p().m2Calc());
4556  double a = 0.5*sqrt(mDsq);
4557  double b = 0.25*(mRsq - mSsq) / a;
4558  double c = sqrt(pow2(a) + pow2(b) - 2.*a*b - mSsq);
4559 
4560  Rad4mom.p( 0., 0., c, a+b);
4561  Rec4mom.p( 0., 0.,-c, a-b);
4562 
4563  // Find boost from Rad4mom+Rec4mom rest frame to event cm frame
4564  Vec4 old1 = Vec4(state[Rad].p() + state[Emt].p());
4565  Vec4 old2 = Vec4(state[Rec].p());
4566  RotBstMatrix fromCM;
4567  fromCM.fromCMframe(old1, old2);
4568  // Transform momenta
4569  Rad4mom.rotbst(fromCM);
4570  Rec4mom.rotbst(fromCM);
4571 
4572  // Rescale recoiler momentum
4573  Rec4mom = 2.*state[Rec].p() - Rec4mom;
4574 
4575  RadBefore.p(Rad4mom);
4576  RecBefore.p(Rec4mom);
4577  RadBefore.m(sqrt(mRsq));
4578 
4579  // Set mass of initial recoiler to zero
4580  RecBefore.m( 0.0 );
4581 
4582  } else {
4583  // Clustering of initial(rad)/initial(rec) dipole splitting
4584  // We want to cluster: Meaning doing the inverse of a process
4585  // ( pDaughter + pRecoiler -> pOut )
4586  // ==> ( pMother + pPartner -> pOut' + pSister )
4587  // produced by an initial state splitting. The matrix element
4588  // provides us with pMother, pPartner, pSister and pOut'
4589  Vec4 pMother( state[Rad].p() );
4590  Vec4 pSister( state[Emt].p() );
4591  Vec4 pPartner( state[Rec].p() );
4592  Vec4 pDaughter( 0.,0.,0.,0. );
4593  Vec4 pRecoiler( 0.,0.,0.,0. );
4594 
4595  // Find side that radiates event (mother moving in sign * p_z direction).
4596  int sign = (state[Rad].pz() > 0.) ? 1 : -1;
4597 
4598  // Find rotation by phi that would have been done for a
4599  // splitting daughter -> mother + sister
4600  double phi = pSister.phi();
4601  // Find rotation with -phi
4602  RotBstMatrix rot_by_mphi;
4603  rot_by_mphi.rot(0.,-phi);
4604  // Find rotation with +phi
4605  RotBstMatrix rot_by_pphi;
4606  rot_by_pphi.rot(0.,phi);
4607 
4608  // Transform pMother and outgoing momenta
4609  pMother.rotbst( rot_by_mphi );
4610  pSister.rotbst( rot_by_mphi );
4611  pPartner.rotbst( rot_by_mphi );
4612  for(int i=3; i< NewEvent.size(); ++i)
4613  NewEvent[i].rotbst( rot_by_mphi );
4614 
4615  // Get mother and partner x values
4616  // x1 after isr
4617  double x1 = 2. * pMother.e() / eCM;
4618  // x2 after isr
4619  double x2 = 2. * pPartner.e() / eCM;
4620 
4621  pDaughter.p( pMother - pSister);
4622  pRecoiler.p( pPartner );
4623 
4624  // Find boost from event cm frame to rest frame of
4625  // of-shell daughter + on-shell recoiler
4626  RotBstMatrix from_CM_to_DR;
4627  if (sign == 1)
4628  from_CM_to_DR.toCMframe(pDaughter, pRecoiler);
4629  else
4630  from_CM_to_DR.toCMframe(pRecoiler, pDaughter);
4631 
4632  // Transform all momenta
4633  pMother.rotbst( from_CM_to_DR );
4634  pPartner.rotbst( from_CM_to_DR );
4635  pSister.rotbst( from_CM_to_DR );
4636  for(int i=3; i< NewEvent.size(); ++i)
4637  NewEvent[i].rotbst( from_CM_to_DR );
4638 
4639  // Find theta angle between pMother and z-axis and undo
4640  // rotation that would have been done by shower
4641  double theta = pMother.theta();
4642  if ( pMother.px() < 0. ) theta *= -1.;
4643  if (sign == -1) theta += M_PI;
4644 
4645 
4646  // Find rotation by +theta
4647  RotBstMatrix rot_by_ptheta;
4648  rot_by_ptheta.rot(theta, 0.);
4649 
4650  // Transform all momenta
4651  pMother.rotbst( rot_by_ptheta );
4652  pPartner.rotbst( rot_by_ptheta );
4653  pSister.rotbst( rot_by_ptheta );
4654  for(int i=3; i< NewEvent.size(); ++i)
4655  NewEvent[i].rotbst( rot_by_ptheta );
4656 
4657  // Find z of the splitting
4658  Vec4 qDip( pMother - pSister);
4659  Vec4 qAfter(pMother + pPartner);
4660  Vec4 qBefore(qDip + pPartner);
4661  double z = qBefore.m2Calc() / qAfter.m2Calc();
4662 
4663  // Calculate new e_CM^2
4664  double x1New = z*x1; // x1 before isr
4665  double x2New = x2; // x2 before isr
4666  double sHat = x1New*x2New*eCM*eCM;
4667 
4668  // Construct daughter and recoiler momenta
4669  pDaughter.p( 0., 0., sign*0.5*sqrt(sHat), 0.5*sqrt(sHat));
4670  pRecoiler.p( 0., 0., -sign*0.5*sqrt(sHat), 0.5*sqrt(sHat));
4671 
4672  // Find boost from current (daughter+recoiler rest frame)
4673  // frame to rest frame of daughter+unchanged recoiler to
4674  // recover the old x2 value
4675  RotBstMatrix from_DR_to_CM;
4676  from_DR_to_CM.bst( 0., 0., sign*( x1New - x2New ) / ( x1New + x2New ) );
4677 
4678  // Correct for momentum mismatch by transforming all momenta
4679  pMother.rotbst( from_DR_to_CM );
4680  pPartner.rotbst( from_DR_to_CM );
4681  pSister.rotbst( from_DR_to_CM );
4682  pDaughter.rotbst( from_DR_to_CM );
4683  pRecoiler.rotbst( from_DR_to_CM );
4684  for(int i=3; i< NewEvent.size(); ++i)
4685  NewEvent[i].rotbst( from_DR_to_CM );
4686 
4687  // Transform pMother and outgoing momenta
4688  pMother.rotbst( rot_by_pphi );
4689  pPartner.rotbst( rot_by_pphi );
4690  pSister.rotbst( rot_by_pphi );
4691  pDaughter.rotbst( rot_by_pphi );
4692  pRecoiler.rotbst( rot_by_pphi );
4693  for(int i=3; i< NewEvent.size(); ++i)
4694  NewEvent[i].rotbst( rot_by_pphi );
4695 
4696  // Set momenta of particles to be attached to new event record
4697  RecBefore.p( pRecoiler );
4698  RadBefore.p( pDaughter );
4699  if (RecBefore.pz() > 0.) RecBefore.mother1(1);
4700  else RecBefore.mother1(2);
4701  if (RadBefore.pz() > 0.) RadBefore.mother1(1);
4702  else RadBefore.mother1(2);
4703 
4704  }
4705 
4706  // Put some dummy production scales for RecBefore, RadBefore
4707  RecBefore.scale(mu);
4708  RadBefore.scale(mu);
4709 
4710  // Append new recoiler and find new radiator colour
4711  NewEvent.append(RecBefore);
4712 
4713  // Assign the correct colour to re-clustered radiator.
4714  // Keep old radiator colours for electroweak emission.
4715  int emtID = state[Emt].id();
4716  if ( emtID == 22 || emtID == 23 || abs(emtID) == 24 )
4717  RadBefore.cols( state[Rad].col(), state[Rad].acol() );
4718  // For QCD, carefully construct colour.
4719  else if ( !connectRadiator( RadBefore, radType, RecBefore, recType,
4720  NewEvent ) ) {
4721  // Could happen if previous clustering produced several colour
4722  // singlett subsystems in the event
4723  NewEvent.reset();
4724  return NewEvent;
4725  }
4726 
4727  // Build the clustered event
4728  Event outState = Event();
4729  outState.init("(hard process-modified)", particleDataPtr);
4730  outState.clear();
4731 
4732  // Copy system and incoming beam particles to outState
4733  for (int i = 0; i < 3; ++i)
4734  outState.append( NewEvent[i] );
4735  // Copy all the junctions one by one
4736  for (int i = 0; i < state.sizeJunction(); ++i)
4737  outState.appendJunction( state.getJunction(i) );
4738  // Initialise scales for new event
4739  outState.saveSize();
4740  outState.saveJunctionSize();
4741  outState.scale(mu);
4742  outState.scaleSecond(mu);
4743  bool radAppended = false;
4744  bool recAppended = false;
4745  int size = int(outState.size());
4746  // Save position of radiator in new event record
4747  int radPos = 0;
4748 
4749  // Append first incoming particle
4750  if ( RecBefore.mother1() == 1) {
4751  outState.append( RecBefore );
4752  recAppended = true;
4753  } else if ( RadBefore.mother1() == 1 ) {
4754  radPos = outState.append( RadBefore );
4755  radAppended = true;
4756  } else {
4757  // Find second incoming in input event
4758  int in1 = 0;
4759  for(int i=0; i < int(state.size()); ++i)
4760  if (state[i].mother1() == 1) in1 =i;
4761  outState.append( state[in1] );
4762  size++;
4763  }
4764  // Append second incoming particle
4765  if ( RecBefore.mother1() == 2) {
4766  outState.append( RecBefore );
4767  recAppended = true;
4768  } else if ( RadBefore.mother1() == 2 ) {
4769  radPos = outState.append( RadBefore );
4770  radAppended = true;
4771  } else {
4772  // Find second incoming in input event
4773  int in2 = 0;
4774  for(int i=0; i < int(state.size()); ++i)
4775  if (state[i].mother1() == 2) in2 =i;
4776 
4777  outState.append( state[in2] );
4778  size++;
4779  }
4780 
4781  // Append new recoiler if not done already
4782  if (!recAppended && !RecBefore.isFinal()) {
4783  recAppended = true;
4784  outState.append( RecBefore);
4785  }
4786  // Append new radiator if not done already
4787  if (!radAppended && !RadBefore.isFinal()) {
4788  radAppended = true;
4789  radPos = outState.append( RadBefore);
4790  }
4791 
4792  // Append intermediate particle
4793  // (careful not to append reclustered recoiler)
4794  // Append intermediate particle
4795  // (careful not to append reclustered recoiler)
4796  for (int i = 0; i < int(NewEvent.size()-1); ++i)
4797  if (NewEvent[i].status() == -22) outState.append( NewEvent[i] );
4798  // Append final state particles, resonances first
4799  for (int i = 0; i < int(NewEvent.size()-1); ++i)
4800  if (NewEvent[i].status() == 22) outState.append( NewEvent[i] );
4801  // Then start appending partons
4802  if (!radAppended && RadBefore.statusAbs() == 22)
4803  radPos = outState.append(RadBefore);
4804  if (!recAppended)
4805  outState.append(RecBefore);
4806  if (!radAppended && RadBefore.statusAbs() != 22)
4807  radPos = outState.append(RadBefore);
4808  // Then partons (not reclustered recoiler)
4809  for(int i = 0; i < int(NewEvent.size()-1); ++i)
4810  if ( NewEvent[i].status() != 22
4811  && NewEvent[i].colType() != 0
4812  && NewEvent[i].isFinal())
4813  outState.append( NewEvent[i] );
4814  // Then the rest
4815  for(int i = 0; i < int(NewEvent.size()-1); ++i)
4816  if ( NewEvent[i].status() != 22
4817  && NewEvent[i].colType() == 0
4818  && NewEvent[i].isFinal() )
4819  outState.append( NewEvent[i]);
4820 
4821  // Find intermediate and respective daughters
4822  vector<int> PosIntermediate;
4823  vector<int> PosDaughter1;
4824  vector<int> PosDaughter2;
4825  for(int i=0; i < int(outState.size()); ++i)
4826  if (outState[i].status() == -22) {
4827  PosIntermediate.push_back(i);
4828  int d1 = outState[i].daughter1();
4829  int d2 = outState[i].daughter2();
4830  // Find daughters in output state
4831  int daughter1 = FindParticle( state[d1], outState);
4832  int daughter2 = FindParticle( state[d2], outState);
4833  // If both daughters found, done
4834  // Else put first final particle as first daughter
4835  // and last final particle as second daughter
4836  if (daughter1 > 0)
4837  PosDaughter1.push_back( daughter1);
4838  else {
4839  daughter1 = 0;
4840  while(!outState[daughter1].isFinal() ) daughter1++;
4841  PosDaughter1.push_back( daughter1);
4842  }
4843  if (daughter2 > 0)
4844  PosDaughter2.push_back( daughter2);
4845  else {
4846  daughter2 = outState.size()-1;
4847  while(!outState[daughter2].isFinal() ) daughter2--;
4848  PosDaughter2.push_back( daughter2);
4849  }
4850  }
4851  // Set daughters and mothers
4852  for(int i=0; i < int(PosIntermediate.size()); ++i) {
4853  outState[PosIntermediate[i]].daughters(PosDaughter1[i],PosDaughter2[i]);
4854  outState[PosDaughter1[i]].mother1(PosIntermediate[i]);
4855  outState[PosDaughter2[i]].mother1(PosIntermediate[i]);
4856  }
4857 
4858  // Find range of final state partons
4859  int minParFinal = int(outState.size());
4860  int maxParFinal = 0;
4861  for(int i=0; i < int(outState.size()); ++i)
4862  if (outState[i].mother1() == 3 && outState[i].mother2() == 4) {
4863  minParFinal = min(i,minParFinal);
4864  maxParFinal = max(i,maxParFinal);
4865  }
4866 
4867  if (minParFinal == maxParFinal) maxParFinal = 0;
4868  outState[3].daughters(minParFinal,maxParFinal);
4869  outState[4].daughters(minParFinal,maxParFinal);
4870 
4871  // Update event properties
4872  outState.saveSize();
4873  outState.saveJunctionSize();
4874 
4875  // Almost there...
4876  // If an intermediate coloured parton exists which was directly
4877  // colour connected to the radiator before the splitting, and the
4878  // radiator before and after the splitting had only one colour, problems
4879  // will arise since the colour of the radiator will be changed, whereas
4880  // the intermediate parton still has the old colour. In effect, this
4881  // means that when setting up a event for trial showering, one colour will
4882  // be free.
4883  // Hence, check for an intermediate coloured triplet resonance has been
4884  // colour-connected to the "old" radiator.
4885  // Find resonance
4886  int iColRes = 0;
4887  if ( radType == -1 && state[Rad].colType() == 1) {
4888  // Find resonance connected to initial colour
4889  for(int i=0; i < int(state.size()); ++i)
4890  if ( i != Rad && i != Emt && i != Rec
4891  && state[i].status() == -22
4892  && state[i].col() == state[Rad].col() )
4893  iColRes = i;
4894  } else if ( radType == -1 && state[Rad].colType() == -1) {
4895  // Find resonance connected to initial anticolour
4896  for(int i=0; i < int(state.size()); ++i)
4897  if ( i != Rad && i != Emt && i != Rec
4898  && state[i].status() == -22
4899  && state[i].acol() == state[Rad].acol() )
4900  iColRes = i;
4901  } else if ( radType == 1 && state[Rad].colType() == 1) {
4902  // Find resonance connected to final state colour
4903  for(int i=0; i < int(state.size()); ++i)
4904  if ( i != Rad && i != Emt && i != Rec
4905  && state[i].status() == -22
4906  && state[i].col() == state[Rad].col() )
4907  iColRes = i;
4908  } else if ( radType == 1 && state[Rad].colType() == -1) {
4909  // Find resonance connected to final state anticolour
4910  for(int i=0; i < int(state.size()); ++i)
4911  if ( i != Rad && i != Emt && i != Rec
4912  && state[i].status() == -22
4913  && state[i].acol() == state[Rad].acol() )
4914  iColRes = i;
4915  }
4916 
4917  if (iColRes > 0) {
4918  // Now find this resonance in the reclustered state
4919  int iColResNow = FindParticle( state[iColRes], outState);
4920 
4921  // Find reclustered radiator colours
4922  int radCol = outState[radPos].col();
4923  int radAcl = outState[radPos].acol();
4924  // Find resonance radiator colours
4925  int resCol = outState[iColResNow].col();
4926  int resAcl = outState[iColResNow].acol();
4927  // Check if any of the reclustered radiators colours match the resonance
4928  bool matchesRes = (radCol > 0
4929  && ( radCol == resCol || radCol == resAcl))
4930  || (radAcl > 0
4931  && ( radAcl == resCol || radAcl == resAcl));
4932 
4933  // If a resonance has been found, but no colours match, change
4934  // the colour of the resonance
4935  if (!matchesRes && iColResNow > 0) {
4936  if ( radType == -1 && outState[radPos].colType() == 1)
4937  outState[iColResNow].col(radCol);
4938  else if ( radType ==-1 && outState[radPos].colType() ==-1)
4939  outState[iColResNow].acol(radAcl);
4940  else if ( radType == 1 && outState[radPos].colType() == 1)
4941  outState[iColResNow].col(radCol);
4942  else if ( radType == 1 && outState[radPos].colType() ==-1)
4943  outState[iColResNow].acol(radAcl);
4944  }
4945 
4946 
4947  // If a resonance has been found, but no colours match, and the position
4948  // of the resonance in the event record has been changed, update the
4949  // radiator mother
4950  if (!matchesRes && iColResNow > 0 && iColRes != iColResNow)
4951  outState[radPos].mother1(iColResNow);
4952 
4953  }
4954 
4955  // If event is not constructed properly, return false
4956  if ( !validEvent(outState) ) {
4957  outState.reset();
4958  return outState;
4959  }
4960 
4961  // Remember position of reclustered radiator in state
4962  iReclusteredNew = radPos;
4963 
4964  // Done
4965  return outState;
4966 }
4967 
4968 //--------------------------------------------------------------------------
4969 
4970 // Function to get the flavour of the radiator before the splitting
4971 // for clustering
4972 // IN int : Flavour of the radiator after the splitting
4973 // int : Flavour of the emitted after the splitting
4974 // OUT int : Flavour of the radiator before the splitting
4975 
4976 int History::getRadBeforeFlav(const int RadAfter, const int EmtAfter,
4977  const Event& event) {
4978 
4979  int type = event[RadAfter].isFinal() ? 1 :-1;
4980  int emtID = event[EmtAfter].id();
4981  int radID = event[RadAfter].id();
4982  int emtCOL = event[EmtAfter].col();
4983  int radCOL = event[RadAfter].col();
4984  int emtACL = event[EmtAfter].acol();
4985  int radACL = event[RadAfter].acol();
4986 
4987  bool colConnected = ((type == 1) && ( (emtCOL !=0 && (emtCOL ==radACL))
4988  || (emtACL !=0 && (emtACL ==radCOL)) ))
4989  ||((type ==-1) && ( (emtCOL !=0 && (emtCOL ==radCOL))
4990  || (emtACL !=0 && (emtACL ==radACL)) ));
4991  // QCD splittings
4992  // Gluon radiation
4993  if ( emtID == 21 )
4994  return radID;
4995  // Final state gluon splitting
4996  if ( type == 1 && emtID == -radID && !colConnected )
4997  return 21;
4998  // Initial state s-channel gluon splitting
4999  if ( type ==-1 && radID == 21 )
5000  return -emtID;
5001  // Initial state t-channel gluon splitting
5002  if ( type ==-1 && !colConnected
5003  && emtID != 21 && radID != 21 && abs(emtID) < 10 && abs(radID) < 10)
5004  return 21;
5005 
5006  // SQCD splittings
5007  int radSign = (radID < 0) ? -1 : 1;
5008  int offsetL = 1000000;
5009  int offsetR = 2000000;
5010  // Gluino radiation
5011  if ( emtID == 1000021 ) {
5012  // Gluino radiation combined with quark yields squark.
5013  if (abs(radID) < 10 ) {
5014  int offset = offsetL;
5015  // Check if righthanded squark present. If so, make the reclustered
5016  // squark match. Works for squark pair production + gluino emission.
5017  for (int i=0; i < int(event.size()); ++i)
5018  if ( event[i].isFinal()
5019  && event[i].idAbs() < offsetR+10 && event[i].idAbs() > offsetR)
5020  offset = offsetR;
5021  return radSign*(abs(radID)+offset);
5022  }
5023  // Gluino radiation combined with squark yields quark.
5024  if (abs(radID) > offsetL && abs(radID) < offsetL+10 )
5025  return radSign*(abs(radID)-offsetL);
5026  if (abs(radID) > offsetR && abs(radID) < offsetR+10 )
5027  return radSign*(abs(radID)-offsetR);
5028  // Gluino radiation off gluon yields gluino.
5029  if (radID == 21 ) return emtID;
5030  }
5031 
5032  int emtSign = (emtID < 0) ? -1 : 1;
5033  // Get PDG numbering offsets.
5034  int emtOffset = 0;
5035  if ( abs(emtID) > offsetL && abs(emtID) < offsetL+10 )
5036  emtOffset = offsetL;
5037  if ( abs(emtID) > offsetR && abs(emtID) < offsetR+10 )
5038  emtOffset = offsetR;
5039  int radOffset = 0;
5040  if ( abs(radID) > offsetL && abs(radID) < offsetL+10 )
5041  radOffset = offsetL;
5042  if ( abs(radID) > offsetR && abs(radID) < offsetR+10 )
5043  radOffset = offsetR;
5044 
5045  // Final state gluino splitting
5046  if ( type == 1 && !colConnected ) {
5047  // Emitted squark, radiating quark.
5048  if ( emtOffset > 0 && radOffset == 0
5049  && emtSign*(abs(emtID) - emtOffset) == -radID )
5050  return 1000021;
5051  // Emitted quark, radiating squark.
5052  if ( emtOffset == 0 && radOffset > 0
5053  && emtID == -radSign*(abs(radID) - radOffset) )
5054  return 1000021;
5055  }
5056 
5057  // Initial state s-channel gluino splitting
5058  if ( type ==-1 && radID == 1000021 ) {
5059  // Quark entering underlying hard process.
5060  if ( emtOffset > 0 ) return -emtSign*(abs(emtID) - emtOffset);
5061  // Squark entering underlying hard process.
5062  else return -emtSign*(abs(emtID) + emtOffset);
5063  }
5064 
5065  // Initial state t-channel gluino splitting.
5066  if ( type ==-1
5067  && ( (abs(emtID) > offsetL && abs(emtID) < offsetL+10)
5068  || (abs(emtID) > offsetR && abs(emtID) < offsetR+10))
5069  && ( (abs(radID) > offsetL && abs(radID) < offsetL+10)
5070  || (abs(radID) > offsetR && abs(radID) < offsetR+10))
5071  && emtSign*(abs(emtID)+emtOffset) == radSign*(abs(radID) - radOffset)
5072  && !colConnected ) {
5073  return 1000021;
5074  }
5075 
5076  // Electroweak splittings splittings
5077  // Photon / Z radiation: Calculate invariant mass of system
5078  double m2final = (event[RadAfter].p()+ event[EmtAfter].p()).m2Calc();
5079 
5080  if ( emtID == 22 || emtID == 23 ) return radID;
5081  // Final state Photon splitting
5082  if ( type == 1 && emtID == -radID && colConnected && sqrt(m2final) <= 10. )
5083  return 22;
5084  // Final state Photon splitting
5085  if ( type == 1 && emtID == -radID && colConnected && sqrt(m2final) > 10. )
5086  return 23;
5087  // Initial state s-channel photon/ Z splitting
5088  if ( type ==-1 && (radID == 22 || radID == 23) )
5089  return -emtID;
5090  // Initial state t-channel photon / Z splitting: Always bookkeep as photon
5091  if ( type ==-1 && abs(emtID) < 10 && abs(radID) < 10 && colConnected )
5092  return 22;
5093 
5094  // W+ radiation
5095  // Final state W+ splitting
5096  if ( emtID == 24 && radID < 0 ) return radID + 1;
5097  if ( emtID == 24 && radID > 0 ) return radID + 1;
5098 
5099  // W- radiation
5100  // Final state W- splitting
5101  if ( emtID ==-24 && radID < 0 ) return radID - 1;
5102  if ( emtID ==-24 && radID > 0 ) return radID - 1;
5103 
5104  // Done.
5105  return 0;
5106 
5107 }
5108 
5109 //--------------------------------------------------------------------------
5110 
5111 // Function to properly colour-connect the radiator to the rest of
5112 // the event, as needed during clustering
5113 // IN Particle& : Particle to be connected
5114 // Particle : Recoiler forming a dipole with Radiator
5115 // Event : event to which Radiator shall be appended
5116 // OUT true : Radiator could be connected to the event
5117 // false : Radiator could not be connected to the
5118 // event or the resulting event was
5119 // non-valid
5120 
5121 bool History::connectRadiator( Particle& Radiator, const int RadType,
5122  const Particle& Recoiler, const int RecType,
5123  const Event& event ) {
5124 
5125  // Start filling radiator colour indices with dummy values
5126  Radiator.cols( -1, -1 );
5127 
5128  // Radiator should always be colour-connected to recoiler.
5129  // Three cases (rad = Anti-Quark, Quark, Gluon) to be considered
5130  if ( Radiator.colType() == -1 ) {
5131  // For final state antiquark radiator, the anticolour is fixed
5132  // by the final / initial state recoiler colour / anticolour
5133  if ( RadType + RecType == 2 )
5134  Radiator.cols( 0, Recoiler.col());
5135  else if ( RadType + RecType == 0 )
5136  Radiator.cols( 0, Recoiler.acol());
5137  // For initial state antiquark radiator, the anticolour is fixed
5138  // by the colour of the emitted gluon (which will be the
5139  // leftover anticolour of a final state particle or the leftover
5140  // colour of an initial state particle ( = the recoiler))
5141  else {
5142  // Set colour of antiquark radiator to zero
5143  Radiator.col( 0 );
5144  for (int i = 0; i < event.size(); ++i) {
5145  int col = event[i].col();
5146  int acl = event[i].acol();
5147 
5148  if ( event[i].isFinal()) {
5149  // Search for leftover anticolour in final / initial state
5150  if ( acl > 0 && FindCol(acl,i,0,event,1,true) == 0
5151  && FindCol(acl,i,0,event,2,true) == 0 )
5152  Radiator.acol(event[i].acol());
5153  } else {
5154  // Search for leftover colour in initial / final state
5155  if ( col > 0 && FindCol(col,i,0,event,1,true) == 0
5156  && FindCol(col,i,0,event,2,true) == 0 )
5157  Radiator.acol(event[i].col());
5158  }
5159  } // end loop over particles in event record
5160  }
5161 
5162  } else if ( Radiator.colType() == 1 ) {
5163  // For final state quark radiator, the colour is fixed
5164  // by the final / initial state recoiler anticolour / colour
5165  if ( RadType + RecType == 2 )
5166  Radiator.cols( Recoiler.acol(), 0);
5167 
5168  else if ( RadType + RecType == 0 )
5169  Radiator.cols( Recoiler.col(), 0);
5170  // For initial state quark radiator, the colour is fixed
5171  // by the anticolour of the emitted gluon (which will be the
5172  // leftover colour of a final state particle or the leftover
5173  // anticolour of an initial state particle ( = the recoiler))
5174 
5175  else {
5176  // Set anticolour of quark radiator to zero
5177  Radiator.acol( 0 );
5178  for (int i = 0; i < event.size(); ++i) {
5179  int col = event[i].col();
5180  int acl = event[i].acol();
5181 
5182  if ( event[i].isFinal()) {
5183  // Search for leftover colour in final / initial state
5184  if ( col > 0 && FindCol(col,i,0,event,1,true) == 0
5185  && FindCol(col,i,0,event,2,true) == 0)
5186  Radiator.col(event[i].col());
5187  } else {
5188  // Search for leftover anticolour in initial / final state
5189  if ( acl > 0 && FindCol(acl,i,0,event,1,true) == 0
5190  && FindCol(acl,i,0,event,2,true) == 0)
5191  Radiator.col(event[i].acol());
5192  }
5193  } // end loop over particles in event record
5194 
5195  } // end distinction between fsr / fsr+initial recoiler / isr
5196 
5197  } else if ( Radiator.colType() == 2 ) {
5198  // For a gluon radiator, one (anticolour) colour index is defined
5199  // by the recoiler colour (anticolour).
5200  // The remaining index is chosen to match the free index in the
5201  // event
5202  // Search for leftover colour (anticolour) in the final state
5203  for (int i = 0; i < event.size(); ++i) {
5204  int col = event[i].col();
5205  int acl = event[i].acol();
5206  int iEx = i;
5207 
5208  if ( event[i].isFinal()) {
5209  if ( col > 0 && FindCol(col,iEx,0,event,1,true) == 0
5210  && FindCol(col,iEx,0,event,2,true) == 0) {
5211  if (Radiator.status() < 0 ) Radiator.col(event[i].col());
5212  else Radiator.acol(event[i].col());
5213  }
5214  if ( acl > 0 && FindCol(acl,iEx,0,event,2,true) == 0
5215  && FindCol(acl,iEx,0,event,1,true) == 0 ) {
5216  if (Radiator.status() < 0 ) Radiator.acol(event[i].acol());
5217  else Radiator.col(event[i].acol());
5218  }
5219  } else {
5220  if ( col > 0 && FindCol(col,iEx,0,event,1,true) == 0
5221  && FindCol(col,iEx,0,event,2,true) == 0) {
5222  if (Radiator.status() < 0 ) Radiator.acol(event[i].col());
5223  else Radiator.col(event[i].col());
5224  }
5225  if ( acl > 0 && (FindCol(acl,iEx,0,event,2,true) == 0
5226  && FindCol(acl,iEx,0,event,1,true) == 0)) {
5227  if (Radiator.status() < 0 ) Radiator.col(event[i].acol());
5228  else Radiator.acol(event[i].acol());
5229  }
5230  }
5231  } // end loop over particles in event record
5232  } // end cases of different radiator colour type
5233 
5234  // If either colour or anticolour has not been set, return false
5235  if (Radiator.col() < 0 || Radiator.acol() < 0) return false;
5236  // Done
5237  return true;
5238 }
5239 
5240 //--------------------------------------------------------------------------
5241 
5242 // Function to find a colour (anticolour) index in the input event
5243 // IN int col : Colour tag to be investigated
5244 // int iExclude1 : Identifier of first particle to be excluded
5245 // from search
5246 // int iExclude2 : Identifier of second particle to be excluded
5247 // from search
5248 // Event event : event to be searched for colour tag
5249 // int type : Tag to define if col should be counted as
5250 // colour (type = 1) [->find anti-colour index
5251 // contracted with col]
5252 // anticolour (type = 2) [->find colour index
5253 // contracted with col]
5254 // OUT int : Position of particle in event record
5255 // contraced with col [0 if col is free tag]
5256 
5257 int History::FindCol(int col, int iExclude1, int iExclude2,
5258  const Event& event, int type, bool isHardIn) {
5259 
5260  bool isHard = isHardIn;
5261  int index = 0;
5262 
5263  if (isHard) {
5264  // Search event record for matching colour & anticolour
5265  for(int n = 0; n < event.size(); ++n) {
5266  if ( n != iExclude1 && n != iExclude2
5267  && event[n].colType() != 0
5268  &&( event[n].status() > 0 // Check outgoing
5269  || event[n].status() == -21) ) { // Check incoming
5270  if ( event[n].acol() == col ) {
5271  index = -n;
5272  break;
5273  }
5274  if ( event[n].col() == col ) {
5275  index = n;
5276  break;
5277  }
5278  }
5279  }
5280  } else {
5281 
5282  // Search event record for matching colour & anticolour
5283  for(int n = 0; n < event.size(); ++n) {
5284  if ( n != iExclude1 && n != iExclude2
5285  && event[n].colType() != 0
5286  &&( event[n].status() == 43 // Check outgoing from ISR
5287  || event[n].status() == 51 // Check outgoing from FSR
5288  || event[n].status() == -41 // first initial
5289  || event[n].status() == -42) ) { // second initial
5290  if ( event[n].acol() == col ) {
5291  index = -n;
5292  break;
5293  }
5294  if ( event[n].col() == col ) {
5295  index = n;
5296  break;
5297  }
5298  }
5299  }
5300  }
5301  // if no matching colour / anticolour has been found, return false
5302  if ( type == 1 && index < 0) return abs(index);
5303  if ( type == 2 && index > 0) return abs(index);
5304 
5305  return 0;
5306 }
5307 
5308 //--------------------------------------------------------------------------
5309 
5310 // Function to in the input event find a particle with quantum
5311 // numbers matching those of the input particle
5312 // IN Particle : Particle to be searched for
5313 // Event : Event to be searched in
5314 // OUT int : > 0 : Position of matching particle in event
5315 // < 0 : No match in event
5316 
5317 int History::FindParticle( const Particle& particle, const Event& event,
5318  bool checkStatus ) {
5319 
5320  int index = -1;
5321 
5322  for ( int i = int(event.size()) - 1; i > 0; --i )
5323  if ( event[i].id() == particle.id()
5324  && event[i].colType() == particle.colType()
5325  && event[i].chargeType() == particle.chargeType()
5326  && event[i].col() == particle.col()
5327  && event[i].acol() == particle.acol()
5328  && event[i].charge() == particle.charge() ) {
5329  index = i;
5330  break;
5331  }
5332 
5333  if ( checkStatus && event[index].status() != particle.status() )
5334  index = -1;
5335 
5336  return index;
5337 }
5338 
5339 //--------------------------------------------------------------------------
5340 
5341 // Function to get the colour of the radiator before the splitting
5342 // for clustering
5343 // IN int : Position of the radiator after the splitting, in the event
5344 // int : Position of the emitted after the splitting, in the event
5345 // Event : Reference event
5346 // OUT int : Colour of the radiator before the splitting
5347 
5348 int History::getRadBeforeCol(const int rad, const int emt,
5349  const Event& event) {
5350 
5351  // Save type of splitting
5352  int type = (event[rad].isFinal()) ? 1 :-1;
5353  // Get flavour of radiator after potential clustering
5354  int radBeforeFlav = getRadBeforeFlav(rad,emt,event);
5355  // Get colours of the radiator before the potential clustering
5356  int radBeforeCol = -1;
5357  // Get reconstructed gluon colours
5358  if (radBeforeFlav == 21) {
5359 
5360  // Start with quark emissions in FSR
5361  if (type == 1 && event[emt].id() != 21) {
5362  radBeforeCol = (event[rad].col() > 0)
5363  ? event[rad].col() : event[emt].col();
5364  // Quark emissions in ISR
5365  } else if (type == -1 && event[emt].id() != 21) {
5366  radBeforeCol = (event[rad].col() > 0)
5367  ? event[rad].col() : event[emt].acol();
5368  //Gluon emissions in FSR
5369  } else if (type == 1 && event[emt].id() == 21) {
5370  // If emitted is a gluon, remove the repeated index, and take
5371  // the remaining indices as colour and anticolour
5372  int colRemove = (event[rad].col() == event[emt].acol())
5373  ? event[rad].acol() : event[rad].col();
5374  radBeforeCol = (event[rad].col() == colRemove)
5375  ? event[emt].col() : event[rad].col();
5376  //Gluon emissions in ISR
5377  } else if (type == -1 && event[emt].id() == 21) {
5378  // If emitted is a gluon, remove the repeated index, and take
5379  // the remaining indices as colour and anticolour
5380  int colRemove = (event[rad].col() == event[emt].col())
5381  ? event[rad].col() : event[rad].acol();
5382  radBeforeCol = (event[rad].col() == colRemove)
5383  ? event[emt].acol() : event[rad].col();
5384  }
5385 
5386  // Get reconstructed quark colours
5387  } else if ( radBeforeFlav != 21 && radBeforeFlav > 0) {
5388 
5389  // Quark emission in FSR
5390  if (type == 1 && event[emt].id() != 21) {
5391  // If radiating is a quark, remove the repeated index, and take
5392  // the remaining indices as colour and anticolour
5393  int colRemove = (event[rad].col() == event[emt].acol())
5394  ? event[rad].acol() : 0;
5395  radBeforeCol = (event[rad].col() == colRemove)
5396  ? event[emt].col() : event[rad].col();
5397  //Gluon emissions in FSR
5398  } else if (type == 1 && event[emt].id() == 21) {
5399  // If emitted is a gluon, remove the repeated index, and take
5400  // the remaining indices as colour and anticolour
5401  int colRemove = (event[rad].col() == event[emt].acol())
5402  ? event[rad].col() : 0;
5403  radBeforeCol = (event[rad].col() == colRemove)
5404  ? event[emt].col() : event[rad].col();
5405  //Quark emissions in ISR
5406  } else if (type == -1 && event[emt].id() != 21) {
5407  // If emitted is a quark, remove the repeated index, and take
5408  // the remaining indices as colour and anticolour
5409  int colRemove = (event[rad].col() == event[emt].col())
5410  ? event[rad].col() : 0;
5411  radBeforeCol = (event[rad].col() == colRemove)
5412  ? event[emt].acol() : event[rad].col();
5413  //Gluon emissions in ISR
5414  } else if (type == -1 && event[emt].id() == 21) {
5415  // If emitted is a gluon, remove the repeated index, and take
5416  // the remaining indices as colour and anticolour
5417  int colRemove = (event[rad].col() == event[emt].col())
5418  ? event[rad].col() : 0;
5419  radBeforeCol = (event[rad].col() == colRemove)
5420  ? event[emt].acol() : event[rad].col();
5421  }
5422  // Other particles are assumed uncoloured
5423  } else {
5424  radBeforeCol = 0;
5425  }
5426 
5427  return radBeforeCol;
5428 
5429 }
5430 
5431 //--------------------------------------------------------------------------
5432 
5433 // Function to get the anticolour of the radiator before the splitting
5434 // for clustering
5435 // IN int : Position of the radiator after the splitting, in the event
5436 // int : Position of the emitted after the splitting, in the event
5437 // Event : Reference event
5438 // OUT int : Anticolour of the radiator before the splitting
5439 
5440 int History::getRadBeforeAcol(const int rad, const int emt,
5441  const Event& event) {
5442 
5443  // Save type of splitting
5444  int type = (event[rad].isFinal()) ? 1 :-1;
5445  // Get flavour of radiator after potential clustering
5446 
5447  int radBeforeFlav = getRadBeforeFlav(rad,emt,event);
5448  // Get colours of the radiator before the potential clustering
5449  int radBeforeAcl = -1;
5450  // Get reconstructed gluon colours
5451  if (radBeforeFlav == 21) {
5452 
5453  // Start with quark emissions in FSR
5454  if (type == 1 && event[emt].id() != 21) {
5455  radBeforeAcl = (event[rad].acol() > 0)
5456  ? event[rad].acol() : event[emt].acol();
5457  // Quark emissions in ISR
5458  } else if (type == -1 && event[emt].id() != 21) {
5459  radBeforeAcl = (event[rad].acol() > 0)
5460  ? event[rad].acol() : event[emt].col();
5461  //Gluon emissions in FSR
5462  } else if (type == 1 && event[emt].id() == 21) {
5463  // If emitted is a gluon, remove the repeated index, and take
5464  // the remaining indices as colour and anticolour
5465  int colRemove = (event[rad].col() == event[emt].acol())
5466  ? event[rad].acol() : event[rad].col();
5467  radBeforeAcl = (event[rad].acol() == colRemove)
5468  ? event[emt].acol() : event[rad].acol();
5469  //Gluon emissions in ISR
5470  } else if (type == -1 && event[emt].id() == 21) {
5471  // If emitted is a gluon, remove the repeated index, and take
5472  // the remaining indices as colour and anticolour
5473  int colRemove = (event[rad].col() == event[emt].col())
5474  ? event[rad].col() : event[rad].acol();
5475  radBeforeAcl = (event[rad].acol() == colRemove)
5476  ? event[emt].col() : event[rad].acol();
5477  }
5478 
5479  // Get reconstructed anti-quark colours
5480  } else if ( radBeforeFlav != 21 && radBeforeFlav < 0) {
5481 
5482  // Antiquark emission in FSR
5483  if (type == 1 && event[emt].id() != 21) {
5484  // If radiating is a antiquark, remove the repeated index, and take
5485  // the remaining indices as colour and anticolour
5486  int colRemove = (event[rad].col() == event[emt].acol())
5487  ? event[rad].acol() : 0;
5488  radBeforeAcl = (event[rad].acol() == colRemove)
5489  ? event[emt].acol() : event[rad].acol();
5490  //Gluon emissions in FSR
5491  } else if (type == 1 && event[emt].id() == 21) {
5492  // If emitted is a gluon, remove the repeated index, and take
5493  // the remaining indices as colour and anticolour
5494  int colRemove = (event[rad].acol() == event[emt].col())
5495  ? event[rad].acol() : 0;
5496  radBeforeAcl = (event[rad].acol() == colRemove)
5497  ? event[emt].acol() : event[rad].acol();
5498  //Antiquark emissions in ISR
5499  } else if (type == -1 && event[emt].id() != 21) {
5500  // If emitted is an antiquark, remove the repeated index, and take
5501  // the remaining indices as colour and anticolour
5502  int colRemove = (event[rad].acol() == event[emt].acol())
5503  ? event[rad].acol() : 0;
5504  radBeforeAcl = (event[rad].acol() == colRemove)
5505  ? event[emt].col() : event[rad].acol();
5506  //Gluon emissions in ISR
5507  } else if (type == -1 && event[emt].id() == 21) {
5508  // If emitted is a gluon, remove the repeated index, and take
5509  // the remaining indices as colour and anticolour
5510  int colRemove = (event[rad].acol() == event[emt].acol())
5511  ? event[rad].acol() : 0;
5512  radBeforeAcl = (event[rad].acol() == colRemove)
5513  ? event[emt].col() : event[rad].acol();
5514  }
5515  // Other particles are considered uncoloured
5516  } else {
5517  radBeforeAcl = 0;
5518  }
5519 
5520  return radBeforeAcl;
5521 
5522 }
5523 
5524 //--------------------------------------------------------------------------
5525 
5526  // Function to get the parton connected to in by a colour line
5527  // IN int : Position of parton for which partner should be found
5528  // Event : Reference event
5529  // OUT int : If a colour line connects the "in" parton with another
5530  // parton, return the Position of the partner, else return 0
5531 
5532 int History::getColPartner(const int in, const Event& event) {
5533 
5534  if (event[in].col() == 0) return 0;
5535 
5536  int partner = 0;
5537  // Try to find anticolour index first
5538  partner = FindCol(event[in].col(),in,0,event,1,true);
5539  // If no anticolour index has been found, try colour
5540  if (partner == 0)
5541  partner = FindCol(event[in].col(),in,0,event,2,true);
5542 
5543  return partner;
5544 
5545 }
5546 
5547 //--------------------------------------------------------------------------
5548 
5549 
5550  // Function to get the parton connected to in by an anticolour line
5551  // IN int : Position of parton for which partner should be found
5552  // Event : Reference event
5553  // OUT int : If an anticolour line connects the "in" parton with another
5554  // parton, return the Position of the partner, else return 0
5555 
5556 int History::getAcolPartner(const int in, const Event& event) {
5557 
5558  if (event[in].acol() == 0) return 0;
5559 
5560  int partner = 0;
5561  // Try to find colour index first
5562  partner = FindCol(event[in].acol(),in,0,event,2,true);
5563  // If no colour index has been found, try anticolour
5564  if (partner == 0)
5565  partner = FindCol(event[in].acol(),in,0,event,1,true);
5566 
5567  return partner;
5568 
5569 }
5570 
5571 //--------------------------------------------------------------------------
5572 
5573 // Function to get the list of partons connected to the particle
5574 // formed by reclusterinf emt and rad by colour and anticolour lines
5575 // IN int : Position of radiator in the clustering
5576 // IN int : Position of emitted in the clustering
5577 // Event : Reference event
5578 // OUT vector<int> : List of positions of all partons that are connected
5579 // to the parton that will be formed
5580 // by clustering emt and rad.
5581 
5582 vector<int> History::getReclusteredPartners(const int rad, const int emt,
5583  const Event& event) {
5584 
5585  // Save type
5586  int type = event[rad].isFinal() ? 1 : -1;
5587  // Get reclustered colours
5588  int radBeforeCol = getRadBeforeCol(rad, emt, event);
5589  int radBeforeAcl = getRadBeforeAcol(rad, emt, event);
5590  // Declare output
5591  vector<int> partners;
5592 
5593 
5594  // Start with FSR clusterings
5595  if (type == 1) {
5596 
5597  for(int i=0; i < int(event.size()); ++i) {
5598  // Check all initial state partons
5599  if ( i != emt && i != rad
5600  && event[i].status() == -21
5601  && event[i].col() > 0
5602  && event[i].col() == radBeforeCol)
5603  partners.push_back(i);
5604  // Check all final state partons
5605  if ( i != emt && i != rad
5606  && event[i].isFinal()
5607  && event[i].acol() > 0
5608  && event[i].acol() == radBeforeCol)
5609  partners.push_back(i);
5610  // Check all initial state partons
5611  if ( i != emt && i != rad
5612  && event[i].status() == -21
5613  && event[i].acol() > 0
5614  && event[i].acol() == radBeforeAcl)
5615  partners.push_back(i);
5616  // Check all final state partons
5617  if ( i != emt && i != rad
5618  && event[i].isFinal()
5619  && event[i].col() > 0
5620  && event[i].col() == radBeforeAcl)
5621  partners.push_back(i);
5622  }
5623  // Start with ISR clusterings
5624  } else {
5625 
5626  for(int i=0; i < int(event.size()); ++i) {
5627  // Check all initial state partons
5628  if ( i != emt && i != rad
5629  && event[i].status() == -21
5630  && event[i].acol() > 0
5631  && event[i].acol() == radBeforeCol)
5632  partners.push_back(i);
5633  // Check all final state partons
5634  if ( i != emt && i != rad
5635  && event[i].isFinal()
5636  && event[i].col() > 0
5637  && event[i].col() == radBeforeCol)
5638  partners.push_back(i);
5639  // Check all initial state partons
5640  if ( i != emt && i != rad
5641  && event[i].status() == -21
5642  && event[i].col() > 0
5643  && event[i].col() == radBeforeAcl)
5644  partners.push_back(i);
5645  // Check all final state partons
5646  if ( i != emt && i != rad
5647  && event[i].isFinal()
5648  && event[i].acol() > 0
5649  && event[i].acol() == radBeforeAcl)
5650  partners.push_back(i);
5651  }
5652 
5653  }
5654  // Done
5655  return partners;
5656 }
5657 
5658 //--------------------------------------------------------------------------
5659 
5660 // Function to extract a chain of colour-connected partons in
5661 // the event
5662 // IN int : Type of parton from which to start extracting a
5663 // parton chain. If the starting point is a quark
5664 // i.e. flavType = 1, a chain of partons that are
5665 // consecutively connected by colour-lines will be
5666 // extracted. If the starting point is an antiquark
5667 // i.e. flavType =-1, a chain of partons that are
5668 // consecutively connected by anticolour-lines
5669 // will be extracted.
5670 // IN int : Position of the parton from which a
5671 // colour-connected chain should be derived
5672 // IN Event : Refernence event
5673 // IN/OUT vector<int> : Partons that should be excluded from the search.
5674 // OUT vector<int> : Positions of partons along the chain
5675 // OUT bool : Found singlet / did not find singlet
5676 
5677 bool History::getColSinglet( const int flavType, const int iParton,
5678  const Event& event, vector<int>& exclude, vector<int>& colSinglet) {
5679 
5680  // If no possible flavour to start from has been found
5681  if (iParton < 0) return false;
5682 
5683  // If no further partner has been found in a previous iteration,
5684  // and the whole final state has been excluded, we're done
5685  if (iParton == 0) {
5686 
5687  // Count number of final state partons
5688  int nFinal = 0;
5689  for(int i=0; i < int(event.size()); ++i)
5690  if ( event[i].isFinal() && event[i].colType() != 0)
5691  nFinal++;
5692 
5693  // Get number of initial state partons in the list of
5694  // excluded partons
5695  int nExclude = int(exclude.size());
5696  int nInitExclude = 0;
5697  if (!event[exclude[2]].isFinal())
5698  nInitExclude++;
5699  if (!event[exclude[3]].isFinal())
5700  nInitExclude++;
5701 
5702  // If the whole final state has been considered, return
5703  if (nFinal == nExclude - nInitExclude)
5704  return true;
5705  else
5706  return false;
5707 
5708  }
5709 
5710  // Declare colour partner
5711  int colP = 0;
5712  // Save the colour partner
5713  colSinglet.push_back(iParton);
5714  // Remove the partner from the list
5715  exclude.push_back(iParton);
5716  // When starting out from a quark line, follow the colour lines
5717  if (flavType == 1)
5718  colP = getColPartner(iParton,event);
5719  // When starting out from an antiquark line, follow the anticolour lines
5720  else
5721  colP = getAcolPartner(iParton,event);
5722 
5723  // Do not count excluded partons twice
5724  for(int i = 0; i < int(exclude.size()); ++i)
5725  if (colP == exclude[i])
5726  return true;
5727 
5728  // Recurse
5729  return getColSinglet(flavType,colP,event,exclude,colSinglet);
5730 
5731 }
5732 
5733 //--------------------------------------------------------------------------
5734 
5735 // Function to check that a set of partons forms a colour singlet
5736 // IN Event : Reference event
5737 // IN vector<int> : Positions of the partons in the set
5738 // OUT bool : Is a colour singlet / is not
5739 
5740 bool History::isColSinglet( const Event& event,
5741  vector<int> system ) {
5742 
5743  // Check if system forms a colour singlet
5744  for(int i=0; i < int(system.size()); ++i ) {
5745  // Match quark and gluon colours
5746  if ( system[i] > 0
5747  && (event[system[i]].colType() == 1
5748  || event[system[i]].colType() == 2) ) {
5749  for(int j=0; j < int(system.size()); ++j)
5750  // If flavour matches, remove both partons and continue
5751  if ( system[i] > 0
5752  && system[j] > 0
5753  && event[system[i]].col() == event[system[j]].acol()) {
5754  // Remove index and break
5755  system[i] = 0;
5756  system[j] = 0;
5757  break;
5758  }
5759  }
5760  // Match antiquark and gluon anticolours
5761  if ( system[i] > 0
5762  && (event[system[i]].colType() == -1
5763  || event[system[i]].colType() == 2) ) {
5764  for(int j=0; j < int(system.size()); ++j)
5765  // If flavour matches, remove both partons and continue
5766  if ( system[i] > 0
5767  && system[j] > 0
5768  && event[system[i]].acol() == event[system[j]].col()) {
5769  // Remove index and break
5770  system[i] = 0;
5771  system[j] = 0;
5772  break;
5773  }
5774  }
5775 
5776  }
5777 
5778  // The system is a colour singlet if for all colours,
5779  // an anticolour was found
5780  bool isColSing = true;
5781  for(int i=0; i < int(system.size()); ++i)
5782  if ( system[i] != 0 )
5783  isColSing = false;
5784 
5785  // Return
5786  return isColSing;
5787 
5788 
5789 }
5790 
5791 //--------------------------------------------------------------------------
5792 
5793 // Function to check that a set of partons forms a flavour singlet
5794 // IN Event : Reference event
5795 // IN vector<int> : Positions of the partons in the set
5796 // IN int : Flavour of all the quarks in the set, if
5797 // all quarks in a set should have a fixed flavour
5798 // OUT bool : Is a flavour singlet / is not
5799 
5800 bool History::isFlavSinglet( const Event& event,
5801  vector<int> system, int flav) {
5802 
5803  // If a decoupled colour singlet has been found, check if this is also
5804  // a flavour singlet
5805  // Check that each quark matches an antiquark
5806  for(int i=0; i < int(system.size()); ++i)
5807  if ( system[i] > 0 ) {
5808  for(int j=0; j < int(system.size()); ++j) {
5809  // If flavour of outgoing partons matches,
5810  // remove both partons and continue.
5811  // Skip all bosons
5812  if ( event[i].idAbs() != 21
5813  && event[i].idAbs() != 22
5814  && event[i].idAbs() != 23
5815  && event[i].idAbs() != 24
5816  && system[i] > 0
5817  && system[j] > 0
5818  && event[system[i]].isFinal()
5819  && event[system[j]].isFinal()
5820  && event[system[i]].id() == -1*event[system[j]].id()) {
5821  // If we want to check if only one flavour of quarks
5822  // exists
5823  if (abs(flav) > 0 && event[system[i]].idAbs() != flav)
5824  return false;
5825  // Remove index and break
5826  system[i] = 0;
5827  system[j] = 0;
5828  break;
5829  }
5830  // If flavour of outgoing and incoming partons match,
5831  // remove both partons and continue.
5832  // Skip all bosons
5833  if ( event[i].idAbs() != 21
5834  && event[i].idAbs() != 22
5835  && event[i].idAbs() != 23
5836  && event[i].idAbs() != 24
5837  && system[i] > 0
5838  && system[j] > 0
5839  && ( ( !event[system[i]].isFinal() && event[system[j]].isFinal())
5840  ||( !event[system[j]].isFinal() && event[system[i]].isFinal()) )
5841  && event[system[i]].id() == event[system[j]].id()) {
5842  // If we want to check if only one flavour of quarks
5843  // exists
5844  if (abs(flav) > 0 && event[system[i]].idAbs() != flav)
5845  return false;
5846  // Remove index and break
5847  system[i] = 0;
5848  system[j] = 0;
5849  break;
5850  }
5851 
5852  }
5853  }
5854 
5855  // The colour singlet is a flavour singlet if for all quarks,
5856  // an antiquark was found
5857  bool isFlavSing = true;
5858  for(int i=0; i < int(system.size()); ++i)
5859  if ( system[i] != 0 )
5860  isFlavSing = false;
5861 
5862  // Return
5863  return isFlavSing;
5864 
5865 }
5866 
5867 //--------------------------------------------------------------------------
5868 
5869 // Function to check if rad,emt,rec triple is allowed for clustering
5870 // IN int rad,emt,rec : Positions (in event record) of the three
5871 // particles considered for clustering
5872 // Event event : Reference event
5873 
5874 bool History::allowedClustering( int rad, int emt, int rec, int partner,
5875  const Event& event ) {
5876 
5877  // Declare output
5878  bool allowed = true;
5879 
5880  // CONSTRUCT SOME PROPERTIES FOR LATER INVESTIGATION
5881 
5882  // Check if the triple forms a colour singlett
5883  bool isSing = isSinglett(rad,emt,partner,event);
5884  int type = (event[rad].isFinal()) ? 1 :-1;
5885  // Get flavour of radiator after potential clustering
5886  int radBeforeFlav = getRadBeforeFlav(rad,emt,event);
5887  // Get colours of the radiator before the potential clustering
5888  int radBeforeCol = getRadBeforeCol(rad,emt,event);
5889  int radBeforeAcl = getRadBeforeAcol(rad,emt,event);
5890  // Get colour partner of reclustered parton
5891  vector<int> radBeforeColP = getReclusteredPartners(rad, emt, event);
5892 
5893  // Count coloured partons in hard process
5894  int nPartonInHard = 0;
5895  for(int i=0; i < int(event.size()); ++i)
5896  // Check all final state partons
5897  if ( event[i].isFinal()
5898  && event[i].colType() != 0
5899  && mergingHooksPtr->hardProcess.matchesAnyOutgoing(i, event) )
5900  nPartonInHard++;
5901 
5902  // Count coloured final state partons in event, excluding
5903  // rad, rec, emt and hard process
5904  int nPartons = 0;
5905  for(int i=0; i < int(event.size()); ++i)
5906  // Check all final state partons
5907  if ( i!=emt && i!=rad && i!=rec
5908  && event[i].isFinal()
5909  && event[i].colType() != 0
5910  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i, event) )
5911  nPartons++;
5912 
5913  // Count number of initial state partons
5914  int nInitialPartons = 0;
5915  for(int i=0; i < int(event.size()); ++i)
5916  if ( event[i].status() == -21
5917  && event[i].colType() != 0 )
5918  nInitialPartons++;
5919 
5920  // Get number of non-charged final state particles
5921  int nFinalEW = 0;
5922  for(int i=0; i < int(event.size()); ++i)
5923  if ( event[i].isFinal()
5924  &&( event[i].id() == 22
5925  || event[i].id() == 23
5926  || event[i].id() == 24
5927  ||(event[i].idAbs() > 10 && event[i].idAbs() < 20)
5928  ||(event[i].idAbs() > 10 && event[i].idAbs() < 20)
5929  ||(event[i].idAbs() > 1000010 && event[i].idAbs() < 1000020)
5930  ||(event[i].idAbs() > 2000010 && event[i].idAbs() < 2000020) ))
5931  nFinalEW++;
5932 
5933  // Check if event after potential clustering contains an even
5934  // number of quarks and/or antiquarks
5935  // (otherwise no electroweak vertex could be formed!)
5936  // Get number of final quarks
5937  int nFinalQuark = 0;
5938  // Get number of excluded final state quarks as well
5939  int nFinalQuarkExc = 0;
5940  for(int i=0; i < int(event.size()); ++i) {
5941  if (i !=rad && i != emt && i != rec) {
5942  if (event[i].isFinal() && abs(event[i].colType()) == 1 ) {
5943  if ( !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,event) )
5944  nFinalQuark++;
5945  else
5946  nFinalQuarkExc++;
5947  }
5948  }
5949  }
5950 
5951  // Add recoiler to number of final quarks
5952  if (event[rec].isFinal() && event[rec].isQuark()) nFinalQuark++;
5953  // Add radiator after clustering to number of final quarks
5954  if (event[rad].isFinal() && abs(radBeforeFlav) < 10) nFinalQuark++;
5955 
5956  // Get number of initial quarks
5957  int nInitialQuark = 0;
5958  if (type == 1) {
5959  if (event[rec].isFinal()) {
5960  if (event[3].isQuark()) nInitialQuark++;
5961  if (event[4].isQuark()) nInitialQuark++;
5962  } else {
5963  int iOtherIn = (rec == 3) ? 4 : 3;
5964  if (event[rec].isQuark()) nInitialQuark++;
5965  if (event[iOtherIn].isQuark()) nInitialQuark++;
5966  }
5967  } else {
5968  // Add recoiler to number of initial quarks
5969  if (event[rec].isQuark()) nInitialQuark++;
5970  // Add radiator after clustering to number of initial quarks
5971  if (abs(radBeforeFlav) < 10) nInitialQuark++;
5972  }
5973 
5974  // BEGIN CHECKING THE CLUSTERING
5975 
5976  // Do not allow clusterings that lead to a disallowed proton content.
5977  int proton[] = {1,2,3,4,5,21,22,23,24};
5978  bool isInProton = false;
5979  for(int i=0; i < 9; ++i)
5980  if (abs(radBeforeFlav) == proton[i]) isInProton = true;
5981  if (type == -1 && !isInProton) return false;
5982 
5983  // Check if colour is conserved
5984  vector<int> unmatchedCol;
5985  vector<int> unmatchedAcl;
5986  // Check all unmatched colours
5987  for ( int i = 0; i < event.size(); ++i)
5988  if ( i != emt && i != rad
5989  && (event[i].isFinal() || event[i].status() == -21)
5990  && event[i].colType() != 0 ) {
5991 
5992  int colP = getColPartner(i,event);
5993  int aclP = getAcolPartner(i,event);
5994 
5995  if (event[i].col() > 0
5996  && (colP == emt || colP == rad || colP == 0) )
5997  unmatchedCol.push_back(i);
5998  if (event[i].acol() > 0
5999  && (aclP == emt || aclP == rad || aclP == 0) )
6000  unmatchedAcl.push_back(i);
6001 
6002  }
6003 
6004  // If more than one colour or more than one anticolour are unmatched,
6005  // there is no way to make this clustering work
6006  if (int(unmatchedCol.size()) + int(unmatchedAcl.size()) > 2)
6007  return false;
6008 
6009  // If triple forms colour singlett, check that resulting state
6010  // matches hard core process
6011  if (isSing)
6012  allowed = false;
6013  if (isSing && (abs(radBeforeFlav)<10 && event[rec].isQuark()) )
6014  allowed = true;
6015 
6016  // Never recluster any outgoing partons of the core V -> qqbar' splitting!
6017  if ( mergingHooksPtr->hardProcess.matchesAnyOutgoing(emt,event) ) {
6018  // Check if any other particle could replace "emt" as part of the candidate
6019  // core process. If so, replace emt with the new candidate and allow the
6020  // clustering.
6021  bool canReplace = mergingHooksPtr->hardProcess.findOtherCandidates(emt,
6022  event, true);
6023  if (canReplace) allowed = true;
6024  else allowed = false;
6025  }
6026 
6027  // Never allow clustering of any outgoing partons of the hard process
6028  // which would change the flavour of one of the hard process partons!
6029  if ( mergingHooksPtr->hardProcess.matchesAnyOutgoing(rad,event)
6030  && event[rad].id() != radBeforeFlav )
6031  allowed = false;
6032 
6033  // If only gluons in initial state and no quarks in final state,
6034  // reject (no electroweak vertex can be formed)
6035  if (nFinalEW != 0 && nInitialQuark == 0
6036  && nFinalQuark == 0 && nFinalQuarkExc == 0)
6037  allowed = false;
6038 
6039  if ( (nInitialQuark + nFinalQuark + nFinalQuarkExc)%2 != 0 )
6040  allowed = false;
6041 
6042  // Disallow final state splittings that lead to a purely gluonic final
6043  // state, while having a completely colour-connected initial state.
6044  // This means that the clustering is discarded if it does not lead to the
6045  // t-channel gluon needed to connect the final state to a qq~ initial state.
6046  // Here, partons excluded from clustering are not counted as possible
6047  // partners to form a t-channel gluon
6048  if (event[3].col() == event[4].acol()
6049  && event[3].acol() == event[4].col()
6050  && nFinalQuark == 0){
6051  // Careful if rad and rec are the only quarks in the final state, but
6052  // were both excluded from the list of final state quarks.
6053  int nTripletts = abs(event[rec].colType())
6054  + abs(particleDataPtr->colType(radBeforeFlav));
6055  if (event[3].isGluon()) allowed = false;
6056  else if (nTripletts != 2 && nFinalQuarkExc%2 == 0) allowed = false;
6057  }
6058 
6059  // No problems with gluon radiation
6060  if (event[emt].id() == 21)
6061  return allowed;
6062 
6063  // No problems with gluino radiation
6064  if (event[emt].id() == 1000021)
6065  return allowed;
6066 
6067  // Save all hard process candidates
6068  vector<int> outgoingParticles;
6069  int nOut1 = int(mergingHooksPtr->hardProcess.PosOutgoing1.size());
6070  for ( int i=0; i < nOut1; ++i ) {
6071  int iPos = mergingHooksPtr->hardProcess.PosOutgoing1[i];
6072  outgoingParticles.push_back(
6073  mergingHooksPtr->hardProcess.state[iPos].id() );
6074  }
6075  int nOut2 = int(mergingHooksPtr->hardProcess.PosOutgoing2.size());
6076  for ( int i=0; i < nOut2; ++i ) {
6077  int iPos = mergingHooksPtr->hardProcess.PosOutgoing2[i];
6078  outgoingParticles.push_back(
6079  mergingHooksPtr->hardProcess.state[iPos].id() );
6080  }
6081 
6082  // Start more involved checks. g -> q_1 qbar_1 splittings are
6083  // particularly problematic if more than one quark of the emitted
6084  // flavour is present.
6085  // Count number of initial quarks of radiator or emitted flavour
6086  vector<int> iInQuarkFlav;
6087  for(int i=0; i < int(event.size()); ++i)
6088  // Check all initial state partons
6089  if ( i != emt && i != rad
6090  && event[i].status() == -21
6091  && event[i].idAbs() == event[emt].idAbs() )
6092  iInQuarkFlav.push_back(i);
6093 
6094  // Count number of final quarks of radiator or emitted flavour
6095  vector<int> iOutQuarkFlav;
6096  for(int i=0; i < int(event.size()); ++i)
6097  // Check all final state partons
6098  if ( i != emt && i != rad
6099  && event[i].isFinal()
6100  && event[i].idAbs() == event[emt].idAbs() ) {
6101 
6102  // Loop through final state hard particles. If one matches, remove the
6103  // matching one, and do not count.
6104  bool matchOut = false;
6105  for (int j = 0; j < int(outgoingParticles.size()); ++j)
6106  if ( event[i].idAbs() == abs(outgoingParticles[j])) {
6107  matchOut = true;
6108  outgoingParticles[j] = 99;
6109  }
6110  if (!matchOut) iOutQuarkFlav.push_back(i);
6111 
6112  }
6113 
6114  // Save number of potentially dangerous quarks
6115  int nInQuarkFlav = int(iInQuarkFlav.size());
6116  int nOutQuarkFlav = int(iOutQuarkFlav.size());
6117 
6118  // Easiest problem 0:
6119  // Radiator before splitting exactly matches the partner
6120  // after the splitting
6121  if ( event[partner].isFinal()
6122  && event[partner].id() == 21
6123  && radBeforeFlav == 21
6124  && event[partner].col() == radBeforeCol
6125  && event[partner].acol() == radBeforeAcl)
6126  return false;
6127 
6128  // If there are no ambiguities in qqbar pairs, return
6129  if (nInQuarkFlav + nOutQuarkFlav == 0)
6130  return allowed;
6131 
6132  // Save all quarks and gluons that will not change colour
6133  vector<int> gluon;
6134  vector<int> quark;
6135  vector<int> antiq;
6136  vector<int> partons;
6137  for(int i=0; i < int(event.size()); ++i)
6138  // Check initial and final state partons
6139  if ( i!=emt && i!=rad
6140  && event[i].colType() != 0
6141  && (event[i].isFinal() || event[i].status() == -21) ) {
6142  // Save index
6143  partons.push_back(i);
6144  // Split into components
6145  if (event[i].colType() == 2)
6146  gluon.push_back(i);
6147  else if (event[i].colType() == 1)
6148  quark.push_back(i);
6149  else if (event[i].colType() == -1)
6150  antiq.push_back(i);
6151  }
6152 
6153  // We split up the test of the g->qq splitting into final state
6154  // and initial state problems
6155  bool isFSRg2qq = ((type == 1) && (event[rad].id() == -1*event[emt].id()) );
6156  bool isISRg2qq = ((type ==-1) && (event[rad].id() == event[emt].id()) );
6157 
6158  // First check general things about colour connections
6159  // Check that clustering does not produce a gluon that is exactly
6160  // matched in the final state, or does not have any colour connections
6161  if ( (isFSRg2qq || isISRg2qq)
6162  && int(quark.size()) + int(antiq.size())
6163  + int(gluon.size()) > nPartonInHard ) {
6164 
6165  vector<int> colours;
6166  vector<int> anticolours;
6167  // Add the colour and anticolour of the gluon before the emission
6168  // to the list, bookkeep initial colour as final anticolour, and
6169  // initial anticolour as final colour
6170  if (type == 1) {
6171  colours.push_back(radBeforeCol);
6172  anticolours.push_back(radBeforeAcl);
6173  } else {
6174  colours.push_back(radBeforeAcl);
6175  anticolours.push_back(radBeforeCol);
6176  }
6177  // Now store gluon colours and anticolours.
6178  for(int i=0; i < int(gluon.size()); ++i)
6179  if (event[gluon[i]].isFinal()) {
6180  colours.push_back(event[gluon[i]].col());
6181  anticolours.push_back(event[gluon[i]].acol());
6182  } else {
6183  colours.push_back(event[gluon[i]].acol());
6184  anticolours.push_back(event[gluon[i]].col());
6185  }
6186 
6187  // Loop through colours and check if any match with
6188  // anticolours. If colour matches, remove from list
6189  for(int i=0; i < int(colours.size()); ++i)
6190  for(int j=0; j < int(anticolours.size()); ++j)
6191  if (colours[i] > 0 && anticolours[j] > 0
6192  && colours[i] == anticolours[j]) {
6193  colours[i] = 0;
6194  anticolours[j] = 0;
6195  }
6196 
6197 
6198  // If all gluon anticolours and all colours matched, disallow
6199  // the clustering
6200  bool allMatched = true;
6201  for(int i=0; i < int(colours.size()); ++i)
6202  if (colours[i] != 0)
6203  allMatched = false;
6204  for(int i=0; i < int(anticolours.size()); ++i)
6205  if (anticolours[i] != 0)
6206  allMatched = false;
6207 
6208  if (allMatched)
6209  return false;
6210 
6211  // Now add the colours of the hard process, and check if all
6212  // colours match.
6213  for(int i=0; i < int(quark.size()); ++i)
6214  if ( event[quark[i]].isFinal()
6215  && mergingHooksPtr->hardProcess.matchesAnyOutgoing(quark[i], event) )
6216  colours.push_back(event[quark[i]].col());
6217 
6218  for(int i=0; i < int(antiq.size()); ++i)
6219  if ( event[antiq[i]].isFinal()
6220  && mergingHooksPtr->hardProcess.matchesAnyOutgoing(antiq[i], event) )
6221  anticolours.push_back(event[antiq[i]].acol());
6222 
6223  // Loop through colours again and check if any match with
6224  // anticolours. If colour matches, remove from list
6225  for(int i=0; i < int(colours.size()); ++i)
6226 
6227  for(int j=0; j < int(anticolours.size()); ++j)
6228  if (colours[i] > 0 && anticolours[j] > 0
6229  && colours[i] == anticolours[j]) {
6230  colours[i] = 0;
6231  anticolours[j] = 0;
6232  }
6233 
6234  // Check if clustering would produce the hard process
6235  int nNotInHard = 0;
6236  for ( int i=0; i < int(quark.size()); ++i )
6237  if ( !mergingHooksPtr->hardProcess.matchesAnyOutgoing( quark[i],
6238  event) )
6239  nNotInHard++;
6240  for ( int i=0; i < int(antiq.size()); ++i )
6241  if ( !mergingHooksPtr->hardProcess.matchesAnyOutgoing( antiq[i],
6242  event) )
6243  nNotInHard++;
6244  for(int i=0; i < int(gluon.size()); ++i)
6245  if ( event[gluon[i]].isFinal() )
6246  nNotInHard++;
6247  if ( type == 1 )
6248  nNotInHard++;
6249 
6250  // If all colours are matched now, and since we have more quarks than
6251  // present in the hard process, disallow the clustering
6252  allMatched = true;
6253  for(int i=0; i < int(colours.size()); ++i)
6254  if (colours[i] != 0)
6255  allMatched = false;
6256  for(int i=0; i < int(anticolours.size()); ++i)
6257  if (anticolours[i] != 0)
6258  allMatched = false;
6259 
6260  if (allMatched && nNotInHard > 0)
6261  return false;
6262 
6263  }
6264 
6265  // FSR PROBLEMS
6266 
6267  if (isFSRg2qq && nInQuarkFlav + nOutQuarkFlav > 0) {
6268 
6269  // Easiest problem 1:
6270  // RECLUSTERED FINAL STATE GLUON MATCHES INITIAL STATE GLUON
6271  for(int i=0; i < int(gluon.size()); ++i) {
6272  if (!event[gluon[i]].isFinal()
6273  && event[gluon[i]].col() == radBeforeCol
6274  && event[gluon[i]].acol() == radBeforeAcl)
6275  return false;
6276  }
6277 
6278  // Easiest problem 2:
6279  // RECLUSTERED FINAL STATE GLUON MATCHES FINAL STATE GLUON
6280  for(int i=0; i < int(gluon.size()); ++i) {
6281  if (event[gluon[i]].isFinal()
6282  && event[gluon[i]].col() == radBeforeAcl
6283  && event[gluon[i]].acol() == radBeforeCol)
6284  return false;
6285  }
6286 
6287  // Easiest problem 3:
6288  // RECLUSTERED FINAL STATE GLUON MATCHES FINAL STATE Q-QBAR PAIR
6289  if ( int(radBeforeColP.size()) == 2
6290  && event[radBeforeColP[0]].isFinal()
6291  && event[radBeforeColP[1]].isFinal()
6292  && event[radBeforeColP[0]].id() == -1*event[radBeforeColP[1]].id() ) {
6293 
6294  // This clustering is allowed if there is no colour in the
6295  // initial state
6296  if (nInitialPartons > 0)
6297  return false;
6298  }
6299 
6300  // Next-to-easiest problem 1:
6301  // RECLUSTERED FINAL STATE GLUON MATCHES ONE FINAL STARE Q_1
6302  // AND ONE INITIAL STATE Q_1
6303  if ( int(radBeforeColP.size()) == 2
6304  && (( event[radBeforeColP[0]].status() == -21
6305  && event[radBeforeColP[1]].isFinal())
6306  ||( event[radBeforeColP[0]].isFinal()
6307  && event[radBeforeColP[1]].status() == -21))
6308  && event[radBeforeColP[0]].id() == event[radBeforeColP[1]].id() ) {
6309 
6310  // In principle, clustering this splitting can disconnect
6311  // the colour lines of a graph. However, the colours can be connected
6312  // again if a final or initial partons of the correct flavour exists.
6313 
6314  // Check which of the partners are final / initial
6315  int incoming = (event[radBeforeColP[0]].isFinal())
6316  ? radBeforeColP[1] : radBeforeColP[0];
6317  int outgoing = (event[radBeforeColP[0]].isFinal())
6318  ? radBeforeColP[0] : radBeforeColP[1];
6319 
6320  // Loop through event to find "recovery partons"
6321  bool clusPossible = false;
6322  for(int i=0; i < int(event.size()); ++i)
6323  if ( i != emt && i != rad
6324  && i != incoming && i != outgoing
6325  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,event) ) {
6326  // Check if an incoming parton matches
6327  if ( event[i].status() == -21
6328  && (event[i].id() == event[outgoing].id()
6329  ||event[i].id() == -1*event[incoming].id()) )
6330  clusPossible = true;
6331  // Check if a final parton matches
6332  if ( event[i].isFinal()
6333  && (event[i].id() == -1*event[outgoing].id()
6334  ||event[i].id() == event[incoming].id()) )
6335  clusPossible = true;
6336  }
6337 
6338  // There can be a further complication: If e.g. in
6339  // t-channel photon exchange topologies, both incoming
6340  // partons are quarks, and form colour singlets with any
6341  // number of final state partons, at least try to
6342  // recluster as much as possible.
6343  // For this, check if the incoming parton
6344  // connected to the radiator is connected to a
6345  // colour and flavour singlet
6346  vector<int> excludeIn1;
6347  for(int i=0; i < 4; ++i)
6348  excludeIn1.push_back(0);
6349  vector<int> colSingletIn1;
6350  int flavIn1Type = (event[incoming].id() > 0) ? 1 : -1;
6351  // Try finding colour singlets
6352  bool isColSingIn1 = getColSinglet(flavIn1Type,incoming,event,
6353  excludeIn1,colSingletIn1);
6354  // Check if colour singlet also is a flavour singlet
6355  bool isFlavSingIn1 = isFlavSinglet(event,colSingletIn1);
6356 
6357  // Check if the incoming parton not
6358  // connected to the radiator is connected to a
6359  // colour and flavour singlet
6360  int incoming2 = (incoming == 3) ? 4 : 3;
6361  vector<int> excludeIn2;
6362  for(int i=0; i < 4; ++i)
6363  excludeIn2.push_back(0);
6364  vector<int> colSingletIn2;
6365  int flavIn2Type = (event[incoming2].id() > 0) ? 1 : -1;
6366  // Try finding colour singlets
6367  bool isColSingIn2 = getColSinglet(flavIn2Type,incoming2,event,
6368  excludeIn2,colSingletIn2);
6369  // Check if colour singlet also is a flavour singlet
6370  bool isFlavSingIn2 = isFlavSinglet(event,colSingletIn2);
6371 
6372  // If no "recovery clustering" is possible, reject clustering
6373  if (!clusPossible
6374  && (!isColSingIn1 || !isFlavSingIn1
6375  || !isColSingIn2 || !isFlavSingIn2))
6376  return false;
6377 
6378  }
6379 
6380  // Next-to-easiest problem 2:
6381  // FINAL STATE Q-QBAR CLUSTERING DISCONNECTS SINGLETT SUBSYSTEM WITH
6382  // FINAL STATE Q-QBAR PAIR FROM GRAPH
6383 
6384  // Prepare to check for colour singlet combinations of final state quarks
6385  // Start by building a list of partons to exclude when checking for
6386  // colour singlet combinations
6387  int flav = event[emt].id();
6388  vector<int> exclude;
6389  exclude.push_back(emt);
6390  exclude.push_back(rad);
6391  exclude.push_back(radBeforeColP[0]);
6392  exclude.push_back(radBeforeColP[1]);
6393  vector<int> colSinglet;
6394  // Now find parton from which to start checking colour singlets
6395  int iOther = -1;
6396  // Loop through event to find a parton of correct flavour
6397  for(int i=0; i < int(event.size()); ++i)
6398  // Check final state for parton equalling emitted flavour.
6399  // Exclude the colour system coupled to the clustering
6400  if ( i != emt
6401  && i != rad
6402  && i != radBeforeColP[0]
6403  && i != radBeforeColP[1]
6404  && event[i].isFinal() ) {
6405  // Stop if one parton of the correct flavour is found
6406  if (event[i].id() == flav) {
6407  iOther = i;
6408  break;
6409  }
6410  }
6411  // Save the type of flavour
6412  int flavType = (event[iOther].id() > 0) ? 1 : -1;
6413  // Try finding colour singlets
6414  bool isColSing = getColSinglet(flavType,iOther,event,exclude,colSinglet);
6415  // Check if colour singlet also is a flavour singlet
6416  bool isFlavSing = isFlavSinglet(event,colSinglet);
6417 
6418  // Check if the colour singlet is precisely contained in the hard process.
6419  // If so, then we're safe to recluster.
6420  bool isHardSys = true;
6421  for(int i=0; i < int(colSinglet.size()); ++i)
6422  isHardSys =
6423  mergingHooksPtr->hardProcess.matchesAnyOutgoing(colSinglet[i], event);
6424 
6425  // Nearly there...
6426  // If the decoupled colour singlet system is NOT contained in the hard
6427  // process, we need to check the whole final state.
6428  if (isColSing && isFlavSing && !isHardSys) {
6429 
6430  // In a final check, ensure that the final state does not only
6431  // consist of colour singlets that are also flavour singlets
6432  // of the identical (!) flavours
6433  // Loop through event and save all final state partons
6434  vector<int> allFinal;
6435  for(int i=0; i < int(event.size()); ++i)
6436  if ( event[i].isFinal() )
6437  allFinal.push_back(i);
6438 
6439  // Check if all final partons form a colour singlet
6440  bool isFullColSing = isColSinglet(event,allFinal);
6441  // Check if all final partons form a flavour singlet
6442  bool isFullFlavSing = isFlavSinglet(event,allFinal,flav);
6443 
6444  // If all final quarks are of identical flavour,
6445  // no possible clustering should be discriminated.
6446  // Otherwise, disallow
6447  if (!isFullColSing || !isFullFlavSing)
6448  return false;
6449  }
6450  }
6451 
6452  // ISR PROBLEMS
6453 
6454  if (isISRg2qq && nInQuarkFlav + nOutQuarkFlav > 0) {
6455 
6456  // Easiest problem 1:
6457  // RECLUSTERED INITIAL STATE GLUON MATCHES FINAL STATE GLUON
6458  for(int i=0; i < int(gluon.size()); ++i) {
6459  if (event[gluon[i]].isFinal()
6460  && event[gluon[i]].col() == radBeforeCol
6461  && event[gluon[i]].acol() == radBeforeAcl)
6462  return false;
6463  }
6464 
6465  // Easiest problem 2:
6466  // RECLUSTERED INITIAL STATE GLUON MATCHES INITIAL STATE GLUON
6467  for(int i=0; i < int(gluon.size()); ++i) {
6468  if (event[gluon[i]].status() == -21
6469  && event[gluon[i]].acol() == radBeforeCol
6470  && event[gluon[i]].col() == radBeforeAcl)
6471  return false;
6472  }
6473 
6474  // Next-to-easiest problem 1:
6475  // RECLUSTERED INITIAL STATE GLUON MATCHES FINAL STATE Q-QBAR PAIR
6476  if ( int(radBeforeColP.size()) == 2
6477  && event[radBeforeColP[0]].isFinal()
6478  && event[radBeforeColP[1]].isFinal()
6479  && event[radBeforeColP[0]].id() == -1*event[radBeforeColP[1]].id() ) {
6480 
6481  // In principle, clustering this splitting can disconnect
6482  // the colour lines of a graph. However, the colours can be connected
6483  // again if final state partons of the correct (anti)flavour, or
6484  // initial state partons of the correct flavour exist
6485  // Loop through event to check
6486  bool clusPossible = false;
6487  for(int i=0; i < int(event.size()); ++i)
6488  if ( i != emt && i != rad
6489  && i != radBeforeColP[0]
6490  && i != radBeforeColP[1]
6491  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,event) ) {
6492  if (event[i].status() == -21
6493  && ( event[radBeforeColP[0]].id() == event[i].id()
6494  || event[radBeforeColP[1]].id() == event[i].id() ))
6495 
6496  clusPossible = true;
6497  if (event[i].isFinal()
6498  && ( event[radBeforeColP[0]].id() == -1*event[i].id()
6499  || event[radBeforeColP[1]].id() == -1*event[i].id() ))
6500  clusPossible = true;
6501  }
6502 
6503  // There can be a further complication: If e.g. in
6504  // t-channel photon exchange topologies, both incoming
6505  // partons are quarks, and form colour singlets with any
6506  // number of final state partons, at least try to
6507  // recluster as much as possible.
6508  // For this, check if the incoming parton
6509  // connected to the radiator is connected to a
6510  // colour and flavour singlet
6511  int incoming1 = 3;
6512  vector<int> excludeIn1;
6513  for(int i=0; i < 4; ++i)
6514  excludeIn1.push_back(0);
6515  vector<int> colSingletIn1;
6516  int flavIn1Type = (event[incoming1].id() > 0) ? 1 : -1;
6517  // Try finding colour singlets
6518  bool isColSingIn1 = getColSinglet(flavIn1Type,incoming1,event,
6519  excludeIn1,colSingletIn1);
6520  // Check if colour singlet also is a flavour singlet
6521  bool isFlavSingIn1 = isFlavSinglet(event,colSingletIn1);
6522 
6523  // Check if the incoming parton not
6524  // connected to the radiator is connected to a
6525  // colour and flavour singlet
6526  int incoming2 = 4;
6527  vector<int> excludeIn2;
6528  for(int i=0; i < 4; ++i)
6529  excludeIn2.push_back(0);
6530  vector<int> colSingletIn2;
6531  int flavIn2Type = (event[incoming2].id() > 0) ? 1 : -1;
6532  // Try finding colour singlets
6533  bool isColSingIn2 = getColSinglet(flavIn2Type,incoming2,event,
6534  excludeIn2,colSingletIn2);
6535  // Check if colour singlet also is a flavour singlet
6536  bool isFlavSingIn2 = isFlavSinglet(event,colSingletIn2);
6537 
6538  // If no "recovery clustering" is possible, reject clustering
6539  if (!clusPossible
6540  && (!isColSingIn1 || !isFlavSingIn1
6541  || !isColSingIn2 || !isFlavSingIn2))
6542  return false;
6543 
6544  }
6545 
6546  }
6547 
6548  // Done
6549  return allowed;
6550 }
6551 
6552 //--------------------------------------------------------------------------
6553 
6554 // Function to check if rad,emt,rec triple is results in
6555 // colour singlet radBefore+recBefore
6556 // IN int rad,emt,rec : Positions (in event record) of the three
6557 // particles considered for clustering
6558 // Event event : Reference event
6559 
6560 bool History::isSinglett( int rad, int emt, int rec, const Event& event ) {
6561 
6562  int radCol = event[rad].col();
6563  int emtCol = event[emt].col();
6564  int recCol = event[rec].col();
6565  int radAcl = event[rad].acol();
6566  int emtAcl = event[emt].acol();
6567  int recAcl = event[rec].acol();
6568  int recType = event[rec].isFinal() ? 1 : -1;
6569 
6570  bool isSing = false;
6571 
6572  if ( ( recType == -1
6573  && radCol + emtCol == recCol && radAcl + emtAcl == recAcl)
6574  ||( recType == 1
6575  && radCol + emtCol == recAcl && radAcl + emtAcl == recCol) )
6576  isSing = true;
6577 
6578  return isSing;
6579 
6580 }
6581 
6582 //--------------------------------------------------------------------------
6583 
6584 // Function to check if event is sensibly constructed: Meaning
6585 // that all colour indices are contracted and that the charge in
6586 // initial and final states matches
6587 // IN event : event to be checked
6588 // OUT TRUE : event is properly construced
6589 // FALSE : event not valid
6590 
6591 bool History::validEvent( const Event& event ) {
6592 
6593  // Check if event is coloured
6594  bool validColour = true;
6595  for ( int i = 0; i < event.size(); ++i)
6596  // Check colour of quarks
6597  if ( event[i].isFinal() && event[i].colType() == 1
6598  // No corresponding anticolour in final state
6599  && ( FindCol(event[i].col(),i,0,event,1,true) == 0
6600  // No corresponding colour in initial state
6601  && FindCol(event[i].col(),i,0,event,2,true) == 0 )) {
6602  validColour = false;
6603  break;
6604  // Check anticolour of antiquarks
6605  } else if ( event[i].isFinal() && event[i].colType() == -1
6606  // No corresponding colour in final state
6607  && ( FindCol(event[i].acol(),i,0,event,2,true) == 0
6608  // No corresponding anticolour in initial state
6609  && FindCol(event[i].acol(),i,0,event,1,true) == 0 )) {
6610  validColour = false;
6611  break;
6612  // No uncontracted colour (anticolour) charge of gluons
6613  } else if ( event[i].isFinal() && event[i].colType() == 2
6614  // No corresponding anticolour in final state
6615  && ( FindCol(event[i].col(),i,0,event,1,true) == 0
6616  // No corresponding colour in initial state
6617  && FindCol(event[i].col(),i,0,event,2,true) == 0 )
6618  // No corresponding colour in final state
6619  && ( FindCol(event[i].acol(),i,0,event,2,true) == 0
6620  // No corresponding anticolour in initial state
6621  && FindCol(event[i].acol(),i,0,event,1,true) == 0 )) {
6622  validColour = false;
6623  break;
6624  }
6625 
6626  // Check charge sum in initial and final state
6627  bool validCharge = true;
6628  double initCharge = event[3].charge() + event[4].charge();
6629  double finalCharge = 0.0;
6630  for(int i = 0; i < event.size(); ++i)
6631  if (event[i].isFinal()) finalCharge += event[i].charge();
6632  if (abs(initCharge-finalCharge) > 1e-12) validCharge = false;
6633 
6634  return (validColour && validCharge);
6635 
6636 }
6637 
6638 //--------------------------------------------------------------------------
6639 
6640 // Function to check whether two clusterings are identical, used
6641 // for finding the history path in the mother -> children direction
6642 
6643 bool History::equalClustering( Clustering clus1 , Clustering clus2 ) {
6644  return ( (clus1.emittor == clus2.emittor)
6645  && (clus1.emitted == clus2.emitted)
6646  && (clus1.recoiler == clus2.recoiler)
6647  && (clus1.partner == clus2.partner)
6648  && (clus1.pT() == clus2.pT()) );
6649 }
6650 
6651 //--------------------------------------------------------------------------
6652 
6653 // Chose dummy scale for event construction. By default, choose
6654 // sHat for 2->Boson(->2)+ n partons processes and
6655 // M_Boson for 2->Boson(->) processes
6656 
6657 double History::choseHardScale( const Event& event ) const {
6658 
6659  // Get sHat
6660  double mHat = (event[3].p() + event[4].p()).mCalc();
6661 
6662  // Find number of final state particles and bosons
6663  int nFinal = 0;
6664  int nFinBos= 0;
6665  int nBosons= 0;
6666  double mBos = 0.0;
6667  for(int i = 0; i < event.size(); ++i)
6668  if ( event[i].isFinal() ) {
6669  nFinal++;
6670  // Remember final state unstable bosons
6671  if ( event[i].idAbs() == 23
6672  || event[i].idAbs() == 24 ) {
6673  nFinBos++;
6674  nBosons++;
6675  mBos += event[i].m();
6676  }
6677  } else if ( abs(event[i].status()) == 22
6678  && ( event[i].idAbs() == 23
6679  || event[i].idAbs() == 24 )) {
6680  nBosons++;
6681  mBos += event[i].m(); // Real mass
6682  }
6683 
6684  // Return averaged boson masses
6685  if ( nBosons > 0 && (nFinal + nFinBos*2) <= 3)
6686  return (mBos / double(nBosons));
6687  else return
6688  mHat;
6689 }
6690 
6691 
6692 //--------------------------------------------------------------------------
6693 
6694 // If the state has an incoming hadron return the flavour of the
6695 // parton entering the hard interaction. Otherwise return 0
6696 
6697 int History::getCurrentFlav(const int side) const {
6698  int in = (side == 1) ? 3 : 4;
6699  return state[in].id();
6700 }
6701 
6702 //--------------------------------------------------------------------------
6703 
6704 double History::getCurrentX(const int side) const {
6705  int in = (side == 1) ? 3 : 4;
6706  return ( 2.*state[in].e()/state[0].e() );
6707 }
6708 
6709 //--------------------------------------------------------------------------
6710 
6711 double History::getCurrentZ(const int rad,
6712  const int rec, const int emt) const {
6713 
6714  int type = state[rad].isFinal() ? 1 : -1;
6715  double z = 0.;
6716 
6717  if (type == 1) {
6718  // Construct 2->3 variables for FSR
6719  Vec4 sum = state[rad].p() + state[rec].p()
6720  + state[emt].p();
6721  double m2Dip = sum.m2Calc();
6722  double x1 = 2. * (sum * state[rad].p()) / m2Dip;
6723  double x3 = 2. * (sum * state[emt].p()) / m2Dip;
6724  // Calculate z of splitting, different for FSR
6725  z = x1/(x1+x3);
6726  } else {
6727  // Construct momenta of dipole before/after splitting for ISR
6728  Vec4 qBR(state[rad].p() - state[emt].p() + state[rec].p());
6729  Vec4 qAR(state[rad].p() + state[rec].p());
6730  // Calculate z of splitting, different for ISR
6731  z = (qBR.m2Calc())/( qAR.m2Calc());
6732  }
6733 
6734  return z;
6735 
6736 }
6737 
6738 //--------------------------------------------------------------------------
6739 
6740 // Function to compute "pythia pT separation" from Particle input
6741 
6742 double History::pTLund(const Particle& RadAfterBranch,
6743  const Particle& EmtAfterBranch,
6744  const Particle& RecAfterBranch, int ShowerType) {
6745 
6746  // Save type: 1 = FSR pT definition, else ISR definition
6747  int Type = ShowerType;
6748  // Calculate virtuality of splitting
6749  int sign = (Type==1) ? 1 : -1;
6750  Vec4 Q(RadAfterBranch.p() + sign*EmtAfterBranch.p());
6751  double Qsq = sign * Q.m2Calc();
6752  // Mass term of radiator: Consider all non-light quark or gluon radiators
6753  // massive partons.
6754  bool isMassive = ( RadAfterBranch.idAbs() >= 4
6755  && RadAfterBranch.id() != 21 );
6756  double m2Rad = ( mergingHooksPtr->includeMassive() && isMassive )
6757  ? pow2( particleDataPtr->m0(RadAfterBranch.id()) ) : 0.;
6758  // Construct 2->3 variables for FSR
6759  Vec4 sum = RadAfterBranch.p() + RecAfterBranch.p()
6760  + EmtAfterBranch.p();
6761  double m2Dip = sum.m2Calc();
6762  double x1 = 2. * (sum * RadAfterBranch.p()) / m2Dip;
6763  double x3 = 2. * (sum * EmtAfterBranch.p()) / m2Dip;
6764  // Construct momenta of dipole before/after splitting for ISR
6765  Vec4 qBR(RadAfterBranch.p() - EmtAfterBranch.p() + RecAfterBranch.p());
6766  Vec4 qAR(RadAfterBranch.p() + RecAfterBranch.p());
6767  // Calculate z of splitting, different for FSR and ISR
6768 
6769  double z = (Type==1) ? x1/(x1+x3)
6770  : (qBR.m2Calc())/( qAR.m2Calc());
6771  // Separation of splitting, different for FSR and ISR
6772  double pTpyth = (Type==1) ? z*(1.-z) : (1.-z);
6773  // pT^2 = separation*virtuality
6774  pTpyth *= (Qsq - sign*m2Rad);
6775  if ( pTpyth < 0. ) pTpyth = 0.;
6776 
6777  // Return pT
6778  return sqrt(pTpyth);
6779 }
6780 
6781 //--------------------------------------------------------------------------
6782 
6783 // Function to return the position of the initial line before (or after)
6784 // a single (!) splitting.
6785 
6786 int History::posChangedIncoming(const Event& event, bool before) {
6787 
6788  // Check for initial state splittings.
6789  // Consider a splitting to exist if both mother and sister were found.
6790  // Find sister
6791  int iSister = 0;
6792  for (int i =0; i < event.size(); ++i)
6793  if (event[i].status() == 43) {
6794  iSister = i;
6795  break;
6796  }
6797  // Find mother
6798  int iMother = 0;
6799  if (iSister > 0) iMother = event[iSister].mother1();
6800 
6801  // Initial state splitting has been found.
6802  if (iSister > 0 && iMother > 0) {
6803 
6804  // Find flavour, mother flavour
6805  int flavSister = event[iSister].id();
6806  int flavMother = event[iMother].id();
6807 
6808  // Find splitting flavour
6809  int flavDaughter = 0;
6810  if ( abs(flavMother) < 21 && flavSister == 21)
6811  flavDaughter = flavMother;
6812  else if ( flavMother == 21 && flavSister == 21)
6813  flavDaughter = flavMother;
6814  else if ( flavMother == 21 && abs(flavSister) < 21)
6815  flavDaughter = -1*flavSister;
6816  else if ( abs(flavMother) < 21 && abs(flavSister) < 21)
6817  flavDaughter = 21;
6818 
6819  // Find initial state (!) daughter
6820  int iDaughter = 0;
6821  for (int i =0; i < event.size(); ++i)
6822  if ( !event[i].isFinal()
6823  && event[i].mother1() == iMother
6824  && event[i].id() == flavDaughter )
6825  iDaughter = i;
6826 
6827  // Done for initial state splitting.
6828  if ( !before ) return iMother;
6829  else return iDaughter;
6830 
6831  }
6832 
6833  // Check for final state splittings with initial state recoiler.
6834  // Consider a splitting to exist if both mother and daughter were found.
6835  // Find new mother
6836  iMother = 0;
6837  for (int i =0; i < event.size(); ++i)
6838  if ( abs(event[i].status()) == 53 || abs(event[i].status()) == 54) {
6839  iMother = i;
6840  break;
6841  }
6842  // Find daughter
6843  int iDaughter = 0;
6844  if (iMother > 0) iDaughter = event[iMother].daughter1();
6845 
6846  // Done if final state splitting has been found.
6847  if (iDaughter > 0 && iMother > 0) {
6848 
6849  // Done for final state splitting.
6850  if ( !before ) return iMother;
6851  else return iDaughter;
6852 
6853  }
6854 
6855  // If no splitting has been found, return zero.
6856  return 0;
6857 
6858 }
6859 
6860 //--------------------------------------------------------------------------
6861 
6862 // Function to give back the ratio of PDFs and PDF * splitting kernels needed
6863 // to convert a splitting at scale pdfScale, chosen with running PDFs, to a
6864 // splitting chosen with PDFs at a fixed scale mu. As needed to properly count
6865 // emissions.
6866 
6867 double History::pdfFactor( const Event& event, const int type,
6868  double pdfScale, double mu ) {
6869 
6870  double weight = 1.;
6871 
6872  // Final state splittings
6873  if (type >= 3) {
6874 
6875  // Find new mother
6876  int iMother = 0;
6877  for (int i =0; i < event.size(); ++i)
6878  if ( abs(event[i].status()) == 53 || abs(event[i].status()) == 54) {
6879  iMother = i;
6880  break;
6881  }
6882  int flavMother = event[iMother].id();
6883 
6884  // Done if no initial state recoiler was found
6885  if ( iMother == 0 ) return 1.;
6886 
6887  // Find daughter
6888  int iDaughter = event[iMother].daughter1();
6889  int flavDaughter = event[iDaughter].id();
6890 
6891  // Find x values
6892  double xMother = 2.*event[iMother].e() / event[0].e();
6893  double xDaughter = 2.*event[iDaughter].e() / event[0].e();
6894 
6895  // Calculate PDF ratios
6896 
6897  int sideSplit = ( event[iMother].pz() > 0.) ? 1 : -1;
6898  double pdfDen1, pdfDen2, pdfNum1, pdfNum2;
6899  pdfDen1 = pdfDen2 = pdfNum1 = pdfNum2 = 1.;
6900  if ( sideSplit == 1 ) {
6901  // Find PDFs
6902  pdfDen1 = max(1e-15,beamA.xfISR(0, flavDaughter, xDaughter, pow2(mu)) );
6903  pdfNum1 = beamA.xfISR(0, flavDaughter, xDaughter, pow2(pdfScale) );
6904  pdfNum2 = beamA.xfISR(0, flavMother, xMother, pow2(mu) );
6905  pdfDen2 = max(1e-15,beamA.xfISR(0,flavMother, xMother, pow2(pdfScale)) );
6906  } else {
6907  // Find PDFs
6908  pdfDen1 = max(1e-15,beamB.xfISR(0, flavDaughter, xDaughter, pow2(mu)) );
6909  pdfNum1 = beamB.xfISR(0, flavDaughter, xDaughter, pow2(pdfScale) );
6910  pdfNum2 = beamB.xfISR(0, flavMother, xMother, pow2(mu) );
6911  pdfDen2 = max(1e-15,beamB.xfISR(0,flavMother, xMother, pow2(pdfScale)) );
6912  }
6913 
6914  // The magnitude of the PDF ratio in FSR is limited to one. If that was
6915  // the case, return one.
6916  if ( pdfDen2/pdfNum1 > 1. ) return 1.;
6917 
6918  // Calculate PDF weight to reweight emission to emission evaluated at
6919  // constant factorisation scale. No need to include the splitting kernel in
6920  // the weight, since it will drop out anyway.
6921  weight = (pdfNum1/pdfDen1) * (pdfNum2)/(pdfDen2);
6922 
6923  // Initial state splittings
6924  } else if (type == 2) {
6925 
6926  // Find sister
6927  int iSister = 0;
6928  for (int i =0; i < event.size(); ++i)
6929  if (event[i].status() == 43) {
6930  iSister = i;
6931  break;
6932  }
6933  int flavSister = event[iSister].id();
6934 
6935  // Find mother
6936  int iMother = event[iSister].mother1();
6937  int flavMother = event[iMother].id();
6938 
6939  // Find splitting flavour
6940  int flavDaughter = 0;
6941  if ( abs(flavMother) < 21 && flavSister == 21)
6942  flavDaughter = flavMother;
6943  else if ( flavMother == 21 && flavSister == 21)
6944  flavDaughter = flavMother;
6945  else if ( flavMother == 21 && abs(flavSister) < 21)
6946  flavDaughter = -1*flavSister;
6947  else if ( abs(flavMother) < 21 && abs(flavSister) < 21)
6948  flavDaughter = 21;
6949 
6950  // Find x values
6951  double xMother = 2.*event[iMother].e() / event[0].e();
6952 
6953  // Find initial state (!) daughter
6954  int iDaughter = 0;
6955  for (int i =0; i < event.size(); ++i)
6956  if ( !event[i].isFinal()
6957  && event[i].mother1() == iMother
6958  && event[i].id() == flavDaughter )
6959  iDaughter = i;
6960  double xDaughter = 2.*event[iDaughter].e() / event[0].e();
6961 
6962  // Calculate PDF weight to reweight emission to emission evaluated at
6963  // constant factorisation scale. No need to include the splitting kernel
6964  // in the weight, since it will drop out anyway.
6965  int sideSplit = ( event[iMother].pz() > 0.) ? 1 : -1;
6966  double ratio1 = getPDFratio( sideSplit, false, false, flavDaughter,
6967  xDaughter, pdfScale, flavDaughter, xDaughter, mu );
6968  double ratio2 = getPDFratio( sideSplit, false, false, flavMother,
6969  xMother, mu, flavMother, xMother, pdfScale );
6970 
6971  weight = ratio1*ratio2;
6972 
6973  // Do nothing for MPI
6974  } else {
6975  weight = 1.;
6976  }
6977 
6978  // Done
6979  return weight;
6980 }
6981 
6982 //--------------------------------------------------------------------------
6983 
6984 // Function giving the product of splitting kernels and PDFs so that the
6985 // resulting flavour is given by flav. This is used as a helper routine
6986 // to dgauss
6987 
6988 double History::integrand(int flav, double x, double scaleInt, double z) {
6989 
6990  // Declare constants
6991  double CF = 4./3.;
6992  double TR = 1./2.;
6993  double CA = 3.;
6994 
6995  double result = 0.;
6996 
6997  // Integrate NLL sudakov remainder
6998  if (flav==0) {
6999 
7000  AlphaStrong* as = mergingHooksPtr->AlphaS_ISR();
7001  double asNow = (*as).alphaS(z);
7002  result = 1./z *asNow*asNow* ( log(scaleInt/z) -3./2. );
7003 
7004  // Integrand for PDF ratios. Careful about factors if 1/z, since formulae
7005  // are expressed in terms if f(x,mu), while Pythia uses x*f(x,mu)!
7006  } else if (flav==21) {
7007 
7008  double measure1 = 1./(1. - z);
7009  double measure2 = 1.;
7010 
7011  double integrand1 =
7012  2.*CA
7013  * z * beamB.xf( 21,x/z,pow(scaleInt,2))
7014  / beamB.xf( 21,x, pow(scaleInt,2))
7015  - 2.*CA;
7016 
7017  double integrand2 =
7018  // G -> G terms
7019  2.*CA *((1. -z)/z + z*(1.-z))
7020  * beamB.xf( 21,x/z,pow(scaleInt,2))
7021  / beamB.xf( 21,x, pow(scaleInt,2))
7022  // G -> Q terms
7023  + CF * ((1+pow(1-z,2))/z)
7024  *( beamB.xf( 1, x/z,pow(scaleInt,2))
7025  / beamB.xf( 21, x, pow(scaleInt,2))
7026  + beamB.xf( -1, x/z,pow(scaleInt,2))
7027  / beamB.xf( 21, x, pow(scaleInt,2))
7028  + beamB.xf( 2, x/z,pow(scaleInt,2))
7029  / beamB.xf( 21, x, pow(scaleInt,2))
7030  + beamB.xf( -2, x/z,pow(scaleInt,2))
7031  / beamB.xf( 21, x, pow(scaleInt,2))
7032  + beamB.xf( 3, x/z,pow(scaleInt,2))
7033  / beamB.xf( 21, x, pow(scaleInt,2))
7034  + beamB.xf( -3, x/z,pow(scaleInt,2))
7035  / beamB.xf( 21, x, pow(scaleInt,2))
7036  + beamB.xf( 4, x/z,pow(scaleInt,2))
7037  / beamB.xf( 21, x, pow(scaleInt,2))
7038  + beamB.xf( -4, x/z,pow(scaleInt,2))
7039  / beamB.xf( 21, x, pow(scaleInt,2)) );
7040 
7041  // Done
7042  result = integrand1*measure1 + integrand2*measure2;
7043 
7044  } else {
7045 
7046  double measure1 = 1./(1. -z);
7047  double measure2 = 1.;
7048 
7049  // Q -> Q terms
7050  double integrand1 =
7051  CF * (1+pow(z,2))
7052  * beamB.xf( flav, x/z, pow(scaleInt,2))
7053  / beamB.xf( flav, x, pow(scaleInt,2))
7054  - 2.*CF;
7055 
7056  // Q -> G terms
7057  double integrand2 =
7058  + TR * (pow(z,2) + pow(1-z,2))
7059  * beamB.xf( 21, x/z, pow(scaleInt,2))
7060  / beamB.xf( flav, x, pow(scaleInt,2));
7061 
7062  // Done
7063  result = measure1*integrand1 + measure2*integrand2;
7064  }
7065 
7066  return result;
7067 
7068 }
7069 
7070 //==========================================================================
7071 
7072 } // end namespace Pythia8
Definition: AgUStep.h:26