How can I rebin a Tree?

Hi
I have a problem.
I write a simple tree like this :

void tree1w()
{
   //create a Tree file tree1.root
   
   //create the file, the Tree and a few branches
   TFile f("tree1.root","recreate");
   TTree t1("t1","a simple Tree with simple variables");
   Float_t px, py, pz;
   Double_t random;
   Int_t ev;
   t1.Branch("px",&px,"px/F");
   t1.Branch("py",&py,"py/F");
   t1.Branch("pz",&pz,"pz/F");
   t1.Branch("random",&random,"random/D");
   t1.Branch("ev",&ev,"ev/I");
   
   //fill the tree
   for (Int_t i=0;i<10000;i++) {
     gRandom->Rannor(px,py);
     pz = px*px + py*py;
     random = gRandom->Rndm();
     ev = i;
     t1.Fill();
  }
  
  //save the Tree header. The file will be automatically closed
  //when going out of the function scope
  t1.Write();
}

I would like to bin each leaf px, py, pz not with a standard number of bins of 100 but with another number.
How can I do?
thanks in advance

TTree leaves have NO bins (and your “t1” keeps single-precision floating-point values “px”, “py”, “pz”, i.e. about 7 decimal digits precision).
What is your problem then?
Histograms DO have bins.
Maybe you try to:
t1->Draw("px");
and then you see a histogram with 100 bins drawn?
If that’s your problem, then … search for “>>” and/or “binning” in TTree::Draw … and try something like:
t1->Draw("px>>htemp(1000)");

1 Like

oh thanks!
I didn’t control that in the leaf (es. tree.Scan("px")) is stored the whole double number; it’s only a problem to draw it into the right histogram