9 #include <Geant4/G4Event.hh>
10 #include <Geant4/G4ParticleTable.hh>
11 #include <Geant4/G4PrimaryParticle.hh>
12 #include <Geant4/G4PrimaryVertex.hh>
13 #include <Geant4/G4SystemOfUnits.hh>
14 #include <Geant4/G4ThreeVector.hh>
29 map<int, PHG4VtxPoint *>::const_iterator vtxiter;
30 multimap<int, PHG4Particle *>::const_iterator particle_iter;
31 std::pair< std::map<int, PHG4VtxPoint *>::const_iterator, std::map<int, PHG4VtxPoint *>::const_iterator > vtxbegin_end = inEvent->GetVertices();
33 for (vtxiter = vtxbegin_end.first; vtxiter != vtxbegin_end.second; ++vtxiter)
38 G4ThreeVector position((*vtxiter->second).get_x()*cm, (*vtxiter->second).get_y()*cm, (*vtxiter->second).get_z()*cm );
39 G4PrimaryVertex* vertex =
new G4PrimaryVertex(position, (*vtxiter->second).get_t()*nanosecond);
40 pair<multimap<int, PHG4Particle *>::const_iterator, multimap<int, PHG4Particle *>::const_iterator > particlebegin_end = inEvent->GetParticles(vtxiter->first);
41 for (particle_iter = particlebegin_end.first; particle_iter != particlebegin_end.second; ++particle_iter)
54 if (!(*particle_iter->second).get_pid())
56 G4String particleName = (*particle_iter->second).get_name();
57 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
58 G4ParticleDefinition* particledef
59 = particleTable->FindParticle(particleName);
62 (*particle_iter->second).set_pid(particledef->GetPDGEncoding());
66 cout <<
PHWHERE <<
"Cannot get PDG value for particle " << particleName
67 <<
", dropping it" << endl;
71 G4PrimaryParticle* g4part =
NULL;
72 if (!(*particle_iter->second).get_pid())
74 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
75 G4ParticleDefinition* particle_definition
76 = particleTable->FindParticle((*particle_iter->second).get_name());
77 if (particle_definition)
79 G4double mass = particle_definition->GetPDGMass();
80 g4part =
new G4PrimaryParticle(particle_definition);
81 double ekin = sqrt((*particle_iter->second).get_px() * (*particle_iter->second).get_px() +
82 (*particle_iter->second).get_py() * (*particle_iter->second).get_py() +
83 (*particle_iter->second).get_pz() * (*particle_iter->second).get_pz());
86 g4part->SetKineticEnergy( ekin*GeV );
87 g4part->SetMass( mass );
88 G4ThreeVector v((*particle_iter->second).get_px(), (*particle_iter->second).get_py(), (*particle_iter->second).get_pz());
89 G4ThreeVector vunit = v.unit();
90 g4part->SetMomentumDirection( vunit );
91 g4part->SetCharge( particle_definition->GetPDGCharge() );
92 G4ThreeVector particle_polarization;
93 g4part->SetPolarization(particle_polarization.x(),
94 particle_polarization.y(),
95 particle_polarization.z());
99 cout <<
PHWHERE <<
" cannot get G4 particle definition" << endl;
100 cout <<
"you should have never gotten here, please check this in detail" << endl;
101 cout <<
"exiting now" << endl;
108 g4part =
new G4PrimaryParticle((*particle_iter->second).get_pid(),
109 (*particle_iter->second).get_px()*GeV,
110 (*particle_iter->second).get_py()*GeV,
111 (*particle_iter->second).get_pz()*GeV);
119 g4part->SetUserInformation(userdata);
121 vertex->SetPrimary(g4part);
124 anEvent->AddPrimaryVertex(vertex);
virtual void GeneratePrimaries(G4Event *anEvent)
void set_user_barcode(int bcd)