-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpullRawKntsFunc2.py
60 lines (49 loc) · 1.67 KB
/
pullRawKntsFunc2.py
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
# Script name: pullRawKntsFunc.py
# Purpose: Pull raw knts from .xml and returns array with xsec
# all added up
#
# Pueh Leng Tan, 17 Dec 2018
def pullRawKntsFunc2(fName, chType, nuType, tgtType):
import matplotlib.pyplot as plt
import scipy.interpolate as itp
import numpy as np
import xml.etree.cElementTree as ET
import pdb
import sys # For adding paths
chkList = [chType, tgtType, 'nu:%s' % (str(nuType))]
myTree = ET.parse(fName)
myRoot = myTree.getroot()
eBag = []
xsBag = []
nameBag = []
minBag = []
maxBag = []
for spl in myRoot: # for each spline in xml file
splName = spl.get('name')
# Achtung: boo is empty if all strings in chkList are found in splName
boo = list(filter(lambda x: x not in splName, chkList))
if len(boo)!=0:
continue
eTmpBag = []
xsTmpBag = []
for knt in spl: # for each knot in spline
eTmpBag.append(float(knt[0].text))
xsTmpBag.append(float(knt[1].text))
eBag.append(eTmpBag)
xsBag.append(xsTmpBag)
minBag.append(eTmpBag[0])
maxBag.append(eTmpBag[-1])
nameBag.append(splName)
## Interpolation, so that I can add the xsec up
eMin_GeV = max(minBag)
eMax_GeV = min(maxBag)
nEBins = 200
eLog = np.linspace(np.log10(eMin_GeV), np.log10(eMax_GeV), nEBins)
eListFine_GeV = 10**eLog
[nSpl, nKnts] = np.shape(eBag)
xsItpBag = []
for iSpl in range(0, nSpl):
xsItpFunc = itp.interp1d(eBag[iSpl], xsBag[iSpl], kind='linear')
xsItpBag.append(xsItpFunc(eListFine_GeV))
totCC = np.sum(xsItpBag, axis=0)
return [eListFine_GeV, totCC]