16 #include "boost/program_options.hpp"
24 #include <TApplication.h>
32 #include <FairMQLogger.h>
42 template<
typename T,
typename ManagerType>
43 void SaveDataToFile(ManagerType& outMan, RooDataSet* dataset,
bool printval =
false);
45 template<
typename T,
typename ManagerType>
46 void SavePodDataToFile(ManagerType& outMan, RooDataSet* dataset,
bool printval =
false);
52 int main(
int argc,
char** argv)
66 namespace po = boost::program_options;
68 po::options_description desc(
"Data generator options");
71 (
"output-file", po::value<string>(&filename)->required(),
"Path to the output root file of generated data")
72 (
"tree", po::value<string>(&treename)->default_value(
"T7SamplerTree"),
"Name of the tree")
73 (
"branch", po::value<string>(&branchname)->default_value(
"MyDigi"),
"Name of the Branch")
74 (
"class-name", po::value<string>(&classname)->default_value(
"MyDigi"),
"Name of the Payload class")
75 (
"rootfile-option", po::value<string>(&fileoption)->default_value(
"RECREATE"),
"Root file option.")
76 (
"use-TCA", po::value<bool>(&useTClonesArray)->default_value(
true),
"Store data bunches in TClonesArray")
77 (
"plot-data", po::value<bool>(&plotdata)->default_value(
false),
"Plot generated data")
78 (
"tmax", po::value<unsigned int>(&tmax)->default_value(100),
"max time index=bunch number")
79 (
"Nmean", po::value<double>(&nMean)->default_value(1595),
"mean number of generated data / bunch")
80 (
"Nsigma", po::value<double>(&nSigma)->default_value(25.98),
"std deviation of the number of generated data / bunch");
85 po::store(po::parse_command_line(argc, argv, desc), vm);
87 if (vm.count(
"help")) {
88 std::cout <<
"Basic Command Line Parameter App" << std::endl << desc << std::endl;
93 }
catch (po::error& e) {
94 std::cerr <<
"error: " << e.what() << std::endl << std::endl;
95 std::cerr << desc << std::endl;
101 rootman.
SetFileProperties(filename, treename, branchname, classname, fileoption, useTClonesArray);
106 RooRealVar n(
"N",
"N", nval.
fMin, nval.
fMax);
107 RooGaussian gaussN(
"gaussN",
110 RooFit::RooConst(nval.
fMean),
111 RooFit::RooConst(nval.
fSigma));
118 for (
unsigned int t = 0; t < tmax; t++) {
119 unique_ptr<RooDataSet> gaussSample(gaussN.generate(n, 1));
120 unsigned int nDigi =
static_cast<unsigned int>(gaussSample->get(0)->getRealValue(
"N"));
121 LOG(info) <<
"Bunch number " << t + 1 <<
"/" << tmax <<
" ("
122 << 100. *
static_cast<double>(t + 1) / static_cast<double>(tmax)
123 <<
" %). Number of generated digis: " << nDigi
124 <<
", payload = " << nDigi * (3 *
sizeof(Int_t) + 2 *
sizeof(Double_t)) <<
" bytes";
127 SaveDataToFile<TDigi, RootFileManager>(rootman, simdataset.get());
130 LOG(info) <<
"Data generation successful";
135 man.
SetFileProperties(filename, treename, branchname, classname,
"READ", useTClonesArray);
136 vector<vector<TDigi>> data = man.
GetAllObj(filename, treename, branchname);
146 TH1D histox(
"fx",
"digi.fx", 100, pdfConfig.
fX.
fMin, pdfConfig.
fX.
fMax);
147 TH1D histoy(
"fy",
"digi.fy", 100, pdfConfig.
fY.
fMin, pdfConfig.
fY.
fMax);
148 TH1D histoz(
"fz",
"digi.fz", 100, pdfConfig.
fZ.
fMin, pdfConfig.
fZ.
fMax);
149 TH1D histot(
"ftimestamp",
"digi.ftimestamp", 10 * tmax, 0., static_cast<double>(tmax + 1));
150 TH1D histoterr(
"ftimestampErr",
"digi.ftimestampErr", 100, pdfConfig.
fTErr.
fMin, pdfConfig.
fTErr.
fMax);
151 TH1D histoN(
"f_N",
"Number of digi distribution", 100, nval.
fMin, nval.
fMax);
153 for (
auto& p : data) {
154 histoN.Fill(static_cast<double>(p.size()));
156 histox.Fill(q.GetX());
157 histoy.Fill(q.GetY());
158 histoxy.Fill(q.GetX(), q.GetY());
159 histoz.Fill(q.GetZ());
160 histot.Fill(q.GetTimeStamp());
161 histoterr.Fill(q.GetTimeStampError());
165 TApplication app(
"App", &argc, argv);
167 TCanvas canvas(
"Tutorial7",
"Tutorial7", 1000, 800);
177 histoxy.Draw(
"zcol");
193 }
catch (exception& e) {
194 LOG(error) << e.what();
201 template<
typename T,
typename ManagerType>
205 for (
int i = 0; i < dataset->numEntries(); i++) {
207 data.SetTimeStamp(dataset->get(i)->getRealValue(
"t"));
208 data.SetTimeStampError(dataset->get(i)->getRealValue(
"tErr"));
210 data.SetX(static_cast<Int_t>(round(dataset->get(i)->getRealValue(
"x"))));
211 data.SetY(static_cast<Int_t>(round(dataset->get(i)->getRealValue(
"y"))));
212 data.SetZ(static_cast<Int_t>(round(dataset->get(i)->getRealValue(
"z"))));
215 LOG(info) <<
"x=" << data.GetX() <<
" y=" << data.GetY() <<
" z=" << data.GetZ()
216 <<
" t=" << data.GetTimeStamp() <<
" tErr=" << data.GetTimeStampError();
218 dataBunch.push_back(data);
221 outMan.AddToFile(dataBunch);
224 template<
typename T,
typename ManagerType>
228 for (
int i = 0; i < dataset->numEntries(); i++) {
230 data.fTimeStamp = dataset->get(i)->getRealValue(
"t");
231 data.fTimeStampError = dataset->get(i)->getRealValue(
"tErr");
233 data.fX =
static_cast<Int_t
>(round(dataset->get(i)->getRealValue(
"x")));
234 data.fY =
static_cast<Int_t
>(round(dataset->get(i)->getRealValue(
"y")));
235 data.fZ =
static_cast<Int_t
>(round(dataset->get(i)->getRealValue(
"z")));
238 LOG(info) <<
"x=" << data.fX <<
" y=" << data.fY <<
" z=" << data.fZ <<
" t=" << data.fTimeStamp
239 <<
" tErr=" << data.fTimeStampError;
241 dataBunch.push_back(data);
244 outMan.AddToFile(dataBunch);
RooDataSet * GetGeneratedData(unsigned int n, unsigned int ti)
void SavePodDataToFile(ManagerType &outMan, RooDataSet *dataset, bool printval=false)
void SaveDataToFile(ManagerType &outMan, RooDataSet *dataset, bool printval=false)
void SetFileProperties(const std::string &filename, const std::string &treeName, const std::string &branchName, const std::string &className="", const std::string &fileOption="RECREATE", bool useClonesArray=false, bool flowMode=true)
std::vector< std::vector< DataType > > GetAllObj(const std::string &filename, const std::string &treename, const std::string &branchname)
RootOutFileManager< TDigi > RootFileManager