1 |
|
#!/usr/bin/env python |
2 |
|
import os |
3 |
+ |
import re |
4 |
|
import sys |
5 |
+ |
import math |
6 |
|
import datetime |
7 |
+ |
import copy |
8 |
|
from optparse import OptionParser |
9 |
< |
from OSUT3Analysis.Configuration.configurationOptions import * |
9 |
> |
import OSUT3Analysis.DBTools.osusub_cfg as osusub |
10 |
> |
import FWCore.ParameterSet.Config as cms |
11 |
|
|
12 |
< |
|
9 |
< |
def split_composite_datasets(datasets): |
12 |
> |
def split_composite_datasets(datasets, composite_dataset_definitions): |
13 |
|
for dataset in datasets: |
14 |
|
if dataset in composite_dataset_definitions: |
15 |
|
for component_dataset in composite_dataset_definitions[dataset]: |
17 |
|
datasets.remove(dataset) |
18 |
|
return datasets |
19 |
|
|
20 |
< |
def get_composite_datasets(datasets): |
20 |
> |
def get_composite_datasets(datasets, composite_dataset_definitions): |
21 |
|
composite_datasets = [] |
22 |
|
for dataset in datasets: |
23 |
|
if dataset in composite_dataset_definitions: |
59 |
|
help="specify an output file name for the histogram file, default is 'stacked_histograms.root'") |
60 |
|
parser.add_option("-t", "--no-weights", action="store_true", dest="noWeights", default=False, |
61 |
|
help="do not apply cross section weights") |
62 |
+ |
parser.add_option("-q", "--quickMerge", action="store_true", dest="quickMerge", default=False, |
63 |
+ |
help="do merge without making cutflow or plots") |
64 |
|
|
65 |
|
|
66 |
|
#### Histogram Formatting Options |
73 |
|
|
74 |
|
parser.add_option("-r", "--ratio", action="store_true", dest="makeRatioPlots", default=False, |
75 |
|
help="draw (data-MC)/MC plots below all 1D histograms") |
76 |
+ |
parser.add_option("-R", "--ratioYRange", dest="ratioYRange", |
77 |
+ |
help="maximum of range of vertical scale for ratio plots") |
78 |
|
parser.add_option("-d", "--diff", action="store_true", dest="makeDiffPlots", default=False, |
79 |
|
help="draw data-MC plots below all 1D histograms") |
80 |
< |
parser.add_option("-b", "--rebin", dest="rebinFactor", |
80 |
> |
parser.add_option("-b", "--rebin", dest="rebinFactor", |
81 |
|
help="Rebin all the histograms which will have at least 10 bins after rebinning") |
82 |
+ |
parser.add_option("--2D", action="store_true", dest="draw2DPlots", default=False, |
83 |
+ |
help="draw stacked 2D histograms") |
84 |
+ |
parser.add_option("-y", "--yields", action="store_true", dest="printYields", default=False, |
85 |
+ |
help="Include the yield of each source in the legend") |
86 |
+ |
parser.add_option("-p", "--pdfs", action="store_true", dest="savePDFs", default=False, |
87 |
+ |
help="Save pdfs files for all plots made") |
88 |
|
|
89 |
|
return parser |
90 |
|
|
91 |
< |
def get_short_name(dataset): |
91 |
> |
def get_short_name(dataset, dataset_names): |
92 |
|
for key in dataset_names: |
93 |
|
if dataset_names[key] == dataset: |
94 |
< |
return key; |
94 |
> |
return key |
95 |
|
return "Unknown" |
96 |
+ |
|
97 |
+ |
def stop_ctau (dataset): |
98 |
+ |
if not re.match (r"stop[^_]*to[^_]*_[^_]*mm.*", dataset): |
99 |
+ |
return 0.0 |
100 |
+ |
return float (re.sub (r"stop[^_]*to[^_]*_([^_]*)mm.*", r"\1", dataset)) |
101 |
+ |
|
102 |
+ |
def source_stop_ctau (ctau): |
103 |
+ |
return int (math.pow (10.0, math.ceil (math.log10 (ctau)))) |
104 |
+ |
|
105 |
+ |
def add_stops (options, masses, ctaus, bottomBranchingRatios = []): |
106 |
+ |
if not bottomBranchingRatios: |
107 |
+ |
bottomBranchingRatios.append (50.0) |
108 |
+ |
for mass in masses: |
109 |
+ |
for ctau in ctaus: |
110 |
+ |
for bottomBranchingRatio in bottomBranchingRatios: |
111 |
+ |
datasetName = 'stop' + str (mass) + "_" + str (ctau) + "mm_br" + str (int (bottomBranchingRatio)) |
112 |
+ |
bottomDatasetName = 'stop' + str (mass) + "toBl_" + str (ctau) + "mm" |
113 |
+ |
sourceBottomDatasetName = 'stop' + str (mass) + "toBl_" + str (source_stop_ctau (ctau)) + "mm" |
114 |
+ |
topDatasetName = 'stop' + str (mass) + "toTnu_" + str (ctau) + "mm" |
115 |
+ |
sourceTopDatasetName = 'stop' + str (mass) + "toTnu_" + str (source_stop_ctau (ctau)) + "mm" |
116 |
+ |
mixedDatasetName = 'stop' + str (mass) + "toBT_" + str (ctau) + "mm" |
117 |
+ |
sourceMixedDatasetName = 'stop' + str (mass) + "toBT_" + str (source_stop_ctau (ctau)) + "mm" |
118 |
+ |
|
119 |
+ |
options['datasets'].append (datasetName) |
120 |
+ |
bottomBranchingRatio /= 100.0 |
121 |
+ |
options['composite_dataset_definitions'][datasetName] = { |
122 |
+ |
bottomDatasetName : bottomBranchingRatio * bottomBranchingRatio, |
123 |
+ |
topDatasetName : (1 - bottomBranchingRatio) * (1 - bottomBranchingRatio), |
124 |
+ |
mixedDatasetName : (1 - bottomBranchingRatio * bottomBranchingRatio - (1 - bottomBranchingRatio) * (1 - bottomBranchingRatio)) |
125 |
+ |
} |
126 |
+ |
options['dataset_names'][bottomDatasetName] = options['dataset_names'][sourceBottomDatasetName] |
127 |
+ |
options['dataset_names'][topDatasetName] = options['dataset_names'][sourceTopDatasetName] |
128 |
+ |
options['dataset_names'][mixedDatasetName] = options['dataset_names'][sourceMixedDatasetName] |
129 |
+ |
options['nJobs'][bottomDatasetName] = 1 |
130 |
+ |
options['nJobs'][topDatasetName] = 1 |
131 |
+ |
options['nJobs'][mixedDatasetName] = 1 |
132 |
+ |
options['maxEvents'][bottomDatasetName] = -1 |
133 |
+ |
options['maxEvents'][topDatasetName] = -1 |
134 |
+ |
options['maxEvents'][mixedDatasetName] = -1 |
135 |
+ |
options['types'][datasetName] = "signalMC" |
136 |
+ |
options['types'][bottomDatasetName] = "signalMC" |
137 |
+ |
options['types'][topDatasetName] = "signalMC" |
138 |
+ |
options['types'][mixedDatasetName] = "signalMC" |
139 |
+ |
options['labels'][datasetName] = str (mass) + " GeV stop (#LTc#tau#GT = " + str (ctau) + " mm)" |
140 |
+ |
options['labels'][bottomDatasetName] = "#tilde{t}#tilde{t}#rightarrowbbll (#LTc#tau#GT = " + str (ctau) + " mm)" |
141 |
+ |
options['labels'][topDatasetName] = "#tilde{t}#tilde{t}#rightarrowtt#nu#nu (#LTc#tau#GT = " + str (ctau) + " mm)" |
142 |
+ |
options['labels'][mixedDatasetName] = "#tilde{t}#tilde{t}#rightarrowbtl#nu (#LTc#tau#GT = " + str (ctau) + " mm)" |
143 |
+ |
|
144 |
+ |
def add_channels (process, channels): |
145 |
+ |
suffix = "" |
146 |
+ |
if osusub.batchMode: |
147 |
+ |
suffix = "_" + str (osusub.jobNumber) |
148 |
+ |
i = 0 |
149 |
+ |
for channel in channels: |
150 |
+ |
channelName = channel.name.pythonValue () |
151 |
+ |
channelName = channelName[1:-1] |
152 |
+ |
try: |
153 |
+ |
os.mkdir (channelName) |
154 |
+ |
except OSError: |
155 |
+ |
pass |
156 |
+ |
out = cms.OutputModule ("PoolOutputModule", |
157 |
+ |
fileName = cms.untracked.string (channelName + "/bean" + suffix + ".root"), |
158 |
+ |
SelectEvents = cms.untracked.PSet ( |
159 |
+ |
SelectEvents = cms.vstring ("myFilterPath" + str (i)) |
160 |
+ |
), |
161 |
+ |
outputCommands = cms.untracked.vstring ( |
162 |
+ |
"keep *", |
163 |
+ |
), |
164 |
+ |
dropMetaData = cms.untracked.string ("ALL") |
165 |
+ |
) |
166 |
+ |
myFilter = cms.EDFilter ("FilterOnChannelDecision", |
167 |
+ |
src = cms.InputTag ("OSUAnalysis", "channelDecisions"), |
168 |
+ |
channelName = cms.string (channelName) |
169 |
+ |
) |
170 |
+ |
myFilterPath = cms.Path (myFilter) |
171 |
+ |
myEndPath = cms.EndPath (out) |
172 |
+ |
process.__setattr__ ("out" + str (i), out) |
173 |
+ |
process.OSUAnalysis.channels.append (channel) |
174 |
+ |
process.OSUAnalysis.useEDMFormat = cms.bool (True) |
175 |
+ |
process.__setattr__ ("myFilter" + str (i), myFilter) |
176 |
+ |
process.__setattr__ ("myFilterPath" + str (i), myFilterPath) |
177 |
+ |
process.__setattr__ ("myEndPath" + str (i), myEndPath) |
178 |
+ |
i += 1 |