Skip to content

Commit f877711

Browse files
committed
Add ini file and test
1 parent ace99f6 commit f877711

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### The external generator derives from GeneratorPythia8.
2+
[GeneratorExternal]
3+
fileName=${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGHF/external/generator/generator_pythia8_gaptriggered_hf.C
4+
funcName=GeneratorPythia8GapTriggeredBeauty(5, -1.5, 1.5)
5+
6+
[GeneratorPythia8]
7+
config=${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGHF/pythia8/generator/pythia8_beautyhadronic_with_BtoDK_Mode2.cfg
8+
includePartonEvent=true
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
int External() {
2+
std::string path{"o2sim_Kine.root"};
3+
4+
int checkPdgQuark{5};
5+
float ratioTrigger = 1./5; // one event triggered out of 5
6+
7+
std::vector<int> checkPdgHadron{411, 421, 431, 4122, 4132, 4232, 4332, 511, 521, 531, 5122};
8+
std::map<int, std::vector<std::vector<int>>> checkHadronDecays{ // sorted pdg of daughters
9+
{411, {{-321, 211, 211}, {-313, 211}, {211, 311}, {211, 333}}}, // D+
10+
{421, {{-321, 211}, {-321, 111, 211}}}, // D0
11+
{431, {{211, 333}, {-313, 321}}}, // Ds+
12+
{4122, {{-313, 2212}, {-321, 2224}, {211, 102134}, {-321, 211, 2212}, {311, 2212}}}, // Lc+
13+
{4132, {{211, 3312}}}, // Xic0
14+
{4232, {{-313, 2212}, {-321, 3324}, {211, 211, 3312}, {-321, 211, 2212}}}, // Xic+
15+
{4332, {{211, 3334}}}, // Omegac+
16+
{511, {{-411, 211}, {-411, 321}}}, // B0
17+
{521, {{-421, 211}, {-421, 321}}}, // B+
18+
{531, {{-431, 211}, {-431, 321}}}, // Bs0
19+
{5122, {{4122, -211}, {4122, -321}}} // Lb0
20+
};
21+
22+
TFile file(path.c_str(), "READ");
23+
if (file.IsZombie()) {
24+
std::cerr << "Cannot open ROOT file " << path << "\n";
25+
return 1;
26+
}
27+
28+
auto tree = (TTree *)file.Get("o2sim");
29+
std::vector<o2::MCTrack> *tracks{};
30+
tree->SetBranchAddress("MCTrack", &tracks);
31+
o2::dataformats::MCEventHeader *eventHeader = nullptr;
32+
tree->SetBranchAddress("MCEventHeader.", &eventHeader);
33+
34+
int nEventsMB{}, nEventsInj{};
35+
int nQuarks{}, nSignals{}, nSignalGoodDecay{};
36+
auto nEvents = tree->GetEntries();
37+
38+
for (int i = 0; i < nEvents; i++) {
39+
tree->GetEntry(i);
40+
41+
// check subgenerator information
42+
if (eventHeader->hasInfo(o2::mcgenid::GeneratorProperty::SUBGENERATORID)) {
43+
bool isValid = false;
44+
int subGeneratorId = eventHeader->getInfo<int>(o2::mcgenid::GeneratorProperty::SUBGENERATORID, isValid);
45+
if (subGeneratorId == 0) {
46+
nEventsMB++;
47+
} else if (subGeneratorId == checkPdgQuark) {
48+
nEventsInj++;
49+
}
50+
}
51+
52+
for (auto &track : *tracks) {
53+
auto pdg = track.GetPdgCode();
54+
if (std::abs(pdg) == checkPdgQuark) {
55+
nQuarks++;
56+
continue;
57+
}
58+
if (std::find(checkPdgHadron.begin(), checkPdgHadron.end(), std::abs(pdg)) != checkPdgHadron.end()) { // found signal
59+
nSignals++; // count signal PDG
60+
61+
std::vector<int> pdgsDecay{};
62+
std::vector<int> pdgsDecayAntiPart{};
63+
for (int j{track.getFirstDaughterTrackId()}; j <= track.getLastDaughterTrackId(); ++j) {
64+
auto pdgDau = tracks->at(j).GetPdgCode();
65+
pdgsDecay.push_back(pdgDau);
66+
if (pdgDau != 333) { // phi is antiparticle of itself
67+
pdgsDecayAntiPart.push_back(-pdgDau);
68+
} else {
69+
pdgsDecayAntiPart.push_back(pdgDau);
70+
}
71+
}
72+
73+
std::sort(pdgsDecay.begin(), pdgsDecay.end());
74+
std::sort(pdgsDecayAntiPart.begin(), pdgsDecayAntiPart.end());
75+
76+
for (auto &decay : checkHadronDecays[std::abs(pdg)]) {
77+
if (pdgsDecay == decay || pdgsDecayAntiPart == decay) {
78+
nSignalGoodDecay++;
79+
break;
80+
}
81+
}
82+
}
83+
}
84+
}
85+
86+
std::cout << "--------------------------------\n";
87+
std::cout << "# Events: " << nEvents << "\n";
88+
std::cout << "# MB events: " << nEventsMB << "\n";
89+
std::cout << Form("# events injected with %d quark pair: ", checkPdgQuark) << nEventsInj << "\n";
90+
std::cout << Form("# %d (anti)quarks: ", checkPdgQuark) << nQuarks << "\n";
91+
std::cout <<"# signal hadrons: " << nSignals << "\n";
92+
std::cout <<"# signal hadrons decaying in the correct channel: " << nSignalGoodDecay << "\n";
93+
94+
if (nEventsMB < nEvents * (1 - ratioTrigger) * 0.95 || nEventsMB > nEvents * (1 - ratioTrigger) * 1.05) { // we put some tolerance since the number of generated events is small
95+
std::cerr << "Number of generated MB events different than expected\n";
96+
return 1;
97+
}
98+
if (nEventsInj < nEvents * ratioTrigger * 0.95 || nEventsInj > nEvents * ratioTrigger * 1.05) {
99+
std::cerr << "Number of generated events injected with " << checkPdgQuark << " different than expected\n";
100+
return 1;
101+
}
102+
103+
if (nQuarks < nEvents * ratioTrigger) { // we expect anyway more because the same quark is repeated several time, after each gluon radiation
104+
std::cerr << "Number of generated (anti)quarks " << checkPdgQuark << " lower than expected\n";
105+
return 1;
106+
}
107+
108+
float fracForcedDecays = float(nSignalGoodDecay) / nSignals;
109+
if (fracForcedDecays < 0.85) { // we put some tolerance (e.g. due to oscillations which might change the final state)
110+
std::cerr << "Fraction of signals decaying into the correct channel " << fracForcedDecays << " lower than expected\n";
111+
return 1;
112+
}
113+
114+
return 0;
115+
}

0 commit comments

Comments
 (0)