Skip to content

Commit 1e3f8b2

Browse files
committed
Add test macro
1 parent f9f9e7f commit 1e3f8b2

1 file changed

Lines changed: 192 additions & 0 deletions

File tree

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
int External() {
2+
std::string path{"o2sim_Kine.root"};
3+
//std::string path{"tf1/sgn_1_Kine.root"};
4+
5+
int checkPdgQuarkOne{4};
6+
int checkPdgQuarkTwo{5};
7+
float ratioTrigger = 1.; // one event triggered out of 1
8+
9+
std::vector<int> checkPdgHadron{411, 421, 431, 4122, 4132, 4232, 4332};
10+
std::map<int, std::vector<std::vector<int>>> checkHadronDecays{ // sorted pdg of daughters
11+
{421, {
12+
{-321, 211}, // D0 -> K-, pi+
13+
{-321, 211, 111}, // D0 -> K-, pi+, pi0
14+
{213, -321}, // D0 -> rho(770)+, K-
15+
{-313, 111}, // D0 -> Kbar^*(892)0, pi0
16+
{-323, 211}, // D0 -> K^*(892)-, pi+
17+
{-211, 211}, // D0 -> pi-, pi+
18+
{213, -211}, // D0 -> rho(770)+, pi-
19+
{-211, 211, 111}, // D0 -> pi-, pi+, pi0
20+
{-321, 321}, // D0 -> K-, K+
21+
}},
22+
23+
{411, {
24+
{-321, 211, 211}, // D+ -> K-, pi+, pi+
25+
{-10311, 211}, // D+ -> Kbar0^*(1430)0, pi+
26+
{-313, 211}, // D+ -> Kbar^*(892)0, pi+
27+
{-321, 211, 211, 111}, // D+ -> K-, pi+, pi+, pi0
28+
{333, 211}, // D+ -> phi(1020)0, pi+
29+
{-313, 321}, // D+ -> Kbar^*(892)0, K+
30+
{-10311, 321}, // D+ -> Kbar0^*(1430)0, K+
31+
{-321, 321, 211}, // D+ -> K-, K+, pi+
32+
{113, 211}, // D+ -> rho(770)0, pi+
33+
{225, 211}, // D+ -> f2(1270)0, pi+
34+
{-211, 211, 211}, // D+ -> pi-, pi+, pi+
35+
}},
36+
37+
{431, {
38+
{333, 211}, // Ds+ -> phi(1020)0, pi+
39+
{-313, 321}, // Ds+ -> Kbar^*(892)0, K+
40+
{333, 213}, // Ds+ -> phi(1020)0, rho(770)+
41+
{113, 211}, // Ds+ -> rho(770)0, pi+
42+
{225, 211}, // Ds+ -> f2(1270)0, pi+
43+
{-211, 211, 211}, // Ds+ -> pi-, pi+, pi+
44+
{313, 211}, // Ds+ -> K^*(892)0, pi+
45+
{10221, 321}, // Ds+ -> f0(1370)0, K+
46+
{113, 321}, // Ds+ -> rho(770)0, K+
47+
{-211, 321, 211}, // Ds+ -> pi-, K+, pi+
48+
{221, 211}, // Ds+ -> eta, pi+
49+
}},
50+
51+
{4122, {
52+
{2212, -321, 211}, // Lambdac+ -> p, K-, pi+
53+
{2212, -313}, // Lambdac+ -> p, Kbar^*(892)0
54+
{2224, -321}, // Lambdac+ -> Delta(1232)++, K-
55+
{102134, 211}, // Lambdac+ -> 102134, pi+
56+
{2212, 310}, // Lambdac+ -> p, K0s
57+
{2212, -321, 211, 111}, // Lambdac+ -> p, K-, pi+, pi0
58+
{2212, -211, 211}, // Lambdac+ -> p, pi-, pi+
59+
{2212, 333}, // Lambdac+ -> p, phi(1020)0
60+
}},
61+
62+
{4232, {
63+
{2212, -321, 211}, // Xic+ -> p, K-, pi+
64+
{2212, -313}, // Xic+ -> p, Kbar^*(892)0
65+
{3312, 211, 211}, // Xic+ -> Xi-, pi+, pi+
66+
{2212, 333}, // Xic+ -> p, phi(1020)0
67+
{3222, -211, 211}, // Xic+ -> Sigma+, pi-, pi+
68+
{3324, 211}, // Xic+ -> Xi(1530)0, pi+
69+
}},
70+
71+
{4132, {
72+
{3312, 211}, // Xic0 -> Xi-, pi+
73+
}},
74+
75+
{4332, {
76+
{3334, 211}, // Omegac0 -> Omega-, pi+
77+
{3312, 211}, // Omegac0 -> Xi-, pi+
78+
}},
79+
};
80+
81+
TFile file(path.c_str(), "READ");
82+
if (file.IsZombie()) {
83+
std::cerr << "Cannot open ROOT file " << path << "\n";
84+
return 1;
85+
}
86+
87+
auto tree = (TTree *)file.Get("o2sim");
88+
std::vector<o2::MCTrack> *tracks{};
89+
tree->SetBranchAddress("MCTrack", &tracks);
90+
o2::dataformats::MCEventHeader *eventHeader = nullptr;
91+
tree->SetBranchAddress("MCEventHeader.", &eventHeader);
92+
93+
int nEventsMB{}, nEventsInjOne{}, nEventsInjTwo{};
94+
int nQuarksOne{}, nQuarksTwo{}, nSignals{}, nSignalGoodDecay{};
95+
auto nEvents = tree->GetEntries();
96+
97+
for (int i = 0; i < nEvents; i++) {
98+
tree->GetEntry(i);
99+
100+
// check subgenerator information
101+
//if (eventHeader->hasInfo(o2::mcgenid::GeneratorProperty::SUBGENERATORID)) {
102+
// bool isValid = false;
103+
// int subGeneratorId = eventHeader->getInfo<int>(o2::mcgenid::GeneratorProperty::SUBGENERATORID, isValid);
104+
// if (subGeneratorId == 0) {
105+
// nEventsMB++;
106+
// } else if (subGeneratorId == checkPdgQuarkOne) {
107+
// nEventsInjOne++;
108+
// } else if (subGeneratorId == checkPdgQuarkTwo) {
109+
// nEventsInjTwo++;
110+
// }
111+
//}
112+
113+
for (auto &track : *tracks) {
114+
auto pdg = track.GetPdgCode();
115+
if (std::abs(pdg) == checkPdgQuarkOne) {
116+
nQuarksOne++;
117+
continue;
118+
}
119+
if (std::abs(pdg) == checkPdgQuarkTwo) {
120+
nQuarksTwo++;
121+
continue;
122+
}
123+
if (std::find(checkPdgHadron.begin(), checkPdgHadron.end(), std::abs(pdg)) != checkPdgHadron.end()) { // found signal
124+
nSignals++; // count signal PDG
125+
126+
std::vector<int> pdgsDecay{};
127+
std::vector<int> pdgsDecayAntiPart{};
128+
for (int j{track.getFirstDaughterTrackId()}; j <= track.getLastDaughterTrackId(); ++j) {
129+
auto pdgDau = tracks->at(j).GetPdgCode();
130+
pdgsDecay.push_back(pdgDau);
131+
if (pdgDau != 333 && pdgDau != 111 && pdgDau != 221 && pdgDau != 113 && pdgDau != 225) { // phi is antiparticle of itself
132+
pdgsDecayAntiPart.push_back(-pdgDau);
133+
} else {
134+
pdgsDecayAntiPart.push_back(pdgDau);
135+
}
136+
}
137+
138+
std::sort(pdgsDecay.begin(), pdgsDecay.end());
139+
std::sort(pdgsDecayAntiPart.begin(), pdgsDecayAntiPart.end());
140+
141+
for (auto &decay : checkHadronDecays[std::abs(pdg)]) {
142+
std::sort(decay.begin(), decay.end());
143+
if (pdgsDecay == decay || pdgsDecayAntiPart == decay) {
144+
nSignalGoodDecay++;
145+
break;
146+
}
147+
}
148+
}
149+
}
150+
}
151+
152+
std::cout << "--------------------------------\n";
153+
std::cout << "# Events: " << nEvents << "\n";
154+
//std::cout << "# MB events: " << nEventsMB << "\n";
155+
//std::cout << Form("# events injected with %d quark pair: ", checkPdgQuarkOne) << nEventsInjOne << "\n";
156+
//std::cout << Form("# events injected with %d quark pair: ", checkPdgQuarkTwo) << nEventsInjTwo << "\n";
157+
std::cout << Form("# %d (anti)quarks: ", checkPdgQuarkOne) << nQuarksOne << "\n";
158+
std::cout << Form("# %d (anti)quarks: ", checkPdgQuarkTwo) << nQuarksTwo << "\n";
159+
std::cout <<"# signal hadrons: " << nSignals << "\n";
160+
std::cout <<"# signal hadrons decaying in the correct channel: " << nSignalGoodDecay << "\n";
161+
162+
//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
163+
// std::cerr << "Number of generated MB events different than expected\n";
164+
// return 1;
165+
//}
166+
//if (nEventsInjOne < nEvents * ratioTrigger * 0.5 * 0.95 || nEventsInjOne > nEvents * ratioTrigger * 0.5 * 1.05) {
167+
// std::cerr << "Number of generated events injected with " << checkPdgQuarkOne << " different than expected\n";
168+
// return 1;
169+
//}
170+
//if (nEventsInjTwo < nEvents * ratioTrigger * 0.5 * 0.95 || nEventsInjTwo > nEvents * ratioTrigger * 0.5 * 1.05) {
171+
// std::cerr << "Number of generated events injected with " << checkPdgQuarkTwo << " different than expected\n";
172+
// return 1;
173+
//}
174+
175+
if (nQuarksOne < nEvents * ratioTrigger) { // we expect anyway more because the same quark is repeated several time, after each gluon radiation
176+
std::cerr << "Number of generated (anti)quarks " << checkPdgQuarkOne << " lower than expected\n";
177+
return 1;
178+
}
179+
if (nQuarksTwo < nEvents * ratioTrigger) { // we expect anyway more because the same quark is repeated several time, after each gluon radiation
180+
std::cerr << "Number of generated (anti)quarks " << checkPdgQuarkTwo << " lower than expected\n";
181+
return 1;
182+
}
183+
184+
float fracForcedDecays = nSignals ? float(nSignalGoodDecay) / nSignals : 0.0f;
185+
float uncFracForcedDecays = nSignals ? std::sqrt(fracForcedDecays * (1 - fracForcedDecays) / nSignals) : 1.0f;
186+
if (1 - fracForcedDecays > 0.15 + uncFracForcedDecays) { // we put some tolerance (e.g. due to oscillations which might change the final state)
187+
std::cerr << "Fraction of signals decaying into the correct channel " << fracForcedDecays << " lower than expected\n";
188+
return 1;
189+
}
190+
191+
return 0;
192+
}

0 commit comments

Comments
 (0)