Write and read STL vectors in a tree.
#include <vector>
void write()
{
if (!f) { return; }
TH1F *hpx =
new TH1F(
"hpx",
"This is the px distribution",100,-4,4);
std::vector<float> vpx;
std::vector<float> vpy;
std::vector<float> vpz;
std::vector<float> vrand;
TCanvas *c1 =
new TCanvas(
"c1",
"Dynamic Filling Example",200,10,700,500);
gRandom->SetSeed();
const Int_t kUPDATE = 1000;
for (
Int_t i = 0; i < 25000; i++) {
vpx.clear();
vpy.clear();
vpz.clear();
vrand.clear();
for (
Int_t j = 0; j < npx; ++j) {
gRandom->Rannor(px,py);
pz = px*px + py*py;
vpx.emplace_back(px);
vpy.emplace_back(py);
vpz.emplace_back(pz);
vrand.emplace_back(random);
}
if (i && (i%kUPDATE) == 0) {
if (i == kUPDATE) hpx->
Draw();
break;
}
}
}
void read()
{
if (!f) { return; }
std::vector<float> *vpx = 0;
TCanvas *c1 =
new TCanvas(
"c1",
"Dynamic Filling Example",200,10,700,500);
const Int_t kUPDATE = 1000;
TH1F *h =
new TH1F(
"h",
"This is the px distribution",100,-4,4);
for (
Int_t i = 0; i < 25000; i++) {
for (
UInt_t j = 0; j < vpx->size(); ++j) {
}
if (i && (i%kUPDATE) == 0) {
if (i == kUPDATE) h->
Draw();
break;
}
}
}
void hvector()
{
write();
read();
}
- Author
- The ROOT Team
Definition in file hvector.C.