To neglect fluctuations, we want to fit the background now to get a good background model, it looks very exponential:
TF1 *fit = new TF1("f1", "[0] + exp([2]*x+[1])", -1, 12);
hBkg -> Fit(fit);
fit -> SetLineColor(kRed);
c->Draw();
Great, if we now look at the difference between data und background we should be able to see a possible signal, let's create a new histogram in which we store the difference:
TH1D *hDiff = (TH1D*)hData -> Clone(0);
int nBins = hData->GetNbinsX();
We need to loop over the bins and calculate the difference between data and fit for each bin. This is how you can get the information:
`hData->GetXaxis()->GetBinCenter(iBin); hData->GetBinContent(iBin); fit -> Eval(binCenter);`
for(int iBin = 1; iBin <= nBins; ++iBin){
double binCenter = hData->GetXaxis()->GetBinCenter(iBin);
double dataValue = hData->GetBinContent(iBin);
double functionVal = fit -> Eval(binCenter);
double difference = dataValue - functionVal;
hDiff -> SetBinContent(iBin, difference);
}
Let's plot this in the second pad below the first one:
pad2 -> cd();
Make the histogram a bit nicer and draw:
hDiff -> Draw();
c -> Draw();
In order to better visualize an excess or deficiency, we can draw a line at zero.
TF1 *zero = new TF1("zero", "0", 100, 160);
zero -> SetLineColor(kBlack);
zero -> SetLineWidth(3);
zero -> SetLineStyle(2);
zero -> Draw("SAME");
c->Draw();