Commit 73bf2f1c authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

You can see individual tress in TP.root. Not yet merged

parent bcc55928
//TList* TPlist = new TList;
void TreeEnergyWrite(){
TFile* TPfile = new TFile("TP.root","update"); // Declared globally coz TPfile is closed in ain function after going through all the pixels
TList* TPlist = new TList;
void treeWrite(int c, int r){
int TPcol1, TPcol2, TPcol3;
double tot, tot_var, toa, toa_var,Ecol1,Ecol2,Ecol3,Ecol4;
string line_TP;
int Ecol1;
double Ecol2,Ecol3,Ecol4;
string line_E;
std::vector<double>Energy_e = {200,300,400,500,600,700,800,900,1000,1100,1200,
1300,1400,1500,1700,2200,2700,3200,4000,5000,6000,
7000,8000,9000,10000,11000,12000,13000,14000};
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();
//Creating TProot file with a TP tree
}
void TreeTPWrite(int c, int r){
std::cout << " Looking at pixel " << c << "_" << r << std::endl;
int energy, TPcol1, TPcol2, TPcol3;
double voltage,tot, tot_var, toa, toa_var;
string line_TP;
TFile* Efile = new TFile("Energy_table.root");
TTree* ETree = (TTree*)Efile->Get("ETree");
// TFile* TPfile = new TFile("TP.root","update");
TFile* TPfile = new TFile("TP.root","update");
std::string TPtreeName = "TPtree" + std::to_string(c) + "_" + std::to_string(r);
TTree* TPtree = new TTree(TPtreeName.c_str()," TP tree");
// TList* list = new TList;
TTree* Mergedtree = new TTree("MergedTree", "Merged trees");
Mergedtree->SetDirectory(TPfile);
TPtree->Branch("TPcol1",&TPcol1,"TPcol1/I");
TPtree->Branch("TPcol2",&TPcol2,"TPcol2/I");
......@@ -29,65 +53,72 @@ void treeWrite(int c, int r){
TPtree->Branch("toa",&toa,"toa/D");
TPtree->Branch("toa_var",&toa_var,"toa_var/D");
//Creating second root file(Energy_table.dat) with a different tree
/* TFile* friend = new TFile("TPtreeFriend.root","recreate");
TTree* Frirendtree = new TTree("Friendtree","friend tree");
Friendtree->Branch("Ecol4",&Ecol4,"Ecol4/D");*/
ETree->SetBranchAddress("Ecol1",&energy);
ETree->SetBranchAddress("Ecol4",&voltage);
//Filling the trees
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());
cout << "The tree is filled with values of col " << c << " and row "<< r << std::endl;
for(int i= 0; i < Energy_e.size(); i++){
stringstream Sfile;
Sfile << Energy_e.at(i) << ".dat";
std::vector<std::string>Filenames = {std::string("tp_dat_" + Sfile.str())};
for(int j = 0; j < Filenames.size(); j++){
std::ifstream TPdata_file(Filenames.at(j).c_str());
if(TPdata_file.is_open()){
std::cout << " The data file" << Filenames.at(j) << " is opened ..." <<std::endl;
if(TPdatafile.is_open()){
std::cout << " The data file " << TPfilename.c_str() << " is opened ..." <<std::endl;
// make a new branch and connect it to the same variable as the branch address of the energy tree
auto voltageBranch = TPtree->Branch("voltage", &voltage, "voltage/D");
// reading through individial tp_dat_ files
while(getline(TPdatafile,line_TP)){
if(line_TP.rfind("#", 0) == 0) {
continue;
}
while(getline(TPdata_file,line_TP)){
if(line_TP.rfind("#", 0) == 0) {
continue;
}
istringstream ssTP(line_TP);
ssTP >> TPcol1 >> TPcol2 >> TPcol3 >> tot >> tot_var >> toa >> toa_var;
if(TPcol1==c && TPcol2 ==r){
TPtree->Fill();
break;
}
} //While loop getline
} //if statement TPdatafile open
} // for loop j filenames
} // if statement energy_e.size()
// TPtree->Scan(); //Displays the data corresponding to all energy values of each pixel
istringstream ssTP(line_TP);
ssTP >> TPcol1 >> TPcol2 >> TPcol3 >> tot >> tot_var >> toa >> toa_var;
if(TPcol1==c && TPcol2 ==r){
TPtree->Fill();
voltageBranch->Fill();
break;
}
} //While loop getline
}//if statement TPdatafile open
}//For loop GetEntries
//Save only the new version of the tree
// TPtree->Write("",TObject::kOverwrite);
// TPtree->Write("",TObject::kWriteDelete);
TPtree->Write();
// TPtree->Scan();
//Add new trees (incl voltage col) to list and merge the trees
/* std::cout << " The tree for the pixel " << c << " and " << r << " is added to the list " << std::endl;
TList* TPlist = new TList;
TPlist->Add(TPtree);
// list->Print(); //Prints the contents of the list
// std::cout <<" The size of the tree list is " << list->GetSize() << std::endl; // list size = 1, not growing!!
TTree* newtree = TTree::MergeTrees(TPlist);
newtree->SetName("MergedTree");
newtree->Write("",TObject::kWriteDelete);
//TPfile->Close();
}
Mergedtree = TTree::MergeTrees(TPlist);
Mergedtree->Write("",TObject::kWriteDelete);*/
TPfile->Close();
//Efile->Close();
}
void TreeTest(){
int col, row ;
int col, row ;
TreeEnergyWrite();
for(col=0;col<2;col++){
for(row=0;row<2;row++){
treeWrite(col,row);
TreeTPWrite(col,row);
}
}
std::cout <<" The size of the tree list is " << TPlist->GetSize() << std::endl;
TPfile->Close();
// treeRead();
// std::cout <<" The size of the tree list is " << TPlist->GetSize() << std::endl;
//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