generate_prod3_irfs.py
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#! /usr/bin/env python
# ==========================================================================
# Generates Prod3 IRFs from ROOT performance files
#
# Copyright (C) 2016 Juergen Knoedlseder
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ==========================================================================
import sys
import cscripts
# ======================= #
# Set Prod3 DESY database #
# ======================= #
def set_prod3_desy(datadir):
"""
Set Prod3 DESY database
This function sets the calibration database. By adding dictionaries to
the "db" list a number of calibrations can be defined for which IRFs
should be generated. All calibrations will be added to the calibration
database.
Parameters
----------
datadir : str
Data directory
Returns
-------
db : list of dict
Database
"""
# Set database content
db = [{'inst': 'prod3', 'id': 'South_50h', 'analysis': 'DESY',
'oversample': 3, 'norm1d': False, 'bgdinfill': False,
'bgdethres': 10.0, 'path': datadir, 'file': 'irf.root'}]
# Return database
return db
# =================== #
# Generate Prod3 IRFs #
# =================== #
def generate_prod3_irfs():
"""
Generate Prod3 IRFs
"""
# Get optional argument
if len(sys.argv) == 2:
datadir = sys.argv[1]
else:
datadir = 'data'
# Get database
entries = set_prod3_desy(datadir)
# Loop over entries
for entry in entries:
# Set filename
filename = entry['path']+'/'+entry['file']
# Set-up csroot2caldb
caldb = cscripts.csroot2caldb()
caldb['infile'] = filename
caldb['outdir'] = 'prod3'
caldb['inst'] = entry['inst']
caldb['id'] = entry['id']
caldb['version'] = entry['inst']
caldb['analysis'] = entry.setdefault('analysis', 'DESY')
caldb['psftype'] = entry.setdefault('psftype', 'Gauss')
caldb['norm1d'] = entry.setdefault('norm1d', False)
caldb['rebin'] = entry.setdefault('rebin', False)
caldb['eascale'] = entry.setdefault('eascale', 1.0)
caldb['bgdscale'] = entry.setdefault('bgdscale', 1.0)
caldb['bgdoversample'] = entry.setdefault('oversample', 1)
caldb['bgdethres'] = entry.setdefault('bgdethres', 1000.0)
caldb['bgdinfill'] = entry.setdefault('bgdinfill', False)
caldb['logfile'] = 'generate_prod3_irfs.log'
# Add CALDB entry
caldb.execute()
# Return
return
# ======================== #
# Main routine entry point #
# ======================== #
if __name__ == '__main__':
# Generate Prod3 IRFs
generate_prod3_irfs()