ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/prepare_environment_with_config.py
Revision: 1.2
Committed: Wed Jun 6 16:28:25 2012 UTC (12 years, 11 months ago) by bortigno
Content type: text/x-python
Branch: MAIN
Changes since 1.1: +3 -3 lines
Log Message:
fixes

File Contents

# User Rev Content
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     from ConfigParser import SafeConfigParser
8     import ROOT
9    
10     prefix='ZllH.Jun01.'
11    
12 bortigno 1.2 lumi=(530.+1725.)
13 bortigno 1.1
14     pathIN=sys.argv[1]
15     pathOUT=sys.argv[2]
16    
17     weightexpression='(PUweight*weightTrig)'
18     #this is only to speed it up, remove for final trees!
19     Precut=''
20     info = []
21    
22     #get files info from config
23     config = SafeConfigParser()
24     config.read('./8TeVsamples.cfg')
25     for Sample in config.sections():
26     infile = config.get(Sample,'infile')
27     if not ROOT.TFile.Open(pathIN+prefix+infile+'.root',"READ"):
28     print 'WARNING: No file ' + pathIN+prefix+infile+ ' found! '
29     continue
30     #this need exception handle
31     # if type(eval(config.get(Sample,'sampleName'))) != list:
32     if len(config.get(Sample,'sampleName').split(",")) == 1:
33     sampleName = [(config.get(Sample,'sampleName'))]
34     sampleType = [(config.get(Sample,'sampleType'))]
35     sampleGroup = [(config.get(Sample,'sampleGroup'))]
36     Aprefix = [(config.get(Sample,'Aprefix'))]
37     cut = [(config.get(Sample, 'cut'))]
38     if sampleType[0] != 'DATA':
39     SF = [(config.get(Sample, 'SF'))]
40     xSec = [(config.get(Sample,'xSec'))]
41     else:
42     sampleName = eval(config.get(Sample,'sampleName'))
43     sampleType = eval(config.get(Sample,'sampleType'))
44     sampleGroup = eval(config.get(Sample,'sampleGroup'))
45     Aprefix = eval(config.get(Sample,'Aprefix'))
46     cut = eval(config.get(Sample, 'cut'))
47     if sampleType[0] != 'DATA':
48     SF = eval(config.get(Sample, 'SF'))
49     xSec = eval(config.get(Sample,'xSec'))
50    
51     for i in range(0,len(sampleName)):
52     print cut[i]
53     print Aprefix[i]
54     copytree(pathIN,pathOUT,prefix,infile,Aprefix[i],cut[i]+Precut)
55     info.append(sample(sampleName[i],sampleType[i]))
56     info[-1].path=pathOUT
57     info[-1].identifier=Aprefix[i]+infile
58     info[-1].weightexpression=weightexpression
59     info[-1].group=sampleGroup[i]
60     info[-1].lumi=lumi
61     info[-1].prefix=prefix
62     info[-1].addtreecut(cut[i])
63     if sampleType[i] != 'DATA':
64 bortigno 1.2 info[-1].xsec=(xSec[i])
65     info[-1].sf=(SF[i])
66 bortigno 1.1
67     #dump info
68     infofile = open(pathOUT+'/samples.info','w')
69     pickle.dump(info,infofile)
70     infofile.close()