93 MsgStream log(messageService(), name());
95 static const bool CREATEIFNOTTHERE(
true);
96 StatusCode RndmStatus = service(
"BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
97 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
99 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
105 const HepPDT::ParticleData* particle =
m_particleTable->particle(HepPDT::ParticleID(
abs(m_pdgCode)));
107 m_mass = particle?particle->mass().value():0;
114 if(!m_PtGenMode && (m_minPt > m_requestedPt || m_maxPt < m_requestedPt)
115 || m_maxPt < m_minPt ) {
116 log << MSG:: ERROR <<
" Pt min and max out of range. \n" <<
117 " Will set Pt mode to Fixed!!!" << endreq;
120 if(!m_ThetaGenMode && (m_minTheta > m_requestedTheta || m_maxTheta < m_requestedTheta)
121 || m_maxTheta < m_minTheta ) {
122 log << MSG:: ERROR <<
" Theta min and max out of range. \n" <<
123 " Will set Theta mode to Fixed!!!" << endreq;
126 if(!m_PhiGenMode && (m_minPhi > m_requestedPhi || m_maxPhi < m_requestedPhi)
127 || m_maxPhi < m_minPhi ) {
128 log << MSG:: ERROR <<
" Phi min and max out of range. \n" <<
129 " Will set Phi mode to Fixed!!!" << endreq;
134 if(!m_EGenMode && (m_minE > m_requestedE || m_maxE < m_requestedE)
135 || m_maxE < m_minE ) {
136 log << MSG:: ERROR <<
" E min and max out of range. \n" <<
137 " Will set E mode to Fixed!!!" << endreq;
140 if(!m_ThetaGenMode && (m_minTheta > m_requestedTheta || m_maxTheta < m_requestedTheta)
141 || m_maxTheta < m_minTheta ) {
142 log << MSG:: ERROR <<
" Theta min and max out of range. \n" <<
143 " Will set Theta mode to Fixed!!!" << endreq;
146 if(!m_PhiGenMode && (m_minPhi > m_requestedPhi || m_maxPhi < m_requestedPhi)
147 || m_maxPhi < m_minPhi ) {
148 log << MSG:: ERROR <<
" Phi min and max out of range. \n" <<
149 " Will set Phi mode to Fixed!!!" << endreq;
154 return StatusCode::SUCCESS;
163 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->
GetEngine(
"SINGLE");
164 const long*
s = engine->getSeeds();
166 m_seeds.push_back(
s[0]);
167 m_seeds.push_back(
s[1]);
171 double pt,phi,theta,E,px,py,pz,p;
175 pt = generateValue(m_PtGenMode,m_requestedPt, m_sigmaPt,
177 theta = generateValue(m_ThetaGenMode,m_requestedTheta, m_sigmaTheta,
178 m_minTheta, m_maxTheta);
179 phi = generateValue(m_PhiGenMode,m_requestedPhi, m_sigmaPhi,
187 m_fourMom.setVectM(CLHEP::Hep3Vector(px,py,pz),m_mass);
188 m_fourPos.set(m_requestedX,m_requestedY,m_requestedZ,m_requestedT);
189 return StatusCode::SUCCESS;
192 E = generateValue(m_EGenMode,m_requestedE, m_sigmaE,
194 theta = generateValue(m_ThetaGenMode,m_requestedTheta, m_sigmaTheta,
195 m_minTheta, m_maxTheta);
196 phi = generateValue(m_PhiGenMode,m_requestedPhi, m_sigmaPhi,
201 if(E*E-m_mass*m_mass < 0.){
202 MsgStream log(messageService(), name());
203 log << MSG::ERROR <<
"You have Generated a Tachyon!! Increase energy or change particle ID" << endreq;
204return StatusCode::FAILURE;
206 p=sqrt(E*E-m_mass*m_mass);
207 px = p*
sin(theta)*
cos(phi);
208 py = p*
sin(theta)*
sin(phi);
211 m_fourMom.setVectM(CLHEP::Hep3Vector(px,py,pz),m_mass);
212 m_fourPos.set(m_requestedX,m_requestedY,m_requestedZ,m_requestedT);
213 return StatusCode::SUCCESS;
215 return StatusCode::SUCCESS;
229 evt->set_event_number(m_events);
230 GenVertex* v1 =
new GenVertex(m_fourPos);
232 std::cout <<
" SingleParticleGun::fillEvt --> " <<std::endl;
233 std::cout <<
" Event number:: " << m_events << std::endl;
234 std::cout <<
" vertex.x = " << m_fourPos.x()
235 <<
" vertex.y = " << m_fourPos.y()
236 <<
" vertex.z = " << m_fourPos.z()
237 <<
" vertex.t = " << m_fourPos.t() << std::endl;
239 std::cout <<
" momentum.x = " << m_fourMom.x()
240 <<
" momentum.y = " << m_fourMom.y()
241 <<
" momentum.z = " << m_fourMom.z()
242 <<
" momentum.t = " << m_fourMom.t() << std::endl;
244 evt->add_vertex( v1 );
247 v1->add_particle_out(
new GenParticle( m_fourMom, m_pdgCode,1) );
249 std::cout <<
" particles_size = " << evt->particles_size()
250 <<
" vertices_size = " << evt->vertices_size()
253 evt->set_signal_process_id(
SINGLE);
254 evt->set_random_states(m_seeds);
256 return StatusCode::SUCCESS;
virtual StatusCode fillEvt(GenEvent *evt)
virtual StatusCode genFinalize()
virtual StatusCode genInitialize()
virtual StatusCode callGenerator()
virtual ~SingleParticleGun()