ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeCutFlows.py
Revision: 1.7
Committed: Tue Feb 12 20:59:53 2013 UTC (12 years, 2 months ago) by ahart
Content type: text/x-python
Branch: MAIN
Changes since 1.6: +4 -1 lines
Log Message:
Do not weight data.

File Contents

# Content
1 #!/usr/bin/env python
2 import sys
3 import os
4 import fileinput
5 from array import *
6 from optparse import OptionParser
7 from OSUT3Analysis.Configuration.configurationOptions import *
8 from OSUT3Analysis.Configuration.processingUtilities import *
9
10 parser = OptionParser()
11 parser = set_commandline_arguments(parser)
12
13 (options, args) = parser.parse_args()
14
15 if options.localConfig:
16 sys.path.append(os.getcwd())
17 exec("from " + options.localConfig.rstrip('.py') + " import *")
18
19 condor_dir = set_condor_output_dir(options)
20
21 from ROOT import TFile, gROOT, gStyle, gDirectory, TKey
22
23 channels = []
24 processed_datasets = []
25 texfile = condor_dir + "/cutFlow.tex"
26
27 replacements = {
28 ">":"$>$",
29 "<":"$<$",
30 "eta ":"$\\eta$ ",
31 "#":"Num",
32
33 "\\rightarrow":"{\\rightarrow}",
34 "\\mu QCD":"\\mu$ $QCD",
35 "EM QCD":"EM$ $QCD",
36 "BCtoE QCD":"BCtoE$ $QCD",
37
38
39 "Pt ":"pt ",
40 "PT ":"pt ",
41 "pT ":"pt ",
42 "pt ":"$p_{T}$ ",
43
44 "Ht ":"HT ",
45 "ht ":"HT ",
46 "hT ":"HT ",
47 "HT ":"$H_{T}$ ",
48 "tig$H_{T}$ ":"tight ",
49
50 "D0":"d0",
51 "d0":"$d_{0}$",
52
53 "MET ":"Met ",
54 "MEt ":"Met ",
55 "met ":"Met ",
56 "Met ":"$\\not\\!\\!{E}_{T}$ ",
57
58 "MHT ":"Mht ",
59 "MHt ":"Mht ",
60 "mht ":"Mht ",
61 "Mht ":"$\\not\\!\\!{H}_{T}$ ",
62
63 "M_Z" : "$M_{Z}$",
64 "M_mumu" : "$M_{\\mu\\mu}$",
65 "M_ee" : "$M_{ee}$",
66 "M_ll" : "$M_{ll}$",
67
68 "|" : "$|$"
69 }
70
71 secondary_replacements = {
72 "$$<$":"$<"
73 }
74
75
76 #### check which input datasets have valid output files
77 for dataset in datasets:
78 fileName = condor_dir + "/" + dataset + ".root"
79 if not os.path.exists(fileName):
80 #print "Couldn't find output file for",dataset,"dataset"
81 continue
82 testFile = TFile(fileName)
83 if not (testFile.IsZombie()):
84 processed_datasets.append(dataset)
85
86 if len(processed_datasets) is 0:
87 sys.exit("Can't find any output root files for the given list of datasets")
88
89 #### open first input file and re-make its directory structure in the output file
90 testFile = TFile(condor_dir + "/" + processed_datasets[0] + ".root")
91 testFile.cd()
92 for key in testFile.GetListOfKeys():
93 if (key.GetClassName() != "TDirectoryFile"):
94 continue
95 rootDirectory = key.GetName()
96 testFile.cd(key.GetName())
97 for key2 in gDirectory.GetListOfKeys():
98 if (key2.GetClassName() != "TDirectoryFile"):
99 continue
100 channels.append(key2.GetName())
101
102 fout = open (texfile, "w")
103 fout.write ("\\documentclass{article}\n\n")
104 fout.write ("\\usepackage[landscape,margin=0.15cm]{geometry}\n\n")
105 fout.write ("\\usepackage{multirow}\n\n")
106 fout.write ("\\begin{document}\n\n")
107 fout.write ("\\pagestyle{empty}\n\n")
108 fout.close ()
109
110 firstChannel = True
111
112 weight = intLumi / 10000.0
113 for dataset in processed_datasets:
114 dataset_file = "%s/%s.root" % (condor_dir,dataset)
115 if types[dataset] != "data":
116 os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", weight))
117 else:
118 os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", 1.0))
119
120 for channel in channels: # loop over final states, which each have their own directory
121 fout = open (texfile, "a")
122 if not firstChannel:
123 fout.write ("\\pagebreak\n\n")
124 firstChannel = False
125 fout.write ("\\section{" + channel + " channel}\n\n")
126 fout.close ()
127
128 cutFlowArgs = ""
129 selectionArgs = ""
130 minusOneArgs = ""
131 #print hist
132 for dataset in processed_datasets:
133 dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
134 #print dataset_file
135 cutFlowArgs = cutFlowArgs + " " + dataset_file
136 selectionArgs = selectionArgs + " " + dataset_file
137 minusOneArgs = minusOneArgs + " " + dataset_file
138 cutFlowArgs = cutFlowArgs + " " + channel + "CutFlow"
139 selectionArgs = selectionArgs + " " + channel + "Selection"
140 minusOneArgs = minusOneArgs + " " + channel + "MinusOne"
141
142 rawlabel = "$" + labels[dataset] + "$"
143 label = rawlabel.replace("#","\\")
144 label = "'" + label + "'"
145 #print label
146 cutFlowArgs = cutFlowArgs + " " + label
147 selectionArgs = selectionArgs + " " + label
148 minusOneArgs = minusOneArgs + " " + label
149
150
151 #make cutFlowTable objects
152 fout = open (texfile, "a")
153 fout.write ("\\subsection{Cut Flow}\n\n")
154 fout.close ()
155 os.system("cutFlowTable -l %g %s >> %s" % (intLumi,cutFlowArgs,texfile))
156 fout = open (texfile, "a")
157 fout.write ("\\pagebreak\n\n")
158 fout.write ("\\subsection{Individual Selection}\n\n")
159 fout.close ()
160 os.system("cutFlowTable -l %g %s >> %s" % (intLumi,selectionArgs,texfile))
161 fout = open (texfile, "a")
162 fout.write ("\\pagebreak\n\n")
163 fout.write ("\\subsection{Minus One}\n\n")
164 fout.close ()
165 os.system("cutFlowTable -l %g %s >> %s" % (intLumi,minusOneArgs,texfile))
166
167 for dataset in processed_datasets:
168 dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
169 os.remove(dataset_file)
170
171 #reformat tex files
172 for line in fileinput.FileInput(texfile,inplace=1):
173 for replacement in replacements.keys():
174 line = line.replace(replacement,replacements[replacement])
175 print line,
176
177 for line in fileinput.FileInput(texfile,inplace=1):
178 for replacement in secondary_replacements.keys():
179 line = line.replace(replacement,secondary_replacements[replacement])
180 print line,
181
182 fout = open (texfile, "a")
183 fout.write ("\\end{document}\n")
184 fout.close ()
185
186 #process tex files to make pdf files
187 command = "pdflatex -interaction=batchmode -output-directory=./%s %s > /dev/null" % (condor_dir,texfile)
188 os.system(command)
189 os.system(command)
190 #os.system("rm %s" % texfile)
191 os.system("rm %saux" % (texfile.rstrip("tex")))
192 os.system("rm %slog" % (texfile.rstrip("tex")))