Skip to content

Commit 32389d2

Browse files
committed
test macro added
1 parent bdfacc6 commit 32389d2

File tree

1 file changed

+58
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)