ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/python/processingUtilities.py
Revision: 1.23
Committed: Tue Jun 11 00:35:02 2013 UTC (11 years, 10 months ago) by ahart
Content type: text/x-python
Branch: MAIN
Changes since 1.22: +37 -1 lines
Log Message:
Added the "add_channels" function for use when producing BEAN-format skims.

File Contents

# Content
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 import OSUT3Analysis.DBTools.osusub_cfg as osusub
10 import FWCore.ParameterSet.Config as cms
11
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]:
16 datasets.insert(datasets.index(dataset),component_dataset)
17 datasets.remove(dataset)
18 return datasets
19
20 def get_composite_datasets(datasets, composite_dataset_definitions):
21 composite_datasets = []
22 for dataset in datasets:
23 if dataset in composite_dataset_definitions:
24 composite_datasets.append(dataset)
25 return composite_datasets
26
27 def set_condor_submit_dir(arguments):
28 if arguments.condorDir:
29 condor_dir = "condor/%s" % arguments.condorDir
30 else:
31 now = datetime.datetime.now()
32 date_hash = now.strftime("%Y_%m_%d_%H:%M:%S")
33 condor_dir = "condor/condor_%s" % date_hash
34 #print "Condor submit directory set to ",condor_dir
35 return condor_dir
36
37 def set_condor_output_dir(arguments):
38 if arguments.condorDir:
39 condor_dir = "condor/%s" % arguments.condorDir
40 else: #get most recent condor submission directory
41 dir_list = []
42 for directory in os.listdir("./condor/"):
43 if directory.find("condor_") is not -1:
44 dir_list.append(directory)
45 if len(dir_list) is 0:
46 sys.exit("Cannot find last condor working directory")
47 dir_list.sort(reverse=True)
48 condor_dir = "condor/%s" % dir_list[0]
49 #print "Condor output directory set to ",condor_dir
50 return condor_dir
51
52 def set_commandline_arguments(parser):
53 #### Configuration-related Options
54 parser.add_option("-l", "--localConfig", dest="localConfig",
55 help="local configuration file")
56 parser.add_option("-c", "--condorDir", dest="condorDir",
57 help="condor output directory")
58 parser.add_option("-o", "--output-file", dest="outputFileName",
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
67 parser.add_option("-n", "--normalize", action="store_true", dest="normalizeToData", default=False,
68 help="normalize total background MC yield to the data")
69 parser.add_option("-u", "--unit-area", action="store_true", dest="normalizeToUnitArea", default=False,
70 help="normalize all samples to unit area (useful to compare shapes)")
71 parser.add_option("-e", "--empty", action="store_true", dest="noStack", default=False,
72 help="don't stack the background samples, draw them as empty histograms instead")
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", default=1.15,
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",
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
90 ### Only used by makeBNTreePlot.py (maybe move to another file?)
91 parser.add_option("-D", "--dataset", dest="datasetName",
92 help="Name of dataset (overrides value from local configuration file)")
93 parser.add_option("-C", "--runOnCondor", action="store_true", dest="runOnCondor", default=False,
94 help="Run on condor instead of interactively")
95
96
97 return parser
98
99 def get_short_name(dataset, dataset_names):
100 for key in dataset_names:
101 if dataset_names[key] == dataset:
102 return key
103 return "Unknown"
104
105 def stop_ctau (dataset):
106 if not re.match (r"stop[^_]*to[^_]*_[^_]*mm.*", dataset):
107 return 0.0
108 return float (re.sub (r"stop[^_]*to[^_]*_([^_]*)mm.*", r"\1", dataset))
109
110 def source_stop_ctau (ctau):
111 return int (math.pow (10.0, math.ceil (math.log10 (ctau))))
112
113 def add_stops (options, masses, ctaus, bottomBranchingRatios = []):
114 if not bottomBranchingRatios:
115 bottomBranchingRatios.append (50.0)
116 for mass in masses:
117 for ctau in ctaus:
118 for bottomBranchingRatio in bottomBranchingRatios:
119 datasetName = 'stop' + str (mass) + "_" + str (ctau) + "mm_br" + str (int (bottomBranchingRatio))
120 bottomDatasetName = 'stop' + str (mass) + "toBl_" + str (ctau) + "mm"
121 sourceBottomDatasetName = 'stop' + str (mass) + "toBl_" + str (source_stop_ctau (ctau)) + "mm"
122 topDatasetName = 'stop' + str (mass) + "toTnu_" + str (ctau) + "mm"
123 sourceTopDatasetName = 'stop' + str (mass) + "toTnu_" + str (source_stop_ctau (ctau)) + "mm"
124 mixedDatasetName = 'stop' + str (mass) + "toBT_" + str (ctau) + "mm"
125 sourceMixedDatasetName = 'stop' + str (mass) + "toBT_" + str (source_stop_ctau (ctau)) + "mm"
126
127 options['datasets'].append (datasetName)
128 bottomBranchingRatio /= 100.0
129 options['composite_dataset_definitions'][datasetName] = {
130 bottomDatasetName : bottomBranchingRatio * bottomBranchingRatio,
131 topDatasetName : (1 - bottomBranchingRatio) * (1 - bottomBranchingRatio),
132 mixedDatasetName : (1 - bottomBranchingRatio * bottomBranchingRatio - (1 - bottomBranchingRatio) * (1 - bottomBranchingRatio))
133 }
134 options['dataset_names'][bottomDatasetName] = options['dataset_names'][sourceBottomDatasetName]
135 options['dataset_names'][topDatasetName] = options['dataset_names'][sourceTopDatasetName]
136 options['dataset_names'][mixedDatasetName] = options['dataset_names'][sourceMixedDatasetName]
137 options['nJobs'][bottomDatasetName] = 1
138 options['nJobs'][topDatasetName] = 1
139 options['nJobs'][mixedDatasetName] = 1
140 options['maxEvents'][bottomDatasetName] = -1
141 options['maxEvents'][topDatasetName] = -1
142 options['maxEvents'][mixedDatasetName] = -1
143 options['types'][datasetName] = "signalMC"
144 options['types'][bottomDatasetName] = "signalMC"
145 options['types'][topDatasetName] = "signalMC"
146 options['types'][mixedDatasetName] = "signalMC"
147 options['labels'][datasetName] = str (mass) + " GeV stop (#LTc#tau#GT = " + str (ctau) + " mm)"
148 options['labels'][bottomDatasetName] = "#tilde{t}#tilde{t}#rightarrowbbll (#LTc#tau#GT = " + str (ctau) + " mm)"
149 options['labels'][topDatasetName] = "#tilde{t}#tilde{t}#rightarrowtt#nu#nu (#LTc#tau#GT = " + str (ctau) + " mm)"
150 options['labels'][mixedDatasetName] = "#tilde{t}#tilde{t}#rightarrowbtl#nu (#LTc#tau#GT = " + str (ctau) + " mm)"
151
152 def add_channels (process, channels):
153 suffix = ""
154 if osusub.batchMode:
155 suffix = "_" + str (osusub.jobNumber)
156 i = 0
157 for channel in channels:
158 channelName = channel.name.pythonValue ()
159 channelName = channelName[1:-1]
160 out = cms.OutputModule ("PoolOutputModule",
161 fileName = cms.untracked.string ("bean_" + channelName + suffix + ".root"),
162 SelectEvents = cms.untracked.PSet (
163 SelectEvents = cms.vstring ("myFilterPath" + str (i))
164 ),
165 outputCommands = cms.untracked.vstring (
166 "drop *",
167 "keep *_BNproducer_*_*",
168 "keep double_kt6PFJets*_rho_*",
169 ),
170 dropMetaData = cms.untracked.string ("ALL")
171 )
172 myFilter = cms.EDFilter ("FilterOnChannelDecision",
173 src = cms.InputTag ("OSUAnalysis", "channelDecisions"),
174 channelName = cms.string (channelName)
175 )
176 myFilterPath = cms.Path (myFilter)
177 myEndPath = cms.EndPath (out)
178 process.__setattr__ ("out" + str (i), out)
179 process.OSUAnalysis.channels.append (channel)
180 process.OSUAnalysis.useEDMFormat = cms.bool (True)
181 process.__setattr__ ("myFilter" + str (i), myFilter)
182 process.__setattr__ ("myFilterPath" + str (i), myFilterPath)
183 process.__setattr__ ("myEndPath" + str (i), myEndPath)
184 i += 1