Commit 216fd1d5 authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

Noise measurements added and fitted with gaussian function.

parent afd22227
double xmin=850.0,xmax = 1750.0,nbins=450.0; double xmin=850.0,xmax = 1750.0,nbins=450.0;
/////////////////////////////////////////////////////////////
// The function fit_1d sets the cosmetics for the histograms/
// and fits the histogram with modified erf function. /
/////////////////////////////////////////////////////////////
void fit_1d(TH1D* hist_255,int colors,int markers,int amplitude,double fitmin,double fitmax) void fit_gaussian_noise(TH1D* hist_255,int colors,int markers,int amplitude,double fitmin,double fitmax)
{
hist_255->SetMarkerColor(colors);
hist_255->SetMarkerStyle(markers);
TF1 *fitgauss = new TF1("fitgauss","([0]*exp(-0.5*((x-[1])/[2])^2))",fitmin,fitmax);
// cout<<"The fit parameters for the amplitude amp_0"<<amplitude<<""<<" are as follows :"<<std::endl;
//Setting parameter names
fitgauss->SetParNames("constant","mean","noise");
//Assigning Initial values to the parameters
fitgauss->SetParameter(0,200.0);
int lastbin1 = hist_255->FindLastBinAbove(200);
double mean = hist_255->GetBinCenter(lastbin1);
// cout<<"The initial mean value assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<mean<<std::endl;
fitgauss->SetParameter(1,mean);
int lastbin2 = hist_255->FindLastBinAbove(150);
int lastbin3 = hist_255->FindLastBinAbove(50);
int sigma = lastbin3 -lastbin2;
// cout<<"The initial noise assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<sigma<<std::endl;
fitgauss->SetParameter(2,sigma);
fitgauss->SetLineWidth(2);
fitgauss->SetLineColor(2);
hist_255->Fit("fitgauss"," R");
hist_255->GetListOfFunctions()->FindObject("fitgauss")->Draw("same");
hist_255->SetStats(0);
}
void fit_modified_erf(TH1D* hist_255,int colors,int markers,int amplitude,double fitmin,double fitmax)
{ {
// hist_255->GetXaxis()->SetTitle("Threshold"); // hist_255->GetXaxis()->SetTitle("Threshold");
// hist_255->GetYaxis()->SetTitle("# signals above the threshold"); // hist_255->GetYaxis()->SetTitle("# signals above the threshold");
...@@ -13,47 +43,43 @@ void fit_1d(TH1D* hist_255,int colors,int markers,int amplitude,double fitmin,do ...@@ -13,47 +43,43 @@ void fit_1d(TH1D* hist_255,int colors,int markers,int amplitude,double fitmin,do
hist_255->SetMarkerStyle(markers); hist_255->SetMarkerStyle(markers);
TF1 *fitfunc = new TF1("fitfunc","([0]/2)*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))",fitmin,fitmax); TF1 *fiterf = new TF1("fiterf","([0]/2)*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))",fitmin,fitmax);
cout<<"The fit parameters for the amplitude amp_0"<<amplitude<<""<<" are as follows :"<<std::endl; // cout<<"The fit parameters for the amplitude amp_0"<<amplitude<<""<<" are as follows :"<<std::endl;
/*Setting parameter names*/ /*Setting parameter names*/
fitfunc->SetParNames("constant","mean","noise"); fiterf->SetParNames("constant","mean","noise");
//Assigning Initial values to the parameters //Assigning Initial values to the parameters
fitfunc->SetParameter(0,200.0); fiterf->SetParameter(0,200.0);
int lastbin1 = hist_255->FindLastBinAbove(200); int lastbin1 = hist_255->FindLastBinAbove(200);
double mean = hist_255->GetBinCenter(lastbin1); double mean = hist_255->GetBinCenter(lastbin1);
// cout<<"The initial mean value assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<mean<<std::endl; // cout<<"The initial mean value assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<mean<<std::endl;
fitfunc->SetParameter(1,mean); fiterf->SetParameter(1,mean);
int lastbin2 = hist_255->FindLastBinAbove(150); int lastbin2 = hist_255->FindLastBinAbove(150);
int lastbin3 = hist_255->FindLastBinAbove(50); int lastbin3 = hist_255->FindLastBinAbove(50);
int sigma = lastbin3 -lastbin2; int sigma = lastbin3 -lastbin2;
// cout<<"The initial noise assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<sigma<<std::endl; // cout<<"The initial noise assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<sigma<<std::endl;
fitfunc->SetParameter(2,sigma); fiterf->SetParameter(2,sigma);
fitfunc->SetLineWidth(2); fiterf->SetLineWidth(2);
fitfunc->SetLineColor(2); fiterf->SetLineColor(2);
hist_255->Fit("fitfunc"," R"); hist_255->Fit("fiterf"," R");
hist_255->GetListOfFunctions()->FindObject("fitfunc")->Draw("same"); hist_255->GetListOfFunctions()->FindObject("fiterf")->Draw("same");
hist_255->SetStats(0); hist_255->SetStats(0);
} }
std::vector<TH1D*> gain_measurement_pixel(int i, int j) std::vector<TH1D*> gain_measurement_pixel(int i, int j)
{ {
//double xmin=850.0,xmax = 1750.0; std::vector<int>colors={kAzure,kTeal+3,kViolet+3,kOrange+4};
std::vector<int>markers={1,1,1,1};
std::vector<int>colors={kAzure,kTeal+3,kViolet+3}; std::vector<double>fitmin ={1220.,1200.,1150.,1000.0};
std::vector<int>markers={1,1,1}; std::vector<double>fitmax={1700.,1420.,1240.,1500.0};
std::vector<double>fitmin ={1220.,1200.,1150.};
std::vector<double>fitmax={1700.,1420.,1240.};
std::vector<TH1D*> hist_255; std::vector<TH1D*> hist_255;
//The data files are named as following : 000_000.dat to 256_256.dat //The data files are named as following : 000_000.dat to 256_256.dat
...@@ -65,11 +91,12 @@ std::vector<TH1D*> gain_measurement_pixel(int i, int j) ...@@ -65,11 +91,12 @@ std::vector<TH1D*> gain_measurement_pixel(int i, int j)
std::vector<std::string> filenames = { std::vector<std::string> filenames = {
std::string("amp03/" + sfilename.str()), std::string("amp03/" + sfilename.str()),
std::string("amp02/" + sfilename.str()), std::string("amp02/" + sfilename.str()),
std::string("amp01/" + sfilename.str()) std::string("amp01/" + sfilename.str()),
std::string("amp00/" + sfilename.str())
}; };
for(int amp = 0; amp < 3; amp++) { for(int amp = 0; amp < 4; amp++) {
std::ifstream amplitude_file(filenames.at(amp).c_str()); std::ifstream amplitude_file(filenames.at(amp).c_str());
if(amplitude_file.is_open()) { if(amplitude_file.is_open()) {
...@@ -95,7 +122,12 @@ std::vector<TH1D*> gain_measurement_pixel(int i, int j) ...@@ -95,7 +122,12 @@ std::vector<TH1D*> gain_measurement_pixel(int i, int j)
} else { } else {
cout << "Error opening file. Exit." <<std::endl; cout << "Error opening file. Exit." <<std::endl;
} }
fit_1d(hist_255.at(amp),colors.at(amp),markers.at(amp),amp,fitmin.at(amp),fitmax.at(amp)); if(filenames.at(amp)==0||filenames.at(amp)==1||filenames.at(amp)==2){
fit_modified_erf(hist_255.at(amp),colors.at(amp),markers.at(amp),amp,fitmin.at(amp),fitmax.at(amp));
}
else{
fit_gaussian_noise(hist_255.at(amp),colors.at(amp),markers.at(amp),amp,fitmin.at(amp),fitmax.at(amp));
}
} }
return hist_255; return hist_255;
} }
...@@ -148,6 +180,11 @@ void gain_measurement() ...@@ -148,6 +180,11 @@ void gain_measurement()
if(pixel_histograms.at(2)){ if(pixel_histograms.at(2)){
leg->AddEntry(pixel_histograms.at(2),"low amplitude","p"); leg->AddEntry(pixel_histograms.at(2),"low amplitude","p");
} }
if(pixel_histograms.at(3)){
leg->AddEntry(pixel_histograms.at(3),"noise","p");
}
leg->Draw("SAME"); leg->Draw("SAME");
} }
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