Add unpolarized unbinned source injector capability [Yong2Sheng's]#499
Add unpolarized unbinned source injector capability [Yong2Sheng's]#499israelmcmc wants to merge 3 commits intocositools:developfrom
Conversation
|
I will add the unit tests after the changes have been reviewed and approved. I’d like to avoid adding them too early, since they may need to be updated if the code changes during review. |
Documentation build overview
Show files changed (10 files in total): 📝 8 modified | ➕ 2 added | ➖ 0 deleted
|
|
Hi @ldigesu , I have added the saving function. Could you please take a look? Thank you! |
|
Hello Yong, I suggest adding an introductory paragraph at the beginning of the notebook, describing what this simulator does and what it is expected to produce as outputs. Something like the summary written in this PR should be ok. Secondly, I thinks the tutorial is missing some sanity checks of the outputs. All the plots run correctly to show the simulated data, but there is no comparison with what was input, thus no checks that what was produced by the simulator is indeed what we expected. The saved fits output cannot be used in a binned analysis: the binning function does not work, because it can't find the Time Tags of the photons. Thus, my suggestion as a sanity check is the following: instead of showing as an example a random point source, you could take one of the point sources of DC3 e.g., a bright GRB or the Crab nebula, and simulate exactly the same position, spectrum, source duration, ecc.. Then you can produce plots from your simulator and from the fits file produced by Megalib and show that they are consistent. Let me know if this could work. Thirdly, I remind you Israel's comment to PR #528 (here above), that is relevant to this PR. Finally, a last minor comment: I find the last plot showing the distribution of the photons in the CDS not particularly explanatory. I understand that there are no Galactic coordinates in these data, thus no way to visualize a ring around the expected source position. However, maybe you could try to you apply some cuts in Energy or Phi angles before plotting and see if point clusters. I suggest in any case to add a note for inexperienced COSI users explaining that in local/spacecraft coordinates, no ring/cone can be visualized. Thanks! Let me know If everything is clear, |
|
Thanks for the comments @ldigesu About this:
Maybe we can do a better job for that plot and the explanation, but the point of the plot is that if you take all the event with a given phi (color coded) then they should make a circle with radius=phi around the location of the source (the cross). It's a visualization of the Compton cone, using a colorbar for Phi instead ofa "z-axis". |
I'm bringing @Yong2Sheng from my fork to develop, now that the interfaces branch is merged.
Summary
This PR introduces an initial implementation for unpolarized unbinned continuum point source injector in the spacecraft frame. It follows the existing line injector workflow, but with additional steps to (1) compute the integrated detected rate across an energy band and (2) sample detected photon energies across that band.
Compute incident photons and simulate events
1) Define a continuum spectrum (differential photon flux)
A power-law spectrum is used as the working example in the tutorial:
where$K$ is the normalization (differential flux at the pivot energy $\mathrm{piv}$ ).
2) Convolve the spectrum with effective area
The detected count-rate density is
3) Integrate$w(E)$ to get the total detected rate and total counts
The integrated detected photon rate is
In practice, the spectrum might not be analytical. And the effective area is also usually not analytical as well. So we do not perform the integral directly. Instead, we will use a very fine energy grid to obtain the integral by trapezoids.
The expected detected counts is
and the realized detected counts are sampled as
4) Build an inverse-CDF sampler to draw detected photon energies
scipy.interpolate.interp1dwith linear interpolation.5) Simulate each sampled energy
Feed the sampled photon energies (and their multiplicities, although they should show up only once) into
UnpolarizedIdealComptonIRF.random_events(...)to produce the event list.Implementation notes
RandomEventDataFromContinuumInSCFrameis responsible for continuum injection.@cached_property:energy_gridunpolarized_aeffunpol_countsincident_photonsunpol_counts) bookkeeping:UnpolCountsSummary(rate_density, rate, total_expected_counts)What is not included yet