1 | // -*- C++ -*-
|
---|
2 | //
|
---|
3 | // This file is part of HepMC
|
---|
4 | // Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
|
---|
5 | //
|
---|
6 | /**
|
---|
7 | * @file GenHeavyIon.cc
|
---|
8 | * @brief Implementation of \b class GenHeavyIon
|
---|
9 | *
|
---|
10 | */
|
---|
11 | #include "HepMC3/GenHeavyIon.h"
|
---|
12 | #include <cstring> // memcmp
|
---|
13 | #include <cstdlib> // atoi
|
---|
14 | #include <cstdio> // sprintf
|
---|
15 | #include <sstream> // sprintf
|
---|
16 |
|
---|
17 | namespace HepMC3 {
|
---|
18 |
|
---|
19 | bool GenHeavyIon::from_string(const std::string &att) {
|
---|
20 |
|
---|
21 | #ifdef HEPMC3_NO_DEPRECATED
|
---|
22 | double spectator_neutrons, spectator_protons, eccentricity;
|
---|
23 | #endif
|
---|
24 |
|
---|
25 | std::istringstream is(att);
|
---|
26 | std::string version;
|
---|
27 |
|
---|
28 | if ( att[0] != 'v' ) {
|
---|
29 | is >> Ncoll_hard >> Npart_proj >> Npart_targ >> Ncoll
|
---|
30 | >> spectator_neutrons >> spectator_protons
|
---|
31 | >> N_Nwounded_collisions >> Nwounded_N_collisions
|
---|
32 | >> Nwounded_Nwounded_collisions >> impact_parameter
|
---|
33 | >> event_plane_angle >> eccentricity >> sigma_inel_NN
|
---|
34 | >> centrality;
|
---|
35 | return !is.fail();
|
---|
36 | } else
|
---|
37 | is >> version;
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | is >> Ncoll_hard >> Npart_proj >> Npart_targ >> Ncoll;
|
---|
42 | if ( version == "v0" ) is >> spectator_neutrons >> spectator_protons;
|
---|
43 | is >> N_Nwounded_collisions >> Nwounded_N_collisions
|
---|
44 | >> Nwounded_Nwounded_collisions >> impact_parameter
|
---|
45 | >> event_plane_angle;
|
---|
46 | if ( version == "v0" ) is >> eccentricity;
|
---|
47 | is >> sigma_inel_NN >> centrality;
|
---|
48 | if ( version != "v0" ) is >> user_cent_estimate;
|
---|
49 | is >> Nspec_proj_n >> Nspec_targ_n >> Nspec_proj_p >> Nspec_targ_p;
|
---|
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 |
|
---|
66 | bool 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
|
---|
81 | << N_Nwounded_collisions << " " << Nwounded_N_collisions << " "
|
---|
82 | << Nwounded_Nwounded_collisions << " " << impact_parameter << " "
|
---|
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 |
|
---|
109 | bool GenHeavyIon::operator==( const GenHeavyIon& a ) const {
|
---|
110 | return ( memcmp( (void*) this, (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
|
---|