7 #include "StSvtEnergySim.hh"
9 StSvtEnergySim::StSvtEnergySim()
11 mNumberOfParticles = 0;
16 StSvtEnergySim::~StSvtEnergySim()
21 void StSvtEnergySim::SetParticle(
int numOfPar,
float maxEnergy)
23 mNumberOfParticles = numOfPar;
24 mMaxEnergy = maxEnergy;
25 mParticle =
new StParticle[mNumberOfParticles];
30 void StSvtEnergySim::CalculateEnAndMom(
char* option,
char* parType)
32 float randNum1 =0, randNum2 = 0;
34 for(
int i = 0; i<mNumberOfParticles; i++)
37 if(parType ==
"proton")
38 mParticle[i].mass = 931.0;
40 randNum1 = 2.0*((float)rand()/(float)RAND_MAX) - 1.0;
42 mParticle[i].theta = acos(randNum1);
44 randNum2 = 2.0*((float)rand()/(float)RAND_MAX) - 1.0;
46 mParticle[i].phi = (float)(2*3.14*randNum2);
48 if(strncmp(option,
"expdev",strlen(
"expdev"))== 0)
49 mParticle[i].energy = mMaxEnergy*Expdev();
50 else if(strncmp(option,
"gausdev",strlen(
"gausdev"))== 0)
51 mParticle[i].energy = mMaxEnergy*Gausdev();
55 mParticle[i].momentum = ::sqrt((mParticle[i].energy )-(mParticle[i].mass*mParticle[i].mass ));
57 mParticle[i].momentumZ = mParticle[i].momentum *cos( mParticle[i].theta);
59 mParticle[i].momentumXY = mParticle[i].momentum *sin( mParticle[i].theta);
61 mParticle[i].momentumX = mParticle[i].momentum *sin( mParticle[i].theta)*cos( mParticle[i].phi);
63 mParticle[i].momentumY = mParticle[i].momentum *sin( mParticle[i].theta)*sin( mParticle[i].phi);
69 float StSvtEnergySim::Expdev(){
74 dum = (float)rand()/(float)RAND_MAX;
80 float StSvtEnergySim::Gausdev()
92 v1 = 2.0*((float)rand()/(float)RAND_MAX) - 1.0;
93 v2 = 2.0*((float)rand()/(float)RAND_MAX) - 1.0;
95 }
while(rsq >= 1.0 || rsq == 1.0);
97 fac = 3.0*::sqrt(-2.0*::log(rsq)/rsq);