StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
HeavyIon.cc
1 //--------------------------------------------------------------------------
2 //
3 // HeavyIon.cc
4 // Author: Lynn Garren
5 //
6 // Implement operator >> and operator <<
7 //
8 // ----------------------------------------------------------------------
9 
10 #include <iostream>
11 #include <ostream>
12 #include <istream>
13 #include <sstream>
14 
15 #include "HepMC/HeavyIon.h"
16 #include "HepMC/StreamHelpers.h"
17 #include "HepMC/IO_Exception.h"
18 
19 namespace HepMC {
20 
23 std::ostream & operator << (std::ostream & os, HeavyIon const * ion)
24 {
25  if ( !os ) {
26  std::cerr << "HeavyIon output stream !os, "
27  << " setting badbit" << std::endl;
28  os.clear(std::ios::badbit);
29  return os;
30  }
31  os << 'H';
32  // HeavyIon* is set to 0 by default
33  if ( !ion ) {
34  detail::output( os, 0 );
35  detail::output( os, 0 );
36  detail::output( os, 0 );
37  detail::output( os, 0 );
38  detail::output( os, 0 );
39  detail::output( os, 0 );
40  detail::output( os, 0 );
41  detail::output( os, 0 );
42  detail::output( os, 0 );
43  detail::output( os, 0. );
44  detail::output( os, 0. );
45  detail::output( os, 0. );
46  detail::output( os, 0. );
47  detail::output( os,'\n');
48  return os;
49  }
50  //
51  detail::output( os, ion->Ncoll_hard() );
52  detail::output( os, ion->Npart_proj() );
53  detail::output( os, ion->Npart_targ() );
54  detail::output( os, ion->Ncoll() );
55  detail::output( os, ion->spectator_neutrons() );
56  detail::output( os, ion->spectator_protons() );
57  detail::output( os, ion->N_Nwounded_collisions() );
58  detail::output( os, ion->Nwounded_N_collisions() );
59  detail::output( os, ion->Nwounded_Nwounded_collisions() );
60  detail::output( os, ion->impact_parameter() );
61  detail::output( os, ion->event_plane_angle() );
62  detail::output( os, ion->eccentricity() );
63  detail::output( os, ion->sigma_inel_NN() );
64  detail::output( os,'\n');
65 
66  return os;
67 }
68 
71 std::istream & operator >> (std::istream & is, HeavyIon * ion)
72 {
73  // make sure the stream is valid
74  if ( !is ) {
75  std::cerr << "HeavyIon input stream setting badbit." << std::endl;
76  is.clear(std::ios::badbit);
77  return is;
78  }
79  // get the HeavyIon line
80  std::string line;
81  std::getline(is,line);
82  std::istringstream iline(line);
83  std::string firstc;
84  iline >> firstc;
85  // test to be sure the next entry is of type "H"
86  if( firstc != "H" ) {
87  std::cerr << "HeavyIon input stream invalid line type: "
88  << firstc << std::endl;
89  // The most likely problem is that we have found a HepMC block line
90  throw IO_Exception("HeavyIon input stream encounterd invalid data");
91  }
92  // read values into temp variables, then create a new HeavyIon object
93  int nh =0, np =0, nt =0, nc =0,
94  neut = 0, prot = 0, nw =0, nwn =0, nwnw =0;
95  float impact = 0., plane = 0., xcen = 0., inel = 0.;
96  iline >> nh ;
97  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
98  iline >> np ;
99  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
100  iline >> nt ;
101  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
102  iline >> nc ;
103  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
104  iline >> neut ;
105  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
106  iline >> prot;
107  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
108  iline >> nw ;
109  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
110  iline >> nwn ;
111  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
112  iline >> nwnw ;
113  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
114  iline >> impact ;
115  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
116  iline >> plane ;
117  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
118  iline >> xcen ;
119  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
120  iline >> inel;
121  if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
122  if( nh == 0 ) {
123  return is;
124  }
125 
126  ion->set_Ncoll_hard(nh);
127  ion->set_Npart_proj(np);
128  ion->set_Npart_targ(nt);
129  ion->set_Ncoll(nc);
130  ion->set_spectator_neutrons(neut);
131  ion->set_spectator_protons(prot);
132  ion->set_N_Nwounded_collisions(nw);
133  ion->set_Nwounded_N_collisions(nwn);
135  ion->set_impact_parameter(impact);
136  ion->set_event_plane_angle(plane);
137  ion->set_eccentricity(xcen);
138  ion->set_sigma_inel_NN(inel);
139 
140  return is;
141 }
142 
143 
144 } // HepMC
IO exception handling.
Definition: IO_Exception.h:28
void set_N_Nwounded_collisions(const int &i)
set number of N-Nwounded collisions
Definition: HeavyIon.h:131
float impact_parameter() const
Impact Parameter(in fm) of collision.
Definition: HeavyIon.h:105
void set_Nwounded_Nwounded_collisions(const int &i)
set number of Nwounded-Nwounded collisions
Definition: HeavyIon.h:135
float event_plane_angle() const
Azimuthal angle of event plane.
Definition: HeavyIon.h:107
void set_impact_parameter(const float &f)
set Impact Parameter in fm
Definition: HeavyIon.h:138
void set_Npart_proj(const int &i)
set number of projectile participants
Definition: HeavyIon.h:121
int Npart_targ() const
Number of target participants.
Definition: HeavyIon.h:91
void set_sigma_inel_NN(const float &f)
set nucleon-nucleon inelastic cross-section
Definition: HeavyIon.h:144
void set_event_plane_angle(const float &f)
set azimuthal angle of event plane
Definition: HeavyIon.h:140
void set_Npart_targ(const int &i)
set number of target participants
Definition: HeavyIon.h:123
void set_Ncoll(const int &i)
set number of NN (nucleon-nucleon) collisions
Definition: HeavyIon.h:125
int N_Nwounded_collisions() const
Number of N-Nwounded collisions.
Definition: HeavyIon.h:99
int Ncoll_hard() const
Number of hard scatterings.
Definition: HeavyIon.h:87
int Ncoll() const
Number of NN (nucleon-nucleon) collisions.
Definition: HeavyIon.h:93
void set_eccentricity(const float &f)
set eccentricity of participating nucleons in the transverse plane
Definition: HeavyIon.h:142
float eccentricity() const
Definition: HeavyIon.h:110
int spectator_neutrons() const
Number of spectator neutrons.
Definition: HeavyIon.h:95
int Npart_proj() const
Number of projectile participants.
Definition: HeavyIon.h:89
void set_Ncoll_hard(const int &i)
set number of hard scatterings
Definition: HeavyIon.h:119
int spectator_protons() const
Number of spectator protons.
Definition: HeavyIon.h:97
int Nwounded_Nwounded_collisions() const
Number of Nwounded-Nwounded collisions.
Definition: HeavyIon.h:103
int Nwounded_N_collisions() const
Number of Nwounded-N collisons.
Definition: HeavyIon.h:101
The HeavyIon class stores information about heavy ions.
Definition: HeavyIon.h:45
void set_Nwounded_N_collisions(const int &i)
set number of Nwounded-N collisons
Definition: HeavyIon.h:133
void set_spectator_neutrons(const int &i)
set number of spectator neutrons
Definition: HeavyIon.h:127
float sigma_inel_NN() const
nucleon-nucleon inelastic (including diffractive) cross-section
Definition: HeavyIon.h:112
void set_spectator_protons(const int &i)
set number of spectator protons
Definition: HeavyIon.h:129