ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/test/prepare_datacard.py
Revision: 1.5
Committed: Tue Oct 9 14:53:12 2012 UTC (12 years, 7 months ago) by bortigno
Content type: text/x-python
Branch: MAIN
CVS Tags: lhcp_UnblindFix, hcp_Unblind, lhcp_11April, LHCP_PreAppFixAfterFreeze, LHCP_PreAppFreeze, workingVersionAfterHCP, hcpApproval, hcpPreApp, HEAD
Changes since 1.4: +3 -3 lines
Log Message:
new DC print out format

File Contents

# Content
1 #!/afs/cern.ch/cms/slc5_amd64_gcc434/cms/cmssw/CMSSW_4_2_8/external/slc5_amd64_gcc434/bin/python2.6
2 ##!/usr/bin/python2.6
3
4 import os
5 import math
6
7 def getfloat_from_line( line ):
8 start = line.find('.')
9 number = float(line[start-1:])
10 return number
11
12 def sum_errors( e1, e2 ):
13 return math.sqrt( e1 * e1 + e2 * e2 )
14
15 def get_errors( line, sf ):
16 if line.find('up') > 0:
17 sf.append(getfloat_from_line(line))
18 if line.find('down') > 0:
19 sf.append(getfloat_from_line(line))
20 return sf
21
22 def get_correlation_matrix( file ):
23 return [line.split() for line in file]
24
25 file = open('SFErrors_Pt50To100.txt','r')
26 stat = [0, 0, 0, 0]
27 dyl_btag = []
28 dyc_btag = []
29 dyb_btag = []
30 ttbar_btag = []
31 dyl_je = []
32 dyc_je = []
33 dyb_je = []
34 ttbar_je = []
35
36 for line in file:
37 # print line
38
39 if ( line.find('DYL') ) > 0:
40 if( line.find('stat') > 0 ):
41 stat[0] = getfloat_from_line(line)
42 if ( line.find('btag') > 0 ) or (line.find('mistag') > 0 ):
43 dyl_btag = get_errors( line, dyl_btag )
44 if ( line.find('jer') > 0 ) or ( line.find('jec') > 0):
45 dyl_je = get_errors( line, dyl_je )
46
47 if ( line.find('DYC') ) > 0:
48 if( line.find('stat') > 0 ):
49 stat[1] = getfloat_from_line(line)
50 if ( line.find('btag') > 0 ) or (line.find('mistag') > 0 ):
51 dyc_btag = get_errors( line, dyc_btag )
52 if ( line.find('jer') > 0 ) or ( line.find('jec') > 0):
53 dyc_je = get_errors( line, dyc_je )
54
55 if ( line.find('DYB') ) > 0:
56 if( line.find('stat') > 0 ):
57 stat[1] = getfloat_from_line(line)
58 if ( line.find('btag') > 0 ) or (line.find('mistag') > 0 ):
59 dyb_btag = get_errors( line, dyb_btag )
60 if ( line.find('jer') > 0 ) or ( line.find('jec') > 0):
61 dyb_je = get_errors( line, dyb_je )
62
63 if ( line.find('TTbar') ) > 0:
64 if( line.find('stat') > 0 ):
65 stat[2] = getfloat_from_line(line)
66 if ( line.find('btag') > 0 ) or (line.find('mistag') > 0 ):
67 ttbar_btag = get_errors( line, ttbar_btag )
68 if ( line.find('jer') > 0 ) or ( line.find('jec') > 0):
69 ttbar_je = get_errors( line, ttbar_je )
70
71
72 dyl_syst = sum_errors( max(dyl_btag), max(dyl_je) )
73 #dyc_syst = sum_errors( max(dyc_btag), max(dyc_je) )
74 dyb_syst = sum_errors( max(dyb_btag), max(dyb_je) )
75 ttbar_syst = sum_errors( max(dyl_btag), max(ttbar_je) )
76
77
78 print 'Systematics only'
79 print dyl_syst
80 #print dyc_syst
81 print dyb_syst
82 print ttbar_syst
83
84 print "Final"
85
86 dyl_err = sum_errors( stat[0], dyl_syst )
87 #dyc_err = sum_errors( stat[1], dyc_syst )
88 dyb_err = sum_errors( stat[1], dyb_syst )
89 ttbar_err = sum_errors( stat[2], ttbar_syst )
90
91 print dyl_err
92 #print dyc_err
93 print dyb_err
94 print ttbar_err
95
96 correlation_file = open('CorrelationMatrix_Pt50To100.txt','r')
97 corr = get_correlation_matrix( correlation_file )
98 print corr
99
100 # dyl_string = 'CMS_vhbb_ZjLF_SF lnN - - - ' + '%.3f' % (1.+float(corr[0][0])*dyl_err) + ' ' + '%.3f' %(1.+(float(corr[0][1])*dyl_err)) + ' ' + '%.3f' %(1.+float(corr[0][2])*dyl_err) + ' ' + '%.3f' %(1.+float(corr[0][3])*dyl_err) + ' - - - - \n'
101 # dyc_string = 'CMS_vhbb_ZjCF_SF lnN - - - ' + '%.3f' %(1.+float(corr[1][0])*dyc_err) + ' ' + '%.3f' %(1.+(float(corr[1][1])*dyc_err)) + ' ' + '%.3f' %(1.+float(corr[1][2])*dyc_err) + ' ' + '%.3f' %(1.+float(corr[1][3])*dyc_err) + ' - - - - \n'
102 # dyb_string = 'CMS_vhbb_ZjHF_SF lnN - - - ' + '%.3f' %(1.+float(corr[2][0])*dyb_err) + ' ' + '%.3f' %(1.+(float(corr[2][1])*dyb_err)) + ' ' + '%.3f' %(1.+float(corr[2][2])*dyb_err) + ' ' + '%.3f' %(1.+float(corr[2][3])*dyb_err) + ' - - - - \n'
103 # ttbar_string = 'CMS_vhbb_TT_SF lnN - - - ' + '%.3f' %(1.+float(corr[3][0])*ttbar_err) + ' ' + '%.3f' %(1.+(float(corr[3][1])*ttbar_err)) + ' ' + '%.3f' %(1.+float(corr[3][2])*ttbar_err) + ' ' + '%.3f' %(1.+float(corr[3][3])*ttbar_err) + ' - - - - \n'
104
105 dyl_string = 'CMS_vhbb_ZjLF_SF_8TeV: {\'type\':\'lnN\', \'DYlight\':' + '%.3f' % (1.+float(corr[0][0])*dyl_err) + ',\'DYb\':' + '%.3f' %(1.+(float(corr[0][1])*dyl_err)) + ',\'TT\':' + '%.3f' %(1.+float(corr[0][2])*dyl_err) + '} \n'
106 dyb_string = 'CMS_vhbb_ZjHF_SF_8TeV: {\'type\':\'lnN\', \'DYlight\':' + '%.3f' %(1.+float(corr[1][0])*dyb_err) + ',\'DYb\':' + '%.3f' %(1.+(float(corr[1][1])*dyb_err)) + ',\'TT\':' + '%.3f' %(1.+float(corr[1][2])*dyb_err) + '} \n'
107 ttbar_string = 'CMS_vhbb_TT_SF_8TeV: {\'type\':\'lnN\', \'DYlight\':' + '%.3f' %(1.+float(corr[2][0])*ttbar_err) + ',\'DYb\':' + '%.3f' %(1.+(float(corr[2][1])*ttbar_err)) + ',\'TT\':' + '%.3f' %(1.+float(corr[2][2])*ttbar_err) + '} \n'
108
109
110 print dyl_string
111 #print dyc_string
112 print dyb_string
113 print ttbar_string
114
115 outfile = open("Datacard.txt",'w')
116 outfile.writelines(dyl_string)
117 #outfile.writelines(dyc_string)
118 outfile.writelines(dyb_string)
119 outfile.writelines(ttbar_string)
120 outfile.close()
121