How to draw min/max value from ntuple variables?

Hi,

I’m quite a new ROOT user, trying to get to grips with it still, so sorry if this question is a bit basic.

I have an ntuple root file with x, y, t variables, with multiple values of t for specific x, y coordinates. I would like to draw this to a 3D graph where only the minimum value of t per coordinate is drawn, ignoring all other values of t.

Is there any way to do this? I’m not sure where to even start.

Thanks in advance!

Hi,

let’s divide the problem in steps:

  1. Reading a TTree
  2. Getting the maximum of a collection
  3. Plotting values in a 3D graphic

Now, ROOT can help you in each of the steps!

  1. See root.cern.ch/doc/master/hsimpleReader_8C.html and modify according to your needs.
  2. This one depends on how you stored the t values. In general, the STL library offers a way to get the min element of a collection en.cppreference.com/w/cpp/algorithm/min_element
  3. Here you find the ROOT implementation of a 3D graph: root.cern.ch/doc/master/graph2d … it_8C.html

Cheers,
Danilo

Thanks for the reply!

I stupidly failed to mention that I’m forced to run ROOT version 5 as I’m using a windows machine, which doesn’t have TTreeReader. Is there an equivalent for ver 5?

{

   Float_t x,y,t;
   TTree *T = new TTree("T","test tree");
   T->Branch("x",&x,"x/F");
   T->Branch("y",&y,"y/F");
   T->Branch("t",&t,"t/F");
   TRandom r;
   for (Int_t i=0;i<5000;i++) {
      x = r.Gaus(10,1);
      y = r.Gaus(20,2);
      if (i<100) t = -100;
      else t = r.Landau(2,1);
      T->Fill();
   }

   Int_t n = T->Draw("t","","goff");

   Double_t *vt = T->GetVal(0);
   Double_t min = 99999;
   for (int i=0; i<n;i++)  {if (vt[i] < min) min = vt[i];}
   T->SetMarkerStyle(20);
   T->Draw("x:y:t", Form("t==%f",min));
}