Commit 1e1edc7f authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

Dead pixels and pixels removed from fitting!

parent bb1c36b3
......@@ -31,6 +31,8 @@ void TreeTPWrite(){
int energy, col, row, pc;
double voltage,tot, tot_var, toa, toa_var, time_ref,toa_cut,mean,RMS;
string line_TP;
std::ofstream skippixels;
skippixels.open("skip_pixels.txt",std::ofstream::app);
TFile* Efile = new TFile("Energy_table.root");
TTree* ETree = (TTree*)Efile->Get("ETree");
......@@ -74,10 +76,12 @@ void TreeTPWrite(){
istringstream ssTP(line_TP);
ssTP >> col >> row >> pc >> tot >> tot_var >> toa >> toa_var >> time_ref;
TPtree->Fill();
} //While loop getline
}//if statement TPdatafile open
TPtree->Draw("toa",Form("voltage==(%f)",voltage),"goff");
mean = TMath::Mean(TPtree->GetSelectedRows(), TPtree->GetV1());
RMS = TMath::RMS(TPtree->GetSelectedRows(), TPtree->GetV1());
......@@ -101,14 +105,10 @@ void TreeTPWrite(){
TPfile->Close();
}
void timewalkfit(){
// gROOT->Reset();
int col, row, pc ;
double tot, tot_var, toa, toa_var;
double tot, tot_var, toa, toa_var,voltage;
TFile* TPfile = new TFile("TP.root");
TTree* TPtree = (TTree*)TPfile->Get("TPtree");
......@@ -120,58 +120,71 @@ void timewalkfit(){
TPtree->SetBranchAddress("toa",&toa);
TPtree->SetBranchAddress("toa_var",&toa_var);
TPtree->SetBranchAddress("voltage",&voltage);
for(int icol = 0; icol < 256; icol++){
for (int irow = 0; irow <256; irow++){
for(int icol = 19; icol < 256; icol++){
for (int irow = 86; irow <256; irow++){
std::cout <<icol << " " << irow << std::endl;
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", icol, irow),"goff");
// cout << N <<std::endl;
TGraphErrors *graph = new TGraphErrors(N,TPtree->GetV1(),TPtree->GetV2(),0,TPtree->GetV3());
// std::cout << icol << " " << irow << std::endl; //Correct values printed here..but text file still prints 255_255
if(N==0)
{
std::cout << "Dead pixel or no enough points for fitting. Skipping pixel " << icol << "_" << irow << std::endl;
std::ofstream skippixels;
skippixels.open("skip_pixels.txt",std::ofstream::app);
skippixels << "Skipping the pixel " << icol << "_" << irow <<std::endl;
}
else{
TGraphErrors *graph = new TGraphErrors(N,TPtree->GetV1(),TPtree->GetV2(),0,TPtree->GetV3());
// 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 << icol << "\t" << irow << "\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 << icol << "\t" << irow << "\t" << fitfuncTOA->GetParameter(2)
<< setw(10) << fitfuncTOA->GetParameter(0) << setw(10) << fitfuncTOA->GetParameter(1) << std::endl; //NO chi2/ndf for the time-being!
}
}
}
......@@ -185,3 +198,6 @@ void TreeTest(){
timewalkfit();
}
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