Help/Suggestion on using tree

I have a big tree with somthing like 90 different branch which contains the same leaf. See example:

One of the branch:
JetIC_TR_DR30_size = 5
JetIC_TR_DR30.E = 212.257843, 135.838760, 227.203079, 37.975430, 22.027512
JetIC_TR_DR30.Px = -140.315536, -1.380136, -18.705088, 29.495493, -7.386530
JetIC_TR_DR30.Py = 158.080704, -60.837593, -46.806648, -22.121532, -6.835046
JetIC_TR_DR30.Pz = -14.499918, -121.257324, -221.510529, 8.405622, -19.575159

Another one
JetIC_TR_DR35_size = 6
JetIC_TR_DR35.E = 212.257843, 135.838760, 227.203079, 45.725357, 22.027512, 34,4234432
JetIC_TR_DR35.Px = -140.315536, -1.380136, -18.705088, 35.674442, -7.386530, 654,4323
JetIC_TR_DR35.Py = 158.080704, -60.837593, -46.806648, -26.679886, -6.835046, 54,12332
JetIC_TR_DR35.Pz = -14.499918, -121.257324, -221.510529, 7.398261, -19.575159, 786,432443

I have to reapeat the same peace of code on each branch. The rough algo would be something like this:

A) choose branch

B) assign:
for (int n0=0;n0<chooseBranch_size;n0++) {
myPx[n0]= chooseBranch_Px[n0]
myPy[n0]= chooseBranch_Py[n0]


C) do whatever I need using myPx, myPy, myPz…

On option would be using a switch reapting step B) and using 90 case… but I hope there is a more efficient way, like define a variable name from a charcter array.

Any idea, suggestion, example on a better way to deal with this problem?


I am not sure to understand your request. It lloks to me taht you are using
the wrong data model! Instead of using 90 branches, you should use
a TClonesArray od std::vector in split mode.

If your question is simply how to encode an integer into a string, you can do something like
for (Int_t i=0;i<90;i++0 {
T.Branch(Form(" JetIC_TR_DR%d",i,…
This will create branches
JetIC_TR_DR1, etc


Well, it’s not that simple. I agree that this is not the more efficient way but the tree is produced by a very complicated program and it would take too much effort to change it.

I’ll try to be more clear:
I have this tree and I have to run the same peace of code on all the 90 branch (which have been already named… and saved to a file, so I’m reading from that file).

Suppose that I have to calculate the Pt for each branch, the simple way could be:
float function pt(int jetType) {
float myPt;
switch(jetType) {
case 1:
myPt=sqrt(JetIC_TR_DR30.Px*JetIC_TR_DR30.Px+JetIC_TR_DR30.Py JetIC_TR_DR30.Py );
case 2:
JetIC_TR_DR35.Px+JetIC_TR_DR35.Py *JetIC_TR_DR35.Py );
case 3:

case 90:

return myPt;

The code is not really working but I suppose it gives an idea.

My question is: given the tree saved in a file and using the method MakeClass I have in the class.h something like this:

const Int_t kMaxJetIC_NO_DR30 = 40;
const Int_t kMaxJetIC_NO_DR35 = 40;
const Int_t kMaxJetIC_NO_DR40 = 40;
const Int_t kMaxJetIC_NO_DR45 = 40;

Int_t JetIC_NO_DR30_size;
Int_t JetIC_NO_DR30_;
UInt_t JetIC_NO_DR30_fUniqueID[kMaxJetIC_NO_DR30]; //[JetIC_NO_DR30_]
UInt_t JetIC_NO_DR30_fBits[kMaxJetIC_NO_DR30]; //[JetIC_NO_DR30_]
Float_t JetIC_NO_DR30_E[kMaxJetIC_NO_DR30]; //[JetIC_NO_DR30_]
Float_t JetIC_NO_DR30_Px[kMaxJetIC_NO_DR30]; //[JetIC_NO_DR30_]
Float_t JetIC_NO_DR30_Py[kMaxJetIC_NO_DR30]; //[JetIC_NO_DR30_]
Float_t JetIC_NO_DR30_Pz[kMaxJetIC_NO_DR30]; //[JetIC_NO_DR30_]


All the 90 different branches have the same leafes and I was wondering if the above example function can be written in a more efficient way starting from what is written in the class.h file.

I hope to have clearified my question.


Try using MakeProxy. It should create a skeleton where the object hierarchy of your file is preserver and you maybe able to manipulate directly the JetIC_TR_DR30 as object.