How to plot background subtraction in ROOFIT?

When i finish a fit by “ROOFIT”, how can i draw the background subtracted
data points and the fit line (signal PDF) on another pad? The data points
of signal have minus values after background subtraction.

Hi,

You can substract events by making a weighted dataset. Suppose you start with two datasets, one with all data and one with the bkg data only to be substracted.

RooDataSet *allData, *bkgData ;

You do it as follows

// Assign a weight variable to both datasets
RooRealVar w(“w”,“w”,-1,1) ;
w.setVal(1) ; allData->addColumn(“w”,kFALSE) ;
w.setVal(-1) ; bkgData->addColumn(“w”,kFALSE) ;

// Append datasets and interpret w as event weight
allData->append(*bkgData) ;
allData->setWeightVar(w) ;

Now you can plot allData on your frame

allData->plotOn(frame,DataError(RooAbsData::SumW2)) ;

Note that you need to select sum-of-weight error bars for the histogram now as the default Poisson error bars are not applicable to weighted events.

See $ROOTSYS/tutorials/roofit/rf403_weightedevts.C for some more info on dealing with weighted events.

Wouter

Because the event number is very large, i have to use RooDataHist.
I use these lines to do the subtraction, but when i define the New RooDataHist, the minus values bins of the subtracted hist are all
set to zero.
How can i convert the new Th1F to RooDataHist with minus bin content and draw the fit curve on it?
eg is the data histogram
bkg is the bkg pdf.

TH1D subbkg=(TH1D)bkg.createHistogram(“subbkg”,energy);
eg->Add(subbkg,-double(nbkg.getVal()));
RooDataHist* egsub = new RooDataHist(“egsub”, “Photon Energy(GeV)”, energy, eg);

hi,

how am i able to do that nowadays since Exception:
ERROR: RooDataSet::setWeightVar() is deprecated. Specify weight variable in RooDataSet constructor instead using WeightVar()

I split my signal and background slices using the reduce method… then i cant really give the weight in the contructor argument.

thanks,
kazu.