#include #include #include #include #include void final1() { cout << "here1" << endl; 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(); } cout << "here2" << endl; string line(""); string title_a(""); string title_b(""); string title_c(""); string x_axis_title_s(""); string top_title_s(""); string y_axis_title_s(""); string scrap(""); string scale(""); vector x_values; vector y_values; vector dy_values; cout << "here3" << endl; 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; double lower_x_limit; double upper_x_limit; int x_number; int y_number; int dy_number; int length; int index_count = 0; cout << "here4" << endl; 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); cout << "here4" << endl; 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) { cout << "here5" << endl; 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) { cout << "here5.1" << endl; loc_1 = line.find_first_of("\""); top_title_s = line.substr(loc_1); cout << "here5.12" << endl; continue; } else if (std::string::npos != loc_2) { loc_1 = line.find_first_of("\""); y_axis_title_s = line.substr(loc_1); cout << "here5.2" << endl; continue; } else if (std::string::npos != loc_3) { cout << "here5.3" << endl; continue; } else { cout << "here5.5.401" << endl; title_counter++; cout << "here5.5.402" << endl; if (title_counter == 1) { cout << "here5.41" << endl; loc_1 = line.find_first_of("\""); cout << "here5.411" << endl; cout << loc_1 << endl; cout << line << endl; title_a = line.substr(loc_1); cout << "here5.42" << endl; continue; } else if (title_counter == 2) { loc_1 = line.find_first_of("\""); title_b = line.substr(loc_1); cout << "here5.5" << endl; continue; } else { loc_1 = line.find_first_of("\""); title_c = line.substr(loc_1); title_counter = 0; cout << "here5.6" << endl; continue; } } } else if (std::string::npos != loc_3) { cout << line << endl; line_stream >> scrap; line_stream >> scrap; line_stream >> scrap; line_stream >> lower_x_limit; line_stream >> upper_x_limit; cout << lower_x_limit << endl; cout << upper_x_limit << endl; cout << "here6" << endl; continue; } else if (std::string::npos != loc_4) { loc_1 = line.find_first_of("\""); x_axis_title_s = line.substr(loc_1); cout << "here7" << endl; 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); cout << "here8" << endl; } continue; } else if (std::string::npos != loc_6) { length = x_values.size(); TCanvas *canvas_1 = new TCanvas("canvas_1","Canvas One",1); canvas_1->Divide(2,1); canvas_1->cd(1); canvas_1->SetFillColor(kWhite); 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(1); histo1->SetMarkerColor(kBlack); x_axis_title_s = x_axis_title_s.substr(1, (x_axis_title_s.length() - 2)); y_axis_title_s = y_axis_title_s.substr(1, (y_axis_title_s.length() - 2)); cout << x_axis_title_s << endl; const char* x_axis_title_c = x_axis_title_s.c_str(); const char* y_axis_title_c = y_axis_title_s.c_str(); histo1->GetXaxis()->SetTitle(x_axis_title_c); histo1->GetYaxis()->SetTitle(y_axis_title_c); 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); top_title_s = top_title_s.substr(1, (top_title_s.length() - 2)); const char* top_title_c = top_title_s.c_str(); line_one = histo_title.AddText(top_title_c); // histo_title.Draw("same"); canvas_1->cd(2); histo_info = TPaveLabel(0.34, 0.9, 0.65, 0.99); histo_info.SetFillColor(0); title_a = title_a.substr(1, (title_a.length() - 2)); const char* title_a_c = title_a.c_str(); title_b = title_b.substr(1, (title_b.length() - 2)); const char* title_b_c = title_b.c_str(); title_c = title_c.substr(1, (title_c.length() - 2)); const char* title_c_c = title_c.c_str(); line_a = histo_info.AddText(title_a_c); line_b = histo_info.AddText(title_b_c); line_c = histo_info.AddText(title_c_c); // histo_info.Draw(); cout << "here9" << endl; if (scale == "LOG") { canvas_1->SetLogy(1); } 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_file2.root","RECREATE"); // canvas_1.Update(); canvas_1->Write(); new_root_file->Close(); cout << "here10" << endl; continue; } else { continue; } } return 0; } /////////////////////////////////////////////////////////////////////////////// //Histogram Title A: "INT = 3.495E-02 AVG = 1.821E+00 RMS = 7.755E-01" -- not appearing //Histogram Title B: "Entries = 197502 Undersc = 0 Oversc = 0" -- not appearing //Histogram Title C: "Intgr ufloat= 0.000E+00 Intgr ofloat= 0.000E+00" -- not appearing //legend -- possibly dont need //more plots -- lots more code, generally just repetition though. //Title not appearing -- appears in file. Doesn't appear on drawn plot. ///////////////////////////////////////////////////////////////////////////////