## Beam Shape

The Beam Parameters page explains how you can set a momentum spread of the two incoming beams, and a spread and offset for the location of the interaction vertex. The spread is based on a simple parametrization in terms of independent Gaussians, however, which is likely to be too primitive for realistic applications.

It is therefore possible to define your own class, derived from the `BeamShape` base class, and hand it in to Pythia with the `pythia.setBeamShapePtr( BeamShape*)` method. Below we describe what such a class has to do. An explicit toy example is shown in `main23.cc`.

The `BeamShape` base class has a very simple structure. It only has two main virtual methods. The first, `init()`, is used for initialization. The second, `pick()`, selects beam momentum and production vertex in the current event.

BeamShape::BeamShape()
virtual BeamShape::~BeamShape()
the constructor and destructor do not need to do anything.

virtual void BeamShape::init( Settings& settings, Rndm* rndmPtrIn)
the base-class method simply reads in the relevant values stored in the `Settings` data base, and saves a pointer to the random-number generator. You are free to write your own derived initialization routine, or use the existing one. In the latter case you can then give your own modified interpretation to the beam spread parameters defined there.
The two flags `Beams:allowMomentumSpread` and `Beams:allowVertexSpread` should not be tampered with, however. These are checked elsewhere to determine whether the beam shape should be set or not, whereas the other momentum-spread and vertex-spread parameters are local to this class.

virtual void BeamShape::pick()
this method is the key one to supply in the derived class. Here you are free to pick whatever parametrization you desire for beam momenta and vertex position, including correlations between the two. At the end of the day, you should set a few protected `double` numbers:
`deltaPxA, deltaPyA, deltaPzA` for the three-momentum shift of the first incoming beam, relative to the nominal values;
`deltaPxB, deltaPyB, deltaPzB` for the three-momentum shift of the second incoming beam, relative to the nominal values;
`vertexX, vertexY, vertexZ, vertexT` for the production-vertex position and time.
As usual, momentum is given in GeV, and space and time in mm, with c = 1.

Vec4 BeamShape::deltaPA()
Vec4 BeamShape::deltaPB()
read out the three-momentum shifts for beams A and B that were set by `pick()`. The energy components are put to zero at this stage, since they are most conveniently calculated after the original and the shift three-momenta have been added.

Vec4 BeamShape::vertex()
read out the production-vertex position and time that were set by `pick()`.