BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
BesPrimaryGeneratorAction.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2// BOOST --- BESIII Object_Oriented Simulation Tool //
3//---------------------------------------------------------------------------//
4//Description: Mimic the BES generator, TESTER
5//Author: Liuhm
6//Created: June, 2003
7//Modified: Liuhm, 7 April, 2004, re-randomize phi distribution
8//Comment: Use Geant4 ParticleGun
9//---------------------------------------------------------------------------//
10
13#include "globals.hh"
14#include "G4Event.hh"
15#include "G4ParticleGun.hh"
16#include "G4ParticleTable.hh"
17#include "G4ParticleDefinition.hh"
18#include "G4ParticleMomentum.hh"
19#include "Randomize.hh"
20#include "G4HEPEvtInterface.hh"
21#include "TFile.h"
22#include "TH1F.h"
23
24using namespace CLHEP;
25
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}
71
73{
74 delete particleGun;
75 if(messenger) delete messenger;
76 if(generatorName=="genbes")delete HEPEvt;
77}
78
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}
185
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
TFile * f1
void GeneratePrimaries(G4Event *anEvent)
float costheta
#define ns(x)
Definition xmltok.c:1504