36#define G_PROCESS "ctbkgcube::process()"
187 this->GApplication::clear();
221 log_header1(TERSE,
"Prepare model");
225 GModels models_orig =
m_obs.models();
230 std::string instruments;
236 for (
int i = num-1; i >= 0; --i) {
243 if ((
dynamic_cast<GModelData*
>(
m_bkgmdl[i]) != NULL) &&
244 (
m_bkgmdl[i]->classname().substr(0,4) ==
"GCTA")) {
250 if (instruments.length() > 0) {
253 instruments +=
m_bkgmdl[i]->instruments();
257 std::string what = (remove) ?
"Remove model" :
"Keep model";
260 log_value(NORMAL, what, value);
276 std::string msg =
"No background model found in model container. "
277 "At least one background model is required in the "
278 "model container to generate a background cube.";
279 throw GException::invalid_value(
G_PROCESS, msg);
283 log_header1(TERSE,
"Generate background cube");
289 GLog* logger = (logNormal()) ? &log : NULL;
296 GSkyMap* bkg =
const_cast<GSkyMap*
>(&
m_background.cube());
297 for (
int pixel = 0; pixel <
m_cube.npix(); ++pixel) {
298 for (
int iebin = 0; iebin <
m_cube.ebins(); ++iebin) {
299 double weight =
m_cube.weights()(pixel, iebin);
301 (*bkg)(pixel, iebin) /= weight;
310 GModelSpectralPlaw spectral(1.0, 0.0, GEnergy(1.0,
"TeV"));
311 spectral[
"Prefactor"].range(0.01, 100.0);
312 spectral[
"Index"].range(-5.0, 5.0);
313 GCTAModelCubeBackground model(spectral);
316 model.name(
"BackgroundModel");
320 model.instruments(
"CTA,HESS,MAGIC,VERITAS,ASTRI");
332 m_obs.models(models_orig);
353 log_header1(TERSE,
"Save background cube");
356 bool write_moddef = (*this)[
"outmodel"].is_valid();
360 if ((*
this)[
"outcube"].is_valid() && !
m_background.cube().is_empty()) {
363 m_outcube = (*this)[
"outcube"].filename();
385 std::string mname = (write_moddef) ?
m_outmodel.url() :
"NONE";
387 fname.append(
" (cube is empty, no file created)");
389 log_value(NORMAL,
"Background cube file", fname);
390 log_value(NORMAL,
"Model definition file", mname);
405 log_header1(TERSE,
"Publish background cube");
408 std::string user_name(name);
409 if (user_name.empty()) {
414 log_value(NORMAL,
"Publish background cube", user_name);
500 m_cube = GCTAEventCube((*
this)[
"incube"].filename());
510 m_publish = (*this)[
"publish"].boolean();
511 m_chatter =
static_cast<GChatter
>((*this)[
"chatter"].integer());
515 (*this)[
"outcube"].query();
516 (*this)[
"outmodel"].query();
Background cube generation tool.
ctbkgcube & operator=(const ctbkgcube &app)
Assignment operator.
GCTACubeBackground m_background
Background cube.
ctbkgcube(void)
Void constructor.
void copy_members(const ctbkgcube &app)
Copy class members.
GChatter m_chatter
Chattiness.
virtual ~ctbkgcube(void)
Destructor.
void process(void)
Generate the background cube(s).
GFilename m_outcube
Filename of output cube.
void save(void)
Save background cube.
GModels m_bkgmdl
CTA background models.
void get_parameters(void)
Get application parameters.
bool m_publish
Publish background cube?
void free_members(void)
Delete class members.
GFilename m_outmodel
Filename of output XML model.
void init_members(void)
Initialise class members.
GModels m_outmdl
Output models.
void clear(void)
Clear ctbkgcube tool.
void publish(const std::string &name="")
Publish background cube.
GCTAEventCube m_cube
Event cube.
Base class for observation tools.
void free_members(void)
Delete class members.
ctobservation & operator=(const ctobservation &app)
Assignment operator.
GObservations m_obs
Observation container.
void init_members(void)
Initialise class members.
Background cube generation tool definition.