Reading variables as branches

Hello,

I created a tree having Branches that contain some physical variables. I decided to filter this first tree, adding some selection cuts on the variables of this tree. So I cloned my first tree and created a new one. My question sounds very simple, but I can’t answer to it yet : Does somebody know how to access the value of the different variables (contained in each Branch of the Tree), event by event ?
Indeed, it is quite simple when you use a branch with leaves, because you can use some TClonesArray or TCollection to keep the type of particules inside (filled in branches), and then you take their variables (like pt or eta…) easily, but if you only have branches (filled with pt or eta of a given type of particule, for example), I really don’t know how to get the value of each variable per event.

Cheers,

Jerome 

(a new user of root framework)

Jerome,

I am not sure to understand what you mean. Could you post the result of mytree.Print(), such that we can see the layout of your Tree (or even better a small tree.root file)?

Rene

Hello Rene,

Thank you for your answer.
This is a part of the result of My_Tree->Print() - the first 30 variables - and the root file is attached.
Cheers,

Jerome


*Tree :My_Tree : Lepton+tau preselection *
*Entries : 85 : Total = 115618 bytes File Size = 50813 *

  •    :          : Tree compression factor =   1.00                       *
    

*Br 0 :RunNumber : _RunNumber/I *
*Entries : 85 : Total Size= 999 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 1 :EventNumber : _EventNumber/I *
*Entries : 85 : Total Size= 1011 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 2 :JetN : _JetN/I *
*Entries : 85 : Total Size= 969 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 3 :GoodJetN : _GJetN/I *
*Entries : 85 : Total Size= 984 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 4 :EventWeightNoMC : _EventWeightNoMC/D *
*Entries : 85 : Total Size= 1383 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 5 :MCWeight : _MCWeight/D *
*Entries : 85 : Total Size= 1341 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 6 :EventWeight : _EventWeight/D *
*Entries : 85 : Total Size= 1359 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 7 :TriggerProbability : _TriggerProbability/D *
*Entries : 85 : Total Size= 1401 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 8 :ObjectCorrection : _ObjectCorrection/D *
*Entries : 85 : Total Size= 1389 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 9 :MET : _METPt/D *
*Entries : 85 : Total Size= 1317 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 10 :METPhi : _METPhi/D *
*Entries : 85 : Total Size= 1329 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 11 :METx : _METPx/D *
*Entries : 85 : Total Size= 1320 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 12 :METy : _METPy/D *
*Entries : 85 : Total Size= 1320 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 13 :GJetPt_0 : _GJetPt_0/D *
*Entries : 85 : Total Size= 1341 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 14 :GJetEta_0 : _GJetEta_0/D *
*Entries : 85 : Total Size= 1347 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 15 :GoodJetCalEta_0 : _GJetCalEta_0/D *
*Entries : 85 : Total Size= 1374 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 16 :GoodJetPhi_0 : _GJetPhi_0/D *
*Entries : 85 : Total Size= 1356 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 17 :GoodJetPt_1 : _GJetPt_1/D *
*Entries : 85 : Total Size= 1350 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 18 :GoodJetEta_1 : _GJetEta_1/D *
*Entries : 85 : Total Size= 1356 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 19 :GoodJetPhi_1 : _GJetPhi_1/D *
*Entries : 85 : Total Size= 1356 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 20 :GoodJetPt_2 : _GJetPt_2/D *
*Entries : 85 : Total Size= 1350 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 21 :GoodJetEta_2 : _GJetEta_2/D *
*Entries : 85 : Total Size= 1356 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 22 :GoodJetPhi_2 : _GJetPhi_2/D *
*Entries : 85 : Total Size= 1356 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 23 :GoodJetPt_3 : _GJetPt_3/D *
*Entries : 85 : Total Size= 1350 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 24 :GoodJetEta_3 : _GJetEta_3/D *
*Entries : 85 : Total Size= 1356 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 25 :GoodJetPhi_3 : _GJetPhi_3/D *
*Entries : 85 : Total Size= 1356 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 26 :GoodJet1MetDeltaPhi : _GJet1MetDeltaPhi/D *
*Entries : 85 : Total Size= 1398 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 27 :GoodJet2MetDeltaPhi : _GJet2MetDeltaPhi/D *
*Entries : 85 : Total Size= 1398 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 28 :Jet_Pt : _Jet_Pt[_JetN]/D *
*Entries : 85 : Total Size= 4468 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 29 :GoodJet_Pt : _GJet_Pt[_GJetN]/D *
*Entries : 85 : Total Size= 3191 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 30 :Jet_detEta : _Jet_detEta[_JetN]/D *
*Entries : 85 : Total Size= 4492 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

My_Tree_WJets.root (53.9 KB)

Jerome,

I suggest to generate a simple skeleton analysis code by doing:

root > TFile f("My_Tree_WJets.root") root > My_Tree.MakeClass("T")
This will generate T.H and T.C. Add your analysis code in T::Loop. In this function you can access directly the variables of your entry.

Rene

It’s really a perfect way to do it!
Thank you very much Rene,
Cheers,

Jerome