#include #include #include #include #include #include #include #include #include static inline void RemoveTopic(RooFit::MsgTopic pTopic) { RooMsgService::instance().getStream(0).removeTopic(pTopic); RooMsgService::instance().getStream(1).removeTopic(pTopic); } static inline double GenerateFromPdf(RooAbsPdf& pPdf, RooRealVar& pVar) { RooDataSet* data = pPdf.generate( RooArgSet(pVar), 1, RooFit::AutoBinned(kFALSE)); // this creates the correct distribution if // called often enough const RooArgSet* args = data->get(0); RooRealVar* var = dynamic_cast(args->find(pVar)); double value = var->getVal(); delete data; return value; } struct HistogramWrapper { HistogramWrapper(TH1* pHistogram) : Histogram(pHistogram), Var((std::string("Var_") + pHistogram->GetName()).c_str(), pHistogram->GetTitle(), pHistogram->GetXaxis()->GetXmin(), pHistogram->GetXaxis()->GetXmax()), Data((std::string("Data_") + pHistogram->GetName()).c_str(), pHistogram->GetTitle(), RooArgList(Var), Histogram), Pdf((std::string("Pdf_") + pHistogram->GetName()).c_str(), pHistogram->GetTitle(), RooArgSet(Var), Data) {} double Get() { return GenerateFromPdf(Pdf, Var); } TH1* Histogram; RooRealVar Var; RooDataHist Data; RooHistPdf Pdf; }; int main() { RemoveTopic(RooFit::DataHandling); for (std::size_t index = 0; index < 1e9; ++index) { if (index && index % 10000 == 0) std::cout << index << " of " << 1e9 << std::endl; TH1D hist("hist", "hist", 100, 0, 100); for (std::size_t bin = 1; bin < 101; ++bin) hist.SetBinContent(bin, bin); HistogramWrapper wrapper(&hist); wrapper.Get(); } return 0; }