9#include <top/modules/TOPRingPlotter/TOPRingPlotterModule.h>
11#include <analysis/dataobjects/ParticleList.h>
12#include <analysis/dataobjects/Particle.h>
14#include <framework/datastore/StoreArray.h>
15#include <framework/datastore/StoreObjPtr.h>
17#include <framework/logging/Logger.h>
18#include <framework/utilities/MakeROOTCompatible.h>
22#include <TDirectory.h>
25#include <framework/datastore/DataStore.h>
26#include <framework/datastore/StoreArray.h>
27#include <framework/datastore/StoreObjPtr.h>
30#include <framework/gearbox/Unit.h>
31#include <framework/gearbox/Const.h>
32#include <framework/logging/Logger.h>
35#include <mdst/dataobjects/Track.h>
36#include <mdst/dataobjects/MCParticle.h>
37#include <top/dataobjects/TOPLikelihoodScanResult.h>
38#include <top/dataobjects/TOPLikelihood.h>
39#include <top/dataobjects/TOPBarHit.h>
40#include <tracking/dataobjects/ExtHit.h>
41#include <top/dataobjects/TOPDigit.h>
42#include <mdst/dataobjects/ECLCluster.h>
44#include <top/geometry/TOPGeometryPar.h>
45#include <top/reconstruction_cpp/TOPTrack.h>
46#include <top/reconstruction_cpp/PDFConstructor.h>
47#include <top/reconstruction_cpp/TOPRecoManager.h>
51using namespace Belle2::Variable;
60 R
"DOC(A module to plot the x-t images from TOP, and in general study the distribution of the digits associated to the particles in a particleList)DOC");
63 addParam(
"particleList",
m_particleList,
"List of particles to be used for plotting", std::string(
"pi+:all"));
65 addParam(
"pdgHyp",
m_pdgHyp,
"List of pdg codes for which the PDF is sampled and saved. Valid values are 11, 13, 211, 321, 2212.",
69 "Number of toys used to sample the PDFs. Set it to a large number for a precise sampling of the PDF in the histograms (suggested for small number of events) ",
72 "Set true to save the histograms of the maps in addition to the list of sampled pseudo-digits",
false);
74 "Set true to save the results of the LL scan. Requires to add TOPLLScannerModule to the path",
false);
98 for (
int i = 0; i < 10000; i++) {
142 float* timeArray,
int& arrayGuard,
int& toyCounter)
145 if (not track)
return;
153 if (not pdfConstructor.
isValid())
return;
159 for (
int pixelID = 1; pixelID <= 512; pixelID++) {
160 for (
int iBinY = 1; iBinY < 500 + 1; iBinY++) {
162 auto time =
m_pdfAsHisto->GetYaxis()->GetBinCenter(iBinY);
163 auto pdfVal = pdfConstructor.
getPDFValue(pixelID, time, 0.070);
165 short pixelCol = (pixelID - 1) % 64 + 1;
166 histo->Fill(pixelCol, time, pdfVal * 1.6);
173 histo->Scale(nExpPhot);
181 std::vector<float> tmpTime;
182 std::vector<short> tmpPixel;
184 short numPhot = gRandom->Poisson(nExpPhot);
186 for (
short rn = 0;
rn < numPhot;
rn++) {
190 tmpTime.push_back(time);
191 tmpPixel.push_back(
short(pxID));
197 for (
unsigned int iPh = 0; iPh < tmpTime.size(); iPh++) {
198 pixelArray[arrayGuard] = tmpPixel[iPh];
199 timeArray[arrayGuard] = tmpTime[iPh];
219 B2FATAL(
"Invalid PDG hypothesis for the PDF evaluation: " << pdg);
220 short duplicateCount = 0;
225 if (duplicateCount > 1)
226 B2FATAL(
"Duplicate PDG hypothesis found");
229 m_hitMapMCK =
new TH2F(
"hitMapMCK",
"x-t map of the kaon PDF", 64, 0, 64, 500, 0, 100);
230 m_hitMapMCPI =
new TH2F(
"hitMapMCPI",
"x-t map of the pion PDF", 64, 0, 64, 500, 0, 100);
231 m_hitMapMCP =
new TH2F(
"hitMapMCP",
"x-t map of the proton PDF", 64, 0, 64, 500, 0, 100);
232 m_hitMapMCE =
new TH2F(
"hitMapMCE",
"x-t map of the electron PDF", 64, 0, 64, 500, 0, 100);
233 m_hitMapMCMU =
new TH2F(
"hitMapMCMU",
"x-t map of the muon PDF", 64, 0, 64, 500, 0, 100);
235 m_pdfAsHisto =
new TH2F(
"pdfAsHisto",
"tms holder for the pdf to be sampled", 512, 0, 512, 500, 0, 100);
237 TDirectory::TContext context;
238 B2INFO(
"creating a tree for TOPRingPlotterModule");
240 m_tree =
new TTree(
"tree",
"tree");
308 size_t enumerate = 0;
315 B2ERROR(
"Variable '" << varStr <<
"' is not available in Variable::Manager!");
317 if (
m_particleList.empty() && var->description.find(
"[Eventbased]") == std::string::npos) {
318 B2ERROR(
"Variable '" << varStr <<
"' is not an event-based variable, "
319 "but you are using VariablesToNtuple without a decay string, i.e. in the event-wise mode.\n"
320 "If you have created an event-based alias you can wrap your alias with `eventCached` to "
321 "declare it as event based, which avoids this error.\n\n"
322 "vm.addAlias('myAliasName', 'eventCached(myAlias)')");
354 if (! particles.isValid())
358 int n_part = particles->getListSize();
359 for (
int i = 0; i < n_part; i++) {
365 const Particle* particle = particles->getParticle(i);
366 const Track* track = particle->getTrack();
368 bool isFromTrack =
true;
370 short deltaModule = 0;
377 const ECLCluster* clstr = particle->getECLCluster();
385 auto phi = particle->getECLCluster()->getPhi();
387 phi = 2 * M_PI - phi;
388 auto rawModuleID = phi / (M_PI / 8) + 1;
389 moduleID = int(rawModuleID);
390 if (rawModuleID - moduleID > 0.5) {
412 for (
const auto& digi : digits) {
415 if ((digi.getModuleID() == moduleID) || (!isFromTrack && digi.getModuleID() == moduleID + deltaModule)) {
435 for (
unsigned int iVar = 0; iVar <
m_variables.size(); iVar++) {
436 if (std::holds_alternative<double>(
m_functions[iVar](particle))) {
438 }
else if (std::holds_alternative<int>(
m_functions[iVar](particle))) {
440 }
else if (std::holds_alternative<bool>(
m_functions[iVar](particle))) {
452 auto lls = llScan->getCoarseScanLLValues();
454 for (
unsigned int j = 0; j < lls.size(); j++) {
482 TDirectory::TContext context;
Provides a type-safe way to pass members of the chargedStableSet set.
static const ChargedStable muon
muon particle
static const ChargedStable pion
charged pion particle
static const ChargedStable proton
proton particle
static const ChargedStable kaon
charged kaon particle
static const ChargedStable electron
electron particle
int getDetectorRegion() const
Return detector region: 0: below acceptance, 1: FWD, 2: BRL, 3: BWD, 11: FWDGAP, 13: BWDGAP.
static std::string makeROOTCompatible(std::string str)
Remove special characters that ROOT dislikes in branch names, e.g.
void setDescription(const std::string &description)
Sets the description of the module.
Class to store reconstructed particles.
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.
Type-safe access to single objects in the data store.
Class to store the result of the TOP LL scan (output of TOPLLScanner).
std::vector< float > getCoarseScanMassPoints() const
Return a std::vector containing the mass points used for the coarse LL scane.
short m_digitQuality[m_MaxPhotons]
Digit quality
TFile * m_outputFile
output file
float m_pdfTimePI[m_MaxPDFPhotons]
array with the times of the sampled pseudo-hits for the pion PDF
float m_pdfTimeE[m_MaxPDFPhotons]
array with the times of the sampled pseudo-hits for the electron PDF
short m_digitPixelCol[m_MaxPhotons]
Pixel column.
short m_pdfPixelK[m_MaxPDFPhotons]
array with the pixel location of the sampled pseudo-hits for the kaon PDF
TTree * m_tree
tree where data are saved.
std::vector< std::string > m_variables
List of variables to save.
short m_digitPixel[m_MaxPhotons]
Pixel number (1-512)
short m_digitSlot[m_MaxPhotons]
Slot number (1-16)
TH2F * m_hitMapMCPI
x-t plot of the pion PDF
short m_digitPixelRow[m_MaxPhotons]
Pixel row.
std::vector< short > m_pdgHyp
List of pdg codes for which the PDF is sampled and saved.
void initialize() override
Prepares the tree.
TOPRingPlotterModule()
Constructor: Sets the description, the properties and the parameters of the module.
float m_pdfTimeP[m_MaxPDFPhotons]
array with the times of the sampled pseudo-hits for the proton PDF
void event() override
Fills the tree.
float m_scanLL[10000]
LL values of the scan.
void fillPDF(Belle2::Const::ChargedStable, const Track *, TH2F *, short *, float *, int &, int &)
Fills the pdf-related branches.
bool m_saveHistograms
Set true to save the histograms of the maps.
float m_digitAmplitude[m_MaxPhotons]
Digit amplitude [ADC].
int m_pdfSamplesPI
total number of samples drawn from the pion PDF
void terminate() override
Writes the tree.
TH2F * m_hitMapMCK
x-t plot of the kaon PDF
int m_pdfToysP
total number of toys from the proton PDF
TH2F * m_hitMapMCMU
x-t plot of the muon PDF
std::vector< double > m_branchAddresses
Variable branch addresses.
int m_pdfSamplesK
total number of samples drawn from the kaon PDF
bool m_saveLLScan
Set to true to save the results of the LL scan.
static const int m_MaxPhotons
maximum number of digits allowed per PDF
int m_pdfSamplesMU
total number of samples drawn from the muon PDF
int m_pdfToysMU
total number of toys from the muon PDF
std::string m_outputName
Name of the output file.
short m_digitBoardstack[m_MaxPhotons]
BoardStack number
int m_pdfToysPI
total number of toys from the pion PDF
static const int m_MaxPDFPhotons
maximum number of digits allowed per PDF
std::vector< Variable::Manager::FunctionPtr > m_functions
List of function pointers corresponding to given variables.
int m_pdfSamplesE
total number of samples drawn from the electron PDF
std::string m_particleList
List of particles to be used for plotting.
short m_digitCarrier[m_MaxPhotons]
Carrier number
float m_scanMass[10000]
masses used in the LL scan
short m_pdfPixelE[m_MaxPDFPhotons]
array with the pixel location of the sampled pseudo-hits for the electron PDF
short m_digitAsic[m_MaxPhotons]
Asic number
float m_pdfTimeMU[m_MaxPDFPhotons]
array with the times of the sampled pseudo-hits for the muon PDF
void resetTree()
reset the tree variables.
short m_digitASICChannel[m_MaxPhotons]
ASIC channel number.
TH2F * m_hitMapMCE
x-t plot of the electron PDF
int m_pdfToysK
total number of toys from the kaon PDF
TH2F * m_pdfAsHisto
histogram to hot the PDF that will be sampled
float m_digitTime[m_MaxPhotons]
Digit calibrated time [ns].
short m_digitChannel[m_MaxPhotons]
SW channel (0-511)
short m_pdfPixelPI[m_MaxPDFPhotons]
array with the pixel location of the sampled pseudo-hits for the pion PDF
short m_pdfPixelP[m_MaxPDFPhotons]
array with the pixel location of the sampled pseudo-hits for the proton PDF
float m_digitWidth[m_MaxPhotons]
Digit calibrated width [ns].
short m_digitPMTNumber[m_MaxPhotons]
Digit PMT number.
int m_nScanPoints
number of points used in the LL scan
short m_nDigits
Total number of digits in the slot where the track is extrapolated.
int m_toyNumber
Number of toys used to populate the arrays of expected hits.
TH2F * m_hitMapMCP
x-t plot of the proton PDF
short m_pdfPixelMU[m_MaxPDFPhotons]
array with the pixel location of the sampled pseudo-hits for the muon PDF
float m_pdfTimeK[m_MaxPDFPhotons]
array with the times of the sampled pseudo-hits for the kaon PDF
int m_pdfToysE
total number of toys from the electron PDF
int m_pdfSamplesP
total number of samples drawn from the proton PDF
PDF construction and log likelihood determination for a given track and particle hypothesis.
double getPDFValue(int pixelID, double time, double timeErr, double sigt=0) const
Returns PDF value.
bool isValid() const
Checks the object status.
double getExpectedPhotons() const
Returns the expected number of all photons within the default time window.
@ c_Fine
y dependent everywhere
static void setTimeWindow(double minTime, double maxTime)
Sets time window.
Reconstructed track at TOP.
bool isValid() const
Checks if track is successfully constructed.
int getModuleID() const
Returns slot ID.
Class that bundles various TrackFitResults.
std::vector< std::string > resolveCollections(const std::vector< std::string > &variables)
Resolve Collection Returns variable names corresponding to the given collection or if it is not a col...
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
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.
TString rn()
Get random string.
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.