diff --git a/include/types.h b/include/types.h index a7d024e..c69d2e3 100644 --- a/include/types.h +++ b/include/types.h @@ -283,6 +283,7 @@ namespace plotIt { bool no_data = false; bool override = false; // flag to plot only those which have it true (if at least one plot has it true) bool normalized = false; + bool normalizedByBinWidth = false; bool log_y = false; bool log_x = false; diff --git a/include/utilities.h b/include/utilities.h index f27ee53..e6361db 100644 --- a/include/utilities.h +++ b/include/utilities.h @@ -50,8 +50,25 @@ namespace plotIt { float binSize = object->GetXaxis()->GetBinWidth(1); std::string title = plot.y_axis; - boost::format formatter = get_formatter(plot.y_axis_format); - object->GetYaxis()->SetTitle((formatter % title % binSize).str().c_str()); + bool isEquidistantBinning = true; + for(int i = 2; i <= object->GetXaxis()->GetNbins(); ++i) { + if(object->GetXaxis()->GetBinWidth(1)!=object->GetXaxis()->GetBinWidth(i)) + isEquidistantBinning = false; + } + + if(isEquidistantBinning){ + boost::format formatter = get_formatter(plot.y_axis_format); + object->GetYaxis()->SetTitle((formatter % title % binSize).str().c_str()); + } + else if(plot.normalizedByBinWidth){ + std::string format_string = "%1%/%2%"; + boost::format formatter = get_formatter(format_string); + object->GetYaxis()->SetTitle((formatter % title % "Bin width").str().c_str()); + } + else{ + boost::format formatter = get_formatter(plot.y_axis_format); + object->GetYaxis()->SetTitle((formatter % title % binSize).str().c_str()); + } } if (plot.show_ratio && object->GetXaxis()) diff --git a/src/TH1Plotter.cc b/src/TH1Plotter.cc index 10835f8..f5643a5 100644 --- a/src/TH1Plotter.cc +++ b/src/TH1Plotter.cc @@ -458,6 +458,31 @@ namespace plotIt { computeSystematics(mc_stacks, global_summary); } + if (plot.normalizedByBinWidth) { + // Normalize each plot + for (auto& file: m_plotIt.getFiles()) { + if (file.type == SIGNAL) { + TH1* h = dynamic_cast(file.object); + h->Scale(1.,"width"); + } + } + + if (h_data.get()) { + h_data->Scale(1.,"width"); + } + + std::for_each(mc_stacks.begin(), mc_stacks.end(), [](TH1Plotter::Stacks::value_type& value) { + TIter next(value.second.stack->GetHists()); + TH1* h = nullptr; + while ((h = static_cast(next()))) { + h->Scale(1.,"width"); + } + value.second.stat_and_syst->Scale(1.,"width"); + value.second.syst_only->Scale(1.,"width"); + value.second.stat_only->Scale(1.,"width"); + }); + } + // Store all the histograms to draw, and find the one with the highest maximum std::vector> toDraw = { std::make_pair(h_data.get(), data_drawing_options) }; for (File& signal: signal_files) { diff --git a/src/plotIt.cc b/src/plotIt.cc index f38d2b6..99b2a6c 100644 --- a/src/plotIt.cc +++ b/src/plotIt.cc @@ -619,6 +619,9 @@ namespace plotIt { if (node["normalized"]) plot.normalized = node["normalized"].as(); + if (node["normalizedByBinWidth"]) + plot.normalizedByBinWidth = node["normalizedByBinWidth"].as(); + if (node["no-data"]) plot.no_data = node["no-data"].as();