Hi,
I would need your help with a pyROOT/RooFit problem, maybe someone has an idea:
Basically I need to draw my RooCBShape in RooFit on my own, as a RooCurve.
In c++ that would work like that:
// define new RooCBShape to get access to protected member .. as evaluate() ..
class RooCBShapeD : public RooCBShape
{
public:
//Y::Y(int _x) : X(_x) {}
RooCBShapeDerived(const char *name, const char *title, RooAbsReal& _m,
RooAbsReal& _m0, RooAbsReal& _sigma,
RooAbsReal& _alpha, RooAbsReal& _n) :
RooCBShape(name, title, _m, _m0, _sigma, _alpha, _n)
{
}
Double_t eval() { return RooCBShape::evaluate(); } // OK
};
..
RooCurve* curve = new RooCurve();
for( unsigned int i = 0; i <= 2000; i++){
Double_t val = ( Double_t(i) / 1000 );
//std::cout << "[xVal pf CBS]: \t" << val << std::endl;
RooRealVar testVal("testVal","testVal", val );
RooRealVar mean("mean", "mean", cbMean);
RooRealVar sigma("sigma", "sigma",cbSig);
RooRealVar alpha("alpha", "alpha",cbAlpha);
RooRealVar n("n", "n", cbN);
RooCBShapeDerived cbs("cbs", "Crystal Ball shape", testVal, mean, sigma, alpha, n);
std::cout << "[yVal of CBS]: \t" << cbs.eval() << std::endl;
curve->addPoint(val, cbs.eval());
}
curve->Draw();
One would need to create it’s own derived class to get access to the protected member of RooCBShape, as evaluate().
Translated to python it would look something like :
import os
import sys
from ROOT import TCanvas, TFile, gDirectory
from ROOT import gSystem
gSystem.Load('libRooFit')
from ROOT import RooFit, RooRealVar, RooCurve, RooCBShape
class RooCBShapeDerived(RooCBShape):
def __init__(self,name,title, m, m0, sigma, alpha, n):
self._name = name
self._title = title
self._m = m
self._m0 = m0
self._sigma = sigma
self._alpha = alpha
self._n = n
def eval(self) :
return RooCBShape.evaluate()
## Create Canvas
print "---- Create Can ----"
c = TCanvas("c","c",750, 750);
c.cd();
cbMean =1.0145
cbSig =0.025
cbAlpha =-0.555
cbN =1.1731
curve = RooCurve()
for i in range(0,2000):
val = i / 1000
print "[xVal of CBS]: \t",val
testVal= RooRealVar("testVal","testVal", val )
mean=RooRealVar("mean", "mean", cbMean)
sigma=RooRealVar("sigma", "sigma",cbSig)
alpha=RooRealVar("alpha", "alpha",cbAlpha)
n=RooRealVar("n", "n", cbN)
cbs=RooCBShapeDerived("cbs", "Crystal Ball shape", testVal, mean, sigma, alpha, n)
print "[yVal of CBS]: \t", cbs.eval()
curve.addPoint(val, cbs.eval());
curve.Draw();
But somehow my python version of the code does not work.
The error in python I am getting is the following
I don’t know why.
thanks for help,
Florian