lucabaldini / ixpeobssim

Simulation and analysis framework for the Imaging X-ray Polarimetry Explorer
GNU General Public License v3.0
10 stars 13 forks source link

Radial bkg #666

Closed lucabaldini closed 1 year ago

albertomanfreda commented 1 year ago

This does not seem to work. Testing against the second BL Lac observation data I get:

r

and I have to multiply the slope by a factor 5 to get the radial profile kind of correct:

r_slope_times_5

However the profiles of x and y are still wrong:

x_slope_times_5

y_slope_times_5

lucabaldini commented 1 year ago

Thanks Alberto. Can you post the relevant lines of the configuration file that you used? I suspect we're using different definitions for the slope---the one implemented in the code is normalized to the value at the center of the field and it goes from -1 to 2, with typical values in the 0.1--0.2 range.

I am kind of puzzled by the x and y distribution. We should probably look at them more carefully---it might very well be that the radial profile by itself is not the full story.

albertomanfreda commented 1 year ago

The slope I am using is ~0.053, which is the slope from the fit to the data divided by the value of the data at r = 3.5

path_bllac = os.path.join(IXPEOBSSIM_SRCMODEL, 'ascii', 'bkg_conservative_Bl_lac_2.txt')

bkg = xTemplateInstrumentalBkg(file_path = path_bllac, radial_slope=0.05325524441190497)

albertomanfreda commented 1 year ago

The slope seems wrong in the unit test as well. From the fit

Radial_background_r

it looks like something around ~90 for a value at the center of the field of order 3000, so the ratio should be something slightly larger than 0.03. However the relevant lines of codes are

def test_sample(self, half_size=7., num_events=1000000, slope=0.2):
        """Convenience function for the direct transform (radial -> xy).
        """
        radius = numpy.sqrt(2.) * half_size
        x, y = xRadialBackgroundGenerator(half_size, half_size, slope).rvs_xy(num_events)
lucabaldini commented 1 year ago

Ok we're definitely not using the same conventions. I spend quite some time writing the docs and I thought it was clear, but clearly it is not---I welcome suggestions about how to improve.

My proposal for the definition of the "radial slope", given a linear model f(r) = m r + q, was to use m r_0 / f(r_0 / 2) and not m / f(r_0 / 2), where r_0 is the side of the fiducial rectangle. This is an dimensionless quantity representing the total excursion along the y axis divided by the value at the center of the field, and is bound between -1 and 2. Your prescription has the physical dimensions of mm^-1 and the numerical value depend on the size of the detector. I am willing to be convinced that your proposal is better, but I would need more context.

On a related note: would it make sense to have a binning algorithm in xpbin that produces this radial plot, since it looks like a useful thing that we would probably use?

albertomanfreda commented 1 year ago

which side of the fiducial rectangle is r_0? The shortest, the longest or an average? Also, is it the side or half the side?