Skip to content

Instantly share code, notes, and snippets.

@cranmer
Last active February 5, 2020 13:44
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cranmer/b67830e46d53d5f7cf2d to your computer and use it in GitHub Desktop.
RooMomentMorph example for RooFit
#for python, look here: https://gist.github.com/cranmer/46fff8d22015e5a26619
void testMM(){
// #Make statistical model
w = new RooWorkspace("w");
w->factory("Exponential::e(x[-5,15],tau[-.15,-3,0])");
x = w->var("x");
w->factory("mu[0,10]");
mu = w->var("mu");
frame = x->frame();
RooArgList pdfs;
paramVec = TVectorD(5);
for( i=0; i<5; ++i){
w->factory(Form("Gaussian::g%d(x,mu%d[%d,-3,5],sigma[0.5, 0, 2])", i, i,i));
w->factory(Form("SUM::model%d(s[50,0,100]*g%d,b[100,0,1000]*e)",i,i));
w->Print() ;
pdf = w->pdf(Form("model%d",i));
pdf->plotOn(frame);
pdfs.add(*pdf);
paramVec[i]=i;
}
pdfs.Print();
mu = w->var("mu");
RooArgList varlist;
varlist.add(*x);
morph = new RooMomentMorph("morph","morph",*mu,varlist,pdfs, paramVec,RooMomentMorph::Linear);
w->import(*morph);
morph->Print("v");
w->Print();
for (i=0; i<5; ++i){
mu->setVal(.8+i);
mu->Print();
morph->plotOn(frame, RooFit::LineColor(kRed));
}
frame->Draw();
c1->SaveAs("test.pdf");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment