|
| 1 | +int External() { |
| 2 | + std::string path{"~/test_evtgen/tf3/genevents_Kine.root"};//{"o2sim_Kine.root"}; |
| 3 | + |
| 4 | + int checkPdgQuark{5}; |
| 5 | + float ratioTrigger = 1./5; // one event triggered out of 5 |
| 6 | + |
| 7 | + std::vector<int> checkPdgHadron{443, 511, 521, 531, 5122}; |
| 8 | + std::map<int, std::vector<std::vector<int>>> checkHadronDecays{ // sorted pdg of daughters |
| 9 | + {443, {{-11, 11}, {-13, 13}}}, // J/psi |
| 10 | + {511, {{313, 443}}}, // B0 |
| 11 | + {521, {{321, 443}}}, // B+ |
| 12 | + {531, {{333, 443}}}, // Bs0 |
| 13 | + {5122, {{321, 443, 2212}}} // Lb0 |
| 14 | + }; |
| 15 | + |
| 16 | + TFile file(path.c_str(), "READ"); |
| 17 | + if (file.IsZombie()) { |
| 18 | + std::cerr << "Cannot open ROOT file " << path << "\n"; |
| 19 | + return 1; |
| 20 | + } |
| 21 | + |
| 22 | + auto tree = (TTree *)file.Get("o2sim"); |
| 23 | + std::vector<o2::MCTrack> *tracks{}; |
| 24 | + tree->SetBranchAddress("MCTrack", &tracks); |
| 25 | + o2::dataformats::MCEventHeader *eventHeader = nullptr; |
| 26 | + tree->SetBranchAddress("MCEventHeader.", &eventHeader); |
| 27 | + |
| 28 | + int nEventsMB{}, nEventsInj{}; |
| 29 | + int nSignals{}, nSignalGoodDecay{}; |
| 30 | + int nJPsiToEE{}, nJPsiToMuMu{}; |
| 31 | + auto nEvents = tree->GetEntries(); |
| 32 | + |
| 33 | + for (int i = 0; i < nEvents; i++) { |
| 34 | + tree->GetEntry(i); |
| 35 | + |
| 36 | + // check subgenerator information |
| 37 | + if (eventHeader->hasInfo(o2::mcgenid::GeneratorProperty::SUBGENERATORID)) { |
| 38 | + bool isValid = false; |
| 39 | + int subGeneratorId = eventHeader->getInfo<int>(o2::mcgenid::GeneratorProperty::SUBGENERATORID, isValid); |
| 40 | + if (subGeneratorId == 0) { |
| 41 | + nEventsMB++; |
| 42 | + } else if (subGeneratorId == checkPdgQuark) { |
| 43 | + nEventsInj++; |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + for (auto &track : *tracks) { |
| 48 | + auto pdg = track.GetPdgCode(); |
| 49 | + if (std::find(checkPdgHadron.begin(), checkPdgHadron.end(), std::abs(pdg)) != checkPdgHadron.end()) { // found signal |
| 50 | + nSignals++; // count signal PDG |
| 51 | + |
| 52 | + std::vector<int> pdgsDecay{}; |
| 53 | + std::vector<int> pdgsDecayAntiPart{}; |
| 54 | + for (int j{track.getFirstDaughterTrackId()}; j <= track.getLastDaughterTrackId(); ++j) { |
| 55 | + auto pdgDau = tracks->at(j).GetPdgCode(); |
| 56 | + if (pdg == 443 && pdgDau == 22) { |
| 57 | + continue; |
| 58 | + } |
| 59 | + pdgsDecay.push_back(pdgDau); |
| 60 | + if (pdgDau != 333) { // phi is antiparticle of itself |
| 61 | + pdgsDecayAntiPart.push_back(-pdgDau); |
| 62 | + } else { |
| 63 | + pdgsDecayAntiPart.push_back(pdgDau); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + std::sort(pdgsDecay.begin(), pdgsDecay.end()); |
| 68 | + std::sort(pdgsDecayAntiPart.begin(), pdgsDecayAntiPart.end()); |
| 69 | + |
| 70 | + for (auto &decay : checkHadronDecays[std::abs(pdg)]) { |
| 71 | + if (pdgsDecay == decay || pdgsDecayAntiPart == decay) { |
| 72 | + nSignalGoodDecay++; |
| 73 | + if (pdg == 443) { |
| 74 | + if (decay == std::vector{-11, 11}) { |
| 75 | + nJPsiToEE++; |
| 76 | + } else if (decay == std::vector{-13, 13}) { |
| 77 | + nJPsiToMuMu++; |
| 78 | + } |
| 79 | + } |
| 80 | + break; |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + std::cout << "--------------------------------\n"; |
| 88 | + std::cout << "# Events: " << nEvents << "\n"; |
| 89 | + std::cout << "# MB events: " << nEventsMB << "\n"; |
| 90 | + std::cout << Form("# events injected with %d quark pair: ", checkPdgQuark) << nEventsInj << "\n"; |
| 91 | + std::cout <<"# signal hadrons: " << nSignals << "\n"; |
| 92 | + std::cout <<"# signal hadrons decaying in the correct channel: " << nSignalGoodDecay << "\n"; |
| 93 | + std::cout <<"# J/Psi decaying to e+e-: " << nJPsiToEE << "\n"; |
| 94 | + std::cout <<"# J/Psi decaying to mu+mu-: " << nJPsiToMuMu << "\n"; |
| 95 | + |
| 96 | + if (nEventsMB < nEvents * (1 - ratioTrigger) * 0.95 || nEventsMB > nEvents * (1 - ratioTrigger) * 1.05) { // we put some tolerance since the number of generated events is small |
| 97 | + std::cerr << "Number of generated MB events different than expected\n"; |
| 98 | + return 1; |
| 99 | + } |
| 100 | + if (nEventsInj < nEvents * ratioTrigger * 0.95 || nEventsInj > nEvents * ratioTrigger * 1.05) { |
| 101 | + std::cerr << "Number of generated events injected with " << checkPdgQuark << " different than expected\n"; |
| 102 | + return 1; |
| 103 | + } |
| 104 | + |
| 105 | + float fracForcedDecays = nSignals ? float(nSignalGoodDecay) / nSignals : 0.0f; |
| 106 | + float uncFracForcedDecays = nSignals ? std::sqrt(fracForcedDecays * (1 - fracForcedDecays) / nSignals) : 1.0f; |
| 107 | + if (1 - fracForcedDecays > 0.5 + uncFracForcedDecays) { // at least 50% in the main decay channels (we also have correlated backgrounds, mostly from other B decays) |
| 108 | + std::cerr << "Fraction of signals decaying into the correct channel " << fracForcedDecays << " lower than expected\n"; |
| 109 | + return 1; |
| 110 | + } |
| 111 | + |
| 112 | + return 0; |
| 113 | +} |
0 commit comments