ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeCutFlows.py
Revision: 1.15
Committed: Tue Apr 9 21:42:18 2013 UTC (12 years ago) by ahart
Content type: text/x-python
Branch: MAIN
CVS Tags: V02-00-00, V00-01-00
Changes since 1.14: +15 -15 lines
Log Message:
Perform the full weighting at merging instead of splitting it between the merging and plotting steps.

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