39#include "G4LorentzVector.hh"
41#include "G4PrimaryParticle.hh"
42#include "G4PrimaryVertex.hh"
43#include "G4ParticleTable.hh"
44#include "Randomize.hh"
46#include "HepPDT/ParticleDataTable.hh"
47#include "HepPDT/ParticleData.hh"
51#include "GaudiKernel/IDataProviderSvc.h"
52#include "GaudiKernel/IPartPropSvc.h"
53#include "GaudiKernel/IAlgManager.h"
54#include "GaudiKernel/AlgFactory.h"
55#include "GaudiKernel/MsgStream.h"
56#include "GaudiKernel/SvcFactory.h"
57#include "GaudiKernel/ISvcLocator.h"
58#include "GaudiKernel/SmartDataPtr.h"
59#include "GaudiKernel/Bootstrap.h"
61#include "G4PhysicalConstants.hh"
62#include "G4SystemOfUnits.hh"
67 : hepmcEvent(0), m_geantinoPdgId(100), m_chargedgeantinoPdgId(101)
72 ISvcLocator* svcLocator = Gaudi::svcLocator();
73 StatusCode status = svcLocator->service(
"RealizationSvc",tmpReal);
74 if (!status.isSuccess())
76 std::cout <<
" Could not initialize Realization Service in G4HepMCInterface" << std::endl;
81 int pdlId1=-1, pdlId2=-1;
82 auto algMan = svcLocator->as<IAlgManager>();
84 if(algMan->existsAlgorithm(
"EvtDecay")){
86 pdlId1 = evtId1.
getId();
91 pdlId2 = evtId2.
getId();
98 if(pdlId1==-1||pdlId2==-1){
99 IPartPropSvc* p_PartPropSvc;
100 StatusCode PartPropStatus = svcLocator->service(
"PartPropSvc", p_PartPropSvc);
101 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
102 std::cout <<
" Could not initialize Particle Properties Service in G4HepMCInterface" << std::endl;
105 HepPDT::ParticleDataTable* pdt = p_PartPropSvc->PDT();
107 const HepPDT::ParticleData* pd = pdt->particle(
"geantino");
108 if(pd) m_geantinoPdgId = pd->pid();
111 const HepPDT::ParticleData* pd = pdt->particle(
"chargedgeantino");
112 if(pd) m_chargedgeantinoPdgId = pd->pid();
128 for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin();
129 vitr != hepmcevt->vertices_end(); ++vitr ) {
130 G4cout<<G4endl<<
"vertex:"<<i<<
" barcode:"<<(*vitr)->barcode()<<
" ";
136 G4LorentzVector xvtx;
137 xvtx.setX( (*vitr)-> position().
x());
138 xvtx.setY( (*vitr)-> position().
y());
139 xvtx.setZ( (*vitr)-> position().z());
140 xvtx.setT( (*vitr)-> position().
t());
141 G4cout<<
"x:"<<xvtx.x()<<
" y:"<<xvtx.y()<<
" z:"<<xvtx.z()
142 <<
" t:"<<xvtx.t()*mm/c_light<<G4endl;
145 for (HepMC::GenVertex::particle_iterator
146 pitr= (*vitr)->particles_begin(HepMC::children);
147 pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
148 G4int pdgcode= (*pitr)-> pdg_id();
154 G4cout<<
"particle:"<<j<<
" pdgcode:"<<pdgcode<<
" ";
155 G4cout<<
"p:"<<p.x()<<
" "<<p.y()<<
" "<<p.z()<<
" ";
156 if((*pitr)->end_vertex())
157 G4cout<<
"endVtx:"<<(*pitr)->end_vertex()->barcode()<<
" ";
158 G4cout<<
"status:"<<(*pitr)->status()<<G4endl;
167 G4cout<<
"particles sent to Geant4: "<<G4endl;
168 for(
size_t ii=0; ii<
HPlist.size(); ii++ )
170 G4int pdgcode =
HPlist[ii]->GetTheParticle()->GetPDGcode();
171 G4cout<<pdgcode<<
" ";
179 for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin();
180 vitr != hepmcevt->vertices_end(); ++vitr ) {
181 for (HepMC::GenVertex::particle_iterator
182 pitr= (*vitr)->particles_begin(HepMC::children);
183 pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
184 if((*pitr)->end_vertex())
192 G4cout<<G4endl<<
"generator is GENBES!"<<G4endl;
194 G4cout<<G4endl<<
"generator is not GENBES!"<<G4endl;
214 G4LorentzVector ptot(0,0,0,0);
215 double E_cms,p_Mag,e_Mass2,M_cms,theta;
216 for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin();
217 vitr != hepmcevt->vertices_end(); ++vitr ) {
219 for(HepMC::GenVertex::particle_iterator
220 vpitr = (*vitr)->particles_begin(HepMC::children);
221 vpitr != (*vitr)->particles_end(HepMC::children); ++vpitr) {
223 if((*vpitr)->status() !=1)
continue;
236 ISvcLocator* svcLocator = Gaudi::svcLocator();
239 StatusCode sc=svcLocator->service(
"G4Svc", tmpSvc);
240 m_G4Svc=
dynamic_cast<G4Svc *
>(tmpSvc);
243 G4ThreeVector
v(0,0,0);
249 e_Mass2=electron_mass_c2*electron_mass_c2;
250 p_Mag=sqrt((E_cms*E_cms-4*e_Mass2)/(2*(1-
cos(
pi-2*theta))));
251 G4ThreeVector p_Positron(p_Mag*
sin(theta),0,p_Mag*
cos(theta));
252 G4ThreeVector p_Electron(p_Mag*
sin(
pi-theta),0,p_Mag*
cos(
pi-theta));
253 G4ThreeVector vee=p_Positron+p_Electron;
255 if(m_G4Svc-> GetSetBeamShift()==
true && fabs(M_cms-3686)<50.0) {vee = beamshift;}
258 M_cms = sqrt(M_cms*M_cms + pee*pee);
262 for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin();
263 vitr != hepmcevt->vertices_end(); ++vitr ) {
266 G4LorentzVector xvtx;
267 xvtx.setX( (*vitr)-> position().
x());
268 xvtx.setY( (*vitr)-> position().
y());
269 xvtx.setZ( (*vitr)-> position().z());
270 xvtx.setT( (*vitr)-> position().
t());
272 (*vitr)->set_position(xvtx);
276 for (HepMC::GenVertex::particle_iterator
277 vpitr = (*vitr)->particles_begin(HepMC::children);
278 vpitr != (*vitr)->particles_end(HepMC::children); ++vpitr) {
285 (*vpitr)->set_momentum(p);
300 ISvcLocator* svcLocator = Gaudi::svcLocator();
303 StatusCode sc=svcLocator->service(
"G4Svc", tmpSvc);
304 m_G4Svc=
dynamic_cast<G4Svc *
>(tmpSvc);
312 if(m_logLevel <=2 && m_G4Svc->GetBoostLab()==
true)
319 for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin();
320 vitr != hepmcevt->vertices_end(); ++vitr )
323 G4int pOut = (*vitr)->particles_out_size();
324 HepMC::GenVertex::particle_iterator pitr = (*vitr)->particles_begin(HepMC::children);
325 G4int pdgcode= (*pitr)-> pdg_id();
326 if(pOut == 1 &&
abs(pdgcode) == 11)
328 G4int barcodeVtx = (*vitr)->barcode();
330 for (HepMC::GenVertex::particle_iterator pitr= (*vitr)->particles_begin(HepMC::children);
331 pitr != (*vitr)->particles_end(HepMC::children); ++pitr)
333 G4int pdgcode = (*pitr)->pdg_id();
336 if(pdgcode==-22) pdgcode=22;
342 G4PrimaryParticle* particle = 0;
347 if(pdgcode==m_geantinoPdgId){
348 G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(
"geantino");
349 particle =
new G4PrimaryParticle(pd, p.x()*GeV, p.y()*GeV, p.z()*GeV);
350 (*pitr)->set_pdg_id(particle->GetPDGcode());
352 else if(pdgcode==m_chargedgeantinoPdgId){
353 G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(
"chargedgeantino");
354 particle =
new G4PrimaryParticle(pd, p.x()*GeV, p.y()*GeV, p.z()*GeV);
355 (*pitr)->set_pdg_id(particle->GetPDGcode());
361 particle =
new G4PrimaryParticle(pdgcode, p.x()*GeV, p.y()*GeV, p.z()*GeV);
364 G4cout <<
"ERROR! Cannot create particle PDGCode=" << pdgcode << G4endl;
368 G4int ISTHEP = (*pitr)->status();
370 G4int barcodeEndVtx = 0;
371 if((*pitr)->end_vertex())
372 barcodeEndVtx = (*pitr)->end_vertex()->barcode();
375 HPlist.push_back(hepmcParticle);
377 for(
size_t ii=0; ii<
HPlist.size(); ii++ )
379 if(barcodeVtx ==
HPlist[ii]->GetBarcodeEndVtx())
381 HPlist[ii]->GetTheParticle()->SetDaughter(particle);
382 hepmcParticle->
Done();
392 for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin();
393 vitr != hepmcevt->vertices_end(); ++vitr )
395 for (HepMC::GenVertex::particle_iterator pitr= (*vitr)->particles_begin(HepMC::children);
396 pitr != (*vitr)->particles_end(HepMC::children); ++pitr)
398 G4int ISTHEP = (*pitr)->status();
405 G4int pdgcode = (*pitr)->pdg_id();
406 G4int barcodeEndVtx = 0;
407 if((*pitr)->end_vertex())
408 barcodeEndVtx = (*pitr)->end_vertex()->barcode();
409 G4PrimaryParticle* particle = 0;
414 if(pdgcode==m_geantinoPdgId){
415 G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(
"geantino");
416 particle =
new G4PrimaryParticle(pd, p.x()*GeV, p.y()*GeV, p.z()*GeV);
417 (*pitr)->set_pdg_id(particle->GetPDGcode());
419 else if(pdgcode==m_chargedgeantinoPdgId){
420 G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(
"chargedgeantino");
421 particle =
new G4PrimaryParticle(pd, p.x()*GeV, p.y()*GeV, p.z()*GeV);
422 (*pitr)->set_pdg_id(particle->GetPDGcode());
428 particle =
new G4PrimaryParticle(pdgcode, p.x()*GeV, p.y()*GeV, p.z()*GeV);
431 G4cout <<
"ERROR! Cannot create particle PDGCode=" << pdgcode << G4endl;
437 HPlist.push_back(hepmcParticle);
439 hepmcParticle->
Done();
449 G4double pmPosX,pmPosY,pmPosZ,pmTime;
450 G4double tmpPosX,tmpPosY,tmpPosZ,tmpT;
451 G4double beamPosX,beamPosY,beamPosZ,beamSizeX,beamSizeY,beamSizeZ;
453 if(m_RealizationSvc->
UseDBFlag() ==
false) {
481 G4double gaussX = G4RandGauss::shoot();
482 G4double gaussY = G4RandGauss::shoot();
483 G4double gaussZ = G4RandGauss::shoot();
484 G4double gaussT = G4RandGauss::shoot();
491 G4double ran=G4UniformRand();
492 G4double beamTime = bunchTimeSigma*G4RandGauss::shoot() + beamStartTime + beamDeltaTime*int(ran*nBunch);
494 tmpPosX = (beamPosX + beamSizeX*gaussX ) *mm;
495 tmpPosY = (beamPosY + beamSizeY*gaussY ) *mm;
496 tmpPosZ = (beamPosZ + beamSizeZ*gaussZ ) *mm;
497 tmpT = (beamSizeZ * gaussT ) * mm/c_light +beamTime;
499 G4LorentzVector tmpv(tmpPosX,tmpPosY,tmpPosZ,tmpT*c_light/mm);
501 HepMC::GenEvent::vertex_const_iterator vitr0= hepmcevt->vertices_begin();
502 G4LorentzVector xvtx0 ;
503 xvtx0.setX( (*vitr0)-> position().
x());
504 xvtx0.setY( (*vitr0)-> position().
y());
505 xvtx0.setZ( (*vitr0)-> position().z());
506 xvtx0.setT( (*vitr0)-> position().
t());
507 pmPosX = xvtx0.x()*mm + tmpPosX;
508 pmPosY = xvtx0.y()*mm + tmpPosY;
509 pmPosZ = xvtx0.z()*mm + tmpPosZ;
510 pmTime = xvtx0.t()*mm/c_light + tmpT;
515 G4cout<<xvtx0.x()<<
" "<<xvtx0.y()<<
" "<<xvtx0.z()<<
" "
516 <<beamSizeX*gaussX<<
" "
517 <<beamSizeY*gaussY<<
" "
518 <<beamSizeZ*gaussZ<<
" "<<G4endl;
519 G4cout<<xvtx0.t()* mm/c_light<<
" "
520 <<beamSizeZ * gaussT/sqrt(2)*mm/c_light<<
" "
523 for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin();
524 vitr != hepmcevt->vertices_end(); ++vitr )
526 G4LorentzVector xvtx;
527 xvtx.setX((*vitr)-> position().
x());
528 xvtx.setY((*vitr)-> position().
y());
529 xvtx.setZ((*vitr)-> position().z());
530 xvtx.setT((*vitr)-> position().
t());
531 (*vitr)->set_position(xvtx+tmpv);
535 G4PrimaryVertex* g4vtx=
new G4PrimaryVertex(pmPosX,pmPosY,pmPosZ,pmTime);
538 for(
size_t ii=0; ii<
HPlist.size(); ii++ )
540 if(
HPlist[ii]->GetISTHEP() > 0 )
543 G4PrimaryParticle* initialParticle =
HPlist[ii]->GetTheParticle();
544 g4vtx->SetPrimary( initialParticle );
549 for(
size_t iii=0;iii<
HPlist.size();iii++)
553 g4event->AddPrimaryVertex(g4vtx);
561 HepMC::GenEvent* aevent=
new HepMC::GenEvent();
575 G4Exception(
"G4HepMCInterface",
"GeneratePrimaryVertex",RunMustBeAborted,
576 "HepMCInterface: no generated particles. run terminated..." );
double sin(const BesAngle a)
double cos(const BesAngle a)
**********INTEGER nmxhep !maximum number of particles DOUBLE PRECISION vhep INTEGER jdahep COMMON hepevt $ !serial number $ !number of particles $ !status code $ !particle ident KF $ !parent particles $ !childreen particles $ !four momentum
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
static int getStdHep(EvtId id)
static EvtId getId(const std::string &name)
virtual ~G4HepMCInterface()
HepMC::GenEvent * hepmcEvent
void HepMC2G4(HepMC::GenEvent *hepmcevt, G4Event *g4event)
void Print(const HepMC::GenEvent *hepmcevt)
void Boost(HepMC::GenEvent *hepmcevt)
std::vector< G4HepMCParticle * > HPlist
virtual void GeneratePrimaryVertex(G4Event *anEvent)
virtual HepMC::GenEvent * GenerateHepMCEvent()
G4int CheckType(const HepMC::GenEvent *hepmcevt)
double GetBeamDeltaTime()
double GetBunchTimeSigma()
double GetBeamStartTime()
void SetBeamTime(double value)