Commit ba1d9068 authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

Looping over irow and icol and not TTree for fitting and plotting, Correct...

Looping over irow and icol and not TTree for fitting and plotting, Correct values are coutted, but still print s255,255 for col, row in the fitparametrs.txt file
parent 326c4040
......@@ -121,57 +121,58 @@ void timewalkfit(){
TPtree->SetBranchAddress("toa_var",&toa_var);
for(int i = 0; i < TPtree->GetEntries(); i++){
for(int icol = 0; icol < 256; icol++){
for (int irow = 0; irow <256; irow++){
TPtree->GetEntry(i);
std::cout << col << " " << row << std::endl; //Correct values of col and row printed
std::cout <<icol << " " << irow << std::endl;
auto N = TPtree->Draw("voltage:toa:sqrt(toa_var)",Form("col==(%i) && row==(%i) && toa>0 && toa<toa_cut", col, row),"goff");
// cout << N <<std::endl;
TGraphErrors *graph = new TGraphErrors(N,TPtree->GetV1(),TPtree->GetV2(),0,TPtree->GetV3());
auto N = TPtree->Draw("voltage:toa:sqrt(toa_var)",Form("col==(%i) && row==(%i) && toa>0 && toa<toa_cut", icol, irow),"goff");
// cout << N <<std::endl;
TGraphErrors *graph = new TGraphErrors(N,TPtree->GetV1(),TPtree->GetV2(),0,TPtree->GetV3());
// std::cout << col << " " << row << std::endl; // Always printing 255 255
std::cout << icol << " " << irow << std::endl; //Correct values printed here..but text file still prints 255_255
auto fitmin = TMath::MinElement(graph->GetN(),graph->GetX());
// std::cout << "fitmin" << fitmin << std::endl;
auto fitmin = TMath::MinElement(graph->GetN(),graph->GetX());
// std::cout << "fitmin" << fitmin << std::endl;
auto fitmax = TMath::MaxElement(graph->GetN(),graph->GetX());
// std::cout << "fitmax " << fitmax << std::endl;
auto fitmax = TMath::MaxElement(graph->GetN(),graph->GetX());
// std::cout << "fitmax " << fitmax << std::endl;
TF1 *fitfuncTOA = new TF1("fitfuncTOA","(([2]/(x-[0]))+ [1])",fitmin,fitmax);
fitfuncTOA->SetParNames("asymtote","offset","curvature");
TF1 *fitfuncTOA = new TF1("fitfuncTOA","(([2]/(x-[0]))+ [1])",fitmin,fitmax);
fitfuncTOA->SetParNames("asymtote","offset","curvature");
int iymax=TMath::LocMax(graph->GetN(),graph->GetY());
// cout << "iymax " << iymax << std::endl;
auto ttoa = graph->GetPointX(iymax);
// cout << "ttoa" << " " << ttoa << std::endl;;
fitfuncTOA->SetParameter(0,ttoa);
int iymax=TMath::LocMax(graph->GetN(),graph->GetY());
// cout << "iymax " << iymax << std::endl;
auto ttoa = graph->GetPointX(iymax);
// cout << "ttoa" << " " << ttoa << std::endl;;
fitfuncTOA->SetParameter(0,ttoa);
auto xmax = TMath::MaxElement(graph->GetN(),graph->GetX());
auto dtoa = graph->Eval(xmax);
// cout << "dtoa" << " " << dtoa <<std::endl;
fitfuncTOA->SetParameter(1,dtoa);
auto xmax = TMath::MaxElement(graph->GetN(),graph->GetX());
auto dtoa = graph->Eval(xmax);
// cout << "dtoa" << " " << dtoa <<std::endl;
fitfuncTOA->SetParameter(1,dtoa);
auto testx = 0.5*fitmax;
auto ctoa_y = graph->Eval(testx);
auto ctoa = (ctoa_y - dtoa)*(testx - ttoa);
// cout << "ctoa" << " " << ctoa <<std::endl;
fitfuncTOA->SetParameter(2,ctoa);
// gStyle->SetOptFit(1111);
// fitfuncTOA->SetLineColor(kRed);
graph->Fit(fitfuncTOA,"R");
/* graph->GetXaxis()->SetTitle("Volatge[mV]");
graph->GetYaxis()->SetTitle ("time difference[ns]");
graph->SetTitle(" ");
graph->SetMarkerStyle(7);*/
// graph->Draw("AP");
auto testx = 0.5*fitmax;
auto ctoa_y = graph->Eval(testx);
auto ctoa = (ctoa_y - dtoa)*(testx - ttoa);
// cout << "ctoa" << " " << ctoa <<std::endl;
fitfuncTOA->SetParameter(2,ctoa);
// gStyle->SetOptFit(1111);
// fitfuncTOA->SetLineColor(kRed);
graph->Fit(fitfuncTOA,"R");
/* graph->GetXaxis()->SetTitle("Volatge[mV]");
graph->GetYaxis()->SetTitle ("time difference[ns]");
graph->SetTitle(" ");
graph->SetMarkerStyle(7);*/
// graph->Draw("AP");
/* std::ofstream fitpars;
fitpars.open("fit_parameters.txt",std::ofstream::app);
fitpars << col << "\t" << row << "\t" << fitfuncTOA->GetParameter(2)
<< setw(10) << fitfuncTOA->GetParameter(0) << setw(10) << fitfuncTOA->GetParameter(1) << std::endl;*/ //NO chi2/ndf for the time-being!
std::ofstream fitpars;
fitpars.open("fit_parameters.txt",std::ofstream::app);
fitpars << col << "\t" << row << "\t" << fitfuncTOA->GetParameter(2)
<< setw(10) << fitfuncTOA->GetParameter(0) << setw(10) << fitfuncTOA->GetParameter(1) << std::endl; //NO chi2/ndf for the time-being! Prints always 255 255 for col,row
}
}
TPfile->Close();
......
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