92 MsgStream log(messageService(), name());
94 static const bool CREATEIFNOTTHERE(
true);
95 StatusCode RndmStatus = service(
"BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
96 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
98 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
104 const HepPDT::ParticleData* particle =
m_particleTable->particle(HepPDT::ParticleID(
abs(m_pdgCode)));
105 m_mass = particle->mass().value();
112 if(!m_PtGenMode && (m_minPt > m_requestedPt || m_maxPt < m_requestedPt)
113 || m_maxPt < m_minPt ) {
114 log << MSG:: ERROR <<
" Pt min and max out of range. \n" <<
115 " Will set Pt mode to Fixed!!!" << endreq;
118 if(!m_ThetaGenMode && (m_minTheta > m_requestedTheta || m_maxTheta < m_requestedTheta)
119 || m_maxTheta < m_minTheta ) {
120 log << MSG:: ERROR <<
" Theta min and max out of range. \n" <<
121 " Will set Theta mode to Fixed!!!" << endreq;
124 if(!m_PhiGenMode && (m_minPhi > m_requestedPhi || m_maxPhi < m_requestedPhi)
125 || m_maxPhi < m_minPhi ) {
126 log << MSG:: ERROR <<
" Phi min and max out of range. \n" <<
127 " Will set Phi mode to Fixed!!!" << endreq;
132 if(!m_EGenMode && (m_minE > m_requestedE || m_maxE < m_requestedE)
133 || m_maxE < m_minE ) {
134 log << MSG:: ERROR <<
" E min and max out of range. \n" <<
135 " Will set E mode to Fixed!!!" << endreq;
138 if(!m_ThetaGenMode && (m_minTheta > m_requestedTheta || m_maxTheta < m_requestedTheta)
139 || m_maxTheta < m_minTheta ) {
140 log << MSG:: ERROR <<
" Theta min and max out of range. \n" <<
141 " Will set Theta mode to Fixed!!!" << endreq;
144 if(!m_PhiGenMode && (m_minPhi > m_requestedPhi || m_maxPhi < m_requestedPhi)
145 || m_maxPhi < m_minPhi ) {
146 log << MSG:: ERROR <<
" Phi min and max out of range. \n" <<
147 " Will set Phi mode to Fixed!!!" << endreq;
152 return StatusCode::SUCCESS;
161 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->
GetEngine(
"SINGLE");
162 const long*
s = engine->getSeeds();
164 m_seeds.push_back(
s[0]);
165 m_seeds.push_back(
s[1]);
169 double pt,phi,theta,E,px,py,pz,p;
173 pt = generateValue(m_PtGenMode,m_requestedPt, m_sigmaPt,
175 theta = generateValue(m_ThetaGenMode,m_requestedTheta, m_sigmaTheta,
176 m_minTheta, m_maxTheta);
177 phi = generateValue(m_PhiGenMode,m_requestedPhi, m_sigmaPhi,
185 m_fourMom.setVectM(CLHEP::Hep3Vector(px,py,pz),m_mass);
186 m_fourPos.set(m_requestedX,m_requestedY,m_requestedZ,m_requestedT);
187 return StatusCode::SUCCESS;
190 E = generateValue(m_EGenMode,m_requestedE, m_sigmaE,
192 theta = generateValue(m_ThetaGenMode,m_requestedTheta, m_sigmaTheta,
193 m_minTheta, m_maxTheta);
194 phi = generateValue(m_PhiGenMode,m_requestedPhi, m_sigmaPhi,
199 if(E*E-m_mass*m_mass < 0.){
200 MsgStream log(messageService(), name());
201 log << MSG::ERROR <<
"You have Generated a Tachyon!! Increase energy or change particle ID" << endreq;
202return StatusCode::FAILURE;
204 p=sqrt(E*E-m_mass*m_mass);
205 px = p*
sin(theta)*
cos(phi);
206 py = p*
sin(theta)*
sin(phi);
209 m_fourMom.setVectM(CLHEP::Hep3Vector(px,py,pz),m_mass);
210 m_fourPos.set(m_requestedX,m_requestedY,m_requestedZ,m_requestedT);
211 return StatusCode::SUCCESS;
213 return StatusCode::SUCCESS;
227 evt->set_event_number(m_events);
228 GenVertex* v1 =
new GenVertex(m_fourPos);
230 std::cout <<
" SingleParticleGun::fillEvt --> " <<std::endl;
231 std::cout <<
" Event number:: " << m_events << std::endl;
232 std::cout <<
" vertex.x = " << m_fourPos.x()
233 <<
" vertex.y = " << m_fourPos.y()
234 <<
" vertex.z = " << m_fourPos.z()
235 <<
" vertex.t = " << m_fourPos.t() << std::endl;
237 std::cout <<
" momentum.x = " << m_fourMom.x()
238 <<
" momentum.y = " << m_fourMom.y()
239 <<
" momentum.z = " << m_fourMom.z()
240 <<
" momentum.t = " << m_fourMom.t() << std::endl;
242 evt->add_vertex( v1 );
245 v1->add_particle_out(
new GenParticle( m_fourMom, m_pdgCode,1) );
247 std::cout <<
" particles_size = " << evt->particles_size()
248 <<
" vertices_size = " << evt->vertices_size()
251 evt->set_signal_process_id(
SINGLE);
252 evt->set_random_states(m_seeds);
254 return StatusCode::SUCCESS;
virtual StatusCode fillEvt(GenEvent *evt)
virtual StatusCode genFinalize()
virtual StatusCode genInitialize()
virtual StatusCode callGenerator()
SingleParticleGun(const std::string &name, ISvcLocator *pSvcLocator)
virtual ~SingleParticleGun()