Commit 0d8f36d7 authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

User defined functions incorporated to plot and fit the histograms for low,...

User defined functions incorporated to plot and fit the histograms for low, mid and high amplitude cases.
parent a1523825
void gain_measurement()
{
TCanvas *c1 = new TCanvas();
TTree *tree = new TTree("tree", "tree");
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.
/////////////////////////////////////////////////////////////
// The function fit_1d sets the cosmetics for the histograms/
// and fits the histogram with modified erf function. /
/////////////////////////////////////////////////////////////
hist_255->SetMarkerStyle(3);
tree->Draw("x>>hist_255","y","HIST P");
TH1D *fit_1d(TH1D *hist_255, int i,int j, double low_limit, double up_limit)
{
hist_255->GetXaxis()->SetTitle("Threshold");
hist_255->GetYaxis()->SetTitle("# signals above the threshold");
hist_255->SetMarkerStyle(i+1);
hist_255->SetMarkerColor(i+2);
//fitting the histogram with modified error function
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");
TF1 *fitfunc = new TF1("fitfunc","([0]/2)*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))",low_limit,up_limit);
// Seeting the initial values for the fit parameters
cout<<"The fit parameters for the amplitude amp_0"<<j<<""<<" are as follows :"<<std::endl;
fitfunc->SetParNames("constant","mean","noise");
//Assigning Initial values to the parameters
modified_erf->SetParameter(0,200.0);
fitfunc->SetParameter(0,200.0);
double lastbin1 = hist_255->FindLastBinAbove(200);
double mean = hist_255->GetBinCenter(lastbin1);
cout<<"The initial mean value assigned is : "<<mean<<std::endl;
modified_erf->SetParameter(1,mean);
cout<<"The initial mean value assigned for the data of amp_0 "<<j<<""<<" is "<<""<<mean<<std::endl;
fitfunc->SetParameter(1,mean);
double lastbin2 = hist_255->FindLastBinAbove(150);
double lastbin3 = hist_255->FindLastBinAbove(50);
double sigma = lastbin3 -lastbin2;
cout<<"The initial noise assigned is :"<<sigma<<std::endl;
modified_erf->SetParameter(2,sigma);
cout<<"The initial noise assigned for the data of amp_0 "<<j<<""<<" is "<<""<<sigma<<std::endl;
fitfunc->SetParameter(2,sigma);
//Fitting histogram
modified_erf->SetLineWidth(2);
modified_erf->SetLineColor(2);
fitfunc->SetLineWidth(2);
fitfunc->SetLineColor(2);
hist_255->Fit("fitfunc"," R");
hist_255->GetListOfFunctions()->FindObject("fitfunc")->Draw("same");
hist_255->SetStats(0);
return hist_255;
}
void gain_measurement()
{
//Initialising the histograms.
hist_255->Fit("modified_erf","R");
hist_255->GetListOfFunctions()->FindObject("modified_erf")->Draw("same");
TH1D *hist_255_amp03 = new TH1D("hist_255_amp03"," Threshold gain measurement",500,850,1750);
TH1D *hist_255_amp02 = new TH1D("hist_255_amp02"," Threshold gain measurement",500,850,1750);
TH1D *hist_255_amp01 = new TH1D("hist_255_amp01"," Threshold gain measurement",500,850,1750);
//Initialising the trees.
TTree *tree1 = new TTree("tree1", "tree1");
TTree *tree2 = new TTree("tree2", "tree2");
TTree *tree3 = new TTree("tree3", "tree3");
tree1->ReadFile("amp03_255_255.dat", "x/D:y/D");
tree2->ReadFile("amp02_255_255.dat", "x/D:y/D");
tree3->ReadFile("amp01_255_255.dat", "x/D:y/D");
cout<<"Code succesfull..."<<std::endl;
}
tree1->Draw("x>>hist_255_amp03","y","HIST P ");
tree2->Draw("x>>hist_255_amp02","y","HIST SAMES P ");
tree3->Draw("x>>hist_255_amp01","y","HIST SAMES P ");
fit_1d(hist_255_amp03,1,3,1220.0,1700.0);
fit_1d(hist_255_amp02,2,2,1200.0,1420.0);
fit_1d(hist_255_amp01,3,1,1150.0,1240.0);
//Drawing the legend
TLegend *leg = new TLegend(0.7,0.7,0.9,0.9);
leg->AddEntry(hist_255_amp03, "high amplitude","p");
leg->AddEntry(hist_255_amp02,"mid amplitude","p");
leg->AddEntry(hist_255_amp01,"low amplitude","p");
leg->Draw();
cout<<"Done...";
}
Supports Markdown
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