StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BeamShape.cc
1 // BeamShape.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // Function definitions (not found in the header) for the BeamShape class.
7 
8 #include "Pythia8/BeamShape.h"
9 
10 namespace Pythia8 {
11 
12 //==========================================================================
13 
14 // The BeamShape class.
15 
16 //--------------------------------------------------------------------------
17 
18 // Initialize beam parameters.
19 
20  void BeamShape::init( Settings& settings, Rndm* rndmPtrIn) {
21 
22  // Save pointer.
23  rndmPtr = rndmPtrIn;
24 
25  // Main flags.
26  allowMomentumSpread = settings.flag("Beams:allowMomentumSpread");
27  allowVertexSpread = settings.flag("Beams:allowVertexSpread");
28  if (settings.flag("Beams:allowVariableEnergy")) allowMomentumSpread = false;
29 
30  // Parameters for beam A momentum spread.
31  sigmaPxA = settings.parm("Beams:sigmaPxA");
32  sigmaPyA = settings.parm("Beams:sigmaPyA");
33  sigmaPzA = settings.parm("Beams:sigmaPzA");
34  maxDevA = settings.parm("Beams:maxDevA");
35 
36  // Parameters for beam B momentum spread.
37  sigmaPxB = settings.parm("Beams:sigmaPxB");
38  sigmaPyB = settings.parm("Beams:sigmaPyB");
39  sigmaPzB = settings.parm("Beams:sigmaPzB");
40  maxDevB = settings.parm("Beams:maxDevB");
41 
42  // Parameters for beam vertex spread.
43  sigmaVertexX = settings.parm("Beams:sigmaVertexX");
44  sigmaVertexY = settings.parm("Beams:sigmaVertexY");
45  sigmaVertexZ = settings.parm("Beams:sigmaVertexZ");
46  maxDevVertex = settings.parm("Beams:maxDevVertex");
47  sigmaTime = settings.parm("Beams:sigmaTime");
48  maxDevTime = settings.parm("Beams:maxDevTime");
49 
50  // Parameters for beam vertex offset.
51  offsetX = settings.parm("Beams:offsetVertexX");
52  offsetY = settings.parm("Beams:offsetVertexY");
53  offsetZ = settings.parm("Beams:offsetVertexZ");
54  offsetT = settings.parm("Beams:offsetTime");
55 
56 }
57 
58 //--------------------------------------------------------------------------
59 
60 // Set the two beam momentum deviations and the beam vertex.
61 
62 void BeamShape::pick() {
63 
64  // Reset all values.
65  deltaPxA = deltaPyA = deltaPzA = deltaPxB = deltaPyB = deltaPzB
66  = vertexX = vertexY = vertexZ = vertexT = 0.;
67 
68  // Set beam A momentum deviation by a three-dimensional Gaussian.
69  if (allowMomentumSpread) {
70  double totalDev, gauss;
71  do {
72  totalDev = 0.;
73  if (sigmaPxA > 0.) {
74  gauss = rndmPtr->gauss();
75  deltaPxA = sigmaPxA * gauss;
76  totalDev += gauss * gauss;
77  }
78  if (sigmaPyA > 0.) {
79  gauss = rndmPtr->gauss();
80  deltaPyA = sigmaPyA * gauss;
81  totalDev += gauss * gauss;
82  }
83  if (sigmaPzA > 0.) {
84  gauss = rndmPtr->gauss();
85  deltaPzA = sigmaPzA * gauss;
86  totalDev += gauss * gauss;
87  }
88  } while (totalDev > maxDevA * maxDevA);
89 
90  // Set beam B momentum deviation by a three-dimensional Gaussian.
91  do {
92  totalDev = 0.;
93  if (sigmaPxB > 0.) {
94  gauss = rndmPtr->gauss();
95  deltaPxB = sigmaPxB * gauss;
96  totalDev += gauss * gauss;
97  }
98  if (sigmaPyB > 0.) {
99  gauss = rndmPtr->gauss();
100  deltaPyB = sigmaPyB * gauss;
101  totalDev += gauss * gauss;
102  }
103  if (sigmaPzB > 0.) {
104  gauss = rndmPtr->gauss();
105  deltaPzB = sigmaPzB * gauss;
106  totalDev += gauss * gauss;
107  }
108  } while (totalDev > maxDevB * maxDevB);
109  }
110 
111  // Set beam vertex location by a three-dimensional Gaussian.
112  if (allowVertexSpread) {
113  double totalDev, gauss;
114  do {
115  totalDev = 0.;
116  if (sigmaVertexX > 0.) {
117  gauss = rndmPtr->gauss();
118  vertexX = sigmaVertexX * gauss;
119  totalDev += gauss * gauss;
120  }
121  if (sigmaVertexY > 0.) {
122  gauss = rndmPtr->gauss();
123  vertexY = sigmaVertexY * gauss;
124  totalDev += gauss * gauss;
125  }
126  if (sigmaVertexZ > 0.) {
127  gauss = rndmPtr->gauss();
128  vertexZ = sigmaVertexZ * gauss;
129  totalDev += gauss * gauss;
130  }
131  } while (totalDev > maxDevVertex * maxDevVertex);
132 
133  // Set beam collision time by a Gaussian.
134  if (sigmaTime > 0.) {
135  do gauss = rndmPtr->gauss();
136  while (abs(gauss) > maxDevTime);
137  vertexT = sigmaTime * gauss;
138  }
139 
140  // Add offset to beam vertex.
141  vertexX += offsetX;
142  vertexY += offsetY;
143  vertexZ += offsetZ;
144  vertexT += offsetT;
145  }
146 
147 }
148 
149 //==========================================================================
150 
151 } // end namespace Pythia8