ROOT logo

From $ROOTSYS/tutorials/roostats/TestNonCentral.C


using namespace RooFit;
TestNonCentral(){

  RooWorkspace w("w");
  // k <2, must use sum
  w.factory("NonCentralChiSquare::nc(x[0,50],k[1.99,0,5],lambda[5])");
  // kk > 2 can use bessel
  w.factory("NonCentralChiSquare::ncc(x,kk[2.01,0,5],lambda)");
  // kk > 2, force sum
  w.factory("NonCentralChiSquare::nccc(x,kk,lambda)");
  ((RooNonCentralChiSquare*)w.pdf("nccc"))->SetForceSum(true);

  // a normal "central" chi-square for comparision when lambda->0
  w.factory("ChiSquarePdf::cs(x,k)");

  //w.var("kk")->setVal(4.); // test a large kk

  RooDataSet* ncdata = w.pdf("nc")->generate(*w.var("x"),100);
  RooDataSet* csdata = w.pdf("cs")->generate(*w.var("x"),100);
  RooPlot* plot = w.var("x")->frame();
  ncdata->plotOn(plot,MarkerColor(kRed));
  csdata->plotOn(plot,MarkerColor(kBlue));
  w.pdf("nc")->plotOn(plot,LineColor(kRed));
  w.pdf("ncc")->plotOn(plot,LineColor(kGreen));
  w.pdf("nccc")->plotOn(plot,LineColor(kYellow),LineStyle(kDashed));
  w.pdf("cs")->plotOn(plot,LineColor(kBlue),LineStyle(kDotted));
  plot->Draw();
  
}
 TestNonCentral.C:1
 TestNonCentral.C:2
 TestNonCentral.C:3
 TestNonCentral.C:4
 TestNonCentral.C:5
 TestNonCentral.C:6
 TestNonCentral.C:7
 TestNonCentral.C:8
 TestNonCentral.C:9
 TestNonCentral.C:10
 TestNonCentral.C:11
 TestNonCentral.C:12
 TestNonCentral.C:13
 TestNonCentral.C:14
 TestNonCentral.C:15
 TestNonCentral.C:16
 TestNonCentral.C:17
 TestNonCentral.C:18
 TestNonCentral.C:19
 TestNonCentral.C:20
 TestNonCentral.C:21
 TestNonCentral.C:22
 TestNonCentral.C:23
 TestNonCentral.C:24
 TestNonCentral.C:25
 TestNonCentral.C:26
 TestNonCentral.C:27
 TestNonCentral.C:28
 TestNonCentral.C:29
 TestNonCentral.C:30
 TestNonCentral.C:31
thumb