#include #include #include #include #include void final1() { //setup area string file_name_s = "wbbj1.top"; const char* file_name_c = file_name_s.c_str(); ifstream file_in; file_in.open(file_name_c); if ( !file_in.good() ) { cerr << "Cannot access or open the file: \"" << file_name_s << "\"" << endl; abort(); } string line(""); string title_a(""); string title_b(""); string title_c(""); string x_axis_title(""); string histo_title(""); string y_axis_title(""); string scrap(""); string scale(""); vector x_values; vector y_values; vector dy_values; double x; double y; double dy; int loc_1; int loc_2; int loc_3; int loc_4; int loc_5; int loc_6; int loc_7; int title_counter = 0; int lower_x_limit; int upper_x_limit; int x_number; int y_number; int dy_number; int length; int index_count = 0; while(getline(file_in, line)) { loc_1 = line.find("SCALE", 0); loc_2 = line.find("TITLE", 0); loc_3 = line.find("SET LIMITS", 0); loc_4 = line.find("title", 0); loc_5 = line.find("BEGIN HIST", 0); loc_6 = line.find("NEW PLOT", 0); std::istringstream line_stream(line); if (std::string::npos != loc_1) { line_stream >> scrap; line_stream >> scrap; line_stream >> scrap; line_stream >> scale; continue; } else if (std::string::npos != loc_2) { loc_1 = line.find("TOP", 0); loc_2 = line.find("BOTTOM", 0); loc_3 = line.find("SET TITLE", 0); if (std::string::npos != loc_1) { loc_1 = line.find_first_of("\""); top_title = line.substr(loc_1); continue; } else if (std::string::npos != loc_2) { loc_1 = line.find_first_of("\""); bottom_title = line.substr(loc_1); continue; } else if (std::string::npos == loc_3) { continue; } else { title_counter++; if (title_counter == 1) { loc_1 = line.find_first_of("\""); title_a = line.substr(loc_1); continue; } else if (title_counter == 2) { loc_1 = line.find_first_of("\""); title_b = line.substr(loc_1); continue; } else { loc_1 = line.find_first_of("\""); title_c = line.substr(loc_1); title_counter = 0; continue; } } } else if (std::string::npos != loc_3) { line_stream >> scrap; line_stream >> scrap; line_stream >> scrap; line_stream >> lower_x_limit; line_stream >> upper_x_limit; continue; } else if (std::string::npos != loc_4) { line_stream >> scrap; line_stream >> scrap; line_stream >> scrap; line_stream >> scrap; line_stream >> scrap; line_stream >> x_axis_title; continue; } else if (std::string::npos != loc_5) { while(1) { getline(file_in, line); std::istringstream streamer(line); loc_7 = line.find( "END HIST", 0); if (std::string::npos != loc_7) { break; } streamer >> x; streamer >> y; streamer >> dy; x_values.push_back(x); y_values.push_back(y); dy_values.push_back(dy); } continue; } else if (std::string::npos != loc_6) { length = x_values.size(); TCanvas *canvas_1 = new TCanvas("canvas_1","Canvas One",1); TH1F *histo1 = new TH1F("histo1","To Be Changed",length,lower_x_limit,upper_x_limit); histo1->SetLineColor(kBlack); gStyle->SetEndErrorSize(np=3); gStyle->SetOptStat(""); histo1->SetMarkerStyle(4); histo1->SetMarkerColor(kBlack); histo1->GetXaxis()->SetTitle(x); histo1->GetYaxis()->SetTitle(bottom_title); histo1->GetXaxis()->SetTitleOffset(1); histo1->GetYaxis()->SetTitleOffset(1.2); histo1->SetTitle(""); histo1->Draw("hist, E1"); histo_title = TPaveText(0.34, 0.9, 0.65, 0.99, "NDC"); histo_title->SetFillColor(0); line_one = histo_title.AddText(bottom_title); histo_title->Draw("same"); if (scale == "LOG") { gstyle->SetLogy() } double errors [length]; while (index_count < length) { histo1->Fill(x_values[index_count],y_values[index_count]); histo1->SetBinError(index_count, dy_values[index_count]); index_count++; } index_count = 0; TFile *new_root_file = new TFile("new_root_file.root","RECREATE"); canvas_one->write(); new_root_file->close(); continue; } else { continue; } } return 0; } /////////////////////////////////////////////////////////////////////////////// //Histogram Title A: "INT = 3.495E-02 AVG = 1.821E+00 RMS = 7.755E-01" //Histogram Title B: "Entries = 197502 Undersc = 0 Oversc = 0" //Histogram Title C: "Intgr ufloat= 0.000E+00 Intgr ofloat= 0.000E+00" //legend //more plots //save canvas ///////////////////////////////////////////////////////////////////////////////