|
| 1 | +int External() { |
| 2 | + std::string path{"o2sim_Kine.root"}; |
| 3 | + int checkPdgQuark{4}; |
| 4 | + float ratioTrigger = 1. / 3; // one event triggered out of 3 |
| 5 | + std::vector<int> checkPdgHadron{411, 421, 431, 443, 4122, 4132, 4232, 4332}; |
| 6 | + std::map<int, std::vector<std::vector<int>>> checkHadronDecays{ |
| 7 | + // sorted pdg of daughters |
| 8 | + {411, {{-321, 211, 211}, {-313, 211}, {211, 311}, {211, 333}}}, // D+ |
| 9 | + {421, {{-321, 211}, {-321, 111, 211}}}, // D0 |
| 10 | + {431, {{211, 333}}}, // Ds+ |
| 11 | + {443, {{-11, 11}}}, // Jpsi |
| 12 | + {4122, |
| 13 | + {{-313, 2212}, {-321, 2224}, {211, 3124}, {-321, 211, 2212}}}, // Lc+ |
| 14 | + {4132, {{211, 3312}}}, // Xic0 |
| 15 | + {4232, |
| 16 | + {{-313, 2212}, |
| 17 | + {-321, 3324}, |
| 18 | + {211, 211, 3312}, |
| 19 | + {-321, 211, 2212}}}, // Xic+ |
| 20 | + {4332, {{211, 3334}}} // Omegac+ |
| 21 | + }; |
| 22 | + |
| 23 | + TFile file(path.c_str(), "READ"); |
| 24 | + if (file.IsZombie()) { |
| 25 | + std::cerr << "Cannot open ROOT file " << path << "\n"; |
| 26 | + return 1; |
| 27 | + } |
| 28 | + |
| 29 | + auto tree = (TTree *)file.Get("o2sim"); |
| 30 | + std::vector<o2::MCTrack> *tracks{}; |
| 31 | + tree->SetBranchAddress("MCTrack", &tracks); |
| 32 | + |
| 33 | + int nQuarks{}, nSignals{}, nSignalGoodDecay{}; |
| 34 | + auto nEvents = tree->GetEntries(); |
| 35 | + |
| 36 | + // Setting up event header to access event weight info |
| 37 | + o2::dataformats::MCEventHeader *eventHeader = nullptr; |
| 38 | + ; |
| 39 | + tree->SetBranchAddress("MCEventHeader.", &eventHeader); |
| 40 | + int weight1Counter = 0; |
| 41 | + bool isvalid; |
| 42 | + |
| 43 | + for (int i = 0; i < nEvents; i++) { |
| 44 | + tree->GetEntry(i); |
| 45 | + |
| 46 | + float eventWeight = eventHeader->getInfo<float>("weight", isvalid); |
| 47 | + if (!isvalid) { |
| 48 | + std::cerr << "Could not retrieve event weight from MCEventHeader\n"; |
| 49 | + return 1; |
| 50 | + } |
| 51 | + if (abs(eventWeight - 1) < |
| 52 | + 1E-5) { // checks that the event weights are not unitary |
| 53 | + weight1Counter++; |
| 54 | + } |
| 55 | + |
| 56 | + for (auto &track : *tracks) { |
| 57 | + auto pdg = track.GetPdgCode(); |
| 58 | + if (std::abs(pdg) == checkPdgQuark) { |
| 59 | + nQuarks++; |
| 60 | + continue; |
| 61 | + } |
| 62 | + if (std::find(checkPdgHadron.begin(), checkPdgHadron.end(), |
| 63 | + std::abs(pdg)) != checkPdgHadron.end()) // found signal |
| 64 | + { |
| 65 | + // count signal PDG |
| 66 | + nSignals++; |
| 67 | + |
| 68 | + std::vector<int> pdgsDecay{}; |
| 69 | + std::vector<int> pdgsDecayAntiPart{}; |
| 70 | + for (int j{track.getFirstDaughterTrackId()}; |
| 71 | + j <= track.getLastDaughterTrackId(); ++j) { |
| 72 | + auto pdgDau = tracks->at(j).GetPdgCode(); |
| 73 | + pdgsDecay.push_back(pdgDau); |
| 74 | + if (pdgDau != 333) { // phi is antiparticle of itself |
| 75 | + pdgsDecayAntiPart.push_back(-pdgDau); |
| 76 | + } else { |
| 77 | + pdgsDecayAntiPart.push_back(pdgDau); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + std::sort(pdgsDecay.begin(), pdgsDecay.end()); |
| 82 | + std::sort(pdgsDecayAntiPart.begin(), pdgsDecayAntiPart.end()); |
| 83 | + |
| 84 | + for (auto &decay : checkHadronDecays[std::abs(pdg)]) { |
| 85 | + if (pdgsDecay == decay || pdgsDecayAntiPart == decay) { |
| 86 | + nSignalGoodDecay++; |
| 87 | + break; |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + std::cout << "--------------------------------\n"; |
| 94 | + std::cout << "# Events: " << nEvents << "\n"; |
| 95 | + std::cout << Form("# %d (anti)quarks: ", checkPdgQuark) << nQuarks << "\n"; |
| 96 | + std::cout << "# signal hadrons: " << nSignals << "\n"; |
| 97 | + std::cout << "# signal hadrons decaying in the correct channel: " |
| 98 | + << nSignalGoodDecay << "\n"; |
| 99 | + |
| 100 | + if (nQuarks < |
| 101 | + 2 * nEvents * |
| 102 | + ratioTrigger) // we expect anyway more because the same quark is |
| 103 | + // repeated several time, after each gluon radiation |
| 104 | + { |
| 105 | + std::cerr << "Number of generated (anti)quarks " << checkPdgQuark |
| 106 | + << " lower than expected\n"; |
| 107 | + return 1; |
| 108 | + } |
| 109 | + |
| 110 | + float fracForcedDecays = float(nSignalGoodDecay) / nSignals; |
| 111 | + if (fracForcedDecays < 0.9) // we put some tolerance (e.g. due to oscillations |
| 112 | + // which might change the final state) |
| 113 | + { |
| 114 | + std::cerr << "Fraction of signals decaying into the correct channel " |
| 115 | + << fracForcedDecays << " lower than expected\n"; |
| 116 | + return 1; |
| 117 | + } |
| 118 | + |
| 119 | + if (weight1Counter == nEvents) { |
| 120 | + std::cerr << "All events have a unitary weight\n"; |
| 121 | + return 1; |
| 122 | + } |
| 123 | + |
| 124 | + return 0; |
| 125 | +} |
0 commit comments