How to copy Branch properly ( MakeClass() used )?

I have a TTree tree1 and I used TTree::MakeClass("Selector") method for loop over this tree. I create some other TTree tree2 in Loop() which branches are derived from some calculations with branches of tree1. But for some branches I want to copy entire branch to tree2 with the same name? What is proper way to do this?

When using MakeClass, you need create by hand in the new TTree each of the branch you want to copy.


OK. Suppose I have the following line:


i.e. this branch is the branch of arrays of length 3. Suppose that tree1 also contain branch b2.
How to copy b2 in tree1 to tree2 as b2?

Something like

tree1->GetEntry(...); // or tree1->GetBranch("b2")->GetEntry(...);

I use Selector.C (created by MakeClass) in the following way:

[sikach@sl16cmd KinFitter]$ root -l root://cmd//scan2011/scan2011_tr_ph_fc_e700_v3.root
Hello, Explorer. The Universe is still working. Go Ahead.
root [0] 
Attaching file root://cmd//scan2011/scan2011_tr_ph_fc_e700_v3.root as _file0...
(TFile *) 0x3678220
root [1] .L Selector.C
root [2] Selector a(tr_ph)
(Selector &) @0x7fd53800a000
root [3] a.Loop()

And this is piece of Selector.C code:

void Selector::Loop(){
 for (Long64_t jentry=0; jentry<nentries;jentry++){
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);  
      nbytes += nb;

You see that I cannot just type


because I load tree in Loop() function. Am I missing something?

I think I know the solution. Look at this ( in Selector.h ):

class Selector {
  public :
     TTree          *fChain;   //!pointer to the analyzed TTree or TChain
     Int_t           fCurrent; //!current Tree number in a TChain

I just added
and it seems working.
Should I remove this topic?

In context, the fChain->SetBranchAddress should already have been existing … but using one of the data member of the Selector. You could have used this datamember to create the new branch.


I think I understand what do you mean, but want to confirm: Is this valid:

tree2->Branch("b2", &b2, "b2[3]/F")

And that’s all?

If b2 is a data member of the selector and there is a fChain->SetBranchAddress(“b2”,&b2, …
then yes it should be valid.


It is really the shortest way. Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.