Adding new branches to existing tree, with TSelector


I have made an analyzer with TTree::MakeSelector(), now I want to use this analyzer to add more branches to my tree. Is this possible? If yes please point me to example.

Thank you,


So far I have tried the following:

in the constructor:

[code] TFile* new_file;

//My new branches
TBranch* b_recHit_n3;
TBranch* b_recHit_x3;[/code]

in the Init(TTree *tree)

[code]TFile *new_file = new TFile(“new.root”,“recreate”);

if (!tree) return;
fChain = tree;
//new Branches
b_recHit_n3 = fChain->Branch(“recHit_n3”,&recHit_n3,“recHit_n3/I”);
b_recHit_x3 = fChain->Branch(“recHit_x3”,recHit_x3,“recHit_x3[recHit_n3]/D”);[/code]

The in the Process(Long64_t entry)

and in the Terminate()

But all I get is:

[quote]Error in TTree::Fill: Failed filling branch:Events_run112.pulse_height3, nbytes=-1
This error is symptomatic of a Tree created as a memory-resident Tree
Instead of doing:
TTree *T = new TTree(…)
TFile *f = new TFile(…)
you should do:
TFile *f = new TFile(…)
TTree *T = new TTree(…)

and when I am trying to access the TTree in the new file I am getting segmentation faults.

Any ideas on what should I do differently?

Thank you,



TChain object are read only. Adding branch to a TTree is technically possible but strongly discouraged (you need to both add them and make sure that there are filled with the ‘right’ amount of entries without affecting the content of the other branches or the length of the TTree) (thus you could maybe possibly implement what you tried but it will both much more complex that what you have and brittle).

I recommend that you simply create a new TTree that you will (in the later analysis) use as a Friend of the input Tree(s).