forked from mflechl/ProductionFromNano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
develop.py
63 lines (53 loc) · 2.01 KB
/
develop.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
61
62
63
import subprocess as sp
import shlex
import json
import shutil
import os
from runUtils import checkProxy
import getFilelists as getFL
import sys, os
from glob import glob
# create the diretory merged within MCpuHistograms (if it does not exist)
if not os.path.exists("./MCpuHistograms/merged") :
os.makedirs("./MCpuHistograms/merged")
with open("sample_collection.json","r") as FSO:
config = json.load(FSO)
base_dir = "/afs/hephy.at/work/j/jandrejkovic/MC_histWriting/CMSSW_9_4_4_fromNano/src/WawTools/NanoAODTools/"
# get the list of all available MC histograms to be merged
MC_hist_list = [mc[112:] for mc in glob(base_dir+'/MCpuHistograms/*') if '.root' in mc]
# use only MC samples as this is used to produce a list
# that will be used later for MC PU distribution merging
frmt = 'mc'
f = config[frmt]
r = f["run"]["RunIIFall17NanoAOD"]
no_of_available_histos = len(MC_hist_list)
no_of_merged_histos = 0
counter = 0
for sample in r["samples"]:
#print sample
links = r["samples"][sample]
for link in links:
#print link
first_parser = link.split('/')[1]
if 'ext' in link :
hadd_list = [mc for mc in MC_hist_list if 'ext' in mc and first_parser in mc]
#print link
#print first_parser
#print len(hadd_list)
#print '-'*30
else :
hadd_list = [mc for mc in MC_hist_list if 'ext' not in mc and first_parser in mc]
no_of_merged_histos += len(hadd_list)
hadd_list_withPath = ['MCpuHistograms/'+s for s in hadd_list ]
hadd_cmd = 'hadd ./MCpuHistograms/merged/' + link.replace('/','_')+'.root ' +' '.join(hadd_list_withPath)
if link == '/DYJetsToLL_M-5to50_TuneCP5_13TeV-madgraphMLM-pythia8/RunIIFall17NanoAOD-PU2017_12Apr2018_94X_mc2017_realistic_v14-v2/NANOAODSIM' :
print hadd_cmd
#print hadd_cmd
#os.system(hadd_cmd)
counter += 1
#print link
print 'number of output files ', counter
if (no_of_merged_histos - no_of_available_histos) == 0 :
print 'merging was successful!'
else :
print 'not all files were merged, something went wrong'