RooSimPdfBuilder with 2 prototype pdfs

Dear all,

I am using the RooSimPdfBuilder class to generate a large number of very similar pdfs to fit subsets of my data. The code below works great. However, I am struggling to add a small extension…

I would like to have one prototype pdf for one subset of the data (00_data) and another prototype pdf for another subset of the data (10_data).

I know this is possible and the answer seems to be on page 11 of the tutorial here:

roofit.sourceforge.net/docs/tuto … ptools.pdf

However, I do not seem to be able to add the correct couple of lines to the code below to get things to work #-o

If anyone could help RE those lines, I would be incredibly grateful!

Cheers!

S

[code] // Data categories
RooCategory Data_Category(“Data_Category”,“Data_Category”);
Data_Category.defineType(“00_data”);
Data_Category.defineType(“10_data”);

// Cut to get the datasets
RooDataSet* RDS_00_data = new RooDataSet("RDS_00_data", "RDS_00_data", data, varList, "ft_hs==0 && ft_as==0");

RooDataSet* RDS_10_data = new RooDataSet(“RDS_10_data”, “RDS_10_data”, data, varList, “ft_hs==1 && ft_as==0”);

// Create RooDataHists
RooDataHist* RDH_00_data_hist = new RooDataHist(“RDH_00_data_hist” ,“RDH_00_data_hist”, RooArgList(ft_hs,ft_as), RDS_00_data) ;
RooDataHist
RDH_10_data_hist = new RooDataHist(“RDH_10_data_hist” ,“RDH_10_data_hist”, RooArgList(ft_hs,ft_as), *RDS_10_data) ;

mapstd::string,RooDataHist* myMap;
myMap.insert( pairstd::string,RooDataHist*(“00_data”,RDH_00_data_hist) );
myMap.insert( pairstd::string,RooDataHist*(“10_data”,RDH_10_data_hist) );

RooSimultaneous simPdf(“simPdf”,“simultaneous pdf”,Data_Category) ;
RooDataHist combData(“combData”,“combined data”, RooArgList(ft_hs,ft_as), Data_Category, myMap);

//--------- PDF builder method

// Code up the simplified DC model
RooRealVar h_att_param(“h_att_param”,“h_att_param”,0.5,0,1);
RooRealVar h_def_param(“h_def_param”,“h_def_param”,0.5,0,1);
RooRealVar a_att_param(“a_att_param”,“a_att_param”,0.5,0,1);
RooRealVar a_def_param(“a_def_param”,“a_def_param”,0.5,0,1);
RooRealVar gamma(“gamma”,“gamma”,0.5,0,1);
RooFormulaVar home_rate(“home_rate”, “h_att_parama_def_paramgamma”, RooArgList(h_att_param, a_def_param, gamma));
RooFormulaVar away_rate(“away_rate”, “a_att_param*h_def_param”, RooArgList(a_att_param, h_def_param));

RooPoisson home_goals_poisson(“home_goals_poisson”, “home_goals_poisson”, ft_hs, home_rate);
RooPoisson away_goals_poisson(“away_goals_poisson”, “away_goals_poisson”, ft_as, away_rate);

// Multiply the components
RooProdPdf DC(“DC”, “DC”, home_goals_poisson, away_goals_poisson);

// Define a category with labels only
RooCategory Category(“Category”,“Category”);
RooCategory hid(“hid”,“hid”) ;
hid.defineType(“France”) ;
hid.defineType(“Uruguay”) ;

RooCategory aid(“aid”,“aid”) ;
aid.defineType(“Denmark”) ;
aid.defineType(“Senegal”) ;

// Make dummy data set for use by simpdf builder later on
RooDataSet data_dummy(“data_dummy”,“data_dummy”,RooArgList(home_rate, away_rate, ft_hs,ft_as,hid,aid)) ;

// Instantiate a builder
RooSimPdfBuilder mgr(DC) ;

// Create an empty configuration object suitable for configuring
// A configuration object is a RooArgSet with RooStringVar objects
RooArgSet* config = mgr.createProtoBuildConfig() ;

// Enter configuration data

config->setStringValue(“physModels”,“DC”) ; // We wil only use prototype ‘sum’
config->setStringValue(“splitCats” ,“hid aid”) ; // We will use ‘tagCat’ and ‘runBlock’ to split parameters
config->setStringValue(“DC”, "hid : h_att_param " // Split parameter ‘gfrac’ of ‘sum’ using ‘tagCat’
"aid : a_def_param "
"hid : h_def_param "
"aid : a_att_param "

                              ) ;  

// Build the PDF
RooSimultaneous* simSum = mgr.buildPdf(*config,&data_dummy) ;
simSum->Print(“v”) ;
simSum->getParameters(&data_dummy)->Print(“v”) ;

[/code]

I tried the simple implementation below, but I see the following error:

