65 event =
new HepMC::GenEvent();
75 HepMC::GenParticle* particle =
new HepMC::GenParticle(momentum, pdg_id);
76 particle->suggest_barcode(partID);
79 segmentations[partID] = 1;
82 HepMC::GenVertex* endvertex =
new HepMC::GenVertex(endpos);
85 endvertex->suggest_barcode(-partID);
86 endvertex->add_particle_in(particle);
87 event->add_vertex(endvertex);
93 HepMC::GenParticle* mother =
event->barcode_to_particle(motherID);
99 HepMC::GenVertex* motherendvtx = mother->end_vertex();
100 HepMC::FourVector mp0 = motherendvtx->position();
103 if( motherendpos.x() == prodpos.
x() &&
104 motherendpos.y() == prodpos.
y() &&
105 motherendpos.z() == prodpos.
z() )
107 motherendvtx->add_particle_out(particle);
118 for(HepMC::GenVertex::particles_out_const_iterator
119 it=motherendvtx->particles_out_const_begin();
120 it!=motherendvtx->particles_out_const_end();it++)
122 if((*it)->pdg_id()==-999999)
124 HepMC::FourVector dp0 = (*it)->end_vertex()->position();
127 if( dummypos.
x() == prodpos.
x() &&
128 dummypos.
y() == prodpos.
y() &&
129 dummypos.
z() == prodpos.
z() )
131 (*it)->end_vertex()->add_particle_out(particle);
143 HepMC::GenVertex* childvtx =
new HepMC::GenVertex(prodpos);
144 childvtx->add_particle_out(particle);
149 childvtx->suggest_barcode(-500000-partID);
150 event->add_vertex(childvtx);
152 HepMC::GenParticle* dummypart =
158 dummypart->suggest_barcode(500000+partID);
159 childvtx->add_particle_in(dummypart);
160 motherendvtx->add_particle_out(dummypart);
169 G4int number_of_segments = segmentations[motherID];
174 while ( !((mother->end_vertex()->position().t()>prodpos.
t()) &&
175 (mother->production_vertex()->position().t()<prodpos.
t())) )
178 if (segment == number_of_segments)
179 G4cerr <<
"Problem!!!! Time coordinates incompatible!" <<
G4endl;
181 mother =
event->barcode_to_particle(segment*10000000 + motherID);
187 HepMC::GenVertex* childvtx =
new HepMC::GenVertex(prodpos);
188 childvtx->add_particle_out(particle);
189 event->add_vertex(childvtx);
193 HepMC::GenVertex* orig_mother_end_vtx = mother->end_vertex();
194 orig_mother_end_vtx->remove_particle(mother);
198 childvtx->add_particle_in(mother);
204 HepMC::GenParticle* mothertwo =
new HepMC::GenParticle(*mother);
205 mothertwo->suggest_barcode(segmentations[motherID]*10000000
206 + mother->barcode());
210 orig_mother_end_vtx->suggest_barcode(-segmentations[motherID]
211 *10000000 - mother->barcode());
212 childvtx->suggest_barcode(-mother->barcode());
216 childvtx->add_particle_out(mothertwo);
220 orig_mother_end_vtx->add_particle_in(mothertwo);
224 segmentations[motherID] = segmentations[motherID]+1;
234 G4cerr <<
"barcode " << motherID <<
" mother not there! "<<
G4endl;
239 HepMC::GenVertex* primaryvtx =
new HepMC::GenVertex(prodpos);
240 primaryvtx->add_particle_out(particle);
241 event->add_vertex(primaryvtx);
245 primarybarcodes.push_back(partID);
255 for(std::vector<int>::const_iterator primarybar=primarybarcodes.begin();
256 primarybar!=primarybarcodes.end();primarybar++)
258 printTree(event->barcode_to_particle(*primarybar),
" | ");
262 void MCTruthManager::printTree(HepMC::GenParticle* particle,
G4String offset)
264 G4cout << offset <<
"--- barcode: " << particle->barcode() <<
" pdg: "
265 << particle->pdg_id() <<
" energy: " << particle->momentum().e()
266 <<
" production vertex: "
267 << particle->production_vertex()->position().x() <<
", "
268 << particle->production_vertex()->position().y() <<
", "
269 << particle->production_vertex()->position().z() <<
", "
270 << particle->production_vertex()->position().t()
273 for(HepMC::GenVertex::particles_out_const_iterator
274 it=particle->end_vertex()->particles_out_const_begin();
275 it!=particle->end_vertex()->particles_out_const_end();
280 G4int curr = std::fmod(
double((*it)->barcode()),10000000.);
281 G4int part = std::fmod(
double(particle->barcode()),10000000.);
287 printTree((*it), offset + deltaoffset);
static MCTruthManager * GetInstance()
void AddParticle(G4LorentzVector &, G4LorentzVector &, G4LorentzVector &, G4int, G4int, G4int, G4bool)
virtual ~MCTruthManager()
Definition of the MCTruthManager class.
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
G4GLOB_DLL std::ostream G4cout
G4GLOB_DLL std::ostream G4cerr
CLHEP::HepLorentzVector G4LorentzVector