Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // VinciaFSR.h is a part of the PYTHIA event generator.
0002 // Copyright (C) 2024 Peter Skands, 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 contains header information for the VinciaFSR class for
0007 // QCD final-state antenna showers, and auxiliary classes.
0008 
0009 #ifndef Pythia8_VinciaFSR_H
0010 #define Pythia8_VinciaFSR_H
0011 
0012 #include "Pythia8/TimeShower.h"
0013 #include "Pythia8/VinciaAntennaFunctions.h"
0014 #include "Pythia8/VinciaCommon.h"
0015 #include "Pythia8/VinciaISR.h"
0016 #include "Pythia8/VinciaMergingHooks.h"
0017 #include "Pythia8/VinciaTrialGenerators.h"
0018 #include "Pythia8/VinciaQED.h"
0019 #include "Pythia8/VinciaEW.h"
0020 #include "Pythia8/VinciaWeights.h"
0021 #include "Pythia8/VinciaDiagnostics.h"
0022 
0023 namespace Pythia8 {
0024 
0025 // Forward declarations.
0026 class VinciaISR;
0027 
0028 //==========================================================================
0029 
0030 // Helper struct to store information about junctions that involved
0031 // resonances that have now decayed.
0032 
0033 struct ResJunctionInfo {
0034 
0035   // Number of junction in event record.
0036   int iJunction;
0037   // Which of the three ends of iJunction are we talking about.
0038   int iEndCol;
0039   // What is the colour tag of iEndCol in iJunctions.
0040   int iEndColTag;
0041   // Pythia index of quark that should be on the end. Specifically it
0042   // should be the quark from the decay of the resonance.
0043   int iEndQuark;
0044   // iEndColTag and iEnd Quark will get updated as the quark radiates.
0045   // Cector of colours lines between res and end quark, needed in
0046   // order to track if a gluon in chain splits to find correct
0047   // junction end.
0048   vector<int> colours;
0049 
0050 };
0051 
0052 //==========================================================================
0053 
0054 // The Brancher class, base class containing a generic set of "parent
0055 // partons" as well as virtual methods for generating trial
0056 // branchings.
0057 
0058 class Brancher {
0059 
0060 public:
0061 
0062   // Main base class constructor.
0063   Brancher(int iSysIn, Event& event, bool sectorShowerIn,
0064 vector<int> iIn) : sectorShower(sectorShowerIn) {
0065     reset(iSysIn, event, iIn);
0066   }
0067 
0068   // Wrapper for 2- and 3-parton parents.
0069   Brancher(int iSysIn, Event& event, bool sectorShowerIn,
0070     int iIn0, int iIn1, int iIn2=0) : sectorShower(sectorShowerIn) {
0071     reset(iSysIn, event, iIn0, iIn1, iIn2);
0072   }
0073 
0074   // Base class must have a virtual destructor.
0075   virtual ~Brancher() {}
0076 
0077   // Reset (common functionality implemented in base class).
0078   void reset(int iSysIn, Event& event, vector<int> iIn);
0079 
0080   // Wrapper for simple 2- (or 3-) parton antennae.
0081   void reset(int iSysIn, Event& event, int i0In, int i1In, int i2In = 0) {
0082     vector<int> iIn {i0In, i1In}; if (i2In >= 1) iIn.push_back(i2In);
0083     reset(iSysIn,event,iIn);}
0084 
0085   // Methods to get (explicit for up to 3 parents, otherwise just use iVec).
0086   int i0() const {return (iSav.size() >= 1) ? iSav[0] : -1;}
0087   int i1() const {return (iSav.size() >= 2) ? iSav[1] : -1;}
0088   int i2() const {return (iSav.size() >= 3) ? iSav[2] : -1;}
0089   int iVec(unsigned int i) const {return (iSav.size() > i) ? iSav[i] : -1;}
0090   vector<int> iVec() {return iSav;}
0091   int id0() const {return (idSav.size() >= 1) ? idSav[0] : -1;}
0092   int id1() const {return (idSav.size() >= 2) ? idSav[1] : -1;}
0093   int id2() const {return (idSav.size() >= 3) ? idSav[2] : -1;}
0094   vector<int> idVec() const {return idSav;}
0095   int colType0() const {return (colTypeSav.size() >= 1) ? colTypeSav[0] : -1;}
0096   int colType1() const {return (colTypeSav.size() >= 2) ? colTypeSav[1] : -1;}
0097   int colType2() const {return (colTypeSav.size() >= 3) ? colTypeSav[2] : -1;}
0098   vector<int> colTypeVec() const {return colTypeSav;}
0099   int col0() const {return (colSav.size() >= 1) ? colSav[0] : 0;}
0100   int col1() const {return (colSav.size() >= 2) ? colSav[1] : 0;}
0101   int col2() const {return (colSav.size() >= 3) ? colSav[2] : 0;}
0102   vector<int> colVec() const {return colSav;}
0103   int acol0() const {return (acolSav.size() >= 1) ? acolSav[0] : 0;}
0104   int acol1() const {return (acolSav.size() >= 2) ? acolSav[1] : 0;}
0105   int acol2() const {return (acolSav.size() >= 3) ? acolSav[2] : 0;}
0106   vector<int> acolVec() const {return acolSav;}
0107   int h0() const {return (hSav.size() >= 1) ? hSav[0] : -1;}
0108   int h1() const {return (hSav.size() >= 2) ? hSav[1] : -1;}
0109   int h2() const {return (hSav.size() >= 3) ? hSav[2] : -1;}
0110   vector<int> hVec() const {return hSav;}
0111   double m0() const {return (mSav.size() >= 1) ? mSav[0] : -1;}
0112   double m1() const {return (mSav.size() >= 2) ? mSav[1] : -1;}
0113   double m2() const {return (mSav.size() >= 3) ? mSav[2] : -1;}
0114   vector<double> mVec() const {return mSav;}
0115   vector<double> getmPostVec() {return mPostSav;}
0116   int colTag() {return colTagSav;}
0117 
0118   // Method to get maximum value of evolution scale for this brancher.
0119   // Must be redefined in base classes.
0120   virtual double getQ2Max(int) = 0;
0121 
0122   // Methods to return saved/derived quantities.
0123   int    system()     const {return systemSav;}
0124   double mAnt()       const {return mAntSav;}
0125   double m2Ant()      const {return m2AntSav;}
0126   double sAnt()       const {return sAntSav;}
0127   double kallenFac()  const {return kallenFacSav;}
0128   double enhanceFac() const {return enhanceSav;}
0129   double q2Trial()    const {return q2NewSav;}
0130   enum AntFunType antFunTypePhys()   const {return antFunTypeSav;}
0131 
0132   // Generate a new Q2 scale.
0133   virtual double genQ2(int evTypeIn, double q2MaxNow, Rndm* rndmPtr,
0134     Logger* loggerPtr, const EvolutionWindow* evWindowPtrIn, double colFac,
0135     vector<double> headroomIn, vector<double> enhanceFacIn,
0136     int verboseIn) = 0;
0137 
0138   // Generate complementary invariant(s) for saved trial. Return false
0139   // if no physical kinematics possible. Base class returns false.
0140   virtual bool genInvariants(vector<double>& invariants, Rndm*, int,
0141     Logger*) {
0142     invariants.clear(); return false;}
0143 
0144   // Compute antPhys/antTrial, given an input value for antPhys. Base
0145   // class returns 0.
0146   virtual double pAccept(const double, Logger* /*loggerPtr*/, int = 0) {
0147     return 0.;}
0148 
0149   // Compute pT scale of trial branching.
0150   virtual double getpTscale();
0151 
0152   // Return Xj.
0153   virtual double getXj();
0154 
0155   // What kind of particle(s) are being created, e.g. return 21 for
0156   // gluon emission, quark flavour for splitting, etc.
0157   virtual int idNew() const {return 0;}
0158   virtual double mNew() const {return 0.0;}
0159 
0160   // Return new particles, must be implemented by derived class.
0161   virtual bool getNewParticles(Event& event, vector<Vec4> momIn,
0162     vector<int> hIn, vector<Particle> &pNew,Rndm* rndmPtr,
0163     VinciaColour* colourPtr) = 0;
0164 
0165   // Simple print utility, showing the contents of the Brancher. Base
0166   // class implementation allows for up to three explicit parents.
0167   virtual void list(string header="none", bool withLegend=true) const;
0168 
0169   // Set post-branching IDs and masses. Base class is for gluon emission.
0170   virtual void setidPost();
0171   virtual vector<double> setmPostVec();
0172   virtual void setStatPost();
0173   virtual void setMaps(int);
0174 
0175   // Return index of new particle (slightly arbitrary choice for splittings).
0176   virtual int iNew();
0177 
0178   // Method returns pos of resonance if there is one participating in
0179   // decay, -1 otherwise.
0180   virtual int posR() const {return -1;}
0181 
0182   // Method returns pos of colour-connected daughter to resonance if
0183   // there is one participating in decay, -1 otherwise.
0184   virtual int posF() const {return -1;}
0185 
0186   // Return sector label.
0187   virtual int getSector(){
0188     return iSectorWinner;
0189   };
0190 
0191   // Return branch type.
0192   enum BranchType getBranchType() {return branchType;}
0193   // Check if swapped.
0194   bool isSwapped() {return swapped;}
0195   // Return the saved invariants.
0196   vector<double> getInvariants() {return invariantsSav;}
0197 
0198   // This method allows to reset enhanceFac if we do an accept/reject.
0199   void resetEnhanceFac(const double enhanceIn) {enhanceSav = enhanceIn;}
0200 
0201   // Method to see if a saved trial has been generated, and to erase
0202   // memory of it.
0203   bool hasTrial() const {return hasTrialSav;}
0204   // Method to mark new trial needed *without* erasing current one.
0205   void needsNewTrial() {
0206     hasTrialSav = false;
0207     if (trialGenPtr != nullptr) {
0208       trialGenPtr->needsNewTrial();
0209     }
0210   }
0211   // Method to mark new trial needed *and* erase current one.
0212   void eraseTrial() {
0213     hasTrialSav = false;
0214     q2NewSav = 0.;
0215     if (trialGenPtr != nullptr) {
0216       trialGenPtr->resetTrial();
0217     }
0218   }
0219   // Object to perform trial generation.
0220   shared_ptr<TrialGenerator> trialGenPtr = {};
0221 
0222   // Publicly accessible members for storing mother/daughter connections.
0223   map<int, pair<int, int> > mothers2daughters;
0224   map<int, pair<int, int> > daughters2mothers;
0225 
0226 protected:
0227 
0228   // Data members for storing information about parent partons.
0229   int systemSav{};
0230   vector<int> iSav, idSav, colTypeSav, hSav, colSav, acolSav;
0231   vector<int> idPostSav, statPostSav;
0232   vector<double> mSav, mPostSav;
0233   int colTagSav{}, evTypeSav{};
0234 
0235   // All alphaS information.
0236   const EvolutionWindow* evWindowSav{};
0237 
0238   // Saved antenna mass parameters.
0239   double mAntSav{}, m2AntSav{}, kallenFacSav{}, sAntSav{};
0240 
0241   // Data members for storing information about generated trial branching.
0242   bool   hasTrialSav{false};
0243   double headroomSav{1.}, enhanceSav{1.}, q2BegSav{}, q2NewSav{};
0244   vector<double> invariantsSav;
0245 
0246   // Store which branching type we are doing.
0247   enum BranchType branchType{BranchType::Void};
0248 
0249   // Index of FF antenna function.
0250   enum AntFunType antFunTypeSav{NoFun};
0251 
0252   // If true, flip identities of A and B.
0253   bool swapped{false};
0254 
0255   // Parameters for the sector shower.
0256   bool sectorShower{};
0257   int iSectorWinner{};
0258 
0259 };
0260 
0261 //==========================================================================
0262 
0263 // Class BrancherEmitFF, branch elemental for 2->3 gluon emissions.
0264 
0265 class BrancherEmitFF : public Brancher {
0266 
0267 public:
0268 
0269   // Create branch elemental for antenna(e) with parents in iIn.
0270   BrancherEmitFF(int iSysIn, Event& event, bool sectorShowerIn,
0271     vector<int> iIn, ZetaGeneratorSet* zetaGenSet) :
0272     Brancher(iSysIn, event, sectorShowerIn, iIn) {
0273     // Initialise derived-class members and set up trial generator.
0274     initBrancher(zetaGenSet);
0275   }
0276 
0277   // Wrapper to provide simple 2-parton systems as parents.
0278   BrancherEmitFF(int iSysIn, Event& event, bool sectorShowerIn,
0279     int iIn0, int iIn1, ZetaGeneratorSet* zetaGenSet) :
0280     Brancher(iSysIn, event, sectorShowerIn, iIn0, iIn1) {
0281     // Initialise derived-class members and set up trial generator.
0282     initBrancher(zetaGenSet);
0283   }
0284 
0285   // Method to initialise members specific to BrancherEmitFF.
0286   void initBrancher(ZetaGeneratorSet* zetaGenSet);
0287 
0288   // Generate a new Q2 value, soft-eikonal 2/yij/yjk implementation.
0289   double genQ2(int evTypeIn, double q2MaxNow, Rndm* rndmPtr,
0290     Logger* loggerPtr, const EvolutionWindow* evWindowPtrIn, double colFac,
0291     vector<double> headroomIn, vector<double> enhanceFacIn,int verboseIn);
0292 
0293   // Generate invariants. Method to generate complementary
0294   // invariant(s) for saved trial scale for gluon emission. Return
0295   // false if no physical kinematics possible.
0296   virtual bool genInvariants(vector<double>& invariants, Rndm* rndmPtr,
0297     int verboseIn, Logger* loggerPtr);
0298 
0299   // Compute antPhys/antTrial for gluon emissions, given
0300   // antPhys. Note, antPhys should be normalised to include charge and
0301   // coupling factors.
0302   virtual double pAccept(const double antPhys, Logger* loggerPtr,
0303     int verboseIn);
0304 
0305   // Return the maximum Q2.
0306   double getQ2Max(int evType);
0307 
0308   // Method to make mothers2daughters and daughters2mothers pairs.
0309   virtual void setMaps(int sizeOld);
0310 
0311   // Flavour and mass of emitted particle
0312   virtual int idNew() const {return 21;}
0313   virtual double mNew() const {return 0.0;}
0314 
0315   // Generic getter method. Assumes setter methods called earlier.
0316   virtual bool getNewParticles(Event& event, vector<Vec4> momIn,
0317     vector<int> hIn, vector<Particle> &pNew, Rndm* rndmPtr,
0318     VinciaColour* colourPtr);
0319 
0320 private:
0321 
0322   // Data members to store information about generated trials.
0323   double colFacSav{};
0324 
0325 };
0326 
0327 //==========================================================================
0328 
0329 // Class BrancherSplitFF, branch elemental for 2->3 gluon splittings.
0330 
0331 class BrancherSplitFF : public Brancher {
0332 
0333 public:
0334 
0335   // Create branch elemental for antenna(e) with parents in iIn.
0336   BrancherSplitFF(int iSysIn, Event& event, bool sectorShowerIn,
0337     vector<int> iIn, ZetaGeneratorSet* zetaGenSet) :
0338     Brancher(iSysIn, event, sectorShowerIn, iIn) {
0339     // Initialise derived-class members and set up trial generator.
0340     initBrancher(zetaGenSet);
0341   }
0342 
0343   // Wrapper to provide simple 2-parton systems as parents. Set if it
0344   // is the anticolour or colour side of the gluon that participates
0345   // in the antenna (used to decide pTj or pTi measure).
0346   BrancherSplitFF(int iSysIn, Event& event, bool sectorShowerIn, int iIn0,
0347     int iIn1, bool col2acol, ZetaGeneratorSet* zetaGenSet) :
0348     Brancher(iSysIn, event, sectorShowerIn, iIn0, iIn1) {
0349     // Initialise derived-class members and set up trial generator.
0350     initBrancher(zetaGenSet, col2acol);
0351   }
0352 
0353   // Method to initialise data members specific to BrancherSplitFF.
0354   void initBrancher(ZetaGeneratorSet* zetaGenSet, bool col2acolIn=true);
0355 
0356   // Method to check if it is the colour (false) or anticolour (true)
0357   // side of the gluon that is splitting, corresponding to the quark
0358   // or antiquark being regarded as the emitted parton respectively.
0359   virtual bool isXG() const {return isXGsav;}
0360 
0361   // Flavour and mass of emitted particle.
0362   virtual int idNew() const {return idFlavSav;}
0363   virtual double mNew() const {return mFlavSav;}
0364 
0365   // Generate a new Q2 scale (collinear 1/(2q2) implementation) with
0366   // constant trial alphaS.
0367   double genQ2(int evTypeIn, double q2MaxNow, Rndm* rndmPtr,
0368     Logger* loggerPtr, const EvolutionWindow* evWindowPtrIn, double colFac,
0369     vector<double> headroomIn, vector<double> enhanceFacIn,int verboseIn);
0370 
0371   // Generate complementary invariant(s) for saved trial scale for
0372   // gluon splitting. Return false if no physical kinematics possible.
0373   virtual bool genInvariants(vector<double>& invariants, Rndm* rnmdPtr,
0374     int verboseIn, Logger* loggerPtr);
0375 
0376   // Compute antPhys/antTrial for gluon splittings, given antPhys.
0377   // Note, antPhys should be normalised to include charge and coupling
0378   // factors.
0379   virtual double pAccept(const double antPhys, Logger* loggerPtr,
0380     int verboseIn);
0381 
0382   // Getter and setter methods.
0383   double getQ2Max(int evType);
0384   virtual vector<double> setmPostVec();
0385   virtual void setidPost();
0386   virtual void setStatPost();
0387   virtual void setMaps(int sizeOld);
0388 
0389   // Generic getter method. Assumes setter methods called earlier.
0390   virtual bool getNewParticles(Event& event, vector<Vec4> momIn,
0391     vector<int> hIn, vector<Particle> &pNew, Rndm*, VinciaColour*);
0392 
0393  private:
0394 
0395   // Data members for storing information on generated trials.
0396   int     idFlavSav{};
0397   double  mFlavSav{};
0398 
0399   // Data member to store whether this is a GXbar (false) or XG (true) antenna,
0400   // i.e. if it is the colour side (false) of the gluon or the anticolour
0401   // side which is participating in the LC antenna. In the former case, we
0402   // use pT(q) as the measure, else pT(qbar) = pTj.
0403   bool isXGsav{};
0404 
0405 };
0406 
0407 //==========================================================================
0408 
0409 // BrancherRF base class for resonance-final antennae.
0410 
0411 class BrancherRF : public Brancher {
0412 
0413 public:
0414 
0415   // Base class constructor = inherited from Brancher.
0416   BrancherRF(int iSysIn, Event& event, bool sectorShowerIn,
0417     vector<int> allIn) : Brancher(iSysIn, event, sectorShowerIn, allIn) {}
0418 
0419   // RF branchers have a different initBrancher structure.
0420   virtual void initRF(Event& event, vector<int> allIn,
0421     unsigned int posResIn, unsigned int posFIn, double q2cut,
0422     ZetaGeneratorSet* zetaGenSet) = 0;
0423 
0424   // Reset the brancher.
0425   void resetRF(int iSysIn, Event& event, vector<int> allIn,
0426     unsigned int posResIn, unsigned int posFIn, double q2cut,
0427     ZetaGeneratorSet* zetaGenSet) {
0428     reset(iSysIn, event, allIn);
0429     initRF(event, allIn, posResIn, posFIn, q2cut, zetaGenSet);
0430   }
0431 
0432   // Setter methods that are common for all derived RF classes.
0433   int iNew();
0434   void setMaps(int sizeOld);
0435 
0436   // Return position of resonance and colour-connected final-state parton.
0437   int posR() const {return int(posRes);}
0438   int posF() const {return int(posFinal);}
0439 
0440   // Return maximum Q2.
0441   double getQ2Max(int evType) {return evType == 1 ? q2MaxSav : 0.;}
0442 
0443 protected:
0444 
0445   // Protected helper methods for internal class use.
0446   double getsAK(double mA, double mK, double mAK);
0447   double calcQ2Max(double mA, double mAK, double mK);
0448 
0449   // Veto point if outside available phase space.
0450   bool vetoPhSpPoint(const vector<double>& invariants, int verboseIn);
0451 
0452   // Save reference to position in vectors of resonance and colour
0453   // connected parton.
0454   unsigned int posRes{}, posFinal{};
0455   // Mass of resonance.
0456   double mRes{};
0457   // Mass of final state parton in antennae.
0458   double mFinal{};
0459   // Collective mass of rest of downstream decay products of resonance
0460   // these will just take recoil.
0461   double mRecoilers{};
0462   double sAK{};
0463 
0464   // Max Q2 for this brancher, still an overestimate.
0465   double q2MaxSav{};
0466   double colFacSav{};
0467   // Store whether the colour flow is from R to F (e.g. t -> bW+) or F
0468   // to R (e.g. tbar -> bbarW-).
0469   bool colFlowRtoF{};
0470   map<unsigned int,unsigned int> posNewtoOld{};
0471 
0472 };
0473 
0474 
0475 //==========================================================================
0476 
0477 // BrancherEmitRF class for storing information on antennae between a
0478 // coloured resonance and final state parton, and generating a new
0479 // emission.
0480 
0481 class BrancherEmitRF : public BrancherRF {
0482 
0483 public:
0484 
0485   // Constructor.
0486   BrancherEmitRF(int iSysIn, Event& event, bool sectorShowerIn,
0487     vector<int> allIn, unsigned int posResIn, unsigned int posFIn,
0488     double q2cut, ZetaGeneratorSet* zetaGenSet) :
0489     BrancherRF(iSysIn, event, sectorShowerIn, allIn) {
0490     // Initialise derived-class members and set up trial generator.
0491     initBrancher(event, allIn, posResIn, posFIn, q2cut, zetaGenSet);
0492   }
0493 
0494   // Method to initialise data members specific to BrancherEmitRF.
0495   void initBrancher(Event& event, vector<int> allIn, unsigned int posResIn,
0496     unsigned int posFIn, double q2cut, ZetaGeneratorSet* zetaGenSet);
0497   void initRF(Event& event, vector<int> allIn, unsigned int posResIn,
0498     unsigned int posFIn, double q2cut, ZetaGeneratorSet* zetaGenSet) override {
0499     initBrancher(event, allIn, posResIn, posFIn, q2cut, zetaGenSet);}
0500 
0501   // Setter methods.
0502   vector<double> setmPostVec() override;
0503   void setidPost() override;
0504   void setStatPost() override;
0505 
0506   // Generic method, assumes setter methods called earlier.
0507   bool getNewParticles(Event& event, vector<Vec4> momIn, vector<int> hIn,
0508     vector<Particle> &pNew, Rndm* rndmPtr, VinciaColour*) override;
0509 
0510   // Generate a new Q2 scale.
0511   double genQ2(int evTypeIn, double q2MaxNow, Rndm* rndmPtr,
0512     Logger* loggerPtr, const EvolutionWindow* evWindowPtrIn, double colFac,
0513     vector<double> headroomIn, vector<double> enhanceFacIn,
0514     int verboseIn) override;
0515 
0516   // Generate complementary invariant(s) for saved trial scale. Return
0517   // false if no physical kinematics possible.
0518   bool genInvariants(vector<double>& invariants,Rndm* rndmPtr,
0519     int verboseIn, Logger* loggerPtr) override;
0520 
0521   // Compute antPhys/antTrial, given antPhys. Note, antPhys should be
0522   // normalised to include charge and coupling factors.
0523   double pAccept(const double, Logger* loggerPtr, int verboseIn) override;
0524 
0525 };
0526 
0527 //==========================================================================
0528 
0529 // BrancherSplitRF class for storing information on antennae between a
0530 // coloured resonance and final state parton, and generating a new
0531 // emission.
0532 
0533 class BrancherSplitRF : public BrancherRF {
0534 
0535 public:
0536 
0537   // Constructor.
0538   BrancherSplitRF(int iSysIn, Event& event, bool sectorShowerIn,
0539     vector<int> allIn, unsigned int posResIn, unsigned int posFIn,
0540     double q2cut, ZetaGeneratorSet* zetaGenSet) :
0541     BrancherRF(iSysIn, event, sectorShowerIn, allIn) {
0542     // Initialise derived-class members and set up trial generator.
0543     initBrancher(event, allIn, posResIn, posFIn, q2cut, zetaGenSet);
0544   }
0545 
0546   // Method to initialise data members specific to BrancherSplitRF.
0547   void initBrancher(Event& event, vector<int> allIn, unsigned int posResIn,
0548     unsigned int posFIn, double q2cut, ZetaGeneratorSet* zetaGenSet);
0549   void initRF(Event& event, vector<int> allIn, unsigned int posResIn,
0550     unsigned int posFIn, double q2cut, ZetaGeneratorSet* zetaGenSet) override {
0551     initBrancher(event, allIn, posResIn, posFIn, q2cut, zetaGenSet);}
0552 
0553   // Setter methods.
0554   vector<double> setmPostVec() override;
0555   void setidPost() override;
0556   void setStatPost() override;
0557 
0558   // Generic method, assumes setter methods called earlier.
0559   bool getNewParticles(Event& event, vector<Vec4> momIn,
0560     vector<int> hIn, vector<Particle>& pNew, Rndm*, VinciaColour*) override;
0561 
0562   // Generate a new Q2 scale.
0563   double genQ2(int evTypeIn, double q2MaxNow, Rndm* rndmPtr,
0564     Logger* loggerPtr, const EvolutionWindow* evWindowPtrIn, double colFac,
0565     vector<double> headroomIn, vector<double> enhanceFacIn,
0566     int verboseIn) override;
0567 
0568 protected:
0569 
0570   // Members.
0571   int     idFlavSav{};
0572   double  mFlavSav{};
0573 
0574 };
0575 
0576 //==========================================================================
0577 
0578 // The VinciaFSR class for resonant decays. Inherits from TimeShower
0579 // in Pythia 8 so can be used as alternative to TimeShower.
0580 // Methods that must replace ones in TimeShower are marked with override.
0581 
0582 class VinciaFSR : public TimeShower {
0583 
0584   // Allow VinciaISR and VinciaHistory to access private information.
0585   friend class VinciaISR;
0586   friend class VinciaHistory;
0587 
0588 public:
0589 
0590   // Constructor.
0591   VinciaFSR() :
0592     zetaGenSetRF(ZetaGeneratorSet(TrialGenType::RF)),
0593       zetaGenSetFF(ZetaGeneratorSet(TrialGenType::FF)) {
0594     verbose = 0; headerIsPrinted = false; isInit = false;
0595     isPrepared = false; diagnosticsPtr = 0;}
0596 
0597   // Destructor.
0598   ~VinciaFSR() {;}
0599 
0600   // The following methods control main flow of shower and are
0601   // inherited from TimeShower. Any method re-implementing a
0602   // TimeShower method is appended with (TimeShower).
0603 
0604   // Initialize alphaStrong and related pTmin parameters (TimeShower).
0605   void init(BeamParticle* beamAPtrIn = 0, BeamParticle* beamBPtrIn = 0)
0606     override;
0607 
0608   // Force reset at beginning of each event.
0609   void onBeginEvent() override { isPrepared = false; }
0610 
0611   // Determines if max pT limit should be imposed on first emission.
0612   // Note: in Vincia, the second argument is purely dummy.
0613   bool limitPTmax(Event& event, double q2Fac, double q2Ren) override;
0614 
0615   // Top-level routine to do a full time-like shower in resonance
0616   // decay (TimeShower).
0617   int shower( int iBeg, int iEnd, Event& event, double pTmax,
0618     int nBranchMax = 0) override;
0619 
0620   // Method to add QED showers in hadron decays (TimeShower).
0621   int showerQED(int iBeg, int iEnd, Event& event, double pTmax) override;
0622 
0623   // Method to add QED showers to partons below colour resolution
0624   // scale (TimeShower).
0625   int showerQEDafterRemnants(Event& event) override;
0626 
0627   // Prepare process-level event for shower + interleaved resonance decays.
0628   // Usage: prepareProcess( process, event, iPos).
0629   // iPos provides mapping from process to event entries (before showering).
0630   void prepareProcess( Event& process, Event& event,
0631     vector<int>& iPosBefShow) override;
0632 
0633   // Used for global recoil scheme (TimeShower, no Vincia implementation yet).
0634   // void prepareGlobal(Event&);
0635 
0636   // Prepare system for evolution (TimeShower).
0637   void prepare( int iSys, Event& event, bool limitPTmaxIn) override;
0638 
0639   // Update antenna list after a multiple interactions rescattering
0640   // (TimeShower, no Vincia implementation yet).
0641   // void rescatterUpdate( int iSys, Event& event);
0642 
0643   // Update antenna list after each ISR emission (TimeShower).
0644   void update( int iSys, Event& event, bool hasWeakRad = false) override;
0645 
0646   // Select next pT in downwards evolution (TimeShower).
0647   double pTnext( Event& event, double pTbegAll, double pTendAll,
0648     bool isFirstTrial = false, bool doTrialIn = false) override;
0649 
0650   // Select next pT for interleaved resonance decays.
0651   double pTnextResDec() override {
0652     double pTresDecMax =  0.;
0653     iHardResDecSav = -1 ;
0654     for (size_t i=0; i<pTresDecSav.size(); ++i) {
0655       if (pTresDecSav[i] > pTresDecMax) {
0656         pTresDecMax    = pTresDecSav[i];
0657         iHardResDecSav = i;
0658       }
0659     }
0660     return pTresDecMax;
0661   }
0662 
0663   // Branch event, including accept/reject veto (TimeShower).
0664   bool branch( Event& event, bool isInterleaved = false) override;
0665 
0666   // Do a resonance decay + resonance shower (including any nested decays).
0667   // May be called recursively for nested decays.
0668   // Usage: resonanceShower( process, event, iPos, pTmerge), where iPos
0669   // maps process to event entries, and pTmerge is the scale at which this
0670   // system should be merged into its parent system.
0671   bool resonanceShower(Event& process, Event& event, vector<int>& iPos,
0672     double qRestart) override;
0673 
0674   // Utility to print antenna list; for debug mainly (TimeShower).
0675   void list() const override;
0676 
0677   // Initialize data members for calculation of uncertainty bands
0678   // (TimeShower, no Vincia implementation yet).
0679   // virtual bool initUncertainties();
0680 
0681   // Tell whether FSR has done a weak emission.
0682   bool getHasWeaklyRadiated() override {return hasWeaklyRadiated;}
0683 
0684   // Tell which system was the last processed one (TimeShower).
0685   int system() const override {return iSysWin;}
0686 
0687   // Potential enhancement factor of pTmax scale for hardest emission.
0688   // Used if limitPTmax = true (TimeShower).
0689   double enhancePTmax() override {return pTmaxFudge;}
0690 
0691   // Provide the pT scale of the last branching in the above shower
0692   // (TimeShower).
0693   double pTLastInShower() override {return pTLastAcceptedSav;}
0694 
0695   // The following methods for merging not yet implemented in Vincia:
0696   //   Event clustered()
0697   //   map<string, double> getStateVariables (const Event &, int, int, int,
0698   //     string)
0699   //   bool isTimelike()
0700   //   vector<string> getSplittingName()
0701   //   double getSplittingProb()
0702   //   bool allowedSplitting()
0703   //   vector<int> getRecoilers()
0704 
0705   // The remaining public functions Vincia only, i.e. not inherited
0706   // from Pythia 8.
0707 
0708   // Initialise pointers to Vincia objects.
0709   void initVinciaPtrs(VinciaColour* colourPtrIn,
0710     shared_ptr<VinciaISR> isrPtrIn, MECs* mecsPtrIn,
0711     Resolution* resolutionPtrIn, VinciaCommon* vinComPtrIn,
0712     VinciaWeights* vinWeightsPtrIn);
0713 
0714   // Set pointer to object to use for diagnostics and profiling.
0715   void setDiagnosticsPtr(shared_ptr<VinciaDiagnostics> diagnosticsPtrIn) {
0716     diagnosticsPtr = diagnosticsPtrIn;
0717   }
0718 
0719   // Set EW shower module.
0720   void setEWShowerPtr(VinciaModulePtr ewShowerPtrIn) {
0721     ewShowerPtr = ewShowerPtrIn;
0722   }
0723 
0724   // Set QED shower module for hard scattering (and resonance decays).
0725   void setQEDShowerHardPtr(VinciaModulePtr qedShowerPtrIn) {
0726     qedShowerHardPtr = qedShowerPtrIn;
0727   }
0728 
0729   // Set QED shower module for MPI and hadronization.
0730   void setQEDShowerSoftPtr(VinciaModulePtr qedShowerPtrIn) {
0731     qedShowerSoftPtr = qedShowerPtrIn;
0732   }
0733 
0734   // Initialize pointers to antenna sets.
0735   void initAntPtr(AntennaSetFSR* antSetIn) {antSetPtr = antSetIn;}
0736 
0737   // Wrapper function to return a specific antenna inside an antenna set.
0738   AntennaFunction* getAntFunPtr(enum AntFunType antFunType) {
0739     return antSetPtr->getAntFunPtr(antFunType);}
0740   // Wrapper to return all AntFunTypes that are contained in antSetPtr.
0741   vector<enum AntFunType> getAntFunTypes() {
0742     return antSetPtr->getAntFunTypes();}
0743 
0744   // Print header information (version, settings, parameters, etc.).
0745   void header();
0746 
0747   // Communicate information about trial showers for merging.
0748   void setIsTrialShower(bool isTrialShowerIn){
0749     isTrialShower=isTrialShowerIn;
0750   }
0751   void setIsTrialShowerRes(bool isTrialShowerResIn){
0752     isTrialShowerRes=isTrialShowerResIn;
0753   }
0754 
0755   // Save the flavour content of system in Born state
0756   // (needed for sector shower).
0757   void saveBornState(int iSys, Event& born);
0758   // Save the flavour content of Born for trial shower.
0759   void saveBornForTrialShower(Event& born);
0760 
0761   // Check self-consistency, for specific iSys >= 0 or all systems (iSys < 0).
0762   bool check(int iSys, Event &event);
0763 
0764   // Set verbosity level.
0765   void setVerbose(int verboseIn) {verbose = verboseIn;}
0766 
0767 private:
0768 
0769   // Constants
0770   static const int NLOOPMAX;
0771 
0772   // Initialize evolution windows.
0773   void initEvolutionWindows(void);
0774   // Return window Q2.
0775   double getQ2Window(int iWindow, double q2cutoff);
0776   // Return Lambda value.
0777   double getLambda(int nFin, AlphaStrong* aSptr);
0778   // Method to return renormalisation-scale prefactor.
0779   double getkMu2(bool isEmit);
0780   // Method to return renormalisation scale. Default scale is kMu *
0781   // evolution scale.
0782   double getMu2(bool isEmit);
0783   // Reset (or clear) sizes of all containers.
0784   void clearContainers();
0785   // Method to set up QCD antennae, called in prepare.
0786   bool setupQCDantennae(int iSys, Event& event);
0787   // Set starting scale of shower (power vs wimpy) for system iSys.
0788   void setStartScale(int iSys, Event& event);
0789 
0790   // Auxiliary method to compute scale for interleaved resonance decays
0791   virtual double calcPTresDec(Particle& res) {
0792     if (resDecScaleChoice == 0) return res.mWidth();
0793     double virt = pow2(res.m()) - pow2(res.m0());
0794     if (resDecScaleChoice == 1) return abs(virt) / res.m0();
0795     else if (resDecScaleChoice == 2) return sqrt(abs(virt));
0796     return 0.;
0797   }
0798 
0799   // Template method for generating the next Q2 for a generic Brancher.
0800   template <class T> bool q2NextQCD( vector<shared_ptr<T> > &brancherVec,
0801     const map<double, EvolutionWindow>& evWindows, const int evType,
0802     const double q2Begin, const double q2End, bool isEmit);
0803 
0804   // Methods to generate trial scales for each QCD shower component.
0805   // Based on the generic template method above.
0806   bool q2NextEmitQCD(const double q2Begin, double q2End);
0807   bool q2NextSplitQCD(const double q2Begin, double q2End);
0808   bool q2NextEmitResQCD(const double q2Begin, const double q2End);
0809   bool q2NextSplitResQCD(const double q2Begin, const double q2End);
0810   bool q2NextEmitQED(double q2Begin, const double q2End);
0811   bool q2NextSplitQED(double q2Begin, const double q2End);
0812 
0813   // Perform a QCD branching.
0814   bool branchQCD(Event& event);
0815   // Perform an EW/QED branching.
0816   bool branchEW(Event& event);
0817 
0818   // Perform an early antenna rejection.
0819   bool rejectEarly(AntennaFunction* &antFunPtr,bool doMEC);
0820   // Compute physical antenna function.
0821   double getAntFunPhys(AntennaFunction* &antFunPtr);
0822   // Calculate acceptance probability.
0823   double pAcceptCalc(double antPhys);
0824   // Generate the full kinematics.
0825   bool genFullKinematics(int kineMap, Event event, vector<Vec4> &pPost);
0826   // Check if a trial is accepted.
0827   bool acceptTrial(Event& event);
0828   // Generate new particles for the antenna.
0829   bool getNewParticles(Event& event, AntennaFunction* antFunPtr,
0830     vector<Particle> &newParts);
0831 
0832   // Generate new helicities for the antenna. Default is to set same
0833   // as before, with a new unpolarised emission inserted. If helicity
0834   // shower is off, this will correspond to all unpolarised. Do it
0835   // this way because in case of resonance decays rest of vector
0836   // includes whole resonance system, whose polarisations we don't
0837   // want to change, i.e. they only recoil kinematically.
0838   vector<int> genHelicities(AntennaFunction* antFunPtr);
0839 
0840   // ME corrections.
0841   double getMEC(int iSys, const Event& event,
0842     const vector<Particle>& statePost, VinciaClustering& thisClus);
0843 
0844   // Update the event.
0845   bool updateEvent(Event& event,ResJunctionInfo & junctionInfoIn);
0846   // Update the parton systems.
0847   void updatePartonSystems();
0848   // Create a new emission brancher.
0849   void saveEmitterFF(int iSysIn, Event& event, int i0, int i1);
0850   // Create a new resonance emission brancher.
0851   void saveEmitterRF(int iSys, Event& event, vector<int> allIn,
0852     unsigned int posResIn, unsigned int posFIn, bool colMode);
0853   // Create a new resonance splitter.
0854   void saveSplitterRF(int iSysIn, Event& event, vector<int> allIn,
0855     unsigned int posResIn, unsigned int posFIn,bool colMode);
0856   // Create a new splitter brancher.
0857   void saveSplitterFF(int iSysIn, Event& event, int i0, int i1, bool col2acol);
0858   // Update emission branchers due to a recoiled parton.
0859   void updateEmittersFF(Event& event, int iOld, int iNew);
0860   // Update emission brancher due to an emission.
0861   void updateEmitterFF(Event& event, int iOld1, int iOld2, int iNew1,
0862     int iNew2);
0863   // Update splitter branchers due to a recoiled parton.
0864   void updateSplittersFF(Event& event, int iOld, int iNew);
0865   // Update splitter brancher due to an emission.
0866   void updateSplitterFF(Event& event, int iOld1, int iOld2, int iNew1,
0867     int iNew2, bool col2acol);
0868   // Remove a splitter due to a gluon that has branched, assumes that
0869   // iRemove is splitting gluon.
0870   void removeSplitterFF(int iRemove);
0871   // Update resonance emitter due to changed downstream decay products.
0872   bool updateEmittersRF(int iSysRes, Event& event, int iRes);
0873   // Update resonance emitter due to changed downstream decay products.
0874   void updateEmittersRF(int iSysRes, Event& event, vector<int> resSysAll,
0875     unsigned int posRes, unsigned int posPartner, bool isCol);
0876   // Update the antennae.
0877   bool updateAntennae(Event& event);
0878   // Update systems of QCD antennae after an EW/QED branching.
0879   bool updateAfterEW(Event& event, int sizeOld);
0880   // Print a brancher lookup.
0881   void printLookup(unordered_map< pair<int, bool>, unsigned int>&
0882     lookupEmitter, string name);
0883   // Print the brancher lookup maps.
0884   void printLookup();
0885   // Calculate the headroom factor.
0886   vector<double> getHeadroom(int iSys, bool isEmit, double q2Next);
0887   // Calculate the enhancement factor.
0888   vector<double> getEnhance(int iSys, bool isEmit, double q2Next);
0889 
0890   // Flags if initialized and prepared.
0891   bool isInit{}, isPrepared{};
0892 
0893   // Beam info.
0894   double eCMBeamsSav{}, m2BeamsSav{};
0895 
0896   // Main on/off switches.
0897   bool doFF{}, doRF{}, doII{}, doIF{}, doQED{}, doWeak{};
0898   int ewMode{}, ewModeMPI{};
0899 
0900   // Parameter setting which kind of 2->4 modifications (if any) are used.
0901   int mode2to4{};
0902 
0903   // Shower parameters.
0904   bool helicityShower{}, sectorShower{};
0905   int evTypeEmit{}, evTypeSplit{}, nGluonToQuark{};
0906   double q2CutoffEmit{}, q2CutoffSplit{};
0907   int nFlavZeroMass{};
0908   map<int,int> resSystems;
0909   int kMapResEmit{};
0910   int kMapResSplit{};
0911 
0912   // Factorization scale and shower starting settings.
0913   int    pTmaxMatch{}, pTdampMatch{};
0914   double pTmaxFudge{}, pT2maxFudge{}, pT2maxFudgeMPI{}, pTdampFudge{};
0915 
0916   // AlphaS parameters.
0917   bool useCMW{};
0918   int alphaSorder{};
0919   double alphaSvalue{}, alphaSmax{}, alphaSmuFreeze{}, alphaSmuMin{};
0920   double aSkMu2Emit{}, aSkMu2Split{};
0921 
0922   // Calculated alphaS values.
0923   double mu2freeze{}, mu2min{};
0924 
0925   // Map of qmin evolution window.
0926   map<double, EvolutionWindow> evWindowsEmit;
0927   map<double, EvolutionWindow> evWindowsSplit;
0928 
0929   // Lists of different types of antennae.
0930   vector< shared_ptr<BrancherEmitRF> >  emittersRF;
0931   vector< shared_ptr<BrancherEmitFF> >  emittersFF;
0932   vector< shared_ptr<BrancherSplitRF> > splittersRF;
0933   vector< shared_ptr<BrancherSplitFF> > splittersFF;
0934 
0935   // Look up resonance emitter, bool switches between R (true) or F
0936   // (false), n.b. multiply resonance index by sign of colour index
0937   // involved in branching to avoid a multiple-valued map.
0938   unordered_map< pair<int, bool>, unsigned int> lookupEmitterRF{};
0939   unordered_map< pair<int, bool>, unsigned int> lookupSplitterRF{};
0940   // Look up emitter, bool switches between col and anticol end
0941   unordered_map< pair<int, bool>, unsigned int> lookupEmitterFF{};
0942   // Lookup splitter, bool switches between splitter and recoiler.
0943   unordered_map< pair<int, bool>, unsigned int> lookupSplitterFF{};
0944 
0945   // Current winner.
0946   BrancherPtr winnerQCD{};
0947   VinciaModulePtr winnerEW{};
0948   double q2WinSav{}, pTLastAcceptedSav{};
0949 
0950   // Variables set by branch().
0951   int iSysWin{};
0952   enum AntFunType antFunTypeWin{AntFunType::NoFun};
0953   bool hasWeaklyRadiated{false};
0954 
0955   // Index of latest emission (slightly arbritrary for splittings but
0956   // only used to populate some internal histograms.
0957   int iNewSav{};
0958 
0959   // Storage of the post-branching configuration while it is being built.
0960   vector<Particle> pNew;
0961   // Total and MEC accept probability.
0962   vector<double> pAccept;
0963 
0964   // Colour reconnection parameters.
0965   bool doCR{}, CRjunctions{};
0966 
0967   // Enhancement switches and parameters.
0968   bool enhanceInHard{}, enhanceInResDec{}, enhanceInMPI{};
0969   double enhanceAll{}, enhanceBottom{}, enhanceCharm{}, enhanceCutoff{};
0970 
0971   // Possibility to allow user veto of emission step.
0972   bool hasUserHooks{}, canVetoEmission{}, canVetoISREmission{};
0973 
0974   // Flags to tell a few basic properties of each parton system.
0975   map<int, bool> isHardSys{}, isResonanceSys{}, polarisedSys{}, doMECsSys{};
0976   map<int, bool> stateChangeSys{};
0977   bool stateChangeLast;
0978 
0979   // Save initial FSR starting scale system by system.
0980   map<int, double> q2Hat{};
0981   vector<bool> doPTlimit{}, doPTdamp{};
0982   map<int, double> pT2damp{};
0983 
0984   // Count the number of branchings in the system.
0985   map<int, int> nBranch, nBranchFSR;
0986 
0987   // Total mass of showering system.
0988   map<int, double> mSystem;
0989 
0990   // Count numbers of quarks and gluons.
0991   map<int, int> nG, nQ, nLep, nGam;
0992 
0993   // Partons present in the Born (needed in sector shower).
0994   map<int, bool> savedBorn;
0995   map<int, bool> resolveBorn;
0996   map<int, map<int, int>> nFlavsBorn;
0997 
0998   // Save headroom and enhancement factors for each system for both
0999   // emission and splitting branchers.
1000   unordered_map<pair<int, pair<bool,bool> >, vector<double> > headroomSav;
1001   unordered_map<pair<int, pair<bool,bool> >, vector<double> > enhanceSav;
1002 
1003   // Information about resonances that participate in junctions.
1004   map<int, bool> hasResJunction;
1005   map<int, ResJunctionInfo> junctionInfo;
1006 
1007   // Flags used in merging.
1008   bool doMerging, isTrialShower, isTrialShowerRes;
1009 
1010   // Verbose settings.
1011   int verbose{};
1012   bool headerIsPrinted{};
1013 
1014   // Diagnostics.
1015   shared_ptr<VinciaDiagnostics> diagnosticsPtr{};
1016 
1017   // Debug settings.
1018   bool allowforceQuit{}, forceQuit{};
1019   int nBranchQuit{};
1020 
1021   // Zeta generators for trial generators.
1022   ZetaGeneratorSet      zetaGenSetRF;
1023   ZetaGeneratorSet      zetaGenSetFF;
1024 
1025   // Pointers to VINCIA objects.
1026   AntennaSetFSR*        antSetPtr{};
1027   MECs*                 mecsPtr{};
1028   VinciaColour*         colourPtr{};
1029   Resolution*           resolutionPtr{};
1030   shared_ptr<VinciaISR> isrPtr{};
1031   VinciaCommon*         vinComPtr{};
1032   VinciaWeights*        weightsPtr{};
1033 
1034   // Electroweak shower pointers.
1035   VinciaModulePtr       ewShowerPtr{};
1036   VinciaModulePtr       qedShowerHardPtr{};
1037   VinciaModulePtr       qedShowerSoftPtr{};
1038   // Pointer to either ewShowerPtr or qedShowerHardPtr depending on ewMode.
1039   VinciaModulePtr       ewHandlerHard{};
1040 
1041   // Pointer to AlphaS instances.
1042   AlphaStrong* aSemitPtr{};
1043   AlphaStrong* aSsplitPtr{};
1044 
1045   // Settings and member variables for interleaved resonance decays
1046   bool doFSRinResonances{true}, doInterleaveResDec{true};
1047   int resDecScaleChoice{-1}, iHardResDecSav{}, nRecurseResDec{};
1048   vector<int> idResDecSav, iPosBefSav;
1049   vector<double> pTresDecSav;
1050 
1051 };
1052 
1053 //==========================================================================
1054 
1055 } // end namespace Pythia8
1056 
1057 #endif // Pythia8_VinciaFSR_H