Commit 43bfa9d0 authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

code with huge error list

parent b88e9eec
//Global parameters defined
/*defining global variables*/
const int namplitudes = 3;
int nbins = 450;
double xmin=850.0,xmax = 1750.0;
TH1D *hist_255[namplitudes];
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);
int colors[namplitudes]={kAzure,kRed,kViolet};
int markers[namplitudes]={2, 3, 5};
double fitmin[namplitudes]={1220.,1200.,1150.};
double fitmax[namplitudes]={1700.,1420.,1240.};
std::vector<TH1D*>hist_255;
std::vector<int>colors={kAzure,kRed,kViolet};
std::vector<int>markers={2,3,5};
std::vector<double>fitmin={1220.,1200.,1150.};
std::vector<double>fitmax={1700.,1420.,1240.};
......@@ -33,105 +17,84 @@ double fitmax[namplitudes]={1700.,1420.,1240.};
// 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[namplitudes],int colors[namplitudes],int markers[namplitudes],int amp, double fitmin[namplitudes],double fitmax[namplitudes])
TH1D *fit_1d(TH1D* &hist_255.at(amp),int &colors.at(amp),int &markers.at(amp),int amplitude,double &fitmin.at(amp),double &fitmax.at(amp))
{
hist_255.at(amp)->GetXaxis()->SetTitle("Threshold");
hist_255.at(amp)->GetYaxis()->SetTitle("# sugnals above the threshold");
hist_255.at(amp)->SetMarkerColor(colors.at(amp));
hist_255.at(amp)->SetMarkerStyle(markers.at(amp));
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])))",fitmin.at(amp),fitmax.at(amp));
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"<<amplitude<<""<<" are as follows :"<<std::endl;
cout<<"The fit parameters for the amplitude amp_0"<<amp<<""<<" are as follows :"<<std::endl;
/*Setting parameter names*/
fitfunc->SetParNames("constant","mean","noise");
//Assigning Initial values to the parameters
fitfunc->SetParameter(0,200.0);
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;
int lastbin1 = hist_255.at(amp)->FindLastBinAbove(200);
double mean = hist_255.at(amp)->GetBinCenter(lastbin1);
cout<<"The initial mean value assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<mean<<std::endl;
fitfunc->SetParameter(1,mean);
int lastbin2 = hist_255[namplitudes]->FindLastBinAbove(150);
int lastbin3 = hist_255[namplitudes]->FindLastBinAbove(50);
int lastbin2 = hist_255.at(amp)->FindLastBinAbove(150);
int lastbin3 = hist_255.at(amp)->FindLastBinAbove(50);
int sigma = lastbin3 -lastbin2;
cout<<"The initial noise assigned for the data of amp_0 "<<amp<<""<<" is "<<""<<sigma<<std::endl;
cout<<"The initial noise assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<sigma<<std::endl;
fitfunc->SetParameter(2,sigma);
fitfunc->SetLineWidth(2);
fitfunc->SetLineColor(2);
hist_255[namplitudes]->Fit("fitfunc"," R");
hist_255[namplitudes]->GetListOfFunctions()->FindObject("fitfunc")->Draw("same");
hist_255.at(amp)->Fit("fitfunc"," R");
hist_255.at(amp)->GetListOfFunctions()->FindObject("fitfunc")->Draw("same");
hist_255[namplitudes]->SetStats(0);
return hist_255[namplitudes];
hist_255.at(amp)->SetStats(0);
return hist_255.at(amp);
}
void gain_measurement()
{
//Initialising the trees.
void gain_6()
{
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;
cout<<"The trees are created..."<<std::endl;
/*Reading data from the files are storing into trees*/
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[0]","y","HIST P ");
tree2->Draw("x>>hist_255[1]","y","HIST SAME P ");
tree3->Draw("x>>hist_255[2]","y","HIST SAME P ");
TH1D *hist1 = hist_255.at(0);
TH1D *hist2 = hist_255.at(1);
TH1D *hist3 = hist_255.at(2);
tree1->Draw("x>>hist1","y","HIST P ");
tree2->Draw("x>>hist2","y","HIST SAME P ");
tree3->Draw("x>>hist3","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]);
hist_255.push_back(hist1);
hist_255.push_back(hist2);
hist_255.push_back(hist3);
for(int iamp=0;iamp<3;iamp++)
{
fit_1d(hist_255.at(iamp),colors.at(iamp),markers.at(iamp),fitmin.at(iamp),fitmax.at(iamp));
}
cout<<"The fiiting function is called three times..."<<std::endl;
//Drawing the legend
TLegend *leg = new TLegend(0.7,0.7,0.9,0.9);
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...";
cout<<"Done..."<<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