Commit 52b51d1f authored by Keerthi Nakkalil's avatar Keerthi Nakkalil
Browse files

1st working code!!!

parent 66cf46bc
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;
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};
//Creating TProot file with a TP tree
// 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;
TPtree->Branch("TPcol1",&TPcol1,"TPcol1/I");
TPtree->Branch("TPcol2",&TPcol2,"TPcol2/I");
TPtree->Branch("TPcol3",&TPcol3,"TPcol3/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");
//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");*/
//Filling the trees
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;
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
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();
}
void TreeTest(){
int col, row ;
for(col=0;col<2;col++){
for(row=0;row<2;row++){
treeWrite(col,row);
}
}
std::cout <<" The size of the tree list is " << TPlist->GetSize() << std::endl;
TPfile->Close();
// treeRead();
}
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