Please read tips for efficient and successful posting and posting code
ROOT Version: 6.24
Platform: macOS Monterey
Compiler: clang
Hi,
I wrote a macro (below) to add a branch to an existing tree
void makeAvgBranch() {
TFile* inFile = new TFile("somefile.root", "update");
TTree* tree = static_cast<TTree*>(inFile->Get("someTree"));
tree->Print();
Double_t newBranch;
tree->Branch("avg", &newBranch);
Double_t data_a, data_b;
tree->SetBranchAddress("a", &data_a);
tree->SetBranchAddress("b", &data_b);
for (int i = 0; i < tree->GetEntries(); i++) {
tree->GetEntry(i);
newBranch->Fill(0.5*(data_a + data_b));
}
tree->Print();
}
This version produces the following error:
root [0]
Processing makeAvgBranch.C...
In file included from input_line_8:1:
/path/to/makeAvgBranch.C:12:20: error: member reference type 'Double_t' (aka 'double') is not a pointer
newBranch->Fill(0.5*(data_a + data_b));
~~~~~~~~~ ^
root [1]
So, to fix this error, I changed to above macro to the following:
void makeAvgBranch() {
TFile* inFile = new TFile("somefile.root", "update");
TTree* tree = static_cast<TTree*>(inFile->Get("someTree"));
tree->Print();
Double_t newBranch;
TBranch* avgBranch = tree->Branch("avg", &newBranch);
Double_t data_a, data_b;
tree->SetBranchAddress("a", &data_a);
tree->SetBranchAddress("b", &data_b);
for (int i = 0; i < tree->GetEntries(); i++) {
tree->GetEntry(i);
avgBranch->Fill(0.5*(data_a + data_b));
}
tree->Print();
}
However, the same error still shows up. I made some other changes like commenting out everything below the first tree->Print(); line, but no matter what I do, the same error keeps popping up. How do I fix this?