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 |
cutFlowArgs = ""
|
122 |
selectionArgs = ""
|
123 |
minusOneArgs = ""
|
124 |
#print hist
|
125 |
for dataset in processed_datasets:
|
126 |
dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
|
127 |
#print dataset_file
|
128 |
cutFlowArgs = cutFlowArgs + " " + dataset_file
|
129 |
selectionArgs = selectionArgs + " " + dataset_file
|
130 |
minusOneArgs = minusOneArgs + " " + dataset_file
|
131 |
cutFlowArgs = cutFlowArgs + " " + channel + "CutFlow"
|
132 |
selectionArgs = selectionArgs + " " + channel + "Selection"
|
133 |
minusOneArgs = minusOneArgs + " " + channel + "MinusOne"
|
134 |
|
135 |
rawlabel = "$" + labels[dataset] + "$"
|
136 |
label = rawlabel.replace("#","\\")
|
137 |
label = "'" + label + "'"
|
138 |
#print label
|
139 |
cutFlowArgs = cutFlowArgs + " " + label
|
140 |
selectionArgs = selectionArgs + " " + label
|
141 |
minusOneArgs = minusOneArgs + " " + label
|
142 |
|
143 |
|
144 |
#make cutFlowTable objects
|
145 |
fout = open (texfile, "a")
|
146 |
if not firstChannel:
|
147 |
fout.write ("\\pagebreak\n\n")
|
148 |
firstChannel = False
|
149 |
fout.write ("\\section*{" + channel + " channel}\n\n")
|
150 |
fout.write ("\\subsection*{Cut flow}\n\n")
|
151 |
fout.close ()
|
152 |
os.system("cutFlowTable -l %g %s >> %s" % (intLumi,cutFlowArgs,texfile))
|
153 |
fout = open (texfile, "a")
|
154 |
fout.write ("\\pagebreak\n\n")
|
155 |
fout.write ("\\section*{" + channel + " channel}\n\n")
|
156 |
fout.write ("\\subsection*{Individual selection}\n\n")
|
157 |
fout.close ()
|
158 |
os.system("cutFlowTable -l %g %s >> %s" % (intLumi,selectionArgs,texfile))
|
159 |
fout = open (texfile, "a")
|
160 |
fout.write ("\\pagebreak\n\n")
|
161 |
fout.write ("\\section*{" + channel + " channel}\n\n")
|
162 |
fout.write ("\\subsection*{Minus one}\n\n")
|
163 |
fout.close ()
|
164 |
os.system("cutFlowTable -l %g %s >> %s" % (intLumi,minusOneArgs,texfile))
|
165 |
|
166 |
for dataset in processed_datasets:
|
167 |
dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
|
168 |
os.remove(dataset_file)
|
169 |
|
170 |
#reformat tex files
|
171 |
for line in fileinput.FileInput(texfile,inplace=1):
|
172 |
for replacement in replacements.keys():
|
173 |
line = line.replace(replacement,replacements[replacement])
|
174 |
print line,
|
175 |
|
176 |
for line in fileinput.FileInput(texfile,inplace=1):
|
177 |
for replacement in secondary_replacements.keys():
|
178 |
line = line.replace(replacement,secondary_replacements[replacement])
|
179 |
print line,
|
180 |
|
181 |
fout = open (texfile, "a")
|
182 |
fout.write ("\\end{document}\n")
|
183 |
fout.close ()
|
184 |
|
185 |
#process tex files to make pdf files
|
186 |
command = "pdflatex -interaction=batchmode -output-directory=./%s %s > /dev/null" % (condor_dir,texfile)
|
187 |
os.system(command)
|
188 |
os.system(command)
|
189 |
#os.system("rm %s" % texfile)
|
190 |
os.system("rm %saux" % (texfile.rstrip("tex")))
|
191 |
os.system("rm %slog" % (texfile.rstrip("tex")))
|