|
| 1 | +int External() { |
| 2 | + std::string path{"o2sim_Kine.root"}; |
| 3 | + //std::string path{"tf1/sgn_1_Kine.root"}; |
| 4 | + |
| 5 | + int checkPdgQuarkOne{4}; |
| 6 | + int checkPdgQuarkTwo{5}; |
| 7 | + float ratioTrigger = 1.; // one event triggered out of 1 |
| 8 | + |
| 9 | + std::vector<int> checkPdgHadron{411, 421, 431, 4122, 4232}; |
| 10 | + std::map<int, std::vector<std::vector<int>>> checkHadronDecays{ // sorted pdg of daughters |
| 11 | + {411, { |
| 12 | + {-321, 211, 211}, // K- π+ π+ (non-resonant) |
| 13 | + {-313, 321}, // K*0(892) K+ |
| 14 | + {-10311, 321}, // K*0(1430) K+ |
| 15 | + {211, 333}, // φ π+ |
| 16 | + {-321, 321, 211}, // K- K+ π+ (non-resonant) |
| 17 | + {113, 211}, // ρ0 π+ |
| 18 | + {225, 211}, // f2(1270) π+ |
| 19 | + {-211, 211, 211} // π- π+ π+ (non-resonant) |
| 20 | + }}, |
| 21 | + {421, { |
| 22 | + {-321, 211}, // K- π+ (non-resonant) |
| 23 | + {-321, 111, 211}, // K- π+ π0 |
| 24 | + {213, -321}, // ρ+ K- |
| 25 | + {-313, 111}, // antiK*0(892) π0 |
| 26 | + {-323, 211}, // K*-(892) π+ |
| 27 | + {-211, 211}, // π- π+ |
| 28 | + {213, -211}, // ρ+ π- |
| 29 | + {-211, 211, 111}, // π- π+ π0 |
| 30 | + {-321, 321} // K- K+ |
| 31 | + }}, |
| 32 | + {431, { |
| 33 | + {211, 333}, // φ π+ |
| 34 | + {-313, 321}, // antiK*(892) K+ |
| 35 | + {333, 213}, // φ ρ |
| 36 | + {113, 211}, // ρ π+ |
| 37 | + {225, 211}, // f2(1270) π+ |
| 38 | + {-211, 211, 211}, // π- π+ π+ (s-wave) |
| 39 | + {313, 211}, // K*(892)0 π+ |
| 40 | + {10221, 321}, // f0(1370) K+ |
| 41 | + {113, 321}, // ρ0 K+ |
| 42 | + {-211, 321, 211}, // π- K+ π+ (non-resonant) |
| 43 | + {221, 211} // η π+ |
| 44 | + }}, |
| 45 | + {4122, { |
| 46 | + {2212, -321, 211}, // p K- π+ (non-resonant) |
| 47 | + {2212, -313}, // p K*0(892) |
| 48 | + {2224, -321}, // Δ++ K- |
| 49 | + {102134, 211}, // Λ(1520) K- |
| 50 | + {2212, -321, 211, 111}, // p K- π+ π0 |
| 51 | + {2212, -211, 211}, // p π- π+ |
| 52 | + {2212, 333} // p φ |
| 53 | + }}, |
| 54 | + {4232, { |
| 55 | + {-313, 2212}, // antiK*0(892) p |
| 56 | + {2212, -321, 211}, // p K- π+ |
| 57 | + {2212, 333}, // p φ |
| 58 | + {3222, -211, 211} // Σ+ π- π+ |
| 59 | + }}, |
| 60 | + }; |
| 61 | + |
| 62 | + |
| 63 | + TFile file(path.c_str(), "READ"); |
| 64 | + if (file.IsZombie()) { |
| 65 | + std::cerr << "Cannot open ROOT file " << path << "\n"; |
| 66 | + return 1; |
| 67 | + } |
| 68 | + |
| 69 | + auto tree = (TTree *)file.Get("o2sim"); |
| 70 | + std::vector<o2::MCTrack> *tracks{}; |
| 71 | + tree->SetBranchAddress("MCTrack", &tracks); |
| 72 | + o2::dataformats::MCEventHeader *eventHeader = nullptr; |
| 73 | + tree->SetBranchAddress("MCEventHeader.", &eventHeader); |
| 74 | + |
| 75 | + int nEventsMB{}, nEventsInjOne{}, nEventsInjTwo{}; |
| 76 | + int nQuarksOne{}, nQuarksTwo{}, nSignals{}, nSignalGoodDecay{}; |
| 77 | + auto nEvents = tree->GetEntries(); |
| 78 | + |
| 79 | + for (int i = 0; i < nEvents; i++) { |
| 80 | + tree->GetEntry(i); |
| 81 | + |
| 82 | + // check subgenerator information |
| 83 | + //if (eventHeader->hasInfo(o2::mcgenid::GeneratorProperty::SUBGENERATORID)) { |
| 84 | + // bool isValid = false; |
| 85 | + // int subGeneratorId = eventHeader->getInfo<int>(o2::mcgenid::GeneratorProperty::SUBGENERATORID, isValid); |
| 86 | + // if (subGeneratorId == 0) { |
| 87 | + // nEventsMB++; |
| 88 | + // } else if (subGeneratorId == checkPdgQuarkOne) { |
| 89 | + // nEventsInjOne++; |
| 90 | + // } else if (subGeneratorId == checkPdgQuarkTwo) { |
| 91 | + // nEventsInjTwo++; |
| 92 | + // } |
| 93 | + //} |
| 94 | + |
| 95 | + for (auto &track : *tracks) { |
| 96 | + auto pdg = track.GetPdgCode(); |
| 97 | + if (std::abs(pdg) == checkPdgQuarkOne) { |
| 98 | + nQuarksOne++; |
| 99 | + continue; |
| 100 | + } |
| 101 | + if (std::abs(pdg) == checkPdgQuarkTwo) { |
| 102 | + nQuarksTwo++; |
| 103 | + continue; |
| 104 | + } |
| 105 | + if (std::find(checkPdgHadron.begin(), checkPdgHadron.end(), std::abs(pdg)) != checkPdgHadron.end()) { // found signal |
| 106 | + nSignals++; // count signal PDG |
| 107 | + |
| 108 | + std::vector<int> pdgsDecay{}; |
| 109 | + std::vector<int> pdgsDecayAntiPart{}; |
| 110 | + for (int j{track.getFirstDaughterTrackId()}; j <= track.getLastDaughterTrackId(); ++j) { |
| 111 | + auto pdgDau = tracks->at(j).GetPdgCode(); |
| 112 | + pdgsDecay.push_back(pdgDau); |
| 113 | + if (pdgDau != 333) { // phi is antiparticle of itself |
| 114 | + pdgsDecayAntiPart.push_back(-pdgDau); |
| 115 | + } else { |
| 116 | + pdgsDecayAntiPart.push_back(pdgDau); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + std::sort(pdgsDecay.begin(), pdgsDecay.end()); |
| 121 | + std::sort(pdgsDecayAntiPart.begin(), pdgsDecayAntiPart.end()); |
| 122 | + |
| 123 | + for (auto &decay : checkHadronDecays[std::abs(pdg)]) { |
| 124 | + if (pdgsDecay == decay || pdgsDecayAntiPart == decay) { |
| 125 | + nSignalGoodDecay++; |
| 126 | + break; |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + std::cout << "--------------------------------\n"; |
| 134 | + std::cout << "# Events: " << nEvents << "\n"; |
| 135 | + //std::cout << "# MB events: " << nEventsMB << "\n"; |
| 136 | + //std::cout << Form("# events injected with %d quark pair: ", checkPdgQuarkOne) << nEventsInjOne << "\n"; |
| 137 | + //std::cout << Form("# events injected with %d quark pair: ", checkPdgQuarkTwo) << nEventsInjTwo << "\n"; |
| 138 | + std::cout << Form("# %d (anti)quarks: ", checkPdgQuarkOne) << nQuarksOne << "\n"; |
| 139 | + std::cout << Form("# %d (anti)quarks: ", checkPdgQuarkTwo) << nQuarksTwo << "\n"; |
| 140 | + std::cout <<"# signal hadrons: " << nSignals << "\n"; |
| 141 | + std::cout <<"# signal hadrons decaying in the correct channel: " << nSignalGoodDecay << "\n"; |
| 142 | + |
| 143 | + //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 |
| 144 | + // std::cerr << "Number of generated MB events different than expected\n"; |
| 145 | + // return 1; |
| 146 | + //} |
| 147 | + //if (nEventsInjOne < nEvents * ratioTrigger * 0.5 * 0.95 || nEventsInjOne > nEvents * ratioTrigger * 0.5 * 1.05) { |
| 148 | + // std::cerr << "Number of generated events injected with " << checkPdgQuarkOne << " different than expected\n"; |
| 149 | + // return 1; |
| 150 | + //} |
| 151 | + //if (nEventsInjTwo < nEvents * ratioTrigger * 0.5 * 0.95 || nEventsInjTwo > nEvents * ratioTrigger * 0.5 * 1.05) { |
| 152 | + // std::cerr << "Number of generated events injected with " << checkPdgQuarkTwo << " different than expected\n"; |
| 153 | + // return 1; |
| 154 | + //} |
| 155 | + |
| 156 | + if (nQuarksOne < nEvents * ratioTrigger) { // we expect anyway more because the same quark is repeated several time, after each gluon radiation |
| 157 | + std::cerr << "Number of generated (anti)quarks " << checkPdgQuarkOne << " lower than expected\n"; |
| 158 | + return 1; |
| 159 | + } |
| 160 | + if (nQuarksTwo < nEvents * ratioTrigger) { // we expect anyway more because the same quark is repeated several time, after each gluon radiation |
| 161 | + std::cerr << "Number of generated (anti)quarks " << checkPdgQuarkTwo << " lower than expected\n"; |
| 162 | + return 1; |
| 163 | + } |
| 164 | + |
| 165 | + float fracForcedDecays = float(nSignalGoodDecay) / nSignals; |
| 166 | + if (fracForcedDecays < 0.9) { // we put some tolerance (e.g. due to oscillations which might change the final state) |
| 167 | + std::cerr << "Fraction of signals decaying into the correct channel " << fracForcedDecays << " lower than expected\n"; |
| 168 | + return 1; |
| 169 | + } |
| 170 | + |
| 171 | + return 0; |
| 172 | +} |
0 commit comments