ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/prepare_environment_with_config.py
Revision: 1.15
Committed: Wed Dec 5 14:08:41 2012 UTC (12 years, 5 months ago) by bortigno
Content type: text/x-python
Branch: MAIN
Changes since 1.14: +3 -15 lines
Log Message:
fix. revert back to revision 1.13

File Contents

# User Rev Content
1 bortigno 1.12 #! /usr/bin/env python
2     import os, pickle, sys, ROOT
3 nmohr 1.8 from optparse import OptionParser
4 nmohr 1.4 from BetterConfigParser import BetterConfigParser
5 bortigno 1.1
6 peller 1.11 argv = sys.argv
7 bortigno 1.1
8     #get files info from config
9 nmohr 1.8 parser = OptionParser()
10     parser.add_option("-I", "--inPath", dest="pathIn", default="",
11     help="path to the input files")
12     parser.add_option("-O", "--outPath", dest="pathOut", default="",
13     help="path to the output files")
14     parser.add_option("-C", "--config", dest="config", default="",
15 peller 1.9 help="configuration of samples")
16     parser.add_option("-U", "--update", dest="update", default=False, action='store_true',
17     help="append sample to existing samples.info")
18     parser.add_option("-D", "--dry", dest="dry", default=False, action='store_true',
19     help="dry drun - just write samples. info withou copying and skimming trees")
20 peller 1.10 parser.add_option("-S", "--samples", dest="samples", default="",
21     help="List of samples")
22 bortigno 1.15
23 peller 1.9
24 peller 1.10 (opts, args) = parser.parse_args(argv)
25 peller 1.9
26 bortigno 1.12 from copytree import copytree
27     from printcolor import printc
28     from samplesclass import sample
29 bortigno 1.13 from addingSamples import writeLheWeights
30 bortigno 1.12
31 bortigno 1.13 SamplesList=opts.samples.split(',')
32 nmohr 1.8
33     pathIN=opts.pathIn
34     pathOUT=opts.pathOut
35    
36     print "Config is: %s" %(opts.config)
37 nmohr 1.4 config = BetterConfigParser()
38 nmohr 1.8 config.read(opts.config)
39 nmohr 1.3
40     prefix=config.get('General','prefix')
41 nmohr 1.5 newprefix=config.get('General','newprefix')
42 nmohr 1.3 lumi=float(config.get('General','lumi'))
43 nmohr 1.8 weightexpression=config.get('General','weightexpression')
44     #this is only to speed it up, remove for final trees!
45     Precut=''
46     info = []
47 nmohr 1.3
48 bortigno 1.1 for Sample in config.sections():
49 nmohr 1.3 if not config.has_option(Sample,'infile'): continue
50 peller 1.10 if not SamplesList == [''] and not config.get(Sample,'sampleName') in SamplesList: continue
51 bortigno 1.1 infile = config.get(Sample,'infile')
52     if not ROOT.TFile.Open(pathIN+prefix+infile+'.root',"READ"):
53     print 'WARNING: No file ' + pathIN+prefix+infile+ ' found! '
54     continue
55 peller 1.6 #this need exception handle
56 nmohr 1.3 #if type(eval(config.get(Sample,'sampleName'))) != list:
57 peller 1.6
58    
59     #Initialize samplecalss element
60     sampleName = config.get(Sample,'sampleName')
61     sampleType = config.get(Sample,'sampleType')
62     cut = config.get(Sample, 'cut')
63     info.append(sample(sampleName,sampleType))
64    
65     info[-1].addtreecut(cut)
66     info[-1].path=pathOUT
67     info[-1].identifier=infile
68     info[-1].weightexpression=weightexpression
69     info[-1].lumi=lumi
70     info[-1].prefix=newprefix
71    
72     if eval(config.get(Sample,'subsamples')):
73     info[-1].subsamples=True
74     info[-1].group = eval((config.get(Sample,'sampleGroup')))
75     info[-1].subcuts = eval((config.get(Sample, 'subcuts')))
76     info[-1].subnames = eval((config.get(Sample, 'subnames')))
77     if sampleType != 'DATA':
78     info[-1].sf = eval((config.get(Sample, 'SF')))
79     info[-1].xsec = eval((config.get(Sample,'xSec')))
80 bortigno 1.1 else:
81 peller 1.6 info[-1].group = config.get(Sample,'sampleGroup')
82     if sampleType != 'DATA':
83     info[-1].sf = config.get(Sample, 'SF')
84     info[-1].xsec = config.get(Sample,'xSec')
85    
86 bortigno 1.13 if not opts.dry:
87     if not 'DY' in sampleName: # for the DY sample we use writeLheConfig
88     copytree(pathIN,pathOUT,prefix,newprefix,infile,'',cut+Precut)
89    
90 bortigno 1.15 #this copy the trees for the DYJets samples
91 bortigno 1.13 if not opts.dry:
92 bortigno 1.15 writeLheWeights( config, pathIN, pathOUT, prefix, newprefix, infile, '', cut+Precut )
93 peller 1.9
94     #dump info
95 bortigno 1.13 pathConfig = 'pathConfig8TeV'
96     print "Path Config is: " + str(pathConfig)
97     pathconfig = BetterConfigParser()
98     pathconfig.read(pathConfig)
99    
100 peller 1.9 if opts.update:
101 bortigno 1.13 infofile = open(pathconfig.get('Directories','samplesinfo'),'r')
102 peller 1.9 info_old = pickle.load(infofile)
103     infofile.close()
104    
105     info += info_old
106    
107 bortigno 1.13 infofile = open(pathconfig.get('Directories','samplesinfo'),'w')
108 bortigno 1.1 pickle.dump(info,infofile)
109     infofile.close()