ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/mergeOutput.py
Revision: 1.14
Committed: Fri Apr 12 05:25:01 2013 UTC (12 years ago) by ahart
Content type: text/x-python
Branch: MAIN
Changes since 1.13: +14 -3 lines
Log Message:
If the list of component datasets for a composite dataset is a dictionary instead of a list, use the values as weights when merging the component datasets.

File Contents

# User Rev Content
1 lantonel 1.1 #!/usr/bin/env python
2     import os
3     import sys
4 lantonel 1.8 from optparse import OptionParser
5 lantonel 1.1
6 lantonel 1.2 from OSUT3Analysis.Configuration.configurationOptions import *
7     from OSUT3Analysis.Configuration.processingUtilities import *
8 lantonel 1.1
9 ahart 1.9 from ROOT import TFile, TH1D
10    
11 lantonel 1.8 parser = OptionParser()
12 lantonel 1.1 parser = set_commandline_arguments(parser)
13 lantonel 1.8 (arguments, args) = parser.parse_args()
14 lantonel 1.1
15 lantonel 1.7 if arguments.localConfig:
16 lantonel 1.1 sys.path.append(os.getcwd())
17 lantonel 1.7 exec("from " + arguments.localConfig.rstrip('.py') + " import *")
18 lantonel 1.1
19 lantonel 1.7 condor_dir = set_condor_output_dir(arguments)
20 lantonel 1.1
21     #save a list of composite datasets
22     composite_datasets = get_composite_datasets(datasets)
23     #save a list of datasets with composite datasets split up
24     split_datasets = split_composite_datasets(datasets)
25    
26    
27     #merge first layer
28 ahart 1.9 flags = TH1D ("flags", "", 1, 0, 1)
29     flags.GetXaxis ().SetBinLabel (1, "noWeights")
30     if arguments.noWeights:
31     flags.SetBinContent (1, 1)
32    
33 lantonel 1.1 for dataset in split_datasets:
34     dataset_dir = "%s/%s" % (condor_dir,dataset)
35 ahart 1.9 if arguments.noWeights:
36     command = "mergeHists -w 1 -p %s %s" % (dataset_dir, dataset_dir)
37     else:
38 ahart 1.13 command = "mergeHists -l %g -p %s %s" % (intLumi, dataset_dir, dataset_dir)
39 lantonel 1.1 print "Merging output for",dataset, "dataset"
40     #print command
41     os.system(command)
42 ahart 1.9 fout = TFile (dataset_dir + ".root", "update")
43     fout.cd ()
44     flags.Write ()
45     fout.Close
46 lantonel 1.1
47     #merge together components of composite datasets
48     for composite_dataset in composite_datasets:
49     component_datasets_list = ""
50 ahart 1.14 component_weights_list = ""
51 lantonel 1.1 component_dataset_file_path = ""
52     composite_dataset_dir = "%s/%s" % (condor_dir,composite_dataset)
53     for component_dataset in composite_dataset_definitions[composite_dataset]:
54     component_dataset_dir = "%s/%s" % (condor_dir,component_dataset)
55     component_dataset_file_path = component_dataset_dir + ".root"
56     if os.path.isfile(component_dataset_file_path):
57 ahart 1.14 component_datasets_list += " " + component_dataset_file_path
58     if isinstance (composite_dataset_definitions[composite_dataset], dict):
59     if len (component_weights_list):
60     component_weights_list += "," + str (composite_dataset_definitions[composite_dataset][component_dataset])
61     else:
62     component_weights_list += str (composite_dataset_definitions[composite_dataset][component_dataset])
63     else:
64     if len (component_weights_list):
65     component_weights_list += ",1"
66     else:
67     component_weights_list += "1"
68     command = "mergeHists -w %s -p %s %s" % (component_weights_list, composite_dataset_dir, component_datasets_list)
69 lantonel 1.1 print "Merging component datasets for",composite_dataset, "dataset"
70     #print command
71     os.system(command)
72 ahart 1.9 fout = TFile (dataset_dir + ".root", "update")
73     fout.cd ()
74     flags.Write ()
75     fout.Close
76 lantonel 1.1
77     #recreate plots file with all datasets combined and in pretty colors
78     args = "-c %s" % condor_dir.partition('/')[2]
79 lantonel 1.7
80     #pass all the options on to the plot and cutflow making scripts
81     if arguments.localConfig:
82     args = args + " -l " + arguments.localConfig
83     if arguments.normalizeToData:
84 lantonel 1.4 args = args + " -n "
85 lantonel 1.7 if arguments.normalizeToUnitArea:
86 lantonel 1.5 args = args + " -u "
87 lantonel 1.7 if arguments.noStack:
88 lantonel 1.5 args = args + " -e "
89 lantonel 1.7 if arguments.makeRatioPlots:
90 lantonel 1.6 args = args + " -r "
91 lantonel 1.11 if arguments.draw2DPlots:
92     args = args + " --2D "
93 lantonel 1.7 if arguments.outputFileName:
94     args = args + " -o " + arguments.outputFileName
95 lantonel 1.12 if arguments.rebinFactor:
96     args = args + " -b " + arguments.rebinFactor
97 ahart 1.14
98 lantonel 1.1 print "running makePlots.py"
99     os.system("makePlots.py %s" % args)
100     print "running makeCutFlows.py"
101     os.system("makeCutFlows.py %s" % args)