/***********************************************************************//** * @brief Get application parameters * * Get all task parameters from parameter file or (if required) by querying * the user. The parameters are read in the correct order. ***************************************************************************/ void ctmodel::get_parameters(void) { // Reset cube append flag m_append_cube = false; // If there are no observations in container then load them via user // parameters. if (m_obs.size() == 0) { get_obs(); } // If we have now excactly one CTA observation (but no cube has yet been // appended to the observation) then check whether this observation // is a binned observation, and if yes, extract the counts cube for // model generation if ((m_obs.size() == 1) && (m_append_cube == false)) { // Get CTA observation GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[0]); // Continue only if observation is a CTA observation if (obs != NULL) { // Check for binned observation if (obs->eventtype() == "CountsCube") { // Set cube from binned observation GCTAEventCube* evtcube = dynamic_cast<GCTAEventCube*>(const_cast<GEvents*>(obs->events())); cube(*evtcube); // Signal that cube has been set m_has_cube = true; // Signal that we are in binned mode m_binned = true; } // endif: observation was binned } // endif: observation was CTA } // endif: had exactly one observation // Read model definition file if required if (m_obs.models().size() == 0) { // Get model filename std::string inmodel = (*this)["inmodel"].filename(); // Load models from file m_obs.models(inmodel); } // endif: there were no models // Get energy dispersion flag parameters m_apply_edisp = (*this)["edisp"].boolean(); // If we do not have yet a counts cube for model computation then check // whether we should read it from the "incube" parameter or whether we // should create it from scratch using the task parameters if (!m_has_cube) { // Read cube definition file std::string incube = (*this)["incube"].filename(); // If no cube file has been specified then create a cube from // the task parameters ... if ((incube == "NONE") || (gammalib::strip_whitespace(incube) == "")) { // Create cube from scratch m_cube = create_cube(m_obs); } // ... otherwise load the cube from file and reset all bins // to zero else { // Load cube from given file m_cube.load(incube); // Set all cube bins to zero for (int i = 0; i < m_cube.size(); ++i) { m_cube[i]->counts(0.0); } } // Signal that cube has been set m_has_cube = true; } // endif: we had no cube yet // Read optionally output cube filenames if (read_ahead()) { m_outcube = (*this)["outcube"].filename(); } // If cube should be appended to first observation then do that now. // This is a kluge that makes sure that the cube is passed as part // of the observation in case that a cube response is used. The kluge // is needed because the GCTACubeSourceDiffuse::set method needs to // get the full event cube from the observation. It is also at this // step that the GTI, which may just be a dummy GTI when create_cube() // has been used, will be set. if (m_append_cube) { //TODO: Check that energy boundaries are compatible // Attach GTI of observations to model cube m_cube.gti(m_obs[0]->events()->gti()); // Attach model cube to observations m_obs[0]->events(m_cube); } // endif: cube was scheduled for appending // Return return; }
/***********************************************************************//** * @brief Generate the model map(s) * * This method reads the task parameters from the parfile, sets up the * observation container, loops over all CTA observations in the container * and generates a model map for each CTA observation. ***************************************************************************/ void ctmodel::run(void) { // If we're in debug mode then all output is also dumped on the screen if (logDebug()) { log.cout(true); } // Get task parameters get_parameters(); // Write parameters into logger if (logTerse()) { log_parameters(); log << std::endl; } // Set energy dispersion flag for all CTA observations and save old // values in save_edisp vector std::vector<bool> save_edisp; save_edisp.assign(m_obs.size(), false); for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); if (obs != NULL) { save_edisp[i] = obs->response()->apply_edisp(); obs->response()->apply_edisp(m_apply_edisp); } } // Write observation(s) into logger if (logTerse()) { log << std::endl; if (m_obs.size() > 1) { log.header1("Observations"); } else { log.header1("Observation"); } log << m_obs << std::endl; } // Write models into logger if (logTerse()) { log << std::endl; log.header1("Models"); log << m_obs.models() << std::endl; } // Write header if (logTerse()) { log << std::endl; log.header1("Generate model cube"); } // Loop over all observations in the container for (int i = 0; i < m_obs.size(); ++i) { // Write header for observation if (logTerse()) { std::string header = m_obs[i]->instrument() + " observation"; if (m_obs[i]->name().length() > 1) { header += " \"" + m_obs[i]->name() + "\""; } if (m_obs[i]->id().length() > 1) { header += " (id=" + m_obs[i]->id() +")"; } log.header3(header); } // Get CTA observation GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); // Skip observation if it's not CTA if (obs == NULL) { if (logTerse()) { log << " Skipping "; log << m_obs[i]->instrument(); log << " observation" << std::endl; } continue; } // Fill cube and leave loop if we are binned mode (meaning we // only have one binned observation) if (m_binned) { fill_cube(obs); break; } // Skip observation if we have a binned observation if (obs->eventtype() == "CountsCube") { if (logTerse()) { log << " Skipping binned "; log << obs->instrument(); log << " observation" << std::endl; } continue; } // Fill the cube fill_cube(obs); // Dispose events to free memory if event file exists on disk if (obs->eventfile().length() > 0 && gammalib::file_exists(obs->eventfile())) { obs->dispose_events(); } } // endfor: looped over observations // Log cube if (logTerse()) { log << std::endl; log.header1("Model cube"); log << m_cube << std::endl; } // Restore energy dispersion flag for all CTA observations for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); if (obs != NULL) { obs->response()->apply_edisp(save_edisp[i]); } } // Return return; }