Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Fun4All_MCEventGen.C
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file Fun4All_MCEventGen.C
1
2
int
Fun4All_MCEventGen
(
3
const
int
nEvents
= 100,
4
const
char
* outputFile =
"G4MCEventGen.root"
5
)
6
{
7
//===============
8
// Input options
9
//===============
10
11
// read files in HepMC format (typically output from event generators like hijing or pythia)
12
const
bool
readhepmc =
false
;
// read HepMC files
13
14
// read files in EICTree format generated by eicsmear package
15
const
bool
readeictree =
false
;
16
17
// Use particle generator Pythia 8
18
const
bool
runpythia8 =
false
;
19
20
// Use particle generator Pythia 6
21
const
bool
runpythia6 =
true
;
22
const
char
* pythia6configfile =
"config_pythia6/phpythia6_ep.cfg"
;
23
24
// Use particle generator HEPGen
25
const
bool
runhepgen =
false
;
26
27
// Use particle generator Sartre
28
const
bool
runsartre =
false
;
29
30
// Other options
31
const
bool
do_dst_compress =
true
;
32
33
// Option to save DST output file (for later use with Genat4 simulation)
34
const
bool
do_DSTOutput =
true
;
35
36
// Option to convert DST to human command readable TTree for quick poke around the outputs
37
const
bool
do_DSTReader =
false
;
38
39
// Option to save events in ASCII HepMC format
40
const
bool
do_ASCIIOutput =
false
;
41
42
43
//---------------
44
// Load libraries
45
//---------------
46
gSystem->Load(
"libfun4all.so"
);
47
gSystem->Load(
"libphhepmc.so"
);
48
gSystem->Load(
"libg4detectors.so"
);
49
gSystem->Load(
"libg4eval.so"
);
50
51
//---------------
52
// Fun4All server
53
//---------------
54
Fun4AllServer
*se =
Fun4AllServer::instance
();
55
se->
Verbosity
(0);
// uncomment for batch production running with minimal output messages
56
// se->Verbosity(Fun4AllServer::VERBOSITY_SOME); // uncomment for some info for interactive running
57
58
// just if we set some flags somewhere in this macro
59
recoConsts
*rc =
recoConsts::instance
();
60
// By default every random number generator uses
61
// PHRandomSeed() which reads /dev/urandom to get its seed
62
// if the RANDOMSEED flag is set its value is taken as seed
63
// You can either set this to a random value using PHRandomSeed()
64
// which will make all seeds identical (not sure what the point of
65
// this would be:
66
// rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
67
// or set it to a fixed value so you can debug your code
68
// rc->set_IntFlag("RANDOMSEED", 12345);
69
70
/* Set world parameters in reco consts */
71
rc->
set_FloatFlag
(
"WorldSizex"
, 1000.);
72
rc->
set_FloatFlag
(
"WorldSizey"
, 1000.);
73
rc->
set_FloatFlag
(
"WorldSizez"
, 1000.);
74
rc->set_CharFlag(
"WorldShape"
,
"G4Tubs"
);
75
76
77
//-----------------
78
// Event generation
79
//-----------------
80
81
if
(readhepmc)
82
{
83
}
84
else
if
(readeictree)
85
{
86
// this module is needed to read the EICTree style records into our G4 sims
87
ReadEICFiles
*eicr =
new
ReadEICFiles
();
88
eicr->
OpenInputFile
(
"data/eictree_milou_dvcs_10x250.root"
);
89
90
se->
registerSubsystem
(eicr);
91
}
92
else
if
(runpythia8)
93
{
94
gSystem->Load(
"libPHPythia8.so"
);
95
96
PHPythia8
* pythia8 =
new
PHPythia8
();
97
// see coresoftware/generators/PHPythia8 for example config
98
pythia8->
set_config_file
(
"phpythia8.cfg"
);
99
se->
registerSubsystem
(pythia8);
100
}
101
else
if
(runpythia6)
102
{
103
gSystem->Load(
"libPHPythia6.so"
);
104
105
PHPythia6
*pythia6 =
new
PHPythia6
();
106
pythia6->
set_config_file
( pythia6configfile );
107
se->
registerSubsystem
(pythia6);
108
}
109
else
if
(runhepgen)
110
{
111
gSystem->Load(
"libsHEPGen.so"
);
112
113
sHEPGen
*hepgen =
new
sHEPGen
();
114
hepgen->
set_datacard_file
(
"config/hepgen_eic_dvcs.data"
);
115
hepgen->
set_momentum_electron
(-10);
116
hepgen->
set_momentum_hadron
(250);
117
se->
registerSubsystem
(hepgen);
118
}
119
else
if
(runsartre)
120
{
121
// see coresoftware/generators/PHSartre/README for setup instructions
122
// before running:
123
// setenv SARTRE_DIR /opt/sphenix/core/sartre-1.20_root-5.34.36
124
gSystem->Load(
"libPHSartre.so"
);
125
126
PHSartre
* mysartre =
new
PHSartre
();
127
// see coresoftware/generators/PHSartre for example config
128
mysartre->
set_config_file
(
"config/sartre_ep.cfg"
);
129
130
// particle trigger to enhance forward J/Psi -> ee
131
//PHSartreParticleTrigger* pTrig = new PHSartreParticleTrigger("MySartreTrigger");
132
//pTrig->AddParticles(-11);
133
//pTrig->SetEtaHighLow(4.0,1.4);
134
//pTrig->SetEtaHighLow(1.0,-1.1); // central arm
135
//pTrig->PrintConfig();
136
//mysartre->register_trigger((PHSartreGenTrigger *)pTrig);
137
se->
registerSubsystem
(mysartre);
138
}
139
140
/* Write DST output file */
141
if
( do_DSTOutput )
142
{
143
Fun4AllDstOutputManager
*
out
=
new
Fun4AllDstOutputManager
(
"DSTOUT"
, outputFile);
144
se->
registerOutputManager
(out);
145
}
146
147
/* write DSTReader human readable output tree */
148
if
(do_DSTReader)
149
{
150
// load HepMCNodeReader
151
HepMCNodeReader
*hr =
new
HepMCNodeReader
();
152
se->
registerSubsystem
(hr);
153
154
// load module to access truth particle information
155
PHG4Reco
* g4Reco =
new
PHG4Reco
();
156
PHG4TruthSubsystem
*truth =
new
PHG4TruthSubsystem
();
157
g4Reco->
registerSubsystem
(truth);
158
se->
registerSubsystem
( g4Reco );
159
160
// save a comprehensive evaluation file
161
PHG4DSTReader
* ana =
new
PHG4DSTReader
(
string
(outputFile) +
string
(
"_DSTReader.root"
));
162
ana->
set_save_particle
(
true
);
163
ana->
set_load_all_particle
(
false
);
164
ana->
set_load_active_particle
(
true
);
165
ana->
set_save_vertex
(
true
);
166
167
se->
registerSubsystem
(ana);
168
}
169
170
/* Write HepMC ASCII output */
171
else
if
( do_ASCIIOutput )
172
{
173
Fun4AllHepMCOutputManager
*asciiout =
new
Fun4AllHepMCOutputManager
(
"HEPMCOUT"
,outputFile);
174
se->
registerOutputManager
(asciiout);
175
}
176
177
//-----------------
178
// Event processing
179
//-----------------
180
if
(
nEvents
<= 0 && !readhepmc)
181
{
182
cout <<
"using 0 for number of events is a bad idea when using particle generators"
<< endl;
183
cout <<
"it will run forever, so I just return without running anything"
<< endl;
184
return
;
185
}
186
else
187
{
188
se->
run
(
nEvents
);
189
190
se->
End
();
191
std::cout <<
"All done"
<< std::endl;
192
delete
se;
193
gSystem->Exit(0);
194
}
195
196
}
197
198
199
void
200
G4Cmd
(
const
char
*
cmd
)
201
{
202
Fun4AllServer
*se =
Fun4AllServer::instance
();
203
PHG4Reco
*
g4
= (
PHG4Reco
*) se->
getSubsysReco
(
"PHG4RECO"
);
204
g4->
ApplyCommand
(cmd);
205
}
analysis
blob
master
EICAnalysis
eventgen
Fun4All_MCEventGen.C
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:17:48
using
1.8.2 with
sPHENIX GitHub integration