ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeCutFlows.py
Revision: 1.3
Committed: Wed Jan 30 01:30:53 2013 UTC (12 years, 3 months ago) by ahart
Content type: text/x-python
Branch: MAIN
Changes since 1.2: +46 -25 lines
Log Message:
Output all channels into a single file with sections.

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     "eta ":"$\\eta$ ",
31     "#":"Num",
32    
33     "\\rightarrow":"{\\rightarrow}",
34     "\\mu QCD":"\\mu$ $QCD",
35     "EM QCD":"EM$ $QCD",
36     "BCtoE QCD":"BCtoE$ $QCD",
37 ahart 1.3
38    
39 lantonel 1.1 "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 ahart 1.3
50 lantonel 1.1 "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("No datasets have been processed")
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 ahart 1.3 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 lantonel 1.1 for channel in channels: # loop over final states, which each have their own directory
113 ahart 1.3 fout = open (texfile, "a")
114     if not firstChannel:
115     fout.write ("\\pagebreak\n\n")
116     firstChannel = False
117     fout.write ("\\section{" + channel + " channel}\n\n")
118     fout.close ()
119    
120 lantonel 1.1 args = ""
121     hist = channel + "CutFlow"
122     #print hist
123     for dataset in processed_datasets:
124     dataset_file = "%s/%s.root" % (condor_dir,dataset)
125     #print dataset_file
126     args = args + " " + dataset_file
127     args = args + " " + hist
128 ahart 1.3
129 lantonel 1.1 rawlabel = "$" + labels[dataset] + "$"
130     label = rawlabel.replace("#","\\")
131     label = "'" + label + "'"
132     #print label
133     args = args + " " + label
134    
135    
136     #make cutFlowTable objects
137 ahart 1.3 os.system("cutFlowTable %s >> %s" % (args,texfile))
138    
139     #reformat tex files
140     for line in fileinput.FileInput(texfile,inplace=1):
141     for replacement in replacements.keys():
142     line = line.replace(replacement,replacements[replacement])
143     print line,
144    
145     for line in fileinput.FileInput(texfile,inplace=1):
146     for replacement in secondary_replacements.keys():
147     line = line.replace(replacement,secondary_replacements[replacement])
148     print line,
149    
150     fout = open (texfile, "a")
151     fout.write ("\\end{document}\n")
152     fout.close ()
153    
154     #process tex files to make pdf files
155     command = "pdflatex -interaction=batchmode -output-directory=./%s %s > /dev/null" % (condor_dir,texfile)
156     os.system(command)
157     os.system(command)
158     #os.system("rm %s" % texfile)
159     os.system("rm %saux" % (texfile.rstrip("tex")))
160     os.system("rm %slog" % (texfile.rstrip("tex")))