-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprimary.cc
137 lines (112 loc) · 3.27 KB
/
primary.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "primary.h"
#include <G4Event.hh>
#include <G4SystemOfUnits.hh>
#include <G4ParticleTable.hh>
#include <G4PrimaryParticle.hh>
#include <G4RandomDirection.hh>
#include <err.h>
#include <unistd.h>
static double primary_energy;
static const char *primary_name;
static const char *pythia_config_name;
static const G4ParticleDefinition *primary;
void set_primary_name(const char *name)
{
primary_name = name;
}
void set_primary_energy(double E)
{
primary_energy = E * GeV;
}
bool use_pythia()
{
return pythia_config_name != nullptr;
}
void set_pythia_config(const char *name)
{
pythia_config_name = name;
}
PrimaryGeneratorAction::PrimaryGeneratorAction()
{
if (!(primary = G4ParticleTable::GetParticleTable()->FindParticle(primary_name)))
errx(1, "unknown particle type: %s", primary_name);
}
void PrimaryGeneratorAction::GeneratePrimaries(G4Event* event)
{
static const G4double time = 0.0;
static const G4ThreeVector position(0.0, 0.0, 0.0);
G4PrimaryVertex* vertex = new G4PrimaryVertex(position, time);
G4PrimaryParticle* particle = new G4PrimaryParticle(primary);
particle->SetKineticEnergy(primary_energy);
particle->SetMomentumDirection(G4RandomDirection());
particle->SetPolarization(0.0, 0.0, 0.0);
vertex->SetPrimary(particle);
event->AddPrimaryVertex(vertex);
}
#if USE_PYTHIA
static const char *pythia_defaults[] = {
"Print:quiet = on",
"Beams:idA = 2212",
"Beams:idB = 2212",
"Beams:eCM = 14000.0",
"Init:showProcesses = off",
"Init:showMultipartonInteractions = off",
"Init:showChangedParticleData = off",
"Stat:showProcessLevel = off",
"Stat:showErrors = off",
};
static const char *pythia_minbias[] = {
"HardQCD:all = on",
"Beams:eCM = 14000.0",
"PhaseSpace:pTHatMin = 20.0",
};
static const char *pythia_higgs[] = {
"HiggsSM:all = on",
"Beams:eCM = 14000.0",
"PhaseSpace:pTHatMin = 20.0",
};
static const char *pythia_ttbar[] = {
"Top:gg2ttbar = on",
"Top:qqbar2ttbar = on",
"Beams:eCM = 14000.0",
"PhaseSpace:pTHatMin = 20.0",
};
PythiaPrimaryGeneratorAction::PythiaPrimaryGeneratorAction() {
if (access(pythia_config_name, R_OK) == 0) {
pythia.readFile(pythia_config_name);
} else {
for (const auto str : pythia_defaults)
pythia.readString(str);
if (strcmp("minbias", pythia_config_name) == 0) {
for (const auto str : pythia_minbias)
pythia.readString(str);
} else if (strcmp("higgs", pythia_config_name) == 0) {
for (const auto str : pythia_higgs)
pythia.readString(str);
} else if (strcmp("ttbar", pythia_config_name) == 0) {
for (const auto str : pythia_ttbar)
pythia.readString(str);
} else {
errx(1, "unknown Pythia configuration: %s", pythia_config_name);
}
}
pythia.init();
}
void PythiaPrimaryGeneratorAction::GeneratePrimaries(G4Event *event)
{
static const G4double time = 0.0;
static const G4ThreeVector position(0.0, 0.0, 0.0);
G4PrimaryVertex* vertex = new G4PrimaryVertex(position, time);
pythia.next();
for (auto i = 1, n = pythia.event.size(); i < n; ++i) {
const auto& particle = pythia.event[i];
if (!particle.isFinal())
continue;
G4PrimaryParticle* p = new G4PrimaryParticle(particle.id());
p->SetMass(particle.m() * GeV);
p->SetMomentum(particle.px() * GeV, particle.py() * GeV, particle.pz() * GeV);
vertex->SetPrimary(p);
}
event->AddPrimaryVertex(vertex);
}
#endif