32 Generates energy boundaries for stacked analysis
41 self._init_csobservation(self.__class__.__name__, ctools.__version__, argv)
53 Get parameters from parfile
56 if self.obs().size() == 0:
60 if self[
'inobs'].is_valid():
61 self.obs(gammalib.GObservations(self[
'inobs'].filename()))
63 cta = gammalib.GCTAObservation()
64 mission = gammalib.tolower(self[
'instrument'].string())
65 caldb = gammalib.GCaldb(mission, self[
'caldb'].string())
66 rsp = gammalib.GCTAResponseIrf(self[
'irf'].string(), caldb)
67 cta.instrument(mission)
69 self.obs().append(cta)
74 self[
'aeffthres'].real()
75 self[
'bkgthres'].real()
78 if self._read_ahead():
79 self[
'outfile'].filename()
82 self._log_parameters(gammalib.TERSE)
89 Set energy boundaries for one CTA observation
93 responses : list of dict
94 List of response dictionaries
96 Energy to insert (TeV)
98 Reason for energy insertion
101 logE = math.log10(energy)
102 for rsp
in responses:
103 rsp[
'thres'] = rsp[
'irf'](logE, 0.0, 0.0)
106 eng = gammalib.GEnergy(energy,
'TeV')
109 msg = str(energy)+
' TeV'
111 msg +=
' ('+comment+
')'
115 if self._ebounds.size() == 0:
118 self._ebounds.append(eng, eng)
121 self._log_value(gammalib.NORMAL,
'First boundary', msg)
124 elif self._ebounds.size() > 0:
128 if self._ebounds.emin() == self._ebounds.emax():
131 emin = self._ebounds.emin().copy()
133 self._ebounds.remove(0)
134 self._ebounds.append(emin, emax)
137 self._log_value(gammalib.NORMAL,
'Boundary', msg)
142 emin = self._ebounds.emax()
144 self._ebounds.append(emin, eng)
147 self._log_value(gammalib.NORMAL,
'Boundary', msg)
154 Set energy boundaries for one CTA observation
158 obs : `~gammalib.GObservations`
162 emin = self[
'emin'].real()
163 emax = self[
'emax'].real()
164 aeffthres = self[
'aeffthres'].real()
165 bkgthres = self[
'bkgthres'].real()
174 mission = run.response().caldb().mission()
175 instrument = run.response().caldb().instrument()
176 rspname = run.response().rspname()
177 name =
'%s::%s::%s' % (mission, instrument, rspname)
181 for rsp
in responses:
182 if rsp[
'name'] == name:
189 aeff = {
'name': name,
'type':
'Aeff',
190 'irf': run.response().aeff(),
'thres': 0.0}
191 bkg = {
'name': name,
'type':
'Background',
192 'irf': run.response().background(),
'thres': 0.0}
193 responses.append(aeff)
194 responses.append(bkg)
197 self._log_value(gammalib.NORMAL,
'Append response',
'%s (%s) [%s]' %
198 (rspname, instrument, mission))
201 logEs = [math.log10(1.0e-3*float(i))
for i
in range(int(emin*1000),int(emax*1000))]
207 for rsp
in responses:
210 irf = rsp[
'irf'](logE, 0.0, 0.0)
213 if rsp[
'type'] ==
'Aeff':
214 threshold = aeffthres
220 if rsp[
'thres'] == 0.0
and irf > 0.0:
226 elif rsp[
'thres'] != 0.0:
228 if 1.0-f > threshold
or f-1.0 > threshold:
236 self._log_value(gammalib.NORMAL,
'Number of boundaries', self._ebounds.size())
251 self._log_observations(gammalib.NORMAL, self.obs(),
'Input observation')
254 self._log_header1(gammalib.TERSE,
'Define energy boundaries')
264 Save energy boundaries
267 self._log_header1(gammalib.TERSE,
'Save energy boundaries')
270 outfile = self[
'outfile'].filename()
273 self._log_value(gammalib.NORMAL,
'Energy boundaries file', outfile.url())
276 self._ebounds.save(outfile, self._clobber())
286 Return energy boundaries
290 ebounds : `~gammalib.GEbounds()`
300 if __name__ ==
'__main__':