RooClassFactory with RooCategory arguments

Hello,
I want to define a Pdf that returns a different value depending on the discrete value of a variable tag that can be -1, 1 or 0.

I defined:
RooCategory tag= new RooCategory(“tag”,“tag”);
tag->defineType(“R”,-1); tag->defineType(“W”,1); tag->defineType(“U”,0);
RooRealVar prob = new RooRealVar(“prob”,“NNet probability”,-2.5,1);
Double_t mm=0.34;
Double_t rms=0.03;
RooRealVar p_0 = new RooRealVar(“p_0”,“p_0”,mm,0.5mm,2.mm);
RooRealVar p_1 = new RooRealVar(“p_1”,“p_1”,1,0.5,2.);
RooRealVar
MM = new RooRealVar(“Net_mean”,“Net mean”,mm,0.5
mm,2
mm); MM->setError(0.1
mm);
RooRealVar* RMS = new RooRealVar(“Net_RMS”,“Net RMS”,rms,0.5rms,2rms); RMS->setError(0.1*rms);

If I type :
RooClassFactory::makePdf(“pippo”,“tag,prob,p_0,p_1,Net_mean,Net_RMS”);

I see that tag is defined as RooAbsReal in the pippo.h(cxx) and when I try to compile in my code it gives me errors since there is a definition mismatch on tag.
So I changed the _tag definition to RooAbsCategory and the corresponding tag from RooRealProxy into RooCategoryProxy.
It compiles and apparently runs, but then if in the eval() method I write:
cout<< tag <<" "<<prob<<endl;
I see that rather frequently the tag variable is NOT the one I read from my file (I get -1 instead of 0. I can tell because I know that if tag=0 prob=-2).

So the question is:
Does the RooClassFactory support the RooCategory arguments?

How could I implement some code like this:
Double_t pippo::evaluate() const
{
Double_t weight=0;
cout<<" “<<tag<<” "<<prob<<endl;
if(tag!=0){
if( fabs(prob-Net_mean)<4Net_RMS){
if(tag>0) // Wrong Tag
weight = p_0+p_1
(prob-Net_mean);
else
weight = 1-(p_0+p_1*(prob-Net_mean));
if(weight>1) weight=1;
if(weight<0) weight=0;
}
}
return weight;
}

Thanks,
Stefania

Hi Stefania,

The class factory does support categories, but you need to list them separately in your call
to makePdf, i.e. the category names should be listed as the 3rd argument

static Bool_t makePdf(const char* name, const char* realArgNames=0, const char* catArgNames=0,
const char* expression=“1.0”, Bool_t hasAnaInt=kFALSE, Bool_t hasIntGen=kFALSE, const char* intExpression=0) ;

Wouter