#include "TFile.h" #include "TCanvas.h" #include "TPad.h" #include "TH1D.h" #include #include #include #include #include #include // for double -> string #include #include /* #include "boost/program_options.hpp" */ //================================================== // myTools: //================================================== /* bool execute(std::string str_file_sPlot_IO, std::string str_output_saveAddon, std::string str_year, std::string str_ROOTsaveDir, std::string str_th1_name, std::string str_x_title, std::string str_y_title, std::vector x_vec, std::vector xe_vec, std::vector y_vec, std::vector ye_vec, std::vector range_xy) */ void graph() { gROOT->SetBatch(kTRUE); gStyle->SetOptStat(0); //================================================ // these options would be set via the commandline std::string str_file_sPlot_IO = "/DATA/Lb2D0PHD02HH/sPlot/output/sPlot_DATAs21r1_TupleLb2D0ppi_D02Kmpip.root"; std::string str_output_saveAddon = "Pt_Lb2D0pK_D0Kmpip"; std::string str_year = "11"; std::string str_ROOTsaveDir = "reweightMC_01_wNone"; std::string str_th1_name = "h1_fracPT_DATAdivMC"; std::string str_x_title = "p_{t}"; std::string str_y_title = ""; std::vector x_vec = {2000.0, 2434.34350586, 2868.68676758, 3303.03027344, 3737.3737793, 4171.71728516, 4606.06054688, 5040.40380859, 5474.74755859, 5909.09082031, 6343.43457031, 6777.77783203, 7212.12109375, 7646.46484375, 8080.80810547, 8515.15136719, 8949.49511719, 9383.83886719, 9818.18164062, 10252.5253906, 10686.8691406, 11121.2119141, 11555.5556641, 11989.8994141, 12424.2421875, 12858.5859375, 13292.9296875, 13727.2724609, 14161.6162109, 14595.9599609, 15030.3027344, 15464.6464844, 15898.9902344, 16333.3330078, 16767.6777344, 17202.0195312, 17636.3632812, 18070.7070312, 18505.0507812, 18939.3945312, 19373.7382812, 19808.0800781, 20242.4238281, 20676.7675781, 21111.1113281, 21545.4550781, 21979.7988281, 22414.140625, 22848.484375, 23282.828125, 23717.171875, 24151.515625, 24585.859375, 25020.2011719, 25454.5449219, 25888.8886719, 26323.2324219, 26757.5761719, 27191.9199219, 27626.2617188, 28060.6054688, 28494.9492188, 28929.2929688, 29363.6367188, 29797.9804688, 30232.3222656, 30666.6660156, 31101.0097656, 31535.3535156, 31969.6972656, 32404.0410156, 32838.3828125, 33272.7265625, 33707.0703125, 34141.4140625, 34575.7578125, 35010.1015625, 35444.4453125, 35878.7890625, 36313.1328125, 36747.4765625, 37181.8164062, 37616.1601562, 38050.5039062, 38484.8476562, 38919.1914062, 39353.5351562, 39787.8789062, 40222.2226562, 40656.5664062, 41090.9101562, 41525.2539062, 41959.5976562, 42393.9375, 42828.28125, 43262.625, 43696.96875, 44131.3125, 44565.65625, 45000.0}; std::vector y_vec = {1.38509845734, 1.36534774303, 1.34560024738, 1.32585918903, 1.30612778664, 1.28640925884, 1.26670694351, 1.24702394009, 1.22736346722, 1.20772874355, 1.18812298775, 1.16854953766, 1.14901161194, 1.12951231003, 1.11005485058, 1.09064257145, 1.07127857208, 1.05196619034, 1.03270864487, 1.01350915432, 0.994370818138, 0.975296974182, 0.956290781498, 0.937355518341, 0.918494403362, 0.899710655212, 0.881007432938, 0.862388074398, 0.84385573864, 0.825413584709, 0.807065010071, 0.788813054562, 0.770660996437, 0.752612173557, 0.734670341015, 0.716842591763, 0.699136435986, 0.681559503078, 0.664119422436, 0.646823823452, 0.629680335522, 0.612696707249, 0.595880329609, 0.579239010811, 0.56278026104, 0.546511769295, 0.530441105366, 0.514576077461, 0.498924046755, 0.48349276185, 0.468289881945, 0.453322976828, 0.438599705696, 0.424127727747, 0.409914553165, 0.395967900753, 0.3822953403, 0.368904531002, 0.355803132057, 0.342998743057, 0.330498933792, 0.318311393261, 0.306443721056, 0.294903516769, 0.2836984694, 0.272836208344, 0.262324273586, 0.252167254686, 0.24235740304, 0.2328838557, 0.223735749722, 0.214902296662, 0.206372559071, 0.198135733604, 0.190180972219, 0.182497411966, 0.175074219704, 0.167900547385, 0.160965546966, 0.154258355498, 0.147768139839, 0.141484096646, 0.135395273566, 0.129490882158, 0.123760052025, 0.118191957474, 0.112775735557, 0.107500553131, 0.102355547249, 0.097329877317, 0.0924126878381, 0.0875931382179, 0.0828603804111, 0.0782035961747, 0.0736118704081, 0.0690743774176, 0.064580284059, 0.0601187348366, 0.0556788817048, 0.0512498766184}; std::vector xe_vec = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; std::vector ye_vec = {0.134594887495, 0.12670995295, 0.118932507932, 0.111295379698, 0.103834398091, 0.0965890437365, 0.0896032825112, 0.0829264819622, 0.0766143724322, 0.0707297846675, 0.0653427168727, 0.06052910164, 0.0563670918345, 0.0529299415648, 0.0502749979496, 0.0484303794801, 0.0473834313452, 0.0470762252808, 0.0474111326039, 0.0482646860182, 0.0495041683316, 0.051001675427, 0.0526430979371, 0.0543322563171, 0.0559918060899, 0.0575624741614, 0.0590017922223, 0.060282997787, 0.0613944940269, 0.0623398572206, 0.0631385743618, 0.0638273209333, 0.0644615888596, 0.0651174485683, 0.065895177424, 0.0669166371226, 0.0682961717248, 0.0701270624995, 0.0724742934108, 0.0753706023097, 0.0788166671991, 0.082784935832, 0.0872259289026, 0.0920751169324, 0.0972595214844, 0.102703034878, 0.10833042115, 0.114070214331, 0.119856745005, 0.12563149631, 0.131344303489, 0.136954411864, 0.142431542277, 0.147757098079, 0.15292571485, 0.157946690917, 0.162846028805, 0.167668387294, 0.172479227185, 0.177366763353, 0.182443723083, 0.187848180532, 0.193743526936, 0.200316861272, 0.207775563002, 0.216341942549, 0.22624643147, 0.237717404962, 0.250954419374, 0.266105562449, 0.283265560865, 0.302479565144, 0.323751091957, 0.34705016017, 0.372322410345, 0.399496763945, 0.428491592407, 0.459219455719, 0.491590440273, 0.525514423847, 0.560902416706, 0.597667038441, 0.635724425316, 0.674992084503, 0.715390563011, 0.75684261322, 0.799273371696, 0.842609941959, 0.886781156063, 0.931717634201, 0.977351486683, 1.0236158371, 1.07044541836, 1.11777508259, 1.16554224491, 1.21368360519, 1.2621370554, 1.31084120274, 1.35973501205, 1.40875828266}; std::vector range_xy = {2000.0, 45000.0, -0.6, 2.0}; // end options //================================================ std::cout << "INFO :: Add Fit-Plot to IOfile" << std::endl; std::cout << " IOfile = " << str_file_sPlot_IO << std::endl; std::cout << " saveAddon = " << str_output_saveAddon << std::endl; std::cout << " year = " << str_year << std::endl; std::cout << " ROOTdir = " << str_ROOTsaveDir << std::endl; std::cout << " th1_name = " << str_th1_name << std::endl; std::cout << " x = " << range_xy[0] << " -> " << range_xy[1] << std::endl; std::cout << " y = " << range_xy[2] << " -> " << range_xy[3] << std::endl; /* auto _file = new TFile( str_file_sPlot_IO.c_str(), "update" ); std::string str_th1_2_get = str_ROOTsaveDir + "/" + str_th1_name; auto _th1 = (TH1D*)_file->Get( str_th1_2_get.c_str() ); _th1->GetYaxis()->SetRangeUser(range_xy[2], range_xy[3]); _th1->SetLineColor(1); _th1->GetXaxis()->SetTitle( str_x_title.c_str() ); str_y_title = "frac( DATA / MC " + str_y_title + " )"; _th1->GetYaxis()->SetTitle( str_y_title.c_str() ); range_xy[0] = _th1->GetBinLowEdge(1); range_xy[1] = _th1->GetBinLowEdge(_th1->GetNbinsX()) + 1.*_th1->GetBinWidth(_th1->GetNbinsX()); std::cout << "CXX -> Range Histo:" << range_xy[0] << ", " << range_xy[1] << std::endl; std::cout << "CXX -> Range Plot:" << x_vec[0] << ", " << x_vec[x_vec.size()-1] << std::endl; _file->cd( str_ROOTsaveDir.c_str() ); */ auto _th1 = new TH1D("_th1","test",10,range_xy[0], range_xy[1]); _th1->GetYaxis()->SetRangeUser(range_xy[2], range_xy[3]); auto graph_fit = new TGraphErrors(x_vec.size(), &(x_vec[0]), &(y_vec[0]), &(xe_vec[0]), &(ye_vec[0])); graph_fit->SetTitle("CSpline-Fit"); graph_fit->GetYaxis()->SetRangeUser(range_xy[2], range_xy[3]); graph_fit->GetXaxis()->SetRangeUser(range_xy[0], range_xy[1]); graph_fit->GetXaxis()->SetLabelSize(0); graph_fit->GetYaxis()->SetLabelSize(0); graph_fit->GetXaxis()->SetTickLength(0); graph_fit->GetYaxis()->SetTickLength(0); graph_fit->SetLineColor(2); // 1 = black graph_fit->SetFillColorAlpha(1,0.25); // 16 = grey graph_fit->SetFillStyle(1001); // = solid auto can_fit = new TCanvas("test_fit","",800,600); can_fit->cd(); _th1->Draw("e"); graph_fit->Draw("L4same"); // graph_fit->Draw("L4same"); can_fit->Update(); //can_fit->Write(); std::string save_string = "test_fit_"+str_ROOTsaveDir+".pdf"; can_fit->SaveAs( save_string.c_str() ); /* _file->Close(); return true; */ } //============================ /* namespace { const size_t ERROR_IN_COMMAND_LINE = 1; const size_t SUCCESS = 0; const size_t ERROR_UNHANDLED_EXCEPTION = 2; } // namespace int main( int argc, // Number of strings in array argv char *argv[], // Array of command-line argument strings char *envp[] ) // Array of environment variable strings { // 2012 / Lb->D0ppi / D0->Kmpip std::string str_IOfile; std::string str_out_saveAddon; std::string str_year; std::string str_ROOTsaveDir, str_th1_name, str_x_title, str_y_title; std::vector vec_x, vec_xe, vec_y, vec_ye; std::vector range_xy; // x_range_0, x_range_1, y_range_0, y_range_1 try { namespace po = boost::program_options; po::options_description desc("Options"); desc.add_options() ("help" , "Help screen") ("IOfile" , po::value (&str_IOfile )->required() , "InputOutput-file DATA" ) ("sAddon" , po::value (&str_out_saveAddon)->required() , "Define additional string for save" ) ("year" , po::value (&str_year )->required() , "Define Year" ) ("ROOTdir", po::value (&str_ROOTsaveDir )->required() , "Define directory for ROOT-file storage") ("histo" , po::value (&str_th1_name )->required() , "Histogram that was fitted" ) ("title_x", po::value (&str_x_title ) , "(optional) title x-axis" ) ("title_y", po::value (&str_y_title ) , "(optional) title y-axis" ) ("vec_x" , po::value >(&vec_x )->multitoken()->required(), "List of x-Values" ) ("vec_xe" , po::value >(&vec_xe )->multitoken()->required(), "List of x-Errors" ) ("vec_y" , po::value >(&vec_y )->multitoken()->required(), "List of y-Values (Spline)" ) ("vec_ye" , po::value >(&vec_ye )->multitoken()->required(), "List of y-Errors (Spline)" ) ("range" , po::value >(&range_xy)->multitoken()->required(), "Range to plot: x0, x1, y0, y1" ) ; po::variables_map vm; try { //po::store(po::parse_command_line(argc, argv, desc), vm); // can throw // disable short-opt like "-o xx" to use negative floats as cmd-option po::store(parse_command_line(argc, argv, desc, po::command_line_style::unix_style ^ po::command_line_style::allow_short), vm); // --help option if ( vm.count("help") ) { std::cout << "Basic Command Line Parameter App" << std::endl << desc << std::endl; return SUCCESS; } po::notify(vm); // throws on error, so do after help in case // there are any problems } catch(po::error& e) { std::cerr << "ERROR: " << e.what() << std::endl << std::endl; std::cerr << desc << std::endl; return ERROR_IN_COMMAND_LINE; } // application code here // execute(myTools::path_eos()+str_IOfile, str_out_saveAddon, str_year, str_ROOTsaveDir, str_th1_name, str_x_title, str_y_title, vec_x, vec_xe, vec_y, vec_ye, range_xy); } catch(std::exception& e) { std::cerr << "Unhandled Exception reached the top of main: " << e.what() << ", application will now exit" << std::endl; return ERROR_UNHANDLED_EXCEPTION; } return SUCCESS; } // main */