61 if ( *(evt_orig->vertices_begin()) == 0 )
63 throw SimG4Exception(
"SimG4CoreGenerator: Corrupted Event - GenEvent with no vertex" ) ;
67 HepMC::GenEvent* evt =
new HepMC::GenEvent(*evt_orig) ;
69 if ( evt->weights().size() > 0 )
72 for (
unsigned int iw=1; iw<evt->weights().size(); iw++ )
75 if ( evt->weights()[iw] <= 0 )
break;
82 (*(evt->vertices_begin()))->position().y(),
83 (*(evt->vertices_begin()))->position().z(),
84 (*(evt->vertices_begin()))->position().t());
88 LogDebug(
"SimG4CoreGenerator") <<
"Primary Vertex = (" <<
vtx_->x() <<
","
96 unsigned int ng4vtx = 0;
98 for(HepMC::GenEvent::vertex_const_iterator vitr= evt->vertices_begin();
99 vitr != evt->vertices_end(); ++vitr ) {
104 for (HepMC::GenVertex::particle_iterator pitr= (*vitr)->particles_begin(HepMC::children);
105 pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
107 if ((*pitr)->status()==1) {
109 if (
verbose > 2 )
LogDebug(
"SimG4CoreGenerator") <<
"GenVertex barcode = " << (*vitr)->barcode()
110 <<
" selected for GenParticle barcode = " << (*pitr)->barcode() << std::endl;
116 else if ( (*pitr)->status()== 2 ) {
117 if ( (*pitr)->end_vertex() != 0 ) {
120 double xx = (*pitr)->end_vertex()->position().x();
121 double yy = (*pitr)->end_vertex()->position().y();
125 if (
verbose > 2 )
LogDebug(
"SimG4CoreGenerator") <<
"GenVertex barcode = " << (*vitr)->barcode()
126 <<
" selected for GenParticle barcode = " << (*pitr)->barcode() <<
" radius = " << r_dd << std::endl;
138 double x1 = (*vitr)->position().x();
139 double y1 = (*vitr)->position().y();
140 double z1 = (*vitr)->position().z();
141 double t1 = (*vitr)->position().t();
142 G4PrimaryVertex* g4vtx=
143 new G4PrimaryVertex(x1*mm, y1*mm, z1*mm, t1*mm/c_light);
145 for (HepMC::GenVertex::particle_iterator vpitr= (*vitr)->particles_begin(HepMC::children);
146 vpitr != (*vitr)->particles_end(HepMC::children); ++vpitr){
156 double r_decay_length=-1;
157 double decay_length=-1;
159 if ( (*vpitr)->status() == 1 || (*vpitr)->status() == 2 ) {
161 if ( (*vpitr)->end_vertex() != 0 ) {
166 double x2 = (*vpitr)->end_vertex()->position().x();
167 double y2 = (*vpitr)->end_vertex()->position().y();
168 double z2 = (*vpitr)->end_vertex()->position().z();
170 decay_length=
std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
176 bool toBeAdded =
false;
178 (*vpitr)->momentum().py(),
179 (*vpitr)->momentum().pz(),
180 (*vpitr)->momentum().e());
183 const double minTan = 1.e-20;
185 if ( fabs(z1) <
Z_hector && fabs(
p.pt()/
p.pz()) >= minTan ) {
190 if (
verbose > 2 )
LogDebug(
"SimG4CoreGenerator") <<
"Processing GenParticle barcode = " << (*vpitr)->barcode()
191 <<
" status = " << (*vpitr)->status()
192 <<
" zimpact = " << zimpact;
195 if( (*vpitr)->status() == 1 && fabs(zimpact) <
Z_hector ) {
200 if (
verbose > 2 )
LogDebug(
"SimG4CoreGenerator") <<
"GenParticle barcode = " << (*vpitr)->barcode() <<
" passed case 1" << std::endl;
204 else if((*vpitr)->status() == 2 && r_decay_length >
theRDecLenCut &&
207 if (
verbose > 2 )
LogDebug(
"SimG4CoreGenerator") <<
"GenParticle barcode = " << (*vpitr)->barcode() <<
" passed case 2" << std::endl;
212 else if( (*vpitr)->status() == 1 && fabs(zimpact) >=
Z_hector && fabs(z1) >=
Z_hector) {
214 if (
verbose > 2 )
LogDebug(
"SimG4CoreGenerator") <<
"GenParticle barcode = " << (*vpitr)->barcode() <<
" passed case 3" << std::endl;
219 G4int pdgcode= (*vpitr)-> pdg_id();
220 G4PrimaryParticle* g4prim=
221 new G4PrimaryParticle(pdgcode,
p.Px()*GeV,
p.Py()*GeV,
p.Pz()*GeV);
223 if ( g4prim->GetG4code() != 0 ){
224 g4prim->SetMass( g4prim->GetG4code()->GetPDGMass() ) ;
225 g4prim->SetCharge( g4prim->GetG4code()->GetPDGCharge() ) ;
228 g4prim->SetWeight( 10000*(*vpitr)->barcode() ) ;
229 setGenId( g4prim, (*vpitr)->barcode() ) ;
231 if ( (*vpitr)->status() == 2 )
233 if (
verbose > 1 ) g4prim->Print();
234 g4vtx->SetPrimary(g4prim);
236 if ( (*vpitr)->status()==1 && (*vpitr)->end_vertex()!=0) {
237 double proper_time=decay_length/(
p.Beta()*
p.Gamma()*c_light);
238 if (
verbose > 1 )
LogDebug(
"SimG4CoreGenerator") <<
"Setting proper time for beta="<<
p.Beta()<<
" gamma="<<
p.Gamma()<<
" Proper time=" <<proper_time<<
" ns" ;
239 g4prim->SetProperTime(proper_time*ns);
244 if (
verbose > 1 ) g4vtx->Print();
245 g4evt->AddPrimaryVertex(g4vtx);
255 G4PrimaryVertex* g4vtx=
256 new G4PrimaryVertex(x1*mm, y1*mm, z1*mm, t1*mm/c_light);
257 if (
verbose > 1 ) g4vtx->Print();
258 g4evt->AddPrimaryVertex(g4vtx);
void setGenId(G4PrimaryParticle *p, int id) const
void particleAssignDaughters(G4PrimaryParticle *p, HepMC::GenParticle *hp, double length)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
math::XYZTLorentzVector * vtx_
bool particlePassesPrimaryCuts(const G4PrimaryParticle *p) const