Commit 621efaf1 authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

FindLastBinAbove() assigned properly to an integer variable. Colours and...

FindLastBinAbove() assigned properly to an integer variable. Colours and marker styles for the histogram globally declared. The code still doesnt work properly..
parent 0d8f36d7
//Global parameters defined
/////////////////////////////////////////////////////////////
const int namplitudes = 3;
int nbins = 450;
double xmin=850.0,xmax = 1750.0;
TH1D *hist_255[namplitudes];
int colors[namplitudes]={kAzure,kRed,kViolet};
int markers[namplitudes]={2, 3, 5};
double fitmin[namplitudes]={1220.,1200.,1150.};
double fitmax[namplitudes]={1700.,1420.,1240.};
/////////////////////////////////////////////////////////////
// The function fit_1d sets the cosmetics for the histograms/
// and fits the histogram with modified erf function. /
/////////////////////////////////////////////////////////////
TH1D *fit_1d(TH1D *hist_255, int i,int j, double low_limit, double up_limit)
//TH1D *fit_1d(TH1D *hist_255, int i,int j, double low_limit, double up_limit)
TH1D *fit_1d(TH1D *hist_255[namplitudes],int colors[namplitudes],int markers[namplitudes],int amp, double fitmin[namplitudes],double fitmax[namplitudes])
{
hist_255->GetXaxis()->SetTitle("Threshold");
hist_255->GetYaxis()->SetTitle("# signals above the threshold");
hist_255->SetMarkerStyle(i+1);
hist_255->SetMarkerColor(i+2);
hist_255[namplitudes]->GetXaxis()->SetTitle("Threshold");
hist_255[namplitudes]->GetYaxis()->SetTitle("#signals above the threshold");
hist_255[namplitudes]->SetMarkerColor(namplitudes);
hist_255[namplitudes]->SetMarkerStyle(namplitudes);
// hist_255->SetMarkerStyle(i+1);
// hist_255->SetMarkerColor(i+2);
TF1 *fitfunc = new TF1("fitfunc","([0]/2)*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))",low_limit,up_limit);
TF1 *fitfunc = new TF1("fitfunc","([0]/2)*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))",fitmin[namplitudes], fitmax[namplitudes]);
cout<<"The fit parameters for the amplitude amp_0"<<j<<""<<" are as follows :"<<std::endl;
cout<<"The fit parameters for the amplitude amp_0"<<amp<<""<<" are as follows :"<<std::endl;
fitfunc->SetParNames("constant","mean","noise");
//Assigning Initial values to the parameters
fitfunc->SetParameter(0,200.0);
double lastbin1 = hist_255->FindLastBinAbove(200);
double mean = hist_255->GetBinCenter(lastbin1);
cout<<"The initial mean value assigned for the data of amp_0 "<<j<<""<<" is "<<""<<mean<<std::endl;
int lastbin1 = hist_255[namplitudes]->FindLastBinAbove(200);
double mean = hist_255[namplitudes]->GetBinCenter(lastbin1);
cout<<"The initial mean value assigned for the data of amp_0 "<<amp<<""<<" 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 for the data of amp_0 "<<j<<""<<" is "<<""<<sigma<<std::endl;
int lastbin2 = hist_255[namplitudes]->FindLastBinAbove(150);
int lastbin3 = hist_255[namplitudes]->FindLastBinAbove(50);
int sigma = lastbin3 -lastbin2;
cout<<"The initial noise assigned for the data of amp_0 "<<amp<<""<<" is "<<""<<sigma<<std::endl;
fitfunc->SetParameter(2,sigma);
fitfunc->SetLineWidth(2);
fitfunc->SetLineColor(2);
hist_255->Fit("fitfunc"," R");
hist_255->GetListOfFunctions()->FindObject("fitfunc")->Draw("same");
hist_255[namplitudes]->Fit("fitfunc"," R");
hist_255[namplitudes]->GetListOfFunctions()->FindObject("fitfunc")->Draw("same");
hist_255->SetStats(0);
return hist_255;
hist_255[namplitudes]->SetStats(0);
return hist_255[namplitudes];
}
......@@ -46,37 +72,55 @@ void gain_measurement()
{
//Initialising the histograms.
TH1D *hist_255_amp03 = new TH1D("hist_255_amp03"," Threshold gain measurement",500,850,1750);
hist_255[0] = new TH1D("hist_255_amp03","Threshold gain measurement",nbins, xmin, xmax);
hist_255[1] = new TH1D("hist_255_amp02","Threshold gain measurement",nbins, xmin, xmax);
hist_255[2] = new TH1D("hist_255_amp01","Threshold gain measurement",nbins, xmin, xmax);
cout<<"THe histograms initialised..."<<std::endl;
/*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);
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");
cout<<"The trees are initialised..."<<std::endl;
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<<"The data is stored into the trees from the file..."<<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 ");
tree1->Draw("x>>hist_255[0]","y","HIST P ");
tree2->Draw("x>>hist_255[1]","y","HIST SAME P ");
tree3->Draw("x>>hist_255[2]","y","HIST SAME P ");
cout<<"The histograms are plotted.."<<std::endl;
for (int iamp=0; iamp<3;iamp++)
{
fit_1d(&hist_255[iamp],&colors[iamp],&markers[iamp],iamp, &fitmin[iamp], &fitmax[iamp]);
}
cout<<"The fiiting function is called three times..."<<std::endl;
fit_1d(hist_255_amp03,1,3,1220.0,1700.0);
/* 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);
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->AddEntry(hist_255[0], "high amplitude","p");
leg->AddEntry(hist_255[1],"mid amplitude","p");
leg->AddEntry(hist_255[2],"low amplitude","p");
leg->Draw();
cout<<"The legend is drawn.."<<std::endl;
cout<<"Done...";
}
......
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