Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:26

0001 // MergingHooks.h is a part of the PYTHIA event generator.
0002 // Copyright (C) 2024 Torbjorn Sjostrand.
0003 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
0004 // Please respect the MCnet Guidelines, see GUIDELINES for details.
0005 
0006 // This file is written by Stefan Prestel.
0007 // Header file to allow user access to program at different stages.
0008 // HardProcess: Container class for the hard process to be merged. Holds the
0009 //              bookkeeping of particles not be be reclustered
0010 // MergingHooks: Steering class for matrix element merging. Some functions can
0011 //               be redefined in a derived class to have access to the merging
0012 
0013 #ifndef Pythia8_MergingHooks_H
0014 #define Pythia8_MergingHooks_H
0015 
0016 #include "Pythia8/Basics.h"
0017 #include "Pythia8/BeamParticle.h"
0018 #include "Pythia8/Event.h"
0019 #include "Pythia8/Info.h"
0020 #include "Pythia8/ParticleData.h"
0021 #include "Pythia8/PartonSystems.h"
0022 #include "Pythia8/PhysicsBase.h"
0023 #include "Pythia8/PythiaStdlib.h"
0024 #include "Pythia8/Settings.h"
0025 
0026 
0027 namespace Pythia8 {
0028 
0029 class PartonLevel;
0030 
0031 //==========================================================================
0032 
0033 // Declaration of hard process class
0034 // This class holds information on the desired hard 2->2 process
0035 // for the merging.
0036 // This class is a container class for History class use.
0037 
0038 class HardProcess {
0039 
0040 public:
0041 
0042    // Flavour of the first incoming particle
0043   int hardIncoming1;
0044   // Flavour of the second incoming particle
0045   int hardIncoming2;
0046   // Flavours of the outgoing particles
0047   vector<int> hardOutgoing1;
0048   vector<int> hardOutgoing2;
0049   // Flavour of intermediate bosons in the hard 2->2
0050   vector<int> hardIntermediate;
0051 
0052   // Current reference event
0053   Event state;
0054   // Potential positions of outgoing particles in reference event
0055   vector<int> PosOutgoing1;
0056   vector<int> PosOutgoing2;
0057   // Potential positions of intermediate bosons in reference event
0058   vector<int> PosIntermediate;
0059 
0060   // Information on merging scale read from LHE file
0061   double tms;
0062 
0063   // Default constructor
0064   HardProcess() : hardIncoming1(), hardIncoming2(), tms(){}
0065   // Default destructor
0066   virtual ~HardProcess(){}
0067 
0068   // Copy constructor
0069   HardProcess( const HardProcess& hardProcessIn )
0070     : state(hardProcessIn.state),
0071       tms(hardProcessIn.tms) {
0072     hardIncoming1 = hardProcessIn.hardIncoming1;
0073     hardIncoming2 = hardProcessIn.hardIncoming2;
0074     for(int i =0; i < int(hardProcessIn.hardOutgoing1.size());++i)
0075       hardOutgoing1.push_back( hardProcessIn.hardOutgoing1[i]);
0076     for(int i =0; i < int(hardProcessIn.hardOutgoing2.size());++i)
0077       hardOutgoing2.push_back( hardProcessIn.hardOutgoing2[i]);
0078     for(int i =0; i < int(hardProcessIn.hardIntermediate.size());++i)
0079       hardIntermediate.push_back( hardProcessIn.hardIntermediate[i]);
0080     for(int i =0; i < int(hardProcessIn.PosOutgoing1.size());++i)
0081       PosOutgoing1.push_back( hardProcessIn.PosOutgoing1[i]);
0082     for(int i =0; i < int(hardProcessIn.PosOutgoing2.size());++i)
0083       PosOutgoing2.push_back( hardProcessIn.PosOutgoing2[i]);
0084     for(int i =0; i < int(hardProcessIn.PosIntermediate.size());++i)
0085       PosIntermediate.push_back( hardProcessIn.PosIntermediate[i]);
0086   }
0087 
0088   // Constructor with path to LHE file
0089   HardProcess( string LHEfile, ParticleData* particleData) : hardIncoming1(),
0090     hardIncoming2(), tms() {
0091     state = Event();
0092     state.init("(hard process)", particleData);
0093     translateLHEFString(LHEfile);
0094   }
0095 
0096   // Constructor with core process input
0097   virtual void initOnProcess( string process, ParticleData* particleData);
0098 
0099   // Constructor with path to LHE file input
0100   void initOnLHEF( string LHEfile, ParticleData* particleData);
0101 
0102   // Function to access the LHE file and read relevant information
0103   void translateLHEFString( string LHEpath);
0104 
0105   // Function to translate the process string (in MG/ME notation)
0106   virtual void translateProcessString( string process);
0107 
0108   // Function to clear hard process information
0109   void clear();
0110 
0111   // Function to check whether the sets of candidates Pos1, Pos2, together
0112   // with the proposed candidate iPos give an allowed hard process state
0113   virtual bool allowCandidates(int iPos, vector<int> Pos1, vector<int> Pos2,
0114     const Event& event);
0115   // Function to identify the hard subprocess in the current event
0116   virtual void storeCandidates( const Event& event, string process);
0117   // Function to check if the particle event[iPos] matches any of
0118   // the stored outgoing particles of the hard subprocess
0119   virtual bool matchesAnyOutgoing(int iPos, const Event& event);
0120   // Function to check if instead of the particle event[iCandidate], another
0121   // particle could serve as part of the hard process. Assumes that iCandidate
0122   // is already stored as part of the hard process.
0123   virtual bool findOtherCandidates(int iPos, const Event& event,
0124     bool doReplace);
0125   // Function to exchange a stored hard process candidate with another choice.
0126   virtual bool exchangeCandidates( vector<int> candidates1,
0127     vector<int> candidates2,
0128     unordered_map<int,int> further1, unordered_map<int,int> further2);
0129 
0130   // Function to get the number of coloured final state partons in the
0131   // hard process
0132   int nQuarksOut();
0133   // Function to get the number of uncoloured final state particles in the
0134   // hard process
0135   int nLeptonOut();
0136   // Function to get the number of electroweak final state bosons in the
0137   // hard process
0138   int nBosonsOut();
0139 
0140   // Function to get the number of coloured initial state partons in the
0141   // hard process
0142   int nQuarksIn();
0143   // Function to get the number of uncoloured initial state particles in the
0144   // hard process
0145   int nLeptonIn();
0146   // Function to report if a resonace decay was found in the 2->2 sub-process
0147   // of the  current state
0148   int hasResInCurrent();
0149   // Function to report the number of resonace decays in the 2->2 sub-process
0150   // of the  current state
0151   int nResInCurrent();
0152   // Function to report if a resonace decay was found in the 2->2 hard process
0153   bool hasResInProc();
0154   // Function to print the hard process (for debug)
0155   void list() const;
0156   // Function to print the hard process candidates in the
0157   // Matrix element state (for debug)
0158   void listCandidates() const;
0159 
0160 };
0161 
0162 //==========================================================================
0163 
0164 // MergingHooks is base class for user input to the merging procedure.
0165 
0166 class MergingHooks : public PhysicsBase {
0167 
0168 public:
0169 
0170   // Constructor.
0171   MergingHooks() : useShowerPluginSave(), showers(),
0172     doUserMergingSave(false),
0173     doMGMergingSave(false),
0174     doKTMergingSave(false),
0175     doPTLundMergingSave(false),
0176     doCutBasedMergingSave(false), includeMassiveSave(),
0177     enforceStrongOrderingSave(),
0178     orderInRapiditySave(), pickByFullPSave(), pickByPoPT2Save(),
0179     includeRedundantSave(), pickBySumPTSave(), allowColourShufflingSave(),
0180     resetHardQRenSave(), resetHardQFacSave(), unorderedScalePrescipSave(),
0181     unorderedASscalePrescipSave(), unorderedPDFscalePrescipSave(),
0182     incompleteScalePrescipSave(), ktTypeSave(), nReclusterSave(),
0183     nQuarksMergeSave(), nRequestedSave(), scaleSeparationFactorSave(),
0184     nonJoinedNormSave(), fsrInRecNormSave(), herwigAcollFSRSave(),
0185     herwigAcollISRSave(), pT0ISRSave(), pTcutSave(),
0186     doNL3TreeSave(false),
0187     doNL3LoopSave(false),
0188     doNL3SubtSave(false),
0189     doUNLOPSTreeSave(false),
0190     doUNLOPSLoopSave(false),
0191     doUNLOPSSubtSave(false),
0192     doUNLOPSSubtNLOSave(false),
0193     doUMEPSTreeSave(false),
0194     doUMEPSSubtSave(false),
0195     doEstimateXSection(false),
0196     doRuntimeAMCATNLOInterfaceSave(false),
0197     applyVeto(),
0198     doRemoveDecayProducts(false), muMISave(), kFactor0jSave(), kFactor1jSave(),
0199     kFactor2jSave(), tmsValueSave(), tmsValueNow(), DparameterSave(),
0200     nJetMaxSave(), nJetMaxNLOSave(),
0201     doOrderHistoriesSave(true),
0202     doCutOnRecStateSave(false),
0203     doWeakClusteringSave(false),
0204     doSQCDClusteringSave(false), muFSave(), muRSave(), muFinMESave(),
0205     muRinMESave(),
0206     doIgnoreEmissionsSave(true),
0207     doIgnoreStepSave(true), pTsave(), weightCKKWL1Save(), weightCKKWL2Save(),
0208     nMinMPISave(), weightCKKWLSave(), weightFIRSTSave(),
0209     doVariations(false), nWgts(0), nJetMaxLocal(), nJetMaxNLOLocal(),
0210     hasJetMaxLocal(false),
0211     includeWGTinXSECSave(false), nHardNowSave(), nJetNowSave(),
0212     tmsHardNowSave(), tmsNowSave() {
0213       inputEvent = Event(); resonances.resize(0);
0214       useOwnHardProcess = false; hardProcess = 0; stopScaleSave= 0.0;
0215       nVetoedInMainShower = 0;}
0216 
0217   // Make History class friend to allow access to advanced switches
0218   friend class History;
0219   // Make Pythia class friend
0220   friend class Pythia;
0221   // Make PartonLevel class friend
0222   friend class PartonLevel;
0223   // Make SpaceShower class friend
0224   friend class SpaceShower;
0225   // Make TimeShower class friend
0226   friend class TimeShower;
0227   // Make Merging class friend
0228   friend class Merging;
0229 
0230   // Destructor.
0231   virtual ~MergingHooks();
0232   // Function encoding the functional definition of the merging scale
0233   virtual double tmsDefinition( const Event& event){ return event[0].e();}
0234   // Function to dampen weights calculated from histories with lowest
0235   // multiplicity reclustered events that do not pass the ME cuts
0236   virtual double dampenIfFailCuts( const Event& inEvent ) {
0237     // Dummy statement to avoid compiler warnings
0238     if(false) cout << inEvent[0].e();
0239     return 1.;
0240   }
0241   // Hooks to disallow states in the construction of all histories, e.g.
0242   // because jets are below the merging scale or fail the matrix element cuts
0243   // Function to allow interference in the construction of histories
0244   virtual bool canCutOnRecState() { return doCutOnRecStateSave; }
0245   // Function to check reclustered state while generating all possible
0246   // histories
0247   // Function implementing check of reclustered events while constructing
0248   // all possible histories
0249   virtual bool doCutOnRecState( const Event& event ) {
0250     // Dummy statement to avoid compiler warnings.
0251     if(false) cout << event[0].e();
0252     // Count number of final state partons.
0253     int nPartons = 0;
0254     for( int i=0; i < int(event.size()); ++i)
0255       if(  event[i].isFinal()
0256         && (event[i].isGluon() || event[i].isQuark()) )
0257         nPartons++;
0258     // For gg -> h, allow only histories with gluons in initial state
0259     if( hasEffectiveG2EW() && nPartons < 2){
0260       if(event[3].id() != 21 && event[4].id() != 21)
0261         return true;
0262     }
0263     return false;
0264   }
0265   // Function to allow not counting a trial emission.
0266   virtual bool canVetoTrialEmission() { return false;}
0267   // Function to check if trial emission should be rejected.
0268   virtual bool doVetoTrialEmission( const Event&, const Event& ) {
0269     return false; }
0270 
0271   // Function to calculate the hard process matrix element.
0272   virtual double hardProcessME( const Event& inEvent ) {
0273     // Dummy statement to avoid compiler warnings.
0274     if ( false ) cout << inEvent[0].e();
0275     return 1.; }
0276 
0277   // Functions for internal use inside Pythia source code
0278   // Initialize.
0279   virtual void init();
0280 
0281   // Function returning the value of the merging scale.
0282   double tms() {
0283     if(doCutBasedMergingSave) return 0.;
0284     //else return tmsValueSave;
0285     else return tmsValueNow;
0286   }
0287   double tmsCut() {
0288     if(doCutBasedMergingSave) return 0.;
0289     else return tmsValueSave;
0290   }
0291   void tms( double tmsIn ) { tmsValueNow = tmsIn; }
0292 
0293   // Function returning the value of the Delta R_{ij} cut for
0294   // cut based merging scale definition.
0295   double dRijMS() {
0296     return ((tmsListSave.size() == 3) ? tmsListSave[0] : 0.);
0297   }
0298   // Function returning the value of the pT_{i} cut for
0299   // cut based merging scale definition.
0300   double pTiMS() {
0301     return ((tmsListSave.size() == 3) ? tmsListSave[1] : 0.);
0302   }
0303   // Function returning the value of the pT_{i} cut for
0304   // cut based merging scale definition.
0305   double QijMS() {
0306     return ((tmsListSave.size() == 3) ? tmsListSave[2] : 0.);
0307   }
0308   // Function returning the value of the maximal number of merged jets.
0309   int nMaxJets() { return (hasJetMaxLocal) ? nJetMaxLocal : nJetMaxSave;}
0310   // Function returning the value of the maximal number of merged jets,
0311   // for which NLO corrections are available.
0312   int nMaxJetsNLO()
0313     { return (hasJetMaxLocal) ? nJetMaxNLOLocal : nJetMaxNLOSave;}
0314   // Function to return hard process string.
0315   string getProcessString() { return processNow;}
0316   // Function to return the number of outgoing partons in the core process
0317   int nHardOutPartons(){ return hardProcess->nQuarksOut();}
0318   // Function to return the number of outgoing leptons in the core process
0319   int nHardOutLeptons(){ return hardProcess->nLeptonOut();}
0320   // Function to return the number of outgoing electroweak bosons in the core
0321   // process.
0322   int nHardOutBosons(){ return hardProcess->nBosonsOut();}
0323   // Function to return the number of incoming partons (hadrons) in the core
0324   // process.
0325   int nHardInPartons(){ return hardProcess->nQuarksIn();}
0326   // Function to return the number of incoming leptons in the core process.
0327   int nHardInLeptons(){ return hardProcess->nLeptonIn();}
0328   // Function to report the number of resonace decays in the 2->2 sub-process
0329   // of the  current state.
0330   int nResInCurrent(){ return hardProcess->nResInCurrent();}
0331   // Function to determine if user defined merging should be applied.
0332   bool doUserMerging(){ return doUserMergingSave;}
0333   // Function to determine if automated MG/ME merging should be applied.
0334   bool doMGMerging() { return doMGMergingSave;}
0335   // Function to determine if KT merging should be applied.
0336   bool doKTMerging() { return doKTMergingSave;}
0337   // Function to determine if PTLund merging should be applied.
0338   bool doPTLundMerging() { return doPTLundMergingSave;}
0339   // Function to determine if cut based merging should be applied.
0340   bool doCutBasedMerging() { return doCutBasedMergingSave;}
0341   bool doCKKWLMerging() { return (doUserMergingSave || doMGMergingSave
0342     || doKTMergingSave || doPTLundMergingSave || doCutBasedMergingSave); }
0343   // Functions to determine if and which part of  UMEPS merging
0344   // should be applied
0345   bool doUMEPSTree() { return doUMEPSTreeSave;}
0346   bool doUMEPSSubt() { return doUMEPSSubtSave;}
0347   bool doUMEPSMerging() { return (doUMEPSTreeSave || doUMEPSSubtSave);}
0348   // Functions to determine if and which part of  NL3 merging
0349   // should be applied
0350   bool doNL3Tree() { return doNL3TreeSave;}
0351   bool doNL3Loop() { return doNL3LoopSave;}
0352   bool doNL3Subt() { return doNL3SubtSave;}
0353   bool doNL3Merging() { return (doNL3TreeSave || doNL3LoopSave
0354                              || doNL3SubtSave); }
0355   // Functions to determine if and which part of UNLOPS merging
0356   // should be applied
0357   bool doUNLOPSTree() { return doUNLOPSTreeSave;}
0358   bool doUNLOPSLoop() { return doUNLOPSLoopSave;}
0359   bool doUNLOPSSubt() { return doUNLOPSSubtSave;}
0360   bool doUNLOPSSubtNLO() { return doUNLOPSSubtNLOSave;}
0361   bool doUNLOPSMerging() { return (doUNLOPSTreeSave || doUNLOPSLoopSave
0362                              || doUNLOPSSubtSave || doUNLOPSSubtNLOSave); }
0363 
0364   // Function to determine if we have a runtime interface to aMC@NLO.
0365   bool doRuntimeAMCATNLOInterface() { return doRuntimeAMCATNLOInterfaceSave;}
0366 
0367   // Return the number clustering steps that have actually been done.
0368   int nRecluster() { return nReclusterSave;}
0369 
0370   // Return number of requested additional jets on top of the Born process.
0371   int nRequested() { return nRequestedSave;}
0372 
0373   //----------------------------------------------------------------------//
0374   // Output functions to analyse/prepare event for merging
0375   //----------------------------------------------------------------------//
0376 
0377   // Function to check if event contains an emission not present in the hard
0378   // process.
0379   bool isFirstEmission(const Event& event);
0380 
0381   // Function to allow effective gg -> EW boson couplings.
0382   bool hasEffectiveG2EW() {
0383     if ( getProcessString().compare("pp>h") == 0 ) return true;
0384     return false; }
0385 
0386   // Function to allow effective gg -> EW boson couplings.
0387   bool allowEffectiveVertex( vector<int> in, vector<int> out) {
0388     if ( getProcessString().compare("ta+ta->jj") == 0
0389       || getProcessString().compare("ta-ta+>jj") == 0 ) {
0390       int nInFermions(0), nOutFermions(0);
0391       for (int i=0; i < int(in.size()); ++i)
0392         if (abs(in[i])<20) nInFermions++;
0393       for (int i=0; i < int(out.size()); ++i)
0394         if (abs(out[i])<20) nOutFermions++;
0395       return (nInFermions%2==0 && nOutFermions%2==0);
0396     }
0397     return false;
0398   }
0399 
0400   // Return event stripped from decay products.
0401   Event bareEvent( const Event& inputEventIn, bool storeInputEvent );
0402   // Write event with decay products attached to argument.
0403   bool reattachResonanceDecays( Event& process );
0404 
0405   // Check if particle at position iPos is part of the hard sub-system
0406   bool isInHard( int iPos, const Event& event);
0407 
0408   // Function to return the number of clustering steps for the current event
0409   virtual int getNumberOfClusteringSteps(const Event& event,
0410     bool resetNjetMax = false);
0411 
0412   //----------------------------------------------------------------------//
0413   // Functions to steer construction of histories
0414   //----------------------------------------------------------------------//
0415 
0416   // Function to force preferred picking of ordered histories. By default,
0417   // unordered histories will only be considered if no ordered histories
0418   // were found.
0419   void orderHistories( bool doOrderHistoriesIn) {
0420     doOrderHistoriesSave = doOrderHistoriesIn; }
0421   // Function to force cut on reconstructed states internally, as needed
0422   // for gg -> Higgs to ensure that e.g. uu~ -> Higgs is not constructed.
0423   void allowCutOnRecState( bool doCutOnRecStateIn) {
0424     doCutOnRecStateSave = doCutOnRecStateIn; }
0425 
0426   // Function to allow final state clusterings of weak bosons
0427   void doWeakClustering( bool doWeakClusteringIn ) {
0428     doWeakClusteringSave = doWeakClusteringIn; }
0429 
0430   //----------------------------------------------------------------------//
0431   // Functions used as default merging scales
0432   //----------------------------------------------------------------------//
0433 
0434   // Function to check if the input particle is a light jet, i.e. should be
0435   // checked against the merging scale defintion.
0436   bool checkAgainstCut( const Particle& particle);
0437   // Function to return the value of the merging scale function in the
0438   // current event.
0439   virtual double tmsNow( const Event& event );
0440   // Find the minimal Lund pT between coloured partons in the event
0441   double rhoms( const Event& event, bool withColour);
0442   // Function to calculate the minimal kT in the event
0443   double kTms(const Event & event);
0444   // Find the if the event passes the Delta R_{ij}, pT_{i} and Q_{ij} cuts on
0445   // the matrix element, as needed for cut-based merging scale definition
0446   double cutbasedms( const Event& event );
0447 
0448   //----------------------------------------------------------------------//
0449   // Functions to steer shower evolution (public to allow for PS plugin)
0450   //----------------------------------------------------------------------//
0451 
0452   // Flag to indicate trial shower usage.
0453   void doIgnoreEmissions( bool doIgnoreIn ) {
0454     doIgnoreEmissionsSave = doIgnoreIn;
0455   }
0456   // Function to allow not counting a trial emission.
0457   virtual bool canVetoEmission() { return !doIgnoreEmissionsSave; }
0458   // Function to check if emission should be rejected.
0459   virtual bool doVetoEmission( const Event& );
0460   virtual bool usesVincia() {return false;}
0461 
0462   //----------------------------------------------------------------------//
0463   // Functions used as clusterings / probabilities
0464   //----------------------------------------------------------------------//
0465 
0466   bool useShowerPluginSave;
0467   virtual bool useShowerPlugin() { return useShowerPluginSave; }
0468 
0469   //----------------------------------------------------------------------//
0470   // Functions to retrieve if merging weight should countin the internal
0471   // cross section and the event weight.
0472   //----------------------------------------------------------------------//
0473 
0474   bool includeWGTinXSEC() { return includeWGTinXSECSave;}
0475 
0476   //----------------------------------------------------------------------//
0477   // Functions to retrieve event veto information
0478   //----------------------------------------------------------------------//
0479 
0480   int nHardNow()      { return nHardNowSave; }
0481   double tmsHardNow() { return tmsHardNowSave; }
0482   int nJetsNow()      { return nJetNowSave; }
0483   double tmsNow()     { return tmsNowSave;}
0484 
0485   void setHardProcessPtr(HardProcess* hardProcIn) { hardProcess = hardProcIn; }
0486 
0487   //----------------------------------------------------------------------//
0488   // Functions related to renormalization scale variations
0489   //----------------------------------------------------------------------//
0490 
0491   int nMuRVar() { return muRVarFactors.size(); }
0492   void printIndividualWeights();
0493 
0494   //----------------------------------------------------------------------//
0495   // The members, switches etc.
0496   //----------------------------------------------------------------------//
0497 
0498   // Helper class doing all the core process book-keeping
0499   bool useOwnHardProcess;
0500   HardProcess* hardProcess;
0501 
0502   PartonLevel* showers;
0503   void setShowerPointer(PartonLevel* psIn ) {showers = psIn;}
0504 
0505   // AlphaS objects for alphaS reweighting use
0506   AlphaStrong AlphaS_FSRSave;
0507   AlphaStrong AlphaS_ISRSave;
0508   AlphaEM AlphaEM_FSRSave;
0509   AlphaEM AlphaEM_ISRSave;
0510 
0511   // Saved path to LHE file for more automated merging
0512   string lheInputFile;
0513 
0514   // Flags for merging procedure definition.
0515   bool   doUserMergingSave, doMGMergingSave, doKTMergingSave,
0516          doPTLundMergingSave, doCutBasedMergingSave,
0517          includeMassiveSave, enforceStrongOrderingSave, orderInRapiditySave,
0518          pickByFullPSave, pickByPoPT2Save, includeRedundantSave,
0519          pickBySumPTSave, allowColourShufflingSave, resetHardQRenSave,
0520          resetHardQFacSave;
0521   int    unorderedScalePrescipSave, unorderedASscalePrescipSave,
0522          unorderedPDFscalePrescipSave, incompleteScalePrescipSave,
0523          ktTypeSave, nReclusterSave, nQuarksMergeSave, nRequestedSave;
0524 
0525   double scaleSeparationFactorSave, nonJoinedNormSave,
0526          fsrInRecNormSave, herwigAcollFSRSave, herwigAcollISRSave,
0527          pT0ISRSave, pTcutSave, pTminISRSave, pTminFSRSave;
0528   bool   doNL3TreeSave, doNL3LoopSave, doNL3SubtSave;
0529   bool   doUNLOPSTreeSave, doUNLOPSLoopSave, doUNLOPSSubtSave,
0530          doUNLOPSSubtNLOSave;
0531   bool   doUMEPSTreeSave, doUMEPSSubtSave;
0532 
0533   // Flag to only do phase space cut, rejecting events below the tms cut.
0534   bool   doEstimateXSection;
0535 
0536   // Flag for runtime aMC@NLO interface. Needed for aMC@NLO-Delta.
0537   bool   doRuntimeAMCATNLOInterfaceSave;
0538 
0539   // Flag for postponing event vetos. If false, events are not vetoed
0540   // based on the merging scale in CKKW-L merging, but have to be
0541   // vetoed by the user in the main program.
0542   bool   applyVeto;
0543 
0544   // Save input event in case decay products need to be detached.
0545   Event inputEvent;
0546   vector< pair<int,int> > resonances;
0547   bool doRemoveDecayProducts;
0548 
0549   // Starting scale for attaching MPI.
0550   double muMISave;
0551 
0552   // Precalculated K-factors.
0553   double kFactor0jSave;
0554   double kFactor1jSave;
0555   double kFactor2jSave;
0556 
0557   // Saved members.
0558   double tmsValueSave, tmsValueNow, DparameterSave;
0559   int nJetMaxSave;
0560   int nJetMaxNLOSave;
0561 
0562   string processSave, processNow;
0563 
0564   // List of cut values to used to define a merging scale. Ordering:
0565   // 0: DeltaR_{jet_i,jet_j,min}
0566   // 1: p_{T,jet_i,min}
0567   // 2: Q_{jet_i,jet_j,min}
0568   vector<double> tmsListSave;
0569 
0570   // INTERNAL Hooks to allow construction of all histories,
0571   // including un-ordered ones
0572   bool doOrderHistoriesSave;
0573 
0574   // INTERNAL Hooks to disallow states in the construction of all histories,
0575   // e.g. because jets are below the merging scale, of to avoid the
0576   // construction of uu~ -> Higgs histories.
0577   bool doCutOnRecStateSave;
0578 
0579   // INTERNAL Hooks to allow clustering W bosons.
0580   bool doWeakClusteringSave, doSQCDClusteringSave;
0581 
0582   // Store / get first scale in PDF's that Pythia should have used
0583   double muFSave;
0584   double muRSave;
0585 
0586   // Store / get factorisation scale used in matrix element calculation.
0587   double muFinMESave;
0588   double muRinMESave;
0589 
0590   // Flag to indicate trial shower usage.
0591   bool doIgnoreEmissionsSave;
0592   // Flag to indicate if events should be vetoed.
0593   bool doIgnoreStepSave;
0594   // Stored weights in case veot needs to be revoked
0595   double pTsave;
0596   vector<double> weightCKKWL1Save, weightCKKWL2Save;
0597   int nMinMPISave;
0598   // Save CKKW-L weight / O(\alpha_s) weight.
0599   vector<double> weightCKKWLSave, weightFIRSTSave;
0600 
0601   // Struct to save individual weights
0602   struct IndividualWeights {
0603     vector<double> wtSave;
0604     vector<double> pdfWeightSave;
0605     vector<double> mpiWeightSave;
0606     vector<double> asWeightSave;
0607     vector<double> aemWeightSave;
0608     vector<double> bornAsVarFac;
0609   };
0610 
0611   IndividualWeights individualWeights;
0612 
0613   // Flag to indicate whether renormalization scale variations are performed
0614   bool doVariations;
0615   // Vector of variation factors applied to renormalization scale
0616   vector<double> muRVarFactors;
0617   // Number of weights, nominal + variations
0618   int nWgts;
0619 
0620   // Local copies of nJetMax inputs, if recalculation is necessary.
0621   int nJetMaxLocal;
0622   int nJetMaxNLOLocal;
0623   bool hasJetMaxLocal;
0624 
0625   // Event veto and hard process information, if veto should not applied be
0626   // directly, but is up to the user.
0627   bool includeWGTinXSECSave;
0628   int nHardNowSave, nJetNowSave;
0629   double tmsHardNowSave, tmsNowSave;
0630 
0631   //----------------------------------------------------------------------//
0632   // Generic setup functions
0633   //----------------------------------------------------------------------//
0634 
0635   // Function storing candidates for the hard process in the current event
0636   // Needed in order not to cluster members of the core process
0637   void storeHardProcessCandidates(const Event& event){
0638     hardProcess->storeCandidates(event,getProcessString());
0639   }
0640 
0641   // Function to set the path to the LHE file, so that more automated merging
0642   // can be used.
0643   // Remove "_1.lhe" suffix from LHE file name.
0644   // This is done so that the HarsProcess class can access both the +0 and +1
0645   // LHE files to find both the merging scale and the core process string
0646   // Store.
0647   void setLHEInputFile( string lheFile) {
0648     lheInputFile = lheFile.substr(0,lheFile.size()-6); }
0649 
0650   //----------------------------------------------------------------------//
0651   // Functions for output of class members.
0652   //----------------------------------------------------------------------//
0653 
0654   // Return AlphaStrong objects
0655   AlphaStrong* AlphaS_FSR() { return &AlphaS_FSRSave;}
0656   AlphaStrong* AlphaS_ISR() { return &AlphaS_ISRSave;}
0657   AlphaEM* AlphaEM_FSR() { return &AlphaEM_FSRSave;}
0658   AlphaEM* AlphaEM_ISR() { return &AlphaEM_ISRSave;}
0659 
0660   // Functions to return advanced merging switches
0661   // Include masses in definition of evolution pT and splitting kernels
0662   bool includeMassive() { return includeMassiveSave;}
0663   // Prefer strongly ordered histories
0664   bool enforceStrongOrdering() { return enforceStrongOrderingSave;}
0665   // Prefer histories ordered in rapidity and evolution pT
0666   bool orderInRapidity() { return orderInRapiditySave;}
0667   // Pick history probabilistically by full (correct) splitting probabilities
0668   bool pickByFull() { return pickByFullPSave;}
0669   // Pick history probabilistically, with easier form of probabilities
0670   bool pickByPoPT2() { return pickByPoPT2Save;}
0671   // Include redundant terms (e.g. PDF ratios) in the splitting probabilities
0672   bool includeRedundant(){ return includeRedundantSave;}
0673   // Pick by winner-takes-it-all, with minimum sum of scalar evolution pT
0674   bool pickBySumPT(){ return pickBySumPTSave;}
0675 
0676   // Prescription for combined scale of unordered emissions
0677   // 0 : use larger scale
0678   // 1 : use smaller scale
0679   int unorderedScalePrescip() { return unorderedScalePrescipSave;}
0680   // Prescription for combined scale used in alpha_s for unordered emissions
0681   // 0 : use combined emission scale in alpha_s weight for both (!) splittings
0682   // 1 : use original reclustered scales of each emission in alpha_s weight
0683   int unorderedASscalePrescip() { return unorderedASscalePrescipSave;}
0684   // Prescription for combined scale used in PDF ratios for unordered
0685   // emissions
0686   // 0 : use combined emission scale in PDFs for both (!) splittings
0687   // 1 : use original reclustered scales of each emission in PDF ratiost
0688   int unorderedPDFscalePrescip() { return unorderedPDFscalePrescipSave;}
0689   // Prescription for starting scale of incomplete histories
0690   // 0: use factorization scale
0691   // 1: use sHat
0692   // 2: use s
0693   int incompleteScalePrescip() { return incompleteScalePrescipSave;}
0694 
0695   // Allow swapping one colour index while reclustering
0696   bool allowColourShuffling() { return allowColourShufflingSave;}
0697 
0698   // Allow use of dynamical renormalisation scale of the core 2-> 2 process.
0699   bool resetHardQRen() { return resetHardQRenSave; }
0700   // Allow use of dynamical factorisation scale of the core 2-> 2 process.
0701   bool resetHardQFac() { return resetHardQFacSave; }
0702 
0703   // Factor by which two scales should differ to be classified strongly
0704   // ordered.
0705   double scaleSeparationFactor() { return scaleSeparationFactorSave;}
0706   // Absolute normalization of splitting probability for non-joined
0707   // evolution.
0708   double nonJoinedNorm() { return nonJoinedNormSave;}
0709   // Absolute normalization of splitting probability for final state
0710   // splittings with initial state recoiler
0711   double fsrInRecNorm() { return fsrInRecNormSave;}
0712   // Factor multiplying scalar evolution pT for FSR splitting, when picking
0713   // history by minimum scalar pT (see Jonathan Tully's thesis)
0714   double herwigAcollFSR() { return herwigAcollFSRSave;}
0715   // Factor multiplying scalar evolution pT for ISR splitting, when picking
0716   // history by minimum scalar pT (see Jonathan Tully's thesis)
0717   double herwigAcollISR() { return herwigAcollISRSave;}
0718   // ISR regularisation scale
0719   double pT0ISR() { return pT0ISRSave;}
0720   // Shower cut-off scale
0721   double pTcut() { return pTcutSave;}
0722 
0723   // MI starting scale.
0724   void muMI( double mu) { muMISave = mu; }
0725   double muMI() { return muMISave;}
0726 
0727   // Full k-Factor for current event
0728   double kFactor(int njet = 0) {
0729     return (njet == 0) ? kFactor0jSave
0730           :(njet == 1) ? kFactor1jSave
0731           : kFactor2jSave;
0732   }
0733   // O(\alhpa_s)-term of the k-Factor for current event
0734   double k1Factor( int njet = 0) {
0735     return (kFactor(njet) - 1)/infoPtr->alphaS();
0736   }
0737 
0738   // Function to return if construction of histories is biased towards ordered
0739   // histories.
0740   bool orderHistories() { return doOrderHistoriesSave;}
0741 
0742   // INTERNAL Hooks to disallow states in the construction of all histories,
0743   // e.g. because jets are below the merging scale, of to avoid the
0744   // construction of uu~ -> Higgs histories.
0745   bool allowCutOnRecState() { return doCutOnRecStateSave;}
0746 
0747   // INTERNAL Hooks to allow clustering W bosons.
0748   bool doWeakClustering() { return doWeakClusteringSave;}
0749   // INTERNAL Hooks to allow clustering clustering of gluons to squarks.
0750   bool doSQCDClustering() { return doSQCDClusteringSave;}
0751 
0752   // Store / get first scale in PDF's that Pythia should have used
0753   double muF() { return (muFSave > 0.) ? muFSave : infoPtr->QFac();}
0754   double muR() { return (muRSave > 0.) ? muRSave : infoPtr->QRen();}
0755   // Store / get factorisation scale used in matrix element calculation.
0756   double muFinME() {
0757     // Start with checking the event attribute called "muf".
0758     string mus = infoPtr->getEventAttribute("muf2",true);
0759     double mu  = (mus.empty()) ? 0. : atof((char*)mus.c_str());
0760     mu = sqrt(mu);
0761     // Check the scales tag of the event.
0762     if (infoPtr->scales) mu = infoPtr->getScalesAttribute("muf");
0763     return (mu > 0.) ? mu : (muFinMESave > 0.) ? muFinMESave
0764       : infoPtr->QFac();
0765   }
0766   double muRinME() {
0767     // Start with checking the event attribute called "mur2".
0768     string mus = infoPtr->getEventAttribute("mur2",true);
0769     double mu  = (mus.empty()) ? 0. : atof((char*)mus.c_str());
0770     mu = sqrt(mu);
0771     // Check the scales tag of the event.
0772     if (infoPtr->scales) mu = infoPtr->getScalesAttribute("mur");
0773     return (mu > 0.) ? mu : (muRinMESave > 0.) ? muRinMESave
0774       : infoPtr->QRen();
0775   }
0776 
0777 
0778   //----------------------------------------------------------------------//
0779   // Functions to steer merging code
0780   //----------------------------------------------------------------------//
0781 
0782   // Flag to indicate if events should be vetoed.
0783   void doIgnoreStep(bool doIgnoreIn) {doIgnoreStepSave = doIgnoreIn;}
0784   // Function to allow event veto.
0785   virtual bool canVetoStep() {return !doIgnoreStepSave;}
0786 
0787   // Stored weights in case veto needs to be revoked
0788   void storeWeights(vector<double> weight) {
0789     weightCKKWL1Save = weightCKKWL2Save = weight;}
0790 
0791   // Function to check event veto.
0792   virtual bool doVetoStep(const Event& process, const Event& event,
0793     bool doResonance = false);
0794 
0795   // Set starting scales
0796   virtual bool setShowerStartingScales( bool isTrial, bool doMergeFirstEmm,
0797     double& pTscaleIn, const Event& event,
0798     double& pTmaxFSRIn, bool& limitPTmaxFSRin,
0799     double& pTmaxISRIn, bool& limitPTmaxISRin,
0800     double& pTmaxMPIIn, bool& limitPTmaxMPIin );
0801 
0802   // Set shower stopping scale. Necessary to e.g. avoid accumulation of
0803   // incorrect (low-pT) shower weights through trial showering.
0804   double stopScaleSave;
0805   void setShowerStoppingScale(double scale = 0.) {stopScaleSave = scale;}
0806   double getShowerStoppingScale() {return stopScaleSave;}
0807 
0808   void nMinMPI(int nMinMPIIn) {nMinMPISave = nMinMPIIn; }
0809   int nMinMPI() {return nMinMPISave;}
0810 
0811   //----------------------------------------------------------------------//
0812   // Functions for internal merging scale definions
0813   //----------------------------------------------------------------------//
0814 
0815   // Function to calculate the kT separation between two particles
0816   double kTdurham(const Particle& RadAfterBranch,
0817     const Particle& EmtAfterBranch, int Type, double D );
0818   // Function to compute "pythia pT separation" from Particle input
0819   double rhoPythia(const Event& event, int rad, int emt, int rec,
0820     int ShowerType);
0821 
0822   // Function to find a colour (anticolour) index in the input event,
0823   // used to find colour-connected recoilers
0824   int findColour(int col, int iExclude1, int iExclude2,
0825     const Event& event, int type, bool isHardIn);
0826   // Function to compute Delta R separation from 4-vector input
0827   double deltaRij(Vec4 jet1, Vec4 jet2);
0828 
0829   //----------------------------------------------------------------------//
0830   // Functions for weight management
0831   //----------------------------------------------------------------------//
0832 
0833   // Function to get the CKKW-L weight for the current event
0834   double getWeightNLO(int i=0) { return (weightCKKWLSave[i]
0835                                          - weightFIRSTSave[i]);}
0836   // Return CKKW-L weight.
0837   vector<double> getWeightCKKWL() { return weightCKKWLSave; }
0838   // Return O(\alpha_s) weight.
0839   vector<double> getWeightFIRST() { return weightFIRSTSave; }
0840   // Set CKKW-L weight.
0841   void setWeightCKKWL( vector<double> weightIn){
0842     weightCKKWLSave = weightIn;
0843     infoPtr->weightContainerPtr
0844       ->weightsMerging.setValueVector(weightIn); }
0845   // Set O(\alpha_s) weight.
0846   void setWeightFIRST( vector<double> weightIn){
0847     weightFIRSTSave = weightIn;
0848     infoPtr->weightContainerPtr->weightsMerging
0849       .setValueFirstVector(weightIn); }
0850   // Function to return Sudakov weight as calculated before, also include MPI
0851   // weight. Only call after regular weight functions, since it is calculated
0852   // there.
0853   vector<double> getSudakovWeight() {
0854     vector<double> ret = individualWeights.wtSave;
0855     for (int i = 0; i < nWgts; ++i) {
0856      ret[i] *= individualWeights.pdfWeightSave[i] *
0857                individualWeights.mpiWeightSave[i];
0858     }
0859    return ret;
0860   }
0861   // Function to return coupling weight.
0862   vector<double> getCouplingWeight() {
0863     vector<double> ret = individualWeights.asWeightSave;
0864     for (int i = 0; i < nWgts; ++i) {
0865       ret[i] *= individualWeights.aemWeightSave[i];
0866     }
0867     return ret;
0868   }
0869 
0870 //--------------------------------------------------------------------------
0871 
0872 
0873 
0874   //----------------------------------------------------------------------//
0875   // Functions and members to store the event veto information
0876   //----------------------------------------------------------------------//
0877 
0878   // Set CKKWL veto information.
0879   void setEventVetoInfo(int nJetNowIn, double tmsNowIn) {
0880     nJetNowSave = nJetNowIn; tmsNowSave = tmsNowIn; }
0881 
0882   // Set the hard process information.
0883   void setHardProcessInfo(int nHardNowIn, double tmsHardNowIn) {
0884     nHardNowSave = nHardNowIn; tmsHardNowSave = tmsHardNowIn; }
0885 
0886   // Statistics.
0887   int nVetoedInMainShower;
0888   void addVetoInMainShower() {++nVetoedInMainShower;}
0889   int getNumberVetoedInMainShower() {return nVetoedInMainShower;}
0890 
0891 };
0892 
0893 //==========================================================================
0894 
0895 } // end namespace Pythia8
0896 
0897 #endif // Pythia8_MergingHooks_H