Accessing a set of histograms in Roofit

Dear all,

I have a Roofit job that used to read unbinned data in the following way:
RooDataSet data = RooDataSet::read(filename, mass);
where filename is an ASCII file containing the variable mass, and I fit the unbinned distribution of this variable.
filename is declared in the following way:
void MassFit(const char
filename = “mass.dat”, const char* plotOpt = “NEU”)

Now since I have now a huge quantity of events, I would like to do an unbinned fit of the histogram of this variable. Actually I have a set of such histograms in a root file such as for instance mass.root, containing histograms “mass cond 1”, “mass cond 2”, etc…

I suppose I can still access the root file in the same way:
void MassFit(const char* filename = “mass.root”, const char* plotOpt = “NEU”)
right?
But then I am lost. I basically know that I should use RooDataHist instead of RooDataSet, but from what I found in this forum or on various tutorials I could not figure out how to do that.

After that, if I understood correctly, the fit procedure is exactly the same. Is that right?

Can you help?

Thanks and best regards,

Elizabeth

Hi Elizabeth

I presume you want to do a binned fit starting from ROOT histograms. In this case you need to create a RooDataHist object. There is a constructor for RooDataHist taking an histogram or a list of histograms.
See the reference documentation
https://root.cern.ch/doc/v606/classRooDataHist.html#a1e30c1430e864be4ebdc0e0ee62b79e0

Also this slide below as example.

Best Regards

Lorenzo

Dear Lorenzo,
Thank you for your reply.
It is basically what I have done, but I think that the problem comes from the way I access the histograms, namely this statement

myHist[0] = (TH1D*)(filename->FindObjectAny(histogramName)); // get histo with name histogramName

which used to work in another case.

The diagnostic is:
histogramName Standard Z mass
Error: non class,struct,union object filename used with . or -> MassFit.cc:25:
*** Interpreter error recovered ***

Here after is the very short code, tried in accessing one single histogram for the moment.

Thanks and best regards,

Elizabeth

/** \macro MassFit.cc
*
*/

using namespace std;
using namespace RooFit;

void MassFit(const char* filename = “DYJetsM50_BuildEoPhis.root”, const char* plotOpt = “NEU”) {

Float_t massMin(75), massMax(105);
RooRealVar mass(“mass”,“M(e^{+}e^{-})”, massMin, massMax,“GeV/c^{2}”);
Int_t nBins(150);

TH1D *myHist[50];
char hist = new char[50];
std::ostringstream os1;
os1 << “Standard Z mass”;
TString histogramName = os1.str(); // build histo namefor individual histo access
cout << " histogramName " << histogramName << endl;
myHist[0] = (TH1D
)(filename->FindObjectAny(histogramName)); // get histo with name histogramName

// Create a datahist that imports contents of all TH1 mapped by index category c
RooDataHist dh(“mass”,“mass”,mass,Import(*myHist[0])) ;

// RooPlot* plot = mass.frame(Range(massMin,massMax),Bins(nBins));
// dh->plotOn(plot);
// plot->Draw();

}

Hi,

You can try to do :

myHist[0] = (TH1*) filename->Get(histogramName); 

Lorenzo

Hi Lorenzo,

It seems to work, at least for histograms having a name without any space in it. I will rebuild the root file in order to suppress spaces.
Then it is not the end of the story as I have to read all the histograms and to fit. Let’s hope it will go smoothly…

Thanks and best regards,

Elizabeth

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