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

Code to refine the toa_cuts. Idea is to use a corase cut and plot toa vs...

Code to refine the toa_cuts. Idea is to use a corase cut and plot toa vs voltage, do a gauss fit, extraxct gauss mean and sigma to refine fine_toacut before fitting with time walk function. The Tree->Draw() with selection condition is not yet working
parent de42755b
void TreeEnergyWrite(){
int Ecol1;
double Ecol2,Ecol3,Ecol4;
string line_E;
TFile* Efile = new TFile("Energy_table_Tree_Check.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,isigma;
double voltage,tot, tot_var, toa, toa_var, time_ref,rough_toacut,mean,RMS,events;
string line_TP;
TCanvas*c = new TCanvas();
TFile* Efile = new TFile("Energy_table_Tree_Check.root");
TTree* ETree = (TTree*)Efile->Get("ETree");
ETree->SetBranchAddress("Ecol1",&energy);
ETree->SetBranchAddress("Ecol4",&voltage);
TFile* TPfile = new TFile("TreeCheck.root","recreate");
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_coarse_toacut = TPtree->Branch("rough_toacut",&rough_toacut,"rough_toacut/D");
auto Branch_mean = TPtree->Branch("mean",&mean,"mean/D");
auto Branch_RMS = TPtree->Branch("RMS",&RMS,"RMS/D");
auto Branch_isigma = TPtree->Branch("isigma",&isigma,"RMS/I");
auto Branch_events = TPtree->Branch("events",&events,"events/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
TPtree->Draw("toa",Form("voltage==(%f)",voltage),"goff");
mean = TMath::Mean(TPtree->GetSelectedRows(), TPtree->GetV1());
Branch_mean->Fill();
RMS = TMath::RMS(TPtree->GetSelectedRows(), TPtree->GetV1());
Branch_RMS->Fill();
// std::cout <<" mean " << mean << " RMS " << RMS <<std::endl;
rough_toacut = mean + 6*RMS;
// cout << " toa : " << toa << " " << "rough toa cut : " << rough_toacut <<std::endl;
Branch_coarse_toacut->Fill();
/* c->SetLogy();
TF1 *fgaus = new TF1("fgaus", "gaus", 0, 700) ;
TPtree->Fit("fgaus", "toa>>hfit(1000)",Form("voltage==(%f)",voltage)," ");
gPad->SaveAs(Form("toa>>htoa_everything_%d.png", i));*/
c->SetLogy();
TPtree->Draw(Form("toa>>htoa_%d", i),Form("voltage==(%f)",voltage),"toa<rough_toacut");//coarse selection
TPtree->Draw(Form("toa>>htoa_%d", i),Form("voltage==(%f)",voltage),"");//No selection->Plot all toa
// gPad->Update();
gPad->SaveAs(Form("toa>>htoa_coarsecut__%d.png", i));
}//For loop GetEntries
//Save only the new version of the tree
TPtree->Write("",TObject::kOverwrite);
// TPfile->Close();
}
void TreeCheck(){
TreeEnergyWrite();
TreeTPWrite();
}
/* for ( 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;
Branch_isigma->Fill();
events = 100.0*TPtree->GetEntries(Form("toa<(%f) && voltage==(%f)",mean+isigma*RMS,voltage))/TPtree->GetEntries(Form("voltage==(%f)",voltage));
std::cout << isigma << " times RMS : " << events << std::endl;
Branch_events->Fill();
}*/
// TPtree->Draw(Form("events>>hevents_%d",i));
// gPad->SaveAs(Form("events>>hevents_%d.png",i));
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