1 |
|
#!/usr/bin/env python |
2 |
|
import os |
3 |
+ |
import re |
4 |
|
import sys |
5 |
+ |
import math |
6 |
|
import datetime |
7 |
|
from optparse import OptionParser |
8 |
+ |
#from OSUT3Analysis.Configuration.configurationOptions import * |
9 |
|
|
10 |
< |
from OSUT3Analysis.Configuration.configurationOptions import * |
8 |
< |
|
9 |
< |
|
10 |
< |
def split_composite_datasets(datasets): |
10 |
> |
def split_composite_datasets(datasets, composite_dataset_definitions): |
11 |
|
for dataset in datasets: |
12 |
|
if dataset in composite_dataset_definitions: |
13 |
|
for component_dataset in composite_dataset_definitions[dataset]: |
15 |
|
datasets.remove(dataset) |
16 |
|
return datasets |
17 |
|
|
18 |
< |
def get_composite_datasets(datasets): |
18 |
> |
def get_composite_datasets(datasets, composite_dataset_definitions): |
19 |
|
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 |
< |
def set_condor_submit_dir(options): |
26 |
< |
if options.condorDir: |
27 |
< |
condor_dir = "condor/%s" % options.condorDir |
25 |
> |
def set_condor_submit_dir(arguments): |
26 |
> |
if arguments.condorDir: |
27 |
> |
condor_dir = "condor/%s" % arguments.condorDir |
28 |
|
else: |
29 |
|
now = datetime.datetime.now() |
30 |
|
date_hash = now.strftime("%Y_%m_%d_%H:%M:%S") |
32 |
|
#print "Condor submit directory set to ",condor_dir |
33 |
|
return condor_dir |
34 |
|
|
35 |
< |
def set_condor_output_dir(options): |
36 |
< |
if options.condorDir: |
37 |
< |
condor_dir = "condor/%s" % options.condorDir |
35 |
> |
def set_condor_output_dir(arguments): |
36 |
> |
if arguments.condorDir: |
37 |
> |
condor_dir = "condor/%s" % arguments.condorDir |
38 |
|
else: #get most recent condor submission directory |
39 |
|
dir_list = [] |
40 |
|
for directory in os.listdir("./condor/"): |
48 |
|
return condor_dir |
49 |
|
|
50 |
|
def set_commandline_arguments(parser): |
51 |
+ |
#### Configuration-related Options |
52 |
|
parser.add_option("-l", "--localConfig", dest="localConfig", |
53 |
|
help="local configuration file") |
53 |
– |
|
54 |
|
parser.add_option("-c", "--condorDir", dest="condorDir", |
55 |
|
help="condor output directory") |
56 |
+ |
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 |
+ |
parser.add_option("-q", "--quickMerge", action="store_true", dest="quickMerge", default=False, |
61 |
+ |
help="do merge without making cutflow or plots") |
62 |
+ |
|
63 |
+ |
|
64 |
+ |
#### Histogram Formatting Options |
65 |
|
parser.add_option("-n", "--normalize", action="store_true", dest="normalizeToData", default=False, |
66 |
|
help="normalize total background MC yield to the data") |
67 |
|
parser.add_option("-u", "--unit-area", action="store_true", dest="normalizeToUnitArea", default=False, |
68 |
|
help="normalize all samples to unit area (useful to compare shapes)") |
69 |
|
parser.add_option("-e", "--empty", action="store_true", dest="noStack", default=False, |
70 |
|
help="don't stack the background samples, draw them as empty histograms instead") |
71 |
< |
|
71 |
> |
|
72 |
> |
parser.add_option("-r", "--ratio", action="store_true", dest="makeRatioPlots", default=False, |
73 |
> |
help="draw (data-MC)/MC plots below all 1D histograms") |
74 |
> |
parser.add_option("-R", "--ratioYRange", dest="ratioYRange", default=1.15, |
75 |
> |
help="maximum of range of vertical scale for ratio plots") |
76 |
> |
parser.add_option("-d", "--diff", action="store_true", dest="makeDiffPlots", default=False, |
77 |
> |
help="draw data-MC plots below all 1D histograms") |
78 |
> |
parser.add_option("-b", "--rebin", dest="rebinFactor", |
79 |
> |
help="Rebin all the histograms which will have at least 10 bins after rebinning") |
80 |
> |
parser.add_option("--2D", action="store_true", dest="draw2DPlots", default=False, |
81 |
> |
help="draw stacked 2D histograms") |
82 |
> |
parser.add_option("-y", "--yields", action="store_true", dest="printYields", default=False, |
83 |
> |
help="Include the yield of each source in the legend") |
84 |
> |
parser.add_option("-p", "--pdfs", action="store_true", dest="savePDFs", default=False, |
85 |
> |
help="Save pdfs files for all plots made") |
86 |
> |
|
87 |
> |
|
88 |
> |
### Only used by makeBNTreePlot.py (maybe move to another file?) |
89 |
> |
parser.add_option("-D", "--dataset", dest="datasetName", |
90 |
> |
help="Name of dataset (overrides value from local configuration file)") |
91 |
> |
parser.add_option("-C", "--runOnCondor", action="store_true", dest="runOnCondor", default=False, |
92 |
> |
help="Run on condor instead of interactively") |
93 |
> |
|
94 |
|
|
95 |
|
return parser |
96 |
|
|
97 |
< |
def get_short_name(dataset): |
97 |
> |
def get_short_name(dataset, dataset_names): |
98 |
|
for key in dataset_names: |
99 |
|
if dataset_names[key] == dataset: |
100 |
< |
return key; |
100 |
> |
return key |
101 |
|
return "Unknown" |
102 |
+ |
|
103 |
+ |
def stop_ctau (dataset): |
104 |
+ |
if not re.match (r"stop[^_]*to[^_]*_[^_]*mm.*", dataset): |
105 |
+ |
return 0.0 |
106 |
+ |
return float (re.sub (r"stop[^_]*to[^_]*_([^_]*)mm.*", r"\1", dataset)) |
107 |
+ |
|
108 |
+ |
def source_stop_ctau (ctau): |
109 |
+ |
return int (math.pow (10.0, math.ceil (math.log10 (ctau)))) |
110 |
+ |
|
111 |
+ |
def add_stops (options, masses, ctaus, bottomBranchingRatios = []): |
112 |
+ |
if not bottomBranchingRatios: |
113 |
+ |
bottomBranchingRatios.append (50.0) |
114 |
+ |
for mass in masses: |
115 |
+ |
for ctau in ctaus: |
116 |
+ |
for bottomBranchingRatio in bottomBranchingRatios: |
117 |
+ |
datasetName = 'stop' + str (mass) + "_" + str (ctau) + "mm_br" + str (int (bottomBranchingRatio)) |
118 |
+ |
bottomDatasetName = 'stop' + str (mass) + "toBl_" + str (ctau) + "mm" |
119 |
+ |
sourceBottomDatasetName = 'stop' + str (mass) + "toBl_" + str (source_stop_ctau (ctau)) + "mm" |
120 |
+ |
topDatasetName = 'stop' + str (mass) + "toTnu_" + str (ctau) + "mm" |
121 |
+ |
sourceTopDatasetName = 'stop' + str (mass) + "toTnu_" + str (source_stop_ctau (ctau)) + "mm" |
122 |
+ |
mixedDatasetName = 'stop' + str (mass) + "toBT_" + str (ctau) + "mm" |
123 |
+ |
sourceMixedDatasetName = 'stop' + str (mass) + "toBT_" + str (source_stop_ctau (ctau)) + "mm" |
124 |
+ |
|
125 |
+ |
options['datasets'].append (datasetName) |
126 |
+ |
bottomBranchingRatio /= 100.0 |
127 |
+ |
options['composite_dataset_definitions'][datasetName] = { |
128 |
+ |
bottomDatasetName : bottomBranchingRatio * bottomBranchingRatio, |
129 |
+ |
topDatasetName : (1 - bottomBranchingRatio) * (1 - bottomBranchingRatio), |
130 |
+ |
mixedDatasetName : (1 - bottomBranchingRatio * bottomBranchingRatio - (1 - bottomBranchingRatio) * (1 - bottomBranchingRatio)) |
131 |
+ |
} |
132 |
+ |
options['dataset_names'][bottomDatasetName] = options['dataset_names'][sourceBottomDatasetName] |
133 |
+ |
options['dataset_names'][topDatasetName] = options['dataset_names'][sourceTopDatasetName] |
134 |
+ |
options['dataset_names'][mixedDatasetName] = options['dataset_names'][sourceMixedDatasetName] |
135 |
+ |
options['nJobs'][bottomDatasetName] = 1 |
136 |
+ |
options['nJobs'][topDatasetName] = 1 |
137 |
+ |
options['nJobs'][mixedDatasetName] = 1 |
138 |
+ |
options['maxEvents'][bottomDatasetName] = -1 |
139 |
+ |
options['maxEvents'][topDatasetName] = -1 |
140 |
+ |
options['maxEvents'][mixedDatasetName] = -1 |
141 |
+ |
options['types'][datasetName] = "signalMC" |
142 |
+ |
options['types'][bottomDatasetName] = "signalMC" |
143 |
+ |
options['types'][topDatasetName] = "signalMC" |
144 |
+ |
options['types'][mixedDatasetName] = "signalMC" |
145 |
+ |
options['labels'][datasetName] = str (mass) + " GeV stop (#LTc#tau#GT = " + str (ctau) + " mm)" |
146 |
+ |
options['labels'][bottomDatasetName] = "#tilde{t}#tilde{t}#rightarrowbbll (#LTc#tau#GT = " + str (ctau) + " mm)" |
147 |
+ |
options['labels'][topDatasetName] = "#tilde{t}#tilde{t}#rightarrowtt#nu#nu (#LTc#tau#GT = " + str (ctau) + " mm)" |
148 |
+ |
options['labels'][mixedDatasetName] = "#tilde{t}#tilde{t}#rightarrowbtl#nu (#LTc#tau#GT = " + str (ctau) + " mm)" |