In the function treer, the first Tree is open. The second Tree is declared friend of the first tree. TTree::Draw is called with variables from both Trees.
void tree107_write()
{
const Int_t kMaxTrack = 500;
TFile f(
"tree108.root",
"recreate");
auto t3 =
new TTree(
"t3",
"Reconst ntuple");
t3->Branch("ntrack", &ntrack, "ntrack/I");
t3->Branch("stat", stat, "stat[ntrack]/I");
t3->Branch("sign", sign, "sign[ntrack]/I");
t3->Branch("px", px, "px[ntrack]/F");
t3->Branch("py", py, "py[ntrack]/F");
t3->Branch("pz", pz, "pz[ntrack]/F");
t3->Branch("zv", zv, "zv[ntrack]/F");
t3->Branch("chi2", chi2, "chi2[ntrack]/F");
TFile fr(
"tree108f.root",
"recreate");
auto t3f =
new TTree(
"t3f",
"a friend Tree");
t3f->Branch("ntrack", &ntrack, "ntrack/I");
t3f->Branch("sumstat", &sumstat, "sumstat/D");
t3f->Branch(
"pt",
pt,
"pt[ntrack]/F");
for (
Int_t i=0; i<1000; i++) {
ntrack = nt;
sumstat = 0;
}
t3->Fill();
t3f->Fill();
}
t3->Print();
t3->Write();
fr.cd();
t3f->Write();
}
void tree107_read()
{
auto t3 =
f->Get<
TTree>(
"t3");
}
void tree107_read2()
{
auto p =
new TPad(
"p",
"p", 0.6, 0.4, 0.98, 0.8);
p->Draw();
p->cd();
}
void tree107_tree()
{
tree107_write();
tree107_read();
tree107_read2();
}
int Int_t
Signed integer 4 bytes (int).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
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.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
The most important graphics class in the ROOT system.
A TTree represents a columnar dataset.
virtual TFriendElement * AddFriend(const char *treename, const char *filename="")
Add a TFriendElement to the list of friends.
Double_t Sqrt(Double_t x)
Returns the square root of x.