ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeCutFlows.py
(Generate patch)

Comparing UserCode/OSUT3Analysis/Configuration/scripts/makeCutFlows.py (file contents):
Revision 1.6 by ahart, Wed Feb 6 00:28:41 2013 UTC vs.
Revision 1.19 by wulsin, Tue Jul 16 09:05:34 2013 UTC

# Line 10 | Line 10 | from OSUT3Analysis.Configuration.process
10   parser = OptionParser()
11   parser = set_commandline_arguments(parser)
12  
13 < (options, args) = parser.parse_args()
13 > parser.remove_option("-d")
14 > parser.remove_option("-n")
15 > parser.remove_option("-u")
16 > parser.remove_option("-e")
17 > parser.remove_option("-R")
18 > parser.remove_option("-b")
19 > parser.remove_option("-y")
20 > parser.remove_option("-p")
21 > parser.remove_option("-r")
22 > parser.remove_option("-o")
23 > parser.remove_option("--2D")
24 >
25 > parser.add_option("-d", "--diff", action="store_true", dest="makeDiffPlots", default=False,
26 >                  help="add a column for data-MC to the tables")
27 > parser.add_option("-r", "--ratio", action="store_true", dest="makeRatioPlots", default=False,
28 >                  help="add a colunn for (data-MC)/MC to the tables")
29 > parser.add_option("-s", "--sToB", action="store_true", dest="signalToBackground", default=False,
30 >                  help="add a column for S/sqrt(S+B) to the tables")
31 > parser.add_option("-o", "--output-file", dest="outputFileName",
32 >                  help="specify an output file base name for the cutflow table (suffix will be appended), default is 'cutFlow'")
33  
34 < if options.localConfig:
34 >
35 > (arguments, args) = parser.parse_args()
36 >
37 > if arguments.localConfig:
38      sys.path.append(os.getcwd())
39 <    exec("from " + options.localConfig.rstrip('.py') + " import *")
39 >    exec("from " + arguments.localConfig.rstrip('.py') + " import *")
40  
41 < condor_dir = set_condor_output_dir(options)
41 > condor_dir = set_condor_output_dir(arguments)
42  
43   from ROOT import TFile, gROOT, gStyle, gDirectory, TKey
44  
45   channels = []
46   processed_datasets = []
47 < texfile = condor_dir + "/cutFlow.tex"
47 >
48 > outputFileName = "cutFlow"
49 > if arguments.outputFileName:
50 >    outputFileName = arguments.outputFileName
51 > outputFileName = outputFileName.partition(".")[0]  # If the input filename contains a period, take only the part before the period.  
52 >
53 > texfile = condor_dir + "/" + outputFileName + ".tex"
54  
55   replacements = {
56      ">":"$>$",
57      "<":"$<$",
58 <    "eta ":"$\\eta$ ",
58 >    " eta ":" $\\eta$ ",
59 >    " abs(eta) ":" $|\\eta|$ ",
60      "#":"Num",
61  
62      "\\rightarrow":"{\\rightarrow}",
# Line 36 | Line 65 | replacements = {
65      "BCtoE QCD":"BCtoE$ $QCD",
66  
67  
68 <    "Pt ":"pt ",
69 <    "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 ",
68 >    " pt ":" $p_{T}$ ",
69 >    " ht ":"$H_{T}$ ",
70  
50    "D0":"d0",
71      "d0":"$d_{0}$",
72  
73 <    "MET ":"Met ",
74 <    "MEt ":"Met ",
75 <    "met ":"Met ",
76 <    "Met ":"$\\not\\!\\!{E}_{T}$ ",
77 <
78 <    "MHT ":"Mht ",
79 <    "MHt ":"Mht ",
80 <    "mht ":"Mht ",
81 <    "Mht ":"$\\not\\!\\!{H}_{T}$ ",
73 >    " MET ":" Met ",
74 >    " MEt ":" Met ",
75 >    " met ":" Met ",
76 >    " Met ":"$\\not\\!\\!{E}_{T}$ ",
77 >
78 >    " MHT ":" Mht ",
79 >    " MHt ":" Mht ",
80 >    " mht ":" Mht ",
81 >    " Mht ":"$\\not\\!\\!{H}_{T}$ ",
82  
83      "M_Z" : "$M_{Z}$",
84      "M_mumu" : "$M_{\\mu\\mu}$",
85      "M_ee" : "$M_{ee}$",
86      "M_ll" : "$M_{ll}$",
87  
68    "|" : "$|$"
88   }
89  
90   secondary_replacements = {
91      "$$<$":"$<"
92 +
93   }
94  
95  
# Line 100 | Line 120 | for key in testFile.GetListOfKeys():
120          channels.append(key2.GetName())
121  
122   fout = open (texfile, "w")
123 < fout.write ("\\documentclass{article}\n\n")
123 > fout.write ("\\documentclass[a2paper,8pt]{article}\n\n")
124   fout.write ("\\usepackage[landscape,margin=0.15cm]{geometry}\n\n")
125   fout.write ("\\usepackage{multirow}\n\n")
126   fout.write ("\\begin{document}\n\n")
# Line 109 | Line 129 | fout.close ()
129  
130   firstChannel = True
131  
132 < weight = intLumi / 10000.0
133 < for dataset in processed_datasets:
134 <    dataset_file = "%s/%s.root" % (condor_dir,dataset)
135 <    os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", weight))
132 > #weight = intLumi / 10000.0
133 > #for dataset in processed_datasets:
134 > #    dataset_file = "%s/%s.root" % (condor_dir,dataset)
135 > #    fin = TFile (dataset_file)
136 > #    flags = fin.Get ("flags")
137 > #    noWeights = flags and flags.GetBinContent (1)
138 > #    fin.Close ()
139 > #    if types[dataset] != "data" and not noWeights:
140 > #        os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", weight))
141 > #    else:
142 > #        os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", 1.0))
143  
117 for channel in channels: # loop over final states, which each have their own directory
118    fout = open (texfile, "a")
119    if not firstChannel:
120        fout.write ("\\pagebreak\n\n")
121    firstChannel = False
122    fout.write ("\\section{" + channel + " channel}\n\n")
123    fout.close ()
144  
145 + for channel in channels: # loop over final states, which each have their own directory
146 +    formatted_channel = channel.replace("_"," ")
147      cutFlowArgs = ""
148      selectionArgs = ""
149      minusOneArgs = ""
150      #print hist
151 +
152      for dataset in processed_datasets:
153 <            dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
153 >            dataset_file = "%s/%s.root" % (condor_dir,dataset)
154              #print dataset_file
155 +            if arguments.makeDiffPlots or arguments.makeRatioPlots:
156 +              if types[dataset] == "data":
157 +                dataset_file = "\"<" + dataset_file + "\""
158 +              elif types[dataset] == "bgMC":
159 +                dataset_file = "\">" + dataset_file + "\""
160 +            if arguments.signalToBackground:
161 +              if types[dataset] == "signalMC":
162 +                dataset_file = "\"<" + dataset_file + "\""
163 +              elif types[dataset] == "bgMC":
164 +                dataset_file = "\">" + dataset_file + "\""
165              cutFlowArgs = cutFlowArgs + " " + dataset_file
166              selectionArgs = selectionArgs + " " + dataset_file
167              minusOneArgs = minusOneArgs + " " + dataset_file
168 <            cutFlowArgs = cutFlowArgs + " " + channel + "CutFlow"
169 <            selectionArgs = selectionArgs + " " + channel + "Selection"
170 <            minusOneArgs = minusOneArgs + " " + channel + "MinusOne"
168 >            cutFlowArgs = cutFlowArgs + " '" + channel + "CutFlow'"
169 >            selectionArgs = selectionArgs + " '" + channel + "Selection'"
170 >            minusOneArgs = minusOneArgs + " '" + channel + "MinusOne'"
171  
172              rawlabel = "$" + labels[dataset] + "$"
173              label = rawlabel.replace("#","\\")
# Line 144 | Line 177 | for channel in channels: # loop over fin
177              selectionArgs = selectionArgs + " " + label
178              minusOneArgs = minusOneArgs + " " + label
179  
147
180      #make cutFlowTable objects
181      fout = open (texfile, "a")
182 <    fout.write ("\\subsection{Cut Flow}\n\n")
182 >    if not firstChannel:
183 >        fout.write ("\\pagebreak\n\n")
184 >    cutFlowTable = "cutFlowTable"
185 >    if arguments.makeDiffPlots:
186 >      cutFlowTable += " -d \"Data - MC\""
187 >    if arguments.makeRatioPlots:
188 >      cutFlowTable += " -r \"(Data - MC) / MC\""
189 >    if arguments.signalToBackground:
190 >      cutFlowTable += " -s \"$\\mathrm{S} / \\sqrt{\\mathrm{S} + \\mathrm{B}}$\""
191 >    firstChannel = False
192 >    fout.write ("\\section*{" + formatted_channel + " channel}\n\n")
193 >    fout.write ("\\subsection*{Cut flow}\n\n")
194      fout.close ()
195 <    os.system("cutFlowTable -l %g %s >> %s" % (intLumi,cutFlowArgs,texfile))
195 >    #    print "Debug:  running command:  %s -l %g -m %s >> %s" % (cutFlowTable, intLumi,cutFlowArgs,texfile)
196 >    os.system("%s -l %g -m %s >> %s" % (cutFlowTable, intLumi,cutFlowArgs,texfile))
197      fout = open (texfile, "a")
198      fout.write ("\\pagebreak\n\n")
199 <    fout.write ("\\subsection{Individual Selection}\n\n")
199 >    fout.write ("\\section*{" + formatted_channel + " channel}\n\n")
200 >    fout.write ("\\subsection*{Individual selection}\n\n")
201      fout.close ()
202 <    os.system("cutFlowTable -l %g %s >> %s" % (intLumi,selectionArgs,texfile))
202 >    os.system("%s -l %g %s >> %s" % (cutFlowTable, intLumi,selectionArgs,texfile))
203      fout = open (texfile, "a")
204      fout.write ("\\pagebreak\n\n")
205 <    fout.write ("\\subsection{Minus One}\n\n")
205 >    fout.write ("\\section*{" + formatted_channel + " channel}\n\n")
206 >    fout.write ("\\subsection*{Minus one}\n\n")
207      fout.close ()
208 <    os.system("cutFlowTable -l %g %s >> %s" % (intLumi,minusOneArgs,texfile))
208 >    os.system("%s -l %g %s >> %s" % (cutFlowTable, intLumi,minusOneArgs,texfile))
209  
210 < for dataset in processed_datasets:
211 <    dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
212 <    os.remove(dataset_file)
210 > #for dataset in processed_datasets:
211 > #    dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset)
212 > #    os.remove(dataset_file)
213  
214   #reformat tex files
215   for line in fileinput.FileInput(texfile,inplace=1):
# Line 187 | Line 233 | os.system(command)
233   #os.system("rm %s" % texfile)
234   os.system("rm %saux" % (texfile.rstrip("tex")))
235   os.system("rm %slog" % (texfile.rstrip("tex")))
236 +
237 + print "Finished writing cutFlow to " + condor_dir + "/" + outputFileName + "{.tex,.pdf}"
238 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines