diff --git a/.gitignore b/.gitignore index c0a2f2f..b7edd17 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ *.o *.so *.root +*.pdf +*.C + diff --git a/plotting/Makefile b/plotting/Makefile index fbc5081..0be2789 100644 --- a/plotting/Makefile +++ b/plotting/Makefile @@ -7,17 +7,24 @@ REPO = $(shell git rev-parse --show-toplevel)/plotting COMMON = $(shell git rev-parse --show-toplevel)/common CPPFLAGS := $(shell root-config --cflags) -I$(REPO)/include -I$(COMMON)/include -I$(CMSSW_INC)/src -LDFLAGS := $(shell root-config --glibs) $(STDLIBDIR) -lRooFit -lRooFitCore -L$(CMSSW_INC)/lib/slc6_amd64_gcc530/ -lHiggsAnalysisCombinedLimit +#LDFLAGS := $(shell root-config --glibs) $(STDLIBDIR) -lRooFit -lRooFitCore -L$(CMSSW_INC)/lib/slc6_amd64_gcc530/ -lHiggsAnalysisCombinedLimit +LDFLAGS := $(shell root-config --glibs) $(STDLIBDIR) -lRooFit -lRooFitCore -L$(CMSSW_INC)/lib/slc6_amd64_gcc530/ CPPFLAGS += -g -std=c++1y TARGET = PlotLimits +TARGET2 = PlotVR +TARGET3 = GetExtraSysUnc SRC = $(REPO)/app/plot_limits.cc $(COMMON)/src/CommandLineInput.cc +SRC2 = $(REPO)/app/plot_validation_region.cc $(REPO)/src/helper_functions.cc $(COMMON)/src/CommandLineInput.cc +SRC3 = $(REPO)/app/get_extra_sys_unc.cc $(REPO)/src/helper_functions.cc $(COMMON)/src/CommandLineInput.cc OBJ = $(SRC:.cc=.o) +OBJ2 = $(SRC2:.cc=.o) +OBJ3 = $(SRC3:.cc=.o) -all : $(TARGET) +all : $(TARGET) $(TARGET2) $(TARGET3) $(TARGET) : $(OBJ) $(LD) $(CPPFLAGS) -o $(TARGET) $(OBJ) $(LDFLAGS) @@ -25,9 +32,24 @@ $(TARGET) : $(OBJ) @echo $< @echo $^ +$(TARGET2) : $(OBJ2) + $(LD) $(CPPFLAGS) -o $(TARGET2) $(OBJ2) $(LDFLAGS) + @echo $@ + @echo $< + @echo $^ + + +$(TARGET3) : $(OBJ3) + $(LD) $(CPPFLAGS) -o $(TARGET3) $(OBJ3) $(LDFLAGS) + @echo $@ + @echo $< + @echo $^ + + %.o : %.cc $(CXX) $(CPPFLAGS) -o $@ -c $< @echo $@ @echo $< + clean : - rm -f *.o app/*.o src/*.o include/*.o $(TARGET) *~ \ No newline at end of file + rm -f *.o app/*.o src/*.o include/*.o $(TARGET) $(TARGET2) $(TARGET3) *~ diff --git a/plotting/app/get_extra_sys_unc.cc b/plotting/app/get_extra_sys_unc.cc new file mode 100644 index 0000000..41056cd --- /dev/null +++ b/plotting/app/get_extra_sys_unc.cc @@ -0,0 +1,152 @@ +//C++ +#include +#include +#include +#include +#include +//ROOT +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//LOCAL INCLUDES +#include +#include + +const bool _info = true; +const bool _debug = false; + +bool AddCMS( TCanvas* C ); + +int main( int argc, char** argv ) +{ + + //----------------- + //Input File List + //----------------- + std::string inputList = ParseCommandLine( argc, argv, "-inputList=" ); + if ( inputList == "" ) + { + std::cerr << "[ERROR]: please provide an inputList. Use --inputList=" << std::endl; + return -1; + } + //std::ifstream ifs ( inputList.c_str(), std::ifstream::in );//input file list + + //---------------------- + //validation region name + //---------------------- + //std::string vrName = ParseCommandLine( argc, argv, "-vrName=" ); + //if ( vrName == "" ) + //{ + // std::cerr << "[ERROR]: please provide validation region name. Use --vrName=" << std::endl; + // return -1; + //} + + + if( _info ) + { + std::cout << "[INFO]: input file: " << inputList << std::endl; + //std::cout << "[INFO]: validation region name: " << vrName << std::endl; + } + + //-------------------------------- + //Array with bin extra uncertainty + //-------------------------------- + double err_ee[] = {0.0, 0.0, 0.0}; + double err_mumu[] = {0.0, 0.0, 0.0}; + + TFile* fin; + std::ifstream ifs ( inputList.c_str(), std::ifstream::in); + if (ifs.is_open()) + { + while (ifs.good()) + { + std::string current_fname; + ifs >> current_fname; + if (ifs.eof()) break; + //----------------- + //Getting ROOT file + //----------------- + fin = new TFile( current_fname.c_str(), "READ"); + //---------------------------------------------------------- + //GETTING POST-FIT RESULTS FROM COMBINE + //---------------------------------------------------------- + //--------------------- + //TwoEleZH + //--------------------- + TDirectory* dir_postfit_two_ee_zh = (TDirectory*)(((TDirectory*)fin->Get("shapes_fit_b"))->Get("TwoEleZH")); + TH1F* bkg_total_two_ee_zh_pf = (TH1F*)dir_postfit_two_ee_zh->Get("total_background"); + TGraphAsymmErrors* data_two_ee_zh_pf = (TGraphAsymmErrors*)dir_postfit_two_ee_zh->Get("data"); + for( unsigned int i = 1; i <= bkg_total_two_ee_zh_pf->GetNbinsX(); i++ ) + { + //data treatment + double y_data, x_data; + data_two_ee_zh_pf->GetPoint(i-1, x_data, y_data); + //relative difference + double delta_y = y_data - bkg_total_two_ee_zh_pf->GetBinContent(i); + double delta_y_rel = delta_y/bkg_total_two_ee_zh_pf->GetBinContent(i); + double y_unc = bkg_total_two_ee_zh_pf->GetBinError(i); + + if( fabs( delta_y ) > 2.*y_unc && y_data != 0.0 ) + { + std::cout << "ee->"<< i-1 << " " << delta_y_rel<< std::endl; + err_ee[i-1] += pow(delta_y_rel,2.0); + } + } + + + //--------------------- + //TwoMuZH + //--------------------- + TDirectory* dir_postfit_two_mumu_zh = (TDirectory*)(((TDirectory*)fin->Get("shapes_fit_b"))->Get("TwoMuZH")); + TH1F* bkg_total_two_mumu_zh_pf = (TH1F*)dir_postfit_two_mumu_zh->Get("total_background"); + TGraphAsymmErrors* data_two_mumu_zh_pf = (TGraphAsymmErrors*)dir_postfit_two_mumu_zh->Get("data"); + for( unsigned int i = 1; i <= bkg_total_two_mumu_zh_pf->GetNbinsX(); i++ ) + { + //data treatment + double y_data, x_data; + data_two_mumu_zh_pf->GetPoint(i-1, x_data, y_data); + //relative difference + double delta_y = y_data - bkg_total_two_mumu_zh_pf->GetBinContent(i); + double delta_y_rel = delta_y/bkg_total_two_mumu_zh_pf->GetBinContent(i); + double y_unc = bkg_total_two_mumu_zh_pf->GetBinError(i); + //std::cout << i-1 << " " << delta_y_rel<< std::endl; + if( fabs( delta_y ) > 2.*y_unc && y_data != 0.0 ) + { + std::cout << "mumu->"<< i-1 << " " << delta_y_rel<< std::endl; + err_mumu[i-1] += pow(delta_y_rel,2.0); + } + } + + + //Close current root file + fin->Close(); + } + } + else { + // show message: + std::cerr << "[ERROR]: Error opening file: " << inputList << std::endl; + std::cout << "Exiting program!!!" << std::endl; + return -1; + } + + //-------------------- + //ee extra uncertainty + //-------------------- + std::cout << "ee extra_unc bins (0,1,2) is: (" << sqrt(err_ee[0]) << ", " + << sqrt(err_ee[1]) << ", " << sqrt(err_ee[2]) << ")"<< std::endl; + //---------------------- + //mumu extra uncertainty + //---------------------- + std::cout << "mumu extra_unc bins (0,1,2) is: (" << sqrt(err_mumu[0]) << ", " + << sqrt(err_mumu[1]) << ", " << sqrt(err_mumu[2]) << ")"<< std::endl; + + return 0; +} diff --git a/plotting/app/plot_validation_region.cc b/plotting/app/plot_validation_region.cc new file mode 100644 index 0000000..cf86511 --- /dev/null +++ b/plotting/app/plot_validation_region.cc @@ -0,0 +1,390 @@ +//C++ +#include +#include +#include +#include +#include +//ROOT +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//LOCAL INCLUDES +#include +#include + +struct Limit +{ + double obs; + double exp0p025; + double exp0p16; + double exp0p5; + double exp0p84; + double exp0p975; +}; + + +const bool _info = true; +const bool _debug = false; + +/* +const float lumi = 5; +//Axis +const float axisTitleSize = 0.06; +const float axisTitleOffset = .8; + +const float axisTitleSizeRatioX = 0.18; +const float axisLabelSizeRatioX = 0.12; +const float axisTitleOffsetRatioX = 0.94; + +const float axisTitleSizeRatioY = 0.15; +const float axisLabelSizeRatioY = 0.108; +const float axisTitleOffsetRatioY = 0.32; + +//Margins +const float leftMargin = 0.12; +const float rightMargin = 0.05; +const float topMargin = 0.07; +const float bottomMargin = 0.12; + +//CMS STANDARD +TString CMSText = "CMS"; +//TString extraText = ""; +TString extraText = "Preliminary"; +//TString lumiText = "2.32 fb^{-1} (13 TeV)"; +//TString lumiText = "35.9 fb^{-1} (13 TeV)"; +TString lumiText = "16.2 fb^{-1} (13 TeV)"; +*/ +bool AddCMS( TCanvas* C ); + +int main( int argc, char** argv ) +{ + + //----------------- + //Input File List + //----------------- + std::string inputFile = ParseCommandLine( argc, argv, "-inputFile=" ); + if ( inputFile == "" ) + { + std::cerr << "[ERROR]: please provide an inputList. Use --inputFile=" << std::endl; + return -1; + } + //std::ifstream ifs ( inputList.c_str(), std::ifstream::in );//input file list + + //---------------------- + //validation region name + //---------------------- + std::string vrName = ParseCommandLine( argc, argv, "-vrName=" ); + if ( vrName == "" ) + { + std::cerr << "[ERROR]: please provide validation region name. Use --vrName=" << std::endl; + return -1; + } + + + if( _info ) + { + std::cout << "[INFO]: input file: " << inputFile << std::endl; + std::cout << "[INFO]: validation region name: " << vrName << std::endl; + } + + //----------------- + //Getting ROOT file + //----------------- + TFile* fin = new TFile( inputFile.c_str(), "READ"); + + //---------------------------------------------------------- + //GETTING PRE-FIT RESULTS FROM COMBINE + //---------------------------------------------------------- + //--------------------- + //TwoEleDY + //--------------------- + TDirectory* dir_prefit_two_ee_dy = (TDirectory*)(((TDirectory*)fin->Get("shapes_prefit"))->Get("TwoEleDY")); + TH1F* light_two_ee_dy = (TH1F*)dir_prefit_two_ee_dy->Get("light"); + TH1F* heavy_two_ee_dy = (TH1F*)dir_prefit_two_ee_dy->Get("heavy"); + TH1F* other_two_ee_dy = (TH1F*)dir_prefit_two_ee_dy->Get("other"); + TH1F* bkg_total_two_ee_dy = (TH1F*)dir_prefit_two_ee_dy->Get("total_background"); + TH1F* signal_two_ee_dy = (TH1F*)dir_prefit_two_ee_dy->Get("total_signal"); + TGraphAsymmErrors* data_two_ee_dy = (TGraphAsymmErrors*)dir_prefit_two_ee_dy->Get("data"); + + THStack* stack_two_ee_dy = new THStack( "two_ee_dy_prefit" , "two_ee_dy combine-prefit" ); + create_stack( stack_two_ee_dy, light_two_ee_dy, heavy_two_ee_dy, other_two_ee_dy); + create_ratio_plot(data_two_ee_dy, stack_two_ee_dy, bkg_total_two_ee_dy, + Form("two_ee_dy_prefit_%s",vrName.c_str()), light_two_ee_dy, heavy_two_ee_dy, other_two_ee_dy); + + //--------------------- + //TwoMuDY + //--------------------- + TDirectory* dir_prefit_two_mumu_dy = (TDirectory*)(((TDirectory*)fin->Get("shapes_prefit"))->Get("TwoMuDY")); + TH1F* light_two_mumu_dy = (TH1F*)dir_prefit_two_mumu_dy->Get("light"); + TH1F* heavy_two_mumu_dy = (TH1F*)dir_prefit_two_mumu_dy->Get("heavy"); + TH1F* other_two_mumu_dy = (TH1F*)dir_prefit_two_mumu_dy->Get("other"); + TH1F* bkg_total_two_mumu_dy = (TH1F*)dir_prefit_two_mumu_dy->Get("total_background"); + TH1F* signal_two_mumu_dy = (TH1F*)dir_prefit_two_mumu_dy->Get("total_signal"); + TGraphAsymmErrors* data_two_mumu_dy = (TGraphAsymmErrors*)dir_prefit_two_mumu_dy->Get("data"); + + THStack* stack_two_mumu_dy = new THStack( "two_mumu_dy_prefit" , "two_mumu_dy combine-prefit" ); + create_stack( stack_two_mumu_dy, light_two_mumu_dy, heavy_two_mumu_dy, other_two_mumu_dy); + create_ratio_plot(data_two_mumu_dy, stack_two_mumu_dy, bkg_total_two_mumu_dy, + Form("two_mumu_dy_prefit_%s",vrName.c_str()), light_two_mumu_dy, heavy_two_mumu_dy, other_two_mumu_dy); + + //--------------------- + //EleMu + //--------------------- + TDirectory* dir_prefit_elemu_dy = (TDirectory*)(((TDirectory*)fin->Get("shapes_prefit"))->Get("EleMu")); + TH1F* light_elemu_dy = (TH1F*)dir_prefit_elemu_dy->Get("light"); + TH1F* heavy_elemu_dy = (TH1F*)dir_prefit_elemu_dy->Get("heavy"); + TH1F* other_elemu_dy = (TH1F*)dir_prefit_elemu_dy->Get("other"); + TH1F* bkg_total_elemu_dy = (TH1F*)dir_prefit_elemu_dy->Get("total_background"); + TH1F* signal_elemu_dy = (TH1F*)dir_prefit_elemu_dy->Get("total_signal"); + TGraphAsymmErrors* data_elemu_dy = (TGraphAsymmErrors*)dir_prefit_elemu_dy->Get("data"); + + THStack* stack_elemu_dy = new THStack( "elemu_dy_prefit" , "elemu_dy combine-prefit" ); + create_stack( stack_elemu_dy, light_elemu_dy, heavy_elemu_dy, other_elemu_dy); + create_ratio_plot(data_elemu_dy, stack_elemu_dy, bkg_total_elemu_dy, + Form("elemu_dy_prefit_%s",vrName.c_str()), light_elemu_dy, heavy_elemu_dy, other_elemu_dy); + + //--------------------- + //EleMuL + //--------------------- + TDirectory* dir_prefit_elemul_dy = (TDirectory*)(((TDirectory*)fin->Get("shapes_prefit"))->Get("EleMuL")); + TH1F* light_elemul_dy = (TH1F*)dir_prefit_elemul_dy->Get("light"); + TH1F* heavy_elemul_dy = (TH1F*)dir_prefit_elemul_dy->Get("heavy"); + TH1F* other_elemul_dy = (TH1F*)dir_prefit_elemul_dy->Get("other"); + TH1F* bkg_total_elemul_dy = (TH1F*)dir_prefit_elemul_dy->Get("total_background"); + TH1F* signal_elemul_dy = (TH1F*)dir_prefit_elemul_dy->Get("total_signal"); + TGraphAsymmErrors* data_elemul_dy = (TGraphAsymmErrors*)dir_prefit_elemul_dy->Get("data"); + + THStack* stack_elemul_dy = new THStack( "elemul_dy_prefit" , "elemul_dy combine-prefit" ); + create_stack( stack_elemul_dy, light_elemul_dy, heavy_elemul_dy, other_elemul_dy); + create_ratio_plot(data_elemul_dy, stack_elemul_dy, bkg_total_elemul_dy, + Form("elemul_dy_prefit_%s",vrName.c_str()), light_elemul_dy, heavy_elemul_dy, other_elemul_dy); + + //--------------------- + //TwoEleZH + //--------------------- + TDirectory* dir_prefit_two_ee_zh = (TDirectory*)(((TDirectory*)fin->Get("shapes_prefit"))->Get("TwoEleZH")); + TH1F* light_two_ee_zh = (TH1F*)dir_prefit_two_ee_zh->Get("light"); + TH1F* heavy_two_ee_zh = (TH1F*)dir_prefit_two_ee_zh->Get("heavy"); + TH1F* other_two_ee_zh = (TH1F*)dir_prefit_two_ee_zh->Get("other"); + TH1F* bkg_total_two_ee_zh = (TH1F*)dir_prefit_two_ee_zh->Get("total_background"); + TH1F* signal_two_ee_zh = (TH1F*)dir_prefit_two_ee_zh->Get("total_signal"); + TGraphAsymmErrors* data_two_ee_zh = (TGraphAsymmErrors*)dir_prefit_two_ee_zh->Get("data"); + + THStack* stack_two_ee_zh = new THStack( "two_ee_zh_prefit" , "two_ee_zh combine-prefit" ); + create_stack( stack_two_ee_zh, light_two_ee_zh, heavy_two_ee_zh, other_two_ee_zh); + create_ratio_plot(data_two_ee_zh, stack_two_ee_zh, bkg_total_two_ee_zh, + Form("two_ee_zh_prefit_%s",vrName.c_str()), light_two_ee_zh, heavy_two_ee_zh, other_two_ee_zh); + + //--------------------- + //TwoMuZH + //--------------------- + TDirectory* dir_prefit_two_mumu_zh = (TDirectory*)(((TDirectory*)fin->Get("shapes_prefit"))->Get("TwoMuZH")); + TH1F* light_two_mumu_zh = (TH1F*)dir_prefit_two_mumu_zh->Get("light"); + TH1F* heavy_two_mumu_zh = (TH1F*)dir_prefit_two_mumu_zh->Get("heavy"); + TH1F* other_two_mumu_zh = (TH1F*)dir_prefit_two_mumu_zh->Get("other"); + TH1F* bkg_total_two_mumu_zh = (TH1F*)dir_prefit_two_mumu_zh->Get("total_background"); + TH1F* signal_two_mumu_zh = (TH1F*)dir_prefit_two_mumu_zh->Get("total_signal"); + TGraphAsymmErrors* data_two_mumu_zh = (TGraphAsymmErrors*)dir_prefit_two_mumu_zh->Get("data"); + + THStack* stack_two_mumu_zh = new THStack( "two_mumu_zh_prefit" , "two_mumu_zh combine-prefit" ); + create_stack( stack_two_mumu_zh, light_two_mumu_zh, heavy_two_mumu_zh, other_two_mumu_zh); + create_ratio_plot(data_two_mumu_zh, stack_two_mumu_zh, bkg_total_two_mumu_zh, + Form("two_mumu_zh_prefit_%s",vrName.c_str()), light_two_mumu_zh, heavy_two_mumu_zh, other_two_mumu_zh); + + + //---------------------------------------------------------- + //GETTING POST-FIT RESULTS FROM COMBINE + //---------------------------------------------------------- + //--------------------- + //TwoEleDY + //--------------------- + TDirectory* dir_postfit_two_ee_dy = (TDirectory*)(((TDirectory*)fin->Get("shapes_fit_b"))->Get("TwoEleDY")); + TH1F* light_two_ee_dy_pf = (TH1F*)dir_postfit_two_ee_dy->Get("light"); + TH1F* heavy_two_ee_dy_pf = (TH1F*)dir_postfit_two_ee_dy->Get("heavy"); + TH1F* other_two_ee_dy_pf = (TH1F*)dir_postfit_two_ee_dy->Get("other"); + TH1F* bkg_total_two_ee_dy_pf = (TH1F*)dir_postfit_two_ee_dy->Get("total_background"); + TH1F* signal_two_ee_dy_pf = (TH1F*)dir_postfit_two_ee_dy->Get("total_signal"); + TGraphAsymmErrors* data_two_ee_dy_pf = (TGraphAsymmErrors*)dir_postfit_two_ee_dy->Get("data"); + + THStack* stack_two_ee_dy_pf = new THStack( "two_ee_dy_postfit" , "two_ee_dy combine-postfit" ); + create_stack( stack_two_ee_dy_pf, light_two_ee_dy_pf, heavy_two_ee_dy_pf, other_two_ee_dy_pf); + create_ratio_plot(data_two_ee_dy_pf, stack_two_ee_dy_pf, bkg_total_two_ee_dy_pf, + Form("two_ee_dy_postfit_%s",vrName.c_str()), light_two_ee_dy_pf, heavy_two_ee_dy_pf, other_two_ee_dy_pf); + + //--------------------- + //TwoMuDY + //--------------------- + TDirectory* dir_postfit_two_mumu_dy = (TDirectory*)(((TDirectory*)fin->Get("shapes_fit_b"))->Get("TwoMuDY")); + TH1F* light_two_mumu_dy_pf = (TH1F*)dir_postfit_two_mumu_dy->Get("light"); + TH1F* heavy_two_mumu_dy_pf = (TH1F*)dir_postfit_two_mumu_dy->Get("heavy"); + TH1F* other_two_mumu_dy_pf = (TH1F*)dir_postfit_two_mumu_dy->Get("other"); + TH1F* bkg_total_two_mumu_dy_pf = (TH1F*)dir_postfit_two_mumu_dy->Get("total_background"); + TH1F* signal_two_mumu_dy_pf = (TH1F*)dir_postfit_two_mumu_dy->Get("total_signal"); + TGraphAsymmErrors* data_two_mumu_dy_pf = (TGraphAsymmErrors*)dir_postfit_two_mumu_dy->Get("data"); + + THStack* stack_two_mumu_dy_pf = new THStack( "two_mumu_dy_postfit" , "two_mumu_dy combine-postfit" ); + create_stack( stack_two_mumu_dy_pf, light_two_mumu_dy_pf, heavy_two_mumu_dy_pf, other_two_mumu_dy_pf); + create_ratio_plot(data_two_mumu_dy_pf, stack_two_mumu_dy_pf, bkg_total_two_mumu_dy_pf, + Form("two_mumu_dy_postfit_%s",vrName.c_str()), light_two_mumu_dy_pf, heavy_two_mumu_dy_pf, other_two_mumu_dy_pf); + + //--------------------- + //EleMu + //--------------------- + TDirectory* dir_postfit_elemu_dy = (TDirectory*)(((TDirectory*)fin->Get("shapes_fit_b"))->Get("EleMu")); + TH1F* light_elemu_dy_pf = (TH1F*)dir_postfit_elemu_dy->Get("light"); + TH1F* heavy_elemu_dy_pf = (TH1F*)dir_postfit_elemu_dy->Get("heavy"); + TH1F* other_elemu_dy_pf = (TH1F*)dir_postfit_elemu_dy->Get("other"); + TH1F* bkg_total_elemu_dy_pf = (TH1F*)dir_postfit_elemu_dy->Get("total_background"); + TH1F* signal_elemu_dy_pf = (TH1F*)dir_postfit_elemu_dy->Get("total_signal"); + TGraphAsymmErrors* data_elemu_dy_pf = (TGraphAsymmErrors*)dir_postfit_elemu_dy->Get("data"); + + THStack* stack_elemu_dy_pf = new THStack( "elemu_dy_postfit" , "elemu_dy combine-postfit" ); + create_stack( stack_elemu_dy_pf, light_elemu_dy_pf, heavy_elemu_dy_pf, other_elemu_dy_pf); + create_ratio_plot(data_elemu_dy_pf, stack_elemu_dy_pf, bkg_total_elemu_dy_pf, + Form("elemu_dy_postfit_%s",vrName.c_str()), light_elemu_dy_pf, heavy_elemu_dy_pf, other_elemu_dy_pf); + + //--------------------- + //EleMuL + //--------------------- + TDirectory* dir_postfit_elemul_dy = (TDirectory*)(((TDirectory*)fin->Get("shapes_fit_b"))->Get("EleMuL")); + TH1F* light_elemul_dy_pf = (TH1F*)dir_postfit_elemul_dy->Get("light"); + TH1F* heavy_elemul_dy_pf = (TH1F*)dir_postfit_elemul_dy->Get("heavy"); + TH1F* other_elemul_dy_pf = (TH1F*)dir_postfit_elemul_dy->Get("other"); + TH1F* bkg_total_elemul_dy_pf = (TH1F*)dir_postfit_elemul_dy->Get("total_background"); + TH1F* signal_elemul_dy_pf = (TH1F*)dir_postfit_elemul_dy->Get("total_signal"); + TGraphAsymmErrors* data_elemul_dy_pf = (TGraphAsymmErrors*)dir_postfit_elemul_dy->Get("data"); + + THStack* stack_elemul_dy_pf = new THStack( "elemul_dy_postfit" , "elemul_dy combine-postfit" ); + create_stack( stack_elemul_dy_pf, light_elemul_dy_pf, heavy_elemul_dy_pf, other_elemul_dy_pf); + create_ratio_plot(data_elemul_dy_pf, stack_elemul_dy_pf, bkg_total_elemul_dy_pf, + Form("elemul_dy_postfit_%s",vrName.c_str()), light_elemul_dy_pf, heavy_elemul_dy_pf, other_elemul_dy_pf); + + //--------------------- + //TwoEleZH + //--------------------- + TDirectory* dir_postfit_two_ee_zh = (TDirectory*)(((TDirectory*)fin->Get("shapes_fit_b"))->Get("TwoEleZH")); + TH1F* light_two_ee_zh_pf = (TH1F*)dir_postfit_two_ee_zh->Get("light"); + TH1F* heavy_two_ee_zh_pf = (TH1F*)dir_postfit_two_ee_zh->Get("heavy"); + TH1F* other_two_ee_zh_pf = (TH1F*)dir_postfit_two_ee_zh->Get("other"); + TH1F* bkg_total_two_ee_zh_pf = (TH1F*)dir_postfit_two_ee_zh->Get("total_background"); + TH1F* signal_two_ee_zh_pf = (TH1F*)dir_postfit_two_ee_zh->Get("total_signal"); + TGraphAsymmErrors* data_two_ee_zh_pf = (TGraphAsymmErrors*)dir_postfit_two_ee_zh->Get("data"); + + THStack* stack_two_ee_zh_pf = new THStack( "two_ee_zh_postfit" , "two_ee_zh combine-postfit" ); + create_stack( stack_two_ee_zh_pf, light_two_ee_zh_pf, heavy_two_ee_zh_pf, other_two_ee_zh_pf); + create_ratio_plot(data_two_ee_zh_pf, stack_two_ee_zh_pf, bkg_total_two_ee_zh_pf, + Form("two_ee_zh_postfit_%s",vrName.c_str()), light_two_ee_zh_pf, heavy_two_ee_zh_pf, other_two_ee_zh_pf); + + //--------------------- + //TwoMuZH + //--------------------- + TDirectory* dir_postfit_two_mumu_zh = (TDirectory*)(((TDirectory*)fin->Get("shapes_fit_b"))->Get("TwoMuZH")); + TH1F* light_two_mumu_zh_pf = (TH1F*)dir_postfit_two_mumu_zh->Get("light"); + TH1F* heavy_two_mumu_zh_pf = (TH1F*)dir_postfit_two_mumu_zh->Get("heavy"); + TH1F* other_two_mumu_zh_pf = (TH1F*)dir_postfit_two_mumu_zh->Get("other"); + TH1F* bkg_total_two_mumu_zh_pf = (TH1F*)dir_postfit_two_mumu_zh->Get("total_background"); + TH1F* signal_two_mumu_zh_pf = (TH1F*)dir_postfit_two_mumu_zh->Get("total_signal"); + TGraphAsymmErrors* data_two_mumu_zh_pf = (TGraphAsymmErrors*)dir_postfit_two_mumu_zh->Get("data"); + + THStack* stack_two_mumu_zh_pf = new THStack( "two_mumu_zh_postfit" , "two_mumu_zh combine-postfit" ); + create_stack( stack_two_mumu_zh_pf, light_two_mumu_zh_pf, heavy_two_mumu_zh_pf, other_two_mumu_zh_pf); + create_ratio_plot(data_two_mumu_zh_pf, stack_two_mumu_zh_pf, bkg_total_two_mumu_zh_pf, + Form("two_mumu_zh_postfit_%s",vrName.c_str()), light_two_mumu_zh_pf, heavy_two_mumu_zh_pf, other_two_mumu_zh_pf); + + /* + TCanvas* c = new TCanvas( "c", "c", 2119, 33, 800, 700 ); + c->SetHighLightColor(2); + c->SetFillColor(0); + c->SetBorderMode(0); + c->SetBorderSize(2); + c->SetLeftMargin( leftMargin ); + c->SetRightMargin( rightMargin ); + c->SetTopMargin( topMargin ); + c->SetBottomMargin( bottomMargin ); + c->SetFrameBorderMode(0); + c->SetFrameBorderMode(0); + //c->SetLogy(); + //c->SetLogx(); + + stack_two_ee_dy->Draw(); + data_two_ee_dy->Draw("P"); + + gStyle->SetPaintTextFormat("4.3f"); + + TLegend* leg = new TLegend( 0.51, 0.75-5*0.065, 0.85, 0.75-0.05, NULL, "brNDC" ); + leg->SetBorderSize(0); + leg->SetLineColor(1); + leg->SetLineStyle(1); + leg->SetLineWidth(1); + leg->SetFillColor(0); + leg->SetFillStyle(1001); + leg->SetTextSize(0.04); + + //leg->AddEntry( gTheory, " NLO+NNL theory", "l"); + //leg->AddEntry( gObs, " Observed limit (95% CL)", "l" ); + //leg->AddEntry( gExp, " Median expected limit", "l" ); + //leg->AddEntry( gOneS, " 68% expected", "f" ); + //leg->AddEntry( gTwoS, " 95% expected", "f" ); + //leg->Draw("SAME"); + + //95% CL label + float cmsx = 0.81; + float cmsy = 0.63-0.05; + float cmsSize = 0.04; + float cmsTextFont = 41; // default is helvetic-bold + TLatex latex; + latex.SetNDC(); + latex.SetTextAngle(0); + latex.SetTextColor(kBlack); + latex.SetTextAlign(31); + latex.SetTextSize(cmsSize); + latex.SetTextFont(cmsTextFont); + //latex.DrawLatex(cmsx, cmsy, "95% CL upper limits"); + + TLatex latex2; + cmsx = 0.29; + cmsy = 0.88; + latex2.SetNDC(); + latex2.SetTextSize(0.038); + latex2.SetTextFont(42); + //HH + //latex2.DrawLatex(cmsx, cmsy, "pp #rightarrow #tilde{#chi}^{0,#pm}_{i} #tilde{#chi}^{0,#pm}_{j} #rightarrow #tilde{#chi}^{0}_{1} #tilde{#chi}^{0}_{1} + X_{soft}; #tilde{#chi}^{0}_{1} #rightarrow H #tilde{G} (100%)"); + //latex2.DrawLatex(cmsx+0.263, cmsy-0.07, "m_{#tilde{#chi}^{0}_{2}} #approx m_{#tilde{#chi}^{#pm}_{1}} #approx m_{#tilde{#chi}^{0}_{1}}; m_{#tilde{G}} = 1 GeV"); + //HZ + //latex2.DrawLatex(cmsx, cmsy, "pp #rightarrow #tilde{#chi}^{0,#pm}_{i} #tilde{#chi}^{0,#pm}_{j} #rightarrow #tilde{#chi}^{0}_{1} #tilde{#chi}^{0}_{1} + X_{soft}; #tilde{#chi}^{0}_{1} #rightarrow H #tilde{G} (50%)"); + latex2.DrawLatex(cmsx+0.15, cmsy, "pp #rightarrow ZH #rightarrow Z #chi^{0}#chi^{0}; #chi}^{0} #rightarrow b#bar{b} (85%)"); + latex2.DrawLatex(cmsx+0.455, cmsy-0.07, "m_{#chi^{0}} = 40 GeV"); + //latex2.DrawLatex(cmsx+0.25, cmsy-0.13, "m_{#tilde{#chi}^{0}_{2}} #approx m_{#tilde{#chi}^{#pm}_{1}} #approx m_{#tilde{#chi}^{0}_{1}}; m_{#tilde{G}} = 1 GeV"); + //1D WH + //latex2.DrawLatex(cmsx+0.15, cmsy, "pp #rightarrow #tilde{#chi}^{#pm}_{1} #tilde{#chi}^{0}_{2} ; #tilde{#chi}^{#pm}_{1} #rightarrow W^{#pm} #tilde{#chi}^{0}_{1}, #tilde{#chi}^{0}_{2} #rightarrow H #tilde{#chi}^{0}_{1}"); + //std::cout << "hola " << latex2.GetTextFont() << std::endl; + TLatex latex3; + latex3.SetNDC(); + latex3.SetTextSize(0.038); + latex3.SetTextFont(42); + //latex2.DrawLatex(0.2, 0.66, "#bf{EWP Analysis}"); + AddCMS(c); + + //c->SetLogx(); + c->SaveAs("NarrowResLimit_BIAS_fix.pdf"); + c->SaveAs("NarrowResLimit_BIAS_fix.C"); + + //gObs->GetXaxis()->SetRangeUser(0, 30); + //gObs->Write("gObs"); + //gExp->GetXaxis()->SetRangeUser(0, 30); + //gExp->Write("gExp"); + //gOneS->Write("gOneS"); + //gTwoS->Write("gTwoS"); + + //out->Close(); + */ + return 0; +} diff --git a/plotting/include/helper_functions.hh b/plotting/include/helper_functions.hh new file mode 100644 index 0000000..44f54cf --- /dev/null +++ b/plotting/include/helper_functions.hh @@ -0,0 +1,16 @@ +#ifndef HELPER_FUNCTIONS_HH +#define HELPER_FUNCTIONS_HH +#include +#include +#include +#include +#include +#include + +bool create_stack(THStack* stack, TH1F* light, TH1F* heavy, TH1F* other); +bool create_ratio_plot(TGraphAsymmErrors* data, THStack* stack, TH1F* total_bkg, + TString plot_name, TH1F* light, TH1F* heavy, TH1F* other); +bool AddCMS( TCanvas* C ); + + +#endif diff --git a/plotting/src/helper_functions.cc b/plotting/src/helper_functions.cc new file mode 100644 index 0000000..e20ee71 --- /dev/null +++ b/plotting/src/helper_functions.cc @@ -0,0 +1,283 @@ +#include +#include +#include + +//------------------------ +//CMS COSMETICS DEFINITION +//------------------------ +const float lumi = 5; +//Axis +const float axisTitleSize = 0.06; +const float axisTitleOffset = .8; + +const float axisTitleSizeRatioX = 0.18; +const float axisLabelSizeRatioX = 0.12; +const float axisTitleOffsetRatioX = 0.94; + +const float axisTitleSizeRatioY = 0.15; +const float axisLabelSizeRatioY = 0.108; +const float axisTitleOffsetRatioY = 0.32; + +//Margins +const float leftMargin = 0.12; +const float rightMargin = 0.05; +const float topMargin = 0.07; +const float bottomMargin = 0.12; + +//CMS STANDARD +TString CMSText = "CMS"; +//TString extraText = ""; +TString extraText = "Preliminary"; +//TString lumiText = "2.32 fb^{-1} (13 TeV)"; +//TString lumiText = "35.9 fb^{-1} (13 TeV)"; +TString lumiText = "16.2 fb^{-1} (13 TeV)"; + + +bool create_stack(THStack* stack, TH1F* light, TH1F* heavy, TH1F* other) +{ + //cosmetics for light + light->SetFillColor(kGreen-3); + light->SetLineColor(kGreen-3); + //cosmetics for heavy + heavy->SetFillColor(kMagenta-4); + heavy->SetLineColor(kMagenta-4); + //cosmetics for other + other->SetFillColor(kAzure-4); + other->SetLineColor(kAzure-4); + + stack->Add( other, "histo" ); + stack->Add( heavy, "histo" ); + stack->Add( light, "histo" ); + + //stack cosmetics + stack->SetTitle(""); + return true; +}; + +bool create_ratio_plot(TGraphAsymmErrors* data, THStack* stack, TH1F* total_bkg, + TString plot_name, TH1F* light, TH1F* heavy, TH1F* other) +{ + //cosmetics for data + data->SetLineColor(kBlack); + data->SetMarkerColor(kBlack); + data->SetLineWidth(2); + data->SetMarkerSize(1.5); + data->SetMarkerStyle(20); + + + TCanvas* c = new TCanvas( "c", "c", 2119, 33, 800, 700 ); + c->SetHighLightColor(2); + c->SetFillColor(0); + c->SetBorderMode(0); + c->SetBorderSize(2); + c->SetLeftMargin( leftMargin ); + c->SetRightMargin( rightMargin ); + c->SetTopMargin( topMargin ); + c->SetBottomMargin( bottomMargin ); + c->SetFrameBorderMode(0); + c->SetFrameBorderMode(0); + c->cd(); + + TPad *pad1 = new TPad("pad1","pad1", 0.0, 0.3, 1., 1.); + pad1->SetBottomMargin(0); + pad1->SetRightMargin( rightMargin ); + pad1->SetLeftMargin( leftMargin ); + pad1->Draw(); + pad1->cd(); + + stack->Draw(); + stack->SetMinimum(1e-3); + //Get maximum for data and compare to max in bkg histo + double x_b0,y_b0; + if(data->GetPoint(0,x_b0,y_b0) > total_bkg->GetBinContent(1)) + { + stack->SetMaximum(1000.*y_b0); + } + else + { + stack->SetMaximum(1000.*total_bkg->GetBinContent(1)); + } + + data->Draw("P"); + pad1->SetLogy(); + + //----------------- + //Legend + //------------------ + TLegend* leg = new TLegend( 0.73, 0.65, 0.93, 0.88, NULL, "brNDC" ); + leg->SetBorderSize(0); + leg->SetLineColor(1); + leg->SetLineStyle(1); + leg->SetLineWidth(1); + leg->SetFillColor(0); + leg->SetFillStyle(1001); + leg->SetTextSize(0.04); + leg->AddEntry( data, " data", "lep" ); + leg->AddEntry( light, " Z/#gamma^{*}", "f" ); + leg->AddEntry( heavy, " t#bar{t}+t", "f" ); + leg->AddEntry( other, " other", "f" ); + + leg->Draw(); + + + //------------------ + //Ratio Plot + //------------------ + c->cd(); + TPad *pad2 = new TPad("pad2","pad2", .0, 0.0, 1., 0.29); + pad2->SetTopMargin(0.04); + pad2->SetTopMargin(0.008); + pad2->SetBottomMargin(0.4); + pad2->SetRightMargin( rightMargin ); + pad2->SetLeftMargin( leftMargin ); + pad2->SetGridy(); + pad2->Draw(); + pad2->cd(); + + TH1F* data_hist = new TH1F("data_hist", "data_hist", 3, -0.5,2.5); + for(int i = 0; i < data_hist->GetNbinsX(); i++) + { + double x,y; + data->GetPoint(i,x,y); + data_hist->SetBinContent(i+1, y); + } + TH1F* ratio = new TH1F( *data_hist ); + ratio->Divide( total_bkg ); + //Set Uncertainty to only the poisson, remove the one from bkg + for ( int i = 1; i <= ratio->GetNbinsX(); i++ ) + { + double rel_unc = data_hist->GetBinError(i)/data_hist->GetBinContent(i); + ratio->SetBinError(i,rel_unc); + } + ratio->SetMarkerStyle( 20 ); + ratio->SetMarkerSize( 1.0 ); + ratio->GetXaxis()->SetTitleSize( axisTitleSizeRatioX ); + ratio->GetXaxis()->SetLabelSize( axisLabelSizeRatioX ); + ratio->GetXaxis()->SetTitleOffset( axisTitleOffsetRatioX ); + ratio->GetYaxis()->SetTitleSize( axisTitleSizeRatioY ); + ratio->GetYaxis()->SetLabelSize( axisLabelSizeRatioY ); + ratio->GetYaxis()->SetTitleOffset( axisTitleOffsetRatioY ); + ratio->SetMarkerColor( kBlack ); + ratio->SetLineColor( kBlack ); + ratio->SetLineWidth( 2 ); + ratio->GetYaxis()->SetRangeUser( 0.4, 1.6 ); + ratio->SetTitle(""); + ratio->GetYaxis()->SetTitle("data / mc"); + ratio->GetXaxis()->SetTitle("nJet_{tags}"); + ratio->GetYaxis()->CenterTitle( true ); + ratio->GetYaxis()->SetNdivisions( 10, false ); + ratio->SetStats( 0 ); + ratio->Draw("E1"); + + + + TH1F* ratio2 = new TH1F( *data_hist ); + TH1F* ratio3 = new TH1F( *data_hist ); + //Set Uncertainty to only the poisson, remove the one from bkg + for ( int i = 1; i <= ratio2->GetNbinsX(); i++ ) + { + ratio2->SetBinContent(i,1.0); + double rel_unc = total_bkg->GetBinError(i)/total_bkg->GetBinContent(i); + ratio2->SetBinError(i,rel_unc); + + ratio3->SetBinContent(i,1.0); + //ratio3->SetBinError(i,0.0); + } + //ratio2->SetMarkerStyle( 20 ); + //ratio2->SetMarkerSize( 1.5 ); + ratio2->GetXaxis()->SetTitleSize( axisTitleSizeRatioX ); + ratio2->GetXaxis()->SetLabelSize( axisLabelSizeRatioX ); + ratio2->GetXaxis()->SetTitleOffset( axisTitleOffsetRatioX ); + ratio2->GetYaxis()->SetTitleSize( axisTitleSizeRatioY ); + ratio2->GetYaxis()->SetLabelSize( axisLabelSizeRatioY ); + ratio2->GetYaxis()->SetTitleOffset( axisTitleOffsetRatioY ); + ratio2->SetMarkerColor( kBlue ); + ratio2->SetLineColor( kBlue ); + ratio2->SetFillColorAlpha(kBlue-9, 0.35); + //ratio2->SetFillColor( kBlue-9 ); + ratio2->SetLineWidth( 2 ); + ratio2->GetYaxis()->SetRangeUser( 0.4, 1.6 ); + ratio2->SetTitle(""); + ratio2->GetYaxis()->SetTitle("data / mc"); + ratio2->GetXaxis()->SetTitle("nJet_{tags}"); + ratio2->GetYaxis()->CenterTitle( true ); + ratio2->GetYaxis()->SetNdivisions( 10, false ); + ratio2->SetStats( 0 ); + + //ratio3->SetMarkerStyle( 20 ); + //ratio3->SetMarkerSize( 1.5 ); + ratio3->GetXaxis()->SetTitleSize( axisTitleSizeRatioX ); + ratio3->GetXaxis()->SetLabelSize( axisLabelSizeRatioX ); + ratio3->GetXaxis()->SetTitleOffset( axisTitleOffsetRatioX ); + ratio3->GetYaxis()->SetTitleSize( axisTitleSizeRatioY ); + ratio3->GetYaxis()->SetLabelSize( axisLabelSizeRatioY ); + ratio3->GetYaxis()->SetTitleOffset( axisTitleOffsetRatioY ); + ratio3->SetMarkerColor( kBlue ); + ratio3->SetLineColor( kBlue ); + //ratio3->SetFillColorAlpha(kBlue-9, 0.35); + //ratio2->SetFillColor( kBlue-9 ); + ratio3->SetLineWidth( 2 ); + ratio3->GetYaxis()->SetRangeUser( 0.4, 1.6 ); + ratio3->SetTitle(""); + ratio3->GetYaxis()->SetTitle("data / mc"); + ratio3->GetXaxis()->SetTitle("nJet_{tags}"); + ratio3->GetYaxis()->CenterTitle( true ); + ratio3->GetYaxis()->SetNdivisions( 10, false ); + ratio3->SetStats( 0 ); + + + ratio3->Draw("HIST"); + ratio2->Draw("E2+SAME"); + ratio->Draw("E1+SAME"); + + c->SaveAs(plot_name+".pdf"); + c->SaveAs(plot_name+".C"); + + for ( int i = 1; i <= ratio2->GetNbinsX(); i++ ) + { + std::cout << "ratio bin " << i << " :" << ratio->GetBinContent(i) << std::endl; + } + return true; +}; + + + +bool AddCMS( TCanvas* C ) +{ + C->cd(); + float lumix = 0.955; + float lumiy = 0.945; + float lumifont = 42; + + float cmsx = 0.25; + float cmsy = 0.94; + float cmsTextFont = 61; // default is helvetic-bold + float extrax = cmsx +0.20; + float extray = cmsy; + //float extrax = cmsx + 0.078; + //float extray = cmsy - 0.04; + float extraTextFont = 52; // default is helvetica-italics + // ratio of "CMS" and extra text size + float extraOverCmsTextSize = 0.76; + float cmsSize = 0.06; + TLatex latex; + latex.SetNDC(); + latex.SetTextAngle(0); + latex.SetTextColor(kBlack); + float extraTextSize = extraOverCmsTextSize*cmsSize; + latex.SetTextFont(lumifont); + latex.SetTextAlign(31); + latex.SetTextSize(cmsSize); + latex.DrawLatex(lumix, lumiy,lumiText); + + latex.SetTextFont(cmsTextFont); + latex.SetTextAlign(31); + latex.SetTextSize(cmsSize); + latex.DrawLatex(cmsx, cmsy, CMSText); + + latex.SetTextFont(extraTextFont); + latex.SetTextAlign(31); + latex.SetTextSize(extraTextSize); + latex.DrawLatex(extrax, extray, extraText); + return true; +};