10 #include <top/modules/TOPPDFDebugger/TOPPDFDebuggerModule.h>
11 #include <top/geometry/TOPGeometryPar.h>
12 #include <top/reconstruction_cpp/TOPRecoManager.h>
13 #include <top/reconstruction_cpp/TOPTrack.h>
14 #include <top/reconstruction_cpp/PDFConstructor.h>
17 #include <tracking/dataobjects/ExtHit.h>
18 #include <mdst/dataobjects/MCParticle.h>
19 #include <top/dataobjects/TOPBarHit.h>
22 #include <framework/logging/Logger.h>
49 setDescription(
"This module makes an analytic PDF available in "
50 "a store array TOPPDFCollections, related from Tracks");
53 setPropertyFlags(c_ParallelProcessingCertified);
56 addParam(
"minTime", m_minTime,
57 "lower limit for photon time [ns] (default from DB used, if minTime >= maxTime)", 0.0);
58 addParam(
"maxTime", m_maxTime,
59 "upper limit for photon time [ns] (default from DB used, if minTime >= maxTime)", 0.0);
60 addParam(
"pdfOption", m_pdfOption,
61 "PDF option, one of 'rough', 'fine', 'optimal'", std::string(
"fine"));
62 addParam(
"pdgCodes", m_pdgCodes,
63 "PDG codes of charged stable particles for which to construct PDF. "
64 "Empty list means all charged stable particles.",
69 void TOPPDFDebuggerModule::initialize()
72 m_digits.isRequired();
73 m_tracks.isRequired();
85 m_pdfCollection.registerInDataStore();
86 m_tracks.registerRelationTo(m_pdfCollection);
87 m_associatedPDFs.registerInDataStore();
88 m_digits.registerRelationTo(m_associatedPDFs);
89 m_pixelData.registerInDataStore();
90 m_tracks.registerRelationTo(m_pixelData);
93 if (m_pdgCodes.empty()) {
94 for (
const auto& part : Const::chargedStableSet) {
95 m_chargedStables.push_back(part);
98 for (
auto pdg : m_pdgCodes) {
100 m_chargedStables.push_back(part);
105 if (m_pdfOption ==
"rough") {
106 m_PDFOption = PDFConstructor::c_Rough;
107 }
else if (m_pdfOption ==
"fine") {
108 m_PDFOption = PDFConstructor::c_Fine;
109 }
else if (m_pdfOption ==
"optimal") {
110 m_PDFOption = PDFConstructor::c_Optimal;
112 B2ERROR(
"TOPPDFDebuggerModule: unknown PDF option '" << m_pdfOption <<
"'");
118 void TOPPDFDebuggerModule::event()
120 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
121 TOPRecoManager::setTimeWindow(m_minTime, m_maxTime);
125 for (
const auto& track : m_tracks) {
127 if (not trk.
isValid())
continue;
131 const auto& module = geo->getModule(trk.
getModuleID());
139 for (
const auto& chargedStable : m_chargedStables) {
140 const PDFConstructor pdfConstructor(trk, chargedStable, m_PDFOption, PDFConstructor::c_Full);
141 if (not pdfConstructor.
isValid()) {
142 B2ERROR(
"PDFConstructor found not valid - bug in reconstruction code?"
143 <<
LogVar(
"PDG", chargedStable.getPDGCode()));
148 associatePDFPeaks(pdfConstructor);
154 for (
const auto& signalPDF : pdfConstructor.
getSignalPDF()) {
155 int pixelID = signalPDF.getPixelID();
156 for (
const auto& peak : signalPDF.getPDFPeaks()) {
157 float position = peak.t0;
158 float width = sqrt(peak.wid);
161 channelPDFCollection.at(pixelID - 1).push_back(tp);
165 topPDFColl->
addHypothesisPDF(channelPDFCollection, chargedStable.getPDGCode());
173 for (
size_t i = 0; i < std::min(pixelLogLs.size(), pixLogLs.size()); i++) {
174 pixLogLs[i] = pixelLogLs[i].logL;
175 pixSigPhots[i] = pixelLogLs[i].expPhotons;
181 track.addRelationTo(topPDFColl);
182 track.addRelationTo(topPLkhs);
189 void TOPPDFDebuggerModule::associatePDFPeaks(
const PDFConstructor& pdfConstructor)
198 for (
const auto& digit : m_digits) {
199 if (digit.getModuleID() != pdfConstructor.
getModuleID())
continue;
200 if (digit.getHitQuality() != TOPDigit::c_Good)
continue;
201 int pixelID = digit.getPixelID();
202 unsigned index = pixelID - 1;
203 if (index >= signalPDFs.size())
continue;
204 const auto& signalPDF = signalPDFs[index];
205 const auto* tts = signalPDF.getTTS();
206 const auto& pdfPeaks = signalPDF.getPDFPeaks();
207 const auto& extraInfos = signalPDF.getPDFExtraInfo();
208 if (extraInfos.size() != pdfPeaks.size()) {
209 B2ERROR(
"associatePDFPeaks: sizes of PDFPeaks and ExtraInfo's differ");
213 auto* associatedPDF = m_associatedPDFs.appendNew(PDGCode);
214 digit.addRelationTo(associatedPDF);
217 associatedPDF->setBackgroundWeight(bkgLevel);
219 associatedPDF->setDeltaRayWeight(deltaLevel);
221 float time = digit.getTime();
222 float timeErr = digit.getTimeError();
224 for (
size_t k = 0; k < pdfPeaks.size(); k++) {
225 const auto& pdfPeak = pdfPeaks[k];
226 const auto& pdfExtra = extraInfos[k];
229 peak.
width = sqrt(pdfPeak.wid);
230 peak.
numPhotons = pdfPeak.nph * signalPhotons;
232 for (
const auto& gaus : tts->getTTS()) {
233 float sig2 = peak.
width * peak.
width + gaus.sigma * gaus.sigma + timeErr * timeErr;
234 float x = pow(time - peak.
position - gaus.position, 2) / sig2;
235 if (x > 20)
continue;
236 wt += peak.
numPhotons * gaus.fraction / sqrt(2 * M_PI * sig2) * exp(-x / 2);
239 peak.
fic = pdfPeak.fic;
241 peak.
sige = pdfExtra.sige;
242 peak.
nx = abs(pdfExtra.Nxm) + abs(pdfExtra.Nxb) + abs(pdfExtra.Nxe);
243 peak.
ny = abs(pdfExtra.Nym) + abs(pdfExtra.Nyb) + abs(pdfExtra.Nye);
244 peak.
nxm = abs(pdfExtra.Nxm);
245 peak.
nym = abs(pdfExtra.Nym);
246 peak.
nxe = abs(pdfExtra.Nxe);
247 peak.
nye = abs(pdfExtra.Nye);
248 peak.
xd = pdfExtra.xD;
249 peak.
yd = pdfExtra.yD;
250 peak.
type = pdfExtra.type;
251 peak.
kxe = pdfExtra.kxE;
252 peak.
kye = pdfExtra.kyE;
253 peak.
kze = pdfExtra.kzE;
254 peak.
kxd = pdfExtra.kxD;
255 peak.
kyd = pdfExtra.kyD;
256 peak.
kzd = pdfExtra.kzD;
257 associatedPDF->appendPeak(peak, wt);
Provides a type-safe way to pass members of the chargedStableSet set.
int getPDGCode() const
PDG code.
TVector3 getMomentum() const
Get momentum at this extrapolation hit.
TVector3 getPosition() const
Get position of this extrapolation hit.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Accessor to arrays stored in the data store.
Class to store analytical PDF relation from Tracks filled top/modules/TOPPDFDebugger/src/TOPPDFDebugg...
std::array< channelPDF_t, 512 > modulePDF_t
the PDF of the module is a list of 512 channel PDFs
void setLocalPositionMomentum(const TVector3 &pos, const TVector3 &mom, int moduleID)
sets the position and momentum of the exthit in local coordinates
bool addHypothesisPDF(const modulePDF_t &pdf, const int hypothesis)
adds the pdf for the given hypothesis (PDG code)
TOP reconstruction module.
Class to store pixel-by-pixel likelihoods for a track relation from Tracks filled in top/modules/TOPP...
std::array< float, 512 > PixelArray_t
Array of length 512 to hold per-pixel information.
void setModuleID(int moduleID)
Sets module ID of the associated exthit.
bool addHypothesisSignalPhotons(const PixelArray_t &sfots, const int hypothesis)
Adds the signal photon array for the given hypothesis (PDG code)
bool addHypothesisLikelihoods(const PixelArray_t &plkhs, const int hypothesis)
Adds the likelihood array for the given hypothesis (PDG code)
double getPDFValue(int pixelID) const
Returns PDF value for given pixel.
double getPDFValue(int pixelID, double time) const
Returns PDF value at given time and pixel.
PDF construction and log likelihood determination for a given track and particle hypothesis.
const Const::ChargedStable & getHypothesis() const
Returns particle hypothesis.
double getExpectedDeltaPhotons() const
Returns the expected number of delta-ray photons within the default time window.
bool isValid() const
Checks the object status.
double getExpectedSignalPhotons() const
Returns the expected number of signal photons within the default time window.
const std::vector< LogL > & getPixelLogLs(double t0, double sigt=0) const
Returns extended log likelihoods in pixels for PDF shifted in time.
int getModuleID() const
Returns slot ID.
const std::vector< SignalPDF > & getSignalPDF() const
Returns signal PDF.
const BackgroundPDF * getBackgroundPDF() const
Returns background PDF.
double getExpectedBkgPhotons() const
Returns the expected number of background photons within the default time window.
const DeltaRayPDF & getDeltaRayPDF() const
Returns delta-ray PDF.
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)
int getModuleID() const
Returns slot ID.
Class to store variables with their name which were sent to the logging service.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
int nx
total number of reflections in x
float kxd
reconstructed photon direction in x at detection
float fic
Cerenkov azimuthal angle phi.
float kze
reconstructed photon direction in z at emission
float e
mean photon energy [eV]
float xd
unfolded x coordinate of a pixel
int nym
number of reflections in y before mirror
int nxe
number of reflections in x in prism
int nye
number of reflections in y in prism
int nxm
number of reflections in x before mirror
float position
position in time
float kzd
reconstructed photon direction in z at detection
float sige
photon energy sigma squared [eV^2]
int ny
total number of reflections in y
float numPhotons
number of photons
float kyd
reconstructed photon direction in y at detection
int type
0 unknown, 1 direct photon, 2 reflected photon
float yd
unfolded y coordinate of a pixel
float kxe
reconstructed photon direction in x at emission
float kye
reconstructed photon direction in y at emission
parameters to describe a Gaussian