PYTHIA  8.313
HIInfo.h
1 // HIInfo.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2025 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 // This file contains the definition of the HIInfo, EventInfo and
7 // HIUserHooks classes.
8 //
9 // EventInfo: stores full nucleon-nucleon events with corresponding Info.
10 // HIInfo: info about a Heavy Ion run and its produced events.
11 // HIUserHooks: User hooks for HeavyIons models.
12 
13 #ifndef Pythia8_HIInfo_H
14 #define Pythia8_HIInfo_H
15 
16 #include "Pythia8/Pythia.h"
17 #include "Pythia8/HIBasics.h"
18 #include "Pythia8/HISubCollisionModel.h"
19 
20 namespace Pythia8 {
21 
22 //==========================================================================
23 
24 // Class for collecting info about a Heavy Ion run and its produced
25 // events.
26 
27 class HIInfo {
28 
29 public:
30 
31  friend class HeavyIons;
32  friend class Angantyr;
33 
34  // Constructor.
35  HIInfo() = default;
36 
37  // The impact-parameter distance in the current event.
38  double b() const { return bSave; }
39 
40  // The impact parameter angle.
41  double phi() const { return phiSave; }
42 
43  // The summed elastic amplitude.
44  double T() { return TSave; }
45 
46  // The average NN non-diffractive impact parameter to be used to
47  // communicate to Pythia's MPI machinery.
48  double avNDb() const { return avNDbSave; }
49 
50  // The number of attempted impact parameter points.
51  long nAttempts() const { return NSave; }
52 
53  // The number of produced events.
54  long nAccepted() const { return NAccSave; }
55 
56  // The total number of sub-collisions in the event.
57  int nCollTot() const { return nCollSave[0]; }
58 
59  // The number of non-diffractive sub-collisions in the event
60  int nCollND() const { return nCollSave[1]; }
61 
62  // The number of single diffractive projectile excitation
63  // sub-collisions in the event
64  int nCollSDP() const { return nCollSave[2]; }
65 
66  // The number of single diffractive target excitation
67  // sub-collisions in the event
68  int nCollSDT() const { return nCollSave[3]; }
69 
70  // The number of double diffractive sub-collisions in the event
71  int nCollDD() const { return nCollSave[4]; }
72 
73  // The number of central diffractive sub-collisions in the event
74  int nCollCD() const { return nCollSave[5]; }
75 
76  // The number of elastic sub-collisions in the event
77  int nCollEl() const { return nCollSave[6]; }
78 
79  // The total number of interacting projectile nucleons in the event.
80  int nPartProj() const { return nProjSave[0]; }
81 
82  // The number of absorptively wounded projectile nucleons in the event.
83  int nAbsProj() const { return nProjSave[1]; }
84 
85  // The number of diffractively wounded projectile nucleons in the event.
86  int nDiffProj() const { return nProjSave[2]; }
87 
88  // The number of elastically scattered target nucleons in the event.
89  int nElProj() const { return nProjSave[3]; }
90 
91  // The total number of interacting target nucleons in the event.
92  int nPartTarg() const { return nTargSave[0]; }
93 
94  // The number of absorptively wounded target nucleons in the event.
95  int nAbsTarg() const { return nTargSave[1]; }
96 
97  // The number of diffractively wounded target nucleons in the event.
98  int nDiffTarg() const { return nTargSave[2]; }
99 
100  // The number of elastically scattered target nucleons in the event.
101  int nElTarg() const { return nTargSave[3]; }
102 
103  // The weight for this collision.
104  double weight() const { return weightSave; }
105 
106  // The sum of weights of the produced events.
107  double weightSum() const { return weightSumSave; }
108 
109  // The number of failed nucleon excitations in the current event.
110  int nFail() const {
111  return nFailSave;
112  }
113 
114  // Register a failed nucleon excitation.
115  void failedExcitation(const SubCollision& subColl) {
116  subColl.failed = true;
117  ++nFailSave;
118  }
119 
120  // The total cross section from the Glauber calculation.
121  double glauberTot() const {
122  return sigmaTotSave*FMSQ2MB;
123  }
124 
125  // The error on the total cross section from the Glauber
126  // calculation.
127  double glauberTotErr() const {
128  return sqrt(sigErr2TotSave/max(1.0, double(NSave)))*FMSQ2MB;
129  }
130 
131  // The non-diffractive cross section from the Glauber calculation.
132  double glauberND() const {
133  return sigmaNDSave*FMSQ2MB;
134  }
135 
136  // The error on the non-diffractive cross section from the Glauber
137  // calculation.
138  double glauberNDErr() const {
139  return sqrt(sigErr2NDSave/max(1.0, double(NSave)))*FMSQ2MB;
140  }
141 
142  // The total inelastic cross section from the Glauber calculation.
143  double glauberINEL() const {
144  return sigmaINELSave*FMSQ2MB;
145  }
146 
147  // The error on the total inelastic cross section from the Glauber
148  // calculation.
149  double glauberINELErr() const {
150  return sqrt(sigErr2INELSave/max(1.0, double(NSave)))*FMSQ2MB;
151  }
152 
153  // The elastic cross section from the Glauber calculation.
154  double glauberEL() const {
155  return sigmaELSave*FMSQ2MB;
156  }
157 
158  // The error on the elastic cross section from the Glauber
159  // calculation.
160  double glauberELErr() const {
161  return sqrt(sigErr2ELSave/max(1.0, double(NSave)))*FMSQ2MB;
162  }
163 
164  // The diffractive taget excitation cross section from the Glauber
165  // calculation.
166  double glauberDiffT() const {
167  return sigmaDiffTSave*FMSQ2MB;
168  }
169 
170  // The error on the diffractive taget excitation cross section from the
171  // Glauber calculation.
172  double glauberDiffTErr() const {
173  return sqrt(sigErr2DiffTSave/max(1.0, double(NSave)))*FMSQ2MB;
174  }
175 
176  // The diffractive projectile excitation cross section from the Glauber
177  // calculation.
178  double glauberDiffP() const {
179  return sigmaDiffPSave*FMSQ2MB;
180  }
181 
182  // The error on the diffractive projectile excitation cross section
183  // from the Glauber calculation.
184  double glauberDiffPErr() const {
185  return sqrt(sigErr2DiffPSave/max(1.0, double(NSave)))*FMSQ2MB;
186  }
187 
188  // The doubly diffractive excitation cross section from the Glauber
189  // calculation.
190  double glauberDDiff() const {
191  return sigmaDDiffSave*FMSQ2MB;
192  }
193 
194  // The error on the doubly diffractive excitation cross section from
195  // the Glauber calculation.
196  double glauberDDiffErr() const {
197  return sqrt(sigErr2DDiffSave/max(1.0, double(NSave)))*FMSQ2MB;
198  }
199 
200  // The elastic slope parameter.
201  double glauberBSlope() const {
202  return slopeSave/(sigmaTotSave*pow2(HBARC));
203  }
204 
205  // The error on the elastic slope parameter.
206  double glauberBSlopeErr() const {
207  return sqrt((slopeErrSave/pow2(slopeSave) +
208  sigErr2TotSave/pow2(sigmaTotSave))/max(1.0, double(NSave)))*
209  glauberBSlope();
210  }
211 
212 private:
213 
214  // Register a tried impact parameter point giving the total elastic
215  // amplitude, the impact parameter and impact parameter generation
216  // weight, together with the cross section scale.
217  void addAttempt(double T, double bin, double phiin,
218  double bweight, double xSecScale);
219 
220  // Reweight event for whatever reason.
221  void reweight(double w) {
222  weightSave *= w;
223  }
224 
225  // Select the primary process.
226  void select(Info & in) {
227  primInfo = in;
228  primInfo.hiInfo = this;
229  }
230 
231  // Accept an event and update statistics in info.
232  void accept();
233 
234  // Reject an attmpted event.
235  void reject() {}
236 
237  // Register Glauber statistics of the event.
238  void glauberStatistics();
239 
240  // Collect running averages for Glauber cross section:
241  static void runAvg(double & sig, double & sigErr2, double N,
242  double w) {
243  double delta = w - sig;
244  sig += delta/N;
245  sigErr2 += (delta*(w - sig) - sigErr2)/N;
246  }
247 
248  // Id of the colliding nuclei.
249  int idProjSave = 0, idTargSave = 0;
250 
251  // Impact parameter.
252  double bSave = 0.0;
253  double phiSave = 0.0;
254 
255  // Amplitude, attempts and weight.
256  long NSave = 0, NAccSave = 0;
257  double TSave = 0.0;
258  // OBS: Cross sections should be accessed through the main info class.
259  double sigmaTotSave = {}, sigmaNDSave = {},
260  sigmaELSave = {}, sigmaINELSave = {},
261  sigmaDiffPSave = {}, sigmaDiffTSave = {}, sigmaDDiffSave = {},
262  slopeSave ={};
263  double sigErr2TotSave = {}, sigErr2NDSave = {},
264  sigErr2ELSave = {}, sigErr2INELSave = {},
265  sigErr2DiffPSave = {}, sigErr2DiffTSave = {}, sigErr2DDiffSave = {},
266  slopeErrSave ={};
267  double avNDbSave = {};
268  double weightSave = {}, weightSumSave = {}, xSecScaleSave = {};
269 
270  // Number of collisions and paricipants. See accessor functions for
271  // indices.
272  vector<int> nCollSave{}, nProjSave{}, nTargSave{};
273 
274  // Map of primary processes and the number of events and the sum of
275  // weights.
276  map<int,double> sumPrimW{}, sumPrimW2{};
277  map<int,int> NPrim{};
278  map<int,string> NamePrim{};
279 
280  // The info object of the primary process.
281  Info primInfo{};
282 
283  // Number of failed nucleon excitations.
284  int nFailSave = 0;
285 
286 public:
287 
288  // Access to subcollision to be extracted by the user.
289  const SubCollisionSet* subCollisionsPtr() { return subCollisionsPtrSave; }
290 
291 private:
292 
293  // Set the subcollision pointer.
294  void setSubCollisions(const SubCollisionSet* subCollisionsPtrIn) {
295  subCollisionsPtrSave = subCollisionsPtrIn; }
296 
297  // Full information about the Glauber calculation, consisting of
298  // all subcollisions.
299  const SubCollisionSet* subCollisionsPtrSave{};
300 
301 };
302 
303 //==========================================================================
304 
305 // This is the heavy ion user hooks class which in the future may be
306 // used inside a Pythia object to generate heavy ion collisons. For
307 // now it is used outside Pythia and requires access to a number of
308 // Pythia objects.
309 
310 class HIUserHooks {
311 
312 public:
313 
314  // The default constructor is empty.
315  HIUserHooks(): idProjSave(0), idTargSave(0) {}
316 
317  // Virtual destructor.
318  virtual ~HIUserHooks() {}
319 
320  // Initialize this user hook.
321  virtual void init(int idProjIn, int idTargIn) {
322  idProjSave = idProjIn;
323  idTargSave = idTargIn;
324  }
325 
326  // A user-supplied impact parameter generator.
327  virtual bool hasImpactParameterGenerator() const { return false; }
328  virtual shared_ptr<ImpactParameterGenerator> impactParameterGenerator()
329  const { return nullptr; }
330 
331  // A user-supplied NucleusModel for the projectile and target.
332  virtual bool hasProjectileModel() const { return false; }
333  virtual shared_ptr<NucleusModel> projectileModel() const { return nullptr; }
334  virtual bool hasTargetModel() const { return false; }
335  virtual shared_ptr<NucleusModel> targetModel() const { return nullptr; }
336 
337  // A user-supplied SubCollisionModel for generating nucleon-nucleon
338  // subcollisions.
339  virtual bool hasSubCollisionModel() { return false; }
340  virtual shared_ptr<SubCollisionModel> subCollisionModel() { return nullptr; }
341 
342  // A user-supplied ordering of events in (inverse) hardness.
343  virtual bool hasEventOrdering() const { return false; }
344  virtual double eventOrdering(const Event &, const Info &) { return -1; }
345 
346  // A user-supplied method for fixing up proton-neutron mismatch in
347  // generated beams.
348  virtual bool canFixIsoSpin() const { return false; }
349  virtual bool fixIsoSpin(EventInfo &) { return false; }
350 
351  // A user-supplied method for shifting the event in impact parameter space.
352  virtual bool canShiftEvent() const { return false; }
353  virtual EventInfo & shiftEvent(EventInfo & ei) const { return ei; }
354 
355  // A user-supplied method of adding a diffractive excitation event
356  // to another event, optionally connecting their colours.
357  bool canAddNucleonExcitation() const { return false; }
358  bool addNucleonExcitation(EventInfo &, EventInfo &, bool) const {
359  return false; }
360 
361  // A user supplied wrapper around the Pythia::forceHadronLevel()
362  virtual bool canForceHadronLevel() const { return false; }
363  virtual bool forceHadronLevel(Pythia &) { return false; }
364 
365  // A user-supplied way of finding the remnants of an
366  // non-diffrcative pp collision (on the target side if tside is
367  // true) to be used to give momentum when adding.
368  virtual bool canFindRecoilers() const { return false; }
369  virtual vector<int>
370  findRecoilers(const Event &, bool /* tside */, int /* beam */, int /* end */,
371  const Vec4 & /* pdiff */, const Vec4 & /* pbeam */) const {
372  return vector<int>();
373  }
374 
375 protected:
376 
377  // Information set in the init() function.
378  // The PDG id of the projectile and target nuclei.
379  int idProjSave, idTargSave;
380 
381 };
382 
383 //==========================================================================
384 
385 } // end namespace Pythia8
386 
387 #endif // Pythia8_HIInfo_H
double glauberTot() const
The total cross section from the Glauber calculation.
Definition: HIInfo.h:121
int nCollSDP() const
Definition: HIInfo.h:64
constexpr double pow2(const double &x)
Powers of small integers - for balance speed/code clarity.
Definition: PythiaStdlib.h:182
virtual void init(int idProjIn, int idTargIn)
Initialize this user hook.
Definition: HIInfo.h:321
bool canAddNucleonExcitation() const
Definition: HIInfo.h:357
virtual bool canFindRecoilers() const
Definition: HIInfo.h:368
long nAttempts() const
The number of attempted impact parameter points.
Definition: HIInfo.h:51
double weight() const
The weight for this collision.
Definition: HIInfo.h:104
int nElProj() const
The number of elastically scattered target nucleons in the event.
Definition: HIInfo.h:89
bool failed
Whether the subcollision failed, i.e. has a failed excitation.
Definition: HISubCollisionModel.h:80
int nFail() const
The number of failed nucleon excitations in the current event.
Definition: HIInfo.h:110
virtual bool canShiftEvent() const
A user-supplied method for shifting the event in impact parameter space.
Definition: HIInfo.h:352
int nCollND() const
The number of non-diffractive sub-collisions in the event.
Definition: HIInfo.h:60
double glauberDiffTErr() const
Definition: HIInfo.h:172
Definition: Info.h:45
The Event class holds all info on the generated event.
Definition: Event.h:408
double glauberBSlopeErr() const
The error on the elastic slope parameter.
Definition: HIInfo.h:206
double glauberND() const
The non-diffractive cross section from the Glauber calculation.
Definition: HIInfo.h:132
double b() const
The impact-parameter distance in the current event.
Definition: HIInfo.h:38
int nCollCD() const
The number of central diffractive sub-collisions in the event.
Definition: HIInfo.h:74
int nElTarg() const
The number of elastically scattered target nucleons in the event.
Definition: HIInfo.h:101
double glauberINELErr() const
Definition: HIInfo.h:149
int nPartTarg() const
The total number of interacting target nucleons in the event.
Definition: HIInfo.h:92
double T()
The summed elastic amplitude.
Definition: HIInfo.h:44
virtual ~HIUserHooks()
Virtual destructor.
Definition: HIInfo.h:318
double glauberDiffP() const
Definition: HIInfo.h:178
The SubCollisionSet gives a set of subcollisions between two nuclei.
Definition: HISubCollisionModel.h:88
Definition: HIInfo.h:310
double weightSum() const
The sum of weights of the produced events.
Definition: HIInfo.h:107
virtual bool hasSubCollisionModel()
Definition: HIInfo.h:339
virtual bool hasImpactParameterGenerator() const
A user-supplied impact parameter generator.
Definition: HIInfo.h:327
constexpr double HBARC
Define conversion hbar * c = 0.2 GeV * fm = 1 and related.
Definition: PythiaStdlib.h:154
const SubCollisionSet * subCollisionsPtr()
Access to subcollision to be extracted by the user.
Definition: HIInfo.h:289
double glauberDiffT() const
Definition: HIInfo.h:166
int nPartProj() const
The total number of interacting projectile nucleons in the event.
Definition: HIInfo.h:80
HIInfo * hiInfo
Definition: Info.h:113
double glauberEL() const
The elastic cross section from the Glauber calculation.
Definition: HIInfo.h:154
int nCollEl() const
The number of elastic sub-collisions in the event.
Definition: HIInfo.h:77
double glauberDDiffErr() const
Definition: HIInfo.h:196
double glauberBSlope() const
The elastic slope parameter.
Definition: HIInfo.h:201
double glauberDiffPErr() const
Definition: HIInfo.h:184
int nCollDD() const
The number of double diffractive sub-collisions in the event.
Definition: HIInfo.h:71
Definition: HISubCollisionModel.h:30
double glauberINEL() const
The total inelastic cross section from the Glauber calculation.
Definition: HIInfo.h:143
virtual bool hasProjectileModel() const
A user-supplied NucleusModel for the projectile and target.
Definition: HIInfo.h:332
void failedExcitation(const SubCollision &subColl)
Register a failed nucleon excitation.
Definition: HIInfo.h:115
HIUserHooks()
The default constructor is empty.
Definition: HIInfo.h:315
double glauberNDErr() const
Definition: HIInfo.h:138
Class for storing Events and Info objects.
Definition: HIBasics.h:25
int idProjSave
Definition: HIInfo.h:379
int nAbsTarg() const
The number of absorptively wounded target nucleons in the event.
Definition: HIInfo.h:95
int nAbsProj() const
The number of absorptively wounded projectile nucleons in the event.
Definition: HIInfo.h:83
HIInfo()=default
Constructor.
constexpr double FMSQ2MB
Define conversion between fm^2 and mb, in both directions.
Definition: PythiaStdlib.h:178
virtual bool canFixIsoSpin() const
Definition: HIInfo.h:348
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
The Pythia class contains the top-level routines to generate an event.
Definition: Pythia.h:71
int nCollSDT() const
Definition: HIInfo.h:68
int nDiffTarg() const
The number of diffractively wounded target nucleons in the event.
Definition: HIInfo.h:98
double glauberDDiff() const
Definition: HIInfo.h:190
double glauberELErr() const
Definition: HIInfo.h:160
double avNDb() const
Definition: HIInfo.h:48
virtual bool canForceHadronLevel() const
A user supplied wrapper around the Pythia::forceHadronLevel()
Definition: HIInfo.h:362
virtual bool hasEventOrdering() const
A user-supplied ordering of events in (inverse) hardness.
Definition: HIInfo.h:343
int nDiffProj() const
The number of diffractively wounded projectile nucleons in the event.
Definition: HIInfo.h:86
double glauberTotErr() const
Definition: HIInfo.h:127
double phi() const
The impact parameter angle.
Definition: HIInfo.h:41
Definition: HeavyIons.h:31
Definition: Basics.h:32
The default HeavyIon model in Pythia.
Definition: HeavyIons.h:162
Definition: HIInfo.h:27
long nAccepted() const
The number of produced events.
Definition: HIInfo.h:54
int nCollTot() const
The total number of sub-collisions in the event.
Definition: HIInfo.h:57