1 |
bortigno |
1.1 |
#!/usr/bin/env python2.6
|
2 |
|
|
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 |
bortigno |
1.1 |
config.read('./8TeVsamples.cfg')
|
21 |
nmohr |
1.3 |
|
22 |
|
|
prefix=config.get('General','prefix')
|
23 |
nmohr |
1.5 |
newprefix=config.get('General','newprefix')
|
24 |
nmohr |
1.3 |
lumi=float(config.get('General','lumi'))
|
25 |
|
|
|
26 |
bortigno |
1.1 |
for Sample in config.sections():
|
27 |
nmohr |
1.3 |
if not config.has_option(Sample,'infile'): continue
|
28 |
bortigno |
1.1 |
infile = config.get(Sample,'infile')
|
29 |
|
|
if not ROOT.TFile.Open(pathIN+prefix+infile+'.root',"READ"):
|
30 |
|
|
print 'WARNING: No file ' + pathIN+prefix+infile+ ' found! '
|
31 |
|
|
continue
|
32 |
|
|
#this need exception handle
|
33 |
nmohr |
1.3 |
#if type(eval(config.get(Sample,'sampleName'))) != list:
|
34 |
bortigno |
1.1 |
if len(config.get(Sample,'sampleName').split(",")) == 1:
|
35 |
|
|
sampleName = [(config.get(Sample,'sampleName'))]
|
36 |
|
|
sampleType = [(config.get(Sample,'sampleType'))]
|
37 |
|
|
sampleGroup = [(config.get(Sample,'sampleGroup'))]
|
38 |
|
|
Aprefix = [(config.get(Sample,'Aprefix'))]
|
39 |
|
|
cut = [(config.get(Sample, 'cut'))]
|
40 |
|
|
if sampleType[0] != 'DATA':
|
41 |
|
|
SF = [(config.get(Sample, 'SF'))]
|
42 |
|
|
xSec = [(config.get(Sample,'xSec'))]
|
43 |
|
|
else:
|
44 |
|
|
sampleName = eval(config.get(Sample,'sampleName'))
|
45 |
|
|
sampleType = eval(config.get(Sample,'sampleType'))
|
46 |
|
|
sampleGroup = eval(config.get(Sample,'sampleGroup'))
|
47 |
|
|
Aprefix = eval(config.get(Sample,'Aprefix'))
|
48 |
|
|
cut = eval(config.get(Sample, 'cut'))
|
49 |
|
|
if sampleType[0] != 'DATA':
|
50 |
|
|
SF = eval(config.get(Sample, 'SF'))
|
51 |
|
|
xSec = eval(config.get(Sample,'xSec'))
|
52 |
|
|
|
53 |
|
|
for i in range(0,len(sampleName)):
|
54 |
|
|
print cut[i]
|
55 |
|
|
print Aprefix[i]
|
56 |
nmohr |
1.5 |
copytree(pathIN,pathOUT,prefix,newprefix,infile,Aprefix[i],cut[i]+Precut)
|
57 |
bortigno |
1.1 |
info.append(sample(sampleName[i],sampleType[i]))
|
58 |
|
|
info[-1].path=pathOUT
|
59 |
|
|
info[-1].identifier=Aprefix[i]+infile
|
60 |
|
|
info[-1].weightexpression=weightexpression
|
61 |
|
|
info[-1].group=sampleGroup[i]
|
62 |
|
|
info[-1].lumi=lumi
|
63 |
nmohr |
1.5 |
info[-1].prefix=newprefix
|
64 |
bortigno |
1.1 |
info[-1].addtreecut(cut[i])
|
65 |
|
|
if sampleType[i] != 'DATA':
|
66 |
bortigno |
1.2 |
info[-1].xsec=(xSec[i])
|
67 |
|
|
info[-1].sf=(SF[i])
|
68 |
bortigno |
1.1 |
|
69 |
|
|
#dump info
|
70 |
|
|
infofile = open(pathOUT+'/samples.info','w')
|
71 |
|
|
pickle.dump(info,infofile)
|
72 |
|
|
infofile.close()
|