TTree::GetVal and Vector in Branch

Hello,

I have been trying to modify the treegetval.C from ROOT tutorial. I would like to retrieve a vector using TTree::Draw(). I am not sure whether this is possible, but could you help me with that ?

NB: I have been trying to use RDataFrame, but my tree is not stored into a file.

void treegetval() {

   Int_t run, evt;

   Float_t x;
   std::vector<Float_t> y(10);

   TTree *T = new TTree("T","test friend trees");
   T->Branch("Run",&run,"Run/I");
   T->Branch("Event",&evt,"Event/I");
   T->Branch("x",&x,"x/F");
   T->Branch("y",&y,"y[10]/F");

   TRandom r;
   for (Int_t i=0;i<10000;i++) {
      if (i < 5000) run = 1;
      else          run = 2;
      evt = i;

      x = r.Gaus(10,1);
      for(int j=0;j<10;j++)
                y[j] = j+1;

      T->Fill();
   }

   // Draw with option goff and generate seven variables
   T->SetMakeClass(0);

   Int_t n = T->Draw("x:y","Run==1","goff");

   printf("The arrays' dimension is %d\n",n);

   Double_t *vx = T->GetVal(0);
   Double_t *vy = T->GetVal(1);

   std::cout << "x[0]:" << vx[0] << std::endl;
   std::cout << "y[0]:" << vy[0] << std::endl;

   std::vector<Double_t> arr(vy, vy + 10);
   for(int j=0;j<10;j++)
        std::cout << arr[j] << std::endl;
}

Cheers, M.

This example allows you to retrieve, in arrays, the tree variables you pass to TTree::Draw. It is not meant to retrieve an array part of the tree. @pcanal may help you with that.

I eventually looped over my tree and used TFormula and defined some parameters…
Handling vector with Tree::Draw()/TTree::GetVal() is… too painful ^^

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.