--- UserCode/OSUT3Analysis/Configuration/scripts/makeCutFlows.py 2013/01/16 13:17:18 1.2 +++ UserCode/OSUT3Analysis/Configuration/scripts/makeCutFlows.py 2013/02/06 00:28:41 1.6 @@ -22,6 +22,7 @@ from ROOT import TFile, gROOT, gStyle, g channels = [] processed_datasets = [] +texfile = condor_dir + "/cutFlow.tex" replacements = { ">":"$>$", @@ -33,8 +34,8 @@ replacements = { "\\mu QCD":"\\mu$ $QCD", "EM QCD":"EM$ $QCD", "BCtoE QCD":"BCtoE$ $QCD", - - + + "Pt ":"pt ", "PT ":"pt ", "pT ":"pt ", @@ -45,7 +46,7 @@ replacements = { "hT ":"HT ", "HT ":"$H_{T}$ ", "tig$H_{T}$ ":"tight ", - + "D0":"d0", "d0":"$d_{0}$", @@ -76,14 +77,14 @@ secondary_replacements = { for dataset in datasets: fileName = condor_dir + "/" + dataset + ".root" if not os.path.exists(fileName): - print "Couldn't find output file for",dataset,"dataset" + #print "Couldn't find output file for",dataset,"dataset" continue testFile = TFile(fileName) if not (testFile.IsZombie()): processed_datasets.append(dataset) if len(processed_datasets) is 0: - sys.exit("No datasets have been processed") + sys.exit("Can't find any output root files for the given list of datasets") #### open first input file and re-make its directory structure in the output file testFile = TFile(condor_dir + "/" + processed_datasets[0] + ".root") @@ -98,42 +99,91 @@ for key in testFile.GetListOfKeys(): continue channels.append(key2.GetName()) +fout = open (texfile, "w") +fout.write ("\\documentclass{article}\n\n") +fout.write ("\\usepackage[landscape,margin=0.15cm]{geometry}\n\n") +fout.write ("\\usepackage{multirow}\n\n") +fout.write ("\\begin{document}\n\n") +fout.write ("\\pagestyle{empty}\n\n") +fout.close () + +firstChannel = True + +weight = intLumi / 10000.0 +for dataset in processed_datasets: + dataset_file = "%s/%s.root" % (condor_dir,dataset) + os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", weight)) + for channel in channels: # loop over final states, which each have their own directory - args = "" - hist = channel + "CutFlow" + fout = open (texfile, "a") + if not firstChannel: + fout.write ("\\pagebreak\n\n") + firstChannel = False + fout.write ("\\section{" + channel + " channel}\n\n") + fout.close () + + cutFlowArgs = "" + selectionArgs = "" + minusOneArgs = "" #print hist for dataset in processed_datasets: - dataset_file = "%s/%s.root" % (condor_dir,dataset) + dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset) #print dataset_file - args = args + " " + dataset_file - args = args + " " + hist - + cutFlowArgs = cutFlowArgs + " " + dataset_file + selectionArgs = selectionArgs + " " + dataset_file + minusOneArgs = minusOneArgs + " " + dataset_file + cutFlowArgs = cutFlowArgs + " " + channel + "CutFlow" + selectionArgs = selectionArgs + " " + channel + "Selection" + minusOneArgs = minusOneArgs + " " + channel + "MinusOne" + rawlabel = "$" + labels[dataset] + "$" label = rawlabel.replace("#","\\") label = "'" + label + "'" #print label - args = args + " " + label + cutFlowArgs = cutFlowArgs + " " + label + selectionArgs = selectionArgs + " " + label + minusOneArgs = minusOneArgs + " " + label #make cutFlowTable objects - texfile = "%s/%s.tex" % (condor_dir,channel) - os.system("cutFlowTable %s > %s" % (args,texfile)) - #reformat tex files - for line in fileinput.FileInput(texfile,inplace=1): - for replacement in replacements.keys(): - line = line.replace(replacement,replacements[replacement]) - print line, - - for line in fileinput.FileInput(texfile,inplace=1): - for replacement in secondary_replacements.keys(): - line = line.replace(replacement,secondary_replacements[replacement]) - print line, - - #process tex files to make pdf files - command = "pdflatex -interaction=batchmode -output-directory=./%s %s > /dev/null" % (condor_dir,texfile) - os.system(command) - os.system(command) - #os.system("rm %s" % texfile) - os.system("rm %saux" % (texfile.rstrip("tex"))) - os.system("rm %slog" % (texfile.rstrip("tex"))) - + fout = open (texfile, "a") + fout.write ("\\subsection{Cut Flow}\n\n") + fout.close () + os.system("cutFlowTable -l %g %s >> %s" % (intLumi,cutFlowArgs,texfile)) + fout = open (texfile, "a") + fout.write ("\\pagebreak\n\n") + fout.write ("\\subsection{Individual Selection}\n\n") + fout.close () + os.system("cutFlowTable -l %g %s >> %s" % (intLumi,selectionArgs,texfile)) + fout = open (texfile, "a") + fout.write ("\\pagebreak\n\n") + fout.write ("\\subsection{Minus One}\n\n") + fout.close () + os.system("cutFlowTable -l %g %s >> %s" % (intLumi,minusOneArgs,texfile)) + +for dataset in processed_datasets: + dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset) + os.remove(dataset_file) + +#reformat tex files +for line in fileinput.FileInput(texfile,inplace=1): + for replacement in replacements.keys(): + line = line.replace(replacement,replacements[replacement]) + print line, + +for line in fileinput.FileInput(texfile,inplace=1): + for replacement in secondary_replacements.keys(): + line = line.replace(replacement,secondary_replacements[replacement]) + print line, + +fout = open (texfile, "a") +fout.write ("\\end{document}\n") +fout.close () + +#process tex files to make pdf files +command = "pdflatex -interaction=batchmode -output-directory=./%s %s > /dev/null" % (condor_dir,texfile) +os.system(command) +os.system(command) +#os.system("rm %s" % texfile) +os.system("rm %saux" % (texfile.rstrip("tex"))) +os.system("rm %slog" % (texfile.rstrip("tex")))