7#include <TGeoManager.h>
13#include "FairMCEventHeader.h"
14#include "FairPrimaryGenerator.h"
17#include "Pythia8Plugins/EvtGen.h"
21#include "TGeoVolume.h"
22#include "TMCProcess.h"
30const Double_t
mbarn = 1
E-3 * 1
E-24 * TMath::Na();
38 fLogger = FairLogger::GetLogger();
39 targetName =
"cave_1/target_vacuum_box_1/TargetArea_1/HeVolume_1";
67 Double_t npot, Int_t nStart) {
71 fin = TFile::Open(fInName);
73 LOG(fatal) <<
"Could not open input file: " << fInName.Data();
76 nTree =
dynamic_cast<TNtuple*
>(
77 fin->FindObjectAny(
"pythia6"));
90 if (
nTree->GetBranch(
"k")) {
91 LOG(info) <<
"+++has branch+++";
92 nTree->SetBranchAddress(
"k", &
ck);
98 LOG(info) <<
"automatic detection of beauty, configured for beauty";
99 LOG(info) <<
"bb cross section / mbias " <<
chicc;
101 LOG(info) <<
"cc cross section / mbias " <<
chicc;
106 auto* potHist =
dynamic_cast<TH1F*
>(
fin->Get(
"2"));
108 LOG(fatal) <<
"Histogram '2' not found in input file";
112 potHist->GetBinContent(1) / 2.;
114 LOG(info) <<
"Input file: " << fInName.Data() <<
" with " <<
nEvents
115 <<
" entries, corresponding to nr-pot=" << (nrcpot /
chicc);
117 <<
" p.o.t. per spill for " << nev <<
" events to process";
129 new Pythia8::Pythia();
133 LOG(error) <<
"Option not known " <<
Option.Data() <<
", abort";
137 std::vector<int> r = {221, 221, 223, 223, 113, 331, 333};
138 std::vector<int> c = {6, 7, 5, 7, 5, 6, 9};
141 fPythiaP->settings.mode(
"Beams:idB", 2212);
142 fPythiaN->settings.mode(
"Beams:idB", 2112);
144 fPythiaP->readString(
"ProcessLevel:all = off");
148 for (
const auto& fPythia : plist) {
154 fPythia->settings.mode(
"Random:seed",
fSeed);
155 fPythia->settings.mode(
"Next:numberCount",
heartbeat);
156 if (
Option ==
"Primary") {
157 fPythia->settings.mode(
"Beams:idA", 2212);
158 fPythia->settings.mode(
"Beams:frameType", 2);
159 fPythia->settings.parm(
"Beams:eA",
fMom);
160 fPythia->settings.parm(
"Beams:eB", 0.);
164 fPythia->readString(
"Onia:all(3S1) = on");
166 "443:new J/psi J/psi 3 0 0 3.09692 0.00009 3.09602 "
167 " 3.09782 0. 1 1 0 1 0");
168 fPythia->readString(
"443:addChannel = 1 1. 0 -13 13");
170 "553:new Upsilon Upsilon 3 0 0 9.46030 0.00005 "
171 "9.45980 9.46080 0.00000e+00 0 1 0 1 0");
172 fPythia->readString(
"553:addChannel = 1 1. 0 -13 13");
175 fPythia->readString(
"WeakSingleBoson:ffbar2gmZ = on");
177 fPythia->readString(
"23:onMode = off");
178 fPythia->readString(
"23:onIfAll = 13 13");
179 fPythia->readString(
"23:mMin = 0.5");
180 fPythia->readString(
"PhaseSpace:mHatMin = 0.5");
181 fPythia->readString(
"PartonLevel:FSR = on");
182 fPythia->readString(
"PDF:pSet = 4");
185 fPythia->readString(
"PhotonCollision:gmgm2mumu = on");
188 fPythia->readString(
"SoftQCD:inelastic = on");
189 fPythia->readString(
"PhotonCollision:gmgm2mumu = on");
190 fPythia->readString(
"PromptPhoton:all = on");
191 fPythia->readString(
"WeakBosonExchange:all = on");
192 fPythia->readString(
"WeakSingleBoson:all = on");
196 "431:new D_s+ D_s- 1 3 0 1.96849 0.00000 0.00000 "
197 "0.00000 1.49900e-01 0 1 0 1 0");
199 "431:addChannel = 1 0.0640000 0 -15 16");
205 n = fPythia->particleData.nextId(n);
206 std::shared_ptr<Pythia8::ParticleDataEntry> p =
207 fPythia->particleData.particleDataEntryPtr(n);
209 std::string particle = std::to_string(n) +
":mayDecay = false";
210 fPythia->readString(particle);
211 LOG(info) <<
"Made " << p->name().c_str()
212 <<
" stable for Pythia, should decay in Geant4";
218 LOG(info) <<
"Rescale BRs of dimuon decays in Pythia: " <<
fBoost;
219 for (
unsigned int i = 0; i < r.size(); ++i) {
220 std::shared_ptr<Pythia8::ParticleDataEntry> V =
221 fPythia->particleData.particleDataEntryPtr(r[i]);
222 Pythia8::DecayChannel ch = V->channel(c[i]);
223 if (TMath::Abs(ch.product(0)) != 13 ||
224 TMath::Abs(ch.product(1)) != 13) {
225 LOG(info) <<
"this is not the right decay channel: " << r[i] <<
" "
233 tmp +=
fBoost * ch.bRatio();
234 fPythia->readString(tmp.Data());
243 const char* evtgendata = getenv(
"EVTGENDATA");
245 LOG(fatal) <<
"EVTGENDATA environment variable not set";
247 TString DecayFile = TString(evtgendata) +
"/DECAY.DEC";
249 TString ParticleFile = TString(evtgendata) +
"/evt.pdl";
250 std::cout <<
"Using $EVTGENDATA " << evtgendata << std::endl;
251 EvtExternalGenList* extPtr =
new EvtExternalGenList();
252 std::list<EvtDecayBase*> models = extPtr->getListOfModels();
253 TString UdecayFile = getenv(
"FAIRSHIP");
254 UdecayFile +=
"/gconfig/USERDECAY.DEC";
256 ParticleFile.Data(), extPtr);
260 if (
Option ==
"Primary") {
262 new Pythia8::EvtGenDecays(
fPythiaN, DecayFile.Data(),
"", extPtr);
274 LOG(info) <<
"FixedTargetGenerator: Using geometry-based target "
275 "coordinates startZ="
283 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
287 LOG(fatal) <<
"Invalid target volume specified";
289 TGeoNode* target = nav->GetCurrentNode();
290 TObjArray* nodes = target->GetVolume()->GetNodes();
292 TGeoNode* first =
static_cast<TGeoNode*
>(nodes->At(0));
293 TGeoNode* last =
static_cast<TGeoNode*
>(nodes->At(nodes->GetSize() - 1));
295 TGeoBBox* sha =
static_cast<TGeoBBox*
>(first->GetVolume()->GetShape());
296 Double_t dz = sha->GetDZ();
297 Double_t origin[3] = {0, 0, -dz};
298 Double_t master[3] = {0, 0, 0};
299 nav->LocalToMaster(origin, master);
302 sha =
static_cast<TGeoBBox*
>(first->GetVolume()->GetShape());
305 nav->LocalToMaster(origin, master);
317 LOG(fatal) <<
"No target set.";
334 Double_t ZoverA = 1.;
339 Double_t prob2int = -1.;
342 Double_t zinterStart =
start[2];
346 if (!(
nTree->GetBranch(
"k"))) {
353 while (prob2int < rndm) {
355 zinter = gRandom->Uniform(zinterStart,
end[2]);
356 Double_t point[3] = {
xOff,
yOff, zinter};
358 Double_t interLength =
mparam[8];
359 TGeoNode* node = gGeoManager->FindNode(point[0], point[1], point[2]);
360 TGeoMaterial* mat =
nullptr;
361 if (node && !gGeoManager->IsOutside()) {
362 mat = node->GetVolume()->GetMaterial();
363 Double_t n = mat->GetDensity() / mat->GetA();
364 ZoverA = mat->GetZ() / mat->GetA();
365 sigma = 1. / (n * mat->GetIntLen()) /
mbarn;
370 rndm = gRandom->Uniform(0., 1.);
372 zinterStart = zinter;
375 zinter = zinter *
cm;
377 Pythia8::Pythia* fPythia;
380 start[2], -1, kTRUE, -1., 0., 1.);
382 }
else if (
Option ==
"Primary") {
383 if (gRandom->Uniform(0., 1.) < ZoverA) {
398 LOG(info) <<
"Rewind input file: " <<
nEntry;
406 if (pt < 1.e-5 &&
n_mid == 2212) {
410 Int_t idabs =
static_cast<int>(TMath::Abs(
n_id));
418 TMCProcess procID = kPTransportation;
427 if (nID1 *
n_id > 0) {
428 LOG(info) <<
"same sign charm: " <<
nEntry <<
", " << nID1 <<
", "
438 fPythia->moreDecays();
441 fPythia->event.list();
444 for (Int_t ii = 1; ii < fPythia->event.size(); ii++) {
445 Double_t e = fPythia->event[ii].e();
446 Double_t
m = fPythia->event[ii].m();
447 Double_t pz = fPythia->event[ii].pz();
448 Int_t
id = fPythia->event[ii].id();
449 Bool_t wanttracking = kTRUE;
450 if (e - m < EMax || !fPythia->event[ii].isFinal() || pz < 0) {
451 wanttracking = kFALSE;
455 if (fabs(
id) != 13) {
456 wanttracking = kFALSE;
459 Double_t z = fPythia->event[ii].zProd() *
mm + zinter *
cm;
460 Double_t x = fPythia->event[ii].xProd() *
mm +
xOff *
cm + dx *
cm;
461 Double_t y = fPythia->event[ii].yProd() *
mm +
yOff *
cm + dy *
cm;
463 fPythia->event[ii].tProd() / (10 *
c_light);
464 Double_t px = fPythia->event[ii].px();
465 Double_t py = fPythia->event[ii].py();
466 Int_t im = fPythia->event[ii].mother1() - 1;
468 if (
Option !=
"Primary") {
479 cpg->AddTrack(
id, px, py, pz, x *
cm, y *
cm, z *
cm, im, wanttracking, e,
482 int idabs = TMath::Abs(
id);
486 if (idabs < 18 || idabs == 22 || idabs == 111 || idabs == 221 ||
487 idabs == 223 || idabs == 331 || idabs == 211 || idabs == 113 ||
488 idabs == 333 || idabs == 321 || idabs == 2212) {
489 Int_t moID = fPythia->event[im + 1].id();
490 fNtuple->Fill(0,
id, px, py, pz, e, x *
cm, y *
cm, z *
cm, moID);
std::pair< Double_t, Double_t > CalculateBeamOffset(Double_t smearBeam, Double_t paintBeam)
~FixedTargetGenerator() override
Bool_t ReadEvent(FairPrimaryGenerator *) override
GenieGenerator * fMaterialInvestigator
TNtuple * fNtuple
special option for Dark Photon physics studies
Bool_t targetFromGeometry
Pythia8::Pythia * fPythiaP
Pythia8::EvtGenDecays * evtgenN
Pythia8::Pythia * fPythiaN
don't make it persistent, magic ROOT command
Bool_t InitForCharmOrBeauty(TString fInName, Int_t nev, Double_t npots=5E13, Int_t nStart=0)
Pythia8::EvtGenDecays * evtgenP
std::shared_ptr< Pythia8::RndmEngine > fRandomEngine
double MeanMaterialBudget(std::span< const double, 3 > start, std::span< const double, 3 > end, std::span< double, 10 > mparam)