babymaker  ab32dd2660a888820fa79c78d72ab78b0a2e3c93
bmaker_basic_cfg.py
Go to the documentation of this file.
1 ###########################################################
2 ### Configuration file to make basic babies from miniAOD
3 ###########################################################
4 import math, sys
5 from os import environ
6 from os.path import exists, join, basename
7 
8 def findFileInPath(theFile):
9  for s in environ["CMSSW_SEARCH_PATH"].split(":"):
10  attempt = join(s,theFile)
11  if exists(attempt):
12  return attempt
13  print "BABYMAKER: Could not find file "+theFile+". Not pre-applying JSON"
14  return None
15 
16 ###### Input parameters parsing
17 import FWCore.ParameterSet.Config as cms
18 from FWCore.ParameterSet.VarParsing import VarParsing
19 options = VarParsing ('analysis')
20 options.register('nEventsSample',
21  100,
22  VarParsing.multiplicity.singleton,
23  VarParsing.varType.int,
24  "Total number of events in dataset for event weight calculation.")
25 options.register('nEvents',
26  100,
27  VarParsing.multiplicity.singleton,
28  VarParsing.varType.int,
29  "Number of events to run over.")
30 options.register('json',
31  'babymaker/data/json/golden_Cert_246908-258714_13TeV_PromptReco_Collisions15_25ns_JSON.json',
32  VarParsing.multiplicity.singleton,
33  VarParsing.varType.string,
34  "Path to json starting with babymaker/...")
35 options.register('condorSubTime',
36  '000000_000000',
37  VarParsing.multiplicity.singleton,
38  VarParsing.varType.string,
39  "Timestamp from condor submission")
40 options.parseArguments()
41 outName = options.outputFile
42 if outName == "output.root": # output filename not set
43  rootfile = basename(options.inputFiles[0])
44  outName = "baby_"+rootfile
45 
46 doSystematics = True
47 cmsswRel = environ["CMSSW_BASE"]
48 if "RunIISpring15DR74" in outName or "RunIISpring15FSPremix" in outName:
49  if cmsswRel.find("CMSSW_7_4_6") == -1: sys.exit("ERROR: Trying to run miniAOD V1 in a new release. Exiting")
50 
51 ## This refers to the official JEC methods. To apply on-the-fly, just set jecLabel to something different from miniAOD
52 doJEC = False
53 if doJEC: jets_label = "patJetsReapplyJEC"
54 else: jets_label = "slimmedJets"
55 
56 # jecLabel must contain the JEC version; this is needed for uncertainty calculation
57 # if there is no need to apply JECs then the jecLabel must also contain 'miniAOD' (as well as the version)
58 jecLabel = 'miniAOD_Summer15_25nsV6_MC' # for 7.4.14 mc, don't apply JEC, but still give the JEC tag because of systematics
59 if "Run2015D" in outName: jecLabel = 'Summer15_25nsV6_DATA' # for 7.4.12 data
60 elif "RunIISpring15FSPremix" in outName: jecLabel = 'MCRUN2_74_V9'
61 else: jecLabel = 'Summer15_25nsV6_MC'
62 
63 if "FSPremix" in outName or "Fast" in outName: fastsim = True
64 else: fastsim = False
65 
66 if "Run2015" in outName:
67  isData = True
68  # These only used for the official application of JECs
69  globalTag = "74X_dataRun2_v2"
70  processRECO = "RECO"
71  jecLevels = ['L1FastJet', 'L2Relative', 'L3Absolute', 'L2L3Residual']
72 else:
73  isData = False
74  # These only used for the official application of JECs
75  globalTag = "74X_mcRun2_asymptotic_v2"
76  processRECO = "PAT"
77  jecLevels = ['L1FastJet', 'L2Relative', 'L3Absolute']
78 
79 # The 7.4.14 re-miniAOD already has V5 JECs with the new prescription
80 # if cmsswRel.find("CMSSW_7_4_14") != -1: jecLabel = 'miniAOD'
81 
82 ###### Defining Baby process, input and output files
83 process = cms.Process("Baby")
84 process.source = cms.Source("PoolSource",
85  fileNames = cms.untracked.vstring(options.inputFiles)
86 )
87 if isData: # Processing only lumis in JSON
88  import FWCore.PythonUtilities.LumiList as LumiList
89  jsonfile = findFileInPath(options.json)
90  process.source.lumisToProcess = LumiList.LumiList(filename = jsonfile).getVLuminosityBlockRange()
91 
92 process.baby_basic = cms.EDAnalyzer('bmaker_basic',
93  condor_subtime = cms.string(options.condorSubTime),
94  outputFile = cms.string(outName),
95  inputFiles = cms.vstring(options.inputFiles),
96  json = cms.string(options.json),
97  jec = cms.string(jecLabel),
98  met = cms.InputTag("slimmedMETs"),
99  met_nohf = cms.InputTag("slimmedMETsNoHF"),
100  jets = cms.InputTag(jets_label),
101  nEventsSample = cms.uint32(options.nEventsSample),
102  doMetRebalancing = cms.bool(True),
103  doSystematics = cms.bool(doSystematics),
104  addBTagWeights = cms.bool(True),
105  isFastSim = cms.bool(fastsim),
106  debugMode = cms.bool(False)
107 )
108 
109 ###### Setting up number of events, and reporing frequency
110 process.load("FWCore.MessageService.MessageLogger_cfi")
111 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.nEvents) )
112 process.MessageLogger.cerr.FwkReport.reportEvery = 100000
113 
114 ###### Setting global tag
115 ## From https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#JecGlobalTag
116 process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
117 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff")
118 process.GlobalTag.globaltag = globalTag
119 
120 
121 ###### HBHE
122 ## HBHE noise filter needs to be recomputed in early 2015 data
123 ##___________________________HCAL_Noise_Filter________________________________||
124 #if "FSPremix" in outName: fastsim = True #(moved earlier)
125 #else: fastsim = False
126 if not fastsim:
127  process.load('CommonTools.RecoAlgos.HBHENoiseFilterResultProducer_cfi')
128  process.HBHENoiseFilterResultProducer.minZeros = cms.int32(99999)
129  process.HBHENoiseFilterResultProducer.IgnoreTS4TS5ifJetInLowBVRegion=cms.bool(False)
130  process.HBHENoiseFilterResultProducer.defaultDecision = cms.string("HBHENoiseFilterResultRun2Loose")
131 
132 if doJEC:
133  ###### Setting sqlite file for the JECs that are in newer global tags
134  ## From https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#JecSqliteFile
135  process.load("CondCore.DBCommon.CondDBCommon_cfi")
136  from CondCore.DBCommon.CondDBSetup_cfi import CondDBSetup
137  process.jec = cms.ESSource("PoolDBESSource",CondDBSetup,
138  connect = cms.string('sqlite_file:data/jec/'+jecLabel+'.db'),
139  toGet = cms.VPSet(
140  cms.PSet(
141  record = cms.string("JetCorrectionsRecord"),
142  tag = cms.string("JetCorrectorParametersCollection_"+jecLabel+"_AK4PFchs"),
143  label = cms.untracked.string("AK4PFchs")
144  ),
145  cms.PSet(
146  record = cms.string("JetCorrectionsRecord"),
147  tag = cms.string("JetCorrectorParametersCollection_"+jecLabel+"_AK4PF"),
148  label = cms.untracked.string("AK4PF")
149  )
150  )
151  )
152  process.es_prefer_jec = cms.ESPrefer("PoolDBESSource","jec")
153  ###### Jets
154  ## From https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#CorrPatJets
155  from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import patJetCorrFactorsUpdated
156  process.patJetCorrFactorsReapplyJEC = patJetCorrFactorsUpdated.clone(
157  src = cms.InputTag("slimmedJets"),
158  levels = jecLevels,
159  payload = 'AK4PFchs' ) # Make sure to choose the appropriate levels and payload here!
160 
161  from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import patJetsUpdated
162  process.patJetsReapplyJEC = patJetsUpdated.clone(
163  jetSource = cms.InputTag("slimmedJets"),
164  jetCorrFactorsSource = cms.VInputTag(cms.InputTag("patJetCorrFactorsReapplyJEC"))
165  )
166 
167  ###### Apply new JECs to MET
168  ## From https://github.com/cms-met/cmssw/blob/METCorUnc74X/PhysicsTools/PatAlgos/test/corMETFromMiniAOD.py
169  process.options = cms.untracked.PSet(
170  allowUnscheduled = cms.untracked.bool(True),
171  wantSummary = cms.untracked.bool(False)
172  )
173  from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
174  runMetCorAndUncFromMiniAOD(process,
175  isData=isData,
176  pfCandColl=cms.InputTag("packedPFCandidates")
177  )
178  if isData:
179  process.patPFMetT1T2Corr.jetCorrLabelRes = cms.InputTag("L3Absolute")
180  process.patPFMetT1T2SmearCorr.jetCorrLabelRes = cms.InputTag("L3Absolute")
181  process.patPFMetT2Corr.jetCorrLabelRes = cms.InputTag("L3Absolute")
182  process.patPFMetT2SmearCorr.jetCorrLabelRes = cms.InputTag("L3Absolute")
183  process.shiftedPatJetEnDown.jetCorrLabelUpToL3Res = cms.InputTag("ak4PFCHSL1FastL2L3Corrector")
184  process.shiftedPatJetEnUp.jetCorrLabelUpToL3Res = cms.InputTag("ak4PFCHSL1FastL2L3Corrector")
185  # Redefine process for data to RECO
186  process.slimmedMETs.t01Variation = cms.InputTag("slimmedMETs","",processRECO)
187 
188  ###### Path
189  process.p = cms.Path(process.patJetCorrFactorsReapplyJEC*
190  process.patJetsReapplyJEC*
191  process.HBHENoiseFilterResultProducer* #produces HBHE baseline bools
192  process.baby_basic)
193 else:
194  ###### Path
195  if not fastsim:
196  process.p = cms.Path(process.HBHENoiseFilterResultProducer* #produces HBHE baseline bools
197  process.baby_basic)
198  else:
199  process.p = cms.Path(process.baby_basic)
def findFileInPath(theFile)