Commit e6d349bfe027c02228dd04f63f1cff22bf2eddfc

Authored by Jürgen Knödlseder
1 parent 8d19bf6c

Support of map cubes lying outside RoI in ctobssim

ChangeLog
1 -2017-03-24 1 +2017-03-28
2 2
3 * Version 1.3.0 released 3 * Version 1.3.0 released
4 ======================== 4 ========================
5 5
  6 + Support of map cubes lying outside RoI in ctobssim
6 Support energy boundary FITS file in ctmapcube (#1978) 7 Support energy boundary FITS file in ctmapcube (#1978)
7 Add csebins script (#1976) 8 Add csebins script (#1976)
8 Consider RoI in ctskymap and use numerical integration for IRF (#1975) 9 Consider RoI in ctskymap and use numerical integration for IRF (#1975)
1 New Features and Important Changes in ctools 1.3.0.dev1 1 New Features and Important Changes in ctools 1.3.0.dev1
2 2
3 -24 March 2017 3 +28 March 2017
4 4
5 5
6 Introduction 6 Introduction
@@ -27,7 +27,10 @@ so that writing commas instead of dots is avoided (#1370). @@ -27,7 +27,10 @@ so that writing commas instead of dots is avoided (#1370).
27 27
28 ctobssim - CTA observation simulation 28 ctobssim - CTA observation simulation
29 ------------------------------------- 29 -------------------------------------
30 -None 30 +The tool now supports map cubes that are not overlapping with the RoI.
  31 +In this case, no spectral nodes exist and before the spectral flux()
  32 +method called in ctobssim::get_model_flux() was throwing an exception.
  33 +Now, for map cubes outside the RoI the flux is set to zero.
31 34
32 35
33 ctselect - CTA event selection 36 ctselect - CTA event selection
src/ctobssim/ctobssim.cpp
@@ -722,6 +722,11 @@ void ctobssim::simulate_source(GCTAObservation* obs, @@ -722,6 +722,11 @@ void ctobssim::simulate_source(GCTAObservation* obs,
722 GRan& ran, 722 GRan& ran,
723 GLog* wrklog) 723 GLog* wrklog)
724 { 724 {
  725 + // Debug code: signal that we step into the simulate_source method
  726 + #if defined(G_SOURCE_DEBUG)
  727 + std::cout << "ctobssim::simulate_source: in" << std::endl;
  728 + #endif
  729 +
725 // Continue only if observation pointer is valid 730 // Continue only if observation pointer is valid
726 if (obs != NULL) { 731 if (obs != NULL) {
727 732
@@ -898,6 +903,11 @@ void ctobssim::simulate_source(GCTAObservation* obs, @@ -898,6 +903,11 @@ void ctobssim::simulate_source(GCTAObservation* obs,
898 903
899 } // endif: observation pointer was valid 904 } // endif: observation pointer was valid
900 905
  906 + // Debug code: signal that we are down with the simulate_source method
  907 + #if defined(G_SOURCE_DEBUG)
  908 + std::cout << "ctobssim::simulate_source: out" << std::endl;
  909 + #endif
  910 +
901 // Return 911 // Return
902 return; 912 return;
903 } 913 }
@@ -946,6 +956,14 @@ void ctobssim::simulate_interval(GCTAObservation* obs, @@ -946,6 +956,14 @@ void ctobssim::simulate_interval(GCTAObservation* obs,
946 std::vector<int>& nphotons, 956 std::vector<int>& nphotons,
947 std::vector<int>& nevents) 957 std::vector<int>& nevents)
948 { 958 {
  959 + // Debug code: signal that we step into the simulate_interval method
  960 + #if defined(G_SOURCE_DEBUG)
  961 + std::cout << "ctobssim::simulate_interval: in";
  962 + std::cout << " Etrue=[" << etrue_min << "," << etrue_max << "]";
  963 + std::cout << " Ereco=[" << ereco_min << "," << ereco_max << "]";
  964 + std::cout << std::endl;
  965 + #endif
  966 +
949 // Loop over all models 967 // Loop over all models
950 for (int i = 0; i < models.size(); ++i) { 968 for (int i = 0; i < models.size(); ++i) {
951 969
@@ -1084,6 +1102,11 @@ void ctobssim::simulate_interval(GCTAObservation* obs, @@ -1084,6 +1102,11 @@ void ctobssim::simulate_interval(GCTAObservation* obs,
1084 1102
1085 } // endfor: looped over models 1103 } // endfor: looped over models
1086 1104
  1105 + // Debug code: signal that we are down with the simulate_interval method
  1106 + #if defined(G_SOURCE_DEBUG)
  1107 + std::cout << "ctobssim::simulate_interval: out" << std::endl;
  1108 + #endif
  1109 +
1087 // Return 1110 // Return
1088 return; 1111 return;
1089 } 1112 }
@@ -1289,6 +1312,13 @@ double ctobssim::get_model_flux(const GModelSky* model, @@ -1289,6 +1312,13 @@ double ctobssim::get_model_flux(const GModelSky* model,
1289 const int& indent, 1312 const int& indent,
1290 GLog* wrklog) 1313 GLog* wrklog)
1291 { 1314 {
  1315 + // Debug code: signal that we step into the get_model_flux method
  1316 + #if defined(G_SOURCE_DEBUG)
  1317 + std::cout << "ctobssim::get_model_flux: in";
  1318 + std::cout << " Etrue=[" << emin << "," << emax << "]";
  1319 + std::cout << std::endl;
  1320 + #endif
  1321 +
1292 // Initialise flux 1322 // Initialise flux
1293 double flux = 0.0; 1323 double flux = 0.0;
1294 1324
@@ -1329,19 +1359,20 @@ double ctobssim::get_model_flux(const GModelSky* model, @@ -1329,19 +1359,20 @@ double ctobssim::get_model_flux(const GModelSky* model,
1329 // function spectral model that is the product of the diffuse 1359 // function spectral model that is the product of the diffuse
1330 // cube node function and the spectral model evaluated at the 1360 // cube node function and the spectral model evaluated at the
1331 // energies of the node function 1361 // energies of the node function
1332 - GModelSpatialDiffuseCube* cube = dynamic_cast<GModelSpatialDiffuseCube*>(model->spatial()); 1362 + GModelSpatialDiffuseCube* cube =
  1363 + dynamic_cast<GModelSpatialDiffuseCube*>(model->spatial());
1333 if (cube != NULL) { 1364 if (cube != NULL) {
1334 1365
1335 // Set MC cone 1366 // Set MC cone
1336 cube->set_mc_cone(centre, radius); 1367 cube->set_mc_cone(centre, radius);
1337 1368
1338 // Allocate node function to replace the spectral component 1369 // Allocate node function to replace the spectral component
1339 - GModelSpectralNodes* nodes = new GModelSpectralNodes(cube->spectrum()); 1370 + GModelSpectralNodes* nodes =
  1371 + new GModelSpectralNodes(cube->spectrum());
1340 for (int i = 0; i < nodes->nodes(); ++i) { 1372 for (int i = 0; i < nodes->nodes(); ++i) {
1341 GEnergy energy = nodes->energy(i); 1373 GEnergy energy = nodes->energy(i);
1342 - GTime time; // Dummy time  
1343 double intensity = nodes->intensity(i); 1374 double intensity = nodes->intensity(i);
1344 - double value = spectral->eval(energy, time); 1375 + double value = spectral->eval(energy);
1345 nodes->intensity(i, value * intensity); 1376 nodes->intensity(i, value * intensity);
1346 } 1377 }
1347 1378
@@ -1351,11 +1382,18 @@ double ctobssim::get_model_flux(const GModelSky* model, @@ -1351,11 +1382,18 @@ double ctobssim::get_model_flux(const GModelSky* model,
1351 // Set the spectral model pointer to the node function 1382 // Set the spectral model pointer to the node function
1352 spectral = nodes; 1383 spectral = nodes;
1353 1384
  1385 + // Kluge: if there are no nodes then the spectral->flux method
  1386 + // will throw an exception. We therefore set here the use_model
  1387 + // flag to false in case that there are no spectral nodes
  1388 + if (nodes->nodes() == 0) {
  1389 + use_model = false;
  1390 + }
  1391 +
1354 } // endif: spatial model was a diffuse cube 1392 } // endif: spatial model was a diffuse cube
1355 1393
1356 // Compute flux within [emin, emax] in model from spectral 1394 // Compute flux within [emin, emax] in model from spectral
1357 // component (units: ph/cm2/s) 1395 // component (units: ph/cm2/s)
1358 - double flux0 = spectral->flux(emin, emax); 1396 + double flux0 = (use_model) ? spectral->flux(emin, emax) : 0.0;
1359 flux = flux0 * norm; 1397 flux = flux0 * norm;
1360 1398
1361 // Dump flux 1399 // Dump flux
@@ -1379,6 +1417,11 @@ double ctobssim::get_model_flux(const GModelSky* model, @@ -1379,6 +1417,11 @@ double ctobssim::get_model_flux(const GModelSky* model,
1379 1417
1380 } // endif: model overlaps with simulation region 1418 } // endif: model overlaps with simulation region
1381 1419
  1420 + // Debug code: signal that we step out of the get_model_flux method
  1421 + #if defined(G_SOURCE_DEBUG)
  1422 + std::cout << "ctobssim::get_model_flux: in" << std::endl;
  1423 + #endif
  1424 +
1382 // Return model flux 1425 // Return model flux
1383 return flux; 1426 return flux;
1384 } 1427 }