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-2021 The HepMC collaboration (see AUTHORS for details)
5//
6/**
7 * @file GenHeavyIon.cc
8 * @brief Implementation of \b class GenHeavyIon
9 *
10 */
11#include <cstring> // memcmp
12#include <cstdlib> // atoi
13#include <cstdio> // sprintf
14#include <sstream> // sprintf
15
16#include "HepMC3/GenHeavyIon.h"
17
18namespace HepMC3 {
19
20bool GenHeavyIon::from_string(const std::string &att) {
21#ifdef HEPMC3_NO_DEPRECATED
23#endif
24
25 std::istringstream is(att);
26 std::string version;
27
28 if ( att[0] != 'v' ) {
34 >> centrality;
35 return !is.fail();
36 } else
37 is >> version;
38
39
40
42 if ( version == "v0" ) is >> spectator_neutrons >> spectator_protons;
46 if ( version == "v0" ) is >> eccentricity;
48 if ( version != "v0" ) is >> user_cent_estimate;
50
51 int N, ord;
52 is >> N;
53 for ( int i = 0; i < N; ++i ) {
54 is >> ord;
55 is >> participant_plane_angles[ord];
56 }
57 is >> N;
58 for ( int i = 0; i < N; ++i ) {
59 is >> ord;
60 is >> eccentricities[ord];
61 }
62
63 return !is.fail();
64}
65
66bool GenHeavyIon::to_string(std::string &att) const {
67 std::ostringstream os;
68
69#ifndef HEPMC3_NO_DEPRECATED
70 if ( !forceoldformat ) os << "v0 ";
71#else
72 os << "v1 ";
73#endif
74
75 os << std::setprecision(8)
76 << Ncoll_hard << " " << Npart_proj << " "
77 << Npart_targ << " " << Ncoll << " "
78#ifndef HEPMC3_NO_DEPRECATED
79 << spectator_neutrons << " " << spectator_protons << " "
80#endif
83 << event_plane_angle << " "
84#ifndef HEPMC3_NO_DEPRECATED
85 << eccentricity << " "
86#endif
87 << sigma_inel_NN << " " << centrality << " " << user_cent_estimate << " "
88 << Nspec_proj_n << " " << Nspec_targ_n << " "
89 << Nspec_proj_p << " " << Nspec_targ_p << " ";
90
91 os << participant_plane_angles.size();
92 for ( std::map<int, double>::const_iterator it = participant_plane_angles.begin();
93 it != participant_plane_angles.end(); ++it )
94 os << " " << it->first << " " << it->second;
95
96 os << " " << eccentricities.size();
97 for ( std::map<int, double>::const_iterator it = eccentricities.begin();
98 it != eccentricities.end(); ++it )
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:28
int Nspec_targ_p
The number of spectator protons in the target.
Definition: GenHeavyIon.h:188
int Nwounded_Nwounded_collisions
Non-diffractive or doubly diffractive collisions.
Definition: GenHeavyIon.h:115
int Nwounded_N_collisions
Collisions with a diffractively excited projectile nucleon.
Definition: GenHeavyIon.h:108
int Nspec_proj_n
The number of spectator neutrons in the projectile.
Definition: GenHeavyIon.h:167
double impact_parameter
The impact parameter.
Definition: GenHeavyIon.h:121
bool forceoldformat
force writing in old format for compatibility purposes.
Definition: GenHeavyIon.h:240
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 &ucent=0.)
Set all fields.
Definition: GenHeavyIon.cc:117
std::map< int, double > eccentricities
Eccentricities.
Definition: GenHeavyIon.h:201
int Nspec_proj_p
The number of spectator protons in the projectile.
Definition: GenHeavyIon.h:181
double event_plane_angle
The event plane angle.
Definition: GenHeavyIon.h:129
std::map< int, double > participant_plane_angles
Participant plane angles.
Definition: GenHeavyIon.h:195
int Npart_proj
the number of participating nucleons in the projectile.
Definition: GenHeavyIon.h:66
bool operator==(const GenHeavyIon &) const
Operator ==.
Definition: GenHeavyIon.cc:109
double eccentricity
The eccentricity.
Definition: GenHeavyIon.h:135
double user_cent_estimate
A user defined centrality estimator.
Definition: GenHeavyIon.h:159
int spectator_protons
Total number of spectator protons.
Definition: GenHeavyIon.h:93
int N_Nwounded_collisions
Collisions with a diffractively excited target nucleon.
Definition: GenHeavyIon.h:101
double centrality
The centrality.
Definition: GenHeavyIon.h:150
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:174
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:59
bool operator!=(const GenHeavyIon &) const
Operator !=.
Definition: GenHeavyIon.cc:113
int Ncoll
the number of inelastic nucleon-nucleon collisions.
Definition: GenHeavyIon.h:82
int Npart_targ
the number of participating nucleons in the target.
Definition: GenHeavyIon.h:73
int spectator_neutrons
Total number of spectator neutrons.
Definition: GenHeavyIon.h:88
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Definition: GenHeavyIon.cc:66
double sigma_inel_NN
The assumed inelastic nucleon-nucleon cross section.
Definition: GenHeavyIon.h:143
HepMC3 main namespace.
std::string version()
Get the HepMC library version string.
Definition: Version.h:20