#ifndef __CINT__ #include "RooGlobalFunc.h" #endif #include "RooRealVar.h" #include "RooDataSet.h" #include "RooDataHist.h" #include "RooGaussian.h" #include "RooConstVar.h" #include "RooCategory.h" #include "TCanvas.h" #include "TAxis.h" #include "TH1F.h" #include "RooPlot.h" #include #include using namespace RooFit ; enum Mode {FINE, FINEV2, FISHY}; void binnedProjections(int mode=FISHY) { if(mode!=FINE && mode != FISHY && mode!=FINEV2) { cout << "Proved FINE, FINEV2 or FISHY as argument" << endl; return; } //define variables and categories RooRealVar x("x","x",-3,3) ; RooCategory c("c","c") ; c.defineType("g"); c.defineType("l"); //build a combined dataset TH1F *h1=new TH1F("h1","h1",100,-3,3); h1->FillRandom("gaus",5000); h1->Sumw2(); h1->SetFillColor(kRed); h1->SetFillStyle(1001); TH1F *h2=new TH1F("h2","h2",100,-3,3); h2->FillRandom("landau",10000); h2->Sumw2(); h2->SetFillColor(kRed); h2->SetFillStyle(1001); std::map hMap; std::maprdhMap; hMap["g"]=h1; rdhMap["g"] = new RooDataHist("g","g",x,h1); hMap["l"]=h2; rdhMap["l"] = new RooDataHist("h","h",x,h2); RooDataHist *dh=0; if(mode==FISHY) dh=new RooDataHist("dh","dh",RooArgSet(x),c,hMap) ; else if(mode==FINE) dh=new RooDataHist("dh","dh",RooArgSet(x),c,rdhMap) ; else dh=new RooDataHist("dh","dh",RooArgSet(x),Index(c),Import("g",*rdhMap["g"]),Import("l",*rdhMap["l"])); //project the dataset TCanvas *cnv=new TCanvas("c","c",400*hMap.size(),400); cnv->Divide(hMap.size(),1); int ipad(1); for(std::map::iterator hit=hMap.begin(); hit!=hMap.end(); hit++,ipad++) { cnv->cd(ipad); RooPlot* frame = x.frame(Title(hit->first.c_str())); TString cut("c==c::"); cut += hit->first; RooDataHist *dhslice = (RooDataHist *)dh->reduce(cut.Data()); dhslice->plotOn(frame,DataError(RooAbsData::SumW2)); frame->Draw(); hit->second->Draw("hist same"); } }