#include #include #include #include #include #include "TCanvas.h" #include "TTree.h" #include "Riostream.h" #include "TH1F.h" #include "TDirectory.h" #include "TSystem.h" #include "ttree_operation.h" using namespace std; //this function is used to get the value we need from a tree //we first create an histogram with TTree::Draw() methode //and we store this data into a vector with HT1F::GetArray() void get_values(float *tab, int size, shared_ptr tree, TString str1, TString str2) { tree->Draw(str1,str2); TH1F *htemp1 = (TH1F*)gDirectory->Get("hist_tmp"); float *tmp_tab = htemp1->GetArray(); for(int i=0; i type = {{"CAID", "/I"}, {"TIME", "/F"}, {"COOR_X", "/F"}, {"COOR_Y", "/F"}, {"COOR_Z", "/F"}, {"TIME_BIN_END_TIME", "/F"}, {"INDUCED_FISSIONS_NB", "/F"}}; string map_default_value = "/C"; //we check if str is a known string or not auto iterator = type.find(str); if (iterator == type.end()) { return map_default_value; } else { return iterator->second; } } //function that create a TTree object from a file shared_ptr file_to_tree(string fdata, string froot){ //init of string variable string first_file_line; string file_head; string str_temp; //init of stream ifstream file_stream; istringstream first_line_stream; //opening file and taking the first line file_stream.open(fdata, ios::in); getline(file_stream, first_file_line); first_line_stream.str(first_file_line); first_line_stream >> str_temp; //creating the branchDescriptor for the tree file_head = file_head + str_temp + type_of_data(str_temp); while(first_line_stream.good()) { first_line_stream >> str_temp; file_head = file_head + ":" + str_temp + type_of_data(str_temp); } //branchDescriptor is a const char*, not a string const char* char_file_head = file_head.c_str(); // create a TTree with the data in fdata shared_ptr mytree(new TTree("Data","This is my first ttree")); mytree->ReadStream(file_stream, char_file_head, ' '); cout << "done" << endl; return mytree; }