/* Name of the programmer: Diksha Garg Date: 16 May, 2017 Comment: This program loads a root file and then fits 2 gaus functions(pre-defined) to the trkmm parameter of the root file. */ { TFile func("test_10GeV_reco.root"); /*loading root file */ TH1F *h= new TH1F("h","trkmm gaussian fit",50,4,16); /*creating empty histogram */ /* projecting the values of trkmm present in root file on the empty histogram,h */ T1-> Project ("h","abs(trkmm[0])","abs(trkmm[0])> 4 && abs(trkmm[0])<16"); /* creating gaussian curves */ g1= new TF1 ("m1","gaus",4,9); g2= new TF1 ("m2","gaus",8,14); // g3= new TF1 ("m3","gaus",12,17); TF1 *f1= new TF1("double_gaus","gaus(0)+gaus(3)",4,16); /* define combined function*/ /* Fitting each gaus fn and adding them to the existing list of functions */ /* the + sign adds the newly fitted fn to the existing fn. */ h-> Fit (g1,"R"); h-> Fit (g2,"R+"); // h-> Fit (g3,"R+"); Double_t par[9]; /* parameter array */ /* get parameters from the fit, it first fits & takes the parameter from there */ g1-> GetParameters (&par[0]); g2-> GetParameters (&par[3]); // g3-> GetParameters (&par[6]); /* use the parameters on the combined function */ double_gaus-> SetParameters (par); h->Fit("double_gaus","+","",4,16); /*fitting gaussian curve on the histogram */ h->Draw("e1"); gStyle->SetOptFit(1); // To print the parameters on the canvas } /* Refer: https://root.cern.ch/root/html534/guides/users-guide/FittingHistograms.html */