Skip to content

Commit a484fd4

Browse files
authored
Add injected nuclei generator for HMPID; extend long-lived generator with phi range selection (#1995)
1 parent 3dd6e6b commit a484fd4

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[GeneratorExternal]
2+
fileName=${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGLF/pythia8/generator_pythia8_longlived.C
3+
funcName=generateLongLived(1000010020,10,0.1,3.0,-0.6,0.6,-0.7,1.7,-1)
4+
5+
[GeneratorPythia8]
6+
config=${O2_ROOT}/share/Generators/egconfig/pythia8_hi.cfg
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
int External()
2+
{
3+
std::string path{"o2sim_Kine.root"};
4+
std::vector<int> possiblePDGs = {1000010020, -1000010020};
5+
6+
int nPossiblePDGs = possiblePDGs.size();
7+
8+
TFile file(path.c_str(), "READ");
9+
if (file.IsZombie())
10+
{
11+
std::cerr << "Cannot open ROOT file " << path << "\n";
12+
return 1;
13+
}
14+
15+
auto tree = (TTree *)file.Get("o2sim");
16+
if (!tree)
17+
{
18+
std::cerr << "Cannot find tree o2sim in file " << path << "\n";
19+
return 1;
20+
}
21+
std::vector<o2::MCTrack> *tracks{};
22+
tree->SetBranchAddress("MCTrack", &tracks);
23+
24+
std::vector<int> injectedPDGs;
25+
26+
auto nEvents = tree->GetEntries();
27+
for (int i = 0; i < nEvents; i++)
28+
{
29+
auto check = tree->GetEntry(i);
30+
for (int idxMCTrack = 0; idxMCTrack < tracks->size(); ++idxMCTrack)
31+
{
32+
auto track = tracks->at(idxMCTrack);
33+
auto pdg = track.GetPdgCode();
34+
auto it = std::find(possiblePDGs.begin(), possiblePDGs.end(), pdg);
35+
if (it != possiblePDGs.end() && track.isPrimary()) // found
36+
{
37+
injectedPDGs.push_back(pdg);
38+
}
39+
}
40+
}
41+
std::cout << "--------------------------------\n";
42+
std::cout << "# Events: " << nEvents << "\n";
43+
if(injectedPDGs.empty()){
44+
std::cerr << "No injected particles\n";
45+
return 1; // At least one of the injected particles should be generated
46+
}
47+
for (int i = 0; i < nPossiblePDGs; i++)
48+
{
49+
std::cout << "# Injected nuclei \n";
50+
std::cout << possiblePDGs[i] << ": " << std::count(injectedPDGs.begin(), injectedPDGs.end(), possiblePDGs[i]) << "\n";
51+
}
52+
return 0;
53+
}

MC/config/PWGLF/pythia8/generator_pythia8_longlived.C

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GeneratorPythia8LongLivedGun : public o2::eventgen::GeneratorPythia8
1616
{
1717
public:
1818
/// constructor
19-
GeneratorPythia8LongLivedGun(int input_pdg, int nInject = 1, float ptMin = 1, float ptMax = 10, int input_pdg2 = -1) : pdg{input_pdg}, nParticles{nInject}, genMinPt{ptMin}, genMaxPt{ptMax}, m{getMass(input_pdg)}, pdg2{input_pdg2}
19+
GeneratorPythia8LongLivedGun(int input_pdg, int nInject = 1, float ptMin = 1, float ptMax = 10, float etaMin = -1.0, float etaMax = 1.0, float phiMin = 0.0, float phiMax = TMath::Pi(), int input_pdg2 = -1) : pdg{input_pdg}, nParticles{nInject}, genMinPt{ptMin}, genMaxPt{ptMax}, genMinEta{etaMin}, genMaxEta{etaMax}, genMinPhi{phiMin}, genMaxPhi{phiMax}, m{getMass(input_pdg)}, pdg2{input_pdg2}
2020
{
2121
}
2222

@@ -51,7 +51,7 @@ public:
5151
{
5252
const double pt = gRandom->Uniform(genMinPt, genMaxPt);
5353
const double eta = gRandom->Uniform(genMinEta, genMaxEta);
54-
const double phi = gRandom->Uniform(0, TMath::TwoPi());
54+
const double phi = gRandom->Uniform(genMinPhi, genMaxPhi);
5555
const double px{pt * std::cos(phi)};
5656
const double py{pt * std::sin(phi)};
5757
const double pz{pt * std::sinh(eta)};
@@ -69,7 +69,7 @@ public:
6969
{
7070
const double pt = gRandom->Uniform(genMinPt, genMaxPt);
7171
const double eta = gRandom->Uniform(genMinEta, genMaxEta);
72-
const double phi = gRandom->Uniform(0, TMath::TwoPi());
72+
const double phi = gRandom->Uniform(genMinPhi, genMaxPhi);
7373
const double px{pt * std::cos(phi)};
7474
const double py{pt * std::sin(phi)};
7575
const double pz{pt * std::sinh(eta)};
@@ -88,8 +88,10 @@ public:
8888
private:
8989
double genMinPt = 0.5; /// minimum 3-momentum for generated particles
9090
double genMaxPt = 12.; /// maximum 3-momentum for generated particles
91-
double genMinEta = -1.; /// minimum pseudorapidity for generated particles
92-
double genMaxEta = +1.; /// maximum pseudorapidity for generated particles
91+
double genMinEta = -1.0; /// minimum pseudorapidity for generated particles
92+
double genMaxEta = +1.0; /// maximum pseudorapidity for generated particles
93+
double genMinPhi = 0.0; /// minimum pseudorapidity for generated particles
94+
double genMaxPhi = TMath::Pi(); /// maximum pseudorapidity for generated particles
9395

9496
double m = 0; /// particle mass [GeV/c^2]
9597
int pdg = 0; /// particle pdg code
@@ -101,7 +103,8 @@ private:
101103
};
102104

103105
///___________________________________________________________
104-
FairGenerator *generateLongLived(int pdg, int nInject, float ptMin = 1, float ptMax = 10, int pdg2 = -1)
106+
FairGenerator *generateLongLived(int pdg, int nInject, float ptMin = 1, float ptMax = 10, float etaMin = -1.0, float etaMax = 1.0, float phiMin = 0.0, float phiMax = TMath::Pi(), int pdg2 = -1)
105107
{
106-
return new GeneratorPythia8LongLivedGun(pdg, nInject, ptMin, ptMax, pdg2);
108+
return new GeneratorPythia8LongLivedGun(pdg, nInject, ptMin, ptMax, etaMin, etaMax, phiMin, phiMax, pdg2);
107109
}
110+

0 commit comments

Comments
 (0)