ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/prepare_environment_with_config.py
Revision: 1.3
Committed: Wed Jun 6 20:52:08 2012 UTC (12 years, 11 months ago) by nmohr
Content type: text/x-python
Branch: MAIN
Changes since 1.2: +6 -5 lines
Log Message:
Add general stuff to config

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