StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PartonLevel.cc
1 // PartonLevel.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 // Function definitions (not found in the header) for the PartonLevel class.
7 
8 #include "PartonLevel.h"
9 
10 namespace Pythia8 {
11 
12 //==========================================================================
13 
14 // The PartonLevel class.
15 
16 //--------------------------------------------------------------------------
17 
18 // Constants: could be changed here if desired, but normally should not.
19 // These are of technical nature, as described for each.
20 
21 // Maximum number of tries to produce parton level from given input.
22 const int PartonLevel::NTRY = 10;
23 
24 //--------------------------------------------------------------------------
25 
26 // Main routine to initialize the parton-level generation process.
27 
28 bool PartonLevel::init( Info* infoPtrIn, Settings& settings,
29  ParticleData* particleDataPtrIn, Rndm* rndmPtrIn,
30  BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn,
31  BeamParticle* beamPomAPtrIn, BeamParticle* beamPomBPtrIn,
32  Couplings* couplingsPtrIn, PartonSystems* partonSystemsPtrIn,
33  SigmaTotal* sigmaTotPtr, TimeShower* timesDecPtrIn, TimeShower* timesPtrIn,
34  SpaceShower* spacePtrIn, RHadrons* rHadronsPtrIn,
35  UserHooks* userHooksPtrIn,
36  MergingHooks* mergingHooksPtrIn, bool useAsTrial ) {
37 
38  // Store input pointers and modes for future use.
39  infoPtr = infoPtrIn;
40  particleDataPtr = particleDataPtrIn;
41  rndmPtr = rndmPtrIn;
42  beamAPtr = beamAPtrIn;
43  beamBPtr = beamBPtrIn;
44  beamHadAPtr = beamAPtr;
45  beamHadBPtr = beamBPtr;
46  beamPomAPtr = beamPomAPtrIn;
47  beamPomBPtr = beamPomBPtrIn;
48  couplingsPtr = couplingsPtrIn;
49  partonSystemsPtr = partonSystemsPtrIn;
50  timesDecPtr = timesDecPtrIn;
51  timesPtr = timesPtrIn;
52  spacePtr = spacePtrIn;
53  rHadronsPtr = rHadronsPtrIn;
54  userHooksPtr = userHooksPtrIn;
55 
56  mergingHooksPtr = mergingHooksPtrIn;
57 
58  // Min bias and single diffraction processes need special treatment.
59  doMinBias = settings.flag("SoftQCD:all")
60  || settings.flag("SoftQCD:minBias");
61  doDiffraction = settings.flag("SoftQCD:all")
62  || settings.flag("SoftQCD:singleDiffractive")
63  || settings.flag("SoftQCD:doubleDiffractive");
64 
65  // Separate low-mass (unresolved) and high-mass (perturbative) diffraction.
66  mMinDiff = settings.parm("Diffraction:mMinPert");
67  mWidthDiff = settings.parm("Diffraction:mWidthPert");
68  pMaxDiff = settings.parm("Diffraction:probMaxPert");
69  if (mMinDiff + mWidthDiff > infoPtr->eCM()) doDiffraction = false;
70 
71  // Need MPI initialization for soft QCD processes, even if only first MPI.
72  // But no need to initialize MPI if never going to use it.
73  doMPI = settings.flag("PartonLevel:MPI");
74  doMPIMB = doMPI;
75  doMPISDA = doMPI;
76  doMPISDB = doMPI;
77  doMPIinit = doMPI;
78  if (doMinBias || doDiffraction) doMPIinit = true;
79  if (!settings.flag("PartonLevel:all")) doMPIinit = false;
80 
81 // doTrial = settings.flag("PartonLevel:Trial");
82 // nTrialEmissions = (doTrial) ? settings.mode("PartonLevel:nTrial") : -1;
83  bool hasMergingHooks = (mergingHooksPtr > 0);
84  doMerging = settings.flag("Merging:doUserMerging")
85  || settings.flag("Merging:doMGMerging")
86  || settings.flag("Merging:doKTMerging");
87  doMerging = doMerging && hasMergingHooks;
88  doTrial = useAsTrial;
89  doMergeFirstEmm = doMerging && !doTrial;
90  nTrialEmissions = 1;
91  pTLastBranch = 0.0;
92  typeLastBranch = 0;
93 
94  // Flags for showers: ISR and FSR.
95  doISR = settings.flag("PartonLevel:ISR");
96  bool FSR = settings.flag("PartonLevel:FSR");
97  bool FSRinProcess = settings.flag("PartonLevel:FSRinProcess");
98  bool interleaveFSR = settings.flag("TimeShower:interleave");
99  doFSRduringProcess = FSR && FSRinProcess && interleaveFSR;
100  doFSRafterProcess = FSR && FSRinProcess && !interleaveFSR;
101  doFSRinResonances = FSR && settings.flag("PartonLevel:FSRinResonances");
102 
103  // Some other flags.
104  doRemnants = settings.flag("PartonLevel:Remnants");
105  doSecondHard = settings.flag("SecondHard:generate");
106 
107  // Allow R-hadron formation.
108  allowRH = settings.flag("RHadrons:allow");
109 
110  // Flag if lepton beams, and if non-resolved ones. May change main flags.
111  hasLeptonBeams = ( beamAPtr->isLepton() || beamBPtr->isLepton() );
112  hasPointLeptons = ( hasLeptonBeams
113  && (beamAPtr->isUnresolved() || beamBPtr->isUnresolved() ) );
114  if (hasLeptonBeams) {
115  doMPIMB = false;
116  doMPISDA = false;
117  doMPISDB = false;
118  doMPIinit = false;
119  }
120  if (hasPointLeptons) {
121  doISR = false;
122  doRemnants = false;
123  }
124 
125  // Possibility to allow user veto during evolution.
126  canVetoPT = (userHooksPtr > 0) ? userHooksPtr->canVetoPT() : false;
127  pTvetoPT = (canVetoPT) ? userHooksPtr->scaleVetoPT() : -1.;
128  canVetoStep = (userHooksPtr > 0) ? userHooksPtr->canVetoStep() : false;
129  nVetoStep = (canVetoStep) ? userHooksPtr->numberVetoStep() : -1;
130  canVetoMPIStep = (userHooksPtr > 0) ? userHooksPtr->canVetoMPIStep() : false;
131  nVetoMPIStep = (canVetoStep) ? userHooksPtr->numberVetoMPIStep() : -1;
132 
133  // Possibility to set maximal shower scale in resonance decays.
134  canSetScale = (userHooksPtr > 0) ? userHooksPtr->canSetResonanceScale()
135  : false;
136 
137  // Set info and initialize the respective program elements.
138  timesPtr->init( beamAPtr, beamBPtr);
139  if (doISR) spacePtr->init( beamAPtr, beamBPtr);
140  doMPIMB = multiMB.init( doMPIinit, 0, infoPtr, settings, particleDataPtr,
141  rndmPtr, beamAPtr, beamBPtr, couplingsPtr, partonSystemsPtr, sigmaTotPtr,
142  userHooksPtr);
143  if (doDiffraction) doMPISDA = multiSDA.init( doMPIinit, 1, infoPtr,
144  settings, particleDataPtr, rndmPtr, beamPomBPtr, beamAPtr, couplingsPtr,
145  partonSystemsPtr, sigmaTotPtr, userHooksPtr);
146  if (doDiffraction) doMPISDB = multiSDB.init( doMPIinit, 2, infoPtr,
147  settings, particleDataPtr, rndmPtr, beamPomAPtr, beamBPtr, couplingsPtr,
148  partonSystemsPtr, sigmaTotPtr, userHooksPtr);
149  remnants.init( infoPtr, settings, rndmPtr, beamAPtr, beamBPtr,
150  partonSystemsPtr);
151 
152  // Succeeded, or not.
153  multiPtr = &multiMB;
154  if (doMPIinit && !doMPIMB) return false;
155  if (doMPIinit && doDiffraction && (!doMPISDA || !doMPISDB)) return false;
156  if (!doMPIMB || !doMPISDA || !doMPISDB) doMPI = false;
157  return true;
158 }
159 
160 //--------------------------------------------------------------------------
161 
162 // Function to reset PartonLevel object for trial shower usage.
163 
164 void PartonLevel::resetTrial() {
165 
166  // Clear input pointers
167  partonSystemsPtr->clear();
168  beamAPtr->clear();
169  beamBPtr->clear();
170  beamHadAPtr->clear();
171  beamHadBPtr->clear();
172  beamPomAPtr->clear();
173  beamPomBPtr->clear();
174 
175  // Clear last branching return values
176  pTLastBranch = 0.0;
177  typeLastBranch = 0;
178 
179 }
180 
181 //--------------------------------------------------------------------------
182 
183 // Main routine to do the parton-level evolution.
184 
185 bool PartonLevel::next( Event& process, Event& event) {
186 
187  // Current event classification.
188  isResolved = infoPtr->isResolved();
189  isResolvedA = isResolved;
190  isResolvedB = isResolved;
191  isDiffA = infoPtr->isDiffractiveA();
192  isDiffB = infoPtr->isDiffractiveB();
193  isDiff = isDiffA || isDiffB;
194  isDoubleDiff = isDiffA && isDiffB;
195  isSingleDiff = isDiff && !isDoubleDiff;
196  isMinBias = infoPtr->isMinBias();
197 
198  // nHardLoop counts how many hard-scattering subsystems are to be processed.
199  // Almost always 1, but elastic and low-mass diffraction gives 0, while
200  // double diffraction can give up to 2. Not to be confused with SecondHard.
201  int nHardLoop = 1;
202  if (!isResolved) nHardLoop = (isDiff) ? decideResolvedDiff( process) : 0;
203 
204  // Handle unresolved subsystems. Done if no resolved ones.
205  sizeProcess = 0;
206  sizeEvent = 0;
207  if (!isResolvedA || !isResolvedB) {
208  bool physical = setupUnresolvedSys( process, event);
209  if (!physical || nHardLoop == 0) return physical;
210  sizeProcess = process.size();
211  sizeEvent = event.size();
212  }
213 
214  // Number of actual branchings
215  int nBranch = 0;
216  // Number of desired branchings, negative value means no restriction
217  int nBranchMax = (doTrial) ? nTrialEmissions : -1;
218 
219  // Big outer loop to handle up to two systems (in double diffraction),
220  // but normally one. (Not indented in following, but end clearly marked.)
221  for (int iHardLoop = 1; iHardLoop <= nHardLoop; ++iHardLoop) {
222  infoPtr->setCounter(20, iHardLoop);
223  infoPtr->setCounter(21);
224 
225  // Process and event records can be out of step for diffraction.
226  if (iHardLoop == 2) {
227  sizeProcess = process.size();
228  sizeEvent = event.size();
229  partonSystemsPtr->clear();
230  }
231 
232  // If you need to restore then do not throw existing diffractive system.
233  if (isDiff) {
234  event.saveSize();
235  event.saveJunctionSize();
236  }
237 
238  // Allow special treatment of diffractive systems.
239  if (isDiff) setupResolvedDiff(iHardLoop, process);
240 
241  // Prepare to do multiparton interactions; at new mass for diffraction.
242  if (doMPIinit) multiPtr->reset();
243 
244  // Special case if minimum bias: do hardest interaction.
245  if (isMinBias || isDiff) {
246  multiPtr->pTfirst();
247  multiPtr->setupFirstSys( process);
248  }
249 
250  // Allow up to ten tries; failure possible for beam remnants.
251  // Main cause: inconsistent colour flow at the end of the day.
252  bool physical = true;
253  int nRad = 0;
254  for (int iTry = 0; iTry < NTRY; ++ iTry) {
255  infoPtr->addCounter(21);
256  for (int i = 22; i < 32; ++i) infoPtr->setCounter(i);
257 
258  // Reset flag, counters and max scales.
259  physical = true;
260  nMPI = (doSecondHard) ? 2 : 1;
261  nISR = 0;
262  nFSRinProc = 0;
263  nFSRinRes = 0;
264  nISRhard = 0;
265  nFSRhard = 0;
266  pTsaveMPI = 0.;
267  pTsaveISR = 0.;
268  pTsaveFSR = 0.;
269 
270  // Identify hard interaction system for showers.
271  setupHardSys( iHardLoop, process, event);
272 
273  // Optionally check for a veto after the hardest interaction.
274  if (canVetoMPIStep) {
275  doVeto = userHooksPtr->doVetoMPIStep( 1, event);
276  // Abort event if vetoed.
277  if (doVeto) {
278  if (isDiff) leaveResolvedDiff( iHardLoop, event);
279  return false;
280  }
281  }
282 
283  // Check matching of process scale to maximum ISR/FSR/MPI scales.
284  double Q2Fac = infoPtr->Q2Fac();
285  double Q2Ren = infoPtr->Q2Ren();
286  bool limitPTmaxISR = (doISR)
287  ? spacePtr->limitPTmax( event, Q2Fac, Q2Ren) : false;
288  bool limitPTmaxFSR = (doFSRduringProcess)
289  ? timesPtr->limitPTmax( event, Q2Fac, Q2Ren) : false;
290  bool limitPTmaxMPI = (doMPI) ? multiPtr->limitPTmax( event) : false;
291 
292  // Set hard scale, maximum for showers and multiparton interactions,
293  double pTscale = process.scale();
294  if (doSecondHard) pTscale = max( pTscale, process.scaleSecond() );
295  double pTmaxMPI = (limitPTmaxMPI) ? pTscale : infoPtr->eCM();
296  double pTmaxISR = (limitPTmaxISR) ? spacePtr->enhancePTmax() * pTscale
297  : infoPtr->eCM();
298  double pTmaxFSR = (limitPTmaxFSR) ? timesPtr->enhancePTmax() * pTscale
299  : infoPtr->eCM();
300  double pTmax = max( pTmaxMPI, max( pTmaxISR, pTmaxFSR) );
301  pTsaveMPI = pTmaxMPI;
302  pTsaveISR = pTmaxISR;
303  pTsaveFSR = pTmaxFSR;
304 
305  // Prepare the classes to begin the generation.
306  if (doMPI) multiPtr->prepare( event, pTmaxMPI);
307  if (doISR) spacePtr->prepare( 0, event, limitPTmaxISR);
308  if (doFSRduringProcess) timesPtr->prepare( 0, event, limitPTmaxFSR);
309  if (doSecondHard && doISR) spacePtr->prepare( 1, event, limitPTmaxISR);
310  if (doSecondHard && doFSRduringProcess)
311  timesPtr->prepare( 1, event, limitPTmaxFSR);
312 
313  // Impact parameter has now been chosen, except for diffraction.
314  if (!isDiff) infoPtr->setImpact( multiPtr->bMPI(), multiPtr->enhanceMPI());
315 
316  // Set up initial veto scale.
317  doVeto = false;
318  double pTveto = pTvetoPT;
319  typeLatest = 0;
320 
321  // Begin evolution down in pT from hard pT scale.
322  do {
323  infoPtr->addCounter(22);
324  typeVetoStep = 0;
325  nRad = nISR + nFSRinProc;
326 
327  // Find next pT value for FSR, MPI and ISR.
328  // Order calls to minimize time expenditure.
329  double pTgen = 0.;
330  double pTtimes = (doFSRduringProcess)
331  ? timesPtr->pTnext( event, pTmaxFSR, pTgen) : -1.;
332  pTgen = max( pTgen, pTtimes);
333  double pTmulti = (doMPI)
334  ? multiPtr->pTnext( pTmaxMPI, pTgen, event) : -1.;
335  pTgen = max( pTgen, pTmulti);
336  double pTspace = (doISR)
337  ? spacePtr->pTnext( event, pTmaxISR, pTgen, nRad) : -1.;
338  double pTnow = max( pTtimes, max( pTmulti, pTspace));
339  infoPtr->setPTnow( pTnow);
340 
341  // Allow a user veto. Only do it once, so remember to change pTveto.
342  if (pTveto > 0. && pTveto > pTnow) {
343  pTveto = -1.;
344  doVeto = userHooksPtr->doVetoPT( typeLatest, event);
345  // Abort event if vetoed.
346  if (doVeto) {
347  if (isDiff) leaveResolvedDiff( iHardLoop, event);
348  return false;
349  }
350  }
351 
352  // Do a multiparton interaction (if allowed).
353  if (pTmulti > 0. && pTmulti > pTspace && pTmulti > pTtimes) {
354  infoPtr->addCounter(23);
355  if (multiPtr->scatter( event)) {
356  typeLatest = 1;
357  ++nMPI;
358  if (canVetoMPIStep && nMPI <= nVetoMPIStep) typeVetoStep = 1;
359 
360  // Update ISR and FSR dipoles.
361  if (doISR) spacePtr->prepare( nMPI - 1, event);
362  if (doFSRduringProcess) timesPtr->prepare( nMPI - 1, event);
363  }
364 
365  // Set maximal scales for next pT to pick.
366  pTmaxMPI = pTmulti;
367  pTmaxISR = min( pTmulti, pTmaxISR);
368  pTmaxFSR = min( pTmulti, pTmaxFSR);
369  pTmax = pTmulti;
370 
371  nBranch++;
372  pTLastBranch = pTmulti;
373  typeLastBranch = 1;
374  }
375 
376  // Do an initial-state emission (if allowed).
377  else if (pTspace > 0. && pTspace > pTtimes) {
378  infoPtr->addCounter(24);
379  if (spacePtr->branch( event)) {
380  typeLatest = 2;
381  iSysNow = spacePtr->system();
382  ++nISR;
383  if (iSysNow == 0) ++nISRhard;
384  if (canVetoStep && iSysNow == 0 && nISRhard <= nVetoStep)
385  typeVetoStep = 2;
386 
387  // Update FSR dipoles.
388  if (doFSRduringProcess) timesPtr->update( iSysNow, event);
389 
390  nBranch++;
391  pTLastBranch = pTspace;
392  typeLastBranch = 2;
393 
394  // Rescatter: it is possible for kinematics to fail, in which
395  // case we need to restart the parton level processing.
396  } else if (spacePtr->doRestart()) {
397  physical = false;
398  break;
399  }
400 
401  // Set maximal scales for next pT to pick.
402  pTmaxMPI = min( pTspace, pTmaxMPI);
403  pTmaxISR = pTspace;
404  pTmaxFSR = min( pTspace, pTmaxFSR);
405  pTmax = pTspace;
406  }
407 
408  // Do a final-state emission (if allowed).
409  else if (pTtimes > 0.) {
410  infoPtr->addCounter(25);
411  if (timesPtr->branch( event, true)) {
412  typeLatest = 3;
413  iSysNow = timesPtr->system();
414  ++nFSRinProc;
415  if (iSysNow == 0) ++nFSRhard;
416  if (canVetoStep && iSysNow == 0 && nFSRhard <= nVetoStep)
417  typeVetoStep = 3;
418 
419  // Update ISR dipoles.
420  if (doISR) spacePtr->update( iSysNow, event);
421 
422  nBranch++;
423  pTLastBranch = pTtimes;
424  typeLastBranch = 3;
425 
426  }
427 
428  // Set maximal scales for next pT to pick.
429  pTmaxMPI = min( pTtimes, pTmaxMPI);
430  pTmaxISR = min( pTtimes, pTmaxISR);
431  pTmaxFSR = pTtimes;
432  pTmax = pTtimes;
433  }
434 
435  // If no pT scales above zero then nothing to be done.
436  else pTmax = 0.;
437 
438  // Optionally check for a veto after the first few interactions,
439  // or after the first few emissions, ISR or FSR, in the hardest system.
440  if (typeVetoStep == 1) {
441  doVeto = userHooksPtr->doVetoMPIStep( nMPI, event);
442  } else if (typeVetoStep > 1) {
443  doVeto = userHooksPtr->doVetoStep( typeVetoStep, nISRhard,
444  nFSRhard, event);
445  }
446 
447  // Abort event if vetoed.
448  if (doVeto) {
449  if (isDiff) leaveResolvedDiff( iHardLoop, event);
450  return false;
451  }
452 
453  // Keep on evolving until nothing is left to be done.
454  if (typeLatest > 0 && typeLatest < 4)
455  infoPtr->addCounter(25 + typeLatest);
456  infoPtr->setPartEvolved( nMPI, nISR);
457 
458  if(doMergeFirstEmm && (nISRhard + nFSRhard == 1)){
459  // Get number of clustering steps
460  int nSteps = mergingHooksPtr->getNumberOfClusteringSteps(process);
461  // Get maximal number of additional jets
462  int nJetMax = mergingHooksPtr->nMaxJets();
463  // Get merging scale value
464  double tms = mergingHooksPtr->tms();
465  // Get merging scale in current event
466  double tnow = 0.;
467  if(mergingHooksPtr->doKTMerging() || mergingHooksPtr->doMGMerging())
468  tnow = mergingHooksPtr->kTms(event);
469  else
470  tnow = mergingHooksPtr->tmsDefinition(event);
471  // Check veto condition
472  if(nSteps < nJetMax && tnow > tms){
473  mergingHooksPtr->setWeight(0.);
474  doVeto = true;
475  }
476  // Abort event if vetoed.
477  if (doVeto) {
478  if (isDiff) leaveResolvedDiff( iHardLoop, event);
479  return false;
480  }
481  }
482 
483  } while (pTmax > 0. && (nBranchMax <= 0 || nBranch < nBranchMax) );
484 
485  // Do all final-state emissions if not already considered above.
486  if (doFSRafterProcess && (nBranchMax <= 0 || nBranch < nBranchMax) ) {
487 
488  // Find largest scale for final partons.
489  pTmax = 0.;
490  for (int i = 0; i < event.size(); ++i)
491  if (event[i].isFinal() && event[i].scale() > pTmax)
492  pTmax = event[i].scale();
493  pTsaveFSR = pTmax;
494 
495  // Prepare all subsystems for evolution.
496  for (int iSys = 0; iSys < partonSystemsPtr->sizeSys(); ++iSys)
497  timesPtr->prepare( iSys, event);
498 
499  // Set up initial veto scale.
500  doVeto = false;
501  pTveto = pTvetoPT;
502 
503  // Begin evolution down in pT from hard pT scale.
504  do {
505  infoPtr->addCounter(29);
506  typeVetoStep = 0;
507  double pTtimes = timesPtr->pTnext( event, pTmax, 0.);
508  infoPtr->setPTnow( pTtimes);
509 
510  // Allow a user veto. Only do it once, so remember to change pTveto.
511  if (pTveto > 0. && pTveto > pTtimes) {
512  pTveto = -1.;
513  doVeto = userHooksPtr->doVetoPT( 4, event);
514  // Abort event if vetoed.
515  if (doVeto) {
516  if (isDiff) leaveResolvedDiff( iHardLoop, event);
517  return false;
518  }
519  }
520 
521  // Do a final-state emission (if allowed).
522  if (pTtimes > 0.) {
523  infoPtr->addCounter(30);
524  if (timesPtr->branch( event, true)) {
525  iSysNow = timesPtr->system();
526  ++nFSRinProc;
527  if (iSysNow == 0) ++nFSRhard;
528  if (canVetoStep && iSysNow == 0 && nFSRhard <= nVetoStep)
529  typeVetoStep = 4;
530 
531  nBranch++;
532  pTLastBranch = pTtimes;
533  typeLastBranch = 4;
534 
535  }
536  pTmax = pTtimes;
537  }
538 
539  // If no pT scales above zero then nothing to be done.
540  else pTmax = 0.;
541 
542  // Optionally check for a veto after the first few emissions.
543  if (typeVetoStep > 0) {
544  doVeto = userHooksPtr->doVetoStep( typeVetoStep, nISRhard,
545  nFSRhard, event);
546  // Abort event if vetoed.
547  if (doVeto) {
548  if (isDiff) leaveResolvedDiff( iHardLoop, event);
549  return false;
550  }
551  }
552 
553  if(doMergeFirstEmm && (nISRhard + nFSRhard == 1)){
554  // Get number of clustering steps
555  int nSteps = mergingHooksPtr->getNumberOfClusteringSteps(process);
556  // Get maximal number of additional jets
557  int nJetMax = mergingHooksPtr->nMaxJets();
558  // Get merging scale value
559  double tms = mergingHooksPtr->tms();
560  // Get merging scale in current event
561  double tnow = 0.;
562  if(mergingHooksPtr->doKTMerging() || mergingHooksPtr->doMGMerging())
563  tnow = mergingHooksPtr->kTms(event);
564  else
565  tnow = mergingHooksPtr->tmsDefinition(event);
566  // Check veto condition
567  if(nSteps < nJetMax && tnow > tms){
568  mergingHooksPtr->setWeight(0.);
569  doVeto = true;
570  }
571  // Abort event if vetoed.
572  if (doVeto) {
573  if (isDiff) leaveResolvedDiff( iHardLoop, event);
574  return false;
575  }
576  }
577 
578  // Keep on evolving until nothing is left to be done.
579  infoPtr->addCounter(31);
580  } while (pTmax > 0. && (nBranchMax <= 0 || nBranch < nBranchMax) );
581  }
582 
583  // Add beam remnants, including primordial kT kick and colour tracing.
584  if (physical && doRemnants && !remnants.add( event)) physical = false;
585 
586  // If no problems then done.
587  if (physical) break;
588 
589  // Else restore and loop, but do not throw existing diffractive system.
590  if (!isDiff) event.clear();
591  else {
592  event.restoreSize();
593  event.restoreJunctionSize();
594  }
595  beamAPtr->clear();
596  beamBPtr->clear();
597  partonSystemsPtr->clear();
598 
599  // End loop over ten tries. Restore from diffraction. Hopefully it worked.
600  }
601  if (isDiff) leaveResolvedDiff( iHardLoop, event);
602  if (!physical) return false;
603 
604  // End big outer loop to handle two systems in double diffraction.
605  }
606 
607  // Perform showers in resonance decay chains.
608  if(nBranchMax <= 0 || nBranch < nBranchMax)
609  doVeto = !resonanceShowers( process, event, true);
610  // Abort event if vetoed.
611  if (doVeto) return false;
612 
613  // Store event properties. Impact parameter not available for diffraction.
614  infoPtr->setEvolution( pTsaveMPI, pTsaveISR, pTsaveFSR,
615  nMPI, nISR, nFSRinProc, nFSRinRes);
616  if (isDiff) {
617  multiPtr->setEmpty();
618  infoPtr->setImpact( multiPtr->bMPI(), multiPtr->enhanceMPI());
619  }
620 
621  // Done.
622  return true;
623 }
624 
625 //--------------------------------------------------------------------------
626 
627 // Decide which diffractive subsystems are resolved (= perturbative).
628 
629 int PartonLevel::decideResolvedDiff( Event& process) {
630 
631  // Loop over two systems.
632  int nHighMass = 0;
633  for (int iDiffSys = 1; iDiffSys <= 2; ++iDiffSys) {
634  int iDiffMot = iDiffSys + 2;
635 
636  // Only high-mass diffractive systems should be resolved.
637  double mDiff = process[iDiffMot].m();
638  bool isHighMass = ( mDiff > mMinDiff && rndmPtr->flat()
639  < pMaxDiff * ( 1. - exp( -(mDiff - mMinDiff) / mWidthDiff ) ) );
640 
641  // Set outcome and done.
642  if (isHighMass) ++nHighMass;
643  if (iDiffSys == 1) isResolvedA = isHighMass;
644  if (iDiffSys == 2) isResolvedB = isHighMass;
645  }
646  return nHighMass;
647 
648 }
649 
650 //--------------------------------------------------------------------------
651 
652 // Set up an unresolved process, i.e. elastic or diffractive.
653 
654 bool PartonLevel::setupUnresolvedSys( Event& process, Event& event) {
655 
656  // No hard scale in event.
657  process.scale( 0.);
658 
659  // Copy particles from process to event.
660  for (int i = 0; i < process.size(); ++ i) event.append( process[i]);
661 
662  // Loop to find diffractively excited beams.
663  for (int i = 0; i < 2; ++i)
664  if ( (i == 0 && isDiffA && !isResolvedA)
665  || (i == 1 && isDiffB && !isResolvedB) ) {
666  int iBeam = i + 3;
667  BeamParticle* beamPtr = (i == 0) ? beamAPtr : beamBPtr;
668 
669  // Diffractive mass. Reconstruct boost and rotation to event cm frame.
670  double mDiff = process[iBeam].m();
671  double m2Diff = mDiff*mDiff;
672  double beta = process[iBeam].pAbs() / process[iBeam].e();
673  double theta = process[iBeam].theta();
674  double phi = process[iBeam].phi();
675 
676  // Pick quark or gluon kicked out and flavour subdivision.
677  bool gluonIsKicked = beamPtr->pickGluon(mDiff);
678  int id1 = beamPtr->pickValence();
679  int id2 = beamPtr->pickRemnant();
680 
681  // Find flavour masses. Scale them down if too big.
682  double m1 = particleDataPtr->constituentMass(id1);
683  double m2 = particleDataPtr->constituentMass(id2);
684  if (m1 + m2 > 0.5 * mDiff) {
685  double reduce = 0.5 * mDiff / (m1 + m2);
686  m1 *= reduce;
687  m2 *= reduce;
688  }
689 
690  // If quark is kicked out, then trivial kinematics in rest frame.
691  if (!gluonIsKicked) {
692  double pAbs = sqrt( pow2(m2Diff - m1*m1 - m2*m2)
693  - pow2(2. * m1 * m2) ) / (2. * mDiff);
694  double e1 = (m2Diff + m1*m1 - m2*m2) / (2. * mDiff);
695  double e2 = (m2Diff + m2*m2 - m1*m1) / (2. * mDiff);
696  Vec4 p1(0.,0., -pAbs, e1);
697  Vec4 p2(0.,0., pAbs, e2);
698 
699  // Boost and rotate to event cm frame.
700  p1.bst(0., 0., beta); p1.rot(theta, phi);
701  p2.bst(0., 0., beta); p2.rot(theta, phi);
702 
703  // Set colours.
704  int col1, acol1, col2, acol2;
705  if (particleDataPtr->colType(id1) == 1) {
706  col1 = event.nextColTag(); acol1 = 0;
707  col2 = 0; acol2 = col1;
708  } else {
709  col1 = 0; acol1 = event.nextColTag();
710  col2 = acol1; acol2 = 0;
711  }
712  // Update process colours to stay in step.
713  process.nextColTag();
714 
715  // Store partons of diffractive system and mark system decayed.
716  int iDauBeg = event.append( id1, 23, iBeam, 0, 0, 0, col1, acol1,
717  p1, m1);
718  int iDauEnd = event.append( id2, 63, iBeam, 0, 0, 0, col2, acol2,
719  p2, m2);
720  event[iBeam].statusNeg();
721  event[iBeam].daughters(iDauBeg, iDauEnd);
722 
723 
724  // If gluon is kicked out: share momentum between two remnants.
725  } else {
726  double m2Sys, zSys, pxSys, pySys, mTS1, mTS2;
727  zSys = beamPtr->zShare(mDiff, m1, m2);
728 
729  // Provide relative pT kick in remnant. Construct (transverse) masses.
730  pxSys = beamPtr->pxShare();
731  pySys = beamPtr->pyShare();
732  mTS1 = m1*m1 + pxSys*pxSys + pySys*pySys;
733  mTS2 = m2*m2 + pxSys*pxSys + pySys*pySys;
734  m2Sys = mTS1 / zSys + mTS2 / (1. - zSys);
735 
736  // Momentum of kicked-out massless gluon in diffractive rest frame.
737  double pAbs = (m2Diff - m2Sys) / (2. * mDiff);
738  Vec4 pG(0., 0., -pAbs, pAbs);
739  Vec4 pRem(0., 0., pAbs, mDiff - pAbs);
740 
741  // Momenta of the two beam remnant flavours. (Lightcone p+ = m_diff!)
742  double e1 = 0.5 * (zSys * mDiff + mTS1 / (zSys * mDiff));
743  double pL1 = 0.5 * (zSys * mDiff - mTS1 / (zSys * mDiff));
744  Vec4 p1(pxSys, pySys, pL1, e1);
745  Vec4 p2 = pRem - p1;
746 
747  // Boost and rotate to event cm frame.
748  pG.bst(0., 0., beta); pG.rot(theta, phi);
749  p1.bst(0., 0., beta); p1.rot(theta, phi);
750  p2.bst(0., 0., beta); p2.rot(theta, phi);
751 
752  // Set colours.
753  int colG, acolG, col1, acol1, col2, acol2;
754  if (particleDataPtr->colType(id1) == 1) {
755  col1 = event.nextColTag(); acol1 = 0;
756  colG = event.nextColTag(); acolG = col1;
757  col2 = 0; acol2 = colG;
758  } else {
759  col1 = 0; acol1 = event.nextColTag();
760  colG = acol1; acolG = event.nextColTag();
761  col2 = acolG; acol2 = 0;
762  }
763  // Update process colours to stay in step.
764  process.nextColTag();
765  process.nextColTag();
766 
767  // Store partons of diffractive system and mark system decayed.
768  int iDauBeg = event.append( 21, 23, iBeam, 0, 0, 0, colG, acolG,
769  pG, m1);
770  event.append( id1, 63, iBeam, 0, 0, 0, col1, acol1, p1, m1);
771  int iDauEnd = event.append( id2, 63, iBeam, 0, 0, 0, col2, acol2,
772  p2, m2);
773  event[iBeam].statusNeg();
774  event[iBeam].daughters(iDauBeg, iDauEnd);
775  }
776 
777  // End loop over beams. Done.
778  }
779  return true;
780 
781 }
782 
783 //--------------------------------------------------------------------------
784 
785 // Set up the hard process(es), excluding subsequent resonance decays.
786 
787  void PartonLevel::setupHardSys( int iHardLoop, Event& process,
788  Event& event) {
789 
790  // Incoming partons to hard process are stored in slots 3 and 4.
791  int inS = 0;
792  int inP = 3;
793  int inM = 4;
794 
795  // Identify any diffractive system, mother, last entry. Offset.
796  int iDiffSys = (iHardLoop == 2 || !isResolvedA) ? 2 : 1;
797  int iDiffMot = iDiffSys + 2;
798  int iDiffDau = process.size() - 1;
799  int nOffset = sizeEvent - sizeProcess;
800 
801  // Resolved diffraction means more entries.
802  if (isDiff) {
803  inS = iDiffMot;
804  inP = iDiffDau - 3;
805  inM = iDiffDau - 2;
806 
807  // Diffractively excited particle described as Pomeron-hadron beams.
808  event[inS].statusNeg();
809  event[inS].daughters( inP - 2 + nOffset, inM - 2 + nOffset);
810  }
811 
812  // If two hard interactions then find where second begins.
813  int iBeginSecond = process.size();
814  if (doSecondHard) {
815  iBeginSecond = 5;
816  while (process[iBeginSecond].status() != -21) ++iBeginSecond;
817  }
818 
819  // If incoming partons are massive then recalculate to put them massless.
820  if (process[inP].m() != 0. || process[inM].m() != 0.) {
821  double pPos = process[inP].pPos() + process[inM].pPos();
822  double pNeg = process[inP].pNeg() + process[inM].pNeg();
823  process[inP].pz( 0.5 * pPos);
824  process[inP].e( 0.5 * pPos);
825  process[inP].m( 0.);
826  process[inM].pz(-0.5 * pNeg);
827  process[inM].e( 0.5 * pNeg);
828  process[inM].m( 0.);
829  }
830 
831  // Add incoming hard-scattering partons to list in beam remnants.
832  double x1 = process[inP].pPos() / process[inS].m();
833  beamAPtr->append( inP + nOffset, process[inP].id(), x1);
834  double x2 = process[inM].pNeg() / process[inS].m();
835  beamBPtr->append( inM + nOffset, process[inM].id(), x2);
836 
837  // Scale. Find whether incoming partons are valence or sea. Store.
838  // When an x-dependent matter profile is used with minBias,
839  // trial interactions mean that the valence/sea choice has already
840  // been made and should be restored here.
841  double scale = process.scale();
842  int vsc1, vsc2;
843  beamAPtr->xfISR( 0, process[inP].id(), x1, scale*scale);
844  if (isMinBias && (vsc1 = multiPtr->getVSC1()) != 0)
845  (*beamAPtr)[0].companion(vsc1);
846  else vsc1 = beamAPtr->pickValSeaComp();
847  beamBPtr->xfISR( 0, process[inM].id(), x2, scale*scale);
848  if (isMinBias && (vsc2 = multiPtr->getVSC2()) != 0)
849  (*beamBPtr)[0].companion(vsc2);
850  else vsc2 = beamBPtr->pickValSeaComp();
851  bool isVal1 = (vsc1 == -3);
852  bool isVal2 = (vsc2 == -3);
853  infoPtr->setValence( isVal1, isVal2);
854 
855  // Initialize info needed for subsequent sequential decays + showers.
856  nHardDone = sizeProcess;
857  iPosBefShow.resize( process.size() );
858  fill (iPosBefShow.begin(),iPosBefShow.end(),0);
859 
860  // Add the beam and hard subprocess partons to the event record.
861  for (int i = sizeProcess; i < iBeginSecond; ++ i) {
862  if (process[i].mother1() > inM) break;
863  int j = event.append(process[i]);
864  iPosBefShow[i] = i;
865 
866  // Offset history if process and event not in step.
867  if (nOffset != 0) {
868  int iOrd = i - iBeginSecond + 7;
869  if (iOrd == 1 || iOrd == 2)
870  event[j].offsetHistory( 0, 0, 0, nOffset);
871  else if (iOrd == 3 || iOrd == 4)
872  event[j].offsetHistory( 0, nOffset, 0, nOffset);
873  else if (iOrd == 5 || iOrd == 6)
874  event[j].offsetHistory( 0, nOffset, 0, 0);
875  }
876 
877  // Currently outgoing ones should not count as decayed.
878  if (event[j].status() == -22) {
879  event[j].statusPos();
880  event[j].daughters(0, 0);
881  }
882 
883  // Complete task of copying hard subsystem into event record.
884  ++nHardDone;
885  }
886 
887  // Store participating partons as first set in list of all systems.
888  partonSystemsPtr->addSys();
889  partonSystemsPtr->setInA(0, inP + nOffset);
890  partonSystemsPtr->setInB(0, inM + nOffset);
891  for (int i = inM + 1; i < nHardDone; ++i)
892  partonSystemsPtr->addOut(0, i + nOffset);
893  partonSystemsPtr->setSHat( 0,
894  (event[inP + nOffset].p() + event[inM + nOffset].p()).m2Calc() );
895 
896  // Identify second hard process where applicable.
897  // Since internally generated incoming partons are guaranteed massless.
898  if (doSecondHard) {
899  int inP2 = iBeginSecond;
900  int inM2 = iBeginSecond + 1;
901 
902  // Add incoming hard-scattering partons to list in beam remnants.
903  // Not valid if not in rest frame??
904  x1 = process[inP2].pPos() / process[0].e();
905  beamAPtr->append( inP2, process[inP2].id(), x1);
906  x2 = process[inM2].pNeg() / process[0].e();
907  beamBPtr->append( inM2, process[inM2].id(), x2);
908 
909  // Find whether incoming partons are valence or sea.
910  scale = process.scaleSecond();
911  beamAPtr->xfISR( 1, process[inP2].id(), x1, scale*scale);
912  beamAPtr->pickValSeaComp();
913  beamBPtr->xfISR( 1, process[inM2].id(), x2, scale*scale);
914  beamBPtr->pickValSeaComp();
915 
916  // Add the beam and hard subprocess partons to the event record.
917  for (int i = inP2; i < process.size(); ++ i) {
918  int mother = process[i].mother1();
919  if ( (mother > 2 && mother < inP2) || mother > inM2 ) break;
920  event.append(process[i]);
921  iPosBefShow[i] = i;
922 
923  // Currently outgoing ones should not count as decayed.
924  if (event[i].status() == -22) {
925  event[i].statusPos();
926  event[i].daughters(0, 0);
927  }
928 
929  // Complete task of copying hard subsystem into event record.
930  ++nHardDone;
931  }
932 
933  // Store participating partons as second set in list of all systems.
934  partonSystemsPtr->addSys();
935  partonSystemsPtr->setInA(1, inP2);
936  partonSystemsPtr->setInB(1, inM2);
937  for (int i = inM2 + 1; i < nHardDone; ++i)
938  partonSystemsPtr->addOut(1, i);
939  partonSystemsPtr->setSHat( 1,
940  (event[inP2].p() + event[inM2].p()).m2Calc() );
941 
942  // End code for second hard process.
943  }
944 
945  // Update event colour tag to maximum in whole process.
946  int maxColTag = 0;
947  for (int i = 0; i < process.size(); ++ i) {
948  if (process[i].col() > maxColTag) maxColTag = process[i].col();
949  if (process[i].acol() > maxColTag) maxColTag = process[i].acol();
950  }
951  event.initColTag(maxColTag);
952 
953  // Copy junctions from process to event.
954  for (int i = 0; i < process.sizeJunction(); ++i)
955  event.appendJunction( process.getJunction(i));
956 
957  // Done.
958 }
959 
960 //--------------------------------------------------------------------------
961 
962 // Resolved diffraction: replace full event with diffractive subsystem.
963 
964 void PartonLevel::setupResolvedDiff(int iHardLoop, Event& process) {
965 
966  // Identify diffractive system, mother, last entry.
967  int iDiffSys = (iHardLoop == 2 || !isResolvedA) ? 2 : 1;
968  int iDiffMot = iDiffSys + 2;
969  int iDiffDau = process.size() - 1;
970 
971  // Diffractive system mass.
972  double mDiff = process[iDiffMot].m();
973  double m2Diff = mDiff * mDiff;
974 
975  // Diffractively excited particle described as Pomeron-hadron beams.
976  process[iDiffMot].statusNeg();
977  process[iDiffMot].daughters( iDiffDau + 1, iDiffDau + 2);
978 
979  // Set up Pomeron-proton system as if it were the complete collision.
980  int idHad = process[iDiffSys].id();
981  double mHad = process[iDiffSys].m();
982  double m2Had = mHad * mHad;
983  double m2Pom = (process[2].p() - process[4].p()).m2Calc();
984  double mPom = (m2Pom >= 0.) ? sqrt(m2Pom) : -sqrt(-m2Pom);
985  double eHad = 0.5 * (m2Diff + m2Had - m2Pom) / mDiff;
986  double ePom = 0.5 * (m2Diff + m2Pom - m2Had) / mDiff;
987  double pzHP = 0.5 * sqrtpos( pow2(m2Diff - m2Had - m2Pom)
988  - 4. * m2Had * m2Pom ) / mDiff;
989  process.append( 990, 13, iDiffMot, 0, 0, 0, 0, 0,
990  0., 0., pzHP, ePom, mPom);
991  process.append( idHad, 13, iDiffMot, 0, 0, 0, 0, 0,
992  0., 0., -pzHP, eHad, mHad);
993 
994  // Reassign multiparton interactions pointer to right object.
995  multiPtr = (iDiffSys == 1) ? &multiSDA : &multiSDB;
996 
997  // Reassign one beam pointer to refer to incoming Pomeron.
998  if (iDiffSys == 1) {
999  beamAPtr = beamPomBPtr;
1000  beamBPtr = beamHadAPtr;
1001  } else {
1002  beamAPtr = beamPomAPtr;
1003  beamBPtr = beamHadBPtr;
1004  }
1005 
1006  // Beams not found in normal slots 1 and 2.
1007  int beamOffset = (sizeEvent > 0) ? sizeEvent - 1 : 4;
1008 
1009  // Reassign beam pointers in other classes.
1010  timesPtr->reassignBeamPtrs( beamAPtr, beamBPtr, beamOffset);
1011  spacePtr->reassignBeamPtrs( beamAPtr, beamBPtr);
1012  remnants.reassignBeamPtrs( beamAPtr, beamBPtr);
1013 
1014  // Pretend that the diffractive system is the whole collision.
1015  eCMsave = infoPtr->eCM();
1016  infoPtr->setECM( mDiff);
1017  beamAPtr->newPzE( pzHP, ePom);
1018  beamBPtr->newPzE( -pzHP, eHad);
1019 
1020 }
1021 
1022 //--------------------------------------------------------------------------
1023 
1024 // Resolved diffraction: restore to original behaviour.
1025 
1026 void PartonLevel::leaveResolvedDiff( int iHardLoop, Event& event) {
1027 
1028  // Identify diffractive system.
1029  int iDiffSys = (iHardLoop == 2 || !isResolvedA) ? 2 : 1;
1030 
1031  // Reconstruct boost and rotation to event cm frame.
1032  Vec4 pPom = event[3 - iDiffSys].p() - event[5 - iDiffSys].p();
1033  Vec4 pHad = event[iDiffSys].p();
1034  RotBstMatrix MtoCM;
1035  MtoCM.fromCMframe( pPom, pHad);
1036 
1037  // Perform rotation and boost on diffractive system.
1038  int iFirst = (iHardLoop == 1) ? 5 + sizeEvent - sizeProcess : sizeEvent;
1039  for (int i = iFirst; i < event.size(); ++i)
1040  event[i].rotbst( MtoCM);
1041 
1042  // Restore multiparton interactions pointer to default object.
1043  multiPtr = &multiMB;
1044 
1045  // Restore beam pointers to incoming hadrons.
1046  beamAPtr = beamHadAPtr;
1047  beamBPtr = beamHadBPtr;
1048 
1049  // Reassign beam pointers in other classes.
1050  timesPtr->reassignBeamPtrs( beamAPtr, beamBPtr, 0);
1051  spacePtr->reassignBeamPtrs( beamAPtr, beamBPtr);
1052  remnants.reassignBeamPtrs( beamAPtr, beamBPtr);
1053 
1054  // Restore cm energy.
1055  infoPtr->setECM( eCMsave);
1056  beamAPtr->newPzE( event[1].pz(), event[1].e());
1057  beamBPtr->newPzE( event[2].pz(), event[2].e());
1058 
1059 }
1060 
1061 //--------------------------------------------------------------------------
1062 
1063 // Handle showers in successive resonance decays.
1064 
1065 bool PartonLevel::resonanceShowers( Event& process, Event& event,
1066  bool skipForR) {
1067 
1068  // Prepare to start over from beginning for R-hadron decays.
1069  if (allowRH) {
1070  if (skipForR) {
1071  nHardDoneRHad = nHardDone;
1072  inRHadDecay.resize(0);
1073  for (int i = 0; i < process.size(); ++i)
1074  inRHadDecay.push_back( false);
1075  } else nHardDone = nHardDoneRHad;
1076  }
1077 
1078  // Isolate next system to be processed, if anything remains.
1079  int nRes = 0;
1080  int nFSRres = 0;
1081  // Number of desired branchings, negative value means no restriction
1082  int nBranchMax = (doTrial) ? nTrialEmissions : -1;
1083 
1084  while (nHardDone < process.size()) {
1085  ++nRes;
1086  int iBegin = nHardDone;
1087 
1088  // In first call (skipForR = true) skip over resonances
1089  // that should form R-hadrons, and their daughters.
1090  if (allowRH) {
1091  if (skipForR) {
1092  bool comesFromR = false;
1093  int iTraceUp = iBegin;
1094  do {
1095  if ( rHadronsPtr->givesRHadron(process[iTraceUp].id()) )
1096  comesFromR = true;
1097  iTraceUp = process[iTraceUp].mother1();
1098  } while (iTraceUp > 0 && !comesFromR);
1099  if (comesFromR) {
1100  inRHadDecay[iBegin] = true;
1101  ++nHardDone;
1102  continue;
1103  }
1104 
1105  // In optional second call (skipForR = false) process decay chains
1106  // inside R-hdrons.
1107  } else if (!inRHadDecay[iBegin]) {
1108  ++nHardDone;
1109  continue;
1110  }
1111  }
1112 
1113  // Mother in hard process and in complete event (after shower).
1114  int iHardMother = process[iBegin].mother1();
1115  Particle& hardMother = process[iHardMother];
1116  int iBefMother = iPosBefShow[iHardMother];
1117  int iAftMother = event.iBotCopyId(iBefMother);
1118  // Possibly trace across intermediate R-hadron state.
1119  if (allowRH) {
1120  int iTraceRHadron = rHadronsPtr->trace( iAftMother);
1121  if (iTraceRHadron > 0) iAftMother = iTraceRHadron;
1122  }
1123  Particle& aftMother = event[iAftMother];
1124 
1125  // From now on mother counts as decayed.
1126  aftMother.statusNeg();
1127 
1128  // Mother can have been moved by showering (in any of previous steps),
1129  // so prepare to update colour and momentum information for system.
1130  int colBef = hardMother.col();
1131  int acolBef = hardMother.acol();
1132  int colAft = aftMother.col();
1133  int acolAft = aftMother.acol();
1134  RotBstMatrix M;
1135  M.bst( hardMother.p(), aftMother.p());
1136 
1137  // Extract next partons from hard event into normal event record.
1138  for (int i = iBegin; i < process.size(); ++ i) {
1139  if (process[i].mother1() != iHardMother) break;
1140  int iNow = event.append( process[i] );
1141  iPosBefShow[i] = iNow;
1142  Particle& now = event.back();
1143 
1144  // Currently outgoing ones should not count as decayed.
1145  if (now.status() == -22) {
1146  now.statusPos();
1147  now.daughters(0, 0);
1148  }
1149 
1150  // Update daughter and mother information.
1151  if (i == iBegin) event[iAftMother].daughter1( iNow);
1152  else event[iAftMother].daughter2( iNow);
1153  now.mother1(iAftMother);
1154 
1155  // Update colour and momentum information.
1156  if (now.col() == colBef) now.col( colAft);
1157  if (now.acol() == acolBef) now.acol( acolAft);
1158  now.rotbst( M);
1159 
1160  // Update vertex information.
1161  if (now.hasVertex()) now.vProd( aftMother.vDec() );
1162 
1163  // Complete task of copying next subsystem into event record.
1164  ++nHardDone;
1165  }
1166  int iEnd = nHardDone - 1;
1167 
1168  // Reset pT of last branching
1169  pTLastBranch = 0.0;
1170 
1171  // Do parton showers inside subsystem: maximum scale by mother mass.
1172  if (doFSRinResonances) {
1173  double pTmax = 0.5 * hardMother.m();
1174  if (canSetScale) pTmax
1175  = userHooksPtr->scaleResonance( iAftMother, event);
1176  nFSRhard = 0;
1177 
1178  // Add new system, automatically with two empty beam slots.
1179  int iSys = partonSystemsPtr->addSys();
1180  partonSystemsPtr->setSHat(iSys, pow2(hardMother.m()) );
1181 
1182  // Loop over allowed range to find all final-state particles.
1183  for (int i = iPosBefShow[iBegin]; i <= iPosBefShow[iEnd]; ++i)
1184  if (event[i].isFinal()) partonSystemsPtr->addOut( iSys, i);
1185 
1186  // Let prepare routine do the setup.
1187  timesDecPtr->prepare( iSys, event);
1188 
1189  // Number of actual branchings
1190  int nBranch = 0;
1191 
1192  // Set up initial veto scale.
1193  doVeto = false;
1194  double pTveto = pTvetoPT;
1195 
1196  // Begin evolution down in pT from hard pT scale.
1197  do {
1198  typeVetoStep = 0;
1199  double pTtimes = timesDecPtr->pTnext( event, pTmax, 0.);
1200 
1201  // Allow a user veto. Only do it once, so remember to change pTveto.
1202  if (pTveto > 0. && pTveto > pTtimes) {
1203  pTveto = -1.;
1204  doVeto = userHooksPtr->doVetoPT( 5, event);
1205  // Abort event if vetoed.
1206  if (doVeto) return false;
1207  }
1208 
1209  // Do a final-state emission (if allowed).
1210  if (pTtimes > 0.) {
1211  if (timesDecPtr->branch( event)) {
1212  ++nFSRres;
1213  ++nFSRhard;
1214  if (canVetoStep && nFSRhard <= nVetoStep) typeVetoStep = 5;
1215 
1216  nBranch++;
1217  pTLastBranch = pTtimes;
1218  typeLastBranch = 5;
1219 
1220  }
1221  pTmax = pTtimes;
1222  }
1223 
1224  // If no pT scales above zero then nothing to be done.
1225  else pTmax = 0.;
1226 
1227  // Optionally check for a veto after the first few emissions.
1228  if (typeVetoStep > 0) {
1229  doVeto = userHooksPtr->doVetoStep( typeVetoStep, 0, nFSRhard,
1230  event);
1231  // Abort event if vetoed.
1232  if (doVeto) return false;
1233  }
1234 
1235  if(doMergeFirstEmm && nFSRhard == 1){
1236  // Get number of clustering steps
1237  int nSteps = mergingHooksPtr->getNumberOfClusteringSteps(process);
1238  // Get maximal number of additional jets
1239  int nJetMax = mergingHooksPtr->nMaxJets();
1240  // Get merging scale value
1241  double tms = mergingHooksPtr->tms();
1242  // Get merging scale in current event
1243  double tnow = 0.;
1244  if(mergingHooksPtr->doKTMerging() || mergingHooksPtr->doMGMerging())
1245  tnow = mergingHooksPtr->kTms(event);
1246  else
1247  tnow = mergingHooksPtr->tmsDefinition(event);
1248  // Check veto condition
1249  if(nSteps < nJetMax && tnow > tms){
1250  mergingHooksPtr->setWeight(0.);
1251  doVeto = true;
1252  }
1253  // Abort event if vetoed.
1254  if (doVeto) return false;
1255  }
1256 
1257  // Keep on evolving until nothing is left to be done.
1258  } while (pTmax > 0. && (nBranchMax <= 0 || nBranch < nBranchMax) );
1259 
1260  }
1261 
1262  // No more systems to be processed. Set total number of emissions.
1263  }
1264  if (skipForR) nFSRinRes = nFSRres;
1265  return true;
1266 
1267 }
1268 
1269 //==========================================================================
1270 
1271 } // end namespace Pythia8
Definition: AgUStep.h:26