Hi Danilo,
thanks for the swift answer. I checked the documentation of RooWorkSpace, unfortunately it did not help me getting to an adequate solution.
I managed to get it to work in another way though. For anybody who is interested in this:
- As soon as I initialize a RooHistPDF, I immediately typecast it into a (TH1F*) and write it to file:
RooDataHist roodatahist_of_a_normal_histogram("roodatahist_of_a_normal_histogram","roodatahist_of_a_normal_histogram",x,normal_histogram);
RooHistPdf roohistpdf_of_the_roodatahist("roohistpdf_of_the_roodatahist","roohistpdf_of_the_roodatahist",x,roodatahist_of_a_normal_histogram,0);
RooRealVar fraction_of_roohistpdf_of_the_roodatahist_that_is_needed_for_later_for_fitting("fraction_of_roohistpdf_of_the_roodatahist_that_is_needed_for_later_for_fitting", "fraction_of_roohistpdf_of_the_roodatahist_that_is_needed_for_later_for_fitting", 0., 0., upperlimit_for_fraction);
TH1F* pdf_converted_back_to_normalhisto = (TH1F*)(roohistpdf_of_the_roodatahist.createHistogram("x",highest_bin_of_roohistpdf));
outputfile->cd();
pdf_converted_back_to_normalhisto->Write();
- As soon as I perform any action on the RooHistPDF, like fitting, summing or convoluting, I do the same procedure again. This helps me to keep track on how the current PDF actual looks like, for example to see whether it has been scaled or shifted already.
- When I’m done with all the fitting, I identify the histogram of the PDF that has been shifted along the x axis after fitting. As it corresponds to a PDF, it is normalized to 1.
- I then get the value of the parameter that has been used during the fit to scale the PDF to the value of the real data. In this case, this is ‘fraction_of_roohistpdf_of_the_roodatahist_that_is_needed_for_later_for_fitting’:
Float_t scalingfactorValue_after_fit = fraction_of_roohistpdf_of_the_roodatahist_that_is_needed_for_later_for_fitting.getValV();
Float_t scalingfactorError_after_fit = fraction_of_roohistpdf_of_the_roodatahist_that_is_needed_for_later_for_fitting.getError();
- I then scale the histogram of the PDF that has been shifted along the x axis by this using the ->Scale() function:
histogram_of_PDF_thathasBeenShiftedAlongXAxis_after_fit->Scale(scalingfactorValue_after_fit);
histogram_of_PDF_thathasBeenShiftedAlongXAxis_after_fit->Write();
This gives me the correct histogram of a spectrum that has been fitted to the real data, whereas the fit did allow for a scaling and for a shifting along the x axis.
Sidenote: In order to get a RooHistPDF that can be shifted along the x axis, you can do the following:
RooRealVar shift_along_xAxis("shift_along_xAxis","shift_along_xAxis",startingvalue_of_shift,allowedShift_lowerbound,allowedShift_higherbound);
RooFormulaVar combination_of_x_and_shiftAlongXAxis("combination_of_x_and_shiftAlongXAxis","x-shift_along_xAxis",RooArgSet(x,shift_along_xAxis));
RooHistPdf roohistpdf_of_the_roodatahist_withShift("roohistpdf_of_the_roodatahist_withShift","roohistpdf_of_the_roodatahist_withShift",combination_of_x_and_shiftAlongXAxis,x,roohistpdf_of_the_roodatahist,0);
The string “x-shift_along_xAxis” actually defines the new variable that enables the shift along x.
However, I think getting the correct histograms after fitting should be way simpler. If anybody has time for that, he or she could implement this whole procedure as a simple function in the next version of ROOFIT.