Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Ropewalk.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 // Header file for Rope Hadronization. The Ropewalk takes care of setting
0007 // up string geometry and calculating overlaps etc. The RopeDipole classes
0008 // take care of the dynamics of string shoving. Flavour-composition-changing
0009 // ropes are handled by FlavourRope which changes parameters, and RopeFragPars
0010 // which calculates parameters for the rope.
0011 //
0012 // The file contains the following classes: RopeDipoleEnd,
0013 // OverlappingRopeDipole, RopeDipole, Ropewalk, RopeFragPars and FlavourRope.
0014 
0015 #ifndef Pythia8_Ropewalk_H
0016 #define Pythia8_Ropewalk_H
0017 
0018 #include "Pythia8/Basics.h"
0019 #include "Pythia8/Event.h"
0020 #include "Pythia8/FragmentationSystems.h"
0021 #include "Pythia8/Info.h"
0022 #include "Pythia8/ParticleData.h"
0023 #include "Pythia8/Settings.h"
0024 #include "Pythia8/PythiaStdlib.h"
0025 #include "Pythia8/StringInteractions.h"
0026 
0027 namespace Pythia8 {
0028 
0029 //==================================================================
0030 
0031 // Define the end of a dipole, containing a pointer to the particle,
0032 // and its index in the event record.
0033 // Includes some methods for kinematics output.
0034 
0035 class RopeDipoleEnd {
0036 
0037 public:
0038 
0039   // Constructors sets event pointer and event record index.
0040   RopeDipoleEnd() : e(nullptr), ne(-1) { }
0041   RopeDipoleEnd(Event* eIn, int neIn) : e(eIn), ne(neIn) { }
0042 
0043   // Get a pointer to the particle.
0044   Particle* getParticlePtr() { if (!e) return nullptr; return &(*e)[ne]; }
0045 
0046   // Get the particle index in event record.
0047   int getNe() {return ne;}
0048 
0049   // Output methods for (modified) rapidity.
0050   double labrap() { return getParticlePtr()->y(); }
0051   double rap(double m0){ return getParticlePtr()->y(m0); }
0052   double rap(double m0, RotBstMatrix& r) { return getParticlePtr()->y(m0, r); }
0053 
0054 private:
0055 
0056   // Pointer to the event and the particle index in event record.
0057   Event* e;
0058   int ne;
0059 
0060 };
0061 
0062 //==================================================================
0063 
0064 // A dipole has many dipoles overlapping with it. The OverlappingRopeDipole
0065 // class does bookkeeping of this. Holds a pointer to the original dipole.
0066 
0067 // Forward declaration of RopeDipole class.
0068 class RopeDipole;
0069 
0070 class OverlappingRopeDipole {
0071 
0072 public:
0073 
0074   // Constructor sets up coordinates in the rest frame of other dipole.
0075   OverlappingRopeDipole(RopeDipole* d, double m0, RotBstMatrix& r);
0076 
0077   // Calculate the overlap at given y and b.
0078   bool overlap(double y, Vec4 ba, double r0);
0079 
0080   // Has the dipole been hadronized?
0081   bool hadronized();
0082 
0083 private:
0084 
0085   // Pointer to the original dipole.
0086   RopeDipole* dipole;
0087 
0088 // Data members are made public rather than making
0089 // the RopeDipole class a friend.
0090 public:
0091 
0092   int dir;
0093   double y1, y2;
0094   Vec4 b1, b2;
0095 
0096 };
0097 
0098 //==================================================================
0099 
0100 // The RopeDipole class holds information about a colour dipole, as well as
0101 // functionality to do shoving and to calculate effective string tension.
0102 
0103 class RopeDipole {
0104 
0105 public:
0106 
0107   // The RopeDipole constructor makes sure that d1 is always the colored
0108   // end and d2 the anti-colored.
0109   RopeDipole(RopeDipoleEnd d1In, RopeDipoleEnd d2In, int iSubIn,
0110     Logger* loggerPtrIn);
0111 
0112   // Insert an excitation on dipole, if not already there.
0113   void addExcitation(double ylab, Particle* ex);
0114 
0115   // Deep access to the RopeDipoleEnds (needed by OverlappingRopeDipole).
0116   RopeDipoleEnd* d1Ptr() { return &d1; }
0117   RopeDipoleEnd* d2Ptr() { return &d2; }
0118 
0119   // Get the rotation matrix to go to dipole rest frame.
0120   RotBstMatrix getDipoleRestFrame();
0121   RotBstMatrix getDipoleLabFrame();
0122 
0123   // Get the dipole momentum four-vector.
0124   Vec4 dipoleMomentum();
0125   // Get the spatial point interpolated to given rapidity.
0126   // In the dipole rest frame.
0127   Vec4 bInterpolateDip(double y, double m0);
0128   // In the lab frame.
0129   Vec4 bInterpolateLab(double y, double m0);
0130   // Given a Lorentz matrix.
0131   Vec4 bInterpolate(double y, RotBstMatrix rb, double m0);
0132 
0133   // Get the quantum numbers m,n characterizing all dipole overlaps
0134   // at a given rapidity value.
0135   pair<int, int> getOverlaps(double yfrac, double m0, double r0);
0136 
0137   // Add an overlapping dipole.
0138   void addOverlappingDipole(OverlappingRopeDipole& d) {
0139     overlaps.push_back(d); }
0140 
0141   // Get the maximal and minimal rapidity of the dipole.
0142   double maxRapidity(double m0) { return (max(d1.rap(m0), d2.rap(m0))); }
0143   double minRapidity(double m0) { return (min(d1.rap(m0), d2.rap(m0))); }
0144 
0145   // Get the maximal and minimal boosted rapidity of the dipole.
0146   double maxRapidity(double m0, RotBstMatrix& r) { return (max(d1.rap(m0,r),
0147     d2.rap(m0,r))); }
0148   double minRapidity(double m0, RotBstMatrix& r) { return (min(d1.rap(m0,r),
0149     d2.rap(m0,r))); }
0150 
0151   // Propagate the dipole itself.
0152   void propagateInit(double deltat);
0153 
0154   // Propagate both dipole ends as well as all excitations.
0155   void propagate(double deltat, double m0);
0156 
0157   // Redistribute momentum to two particles.
0158   void splitMomentum(Vec4 mom, Particle* p1, Particle* p2, double frac = 0.5);
0159 
0160   // Put gluon excitations on the dipole.
0161   void excitationsToString(double m0, Event& event);
0162 
0163   // Test if the dipole is hadronized.
0164   bool hadronized() { return isHadronized; }
0165 
0166   // Get the (event colconfig) index.
0167   int index() { return iSub; }
0168 
0169   // Recoil the dipole from adding a gluon. If the "dummy" option is set,
0170   // the recoil will not be added, but only checked.
0171   // Note: the gluon will not actually be added, only the recoil (if possible).
0172   bool recoil(Vec4& pg, bool dummy = false);
0173 
0174   // Set dipole hadronized flag.
0175   void hadronized(bool h) { isHadronized = h; }
0176 
0177   // The number of excitations on the dipole.
0178   int nExcitations() { return int(excitations.size()); }
0179 
0180 private:
0181 
0182   // The ends (ie. particles) of the dipole.
0183   RopeDipoleEnd d1, d2;
0184 
0185   // The propagated positions in the lab frame.
0186   Vec4 b1, b2;
0187 
0188   // The string index (internal to the event).
0189   int iSub;
0190 
0191   // Lorentz matrices to go to and from dipole rest frame.
0192   RotBstMatrix rotFrom, rotTo;
0193   bool hasRotFrom, hasRotTo;
0194 
0195   // The dipoles overlapping with this one.
0196   vector<OverlappingRopeDipole> overlaps;
0197 
0198   // All excitations belonging to this dipole ordered in rapidity in lab frame.
0199   map<double, Particle*> excitations;
0200 
0201   bool isHadronized;
0202   Logger* loggerPtr;
0203 
0204 };
0205 
0206 //==================================================================
0207 
0208 // The Ropewalk class keeps track of all the strings making up ropes
0209 // for shoving as well as flavour enhancement.
0210 
0211 class Ropewalk : public StringInteractions {
0212 
0213 public:
0214 
0215   // Constructor.
0216   Ropewalk() : r0(), m0(), pTcut(),
0217     shoveJunctionStrings(),
0218     shoveMiniStrings(), shoveGluonLoops(), mStringMin(), limitMom(), rCutOff(),
0219     gAmplitude(), gExponent(), deltay(), deltat(), tShove(), tInit(),
0220     showerCut(), alwaysHighest() {}
0221 
0222   // The Ropewalk init function sets parameters and pointers.
0223   virtual bool init();
0224 
0225   // Extract all dipoles from an event.
0226   bool extractDipoles(Event& event, ColConfig& colConfig);
0227 
0228   // Calculate all overlaps of all dipoles and store as OverlappingRopeDipoles.
0229   bool calculateOverlaps();
0230 
0231   // Calculate the effective string tension a fraction yfrac in on the dipole
0232   // given by indices e1 and e2.
0233   double getKappaHere(int e1, int e2, double yfrac);
0234 
0235   // The multiplicity of a colour state given its quantum numbers.
0236   double multiplicity(double p, double q) {
0237     return ( p < 0 || q < 0 || p + q == 0 )
0238       ? 0.0 : 0.5 * (p + 1) * (q + 1) * (p + q + 2);
0239   }
0240 
0241   // Calculate the average string tension of the event, in units of the default
0242   // string tension (ie. 1 GeV/fm), using random walk in colour space.
0243   double averageKappa();
0244 
0245   // Invoke the random walk and select a state.
0246   pair<int, int> select(int m, int n, Rndm* rndm);
0247 
0248   // Shove all dipoles in the event.
0249   void shoveTheDipoles(Event& event);
0250 
0251 private:
0252 
0253   // Parameters of the ropewalk.
0254   double r0, m0, pTcut;
0255   // Include junction strings in shoving.
0256   bool shoveJunctionStrings;
0257   // Include ministrings in shoving.
0258   bool shoveMiniStrings;
0259   // Include gluon loops in shoving.
0260   bool shoveGluonLoops;
0261   // Limit between string frag and ministring.
0262   double mStringMin;
0263   // Limit participating dipoles by their momentum.
0264   bool limitMom;
0265   // Radius cutoff in multiples of r0.
0266   double rCutOff;
0267   // Parameters of the shoving.
0268   double gAmplitude, gExponent;
0269   // Rapidity slicing.
0270   double deltay;
0271   // Time steps.
0272   double deltat;
0273   // Shove time.
0274   double tShove;
0275   // Intial propagation time.
0276   double tInit;
0277   // Final state shower cut-off.
0278   double showerCut;
0279   // Assume we are always in highest multiplet.
0280   bool alwaysHighest;
0281 
0282   // All dipoles in the event sorted by event record.
0283   // Index of the two partons.
0284   typedef multimap<pair<int,int>, RopeDipole> DMap;
0285   DMap dipoles;
0286 
0287   // All excitations.
0288   vector< vector<Particle> > eParticles;
0289 
0290   // Random walk states and their weights.
0291   vector<pair<int, int> > states;
0292   vector<double> weights;
0293 
0294   // Private assignment operator.
0295   Ropewalk& operator=(const Ropewalk) = delete;
0296 
0297 };
0298 
0299 //==================================================================
0300 
0301 // RopeFragPars recalculates fragmentation parameters according to a
0302 // changed string tension. Helper class to FlavourRope.
0303 
0304 class RopeFragPars : public PhysicsBase {
0305 
0306 public:
0307 
0308   // Constructor.
0309   RopeFragPars() : aIn(), adiqIn(), bIn(), rhoIn(), xIn(),
0310     yIn(), xiIn(), sigmaIn(), kappaIn(), aEff(), adiqEff(), bEff(),
0311     rhoEff(), xEff(), yEff(), xiEff(), sigmaEff(), kappaEff(),
0312     beta() {}
0313 
0314   // The init function sets up initial parameters from settings.
0315   bool init();
0316 
0317   // Return parameters at given string tension, ordered by their
0318   // name for easy insertion in settings.
0319   map<string,double> getEffectiveParameters(double h);
0320 
0321 private:
0322 
0323   // Constants: can only be changed in the code itself.
0324   static const double DELTAA, ACONV, ZCUT;
0325 
0326   // Get the Fragmentation function a parameter from cache or calculate it.
0327   double getEffectiveA(double thisb, double mT2, bool isDiquark);
0328 
0329   // Calculate the effective parameters.
0330   bool calculateEffectiveParameters(double h);
0331 
0332   // Insert calculated parameters in cache for later (re-)use.
0333   bool insertEffectiveParameters(double h);
0334 
0335   // Calculate the a parameter.
0336   double aEffective(double aOrig, double thisb, double mT2);
0337 
0338   // The Lund fragmentation function.
0339   double fragf(double z, double a, double b, double mT2);
0340 
0341   // Integral of the Lund fragmentation function with given parameter values.
0342   double integrateFragFun(double a, double b, double mT2);
0343 
0344   // Helper function for integration.
0345   double trapIntegrate(double a, double b, double mT2, double sOld, int n);
0346 
0347   // Parameter caches to re-use calculations. Sets of parameters, ordered in h.
0348   map<double, map<string, double> > parameters;
0349 
0350   // Values of the a-parameter ordered in b*mT2 grid.
0351   map<double, double> aMap;
0352 
0353   // The same for aDiquark.
0354   map<double, double> aDiqMap;
0355 
0356   // Initial values of parameters.
0357   double aIn, adiqIn, bIn, rhoIn, xIn, yIn, xiIn, sigmaIn, kappaIn;
0358 
0359   // Effective values of parameters.
0360   double aEff, adiqEff, bEff, rhoEff, xEff, yEff, xiEff, sigmaEff, kappaEff;
0361 
0362   // Junction parameter.
0363   double beta;
0364 
0365 };
0366 
0367 //==================================================================
0368 
0369 // The FlavourRope class takes care of placing a string breakup in
0370 // the event, and assigning the string breakup effective parameters.
0371 // It is a UserHooks derived class, and one must make sure to add it
0372 // to the UserHooksVector in the main program or somewhere else.
0373 
0374 class FlavourRope : public FragmentationModifierBase {
0375 
0376 public:
0377 
0378   // Constructor.
0379   FlavourRope(Ropewalk & rwIn) : rwPtr(&rwIn), ePtr(), doBuffon(),
0380               rapiditySpan(), stringProtonRatio(), fixedKappa(), h() {}
0381 
0382   // Initialize. Set pointers.
0383   virtual bool init() override {
0384 
0385     // Initialize event pointer such that it can be tested.
0386     ePtr = nullptr;
0387     h = parm("Ropewalk:presetKappa");
0388     fixedKappa = flag("Ropewalk:setFixedKappa");
0389     doBuffon = flag("Ropewalk:doBuffon");
0390     rapiditySpan = parm("Ropewalk:rapiditySpan");
0391     stringProtonRatio = parm("Ropewalk:stringProtonRatio");
0392     // Initialize FragPar.
0393     fp.init();
0394     return true;
0395   }
0396 
0397   // Change the fragmentation parameters.
0398   bool doChangeFragPar(StringFlav* flavPtr, StringZ* zPtr,
0399    StringPT * pTPtr, double m2Had, vector<int> iParton, int endId) override;
0400 
0401   // Set enhancement manually.
0402   void setEnhancement(double hIn) { h = hIn;}
0403 
0404   // Set pointer to the event.
0405   void setEventPtr(Event& event) { ePtr = &event;}
0406 
0407   // Initialise the current event just before string fragmentation
0408   // starts.
0409   virtual bool initEvent(Event& event, ColConfig& colConfig) override;
0410 
0411 protected:
0412 
0413   virtual void onInitInfoPtr() override {
0414     registerSubObject(fp);
0415   }
0416 
0417 private:
0418 
0419   // Find breakup placement and fetch effective parameters.
0420   // For model depending on vertex information.
0421   map<string, double> fetchParameters(double m2Had, vector<int> iParton,
0422     int endId);
0423   // For simple Buffon model.
0424   map<string, double> fetchParametersBuffon(double m2Had, vector<int> iParton,
0425     int endId);
0426 
0427   // Pointer to the ropewalk object.
0428   Ropewalk* rwPtr;
0429 
0430   // Pointer to the event.
0431   Event* ePtr;
0432 
0433   // The object which handles change in parameters.
0434   RopeFragPars fp;
0435 
0436   // Use Buffon prescription without vertex information.
0437   bool doBuffon;
0438 
0439   // Parameters of Buffon prescription
0440   double rapiditySpan, stringProtonRatio;
0441 
0442   // Keep track of hadronized dipoles in Buffon prescription.
0443   vector<int> hadronized;
0444 
0445   // Use preset kappa from settings.
0446   bool fixedKappa;
0447 
0448   // Locally stored string tension.
0449   double h;
0450 
0451 };
0452 
0453 //==========================================================================
0454 
0455 // Interface to RopeWalk via an ShoverBase object.
0456 
0457 class RopewalkShover : public StringRepulsionBase {
0458 
0459 public:
0460 
0461   // RopeWalk is a friend.
0462   friend class RopeWalk;
0463 
0464   // The costructor needs a RopeWalk object be consistent.
0465   RopewalkShover(Ropewalk & rwIn) : rwPtr(&rwIn) {}
0466 
0467   // Empty virtual destructor.
0468   virtual ~RopewalkShover() {};
0469   // Main virtual function, called before the hadronisation.
0470   virtual bool stringRepulsion(Event & event, ColConfig & colConfig);
0471 
0472 private:
0473 
0474   // The Ropewalk object doing all the work.
0475   Ropewalk * rwPtr;
0476 
0477 };
0478 
0479 //==========================================================================
0480 
0481 } // end namespace Pythia8
0482 
0483 #endif // Pythia8_Ropewalk_H