Commit 70701752641c439b998b76d214bf2ce31ce8243a
1 parent
b5f31e77
Adapt to new calibration database path.
Showing
1 changed file
with
22 additions
and
12 deletions
scripts/cta_kb_bkgrates.py
| ... | ... | @@ -20,7 +20,8 @@ |
| 20 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | 21 | # |
| 22 | 22 | # ========================================================================== |
| 23 | -from gammalib import * | |
| 23 | +import os | |
| 24 | +import glob | |
| 24 | 25 | import math |
| 25 | 26 | import sys |
| 26 | 27 | |
| ... | ... | @@ -69,7 +70,10 @@ def make_file_function(irfname, filename): |
| 69 | 70 | omega = 2.0 * math.pi * (1.0 - math.cos(math.radians(r80))) |
| 70 | 71 | |
| 71 | 72 | # Compute background rate per steradian and MeV |
| 72 | - bkg_rate = bgd/omega/ewidth | |
| 73 | + if omega > 0.0: | |
| 74 | + bkg_rate = bgd/omega/ewidth | |
| 75 | + else: | |
| 76 | + bkg_rate = 0.0 | |
| 73 | 77 | |
| 74 | 78 | # Write |
| 75 | 79 | file.write(str(energy)+" "+str(bkg_rate)+"\n") |
| ... | ... | @@ -89,18 +93,24 @@ if __name__ == '__main__': |
| 89 | 93 | """ |
| 90 | 94 | Main entry point |
| 91 | 95 | """ |
| 96 | + # Set parameters | |
| 97 | + caldb = "/usr/local/gamma/share/caldb/data/cta/kb/" | |
| 98 | + | |
| 92 | 99 | # Get IRF from command line argument |
| 93 | 100 | if (len(sys.argv) > 1): |
| 94 | - irf = sys.argv[1] | |
| 101 | + irfs = [caldb+"/"+sys.argv[1]] | |
| 95 | 102 | else: |
| 96 | - irf = "kb_E_50h_v3" | |
| 103 | + irfs = glob.glob(caldb+"/*.dat") | |
| 104 | + irfs.sort() | |
| 97 | 105 | |
| 98 | - # Set parameters | |
| 99 | - caldb = "/usr/local/gamma/share/caldb/cta" | |
| 100 | - | |
| 101 | - # Set filenames | |
| 102 | - irfname = caldb+"/"+irf+".dat" | |
| 103 | - filename = "bkg_"+irf+".txt" | |
| 106 | + # Loop over all IRFs | |
| 107 | + for irfname in irfs: | |
| 108 | + | |
| 109 | + # Build background filename | |
| 110 | + head, tail = os.path.split(irfname) | |
| 111 | + irf = tail.strip(".dat") | |
| 112 | + filename = "bkg_"+irf+".txt" | |
| 113 | + print(filename) | |
| 104 | 114 | |
| 105 | - # Read | |
| 106 | - make_file_function(irfname, filename) | |
| 115 | + # Make background file | |
| 116 | + make_file_function(irfname, filename) | ... | ... |