Skip to content

Commit 6b61a47

Browse files
authored
Add test file
1 parent 12937b7 commit 6b61a47

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
std::cerr << "Cannot open ROOT file " << path << "\n";
8+
return 1;
9+
}
10+
auto tree = (TTree*)file.Get("o2sim");
11+
if (!tree) {
12+
std::cerr << "Cannot find tree o2sim in file " << path << "\n";
13+
return 1;
14+
}
15+
std::vector<o2::MCTrack>* tracks{};
16+
tree->SetBranchAddress("MCTrack", &tracks);
17+
o2::dataformats::MCEventHeader* eventHeader = nullptr;
18+
tree->SetBranchAddress("MCEventHeader.", &eventHeader);
19+
20+
// Check if there are 2 events, as simulated in the o2dpg-test
21+
auto nEvents = tree->GetEntries();
22+
if (nEvents != 2) {
23+
std::cerr << "Expected 2 events, got " << nEvents << "\n";
24+
return 1;
25+
}
26+
// Beam momentum per nucleon for OO at sqrt(s_NN) = 5.36 TeV
27+
const double beamMomentum = std::sqrt(2680. * 2680. - 0.938 * 0.938);
28+
for (Long64_t i = 0; i < nEvents; ++i) {
29+
tree->GetEntry(i);
30+
if (tracks->empty()) {
31+
std::cerr << "Empty entry found at event " << i << "\n";
32+
return 1;
33+
}
34+
// Check the heavy-ion information of the header
35+
bool isValid = false;
36+
auto nPart = eventHeader->getInfo<int>(o2::dataformats::MCInfoKeys::nPart, isValid);
37+
if (!isValid || nPart <= 0) {
38+
std::cerr << "Event " << i << " has no valid number of participants\n";
39+
return 1;
40+
}
41+
if (eventHeader->GetB() < 0. || eventHeader->GetB() > 20.) {
42+
std::cerr << "Event " << i << " has impact parameter " << eventHeader->GetB() << " outside the [0, 20] fm range\n";
43+
return 1;
44+
}
45+
// Spectator nucleons (pT = 0, beam momentum) must be kept for both beams.
46+
// AMPT writes momenta with 4 decimals, hence the tolerance
47+
int nSpectatorsA = 0, nSpectatorsC = 0;
48+
for (const auto& track : *tracks) {
49+
if (track.GetPdgCode() != 2212 && track.GetPdgCode() != 2112) {
50+
continue;
51+
}
52+
if (track.GetPt() == 0. && std::abs(std::abs(track.GetStartVertexMomentumZ()) - beamMomentum) < 1e-2) {
53+
(track.GetStartVertexMomentumZ() > 0 ? nSpectatorsA : nSpectatorsC)++;
54+
}
55+
}
56+
// The total number of nucleons in each nucleus must be conserved
57+
if (nSpectatorsA + nSpectatorsC + nPart > 2 * 208) {
58+
std::cerr << "Event " << i << " has more nucleons than the colliding nuclei\n";
59+
return 1;
60+
}
61+
if (nSpectatorsA == 0 || nSpectatorsC == 0) {
62+
std::cerr << "Event " << i << " has no spectator nucleons (A side: " << nSpectatorsA << ", C side: " << nSpectatorsC << ")\n";
63+
return 1;
64+
}
65+
std::cout << "Event " << i << ": " << tracks->size() << " tracks, b = " << eventHeader->GetB() << " fm, Npart = " << nPart
66+
<< ", spectators A/C = " << nSpectatorsA << "/" << nSpectatorsC << "\n";
67+
}
68+
return 0;
69+
}

0 commit comments

Comments
 (0)