103 if (not
m_recBunch->isReconstructed())
return;
112 std::unordered_multimap<int, const TOPTrack*> topTracks;
113 for (
const auto& track :
m_tracks) {
115 if (trk->isValid() and trk->getTransverseMomentum() >
m_pTCut) {
116 topTracks.emplace(trk->getModuleID(), trk);
125 for (
unsigned moduleID = 1; moduleID <= geo->getNumModules(); moduleID++) {
129 std::vector<PDFCollection> pdfCollections;
130 const auto& range = topTracks.equal_range(moduleID);
131 for (
auto it = range.first; it != range.second; ++it) {
132 const auto* trk = it->second;
134 if (collection.isValid) pdfCollections.push_back(collection);
136 if (pdfCollections.empty())
continue;
140 if (pdfCollections.size() > 1) {
141 std::vector<int> lastMostProbables;
142 for (
int iter = 0; iter < 10; iter++) {
143 std::vector<int> mostProbables;
144 for (
auto& collection : pdfCollections) {
145 collection.setMostProbable();
146 mostProbables.push_back(collection.mostProbable->getHypothesis().getPDGCode());
148 if (mostProbables == lastMostProbables)
break;
149 else lastMostProbables = mostProbables;
151 for (
auto& collection : pdfCollections) collection.clearPDFOther();
152 for (
auto& collection : pdfCollections) {
153 for (
auto& other : pdfCollections) {
154 if (&other == &collection)
continue;
155 collection.appendPDFOther(other.mostProbable);
163 for (
auto& collection : pdfCollections) {
165 const auto* trk = collection.topTrack;
166 const auto* track = trk->getTrack();
167 track->addRelationTo(topLL);
168 topLL->addRelationTo(trk->getExtHit());
169 topLL->addRelationTo(trk->getBarHit());
172 std::set<int> nfotSet;
173 std::set<double> nbkgSet;
175 for (
const auto* pdfConstructor : collection.PDFs) {
176 const auto& chargedStable = pdfConstructor->getHypothesis();
177 auto LL = pdfConstructor->getLogL();
178 auto expBkgPhotons = pdfConstructor->getExpectedBkgPhotons();
179 topLL->set(chargedStable, LL.numPhotons, LL.logL, LL.expPhotons, expBkgPhotons, LL.effectiveSignalYield);
181 nfotSet.insert(LL.numPhotons);
182 nbkgSet.insert(expBkgPhotons);
184 if (abs(chargedStable.getPDGCode()) == abs(pdgCode)) {
185 for (
const auto& p : pdfConstructor->getPulls()) {
186 auto* pull =
m_topPulls.appendNew(p.pixelID, p.time, p.peakT0 + p.ttsT0, p.sigma, p.phiCer, p.wt);
187 track->addRelationTo(pull);
192 topLL->setModuleID(trk->getModuleID());
193 const auto& emi = trk->getEmissionPoint();
194 topLL->setXZ(emi.position.X(), emi.position.Z());
196 if (nfotSet.size() > 1) B2ERROR(
"Bug in TOP::PDFConstructor: number of photons differs between particle hypotheses");
197 if (nbkgSet.size() > 1) B2ERROR(
"Bug in TOP::PDFConstructor: estimated background differs between particle hypotheses");
200 for (
auto& collection : pdfCollections) collection.deletePDFs();
204 for (
auto& x : topTracks)
delete x.second;