25 TFile *f = TFile::Open(
"hvector.root",
"RECREATE");
30 TH1F *hpx =
new TH1F(
"hpx",
"This is the px distribution",100,-4,4);
31 hpx->SetFillColor(48);
33 std::vector<float> vpx;
34 std::vector<float> vpy;
35 std::vector<float> vpz;
36 std::vector<float> vrand;
39 TTree *t =
new TTree(
"tvec",
"Tree with vectors");
40 t->Branch(
"vpx",&vpx);
41 t->Branch(
"vpy",&vpy);
42 t->Branch(
"vpz",&vpz);
43 t->Branch(
"vrand",&vrand);
46 TCanvas *c1 =
new TCanvas(
"c1",
"Dynamic Filling Example",200,10,700,500);
49 const Int_t kUPDATE = 1000;
50 for (Int_t i = 0; i < 25000; i++) {
51 Int_t npx = (Int_t)(gRandom->Rndm(1)*15);
58 for (Int_t j = 0; j < npx; ++j) {
61 gRandom->Rannor(px,py);
63 Float_t random = gRandom->Rndm(1);
70 vrand.emplace_back(random);
73 if (i && (i%kUPDATE) == 0) {
74 if (i == kUPDATE) hpx->Draw();
77 if (gSystem->ProcessEvents())
91 TFile *f = TFile::Open(
"hvector.root",
"READ");
95 TTree *t; f->GetObject(
"tvec",t);
97 std::vector<float> *vpx = 0;
100 TCanvas *c1 =
new TCanvas(
"c1",
"Dynamic Filling Example",200,10,700,500);
102 const Int_t kUPDATE = 1000;
105 t->SetBranchAddress(
"vpx",&vpx,&bvpx);
109 TH1F *h =
new TH1F(
"h",
"This is the px distribution",100,-4,4);
112 for (Int_t i = 0; i < 25000; i++) {
114 Long64_t tentry = t->LoadTree(i);
115 bvpx->GetEntry(tentry);
117 for (UInt_t j = 0; j < vpx->size(); ++j) {
122 if (i && (i%kUPDATE) == 0) {
123 if (i == kUPDATE) h->Draw();
126 if (gSystem->ProcessEvents())
133 t->ResetBranchAddresses();
139 gBenchmark->Start(
"hvector");
144 gBenchmark->Show(
"hvector");