Accessing the data inside a Ttree leaf


ROOT Version: v06_14_02
Platform: Not Provided
Compiler: Not Provided


okay, so I have a file with a TTree with different leaves, out of which I need three specific branches. However, when i try to access the data from “nu” i cant access the data correctly (i get weird values or if I set the nu_ADC to -1, it stays as -1

void SN_NU_Distributions()
{
   TChain *tc = new TChain("match");
   tc->Add("/Applications/textFiles/compare_sn_vs_nu.root");
  
   unsigned int nu_ADC;
   tc->SetBranchAddress("nu",&nu_ADC);
   int entries = tc->GetEntries();
   std::cout << "Total number of entries "<< entries << std::endl;
   for (int i =0; i<tc->GetEntries();i++)
   {
       tc->GetEntry(i);
	//std::cout <<"tree entry " <<  tc->GetEntry(i) <<std::endl;
       std::cout<< nu_ADC <<std::endl;
	break;
   }




for(int i=0; i<tc->GetListOfLeaves()->GetEntries(); ++i)
    {
        std::cout << tc->GetListOfLeaves()->At(i)->GetName() << std::endl;
    }

   std::cout <<"check if nu was properly allocated " << nu_ADC <<std::endl;





}

From your code I see nothing wrong.

If you have more than 2^31 entries (roughly 2 billion) in the chain you should use the datatype Long64_t instead of int for the variables i and entries, but as long as you stay below 2^31 it should be no problem.

Have you tried whether it works if you don’t use the TChain but access the TTree directly?

Is the branch “nu” a top level branch or a subbranch?
The output of the Print() function of one of the trees might help too cause it shows the Tree structure.

I am trying to work on accessing the

here are the print outputs:

match

trig

frame

crate

card

channel

plane

wirenum

wire

t

packett

i

carryover

starts_with_huffmann

huffmann

sn

sn_boiled1

sn_boiled2

sn_boiled3

sn_boiled

sn_prev

sn_next

nu

sn_bits

nu_bits

sn_nu_bits

packet

stops

header

missingchannel

This looks really strange. For me the output of TTree::Print() looks like this:

******************************************************************************
*Tree    :tDat      : Lambda Analysis Tree                                   *
*Entries :  4054048 : Total =        85560332 bytes  File  Size =   68854282 *
*        :          : Tree compression factor =   1.24                       *
******************************************************************************
*Br    0 :CentPar   : CentPar/F                                              *
*Entries :  4054048 : Total  Size=   16292363 bytes  File Size  =    7272323 *
*Baskets :      807 : Basket Size=      32000 bytes  Compression=   2.24     *
*............................................................................*
*Br    1 :Mot_Px    : Mot_Px/F                                               *
*Entries :  4054048 : Total  Size=   16291552 bytes  File Size  =   15122651 *
*Baskets :      807 : Basket Size=      32000 bytes  Compression=   1.08     *
*............................................................................*
*Br    2 :Mot_Py    : Mot_Py/F                                               *
*Entries :  4054048 : Total  Size=   16291552 bytes  File Size  =   15046883 *
*Baskets :      807 : Basket Size=      32000 bytes  Compression=   1.08     *
*............................................................................*
*Br    3 :Mot_Pz    : Mot_Pz/F                                               *
*Entries :  4054048 : Total  Size=   16291552 bytes  File Size  =   14563808 *
*Baskets :      807 : Basket Size=      32000 bytes  Compression=   1.12     *
*............................................................................*
*Br    4 :Mot_E     : Mot_E/F                                                *
*Entries :  4054048 : Total  Size=   16290741 bytes  File Size  =   14114109 *
*Baskets :      807 : Basket Size=      32000 bytes  Compression=   1.15     *
*............................................................................*
*Br    5 :Parameter : Parameter/b                                            *
*Entries :  4054048 : Total  Size=    4102171 bytes  File Size  =    2696990 *
*Baskets :      498 : Basket Size=      32000 bytes  Compression=   1.52     *
*............................................................................*

sorry, here it is

*Tree    :match     : matched_samples                                        *
*Entries : 79303973 : Total =      8248238129 bytes  File  Size =  910180782 *
*        :          : Tree compression factor =   9.06                       *
******************************************************************************
*Branch  :match                                                              *
*Entries : 79303973 : BranchElement (see below)                              *
*............................................................................*
*Br    0 :trig      : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317238369 bytes  File Size  =    1408847 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression= 225.17     *
*............................................................................*
*Br    1 :frame     : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317238614 bytes  File Size  =    1564237 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression= 202.80     *
*............................................................................*
*Br    2 :crate     : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317238614 bytes  File Size  =    1565248 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression= 202.67     *
*............................................................................*
*Br    3 :card      : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317238369 bytes  File Size  =    1585968 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression= 200.02     *
*............................................................................*
*Br    4 :channel   : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317239104 bytes  File Size  =    3139579 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression= 101.04     *
*............................................................................*
*Br    5 :plane     : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317238614 bytes  File Size  =    2225472 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression= 142.55     *
*............................................................................*
*Br    6 :wirenum   : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317239104 bytes  File Size  =    3177279 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=  99.84     *
*............................................................................*
*Br    7 :wire      : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317238369 bytes  File Size  =    3299535 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=  96.14     *
*............................................................................*
*Br    8 :t         : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317237545 bytes  File Size  =   64950996 *
*Baskets :      240 : Basket Size=   25600000 bytes  Compression=   4.88     *
*............................................................................*
*Br    9 :packett   : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317239104 bytes  File Size  =   13732781 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=  23.10     *
*............................................................................*
*Br   10 :i         : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317237545 bytes  File Size  =   17101003 *
*Baskets :      240 : Basket Size=   25600000 bytes  Compression=  18.55     *
*............................................................................*
*Br   11 :carryover : Bool_t                                                 *
*Entries : 79303973 : Total  Size=   79315841 bytes  File Size  =     359978 *
*Baskets :      119 : Basket Size=   25600000 bytes  Compression= 220.33     *
*............................................................................*
*Br   12 :starts_with_huffmann : Bool_t                                      *
*Entries : 79303973 : Total  Size=   79317194 bytes  File Size  =     375291 *
*Baskets :      119 : Basket Size=   25600000 bytes  Compression= 211.34     *
*............................................................................*
*Br   13 :huffmann  : Bool_t                                                 *
*Entries : 79303973 : Total  Size=   79315718 bytes  File Size  =   13310150 *
*Baskets :      119 : Basket Size=   25600000 bytes  Compression=   5.96     *
*............................................................................*
*Br   14 :sn        : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317237789 bytes  File Size  =   91998769 *
*Baskets :      240 : Basket Size=   25600000 bytes  Compression=   3.45     *
*............................................................................*
*Br   15 :sn_boiled1 : Int_t                                                 *
*Entries : 79303973 : Total  Size=  317239839 bytes  File Size  =   91118673 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=   3.48     *
*............................................................................*
*Br   16 :sn_boiled2 : Int_t                                                 *
*Entries : 79303973 : Total  Size=  317239839 bytes  File Size  =   91117149 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=   3.48     *
*............................................................................*
*Br   17 :sn_boiled3 : Int_t                                                 *
*Entries : 79303973 : Total  Size=  317239839 bytes  File Size  =    1410297 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression= 224.94     *
*............................................................................*
*Br   18 :sn_boiled : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317239594 bytes  File Size  =   91034190 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=   3.48     *
*............................................................................*
*Br   19 :sn_prev   : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317239104 bytes  File Size  =   95445495 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=   3.32     *
*............................................................................*
*Br   20 :sn_next   : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317239104 bytes  File Size  =   95390166 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=   3.33     *
*............................................................................*
*Br   21 :nu        : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317237789 bytes  File Size  =   90107750 *
*Baskets :      240 : Basket Size=   25600000 bytes  Compression=   3.52     *
*............................................................................*
*Br   22 :sn_bits   : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317239104 bytes  File Size  =   50077059 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=   6.33     *
*............................................................................*
*Br   23 :nu_bits   : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317239104 bytes  File Size  =   49647694 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=   6.39     *
*............................................................................*
*Br   24 :sn_nu_bits : Int_t                                                 *
*Entries : 79303973 : Total  Size=  317239839 bytes  File Size  =    8770290 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=  36.17     *
*............................................................................*
*Br   25 :packet    : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317238859 bytes  File Size  =   10706239 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=  29.63     *
*............................................................................*
*Br   26 :stops     : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317238614 bytes  File Size  =    1409818 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression= 225.02     *
*............................................................................*
*Br   27 :header    : Int_t                                                  *
*Entries : 79303973 : Total  Size=  317238859 bytes  File Size  =   13734213 *
*Baskets :      241 : Basket Size=   25600000 bytes  Compression=  23.10     *
*............................................................................*
*Br   28 :missingchannel : Bool_t                                            *
*Entries : 79303973 : Total  Size=   79316456 bytes  File Size  =     359405 *
*Baskets :      119 : Basket Size=   25600000 bytes  Compression= 220.68     *
*............................................................................*

Ok, so the branch “nu” is a subbranch of “match”, but in case the branch is not found you would get an error message. I’m wondering why you set the basket size to 25.6 MB, Default is 32 kB. Furthermore the type of “nu” is int and in your code you use unsigned int but this should not cause such problems.

How did you create the Tree? Is “nu” a data member of a class you wrote to the Tree with a split level > 0?

Unfortunately, i didn’t create the file! But I do have a second question which might help me bypass the problem. Is there a way to write a into a second root file, a ttree->draw(result)?

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