Commit 4f1c14a2 authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

Fitting function works

parent 99eced95
void gain_measurement()
{
ifstream file_255;
file_255.open("255_255.dat");
cout<<"The data file 255_255 is opened..."<<std::endl;
TCanvas *c1 = new TCanvas();
TTree *tree = new TTree("tree", "tree");
TH1D *hist_255 = new TH1D("hist_255"," Threshold gain measurement",100,900,1300);
TH1D *hist_255 = new TH1D("hist_255"," Threshold gain measurement",500,850,1750);
tree->ReadFile("255_255.dat", "x/D:y/D");
tree->SetEstimate(-1);//Set the #entries to estimate variable limits. n=-1, estimate is set to current maximum of the tree.
tree->Draw("x>>hist_255","y","HIST");
hist_255->SetMarkerStyle(3);
tree->Draw("x>>hist_255","y","HIST P");
hist_255->GetXaxis()->SetTitle("Threshold");
hist_255->GetYaxis()->SetTitle("# signals above the threshold");
//fitting the histogram with modified error function
TF1 *modified_erf = new TF1("modified_erf","[0]*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))",1000,1250);//Not sure how to give the fit range
modified_erf->SetParameter(0,100);
modified_erf->SetParameter(1,1115);
modified_erf->SetParameter(2,0);//Not sure how to give the initial value
TF1 *modified_erf = new TF1("modified_erf","([0]/2)*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))",1220,1700);
modified_erf->SetParNames("constant","mean","noise");
hist_255->Fit("modified_erf");
hist_255->Draw();
//file_255.close();
modified_erf->SetParNames("constant","mean","noise");
modified_erf->SetParameter(1,hist_255->GetMean());
modified_erf->SetParameter(2,hist_255->GetRMS());
modified_erf->SetParLimits(0,200,250.0);
modified_erf->SetLineWidth(2);
modified_erf->SetLineColor(2);
hist_255->Fit("modified_erf","R");
hist_255->GetListOfFunctions()->FindObject("modified_erf")->Draw("same");
cout<<"Code succesfull..."<<std::endl;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment