12 #include <top/modules/TOPPDFChecker/TOPPDFCheckerModule.h>
13 #include <top/geometry/TOPGeometryPar.h>
14 #include <top/reconstruction/TOPreco.h>
15 #include <top/reconstruction/TOPtrack.h>
16 #include <top/reconstruction/TOPconfigure.h>
19 #include <framework/datastore/StoreArray.h>
22 #include <mdst/dataobjects/Track.h>
23 #include <tracking/dataobjects/ExtHit.h>
24 #include <top/dataobjects/TOPDigit.h>
25 #include <mdst/dataobjects/MCParticle.h>
26 #include <top/dataobjects/TOPBarHit.h>
29 #include <framework/gearbox/Unit.h>
30 #include <framework/gearbox/Const.h>
31 #include <framework/logging/Logger.h>
61 setDescription(
"Module for checking analytic PDF used in likelihood calculation");
62 setPropertyFlags(c_ParallelProcessingCertified);
65 addParam(
"minTime", m_minTime,
66 "histogram lower bound in time [ns]", 0.0);
67 addParam(
"maxTime", m_maxTime,
68 "histogram upper bound in time [ns]", 50.0);
69 addParam(
"numBins", m_numBins,
70 "histogram number of bins in time", 1000);
74 TOPPDFCheckerModule::~TOPPDFCheckerModule()
78 void TOPPDFCheckerModule::defineHisto()
82 m_hits =
new TH2F(
"hits",
"photon hits", 512, 0.5, 512.5,
83 m_numBins, m_minTime, m_maxTime);
84 m_hits->SetXTitle(
"pixel ID");
85 m_hits->SetYTitle(
"time [ns]");
87 m_pdf =
new TH2F(
"pdf",
"PDF", 512, 0.5, 512.5,
88 m_numBins, m_minTime, m_maxTime);
89 m_pdf->SetXTitle(
"pixel ID");
90 m_pdf->SetYTitle(
"time [ns]");
93 m_hitsCol =
new TH2F(
"hitsCol",
"photon hits", 64, 0.5, 64.5,
94 m_numBins, m_minTime, m_maxTime);
95 m_hitsCol->SetXTitle(
"pixel column");
96 m_hitsCol->SetYTitle(
"time [ns]");
98 m_pdfCol =
new TH2F(
"pdfCol",
"PDF", 64, 0.5, 64.5,
99 m_numBins, m_minTime, m_maxTime);
100 m_pdfCol->SetXTitle(
"pixel column");
101 m_pdfCol->SetYTitle(
"time [ns]");
105 void TOPPDFCheckerModule::initialize()
113 topDigits.isRequired();
119 extHits.isRequired();
122 mcParticles.isRequired();
125 barHits.isRequired();
133 void TOPPDFCheckerModule::beginRun()
137 void TOPPDFCheckerModule::event()
140 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
145 double mass = Const::pion.getMass();
146 int pdg = Const::pion.getPDGCode();
147 TOPreco reco(Nhyp, &mass, &pdg);
155 for (
const auto& track : tracks) {
164 if (reco.
getFlag() != 1)
continue;
168 const auto& module = geo->getModule(trk.
getModuleID());
169 m_avrgMomentum += module.momentumToLocal(trk.
getMomentum());
170 m_avrgPosition += module.pointToLocal(trk.
getPosition());
177 for (
const auto& digit : digits) {
178 if (digit.getModuleID() == trk.
getModuleID() and digit.getTime() < m_maxTime) {
179 if (!isFromThisParticle(digit, trk.
getMCParticle()))
continue;
180 m_hits->Fill(digit.getPixelID(), digit.getTime());
181 m_hitsCol->Fill(digit.getPixelCol(), digit.getTime());
186 for (
int pixelID = 1; pixelID <= 512; pixelID++) {
191 reco.
getPDFPeak(pixelID, peak, t0, sigma, numPhot);
192 for (
int i = 0; i < gRandom->Poisson(numPhot); i++) {
193 double time = gRandom->Gaus(t0, sigma);
194 m_pdf->Fill(pixelID, time);
195 int pixelCol = (pixelID - 1) % 64 + 1;
196 m_pdfCol->Fill(pixelCol, time);
204 B2WARNING(
"No track hitting the bars");
205 }
else if (numTrk > 1) {
206 B2WARNING(
"More than one track hits the bars");
212 void TOPPDFCheckerModule::endRun()
216 void TOPPDFCheckerModule::terminate()
219 m_avrgPosition *= 1.0 / m_numTracks;
220 m_avrgMomentum *= 1.0 / m_numTracks;
222 cout <<
"Average particle parameters at entrance to bar (in local frame):" << endl;
223 cout <<
" slot ID: ";
224 for (
auto slot : m_slotIDs) cout << slot <<
" ";
226 cout <<
" PDG code: ";
227 for (
auto pdg : m_PDGCodes) cout << pdg <<
" ";
229 cout <<
" position: x = " << m_avrgPosition.X()
230 <<
", y = " << m_avrgPosition.Y()
231 <<
", z = " << m_avrgPosition.Z() << endl;
232 cout <<
" momentum: p = " << m_avrgMomentum.Mag()
233 <<
", theta = " << m_avrgMomentum.Theta() / Unit::deg
234 <<
", phi = " << m_avrgMomentum.Phi() / Unit::deg << endl;
235 cout <<
"Number of particles: " << m_numTracks << endl;
236 cout <<
"Photons per particle: simulation = " << m_hits->GetSum() / m_numTracks
237 <<
", PDF = " << m_pdf->GetSum() / m_numTracks << endl;
242 bool TOPPDFCheckerModule::isFromThisParticle(
const TOPDigit& digit,
246 for (
unsigned i = 0; i < particles.size(); ++i) {
247 if (particles[i] == particle and particles.weight(i) > 0)
return true;