HepMC3 event record library
GenHeavyIon.cc
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6/**
7 * @file GenHeavyIon.cc
8 * @brief Implementation of \b class GenHeavyIon
9 *
10 */
11#include <cstdio> // sprintf
12#include <cstdlib> // atoi
13#include <cstring> // memcmp
14#include <sstream> // sprintf
15
16#include "HepMC3/GenHeavyIon.h"
17
18namespace HepMC3 {
19
20bool GenHeavyIon::from_string(const std::string &att) {
21/// If HEPMC3_NO_DEPRECATED is not defined, those are member variables.
22#ifdef HEPMC3_NO_DEPRECATED
24#endif
25
26 std::istringstream is(att);
27 std::string version;
28
29 if ( att[0] != 'v' ) {
35 >> centrality;
36 return !is.fail();
37 }
38 is >> version;
39
40
41
43 if ( version == "v0" ) is >> spectator_neutrons >> spectator_protons;
47 if ( version == "v0" ) is >> eccentricity;
49 if ( version != "v0" ) is >> user_cent_estimate;
51
52 int N=0;
53 int ord=0;
54 is >> N;
55 for ( int i = 0; i < N; ++i ) {
56 is >> ord;
57 is >> participant_plane_angles[ord];
58 }
59 is >> N;
60 for ( int i = 0; i < N; ++i ) {
61 is >> ord;
62 is >> eccentricities[ord];
63 }
64
65 return !is.fail();
66}
67
68bool GenHeavyIon::to_string(std::string &att) const {
69 std::ostringstream os;
70
71#ifndef HEPMC3_NO_DEPRECATED
72 if ( !forceoldformat ) os << "v0 ";
73#else
74 os << "v1 ";
75#endif
76
77 os << std::setprecision(8)
78 << Ncoll_hard << " " << Npart_proj << " "
79 << Npart_targ << " " << Ncoll << " "
80#ifndef HEPMC3_NO_DEPRECATED
81 << spectator_neutrons << " " << spectator_protons << " "
82#endif
85 << event_plane_angle << " "
86#ifndef HEPMC3_NO_DEPRECATED
87 << eccentricity << " "
88#endif
89 << sigma_inel_NN << " " << centrality << " " << user_cent_estimate << " "
90 << Nspec_proj_n << " " << Nspec_targ_n << " "
91 << Nspec_proj_p << " " << Nspec_targ_p << " ";
92
93 os << participant_plane_angles.size();
94 for (const auto& it: participant_plane_angles) {
95 os << " " << it.first << " " << it.second;
96 }
97 os << " " << eccentricities.size();
98 for (const auto& it: eccentricities) {
99 os << " " << it.first << " " << it.second;
100 }
101 att = os.str();
102
103 return true;
104}
105
106
107#ifndef HEPMC3_NO_DEPRECATED
108
110 return ( memcmp( (void*) this, (void*) &a, sizeof(class GenHeavyIon) ) == 0 );
111}
112
114 return !( a == *this );
115}
116
117void GenHeavyIon::set(const int&nh, const int&np, const int&nt, const int&nc, const int&ns, const int&nsp,
118 const int&nnw, const int&nwn, const int&nwnw,
119 const double& im, const double& pl, const double& ec, const double& s, const double& cent, const double& usrcent) {
120 Ncoll_hard = nh;
121 Npart_proj = np;
122 Npart_targ = nt;
123 Ncoll = nc;
125 spectator_protons = nsp;
129 impact_parameter = im;
131 eccentricity = ec;
132 sigma_inel_NN = s;
133 centrality = cent;
134 user_cent_estimate = usrcent;
135}
136
138 if ( Ncoll_hard != 0 ) { return true; }
139 if ( Npart_proj != 0 ) { return true; }
140 if ( Npart_targ != 0 ) { return true; }
141 if ( Ncoll != 0 ) { return true; }
142 if ( spectator_neutrons != 0 ) { return true; }
143 if ( spectator_protons != 0 ) { return true; }
144 if ( N_Nwounded_collisions != 0 ) { return true; }
145 if ( Nwounded_N_collisions != 0 ) { return true; }
146 if ( Nwounded_Nwounded_collisions != 0 ) { return true; }
147 if ( impact_parameter != 0 ) { return true; }
148 if ( event_plane_angle != 0 ) { return true; }
149 if ( eccentricity != 0 ) { return true; }
150 if ( sigma_inel_NN != 0 ) { return true; }
151 if ( centrality != 0 ) { return true; }
152 return false;
153}
154
155#endif
156
157} // namespace HepMC3
Definition of attribute class GenHeavyIon.
Stores additional information about Heavy Ion generator.
Definition: GenHeavyIon.h:26
int Nspec_targ_p
The number of spectator protons in the target.
Definition: GenHeavyIon.h:186
int Nwounded_Nwounded_collisions
Non-diffractive or doubly diffractive collisions.
Definition: GenHeavyIon.h:113
int Nwounded_N_collisions
Collisions with a diffractively excited projectile nucleon.
Definition: GenHeavyIon.h:106
int Nspec_proj_n
The number of spectator neutrons in the projectile.
Definition: GenHeavyIon.h:165
double impact_parameter
The impact parameter.
Definition: GenHeavyIon.h:119
bool forceoldformat
force writing in old format for compatibility purposes.
Definition: GenHeavyIon.h:237
std::map< int, double > eccentricities
Eccentricities.
Definition: GenHeavyIon.h:199
int Nspec_proj_p
The number of spectator protons in the projectile.
Definition: GenHeavyIon.h:179
double event_plane_angle
The event plane angle.
Definition: GenHeavyIon.h:127
std::map< int, double > participant_plane_angles
Participant plane angles.
Definition: GenHeavyIon.h:193
int Npart_proj
the number of participating nucleons in the projectile.
Definition: GenHeavyIon.h:64
bool operator==(const GenHeavyIon &) const
Operator ==.
Definition: GenHeavyIon.cc:109
double eccentricity
The eccentricity.
Definition: GenHeavyIon.h:133
double user_cent_estimate
A user defined centrality estimator.
Definition: GenHeavyIon.h:157
int spectator_protons
Total number of spectator protons.
Definition: GenHeavyIon.h:91
int N_Nwounded_collisions
Collisions with a diffractively excited target nucleon.
Definition: GenHeavyIon.h:99
double centrality
The centrality.
Definition: GenHeavyIon.h:148
bool is_valid() const
Verify that the instance contains non-zero information.
Definition: GenHeavyIon.cc:137
int Nspec_targ_n
The number of spectator neutrons in the target.
Definition: GenHeavyIon.h:172
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
Definition: GenHeavyIon.cc:20
int Ncoll_hard
the number of hard nucleon-nucleon collisions.
Definition: GenHeavyIon.h:57
void set(const int &nh, const int &np, const int &nt, const int &nc, const int &ns, const int &nsp, const int &nnw=0, const int &nwn=0, const int &nwnw=0, const double &im=0., const double &pl=0., const double &ec=0., const double &s=0., const double &cent=0., const double &usrcent=0.)
Set all fields.
Definition: GenHeavyIon.cc:117
bool operator!=(const GenHeavyIon &) const
Operator !=.
Definition: GenHeavyIon.cc:113
int Ncoll
the number of inelastic nucleon-nucleon collisions.
Definition: GenHeavyIon.h:80
int Npart_targ
the number of participating nucleons in the target.
Definition: GenHeavyIon.h:71
int spectator_neutrons
Total number of spectator neutrons.
Definition: GenHeavyIon.h:86
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Definition: GenHeavyIon.cc:68
double sigma_inel_NN
The assumed inelastic nucleon-nucleon cross section.
Definition: GenHeavyIon.h:141
HepMC3 main namespace.
std::string version()
Get the HepMC library version string.
Definition: Version.h:20