void CreateParentTree()
{
auto T =
new TTree(
"T",
"test friend trees");
T->Branch("Run", &Run, "Run/I");
T->Branch(
"Event", &
Event,
"Event/I");
T->Branch(
"x", &
x,
"x/F");
T->Branch(
"y", &
y,
"y/F");
T->Branch("z", &z, "z/F");
for (
Int_t i=0; i<10000; i++) {
if (i < 5000)
Run = 1;
else
Run = 2;
T->Fill();
}
T->Print();
T->Write();
}
void CreateFriendTree()
{
auto TF = T->CopyTree("z<10");
TF->SetName("TF");
TF->BuildIndex("Run", "Event");
TF->Write();
TF->Print();
delete ff;
}
void CompareTrees()
{
auto TF = ff->Get<
TTree>(
"TF");
T->SetBranchAddress(
"Event", &
Event);
T->SetBranchAddress(
"x", &
x);
T->SetBranchAddress(
"y", &
y);
T->SetBranchAddress("z", &z);
TF->SetBranchAddress("Run", &fRun);
TF->SetBranchAddress("Event", &fEvent);
TF->SetBranchAddress("x", &fx);
TF->SetBranchAddress("y", &fy);
TF->SetBranchAddress("z", &fz);
T->AddFriend(TF);
T->GetEntry(i);
if (fRun == Run && fEvent==
Event &&
x==fx &&
y==fy && z==fz) {
nok++;
} else {
if (TF->GetEntryWithIndex(Run,
Event) > 0) {
if (i <100)
printf("i=%lld, Run=%d, Event=%d, x=%g, y=%g, z=%g : fRun=%d, fEvent=%d, fx=%g, fy=%g, fz=%g\n",
i, Run,
Event,
x,
y, z, fRun, fEvent, fx, fy, fz);
}
}
}
printf("nok = %d, fentries=%lld\n", nok, TF->GetEntries());
delete ff;
}
void DrawFriend()
{
}
void tree109_friend()
{
CreateParentTree();
CreateFriendTree();
CompareTrees();
DrawFriend();
}
int Int_t
Signed integer 4 bytes (int).
long long Long64_t
Portable signed long integer 8 bytes.
float Float_t
Float 4 bytes (float).
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.
This is the base class for the ROOT Random number generators.
A TTree represents a columnar dataset.
virtual TFriendElement * AddFriend(const char *treename, const char *filename="")
Add a TFriendElement to the list of friends.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)