Function to access variable from branch name

Hi,

I am trying to access the value of a variable in a TTree using the name of the branch.

The point is that i have a long list of branches:

   fChain->SetBranchAddress("PDF1", &PDF01, &b_PDF01);
   fChain->SetBranchAddress("PDF2", &PDF02, &b_PDF02);
   fChain->SetBranchAddress("PDF3", &PDF03, &b_PDF03);
   fChain->SetBranchAddress("PDF4", &PDF04, &b_PDF04);
   fChain->SetBranchAddress("PDF5", &PDF05, &b_PDF05);
   fChain->SetBranchAddress("PDF6", &PDF06, &b_PDF06);
   fChain->SetBranchAddress("PDF7", &PDF07, &b_PDF07);
   fChain->SetBranchAddress("PDF8", &PDF08, &b_PDF08);
   fChain->SetBranchAddress("PDF9", &PDF09, &b_PDF09);
   fChain->SetBranchAddress("PDF10", &PDF10, &b_PDF10);
   fChain->SetBranchAddress("PDF11", &PDF11, &b_PDF11);
   fChain->SetBranchAddress("PDF12", &PDF12, &b_PDF12);
   fChain->SetBranchAddress("PDF13", &PDF13, &b_PDF13);
...
...
...

and I would like to access the variables PDF01, PDF02 etc within a loop.
Something like:

for(int i=0; i<100; i++){

char bname[10];
sprintf(bname,"PDF%d",i);

// Here I need to get the value of the variable using the branch name


}

is there any simple solution?
One workaround would be to create a vector<float*> pdfs
and push_back the addresses of the variables but, it requires a lot of writing and the branches could be up to 1000.

pdfs.push_back(&PDF01,);
pdfs.push_back(&PDF02,);
pdfs.push_back(&PDF03,);
etc etc

any idea?

cheers,
delo

Hi,

I think found a solution.
I just re-set the branch address in this way


  float pdf[40];

  for(int b=1 ;b<40; b++ ){
    char bname[10]; 
     sprintf(bname,"PDF%d",b);   
     fChain->SetBranchAddress(bname,&pdf[b] );

  } 

so after the GetEntry() the variables are stored in a vector of float and can be easily accessed within a loop.

cheers,
delo