CGEM BOSS 6.6.5.f
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
11#include "BesPrimaryGeneratorAction.hh"
12#include "BesPrimaryGeneratorMessenger.hh"
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
25{
26 nParticle = 1;
27 particleName = "pi-";
28 minCos = -0.8;
29 maxCos = 0.8;
30 phiStart = 0.;
31 phiEnd = 360.;
32 pMomentum = 1.;
33 deltaP = 0.;
34 posX=0;
35 posY=0;
36 posZ=0;
37
38 particleGun = new G4ParticleGun(1);
39 isGenbes = true;
40 HEPEvt = 0;
41 generatorName = "tester";
42 //TESTER parameters passed by this messenger
43 messenger = new BesPrimaryGeneratorMessenger(this);
44
45 if(generatorName == "cosmic")
46 {
47 std::string path = getenv("GENSIMROOT");
48 G4cout<<"path: "<<path<<G4endl;
49
50 path += "/root/";
51 std::string pFile = path + "ppdc.root";
52 std::string thetaFile = path + "theta.root";
53 std::string phiFile = path +"phi.root";
54
55 TFile* f1 = new TFile(pFile.c_str());
56 h1 = (TH1F*)f1->Get("htemp");
57
58 TFile* f2 = new TFile(thetaFile.c_str());
59 h2 = (TH1F*)f2->Get("htemp");
60
61 TFile* f3 = new TFile(phiFile.c_str());
62 h3 = (TH1F*)f3->Get("htemp");
63
64 //ftest = new TFile("ftest.root","recreate");
65 //tuple = new TNtuple("test","test","p:theta:phi");
66 //counter = 0;
67 }
68}
69
71{
72 delete particleGun;
73 if(messenger) delete messenger;
74 if(generatorName=="genbes")delete HEPEvt;
75}
76
78{
79 if(generatorName=="tester")
80 {
81 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
82 G4ParticleDefinition* particle
83 = particleTable->FindParticle(particleName);
84 particleGun->SetParticleDefinition(particle);
85 particleGun->SetParticlePosition(G4ThreeVector(posX,posY,posZ));
86
87 //set TESTER parameters
88 for(G4int i=0; i<nParticle; i++)
89 {
90 G4double pMag = pMomentum;
91 //randomize p
92 if(deltaP>0.)pMag = pMomentum - deltaP*(1.0 - 2.0*G4UniformRand());
93 pMag = pMag*GeV;
94 //randomize cos(theta)
95 G4double costheta = minCos +(maxCos - minCos)*G4UniformRand();
96 //randomize phi
97 G4double phi = phiStart+(phiEnd-phiStart)*G4UniformRand();
98 phi = phi*degree;
99 G4double sintheta = sqrt(1.-costheta*costheta);
100 //computer 3-vector momentum
101 G4ParticleMomentum aMomentum;
102 aMomentum[0] = pMag*sintheta*cos(phi);
103 aMomentum[1] = pMag*sintheta*sin(phi);
104 aMomentum[2] = pMag*costheta;
105 //use ParticleGun to generate event
106 particleGun->SetParticleMomentum(aMomentum);
107 particleGun->GeneratePrimaryVertex(anEvent);
108 }
109 }
110 else if(generatorName=="cosmic")
111 {
112 G4cout<<"generatorName: "<<generatorName<<G4endl;
113 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
114 G4ParticleDefinition* particle
115 = particleTable->FindParticle(particleName);
116 G4cout<<"particleName: "<<particleName<<G4endl;
117
118 particleGun->SetParticleDefinition(particle);
119 particleGun->SetParticlePosition(G4ThreeVector(posX,posY,posZ));
120
121 /*std::string path = getenv("GENSIMROOT");
122 G4cout<<"path: "<<path<<G4endl;
123
124 path += "/root/";
125 std::string pFile = path + "ppdc.root";
126 std::string thetaFile = path + "theta.root";
127 std::string phiFile = path +"phi.root";*/
128
129 //TFile* f1 = new TFile(pFile.c_str());
130 //H1F* h1 = (TH1F*)f1->Get("htemp");
131 G4double pMag = h1->GetRandom()*GeV;
132 G4cout<<"pMag: "<<pMag<<G4endl;
133 //f1->Close();
134
135 //TFile* f2 = new TFile(thetaFile.c_str());
136 //TH1F* h2 = (TH1F*)f2->Get("htemp");
137 //randomize cos(theta)
138 G4double theta =(Double_t)h2->GetRandom();
139 G4cout<<"theta: "<<theta<<G4endl;
140 G4double costheta = cos(theta);
141 //f2->Close();
142
143 //TFile* f3 = new TFile(phiFile.c_str());
144 //TH1F* h3 = (TH1F*)f3->Get("htemp");
145 //randomize phi
146 G4double phi = (Double_t)h3->GetRandom();
147 G4cout<<"phi: "<<phi<<G4endl;
148 //f3->Close();
149
150 //f1->Close();
151 //f2->Close();
152 //f3->Close();
153 //ftest->ReOpen("update");
154 //tuple->Fill(pMag,theta,phi);
155 //counter++;
156 //if(counter==2000)
157 // tuple->Write();
158
159 G4double sintheta = sqrt(1.-costheta*costheta);
160 //computer 3-vector momentum
161 G4ParticleMomentum aMomentum;
162 aMomentum[0] = pMag*sintheta*cos(phi);
163 aMomentum[1] = pMag*sintheta*sin(phi);
164 aMomentum[2] = pMag*costheta;
165 //use ParticleGun to generate event
166 particleGun->SetParticleMomentum(aMomentum);
167 particleGun->GeneratePrimaryVertex(anEvent);
168 }
169
170 else if(generatorName=="genbes")
171 {
172 G4cout<<"genbes called"<<G4endl;
173 if(isGenbes)
174 {
175 isGenbes=false;
176 HEPEvt=new G4HEPEvtInterface(genbesName);
177 }
178 HEPEvt->GeneratePrimaryVertex(anEvent);
179 }
180}
181
TFile * f1
double sin(const BesAngle a)
double cos(const BesAngle a)
void GeneratePrimaries(G4Event *anEvent)