1 #include "StarKinematics.h"
2 #include "StarGenerator/EVENT/StarGenEvent.h"
3 #include "StarGenerator/EVENT/StarGenParticle.h"
4 #include "StarGenerator/UTIL/StarParticleData.h"
5 #include "StarGenerator/UTIL/StarRandom.h"
12 #define random myrandom
17 vector<string> split(
const string &s,
const string &sep_chars)
19 string::size_type prev_pos = 0, pos = 0;
20 vector<string> result;
22 while ((pos = s.find_first_of(sep_chars, pos)) != string::npos) {
23 result.push_back(s.substr(prev_pos, pos - prev_pos));
27 result.push_back(s.substr(prev_pos));
38 static std::random_device _stl_rd;
39 static std::mt19937 _mt19937( _stl_rd() );
45 StarKinematics::StarKinematics(
const Char_t *name ) :
StarGenerator(name)
85 TParticlePDG *pdg = data(type); assert(pdg);
86 Int_t
id = pdg->PdgCode();
95 Double_t ylow, Double_t yhigh,
96 Double_t philow, Double_t phihigh )
99 std::string type = _type;
100 std::vector<std::string> types = split(_type,
", ");
102 for ( Int_t i=0;i<ntrack;i++ )
105 std::shuffle( types.begin(), types.end(), _mt19937 );
111 if ( 0 == IAttr(
"energy") ) {
112 double pt = random(ptlow, pthigh);
113 double y = random(ylow, yhigh );
114 double phi= random(philow, phihigh );
118 if ( IAttr(
"rapidity" ) ) {
120 mt = TMath::Sqrt( pt*pt + m*m );
123 double px = pt * TMath::Cos( phi );
124 double py = pt * TMath::Sin( phi );
125 double pz = mt * TMath::SinH( y );
126 double E = mt * TMath::CosH( y );
138 if ( IAttr(
"energy") ) {
140 assert( 0==IAttr(
"rapidity") );
142 double E = random(ptlow, pthigh);
143 double y = random(ylow, yhigh );
144 double phi= random(philow, phihigh );
146 double pmom = TMath::Sqrt(E*E - m*m);
147 double pt = 2.0 * pmom * TMath::Exp( -y ) / ( 1 + TMath::Exp( -2.0*y ) );
150 if ( IAttr(
"rapidity" ) ) {
152 mt = TMath::Sqrt( pt*pt + m*m );
155 double px = pt * TMath::Cos( phi );
156 double py = pt * TMath::Sin( phi );
157 double pz = mt * TMath::SinH( y );
179 std::string type = _type;
180 std::vector<std::string> types = split(_type,
", ");
182 for ( Int_t i=0; i<ntrack; i++ )
185 std::shuffle( types.begin(), types.end(), _mt19937 );
190 Double_t pt = ptFunc -> GetRandom();
191 Double_t y = etaFunc -> GetRandom();
192 Double_t phi = (phiFunc) ? phiFunc->GetRandom() : random( 0., TMath::TwoPi() );
196 if ( IAttr(
"rapidity" ) ) {
198 mt = TMath::Sqrt( pt*pt + m*m );
201 double px = pt * TMath::Cos( phi );
202 double py = pt * TMath::Sin( phi );
203 double pz = mt * TMath::SinH( y );
204 double E = mt * TMath::CosH( y );
221 std::string type = _type;
222 std::vector<std::string> types = split(_type,
", ");
224 for ( Int_t i=0; i<ntrack; i++ )
227 std::shuffle( types.begin(), types.end(), _mt19937 );
232 Double_t pt = ptFunc -> GetRandom();
233 Double_t y = etaFunc -> GetRandom();
234 Double_t phi = (phiFunc) ? phiFunc->GetRandom() : random( 0., TMath::TwoPi() );
238 if ( IAttr(
"rapidity" ) ) {
240 mt = TMath::Sqrt( pt*pt + m*m );
243 double px = pt * TMath::Cos( phi );
244 double py = pt * TMath::Sin( phi );
245 double pz = mt * TMath::SinH( y );
246 double E = mt * TMath::CosH( y );
261 const double deg2rad = TMath::DegToRad();
263 void StarKinematics::Cosmic(
int ntrack,
const char* _type,
double plow,
double phigh,
double radius,
double zmin,
double zmax,
double dphi )
265 std::string type = _type;
266 std::vector<std::string> types = split(_type,
", ");
268 for ( Int_t i=0; i<ntrack; i++ )
271 std::shuffle( types.begin(), types.end(), _mt19937 );
277 double zvertex = random( zmin, zmax );
278 double phi = random( 0.0, TMath::TwoPi() );
279 double xvertex = radius * TMath::Cos(phi);
280 double yvertex = radius * TMath::Sin(phi);
287 TVector3
vertex(xvertex,yvertex,0);
290 TVector3 direct = vertex.Unit();
293 double pmag = random(plow, phigh);
296 _momentum = -pmag * direct;
299 phi = _momentum.Phi() + deg2rad * random( -dphi, +dphi );
300 double theta = _momentum.Theta() + deg2rad * random( -dphi, +dphi );
302 _momentum.SetPhi(phi);
303 _momentum.SetTheta(theta);
307 Double_t E2 = _momentum.Mag2() + m*m;
308 Double_t E = sqrt(E2);
310 p->
SetPx( _momentum.Px() );
311 p->
SetPy( _momentum.Py() );
312 p->
SetPz( _momentum.Pz() );
StarGenParticle * AddParticle()
Int_t PreGenerate()
Developers may provide a pre-generate method which will execute before Generate().
void SetPx(Float_t px)
Set the x-component of the momentum.
static StarRandom & Instance()
Obtain the single instance of the random number generator.
Int_t GetNumberOfParticles()
Obtain the number of particles in the event record.
void SetVy(Float_t vy)
Set the y-component of the start vertex.
Yet another particle class.
Int_t PostGenerate()
Developers may provide a post-generate method which will execute after Generate().
ABC for defining event generator interfaces.
StarGenEvent * mEvent
Generated event.
void SetVz(Float_t vz)
Set the z-component of the start vertex.
void SetVx(Float_t vx)
Set the x-component of the start vertex.
virtual void Clear(const Option_t *opts="part,data")
Clear the event.
static StarParticleData & instance()
Returns a reference to the single instance of this class.
Interface to PDG information.
void SetStatus(Int_t status)
Set the status code of the particle according to the HEPEVT standard.
void Dist(Int_t ntrack, const Char_t *type, TF1 *pt, TF1 *y, TF1 *phi=0)
void SetPz(Float_t pz)
Set the z-component of the momentum.
A class for providing random number generation.
void SetMass(Float_t mass)
Set the mass.
Int_t Generate()
Generate event.
void SetTof(Float_t tof)
Set the tof.
Base class for event records.
void Cosmic(int ntrack, const char *type="mu+", double plow=3.0, double phigh=10.0, double radius=300.0, double zmin=-3.0, double zmax=+3.0, double dtheta=15.0)
void SetPy(Float_t py)
Set the y-component of the momentum.
void SetEnergy(Float_t energy)
Set the energy.
Float_t GetMass()
Get the mass.
void Kine(Int_t ntrack, const Char_t *type="pi+,pi-,K+,K-,proton,antiproton", Double_t ptlow=0.0, Double_t pthigh=500.0, Double_t ylow=-10.0, Double_t yhigh=+10.0, Double_t philow=0.0, Double_t phihigh=TMath::TwoPi())
StarGenParticle * AddParticle()