5 #include "Pythia8/PythiaStdlib.h" 10 #include "YODA/Histo.h" 11 #include "YODA/Profile.h" 12 #include "YODA/WriterYODA.h" 13 #include "YODA/ReaderYODA.h" 28 using Histo1DPtr = shared_ptr<YODA::Histo1D>;
29 using Histo2DPtr = shared_ptr<YODA::Histo2D>;
30 using Histo3DPtr = shared_ptr<YODA::Histo3D>;
31 using Profile1DPtr = shared_ptr<YODA::Profile1D>;
32 using Profile2DPtr = shared_ptr<YODA::Profile2D>;
40 Pythia8Yoda(
const string& anaNameIn =
"/PYTHIA8/",
const string& outputIn =
41 "pythia") : anaName(
"/"+anaNameIn+
"/"), outName(outputIn),
47 if (!finalized)
write();
52 string purge =
".yoda";
53 size_t pos = outName.find(purge);
54 if (pos != std::string::npos)
55 outName.replace(pos, purge.length(),
"");
56 std::cout <<
"Writing histograms to: " << outName <<
".yoda" << std::endl;
57 YODA::WriterYODA::write(outName+
".yoda", anaObjects.begin(),
65 static T
read(
const string& fName,
const string& objPath) {
67 vector<YODA::AnalysisObject* > anaObjs;
68 YODA::ReaderYODA::read(fName, anaObjs);
72 for (
auto ao : anaObjs)
73 if (ao->path() == objPath)
74 if (T* castObj = dynamic_cast<T*>(ao)) {
80 if (!(result.path() == objPath))
81 cout <<
"Warning: " << objPath <<
" not found/incorrect type," << endl;
84 for (
auto* obj : anaObjs)
delete obj;
90 template<
typename T,
typename... Args>
91 shared_ptr<T>
book(Args&&... args) {
92 auto h = make_shared<T>(std::forward<Args>(args)...);
93 anaObjects.push_back(h);
100 const string& title) {
101 return book<YODA::Histo1D>(nBins, xMin, xMax, anaName + title, title);
105 Histo2DPtr
bookHisto2D(
int nBinsX,
double xMin,
double xMax,
int nBinsY,
106 double yMin,
double yMax,
const std::string& title) {
107 return book<YODA::Histo2D>(nBinsX, xMin, xMax, nBinsY, yMin, yMax,
108 anaName + title, title);
112 Histo3DPtr
bookHisto3D(
int nBinsX,
double xMin,
double xMax,
int nBinsY,
113 double yMin,
double yMax,
int nBinsZ,
double zMin,
double zMax,
114 const std::string& title) {
115 return book<YODA::Histo3D>(nBinsX, xMin, xMax, nBinsY, yMin, yMax,
116 nBinsZ, zMin, zMax, anaName + title, title);
121 const std::string& title) {
122 return book<YODA::Profile1D>(nBins, xMin, xMax, anaName + title, title);
126 Profile2DPtr
bookProfile2D(
int nBinsX,
double xMin,
double xMax,
int nBinsY,
127 double yMin,
double yMax,
const std::string& title) {
128 return book<YODA::Profile2D>(nBinsX, xMin, xMax, nBinsY, yMin, yMax,
129 anaName + title, title);
136 std::vector<AnaObjectPtr> anaObjects;
void write()
Write histograms.
Definition: Pythia8Yoda.h:51
Profile2DPtr bookProfile2D(int nBinsX, double xMin, double xMax, int nBinsY, double yMin, double yMax, const std::string &title)
Book a 2D profile.
Definition: Pythia8Yoda.h:126
Histo3DPtr bookHisto3D(int nBinsX, double xMin, double xMax, int nBinsY, double yMin, double yMax, int nBinsZ, double zMin, double zMax, const std::string &title)
Book a 3D histogram.
Definition: Pythia8Yoda.h:112
~Pythia8Yoda()
Definition: Pythia8Yoda.h:46
Histo2DPtr bookHisto2D(int nBinsX, double xMin, double xMax, int nBinsY, double yMin, double yMax, const std::string &title)
Book a 2D histogram.
Definition: Pythia8Yoda.h:105
static T read(const string &fName, const string &objPath)
Definition: Pythia8Yoda.h:65
shared_ptr< T > book(Args &&...args)
Book any YODA object and return a shared ptr.
Definition: Pythia8Yoda.h:91
Histo1DPtr bookHisto1D(int nBins, double xMin, double xMax, const string &title)
Definition: Pythia8Yoda.h:99
Definition: Pythia8Yoda.h:34
Profile1DPtr bookProfile1D(int nBins, double xMin, double xMax, const std::string &title)
Book a 1D profile.
Definition: Pythia8Yoda.h:120
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
Pythia8Yoda(const string &anaNameIn="/PYTHIA8/", const string &outputIn="pythia")
Definition: Pythia8Yoda.h:40
shared_ptr< YODA::AnalysisObject > AnaObjectPtr
Typedef of shared pointers to analysis objects.
Definition: Pythia8Yoda.h:27