HepMC3 event record library: GenHeavyIon.cc Source File

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
20 bool GenHeavyIon::from_string(const std::string &att) {
21/// If HEPMC3_NO_DEPRECATED is not defined, those are member variables.
22#ifdef HEPMC3_NO_DEPRECATED
23 double spectator_neutrons, spectator_protons, eccentricity;
24#endif
25
26 std::istringstream is(att);
27 std::string version;
28
29 if ( att[0] != 'v' ) {
30 is >> Ncoll_hard >> Npart_proj >> Npart_targ >> Ncoll
31 >> spectator_neutrons >> spectator_protons
32 >> N_Nwounded_collisions >> Nwounded_N_collisions
33 >> Nwounded_Nwounded_collisions >> impact_parameter
34 >> event_plane_angle >> eccentricity >> sigma_inel_NN
35 >> centrality;
36 return !is.fail();
37 }
38 is >> version;
39
40
41
42 is >> Ncoll_hard >> Npart_proj >> Npart_targ >> Ncoll;
43 if ( version == "v0" ) is >> spectator_neutrons >> spectator_protons;
44 is >> N_Nwounded_collisions >> Nwounded_N_collisions
45 >> Nwounded_Nwounded_collisions >> impact_parameter
46 >> event_plane_angle;
47 if ( version == "v0" ) is >> eccentricity;
48 is >> sigma_inel_NN >> centrality;
49 if ( version != "v0" ) is >> user_cent_estimate;
50 is >> Nspec_proj_n >> Nspec_targ_n >> Nspec_proj_p >> Nspec_targ_p;
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
68 bool 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
83 << N_Nwounded_collisions << " " << Nwounded_N_collisions << " "
84 << Nwounded_Nwounded_collisions << " " << impact_parameter << " "
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
109 bool GenHeavyIon::operator==(const GenHeavyIon& a) const {
110 return ( memcmp( static_cast<const void*>(this), static_cast<const void*>(&a), sizeof(class GenHeavyIon) ) == 0 );
111}
112
113 bool GenHeavyIon::operator!=(const GenHeavyIon& a) const {
114 return !( a == *this );
115}
116
117 void 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;
124 spectator_neutrons = ns;
125 spectator_protons = nsp;
126 N_Nwounded_collisions = nnw;
127 Nwounded_N_collisions = nwn;
128 Nwounded_Nwounded_collisions = nwnw;
129 impact_parameter = im;
130 event_plane_angle = pl;
131 eccentricity = ec;
132 sigma_inel_NN = s;
133 centrality = cent;
134 user_cent_estimate = usrcent;
135}
136
137 bool GenHeavyIon::is_valid() const {
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
GenHeavyIon.h
Definition of attribute class GenHeavyIon.
HepMC3::GenHeavyIon::Nspec_targ_p
int Nspec_targ_p
The number of spectator protons in the target.
Definition GenHeavyIon.h:186
HepMC3::GenHeavyIon::Nwounded_Nwounded_collisions
int Nwounded_Nwounded_collisions
Non-diffractive or doubly diffractive collisions.
Definition GenHeavyIon.h:113
HepMC3::GenHeavyIon::Nwounded_N_collisions
int Nwounded_N_collisions
Collisions with a diffractively excited projectile nucleon.
Definition GenHeavyIon.h:106
HepMC3::GenHeavyIon::Nspec_proj_n
int Nspec_proj_n
The number of spectator neutrons in the projectile.
Definition GenHeavyIon.h:165
HepMC3::GenHeavyIon::impact_parameter
double impact_parameter
The impact parameter.
Definition GenHeavyIon.h:119
HepMC3::GenHeavyIon::forceoldformat
bool forceoldformat
force writing in old format for compatibility purposes.
Definition GenHeavyIon.h:237
HepMC3::GenHeavyIon::eccentricities
std::map< int, double > eccentricities
Eccentricities.
Definition GenHeavyIon.h:199
HepMC3::GenHeavyIon::Nspec_proj_p
int Nspec_proj_p
The number of spectator protons in the projectile.
Definition GenHeavyIon.h:179
HepMC3::GenHeavyIon::event_plane_angle
double event_plane_angle
The event plane angle.
Definition GenHeavyIon.h:127
HepMC3::GenHeavyIon::participant_plane_angles
std::map< int, double > participant_plane_angles
Participant plane angles.
Definition GenHeavyIon.h:193
HepMC3::GenHeavyIon::Npart_proj
int Npart_proj
the number of participating nucleons in the projectile.
Definition GenHeavyIon.h:64
HepMC3::GenHeavyIon::operator==
bool operator==(const GenHeavyIon &) const
Operator ==.
Definition GenHeavyIon.cc:109
HepMC3::GenHeavyIon::eccentricity
double eccentricity
The eccentricity.
Definition GenHeavyIon.h:133
HepMC3::GenHeavyIon::user_cent_estimate
double user_cent_estimate
A user defined centrality estimator.
Definition GenHeavyIon.h:157
HepMC3::GenHeavyIon::spectator_protons
int spectator_protons
Total number of spectator protons.
Definition GenHeavyIon.h:91
HepMC3::GenHeavyIon::N_Nwounded_collisions
int N_Nwounded_collisions
Collisions with a diffractively excited target nucleon.
Definition GenHeavyIon.h:99
HepMC3::GenHeavyIon::centrality
double centrality
The centrality.
Definition GenHeavyIon.h:148
HepMC3::GenHeavyIon::is_valid
bool is_valid() const
Verify that the instance contains non-zero information.
Definition GenHeavyIon.cc:137
HepMC3::GenHeavyIon::Nspec_targ_n
int Nspec_targ_n
The number of spectator neutrons in the target.
Definition GenHeavyIon.h:172
HepMC3::GenHeavyIon::from_string
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
Definition GenHeavyIon.cc:20
HepMC3::GenHeavyIon::Ncoll_hard
int Ncoll_hard
the number of hard nucleon-nucleon collisions.
Definition GenHeavyIon.h:57
HepMC3::GenHeavyIon::set
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
HepMC3::GenHeavyIon::operator!=
bool operator!=(const GenHeavyIon &) const
Operator !=.
Definition GenHeavyIon.cc:113
HepMC3::GenHeavyIon::Ncoll
int Ncoll
the number of inelastic nucleon-nucleon collisions.
Definition GenHeavyIon.h:80
HepMC3::GenHeavyIon::GenHeavyIon
GenHeavyIon()
Empty default constructor.
Definition GenHeavyIon.h:31
HepMC3::GenHeavyIon::Npart_targ
int Npart_targ
the number of participating nucleons in the target.
Definition GenHeavyIon.h:71
HepMC3::GenHeavyIon::spectator_neutrons
int spectator_neutrons
Total number of spectator neutrons.
Definition GenHeavyIon.h:86
HepMC3::GenHeavyIon::to_string
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Definition GenHeavyIon.cc:68
HepMC3::GenHeavyIon::sigma_inel_NN
double sigma_inel_NN
The assumed inelastic nucleon-nucleon cross section.
Definition GenHeavyIon.h:141
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24
HepMC3::version
std::string version()
Get the HepMC library version string.
Definition Version.h:25