Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:23:35

0001 // VinciaQED.h is a part of the PYTHIA event generator.
0002 // Copyright (C) 2025 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 the QED antenna-shower class and auxiliary
0007 // classes. Main author is Rob Verheyen.
0008 
0009 #ifndef Pythia8_VinciaQED_H
0010 #define Pythia8_VinciaQED_H
0011 
0012 // PYTHIA 8 headers.
0013 #include "Pythia8/BeamParticle.h"
0014 #include "Pythia8/Event.h"
0015 #include "Pythia8/StandardModel.h"
0016 #include "Pythia8/PartonSystems.h"
0017 
0018 // VINCIA headers.
0019 #include "Pythia8/VinciaCommon.h"
0020 #include "Pythia8/VinciaWeights.h"
0021 
0022 namespace Pythia8 {
0023 
0024 //==========================================================================
0025 
0026 // Class for QED emissions.
0027 
0028 class QEDemitElemental {
0029 
0030 public:
0031 
0032   // Friends for internal private members.
0033   friend class QEDemitSystem;
0034 
0035   // Constuctor.
0036   QEDemitElemental() : rndmPtr(nullptr), partonSystemsPtr(nullptr), q2Sav(0.),
0037     zetaSav(0.), phiSav(0.), sxjSav(0.), syjSav(0.), alpha(0.), c(0.),
0038     hasTrial(false), x(0), y(0), idx(0), idy(0), mx2(0.), my2(0.),
0039     ex(0.), ey(0.), m2Ant(0.), sAnt(0.), QQ(0.), isII(false), isIF(false),
0040     isFF(false), isRF(false), isIA(true), isDip(false), shh(0.),
0041     isInitPtr(false), isInit(false), verbose(1) {;}
0042 
0043   // Initialize the pointers.
0044   void initPtr(Rndm* rndmPtrIn, PartonSystems* partonSystemsPtrIn);
0045   // Initialize.
0046   void init(Event &event, int xIn, int yIn, double shhIn,
0047     double verboseIn);
0048   // Initialize.
0049   void init(Event &event, int xIn, vector<int> iRecoilIn, double shhIn,
0050     double verboseIn);
0051   // Generate a trial point.
0052   double generateTrial(Event &event, double q2Start, double q2Low,
0053     double alphaIn, double cIn);
0054 
0055 private:
0056 
0057   // Random pointer.
0058   Rndm* rndmPtr{};
0059 
0060   // Parton system pointer.
0061   PartonSystems* partonSystemsPtr{};
0062 
0063   // Trial variables.
0064   double q2Sav, zetaSav, phiSav, sxjSav, syjSav, alpha, c;
0065   bool hasTrial;
0066 
0067   // Particle indices.
0068   int x, y;
0069   // Recoiler indices.
0070   vector<int> iRecoil;
0071   // IDs.
0072   int idx, idy;
0073   // Number of spin states.
0074   int spinTypex, spinTypey;
0075   // Particle masses.
0076   double mx2, my2;
0077   // Particle energies.
0078   double ex, ey;
0079   // Antenna invariant mass.
0080   double m2Ant;
0081   // Antenna dot product.
0082   double sAnt;
0083   // The negative of the product of charges.
0084   double QQ;
0085 
0086   // Type switches.
0087   bool isII, isIF, isFF, isRF, isIA, isDip;
0088 
0089   // Hadronic invariant mass.
0090   double shh;
0091 
0092   // Initialization.
0093   bool isInitPtr, isInit;
0094   int verbose;
0095 
0096 };
0097 
0098 //==========================================================================
0099 
0100 // Base class for QED systems.
0101 
0102 class QEDsystem {
0103 
0104  public:
0105 
0106   // Constructor.
0107   QEDsystem() : infoPtr(nullptr), partonSystemsPtr(nullptr),
0108     particleDataPtr(nullptr), rndmPtr(nullptr), settingsPtr(nullptr),
0109     loggerPtr(nullptr), vinComPtr(nullptr), isInitPtr(false), iSys(-1),
0110     verbose(0), jNew(0), shat(0.) {;}
0111 
0112   // Destructor.
0113   virtual ~QEDsystem() = default;
0114 
0115   // Initialize pointers.
0116   void initPtr(Info* infoPtrIn, ParticleData* particleDataPtrIn,
0117     PartonSystems* partonSystemsPtrIn, Rndm* rndmPtrIn,
0118     Settings* settingsPtrIn, VinciaCommon* vinComPtrIn);
0119 
0120   // Initialise settings for current run.
0121   virtual void init(BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn,
0122     int verboseIn) = 0;
0123   virtual void setVerbose(int verboseIn) { verbose = verboseIn; }
0124   // Prepare a parton system for evolution.
0125   virtual void prepare(const int iSysIn, Event &event, const double q2CutIn,
0126     const int scaleRegionIn, const vector<double> evolutionWindowsIn,
0127     AlphaEM alIn) = 0;
0128   // Build parton system.
0129   virtual void buildSystem(Event &event) = 0;
0130   // Generate a trial scale.
0131   virtual double q2Next(Event &event, double q2Start) = 0 ;
0132   // Generate kinematics and check for veto of branching.
0133   virtual bool acceptTrial(Event &event) = 0;
0134   // Update the envent.
0135   virtual void updateEvent(Event &event) = 0;
0136   // Update the parton systems.
0137   virtual void updatePartonSystems();
0138   // Print information about the system.
0139   virtual void print() = 0;
0140 
0141   // Methods to tell which type of brancher this is.
0142   virtual bool isSplitting() {return false;};
0143   virtual bool isInitial() {return false;};
0144 
0145  protected:
0146 
0147   // Pointers.
0148   Info* infoPtr{};
0149   PartonSystems* partonSystemsPtr{};
0150   ParticleData* particleDataPtr{};
0151   Rndm* rndmPtr{};
0152   Settings* settingsPtr{};
0153   Logger* loggerPtr{};
0154   VinciaCommon* vinComPtr{};
0155   bool isInitPtr;
0156 
0157   // Event system.
0158   int iSys;
0159   vector<Vec4> pNew;
0160 
0161   // Verbose setting.
0162   int verbose;
0163 
0164   // Information for partonSystems.
0165   int jNew;
0166   map<int,int> iReplace;
0167   double shat;
0168 
0169 };
0170 
0171 //==========================================================================
0172 
0173 // Class for a QED emission system.
0174 
0175 class QEDemitSystem : public QEDsystem {
0176 
0177 public:
0178 
0179   QEDemitSystem() : shh(-1.), cMat(0.), trialIsVec(false), beamAPtr(nullptr),
0180     beamBPtr(nullptr), qedMode(-1), qedModeMPI(-1),
0181     scaleRegion(0), emitBelowHad(false), q2Cut(-1.), isInit(false),
0182     TINYPDF(-1.), kMapTypeFinal(0) {;}
0183 
0184   // Initialise settings for current run.
0185   void init(BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn,
0186     int verboseIn) override;
0187   // Prepare a parton system for photon emission evolution
0188   void prepare(const int iSysIn, Event &event, const double q2CutIn,
0189     const int scaleRegionIn, const vector<double> evolutionWindowsIn,
0190     AlphaEM alIn) override;
0191   // Set up antenna pairing for incoherent mode.
0192   void buildSystem(Event &event) override;
0193   // Generate a trial scale.
0194   double q2Next(Event &event, double q2Start) override;
0195   // Generate kinematics and check veto.
0196   bool acceptTrial(Event &event) override;
0197   // Update the envent
0198   void updateEvent(Event &event) override;
0199   // Branching type.
0200   bool isInitial() override {return eleTrial->isII || eleTrial->isIF;}
0201   // Print the QED emit internal system.
0202   void print() override;
0203 
0204   // Trial antenna function.
0205   double aTrial(QEDemitElemental* ele, double sxj, double syj, double sxy);
0206   // Physical antenna function.
0207   double aPhys (QEDemitElemental* ele, double sxj, double syj, double sxy);
0208   // Ratio between PDFs.
0209   double pdfRatio(bool isA, double eOld, double eNew, int id, double Qt2);
0210 
0211   private:
0212 
0213   // Event system.
0214   double shh;
0215 
0216   // Internal storage.
0217   vector<vector<QEDemitElemental> > eleMat;
0218   vector<int> iCoh;
0219   double cMat;
0220   vector<QEDemitElemental> eleVec;
0221 
0222   // AlphaEM.
0223   AlphaEM al;
0224 
0225   // Evolution window.
0226   vector<double> evolutionWindows;
0227 
0228   // Trial pointer.
0229   QEDemitElemental* eleTrial{};
0230   bool trialIsVec;
0231 
0232   // Beam pointers.
0233   BeamParticle* beamAPtr{};
0234   BeamParticle* beamBPtr{};
0235 
0236   // Settings.
0237   int qedMode, qedModeMPI;
0238   vector<bool> useSpinsQEDNow, useSpinsQED, useSpinsQEDHadDec;
0239   int scaleRegion, emitBelowHad, isHadronDecay;
0240   double q2Cut;
0241 
0242   // Initialization.
0243   bool isInit;
0244 
0245   // PDF check.
0246   double TINYPDF;
0247 
0248   // Recoil strategy.
0249   int kMapTypeFinal;
0250 
0251   // Global recoil momenta.
0252   Vec4 pRecSum;
0253   vector<Vec4> pRec;
0254   vector<int>  iRec;
0255 
0256 };
0257 
0258 //==========================================================================
0259 
0260 // Class for trial QED splittings.
0261 
0262 class QEDsplitElemental {
0263 
0264 public:
0265 
0266   // Friends for internal private members.
0267   friend class QEDsplitSystem;
0268 
0269   // Constructor.
0270   QEDsplitElemental(Event &event, int iPhotIn, int iSpecIn):
0271     iPhot(iPhotIn), iSpec(iSpecIn), ariWeight(0) {
0272     m2Ant = max(VinciaConstants::PICO,
0273       m2(event[iPhotIn], event[iSpecIn]));
0274     sAnt = max(VinciaConstants::PICO,
0275       2.*event[iPhotIn].p()*event[iSpecIn].p());
0276     m2Spec = max(0., event[iSpecIn].m2());
0277   }
0278 
0279   // Kallen function.
0280   double getKallen() {return m2Ant/(m2Ant - m2Spec);}
0281 
0282 private:
0283 
0284   // Internal members.
0285   int iPhot, iSpec;
0286   double m2Spec, m2Ant, sAnt;
0287   double ariWeight;
0288 };
0289 
0290 //==========================================================================
0291 
0292 // Class for a QED splitting system.
0293 
0294 class QEDsplitSystem : public QEDsystem {
0295 
0296 public:
0297 
0298   // Constructor.
0299   QEDsplitSystem() :
0300     totIdWeight(-1.), hasTrial(false),
0301     q2Trial(-1.), zTrial(-1.), phiTrial(-1.), idTrial(0), nQuark(-1),
0302     nLepton(-1), q2Max(-1.), q2Cut(-1.), scaleRegion(0),
0303     beamAPtr(nullptr), beamBPtr(nullptr), isInit(false), kMapTypeFinal(0) {;}
0304 
0305   // Initialize.
0306   void init(BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn,
0307     int verboseIn) override;
0308   // Prepare list of final-state photons - with recoilers - for splittings.
0309   void prepare(const int iSysIn, Event &event, const double q2CutIn,
0310     const int scaleRegionIn, const vector<double> evolutionWindowsIn,
0311     AlphaEM alIn) override;
0312   // Build the splitting system.
0313   void buildSystem(Event &event) override;
0314   // Generate a scale for the system.
0315   double q2Next(Event &event, double q2Start) override;
0316   // Generate kinematics and check veto.
0317   bool acceptTrial(Event &event) override;
0318   // Update Event.
0319   void updateEvent(Event &event) override;
0320   // Branching type: isSplitting() = true.
0321   bool isSplitting() override { return true;}
0322   // Print the system.
0323   void print() override;
0324 
0325 private:
0326 
0327   // AlphaEM.
0328   AlphaEM al;
0329 
0330   // Evolution window.
0331   vector<double> evolutionWindows;
0332 
0333   // Weights for splitting IDs.
0334   vector<int> ids;
0335   vector<double> idWeights;
0336   double totIdWeight;
0337 
0338   // Antennae.
0339   vector<QEDsplitElemental> eleVec;
0340 
0341   // Trial variables.
0342   bool hasTrial;
0343   double q2Trial, zTrial, phiTrial, idTrial;
0344   QEDsplitElemental* eleTrial{};
0345 
0346   // Settings.
0347   int nQuark, nLepton;
0348   double q2Max, q2Cut;
0349   int scaleRegion;
0350 
0351   // Pointers.
0352   BeamParticle*  beamAPtr;
0353   BeamParticle*  beamBPtr;
0354 
0355   // Initialization.
0356   bool isInit;
0357 
0358   // Recoil strategy.
0359   int kMapTypeFinal;
0360 
0361 };
0362 
0363 //==========================================================================
0364 
0365 // Class for a QED conversion system.
0366 
0367 class QEDconvSystem : public QEDsystem {
0368 
0369 public:
0370 
0371   // Constructor.
0372   QEDconvSystem() : totIdWeight(-1.), maxIdWeight(-1.), shh(-1.), s(-1.),
0373     iA(-1), iB(-1), isAPhot(false), isBPhot(false), hasTrial(false),
0374     iPhotTrial(-1), iSpecTrial(-1), q2Trial(-1.), zTrial(-1.), phiTrial(-1.),
0375     idTrial(-1), nQuark(-1), q2Cut(-1.),
0376     scaleRegion(0), beamAPtr(nullptr), beamBPtr(nullptr),isInit(false),
0377     TINYPDF(-1.) {;}
0378 
0379   // Initialize.
0380   void init(BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn,
0381     int verboseIn) override;
0382   // Prepare for backwards-evolution of photons.
0383   void prepare(const int iSysIn, Event &event, const double q2CutIn,
0384     const int scaleRegionIn, const vector<double> evolutionWindowsIn,
0385     AlphaEM alIn) override;
0386   // Build the system.
0387   void buildSystem(Event &event) override;
0388   // Generate a trial scale.
0389   double q2Next(Event &event, double q2Start) override;
0390   // Generate kinematics and check veto.
0391   bool acceptTrial(Event &event) override;
0392   // Update.
0393   void updateEvent(Event &event) override;
0394   // Branching type: isInitial() = true.
0395   bool isInitial() override {return true;};
0396   // Print.
0397   void print() override;
0398 
0399 private:
0400 
0401   // Trial pdf ratios for conversion.
0402   map<int,double> Rhat;
0403 
0404   // AlphaEM.
0405   AlphaEM al;
0406 
0407   // Evolution window.
0408   vector<double> evolutionWindows;
0409 
0410   // Weights for conversion IDs.
0411   vector<int> ids;
0412   vector<double> idWeights;
0413   double totIdWeight, maxIdWeight;
0414   double shh;
0415 
0416   // Antenna parameters.
0417   double s;
0418   int iA, iB;
0419   bool isAPhot, isBPhot;
0420 
0421   // Trial variables.
0422   bool hasTrial;
0423   int iPhotTrial, iSpecTrial;
0424   double q2Trial, zTrial, phiTrial, idTrial;
0425 
0426   // Settings.
0427   int nQuark;
0428   double q2Cut;
0429 
0430   // Scale Region determines what region and scale we are showering at.
0431   // Scale Region = 0 is above the hadronisation scale.
0432   // Scale Region = 1 is below the hadronisation scale.
0433   // Scale Region = 2 is below the hadronisation scale and contains remanants.
0434   int scaleRegion;
0435 
0436   // Pointers.
0437   BeamParticle*  beamAPtr;
0438   BeamParticle*  beamBPtr;
0439 
0440   // Initialization.
0441   bool isInit;
0442 
0443   // PDF check.
0444   double TINYPDF;
0445 
0446   // Global recoil momenta
0447   vector<Vec4> pRec;
0448   vector<int>  iRec;
0449 
0450 };
0451 
0452 //==========================================================================
0453 
0454 // Base class for Vincia's QED and EW shower modules.
0455 
0456 class VinciaModule {
0457 
0458 public:
0459 
0460   // Default constructor.
0461   VinciaModule(): verbose(-1), isInitPtr(false), isInitSav(false) {;};
0462 
0463   // Default destructor.
0464   virtual ~VinciaModule() = default;
0465 
0466   // Initialise pointers (called at construction time).
0467   virtual void initPtr(Info* infoPtrIn, VinciaCommon* vinComPtrIn) = 0;
0468 
0469   //Some early initialisation (needed for EW shower).
0470   virtual void load() {;}
0471 
0472   // Initialise settings for current run (called as part of Pythia::init()).
0473   virtual void init(BeamParticle* beamAPtrIn = nullptr,
0474     BeamParticle* beamBPtrIn = nullptr) = 0;
0475   bool isInit() {return isInitSav;}
0476 
0477   // Select helicities for a system of particles.
0478   virtual bool polarise(vector<Particle>&) {return false;}
0479 
0480   // Prepare to shower a system.
0481   virtual bool prepare(int iSysIn, Event &event, int scaleRegionIn) = 0;
0482 
0483   // Update shower system each time something has changed in event.
0484   virtual void update(Event &event, int iSys) = 0;
0485 
0486   // Set verbosity level.
0487   virtual void setVerbose(int verboseIn) {verbose = verboseIn;}
0488 
0489   // Clear everything (optionally for specific system).
0490   virtual void clear(int iSys = -1) = 0;
0491 
0492   // Generate a trial scale.
0493   virtual double q2Next(Event &event, double q2Start, double q2End) = 0;
0494 
0495   // Which system does the winner belong to?
0496   virtual int sysWin() = 0;
0497 
0498   // Get information about the latest branching.
0499   virtual bool lastIsSplitting() = 0;
0500   virtual bool lastIsInitial() = 0;
0501   virtual bool lastIsResonanceDecay() {return false;}
0502 
0503   // Generate kinematics and check veto.
0504   virtual bool acceptTrial(Event &event) = 0;
0505 
0506   // Update event after branching accepted.
0507   virtual void updateEvent(Event &event) = 0;
0508 
0509   // Update partonSystems after branching accepted.
0510   virtual void updatePartonSystems(Event &event) = 0;
0511 
0512   // End scales.
0513   virtual double q2minColoured() = 0;
0514   virtual double q2min() = 0;
0515 
0516   // Get number of branchers / systems.
0517   virtual unsigned int nBranchers() = 0;
0518   virtual unsigned int nResDec() = 0;
0519 
0520   // Members.
0521   BeamParticle* beamAPtr{};
0522   BeamParticle* beamBPtr{};
0523   Info* infoPtr{};
0524   ParticleData* particleDataPtr{};
0525   Logger* loggerPtr{};
0526   PartonSystems* partonSystemsPtr{};
0527   Rndm* rndmPtr{};
0528   Settings* settingsPtr{};
0529   VinciaCommon* vinComPtr{};
0530 
0531  protected:
0532 
0533   int verbose;
0534   bool isInitPtr, isInitSav;
0535 
0536 };
0537 
0538 //==========================================================================
0539 
0540 // Class for performing QED showers.
0541 
0542 class VinciaQED : public VinciaModule {
0543 
0544 public:
0545 
0546   // Friends for internal private members.
0547   friend class VinciaFSR;
0548 
0549   // Constructor.
0550   VinciaQED() {;}
0551 
0552   // Initialise pointers (called at construction time).
0553   void initPtr(Info* infoPtrIn, VinciaCommon* vinComPtrIn) override;
0554   // Initialise settings for current run (called as part of Pythia::init()).
0555   void init(BeamParticle* beamAPtrIn = 0, BeamParticle* beamBPtrIn = 0)
0556     override;
0557   // Prepare to shower a system.
0558   bool prepare(int iSysIn, Event& event, int scaleRegionIn) override;
0559   // Update QED shower system(s) each time something has changed in event.
0560   void update(Event& event, int iSys) override;
0561   // Set or change verbosity level, and propagate to QED systems.
0562   virtual void setVerbose(int verboseIn) override {
0563     verbose = verboseIn;
0564     emptyQEDemitSystem.setVerbose(verboseIn);
0565     emptyQEDsplitSystem.setVerbose(verboseIn);
0566     emptyQEDconvSystem.setVerbose(verboseIn);
0567   }
0568   // Clear everything, or specific system.
0569   void clear(int iSys = -1) override {
0570     if (iSys < 0) {emitSystems.clear(); splitSystems.clear();
0571       convSystems.clear();}
0572     else {emitSystems.erase(iSys); splitSystems.erase(iSys);
0573       convSystems.erase(iSys);}
0574     qedTrialSysPtr = nullptr;}
0575 
0576   // Generate a trial scale.
0577   double q2Next(Event& event, double q2Start, double) override;
0578   // Return the system window.
0579   int  sysWin() override {return iSysTrial;}
0580   // Information about last branching.
0581   bool lastIsSplitting() override {
0582     if (qedTrialSysPtr != nullptr) return  qedTrialSysPtr->isSplitting();
0583     else return false;}
0584   bool lastIsInitial() override {
0585     if (qedTrialSysPtr != nullptr) return qedTrialSysPtr->isInitial();
0586     else return false;}
0587   // Generate kinematics and check veto.
0588   bool acceptTrial(Event &event) override;
0589   // Update event after branching accepted.
0590   void updateEvent(Event &event) override;
0591   // Update partonSystems after branching accepted.
0592   void updatePartonSystems(Event &event) override;
0593   // Return scales.
0594   double q2minColoured() override {return q2minColouredSav;}
0595   double q2min() override {return q2minSav;}
0596 
0597   // Getter for number of systems.
0598   unsigned int nBranchers() override {
0599     int sizeNow = emitSystems.size();
0600     sizeNow = max(sizeNow, (int)splitSystems.size());
0601     sizeNow = max(sizeNow, (int)convSystems.size());
0602     return sizeNow;}
0603 
0604   // This module does not implement resonance decays.
0605   unsigned int nResDec() override { return 0; }
0606 
0607 private:
0608 
0609   // Get Q2 for QED system.
0610   template <class T>
0611   void q2NextSystem(map<int, T>& QEDsystemList, Event& event, double q2Start);
0612 
0613   // Systems.
0614   QEDemitSystem emptyQEDemitSystem;
0615   QEDsplitSystem emptyQEDsplitSystem;
0616   QEDconvSystem emptyQEDconvSystem;
0617   map< int, QEDemitSystem> emitSystems;
0618   map< int, QEDsplitSystem> splitSystems;
0619   map< int, QEDconvSystem> convSystems;
0620 
0621   // Settings.
0622   bool doQED, doEmission;
0623   int  nGammaToLepton, nGammaToQuark;
0624   bool doConvertGamma, doConvertQuark;
0625 
0626   // Scales.
0627   double q2minSav, q2minColouredSav;
0628 
0629   // Trial information
0630   int iSysTrial;
0631   double q2Trial;
0632   QEDsystem* qedTrialSysPtr{};
0633 
0634   // AlphaEM.
0635   AlphaEM al;
0636 
0637   // Evolution windows
0638   vector<double> evolutionWindows;
0639 
0640 };
0641 
0642 //==========================================================================
0643 
0644 } // end namespace Pythia8
0645 
0646 #endif // Pythia8_VinciaQED_H