1 |
peller |
1.6 |
#!/usr/bin/env python2.7
|
2 |
bortigno |
1.1 |
from copytree import copytree
|
3 |
|
|
from printcolor import printc
|
4 |
|
|
from samplesclass import sample
|
5 |
|
|
import pickle
|
6 |
|
|
import sys
|
7 |
nmohr |
1.4 |
from BetterConfigParser import BetterConfigParser
|
8 |
bortigno |
1.1 |
import ROOT
|
9 |
|
|
|
10 |
|
|
pathIN=sys.argv[1]
|
11 |
|
|
pathOUT=sys.argv[2]
|
12 |
|
|
|
13 |
|
|
weightexpression='(PUweight*weightTrig)'
|
14 |
|
|
#this is only to speed it up, remove for final trees!
|
15 |
|
|
Precut=''
|
16 |
|
|
info = []
|
17 |
|
|
|
18 |
|
|
#get files info from config
|
19 |
nmohr |
1.4 |
config = BetterConfigParser()
|
20 |
peller |
1.6 |
#config.read('./8TeVsamples.cfg')
|
21 |
peller |
1.7 |
config.read('./7TeVsamples_ZZ.cfg')
|
22 |
nmohr |
1.3 |
|
23 |
|
|
prefix=config.get('General','prefix')
|
24 |
nmohr |
1.5 |
newprefix=config.get('General','newprefix')
|
25 |
nmohr |
1.3 |
lumi=float(config.get('General','lumi'))
|
26 |
|
|
|
27 |
bortigno |
1.1 |
for Sample in config.sections():
|
28 |
nmohr |
1.3 |
if not config.has_option(Sample,'infile'): continue
|
29 |
bortigno |
1.1 |
infile = config.get(Sample,'infile')
|
30 |
|
|
if not ROOT.TFile.Open(pathIN+prefix+infile+'.root',"READ"):
|
31 |
|
|
print 'WARNING: No file ' + pathIN+prefix+infile+ ' found! '
|
32 |
|
|
continue
|
33 |
peller |
1.6 |
#this need exception handle
|
34 |
nmohr |
1.3 |
#if type(eval(config.get(Sample,'sampleName'))) != list:
|
35 |
peller |
1.6 |
|
36 |
|
|
|
37 |
|
|
#Initialize samplecalss element
|
38 |
|
|
sampleName = config.get(Sample,'sampleName')
|
39 |
|
|
sampleType = config.get(Sample,'sampleType')
|
40 |
|
|
cut = config.get(Sample, 'cut')
|
41 |
|
|
info.append(sample(sampleName,sampleType))
|
42 |
|
|
|
43 |
|
|
info[-1].addtreecut(cut)
|
44 |
|
|
info[-1].path=pathOUT
|
45 |
|
|
info[-1].identifier=infile
|
46 |
|
|
info[-1].weightexpression=weightexpression
|
47 |
|
|
info[-1].lumi=lumi
|
48 |
|
|
info[-1].prefix=newprefix
|
49 |
|
|
|
50 |
|
|
if eval(config.get(Sample,'subsamples')):
|
51 |
|
|
info[-1].subsamples=True
|
52 |
|
|
info[-1].group = eval((config.get(Sample,'sampleGroup')))
|
53 |
|
|
info[-1].subcuts = eval((config.get(Sample, 'subcuts')))
|
54 |
|
|
info[-1].subnames = eval((config.get(Sample, 'subnames')))
|
55 |
|
|
if sampleType != 'DATA':
|
56 |
|
|
info[-1].sf = eval((config.get(Sample, 'SF')))
|
57 |
|
|
info[-1].xsec = eval((config.get(Sample,'xSec')))
|
58 |
bortigno |
1.1 |
else:
|
59 |
peller |
1.6 |
info[-1].group = config.get(Sample,'sampleGroup')
|
60 |
|
|
if sampleType != 'DATA':
|
61 |
|
|
info[-1].sf = config.get(Sample, 'SF')
|
62 |
|
|
info[-1].xsec = config.get(Sample,'xSec')
|
63 |
bortigno |
1.1 |
|
64 |
peller |
1.6 |
#copytree(pathIN,pathOUT,prefix,newprefix,infile,'',cut+Precut)
|
65 |
|
|
|
66 |
bortigno |
1.1 |
#dump info
|
67 |
|
|
infofile = open(pathOUT+'/samples.info','w')
|
68 |
|
|
pickle.dump(info,infofile)
|
69 |
|
|
infofile.close()
|