Im using roofit v3.52. I am trying to fit data which falls within a circular region. The data basically forms a 2D Gaussian. When fitting to this distribution I seem to be having two issues with roofit. I’ll start with what’s probably the easier of the two problems
- To test my fit method I generate a generic 2D gaussian pdf using RooGenericPdf. I then generate a RooDataSet from this as follows:
TString generatingFnc("exp(-(@0^2+@1^2)/(2*@2^2))"); RooGenericPdf gauss("gauss","2D Guassian", generatingFnc, RooArgList(x, y, csigma)); RooDataSet *testdata = gauss.generate(RooArgSet(x,y), Ntot);
x and y are obviously coordinates (RooRealVar’s) and csigma is the sigma of the gaussian (a RooConstVar). For some reason when csigma is set to 0.05 (about the correct value for my actual data) the generated RooDataSet has no data just below x~0. If I set csigma larger it seems to do fine. A look at some projections shows that the data is completely missing. The fit to this dataset works, but it is clearly affected. Is there anything I may have done accidentally to cause this? I will attach some short code to illustrate this problem. The script also automatically generates some plots showing the missing data.
- For the actual data I am fitting I have no data past a certain distance from the center of my circular region, so my gaussian distribution could be cuttoff if it’s near the edge. To correct for this I am setting up a circular range for x and y for my fit via the following:
// Set region of map to fit (a circle) RooFormulaVar xlo("xlo","-sqrt(@0*@0-@1*@1)",RooArgSet(RooConst(radi), y)); RooFormulaVar xhi("xhi","sqrt(@0*@0-@1*@1)",RooArgSet(RooConst(radi), y)); y.setRange("circle", -radi, radi); x.setRange("circle", xlo, xhi);
(where radi is the cutoff distance from the center) and fitting to my distribution via:
RooFitResult *fitresult = extfitgauss.fitTo(*testdata, PrintLevel(-1), Range("circle"));
but the fit crashes. If I dont use RooFormulaVar’s in “x.setRange” this problem goes away. But then I’m not fitting to the circular region where my data is defined and the fit may not be accurate. Is this a bug, or is there another way I should be using to fit to a circular range?
I have attached a shortened version of my code which illustrates my problems. I have commented out the code which generates problem 2, but it’s easy enough to see what needs to be changed. If not, I can upload a version which causes problem 2.
This is my first post here, so if anything above needs changing (such as breaking these questions into two separate posts) or if you need more information please let me know.
2DGaussFit_CircularRegion.C (4.05 KB)