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

Code extended for all the pixels. Problem in saving the fit parameters. Col...

Code extended for all the pixels. Problem in saving the fit parameters. Col and Row always printing 255 255
parent a84c19aa
......@@ -29,7 +29,7 @@ void TreeEnergyWrite(){
void TreeTPWrite(){
int energy, col, row, pc;
double voltage,tot, tot_var, toa, toa_var, time_ref;
double voltage,tot, tot_var, toa, toa_var, time_ref,toa_cut,mean,RMS;
string line_TP;
TFile* Efile = new TFile("Energy_table.root");
......@@ -49,7 +49,7 @@ void TreeTPWrite(){
TPtree->Branch("toa_var",&toa_var,"toa_var/D");
TPtree->Branch("time_ref",&time_ref,"time_ref/D");
auto voltageBranch = TPtree->Branch("voltage",&voltage,"voltage/D");// make a new branch and connect it to the same variable as the branch address of the energy tree
auto Branch_toacut = TPtree->Branch("toa_cut",&toa_cut,"toa_cut/D");
for(int i = 0; i < ETree->GetEntries(); i++){
ETree->GetEntry(i);
......@@ -74,23 +74,106 @@ void TreeTPWrite(){
istringstream ssTP(line_TP);
ssTP >> col >> row >> pc >> tot >> tot_var >> toa >> toa_var >> time_ref;
// std:: cout << col << " " << row << " " << pulsecount << " " << toa << " " << toa_var << std::endl;
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());
// std::cout <<" mean " << mean << " RMS " << RMS <<std::endl;
/* for (int isigma=0; isigma < 15; isigma++){
std::cout << " cut at " << isigma << " times the RMS leaves : "
<< 100.0*TPtree->GetEntries(Form("toa<(%f) && voltage==(%f)",mean+isigma*RMS,voltage))/TPtree->GetEntries(Form("voltage==(%f)",voltage))
<< " percentage of entries " << std::endl;
}*/
toa_cut = mean + 6*RMS;
Branch_toacut->Fill();
}//For loop GetEntries
//Save only the new version of the tree
TPtree->Write("",TObject::kOverwrite);
long N = TPtree->Draw("voltage:toa:sqrt(toa_var) ", "row==1 && col==10 && toa>0", "goff");
TGraphErrors *gr = new TGraphErrors(N,TPtree->GetV1(),TPtree->GetV2(),0,TPtree->GetV3());
gr->GetXaxis()->SetTitle("Volatge[mV]");
gr->GetYaxis()->SetTitle ("time difference[ns]");
gr->SetTitle(" ");
gr->SetMarkerStyle(7);
gr->Draw("AP");
TPfile->Close();
}
void timewalkfit(){
// gROOT->Reset();
int col, row, pc ;
double tot, tot_var, toa, toa_var;
TFile* TPfile = new TFile("TP.root");
TTree* TPtree = (TTree*)TPfile->Get("TPtree");
TPtree->SetBranchAddress("col",&col);
TPtree->SetBranchAddress("row",&row);
TPtree->SetBranchAddress("pc",&pc);
TPtree->SetBranchAddress("tot",&tot);
TPtree->SetBranchAddress("tot_var",&tot_var);
TPtree->SetBranchAddress("toa",&toa);
TPtree->SetBranchAddress("toa_var",&toa_var);
for(int i = 0; i < TPtree->GetEntries(); i++){
TPtree->GetEntry(i);
std::cout << col << " " << row << std::endl; //Correct values of col and row printed
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());
// std::cout << col << " " << row << std::endl; // Always printing 255 255
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;
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);
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");
/* 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!
}
TPfile->Close();
}
......@@ -98,4 +181,6 @@ void TreeTest(){
TreeEnergyWrite();
TreeTPWrite();
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