Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:23

0001 #include "PhysicsTools/Utilities/interface/RooFitFunction.h"
0002 #include "PhysicsTools/Utilities/interface/Parameter.h"
0003 #include "PhysicsTools/Utilities/interface/Function.h"
0004 #include "RooRealVar.h"
0005 #include "RooPlot.h"
0006 #include "TROOT.h"
0007 #include "TCanvas.h"
0008 #include <iostream>
0009 using namespace RooFit;
0010 
0011 int main() {
0012   gROOT->SetStyle("Plain");
0013   try {
0014     funct::Parameter yield("Yield", 100);
0015     funct::Parameter mean("Mean", 0);
0016     funct::Parameter sigma("Sigma", 1);
0017     funct::Parameter c("C", 1. / sqrt(2 * M_PI));
0018     funct::X x;
0019     funct::Numerical<2> _2;
0020 
0021     funct::Expression f = yield * c * exp(-(((x - mean) / sigma) ^ _2) / _2);
0022 
0023     RooRealVar rX("x", "x", -5, 5);
0024     RooRealVar rYield(yield.name().c_str(), "Gaussian mean", yield, 0, 1000);
0025     RooRealVar rMean(mean.name().c_str(), "Gaussian mean", mean, -5, 5);
0026     RooRealVar rSigma(sigma.name().c_str(), "Gaussian sigma", sigma, 0, 5);
0027 
0028     TCanvas canvas;
0029     root::RooFitFunction<funct::X, funct::Expression> rooFun(
0030         "rooFun", "rooFun", f, rX, rYield, yield, rMean, mean, rSigma, sigma);
0031     RooPlot* frame = rX.frame();
0032     rooFun.plotOn(frame);
0033     frame->Draw();
0034     canvas.SaveAs("rooPlot.eps");
0035   } catch (std::exception& err) {
0036     std::cerr << "Exception caught:\n" << err.what() << std::endl;
0037     return 1;
0038   }
0039 
0040   return 0;
0041 }