00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "G4HEPEvtInterface.hh"
00033
00034 #include "G4Types.hh"
00035 #include "G4SystemOfUnits.hh"
00036
00037 #include "G4ios.hh"
00038 #include "G4PrimaryVertex.hh"
00039 #include "G4PrimaryParticle.hh"
00040 #include "G4HEPEvtParticle.hh"
00041 #include "G4Event.hh"
00042
00043 G4HEPEvtInterface::G4HEPEvtInterface(char* evfile)
00044 {
00045 inputFile.open(evfile);
00046 if (inputFile) {
00047 fileName = evfile;
00048 }
00049 else {
00050 G4Exception("G4HEPEvtInterface::G4HEPEvtInterface","Event0201",FatalException,
00051 "G4HEPEvtInterface:: cannot open file.");
00052 }
00053 G4ThreeVector zero;
00054 particle_position = zero;
00055 particle_time = 0.0;
00056
00057 }
00058
00059 G4HEPEvtInterface::G4HEPEvtInterface(G4String evfile)
00060 {
00061 const char* fn = evfile.data();
00062 inputFile.open((char*)fn);
00063 if (inputFile) {
00064 fileName = evfile;
00065 }
00066 else {
00067 G4Exception("G4HEPEvtInterface::G4HEPEvtInterface","Event0201",FatalException,
00068 "G4HEPEvtInterface:: cannot open file.");
00069 }
00070 G4ThreeVector zero;
00071 particle_position = zero;
00072 particle_time = 0.0;
00073 }
00074
00075 G4HEPEvtInterface::~G4HEPEvtInterface()
00076 {;}
00077
00078 void G4HEPEvtInterface::GeneratePrimaryVertex(G4Event* evt)
00079 {
00080 G4int NHEP;
00081 inputFile >> NHEP;
00082 if( inputFile.eof() )
00083 {
00084 G4Exception("G4HEPEvtInterface::GeneratePrimaryVertex","Event0202",
00085 JustWarning,"End-Of-File : HEPEvt input file");
00086 return;
00087 }
00088
00089 for( G4int IHEP=0; IHEP<NHEP; IHEP++ )
00090 {
00091 G4int ISTHEP;
00092 G4int IDHEP;
00093 G4int JDAHEP1;
00094 G4int JDAHEP2;
00095 G4double PHEP1;
00096 G4double PHEP2;
00097 G4double PHEP3;
00098 G4double PHEP5;
00099
00100 inputFile >> ISTHEP >> IDHEP >> JDAHEP1 >> JDAHEP2
00101 >> PHEP1 >> PHEP2 >> PHEP3 >> PHEP5;
00102
00103
00104 G4PrimaryParticle* particle
00105 = new G4PrimaryParticle( IDHEP );
00106 particle->SetMass( PHEP5*GeV );
00107 particle->SetMomentum(PHEP1*GeV, PHEP2*GeV, PHEP3*GeV );
00108
00109
00110 G4HEPEvtParticle* hepParticle
00111 = new G4HEPEvtParticle( particle, ISTHEP, JDAHEP1, JDAHEP2 );
00112
00113
00114 HPlist.push_back( hepParticle );
00115 }
00116
00117
00118 if( HPlist.size() == 0 ) return;
00119
00120
00121
00122 for( size_t i=0; i<HPlist.size(); i++ )
00123 {
00124 if( HPlist[i]->GetJDAHEP1() > 0 )
00125 {
00126 G4int jda1 = HPlist[i]->GetJDAHEP1()-1;
00127 G4int jda2 = HPlist[i]->GetJDAHEP2()-1;
00128 G4PrimaryParticle* mother = HPlist[i]->GetTheParticle();
00129 for( G4int j=jda1; j<=jda2; j++ )
00130 {
00131 G4PrimaryParticle* daughter = HPlist[j]->GetTheParticle();
00132 if(HPlist[j]->GetISTHEP()>0)
00133 {
00134 mother->SetDaughter( daughter );
00135 HPlist[j]->Done();
00136 }
00137 }
00138 }
00139 }
00140
00141
00142 G4PrimaryVertex* vertex = new G4PrimaryVertex(particle_position,particle_time);
00143
00144
00145 for( size_t ii=0; ii<HPlist.size(); ii++ )
00146 {
00147 if( HPlist[ii]->GetISTHEP() > 0 )
00148
00149 {
00150 G4PrimaryParticle* initialParticle = HPlist[ii]->GetTheParticle();
00151 vertex->SetPrimary( initialParticle );
00152 }
00153 }
00154
00155
00156
00157 for(size_t iii=0;iii<HPlist.size();iii++)
00158 { delete HPlist[iii]; }
00159 HPlist.clear();
00160
00161
00162 evt->AddPrimaryVertex( vertex );
00163 }
00164