104 if (not
m_recBunch->isReconstructed())
return;
117 std::unordered_multimap<int, const TOPTrack*> topTracks;
118 for (
const auto& track :
m_tracks) {
120 if (trk->isValid() and trk->getTransverseMomentum() >
m_pTCut) {
122 topTracks.emplace(trk->getModuleID(), trk);
131 for (
unsigned moduleID = 1; moduleID <= geo->getNumModules(); moduleID++) {
135 std::vector<PDFCollection> pdfCollections;
136 const auto& range = topTracks.equal_range(moduleID);
137 for (
auto it = range.first; it != range.second; ++it) {
138 const auto* trk = it->second;
140 if (collection.isValid) pdfCollections.push_back(collection);
142 if (pdfCollections.empty())
continue;
146 if (pdfCollections.size() > 1) {
147 std::vector<int> lastMostProbables;
148 for (
int iter = 0; iter < 10; iter++) {
149 std::vector<int> mostProbables;
150 for (
auto& collection : pdfCollections) {
151 collection.setMostProbable();
152 mostProbables.push_back(collection.mostProbable->getHypothesis().getPDGCode());
154 if (mostProbables == lastMostProbables)
break;
155 else lastMostProbables = mostProbables;
157 for (
auto& collection : pdfCollections) collection.clearPDFOther();
158 for (
auto& collection : pdfCollections) {
159 for (
const auto& other : pdfCollections) {
160 if (&other == &collection)
continue;
161 collection.appendPDFOther(other.mostProbable);
169 for (
const auto& collection : pdfCollections) {
171 const auto* trk = collection.topTrack;
172 const auto* track = trk->getTrack();
173 track->addRelationTo(topLL);
174 topLL->addRelationTo(trk->getExtHit());
175 topLL->addRelationTo(trk->getBarHit());
178 std::set<int> nfotSet;
179 std::set<double> nbkgSet;
181 for (
const auto* pdfConstructor : collection.PDFs) {
182 const auto& chargedStable = pdfConstructor->getHypothesis();
183 auto LL = pdfConstructor->getLogL();
184 auto expBkgPhotons = pdfConstructor->getExpectedBkgPhotons();
185 topLL->set(chargedStable, LL.numPhotons, LL.logL, LL.expPhotons, expBkgPhotons, LL.effectiveSignalYield);
187 nfotSet.insert(LL.numPhotons);
188 nbkgSet.insert(expBkgPhotons);
190 if (abs(chargedStable.getPDGCode()) == abs(pdgCode)) {
191 for (
const auto& p : pdfConstructor->getPulls()) {
192 const auto* pull =
m_topPulls.appendNew(p.pixelID, p.time, p.peakT0 + p.ttsT0, p.sigma, p.phiCer, p.wt);
193 track->addRelationTo(pull);
198 topLL->setModuleID(trk->getModuleID());
199 const auto& emi = trk->getEmissionPoint();
200 topLL->setXZ(emi.position.X(), emi.position.Z());
202 if (nfotSet.size() > 1) B2ERROR(
"Bug in TOP::PDFConstructor: number of photons differs between particle hypotheses");
203 if (nbkgSet.size() > 1) B2ERROR(
"Bug in TOP::PDFConstructor: estimated background differs between particle hypotheses");
206 for (
auto& collection : pdfCollections) collection.deletePDFs();
210 for (
const auto& x : topTracks)
delete x.second;