|
| 1 | +int ExternalLc() { |
| 2 | + std::string path{"o2sim_Kine.root"}; |
| 3 | + |
| 4 | + int checkPdgQuarkOne{4}; // c quark injection |
| 5 | + int checkPdgQuarkTwo{5}; // b quark injection |
| 6 | + float ratioTrigger = 1./5.; // one event triggered out of 5 |
| 7 | + |
| 8 | + // PDG replacements: Λc(4122) -> resonances |
| 9 | + std::array<std::array<int, 2>, 4> pdgReplParticles = { |
| 10 | + std::array{4122, 34122}, // Λc -> Λc(2860) |
| 11 | + std::array{4122, 44122}, // Λc -> Λc(2880) |
| 12 | + std::array{4122, 54122}, // Λc -> Λc(2940) |
| 13 | + std::array{4122, 9422111} // Λc -> Tc(3100) |
| 14 | + }; |
| 15 | + |
| 16 | + // Counters for replacements |
| 17 | + std::array<std::array<int, 2>, 4> pdgReplPartCounters = { |
| 18 | + std::array{0,0}, std::array{0,0}, std::array{0,0}, std::array{0,0} |
| 19 | + }; |
| 20 | + |
| 21 | + std::array<float, 4> freqRepl = {0.2, 0.2, 0.2, 0.2}; |
| 22 | + std::map<int,int> sumOrigReplacedParticles = {{4122,0}}; |
| 23 | + |
| 24 | + // Hadrons to check |
| 25 | + std::array<int, 5> checkPdgHadron{34122, 44122, 54122, 9422111, 5122}; |
| 26 | + |
| 27 | + // Correct decays |
| 28 | + std::map<int, std::vector<std::vector<int>>> checkHadronDecays{ |
| 29 | + {34122, {{421, 2212}}}, |
| 30 | + {44122, {{421, 2212}}}, |
| 31 | + {54122, {{421, 2212}}}, |
| 32 | + {9422111, {{413, 2212}}}, |
| 33 | + {5122, {{421, 2212, -211}, {41221, -211}, {34122, -211}, {44122, -211}, {54122, -211}}} |
| 34 | + }; |
| 35 | + |
| 36 | + TFile file(path.c_str(), "READ"); |
| 37 | + if (file.IsZombie()) { std::cerr << "Cannot open ROOT file " << path << "\n"; return 1; } |
| 38 | + |
| 39 | + auto tree = (TTree*)file.Get("o2sim"); |
| 40 | + std::vector<o2::MCTrack>* tracks{}; |
| 41 | + tree->SetBranchAddress("MCTrack", &tracks); |
| 42 | + o2::dataformats::MCEventHeader* eventHeader = nullptr; |
| 43 | + tree->SetBranchAddress("MCEventHeader.", &eventHeader); |
| 44 | + |
| 45 | + int nEventsMB{}, nEventsInjOne{}, nEventsInjTwo{}; |
| 46 | + int nSignals{}, nSignalGoodDecay{}; |
| 47 | + auto nEvents = tree->GetEntries(); |
| 48 | + |
| 49 | + std::map<int,int> signalHadronsPerType; |
| 50 | + std::map<int,int> signalGoodDecayPerType; |
| 51 | + for (auto pdg : checkPdgHadron) { signalHadronsPerType[pdg] = 0; signalGoodDecayPerType[pdg] = 0; } |
| 52 | + |
| 53 | + for (int i=0; i<nEvents; i++) { |
| 54 | + tree->GetEntry(i); |
| 55 | + |
| 56 | + int subGeneratorId{-1}; |
| 57 | + if (eventHeader->hasInfo(o2::mcgenid::GeneratorProperty::SUBGENERATORID)) { |
| 58 | + bool isValid=false; |
| 59 | + subGeneratorId = eventHeader->getInfo<int>(o2::mcgenid::GeneratorProperty::SUBGENERATORID, isValid); |
| 60 | + if (subGeneratorId==0) nEventsMB++; |
| 61 | + else if (subGeneratorId==checkPdgQuarkOne) nEventsInjOne++; |
| 62 | + else if (subGeneratorId==checkPdgQuarkTwo) nEventsInjTwo++; |
| 63 | + } |
| 64 | + |
| 65 | + for (auto& track : *tracks) { |
| 66 | + int pdg = track.GetPdgCode(); |
| 67 | + int absPdg = std::abs(pdg); |
| 68 | + |
| 69 | + if (std::find(checkPdgHadron.begin(), checkPdgHadron.end(), absPdg) != checkPdgHadron.end()) { |
| 70 | + nSignals++; |
| 71 | + signalHadronsPerType[absPdg]++; |
| 72 | + |
| 73 | + if (subGeneratorId==checkPdgQuarkOne) { |
| 74 | + for (int iRepl=0; iRepl<3; ++iRepl) { |
| 75 | + if (absPdg == pdgReplParticles[iRepl][0]) { pdgReplPartCounters[iRepl][0]++; sumOrigReplacedParticles[pdgReplParticles[iRepl][0]]++; } |
| 76 | + else if (absPdg == pdgReplParticles[iRepl][1]) { pdgReplPartCounters[iRepl][1]++; sumOrigReplacedParticles[pdgReplParticles[iRepl][0]]++; } |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + std::vector<int> pdgsDecay; |
| 81 | + std::vector<int> pdgsDecayAnti; |
| 82 | + if (track.getFirstDaughterTrackId()>=0) { |
| 83 | + for (int j=track.getFirstDaughterTrackId(); j<=track.getLastDaughterTrackId(); ++j) { |
| 84 | + int pdgDau = tracks->at(j).GetPdgCode(); |
| 85 | + pdgsDecay.push_back(pdgDau); |
| 86 | + pdgsDecayAnti.push_back((pdgDau==111||pdgDau==333)? pdgDau : -pdgDau); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + std::sort(pdgsDecay.begin(), pdgsDecay.end()); |
| 91 | + std::sort(pdgsDecayAnti.begin(), pdgsDecayAnti.end()); |
| 92 | + |
| 93 | + bool matchedDecay = false; |
| 94 | + for (auto& decay : checkHadronDecays[absPdg]) { |
| 95 | + std::vector<int> decayCopy = decay; |
| 96 | + std::sort(decayCopy.begin(), decayCopy.end()); |
| 97 | + if (pdgsDecay == decayCopy || pdgsDecayAnti == decayCopy) { |
| 98 | + matchedDecay = true; |
| 99 | + nSignalGoodDecay++; |
| 100 | + signalGoodDecayPerType[absPdg]++; |
| 101 | + break; |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + // Print daughters |
| 106 | + std::cout << "Particle " << absPdg << " daughters: "; |
| 107 | + for (auto d : pdgsDecay) std::cout << d << " "; |
| 108 | + if (matchedDecay) std::cout << "(matches expected decay)"; |
| 109 | + else std::cout << "(does NOT match expected decay)"; |
| 110 | + std::cout << "\n"; |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + std::cout << "--------------------------------\n"; |
| 116 | + std::cout << "# Events: " << nEvents << "\n"; |
| 117 | + std::cout << "# MB events: " << nEventsMB << "\n"; |
| 118 | + std::cout << "# events injected with " << checkPdgQuarkOne << ": " << nEventsInjOne << "\n"; |
| 119 | + std::cout << "# events injected with " << checkPdgQuarkTwo << ": " << nEventsInjTwo << "\n"; |
| 120 | + std::cout << "# signal hadrons: " << nSignals << "\n"; |
| 121 | + std::cout << "# signal hadrons decaying in correct channels: " << nSignalGoodDecay << "\n"; |
| 122 | + |
| 123 | + for (auto& [pdg, count] : signalHadronsPerType) { |
| 124 | + int good = signalGoodDecayPerType[pdg]; |
| 125 | + float frac = count>0 ? float(good)/count : 0.; |
| 126 | + std::cout << "Particle " << pdg << ": " << count << " signals, " << good << " good decays, fraction: " << frac << "\n"; |
| 127 | + } |
| 128 | + |
| 129 | + // Optional: sanity checks... |
| 130 | + return 0; |
| 131 | +} |
0 commit comments