Write and read a Vector3 class in a tree.
class Vector3
{
public:
Vector3() : fX(0), fY(0), fZ(0) {}
fZ = z;
}
};
void write_vector3()
{
auto T =
new TTree(
"T",
"vector3 Tree");
T->Branch(
"v3", &
v, 32000, 1);
for (
Int_t i=0; i<10000; i++) {
v->SetXYZ(
r.Gaus(0, 1),
r.Landau(0, 1),
r.Gaus(100, 10));
T->Fill();
}
T->Write();
T->Print();
}
void read_all_vector3()
{
auto h1 =
new TH1F(
"x",
"x component of Vector3", 100, -3, 3);
T->GetEntry(i);
}
}
void read_branch_vector3()
{
auto by = T->GetBranch("fY");
auto h2 =
new TH1F(
"y",
"y component of Vector3", 100, -5, 20);
by->GetEntry(i);
}
h2->Draw();
}
void tree122_vector3()
{
auto c1 =
new TCanvas(
"c1",
"demo of Trees", 10, 10, 600, 800);
write_vector3();
read_all_vector3();
read_branch_vector3();
}
int Int_t
Signed integer 4 bytes (int).
double Double_t
Double 8 bytes.
long long Long64_t
Portable signed long integer 8 bytes.
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)
This is the base class for the ROOT Random number generators.
A TTree represents a columnar dataset.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)
- Author
- The ROOT Team
Definition in file tree122_vector3.C.