Action #3062
Add method that returns number of events in a model component
Status: | Closed | Start date: | 11/08/2019 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assigned To: | Knödlseder Jürgen | % Done: | 100% | |
Category: | - | |||
Target version: | 1.7.0 | |||
Duration: |
Description
A method should be added to GObservations
that returns the number of events in a given model component. A possible implementation would be a method
GObservations::npred(const std::string& name, const std::string& instrument = "")
that returns the number of predicted events for a model name, and optionally, for a given instrument (if the instrument name is blank the number of events should be returned for all instruments).
In addition, a method could also be added that returns the predicted number of events for any kind of model, i.e.
GObservations::npred(const GModel& model, const std::string& instrument = "")
This method would simply loop over the
GObservation::npred(const GModel& model)
method.
Recurrence
No recurrence.
History
#1 Updated by Knödlseder Jürgen about 5 years ago
- Status changed from New to In Progress
- Assigned To set to Knödlseder Jürgen
- Target version set to 1.7.0
- % Done changed from 0 to 50
Both methods were now implemented. Note that the methods invoke the GObservation::npred()
method, meaning that the predicted number of events are actually recomputed. This may eventually take some time, in particular for complex models. It should be checked whether the actual number of events for each model component can be stored in the GObservation
class so that it could be simple read back after model fitting.
#2 Updated by Knödlseder Jürgen about 5 years ago
Here a demonstration of the new methods:
>>> import gammalib
>>> import ctools
>>> sim=ctools.ctobssim()
>>> sim.run()
RA of pointing (degrees) (0-360) [83.63]
Dec of pointing (degrees) (-90-90) [22.51]
Radius of FOV (degrees) (0-180) [5.0]
Start time (UTC string, JD, MJD or MET in seconds) [2020-01-01T00:00:00]
Stop time (UTC string, JD, MJD or MET in seconds) [2020-01-01T00:30:00]
Lower energy limit (TeV) [0.1]
Upper energy limit (TeV) [100.0]
Calibration database [prod2]
Instrument response function [South_0.5h]
Input model definition XML file [$CTOOLS/share/models/crab.xml]
>>> print(sim.obs().npred())
0.0
>>> print(sim.obs().npred('Crab'))
3610.34095249
>>> print(sim.obs().npred('Crab','LAT'))
0.0
>>> print(sim.obs().npred('CTABackgroundModel'))
20275.5905275
>>> print(sim.obs().npred('CTABackgroundModel','LAT'))
0.0
>>> like=ctools.ctlike(sim.obs())
>>> like.run()
>>> print(like.obs().npred())
24046.9982827
>>> print(like.obs().npred('Crab'))
3696.37179287
>>> print(like.obs().npred('Crab','LAT'))
0.0
>>> print(like.obs().npred('CTABackgroundModel'))
20350.6264898
>>> print(like.obs().npred('CTABackgroundModel','LAT'))
0.0
>>> print(like.obs().npred('CTABackgroundModel','CTA'))
20350.6264898
>>>
#3 Updated by Knödlseder Jürgen about 5 years ago
- Status changed from In Progress to Closed
- % Done changed from 50 to 100
Code merged into devel
.