#include <cstdlib>
#include <iostream>
#include <time.h>

#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TH2.h"
#include "TH1.h"
#include "TF2.h"
#include "TF1.h"
#include "TMath.h"
#include "TRandom3.h"

using namespace std;

void howToRootTree()
{
TFile *hist_file = new TFile("tree.root","recreate");  

Double_t x1;
Double_t x2;
Double_t y1;
Double_t y2;

//here define the tree structure
TTree * myTree = new TTree ("myTree", "myTree");
myTree->Branch("x1",&x1);
myTree->Branch("y1",&y1);
myTree->Branch("x2",&x2);
myTree->Branch("y2",&y2);

//here define random number engine 
TRandom3 *rand = new TRandom3(time(NULL));
 
//here fiil the tree 
 for(Int_t i =0; i<1000 ; i++){
   x1= rand->Gaus(1.0,0.5);
   y1= rand->Gaus(1.0,0.5);
   x2= rand->Gaus(-1.0,0.5);
   y2= rand->Gaus(-1.0,0.5);
   myTree->Fill();
 }

//here store tree to the file
hist_file->Write();

}

