using namespace RooFit ; void ex9() { // Make an empty workspace that exports its contents to CINT RooWorkspace *w = new RooWorkspace("w",kTRUE) ; // *** Declare model parameters *** // Generally a variable is declared A[lo,hi], A[initval,lo,hi], or A[constval] // // Here S is the expected Signal event count // Here B is the expected Background event count w->factory("S[0,0,100]") ; // allowed range [0,100] initial value 0 w->factory("B[5]") ; // constant at value 5 // Declare the model observable (i.e. the quantity we measure, in this case an event count) w->factory("N[0,100]") ; // *** Construct an expression for the expected signal yield *** // Generally a function object is created as FunctionType::FunctionName(arguments) // // A very useful one is FunctionType 'expr' which allows a TFormula-style C++ expression // to be interpreted as its value // // expr::FunctionName('',inputvariable1,inputvariable2) // // Construct a function named Nexp that adds parameters S and B w->factory("expr::Nexp('S+B',S,B)") ; // Finally construct a probability model (a special class of functions that can present probabilities // by the virtue that int ProbModel(x) dx == 1 [ unitarity requirement for probability interpretation] // // Generally, all FunctionTypes that exist map one-to-one to existing RooFit function classes // In this case the class RooPoisson is used (you can look at it in $ROOTSYS/roofit/roofit/inc/RooPoisson.h // and $ROOTSYS/roofit/roofit/src/RooPoisson.cxx) // // This class implements the Poisson distribution and has one parameter (here represented by our function expression Nexp // as function of model parameters S(floating) and B(constant) w->factory("Poisson::model(N,Nexp)") ; // Have a look at all the objects created in the workspace w->Print("t") ; // *** STEP 1 *** return ; // Now we have a look at our model // Make a an empty plot frame with N on the X-axis with range [0,100] RooPlot* frame = w->var("N")->frame(0,20,20) ; // Now plot our model on top the plot frame ; w->pdf("model")->plotOn(frame,Precision(1e-4)) ; // ( The Precision(1e-4) improves the adaptive plotting // precision which is needed here because the Poisson // has discontinuities, whereas the plotting code // is generally optimized for continuous functions ) // This draws the plot frame on the canvas frame->Draw() ; // *** STEP 2 *** //return ; // Now we change the value of expected signal yield from 0 to 2 w->var("S")->setVal(2) ; // And we plot again, on the same plot frame w->pdf("model")->plotOn(frame,Precision(1e-4),LineColor(kRed)) ; // This draws the plot frame on the canvas frame->Draw() ; }