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) 2012 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 "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 // Declaration of History class
52 // The only constructor. Default arguments are used when creating
53 // the initial history node. The \a depth is the maximum number of
54 // clusterings requested. \a scalein is the scale at which the \a
55 // statein was clustered (should be set to the merging scale for the
56 // initial history node. \a beamAIn and beamBIn are needed to
57 // calcutate PDF ratios, \a particleDataIn to have access to the
58 // correct masses of particles. If \a isOrdered is true, the previous
59 // clusterings has been ordered. \a is the PDF ratio for this
60 // clustering (=1 for FSR clusterings). \a probin is the accumulated
61 // probabilities for the previous clusterings, and \ mothin is the
62 // previous history node (null for the initial node).
63 
64 History::History( int depth,
65  double scalein,
66  Event statein,
67  Clustering c,
68  MergingHooks* mergingHooksPtrIn,
69  BeamParticle beamAIn,
70  BeamParticle beamBIn,
71  ParticleData* particleDataPtrIn,
72  Info* infoPtrIn,
73  bool isOrdered = true,
74  bool isStronglyOrdered = true,
75  double probin = 1.0,
76  History * mothin = 0)
77  : state(statein),
78  mother(mothin),
79  sumpath(0.0),
80  foundOrderedPath(false),
81  foundStronglyOrderedPath(false),
82  foundCompletePath(false),
83  scale(scalein),
84  prob(probin),
85  clusterIn(c),
86  mergingHooksPtr(mergingHooksPtrIn),
87  beamA(beamAIn),
88  beamB(beamBIn),
89  particleDataPtr(particleDataPtrIn),
90  infoPtr(infoPtrIn)
91  {
92 
93  // Initialise beam particles
94  setupBeams();
95  // Update probability with PDF ratio
96  if(mother && mergingHooksPtr->includeRedundant()) prob *= pdfForSudakov();
97 
98  // Minimal scalar sum of pT used in Herwig to choose history
99  // Keep track of scalar PT
100  if(mother){
101  double acoll = (mother->state[clusterIn.emittor].isFinal())
102  ? mergingHooksPtr->herwigAcollFSR()
103  : mergingHooksPtr->herwigAcollISR();
104  sumScalarPT = mother->sumScalarPT + acoll*scale;
105  } else
106  sumScalarPT = 0.0;
107 
108  // If this is not the fully clustered state, try to find possible
109  // clusterings.
110  vector<Clustering> clusterings;
111  if ( depth > 0 ) clusterings = getAllClusterings();
112 
113  // If no clusterings were found, the recursion is done and we
114  // register this node.
115  if ( clusterings.empty() ) {
116  registerPath(*this, isOrdered, isStronglyOrdered, depth == 0);
117  return;
118  }
119 
120  // Now we sort the possible clusterings so that we try the
121  // smallest scale first.
122  multimap<double, Clustering *> sorted;
123  for ( int i = 0, N = clusterings.size(); i < N; ++i ) {
124  sorted.insert(make_pair(clusterings[i].pT(), &clusterings[i]));
125  }
126 
127  for ( multimap<double, Clustering *>::iterator it = sorted.begin();
128  it != sorted.end(); ++it ) {
129 
130  // If this path is not strongly ordered and we already have found an
131  // ordered path, then we don't need to continue along this path.
132  bool stronglyOrdered = isStronglyOrdered;
133  if ( mergingHooksPtr->enforceStrongOrdering() &&
134  ( !stronglyOrdered
135  || (mother
136  &&(it->first < mergingHooksPtr->scaleSeparationFactor()*scale )))){
137  if ( onlyStronglyOrderedPaths() ) continue;
138  stronglyOrdered = false;
139  }
140 
141  bool ordered = isOrdered;
142  if(mergingHooksPtr->orderInRapidity()){
143  // Get new z value
144  double z = getCurrentZ((*it->second).emittor,
145  (*it->second).recoiler,(*it->second).emitted);
146  // Get z value of splitting that produced this state
147  double zOld = (!mother) ? 0. : mother->getCurrentZ(clusterIn.emittor,
148  clusterIn.recoiler,clusterIn.emitted);
149  // If this path is not ordered in pT and y, and we already have found an
150  // ordered path, then we don't need to continue along this path.
151  if ( !ordered || ( mother && (it->first < scale
152  || it->first < pow(1. - z,2) / (z * (1. - zOld ))*scale ))) {
153  if ( onlyOrderedPaths() ) continue;
154  ordered = false;
155  }
156 
157  } else {
158  // If this path is not ordered in pT and we already have found an
159  // ordered path, then we don't need to continue along this path.
160  if ( !ordered || ( mother && (it->first < scale) ) ) {
161  if ( onlyOrderedPaths() ) continue;
162  ordered = false;
163  }
164  }
165 
166  // Check if reclustered state should be disallowed
167  if( mergingHooksPtr->canCutOnRecState()
168  && mergingHooksPtr->doCutOnRecState(cluster(*it->second)) ){
169  continue;
170  }
171 
172  // Perform the clustering and recurse and construct the next
173  // history node.
174  children.push_back(new History(depth - 1,it->first,cluster(*it->second),
175  *it->second, mergingHooksPtr, beamA, beamB, particleDataPtr,
176  infoPtr, ordered, stronglyOrdered, prob*getProb(*it->second),
177  this ));
178  }
179 }
180 
181 //--------------------------------------------------------------------------
182 
183 // In the initial history node, select one of the paths according to
184 // the probabilities. This function should be called for the initial
185 // history node.
186 // IN trialShower* : Previously initialised trialShower object,
187 // to perform trial showering and as
188 // repository of pointers to initialise alphaS
189 // PartonSystems* : PartonSystems object needed to initialise
190 // shower objects
191 // OUT double : (Sukadov) , (alpha_S ratios) , (PDF ratios)
192 
193 double History::weightTREE(PartonLevel* trial, AlphaStrong * asFSR,
194  AlphaStrong * asISR, double RN){
195 
196  // Read alpha_S in ME calculation and maximal scale (eCM)
197  double asME = infoPtr->alphaS();
198  double maxScale = (foundCompletePath) ? infoPtr->eCM() : infoPtr->QFac();
199 
200  // Select a path of clusterings
201  History * selected = select(RN);
202  // Set scales in the states to the scales pythia would have set
203  selected->setScalesInHistory();
204 
205 // // Reject incomplete histories
206 // if(!foundCompletePath) return 0.;
207 // // Reject unordered histories
208 // if(!foundOrderedPath) return 0.;
209 // // Reject histories without strong ordering
210 // if(mergingHooksPtr->enforceStrongOrdering()
211 // && !foundStronglyOrderedPath) return 0.;
212 
213  double asWeight = 1.;
214  double pdfWeight = 1.;
215 
216  // Do trial shower, calculation of alpha_S ratios, PDF ratios
217  double wt = selected->weightTree(trial,asME,maxScale, asFSR,
218  asISR, asWeight, pdfWeight);
219  // Done
220  return (wt*asWeight*pdfWeight);
221 }
222 
223 //--------------------------------------------------------------------------
224 
225 // Function to set the state with complete scales for evolution
226 
227 void History::getStartingConditions( const double RN, Event& outState ) {
228 
229  // Select the history
230  History * selected = select(RN);
231 
232  // Copy the output state
233  outState = state;
234 
235  // Set the scale of the lowest order process
236  if(!selected->mother){
237  int nFinal = 0;
238  for(int i=0; i < int(outState.size()); ++i)
239  if(outState[i].isFinal()) nFinal++;
240  if(nFinal <=2)
241  outState.scale(infoPtr->QFac());
242 
243 // // If the hard process has a resonance decay which is not
244 // // corrected (e.g. for pp -> (V->jj) + jets merging), set
245 // // factorization scale as starting scale
246 // if(mergingHooksPtr->hardProcess.hasResInProc())
247 // outState.scale(infoPtr->QFac());
248 // // If the hard process has a resonance decay which is
249 // // corrected (e.g. for e+e- -> 2 + n jets merging), set
250 // // half the intermediate mass as starting scale
251 // else
252 // outState.scale(0.5*outState[5].m());
253 
254  // Save information on last splitting, to allow the next
255  // emission in the shower to have smaller rapidity with
256  // respect to the last ME splitting
257  // For hard process, use dummy values
258  if(mergingHooksPtr->getNumberOfClusteringSteps(state) == 0) {
259  infoPtr->zNowISR(0.5);
260  infoPtr->pT2NowISR(pow(state[0].e(),2));
261  infoPtr->hasHistory(true);
262  // For incomplete process, try to use real values
263  } else {
264  infoPtr->zNowISR(selected->zISR());
265  infoPtr->pT2NowISR(pow(selected->pTISR(),2));
266  infoPtr->hasHistory(true);
267  }
268 
269  } else {
270 
271  // Save information on last splitting, to allow the next
272  // emission in the shower to have smaller rapidity with
273  // respect to the last ME splitting
274  infoPtr->zNowISR(selected->zISR());
275  infoPtr->pT2NowISR(pow(selected->pTISR(),2));
276  infoPtr->hasHistory(true);
277  }
278 
279 }
280 
281 //--------------------------------------------------------------------------
282 
283 // Calculate and return pdf ratio
284 
285 double History::getPDFratio( int side, bool forSudakov,
286  int flavNum, double xNum, double muNum,
287  int flavDen, double xDen, double muDen) {
288 
289  // Do nothing for e+e- beams
290  if( abs(flavNum) > 10 && flavNum != 21 ) return 1.0;
291  if( abs(flavDen) > 10 && flavDen != 21 ) return 1.0;
292 
293  // Now calculate PDF ratio if necessary
294  double pdfRatio = 1.0;
295 
296  // Get mother and daughter pdfs
297  double pdfNum = 0.0;
298  double pdfDen = 0.0;
299 
300  // Use rescaled PDFs in the presence of multiparton interactions
301  if(side == 1) {
302  if(forSudakov)
303  pdfNum = mother->beamA.xfISR(0, flavNum, xNum, muNum*muNum);
304  else
305  pdfNum = beamA.xfISR(0, flavNum, xNum, muNum*muNum);
306  if(forSudakov)
307  pdfDen = max(1e-10, beamA.xfISR(0, flavDen, xDen, muDen*muDen));
308  else
309  pdfDen = max(1e-10, beamA.xfISR(0, flavDen, xDen, muDen*muDen));
310 
311  } else {
312  if(forSudakov)
313  pdfNum = mother->beamB.xfISR(0, flavNum, xNum, muNum*muNum);
314  else
315  pdfNum = beamB.xfISR(0, flavNum, xNum, muNum*muNum);
316 
317  if(forSudakov)
318  pdfDen = max(1e-10,beamB.xfISR(0, flavDen, xDen, muDen*muDen));
319  else
320  pdfDen = max(1e-10,beamB.xfISR(0, flavDen, xDen, muDen*muDen));
321  }
322 
323  // Return ratio of pdfs
324  if( pdfNum > 1e-15 && pdfDen > 1e-10 )
325  pdfRatio *= pdfNum / pdfDen;
326  else {
327  infoPtr->errorMsg("Warning in History:getPDFratio: Found tiny PDF in",
328  "calculation of PDF ratio, put PDF ratio to 1.");
329  pdfRatio = 1.;
330  }
331  // Done
332  return pdfRatio;
333 
334 }
335 
336 //--------------------------------------------------------------------------
337 
338 /*--------------- METHODS USED FOR ONLY ONE PATH OF HISTORY NODES ------- */
339 
340 // Function to set all scales in the sequence of states. This is a
341 // wrapper routine for setScales and setEventScales methods
342 
343 void History::setScalesInHistory() {
344  // Find correct links from n+1 to n states (mother --> child), as
345  // needed for enforcing ordered scale sequences
346  vector<int> ident;
347  findPath(ident);
348  // Set production scales in the states to the scales pythia would
349  // have set and enforce ordering
350  setScales(ident,true);
351  // Set the overall event scales to the scale of the last branching
352  setEventScales();
353 }
354 
355 //--------------------------------------------------------------------------
356 
357 // Function to find the index (in the mother histories) of the
358 // child history, thus providing a way access the path from both
359 // initial history (mother == 0) and final history (all children == 0)
360 // IN vector<int> : The index of each child in the children vector
361 // of the current history node will be saved in
362 // this vector
363 // NO OUTPUT
364 
365 void History::findPath(vector<int>& out) {
366 
367  // If the initial and final nodes are identical, return
368  if(!mother && int(children.size()) < 1) return;
369  // Find the child by checking the children vector for the perfomed
370  // clustering
371  int iChild=-1;
372  if( mother ) {
373  int size = int(mother->children.size());
374  // Loop through children and identify child chosen
375  for ( int i=0; i < size; ++i){
376  if( mother->children[i]->scale == scale
377  && mother->children[i]->prob == prob
378  && equalClustering(mother->children[i]->clusterIn,clusterIn)) {
379  iChild = i;
380  break;
381  }
382  }
383  // Save the index of the child in the children vector and recurse
384  if(iChild >-1)
385  out.push_back(iChild);
386  mother->findPath(out);
387  }
388 }
389 
390 //--------------------------------------------------------------------------
391 
392 // Functions to set the parton production scales and enforce
393 // ordering on the scales of the respective clusterings stored in
394 // the History node:
395 // Method will start from lowest multiplicity state and move to
396 // higher states, setting the production scales the shower would
397 // have used.
398 // When arriving at the highest multiplicity, the method will switch
399 // and go back in direction of lower states to check and enforce
400 // ordering for unordered histories.
401 // IN vector<int> : Vector of positions of the chosen child
402 // in the mother history to allow to move
403 // in direction initial->final along path
404 // bool : True: Move in direction low->high
405 // multiplicity and set production scales
406 // False: Move in direction high->low
407 // multiplicity and check and enforce
408 // ordering
409 // NO OUTPUT
410 
411 void History::setScales( vector<int> index, bool forward) {
412 
413  // First, set the scales of the hard process to the kinematial
414  // limit (=s)
415  if( children.empty() && forward ){
416  // New "incomplete" configurations showered from mu
417  if(!mother){
418  double scaleNew = 1.;
419 
420  if(mergingHooksPtr->incompleteScalePrescip()==0){
421  scaleNew = infoPtr->QFac();
422  } else if(mergingHooksPtr->incompleteScalePrescip()==1){
423  Vec4 pOut;
424  pOut.p(0.,0.,0.,0.);
425  for(int i=0; i<int(state.size()); ++i)
426  if(state[i].isFinal())
427  pOut += state[i].p();
428  scaleNew = pOut.mCalc();
429  } else if (mergingHooksPtr->incompleteScalePrescip()==2){
430  scaleNew = state[0].e();
431  }
432 
433  scaleNew = max( mergingHooksPtr->pTcut(), scaleNew);
434 
435  state.scale(scaleNew);
436  for(int i=3; i < int(state.size());++i)
437  if(state[i].colType() != 0)
438  state[i].scale(scaleNew);
439 
440  } else {
441  // 2->2 with non-parton particles showered from eCM
442  state.scale( state[0].e() );
443  // Count final partons
444  bool isLEP = ( state[3].isLepton() && state[4].isLepton() );
445  bool isQCD = true;
446  vector<int> finalPartons;
447  for(int i=0; i < int(state.size());++i) {
448  if(state[i].isFinal() && state[i].colType() != 0){
449  finalPartons.push_back(i);
450  }
451  if(state[i].isFinal() && state[i].colType() == 0){
452  isQCD = false;
453  break;
454  }
455  }
456  // If 2->2, purely partonic, set event scale to kinematic pT
457  if(!isLEP && isQCD && int(finalPartons.size()) == 2)
458  state.scale(state[finalPartons[0]].pT());
459 
460  }
461  }
462  // Set all particle production scales, starting from lowest
463  // multiplicity (final) state
464  if(mother && forward) {
465  // When choosing splitting scale, beware of unordered splittings:
466  double scaleNew = 1.;
467  if(mergingHooksPtr->unorderedScalePrescip() == 0){
468  // Use larger scale as common splitting scale for mother and child
469  scaleNew = max( mergingHooksPtr->pTcut(), max(scale,mother->scale));
470  } else if (mergingHooksPtr->unorderedScalePrescip() == 1){
471  // Use smaller scale as common splitting scale for mother and child
472  if(scale < mother->scale)
473  scaleNew *= max( mergingHooksPtr->pTcut(), min(scale,mother->scale));
474  else
475  scaleNew *= max( mergingHooksPtr->pTcut(), max(scale,mother->scale));
476  }
477 
478  // Rescale the mother state partons to the clustering scales
479  // that have been found along the path
480  mother->state[clusterIn.emitted].scale(scaleNew);
481  mother->state[clusterIn.emittor].scale(scaleNew);
482  mother->state[clusterIn.recoiler].scale(scaleNew);
483 
484  // Find unchanged copies of partons in higher multiplicity states
485  // and rescale those
486  mother->scaleCopies(clusterIn.emitted, mother->state, scaleNew);
487  mother->scaleCopies(clusterIn.emittor, mother->state, scaleNew);
488  mother->scaleCopies(clusterIn.recoiler, mother->state, scaleNew);
489 
490  // Recurse
491  mother->setScales(index,true);
492  }
493 
494  // Now, check and correct ordering from the highest multiplicity
495  // state backwards to all the clustered states
496  if(!mother || !forward) {
497  // Get index of child along the path
498  int iChild = -1;
499  if( int(index.size()) > 0 ) {
500  iChild = index.back();
501  index.pop_back();
502  }
503 
504  // Check that the reclustered scale is above the shower cut
505  if(mother) {
506  scale = max(mergingHooksPtr->pTcut(), scale);
507  }
508  // If this is NOT the 2->2 process, check and enforce ordering
509  if(iChild != -1 && !children.empty()) {
510 
511  if(scale > children[iChild]->scale ) {
512  if(mergingHooksPtr->unorderedScalePrescip() == 0){
513  // Use larger scale as common splitting scale for mother and child
514  double scaleNew = max( mergingHooksPtr->pTcut(),
515  max(scale,children[iChild]->scale));
516  // Enforce ordering in particle production scales
517  for( int i = 0; i < int(children[iChild]->state.size()); ++i)
518  if(children[iChild]->state[i].scale() == children[iChild]->scale)
519  children[iChild]->state[i].scale(scaleNew);
520  // Enforce ordering in saved clustering scale
521  children[iChild]->scale = scaleNew;
522 
523  } else if( mergingHooksPtr->unorderedScalePrescip() == 1){
524  // Use smaller scale as common splitting scale for mother & child
525  double scaleNew = max(mergingHooksPtr->pTcut(),
526  min(scale,children[iChild]->scale));
527  // Enforce ordering in particle production scales
528  for( int i = 0; i < int(state.size()); ++i)
529  if(state[i].scale() == scale)
530  state[i].scale(scaleNew);
531  // Enforce ordering in saved clustering scale
532  scale = scaleNew;
533  }
534  // Just set the overall event scale to the minimal scale
535  } else {
536  double scalemin = state[0].e();
537  for( int i = 0; i < int(state.size()); ++i)
538  if(state[i].colType() != 0)
539  scalemin = max(mergingHooksPtr->pTcut(),
540  min(scalemin,state[i].scale()));
541  state.scale(scalemin);
542  scale = max(mergingHooksPtr->pTcut(), scale);
543  }
544  //Recurse
545  children[iChild]->setScales(index, false);
546  }
547  }
548 
549 }
550 
551 //--------------------------------------------------------------------------
552 
553 // Function to find a particle in all higher multiplicity events
554 // along the history path and set its production scale to the input
555 // scale
556 // IN int iPart : Parton in refEvent to be checked / rescaled
557 // Event& refEvent : Reference event for iPart
558 // double scale : Scale to be set as production scale for
559 // unchanged copies of iPart in subsequent steps
560 
561 void History::scaleCopies(int iPart, const Event& refEvent, double rho) {
562 
563  // Check if any parton recently rescaled is found unchanged:
564  // Same charge, colours in mother->state
565  if( mother ) {
566  for( int i=0; i < mother->state.size(); ++i) {
567  if( ( mother->state[i].id() == refEvent[iPart].id()
568  && mother->state[i].colType() == refEvent[iPart].colType()
569  && mother->state[i].chargeType() == refEvent[iPart].chargeType()
570  && mother->state[i].col() == refEvent[iPart].col()
571  && mother->state[i].acol() == refEvent[iPart].acol() )
572  ) {
573  // Rescale the unchanged parton
574  mother->state[i].scale(rho);
575  // Recurse
576  if(mother->mother)
577  mother->scaleCopies( iPart, refEvent, rho );
578  } // end if found unchanged parton case
579  } // end loop over particle entries in event
580  }
581 }
582 
583 //--------------------------------------------------------------------------
584 
585 // Functions to set the OVERALL EVENT SCALES [=state.scale()] to
586 // the scale of the last clustering
587 // NO INPUT
588 // NO OUTPUT
589 
590 void History::setEventScales() {
591  // Set the event scale to the scale of the last clustering,
592  // except for the very lowest multiplicity state
593  if(mother) {
594  mother->state.scale(scale);
595  // Recurse
596  mother->setEventScales();
597  }
598 }
599 
600 //--------------------------------------------------------------------------
601 
602 // Functions to return the z value of the last ISR splitting
603 // NO INPUT
604 // OUTPUT double : z value of last ISR splitting in history
605 
606 double History::zISR() {
607 
608  // Do nothing for ME level state
609  if (!mother) return 0.0;
610  // Skip FSR splitting
611  if (mother->state[clusterIn.emittor].isFinal()) return mother->zISR();
612  // Calculate z
613  int rad = clusterIn.emittor;
614  int rec = clusterIn.recoiler;
615  int emt = clusterIn.emitted;
616  double z = (mother->state[rad].p() + mother->state[rec].p()
617  - mother->state[emt].p()).m2Calc()
618  / (mother->state[rad].p() + mother->state[rec].p()).m2Calc();
619  // Recurse
620  double znew = mother->zISR();
621  // Update z
622  if(znew > 0.) z = znew;
623 
624  return z;
625 }
626 
627 //--------------------------------------------------------------------------
628 
629 // Functions to return the z value of the last FSR splitting
630 // NO INPUT
631 // OUTPUT double : z value of last FSR splitting in history
632 
633 double History::zFSR() {
634 
635  // Do nothing for ME level state
636  if (!mother) return 0.0;
637  // Skip ISR splitting
638  if (!mother->state[clusterIn.emittor].isFinal()) return mother->zFSR();
639  // Calculate z
640  int rad = clusterIn.emittor;
641  int rec = clusterIn.recoiler;
642  int emt = clusterIn.emitted;
643  // Construct 2->3 variables for FSR
644  Vec4 sum = mother->state[rad].p() + mother->state[rec].p()
645  + mother->state[emt].p();
646  double m2Dip = sum.m2Calc();
647  double x1 = 2. * (sum * mother->state[rad].p()) / m2Dip;
648  double x3 = 2. * (sum * mother->state[emt].p()) / m2Dip;
649  // Calculate z of splitting for FSR
650  double z = x1/(x1+x3);
651  // Recurse
652  double znew = mother->zFSR();
653  // Update z
654  if(znew > 0.) z = znew;
655 
656  return z;
657 }
658 
659 //--------------------------------------------------------------------------
660 
661 // Functions to return the pT scale of the last FSR splitting
662 // NO INPUT
663 // OUTPUT double : pT scale of last FSR splitting in history
664 
665 double History::pTISR() {
666  // Do nothing for ME level state
667  if (!mother) return 0.0;
668  // Skip FSR splitting
669  if(mother->state[clusterIn.emittor].isFinal()) return mother->pTISR();
670  double pT = mother->state.scale();
671  // Recurse
672  double pTnew = mother->pTISR();
673  // Update pT
674  if(pTnew > 0.) pT = pTnew;
675 
676  return pT;
677 }
678 
679 //--------------------------------------------------------------------------
680 
681 // Functions to return the pT scale of the last FSR splitting
682 // NO INPUT
683 // OUTPUT double : pT scale of last FSR splitting in history
684 
685 double History::pTFSR() {
686  // Do nothing for ME level state
687  if (!mother) return 0.0;
688  // Skip ISR splitting
689  if (!mother->state[clusterIn.emittor].isFinal()) return mother->pTFSR();
690  double pT = mother->state.scale();
691  // Recurse
692  double pTnew = mother->pTFSR();
693  // Update pT
694  if(pTnew > 0.) pT = pTnew;
695  return pT;
696 }
697 
698 //--------------------------------------------------------------------------
699 
700 // Function to choose a path from all paths in the tree
701 // according to their splitting probabilities
702 // IN double : Random number
703 // OUT History* : Leaf of history path chosen
704 
705 History * History::select(double rnd) {
706  if ( paths.empty() ) return 0;
707 
708  if(mergingHooksPtr->pickBySumPT()){
709  // Find index of history with minimal sum of scalar pT
710  int nFinal = 0;
711  for (int i=0; i < state.size(); ++i)
712  if(state[i].isFinal())
713  nFinal++;
714  double iMin = 0.;
715  double sumMin = (nFinal-2)*state[0].e();
716  for ( map<double, History*>::iterator it = paths.begin();
717  it != paths.end(); ++it ){
718 
719  if(it->second->sumScalarPT < sumMin){
720  sumMin = it->second->sumScalarPT;
721  iMin = it->first;
722  }
723  }
724  // Choose history with smallest sum of scalar pT
725  return paths.lower_bound(iMin)->second;
726  } else
727  // Choose history according to probability
728  return paths.upper_bound(sumpath*rnd)->second;
729 }
730 
731 //--------------------------------------------------------------------------
732 
733 // For a full path, find the weight calculated from the ratio of
734 // couplings, the no-emission probabilities, and possible PDF
735 // ratios. This function should only be called for the last history
736 // node of a full path.
737 // IN TimeShower : Already initialised shower object to be used as
738 // trial shower
739 // double : alpha_s value used in ME calculation
740 // double : Maximal mass scale of the problem (e.g. E_CM)
741 // AlphaStrong: Initialised shower alpha_s object for FSR
742 // alpha_s ratio calculation
743 // AlphaStrong: Initialised shower alpha_s object for ISR
744 // alpha_s ratio calculation (can be different from previous)
745 
746 double History::weightTree(PartonLevel* trial, double as0, double maxscale,
747  AlphaStrong * asFSR, AlphaStrong * asISR,
748  double& asWeight, double& pdfWeight) {
749 
750  // Use correct scale
751  double newScale = scale;
752 
753  // For ME state, just multiply by PDF ratios
754  if ( !mother ){
755 
756  int sideRad = (state[3].pz() > 0) ? 1 :-1;
757  int sideRec = (state[4].pz() > 0) ? 1 :-1;
758  // Calculate PDF first leg
759  if (state[3].colType() != 0) {
760  // Find x value and flavour
761  double x = 2.*state[3].e() / state[0].e();
762  int flav = state[3].id();
763 
764  // Find numerator/denominator scale
765  double scaleNum = (children.empty()) ? infoPtr->QFac() : maxscale;
766  double scaleDen = infoPtr->QFac();
767  // For initial parton, multiply by PDF ratio
768  double ratio = getPDFratio(sideRad, false, flav, x, scaleNum,
769  flav, x, scaleDen);
770  pdfWeight *= ratio;
771  }
772 
773  // Calculate PDF ratio for second leg
774  if (state[4].colType() != 0) {
775  // Find x value and flavour
776  double x = 2.*state[4].e() / state[0].e();
777  int flav = state[4].id();
778 
779  // Find numerator/denominator scale
780  double scaleNum = (children.empty()) ? infoPtr->QFac() : maxscale;
781  double scaleDen = infoPtr->QFac();
782  // For initial parton, multiply with PDF ratio
783  double ratio = getPDFratio(sideRec, false, flav, x, scaleNum,
784  flav, x, scaleDen);
785  pdfWeight *= ratio;
786  }
787 
788  return 1.0;
789  }
790 
791  // Recurse
792  double w = mother->weightTree(trial, as0, newScale, asFSR, asISR,
793  asWeight, pdfWeight);
794 
795  // Do nothing for empty state
796  if(state.size() < 3) return 1.0;
797  // If up to now, trial shower was not successful, return zero
798  if ( w < 1e-12 ) return 0.0;
799  // Do trial shower on current state, return zero if not successful
800  w *= doTrialShower(trial, maxscale);
801  if ( w < 1e-12 ) return 0.0;
802 
803  // Calculate alpha_s ratio for current state
804  if ( asFSR && asISR ) {
805  double asScale = newScale;
806  if(mergingHooksPtr->unorderedASscalePrescip() == 1)
807  asScale = clusterIn.pT();
808  bool FSR = mother->state[clusterIn.emittor].isFinal();
809  double alphaSinPS = (FSR) ? (*asFSR).alphaS(asScale*asScale)
810  : (*asISR).alphaS(asScale*asScale
811  + pow(mergingHooksPtr->pT0ISR(),2));
812  asWeight *= alphaSinPS / as0;
813  }
814 
815  // Calculate pdf ratios: Get both sides of event
816  int inP = 3;
817  int inM = 4;
818  int sideP = (mother->state[inP].pz() > 0) ? 1 :-1;
819  int sideM = (mother->state[inM].pz() > 0) ? 1 :-1;
820 
821  if ( mother->state[inP].colType() != 0 ) {
822  // Find x value and flavour
823  double x = getCurrentX(sideP);
824  int flav = getCurrentFlav(sideP);
825 
826  // Find numerator scale
827  double scaleNum = (children.empty()) ? infoPtr->QFac() : maxscale;
828  // Multiply PDF ratio
829  double ratio = getPDFratio(sideP, false, flav, x, scaleNum,
830  flav, x, newScale);
831  pdfWeight *= ratio;
832  }
833 
834  if ( mother->state[inM].colType() != 0 ) {
835  // Find x value and flavour
836  double x = getCurrentX(sideM);
837  int flav = getCurrentFlav(sideM);
838 
839  // Find numerator scale
840  double scaleNum = (children.empty()) ? infoPtr->QFac() : maxscale;
841  // Multiply PDF ratio
842  double ratio = getPDFratio(sideM, false, flav, x, scaleNum,
843  flav, x, newScale);
844  pdfWeight *= ratio;
845  }
846 
847  // Done
848  return w;
849 }
850 
851 //--------------------------------------------------------------------------
852 
853 // Perform a trial shower using the \a pythia object between
854 // maxscale down to this scale and return the corresponding Sudakov
855 // form factor.
856 // IN trialShower : Shower object used as trial shower
857 // double : Maximum scale for trial shower branching
858 // OUT 0.0 : trial shower emission outside allowed pT range
859 // 1.0 : trial shower successful (any emission was below
860 // the minimal scale )
861 
862 double History::doTrialShower(PartonLevel* trial, double maxscale) {
863 
864  trial->resetTrial();
865  // Copy state to local process
866  Event process = state;
867  // Construct event to be showered
868  Event event;
869  // Get pT before reclustering
870  double pTreclus = scale;
871  // Declare trial shower pT
872  double pTtrial = 0.0;
873 
874  // Reset output event
875  event.init("(hard process-modified)", particleDataPtr);
876  event.clear();
877  // If the maximal scale and the minimal scale coincide (as would
878  // be the case for the corrected scales of unordered histories),
879  // do not generate Sudakov
880  if(pTreclus >= maxscale) return 1.0;
881 
882  // Find z and pT values at which the current state was formed, to
883  // ensure that the showers can order the next emission correctly in
884  // rapidity, if required
885  double z = ( mergingHooksPtr->getNumberOfClusteringSteps(state) == 0)
886  ? 0.5
887  : mother->getCurrentZ(clusterIn.emittor,clusterIn.recoiler,
888  clusterIn.emitted);
889  // Store z and pT values at which the current state was formed
890  infoPtr->zNowISR(z);
891  infoPtr->pT2NowISR(pow(maxscale,2));
892  infoPtr->hasHistory(true);
893 
894  // Perform trial shower emission
895  trial->next(process,event);
896 
897  // Get trial shower pT
898  pTtrial = trial->pTLastInShower();
899 
900  if(pTtrial > pTreclus) return 0.0;
901 
902  // For 2 -> 2 pure QCD state, do not allow multiparton interactions
903  // above the kinematical pT of the 2 -> 2 state
904  int typeTrial = trial->typeLastInShower();
905  if(typeTrial == 1){
906  // Count number of final state particles and remember partons
907  int nFinal = 0;
908  vector<int> finalPartons;
909  for(int i=0; i < state.size(); ++i){
910  if(state[i].isFinal()) {
911  nFinal++;
912  if( state[i].colType() != 0)
913  finalPartons.push_back(i);
914  }
915  }
916  // Veto if MPI was above 2 -> 2 pT
917  if( nFinal == 2 && int(finalPartons.size()) == 2
918  && pTtrial > event[finalPartons[0]].pT() ) {
919  return 0.0;
920  }
921  }
922 
923  // If pT of trial emission was in suitable range (trial shower
924  // successful), return 1.0
925  if( pTtrial < pTreclus ) return 1.0;
926 
927  // Done
928  return 0.0;
929 }
930 
931 //--------------------------------------------------------------------------
932 
933 /*--------------- METHODS USED FOR CONTRUCTION OF ALL HISTORIES --------- */
934 
935 // Check if a ordered (and complete) path has been found in the
936 // initial node, in which case we will no longer be interested in
937 // any unordered paths.
938 
939 bool History::onlyOrderedPaths() {
940  if ( !mother || foundOrderedPath ) return foundOrderedPath;
941  return foundOrderedPath = mother->onlyOrderedPaths();
942 }
943 
944 //--------------------------------------------------------------------------
945 
946 // Check if a STRONGLY ordered (and complete) path has been found in the
947 // initial node, in which case we will no longer be interested in
948 // any unordered paths.
949 
950 bool History::onlyStronglyOrderedPaths() {
951  if ( !mother || foundStronglyOrderedPath ) return foundStronglyOrderedPath;
952  return foundStronglyOrderedPath = mother->onlyStronglyOrderedPaths();
953 }
954 
955 //--------------------------------------------------------------------------
956 
957 // When a full path has been found, register it with the initial
958 // history node.
959 // IN History : History to be registered as path
960 // bool : Specifying if clusterings so far were ordered
961 // bool : Specifying if path is complete down to 2->2 process
962 // OUT true if History object forms a plausible path (eg prob>0 ...)
963 
964 bool History::registerPath(History & l, bool isOrdered,
965  bool isStronglyOrdered, bool isComplete) {
966 
967  // We are not interested in improbable paths.
968  if ( l.prob <= 0.0) return false;
969  // We only register paths in the initial node.
970  if ( mother ) return mother->registerPath(l, isOrdered,
971  isStronglyOrdered, isComplete);
972  // Again, we are not interested in improbable paths.
973  if ( sumpath == sumpath + l.prob ) return false;
974  if ( mergingHooksPtr->enforceStrongOrdering()
975  && foundStronglyOrderedPath && !isStronglyOrdered ) return false;
976  if ( foundOrderedPath && !isOrdered ) return false;
977  if ( foundCompletePath && !isComplete ) return false;
978 
979  if ( mergingHooksPtr->enforceStrongOrdering() && isStronglyOrdered
980  && isComplete ) {
981  if ( !foundStronglyOrderedPath || !foundCompletePath ) {
982  // If this is the first complete, ordered path, discard the
983  // old, non-ordered or incomplete ones.
984  paths.clear();
985  sumpath = 0.0;
986  }
987 
988  foundStronglyOrderedPath = true;
989  foundCompletePath = true;
990 
991  }
992  if ( isOrdered && isComplete ) {
993  if ( !foundOrderedPath || !foundCompletePath ) {
994  // If this is the first complete, ordered path, discard the
995  // old, non-ordered or incomplete ones.
996  paths.clear();
997  sumpath = 0.0;
998  }
999  foundOrderedPath = true;
1000  foundCompletePath = true;
1001  }
1002  if ( isComplete ) {
1003  if ( !foundCompletePath ) {
1004  // If this is the first complete path, discard the old,
1005  // incomplete ones.
1006  paths.clear();
1007  sumpath = 0.0;
1008  }
1009  foundCompletePath = true;
1010  }
1011 
1012  // Index path by probability
1013  sumpath += l.prob;
1014  paths[sumpath] = &l;
1015 
1016  return true;
1017 }
1018 
1019 //--------------------------------------------------------------------------
1020 
1021 // For the history-defining state (and if necessary interfering
1022 // states), find all possible clusterings.
1023 // NO INPUT
1024 // OUT vector of all (rad,rec,emt) systems
1025 
1026 vector<Clustering> History::getAllClusterings() {
1027  vector<Clustering> ret;
1028  // Initialise vectors to keep track of position of partons in the
1029  // history-defining state
1030  vector <int> PosFinalPartn;
1031  vector <int> PosInitPartn;
1032  vector <int> PosFinalGluon;
1033  vector <int> PosFinalQuark;
1034  vector <int> PosFinalAntiq;
1035  vector <int> PosInitGluon;
1036  vector <int> PosInitQuark;
1037  vector <int> PosInitAntiq;
1038 
1039  // Search event record for final state particles and store these in
1040  // quark, anti-quark and gluon vectors
1041  for (int i=0; i < state.size(); ++i)
1042  if( state[i].isFinal() && state[i].colType() !=0 ) {
1043  // Store final partons
1044  if(state[i].id() == 21) PosFinalGluon.push_back(i);
1045  else if ( abs(state[i].id()) < 10 && state[i].id() > 0)
1046  PosFinalQuark.push_back(i);
1047  else if ( abs(state[i].id()) < 10 && state[i].id() < 0)
1048  PosFinalAntiq.push_back(i);
1049  } else if (state[i].status() == -21 && state[i].colType() != 0 ) {
1050  // Store initial partons
1051  if(state[i].id() == 21) PosInitGluon.push_back(i);
1052  else if ( abs(state[i].id()) < 10 && state[i].id() > 0)
1053  PosInitQuark.push_back(i);
1054  else if ( abs(state[i].id()) < 10 && state[i].id() < 0)
1055  PosInitAntiq.push_back(i);
1056  }
1057 
1058  // Get all clusterings for input state
1059  vector<Clustering> systems;
1060  systems = getClusterings(state);
1061  ret.insert(ret.end(), systems.begin(), systems.end());
1062  systems.resize(0);
1063 
1064  // If valid clusterings were found, return
1065  if( !ret.empty() ) return ret;
1066  // If no clusterings have been found until now, try to find
1067  // clusterings of diagrams that interfere with the current one
1068  // (i.e. change the colours of the current event slightly and run
1069  // search again)
1070  else if( ret.empty()
1071  && mergingHooksPtr->allowColourShuffling() ) {
1072  Event NewState = Event(state);
1073  // Start with changing final state quark colour
1074  for(int i = 0; i < int(PosFinalQuark.size()); ++i){
1075  // Never change the hard process candidates
1076  if( mergingHooksPtr->hardProcess.matchesAnyOutgoing(PosFinalQuark[i],
1077  NewState) )
1078  continue;
1079  int col = NewState[PosFinalQuark[i]].col();
1080  for(int j = 0; j < int(PosInitAntiq.size()); ++j){
1081  // Now swap colours
1082  int acl = NewState[PosInitAntiq[j]].acol();
1083  if( col == acl ) continue;
1084  NewState[PosFinalQuark[i]].col(acl);
1085  NewState[PosInitAntiq[j]].acol(col);
1086  systems = getClusterings(NewState);
1087  if(!systems.empty()) {
1088  state = NewState;
1089  NewState.clear();
1090  ret.insert(ret.end(), systems.begin(), systems.end());
1091  systems.resize(0);
1092  return ret;
1093  }
1094  }
1095  }
1096  // Now change final state antiquark anticolour
1097  for(int i = 0; i < int(PosFinalAntiq.size()); ++i){
1098  // Never change the hard process candidates
1099  if( mergingHooksPtr->hardProcess.matchesAnyOutgoing(PosFinalAntiq[i],
1100  NewState) )
1101  continue;
1102  int acl = NewState[PosFinalAntiq[i]].acol();
1103  for(int j = 0; j < int(PosInitQuark.size()); ++j){
1104  // Now swap colours
1105  int col = NewState[PosInitQuark[j]].col();
1106  if( col == acl ) continue;
1107  NewState[PosFinalAntiq[i]].acol(col);
1108  NewState[PosInitQuark[j]].col(acl);
1109  systems = getClusterings(NewState);
1110  if(!systems.empty()) {
1111  state = NewState;
1112  NewState.clear();
1113  ret.insert(ret.end(), systems.begin(), systems.end());
1114  systems.resize(0);
1115  return ret;
1116  }
1117  }
1118  }
1119 
1120  if(!ret.empty())
1121  infoPtr->errorMsg("Warning in History::getAllClusterings: Changed",
1122  "colour structure to allow at least one clustering");
1123  else
1124  infoPtr->errorMsg("Warning in History::getAllClusterings: No clusterings",
1125  "found. History incomplete");
1126 
1127  // If no colour rearrangements should be done, print warning and return
1128  } else {
1129  infoPtr->errorMsg("Warning in History::getAllClusterings: No clusterings",
1130  "found. History incomplete");
1131  }
1132  // Done
1133  return ret;
1134 }
1135 
1136 //--------------------------------------------------------------------------
1137 
1138 // For one given state, find all possible clusterings.
1139 // IN Event : state to be investigated
1140 // OUT vector of all (rad,rec,emt) systems in the state
1141 
1142 vector<Clustering> History::getClusterings( const Event& event) {
1143  vector<Clustering> ret;
1144 
1145  // Initialise vectors to keep track of position of partons in the
1146  // input event
1147  vector <int> PosFinalPartn;
1148  vector <int> PosInitPartn;
1149 
1150  vector <int> PosFinalGluon;
1151  vector <int> PosFinalQuark;
1152  vector <int> PosFinalAntiq;
1153 
1154  vector <int> PosInitGluon;
1155  vector <int> PosInitQuark;
1156  vector <int> PosInitAntiq;
1157 
1158  // Search event record for final state particles and store these in
1159  // quark, anti-quark and gluon vectors
1160  for (int i=0; i < event.size(); ++i)
1161  if( event[i].isFinal() && event[i].colType() !=0 ) {
1162  // Store final partons
1163  PosFinalPartn.push_back(i);
1164  if(event[i].id() == 21) PosFinalGluon.push_back(i);
1165  else if ( abs(event[i].id()) < 10 && event[i].id() > 0)
1166  PosFinalQuark.push_back(i);
1167  else if ( abs(event[i].id()) < 10 && event[i].id() < 0)
1168  PosFinalAntiq.push_back(i);
1169  } else if (event[i].status() == -21 && event[i].colType() != 0 ) {
1170  // Store initial partons
1171  PosInitPartn.push_back(i);
1172  if(event[i].id() == 21) PosInitGluon.push_back(i);
1173  else if ( abs(event[i].id()) < 10 && event[i].id() > 0)
1174  PosInitQuark.push_back(i);
1175  else if ( abs(event[i].id()) < 10 && event[i].id() < 0)
1176  PosInitAntiq.push_back(i);
1177  }
1178 
1179  int nFiGluon = int(PosFinalGluon.size());
1180  int nFiQuark = int(PosFinalQuark.size());
1181  int nFiAntiq = int(PosFinalAntiq.size());
1182  int nInGluon = int(PosInitGluon.size());
1183  int nInQuark = int(PosInitQuark.size());
1184  int nInAntiq = int(PosInitAntiq.size());
1185 
1186  vector<Clustering> systems;
1187 
1188  // Find rad + emt + rec systems:
1189  // (1) Start from gluon and find all (rad,rec,emt=gluon) triples
1190  for (int i = 0; i < nFiGluon; ++i) {
1191  int EmtGluon = PosFinalGluon[i];
1192  systems = findTriple( EmtGluon, 2, event, PosFinalPartn, PosInitPartn);
1193  ret.insert(ret.end(), systems.begin(), systems.end());
1194  systems.resize(0);
1195  }
1196 
1197  // For more than one quark-antiquark pair in final state, check for
1198  // g -> qqbar splittings
1199  bool check_g2qq = true;
1200  if( ( ( nInQuark + nInAntiq == 0 )
1201  && (nInGluon == 0)
1202  && (nFiQuark == 1) && (nFiAntiq == 1) )
1203  || ( ( nFiQuark + nFiAntiq == 0)
1204  && (nInQuark == 1) && (nInAntiq == 1) ) )
1205  check_g2qq = false;
1206 
1207  if( check_g2qq ) {
1208 
1209  // (2) Start from quark and find all (rad,rec,emt=quark) triples
1210  // ( when g -> q qbar occured )
1211  for( int i=0; i < nFiQuark; ++i) {
1212  int EmtQuark = PosFinalQuark[i];
1213  systems = findTriple( EmtQuark, 1, event, PosFinalPartn, PosInitPartn);
1214  ret.insert(ret.end(), systems.begin(), systems.end());
1215  systems.resize(0);
1216  }
1217 
1218  // (3) Start from anti-quark and find all (rad,rec,emt=anti-quark)
1219  // triples ( when g -> q qbar occured )
1220  for( int i=0; i < nFiAntiq; ++i) {
1221  int EmtAntiq = PosFinalAntiq[i];
1222  systems = findTriple( EmtAntiq, 1, event, PosFinalPartn, PosInitPartn);
1223  ret.insert(ret.end(), systems.begin(), systems.end());
1224  systems.resize(0);
1225  }
1226  }
1227 
1228  return ret;
1229 }
1230 
1231 //--------------------------------------------------------------------------
1232 
1233 // Function to construct (rad,rec,emt) triples from the event
1234 // IN int : Position of Emitted in event record for which
1235 // dipoles should be constructed
1236 // int : Colour topogy to be tested
1237 // 1= g -> qqbar, causing 2 -> 2 dipole splitting
1238 // 2= q(bar) -> q(bar) g && g -> gg,
1239 // causing a 2 -> 3 dipole splitting
1240 // Event : event record to be checked for ptential partners
1241 // OUT vector of all allowed radiator+recoiler+emitted triples
1242 
1243 vector<Clustering> History::findTriple (int EmtTagIn, int colTopIn,
1244  const Event& event,
1245  vector<int> PosFinalPartn,
1246  vector <int> PosInitPartn ) {
1247 
1248  // Copy input parton tag
1249  int EmtTag = EmtTagIn;
1250  // Copy input colour topology tag
1251  // (1: g --> qqbar splitting present, 2:rest)
1252  int colTop = colTopIn;
1253 
1254  // Initialise FinalSize
1255  int FinalSize = int(PosFinalPartn.size());
1256  int InitSize = int(PosInitPartn.size());
1257  int Size = InitSize + FinalSize;
1258 
1259  vector<Clustering> clus;
1260 
1261  // Search final partons to find partons colour-connected to
1262  // event[EmtTag], choose radiator, then choose recoiler
1263  for ( int a = 0; a < Size; ++a ) {
1264  int i = (a < FinalSize)? a : (a - FinalSize) ;
1265  int iRad = (a < FinalSize)? PosFinalPartn[i] : PosInitPartn[i];
1266 
1267  if( event[iRad].col() == event[EmtTag].col()
1268  && event[iRad].acol() == event[EmtTag].acol() )
1269  continue;
1270 
1271  if (iRad != EmtTag ) {
1272  int pTdef = event[iRad].isFinal() ? 1 : -1;
1273  int sign = (a < FinalSize)? 1 : -1 ;
1274 
1275  // First colour topology: g --> qqbar. Here, emt & rad should
1276  // have same flavour (causes problems for gamma->qqbar).
1277  if (colTop == 1) {
1278 
1279  if ( event[iRad].id() == -sign*event[EmtTag].id() ) {
1280  int col = -1;
1281  int acl = -1;
1282  if(event[iRad].id() < 0) {
1283  col = event[EmtTag].acol();
1284  acl = event[iRad].acol();
1285  } else {
1286  col = event[EmtTag].col();
1287  acl = event[iRad].col();
1288  }
1289  // Recoiler
1290  int iRec = 0;
1291  // Colour partner
1292  int iPartner = 0;
1293 
1294  if(col > 0) {
1295  // Find recoiler by colour
1296  iRec = FindCol(col,iRad,EmtTag,event,1,true);
1297  // In initial state splitting has final state colour partner,
1298  // Save both partner and recoiler
1299  if( (sign < 0) && (event[iRec].isFinal()) ){
1300  // Save colour recoiler
1301  iPartner = iRec;
1302  // Reset kinematic recoiler to initial state parton
1303  for(int l = 0; l < int(PosInitPartn.size()); ++l)
1304  if(PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
1305  // For final state splittings, colour partner and recoiler are
1306  // identical
1307  } else {
1308  iPartner = iRec;
1309  }
1310  if( iRec != 0 && iPartner != 0
1311  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ){
1312  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
1313  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
1314  continue;
1315  }
1316 
1317  // Reset partner
1318  iPartner = 0;
1319  // Find recoiler by colour
1320  iRec = FindCol(col,iRad,EmtTag,event,2,true);
1321  // In initial state splitting has final state colour partner,
1322  // Save both partner and recoiler
1323  if( (sign < 0) && (event[iRec].isFinal()) ){
1324  // Save colour recoiler
1325  iPartner = iRec;
1326  // Reset kinematic recoiler to initial state parton
1327  for(int l = 0; l < int(PosInitPartn.size()); ++l)
1328  if(PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
1329  // For final state splittings, colour partner and recoiler are
1330  // identical
1331  } else {
1332  iPartner = iRec;
1333  }
1334  if( iRec != 0 && iPartner != 0
1335  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ){
1336  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
1337  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
1338  continue;
1339  }
1340  }
1341 
1342  if(acl > 0) {
1343 
1344  // Reset partner
1345  iPartner = 0;
1346  // Find recoiler by colour
1347  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
1348  // In initial state splitting has final state colour partner,
1349  // Save both partner and recoiler
1350  if( (sign < 0) && (event[iRec].isFinal()) ){
1351  // Save colour recoiler
1352  iPartner = iRec;
1353  // Reset kinematic recoiler to initial state parton
1354  for(int l = 0; l < int(PosInitPartn.size()); ++l)
1355  if(PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
1356  // For final state splittings, colour partner and recoiler are
1357  // identical
1358  } else {
1359  iPartner = iRec;
1360  }
1361  if( iRec != 0 && iPartner != 0
1362  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ){
1363  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
1364  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
1365  continue;
1366  }
1367 
1368  // Reset partner
1369  iPartner = 0;
1370  // Find recoiler by colour
1371  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
1372  // In initial state splitting has final state colour partner,
1373  // Save both partner and recoiler
1374  if( (sign < 0) && (event[iRec].isFinal()) ){
1375  // Save colour recoiler
1376  iPartner = iRec;
1377  // Reset kinematic recoiler to initial state parton
1378  for(int l = 0; l < int(PosInitPartn.size()); ++l)
1379  if(PosInitPartn[l] != iRad) iRec = PosInitPartn[l];
1380  // For final state splittings, colour partner and recoiler are
1381  // identical
1382  } else {
1383  iPartner = iRec;
1384  }
1385  if( iRec != 0 && iPartner != 0
1386  && allowedClustering( iRad, EmtTag, iRec, iPartner, event) ){
1387  clus.push_back( Clustering(EmtTag, iRad, iRec, iPartner,
1388  pTLund(event[iRad], event[EmtTag], event[iRec], pTdef) ));
1389  continue;
1390  }
1391  }
1392  // Initial gluon splitting
1393  } else if( event[iRad].id() == 21
1394  &&( event[iRad].col() == event[EmtTag].col()
1395  || event[iRad].acol() == event[EmtTag].acol() )) {
1396  // For an initial state radiator, always set recoiler
1397  // to the other initial state parton (recoil is taken
1398  // by full remaining system, so this is just a
1399  // labelling for such a process)
1400  int RecInit = 0;
1401  for(int l = 0; l < int(PosInitPartn.size()); ++l)
1402  if(PosInitPartn[l] != iRad) RecInit = PosInitPartn[l];
1403 
1404  // Find the colour connected partner
1405  // Find colour index of radiator before splitting
1406  int col = getRadBeforeCol(iRad, EmtTag, event);
1407  int acl = getRadBeforeAcol(iRad, EmtTag, event);
1408 
1409  // Find the correct partner: If a colour line has split,
1410  // the partner is connected to the radiator before the splitting
1411  // by a colour line (same reasoning for anticolour). The colour
1412  // that split is the colour appearing twice in the
1413  // radiator + emitted pair.
1414  // Thus, if we remove a colour index with the clustering,
1415  // we should look for a colour partner, else look for
1416  // an anticolour partner
1417  int colRemove = (event[iRad].col() == event[EmtTag].col())
1418  ? event[iRad].col() : 0;
1419 
1420  int iPartner = 0;
1421  if(colRemove > 0 && col > 0)
1422  iPartner = FindCol(col,iRad,EmtTag,event,1,true)
1423  + FindCol(col,iRad,EmtTag,event,2,true);
1424  else if(colRemove > 0 && acl > 0)
1425  iPartner = FindCol(acl,iRad,EmtTag,event,1,true)
1426  + FindCol(acl,iRad,EmtTag,event,2,true);
1427 
1428  if( allowedClustering( iRad, EmtTag, RecInit, iPartner, event ) ) {
1429  clus.push_back( Clustering(EmtTag, iRad, RecInit, iPartner,
1430  pTLund(event[iRad],event[EmtTag],event[RecInit], pTdef) ));
1431  continue;
1432  }
1433 
1434  }
1435 
1436  // Second colour topology: Gluon emission
1437  } else {
1438  if ( (event[iRad].col() == event[EmtTag].acol())
1439  || (event[iRad].acol() == event[EmtTag].col())
1440  || (event[iRad].col() == event[EmtTag].col())
1441  || (event[iRad].acol() == event[EmtTag].acol()) ) {
1442  // For the rest, choose recoiler to have a common colour
1443  // tag with radiator, while not being the "Emitted"
1444 
1445  int col = -1;
1446  int acl = -1;
1447 
1448  if(event[iRad].isFinal() ) {
1449  if ( event[iRad].id() < 0) {
1450  acl = event[EmtTag].acol();
1451  col = event[iRad].col();
1452  } else if( event[iRad].id() > 0 && event[iRad].id() < 10) {
1453  col = event[EmtTag].col();
1454  acl = event[iRad].acol();
1455  } else {
1456  col = event[iRad].col();
1457  acl = event[iRad].acol();
1458  }
1459 
1460  int iRec = 0;
1461  if(col > 0) {
1462  iRec = FindCol(col,iRad,EmtTag,event,1,true);
1463  if( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
1464  if(iRec != 0
1465  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ){
1466  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
1467  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
1468  continue;
1469  }
1470 
1471  iRec = FindCol(col,iRad,EmtTag,event,2,true);
1472  if( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
1473  if(iRec != 0
1474  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ){
1475  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
1476  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
1477  continue;
1478  }
1479  }
1480 
1481  if(acl > 0) {
1482  iRec = FindCol(acl,iRad,EmtTag,event,1,true);
1483  if( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
1484  if(iRec != 0
1485  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ){
1486  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
1487  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
1488  continue;
1489  }
1490 
1491  iRec = FindCol(acl,iRad,EmtTag,event,2,true);
1492  if( (sign < 0) && (event[iRec].isFinal()) ) iRec = 0;
1493  if(iRec != 0
1494  && allowedClustering( iRad, EmtTag, iRec, iRec, event) ){
1495  clus.push_back( Clustering(EmtTag, iRad, iRec, iRec,
1496  pTLund(event[iRad],event[EmtTag],event[iRec], pTdef) ));
1497  continue;
1498  }
1499  }
1500 
1501  } else {
1502 
1503  // For an initial state radiator, always set recoiler
1504  // to the other initial state parton (recoil is taken
1505  // by full remaining system, so this is just a
1506  // labelling for such a process)
1507  int RecInit = 0;
1508  int iPartner = 0;
1509  for(int l = 0; l < int(PosInitPartn.size()); ++l)
1510  if(PosInitPartn[l] != iRad) RecInit = PosInitPartn[l];
1511 
1512  // Find the colour connected partner
1513  // Find colour index of radiator before splitting
1514  col = getRadBeforeCol(iRad, EmtTag, event);
1515  acl = getRadBeforeAcol(iRad, EmtTag, event);
1516 
1517  // Find the correct partner: If a colour line has split,
1518  // the partner is connected to the radiator before the splitting
1519  // by a colour line (same reasoning for anticolour). The colour
1520  // that split is the colour appearing twice in the
1521  // radiator + emitted pair.
1522  // Thus, if we remove a colour index with the clustering,
1523  // we should look for a colour partner, else look for
1524  // an anticolour partner
1525  int colRemove = (event[iRad].col() == event[EmtTag].col())
1526  ? event[iRad].col() : 0;
1527  iPartner = (colRemove > 0)
1528  ? FindCol(col,iRad,EmtTag,event,1,true)
1529  + FindCol(col,iRad,EmtTag,event,2,true)
1530  : FindCol(acl,iRad,EmtTag,event,1,true)
1531  + FindCol(acl,iRad,EmtTag,event,2,true);
1532 
1533  if( allowedClustering( iRad, EmtTag, RecInit, iPartner, event) ){
1534  clus.push_back( Clustering(EmtTag, iRad, RecInit, iPartner,
1535  pTLund(event[iRad],event[EmtTag],event[RecInit], pTdef)));
1536 
1537  continue;
1538  }
1539  }
1540  }
1541  }
1542  }
1543  }
1544 
1545  // Done
1546  return clus;
1547 }
1548 
1549 //--------------------------------------------------------------------------
1550 
1551 // Calculate and return the probability of a clustering.
1552 // IN Clustering : rad,rec,emt - System for which the splitting
1553 // probability should be calcuated
1554 // OUT splitting probability
1555 
1556 double History::getProb(const Clustering & SystemIn) {
1557 
1558  // Get local copies of input system
1559  int Rad = SystemIn.emittor;
1560  int Rec = SystemIn.recoiler;
1561  int Emt = SystemIn.emitted;
1562 
1563  // Initialise shower probability
1564  double showerProb = 0.0;
1565 
1566  // If the splitting resulted in disallowed evolution variable,
1567  // disallow the splitting
1568  if(SystemIn.pT() <= 0.){
1569  infoPtr->errorMsg("Warning in History::getProb: Reconstructed evolution",
1570  "variable has negative value, set splitting probability to 0.");
1571  return 0.;
1572  }
1573  // Initialise all combinatorical factors
1574  double CF = 4./3.;
1575  double NC = 3.;
1576  // Flavour is known when reclustring, thus n_f=1
1577  double NF = 1.;
1578  double TR = NF / 2.;
1579 
1580  // Split up in FSR and ISR
1581  bool isFSR = (state[Rad].isFinal() && state[Rec].isFinal());
1582  bool isFSRinREC = (state[Rad].isFinal() && !state[Rec].isFinal());
1583  bool isISR = !state[Rad].isFinal();
1584 
1585  // Check if this is the clustering 2->3 to 2->2.
1586  // If so, use weight for joined evolution
1587  int nFinal = 0;
1588  for(int i=0; i < state.size(); ++i)
1589  if(state[i].isFinal()) nFinal++;
1590  bool isLast = (nFinal == (mergingHooksPtr->hardProcess.nQuarksOut()
1591  +mergingHooksPtr->hardProcess.nLeptonOut()+1));
1592 
1593  if(isISR){
1594  // Find incoming particles
1595 
1596  int inP = 0;
1597  int inM = 0;
1598  for(int i=0;i< int(state.size()); ++i){
1599  if(state[i].mother1() == 1) inP = i;
1600  if(state[i].mother1() == 2) inM = i;
1601  }
1602  // Construct dipole mass, eCM and sHat = x1*x2*s
1603  Vec4 sum = state[Rad].p() + state[Rec].p() - state[Emt].p();
1604  double m2Dip = sum.m2Calc();
1605  double sHat = (state[inM].p() + state[inP].p()).m2Calc();
1606  // Energy fraction z=E_q1/E_qi in branch q(i)q(2) -> q(1)g(3)q(2)
1607  double z1 = m2Dip / sHat;
1608  // Virtuality of the splittings
1609  Vec4 Q1( state[Rad].p() - state[Emt].p() );
1610  Vec4 Q2( state[Rec].p() - state[Emt].p() );
1611  // Q^2 for emission off radiator line
1612  double Q1sq = -Q1.m2Calc();
1613  // pT^2 for emission off radiator line
1614  double pT1sq = pow(SystemIn.pT(),2);
1615  // Remember if massive particles involved: Mass corrections for
1616  // to g->QQ and Q->Qg splittings
1617  bool g2QQmassive = mergingHooksPtr->includeMassive()
1618  && state[Rad].id() == 21
1619  && ( abs(state[Emt].id()) >= 4 && abs(state[Emt].id()) < 7);
1620  bool Q2Qgmassive = mergingHooksPtr->includeMassive()
1621  && state[Emt].id() == 21
1622  && ( abs(state[Rad].id()) >= 4 && abs(state[Rad].id()) < 7);
1623  bool isMassive = mergingHooksPtr->includeMassive()
1624  && (g2QQmassive || Q2Qgmassive);
1625  double m2Emt0 = pow(particleDataPtr->m0(state[Emt].id()),2);
1626  double m2Rad0 = pow(particleDataPtr->m0(state[Rad].id()),2);
1627 
1628  // Correction of virtuality for massive splittings
1629  if( g2QQmassive) Q1sq += m2Emt0;
1630  else if(Q2Qgmassive) Q1sq += m2Rad0;
1631 
1632  // pT0 dependence!!!
1633  double pT0sq = pow(mergingHooksPtr->pT0ISR(),2);
1634  double Q2sq = -Q2.m2Calc();
1635 
1636  // Correction of virtuality of other splitting
1637  bool g2QQmassiveRec = mergingHooksPtr->includeMassive()
1638  && state[Rec].id() == 21
1639  && ( abs(state[Emt].id()) >= 4 && abs(state[Emt].id()) < 7);
1640  bool Q2QgmassiveRec = mergingHooksPtr->includeMassive()
1641  && state[Emt].id() == 21
1642  && ( abs(state[Rec].id()) >= 4 && abs(state[Rec].id()) < 7);
1643  double m2Rec0 = pow(particleDataPtr->m0(state[Rad].id()),2);
1644  if( g2QQmassiveRec) Q2sq += m2Emt0;
1645  else if(Q2QgmassiveRec) Q2sq += m2Rec0;
1646 
1647  bool hasJoinedEvol = (state[Emt].id() == 21
1648  || state[Rad].id() == state[Rec].id());
1649 
1650  // Initialise normalization factor multiplying the splitting
1651  // function numerator
1652  double fac = 1.;
1653  if( mergingHooksPtr->pickByFull() || mergingHooksPtr->pickBySumPT()){
1654  double facJoined = ( Q2sq + pT0sq/(1.-z1) )
1655  * 1./(Q1sq*Q2sq + pT0sq*sHat + pow(pT0sq/(1.-z1),2));
1656  double facSingle = mergingHooksPtr->nonJoinedNorm()*1./( pT1sq + pT0sq);
1657 
1658  fac = (hasJoinedEvol && isLast) ? facJoined : facSingle;
1659 
1660  } else if(mergingHooksPtr->pickByPoPT2()) {
1661  fac = 1./(pT1sq + pT0sq);
1662  } else {
1663  infoPtr->errorMsg("Error in History::getProb: Scheme for calculating",
1664  "shower splitting probability is undefined.");
1665  }
1666 
1667  // Calculate shower splitting probability:
1668  // Splitting functions*normalization*ME reweighting factors
1669 
1670  // Calculate branching probability for q -> q g
1671  if ( state[Emt].id() == 21 && state[Rad].id() != 21) {
1672  // Find splitting kernel
1673  double num = CF*(1. + pow(z1,2)) / (1.-z1);
1674  if(isMassive) num -= CF * z1 * (1.-z1) * (m2Rad0/pT1sq);
1675 
1676  // Find ME reweighting factor
1677  double meReweighting = 1.;
1678  // Find the number of final state coloured particles, apart
1679  // from those coming from the hard process
1680  int nCol = 0;
1681  for(int i=0; i < state.size(); ++i)
1682  if(state[i].isFinal() && state[i].colType() != 0
1683  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,state))
1684  nCol++;
1685  // For first splitting of single vector boson production,
1686  // apply ME corrections
1687  if(nCol == 1
1688  && int(mergingHooksPtr->hardProcess.hardIntermediate.size()) == 1){
1689  double sH = m2Dip / z1;
1690  double tH = -Q1sq;
1691  double uH = Q1sq - m2Dip * (1. - z1) / z1;
1692  double misMatch = (uH*tH - (uH + tH)*pT0sq/(1.-z1)
1693  + pow(pT0sq/(1.-z1),2) ) / (uH*tH);
1694  meReweighting *= (tH*tH + uH*uH + 2. * m2Dip * sH)
1695  / (sH*sH + m2Dip*m2Dip);
1696  meReweighting *= misMatch;
1697  }
1698  // Multiply factors
1699  showerProb = num*fac*meReweighting;
1700 
1701  // Calculate branching probability for g -> g g
1702  } else if ( state[Emt].id() == 21 && state[Rad].id() == 21) {
1703  // Calculate splitting kernel
1704  double num = 2.*NC*pow2(1. - z1*(1.-z1)) / (z1*(1.-z1));
1705  // Multiply factors
1706  showerProb = num*fac;
1707 
1708  // Calculate branching probability for q -> g q
1709  } else if ( state[Emt].id() != 21 && state[Rad].id() != 21) {
1710  // Calculate splitting kernel
1711  double num = CF*(1. + pow2(1.-z1)) / z1;
1712  // Multiply factors
1713  showerProb = num*fac;
1714 
1715  // Calculate branching probability for g -> q qbar
1716  } else if ( state[Emt].id() != 21 && state[Rad].id() == 21) {
1717  // Calculate splitting kernel
1718  double num = TR * ( pow(z1,2) + pow(1.-z1,2) );
1719  if(isMassive) num += TR * 2.*z1*(1.-z1)*(m2Emt0/pT1sq);
1720  // Calculate ME reweighting factor
1721  double meReweighting = 1.;
1722  // Find the number of final state coloured particles, apart
1723  // from those coming from the hard process
1724  int nCol = 0;
1725  for(int i=0; i < state.size(); ++i)
1726  if(state[i].isFinal() && state[i].colType() != 0
1727  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,state))
1728  nCol++;
1729  // For first splitting of single vector boson production,
1730  // apply ME corrections
1731  if(nCol == 1
1732  && int(mergingHooksPtr->hardProcess.hardIntermediate.size()) == 1){
1733  double sH = m2Dip / z1;
1734  double tH = -Q1sq;
1735  double uH = Q1sq - m2Dip * (1. - z1) / z1;
1736  swap( tH, uH);
1737  double misMatch = ( uH - pT0sq/(1.-z1) ) / uH;
1738  double me = (sH*sH + uH*uH + 2. * m2Dip * tH)
1739  / (pow2(sH - m2Dip) + m2Dip*m2Dip);
1740  // Weight with me/overestimate
1741  meReweighting *= me;
1742  meReweighting *= misMatch;
1743  }
1744  // Multiply factors
1745  showerProb = num*fac*meReweighting;
1746 
1747  // Print error if no kernel calculated
1748  } else {
1749  infoPtr->errorMsg("Error in History::getProb: Splitting kernel undefined",
1750  "in ISR clustering.");
1751  }
1752 
1753  // If corrected pT below zero in ISR, put probability to zero
1754  double m2Sister0 = pow(state[Emt].m0(),2);
1755  double pT2corr = (Q1sq - z1*(m2Dip + Q1sq)*(Q1sq + m2Sister0)/m2Dip);
1756  if(pT2corr < 0.) showerProb *= 1e-9;
1757 
1758  // If creating heavy quark by Q -> gQ then next need g -> Q + Qbar.
1759  // So minimum total mass2 is 4 * m2Sister, but use more to be safe.
1760  if ( state[Emt].id() == state[Rad].id()
1761  && ( abs(state[Rad].id()) == 4 || abs(state[Rad].id()) == 5 )) {
1762  double m2QQsister = 2.*4.*m2Sister0;
1763  double pT2QQcorr = Q1sq - z1*(m2Dip + Q1sq)*(Q1sq + m2QQsister)
1764  / m2Dip;
1765  if(pT2QQcorr < 0.0) showerProb *= 1e-9;
1766  }
1767 
1768  if(mergingHooksPtr->includeRedundant()){
1769  // Initialise the spacelike shower alpha_S
1770  AlphaStrong* asISR = mergingHooksPtr->AlphaS_ISR();
1771  double as = (*asISR).alphaS(pT1sq + pT0sq) / (2.*M_PI);
1772  // Multiply with alpha_S
1773  showerProb *= as;
1774  }
1775 
1776  // Done for ISR case, begin FSR case
1777 
1778  } else if (isFSR || isFSRinREC){
1779 
1780  // Construct dipole mass
1781  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
1782  double m2Dip = sum.m2Calc();
1783  // Construct 2->3 variables for FSR
1784  double x1 = 2. * (sum * state[Rad].p()) / m2Dip;
1785  double x2 = 2. * (sum * state[Rec].p()) / m2Dip;
1786  double prop1 = max(1e-12, 1. - x1);
1787  double prop2 = max(1e-12, 1. - x2);
1788  double x3 = max(1e-12, 2. - x1 - x2);
1789  // Energy fraction z=E_q1/E_qi in branch q(i)q(2) -> q(1)g(3)q(2)
1790  double z1 = x1/(x1 + x3);
1791 
1792  // Virtuality of the splittings
1793  Vec4 Q1( state[Rad].p() + state[Emt].p() );
1794  Vec4 Q2( state[Rec].p() + state[Emt].p() );
1795  // Q^2 for emission off radiator line
1796  double Q1sq = Q1.m2Calc();
1797  // pT^2 for emission off radiator line
1798  double pT1sq = pow(SystemIn.pT(),2);
1799  // Q^2 for emission off recoiler line
1800  double Q2sq = Q2.m2Calc();
1801 
1802  // Correction of virtuality for massive splittings
1803  double m2Rad0 = pow(particleDataPtr->m0(state[Rad].id()),2);
1804  double m2Rec0 = pow(particleDataPtr->m0(state[Rad].id()),2);
1805  if( abs(state[Rad].id()) >= 4 && abs(state[Rad].id()) < 7)
1806  Q1sq -= m2Rad0;
1807  if( abs(state[Rec].id()) >= 4 && abs(state[Rec].id()) < 7)
1808  Q2sq -= m2Rec0;
1809 
1810  // Initialise normalization factor multiplying the splitting
1811  // function numerator
1812  double fac = 1.;
1813  if( mergingHooksPtr->pickByFull() || mergingHooksPtr->pickBySumPT()){
1814  double facJoined = (1.-z1)/Q1sq * m2Dip/( Q1sq + Q2sq );
1815  double facSingle = mergingHooksPtr->fsrInRecNorm() * 1./ pT1sq;
1816  fac = (!isFSRinREC && isLast) ? facJoined : facSingle;
1817  } else if(mergingHooksPtr->pickByPoPT2()) {
1818  fac = 1. / pT1sq;
1819  } else {
1820  infoPtr->errorMsg("Error in History::getProb: Scheme for calculating",
1821  "shower splitting probability is undefined.");
1822  }
1823  // Calculate shower splitting probability:
1824  // Splitting functions*normalization*ME reweighting factors
1825 
1826  // Calculate branching probability for g -> g_1 g_2
1827  if ( state[Emt].id() == 21 && state[Rad].id() == 21) {
1828  // Calculate splitting kernel
1829  double num = 0.5* NC * (1. + pow3(z1)) / (1.-z1);
1830  // Multiply factors
1831  showerProb = num*fac;
1832 
1833  // Calculate branching probability for q -> q g with quark recoiler
1834  } else if ( state[Emt].id() == 21 && state[Rad].id() != 21
1835  && state[Rec].id() != 21) {
1836  // For a qqbar dipole in FSR, ME corrections exist and the
1837  // splitting function "z-weight" is set to 1.0 (only for 2->2 ??)
1838  double num = CF * 2./(1.-z1);
1839  // Find the number of final state coloured particles, apart
1840  // from those coming from the hard process
1841  int nCol = 0;
1842  for(int i=0; i < state.size(); ++i)
1843  if(state[i].isFinal() && state[i].colType() != 0
1844  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,state))
1845  nCol++;
1846  // Calculate splitting kernel
1847  if(nCol > 3
1848  || int(mergingHooksPtr->hardProcess.hardIntermediate.size()) > 1)
1849  num = CF * (1. + pow2(z1)) /(1.-z1);
1850  // Calculate ME reweighting factor
1851  double meReweighting = 1.;
1852  // Correct if this is the process created by the first
1853  // FSR splitting of a 2->2 process
1854  if(nCol == 3
1855  && int(mergingHooksPtr->hardProcess.hardIntermediate.size()) == 1){
1856  // Calculate the ME reweighting factor
1857  double ShowerRate1 = 2./( x3 * prop2 );
1858  double meDividingFactor1 = prop1 / x3;
1859  double me = (pow(x1,2) + pow(x2,2))/(prop1*prop2);
1860  meReweighting = meDividingFactor1 * me / ShowerRate1;
1861  }
1862  // Multiply factors
1863  showerProb = num*fac*meReweighting;
1864 
1865  // Calculate branching probability for q -> q g with gluon recoiler
1866  } else if ( state[Emt].id() == 21 && state[Rad].id() != 21
1867  && state[Rec].id() == 21) {
1868  // For qg /qbarg dipoles, the splitting function is
1869  // calculated and not weighted by a ME correction factor
1870  // Shower splitting function
1871  double num = CF * (1. + pow2(z1)) / (1.-z1);
1872  showerProb = num*fac;
1873 
1874  // Calculate branching probability for g -> q qbar
1875  } else if ( state[Emt].id() != 21) {
1876  // Get flavour of quark / antiquark
1877  int flavour = state[Emt].id();
1878  // Get correct masses for the quarks
1879  // (needed to calculate splitting function?)
1880  double mFlavour = particleDataPtr->m0(flavour);
1881  // Get mass of quark/antiquark pair
1882  double mDipole = m(state[Rad].p(), state[Emt].p());
1883  // Factor determining if gluon decay was allowed
1884  double beta = sqrtpos( 1. - 4.*pow2(mFlavour)/pow2(mDipole) );
1885  // Shower splitting function
1886  double num = 0.5*TR * ( z1*z1 + (1.-z1)*(1.-z1) );
1887  if(beta <= 0.) {
1888  infoPtr->errorMsg("Warning in History::getProb: g->qqbar",
1889  "kinematically not allowed.");
1890  }
1891 
1892  showerProb = num*fac*beta;
1893 
1894  // Print error if no kernel calculated
1895  } else {
1896  infoPtr->errorMsg("Error in History::getProb: Splitting kernel undefined",
1897  "in FSR clustering.");
1898  }
1899 
1900  if(mergingHooksPtr->includeRedundant()){
1901  // Initialise the spacelike shower alpha_S
1902  AlphaStrong* asFSR = mergingHooksPtr->AlphaS_FSR();
1903  double as = (*asFSR).alphaS(pT1sq) / (2.*M_PI);
1904  // Multiply with alpha_S
1905  showerProb *= as;
1906  }
1907 
1908  // Done for FSR
1909  } else {
1910  infoPtr->errorMsg("Error in History::getProb: Radiation could not be",
1911  "interpreted as FSR or ISR.");
1912  }
1913 
1914  if(showerProb <= 0.){
1915  infoPtr->errorMsg("Warning in History::getProb: Splitting probability",
1916  "negative, raised to 0.");
1917  showerProb = 0.;
1918  }
1919 
1920  // Done
1921  return showerProb;
1922 }
1923 
1924 
1925 //--------------------------------------------------------------------------
1926 
1927 // Set up the beams (fill the beam particles with the correct
1928 // current incoming particles) to allow calculation of splitting
1929 // probability.
1930 // For interleaved evolution, set assignments dividing PDFs into
1931 // sea and valence content. This assignment is, until a history path
1932 // is chosen and a first trial shower performed, not fully correct
1933 // (since content is chosen form too high x and too low scale). The
1934 // assignment used for reweighting will be corrected after trial
1935 // showering
1936 
1937 void History::setupBeams(){
1938 
1939  // Do nothing for empty event, possible if sequence of
1940  // clusterings was ill-advised in that it results in
1941  // colour-disconnected states
1942  if(state.size() < 4) return;
1943  // Do nothing for e+e- beams
1944  if( state[3].colType() == 0 ) return;
1945  if( state[4].colType() == 0 ) return;
1946 
1947  // Incoming partons to hard process are stored in slots 3 and 4.
1948  int inS = 0;
1949  int inP = 0;
1950  int inM = 0;
1951  for(int i=0;i< int(state.size()); ++i){
1952  if(state[i].mother1() == 1) inP = i;
1953  if(state[i].mother1() == 2) inM = i;
1954  }
1955 
1956  // Save some info before clearing beams
1957  // Mothers of incoming partons companion code
1958  int motherPcompRes = -1;
1959  int motherMcompRes = -1;
1960 
1961  bool sameFlavP = false;
1962  bool sameFlavM = false;
1963 
1964  if(mother) {
1965  int inMotherP = 0;
1966  int inMotherM = 0;
1967  for(int i=0;i< int(mother->state.size()); ++i){
1968  if(mother->state[i].mother1() == 1) inMotherP = i;
1969  if(mother->state[i].mother1() == 2) inMotherM = i;
1970  }
1971  sameFlavP = (state[inP].id() == mother->state[inMotherP].id());
1972  sameFlavM = (state[inM].id() == mother->state[inMotherM].id());
1973 
1974  motherPcompRes = (sameFlavP) ? beamA[0].companion() : -2;
1975  motherMcompRes = (sameFlavM) ? beamB[0].companion() : -2;
1976  }
1977 
1978  // Append the current incoming particles to the beam
1979  beamA.clear();
1980  beamB.clear();
1981 
1982  // Get energy of incoming particles
1983  double Ep = 2. * state[inP].e();
1984  double Em = 2. * state[inM].e();
1985 
1986  // If incoming partons are massive then recalculate to put them massless.
1987  if (state[inP].m() != 0. || state[inM].m() != 0.) {
1988  Ep = state[inP].pPos() + state[inM].pPos();
1989  Em = state[inP].pNeg() + state[inM].pNeg();
1990  }
1991 
1992  // Add incoming hard-scattering partons to list in beam remnants.
1993  double x1 = Ep / state[inS].m();
1994  beamA.append( inP, state[inP].id(), x1);
1995  double x2 = Em / state[inS].m();
1996  beamB.append( inM, state[inM].id(), x2);
1997 
1998  // Scale. For ME multiplicity history, put scale to mu_F
1999  // (since sea/valence quark content is chosen from this scale)
2000  double scalePDF = (mother) ? scale : infoPtr->QFac();
2001  // Find whether incoming partons are valence or sea. Store.
2002  // Can I do better, e.g. by setting the scale to the hard process
2003  // scale (= M_W) or by replacing one of the x values by some x/z??
2004  beamA.xfISR( 0, state[inP].id(), x1, scalePDF*scalePDF);
2005  if(!mother){
2006  beamA.pickValSeaComp();
2007  } else {
2008  beamA[0].companion(motherPcompRes);
2009  }
2010  beamB.xfISR( 0, state[inM].id(), x2, scalePDF*scalePDF);
2011  if(!mother){
2012  beamB.pickValSeaComp();
2013  } else {
2014  beamB[0].companion(motherMcompRes);
2015  }
2016 
2017 }
2018 
2019 //--------------------------------------------------------------------------
2020 
2021 // Calculate the PDF ratio used in the argument of the no-emission
2022 // probability
2023 
2024 double History::pdfForSudakov() {
2025 
2026  // Do nothing for e+e- beams
2027  if( state[3].colType() == 0 ) return 1.0;
2028  if( state[4].colType() == 0 ) return 1.0;
2029 
2030  // Check if splittings was ISR or FSR
2031  bool FSR = ( mother->state[clusterIn.emittor].isFinal()
2032  && mother->state[clusterIn.recoiler].isFinal());
2033  bool FSRinRec = ( mother->state[clusterIn.emittor].isFinal()
2034  && !mother->state[clusterIn.recoiler].isFinal());
2035 
2036  // Done for pure FSR
2037  if(FSR) return 1.0;
2038 
2039  int iInMother = (FSRinRec)? clusterIn.recoiler : clusterIn.emittor;
2040  // Find side of event that was reclustered
2041  int side = ( mother->state[iInMother].pz() > 0 ) ? 1 : -1;
2042 
2043  int inP = 0;
2044  int inM = 0;
2045  for(int i=0;i< int(state.size()); ++i){
2046  if(state[i].mother1() == 1) inP = i;
2047  if(state[i].mother1() == 2) inM = i;
2048  }
2049 
2050  // Save mother id
2051  int idMother = mother->state[iInMother].id();
2052  // Find daughter position and id
2053  int iDau = (side == 1) ? inP : inM;
2054  int idDaughter = state[iDau].id();
2055  // Get mother x value
2056  double xMother = 2. * mother->state[iInMother].e() / mother->state[0].e();
2057  // Get daughter x value of daughter
2058  double xDaughter = 2.*state[iDau].e() / state[0].e(); // x1 before isr
2059 
2060  // Calculate pdf ratio
2061  double ratio = getPDFratio(side, true, idMother, xMother, scale,
2062  idDaughter, xDaughter, scale);
2063 
2064  // For FSR with incoming recoiler, maximally return 1.0, as
2065  // is done in Pythia::TimeShower.
2066  // For ISR, return ratio
2067  return ( (FSRinRec)? min(1.,ratio) : ratio);
2068 }
2069 
2070 //--------------------------------------------------------------------------
2071 
2072 // Perform the clustering of the current state and return the
2073 // clustered state.
2074 // IN Clustering : rad,rec,emt triple to be clustered to two partons
2075 // OUT clustered state
2076 
2077 Event History::cluster(const Clustering & inSystem) {
2078 
2079  // Initialise tags of particles to be changed
2080  int Rad = inSystem.emittor;
2081  int Rec = inSystem.recoiler;
2082  int Emt = inSystem.emitted;
2083  // Initialise eCM,mHat
2084  double eCM = state[0].e();
2085  // Flags for type of radiation
2086  int radType = state[Rad].isFinal() ? 1 : -1;
2087  int recType = state[Rec].isFinal() ? 1 : -1;
2088 
2089  // Construct the clustered event
2090  Event NewEvent = Event();
2091  NewEvent.init("(hard process-modified)", particleDataPtr);
2092  NewEvent.clear();
2093  // Copy all unchanged particles to NewEvent
2094  for (int i = 0; i < state.size(); ++i)
2095  if( i != Rad && i != Rec && i != Emt )
2096  NewEvent.append( state[i] );
2097 
2098  // Copy all the junctions one by one
2099  for (int i = 0; i < state.sizeJunction(); ++i)
2100  NewEvent.appendJunction( state.getJunction(i) );
2101  // Set particle data table pointer
2102  NewEvent.setPDTPtr();
2103  // Find an appropriate scale for the hard process
2104  double mu = choseHardScale(state);
2105  // Initialise scales for new event
2106  NewEvent.saveSize();
2107  NewEvent.saveJunctionSize();
2108  NewEvent.scale(mu);
2109  NewEvent.scaleSecond(mu);
2110 
2111  // Set properties of radiator/recoiler after the clustering
2112  // Recoiler properties will be unchanged
2113  Particle RecBefore = Particle( state[Rec] );
2114  RecBefore.daughters(0,0);
2115  // Find flavour of radiator before splitting
2116  int radID = getRadBeforeFlav(Rad, Emt, state);
2117  Particle RadBefore = Particle( state[Rad] );
2118  RadBefore.id(radID);
2119  RadBefore.daughters(0,0);
2120  // Put dummy values for colours
2121  RadBefore.cols(RecBefore.acol(),RecBefore.col());
2122  // Put mass for radiator and recoiler
2123  RecBefore.m(particleDataPtr->m0(state[Rec].id()));
2124  RadBefore.m(particleDataPtr->m0(radID));
2125 
2126  // Construct momenta and colours of clustered particles
2127  // ISR/FSR splittings are treated differently
2128  if(radType + recType == 2){
2129  // Clustering of final(rad)/final(rec) dipole splitting
2130  // Get eCM of (rad,rec,emt) triple
2131  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
2132  double eCMME = sum.mCalc();
2133 
2134  // Define radiator and recoiler back-to-back in the dipole
2135  // rest frame [=(state[rad]+state[emt])+state[rec] rest frame]
2136  Vec4 Rad4mom;
2137  Vec4 Rec4mom;
2138  Rad4mom.p( 0., 0., 0.5*eCMME, 0.5*eCMME);
2139  Rec4mom.p( 0., 0.,-0.5*eCMME, 0.5*eCMME);
2140 
2141  // Find boost from Rad4mom+Rec4mom rest frame to event cm frame
2142  Vec4 old1 = Vec4(state[Rad].p() + state[Emt].p());
2143  Vec4 old2 = Vec4(state[Rec].p());
2144  RotBstMatrix fromCM;
2145  fromCM.fromCMframe(old1, old2);
2146  // Transform momenta
2147  Rad4mom.rotbst(fromCM);
2148  Rec4mom.rotbst(fromCM);
2149 
2150  RadBefore.p(Rad4mom);
2151  RecBefore.p(Rec4mom);
2152 
2153  } else if(radType + recType == 0) {
2154  // Clustering of final(rad)/initial(rec) dipole splitting
2155  // Get eCM of (rad,rec,emt) triple
2156  Vec4 sum = state[Rad].p() + state[Rec].p() + state[Emt].p();
2157  double eCMME = sum.mCalc();
2158  // Define radiator and recoiler back-to-back in the dipole
2159  // rest frame [=(state[rad]+state[emt])+state[rec] rest frame]
2160  Vec4 Rad4mom;
2161  Vec4 Rec4mom;
2162  Rad4mom.p( 0., 0., 0.5*eCMME, 0.5*eCMME);
2163  Rec4mom.p( 0., 0.,-0.5*eCMME, 0.5*eCMME);
2164 
2165  // Find boost from Rad4mom+Rec4mom rest frame to event cm frame
2166  Vec4 old1 = Vec4(state[Rad].p() + state[Emt].p());
2167  Vec4 old2 = Vec4(state[Rec].p());
2168  RotBstMatrix fromCM;
2169  fromCM.fromCMframe(old1, old2);
2170  // Transform momenta
2171  Rad4mom.rotbst(fromCM);
2172  Rec4mom.rotbst(fromCM);
2173 
2174  // Rescale recoiler momentum
2175  Rec4mom = 2.*state[Rec].p() - Rec4mom;
2176 
2177  RadBefore.p(Rad4mom);
2178  RecBefore.p(Rec4mom);
2179 
2180  // Set mass of initial recoiler to zero
2181  RecBefore.m( 0.0 );
2182 
2183  } else {
2184  // Clustering of initial(rad)/initial(rec) dipole splitting
2185  // We want to cluster: Meaning doing the inverse of a process
2186  // ( pDaughter + pRecoiler -> pOut )
2187  // ==> ( pMother + pPartner -> pOut' + pSister )
2188  // produced by an initial state splitting. The matrix element
2189  // provides us with pMother, pPartner, pSister and pOut'
2190  Vec4 pMother( state[Rad].p() );
2191  Vec4 pSister( state[Emt].p() );
2192  Vec4 pPartner( state[Rec].p() );
2193  Vec4 pDaughter( 0.,0.,0.,0. );
2194  Vec4 pRecoiler( 0.,0.,0.,0. );
2195 
2196  // Find side that radiates event (mother moving in
2197  // sign * p_z direction)
2198  int sign = state[Rad].pz() > 0 ? 1 : -1;
2199 
2200  // Find rotation by phi that would have been done for a
2201  // splitting daughter -> mother + sister
2202  double phi = pSister.phi();
2203  // Find rotation with -phi
2204  RotBstMatrix rot_by_mphi;
2205  rot_by_mphi.rot(0.,-phi);
2206  // Find rotation with +phi
2207  RotBstMatrix rot_by_pphi;
2208  rot_by_pphi.rot(0.,phi);
2209 
2210  // Transform pMother and outgoing momenta
2211  pMother.rotbst( rot_by_mphi );
2212  pSister.rotbst( rot_by_mphi );
2213  pPartner.rotbst( rot_by_mphi );
2214  for(int i=3; i< NewEvent.size(); ++i)
2215  NewEvent[i].rotbst( rot_by_mphi );
2216 
2217  // Get mother and partner x values
2218  // x1 after isr
2219  double x1 = 2. * pMother.e() / eCM;
2220  // x2 after isr
2221  double x2 = 2. * pPartner.e() / eCM;
2222 
2223  pDaughter.p( pMother - pSister);
2224  pRecoiler.p( pPartner );
2225 
2226  // Find boost from event cm frame to rest frame of
2227  // of-shell daughter + on-shell recoiler
2228  RotBstMatrix from_CM_to_DR;
2229  if(sign == 1)
2230  from_CM_to_DR.toCMframe(pDaughter, pRecoiler);
2231  else
2232  from_CM_to_DR.toCMframe(pRecoiler, pDaughter);
2233 
2234  // Transform all momenta
2235  pMother.rotbst( from_CM_to_DR );
2236  pPartner.rotbst( from_CM_to_DR );
2237  pSister.rotbst( from_CM_to_DR );
2238  for(int i=3; i< NewEvent.size(); ++i)
2239  NewEvent[i].rotbst( from_CM_to_DR );
2240 
2241  // Find theta angle between pMother and z-axis and undo
2242  // rotation that would have been done by shower
2243  double theta = pMother.theta();
2244  if( pMother.px() < 0. ) theta *= -1.;
2245  if(sign == -1) theta += M_PI;
2246  // Find rotation by +theta
2247  RotBstMatrix rot_by_ptheta;
2248  rot_by_ptheta.rot(theta, 0.);
2249 
2250  // Transform all momenta
2251  pMother.rotbst( rot_by_ptheta );
2252  pPartner.rotbst( rot_by_ptheta );
2253  pSister.rotbst( rot_by_ptheta );
2254  for(int i=3; i< NewEvent.size(); ++i)
2255  NewEvent[i].rotbst( rot_by_ptheta );
2256 
2257  // Find z of the splitting
2258  Vec4 qDip( pMother - pSister);
2259  Vec4 qAfter(pMother + pPartner);
2260  Vec4 qBefore(qDip + pPartner);
2261  double z = qBefore.m2Calc() / qAfter.m2Calc();
2262 
2263  // Calculate new e_CM^2
2264  double x1New = z*x1; // x1 before isr
2265  double x2New = x2; // x2 before isr
2266  double sHat = x1New*x2New*eCM*eCM;
2267 
2268  // Construct daughter and recoiler momenta
2269  pDaughter.p( 0., 0., sign*0.5*sqrt(sHat), 0.5*sqrt(sHat));
2270  pRecoiler.p( 0., 0., -sign*0.5*sqrt(sHat), 0.5*sqrt(sHat));
2271 
2272  // Find boost from current (daughter+recoiler rest frame)
2273  // frame to rest frame of daughter+unchanged recoiler to
2274  // recover the old x2 value
2275  RotBstMatrix from_DR_to_CM;
2276  from_DR_to_CM.bst( 0., 0., sign*( x1New - x2New ) / ( x1New + x2New ) );
2277 
2278  // Correct for momentum mismatch by transforming all momenta
2279  pMother.rotbst( from_DR_to_CM );
2280  pPartner.rotbst( from_DR_to_CM );
2281  pSister.rotbst( from_DR_to_CM );
2282  pDaughter.rotbst( from_DR_to_CM );
2283  pRecoiler.rotbst( from_DR_to_CM );
2284  for(int i=3; i< NewEvent.size(); ++i)
2285  NewEvent[i].rotbst( from_DR_to_CM );
2286 
2287  // Transform pMother and outgoing momenta
2288  pMother.rotbst( rot_by_pphi );
2289  pPartner.rotbst( rot_by_pphi );
2290  pSister.rotbst( rot_by_pphi );
2291  pDaughter.rotbst( rot_by_pphi );
2292  pRecoiler.rotbst( rot_by_pphi );
2293  for(int i=3; i< NewEvent.size(); ++i)
2294  NewEvent[i].rotbst( rot_by_pphi );
2295 
2296  // Set momenta of particles to be attached to new event record
2297  RecBefore.p( pRecoiler );
2298  RadBefore.p( pDaughter );
2299 
2300  }
2301 
2302  // Put some dummy production scales for RecBefore, RadBefore
2303  RecBefore.scale(mu);
2304  RadBefore.scale(mu);
2305  RecBefore.setPDTPtr(particleDataPtr);
2306  RadBefore.setPDTPtr(particleDataPtr);
2307 
2308  // Append new recoiler and find new radiator colour
2309  NewEvent.append(RecBefore);
2310  // Assign the correct colour to re-clustered radiator
2311  if( !connectRadiator( RadBefore, radType, RecBefore, recType, NewEvent) ){
2312  // Could happen if previous clustering produced several colour
2313  // singlett subsystems in the event
2314  NewEvent.reset();
2315  return NewEvent;
2316  }
2317 
2318  // Build the clustered event
2319  Event outState = Event();
2320  outState.init("(hard process-modified)", particleDataPtr);
2321  outState.clear();
2322 
2323  // Copy system and incoming beam particles to outState
2324  for (int i = 0; i < 3; ++i)
2325  outState.append( NewEvent[i] );
2326  // Copy all the junctions one by one
2327  for (int i = 0; i < state.sizeJunction(); ++i)
2328  outState.appendJunction( state.getJunction(i) );
2329  // Set particle data table pointer
2330  outState.setPDTPtr();
2331  // Initialise scales for new event
2332  outState.saveSize();
2333  outState.saveJunctionSize();
2334  outState.scale(mu);
2335  outState.scaleSecond(mu);
2336  bool radAppended = false;
2337  bool recAppended = false;
2338  int size = int(outState.size());
2339  // Save position of radiator in new event record
2340  int radPos = 0;
2341  // Append first incoming particle
2342  if( RecBefore.mother1() == 1){
2343  outState.append( RecBefore );
2344  recAppended = true;
2345  } else if( RadBefore.mother1() == 1 ){
2346  radPos = outState.append( RadBefore );
2347  radAppended = true;
2348  } else {
2349  // Find second incoming in input event
2350  int in1 = 0;
2351  for(int i=0; i < int(state.size()); ++i)
2352  if(state[i].mother1() == 1) in1 =i;
2353  outState.append( state[in1] );
2354  size++;
2355  }
2356  // Append second incoming particle
2357  if( RecBefore.mother1() == 2){
2358  outState.append( RecBefore );
2359  recAppended = true;
2360  } else if( RadBefore.mother1() == 2 ){
2361  radPos = outState.append( RadBefore );
2362  radAppended = true;
2363  } else {
2364  // Find second incoming in input event
2365  int in2 = 0;
2366  for(int i=0; i < int(state.size()); ++i)
2367  if(state[i].mother1() == 2) in2 =i;
2368 
2369  outState.append( state[in2] );
2370  size++;
2371  }
2372 
2373  // Append new recoiler if not done already
2374  if(!recAppended && !RecBefore.isFinal()){
2375  recAppended = true;
2376  outState.append( RecBefore);
2377  }
2378  // Append new radiator if not done already
2379  if(!radAppended && !RadBefore.isFinal()){
2380  radAppended = true;
2381  radPos = outState.append( RadBefore);
2382  }
2383 
2384  // Append intermediate particle
2385  // (careful not to append reclustered recoiler)
2386  for (int i = 0; i < int(NewEvent.size()-1); ++i)
2387  if(NewEvent[i].status() == -22) outState.append( NewEvent[i] );
2388 
2389  if(!recAppended) outState.append(RecBefore);
2390  if(!radAppended) radPos = outState.append(RadBefore);
2391 
2392  // Append final state particles, partons first (not reclustered recoiler)
2393  for(int i = 0; i < int(NewEvent.size()-1); ++i)
2394  if(NewEvent[i].colType() != 0 && NewEvent[i].isFinal())
2395  outState.append( NewEvent[i] );
2396 
2397  for(int i = 0; i < int(NewEvent.size()-1); ++i)
2398  if(NewEvent[i].colType() == 0 && NewEvent[i].isFinal())
2399  outState.append( NewEvent[i]);
2400 
2401  // Find intermediate and respective daughters
2402  vector<int> PosIntermediate;
2403  vector<int> PosDaughter1;
2404  vector<int> PosDaughter2;
2405  for(int i=0; i < int(outState.size()); ++i)
2406  if(outState[i].status() == -22) {
2407  PosIntermediate.push_back(i);
2408  int d1 = outState[i].daughter1();
2409  int d2 = outState[i].daughter2();
2410  // Find daughters in output state
2411  int daughter1 = FindParticle( state[d1], outState);
2412  int daughter2 = FindParticle( state[d2], outState);
2413  // If both daughters found, done
2414  // Else put first final particle as first daughter
2415  // and last final particle as second daughter
2416  if(daughter1 > 0)
2417  PosDaughter1.push_back( daughter1);
2418  else {
2419  daughter1 = 0;
2420  while(!outState[daughter1].isFinal() ) daughter1++;
2421  PosDaughter1.push_back( daughter1);
2422  }
2423  if(daughter2 > 0)
2424  PosDaughter2.push_back( daughter2);
2425  else {
2426  daughter2 = outState.size()-1;
2427  while(!outState[daughter2].isFinal() ) daughter2--;
2428  PosDaughter2.push_back( daughter2);
2429  }
2430  }
2431 
2432  // Set daughters and mothers
2433  for(int i=0; i < int(PosIntermediate.size()); ++i){
2434  outState[PosIntermediate[i]].daughters(PosDaughter1[i],PosDaughter2[i]);
2435  outState[PosDaughter1[i]].mother1(PosIntermediate[i]);
2436  outState[PosDaughter2[i]].mother1(PosIntermediate[i]);
2437  }
2438 
2439  // Find range of final state partons
2440  int minParFinal = int(outState.size());
2441  int maxParFinal = 0;
2442  for(int i=0; i < int(outState.size()); ++i)
2443  if(outState[i].mother1() == 3 && outState[i].mother2() == 4){
2444  minParFinal = min(i,minParFinal);
2445  maxParFinal = max(i,maxParFinal);
2446  }
2447 
2448  if(minParFinal == maxParFinal) maxParFinal = 0;
2449  outState[3].daughters(minParFinal,maxParFinal);
2450  outState[4].daughters(minParFinal,maxParFinal);
2451 
2452  // Update event properties
2453  outState.saveSize();
2454  outState.saveJunctionSize();
2455 
2456  // Almost there...
2457  // If an intermediate coloured parton exists which was directly
2458  // colour connected to the radiator before the splitting, and the
2459  // radiator before and after the splitting had only one colour, problems
2460  // will arise since the colour of the radiator will be changed, whereas
2461  // the intermediate parton still has the old colour. In effect, this
2462  // means that when setting up a event for trial showering, one colour will
2463  // be free.
2464  // Hence, check for an intermediate coloured triplet resonance has been
2465  // colour-connected to the "old" radiator.
2466  // Find resonance
2467  int iColRes = 0;
2468  if( radType == -1 && state[Rad].colType() == 1){
2469  // Find resonance connected to initial colour
2470  for(int i=0; i < int(state.size()); ++i)
2471  if( i != Rad && i != Emt && i != Rec
2472  && state[i].status() == -22
2473  && state[i].col() == state[Rad].col() )
2474  iColRes = i;
2475  } else if( radType == -1 && state[Rad].colType() == -1){
2476  // Find resonance connected to initial anticolour
2477  for(int i=0; i < int(state.size()); ++i)
2478  if( i != Rad && i != Emt && i != Rec
2479  && state[i].status() == -22
2480  && state[i].acol() == state[Rad].acol() )
2481  iColRes = i;
2482  } else if( radType == 1 && state[Rad].colType() == 1){
2483  // Find resonance connected to final state colour
2484  for(int i=0; i < int(state.size()); ++i)
2485  if( i != Rad && i != Emt && i != Rec
2486  && state[i].status() == -22
2487  && state[i].acol() == state[Rad].col() )
2488  iColRes = i;
2489  } else if( radType == 1 && state[Rad].colType() == -1){
2490  // Find resonance connected to final state anticolour
2491  for(int i=0; i < int(state.size()); ++i)
2492  if( i != Rad && i != Emt && i != Rec
2493  && state[i].status() == -22
2494  && state[i].col() == state[Rad].acol() )
2495  iColRes = i;
2496  }
2497 
2498  if(iColRes > 0) {
2499  // Now find this resonance in the reclustered state
2500  int iColResNow = FindParticle( state[iColRes], outState);
2501  // Find reclustered radiator colours
2502  int radCol = outState[radPos].col();
2503  int radAcl = outState[radPos].acol();
2504  // Find resonance radiator colours
2505  int resCol = outState[iColResNow].col();
2506  int resAcl = outState[iColResNow].acol();
2507  // Check if any of the reclustered radiators colours match the resonance
2508  bool matchesRes = (radCol > 0
2509  && ( radCol == resCol || radCol == resAcl))
2510  || (radAcl > 0
2511  && ( radAcl == resCol || radAcl == resAcl));
2512 
2513  // If a resonance has been found, but no colours match, change
2514  // the colour of the resonance
2515  if(!matchesRes && iColResNow > 0) {
2516  if( radType == -1 && outState[radPos].colType() == 1)
2517  outState[iColResNow].col(radCol);
2518  else if( radType ==-1 && outState[radPos].colType() ==-1)
2519  outState[iColResNow].acol(radAcl);
2520  else if( radType == 1 && outState[radPos].colType() == 1)
2521  outState[iColResNow].acol(radCol);
2522  else if( radType == 1 && outState[radPos].colType() ==-1)
2523  outState[iColResNow].col(radAcl);
2524  }
2525  }
2526 
2527  // If event is not constructed properly, return false
2528  if ( !validEvent(outState) ){
2529  outState.reset();
2530  return outState;
2531  }
2532 
2533  // Done
2534  return outState;
2535 }
2536 
2537 //--------------------------------------------------------------------------
2538 
2539 // Function to get the flavour of the radiator before the splitting
2540 // for clustering
2541 // IN int : Flavour of the radiator after the splitting
2542 // int : Flavour of the emitted after the splitting
2543 // OUT int : Flavour of the radiator before the splitting
2544 
2545 int History::getRadBeforeFlav(const int RadAfter, const int EmtAfter,
2546  const Event& event){
2547 
2548  int type = event[RadAfter].isFinal() ? 1 :-1;
2549  int emtID = event[EmtAfter].id();
2550  int radID = event[RadAfter].id();
2551  int emtCOL = event[EmtAfter].col();
2552  int radCOL = event[RadAfter].col();
2553  int emtACL = event[EmtAfter].acol();
2554  int radACL = event[RadAfter].acol();
2555 
2556  bool colConnected = ((type == 1) && ( (emtCOL !=0 && (emtCOL ==radACL))
2557  || (emtACL !=0 && (emtACL ==radCOL)) ))
2558  ||((type ==-1) && ( (emtCOL !=0 && (emtCOL ==radCOL))
2559  || (emtACL !=0 && (emtACL ==radACL)) ));
2560  // QCD splittings
2561  // Gluon radiation
2562  if( emtID == 21)
2563  return radID;
2564  // Final state gluon splitting
2565  if( type == 1 && emtID == -radID && !colConnected)
2566  return 21;
2567  // Initial state s-channel gluon splitting
2568  if( type ==-1 && radID == 21)
2569  return -emtID;
2570  // Initial state t-channel gluon splitting
2571  if( type ==-1 && emtID != 21 && radID != 21 && !colConnected)
2572  return 21;
2573 
2574  // Electroweak splittings splittings
2575  // Photon / Z radiation: Calculate invariant mass of system
2576  double m2final = (event[RadAfter].p()+ event[EmtAfter].p()).m2Calc();
2577 
2578  if( emtID == 22 || emtID == 23) return radID;
2579  // Final state Photon splitting
2580  if( type == 1 && emtID == -radID && colConnected && sqrt(m2final) <= 10. )
2581  return 22;
2582  // Final state Photon splitting
2583  if( type == 1 && emtID == -radID && colConnected && sqrt(m2final) > 10. )
2584  return 23;
2585  // Initial state s-channel photon/ Z splitting
2586  if( type ==-1 && (radID == 22 || radID == 23))
2587  return -emtID;
2588  // Initial state t-channel photon / Z splitting: Always bookkeep as photon
2589  if( type ==-1 && abs(emtID) < 10 && abs(radID) < 10 && colConnected)
2590  return 22;
2591 
2592  // W+ radiation
2593  // Final state W+ splitting
2594 
2595  return 0;
2596 
2597 }
2598 
2599 //--------------------------------------------------------------------------
2600 
2601 // Function to properly colour-connect the radiator to the rest of
2602 // the event, as needed during clustering
2603 // IN Particle& : Particle to be connected
2604 // Particle : Recoiler forming a dipole with Radiator
2605 // Event : event to which Radiator shall be appended
2606 // OUT true : Radiator could be connected to the event
2607 // false : Radiator could not be connected to the
2608 // event or the resulting event was
2609 // non-valid
2610 
2611 bool History::connectRadiator( Particle& Radiator, const int RadType,
2612  const Particle& Recoiler, const int RecType,
2613  const Event& event ){
2614 
2615  // Start filling radiator colour indices with dummy values
2616  Radiator.cols( -1, -1 );
2617 
2618  // Radiator should always be colour-connected to recoiler.
2619  // Three cases (rad = Anti-Quark, Quark, Gluon) to be considered
2620  if( Radiator.colType() == -1 ) {
2621  // For final state antiquark radiator, the anticolour is fixed
2622  // by the final / initial state recoiler colour / anticolour
2623  if( RadType + RecType == 2 )
2624  Radiator.cols( 0, Recoiler.col());
2625  else if( RadType + RecType == 0 )
2626  Radiator.cols( 0, Recoiler.acol());
2627  // For initial state antiquark radiator, the anticolour is fixed
2628  // by the colour of the emitted gluon (which will be the
2629  // leftover anticolour of a final state particle or the leftover
2630  // colour of an initial state particle ( = the recoiler))
2631  else {
2632  // Set colour of antiquark radiator to zero
2633  Radiator.col( 0 );
2634  for (int i = 0; i < event.size(); ++i) {
2635  int col = event[i].col();
2636  int acl = event[i].acol();
2637 
2638  if( event[i].isFinal()) {
2639  // Search for leftover anticolour in final / initial state
2640  if( acl > 0 && FindCol(acl,i,0,event,1,true) == 0
2641  && FindCol(acl,i,0,event,2,true) == 0 )
2642  Radiator.acol(event[i].acol());
2643  } else {
2644  // Search for leftover colour in initial / final state
2645  if( col > 0 && FindCol(col,i,0,event,1,true) == 0
2646  && FindCol(col,i,0,event,2,true) == 0 )
2647  Radiator.acol(event[i].col());
2648  }
2649  } // end loop over particles in event record
2650  }
2651 
2652  } else if ( Radiator.colType() == 1 ) {
2653  // For final state quark radiator, the colour is fixed
2654  // by the final / initial state recoiler anticolour / colour
2655  if( RadType + RecType == 2 )
2656  Radiator.cols( Recoiler.acol(), 0);
2657  else if( RadType + RecType == 0 )
2658  Radiator.cols( Recoiler.col(), 0);
2659  // For initial state quark radiator, the colour is fixed
2660  // by the anticolour of the emitted gluon (which will be the
2661  // leftover colour of a final state particle or the leftover
2662  // anticolour of an initial state particle ( = the recoiler))
2663 
2664  else {
2665  // Set anticolour of quark radiator to zero
2666  Radiator.acol( 0 );
2667  for (int i = 0; i < event.size(); ++i) {
2668  int col = event[i].col();
2669  int acl = event[i].acol();
2670 
2671  if( event[i].isFinal()) {
2672  // Search for leftover colour in final / initial state
2673  if( col > 0 && FindCol(col,i,0,event,1,true) == 0
2674  && FindCol(col,i,0,event,2,true) == 0)
2675  Radiator.col(event[i].col());
2676  } else {
2677  // Search for leftover anticolour in initial / final state
2678  if( acl > 0 && FindCol(acl,i,0,event,1,true) == 0
2679  && FindCol(acl,i,0,event,2,true) == 0)
2680  Radiator.col(event[i].acol());
2681  }
2682  } // end loop over particles in event record
2683 
2684  } // end distinction between fsr / fsr+initial recoiler / isr
2685 
2686  } else if ( Radiator.colType() == 2 ) {
2687  // For a gluon radiator, one (anticolour) colour index is defined
2688  // by the recoiler colour (anticolour).
2689  // The remaining index is chosen to match the free index in the
2690  // event
2691  // Search for leftover colour (anticolour) in the final state
2692  for (int i = 0; i < event.size(); ++i) {
2693  int col = event[i].col();
2694  int acl = event[i].acol();
2695  int iEx = i;
2696 
2697  if( event[i].isFinal()) {
2698  if( col > 0 && FindCol(col,iEx,0,event,1,true) == 0
2699  && FindCol(col,iEx,0,event,2,true) == 0){
2700  if(Radiator.status() < 0 ) Radiator.col(event[i].col());
2701  else Radiator.acol(event[i].col());
2702  }
2703  if( acl > 0 && FindCol(acl,iEx,0,event,2,true) == 0
2704  && FindCol(acl,iEx,0,event,1,true) == 0 ){
2705  if(Radiator.status() < 0 ) Radiator.acol(event[i].acol());
2706  else Radiator.col(event[i].acol());
2707  }
2708  } else {
2709  if( col > 0 && FindCol(col,iEx,0,event,1,true) == 0
2710  && FindCol(col,iEx,0,event,2,true) == 0){
2711  if(Radiator.status() < 0 ) Radiator.acol(event[i].col());
2712  else Radiator.col(event[i].col());
2713  }
2714  if( acl > 0 && (FindCol(acl,iEx,0,event,2,true) == 0
2715  && FindCol(acl,iEx,0,event,1,true) == 0)){
2716  if(Radiator.status() < 0 ) Radiator.col(event[i].acol());
2717  else Radiator.acol(event[i].acol());
2718  }
2719  }
2720  } // end loop over particles in event record
2721  } // end cases of different radiator colour type
2722 
2723  // If either colour or anticolour has not been set, return false
2724  if (Radiator.col() < 0 || Radiator.acol() < 0) return false;
2725  // Done
2726  return true;
2727 }
2728 
2729 //--------------------------------------------------------------------------
2730 
2731 // Function to find a colour (anticolour) index in the input event
2732 // IN int col : Colour tag to be investigated
2733 // int iExclude1 : Identifier of first particle to be excluded
2734 // from search
2735 // int iExclude2 : Identifier of second particle to be excluded
2736 // from search
2737 // Event event : event to be searched for colour tag
2738 // int type : Tag to define if col should be counted as
2739 // colour (type = 1) [->find anti-colour index
2740 // contracted with col]
2741 // anticolour (type = 2) [->find colour index
2742 // contracted with col]
2743 // OUT int : Position of particle in event record
2744 // contraced with col [0 if col is free tag]
2745 
2746 int History::FindCol(int col, int iExclude1, int iExclude2,
2747  const Event& event, int type, bool isHardIn){
2748 
2749  bool isHard = isHardIn;
2750  int index = 0;
2751 
2752  if(isHard){
2753  // Search event record for matching colour & anticolour
2754  for(int n = 0; n < event.size(); ++n) {
2755  if( n != iExclude1 && n != iExclude2
2756  && event[n].colType() != 0
2757  &&( event[n].status() > 0 // Check outgoing
2758  || event[n].status() == -21) ) { // Check incoming
2759  if ( event[n].acol() == col ) {
2760  index = -n;
2761  break;
2762  }
2763  if ( event[n].col() == col ){
2764  index = n;
2765  break;
2766  }
2767  }
2768  }
2769  } else {
2770 
2771  // Search event record for matching colour & anticolour
2772  for(int n = 0; n < event.size(); ++n) {
2773  if( n != iExclude1 && n != iExclude2
2774  && event[n].colType() != 0
2775  &&( event[n].status() == 43 // Check outgoing from ISR
2776  || event[n].status() == 51 // Check outgoing from FSR
2777  || event[n].status() == -41 // first initial
2778  || event[n].status() == -42) ) { // second initial
2779  if ( event[n].acol() == col ) {
2780  index = -n;
2781  break;
2782  }
2783  if ( event[n].col() == col ){
2784  index = n;
2785  break;
2786  }
2787  }
2788  }
2789  }
2790  // if no matching colour / anticolour has been found, return false
2791  if( type == 1 && index < 0) return abs(index);
2792  if( type == 2 && index > 0) return abs(index);
2793 
2794  return 0;
2795 }
2796 
2797 //--------------------------------------------------------------------------
2798 
2799 // Function to in the input event find a particle with quantum
2800 // numbers matching those of the input particle
2801 // IN Particle : Particle to be searched for
2802 // Event : Event to be searched in
2803 // OUT int : > 0 : Position of matching particle in event
2804 // < 0 : No match in event
2805 
2806 int History::FindParticle(const Particle& particle, const Event& event){
2807 
2808  int index = -1;
2809 
2810  for( int i=0; i < int(event.size()); ++i)
2811  if( event[i].status() == particle.status()
2812  && event[i].id() == particle.id()
2813  && event[i].colType() == particle.colType()
2814  && event[i].chargeType() == particle.chargeType()
2815  && event[i].col() == particle.col()
2816  && event[i].acol() == particle.acol()
2817  && event[i].charge() == particle.charge()){
2818  index = i;
2819  break;
2820  }
2821 
2822  return index;
2823 }
2824 
2825 //--------------------------------------------------------------------------
2826 
2827 // Function to get the colour of the radiator before the splitting
2828 // for clustering
2829 // IN int : Position of the radiator after the splitting, in the event
2830 // int : Position of the emitted after the splitting, in the event
2831 // Event : Reference event
2832 // OUT int : Colour of the radiator before the splitting
2833 
2834 int History::getRadBeforeCol(const int rad, const int emt,
2835  const Event& event){
2836 
2837  // Save type of splitting
2838  int type = (event[rad].isFinal()) ? 1 :-1;
2839  // Get flavour of radiator after potential clustering
2840  int radBeforeFlav = getRadBeforeFlav(rad,emt,event);
2841  // Get colours of the radiator before the potential clustering
2842  int radBeforeCol = -1;
2843  // Get reconstructed gluon colours
2844  if(radBeforeFlav == 21) {
2845 
2846  // Start with quark emissions in FSR
2847  if (type == 1 && event[emt].id() != 21) {
2848  radBeforeCol = (event[rad].col() > 0)
2849  ? event[rad].col() : event[emt].col();
2850  // Quark emissions in ISR
2851  } else if (type == -1 && event[emt].id() != 21) {
2852  radBeforeCol = (event[rad].col() > 0)
2853  ? event[rad].col() : event[emt].acol();
2854  //Gluon emissions in FSR
2855  } else if (type == 1 && event[emt].id() == 21) {
2856  // If emitted is a gluon, remove the repeated index, and take
2857  // the remaining indices as colour and anticolour
2858  int colRemove = (event[rad].col() == event[emt].acol())
2859  ? event[rad].acol() : event[rad].col();
2860  radBeforeCol = (event[rad].col() == colRemove)
2861  ? event[emt].col() : event[rad].col();
2862  //Gluon emissions in ISR
2863  } else if (type == -1 && event[emt].id() == 21) {
2864  // If emitted is a gluon, remove the repeated index, and take
2865  // the remaining indices as colour and anticolour
2866  int colRemove = (event[rad].col() == event[emt].col())
2867  ? event[rad].col() : event[rad].acol();
2868  radBeforeCol = (event[rad].col() == colRemove)
2869  ? event[emt].acol() : event[rad].col();
2870  }
2871 
2872  // Get reconstructed quark colours
2873  } else if ( radBeforeFlav != 21 && radBeforeFlav > 0){
2874 
2875  // Quark emission in FSR
2876  if (type == 1 && event[emt].id() != 21) {
2877  // If radiating is a quark, remove the repeated index, and take
2878  // the remaining indices as colour and anticolour
2879  int colRemove = (event[rad].col() == event[emt].acol())
2880  ? event[rad].acol() : 0;
2881  radBeforeCol = (event[rad].col() == colRemove)
2882  ? event[emt].col() : event[rad].col();
2883  //Gluon emissions in FSR
2884  } else if (type == 1 && event[emt].id() == 21) {
2885  // If emitted is a gluon, remove the repeated index, and take
2886  // the remaining indices as colour and anticolour
2887  int colRemove = (event[rad].col() == event[emt].acol())
2888  ? event[rad].col() : 0;
2889  radBeforeCol = (event[rad].col() == colRemove)
2890  ? event[emt].col() : event[rad].col();
2891  //Quark emissions in ISR
2892  } else if (type == -1 && event[emt].id() != 21) {
2893  // If emitted is a quark, remove the repeated index, and take
2894  // the remaining indices as colour and anticolour
2895  int colRemove = (event[rad].col() == event[emt].col())
2896  ? event[rad].col() : 0;
2897  radBeforeCol = (event[rad].col() == colRemove)
2898  ? event[emt].acol() : event[rad].col();
2899  //Gluon emissions in ISR
2900  } else if (type == -1 && event[emt].id() == 21) {
2901  // If emitted is a gluon, remove the repeated index, and take
2902  // the remaining indices as colour and anticolour
2903  int colRemove = (event[rad].col() == event[emt].col())
2904  ? event[rad].col() : 0;
2905  radBeforeCol = (event[rad].col() == colRemove)
2906  ? event[emt].acol() : event[rad].col();
2907  }
2908  // Other particles are assumed uncoloured
2909  } else {
2910  radBeforeCol = 0;
2911  }
2912 
2913  return radBeforeCol;
2914 
2915 }
2916 
2917 //--------------------------------------------------------------------------
2918 
2919 // Function to get the anticolour of the radiator before the splitting
2920 // for clustering
2921 // IN int : Position of the radiator after the splitting, in the event
2922 // int : Position of the emitted after the splitting, in the event
2923 // Event : Reference event
2924 // OUT int : Anticolour of the radiator before the splitting
2925 
2926 int History::getRadBeforeAcol(const int rad, const int emt,
2927  const Event& event){
2928 
2929  // Save type of splitting
2930  int type = (event[rad].isFinal()) ? 1 :-1;
2931  // Get flavour of radiator after potential clustering
2932  int radBeforeFlav = getRadBeforeFlav(rad,emt,event);
2933  // Get colours of the radiator before the potential clustering
2934  int radBeforeAcl = -1;
2935  // Get reconstructed gluon colours
2936  if(radBeforeFlav == 21) {
2937 
2938  // Start with quark emissions in FSR
2939  if (type == 1 && event[emt].id() != 21) {
2940  radBeforeAcl = (event[rad].acol() > 0)
2941  ? event[rad].acol() : event[emt].acol();
2942  // Quark emissions in ISR
2943  } else if (type == -1 && event[emt].id() != 21) {
2944  radBeforeAcl = (event[rad].acol() > 0)
2945  ? event[rad].acol() : event[emt].col();
2946  //Gluon emissions in FSR
2947  } else if (type == 1 && event[emt].id() == 21) {
2948  // If emitted is a gluon, remove the repeated index, and take
2949  // the remaining indices as colour and anticolour
2950  int colRemove = (event[rad].col() == event[emt].acol())
2951  ? event[rad].acol() : event[rad].col();
2952  radBeforeAcl = (event[rad].acol() == colRemove)
2953  ? event[emt].acol() : event[rad].acol();
2954  //Gluon emissions in ISR
2955  } else if (type == -1 && event[emt].id() == 21) {
2956  // If emitted is a gluon, remove the repeated index, and take
2957  // the remaining indices as colour and anticolour
2958  int colRemove = (event[rad].col() == event[emt].col())
2959  ? event[rad].col() : event[rad].acol();
2960  radBeforeAcl = (event[rad].acol() == colRemove)
2961  ? event[emt].col() : event[rad].acol();
2962  }
2963 
2964  // Get reconstructed anti-quark colours
2965  } else if ( radBeforeFlav != 21 && radBeforeFlav < 0){
2966 
2967  // Antiquark emission in FSR
2968  if (type == 1 && event[emt].id() != 21) {
2969  // If radiating is a antiquark, remove the repeated index, and take
2970  // the remaining indices as colour and anticolour
2971  int colRemove = (event[rad].col() == event[emt].acol())
2972  ? event[rad].acol() : 0;
2973  radBeforeAcl = (event[rad].acol() == colRemove)
2974  ? event[emt].acol() : event[rad].acol();
2975  //Gluon emissions in FSR
2976  } else if (type == 1 && event[emt].id() == 21) {
2977  // If emitted is a gluon, remove the repeated index, and take
2978  // the remaining indices as colour and anticolour
2979  int colRemove = (event[rad].acol() == event[emt].col())
2980  ? event[rad].acol() : 0;
2981  radBeforeAcl = (event[rad].acol() == colRemove)
2982  ? event[emt].acol() : event[rad].acol();
2983  //Antiquark emissions in ISR
2984  } else if (type == -1 && event[emt].id() != 21) {
2985  // If emitted is an antiquark, remove the repeated index, and take
2986  // the remaining indices as colour and anticolour
2987  int colRemove = (event[rad].acol() == event[emt].acol())
2988  ? event[rad].acol() : 0;
2989  radBeforeAcl = (event[rad].acol() == colRemove)
2990  ? event[emt].col() : event[rad].acol();
2991  //Gluon emissions in ISR
2992  } else if (type == -1 && event[emt].id() == 21) {
2993  // If emitted is a gluon, remove the repeated index, and take
2994  // the remaining indices as colour and anticolour
2995  int colRemove = (event[rad].acol() == event[emt].acol())
2996  ? event[rad].acol() : 0;
2997  radBeforeAcl = (event[rad].acol() == colRemove)
2998  ? event[emt].col() : event[rad].acol();
2999  }
3000  // Other particles are considered uncoloured
3001  } else {
3002  radBeforeAcl = 0;
3003  }
3004 
3005  return radBeforeAcl;
3006 
3007 }
3008 
3009 //--------------------------------------------------------------------------
3010 
3011  // Function to get the parton connected to in by a colour line
3012  // IN int : Position of parton for which partner should be found
3013  // Event : Reference event
3014  // OUT int : If a colour line connects the "in" parton with another
3015  // parton, return the Position of the partner, else return 0
3016 
3017 int History::getColPartner(const int in, const Event& event){
3018 
3019  if(event[in].col() == 0) return 0;
3020 
3021  int partner = 0;
3022  // Try to find anticolour index first
3023  partner = FindCol(event[in].col(),in,0,event,1,true);
3024  // If no anticolour index has been found, try colour
3025  if(partner == 0)
3026  partner = FindCol(event[in].col(),in,0,event,2,true);
3027 
3028  return partner;
3029 
3030 }
3031 
3032 //--------------------------------------------------------------------------
3033 
3034  // Function to get the parton connected to in by an anticolour line
3035  // IN int : Position of parton for which partner should be found
3036  // Event : Reference event
3037  // OUT int : If an anticolour line connects the "in" parton with another
3038  // parton, return the Position of the partner, else return 0
3039 
3040 int History::getAcolPartner(const int in, const Event& event){
3041 
3042  if(event[in].acol() == 0) return 0;
3043 
3044  int partner = 0;
3045  // Try to find colour index first
3046  partner = FindCol(event[in].acol(),in,0,event,2,true);
3047  // If no colour index has been found, try anticolour
3048  if(partner == 0)
3049  partner = FindCol(event[in].acol(),in,0,event,1,true);
3050 
3051  return partner;
3052 
3053 }
3054 
3055 //--------------------------------------------------------------------------
3056 
3057 // Function to get the list of partons connected to the particle
3058 // formed by reclusterinf emt and rad by colour and anticolour lines
3059 // IN int : Position of radiator in the clustering
3060 // IN int : Position of emitted in the clustering
3061 // Event : Reference event
3062 // OUT vector<int> : List of positions of all partons that are connected
3063 // to the parton that will be formed
3064 // by clustering emt and rad.
3065 
3066 vector<int> History::getReclusteredPartners(const int rad, const int emt,
3067  const Event& event){
3068 
3069  // Save type
3070  int type = event[rad].isFinal() ? 1 : -1;
3071  // Get reclustered colours
3072  int radBeforeCol = getRadBeforeCol(rad, emt, event);
3073  int radBeforeAcl = getRadBeforeAcol(rad, emt, event);
3074  // Declare output
3075  vector<int> partners;
3076 
3077  // Start with FSR clusterings
3078  if(type == 1){
3079 
3080  for(int i=0; i < int(event.size()); ++i){
3081  // Check all initial state partons
3082  if( i != emt && i != rad
3083  && event[i].status() == -21
3084  && event[i].col() > 0
3085  && event[i].col() == radBeforeCol)
3086  partners.push_back(i);
3087  // Check all final state partons
3088  if( i != emt && i != rad
3089  && event[i].isFinal()
3090  && event[i].acol() > 0
3091  && event[i].acol() == radBeforeCol)
3092  partners.push_back(i);
3093  // Check all initial state partons
3094  if( i != emt && i != rad
3095  && event[i].status() == -21
3096  && event[i].acol() > 0
3097  && event[i].acol() == radBeforeAcl)
3098  partners.push_back(i);
3099  // Check all final state partons
3100  if( i != emt && i != rad
3101  && event[i].isFinal()
3102  && event[i].col() > 0
3103  && event[i].col() == radBeforeAcl)
3104  partners.push_back(i);
3105  }
3106  // Start with ISR clusterings
3107  } else {
3108 
3109  for(int i=0; i < int(event.size()); ++i){
3110  // Check all initial state partons
3111  if( i != emt && i != rad
3112  && event[i].status() == -21
3113  && event[i].acol() > 0
3114  && event[i].acol() == radBeforeCol)
3115  partners.push_back(i);
3116  // Check all final state partons
3117  if( i != emt && i != rad
3118  && event[i].isFinal()
3119  && event[i].col() > 0
3120  && event[i].col() == radBeforeCol)
3121  partners.push_back(i);
3122  // Check all initial state partons
3123  if( i != emt && i != rad
3124  && event[i].status() == -21
3125  && event[i].col() > 0
3126  && event[i].col() == radBeforeAcl)
3127  partners.push_back(i);
3128  // Check all final state partons
3129  if( i != emt && i != rad
3130  && event[i].isFinal()
3131  && event[i].acol() > 0
3132  && event[i].acol() == radBeforeAcl)
3133  partners.push_back(i);
3134  }
3135 
3136  }
3137  // Done
3138  return partners;
3139 }
3140 
3141 //--------------------------------------------------------------------------
3142 
3143 // Function to extract a chain of colour-connected partons in
3144 // the event
3145 // IN int : Type of parton from which to start extracting a
3146 // parton chain. If the starting point is a quark
3147 // i.e. flavType = 1, a chain of partons that are
3148 // consecutively connected by colour-lines will be
3149 // extracted. If the starting point is an antiquark
3150 // i.e. flavType =-1, a chain of partons that are
3151 // consecutively connected by anticolour-lines
3152 // will be extracted.
3153 // IN int : Position of the parton from which a
3154 // colour-connected chain should be derived
3155 // IN Event : Refernence event
3156 // IN/OUT vector<int> : Partons that should be excluded from the search.
3157 // OUT vector<int> : Positions of partons along the chain
3158 // OUT bool : Found singlet / did not find singlet
3159 
3160 bool History::getColSinglet( const int flavType, const int iParton,
3161  const Event& event, vector<int>& exclude, vector<int>& colSinglet){
3162 
3163  // If no possible flavour to start from has been found
3164  if(iParton < 0) return false;
3165 
3166  // If no further partner has been found in a previous iteration,
3167  // and the whole final state has been excluded, we're done
3168  if(iParton == 0){
3169 
3170  // Count number of final state partons
3171  int nFinal = 0;
3172  for(int i=0; i < int(event.size()); ++i)
3173  if( event[i].isFinal() && event[i].colType() != 0)
3174  nFinal++;
3175 
3176  // Get number of initial state partons in the list of
3177  // excluded partons
3178  int nExclude = int(exclude.size());
3179  int nInitExclude = 0;
3180  if(!event[exclude[2]].isFinal())
3181  nInitExclude++;
3182  if(!event[exclude[3]].isFinal())
3183  nInitExclude++;
3184 
3185  // If the whole final state has been considered, return
3186  if(nFinal == nExclude - nInitExclude)
3187  return true;
3188  else
3189  return false;
3190 
3191  }
3192 
3193  // Declare colour partner
3194  int colP = 0;
3195  // Save the colour partner
3196  colSinglet.push_back(iParton);
3197  // Remove the partner from the list
3198  exclude.push_back(iParton);
3199  // When starting out from a quark line, follow the colour lines
3200  if (flavType == 1)
3201  colP = getColPartner(iParton,event);
3202  // When starting out from an antiquark line, follow the anticolour lines
3203  else
3204  colP = getAcolPartner(iParton,event);
3205 
3206  // Do not count excluded partons twice
3207  for(int i = 0; i < int(exclude.size()); ++i)
3208  if(colP == exclude[i])
3209  return true;
3210 
3211  // Recurse
3212  return getColSinglet(flavType,colP,event,exclude,colSinglet);
3213 
3214 }
3215 
3216 //--------------------------------------------------------------------------
3217 
3218 // Function to check that a set of partons forms a colour singlet
3219 // IN Event : Reference event
3220 // IN vector<int> : Positions of the partons in the set
3221 // OUT bool : Is a colour singlet / is not
3222 
3223 bool History::isColSinglet( const Event& event,
3224  vector<int> system ){
3225 
3226  // Check if system forms a colour singlet
3227  for(int i=0; i < int(system.size()); ++i ){
3228  // Match quark and gluon colours
3229  if( system[i] > 0
3230  && (event[system[i]].colType() == 1
3231  || event[system[i]].colType() == 2) ) {
3232  for(int j=0; j < int(system.size()); ++j)
3233  // If flavour matches, remove both partons and continue
3234  if( system[i] > 0
3235  && system[j] > 0
3236  && event[system[i]].col() == event[system[j]].acol()){
3237  // Remove index and break
3238  system[i] = 0;
3239  system[j] = 0;
3240  break;
3241  }
3242  }
3243  // Match antiquark and gluon anticolours
3244  if( system[i] > 0
3245  && (event[system[i]].colType() == -1
3246  || event[system[i]].colType() == 2) ) {
3247  for(int j=0; j < int(system.size()); ++j)
3248  // If flavour matches, remove both partons and continue
3249  if( system[i] > 0
3250  && system[j] > 0
3251  && event[system[i]].acol() == event[system[j]].col()){
3252  // Remove index and break
3253  system[i] = 0;
3254  system[j] = 0;
3255  break;
3256  }
3257  }
3258 
3259  }
3260 
3261  // The system is a colour singlet if for all colours,
3262  // an anticolour was found
3263  bool isColSing = true;
3264  for(int i=0; i < int(system.size()); ++i)
3265  if( system[i] != 0 )
3266  isColSing = false;
3267 
3268  // Return
3269  return isColSing;
3270 
3271 }
3272 
3273 //--------------------------------------------------------------------------
3274 
3275 // Function to check that a set of partons forms a flavour singlet
3276 // IN Event : Reference event
3277 // IN vector<int> : Positions of the partons in the set
3278 // IN int : Flavour of all the quarks in the set, if
3279 // all quarks in a set should have a fixed flavour
3280 // OUT bool : Is a flavour singlet / is not
3281 
3282 bool History::isFlavSinglet( const Event& event,
3283  vector<int> system, int flav){
3284 
3285  // If a decoupled colour singlet has been found, check if this is also
3286  // a flavour singlet
3287  // Check that each quark matches an antiquark
3288  for(int i=0; i < int(system.size()); ++i)
3289  if( system[i] > 0 ) {
3290  for(int j=0; j < int(system.size()); ++j){
3291  // If flavour of outgoing partons matches,
3292  // remove both partons and continue.
3293  // Skip all bosons
3294  if( event[i].idAbs() != 21
3295  && event[i].idAbs() != 22
3296  && event[i].idAbs() != 23
3297  && event[i].idAbs() != 24
3298  && system[i] > 0
3299  && system[j] > 0
3300  && event[system[i]].isFinal()
3301  && event[system[j]].isFinal()
3302  && event[system[i]].id() == -1*event[system[j]].id()) {
3303  // If we want to check if only one flavour of quarks
3304  // exists
3305  if(abs(flav) > 0 && event[system[i]].idAbs() != flav)
3306  return false;
3307  // Remove index and break
3308  system[i] = 0;
3309  system[j] = 0;
3310  break;
3311  }
3312  // If flavour of outgoing and incoming partons match,
3313  // remove both partons and continue.
3314  // Skip all bosons
3315  if( event[i].idAbs() != 21
3316  && event[i].idAbs() != 22
3317  && event[i].idAbs() != 23
3318  && event[i].idAbs() != 24
3319  && system[i] > 0
3320  && system[j] > 0
3321  && ( ( !event[system[i]].isFinal() && event[system[j]].isFinal())
3322  ||( !event[system[j]].isFinal() && event[system[i]].isFinal()) )
3323  && event[system[i]].id() == event[system[j]].id()) {
3324  // If we want to check if only one flavour of quarks
3325  // exists
3326  if(abs(flav) > 0 && event[system[i]].idAbs() != flav)
3327  return false;
3328  // Remove index and break
3329  system[i] = 0;
3330  system[j] = 0;
3331  break;
3332  }
3333 
3334  }
3335  }
3336 
3337  // The colour singlet is a flavour singlet if for all quarks,
3338  // an antiquark was found
3339  bool isFlavSing = true;
3340  for(int i=0; i < int(system.size()); ++i)
3341  if( system[i] != 0 )
3342  isFlavSing = false;
3343 
3344  // Return
3345  return isFlavSing;
3346 
3347 }
3348 
3349 //--------------------------------------------------------------------------
3350 
3351 // Function to check if rad,emt,rec triple is allowed for clustering
3352 // IN int rad,emt,rec : Positions (in event record) of the three
3353 // particles considered for clustering
3354 // Event event : Reference event
3355 
3356 bool History::allowedClustering( int rad, int emt, int rec, int partner,
3357  const Event& event ){
3358 
3359  // Declare output
3360  bool allowed = true;
3361 
3362  // CONSTRUCT SOME PROPERTIES FOR LATER INVESTIGATION
3363 
3364  // Check if the triple forms a colour singlett
3365  bool isSing = isSinglett(rad,emt,partner,event);
3366  int type = (event[rad].isFinal()) ? 1 :-1;
3367  // Get flavour of radiator after potential clustering
3368  int radBeforeFlav = getRadBeforeFlav(rad,emt,event);
3369  // Get colours of the radiator before the potential clustering
3370  int radBeforeCol = getRadBeforeCol(rad,emt,event);
3371  int radBeforeAcl = getRadBeforeAcol(rad,emt,event);
3372  // Get colour partner of reclustered parton
3373  vector<int> radBeforeColP = getReclusteredPartners(rad, emt, event);
3374 
3375  // Count coloured partons in hard process
3376  int nPartonInHard = 0;
3377  for(int i=0; i < int(event.size()); ++i)
3378  // Check all final state partons
3379  if( event[i].isFinal()
3380  && event[i].colType() != 0
3381  && mergingHooksPtr->hardProcess.matchesAnyOutgoing(i, event))
3382  nPartonInHard++;
3383 
3384  // Count coloured final state partons in event, excluding
3385  // rad, rec, emt and hard process
3386  int nPartons = 0;
3387  for(int i=0; i < int(event.size()); ++i)
3388  // Check all final state partons
3389  if( i!=emt && i!=rad && i!=rec
3390  && event[i].isFinal()
3391  && event[i].colType() != 0
3392  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i, event))
3393  nPartons++;
3394 
3395  // Count number of initial state partons
3396  int nInitialPartons = 0;
3397  for(int i=0; i < int(event.size()); ++i)
3398  if( event[i].status() == -21
3399  && event[i].colType() != 0 )
3400  nInitialPartons++;
3401 
3402  // Get number of non-charged final state particles
3403  int nFinalEW = 0;
3404  for(int i=0; i < int(event.size()); ++i)
3405  if( event[i].isFinal()
3406  &&( event[i].id() == 22
3407  || event[i].id() == 23
3408  || event[i].id() == 24
3409  || event[i].id() == 25
3410  ||(event[i].idAbs() > 10 && event[i].idAbs() < 20)))
3411  nFinalEW++;
3412 
3413  // Check if event after potential clustering contains an even
3414  // number of quarks and/or antiquarks
3415  // (otherwise no electroweak vertex could be formed!)
3416  // Get number of final quarks
3417  int nFinalQuark = 0;
3418  // Get number of excluded final state quarks as well
3419  int nFinalQuarkExc = 0;
3420  for(int i=0; i < int(event.size()); ++i) {
3421  if(i !=rad && i != emt && i != rec) {
3422  if(event[i].isFinal() && event[i].isQuark() ){
3423  if ( !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,event) )
3424  nFinalQuark++;
3425  else
3426  nFinalQuarkExc++;
3427  }
3428  }
3429  }
3430 
3431  // Add recoiler to number of final quarks
3432  if(event[rec].isFinal() && event[rec].isQuark()) nFinalQuark++;
3433  // Add radiator after clustering to number of final quarks
3434  if(event[rad].isFinal() && abs(radBeforeFlav) < 10) nFinalQuark++;
3435 
3436  // Get number of initial quarks
3437  int nInitialQuark = 0;
3438  if(type == 1) {
3439  if(event[rec].isFinal()){
3440  if(event[3].isQuark()) nInitialQuark++;
3441  if(event[4].isQuark()) nInitialQuark++;
3442  } else {
3443  int iOtherIn = (rec == 3) ? 4 : 3;
3444  if(event[rec].isQuark()) nInitialQuark++;
3445  if(event[iOtherIn].isQuark()) nInitialQuark++;
3446  }
3447  } else {
3448  // Add recoiler to number of initial quarks
3449  if(event[rec].isQuark()) nInitialQuark++;
3450  // Add radiator after clustering to number of initial quarks
3451  if(abs(radBeforeFlav) < 10) nInitialQuark++;
3452  }
3453 
3454  // If only odd number of quarks in state,
3455  // reject (no electroweak vertex can be formed).
3456  // This is only true of no primary partonic resonance could have produced
3457  // electroweak bosons.
3458  // Check for tops
3459  int nTop = 0;
3460  for(int i=0; i < int(event.size()); ++i)
3461  if(event[i].idAbs() == 6)
3462  nTop++;
3463 
3464  // BEGIN CHECKING THE CLUSTERING
3465 
3466  // Check if colour is conserved
3467  vector<int> unmatchedCol;
3468  vector<int> unmatchedAcl;
3469  // Check all unmatched colours
3470  for ( int i = 0; i < event.size(); ++i)
3471  if( i != emt && i != rad
3472  && (event[i].isFinal() || event[i].status() == -21)
3473  && event[i].colType() != 0 ) {
3474 
3475  int colP = getColPartner(i,event);
3476  int aclP = getAcolPartner(i,event);
3477 
3478  if(event[i].col() > 0
3479  && (colP == emt || colP == rad || colP == 0) )
3480  unmatchedCol.push_back(i);
3481  if(event[i].acol() > 0
3482  && (aclP == emt || aclP == rad || aclP == 0) )
3483  unmatchedAcl.push_back(i);
3484 
3485  }
3486 
3487  // If more than one colour or more than one anticolour are unmatched,
3488  // there is no way to make this clustering work
3489  if(int(unmatchedCol.size()) + int(unmatchedAcl.size()) > 2)
3490  return false;
3491 
3492  // If triple forms colour singlett, check that resulting state
3493  // matches hard core process
3494  if(isSing)
3495  allowed = false;
3496  if(isSing && (abs(radBeforeFlav)<10 && event[rec].isQuark()) )
3497  allowed = true;
3498 
3499  // Never recluster any outgoing partons of the core V -> qqbar' splitting!
3500  if( mergingHooksPtr->hardProcess.matchesAnyOutgoing(emt,event)
3501  || mergingHooksPtr->hardProcess.matchesAnyOutgoing(rad,event) )
3502  allowed = false;
3503 
3504  // If only gluons in initial state and no quarks in final state,
3505  // reject (no electroweak vertex can be formed)
3506  if(nFinalEW != 0 && nInitialQuark == 0
3507  && nFinalQuark == 0 && nFinalQuarkExc == 0)
3508  allowed = false;
3509 
3510  if( nTop == 0 && (nInitialQuark + nFinalQuark)%2 != 0 )
3511  allowed = false;
3512  if( nTop > 0 && (nInitialQuark + nFinalQuark + nFinalQuarkExc)%2 != 0 )
3513  allowed = false;
3514 
3515  // Do not allow final state splitting that produces only
3516  // allowed final state gluons, and has a colour-connected initial state
3517  // This means forbidding clusterings that do not allow for a
3518  // t-channel gluon, which is needed to have a quark-antiquark initial state.
3519  // Here, partons excluded from clustering are not counted as possible
3520  // partners to form a t-cnannel gluon
3521  if(event[3].col() == event[4].acol()
3522  && event[3].acol() == event[4].col()
3523  && nFinalQuark == 0)
3524  allowed = false;
3525 
3526  // No problems with gluon radiation
3527  if(event[emt].id() == 21)
3528  return allowed;
3529 
3530  // Start more involved checks. g -> q_1 qbar_1 splittings are
3531  // particularly problematic if more than one quark of the emitted
3532  // flavour is present.
3533  // Count number of initial quarks of radiator or emitted flavour
3534  vector<int> iInQuarkFlav;
3535  for(int i=0; i < int(event.size()); ++i)
3536  // Check all initial state partons
3537  if( i != emt && i != rad
3538  && event[i].status() == -21
3539  && event[i].idAbs() == event[emt].idAbs() )
3540  iInQuarkFlav.push_back(i);
3541 
3542  // Count number of final quarks of radiator or emitted flavour
3543  vector<int> iOutQuarkFlav;
3544  for(int i=0; i < int(event.size()); ++i)
3545  // Check all final state partons
3546  if( i != emt && i != rad
3547  && event[i].isFinal()
3548  && event[i].idAbs() == event[emt].idAbs()
3549  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i, event))
3550  iOutQuarkFlav.push_back(i);
3551 
3552  // Save number of potentially dangerous quarks
3553  int nInQuarkFlav = int(iInQuarkFlav.size());
3554  int nOutQuarkFlav = int(iOutQuarkFlav.size());
3555 
3556  // Easiest problem 0:
3557  // Radiator before splitting exactly matches the partner
3558  // after the splitting
3559  if( event[partner].isFinal()
3560  && event[partner].id() == 21
3561  && radBeforeFlav == 21
3562  && event[partner].col() == radBeforeCol
3563  && event[partner].acol() == radBeforeAcl)
3564  return false;
3565 
3566  // If there are no ambiguities in qqbar pairs, return
3567  if(nInQuarkFlav + nOutQuarkFlav == 0)
3568  return allowed;
3569 
3570  // Save all quarks and gluons that will not change colour
3571  vector<int> gluon;
3572  vector<int> quark;
3573  vector<int> antiq;
3574  vector<int> partons;
3575  for(int i=0; i < int(event.size()); ++i)
3576  // Check initial and final state partons
3577  if( i!=emt && i!=rad
3578  && event[i].colType() != 0
3579  && (event[i].isFinal() || event[i].status() == -21) ){
3580  // Save index
3581  partons.push_back(i);
3582  // Split into components
3583  if(event[i].colType() == 2)
3584  gluon.push_back(i);
3585  else if (event[i].colType() == 1)
3586  quark.push_back(i);
3587  else if (event[i].colType() == -1)
3588  antiq.push_back(i);
3589  }
3590 
3591  // We split up the test of the g->qq splitting into final state
3592  // and initial state problems
3593  bool isFSRg2qq = ((type == 1) && (event[rad].id() == -1*event[emt].id()) );
3594  bool isISRg2qq = ((type ==-1) && (event[rad].id() == event[emt].id()) );
3595 
3596  // First check general things about colour connections
3597  // Check that clustering does not produce a gluon that is exactly
3598  // matched in the final state, or does not have any colour connections
3599  if( (isFSRg2qq || isISRg2qq)
3600  && int(quark.size()) + int(antiq.size())
3601  + int(gluon.size()) > nPartonInHard ) {
3602 
3603  vector<int> colours;
3604  vector<int> anticolours;
3605  // Add the colour and anticolour of the gluon before the emission
3606  // to the list, bookkeep initial colour as final anticolour, and
3607  // initial anticolour as final colour
3608  if(type == 1) {
3609  colours.push_back(radBeforeCol);
3610  anticolours.push_back(radBeforeAcl);
3611  } else {
3612  colours.push_back(radBeforeAcl);
3613  anticolours.push_back(radBeforeCol);
3614  }
3615  // Now store gluon colours and anticolours.
3616  for(int i=0; i < int(gluon.size()); ++i)
3617  if(event[gluon[i]].isFinal()){
3618  colours.push_back(event[gluon[i]].col());
3619  anticolours.push_back(event[gluon[i]].acol());
3620  } else {
3621  colours.push_back(event[gluon[i]].acol());
3622  anticolours.push_back(event[gluon[i]].col());
3623  }
3624 
3625  // Loop through colours and check if any match with
3626  // anticolours. If colour matches, remove from list
3627  for(int i=0; i < int(colours.size()); ++i)
3628  for(int j=0; j < int(anticolours.size()); ++j)
3629  if(colours[i] > 0 && anticolours[j] > 0
3630  && colours[i] == anticolours[j]){
3631  colours[i] = 0;
3632  anticolours[j] = 0;
3633  }
3634 
3635  // If all gluon anticolours and all colours matched, disallow
3636  // the clustering
3637  bool allMatched = true;
3638  for(int i=0; i < int(colours.size()); ++i)
3639  if(colours[i] != 0)
3640  allMatched = false;
3641  for(int i=0; i < int(anticolours.size()); ++i)
3642  if(anticolours[i] != 0)
3643  allMatched = false;
3644 
3645  if(allMatched)
3646  return false;
3647 
3648  // Now add the colours of the hard process, and check if all
3649  // colours match.
3650  for(int i=0; i < int(quark.size()); ++i)
3651  if( event[quark[i]].isFinal()
3652  && mergingHooksPtr->hardProcess.matchesAnyOutgoing(quark[i], event))
3653  colours.push_back(event[quark[i]].col());
3654 
3655  for(int i=0; i < int(antiq.size()); ++i)
3656  if( event[antiq[i]].isFinal()
3657  && mergingHooksPtr->hardProcess.matchesAnyOutgoing(antiq[i], event))
3658  anticolours.push_back(event[antiq[i]].acol());
3659 
3660  // Loop through colours again and check if any match with
3661  // anticolours. If colour matches, remove from list
3662  for(int i=0; i < int(colours.size()); ++i)
3663  for(int j=0; j < int(anticolours.size()); ++j)
3664  if(colours[i] > 0 && anticolours[j] > 0
3665  && colours[i] == anticolours[j]){
3666  colours[i] = 0;
3667  anticolours[j] = 0;
3668  }
3669 
3670  // If all colours are matched now, and since we have more quarks than
3671  // present in the hard process, disallow the clustering
3672  allMatched = true;
3673  for(int i=0; i < int(colours.size()); ++i)
3674  if(colours[i] != 0)
3675  allMatched = false;
3676  for(int i=0; i < int(anticolours.size()); ++i)
3677  if(anticolours[i] != 0)
3678  allMatched = false;
3679 
3680  if(allMatched)
3681  return false;
3682 
3683  }
3684 
3685  // FSR PROBLEMS
3686 
3687  if(isFSRg2qq && nInQuarkFlav + nOutQuarkFlav > 0){
3688 
3689  // Easiest problem 1:
3690  // RECLUSTERED FINAL STATE GLUON MATCHES INITIAL STATE GLUON
3691  for(int i=0; i < int(gluon.size()); ++i){
3692  if(!event[gluon[i]].isFinal()
3693  && event[gluon[i]].col() == radBeforeCol
3694  && event[gluon[i]].acol() == radBeforeAcl)
3695  return false;
3696  }
3697 
3698  // Easiest problem 2:
3699  // RECLUSTERED FINAL STATE GLUON MATCHES FINAL STATE GLUON
3700  for(int i=0; i < int(gluon.size()); ++i){
3701  if(event[gluon[i]].isFinal()
3702  && event[gluon[i]].col() == radBeforeAcl
3703  && event[gluon[i]].acol() == radBeforeCol)
3704  return false;
3705  }
3706 
3707  // Easiest problem 3:
3708  // RECLUSTERED FINAL STATE GLUON MATCHES FINAL STATE Q-QBAR PAIR
3709  if( int(radBeforeColP.size()) == 2
3710  && event[radBeforeColP[0]].isFinal()
3711  && event[radBeforeColP[1]].isFinal()
3712  && event[radBeforeColP[0]].id() == -1*event[radBeforeColP[1]].id() ){
3713 
3714  // This clustering is allowed if there is no colour in the
3715  // initial state
3716  if(nInitialPartons > 0)
3717  return false;
3718  }
3719 
3720  // Next-to-easiest problem 1:
3721  // RECLUSTERED FINAL STATE GLUON MATCHES ONE FINAL STARE Q_1
3722  // AND ONE INITIAL STATE Q_1
3723  if( int(radBeforeColP.size()) == 2
3724  && (( event[radBeforeColP[0]].status() == -21
3725  && event[radBeforeColP[1]].isFinal())
3726  ||( event[radBeforeColP[0]].isFinal()
3727  && event[radBeforeColP[1]].status() == -21))
3728  && event[radBeforeColP[0]].id() == event[radBeforeColP[1]].id() ){
3729 
3730  // In principle, clustering this splitting can disconnect
3731  // the colour lines of a graph. However, the colours can be connected
3732  // again if a final or initial partons of the correct flavour exists.
3733 
3734  // Check which of the partners are final / initial
3735  int incoming = (event[radBeforeColP[0]].isFinal())
3736  ? radBeforeColP[1] : radBeforeColP[0];
3737  int outgoing = (event[radBeforeColP[0]].isFinal())
3738  ? radBeforeColP[0] : radBeforeColP[1];
3739 
3740  // Loop through event to find "recovery partons"
3741  bool clusPossible = false;
3742  for(int i=0; i < int(event.size()); ++i)
3743  if( i != emt && i != rad
3744  && i != incoming && i != outgoing
3745  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,event) ){
3746  // Check if an incoming parton matches
3747  if( event[i].status() == -21
3748  && (event[i].id() == event[outgoing].id()
3749  ||event[i].id() == -1*event[incoming].id()) )
3750  clusPossible = true;
3751  // Check if a final parton matches
3752  if( event[i].isFinal()
3753  && (event[i].id() == -1*event[outgoing].id()
3754  ||event[i].id() == event[incoming].id()) )
3755  clusPossible = true;
3756  }
3757 
3758  // There can be a further complication: If e.g. in
3759  // t-channel photon exchange topologies, both incoming
3760  // partons are quarks, and form colour singlets with any
3761  // number of final state partons, at least try to
3762  // recluster as much as possible.
3763  // For this, check if the incoming parton
3764  // connected to the radiator is connected to a
3765  // colour and flavour singlet
3766  vector<int> excludeIn1;
3767  for(int i=0; i < 4; ++i)
3768  excludeIn1.push_back(0);
3769  vector<int> colSingletIn1;
3770  int flavIn1Type = (event[incoming].id() > 0) ? 1 : -1;
3771  // Try finding colour singlets
3772  bool isColSingIn1 = getColSinglet(flavIn1Type,incoming,event,
3773  excludeIn1,colSingletIn1);
3774  // Check if colour singlet also is a flavour singlet
3775  bool isFlavSingIn1 = isFlavSinglet(event,colSingletIn1);
3776 
3777  // Check if the incoming parton not
3778  // connected to the radiator is connected to a
3779  // colour and flavour singlet
3780  int incoming2 = (incoming == 3) ? 4 : 3;
3781  vector<int> excludeIn2;
3782  for(int i=0; i < 4; ++i)
3783  excludeIn2.push_back(0);
3784  vector<int> colSingletIn2;
3785  int flavIn2Type = (event[incoming2].id() > 0) ? 1 : -1;
3786  // Try finding colour singlets
3787  bool isColSingIn2 = getColSinglet(flavIn2Type,incoming2,event,
3788  excludeIn2,colSingletIn2);
3789  // Check if colour singlet also is a flavour singlet
3790  bool isFlavSingIn2 = isFlavSinglet(event,colSingletIn2);
3791 
3792  // If no "recovery clustering" is possible, reject clustering
3793  if(!clusPossible
3794  && (!isColSingIn1 || !isFlavSingIn1
3795  || !isColSingIn2 || !isFlavSingIn2))
3796  return false;
3797 
3798  }
3799 
3800  // Next-to-easiest problem 2:
3801  // FINAL STATE Q-QBAR CLUSTERING DISCONNECTS SINGLETT SUBSYSTEM WITH
3802  // FINAL STATE Q-QBAR PAIR FROM GRAPH
3803 
3804  // Prepare to check for colour singlet combinations of final state quarks
3805  // Start by building a list of partons to exclude when checking for
3806  // colour singlet combinations
3807  int flav = event[emt].id();
3808  vector<int> exclude;
3809  exclude.push_back(emt);
3810  exclude.push_back(rad);
3811  exclude.push_back(radBeforeColP[0]);
3812  exclude.push_back(radBeforeColP[1]);
3813  vector<int> colSinglet;
3814  // Now find parton from which to start checking colour singlets
3815  int iOther = -1;
3816  // Loop through event to find a parton of correct flavour
3817  for(int i=0; i < int(event.size()); ++i)
3818  // Check final state for parton equalling emitted flavour.
3819  // Exclude the colour system coupled to the clustering
3820  if( i != emt
3821  && i != rad
3822  && i != radBeforeColP[0]
3823  && i != radBeforeColP[1]
3824  && event[i].isFinal() ) {
3825  // Stop if one parton of the correct flavour is found
3826  if(event[i].id() == flav){
3827  iOther = i;
3828  break;
3829  }
3830  }
3831  // Save the type of flavour
3832  int flavType = (event[iOther].id() > 0) ? 1 : -1;
3833  // Try finding colour singlets
3834  bool isColSing = getColSinglet(flavType,iOther,event,exclude,colSinglet);
3835  // Check if colour singlet also is a flavour singlet
3836  bool isFlavSing = isFlavSinglet(event,colSinglet);
3837 
3838  // Nearly there...
3839  if(isColSing && isFlavSing){
3840 
3841  // In a final check, ensure that the final state does not only
3842  // consist of colour singlets that are also flavour singlets
3843  // of the identical (!) flavours
3844  // Loop through event and save all final state partons
3845  vector<int> allFinal;
3846  for(int i=0; i < int(event.size()); ++i)
3847  if( event[i].isFinal() )
3848  allFinal.push_back(i);
3849 
3850  // Check if all final partons form a colour singlet
3851  bool isFullColSing = isColSinglet(event,allFinal);
3852  // Check if all final partons form a flavour singlet
3853  bool isFullFlavSing = isFlavSinglet(event,allFinal,flav);
3854 
3855  // If all final quarks are of identical flavour,
3856  // no possible clustering should be discriminated.
3857  // Otherwise, disallow
3858  if(!isFullColSing || !isFullFlavSing)
3859  return false;
3860  }
3861  }
3862 
3863  // ISR PROBLEMS
3864 
3865  if(isISRg2qq && nInQuarkFlav + nOutQuarkFlav > 0){
3866 
3867  // Easiest problem 1:
3868  // RECLUSTERED INITIAL STATE GLUON MATCHES FINAL STATE GLUON
3869  for(int i=0; i < int(gluon.size()); ++i){
3870  if(event[gluon[i]].isFinal()
3871  && event[gluon[i]].col() == radBeforeCol
3872  && event[gluon[i]].acol() == radBeforeAcl)
3873  return false;
3874  }
3875 
3876  // Easiest problem 2:
3877  // RECLUSTERED INITIAL STATE GLUON MATCHES INITIAL STATE GLUON
3878  for(int i=0; i < int(gluon.size()); ++i){
3879  if(event[gluon[i]].status() == -21
3880  && event[gluon[i]].acol() == radBeforeCol
3881  && event[gluon[i]].col() == radBeforeAcl)
3882  return false;
3883  }
3884 
3885  // Next-to-easiest problem 1:
3886  // RECLUSTERED INITIAL STATE GLUON MATCHES FINAL STATE Q-QBAR PAIR
3887  if( int(radBeforeColP.size()) == 2
3888  && event[radBeforeColP[0]].isFinal()
3889  && event[radBeforeColP[1]].isFinal()
3890  && event[radBeforeColP[0]].id() == -1*event[radBeforeColP[1]].id() ) {
3891 
3892  // In principle, clustering this splitting can disconnect
3893  // the colour lines of a graph. However, the colours can be connected
3894  // again if final state partons of the correct (anti)flavour, or
3895  // initial state partons of the correct flavour exist
3896  // Loop through event to check
3897  bool clusPossible = false;
3898  for(int i=0; i < int(event.size()); ++i)
3899  if( i != emt && i != rad
3900  && i != radBeforeColP[0]
3901  && i != radBeforeColP[1]
3902  && !mergingHooksPtr->hardProcess.matchesAnyOutgoing(i,event) ){
3903  if(event[i].status() == -21
3904  && ( event[radBeforeColP[0]].id() == event[i].id()
3905  || event[radBeforeColP[1]].id() == event[i].id() ))
3906  clusPossible = true;
3907  if(event[i].isFinal()
3908  && ( event[radBeforeColP[0]].id() == -1*event[i].id()
3909  || event[radBeforeColP[1]].id() == -1*event[i].id() ))
3910  clusPossible = true;
3911  }
3912 
3913  // There can be a further complication: If e.g. in
3914  // t-channel photon exchange topologies, both incoming
3915  // partons are quarks, and form colour singlets with any
3916  // number of final state partons, at least try to
3917  // recluster as much as possible.
3918  // For this, check if the incoming parton
3919  // connected to the radiator is connected to a
3920  // colour and flavour singlet
3921  int incoming1 = 3;
3922  vector<int> excludeIn1;
3923  for(int i=0; i < 4; ++i)
3924  excludeIn1.push_back(0);
3925  vector<int> colSingletIn1;
3926  int flavIn1Type = (event[incoming1].id() > 0) ? 1 : -1;
3927  // Try finding colour singlets
3928  bool isColSingIn1 = getColSinglet(flavIn1Type,incoming1,event,
3929  excludeIn1,colSingletIn1);
3930  // Check if colour singlet also is a flavour singlet
3931  bool isFlavSingIn1 = isFlavSinglet(event,colSingletIn1);
3932 
3933  // Check if the incoming parton not
3934  // connected to the radiator is connected to a
3935  // colour and flavour singlet
3936  int incoming2 = 4;
3937  vector<int> excludeIn2;
3938  for(int i=0; i < 4; ++i)
3939  excludeIn2.push_back(0);
3940  vector<int> colSingletIn2;
3941  int flavIn2Type = (event[incoming2].id() > 0) ? 1 : -1;
3942  // Try finding colour singlets
3943  bool isColSingIn2 = getColSinglet(flavIn2Type,incoming2,event,
3944  excludeIn2,colSingletIn2);
3945  // Check if colour singlet also is a flavour singlet
3946  bool isFlavSingIn2 = isFlavSinglet(event,colSingletIn2);
3947 
3948  // If no "recovery clustering" is possible, reject clustering
3949  if(!clusPossible
3950  && (!isColSingIn1 || !isFlavSingIn1
3951  || !isColSingIn2 || !isFlavSingIn2))
3952  return false;
3953 
3954  }
3955 
3956  }
3957 
3958  // Done
3959  return allowed;
3960 }
3961 
3962 //--------------------------------------------------------------------------
3963 
3964 // Function to check if rad,emt,rec triple is results in
3965 // colour singlet radBefore+recBefore
3966 // IN int rad,emt,rec : Positions (in event record) of the three
3967 // particles considered for clustering
3968 // Event event : Reference event
3969 
3970 bool History::isSinglett( int rad, int emt, int rec, const Event& event ){
3971 
3972  int radCol = event[rad].col();
3973  int emtCol = event[emt].col();
3974  int recCol = event[rec].col();
3975  int radAcl = event[rad].acol();
3976  int emtAcl = event[emt].acol();
3977  int recAcl = event[rec].acol();
3978  int recType = event[rec].isFinal() ? 1 : -1;
3979 
3980  bool isSing = false;
3981 
3982  if( ( recType == -1
3983  && radCol + emtCol == recCol && radAcl + emtAcl == recAcl)
3984  ||( recType == 1
3985  && radCol + emtCol == recAcl && radAcl + emtAcl == recCol) )
3986  isSing = true;
3987 
3988  return isSing;
3989 
3990 }
3991 
3992 //--------------------------------------------------------------------------
3993 
3994 // Function to check if event is sensibly constructed: Meaning
3995 // that all colour indices are contracted and that the charge in
3996 // initial and final states matches
3997 // IN event : event to be checked
3998 // OUT TRUE : event is properly construced
3999 // FALSE : event not valid
4000 
4001 bool History::validEvent( const Event& event ){
4002 
4003  // Check if event is coloured
4004  bool validColour = true;
4005  for ( int i = 0; i < event.size(); ++i)
4006  // Check colour of quarks
4007  if( event[i].isFinal() && event[i].colType() == 1
4008  // No corresponding anticolour in final state
4009  && ( FindCol(event[i].col(),i,0,event,1,true) == 0
4010  // No corresponding colour in initial state
4011  && FindCol(event[i].col(),i,0,event,2,true) == 0 )) {
4012  validColour = false;
4013  break;
4014  // Check anticolour of antiquarks
4015  } else if ( event[i].isFinal() && event[i].colType() == -1
4016  // No corresponding colour in final state
4017  && ( FindCol(event[i].acol(),i,0,event,2,true) == 0
4018  // No corresponding anticolour in initial state
4019  && FindCol(event[i].acol(),i,0,event,1,true) == 0 )) {
4020  validColour = false;
4021  break;
4022  // No uncontracted colour (anticolour) charge of gluons
4023  } else if ( event[i].isFinal() && event[i].colType() == 2
4024  // No corresponding anticolour in final state
4025  && ( FindCol(event[i].col(),i,0,event,1,true) == 0
4026  // No corresponding colour in initial state
4027  && FindCol(event[i].col(),i,0,event,2,true) == 0 )
4028  // No corresponding colour in final state
4029  && ( FindCol(event[i].acol(),i,0,event,2,true) == 0
4030  // No corresponding anticolour in initial state
4031  && FindCol(event[i].acol(),i,0,event,1,true) == 0 )) {
4032  validColour = false;
4033  break;
4034  }
4035 
4036  // Check charge sum in initial and final state
4037  bool validCharge = true;
4038  double initCharge = event[3].charge() + event[4].charge();
4039  double finalCharge = 0.0;
4040  for(int i = 0; i < event.size(); ++i)
4041  if(event[i].isFinal()) finalCharge += event[i].charge();
4042  if(abs(initCharge-finalCharge) > 1e-12) validCharge = false;
4043 
4044  return (validColour && validCharge);
4045 
4046 }
4047 
4048 //--------------------------------------------------------------------------
4049 
4050 // Function to check whether two clusterings are identical, used
4051 // for finding the history path in the mother -> children direction
4052 
4053 bool History::equalClustering( Clustering clus1 , Clustering clus2 ) {
4054  return ( (clus1.emittor == clus2.emittor)
4055  && (clus1.emitted == clus2.emitted)
4056  && (clus1.recoiler == clus2.recoiler)
4057  && (clus1.partner == clus2.partner)
4058  && (clus1.pT() == clus2.pT()) );
4059 }
4060 
4061 //--------------------------------------------------------------------------
4062 
4063 // Chose dummy scale for event construction. By default, choose
4064 // sHat for 2->Boson(->2)+ n partons processes and
4065 // M_Boson for 2->Boson(->) processes
4066 
4067 double History::choseHardScale( const Event& event ) const {
4068 
4069  // Get sHat
4070  double mHat = (event[3].p() + event[4].p()).mCalc();
4071 
4072  // Find number of final state particles and bosons
4073  int nFinal = 0;
4074  int nFinBos= 0;
4075  int nBosons= 0;
4076  double mBos = 0.0;
4077  for(int i = 0; i < event.size(); ++i)
4078  if( event[i].isFinal() ) {
4079  nFinal++;
4080  // Remember final state unstable bosons
4081  if( abs(event[i].id()) == 23
4082  || abs(event[i].id()) == 24 ){
4083  nFinBos++;
4084  nBosons++;
4085  mBos += event[i].m();
4086  }
4087  } else if( abs(event[i].status()) == 22
4088  && ( abs(event[i].id()) == 23
4089  || abs(event[i].id()) == 24 )) {
4090  nBosons++;
4091  mBos += event[i].m(); // Real mass
4092  }
4093 
4094  // Return averaged boson masses
4095  if( nBosons > 0 && (nFinal + nFinBos*2) <= 3)
4096  return (mBos / double(nBosons));
4097  else return
4098  mHat;
4099 }
4100 
4101 //--------------------------------------------------------------------------
4102 
4103 // If the state has an incoming hadron return the flavour of the
4104 // parton entering the hard interaction. Otherwise return 0
4105 
4106 int History::getCurrentFlav(const int side) const {
4107  int in = (side == 1) ? 3 : 4;
4108  return state[in].id();
4109 }
4110 
4111 //--------------------------------------------------------------------------
4112 
4113 double History::getCurrentX(const int side) const {
4114  int in = (side == 1) ? 3 : 4;
4115  return ( 2.*state[in].e()/state[0].e() );
4116 }
4117 
4118 //--------------------------------------------------------------------------
4119 
4120 double History::getCurrentZ(const int rad,
4121  const int rec, const int emt) const {
4122 
4123  int type = state[rad].isFinal() ? 1 : -1;
4124  double z = 0.;
4125 
4126  if(type == 1){
4127  // Construct 2->3 variables for FSR
4128  Vec4 sum = state[rad].p() + state[rec].p()
4129  + state[emt].p();
4130  double m2Dip = sum.m2Calc();
4131  double x1 = 2. * (sum * state[rad].p()) / m2Dip;
4132  double x3 = 2. * (sum * state[emt].p()) / m2Dip;
4133  // Calculate z of splitting, different for FSR
4134  z = x1/(x1+x3);
4135  } else {
4136  // Construct momenta of dipole before/after splitting for ISR
4137  Vec4 qBR(state[rad].p() - state[emt].p() + state[rec].p());
4138  Vec4 qAR(state[rad].p() + state[rec].p());
4139  // Calculate z of splitting, different for ISR
4140  z = (qBR.m2Calc())/( qAR.m2Calc());
4141  }
4142 
4143  return z;
4144 
4145 }
4146 
4147 //--------------------------------------------------------------------------
4148 
4149 // Function to compute "pythia pT separation" from Particle input
4150 
4151 double History::pTLund(const Particle& RadAfterBranch,
4152  const Particle& EmtAfterBranch,
4153  const Particle& RecAfterBranch, int ShowerType){
4154 
4155  // Save type: 1 = FSR pT definition, else ISR definition
4156  int Type = ShowerType;
4157  // Calculate virtuality of splitting
4158  int sign = (Type==1) ? 1 : -1;
4159  Vec4 Q(RadAfterBranch.p() + sign*EmtAfterBranch.p());
4160  double Qsq = sign * Q.m2Calc();
4161  // Mass term of radiator
4162  double m2Rad = (mergingHooksPtr->includeMassive()
4163  && abs(RadAfterBranch.id()) >= 4
4164  && abs(RadAfterBranch.id()) < 7)
4165  ? pow(particleDataPtr->m0(RadAfterBranch.id()), 2)
4166  : 0.;
4167  // Construct 2->3 variables for FSR
4168  Vec4 sum = RadAfterBranch.p() + RecAfterBranch.p()
4169  + EmtAfterBranch.p();
4170  double m2Dip = sum.m2Calc();
4171  double x1 = 2. * (sum * RadAfterBranch.p()) / m2Dip;
4172  double x3 = 2. * (sum * EmtAfterBranch.p()) / m2Dip;
4173  // Construct momenta of dipole before/after splitting for ISR
4174  Vec4 qBR(RadAfterBranch.p() - EmtAfterBranch.p() + RecAfterBranch.p());
4175  Vec4 qAR(RadAfterBranch.p() + RecAfterBranch.p());
4176  // Calculate z of splitting, different for FSR and ISR
4177  double z = (Type==1) ? x1/(x1+x3)
4178  : (qBR.m2Calc())/( qAR.m2Calc());
4179  // Separation of splitting, different for FSR and ISR
4180  double pTpyth = (Type==1) ? z*(1.-z) : (1.-z);
4181  // pT^2 = separation*virtuality
4182  pTpyth *= (Qsq - sign*m2Rad);
4183  if(pTpyth < 0.){
4184  infoPtr->errorMsg("Warning in History::pTLund: Reconstructed evolution",
4185  "variable for massive splitting negative, raised to 0.");
4186  pTpyth = 0.;
4187  }
4188  // Return pT
4189  return sqrt(pTpyth);
4190 }
4191 
4192 //==========================================================================
4193 
4194 } // end namespace Pythia8
Definition: AgUStep.h:26