tree.Draw with an index

Hi,

I am trying to figure out (unsuccessfully) the syntax for
using tree.Draw with an index.

I execute sucessfully

t61057.Draw(“detadc[][0]>>h1”,“Entry$<2500”,"");

Now, I would like to loop over an index, like

for (int i=0; i<48; i++) {
t61057.Draw(“detadc[][i]>>h1”,“Entry$<2500”,"");

h1->Reset();
}

I tried to use something like

for (int i=0; i<48; i++) {
t61057.Draw(“detadc[][Form(”%d",i)]>>h1",“Entry$<2500”,"");

h1->Reset();
}

and various versions of with “Form”, but that did not work ;:sunglasses:
I am sure that solution is simple …

The Form() method is for TStrings, you don’t put them inside the “” quotes. Try to construct the command using TString::Form/Format and then feed that TString to TTree::Draw.

Here’s an example from my (working) code:

  // The various parameters are defined elsewhere.
  TString plotcommand = TString::Format("%s:(x-%f)*TMath::Cos(%f)",y_expr.Data(),x1,a);
  TString cutcommand = TString::Format("w==%i && a == %f && e == 1",i,a);

  tn.Draw(plotcommand,cutcommand,"goff"); // tn is a TNtuple, similar to a TTree