#include <vector>
void write_vector()
{
return;
auto hpx =
new TH1F(
"hpx",
"This is the px distribution", 100, -4, 4);
hpx->SetFillColor(48);
std::vector<float> vpx;
std::vector<float> vpy;
std::vector<float> vpz;
std::vector<float> vrand;
TTree *t =
new TTree(
"tvec",
"Tree with vectors");
auto c1 =
new TCanvas(
"c1",
"Dynamic Filling Example", 200, 10, 700, 500);
for (
Int_t i = 0; i < 25000; i++) {
vpx.clear();
vpy.clear();
vpz.clear();
vrand.clear();
for (
Int_t j = 0; j < npx; ++j) {
pz = px * px + py * py;
hpx->Fill(px);
vpx.emplace_back(px);
vpy.emplace_back(py);
vpz.emplace_back(pz);
vrand.emplace_back(random);
}
hpx->Draw();
break;
}
}
}
void read_vector()
{
return;
auto t =
f->Get<
TTree>(
"tvec");
std::vector<float> *vpx = nullptr;
auto c1 =
new TCanvas(
"c1",
"Dynamic Filling Example", 200, 10, 700, 500);
auto 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) {
}
break;
}
}
}
void tree121_hvector()
{
write_vector();
read_vector();
}
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
long long Long64_t
Portable signed long integer 8 bytes.
float Float_t
Float 4 bytes (float).
externTBenchmark * gBenchmark
A TTree is a list of TBranches.
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all leaves of entry and return total number of bytes read.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
1-D histogram with a float per channel (see TH1 documentation)
A TTree represents a columnar dataset.
virtual Int_t Fill()
Fill all branches.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
virtual Long64_t LoadTree(Long64_t entry)
Set current entry.
virtual void ResetBranchAddresses()
Tell all of our branches to drop their current objects and allocate new ones.