ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/prepare_environment_with_config.py
Revision: 1.8
Committed: Thu Aug 9 11:30:27 2012 UTC (12 years, 9 months ago) by nmohr
Content type: text/x-python
Branch: MAIN
Changes since 1.7: +24 -11 lines
Log Message:
7TeV step 1

File Contents

# User Rev Content
1 nmohr 1.8 #!/usr/bin/env python
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.8 from optparse import OptionParser
8 nmohr 1.4 from BetterConfigParser import BetterConfigParser
9 bortigno 1.1 import ROOT
10    
11    
12     #get files info from config
13 nmohr 1.8 parser = OptionParser()
14     parser.add_option("-I", "--inPath", dest="pathIn", default="",
15     help="path to the input files")
16     parser.add_option("-O", "--outPath", dest="pathOut", default="",
17     help="path to the output files")
18     parser.add_option("-C", "--config", dest="config", default="",
19     help="configuration defining the plots to make")
20     argv=sys.argv
21     (opts, args) = parser.parse_args(argv)
22    
23     pathIN=opts.pathIn
24     pathOUT=opts.pathOut
25    
26     if opts.config =="":
27     opts.config = "7TeVsamples_ZZ.cfg"
28     print "Config is: %s" %(opts.config)
29 nmohr 1.4 config = BetterConfigParser()
30 nmohr 1.8 config.read(opts.config)
31 nmohr 1.3
32     prefix=config.get('General','prefix')
33 nmohr 1.5 newprefix=config.get('General','newprefix')
34 nmohr 1.3 lumi=float(config.get('General','lumi'))
35 nmohr 1.8 weightexpression=config.get('General','weightexpression')
36     #this is only to speed it up, remove for final trees!
37     Precut=''
38     info = []
39 nmohr 1.3
40 bortigno 1.1 for Sample in config.sections():
41 nmohr 1.3 if not config.has_option(Sample,'infile'): continue
42 bortigno 1.1 infile = config.get(Sample,'infile')
43     if not ROOT.TFile.Open(pathIN+prefix+infile+'.root',"READ"):
44     print 'WARNING: No file ' + pathIN+prefix+infile+ ' found! '
45     continue
46 peller 1.6 #this need exception handle
47 nmohr 1.3 #if type(eval(config.get(Sample,'sampleName'))) != list:
48 peller 1.6
49    
50     #Initialize samplecalss element
51     sampleName = config.get(Sample,'sampleName')
52     sampleType = config.get(Sample,'sampleType')
53     cut = config.get(Sample, 'cut')
54     info.append(sample(sampleName,sampleType))
55    
56     info[-1].addtreecut(cut)
57     info[-1].path=pathOUT
58     info[-1].identifier=infile
59     info[-1].weightexpression=weightexpression
60     info[-1].lumi=lumi
61     info[-1].prefix=newprefix
62    
63     if eval(config.get(Sample,'subsamples')):
64     info[-1].subsamples=True
65     info[-1].group = eval((config.get(Sample,'sampleGroup')))
66     info[-1].subcuts = eval((config.get(Sample, 'subcuts')))
67     info[-1].subnames = eval((config.get(Sample, 'subnames')))
68     if sampleType != 'DATA':
69     info[-1].sf = eval((config.get(Sample, 'SF')))
70     info[-1].xsec = eval((config.get(Sample,'xSec')))
71 bortigno 1.1 else:
72 peller 1.6 info[-1].group = config.get(Sample,'sampleGroup')
73     if sampleType != 'DATA':
74     info[-1].sf = config.get(Sample, 'SF')
75     info[-1].xsec = config.get(Sample,'xSec')
76 bortigno 1.1
77 nmohr 1.8 copytree(pathIN,pathOUT,prefix,newprefix,infile,'',cut+Precut)
78 peller 1.6
79 bortigno 1.1 #dump info
80     infofile = open(pathOUT+'/samples.info','w')
81     pickle.dump(info,infofile)
82     infofile.close()