10 #include <top/modules/TOPPDFChecker/TOPPDFCheckerModule.h>
11 #include <top/geometry/TOPGeometryPar.h>
12 #include <top/reconstruction_cpp/TOPTrack.h>
13 #include <top/reconstruction_cpp/PDFConstructor.h>
14 #include <top/reconstruction_cpp/TOPRecoManager.h>
17 #include <tracking/dataobjects/ExtHit.h>
18 #include <top/dataobjects/TOPBarHit.h>
21 #include <framework/gearbox/Unit.h>
22 #include <framework/gearbox/Const.h>
23 #include <framework/logging/Logger.h>
53 setDescription(
"Module for checking analytic PDF used in likelihood calculation");
54 setPropertyFlags(c_ParallelProcessingCertified);
57 addParam(
"minTime", m_minTime,
58 "histogram lower bound in time [ns]", 0.0);
59 addParam(
"maxTime", m_maxTime,
60 "histogram upper bound in time [ns]", 50.0);
61 addParam(
"numBins", m_numBins,
62 "histogram number of bins in time", 1000);
66 void TOPPDFCheckerModule::defineHisto()
70 m_hits =
new TH2F(
"hits",
"photon hits", 512, 0.5, 512.5,
71 m_numBins, m_minTime, m_maxTime);
72 m_hits->SetXTitle(
"pixel ID");
73 m_hits->SetYTitle(
"time [ns]");
75 m_pdf =
new TH2F(
"pdf",
"PDF", 512, 0.5, 512.5,
76 m_numBins, m_minTime, m_maxTime);
77 m_pdf->SetXTitle(
"pixel ID");
78 m_pdf->SetYTitle(
"time [ns]");
81 m_hitsCol =
new TH2F(
"hitsCol",
"photon hits", 64, 0.5, 64.5,
82 m_numBins, m_minTime, m_maxTime);
83 m_hitsCol->SetXTitle(
"pixel column");
84 m_hitsCol->SetYTitle(
"time [ns]");
86 m_pdfCol =
new TH2F(
"pdfCol",
"PDF", 64, 0.5, 64.5,
87 m_numBins, m_minTime, m_maxTime);
88 m_pdfCol->SetXTitle(
"pixel column");
89 m_pdfCol->SetYTitle(
"time [ns]");
93 void TOPPDFCheckerModule::initialize()
100 m_digits.isRequired();
101 m_tracks.isRequired();
115 void TOPPDFCheckerModule::event()
117 TOPRecoManager::setTimeWindow(m_minTime, m_maxTime);
118 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
123 for (
const auto& track : m_tracks) {
125 if (not trk.
isValid())
continue;
129 auto chargedStable = Const::chargedStableSet.find(abs(trk.
getPDGCode()));
130 if (chargedStable == Const::invalidParticle)
continue;
132 PDFConstructor pdfConstructor(trk, chargedStable, PDFConstructor::c_Fine);
133 if (not pdfConstructor.
isValid())
continue;
137 const auto& module = geo->getModule(trk.
getModuleID());
145 for (
const auto& digit : m_digits) {
146 if (digit.getModuleID() == trk.
getModuleID() and digit.getTime() < m_maxTime) {
147 if (not isFromThisParticle(digit, trk.
getMCParticle()))
continue;
148 m_hits->Fill(digit.getPixelID(), digit.getTime());
149 m_hitsCol->Fill(digit.getPixelCol(), digit.getTime());
154 for (
const auto& signalPDF : pdfConstructor.
getSignalPDF()) {
155 int pixelID = signalPDF.getPixelID();
156 for (
const auto& peak : signalPDF.getPDFPeaks()) {
158 double sigma = sqrt(peak.wid);
159 for (
int i = 0; i < gRandom->Poisson(numPhot); i++) {
160 double time = gRandom->Gaus(peak.t0, sigma);
161 m_pdf->Fill(pixelID, time);
162 int pixelCol = (pixelID - 1) % 64 + 1;
163 m_pdfCol->Fill(pixelCol, time);
171 B2WARNING(
"No track hitting the bars");
172 }
else if (numTrk > 1) {
173 B2WARNING(
"More than one track hits the bars");
179 void TOPPDFCheckerModule::terminate()
181 m_avrgPosition *= 1.0 / m_numTracks;
182 m_avrgMomentum *= 1.0 / m_numTracks;
184 cout <<
"Average particle parameters at entrance to bar (in local frame):" << endl;
185 cout <<
" slot ID: ";
186 for (
auto slot : m_slotIDs) cout << slot <<
" ";
188 cout <<
" PDG code: ";
189 for (
auto pdg : m_PDGCodes) cout << pdg <<
" ";
191 cout <<
" position: x = " << m_avrgPosition.X()
192 <<
", y = " << m_avrgPosition.Y()
193 <<
", z = " << m_avrgPosition.Z() << endl;
194 cout <<
" momentum: p = " << m_avrgMomentum.Mag()
195 <<
", theta = " << m_avrgMomentum.Theta() / Unit::deg
196 <<
", phi = " << m_avrgMomentum.Phi() / Unit::deg << endl;
197 cout <<
"Number of particles: " << m_numTracks << endl;
198 cout <<
"Photons per particle: simulation = " << m_hits->GetSum() / m_numTracks
199 <<
", PDF = " << m_pdf->GetSum() / m_numTracks << endl;
204 bool TOPPDFCheckerModule::isFromThisParticle(
const TOPDigit& digit,
208 for (
unsigned i = 0; i < particles.size(); ++i) {
209 if (particles[i] == particle and particles.weight(i) > 0)
return true;
TVector3 getMomentum() const
Get momentum at this extrapolation hit.
TVector3 getPosition() const
Get position of this extrapolation hit.
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
A Class to store the Monte Carlo particle information.
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Class to store TOP digitized hits (output of TOPDigitizer or raw data unpacker) relations to TOPSimHi...
Module for checking analytic PDF used in likelihood calculation.
PDF construction and log likelihood determination for a given track and particle hypothesis.
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< SignalPDF > & getSignalPDF() const
Returns signal PDF.
Reconstructed track at TOP.
int getPDGCode() const
Returns PDG code of associated MCParticle (returns 0 if none)
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)
int getModuleID() const
Returns slot ID.
const MCParticle * getMCParticle() const
Returns 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.