26 info() <<
"Initializing DummyParticleGun" << endmsg;
28 StatusCode sc = Transformer::initialize();
29 if ( !sc.isSuccess() )
return sc;
32 if ( m_parts.size() == 0 )
34 error() <<
"No PDG codes specified" << endmsg;
35 return StatusCode::FAILURE;
38 if ( m_p_range.size() != 2 )
40 error() <<
"Momentum range must be of size 2" << endmsg;
41 return StatusCode::FAILURE;
44 if ( m_costheta_range.size() != 2 )
46 error() <<
"Cos(theta) range must be of size 2" << endmsg;
47 return StatusCode::FAILURE;
50 if ( m_phi_range.size() != 2 )
52 error() <<
"Phi range must be of size 2" << endmsg;
53 return StatusCode::FAILURE;
59 m_costheta1 = m_costheta_range[0];
60 m_costheta2 = m_costheta_range[1];
61 m_phi1 = m_phi_range[0];
62 m_phi2 = m_phi_range[1];
64 if ( m_p2 <= m_p1 ) m_p2 = m_p1;
65 if ( m_costheta2 <= m_costheta1 ) m_costheta2 = m_costheta1;
66 if ( m_phi2 <= m_phi1 ) m_phi2 = m_phi1;
69 m_rndm_svc = service<IBesRndmGenSvc>(
"BesRndmGenSvc" );
72 error() <<
"Could not get random number service" << endmsg;
73 return StatusCode::FAILURE;
76 m_rndm_engine = m_rndm_svc->GetEngine(
"DummyParticleGun" );
79 error() <<
"Could not get random engine" << endmsg;
80 return StatusCode::FAILURE;
84 auto part_prop_svc = service<IPartPropSvc>(
"PartPropSvc" );
87 error() <<
"Could not get Particle Properties Service" << endmsg;
88 return StatusCode::FAILURE;
91 m_particle_table = part_prop_svc->PDT();
92 if ( !m_particle_table )
94 error() <<
"Could not get Particle Data Table" << endmsg;
95 return StatusCode::FAILURE;
98 return StatusCode::SUCCESS;
102 GenEvent* evt =
new GenEvent( 1, 1 );
105 GenVertex* vtx =
new GenVertex();
106 evt->add_vertex( vtx );
109 for (
auto pdg_code : m_parts.value() )
111 const HepPDT::ParticleData* part =
112 m_particle_table->particle( HepPDT::ParticleID(
abs( pdg_code ) ) );
114 double mass = part ? part->mass().value() : 0.0;
117 double p = CLHEP::RandFlat::shoot( m_rndm_engine, m_p1, m_p2 );
118 double cos_theta = CLHEP::RandFlat::shoot( m_rndm_engine, m_costheta1, m_costheta2 );
119 double phi = CLHEP::RandFlat::shoot( m_rndm_engine, m_phi1, m_phi2 );
122 double sin_theta = sqrt( 1.0 - cos_theta * cos_theta );
123 double pt = p * sin_theta;
125 double px = pt *
cos( phi );
126 double py = pt *
sin( phi );
127 double pz = p * cos_theta;
129 CLHEP::HepLorentzVector p4;
130 p4.setVectM( CLHEP::Hep3Vector( px, py, pz ),
mass );
132 vtx->add_particle_out(
new GenParticle( p4, pdg_code, 1 ) );
135 std::vector<long> seeds{ m_rndm_engine->getSeeds()[0], m_rndm_engine->getSeeds()[1] };
136 evt->set_random_states( seeds );