Accessing a leaf within a branch in a branch

Hello all,

I have come across this problem in other places on ~the internet~, but haven’t seen a solution that works.

My problem is simple… I want to access the variable ADCs in the following TTree:

file:
ttree: rawdigit_daq_tree;
tbranch: rawdigit_daq_branch
tbranch: vectorlarlite::rawdigit
leaf: ADCs()

and the code I am using is:

[code]
#include “TTree.h”
#include “TFile.h”
#include “TRandom.h”
#include “TTree.h”
#include “TCanvas.h”
#include “TStyle.h”
#include “TMath.h”
#include
#include “TH1.h”
#include “TChain.h”

using namespace std;

void waveforms(){

TChain* wirecal = new TChain(“wire_caldata_tree”);
wirecal->Add(“file.root”);
TH1D *wf = new TH1D(“wf”,“waveform”,9000,0,9000);

int _ADCs;

THIS IS WHERE I AM LOST***

wirecal->SetBranchAddress(“ttree::rawdigit_daq_tree::rawdigit_daq_branch::vectorlarlite::rawdigit::ADCs()”, &_ADCs);


//I know that the :: isn’t working as a separator to go from branch to sub-branch, but I don’t know what to do

Long64_t nentries = wirecal->GetEntries();

Long64_t nb = 0, cb = 0 , cbytes = 0, nbytes = 0 ;

  for (Long64_t i=0; i<nentries ; i++) {
          Long64_t entry = wirecal->LoadTree(i);
          if (entry <0 ) break;

         nb = wirecal->GetEntry(i); nbytes += nb;
                                                                         
         //wf->Fill(_ADCs);                                            
                                                     
  }                                                                         

TCanvas *cans = new TCanvas(“cans”,“gobble gobble gobble”,750,200);

cans->cd(1);
wf->SetXTitle(“waveform”);
wf->Draw();

}[/code]

Any advice is appreciated.
Thank you!

Hi,

  • The argument to the TChain constructor is the TTree name in all the files. Is that “rawdigit_daq_tree” or “wire_caldata_tree” or “ttree”?

  • “::ADCs()” seems to suggest that you need to call a member function. What do you call that function on, where is that function defined? In larlite::rawdigit? Then you need to get objects of that type, and you need to pass the objects’ address to the TTree. As the TBranch actually holds a collection of those you should pass in a vectorlarlite::rawdigit,

  • Alternatively, you can figure out what “ADCs()” does - maybe it’s just returning a data member. Then you might have a branch of that name, same m_ADC, and you can set the branch address on that branch.

Makes sense? If not, please provide the output of TTree::Print() for your tree.

Cheers, Axel.

I have the same problem. I will appreciate any help.


*Tree :E : *
*Entries : 19 : Total = 133993260 bytes File Size = 12160733 *

  •    :          : Tree compression factor =  11.02                       *
    

*Branch :Evt *
*Entries : 19 : BranchElement (see below) *


*Br 17 :hits : Int_t hits_ *
*Entries : 19 : Total Size= 13884 bytes File Size = 203 *
*Baskets : 1 : Basket Size= 65536 bytes Compression= 1.12 *

My code:

chain[j]->SetBranchStatus("*",0);
chain[j]->SetBranchStatus(“Evt”,1);
chain[j]->SetBranchStatus(“hits”,1);
Evt evt;
Int_t hits_;
TBranch *b_Evt;//
TBranch *b_Evt_hits_; //!

chain[j]->SetBranchAddress(“Evt”, &evt, &b_Evt);
chain[j]->SetBranchAddress(“hits”, &hits_, &b_Evt_hits_);

Many Thanks,