ROOT Discussion Forums

RooSimultaneous: problems in plotting the projections

Discuss RooFit, TMVA and other statistical and mathematical tools here. Please post bug reports here.

Moderators: cranmer, rootdev

RooSimultaneous: problems in plotting the projections

Unread postby gcasa » Thu Mar 10, 2011 12:36

I have problems with plotting the projections of a RooSimultaneous PDF.

given a certain simultaneous PDF I need to be able to choose the parameters that must be shared among the projections from a configuration file, runtime. I've tried to use the RooSimPdfBuilder class but unfortunately it is not general enough for the PDF that I need, therefore I can't use it.
So, to build the PDf I need I build the most general simultaneous PDF (one RooRealVar for each parameter) and then, runtime, I change the name of the RooRealVars using RooRealVar::setName(), reading them from a configuration file. Giving the same name to two parameters (two RooRealVar), they are fitted to the same value.

This procedure seems to work for what concern the fit but when I plot the projections something is wrong.
To study this problem and probe that the fit works I've written a macro:
I create two RooGaussian (one for the D*+ and the other for the D*-), each with its own RooRealVar mean and RooRealVar sigma.
I want the two RooGaussian to share the same mean and the same sigma, therefore I assign the same name to D*+ mean and the D*- mean, and the same for the sigma.
I generate a data sample from each of the two RooGaussian and combine them in a combined dataset with RooCategory.
I change the starting values of the 4 RooRealVar. I build the RooSimultaneous PDF and then do the fit and plot the projections.

The code is here:
Code: Select all
#ifndef __CINT__
#include "RooGlobalFunc.h"
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooCategory.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit ;

void test()
  // C r e a t e   D*+  a n d  D*-  m o d e l s
  // -------------------------------------------------------------

  // Create observables
  RooRealVar x("x","x",-8,8) ;

  // Construct D*+ pdf
  RooRealVar mean_p("mean_common","mean D*+",0,-8,8) ;
  RooRealVar sigma_p("sigma_common","sigma D*+",0.3,0.1,10) ;
  RooGaussian model_p("model_p","g D*+",x,mean_p,sigma_p) ;
  // Construct D*- pdf
  RooRealVar mean_m("mean_common","mean D*-",0,-8,8) ;
  RooRealVar sigma_m("sigma_common","sigma D*-",0.3,0.1,10) ;
  RooGaussian model_m("model_m","g D*-",x,mean_m,sigma_m) ;
  // G e n e r a t e   e v e n t s   f o r   b o t h   s a m p l e s
  // ---------------------------------------------------------------
  // Generate 1000 events in x from models
  RooDataSet *data_p = model_p.generate(RooArgSet(x),1000) ;
  RooDataSet *data_m = model_m.generate(RooArgSet(x),1000) ;

  // change the starting values fo the fit 

  // C r e a t e   i n d e x   c a t e g o r y   a n d   j o i n   s a m p l e s
  // ---------------------------------------------------------------------------

  // Define category to distinguish D*+ and D*- events
  RooCategory sample("sample","sample") ;
  sample.defineType("DstarPlus") ;
  sample.defineType("DstarMinus") ;

  // Construct combined dataset in (x,sample)
  RooDataSet combData("combData","combined data",x,Index(sample),Import("DstarMinus",*data_m),Import("DstarPlus",*data_p)) ;

  // C o n s t r u c t   a   s i m u l t a n e o u s   PDF
  // -----------------------------------------------------------------------------------

  // Construct a simultaneous pdf using category sample as index
  RooSimultaneous simPdf("simPdf","simultaneous pdf",sample) ;

  // Associate the D*+ PDF and the D*- PDF to their category and add them to the simultaneous PDF
  simPdf.addPdf(model_p,"DstarPlus") ;
  simPdf.addPdf(model_m,"DstarMinus") ;

  // P e r f o r m   a   s i m u l t a n e o u s   f i t
  // ---------------------------------------------------

  // Perform simultaneous fit of model_p to data_p and model_m to data_m
  simPdf.fitTo(combData) ;

  // P l o t   
  // ----------------------------------------------------------------
  RooGaussian* pdf_plus = simPdf.getPdf("DstarPlus");
  RooGaussian* pdf_minus = simPdf.getPdf("DstarMinus");

  RooPlot* frame1 = x.frame(Bins(50),Title("DstarPlus")) ;

  RooPlot* frame2 = x.frame(Bins(50),Title("DstarMinus")) ;

  TCanvas* c = new TCanvas("TEST MACRO","TEST MACRO",800,400) ;
  c->Divide(2) ;
  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;

The canvas with the results is here:
The left plot contain the D*+ dataset, the blue line is the D*+ projection and the dotted red line the D*- projection.
The right plot contains the D*- dataset and the D*- projection of the PDF (red line).

The logfile is here:

You can see that the fit is fine and that the D*+ projection is correct while the D*- projection is the D*- PDF plotted with the _starting_ values of the parameters and not the values extracted from the fit.

I've done two tests in order to demonstrate that the fit is correct and that the likelihood is built using the D*+ and the D*- events:
1) I've built the D*+ PDf and the D*- PDF with common RooRealVar:
Code: Select all
       RooRealVar mean("mean_common","mean D*+",0,-8,8) ;
       RooRealVar sigma("sigma_common","sigma D*+",0.3,0.1,10) ;
       // Construct D*+ pdf
       RooGaussian model_p("model_p","g D*+",x,mean,sigma) ;
       // Construct D*- pdf
       RooGaussian model_m("model_m","g D*-",x,mean,sigma) ;

and perfomed the same fit: the extracted values and the stastistical error are exactly the same.

2) in the configuration of the macro, I've generated 10x the D*+ events and done the fit and the10x the D*- events and seen that the statistical error from these 2 fits are the same (and also the extracted values).

Do you have any idea of why this is happening?

Last thing is that I've had problems with the RooSimultaneous projections using the plotOn method (see viewtopic.php?f=3&t=11936) and that's why I use the RooSimultaneous::getPdf() method. I don't know if the current and the previous problem with projections plot are correlated.

Thank you for your help,

Giulia Casarosa
Posts: 2
Joined: Tue Jan 11, 2011 17:11

Return to Stat and Math Tool Support

Who is online

Users browsing this forum: No registered users and 1 guest