//IMP:::This macro is for creating a histogram from data void normalized_roofit_test() { using namespace RooFit; //This is the method for unbinned fitting, for binned fitting histogram and rooDatahist are used. RooRealVar x("x", "x",3,3.2); RooDataSet* data = new RooDataSet("data", "data",RooArgSet(x)); // fit variable Float_t jpsimass,jpsif; // Read data file TFile* input=new TFile("jpsi.root"); TTree* t1 = (TTree*) input->Get("h1"); // no of entries in the datafile Int_t n_tot = (int)t1->GetEntries(); cout << " n_tot = " << n_tot << endl; t1->SetBranchAddress("jpsimass",&jpsimass); t1->SetBranchAddress("jpsif",&jpsif); // Import the data points for(int i=0; iGetEntry(i); if(jpsif ==1){ if(jpsimass >=2.9 && jpsimass <=3.3) { x.setVal(jpsimass); data->add(RooArgSet(x)); } } } //TFile *nf = new TFile("nn_jpsi.root", "RECREATE"); TH1F *h1 = (TH1F*)data->createHistogram("my hist",x); double scale = 1/h1->Integral(); h1->Scale(scale); h1->SetLineColor(kRed); h1->SetLineWidth(3); //nf->Write(); // nf->Close(); TCanvas *c1 = new TCanvas("c1","c1"); c1->cd(); h1->Draw(); }