|
| 1 | +int External() { |
| 2 | + std::string path{"o2sim_Kine.root"}; |
| 3 | + |
| 4 | + int checkPdgQuarkOne{4}; |
| 5 | + int checkPdgQuarkTwo{5}; |
| 6 | + float ratioTrigger = 1./5.; // one event triggered out of 5 |
| 7 | + |
| 8 | + std::vector<int> checkPdgHadron{411, 415, 421, 425, 431, 435, 511, 521, 531, 4122, 10411, 10421, 10433, 20423, 20433}; |
| 9 | + std::map<int, std::vector<std::vector<int>>> checkHadronDecays{ // sorted pdg of daughters |
| 10 | + {411, {{-321, 211, 211}, {-313, 211}, {211, 311}, {211, 333}}}, // D+ |
| 11 | + {415, {{211, 421}}}, // D2*(2460)+ |
| 12 | + {421, {{-321, 211}, {-321, 111, 211}}}, // D0 |
| 13 | + {425, {{-211, 413},{-211, 411}}}, // D2*(2460)0 |
| 14 | + {431, {{211, 333}, {-313, 321}}}, // Ds+ |
| 15 | + {425, {{311, 413}, {311, 411}, {321,421}}}, // Ds2*(2573) |
| 16 | + {511, {{-415, -11, 12}, {-10411, -11, 12}, {-415, -13, 14}, {-10411, -13, 14}, {-415, -15, 16}, {-10411, -15, 16}, |
| 17 | + {-10411, 211}, {-10421, 211}, {-415, 433}, { -415, 431}, {-415, 211}, {-415, 213} }}, // B0 |
| 18 | + {521, {{-20423, -11, 12}, {-425, -11, 12}, {-10421, -11, 12}, {-20423, -13, 14}, {-425, -13, 14}, {-10421, -13, 14}, |
| 19 | + {-20423, -15, 16}, {-425, -15, 16}, {-10421, -15, 16}, {-20423, 211}, {-20423, 213}, {-20423, 431}, {-20423, 433}, |
| 20 | + {-425, 211}, {-425, 213}, {-425, 431}, {-425, 433}}}, // B+ |
| 21 | + {531, {{-435, -11, 12}, {-10433, -11, 12}, {-435, -13, 14}, {-10433, -13, 14}, {-435, -15, 16}, {-10433, -15, 16}, |
| 22 | + {-435, 211}, {-20433, 211}, {-20433, 213}}},// Bs0 |
| 23 | + {4122, {{-313, 2212}, {-321, 2224}, {211, 3124}, {-321, 211, 2212}, {311, 2212}}}, // Lc+ |
| 24 | + {10411, {{211, 421}}}, // D0*+ |
| 25 | + {10421, {{-211, 411}}}, // D0*0 |
| 26 | + {10433, {{311, 413}}}, // Ds1(2536) |
| 27 | + {20423, {{-211, 413}}}, // D1(2430)0 |
| 28 | + {20433, {{22, 431}, {-211, 211, 431} }} // Ds1 (2460) |
| 29 | + }; |
| 30 | + |
| 31 | + TFile file(path.c_str(), "READ"); |
| 32 | + if (file.IsZombie()) { |
| 33 | + std::cerr << "Cannot open ROOT file " << path << "\n"; |
| 34 | + return 1; |
| 35 | + } |
| 36 | + |
| 37 | + auto tree = (TTree *)file.Get("o2sim"); |
| 38 | + std::vector<o2::MCTrack> *tracks{}; |
| 39 | + tree->SetBranchAddress("MCTrack", &tracks); |
| 40 | + o2::dataformats::MCEventHeader *eventHeader = nullptr; |
| 41 | + tree->SetBranchAddress("MCEventHeader.", &eventHeader); |
| 42 | + |
| 43 | + int nEventsMB{}, nEventsInjOne{}, nEventsInjTwo{}; |
| 44 | + int nQuarksOne{}, nQuarksTwo{}, nSignals{}, nSignalGoodDecay{}; |
| 45 | + auto nEvents = tree->GetEntries(); |
| 46 | + |
| 47 | + for (int i = 0; i < nEvents; i++) { |
| 48 | + tree->GetEntry(i); |
| 49 | + |
| 50 | + // check subgenerator information |
| 51 | + if (eventHeader->hasInfo(o2::mcgenid::GeneratorProperty::SUBGENERATORID)) { |
| 52 | + bool isValid = false; |
| 53 | + int subGeneratorId = eventHeader->getInfo<int>(o2::mcgenid::GeneratorProperty::SUBGENERATORID, isValid); |
| 54 | + if (subGeneratorId == 0) { |
| 55 | + nEventsMB++; |
| 56 | + } else if (subGeneratorId == checkPdgQuarkOne) { |
| 57 | + nEventsInjOne++; |
| 58 | + } else if (subGeneratorId == checkPdgQuarkTwo) { |
| 59 | + nEventsInjTwo++; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + for (auto &track : *tracks) { |
| 64 | + auto pdg = track.GetPdgCode(); |
| 65 | + if (std::abs(pdg) == checkPdgQuarkOne) { |
| 66 | + nQuarksOne++; |
| 67 | + continue; |
| 68 | + } |
| 69 | + if (std::abs(pdg) == checkPdgQuarkTwo) { |
| 70 | + nQuarksTwo++; |
| 71 | + continue; |
| 72 | + } |
| 73 | + if (std::find(checkPdgHadron.begin(), checkPdgHadron.end(), std::abs(pdg)) != checkPdgHadron.end()) { // found signal |
| 74 | + nSignals++; // count signal PDG |
| 75 | + |
| 76 | + std::vector<int> pdgsDecay{}; |
| 77 | + std::vector<int> pdgsDecayAntiPart{}; |
| 78 | + for (int j{track.getFirstDaughterTrackId()}; j <= track.getLastDaughterTrackId(); ++j) { |
| 79 | + auto pdgDau = tracks->at(j).GetPdgCode(); |
| 80 | + pdgsDecay.push_back(pdgDau); |
| 81 | + if (pdgDau != 333) { // phi is antiparticle of itself |
| 82 | + pdgsDecayAntiPart.push_back(-pdgDau); |
| 83 | + } else { |
| 84 | + pdgsDecayAntiPart.push_back(pdgDau); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + std::sort(pdgsDecay.begin(), pdgsDecay.end()); |
| 89 | + std::sort(pdgsDecayAntiPart.begin(), pdgsDecayAntiPart.end()); |
| 90 | + |
| 91 | + for (auto &decay : checkHadronDecays[std::abs(pdg)]) { |
| 92 | + if (pdgsDecay == decay || pdgsDecayAntiPart == decay) { |
| 93 | + nSignalGoodDecay++; |
| 94 | + break; |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + std::cout << "--------------------------------\n"; |
| 102 | + std::cout << "# Events: " << nEvents << "\n"; |
| 103 | + std::cout << "# MB events: " << nEventsMB << "\n"; |
| 104 | + std::cout << Form("# events injected with %d quark pair: ", checkPdgQuarkOne) << nEventsInjOne << "\n"; |
| 105 | + std::cout << Form("# events injected with %d quark pair: ", checkPdgQuarkTwo) << nEventsInjTwo << "\n"; |
| 106 | + std::cout << Form("# %d (anti)quarks: ", checkPdgQuarkOne) << nQuarksOne << "\n"; |
| 107 | + std::cout << Form("# %d (anti)quarks: ", checkPdgQuarkTwo) << nQuarksTwo << "\n"; |
| 108 | + std::cout <<"# signal hadrons: " << nSignals << "\n"; |
| 109 | + std::cout <<"# signal hadrons decaying in the correct channel: " << nSignalGoodDecay << "\n"; |
| 110 | + |
| 111 | + 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 |
| 112 | + std::cerr << "Number of generated MB events different than expected\n"; |
| 113 | + return 1; |
| 114 | + } |
| 115 | + if (nEventsInjOne < nEvents * ratioTrigger * 0.5 * 0.95 || nEventsInjOne > nEvents * ratioTrigger * 0.5 * 1.05) { |
| 116 | + std::cerr << "Number of generated events injected with " << checkPdgQuarkOne << " different than expected\n"; |
| 117 | + return 1; |
| 118 | + } |
| 119 | + if (nEventsInjTwo < nEvents * ratioTrigger * 0.5 * 0.95 || nEventsInjTwo > nEvents * ratioTrigger * 0.5 * 1.05) { |
| 120 | + std::cerr << "Number of generated events injected with " << checkPdgQuarkTwo << " different than expected\n"; |
| 121 | + return 1; |
| 122 | + } |
| 123 | + |
| 124 | + if (nQuarksOne < nEvents * ratioTrigger) { // we expect anyway more because the same quark is repeated several time, after each gluon radiation |
| 125 | + std::cerr << "Number of generated (anti)quarks " << checkPdgQuarkOne << " lower than expected\n"; |
| 126 | + return 1; |
| 127 | + } |
| 128 | + if (nQuarksTwo < nEvents * ratioTrigger) { // we expect anyway more because the same quark is repeated several time, after each gluon radiation |
| 129 | + std::cerr << "Number of generated (anti)quarks " << checkPdgQuarkTwo << " lower than expected\n"; |
| 130 | + return 1; |
| 131 | + } |
| 132 | + |
| 133 | + float fracForcedDecays = float(nSignalGoodDecay) / nSignals; |
| 134 | + if (fracForcedDecays < 0.9) { // we put some tolerance (e.g. due to oscillations which might change the final state) |
| 135 | + std::cerr << "Fraction of signals decaying into the correct channel " << fracForcedDecays << " lower than expected\n"; |
| 136 | + return 1; |
| 137 | + } |
| 138 | + |
| 139 | + return 0; |
| 140 | +} |
0 commit comments