Commit c319da92f6c181ab9d7a8aef2a5003e323601418

Authored by Jürgen Knödlseder
1 parent 06d9921b

csphagen only adds observations with Off regions to background model

Showing 1 changed file with 21 additions and 8 deletions
cscripts/csphagen.py
@@ -449,10 +449,13 @@ class csphagen(ctools.csobservation): @@ -449,10 +449,13 @@ class csphagen(ctools.csobservation):
449 # names 449 # names
450 for model in self._models: 450 for model in self._models:
451 451
  452 + # Initialise model usage
  453 + use_model = False
  454 +
452 # If model is a background model then append "OnOff" 455 # If model is a background model then append "OnOff"
453 if 'GCTA' in model.classname(): 456 if 'GCTA' in model.classname():
454 457
455 - # Skip model is background model should not be used 458 + # Skip model if background model should not be used
456 if not self['use_model_bkg'].boolean(): 459 if not self['use_model_bkg'].boolean():
457 self._log_string(gammalib.NORMAL, ' Skip "%s" model "%s" (%s)' % \ 460 self._log_string(gammalib.NORMAL, ' Skip "%s" model "%s" (%s)' % \
458 (model.instruments(), model.name(), model.ids())) 461 (model.instruments(), model.name(), model.ids()))
@@ -460,10 +463,10 @@ class csphagen(ctools.csobservation): @@ -460,10 +463,10 @@ class csphagen(ctools.csobservation):
460 463
461 # Check if model corresponds to one of the relevant 464 # Check if model corresponds to one of the relevant
462 # observations 465 # observations
463 - is_onoff = False  
464 for result in results: 466 for result in results:
465 if model.is_valid(result['instrument'], result['id']): 467 if model.is_valid(result['instrument'], result['id']):
466 - is_onoff = True 468 + if result['bkg_reg'].size() >= self['bkgregmin'].integer():
  469 + use_model = True
467 break 470 break
468 471
469 # If stacked analysis is requested then just use for model 472 # If stacked analysis is requested then just use for model
@@ -482,17 +485,27 @@ class csphagen(ctools.csobservation): @@ -482,17 +485,27 @@ class csphagen(ctools.csobservation):
482 # ... otherwise use model for stacked analysis 485 # ... otherwise use model for stacked analysis
483 else: 486 else:
484 has_stacked_model = True 487 has_stacked_model = True
  488 + use_model = True
485 model.ids('') 489 model.ids('')
486 490
487 # Set instrument name 491 # Set instrument name
488 model.instruments(model.instruments()+'OnOff') 492 model.instruments(model.instruments()+'OnOff')
489 493
490 - # Log model usage  
491 - self._log_string(gammalib.NORMAL, ' Use "%s" model "%s" (%s)' % \  
492 - (model.instruments(), model.name(), model.ids())) 494 + # If model is relevant then append it now to the model
  495 + # container
  496 + if use_model:
  497 +
  498 + # Log model usage
  499 + self._log_string(gammalib.NORMAL, ' Use "%s" model "%s" (%s)' % \
  500 + (model.instruments(), model.name(), model.ids()))
493 501
494 - # Append model to container  
495 - models.append(model) 502 + # Append model to container
  503 + models.append(model)
  504 +
  505 + # ... otherwise signal that model is skipped
  506 + else:
  507 + self._log_string(gammalib.NORMAL, ' Skip "%s" model "%s" (%s)' % \
  508 + (model.instruments(), model.name(), model.ids()))
496 509
497 # Return model container 510 # Return model container
498 return models 511 return models