10#include <top/modules/TOPReconstruction/TOPReconstructorModule.h>
13#include <top/reconstruction_cpp/TOPRecoManager.h>
14#include <top/geometry/TOPGeometryPar.h>
17#include <framework/logging/Logger.h>
43 setDescription(
"Reconstruction for TOP counter. Uses reconstructed tracks "
44 "extrapolated to TOP and TOPDigits to calculate log likelihoods "
45 "for charged stable particles");
52 "lower limit for photon time [ns] (if minTime >= maxTime use the default from DB)", 0.0);
54 "upper limit for photon time [ns] (if minTime >= maxTime use the default from DB)", 0.0);
56 "PDG code of hypothesis to construct pulls (0 means: use MC truth, -1: switched off)", -1);
58 "include (True) or exclude (False) delta-ray modeling in log likelihood calculation",
false);
60 "pT cut to suppress badly extrapolated tracks that cannot reach TOP counter", 0.27);
62 "Name of the collection of TOPDigits",
string(
""));
64 "Name of the produced collection of TOPLikelihoods",
string(
""));
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;
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
bool m_deltaRayModeling
include or exclude delta-ray modeling in log likelihood calculation
StoreObjPtr< TOPRecBunch > m_recBunch
reconstructed bunch
StoreArray< TOPLikelihood > m_likelihoods
collection of likelihoods
std::string m_topDigitCollectionName
name of the collection of TOPDigits
double m_maxTime
optional upper time limit for photons
double m_minTime
optional lower time limit for photons
StoreArray< Track > m_tracks
collection of tracks
StoreArray< TOPPull > m_topPulls
collection of pulls
double m_pTCut
pT cut to suppress badly extrapolated tracks that cannot reach TOP counter
std::string m_topLikelihoodCollectionName
name of the collection of created TOPLikelihoods
StoreArray< TOPDigit > m_digits
collection of digits
StoreArray< ExtHit > m_extHits
collection of extrapolated hits
StoreArray< TOPBarHit > m_barHits
collection of MCParticle hits at TOP
std::string m_topPullCollectionName
name of the collection of created TOPPulls
int m_PDGCode
PDG code of hypothesis to construct pulls.
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using basf2 units.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
static void setTimeWindow(double minTime, double maxTime)
Sets time window.
Reconstructed track at TOP.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
TOPReconstructorModule()
Constructor.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
Abstract base class for different kinds of events.
A collection of PDF's of charged stable particles for a given track.