[code][#1] INFO:ObjectHandling – RooSimPdfBuilder::buildPdf: category indexing physics model: data_cat
[#0] ERROR:InputArguments – RooSimPdfBuilder::buildPdf: ERROR requested physics model DC is not defined

*** Break *** segmentation violation
[/code]

Implementation:

RooCategory data_cat("data_cat", "data_cat");
data_cat.defineType("data_00");
data_cat.defineType("data_10");   

RooSimultaneous simPdf("simPdf","simultaneous pdf",data_cat) ;
simPdf.addPdf(DC,"data_00") ;             
simPdf.addPdf(gauss,"data_10") ;   

// Make dummy data set for use by simpdf builder later on
RooDataSet data_dummy("data_dummy","data_dummy",RooArgList(home_rate, away_rate, ft_hs,ft_as,hid,aid,data_cat)) ;

// Instantiate a builder
RooSimPdfBuilder mgr(simPdf) ;

// Create an empty configuration object suitable for configuring 'sum'
// A configuration object is a RooArgSet with RooStringVar objects
RooArgSet* config = mgr.createProtoBuildConfig() ;

// Enter configuration data
 config->setStringValue("physModels","data_cat : data_00=DC data_10=gauss") ;         
  config->setStringValue("splitCats" ,"hid aid") ;      
  config->setStringValue("DC",       "hid          : h_att_param "  // Split parameter 'gfrac' of 'sum' using 'tagCat'
  			             "aid          : a_def_param "
  			             "hid          : h_def_param "
  			             "aid          : a_att_param "		
			 
                                ) ; 
                                

Hi Sam,

I can’t tell where your additional code is being included. The error makes it look like “DC” isn’t defined, but it is there in the code of the first post. Maybe you can include all the code you are using.

I’m not sure if you need to use RooSimPdfBuilder, or if you can just use this constructor directly

github.com/root-mirror/root/blo … eous.h#L43

Dear Kyle -

Thanks for the response

I have attached the full code I am using as requested.

Best,

Sam

p.s. I also attach a screenshot of the function I am attempting to maximise the likelihood for…

The 5 prototype pdfs will take care of the 5 variations of the tau function. Everything else seems to be working.



BuilderMethod.C (9.21 KB)

Instead of using setStringValue like this

[code] config->setStringValue(“physModels”,“data_cat : data_00=DC data_10=gauss_1 data_01=gauss_2 data_11=gauss_3 data_other=gauss_4”) ;

config->setStringValue(“splitCats” ,“hid aid”) ; // We will use ‘tagCat’ and ‘runBlock’ to split parameters

config->setStringValue(“DC”, "hid : h_a_param " // Split parameters using hid and aid
"aid : a_d_param "
"hid : h_d_param "
"aid : a_a_param "

[/code]

have you tried syntax like this:

RooSimPdfBuilder builder(pdf) ; RooArgSet* config = builder.createProtoBuildConfig() ; (*config)["physModels"] = "pdf" ; (*config)["splitCats"] = “type" ; (*config)["pdf"] = “type : f,s" ; RooSimultaneous* simPdf = builder.buildPdf(*config,&D) ;

Hi Kyle,

Yes, I tried the other syntax. If I switch back to the syntax you mentioned above:

RooSimPdfBuilder mgr(simPdf) ; RooArgSet* config = mgr.createProtoBuildConfig() ; (*config)["physModels"] = "data_cat : data_00=DC data_10=gauss_1 data_01=gauss_2 data_11=gauss_3 data_other=gauss_4" ; (*config)["splitCats"] = "hid aid" ; (*config)["pdf"] = "hid : a_a_param "; RooSimultaneous* simSum = mgr.buildPdf(*config,&data_dummy) ;

I see the following errors:

root [0] .L BuilderMethod.C+
Info in <TUnixSystem::ACLiC>: creating shared library /home/sam/ROOT_installation/ROOT_Coding/./BuilderMethod_C.so
In file included from input_line_12:9:
/home/sam/ROOT_installation/ROOT_Coding/./BuilderMethod.C:238:25: error: no
      viable overloaded '='
(*config)["physModels"] = "data_cat : data_00=DC data_10=gauss_1 data_01=gauss_2 data_11=gauss_3 data_other=gauss_4" ;
~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/sam/ROOT_installation/ROOT_build_dir/include/RooAbsArg.h:66:7: note: 
      candidate function (the implicit copy assignment operator) not viable: no
      known conversion from 'const char [89]' to 'const RooAbsArg' for 1st
      argument
class RooAbsArg : public TNamed, public RooPrintable {
      ^
In file included from input_line_12:9:
/home/sam/ROOT_installation/ROOT_Coding/./BuilderMethod.C:239:24: error: no
      viable overloaded '='
(*config)["splitCats"] = "hid aid" ;
~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~
/home/sam/ROOT_installation/ROOT_build_dir/include/RooAbsArg.h:66:7: note: 
      candidate function (the implicit copy assignment operator) not viable: no
      known conversion from 'const char [8]' to 'const RooAbsArg' for 1st
      argument
class RooAbsArg : public TNamed, public RooPrintable {
      ^
In file included from input_line_12:9:
/home/sam/ROOT_installation/ROOT_Coding/./BuilderMethod.C:240:18: error: no
      viable overloaded '='
(*config)["pdf"] = "hid : a_a_param ";
~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
/home/sam/ROOT_installation/ROOT_build_dir/include/RooAbsArg.h:66:7: note: 
      candidate function (the implicit copy assignment operator) not viable: no
      known conversion from 'const char [17]' to 'const RooAbsArg' for 1st
      argument
class RooAbsArg : public TNamed, public RooPrintable {
      ^
Error in <ACLiC>: Dictionary generation failed!
root [1] .L BuilderMethod.C+
Info in <TUnixSystem::ACLiC>: creating shared library /home/sam/ROOT_installation/ROOT_Coding/./BuilderMethod_C.so
In file included from input_line_12:9:
/home/sam/ROOT_installation/ROOT_Coding/./BuilderMethod.C:238:25: error: no viable overloaded '='
(*config)["physModels"] = "data_cat : data_00=DC data_10=gauss_1 data_01=gauss_2 data_11=gauss_3 data_other=gauss_4" ;
~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/sam/ROOT_installation/ROOT_build_dir/include/RooAbsArg.h:66:7: note: candidate function (the implicit copy assignment operator) not viable: no known
      conversion from 'const char [89]' to 'const RooAbsArg' for 1st argument
class RooAbsArg : public TNamed, public RooPrintable {
      ^
In file included from input_line_12:9:
/home/sam/ROOT_installation/ROOT_Coding/./BuilderMethod.C:239:24: error: no viable overloaded '='
(*config)["splitCats"] = "hid aid" ;
~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~
/home/sam/ROOT_installation/ROOT_build_dir/include/RooAbsArg.h:66:7: note: candidate function (the implicit copy assignment operator) not viable: no known
      conversion from 'const char [8]' to 'const RooAbsArg' for 1st argument
class RooAbsArg : public TNamed, public RooPrintable {
      ^
In file included from input_line_12:9:
/home/sam/ROOT_installation/ROOT_Coding/./BuilderMethod.C:240:18: error: no viable overloaded '='
(*config)["pdf"] = "hid : a_a_param ";
~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
/home/sam/ROOT_installation/ROOT_build_dir/include/RooAbsArg.h:66:7: note: candidate function (the implicit copy assignment operator) not viable: no known
      conversion from 'const char [17]' to 'const RooAbsArg' for 1st argument
class RooAbsArg : public TNamed, public RooPrintable {
      ^
Error in <ACLiC>: Dictionary generation failed!

I’m sure we’re close!

Thanks,

S

weird to have RooAbsArg = const char *

Maybe use

void RooAbsArg::SetName ( const char * name )

like this

(*config)["splitCats"].SetName( "hid aid" );

Not sure

Sadly, changing the syntax didn’t work… :frowning:

I honestly cannot see anything I am doing wrong…

Are you able to replicate the error I see below? (sorry to be a pain, but this is driving me insane #-o )

With the argument fed to RooSimPdfBuilder being the RooProdPdf “DC” everything works fine i.e.

RooSimPdfBuilder mgr(DC) ;
RooArgSet* config = mgr.createProtoBuildConfig() ;
config->setStringValue("physModels","DC") ;             

However, when I change the argument fed to RooSimPdfBuilder to a RooSimultaneous and use as per page 11 of the tutorial here:

roofit.sourceforge.net/docs/tuto … ptools.pdf

RooSimPdfBuilder mgr(simPdf) ;
RooArgSet* config = mgr.createProtoBuildConfig() ;
config->setStringValue("physModels","data_cat : data_00=DC data_10=gauss_1 data_01=gauss_2 data_11=gauss_3 data_other=gauss_4") ;              

Things fall over…

[#1] INFO:ObjectHandling -- RooSimPdfBuilder::buildPdf: category indexing physics model: data_cat
[#0] ERROR:InputArguments -- RooSimPdfBuilder::buildPdf: ERROR requested physics model DC is not defined

 *** Break *** segmentation violation

I will re-attach my code in case you (or anyone else can see the problem). I’m really at my wits end on this :frowning:

Solved!

The problem is that you have to feed the ingredient pdfs of the RooSimultaneous to the RooSimPdfBuilder constructor e.g:

RooSimPdfBuilder mgr(DC, gauss_1, gauss_2.....) ;

Not just the RooSimultaneous itself e.g:

RooSimPdfBuilder mgr(simPdf) ;

The solution was found here:

root.cern.ch/root/html510/src/R … r.cxx.html

Thanks to those that replied!

S

I’m glad you found it

Hi Kyle!

There’s not a lot of documentation on that class (tutorials etc). I just stumbled across it!

Thanks for taking a look,

S