Skip to content

Commit 388c4c6

Browse files
ffiondaBenedikt Volkel
authored andcommitted
fix generator test macros
1 parent 6eedd9c commit 388c4c6

3 files changed

Lines changed: 185 additions & 1 deletion

File tree

MC/config/PWGDQ/ini/GeneratorHF_bbbar_PsiAndJpsi_fwdy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ hooksFuncName = pythia8_userhooks_bbbar(-4.3,-2.3)
1919

2020
[TriggerExternal]
2121
fileName = ${O2DPG_ROOT}/MC/config/PWGDQ/trigger/selectDaughterFromHFwithinAcc.C
22-
funcName = selectDaughterFromHFwithinAcc("443;100443",kTRUE,-4.3,-2.3)
22+
funcName = selecMultipletHFwithinAcc("443;100443",kTRUE,-4.3,-2.3)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
int External()
2+
{
3+
int checkPdgSignal[] = {443,100443};
4+
int checkPdgDecay = 13;
5+
std::string path{"o2sim_Kine.root"};
6+
std::cout << "Check for\nsignal PDG " << checkPdgSignal << "\ndecay PDG " << checkPdgDecay << "\n";
7+
TFile file(path.c_str(), "READ");
8+
if (file.IsZombie()) {
9+
std::cerr << "Cannot open ROOT file " << path << "\n";
10+
return 1;
11+
}
12+
13+
auto tree = (TTree*)file.Get("o2sim");
14+
std::vector<o2::MCTrack>* tracks{};
15+
tree->SetBranchAddress("MCTrack", &tracks);
16+
17+
int nLeptons{};
18+
int nAntileptons{};
19+
int nLeptonPairs{};
20+
int nLeptonPairsToBeDone{};
21+
int nSignalJpsi{};
22+
int nSignalPsi2S{};
23+
int nSignalJpsiWithinAcc{};
24+
int nSignalPsi2SWithinAcc{};
25+
auto nEvents = tree->GetEntries();
26+
o2::steer::MCKinematicsReader mcreader("o2sim", o2::steer::MCKinematicsReader::Mode::kMCKine);
27+
Int_t bpdgs[] = {511, 521, 531, 5112, 5122, 5232, 5132};
28+
Int_t sizePdg = sizeof(bpdgs)/sizeof(Int_t);
29+
Bool_t hasBeautyMoth = kFALSE;
30+
31+
for (int i = 0; i < nEvents; i++) {
32+
tree->GetEntry(i);
33+
for (auto& track : *tracks) {
34+
auto pdg = track.GetPdgCode();
35+
auto rapidity = track.GetRapidity();
36+
auto idMoth = track.getMotherTrackId();
37+
if (pdg == checkPdgDecay) {
38+
// count leptons
39+
nLeptons++;
40+
} else if(pdg == -checkPdgDecay) {
41+
// count anti-leptons
42+
nAntileptons++;
43+
} else if (pdg == checkPdgSignal[0] || pdg == checkPdgSignal[1]) {
44+
// check if mothers are beauty hadrons
45+
hasBeautyMoth = kFALSE;
46+
if(idMoth){ // check beauty mother
47+
auto tdM = mcreader.getTrack(i, idMoth);
48+
for(int i=0; i<sizePdg; i++){ if (TMath::Abs(tdM->GetPdgCode()) == bpdgs[i] ) hasBeautyMoth = kTRUE; }
49+
}
50+
if(hasBeautyMoth){
51+
// count signal PDG
52+
pdg == checkPdgSignal[0] ? nSignalJpsi++ : nSignalPsi2S++;
53+
// count signal PDG within acceptance
54+
if(rapidity > -4.3 && rapidity < -2.3) { pdg == checkPdgSignal[0] ? nSignalJpsiWithinAcc++ : nSignalPsi2SWithinAcc++;}
55+
}
56+
auto child0 = o2::mcutils::MCTrackNavigator::getDaughter0(track, *tracks);
57+
auto child1 = o2::mcutils::MCTrackNavigator::getDaughter1(track, *tracks);
58+
if (child0 != nullptr && child1 != nullptr) {
59+
// check for parent-child relations
60+
auto pdg0 = child0->GetPdgCode();
61+
auto pdg1 = child1->GetPdgCode();
62+
std::cout << "First and last children of parent " << checkPdgSignal << " are PDG0: " << pdg0 << " PDG1: " << pdg1 << "\n";
63+
if (std::abs(pdg0) == checkPdgDecay && std::abs(pdg1) == checkPdgDecay && pdg0 == -pdg1) {
64+
nLeptonPairs++;
65+
if (child0->getToBeDone() && child1->getToBeDone()) {
66+
nLeptonPairsToBeDone++;
67+
}
68+
}
69+
}
70+
}
71+
}
72+
}
73+
std::cout << "#events: " << nEvents << "\n"
74+
<< "#leptons: " << nLeptons << "\n"
75+
<< "#antileptons: " << nAntileptons << "\n"
76+
<< "#signal (jpsi <- b): " << nSignalJpsi << "; within acceptance (-4.3 < y < -2.3): " << nSignalJpsiWithinAcc << "\n"
77+
<< "#signal (psi2S <- b): " << nSignalPsi2S << "; within acceptance (-4.3 < y < -2.3): " << nSignalPsi2SWithinAcc << "\n"
78+
<< "#lepton pairs: " << nLeptonPairs << "\n"
79+
<< "#lepton pairs to be done: " << nLeptonPairs << "\n";
80+
81+
82+
if (nLeptonPairs == 0 || nLeptons == 0 || nAntileptons == 0) {
83+
std::cerr << "Number of leptons, number of anti-leptons as well as number of lepton pairs should all be greater than 1.\n";
84+
return 1;
85+
}
86+
if (nLeptonPairs != nLeptonPairsToBeDone) {
87+
std::cerr << "The number of lepton pairs should be the same as the number of lepton pairs which should be transported.\n";
88+
return 1;
89+
}
90+
91+
return 0;
92+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
int External()
2+
{
3+
int checkPdgSignal[] = {443,100443};
4+
int checkPdgDecay = 11;
5+
std::string path{"o2sim_Kine.root"};
6+
std::cout << "Check for\nsignal PDG " << checkPdgSignal << "\ndecay PDG " << checkPdgDecay << "\n";
7+
TFile file(path.c_str(), "READ");
8+
if (file.IsZombie()) {
9+
std::cerr << "Cannot open ROOT file " << path << "\n";
10+
return 1;
11+
}
12+
13+
auto tree = (TTree*)file.Get("o2sim");
14+
std::vector<o2::MCTrack>* tracks{};
15+
tree->SetBranchAddress("MCTrack", &tracks);
16+
17+
int nLeptons{};
18+
int nAntileptons{};
19+
int nLeptonPairs{};
20+
int nLeptonPairsToBeDone{};
21+
int nSignalJpsi{};
22+
int nSignalPsi2S{};
23+
int nSignalJpsiWithinAcc{};
24+
int nSignalPsi2SWithinAcc{};
25+
auto nEvents = tree->GetEntries();
26+
o2::steer::MCKinematicsReader mcreader("o2sim", o2::steer::MCKinematicsReader::Mode::kMCKine);
27+
Int_t bpdgs[] = {511, 521, 531, 5112, 5122, 5232, 5132};
28+
Int_t sizePdg = sizeof(bpdgs)/sizeof(Int_t);
29+
Bool_t hasBeautyMoth = kFALSE;
30+
31+
for (int i = 0; i < nEvents; i++) {
32+
tree->GetEntry(i);
33+
for (auto& track : *tracks) {
34+
auto pdg = track.GetPdgCode();
35+
auto rapidity = track.GetRapidity();
36+
auto idMoth = track.getMotherTrackId();
37+
if (pdg == checkPdgDecay) {
38+
// count leptons
39+
nLeptons++;
40+
} else if(pdg == -checkPdgDecay) {
41+
// count anti-leptons
42+
nAntileptons++;
43+
} else if (pdg == checkPdgSignal[0] || pdg == checkPdgSignal[1]) {
44+
// check if mothers are beauty hadrons
45+
hasBeautyMoth = kFALSE;
46+
if(idMoth){ // check beauty mother
47+
auto tdM = mcreader.getTrack(i, idMoth);
48+
for(int i=0; i<sizePdg; i++){ if (TMath::Abs(tdM->GetPdgCode()) == bpdgs[i] ) hasBeautyMoth = kTRUE; }
49+
}
50+
if(hasBeautyMoth){
51+
// count signal PDG
52+
pdg == checkPdgSignal[0] ? nSignalJpsi++ : nSignalPsi2S++;
53+
// count signal PDG within acceptance
54+
if(std::abs(rapidity) < 1.0) { pdg == checkPdgSignal[0] ? nSignalJpsiWithinAcc++ : nSignalPsi2SWithinAcc++;}
55+
}
56+
auto child0 = o2::mcutils::MCTrackNavigator::getDaughter0(track, *tracks);
57+
auto child1 = o2::mcutils::MCTrackNavigator::getDaughter1(track, *tracks);
58+
if (child0 != nullptr && child1 != nullptr) {
59+
// check for parent-child relations
60+
auto pdg0 = child0->GetPdgCode();
61+
auto pdg1 = child1->GetPdgCode();
62+
std::cout << "First and last children of parent " << checkPdgSignal << " are PDG0: " << pdg0 << " PDG1: " << pdg1 << "\n";
63+
if (std::abs(pdg0) == checkPdgDecay && std::abs(pdg1) == checkPdgDecay && pdg0 == -pdg1) {
64+
nLeptonPairs++;
65+
if (child0->getToBeDone() && child1->getToBeDone()) {
66+
nLeptonPairsToBeDone++;
67+
}
68+
}
69+
}
70+
}
71+
}
72+
}
73+
std::cout << "#events: " << nEvents << "\n"
74+
<< "#leptons: " << nLeptons << "\n"
75+
<< "#antileptons: " << nAntileptons << "\n"
76+
<< "#signal (jpsi <- b): " << nSignalJpsi << "; within acceptance (|y| < 1): " << nSignalJpsiWithinAcc << "\n"
77+
<< "#signal (psi2S <- b): " << nSignalPsi2S << "; within acceptance (|y| < 1): " << nSignalPsi2SWithinAcc << "\n"
78+
<< "#lepton pairs: " << nLeptonPairs << "\n"
79+
<< "#lepton pairs to be done: " << nLeptonPairs << "\n";
80+
81+
82+
if (nLeptonPairs == 0 || nLeptons == 0 || nAntileptons == 0) {
83+
std::cerr << "Number of leptons, number of anti-leptons as well as number of lepton pairs should all be greater than 1.\n";
84+
return 1;
85+
}
86+
if (nLeptonPairs != nLeptonPairsToBeDone) {
87+
std::cerr << "The number of lepton pairs should be the same as the number of lepton pairs which should be transported.\n";
88+
return 1;
89+
}
90+
91+
return 0;
92+
}

0 commit comments

Comments
 (0)