|
| 1 | +int External() |
| 2 | +{ |
| 3 | + std::string path{"o2sim_Kine.root"}; |
| 4 | + |
| 5 | + // Check that file exists, can be opened and has the correct tree |
| 6 | + TFile file(path.c_str(), "READ"); |
| 7 | + if (file.IsZombie()) |
| 8 | + { |
| 9 | + std::cerr << "Cannot open ROOT file " << path << "\n"; |
| 10 | + return 1; |
| 11 | + } |
| 12 | + |
| 13 | + auto tree = (TTree *)file.Get("o2sim"); |
| 14 | + if (!tree) |
| 15 | + { |
| 16 | + std::cerr << "Cannot find tree o2sim in file " << path << "\n"; |
| 17 | + return 1; |
| 18 | + } |
| 19 | + |
| 20 | + std::vector<o2::MCTrack> *tracks{}; |
| 21 | + tree->SetBranchAddress("MCTrack", &tracks); |
| 22 | + |
| 23 | + // Check if all events are filled |
| 24 | + auto nEvents = tree->GetEntries(); |
| 25 | + for (Long64_t i = 0; i < nEvents; ++i) |
| 26 | + { |
| 27 | + tree->GetEntry(i); |
| 28 | + if (tracks->empty()) |
| 29 | + { |
| 30 | + std::cerr << "Empty entry found at event " << i << "\n"; |
| 31 | + return 1; |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + // Check if there is 1 event, as customly set in the ini file |
| 36 | + // Heavy-ion collisions with hydro and hadronic cascade are very slow to simulate |
| 37 | + if (nEvents != 1) |
| 38 | + { |
| 39 | + std::cerr << "Expected 1 event, got " << nEvents << "\n"; |
| 40 | + return 1; |
| 41 | + } |
| 42 | + |
| 43 | + // ---- Oxygen-Oxygen parameters ---- |
| 44 | + constexpr int kOxygenPDG = 1000080160; // O-16 ion |
| 45 | + constexpr double kEnucleon = 5360.; // GeV per nucleon |
| 46 | + constexpr int kA = 16; // Oxygen mass number |
| 47 | + constexpr double kOxygenEnergy = kA * kEnucleon; // 85760 GeV |
| 48 | + |
| 49 | + // Check if each event has two oxygen ions at expected energy |
| 50 | + for (int i = 0; i < nEvents; i++) |
| 51 | + { |
| 52 | + tree->GetEntry(i); |
| 53 | + int count = 0; |
| 54 | + |
| 55 | + for (int idxMCTrack = 0; idxMCTrack < tracks->size(); ++idxMCTrack) |
| 56 | + { |
| 57 | + auto track = tracks->at(idxMCTrack); |
| 58 | + double energy = track.GetEnergy(); |
| 59 | + |
| 60 | + // 50 MeV tolerance (floating point safety) |
| 61 | + if (std::abs(energy - kOxygenEnergy) < 5e-2 && |
| 62 | + track.GetPdgCode() == kOxygenPDG) |
| 63 | + { |
| 64 | + count++; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + if (count < 2) |
| 69 | + { |
| 70 | + std::cerr << "Event " << i |
| 71 | + << " has less than 2 oxygen ions at " |
| 72 | + << kOxygenEnergy << " GeV\n"; |
| 73 | + return 1; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + return 0; |
| 78 | +} |
0 commit comments