forked from danielbattistini/fempy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumPairs.py
More file actions
45 lines (33 loc) · 1.24 KB
/
SumPairs.py
File metadata and controls
45 lines (33 loc) · 1.24 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
import argparse
from ROOT import TFile
import fempy
parser = argparse.ArgumentParser()
parser.add_argument('inFileName')
args = parser.parse_args()
inFileName = args.inFileName
inFile = TFile(inFileName, 'update')
summedCombs = {
'sc': ['pp', 'mm'],
'oc': ['pm', 'mp'],
}
inFile.ls()
regions = fempy.utils.io.GetSubdirsInDir(inFile.Get('pp/SE'))
def SumHists(hists):
print("Summming: ", hists)
hSum = hists[0].Clone()
for hist in hists[1:]:
hSum.Add(hist)
return hSum
for combName, combsToSum in summedCombs.items():
for event in ['SE', 'ME']:
inFile.mkdir(f'{combName}/{event}')
inFile.cd(f'{combName}/{event}')
inFile.Get(f'pp/{event}').ls()
for histoName in fempy.utils.io.GetHistNamesInDir(inFile.Get(f'pp/{event}')):
SumHists([inFile.Get(f'{comb}/{event}/{histoName}') for comb in combsToSum]).Write()
for region in regions:
inFile.mkdir(f'{combName}/{event}/{region}')
inFile.cd(f'{combName}/{event}/{region}')
for histoName in fempy.utils.io.GetHistNamesInDir(inFile.Get(f'pp/{event}/{region}')):
SumHists([inFile.Get(f'{comb}/{event}/{region}/{histoName}') for comb in combsToSum]).Write()
inFile.Close()