BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DummyParticleGun Class Reference
Inheritance diagram for DummyParticleGun:

Public Member Functions

 DummyParticleGun (const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize () override
McGenEventCol operator() (const EventContext &ctx) const override

Detailed Description

Definition at line 20 of file DummyParticleGun.cxx.

Constructor & Destructor Documentation

◆ DummyParticleGun()

DummyParticleGun::DummyParticleGun ( const std::string & name,
ISvcLocator * pSvcLocator )
inline

Definition at line 22 of file DummyParticleGun.cxx.

23 : Transformer( name, pSvcLocator, { "McGenEventLocation", "/Event/Gen" } ) {}

Member Function Documentation

◆ initialize()

StatusCode DummyParticleGun::initialize ( )
inlineoverride

Definition at line 25 of file DummyParticleGun.cxx.

25 {
26 info() << "Initializing DummyParticleGun" << endmsg;
27
28 StatusCode sc = Transformer::initialize();
29 if ( !sc.isSuccess() ) return sc;
30
31 // check args
32 if ( m_parts.size() == 0 )
33 {
34 error() << "No PDG codes specified" << endmsg;
35 return StatusCode::FAILURE;
36 }
37
38 if ( m_p_range.size() != 2 )
39 {
40 error() << "Momentum range must be of size 2" << endmsg;
41 return StatusCode::FAILURE;
42 }
43
44 if ( m_costheta_range.size() != 2 )
45 {
46 error() << "Cos(theta) range must be of size 2" << endmsg;
47 return StatusCode::FAILURE;
48 }
49
50 if ( m_phi_range.size() != 2 )
51 {
52 error() << "Phi range must be of size 2" << endmsg;
53 return StatusCode::FAILURE;
54 }
55
56 // set ranges
57 m_p1 = m_p_range[0];
58 m_p2 = m_p_range[1];
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];
63
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;
67
68 // retrieve random enging
69 m_rndm_svc = service<IBesRndmGenSvc>( "BesRndmGenSvc" );
70 if ( !m_rndm_svc )
71 {
72 error() << "Could not get random number service" << endmsg;
73 return StatusCode::FAILURE;
74 }
75
76 m_rndm_engine = m_rndm_svc->GetEngine( "DummyParticleGun" );
77 if ( !m_rndm_engine )
78 {
79 error() << "Could not get random engine" << endmsg;
80 return StatusCode::FAILURE;
81 }
82
83 // retrieve particle data table
84 auto part_prop_svc = service<IPartPropSvc>( "PartPropSvc" );
85 if ( !part_prop_svc )
86 {
87 error() << "Could not get Particle Properties Service" << endmsg;
88 return StatusCode::FAILURE;
89 }
90
91 m_particle_table = part_prop_svc->PDT();
92 if ( !m_particle_table )
93 {
94 error() << "Could not get Particle Data Table" << endmsg;
95 return StatusCode::FAILURE;
96 }
97
98 return StatusCode::SUCCESS;
99 }

◆ operator()()

McGenEventCol DummyParticleGun::operator() ( const EventContext & ctx) const
inlineoverride

Definition at line 101 of file DummyParticleGun.cxx.

101 {
102 GenEvent* evt = new GenEvent( 1, 1 );
103
104 // make vertex (0, 0, 0, 0)
105 GenVertex* vtx = new GenVertex();
106 evt->add_vertex( vtx );
107
108 // sample particles
109 for ( auto pdg_code : m_parts.value() )
110 {
111 const HepPDT::ParticleData* part =
112 m_particle_table->particle( HepPDT::ParticleID( abs( pdg_code ) ) );
113
114 double mass = part ? part->mass().value() : 0.0;
115
116 // sample momentum
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 );
120
121 // calculate px, py, pz
122 double sin_theta = sqrt( 1.0 - cos_theta * cos_theta );
123 double pt = p * sin_theta;
124
125 double px = pt * cos( phi );
126 double py = pt * sin( phi );
127 double pz = p * cos_theta;
128
129 CLHEP::HepLorentzVector p4;
130 p4.setVectM( CLHEP::Hep3Vector( px, py, pz ), mass );
131
132 vtx->add_particle_out( new GenParticle( p4, pdg_code, 1 ) );
133 }
134
135 std::vector<long> seeds{ m_rndm_engine->getSeeds()[0], m_rndm_engine->getSeeds()[1] };
136 evt->set_random_states( seeds );
137
138 // add event to collection
139 McGenEventCol mc_col;
140 mc_col.push_back( new McGenEvent( evt ) );
141 return mc_col;
142 };
double mass
ObjectVector< McGenEvent > McGenEventCol

The documentation for this class was generated from the following file: