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