Skip to content

Commit eafe367

Browse files
committed
added validation routine
1 parent a0601bb commit eafe367

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
int External()
2+
{
3+
std::string path{"o2sim_Kine.root"};
4+
// Check that file exists, can be opened and has the correct tree
5+
TFile file(path.c_str(), "READ");
6+
if (file.IsZombie())
7+
{
8+
std::cerr << "Cannot open ROOT file " << path << "\n";
9+
return 1;
10+
}
11+
auto tree = (TTree *)file.Get("o2sim");
12+
if (!tree)
13+
{
14+
std::cerr << "Cannot find tree o2sim in file " << path << "\n";
15+
return 1;
16+
}
17+
std::vector<o2::MCTrack> *tracks{};
18+
tree->SetBranchAddress("MCTrack", &tracks);
19+
20+
// Check if all events are filled
21+
auto nEvents = tree->GetEntries();
22+
for (Long64_t i = 0; i < nEvents; ++i)
23+
{
24+
tree->GetEntry(i);
25+
if (tracks->empty())
26+
{
27+
std::cerr << "Empty entry found at event " << i << "\n";
28+
return 1;
29+
}
30+
}
31+
// Check if there are 100 events, as simulated in the o2dpg-test
32+
if (nEvents != 100)
33+
{
34+
std::cerr << "Expected 100 events, got " << nEvents << "\n";
35+
return 1;
36+
}
37+
// check if each event has two protons with 6800 GeV of energy
38+
// exits if the particle is not a proton
39+
for (int i = 0; i < nEvents; i++)
40+
{
41+
auto check = tree->GetEntry(i);
42+
int count = 0;
43+
for (int idxMCTrack = 0; idxMCTrack < tracks->size(); ++idxMCTrack)
44+
{
45+
auto track = tracks->at(idxMCTrack);
46+
double energy = track.GetEnergy();
47+
// Check if track energy is approximately equal to 6800 GeV (a tolerance of 65 keV is considered, straight equality does not work due to floating point precision)
48+
if (std::abs(energy - 6500) < 1e-4)
49+
{
50+
if (track.GetPdgCode() != 2212){
51+
std::cerr << "Found 6500 GeV particle with pdgID " << track.GetPdgCode() << "\n";
52+
return 1;
53+
}
54+
count++;
55+
}
56+
}
57+
if (count < 2)
58+
{
59+
std::cerr << "Event " << i << " has less than 2 protons at 6500 GeV\n";
60+
return 1;
61+
}
62+
}
63+
return 0;
64+
}

0 commit comments

Comments
 (0)