tree.Draw with an index


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

I execute sucessfully


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

for (int i=0; i<48; i++) {


I tried to use something like

for (int i=0; i<48; i++) {


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