7#include <TGeoManager.h>
11#include "FairPrimaryGenerator.h"
16#include "TGeoVolume.h"
20const Double_t
cm = 10.;
24const Double_t
mbarn = 1
E-3 * 1
E-24 * TMath::Na();
38 fPythia =
new Pythia8::Pythia();
48 LOG(info) <<
"Open external file with charm or beauty hadrons: "
51 LOG(fatal) <<
"Error opening input file.";
61 fTree->SetBranchAddress(
"E", &
hE);
62 fTree->SetBranchAddress(
"M", &
hM);
63 fTree->SetBranchAddress(
"mid", &
mid);
64 fTree->SetBranchAddress(
"mpx", &
mpx);
65 fTree->SetBranchAddress(
"mpy", &
mpy);
66 fTree->SetBranchAddress(
"mpz", &
mpz);
67 fTree->SetBranchAddress(
"mE", &
mE);
68 if (
fTree->GetBranch(
"k")) {
69 fTree->SetBranchAddress(
"k", &
ck);
70 if (
fTree->GetBranch(
"a0")) {
71 for (Int_t i = 0; i < 16; i++) {
85 fPythia->readString(
"ProcessLevel:all = off");
89 n =
fPythia->particleData.nextId(n);
90 std::shared_ptr<Pythia8::ParticleDataEntry> p =
91 fPythia->particleData.particleDataEntryPtr(n);
93 std::string particle = std::to_string(n) +
":mayDecay = false";
95 LOGF(info,
"Made %s stable for Pythia, should decay in Geant4",
102 fPythia->settings.mode(
"Beams:idB", 2212);
103 fPythia->settings.mode(
"Beams:frameType", 2);
105 fPythia->settings.parm(
"Beams:eB", 0.);
118 <<
"Pythia8Generator: Using geometry-based target coordinates startZ="
126 TGeoVolume* top = gGeoManager->GetTopVolume();
129 LOGF(error,
"target not found, %s, program will crash",
132 Double_t z_middle = target->GetMatrix()->GetTranslation()[2];
133 TGeoBBox* sha =
dynamic_cast<TGeoBBox*
>(target->GetVolume()->GetShape());
134 startZ = z_middle - sha->GetDZ();
135 endZ = z_middle + sha->GetDZ();
156 Double_t x, y, z, px, py, pz, dl, e, tof;
165 LOG(warning) <<
"End of input file. Rewind.";
170 if (
static_cast<int>(
mE[0]) == 0) {
174 if (
static_cast<int>(fabs(
hid[0])) == 431) {
178 if (
static_cast<int>(
mE[0]) == 0) {
182 if (
static_cast<int>(fabs(
hid[0])) == 431 || isDs) {
183 Double_t rnr = gRandom->Uniform(0, 1);
195 Double_t prob2int = -1.;
198 Double_t zinterStart =
start[2];
201 Int_t nInter =
ck[0];
205 for (Int_t nI = 0; nI < nInter; nI++) {
209 Double_t intLengthFactor = 1;
211 intLengthFactor = 1.16;
216 while (prob2int < rndm) {
218 zinter = gRandom->Uniform(zinterStart,
end[2]);
219 Double_t point[3] = {
xOff,
yOff, zinter};
221 Double_t interLength =
222 mparam[8] * intLengthFactor *
224 TGeoNode* node = gGeoManager->FindNode(point[0], point[1], point[2]);
225 TGeoMaterial* mat =
nullptr;
226 if (node && !gGeoManager->IsOutside()) {
227 mat = node->GetVolume()->GetMaterial();
228 Double_t n = mat->GetDensity() / mat->GetA();
229 sigma = 1. / (n * mat->GetIntLen()) /
236 rndm = gRandom->Uniform(0., 1.);
238 zinterStart = zinter;
240 zinter = zinter *
cm;
242 for (Int_t c = 0; c < 2; c++) {
248 id =
static_cast<Int_t
>(
hid[0]);
249 fPythia->event.append(
id, 1, 0, 0,
hpx[0],
hpy[0],
hpz[0],
hE[0],
hM[0], 0.,
252 Double_t tau0 =
fPythia->particleData.tau0(
id);
253 dl = gRandom->Exp(tau0) /
hM[0];
255 Int_t addedParticles = 0;
266 cpg->AddTrack(
id, px, py, pz, x /
cm, y /
cm, z /
cm, -1,
false);
269 for (Int_t ii = 1; ii <
fPythia->event.size(); ii++) {
271 Bool_t wanttracking =
false;
272 if (
fPythia->event[ii].isFinal()) {
276 z =
fPythia->event[ii].zProd() + dl *
fPythia->event[1].pz() + zinter;
282 z =
fPythia->event[ii].zProd() + zinter;
283 x =
fPythia->event[ii].xProd();
284 y =
fPythia->event[ii].yProd();
292 im =
fPythia->event[ii].mother1() + key;
297 cpg->AddTrack(
id, px, py, pz, x /
cm, y /
cm, z /
cm, im, wanttracking, e,
301 key += addedParticles - 1;
~Pythia8Generator() override
Bool_t targetFromGeometry
Bool_t ReadEvent(FairPrimaryGenerator *) override
Pythia8::Pythia * fPythia
GenieGenerator * fMaterialInvestigator
TTree * fTree
don't make it persistent, magic ROOT command
std::shared_ptr< Pythia8::RndmEngine > fRandomEngine
std::optional< std::string > fextFile
double MeanMaterialBudget(std::span< const double, 3 > start, std::span< const double, 3 > end, std::span< double, 10 > mparam)