ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeCutFlows.py
Revision: 1.11
Committed: Tue Mar 12 13:57:08 2013 UTC (12 years, 1 month ago) by lantonel
Content type: text/x-python
Branch: MAIN
Changes since 1.10: +18 -25 lines
Log Message:
fixed a couple little formatting things

File Contents

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