BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesPrimaryGeneratorAction Class Reference

#include <BesPrimaryGeneratorAction.hh>

+ Inheritance diagram for BesPrimaryGeneratorAction:

Public Member Functions

 BesPrimaryGeneratorAction ()
 
 ~BesPrimaryGeneratorAction ()
 
void GeneratePrimaries (G4Event *anEvent)
 
G4String GetGeneratorName ()
 
void SetGeneratorName (G4String genNew)
 
G4String GetGenbesName ()
 
void SetGenbesName (G4String genbesNew)
 
void SetNParticle (G4int np)
 
void SetParticleName (G4String pname)
 
void SetMinCos (G4double min1)
 
void SetMaxCos (G4double max1)
 
void SetPhiStart (G4double ps)
 
void SetPhiEnd (G4double pe)
 
void SetMomentum (G4double pm)
 
void SetDeltaP (G4double dp)
 
void SetPosX (G4double x)
 
void SetPosY (G4double y)
 
void SetPosZ (G4double z)
 

Detailed Description

Definition at line 26 of file BesPrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

◆ BesPrimaryGeneratorAction()

BesPrimaryGeneratorAction::BesPrimaryGeneratorAction ( )

Definition at line 26 of file BesPrimaryGeneratorAction.cc.

27{
28 nParticle = 1;
29 particleName = "pi-";
30 minCos = -0.8;
31 maxCos = 0.8;
32 phiStart = 0.;
33 phiEnd = 360.;
34 pMomentum = 1.;
35 deltaP = 0.;
36 posX=0;
37 posY=0;
38 posZ=0;
39
40 particleGun = new G4ParticleGun(1);
41 isGenbes = true;
42 HEPEvt = 0;
43 generatorName = "tester";
44 //TESTER parameters passed by this messenger
45 messenger = new BesPrimaryGeneratorMessenger(this);
46
47 if(generatorName == "cosmic")
48 {
49 std::string path = getenv("GENSIMROOT");
50 G4cout<<"path: "<<path<<G4endl;
51
52 path += "/root/";
53 std::string pFile = path + "ppdc.root";
54 std::string thetaFile = path + "theta.root";
55 std::string phiFile = path +"phi.root";
56
57 TFile* f1 = new TFile(pFile.c_str());
58 h1 = (TH1F*)f1->Get("htemp");
59
60 TFile* f2 = new TFile(thetaFile.c_str());
61 h2 = (TH1F*)f2->Get("htemp");
62
63 TFile* f3 = new TFile(phiFile.c_str());
64 h3 = (TH1F*)f3->Get("htemp");
65
66 //ftest = new TFile("ftest.root","recreate");
67 //tuple = new TNtuple("test","test","p:theta:phi");
68 //counter = 0;
69 }
70}
TFile * f1

◆ ~BesPrimaryGeneratorAction()

BesPrimaryGeneratorAction::~BesPrimaryGeneratorAction ( )

Definition at line 72 of file BesPrimaryGeneratorAction.cc.

73{
74 delete particleGun;
75 if(messenger) delete messenger;
76 if(generatorName=="genbes")delete HEPEvt;
77}

Member Function Documentation

◆ GeneratePrimaries()

void BesPrimaryGeneratorAction::GeneratePrimaries ( G4Event *  anEvent)

Definition at line 79 of file BesPrimaryGeneratorAction.cc.

80{
81 if(generatorName=="tester")
82 {
83 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
84 G4ParticleDefinition* particle
85 = particleTable->FindParticle(particleName);
86 particleGun->SetParticleDefinition(particle);
87 particleGun->SetParticlePosition(G4ThreeVector(posX,posY,posZ));
88 particleGun->SetParticleTime(648*ns);
89
90 //set TESTER parameters
91 for(G4int i=0; i<nParticle; i++)
92 {
93 G4double pMag = pMomentum;
94 //randomize p
95 if(deltaP>0.)pMag = pMomentum - deltaP*(1.0 - 2.0*G4UniformRand());
96 pMag = pMag*GeV;
97 //randomize cos(theta)
98 G4double costheta = minCos +(maxCos - minCos)*G4UniformRand();
99 //randomize phi
100 G4double phi = phiStart+(phiEnd-phiStart)*G4UniformRand();
101 phi = phi*degree;
102 G4double sintheta = sqrt(1.-costheta*costheta);
103 //computer 3-vector momentum
104 G4ParticleMomentum aMomentum;
105 aMomentum[0] = pMag*sintheta*cos(phi);
106 aMomentum[1] = pMag*sintheta*sin(phi);
107 aMomentum[2] = pMag*costheta;
108 //use ParticleGun to generate event
109 particleGun->SetParticleMomentum(aMomentum);
110 particleGun->GeneratePrimaryVertex(anEvent);
111 }
112 }
113 else if(generatorName=="cosmic")
114 {
115 G4cout<<"generatorName: "<<generatorName<<G4endl;
116 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
117 G4ParticleDefinition* particle
118 = particleTable->FindParticle(particleName);
119 G4cout<<"particleName: "<<particleName<<G4endl;
120
121 particleGun->SetParticleDefinition(particle);
122 particleGun->SetParticlePosition(G4ThreeVector(posX,posY,posZ));
123
124 /*std::string path = getenv("GENSIMROOT");
125 G4cout<<"path: "<<path<<G4endl;
126
127 path += "/root/";
128 std::string pFile = path + "ppdc.root";
129 std::string thetaFile = path + "theta.root";
130 std::string phiFile = path +"phi.root";*/
131
132 //TFile* f1 = new TFile(pFile.c_str());
133 //H1F* h1 = (TH1F*)f1->Get("htemp");
134 G4double pMag = h1->GetRandom()*GeV;
135 G4cout<<"pMag: "<<pMag<<G4endl;
136 //f1->Close();
137
138 //TFile* f2 = new TFile(thetaFile.c_str());
139 //TH1F* h2 = (TH1F*)f2->Get("htemp");
140 //randomize cos(theta)
141 G4double theta =(Double_t)h2->GetRandom();
142 G4cout<<"theta: "<<theta<<G4endl;
143 G4double costheta = cos(theta);
144 //f2->Close();
145
146 //TFile* f3 = new TFile(phiFile.c_str());
147 //TH1F* h3 = (TH1F*)f3->Get("htemp");
148 //randomize phi
149 G4double phi = (Double_t)h3->GetRandom();
150 G4cout<<"phi: "<<phi<<G4endl;
151 //f3->Close();
152
153 //f1->Close();
154 //f2->Close();
155 //f3->Close();
156 //ftest->ReOpen("update");
157 //tuple->Fill(pMag,theta,phi);
158 //counter++;
159 //if(counter==2000)
160 // tuple->Write();
161
162 G4double sintheta = sqrt(1.-costheta*costheta);
163 //computer 3-vector momentum
164 G4ParticleMomentum aMomentum;
165 aMomentum[0] = pMag*sintheta*cos(phi);
166 aMomentum[1] = pMag*sintheta*sin(phi);
167 aMomentum[2] = pMag*costheta;
168 //use ParticleGun to generate event
169 particleGun->SetParticleMomentum(aMomentum);
170 particleGun->GeneratePrimaryVertex(anEvent);
171 }
172
173 else if(generatorName=="genbes")
174 {
175 G4cout<<"genbes called"<<G4endl;
176 if(isGenbes)
177 {
178 isGenbes=false;
179 HEPEvt=new G4HEPEvtInterface(genbesName);
180 }
181 HEPEvt->SetParticleTime(648*ns);
182 HEPEvt->GeneratePrimaryVertex(anEvent);
183 }
184}
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
float costheta
#define ns(x)
Definition: xmltok.c:1504

