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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines