9#include <top/modules/TOPLLScannerModule/TOPLLScannerModule.h>
11#include <top/reconstruction_cpp/TOPRecoManager.h>
12#include <top/reconstruction_cpp/TOPTrack.h>
13#include <top/reconstruction_cpp/PDFConstructor.h>
15#include <framework/datastore/StoreArray.h>
16#include <framework/datastore/StoreObjPtr.h>
27#include <framework/datastore/DataStore.h>
28#include <framework/datastore/StoreArray.h>
29#include <framework/datastore/StoreObjPtr.h>
32#include <framework/gearbox/Unit.h>
33#include <framework/gearbox/Const.h>
34#include <framework/logging/Logger.h>
43 setDescription(R
"DOC(A module to perform the TOP PID likelihood scan and find the actual minimum as function of the mass)DOC");
48 float& massMax,
float& minMassRange,
float& maxMassRange)
51 auto llMaxIndex = std::distance(logLs.begin(), std::max_element(logLs.begin(), logLs.end()));
52 maxLL = logLs[llMaxIndex];
53 massMax = masses[llMaxIndex];
57 minMassRange = massMax - 0.03;
58 if (minMassRange < masses[0])
59 minMassRange = masses[0];
61 maxMassRange = massMax + 0.03;
62 if (maxMassRange < masses[0])
63 maxMassRange = masses.back();
67 int llIndex = llMaxIndex;
68 while (llValue > maxLL - deltaLL && llIndex <
int(masses.size())) {
69 llValue = logLs[llIndex];
70 maxMassRange = masses[llIndex];
76 while (llValue > maxLL - deltaLL && llIndex >= 0) {
77 llValue = logLs[llIndex];
78 minMassRange = masses[llIndex];
101 float lastVal = 0.0002;
102 for (
auto i = 1; i < 240; i++) {
109 lastVal = lastVal + step;
116 for (
const auto& track :
m_tracks) {
118 track.addRelationTo(topLLScanRes);
124 topLLScanRes->addRelationTo(trk.
getExtHit());
125 topLLScanRes->addRelationTo(trk.
getBarHit());
130 std::vector<float> logLcoarseScan;
131 std::vector<float> nSignalPhotonsCoarseScan;
136 auto LL = pdfConstructor.
getLogL();
137 logLcoarseScan.push_back(LL.logL);
142 float minMassRange = 0;
143 float maxMassRange = 0;
151 std::vector<float> logLfineScan;
152 std::vector<float> massPointsFineScan;
153 std::vector<float> nSignalPhotonsFineScan;
154 auto mass = minMassRange;
158 while (mass < maxMassRange) {
161 auto LL = pdfConstructor.
getLogL();
162 logLfineScan.push_back(LL.logL);
164 massPointsFineScan.push_back(mass);
169 scanLikelihood(massPointsFineScan, logLfineScan, 0.5, maxLL, massMax, minMassRange, maxMassRange);
174 auto lastLL = logLcoarseScan.back();
175 auto currentLL = logLcoarseScan.back();
177 while (TMath::Abs(lastLL - currentLL) < 0.01 && index > 0) {
179 currentLL = logLcoarseScan[index];
191 topLLScanRes->set(massMax,
199 logLcoarseScan, logLfineScan,
200 nSignalPhotonsCoarseScan, nSignalPhotonsFineScan);
static const ChargedStable pion
charged pion particle
void setDescription(const std::string &description)
Sets the description of the module.
static void scanLikelihood(const std::vector< float > &masses, const std::vector< float > &logLs, float deltaLL, float &maxLL, float &massMax, float &minMassRange, float &maxMassRange)
Finds best fit value and confidence interval form a LL via direct scan.
StoreObjPtr< TOPRecBunch > m_recBunch
reconstructed bunch
void initialize() override
Setup the storearrays.
TOPLLScannerModule()
Constructor: Sets the description, the properties and the parameters of the module.
void event() override
Performs the scan.
short m_nFineScanPoints
number of points for the fine-graned scan
StoreArray< Track > m_tracks
collection of tracks
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::vector< float > m_massPoints
vector with the mass points used in the coarse scan
StoreArray< TOPLikelihoodScanResult > m_likelihoodScanResults
collection of likelihoods
PDF construction and log likelihood determination for a given track and particle hypothesis.
void switchOffDeltaRayPDF() const
Exclude delta-ray PDF in log likelihood calculation.
LogL getLogL() const
Returns extended log likelihood (using the default time window)
double getExpectedDeltaPhotons() const
Returns the expected number of delta-ray photons within the default time window.
double getExpectedSignalPhotons() const
Returns the expected number of signal photons within the default time window.
@ c_Reduced
only PDF peak data
@ c_Optimal
y dependent only where necessary
double getExpectedBkgPhotons() const
Returns the expected number of background photons within the default time window.
Reconstructed track at TOP.
bool isValid() const
Checks if track is successfully constructed.
const ExtHit * getExtHit() const
Returns extrapolated hit (track entrance to the bar)
const TOPBarHit * getBarHit() const
Returns bar hit of MC particle assigned to this track (if any)
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.