Skip to content

Commit

Permalink
create derive_events_rate
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorBarbosaMartins committed Feb 5, 2024
1 parent f04912f commit aca10de
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions ctao_cosmic_ray_spectra/spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,31 +235,34 @@ def integrate_area(self, area):
)

@u.quantity_input(energy=u.TeV)
def integrate_energy(self, energy):
def integrate_energy(self, energy_min, energy_max):
"""
Integrate this powerlaw over the given energy range.
Parameters
----------
energy: tuple of astropy.units.Quantity[energy]
Energy range of integration (min, max).
energy_min: astropy.units.Quantity[energy]
Minimum energy in the integration.
energy_max: astropy.units.Quantity[energy]
Maximum energy in the integration.
Returns
-------
integrated : PowerLaw
A new area integrated powerlaw instance.
"""

nominator = energy[1] ** (self.index + 1) - energy[0] ** (self.index + 1)
nominator = energy_max ** (self.index + 1) - energy_min ** (self.index + 1)
denominator = (self.index + 1) * self.e_ref**self.index

return nominator/denominator * self.normalization

@u.quantity_input(inner=u.deg, outer=u.deg, area=u.cm**2, energy=u.TeV)
@u.quantity_input(inner=u.deg, outer=u.deg, area=u.cm**2, energy_min=u.TeV, energy_max=u.TeV)
def derive_events_rate(self,
inner, outer,
area,
energy):
energy_min,
energy_max):
"""
Integrate all the quantities from the spectrum (except time)and derive the events rate
expected for an integration in a region of space (inner, outer), over the area of the
Expand All @@ -275,17 +278,18 @@ def derive_events_rate(self,
Observation time to integrate the flux.
area: astropy.units.Quantity[area]
Observation time to integrate the flux.
energy: tuple of astropy.units.Quantity[energy]
Energy range of integration (min, max).
energy_min: astropy.units.Quantity[energy]
Minimum energy in the integration.
energy_max: astropy.units.Quantity[energy]
Maximum energy in the integration.
Returns
-------
float:
events rate integrated from the spectral distribution.
"""
spectrum_cone = self.integrate_cone(inner, outer)
spectrum_area = spectrum_cone.integrate_area(area)
return (spectrum_area.integrate_energy(energy)).decompose()
return (spectrum_area.integrate_energy(energy_min, energy_max).decompose()

@u.quantity_input(inner=u.deg, outer=u.deg, obstime=u.s, area=u.cm**2, energy=u.TeV)
def derive_number_events(self,
Expand Down

0 comments on commit aca10de

Please sign in to comment.