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

single pixel eg fit of tot response. Fit parameters (c and t has very high errors)

parent 1e1edc7f
void tot_calib(TGraphErrors* graph){
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 start = 0.5*fitmax;
TF1* f1 = new TF1("f1", "([0]*x + [1])",start,fitmax);
f1->SetParNames("gain","offset");
graph->Fit(f1,"R");
auto a = f1->GetParameter(0);
auto b = f1->GetParameter(1);
cout << " a : " << a << std::endl;
cout << " b : " << b << std::endl;
TF1 *fitfuncTOT = new TF1("fitfuncTOT","([0]*x +[1] - ([3]/(x-[2])))",fitmin,fitmax);
fitfuncTOT->SetParNames("gain","offset","asymtote","curvature");
int iymin=TMath::LocMin(graph->GetN(),graph->GetY());
cout << "iymin " << iymin << std::endl;
auto t = graph->GetPointX(iymin);
cout << "t :" << " " << t << std::endl;;
auto testx = 0.5*fitmax;
auto ctot_y = graph->Eval(testx);
auto c = (a*testx + b - ctot_y)*(testx - t);
cout << "c :" << " " << c <<std::endl;
// cout << a << " " << b << " " << t << " " << c << std::endl;
fitfuncTOT->SetParameters(a,b,t,c);
graph->Fit(fitfuncTOT,"R");
gStyle->SetOptFit(1111);
fitfuncTOT->SetLineColor(kRed);
graph->GetXaxis()->SetTitle("Volatge[mV]");
graph->GetYaxis()->SetTitle ("Tot[LSB]");
graph->SetTitle(" ");
graph->SetMarkerStyle(7);
graph->Draw("AP");
}
void TreeEnergyWrite(){
int Ecol1;
double Ecol2,Ecol3,Ecol4;
string line_E;
TFile* Efile = new TFile("Energy_table.root","recreate");
TTree* ETree = new TTree("ETree","Energy tree");
ETree->Branch("Ecol1",&Ecol1,"Ecol1/I"); // ECol1 = Energy values = {200,300.....14000}
ETree->Branch("Ecol4",&Ecol4,"Ecol4/D"); // Voltage values
std::ifstream Energy_file("Energy_table.dat");
if(Energy_file.is_open()){
while(getline(Energy_file,line_E)){
istringstream ssE(line_E);
ssE >> Ecol1 >> Ecol2 >> Ecol3 >> Ecol4;
ETree->Fill();
}
}
ETree->Write();
Efile->Close();
}
void TreeTPWrite(){
int energy, col, row, pc;
double voltage,tot, tot_var, toa, toa_var, time_ref,toa_cut,mean,RMS;
string line_TP;
TFile* Efile = new TFile("Energy_table.root");
TTree* ETree = (TTree*)Efile->Get("ETree");
ETree->SetBranchAddress("Ecol1",&energy);
ETree->SetBranchAddress("Ecol4",&voltage);
TFile* TPfile = new TFile("TP.root","update");
TTree* TPtree = new TTree("TPtree"," TP tree");
TPtree->Branch("col",&col,"col/I");
TPtree->Branch("row",&row,"row/I");
TPtree->Branch("pc",&pc,"pc/I");
TPtree->Branch("tot",&tot,"tot/D");
TPtree->Branch("tot_var",&tot_var,"tot_var/D");
TPtree->Branch("toa",&toa,"toa/D");
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);
// std:: cout << energy << " " << voltage << std::endl;
std::string TPfilename = "tp_dat_" + std::to_string(energy) + ".dat";
//std:: cout << " The TPfilenames are : " << TPfilename.c_str() <<std::endl;
std::ifstream TPdatafile(TPfilename.c_str());
voltageBranch->Fill();
if(TPdatafile.is_open()){
std::cout << " The data file " << TPfilename.c_str() << " is opened ..." <<std::endl;
// reading through individial tp_dat_ files
while(getline(TPdatafile,line_TP)){
if(line_TP.rfind("#", 0) == 0) {
continue;
}
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
}//For loop GetEntries
//Save only the new version of the tree
TPtree->Write("",TObject::kOverwrite);
long N = TPtree->Draw("voltage:tot:sqrt(tot_var) ", "row==1 && col==10&&tot>0", "goff");
TGraphErrors *gr = new TGraphErrors(N,TPtree->GetV1(),TPtree->GetV2(),0,TPtree->GetV3());
tot_calib(gr);
TPfile->Close();
}
void tot_onepixel(){
TreeEnergyWrite();
TreeTPWrite();
}
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