Home | News | Documentation | Download

How to fit DATA with an MC shape

Hi everybody,
this is my first request to the community, so please excuse me in advance for mistakes.
I have two kind of TTree s: the first one the DATA and the second one the MC entries.
I want to extract the shape of one TBranch of the MC and fit to the same TBranch of the DATA.

I tried with the “RooHistPdf()” class but it doesn’t worked.

I’m working with ROOT 6.17/01 version.
Thank’s in advice!

Hi @emanuele_cardinali,
and welcome to the ROOT forum!

What didn’t work exactly? Can you share a small snippet of code that reproduces the problem, as well as the error message you get?


ROOT 6.17 is a development version, see https://root.cern/about/versioning – you might want to switch to a stable release version, the latest is 6.22/02 and installation instructions are available at https://root.cern/install.

Yes of course.

  TChain chain("h1");

 TChain chain1("h1");

  TH1D *hma1 = new TH1D("hma1","1", 200, 475., 510.);

//Here I create 2 chains and the 1D Histograms (I decide to use only one)

 RooRealVar x("x","x",475,510);         
 chain.Draw("Variable>>hma1","Cuts that I want to add");

//Here I draw on the first Histogram the Variable that I want (with the cuts)

 RooDataHist data("data","data",x,hma1);
 RooHistPdf histpdf1("histpdf1","histpdf1",x,data,0);

chain1.Draw("Variable>>hma1","The same cuts");

  RooDataHist data1("data1","data1",x,hma1);


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

//I do the same for the DATA Values and with "RooDataHistpdf" 
//I take the shape of the MC Histogram. 
//At the end the program overlap the MC histogram to the DATA's one

This program is only able to Overlap the first shape to the second one. It seems that the line “histpdf1.fitTo(data1)” doesn’t work, cause it doesn’t call MINOS in order to do the fit of the second histogram.
How can I do it?

Thanks in advance.

Now I have Root-v6.22.02 :wink:
Thanks for the advice!


First of all when you post the code, please add using pre-formatted text, (as done below) to make it more readable.

The problem is due to the fact that your pdf has no parameters. You can add for example a normalisation parameter doing this, but you will fit only the number of events:

RooRealVar nevts("nevts","nevts",data1.numEntries(),0,10*data1.numEntries());
RooExtendPdf  pdf("extPdf","extPdf",histpdf1,nevts);


I corrected the error. Thanks @moneta for letting me know.

So I wanted to ask you if it was possible with RooFit to make a fit to an indirect variable (i.e. given by a function of other TBranches).

In the example you wrote I imagine that “nevts” is a TBranch of the TTree that I declare.
I need to fit a variable which is a function of many TBranches (including arrays).

One idea would be to declare “RooRealVals” with the names of the TBranches I need and then write the function.
Another one, which is the one I used, is to declare a “RooDataHist” and fill it with the variable I need to fit.

What I’m asking is: can it work?
If it doesn’t work, should I use the first method?
If not, do you know any other strategies?


I am not sure I understand your request.
From the Three you can retrieve a vector of data points. This branch normally can then be used:

  • as an observable variable of your model, but not as a a parameter that you fit. For example you have a vector of x values, you model for these values a Gaussian(x, mu, sigma) and you can fit using these values for the mu and sigma parameters.
  • estimate a distribution (e.g. an histogram) that can then be used then as input for the fit, together with some additional model parameters (e.g. histogram normalisation, bin by bin variation, etc…)



Hi @moneta,
What I want is to derive the invariant mass through the TBranches of the TTree.
Specifically, I have the TBranch of the momentum of the decaying particle and the TBranch of the momentum of the particles produced.
That’s why I used the “Draw ()”. I put:

chain.Draw("Function of P_father and P_sons( i.e. Invariant mass )>>hma1", "Cuts that I want");

in order to then work on the “hma1” histogram which should take into account the entries of the “invariant mass”.
What I’m wondering is if by doing so I can then work on the “invariant mass” via RooFit.

I hope I have explained.


What you can do it is creating a subtree with the variable you want to input to RooFit as RooDataSet.
To create a subtree, you can use the power of RDataFrame to make a snapshot, see for example the tutorial :


Thanks Lorenzo for your advice.
These days I will study the class.
In case it is not useful, I will open a new topic.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.