Hi,
I’m trying to add a new branch constructed from previous branches already stored in a pre-existing TTree to that same TTree. The new branch is just a “smeared” version of the old. I do this by sampling a point in phi-pt space from a pre-existing TH2F.
TString baseString = "location/to/my/file.root";
///read in TH2F histos
TFile *fSyst = new TFile("HistosForSystematics.root","read");
TFile *fIn = new TFile(baseString,"update");
TTree* tree = (TTree*)fIn->Get("tree");
float mpt,mptPhi,mptMod,mptPhiMod;
TBranch *b_nu_ptMod = tree->Branch("nu_ptMod",&mptMod,"nu_ptMod/F");
TBranch *b_nu_phiMod = tree->Branch("nu_phiMod",&mptPhiMod,"nu_phiMod/F");
tree->SetBranchAddress("nu_phi", &mptPhi);
tree->SetBranchAddress("nu_pt", &mpt);
tree->SetBranchStatus("*",0) ;
tree->SetBranchStatus("nu_pt", 1);
tree->SetBranchStatus("nu_phi", 1);
const int nEntries = tree->GetEntries();
for(int iev=0; iev<nEntries; ++iev){
tree->GetEntry(iev);
Double_t sampledDelPhi=0.0,sampledDelPt=0.0;
TString sHistName ="h2DHisto";
TH2* hSyst = NULL;
hSyst = (TH2*)fSyst->Get(sHistName);
hSyst->GetRandom2(sampledDelPt,sampledDelPhi);
smearVar(mptPhi,sampledDelPhi,mptPhiMod);
smearVar(mpt,sampledDelPt,mptMod);
b_nu_ptMod->Fill();
b_nu_phiMod->Fill();
}//iev
tree->Print();
tree->Write();
delete fIn;
delete fSyst;
However, when printing the tree the number of entries in the new branches is always 0. Any ideas?