◆ GetGenbesName()

G4String BesPrimaryGeneratorAction::GetGenbesName ( )
inline

Definition at line 39 of file BesPrimaryGeneratorAction.hh.

39{return genbesName;}

Referenced by BesPrimaryGeneratorMessenger::GetCurrentValue().

◆ GetGeneratorName()

G4String BesPrimaryGeneratorAction::GetGeneratorName ( )
inline

Definition at line 37 of file BesPrimaryGeneratorAction.hh.

37{return generatorName;}

Referenced by BesPrimaryGeneratorMessenger::GetCurrentValue().

◆ SetDeltaP()

void BesPrimaryGeneratorAction::SetDeltaP ( G4double  dp)
inline

Definition at line 48 of file BesPrimaryGeneratorAction.hh.

48{deltaP = dp;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetGenbesName()

void BesPrimaryGeneratorAction::SetGenbesName ( G4String  genbesNew)
inline

Definition at line 40 of file BesPrimaryGeneratorAction.hh.

40{genbesName=genbesNew;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetGeneratorName()

void BesPrimaryGeneratorAction::SetGeneratorName ( G4String  genNew)
inline

Definition at line 38 of file BesPrimaryGeneratorAction.hh.

38{generatorName=genNew;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetMaxCos()

void BesPrimaryGeneratorAction::SetMaxCos ( G4double  max1)
inline

Definition at line 44 of file BesPrimaryGeneratorAction.hh.

44{maxCos = max1;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetMinCos()

void BesPrimaryGeneratorAction::SetMinCos ( G4double  min1)
inline

Definition at line 43 of file BesPrimaryGeneratorAction.hh.

43{minCos = min1;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetMomentum()

void BesPrimaryGeneratorAction::SetMomentum ( G4double  pm)
inline

Definition at line 47 of file BesPrimaryGeneratorAction.hh.

47{pMomentum = pm;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetNParticle()

void BesPrimaryGeneratorAction::SetNParticle ( G4int  np)
inline

Definition at line 41 of file BesPrimaryGeneratorAction.hh.

41{nParticle = np;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetParticleName()

void BesPrimaryGeneratorAction::SetParticleName ( G4String  pname)
inline

Definition at line 42 of file BesPrimaryGeneratorAction.hh.

42{particleName = pname;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetPhiEnd()

void BesPrimaryGeneratorAction::SetPhiEnd ( G4double  pe)
inline

Definition at line 46 of file BesPrimaryGeneratorAction.hh.

46{phiEnd = pe;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetPhiStart()

void BesPrimaryGeneratorAction::SetPhiStart ( G4double  ps)
inline

Definition at line 45 of file BesPrimaryGeneratorAction.hh.

45{phiStart =ps;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetPosX()

void BesPrimaryGeneratorAction::SetPosX ( G4double  x)
inline

Definition at line 49 of file BesPrimaryGeneratorAction.hh.

49{posX = x;}
Double_t x[10]

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetPosY()

void BesPrimaryGeneratorAction::SetPosY ( G4double  y)
inline

Definition at line 50 of file BesPrimaryGeneratorAction.hh.

50{posY = y;}
double y[1000]

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().

◆ SetPosZ()

void BesPrimaryGeneratorAction::SetPosZ ( G4double  z)
inline

Definition at line 51 of file BesPrimaryGeneratorAction.hh.

51{posZ = z;}

Referenced by BesPrimaryGeneratorMessenger::SetNewValue().


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