|
| 1 | +int External() |
| 2 | +{ |
| 3 | + std::string path{"o2sim_Kine.root"}; |
| 4 | + int numberOfInjectedSignalsPerEvent{1}; |
| 5 | + int numberOfGapEvents{4}; |
| 6 | + int numberOfEventsProcessed{0}; |
| 7 | + int numberOfEventsProcessedWithoutInjection{0}; |
| 8 | + std::vector<int> injectedPDGs = { |
| 9 | + 102134, // Lambda(1520)0 |
| 10 | + -102134, // Lambda(1520)0bar |
| 11 | + }; |
| 12 | + std::vector<std::vector<int>> decayDaughters = { |
| 13 | + {2212, -321}, // Lambda(1520)0 |
| 14 | + {-2212, 321}, // Lambda(1520)0bar |
| 15 | + }; |
| 16 | + |
| 17 | + auto nInjection = injectedPDGs.size(); |
| 18 | + |
| 19 | + TFile file(path.c_str(), "READ"); |
| 20 | + if (file.IsZombie()) |
| 21 | + { |
| 22 | + std::cerr << "Cannot open ROOT file " << path << "\n"; |
| 23 | + return 1; |
| 24 | + } |
| 25 | + |
| 26 | + auto tree = (TTree *)file.Get("o2sim"); |
| 27 | + if (!tree) |
| 28 | + { |
| 29 | + std::cerr << "Cannot find tree o2sim in file " << path << "\n"; |
| 30 | + return 1; |
| 31 | + } |
| 32 | + std::vector<o2::MCTrack> *tracks{}; |
| 33 | + tree->SetBranchAddress("MCTrack", &tracks); |
| 34 | + |
| 35 | + std::vector<int> nSignal; |
| 36 | + for (int i = 0; i < nInjection; i++) |
| 37 | + { |
| 38 | + nSignal.push_back(0); |
| 39 | + } |
| 40 | + std::vector<std::vector<int>> nDecays; |
| 41 | + std::vector<int> nNotDecayed; |
| 42 | + for (int i = 0; i < nInjection; i++) |
| 43 | + { |
| 44 | + std::vector<int> nDecay; |
| 45 | + for (int j = 0; j < decayDaughters[i].size(); j++) |
| 46 | + { |
| 47 | + nDecay.push_back(0); |
| 48 | + } |
| 49 | + nDecays.push_back(nDecay); |
| 50 | + nNotDecayed.push_back(0); |
| 51 | + } |
| 52 | + auto nEvents = tree->GetEntries(); |
| 53 | + bool hasInjection = false; |
| 54 | + for (int i = 0; i < nEvents; i++) |
| 55 | + { |
| 56 | + hasInjection = false; |
| 57 | + numberOfEventsProcessed++; |
| 58 | + auto check = tree->GetEntry(i); |
| 59 | + for (int idxMCTrack = 0; idxMCTrack < tracks->size(); ++idxMCTrack) |
| 60 | + { |
| 61 | + auto track = tracks->at(idxMCTrack); |
| 62 | + auto pdg = track.GetPdgCode(); |
| 63 | + auto it = std::find(injectedPDGs.begin(), injectedPDGs.end(), pdg); |
| 64 | + int index = std::distance(injectedPDGs.begin(), it); // index of injected PDG |
| 65 | + if (it != injectedPDGs.end()) // found |
| 66 | + { |
| 67 | + // count signal PDG |
| 68 | + nSignal[index]++; |
| 69 | + if (track.getFirstDaughterTrackId() < 0) |
| 70 | + { |
| 71 | + nNotDecayed[index]++; |
| 72 | + continue; |
| 73 | + } |
| 74 | + for (int j{track.getFirstDaughterTrackId()}; j <= track.getLastDaughterTrackId(); ++j) |
| 75 | + { |
| 76 | + auto pdgDau = tracks->at(j).GetPdgCode(); |
| 77 | + bool foundDau = false; |
| 78 | + // count decay PDGs |
| 79 | + for (int idxDaughter = 0; idxDaughter < decayDaughters[index].size(); ++idxDaughter) |
| 80 | + { |
| 81 | + if (pdgDau == decayDaughters[index][idxDaughter]) |
| 82 | + { |
| 83 | + nDecays[index][idxDaughter]++; |
| 84 | + foundDau = true; |
| 85 | + hasInjection = true; |
| 86 | + break; |
| 87 | + } |
| 88 | + } |
| 89 | + if (!foundDau) |
| 90 | + { |
| 91 | + std::cerr << "Decay daughter not found: " << pdg << " -> " << pdgDau << "\n"; |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + if (!hasInjection) |
| 97 | + { |
| 98 | + numberOfEventsProcessedWithoutInjection++; |
| 99 | + } |
| 100 | + } |
| 101 | + std::cout << "--------------------------------\n"; |
| 102 | + std::cout << "# Events: " << nEvents << "\n"; |
| 103 | + for (int i = 0; i < nInjection; i++) |
| 104 | + { |
| 105 | + std::cout << "# Mother \n"; |
| 106 | + std::cout << injectedPDGs[i] << " generated: " << nSignal[i] << ", " << nNotDecayed[i] << " did not decay\n"; |
| 107 | + if (nSignal[i] == 0) |
| 108 | + { |
| 109 | + std::cerr << "No generated: " << injectedPDGs[i] << "\n"; |
| 110 | + // return 1; // At least one of the injected particles should be generated |
| 111 | + } |
| 112 | + for (int j = 0; j < decayDaughters[i].size(); j++) |
| 113 | + { |
| 114 | + std::cout << "# Daughter " << decayDaughters[i][j] << ": " << nDecays[i][j] << "\n"; |
| 115 | + } |
| 116 | + // if (nSignal[i] != nEvents * numberOfInjectedSignalsPerEvent) |
| 117 | + // { |
| 118 | + // std::cerr << "Number of generated: " << injectedPDGs[i] << ", lower than expected\n"; |
| 119 | + // // return 1; // Don't need to return 1, since the number of generated particles is not the same for each event |
| 120 | + // } |
| 121 | + } |
| 122 | + std::cout << "--------------------------------\n"; |
| 123 | + std::cout << "Number of events processed: " << numberOfEventsProcessed << "\n"; |
| 124 | + std::cout << "Number of input for the gap events: " << numberOfGapEvents << "\n"; |
| 125 | + std::cout << "Number of events processed without injection: " << numberOfEventsProcessedWithoutInjection << "\n"; |
| 126 | + // injected event + numberOfGapEvents*gap events + injected event + numberOfGapEvents*gap events + ... |
| 127 | + // total fraction of the gap event: numberOfEventsProcessedWithoutInjection/numberOfEventsProcessed |
| 128 | + float ratioOfNormalEvents = numberOfEventsProcessedWithoutInjection / numberOfEventsProcessed; |
| 129 | + if (ratioOfNormalEvents > 0.75) |
| 130 | + { |
| 131 | + std::cout << "The number of injected event is loo low!!" << std::endl; |
| 132 | + return 1; |
| 133 | + } |
| 134 | + |
| 135 | + return 0; |
| 136 | +} |
| 137 | + |
| 138 | +void GeneratorLF_Resonances_pp1360_injection() { External(); } |
0 commit comments