How to fill variables into a histogram within selected range?-Roofit

I have variables like

RooRealVar Xmass(“Xmass”, “Xmass”, 3.09, 4.25) ;
RooRealVar x1(“x1”,“x1”, 1.9, 99.);
RooRealVar x2(“x2”,“x2”, 1.9, 99.);
RooRealVar x3(“x3”,“x3”, 1.9, 99.);

and I read the values from txt file

RooDataSet * dataSet= (RooDataSet::read(FileName,RooArgSet(Xmass, x1, x2, x3), “Q”));

and apply roofit on Xmass such like

mytotalPdf.fitTo(*dataSet,“mer”);
RooPlot *frame = Xmass.frame(60);
mytotalPdf.plotOn(frame);

then I select the signal range within 1.5 sigma for both signal and background.

double myXsigma = Bp_width.getVal();
Xmass.setRange(“selection”,3.59-1.5myXsigma, 3.59+1.5myXsigma);
RooAbsReal* pdfBpsignalreg=pdfBp->createIntegral(RooArgSet(Xmass),“selection”);
RooAbsReal* BkgPolPdfreg=BkgPolPdf->createIntegral(RooArgSet(Xmass),“selection”);

Now, what I want to do is, filling variables(x1, x2, x3) into a histogram if myXsigma is within selected range. Long story short, I need the distribution of variables within 1.5 sigma of my signal region. Any help would be appreciated.

Hi,

You can use the function RooAbsData::createHistogram, something as described in

root.cern.ch/doc/master/classRo … 6da4aae9bb

auto h3 = data->createHistogram(“histo”,x,Binning(xmin,xmax,nbinsX), YVar(y,Binning(ymin,max,nbinsY)), ZVar(z,Binning(zmin,zmax,nbinsZ)))

Lorenzo

Thanks Lorenzo but I more of looking for a 1-d histogram of the distribution of each variables separately. I think your suggestion is 3-d histogram of all x,y,z variables.

Hi,

For 1D it is the same, remove the Y and Z variables information.

auto h1 = data->createHistogram(“histo”,x,Binning(xmin,xmax,nbinsX));

You can look also at the documentation at the given link

Lorenzo

Hi Lorenzo,

actually I tried this

RooDataSet * dataSetS= (RooDataSet::read(FileName,RooArgSet(v0,v1),“Q”);
TH1 * h1 = dataSetS->createHistogram(“v1”);

which is OK to get the distribution of v1. But now the problem is, I need to store this into a tree as a branch that I could not achieve so far. Please take a look at my another post here How to store variables of type RooRealVar as a branch in a tree?

Any idea how to do? Thank you.