Skip to content

Commit 74b9754

Browse files
Create Generator_InjectedInclusiveJpsiPsi2SMidy_Pythia8_TriggerGap_2026.C
1 parent b63b529 commit 74b9754

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)