ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/python/processingUtilities.py
Revision: 1.16
Committed: Wed May 1 19:48:28 2013 UTC (12 years ago) by ahart
Content type: text/x-python
Branch: MAIN
CVS Tags: V01-01-00, V01-00-00
Changes since 1.15: +3 -2 lines
Log Message:
Changed the notation for labelling the ROOT files with the bottom branching ratio in add_stops. The branching ratios are now given as percents.

File Contents

# User Rev Content
1 lantonel 1.1 #!/usr/bin/env python
2     import os
3 ahart 1.15 import re
4 lantonel 1.1 import sys
5 ahart 1.15 import math
6 lantonel 1.1 import datetime
7 lantonel 1.8 from optparse import OptionParser
8 ahart 1.15 #from OSUT3Analysis.Configuration.configurationOptions import *
9 lantonel 1.2
10 ahart 1.15 def split_composite_datasets(datasets, composite_dataset_definitions):
11 lantonel 1.1 for dataset in datasets:
12     if dataset in composite_dataset_definitions:
13     for component_dataset in composite_dataset_definitions[dataset]:
14     datasets.insert(datasets.index(dataset),component_dataset)
15     datasets.remove(dataset)
16     return datasets
17    
18 ahart 1.15 def get_composite_datasets(datasets, composite_dataset_definitions):
19 lantonel 1.1 composite_datasets = []
20     for dataset in datasets:
21     if dataset in composite_dataset_definitions:
22     composite_datasets.append(dataset)
23     return composite_datasets
24    
25 lantonel 1.7 def set_condor_submit_dir(arguments):
26     if arguments.condorDir:
27     condor_dir = "condor/%s" % arguments.condorDir
28 lantonel 1.1 else:
29     now = datetime.datetime.now()
30     date_hash = now.strftime("%Y_%m_%d_%H:%M:%S")
31     condor_dir = "condor/condor_%s" % date_hash
32 lantonel 1.3 #print "Condor submit directory set to ",condor_dir
33 lantonel 1.1 return condor_dir
34    
35 lantonel 1.7 def set_condor_output_dir(arguments):
36     if arguments.condorDir:
37     condor_dir = "condor/%s" % arguments.condorDir
38 lantonel 1.1 else: #get most recent condor submission directory
39     dir_list = []
40     for directory in os.listdir("./condor/"):
41     if directory.find("condor_") is not -1:
42     dir_list.append(directory)
43     if len(dir_list) is 0:
44     sys.exit("Cannot find last condor working directory")
45     dir_list.sort(reverse=True)
46     condor_dir = "condor/%s" % dir_list[0]
47 lantonel 1.3 #print "Condor output directory set to ",condor_dir
48 lantonel 1.1 return condor_dir
49    
50     def set_commandline_arguments(parser):
51 lantonel 1.12 #### Configuration-related Options
52 lantonel 1.8 parser.add_option("-l", "--localConfig", dest="localConfig",
53 lantonel 1.1 help="local configuration file")
54 lantonel 1.8 parser.add_option("-c", "--condorDir", dest="condorDir",
55 lantonel 1.5 help="condor output directory")
56 lantonel 1.12 parser.add_option("-o", "--output-file", dest="outputFileName",
57     help="specify an output file name for the histogram file, default is 'stacked_histograms.root'")
58     parser.add_option("-t", "--no-weights", action="store_true", dest="noWeights", default=False,
59     help="do not apply cross section weights")
60    
61    
62     #### Histogram Formatting Options
63 lantonel 1.8 parser.add_option("-n", "--normalize", action="store_true", dest="normalizeToData", default=False,
64 lantonel 1.5 help="normalize total background MC yield to the data")
65 lantonel 1.8 parser.add_option("-u", "--unit-area", action="store_true", dest="normalizeToUnitArea", default=False,
66 lantonel 1.5 help="normalize all samples to unit area (useful to compare shapes)")
67 lantonel 1.8 parser.add_option("-e", "--empty", action="store_true", dest="noStack", default=False,
68 lantonel 1.5 help="don't stack the background samples, draw them as empty histograms instead")
69 lantonel 1.12
70 lantonel 1.8 parser.add_option("-r", "--ratio", action="store_true", dest="makeRatioPlots", default=False,
71 lantonel 1.6 help="draw (data-MC)/MC plots below all 1D histograms")
72 lantonel 1.12 parser.add_option("-d", "--diff", action="store_true", dest="makeDiffPlots", default=False,
73     help="draw data-MC plots below all 1D histograms")
74 ahart 1.15 parser.add_option("-b", "--rebin", dest="rebinFactor",
75 lantonel 1.12 help="Rebin all the histograms which will have at least 10 bins after rebinning")
76 lantonel 1.13 parser.add_option("--2D", action="store_true", dest="draw2DPlots", default=False,
77     help="draw stacked 2D histograms")
78 ahart 1.15 parser.add_option("-y", "--yields", action="store_true", dest="printYields", default=False,
79     help="Include the yield of each source in the legend")
80 lantonel 1.13
81 lantonel 1.12
82 lantonel 1.1 return parser
83    
84 ahart 1.15 def get_short_name(dataset, dataset_names):
85 lantonel 1.1 for key in dataset_names:
86     if dataset_names[key] == dataset:
87 ahart 1.15 return key
88 lantonel 1.1 return "Unknown"
89 ahart 1.15
90     def stop_ctau (dataset):
91     if not re.match (r"stop[^_]*to[^_]*_[^_]*mm.*", dataset):
92     return 0.0
93     return float (re.sub (r"stop[^_]*to[^_]*_([^_]*)mm.*", r"\1", dataset))
94    
95     def source_stop_ctau (ctau):
96     return int (math.pow (10.0, math.ceil (math.log10 (ctau))))
97    
98     def add_stops (options, masses, ctaus, bottomBranchingRatios = []):
99     if not bottomBranchingRatios:
100 ahart 1.16 bottomBranchingRatios.append (50.0)
101 ahart 1.15 for mass in masses:
102     for ctau in ctaus:
103     for bottomBranchingRatio in bottomBranchingRatios:
104 ahart 1.16 datasetName = 'stop' + str (mass) + "_" + str (ctau) + "mm_br" + str (int (bottomBranchingRatio))
105 ahart 1.15 bottomDatasetName = 'stop' + str (mass) + "toBl_" + str (ctau) + "mm"
106     sourceBottomDatasetName = 'stop' + str (mass) + "toBl_" + str (source_stop_ctau (ctau)) + "mm"
107     topDatasetName = 'stop' + str (mass) + "toTnu_" + str (ctau) + "mm"
108     sourceTopDatasetName = 'stop' + str (mass) + "toTnu_" + str (source_stop_ctau (ctau)) + "mm"
109     mixedDatasetName = 'stop' + str (mass) + "toBT_" + str (ctau) + "mm"
110     sourceMixedDatasetName = 'stop' + str (mass) + "toBT_" + str (source_stop_ctau (ctau)) + "mm"
111    
112     options['datasets'].append (datasetName)
113 ahart 1.16 bottomBranchingRatio /= 100.0
114 ahart 1.15 options['composite_dataset_definitions'][datasetName] = {
115     bottomDatasetName : bottomBranchingRatio * bottomBranchingRatio,
116     topDatasetName : (1 - bottomBranchingRatio) * (1 - bottomBranchingRatio),
117     mixedDatasetName : (1 - bottomBranchingRatio * bottomBranchingRatio - (1 - bottomBranchingRatio) * (1 - bottomBranchingRatio))
118     }
119     options['dataset_names'][bottomDatasetName] = options['dataset_names'][sourceBottomDatasetName]
120     options['dataset_names'][topDatasetName] = options['dataset_names'][sourceTopDatasetName]
121     options['dataset_names'][mixedDatasetName] = options['dataset_names'][sourceMixedDatasetName]
122     options['nJobs'][bottomDatasetName] = 1
123     options['nJobs'][topDatasetName] = 1
124     options['nJobs'][mixedDatasetName] = 1
125     options['maxEvents'][bottomDatasetName] = -1
126     options['maxEvents'][topDatasetName] = -1
127     options['maxEvents'][mixedDatasetName] = -1
128     options['types'][datasetName] = "signalMC"
129     options['types'][bottomDatasetName] = "signalMC"
130     options['types'][topDatasetName] = "signalMC"
131     options['types'][mixedDatasetName] = "signalMC"
132     options['labels'][datasetName] = str (mass) + " GeV stop, (" + str (ctau) + "mm)"
133     options['labels'][bottomDatasetName] = "#tilde{t}#tilde{t}#rightarrowbbll (" + str (ctau) + "mm)"
134     options['labels'][topDatasetName] = "#tilde{t}#tilde{t}#rightarrowtt#nu#nu (" + str (ctau) + "mm)"
135     options['labels'][mixedDatasetName] = "#tilde{t}#tilde{t}#rightarrowbtl#nu (" + str (ctau) + "mm)"