#include "HepEvt2HepMC.h"
#include "GaudiKernel/IssueSeverity.h"
#include "HepMC/GenEvent.h"
#include "HepMC/GenParticle.h"
#include "HepMC/GenVertex.h"
#include "CLHEP/Units/SystemOfUnits.h"
#include <string>
#include <sstream>
#include <cstdio>
Include dependency graph for HepEvt2HepMC.cc:
Go to the source code of this file.
Functions | |
static FILE * | open_file (std::string filename) |
static void | close_file (FILE *fp, std::string filename) |
static bool | is_data (const char *line) |
static bool | get_line (FILE *fp, std::string &line) |
static bool | unpack (const std::string &line, HepMC::GenEvent &event) |
static FILE* open_file | ( | std::string | filename | ) | [static] |
Definition at line 42 of file HepEvt2HepMC.cc.
00043 { 00044 size_t siz = filename.size(); 00045 if (filename[siz-1] == '|') { 00046 return popen(filename.substr(0,siz-1).c_str(), "r"); 00047 } 00048 else { 00049 return fopen(filename.c_str(), "r"); 00050 } 00051 return 0; 00052 }
static void close_file | ( | FILE * | fp, | |
std::string | filename | |||
) | [static] |
Definition at line 55 of file HepEvt2HepMC.cc.
00056 { 00057 size_t siz = filename.size(); 00058 if (filename[siz-1] == '|') { 00059 pclose(fp); 00060 } 00061 else { 00062 fclose(fp); 00063 } 00064 }
static bool is_data | ( | const char * | line | ) | [static] |
Definition at line 66 of file HepEvt2HepMC.cc.
00067 { 00068 int numchkindx = 0; // C/C++ generator output 00069 if (line[0] == ' ') numchkindx = 1; // Fortran output 00070 return line[numchkindx] >= '0' && line[numchkindx] <= '9'; 00071 }
static bool get_line | ( | FILE * | fp, | |
std::string & | line | |||
) | [static] |
Definition at line 73 of file HepEvt2HepMC.cc.
00074 { 00075 char buf[1024] = {'\0'}; 00076 if (!fgets(buf,1024,fp)) { 00077 return false; // EOF or error 00078 } 00079 if (buf[1022]) { 00080 return false; // Too large line, treat as error 00081 } 00082 // Non data line, keep fishing 00083 if (!is_data(buf)) return get_line(fp,line); 00084 00085 line = buf; 00086 return true; 00087 }
static bool unpack | ( | const std::string & | line, | |
HepMC::GenEvent & | event | |||
) | [static] |
Definition at line 89 of file HepEvt2HepMC.cc.
00090 { 00091 int status=0; // status code 00092 int pdgid=0; // HEP PDG code 00093 int oldest_daughter=0; // first daughter 00094 int baby_daughter=0; // last daughter 00095 double px=0.0; // px in GeV 00096 double py=0.0; // py in GeV 00097 double pz=0.0; // pz in GeV 00098 double req_novalue=1e30; // larger than the diameter of univers in mm 00099 double mass=req_novalue; // mass in GeV 00100 double vertexX=req_novalue; // x vertex in mm requested on this line 00101 double vertexY=req_novalue; // y vertex in mm " 00102 double vertexZ=req_novalue; // z vertex in mm " 00103 double vertex_dT=req_novalue; // vertex _delta_ time (in ns) 00104 double polx=0.0; // x polarization 00105 double poly=0.0; // y polarization 00106 double polz=0.0; // z polarization 00107 double energy_unit= CLHEP::GeV; 00108 double position_unit= CLHEP::millimeter; 00109 double time_unit= CLHEP::nanosecond; /* used to be mm/c_light */ 00110 00111 std::istringstream is; 00112 is.str(line); 00113 is >> status >> pdgid >> oldest_daughter >> baby_daughter 00114 >> px >> py >> pz >> mass 00115 >> vertex_dT >> vertexX >> vertexY >> vertexZ // note order, T first 00116 >> polx >> poly >> polz; 00117 00118 00119 HepMC::GenParticle* particle = new HepMC::GenParticle 00120 (HepMC::FourVector(px*energy_unit, 00121 py*energy_unit, 00122 pz*energy_unit, 00123 sqrt(px*px+py*py+pz*pz+mass*mass)*energy_unit), 00124 pdgid,status); 00125 HepMC::GenVertex* vertex = new HepMC::GenVertex 00126 (HepMC::FourVector(vertexX*position_unit, 00127 vertexY*position_unit, 00128 vertexZ*position_unit, 00129 vertex_dT*time_unit)); 00130 event.add_vertex(vertex); 00131 if (status == 1) { 00132 vertex->add_particle_out(particle); 00133 event.set_signal_process_vertex(vertex); 00134 } 00135 else { 00136 vertex->add_particle_in(particle); 00137 } 00138 return true; 00139 }