/***********************************************************************//** * @brief Get application parameters * * Get all task parameters from parameter file or (if required) by querying * the user. Most parameters are only required if no observation exists so * far in the observation container. In this case, a single CTA observation * will be added to the container, using the definition provided in the * parameter file. ***************************************************************************/ void ctobssim::get_parameters(void) { // Initialise seed vector m_rans.clear(); // If there are no observations in container then load them via user // parameters if (m_obs.size() == 0) { m_obs = get_observations(); } // ... otherwise make sure that observation boundaries are set else { set_obs_bounds(m_obs); } // Read model definition file if required if (m_obs.models().size() == 0) { std::string inmodel = (*this)["inmodel"].filename(); m_obs.models(inmodel); } // Get other parameters m_seed = (*this)["seed"].integer(); m_apply_edisp = (*this)["edisp"].boolean(); m_max_rate = (*this)["maxrate"].real(); // Optionally read ahead parameters so that they get correctly // dumped into the log file if (read_ahead()) { m_outevents = (*this)["outevents"].filename(); m_prefix = (*this)["prefix"].string(); } // Initialise random number generators. We initialise here one random // number generator per observation so that each observation will // get it's own random number generator. This will lead to identical // results independently of code parallelization with OpenMP. The // seeds for all random number generators are derived randomly but // fully deterministacally from the seed parameter, so that a given // seed parameter leads always to the same set of simulated events, and // this independently of parallelization. // Get a random number generator for seed determination GRan master(m_seed); // Allocate vector of random number generator seeds std::vector<unsigned long long int> seeds; // Loop over all observations in the container for (int i = 0; i < m_obs.size(); ++i) { // Allocate new seed value unsigned long long int new_seed; // Determine new seed value. We make sure that the new seed // value has not been used already for another observation. bool repeat = false; do { new_seed = (unsigned long long int)(master.uniform() * 1.0e10) + m_seed; repeat = false; for (int j = 0; j < seeds.size(); ++j) { if (new_seed == seeds[j]) { repeat = true; break; } } } while(repeat); // Add the seed to the vector for bookkeeping seeds.push_back(new_seed); // Use the seed to create a random number generator for the // actual observation m_rans.push_back(GRan(new_seed)); } // endfor: looped over observations // Return return; }
/***********************************************************************//** * @brief Get observation container * * Get an observation container according to the user parameters. The method * supports loading of a individual FITS file or an observation definition * file in XML format. * * If the input filename is empty, the method checks for the existence of the * "expcube", "psfcube" and "bkgcube" parameters. If file names have been * specified, the method loads the files and creates a dummy events cube that * is appended to the observation container. * * If no file names are specified for the "expcube", "psfcube" or "bkgcube" * parameters, the method reads the necessary parameters to build a CTA * observation from scratch. * * The method sets m_append_cube = true and m_binned = true in case that * a stacked observation is requested (as detected by the presence of the * "expcube", "psfcube", and "bkgcube" parameters). In that case, it appended * a dummy event cube to the observation. ***************************************************************************/ void ctmodel::get_obs(void) { // Get the filename from the input parameters std::string filename = (*this)["inobs"].filename(); // If no observation definition file has been specified then read all // parameters that are necessary to create an observation from scratch if ((filename == "NONE") || (gammalib::strip_whitespace(filename) == "")) { // Get response cube filenames std::string expcube = (*this)["expcube"].filename(); std::string psfcube = (*this)["psfcube"].filename(); std::string bkgcube = (*this)["bkgcube"].filename(); // If the filenames are valid then build an observation from cube // response information if ((expcube != "NONE") && (psfcube != "NONE") && (bkgcube != "NONE") && (gammalib::strip_whitespace(expcube) != "") && (gammalib::strip_whitespace(psfcube) != "") && (gammalib::strip_whitespace(bkgcube) != "")) { // Get exposure, PSF and background cubes GCTACubeExposure exposure(expcube); GCTACubePsf psf(psfcube); GCTACubeBackground background(bkgcube); // Create energy boundaries GEbounds ebounds = create_ebounds(); // Create dummy sky map cube GSkyMap map("CAR","GAL",0.0,0.0,1.0,1.0,1,1,ebounds.size()); // Create event cube GCTAEventCube cube(map, ebounds, exposure.gti()); // Create CTA observation GCTAObservation cta; cta.events(cube); cta.response(exposure, psf, background); // Append observation to container m_obs.append(cta); // Signal that we are in binned mode m_binned = true; // Signal that we appended a cube m_append_cube = true; } // endif: cube response information was available // ... otherwise build an observation from IRF response information else { // Create CTA observation GCTAObservation cta = create_cta_obs(); // Set response set_obs_response(&cta); // Append observation to container m_obs.append(cta); } } // endif: filename was "NONE" or "" // ... otherwise we have a file name else { // If file is a FITS file then create an empty CTA observation // and load file into observation if (gammalib::is_fits(filename)) { // Allocate empty CTA observation GCTAObservation cta; // Load data cta.load(filename); // Set response set_obs_response(&cta); // Append observation to container m_obs.append(cta); // Signal that no XML file should be used for storage m_use_xml = false; } // ... otherwise load file into observation container else { // Load observations from XML file m_obs.load(filename); // For all observations that have no response, set the response // from the task parameters set_response(m_obs); // Set observation boundary parameters (emin, emax, rad) set_obs_bounds(m_obs); // Signal that XML file should be used for storage m_use_xml = true; } // endelse: file was an XML file } // Return return; }