Accessing and adding variables of trees

Hi,

I have input root file as its tree and branches look like when I type the commands as:

TFile *_file0 = TFile::Open("./Bs2KK_MC2017_36.root")
TTree *T = (TTree*)_file0->Get("T1")
T->Print()

******************************************************************************
*Tree    :T1        : CMSSW HF tree                                          *
*Entries :    12799 : Total =      4604483253 bytes  File  Size = 1151609353 *
*        :          : Tree compression factor =   4.00                       *
******************************************************************************
*Branch  :TAna01Event                                                        *
*Entries :    12799 : BranchElement (see below)                              *
*............................................................................*
*Br  169 :fMuons.fChi2LocalMomentum : Float_t fChi2LocalMomentum[fMuons_]    *
*Entries :    12799 : Total  Size=     300421 bytes  File Size  =      81759 *
*Baskets :       37 : Basket Size=      25088 bytes  Compression=   3.66     *
*............................................................................*
*Br  170 :fMuons.fNumberOfLostTrkHits : Int_t fNumberOfLostTrkHits[fMuons_]  *
*Entries :    12799 : Total  Size=     300503 bytes  File Size  =      56581 *
*Baskets :       37 : Basket Size=      25088 bytes  Compression=   5.29     *
*............................................................................*
*Br  171 :fMuons.fNumberOfValidTrkHits : Int_t fNumberOfValidTrkHits[fMuons_]*
*Entries :    12799 : Total  Size=     300544 bytes  File Size  =      59670 *
*Baskets :       37 : Basket Size=      25088 bytes  Compression=   5.02     *
*............................................................................*
*Br  172 :fMuons.fSegmentComp : Float_t fSegmentComp[fMuons_]                *
*Entries :    12799 : Total  Size=     300175 bytes  File Size  =      76596 *
*Baskets :       37 : Basket Size=      25088 bytes  Compression=   3.90     *
*............................................................................*

I’d like to get the variables, e.g. fMuons.fSegmentComp and add them to the data loader container.

How can I access and add the variables to be used for the MVA training?

Thanks a lot.

Hi,

With “data loader container” and “MVA training” you’re referring to TMVA I suppose? You can use dataloader->AddVariable(), see e.g. tutorials/tmva/TMVAClassification.C

Axel.

Thanks. Yes, I know dataloader->AddVariable(). My question is more like accessing the variables I have printed out from the tree. It is NOT straightforward as just calling dataloader->AddVariable( “var”, ‘F’ );

So in my case I cannot just call e.g. dataloader->AddVariable( “fSegmentComp”, ‘F’ );

from the print out you can also follow; I have a tree name T1, then its branch element TAna01Event and then the variables in branches that I want to access :
*Br 172 :fMuons.fSegmentComp : Float_t fSegmentComp[fMuons_]

which I could not achieve to access so far and need help…

Hi,

Have you tried using dataloader->AddVariable("fMuons.fSegmentComp")?

If this branch is an array you can add the individual elements like so:

dataloader->AddVariable("fMuons.fSegmentComp[0]")
dataloader->AddVariable("fMuons.fSegmentComp[1]")
// ...

Cheers,
Kim