def createCfg_comp_jetToTauFakeRate(self, jobOptions): """Create python configuration file for the comp_jetToTauFakeRate executable Args: inputFiles: input file (the ROOT file produced by hadd_stage1) outputFile: output file of the job """ for charge_selection in self.charge_selections: lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['outputFile'])) lines.append("process.comp_jetToTauFakeRate.looseRegion = cms.string('%s')" % jobOptions['looseRegion']) lines.append("process.comp_jetToTauFakeRate.tightRegion = cms.string('%s')" % jobOptions['tightRegion']) lines.append("process.comp_jetToTauFakeRate.processData = cms.string('data_obs')") lines.append("process.comp_jetToTauFakeRate.processesToSubtract = cms.vstring(") lines.append(" 'TTt', 'TTl',") lines.append(" 'EWKt', 'EWKl',") lines.append(" 'Rarest', 'Raresl',") lines.append(" 'TTWt', 'TTWl', ") lines.append(" 'TTWWt', 'TTWWl', ") lines.append(" 'TTZt', 'TTZl', ") lines.append(" 'signalt', 'signall'") lines.append(")") lines.append("process.comp_jetToTauFakeRate.processMC = cms.string('TTj')") lines.append("process.comp_jetToTauFakeRate.absEtaBins = cms.vdouble(%s)" % jobOptions['absEtaBins']) lines.append("process.comp_jetToTauFakeRate.ptBins = cms.vdouble(%s)" % jobOptions['ptBins']) lines.append("process.comp_jetToTauFakeRate.outputFileName = cms.string('%s')" % jobOptions['plots_outputFileName']) create_cfg(self.cfgFile_comp_jetToTauFakeRate, jobOptions['cfgFile_modified'], lines)
def createCfg_prep_dcard(self, jobOptions): """Fills the template of python configuration file for datacard preparation Args: histogramToFit: name of the histogram used for signal extraction """ category_output = self.channel if jobOptions['label']: category_output += "_%s" % jobOptions['label'] lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % jobOptions['datacardFile']) lines.append("process.prepareDatacards.processesToCopy = cms.vstring(%s)" % self.prep_dcard_processesToCopy) lines.append("process.prepareDatacards.signals = cms.vstring(%s)" % self.prep_dcard_signals) lines.append("process.prepareDatacards.makeSubDir = cms.bool(True)") lines.append("process.prepareDatacards.categories = cms.VPSet(") for charge in ["OS", "SS"]: for ptEtaBin in [ "BB_LL", "BB_ML", "BB_MM", "BB_HL", "BB_HM", "BB_HH", "EE_LL", "EE_ML", "EE_MM", "EE_HL", "EE_HM", "EE_HH", "BE_LL", "BE_ML", "EB_ML","BE_MM", "BE_HL", "EB_HL", "BE_HM", "EB_HM", "BE_HH", "total", ]: lines.append(" cms.PSet(") lines.append(" input = cms.string('%s/%s')," % (charge, ptEtaBin)) lines.append(" output = cms.string('ttH_%s_%s_%s')" % (self.channel, charge, ptEtaBin)) lines.append(" ),") lines.append(")") lines.append("process.prepareDatacards.histogramToFit = cms.string('%s')" % jobOptions['histogramToFit']) lines.append("process.prepareDatacards.sysShifts = cms.vstring(%s)" % systematics.muon_E) create_cfg(self.cfgFile_prep_dcard, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions, sample_info): """Create python configuration file for the analyze_jetToTauFakeRate executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TT`, `TTW`, `TTWW`, `TTZ`, `EWK`, `Rares`, `data_obs`, `ttH_hww`, `ttH_hzz` or `ttH_htt` is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/tthAnalysis/HiggsToTauTau/bin/analyze_jetToTauFakeRate.cc """ additionalJobOptions = [ 'chargeSelection', 'jet_minPt', 'jet_maxPt', 'jet_minAbsEta', 'jet_maxAbsEta', 'hadTauSelection_denominator', 'hadTauSelections_numerator', 'absEtaBins', ] lines = super(analyzeConfig_jetToTauFakeRate, self).createCfg_analyze(jobOptions, sample_info, additionalJobOptions) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions, sample_info, lepton_selection): """Create python configuration file for the analyze_ttWctrl executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TT`, `TTW`, `TTZ`, `EWK`, `Rares`, `data_obs`, `ttH_hww`, 'ttH_hzg', 'ttH_hmm', `ttH_hzz` or `ttH_htt` is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/tthAnalysis/HiggsToTauTau/bin/analyze_ttWctrl.cc """ lepton_frWeight = "disabled" if jobOptions['applyFakeRateWeights'] == "disabled" else "enabled" jobOptions['histogramDir'] = getHistogramDir( lepton_selection, lepton_frWeight, jobOptions['leptonChargeSelection'] ) if 'mcClosure' in lepton_selection: self.mcClosure_dir['%s_%s' % (lepton_selection, jobOptions['leptonChargeSelection'])] = jobOptions['histogramDir'] self.set_leptonFakeRateWeightHistogramNames(jobOptions['central_or_shift'], lepton_selection) jobOptions['leptonFakeRateWeight.inputFileName'] = self.leptonFakeRateWeight_inputFile jobOptions['leptonFakeRateWeight.histogramName_e'] = self.leptonFakeRateWeight_histogramName_e jobOptions['leptonFakeRateWeight.histogramName_mu'] = self.leptonFakeRateWeight_histogramName_mu lines = super(analyzeConfig_ttWctrl, self).createCfg_analyze(jobOptions, sample_info) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions): """Create python configuration file for the analyze_charge_flip executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/tthAnalysis/HiggsToTauTau/bin/analyze_charge_flip.cc """ lines = [] ##lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % [ os.path.basename(inputFile) for inputFile in inputFiles ]) lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % jobOptions["ntupleFiles"]) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions["histogramFile"])) lines.append("process.analyze_charge_flip.process = cms.string('%s')" % jobOptions["sample_category"]) lines.append("process.analyze_charge_flip.era = cms.string('%s')" % self.era) lines.append("process.analyze_charge_flip.triggers_1e = cms.vstring(%s)" % self.triggers_1e) lines.append("process.analyze_charge_flip.use_triggers_1e = cms.bool(%s)" % ("1e" in jobOptions["triggers"])) lines.append("process.analyze_charge_flip.triggers_2e = cms.vstring(%s)" % self.triggers_2e) lines.append("process.analyze_charge_flip.use_triggers_2e = cms.bool(%s)" % ("2e" in jobOptions["triggers"])) lines.append("process.analyze_charge_flip.triggers_1mu = cms.vstring(%s)" % self.triggers_1mu) lines.append("process.analyze_charge_flip.use_triggers_1mu = cms.bool(%s)" % ("1mu" in jobOptions["triggers"])) lines.append("process.analyze_charge_flip.triggers_2mu = cms.vstring(%s)" % self.triggers_2mu) lines.append("process.analyze_charge_flip.use_triggers_2mu = cms.bool(%s)" % ("2mu" in jobOptions["triggers"])) lines.append("process.analyze_charge_flip.leptonSelection = cms.string('%s')" % jobOptions["lepton_selection"]) lines.append("process.analyze_charge_flip.isMC = cms.bool(%s)" % jobOptions["is_mc"]) lines.append("process.analyze_charge_flip.central_or_shift = cms.string('%s')" % jobOptions["central_or_shift"]) lines.append("process.analyze_charge_flip.lumiScale = cms.double(%f)" % jobOptions["lumi_scale"]) lines.append("process.analyze_charge_flip.apply_trigger_bits = cms.bool(%s)" % jobOptions["apply_trigger_bits"]) lines.append("process.analyze_charge_flip.selEventsFileName_output = cms.string('%s')" % jobOptions["rleOutputFile"]) lines.append("process.analyze_charge_flip.use_HIP_mitigation_mediumMuonId = cms.bool(%s)" % jobOptions["use_HIP_mitigation_mediumMuonId"]) lines.append("process.analyze_charge_flip.applyFakeRateWeights = cms.string('%s')" % jobOptions["applyFakeRateWeights"]) create_cfg(self.cfgFile_analyze_original, jobOptions["cfgFile_modified"], lines)
def createCfg_prep_dcard_LeptonFakeRate(self, jobOptions): """ Fills the template of python configuration file for datacard preparation Args: histogramToFit: name of the histogram used for signal extraction """ category_output = self.channel if jobOptions['label']: category_output += "_%s" % jobOptions['label'] lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % jobOptions['datacardFile']) lines.append("process.prepareDatacards.histogramToFit = cms.string('%s')" % jobOptions['histogramToFit']) #if self.use_QCD_fromMC : # lines.append("process.prepareDatacards.processesToCopy = cms.vstring('data_obs', 'TTl', 'Raresl', 'EWKl', 'QCD')") #else: # lines.append("process.prepareDatacards.processesToCopy = cms.vstring('data_obs', 'TTl', 'Raresl', 'EWKl', 'data_fakes')") if jobOptions['histogramToFit'] in [ "mT_fix_L", "mT_fix_L_num", "mT_fix_L_den"]: lines.append("process.prepareDatacards.histogramToFit_xMin = cms.double(0.)") lines.append("process.prepareDatacards.histogramToFit_xMax = cms.double(150.)") lines.append("process.prepareDatacards.minEvents_automatic_rebinning = cms.double(10.)") category_entries = jinja2.Template(category_template).render(categories = jobOptions['categories']) lines.append( "process.prepareDatacards.categories = cms.VPSet(%s\n)" % category_entries ) lines.append( "process.prepareDatacards.sysShifts = cms.vstring(\n %s,\n)" % \ ',\n '.join(map(lambda central_or_shift: "'%s'" % central_or_shift, self.central_or_shifts)) ) create_cfg(self.cfgFile_prep_dcard, jobOptions['cfgFile_modified'], lines)
def createCfg_addMEM(self, inputFiles, startRange, endRange, outputFile, era, isMC, cfgFile_modified): """Create python configuration file for the addMEM_2lss_1tau executable (MEM code) Args: inputFile: list of input files (Ntuples) outputFile: output file of the job """ '''Let's assume that the following configuration options remain constant at all times and need not be modified - process.fwliteInput.outputEvery - process.addMEM_2lss_1tau.branchName_electrons - process.addMEM_2lss_1tau.branchName_muons - process.addMEM_2lss_1tau.branchName_hadTaus - process.addMEM_2lss_1tau.branchName_jets - process.addMEM_2lss_1tau.branchName_met ''' lines = [] skipEvents = startRange maxEvents = endRange - startRange lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % inputFiles) lines.append("process.fwliteInput.skipEvents = cms.uint32(%s)" % skipEvents) lines.append("process.fwliteInput.maxEvents = cms.int32(%s)" % maxEvents) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(outputFile)) lines.append("process.addMEM_2lss_1tau.era = cms.string('%s')" % era) if skipEvents > 0: lines.append("process.addMEM_2lss_1tau.copy_histograms = cms.vstring()") lines.append("process.addMEM_2lss_1tau.leptonSelection = cms.string('%s')" % self.leptonSelection) lines.append("process.addMEM_2lss_1tau.hadTauSelection = cms.string('%s')" % self.hadTauSelection) lines.append("process.addMEM_2lss_1tau.isMC = cms.bool(%s)" % isMC) lines.append("process.addMEM_2lss_1tau.isForBDTtraining = cms.bool(%s)" % self.isForBDTtraining) lines.append("process.addMEM_2lss_1tau.isDEBUG = cms.bool(%s)" % self.isDebug) lines.append("process.addMEM_2lss_1tau.central_or_shift = cms.vstring(%s)" % self.central_or_shift) create_cfg(self.cfgFile_addMEM_original, cfgFile_modified, lines)
def createCfg_analyze(self, jobOptions): """Create python configuration file for the analyze_SVfit4tau executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: hh->4tau signal MC sample is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/hhAnalysis/multilepton/bin/analyze_SVfit4tau.cc """ lines = [] ##lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % [ os.path.basename(inputFile) for inputFile in jobOptions['ntupleFiles'] ]) lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % jobOptions['ntupleFiles']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['histogramFile'])) lines.append("process.analyze_SVfit4tau.process = cms.string('%s')" % jobOptions['sample_category']) lines.append("process.analyze_SVfit4tau.era = cms.string('%s')" % self.era) lines.append("process.analyze_SVfit4tau.mode = cms.string('%s')" % jobOptions['mode']) lines.append("process.analyze_SVfit4tau.leptonSelection = cms.string('%s')" % jobOptions['lepton_selection']) lines.append("process.analyze_SVfit4tau.hadTauSelection = cms.string('%s')" % jobOptions['hadTau_selection']) lines.append("process.analyze_SVfit4tau.SVfit4tau.logM_wMassConstraint_MarkovChain = cms.vdouble(%s)" % jobOptions['SVfit4tau_logM_wMassConstraint_MarkovChain']) lines.append("process.analyze_SVfit4tau.SVfit4tau.logM_woMassConstraint_MarkovChain = cms.vdouble(%s)" % jobOptions['SVfit4tau_logM_woMassConstraint_MarkovChain']) lines.append("process.analyze_SVfit4tau.SVfit4tau.logM_wMassConstraint_VAMP = cms.vdouble(%s)" % jobOptions['SVfit4tau_logM_wMassConstraint_VAMP']) lines.append("process.analyze_SVfit4tau.use_HIP_mitigation_mediumMuonId = cms.bool(%s)" % jobOptions['use_HIP_mitigation_mediumMuonId']) lines.append("process.analyze_SVfit4tau.isMC = cms.bool(%s)" % jobOptions['is_mc']) lines.append("process.analyze_SVfit4tau.central_or_shift = cms.string('%s')" % jobOptions['central_or_shift']) lines.append("process.analyze_SVfit4tau.lumiScale = cms.double(%f)" % jobOptions['lumi_scale']) lines.append("process.analyze_SVfit4tau.apply_genWeight = cms.bool(%s)" % jobOptions['apply_genWeight']) lines.append("process.analyze_SVfit4tau.fillGenEvtHistograms = cms.bool(True)") lines.append("process.analyze_SVfit4tau.isDEBUG = cms.bool(%s)" % self.isDebug) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_preselNtuple(self, inputFiles, outputFile, era, isMC, cfgFile_modified, rle_filename=''): """Create python configuration file for the preselNtuple_3l_1tau executable (Ntuple production code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % inputFiles) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(outputFile)) lines.append("process.preselNtuple_3l_1tau.era = cms.string('%s')" % era) if rle_filename: lines.append( "process.preselNtuple_3l_1tau.selEventsFileName_addMEM = cms.string('%s')" % rle_filename) lines.append("process.preselNtuple_3l_1tau.isMC = cms.bool(%s)" % isMC) create_cfg(self.cfgFile_preselNtuple_original, cfgFile_modified, lines)
def createCfg_analyze(self, inputFiles, outputFile, sample_category, era, triggers, lepton_selection, is_mc, central_or_shift, lumi_scale, apply_trigger_bits, cfgFile_modified, rle_output_file): """Create python configuration file for the analyze_charge_flip executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/tthAnalysis/HiggsToTauTau/bin/analyze_charge_flip.cc """ lines = [] ##lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % [ os.path.basename(inputFile) for inputFile in inputFiles ]) lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % inputFiles) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(outputFile)) lines.append("process.analyze_charge_flip.process = cms.string('%s')" % sample_category) lines.append("process.analyze_charge_flip.era = cms.string('%s')" % era) lines.append("process.analyze_charge_flip.triggers_1e = cms.vstring(%s)" % self.triggers_1e) lines.append("process.analyze_charge_flip.use_triggers_1e = cms.bool(%s)" % ("1e" in triggers)) lines.append("process.analyze_charge_flip.triggers_2e = cms.vstring(%s)" % self.triggers_2e) lines.append("process.analyze_charge_flip.use_triggers_2e = cms.bool(%s)" % ("2e" in triggers)) lines.append("process.analyze_charge_flip.leptonSelection = cms.string('%s')" % lepton_selection) lines.append("process.analyze_charge_flip.isMC = cms.bool(%s)" % is_mc) lines.append("process.analyze_charge_flip.central_or_shift = cms.string('%s')" % central_or_shift) lines.append("process.analyze_charge_flip.lumiScale = cms.double(%f)" % lumi_scale) lines.append("process.analyze_charge_flip.apply_trigger_bits = cms.bool(%s)" % apply_trigger_bits) lines.append("process.analyze_charge_flip.selEventsFileName_output = cms.string('%s')" % rle_output_file) create_cfg(self.cfgFile_analyze_original, cfgFile_modified, lines)
def createCfg_comp_jetToTauFakeRate(self, inputFile, outputFile, looseRegion, tightRegion, absEtaBins, ptBins, cfgFile_modified): """Create python configuration file for the comp_jetToTauFakeRate executable Args: inputFiles: input file (the ROOT file produced by hadd_stage1) outputFile: output file of the job """ for charge_selection in self.charge_selections: lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % inputFile) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % outputFile) lines.append("process.comp_jetToTauFakeRate.looseRegion = cms.string('%s')" % looseRegion) lines.append("process.comp_jetToTauFakeRate.tightRegion = cms.string('%s')" % tightRegion) lines.append("process.comp_jetToTauFakeRate.processData = cms.string('data_obs')") lines.append("process.comp_jetToTauFakeRate.processesToSubtract = cms.vstring(") lines.append(" 'TTt', 'TTl',") lines.append(" 'EWKt', 'EWKl',") lines.append(" 'Rarest', 'Raresl',") lines.append(" 'TTWt', 'TTWl', ") lines.append(" 'TTZt', 'TTZl', ") lines.append(" 'signalt', 'signall'") lines.append(")") lines.append("process.comp_jetToTauFakeRate.processMC = cms.string('TTj')") lines.append("process.comp_jetToTauFakeRate.absEtaBins = cms.vdouble(%s)" % absEtaBins) lines.append("process.comp_jetToTauFakeRate.ptBins = cms.vdouble(%s)" % ptBins) create_cfg(self.cfgFile_comp_jetToTauFakeRate_original, cfgFile_modified, lines)
def createCfg_prep_dcard_LeptonFakeRate(self, jobOptions): """ Fills the template of python configuration file for datacard preparation Args: histogramToFit: name of the histogram used for signal extraction """ category_output = self.channel if jobOptions['label']: category_output += "_%s" % jobOptions['label'] lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % jobOptions['datacardFile']) ## DEF LINE # lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['datacardFile'])) ## lines.append("process.prepareDatacards.processesToCopy = cms.vstring(%s)" % self.prep_dcard_processesToCopy) ## lines.append("process.prepareDatacards.signals = cms.vstring(%s)" % self.prep_dcard_signals) # lines.append("process.prepareDatacards.makeSubDir = cms.bool(False)") # lines.append("process.prepareDatacards.categories = cms.VPSet(") # lines.append(" cms.PSet(") # lines.append(" input = cms.string('%s/sel/evt')," % jobOptions['histogramDir']) # lines.append(" output = cms.string('ttH_%s')" % category_output) # lines.append(" )") # lines.append(")") # lines.append("process.prepareDatacards.histogramToFit = cms.string('%s')" % jobOptions['histogramToFit']) create_cfg(self.cfgFile_prep_dcard, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions, sample_info, lepton_selection): """Create python configuration file for the analyze_hh_bb2l executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TT`, `TTW`, `TTZ`, `EWK`, `Rares`, `data_obs`, or `signal` is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/hhAnalysis/multilepton/bin/analyze_hh_bb2l.cc """ lepton_frWeight = "disabled" if jobOptions['applyFakeRateWeights'] == "disabled" else "enabled" jobOptions['histogramDir'] = getHistogramDir(self.evtCategory_inclusive, lepton_selection, lepton_frWeight, jobOptions['leptonChargeSelection']) if 'mcClosure' in lepton_selection: self.mcClosure_dir[lepton_selection] = jobOptions['histogramDir'] self.set_leptonFakeRateWeightHistogramNames(jobOptions['central_or_shift'], lepton_selection) jobOptions['leptonFakeRateWeight.inputFileName'] = self.leptonFakeRateWeight_inputFile jobOptions['leptonFakeRateWeight.histogramName_e'] = self.leptonFakeRateWeight_histogramName_e jobOptions['leptonFakeRateWeight.histogramName_mu'] = self.leptonFakeRateWeight_histogramName_mu if is_nonresonant(sample_info["sample_category"]) or self.do_sync: jobOptions['hhWeight_cfg.denominator_file'] = 'hhAnalysis/bbww/data/denom_{}{}.root'.format(self.era, '_sync' if self.do_sync else '') jobOptions['hhWeight_cfg.histtitle'] = sample_info["sample_category"] lines = super(analyzeConfig_hh_bb2l, self).createCfg_analyze(jobOptions, sample_info) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions, sample_info): additionalJobOptions = [ 'hadTauSelection_tauIdWP', ] lines = super(analyzeConfig_inclusive, self).createCfg_analyze(jobOptions, sample_info, additionalJobOptions) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_addMEM(self, inputFiles, startRange, endRange, outputFile, era, cfgFile_modified): """Create python configuration file for the addMEM_2lss_1tau executable (MEM code) Args: inputFile: list of input files (Ntuples) outputFile: output file of the job """ '''Let's assume that the following configuration options remain constant at all times and need not be modified - process.fwliteInput.outputEvery - process.addMEM_2lss_1tau.branchName_electrons - process.addMEM_2lss_1tau.branchName_muons - process.addMEM_2lss_1tau.branchName_hadTaus - process.addMEM_2lss_1tau.branchName_jets - process.addMEM_2lss_1tau.branchName_met - process.addMEM_2lss_1tau.leptonSelection - process.addMEM_2lss_1tau.hadTauSelection - process.addMEM_2lss_1tau.use_HIP_mitigation_bTag ''' lines = [] skipEvents = startRange maxEvents = endRange - startRange lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % inputFiles) lines.append("process.fwliteInput.skipEvents = cms.uint32(%s)" % skipEvents) lines.append("process.fwliteInput.maxEvents = cms.int32(%s)" % maxEvents) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(outputFile)) lines.append("process.addMEM_2lss_1tau.era = cms.string('%s')" % era) if skipEvents > 0: lines.append("process.addMEM_2lss_1tau.copy_histograms = cms.vstring()") create_cfg(self.cfgFile_addMEM_original, cfgFile_modified, lines)
def createCfg_analyze(self, jobOptions, sample_info, lepton_and_hadTau_selection): """Create python configuration file for the analyze_hh_bb1l1tau executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TT`, `TTW`, `TTZ`, `EWK`, `Rares`, `data_obs`, or `signal` is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/hhAnalysis/multilepton/bin/analyze_hh_bb1l1tau.cc """ lepton_and_hadTau_frWeight = "disabled" if jobOptions['applyFakeRateWeights'] == "disabled" else "enabled" jobOptions['histogramDir'] = getHistogramDir( self.evtCategory_inclusive, lepton_and_hadTau_selection, lepton_and_hadTau_frWeight, jobOptions['chargeSumSelection'] ) if 'mcClosure' in lepton_and_hadTau_selection: self.mcClosure_dir['%s_%s' % (lepton_and_hadTau_selection, jobOptions['chargeSumSelection'])] = jobOptions['histogramDir'] self.set_leptonFakeRateWeightHistogramNames(jobOptions['central_or_shift'], lepton_and_hadTau_selection) jobOptions['leptonFakeRateWeight.inputFileName'] = self.leptonFakeRateWeight_inputFile jobOptions['leptonFakeRateWeight.histogramName_e'] = self.leptonFakeRateWeight_histogramName_e jobOptions['leptonFakeRateWeight.histogramName_mu'] = self.leptonFakeRateWeight_histogramName_mu jobOptions['hadTauFakeRateWeight.inputFileName'] = self.hadTauFakeRateWeight_inputFile graphName = 'jetToTauFakeRate/%s/$etaBin/jetToTauFakeRate_mc_hadTaus_pt' % self.hadTau_mva_wp jobOptions['hadTauFakeRateWeight.lead.graphName'] = graphName fitFunctionName = 'jetToTauFakeRate/%s/$etaBin/fitFunction_data_div_mc_hadTaus_pt' % self.hadTau_mva_wp jobOptions['hadTauFakeRateWeight.lead.fitFunctionName'] = fitFunctionName if "mcClosure" in lepton_and_hadTau_selection: jobOptions['hadTauFakeRateWeight.applyGraph_lead'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_lead'] = False lines = super(analyzeConfig_hh_bb1l1tau, self).createCfg_analyze(jobOptions, sample_info) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions): """Create python configuration file for the analyze_LeptonFakeRate executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TT`, `TTW`, `TTZ`, `EWK`, `Rares`, `data_obs`, `ttH_hww`, `ttH_hzz` or `ttH_htt` is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/tthAnalysis/HiggsToTauTau/bin/analyze_LeptonFakeRate.cc """ lines = [] ##lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % [ os.path.basename(inputFile) for inputFile in inputFiles ]) lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % jobOptions['ntupleFiles']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['histogramFile'])) lines.append( "process.analyze_LeptonFakeRate.process = cms.string('%s')" % jobOptions['sample_category']) lines.append("process.analyze_LeptonFakeRate.era = cms.string('%s')" % self.era) lines.append( "process.analyze_LeptonFakeRate.use_triggers_1e = cms.bool(%s)" % ("1e" in jobOptions['triggers'])) lines.append( "process.analyze_LeptonFakeRate.use_triggers_1mu = cms.bool(%s)" % ("1mu" in jobOptions['triggers'])) lines.append( "process.analyze_LeptonFakeRate.absEtaBins_e = cms.vdouble(%s)" % self.absEtaBins_e) lines.append( "process.analyze_LeptonFakeRate.absEtaBins_mu = cms.vdouble(%s)" % self.absEtaBins_mu) lines.append( "process.analyze_LeptonFakeRate.absPtBins_e = cms.vdouble(%s)" % self.absPtBins_e) lines.append( "process.analyze_LeptonFakeRate.absPtBins_mu = cms.vdouble(%s)" % self.absPtBins_mu) lines.append( "process.analyze_LeptonFakeRate.use_HIP_mitigation_mediumMuonId = cms.bool(%s)" % jobOptions['use_HIP_mitigation_mediumMuonId']) lines.append("process.analyze_LeptonFakeRate.isMC = cms.bool(%s)" % jobOptions['is_mc']) lines.append( "process.analyze_LeptonFakeRate.central_or_shift = cms.string('%s')" % jobOptions['central_or_shift']) lines.append( "process.analyze_LeptonFakeRate.lumiScale = cms.double(%f)" % jobOptions['lumi_scale']) # lines.append("process.analyze_LeptonFakeRate.apply_trigger_bits = cms.bool(%s)" % jobOptions['apply_trigger_bits']) ## REMOVED lines.append( "process.analyze_LeptonFakeRate.apply_genWeight = cms.bool(%s)" % jobOptions['apply_genWeight']) lines.append( "process.analyze_LeptonFakeRate.fillGenEvtHistograms = cms.bool(%s)" % self.fillGenEvtHistograms) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions, sample_info, hadTau_selection): """Create python configuration file for the analyze_hh_0l_4tau executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TT`, `TTW`, `TTZ`, `EWK`, `Rares`, `data_obs`, or `signal` is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/hhAnalysis/multilepton/bin/analyze_hh_0l_4tau.cc """ hadTau_frWeight = "disabled" if jobOptions['applyFakeRateWeights'] == "disabled" else "enabled" jobOptions['histogramDir'] = getHistogramDir( hadTau_selection, hadTau_frWeight, jobOptions['hadTauChargeSelection'] ) if 'mcClosure' in hadTau_selection: self.mcClosure_dir['%s_%s' % (hadTau_selection, jobOptions['hadTauChargeSelection'])] = jobOptions['histogramDir'] jobOptions['hadTauFakeRateWeight.inputFileName'] = self.hadTauFakeRateWeight_inputFile graphName = 'jetToTauFakeRate/%s/$etaBin/jetToTauFakeRate_mc_hadTaus_pt' % self.hadTau_selection_part2 jobOptions['hadTauFakeRateWeight.lead.graphName'] = graphName jobOptions['hadTauFakeRateWeight.sublead.graphName'] = graphName jobOptions['hadTauFakeRateWeight.third.graphName'] = graphName jobOptions['hadTauFakeRateWeight.fourth.graphName'] = graphName fitFunctionName = 'jetToTauFakeRate/%s/$etaBin/fitFunction_data_div_mc_hadTaus_pt' % self.hadTau_selection_part2 jobOptions['hadTauFakeRateWeight.lead.fitFunctionName'] = fitFunctionName jobOptions['hadTauFakeRateWeight.sublead.fitFunctionName'] = fitFunctionName jobOptions['hadTauFakeRateWeight.third.fitFunctionName'] = fitFunctionName jobOptions['hadTauFakeRateWeight.fourth.fitFunctionName'] = fitFunctionName if "mcClosure" in hadTau_selection: jobOptions['hadTauFakeRateWeight.applyGraph_lead'] = True jobOptions['hadTauFakeRateWeight.applyGraph_sublead'] = True jobOptions['hadTauFakeRateWeight.applyGraph_third'] = True jobOptions['hadTauFakeRateWeight.applyGraph_fourth'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_lead'] = False jobOptions['hadTauFakeRateWeight.applyFitFunction_sublead'] = False jobOptions['hadTauFakeRateWeight.applyFitFunction_third'] = False jobOptions['hadTauFakeRateWeight.applyFitFunction_fourth'] = False if self.applyFakeRateWeights not in [ "4tau" ] and not self.isBDTtraining: # We want to preserve the same logic as running in SR and applying the FF method only to leptons [*] jobOptions['hadTauFakeRateWeight.applyFitFunction_lead'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_sublead'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_third'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_fourth'] = True if jobOptions['hadTauSelection'].find("Tight") != -1 and self.applyFakeRateWeights not in [ "4tau" ] and not self.isBDTtraining: # [*] SR and applying the FF method only to leptons jobOptions['hadTauFakeRateWeight.applyGraph_lead'] = False # FR in MC for the leading tau jobOptions['hadTauFakeRateWeight.applyGraph_sublead'] = False jobOptions['hadTauFakeRateWeight.applyGraph_third'] = False jobOptions['hadTauFakeRateWeight.applyGraph_fourth'] = False jobOptions['hadTauFakeRateWeight.applyFitFunction_lead'] = True # data-to-MC SF for the leading tau jobOptions['hadTauFakeRateWeight.applyFitFunction_sublead'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_third'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_fourth'] = True jobOptions['apply_hadTauFakeRateSF'] = True lines = super(analyzeConfig_hh_0l_4tau, self).createCfg_analyze(jobOptions, sample_info) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions, sample_info): """Create python configuration file for the analyze_hadTopTagger executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram """ lines = super(analyzeConfig_hadTopTagger, self).createCfg_analyze(jobOptions, sample_info, [], False, True) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_comp_jetToTauFakeRate(self, jobOptions): """Create python configuration file for the comp_jetToTauFakeRate executable Args: inputFiles: input file (the ROOT file produced by hadd_stage1) outputFile: output file of the job """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['outputFile'])) lines.append( "process.comp_jetToTauFakeRate.looseRegion = cms.string('%s')" % jobOptions['looseRegion']) lines.append( "process.comp_jetToTauFakeRate.tightRegion = cms.string('%s')" % jobOptions['tightRegion']) lines.append( "process.comp_jetToTauFakeRate.processData = cms.string('data_obs')" ) lines.append( "process.comp_jetToTauFakeRate.processesToSubtract = cms.vstring(") for process in self.processes_to_comp: lines.append( " '{process}t', '{process}l',".format(process=process)) lines.append(")") if self.event_selection == "TTemu": lines.append( "process.comp_jetToTauFakeRate.processMC = cms.string('TTj')") elif self.event_selection == "DYmumu": lines.append( "process.comp_jetToTauFakeRate.processMC = cms.string('EWKj')") else: raise ValueError("Invalid event selection: %s" % self.event_selection) lines.append( "process.comp_jetToTauFakeRate.absEtaBins = cms.vdouble(%s)" % jobOptions['absEtaBins']) lines.append("process.comp_jetToTauFakeRate.ptBins = cms.vdouble(%s)" % jobOptions['ptBins']) lines.append( "process.comp_jetToTauFakeRate.decayModes = cms.vint32(%s)" % jobOptions['decayModes']) lines.append( "process.comp_jetToTauFakeRate.hadTauSelections = cms.vstring(%s)" % jobOptions['hadTauSelections']) lines.append( "process.comp_jetToTauFakeRate.trigMatchingOption = cms.string('%s')" % jobOptions['trigMatchingOption']) lines.append( "process.comp_jetToTauFakeRate.outputFileName = cms.string('%s')" % jobOptions['plots_outputFileName']) create_cfg(self.cfgFile_comp_jetToTauFakeRate, jobOptions['cfgFile_modified'], lines)
def createCfg_addBackgrounds_Convs_LeptonFakeRate(self, jobOptions): lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['outputFile'])) lines.append("process.addBackground_LeptonFakeRate.processData = cms.string('%s')" % self.processToSubtractConvsFrom) lines.append("process.addBackground_LeptonFakeRate.processLeptonFakes = cms.string('%s_NC')" % self.processToSubtractConvsFrom) lines.append("process.addBackground_LeptonFakeRate.processesToSubtract = cms.vstring('%sg')" % self.processToSubtractConvsFrom) # lines.append("process.addBackground_LeptonFakeRate.sysShifts = cms.vstring()" % self.central_or_shifts) logging.info("self.cfgFile_addBackgrounds_Convs_LeptonFakeRate => %s" % self.cfgFile_addBackgrounds_Convs_LeptonFakeRate) logging.info("jobOptions['cfgFile_modified'] => %s" % jobOptions['cfgFile_modified']) create_cfg(self.cfgFile_addBackgrounds_Convs_LeptonFakeRate, jobOptions['cfgFile_modified'], lines)
def createCfg_addFlips(self, inputFile, outputFile, cfgFile_modified): """Create python configuration file for the addBackgroundLeptonFlips executable (data-driven estimation of 'Flips' backgrounds) Args: inputFiles: input file (the ROOT file produced by hadd_stage1) outputFile: output file of the job """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % inputFile) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % outputFile) create_cfg(self.cfgFile_addFlips_original, cfgFile_modified, lines)
def createCfg_prodNtuple(self, inputFiles, outputFile, era, cfgFile_modified): """Create python configuration file for the produceNtuple_3l_1tau executable (Ntuple production code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % inputFiles) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(outputFile)) lines.append("process.produceNtuple_3l_1tau.era = cms.string('%s')" % era) create_cfg(self.cfgFile_prodNtuple_original, cfgFile_modified, lines)
def createCfg_analyze(self, jobOptions, sample_info): """Create python configuration file for the analyze_charge_flip executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/tthAnalysis/HiggsToTauTau/bin/analyze_charge_flip.cc """ lines = super(analyzeConfig_charge_flip, self).createCfg_analyze(jobOptions, sample_info) create_cfg(self.cfgFile_analyze_original, jobOptions["cfgFile_modified"], lines)
def createCfg_add_syst_dcard(self, jobOptions): """Fills the template of python configuration file for adding specific shape systematics to the datacard, e.g. CMS_ttHl_Clos_e_shapeUp/Down, CMS_ttHl_Clos_m_shapeUp/Down Args: histogramToFit: name of the histogram used for signal extraction """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % jobOptions['outputFile']) lines.append("process.addSystDatacards.category = cms.string('%s')" % jobOptions['category']) lines.append("process.addSystDatacards.histogramToFit = cms.string('%s')" % jobOptions['histogramToFit']) create_cfg(self.cfgFile_add_syst_dcard, jobOptions['cfgFile_modified'], lines)
def createCfg_prodNtuple(self, jobOptions): """Create python configuration file for the prodNtuple executable (Ntuple production code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram """ if self.skip_tools_step: inputFiles_prepended = jobOptions['inputFiles'] else: inputFiles_prepended = map(lambda path: os.path.basename('%s_ii%s' % os.path.splitext(path)), jobOptions['inputFiles']) if len(inputFiles_prepended) != len(set(inputFiles_prepended)): raise ValueError("Not all input files have a unique base name: %s" % ', '.join(jobOptions['inputFiles'])) lines = [ "process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['outputFile']), "process.produceNtuple.era = cms.string('%s')" % self.era, "process.produceNtuple.minNumLeptons = cms.int32(%i)" % self.preselection_cuts['minNumLeptons'], "process.produceNtuple.minNumHadTaus = cms.int32(%i)" % self.preselection_cuts['minNumHadTaus'], "process.produceNtuple.minNumLeptons_and_HadTaus = cms.int32(%i)" % self.preselection_cuts['minNumLeptons_and_HadTaus'], "process.produceNtuple.minNumJets = cms.int32(%i)" % self.preselection_cuts['minNumJets'], "process.produceNtuple.minNumBJets_loose = cms.int32(%i)" % self.preselection_cuts['minNumBJets_loose'], "process.produceNtuple.minNumBJets_medium = cms.int32(%i)" % self.preselection_cuts['minNumBJets_medium'], "process.produceNtuple.maxNumBJets_loose = cms.int32(%i)" % self.preselection_cuts['maxNumBJets_loose'], "process.produceNtuple.maxNumBJets_medium = cms.int32(%i)" % self.preselection_cuts['maxNumBJets_medium'], "process.produceNtuple.applyJetEtaCut = cms.bool(%s)" % self.preselection_cuts['applyJetEtaCut'], "process.produceNtuple.branchNames_triggersFilter = cms.vstring(%s)" % jobOptions['HLTcuts'], "process.produceNtuple.isMC = cms.bool(%s)" % jobOptions['is_mc'], "process.produceNtuple.redoGenMatching = cms.bool(%s)" % (not self.skip_tools_step), "process.produceNtuple.leptonSelection = cms.string('%s')" % self.leptonSelection, "process.produceNtuple.hadTauWP = cms.string('%s')" % self.hadTauWP, "process.produceNtuple.random_seed = cms.uint32(%i)" % jobOptions['random_seed'], "process.produceNtuple.isDEBUG = cms.bool(%s)" % self.isDebug, "process.produceNtuple.useNonNominal = cms.bool(%s)" % self.use_nonnominal, "process.produceNtuple.genMatchingByIndex = cms.bool(%s)" % self.gen_matching_by_index, "process.produceNtuple.branchNames_triggers = cms.vstring(%s)" % jobOptions['triggers'], "process.fwliteInput.fileNames = cms.vstring(%s)" % inputFiles_prepended, "executable = 'produceNtuple'", "inputFiles = %s" % jobOptions['inputFiles'], "isMC = %s" % str(jobOptions['is_mc']), "isHHnonRes = %s" % str(is_hh_nonres(jobOptions)), "era = %s" % str(self.era), "pileup = '%s'" % self.pileup, "golden_json = '%s'" % self.golden_json, "process_name = '%s'" % jobOptions['process_name'], "skip_tools_step = %s" % self.skip_tools_step, "remove_intermediate = %s" % (not self.do_sync), "compTopRwgt = %s" % jobOptions['compTopRwgt'], "isTuneCP5 = %s" % jobOptions['isTuneCP5'], ] create_cfg(self.cfgFile_prodNtuple_original, jobOptions['cfgFile_modified'], lines)
def createCfg_prep_dcard(self, histogramToFit, histogramDir=None, label=None): """Fills the template of python configuration file for datacard preparation Args: histogramToFit: name of the histogram used for signal extraction """ datacardFile = os.path.join( self.outputDir, DKEY_DCRD, "prepareDatacards_%s_%s.root" % (self.channel, histogramToFit)) category_output = self.channel cfg_file_modified = os.path.join( self.outputDir, DKEY_CFGS, "prepareDatacards_%s_%s_cfg.py" % (self.channel, histogramToFit)) key = histogramToFit if not histogramDir: histogramDir = self.histogramDir_prep_dcard if label: datacardFile = datacardFile.replace(channel, "%s_%s" % (channel, label)) category_output += "_%s" % label cfg_file_modified = cfg_file_modified.replace( "_cfg.py", "_%s_cfg.py" % label) key = getKey(histogramToFit, label) lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % self.histogramFile_hadd_stage2) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % datacardFile) lines.append( "process.prepareDatacards.processesToCopy = cms.vstring(%s)" % self.prep_dcard_processesToCopy) lines.append("process.prepareDatacards.signals = cms.vstring(%s)" % self.prep_dcard_signals) lines.append("process.prepareDatacards.makeSubDir = cms.bool(False)") lines.append("process.prepareDatacards.categories = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" input = cms.string('%s/sel/evt')," % self.histogramDir_prep_dcard) lines.append(" output = cms.string('ttH_%s')" % category_output) lines.append(" )") lines.append(")") lines.append( "process.prepareDatacards.histogramToFit = cms.string('%s')" % histogramToFit) create_cfg(self.cfgFile_prep_dcard_original, cfg_file_modified, lines) self.datacardFiles[key] = datacardFile self.cfgFile_prep_dcard_modified[key] = cfg_file_modified
def createCfg_addBackgrounds(self, inputFile, outputFile, cfgFile_modified, categories, processes_input, process_output): """Create python configuration file for the addBackgrounds executable (sum either all "fake" or all "non-fake" contributions) Args: inputFiles: input file (the ROOT file produced by hadd_stage1) outputFile: output file of the job """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % inputFile) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % outputFile) lines.append("process.addBackgrounds.categories = cms.vstring(%s)" % categories) lines.append("process.addBackgrounds.processes_input = cms.vstring(%s)" % processes_input) lines.append("process.addBackgrounds.process_output = cms.string('%s')" % process_output) create_cfg(self.cfgFile_addBackgrounds_original, cfgFile_modified, lines)
def createCfg_addBackgrounds(self, jobOptions): """Create python configuration file for the addBackgrounds executable (sum either all "fake" or all "non-fake" contributions) Args: inputFiles: input file (the ROOT file produced by hadd_stage1) outputFile: output file of the job """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['outputFile'])) lines.append("process.addBackgrounds.categories = cms.vstring(%s)" % jobOptions['categories']) lines.append("process.addBackgrounds.processes_input = cms.vstring(%s)" % jobOptions['processes_input']) lines.append("process.addBackgrounds.process_output = cms.string('%s')" % jobOptions['process_output']) create_cfg(self.cfgFile_addBackgrounds, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions, sample_info, lepton_and_hadTau_selection): """Create python configuration file for the analyze_2los_1tau executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TTW`, `TTZ`, `Rares`, `data_obs`, `ttH_hww`, 'ttH_hzg', 'ttH_hmm', `ttH_hzz` or `ttH_htt` is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/tthAnalysis/HiggsToTauTau/bin/analyze_2los_1tau.cc """ lepton_and_hadTau_frWeight = "disabled" if jobOptions['applyFakeRateWeights'] == "disabled" else "enabled" histogramDir = getHistogramDir( lepton_and_hadTau_selection, jobOptions['hadTauSelection'], lepton_and_hadTau_frWeight ) jobOptions['histogramDir'] = histogramDir if 'mcClosure' in lepton_and_hadTau_selection: self.mcClosure_dir[lepton_and_hadTau_selection] = histogramDir self.set_leptonFakeRateWeightHistogramNames(jobOptions['central_or_shift'], lepton_and_hadTau_selection) jobOptions['leptonFakeRateWeight.inputFileName'] = self.leptonFakeRateWeight_inputFile jobOptions['leptonFakeRateWeight.histogramName_e'] = self.leptonFakeRateWeight_histogramName_e jobOptions['leptonFakeRateWeight.histogramName_mu'] = self.leptonFakeRateWeight_histogramName_mu jobOptions['hadTauFakeRateWeight.inputFileName'] = self.hadTauFakeRateWeight_inputFile jobOptions['hadTauFakeRateWeight.lead.graphName'] = 'jetToTauFakeRate/%s/$etaBin/jetToTauFakeRate_mc_hadTaus_pt' % self.hadTau_selection_part2 jobOptions['hadTauFakeRateWeight.lead.fitFunctionName'] = 'jetToTauFakeRate/%s/$etaBin/fitFunction_data_div_mc_hadTaus_pt' % self.hadTau_selection_part2 if "mcClosure" in lepton_and_hadTau_selection: jobOptions['hadTauFakeRateWeight.applyGraph_lead'] = True jobOptions['hadTauFakeRateWeight.applyGraph_sublead'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_lead'] = False jobOptions['hadTauFakeRateWeight.applyFitFunction_sublead'] = False if self.applyFakeRateWeights not in [ "3L", "1tau" ] and not self.isBDTtraining: # We want to preserve the same logic as running in SR and applying the FF method only to leptons [*] jobOptions['hadTauFakeRateWeight.applyFitFunction_lead'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_sublead'] = True if jobOptions['hadTauSelection'].find("Tight") != -1 and self.applyFakeRateWeights not in [ "3L", "1tau" ] and not self.isBDTtraining: # [*] SR and applying the FF method only to leptons jobOptions['hadTauFakeRateWeight.applyGraph_lead'] = False # FR in MC for the leading tau jobOptions['hadTauFakeRateWeight.applyGraph_sublead'] = False # data-to-MC SF for the leading tau jobOptions['hadTauFakeRateWeight.applyFitFunction_lead'] = True jobOptions['hadTauFakeRateWeight.applyFitFunction_sublead'] = True jobOptions['apply_hadTauFakeRateSF'] = True lines = super(analyzeConfig_2los_1tau, self).createCfg_analyze(jobOptions, sample_info) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_makePlots_mcClosure(self, jobOptions): """Fills the template of python configuration file for making control plots Args: histogramFile: name of the input ROOT file """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.makePlots_mcClosure.outputFileName = cms.string('%s')" % jobOptions['outputFile']) lines.append("process.makePlots_mcClosure.processesBackground = cms.vstring(%s)" % self.make_plots_backgrounds) lines.append("process.makePlots_mcClosure.processSignal = cms.string('%s')" % self.make_plots_signal) lines.append("process.makePlots_mcClosure.categories = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" signal = cms.string('%s')," % self.histogramDir_prep_dcard) lines.append(" sideband = cms.string('%s')," % self.histogramDir_prep_dcard.replace("Tight", "Fakeable_mcClosure_wFakeRateWeights")) lines.append(" label = cms.string('%s')" % self.channel) lines.append(" )") lines.append(")") create_cfg(self.cfgFile_make_plots_mcClosure, jobOptions['cfgFile_modified'], lines)
def createCfg_prep_dcard(self, histogramToFit, histogramDir=None, label=None): """Fills the template of python configuration file for datacard preparation Args: histogramToFit: name of the histogram used for signal extraction """ datacardFile = os.path.join( self.outputDir, DKEY_DCRD, "prepareDatacards_%s_%s.root" % (self.channel, histogramToFit)) category_output = self.channel cfg_file_modified = os.path.join( self.outputDir, DKEY_CFGS, "prepareDatacards_%s_%s_cfg.py" % (self.channel, histogramToFit)) key = histogramToFit if not histogramDir: histogramDir = self.histogramDir_prep_dcard if label: datacardFile = datacardFile.replace( channel, "%s_%s" % (channel, label)) category_output += "_%s" % label cfg_file_modified = cfg_file_modified.replace( "_cfg.py", "_%s_cfg.py" % label) key = getKey(histogramToFit, label) lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % self.histogramFile_hadd_stage2) lines.append( "process.fwliteOutput.fileName = cms.string('%s')" % datacardFile) lines.append("process.prepareDatacards.processesToCopy = cms.vstring(%s)" % self.prep_dcard_processesToCopy) lines.append("process.prepareDatacards.signals = cms.vstring(%s)" % self.prep_dcard_signals) lines.append("process.prepareDatacards.makeSubDir = cms.bool(False)") lines.append("process.prepareDatacards.categories = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" input = cms.string('%s/sel/evt')," % self.histogramDir_prep_dcard) lines.append(" output = cms.string('ttH_%s')" % category_output) lines.append(" )") lines.append(")") lines.append( "process.prepareDatacards.histogramToFit = cms.string('%s')" % histogramToFit) create_cfg(self.cfgFile_prep_dcard_original, cfg_file_modified, lines) self.datacardFiles[key] = datacardFile self.cfgFile_prep_dcard_modified[key] = cfg_file_modified
def createCfg_prep_dcard(self, histogramToFit, histogramDir = None, label = None): """Fills the template of python configuration file for datacard preparation Args: histogramToFit: name of the histogram used for signal extraction """ datacardFile = os.path.join(self.outputDir, DKEY_DCRD, "prepareDatacards_%s_%s.root" % (self.channel, histogramToFit)) category_output = self.channel cfgFile_modified = os.path.join(self.outputDir, DKEY_CFGS, "prepareDatacards_%s_%s_cfg.py" % (self.channel, histogramToFit)) key = histogramToFit if not histogramDir: histogramDir = self.histogramDir_prep_dcard if label: datacardFile = datacardFile.replace(channel, "%s_%s" % (channel, label)) category_output += "_%s" % label cfgFile_modified = cfgFile_modified.replace("_cfg.py", "_%s_cfg.py" % label) key = getKey(histogramToFit, label) lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % self.histogramFile_hadd_stage2) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % datacardFile) lines.append("process.prepareDatacards.processesToCopy = cms.vstring(%s)" % self.prep_dcard_processesToCopy) lines.append("process.prepareDatacards.signals = cms.vstring(%s)" % self.prep_dcard_signals) lines.append("process.prepareDatacards.makeSubDir = cms.bool(True)") lines.append("process.prepareDatacards.categories = cms.VPSet(") for charge in ["OS", "SS"]: for ptEtaBin in ["BB_LL", "BB_ML", "BB_MM", "BB_HL", "BB_HM", "BB_HH", "EE_LL", "EE_ML", "EE_MM", "EE_HL", "EE_HM", "EE_HH", "BE_LL", "BE_ML", "EB_ML", "BE_MM", "BE_HL", "EB_HL", "BE_HM", "EB_HM", "BE_HH", "total"]: lines.append(" cms.PSet(") lines.append(" input = cms.string('%s/%s')," % (charge, ptEtaBin)) lines.append(" output = cms.string('ttH_%s_%s_%s')" % (self.channel, charge, ptEtaBin)) lines.append(" ),") lines.append(")") lines.append("process.prepareDatacards.histogramToFit = cms.string('%s')" % histogramToFit) lines.append("""process.prepareDatacards.sysShifts = cms.vstring( "CMS_ttHl_electronESBarrelUp", "CMS_ttHl_electronESBarrelDown", "CMS_ttHl_electronESEndcapUp", "CMS_ttHl_electronESEndcapDown", "CMS_ttHl_electronERUp", "CMS_ttHl_electronERDown") """ ) create_cfg(self.cfgFile_prep_dcard_original, cfgFile_modified, lines) self.datacardFiles[key] = datacardFile self.cfgFile_prep_dcard_modified[key] = cfgFile_modified
def createCfg_addBackgrounds_LeptonFakeRate(self, jobOptions): """Create python configuration file for the addBackgrounds executable (sum either all "fake" or all "non-fake" contributions) Args: inputFiles: input file (the ROOT file produced by hadd_stage1) outputFile: output file of the job """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['outputFile'])) # if self.use_QCD_fromMC: # lines.append("process.addBackground_LeptonFakeRate.processData = cms.string('%s')" % "QCD") # lines.append("process.addBackground_LeptonFakeRate.processLeptonFakes = cms.string('%s')" % "QCD") # lines.append("process.addBackground_LeptonFakeRate.processesToSubtract = cms.vstring()") # lines.append("process.addBackgrounds.categories = cms.vstring(%s)" % jobOptions['categories']) # lines.append("process.addBackgrounds.processes_input = cms.vstring(%s)" % jobOptions['processes_input']) # lines.append("process.addBackgrounds.process_output = cms.string('%s')" % jobOptions['process_output']) logging.info("self.cfgFile_addBackgrounds_LeptonFakeRate => %s" % self.cfgFile_addBackgrounds_LeptonFakeRate) logging.info("jobOptions['cfgFile_modified'] => %s" % jobOptions['cfgFile_modified']) create_cfg(self.cfgFile_addBackgrounds_LeptonFakeRate, jobOptions['cfgFile_modified'], lines)
def createCfg_addFakes(self, jobOptions): """Create python configuration file for the addBackgroundLeptonFakes executable (data-driven estimation of 'Fakes' backgrounds) Args: inputFiles: input file (the ROOT file produced by hadd_stage1) outputFile: output file of the job """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(jobOptions['outputFile'])) lines.append("process.addBackgroundLeptonFakes.categories = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" signal = cms.string('%s')," % jobOptions['category_signal']) lines.append(" sideband = cms.string('%s')" % jobOptions['category_sideband']) lines.append(" )") lines.append(")") lines.append("process.addBackgroundLeptonFakes.processesToSubtract = cms.vstring(%s)" % self.nonfake_backgrounds) lines.append("process.addBackgroundLeptonFakes.sysShifts = cms.vstring(%s)" % self.central_or_shifts) create_cfg(self.cfgFile_addFakes, jobOptions['cfgFile_modified'], lines)
def createCfg_addFakes(self, inputFile, outputFile, cfgFile_modified, category_signal, category_sideband): """Create python configuration file for the addBackgroundLeptonFakes executable (data-driven estimation of 'Fakes' backgrounds) Args: inputFiles: input file (the ROOT file produced by hadd_stage1) outputFile: output file of the job """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % inputFile) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % outputFile) lines.append("process.addBackgroundLeptonFakes.categories = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" signal = cms.string('%s')," % category_signal) lines.append(" sideband = cms.string('%s')" % category_sideband) lines.append(" )") lines.append(")") processesToSubtract = self.nonfake_backgrounds ##processesToSubtract.append("fakes_signal") lines.append("process.addBackgroundLeptonFakes.processesToSubtract = cms.vstring(%s)" % processesToSubtract) create_cfg(self.cfgFile_addFakes_original, cfgFile_modified, lines)
def createCfg_analyze(self, inputFiles, outputFile, sample_category, era, triggers, charge_selection, jet_minPt, jet_maxPt, jet_minAbsEta, jet_maxAbsEta, hadTau_selections, absEtaBins, is_mc, central_or_shift, lumi_scale, apply_genWeight, apply_trigger_bits, cfgFile_modified): """Create python configuration file for the analyze_jetToTauFakeRate executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TT`, `TTW`, `TTZ`, `EWK`, `Rares`, `data_obs`, `ttH_hww`, `ttH_hzz` or `ttH_htt` is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/tthAnalysis/HiggsToTauTau/bin/analyze_jetToTauFakeRate.cc """ lines = [] ##lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % [ os.path.basename(inputFile) for inputFile in inputFiles ]) lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % inputFiles) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(outputFile)) lines.append("process.analyze_jetToTauFakeRate.process = cms.string('%s')" % sample_category) lines.append("process.analyze_jetToTauFakeRate.era = cms.string('%s')" % era) lines.append("process.analyze_jetToTauFakeRate.triggers_1e = cms.vstring(%s)" % self.triggers_1e) lines.append("process.analyze_jetToTauFakeRate.use_triggers_1e = cms.bool(%s)" % ("1e" in triggers)) lines.append("process.analyze_jetToTauFakeRate.triggers_1mu = cms.vstring(%s)" % self.triggers_1mu) lines.append("process.analyze_jetToTauFakeRate.use_triggers_1mu = cms.bool(%s)" % ("1mu" in triggers)) lines.append("process.analyze_jetToTauFakeRate.triggers_1e1mu = cms.vstring(%s)" % self.triggers_1e1mu) lines.append("process.analyze_jetToTauFakeRate.use_triggers_1e1mu = cms.bool(%s)" % ("1e1mu" in triggers)) lines.append("process.analyze_jetToTauFakeRate.chargeSelection = cms.string('%s')" % charge_selection) lines.append("process.analyze_jetToTauFakeRate.jet_minPt = cms.double('%f')" % jet_minPt) lines.append("process.analyze_jetToTauFakeRate.jet_maxPt = cms.double('%f')" % jet_maxPt) lines.append("process.analyze_jetToTauFakeRate.jet_minAbsEta = cms.double('%f')" % jet_minAbsEta) lines.append("process.analyze_jetToTauFakeRate.jet_maxAbsEta = cms.double('%f')" % jet_maxAbsEta) lines.append("process.analyze_jetToTauFakeRate.hadTauSelections = cms.vstring(") for hadTau_selection in hadTau_selections: lines.append(" '%s'," % hadTau_selection) lines.append(")") lines.append("process.analyze_jetToTauFakeRate.absEtaBins = cms.vdouble(%s)" % absEtaBins) lines.append("process.analyze_jetToTauFakeRate.isMC = cms.bool(%s)" % is_mc) lines.append("process.analyze_jetToTauFakeRate.central_or_shift = cms.string('%s')" % central_or_shift) lines.append("process.analyze_jetToTauFakeRate.lumiScale = cms.double(%f)" % lumi_scale) lines.append("process.analyze_jetToTauFakeRate.apply_genWeight = cms.bool(%s)" % apply_genWeight) lines.append("process.analyze_jetToTauFakeRate.apply_trigger_bits = cms.bool(%s)" % apply_trigger_bits) create_cfg(self.cfgFile_analyze_original, cfgFile_modified, lines)
def createCfg_makePlots(self, histogramDir=None, label=None, make_plots_backgrounds=None): """Fills the template of python configuration file for making control plots Args: histogram_file: name of the input ROOT file """ outputFileName = os.path.join(self.outputDir, DKEY_PLOT, self.channel, "makePlots_%s.png" % self.channel) category_label = self.channel cfg_file_modified = os.path.join(self.outputDir, DKEY_CFGS, "makePlots_%s_cfg.py" % self.channel) if not histogramDir: histogramDir = self.histogramDir_prep_dcard if label: outputFileName = outputFileName.replace(".png", "_%s.png" % label) category_label += " (%s)" % label cfg_file_modified = cfg_file_modified.replace( "_cfg.py", "_%s_cfg.py" % label) lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % self.histogramFile_hadd_stage2) lines.append("process.makePlots.outputFileName = cms.string('%s')" % outputFileName) if not make_plots_backgrounds: make_plots_backgrounds = self.make_plots_backgrounds lines.append( "process.makePlots.processesBackground = cms.vstring(%s)" % make_plots_backgrounds) lines.append("process.makePlots.processSignal = cms.string('%s')" % self.make_plots_signal) lines.append("process.makePlots.categories = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" name = cms.string('%s')," % histogramDir) lines.append(" label = cms.string('%s')" % category_label) lines.append(" )") lines.append(")") create_cfg(self.cfgFile_make_plots_original, cfg_file_modified, lines) self.cfgFiles_make_plots_modified.append(cfg_file_modified)
def createCfg_makePlots(self, jobOptions): """Fills the template of python configuration file for making control plots Args: histogram_file: name of the input ROOT file """ category_label = self.channel if jobOptions['label']: category_label += " (%s)" % jobOptions['label'] lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % jobOptions['inputFile']) lines.append("process.makePlots.outputFileName = cms.string('%s')" % jobOptions['outputFile']) lines.append("process.makePlots.processesBackground = cms.vstring(%s)" % jobOptions['make_plots_backgrounds']) lines.append("process.makePlots.processSignal = cms.string('%s')" % self.make_plots_signal) lines.append("process.makePlots.categories = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" name = cms.string('%s')," % jobOptions['histogramDir']) lines.append(" label = cms.string('%s')" % category_label) lines.append(" )") lines.append(")") create_cfg(self.cfgFile_make_plots, jobOptions['cfgFile_modified'], lines)
def createCfg_analyze(self, jobOptions, sample_info): """Create python configuration file for the analyze_hh_bbwwMEM_dilepton executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TT` or `signal` """ jobOptions['histogramDir'] = getHistogramDir( self.evtCategory_inclusive, jobOptions['apply_jetSmearing'], jobOptions['apply_metSmearing']) lines = super(analyzeConfig_hh_bbwwMEM_dilepton, self).createCfg_analyze(jobOptions, sample_info, additionalJobOptions=[ "apply_jetSmearing", "apply_metSmearing", "maxSelEvents", "skipSelEvents" ]) create_cfg(self.cfgFile_analyze, jobOptions['cfgFile_modified'], lines)
def createCfg_makePlots_mcClosure(self): """Fills the template of python configuration file for making control plots Args: histogramFile: name of the input ROOT file """ lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % self.histogramFile_hadd_stage2) lines.append("process.makePlots_mcClosure.outputFileName = cms.string('%s')" % os.path.join(self.outputDir, DKEY_PLOT, self.channel, "makePlots_mcClosure_%s.png" % self.channel)) lines.append("process.makePlots_mcClosure.processesBackground = cms.vstring(%s)" % self.make_plots_backgrounds) lines.append("process.makePlots_mcClosure.processSignal = cms.string('%s')" % self.make_plots_signal) lines.append("process.makePlots_mcClosure.categories = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" signal = cms.string('%s')," % self.histogramDir_prep_dcard) lines.append(" sideband = cms.string('%s')," % self.histogramDir_prep_dcard.replace("Tight", "Fakeable_mcClosure_wFakeRateWeights")) lines.append(" label = cms.string('%s')" % self.channel) lines.append(" )") lines.append(")") lines.append("process.makePlots_mcClosure.distributions = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" histogramName = cms.string('sel/evt/$PROCESS/numJets'),") lines.append(" xAxisTitle = cms.string('jet Multiplicity'),") lines.append(" yAxisTitle = cms.string('N')") lines.append(" ),") lines.append(" cms.PSet(") lines.append(" histogramName = cms.string('sel/evt/$PROCESS/mvaOutput_1l_2tau_ttbar'),") lines.append(" xAxisTitle = cms.string('MVA'),") lines.append(" yAxisTitle = cms.string('dN/dMVA')") lines.append(" ),") lines.append(" cms.PSet(") lines.append(" histogramName = cms.string('sel/evt/$PROCESS/mTauTauVis'),") lines.append(" xAxisTitle = cms.string('m_{#tau#tau}^{vis} [GeV]'),") lines.append(" yAxisTitle = cms.string('dN/dm_{#tau#tau}^{vis} [1/GeV]')") lines.append(" )") lines.append(")") cfgFile_modified = os.path.join(self.outputDir, DKEY_CFGS, "makePlots_mcClosure_%s_cfg.py" % self.channel) create_cfg(self.cfgFile_make_plots_original, cfgFile_modified, lines) self.cfgFiles_make_plots_mcClosure_modified.append(cfgFile_modified)
def createCfg_makePlots(self, histogramDir=None, label=None, make_plots_backgrounds=None): """Fills the template of python configuration file for making control plots Args: histogram_file: name of the input ROOT file """ outputFileName = os.path.join( self.outputDir, DKEY_PLOT, self.channel, "makePlots_%s.png" % self.channel) category_label = self.channel cfg_file_modified = os.path.join( self.outputDir, DKEY_CFGS, "makePlots_%s_cfg.py" % self.channel) if not histogramDir: histogramDir = self.histogramDir_prep_dcard if label: outputFileName = outputFileName.replace(".png", "_%s.png" % label) category_label += " (%s)" % label cfg_file_modified = cfg_file_modified.replace( "_cfg.py", "_%s_cfg.py" % label) lines = [] lines.append("process.fwliteInput.fileNames = cms.vstring('%s')" % self.histogramFile_hadd_stage2) lines.append( "process.makePlots.outputFileName = cms.string('%s')" % outputFileName) if not make_plots_backgrounds: make_plots_backgrounds = self.make_plots_backgrounds lines.append( "process.makePlots.processesBackground = cms.vstring(%s)" % make_plots_backgrounds) lines.append("process.makePlots.processSignal = cms.string('%s')" % self.make_plots_signal) lines.append("process.makePlots.categories = cms.VPSet(") lines.append(" cms.PSet(") lines.append(" name = cms.string('%s')," % histogramDir) lines.append(" label = cms.string('%s')" % category_label) lines.append(" )") lines.append(")") create_cfg(self.cfgFile_make_plots_original, cfg_file_modified, lines) self.cfgFiles_make_plots_modified.append(cfg_file_modified)
def createCfg_analyze(self, inputFiles, outputFile, sample_category, era, triggers, lepton_selection, apply_leptonGenMatching, hadTau_selection, apply_hadTauGenMatching, hadTau_charge_selection, applyFakeRateWeights, is_mc, central_or_shift, lumi_scale, apply_genWeight, apply_trigger_bits, cfgFile_modified, rle_output_file): """Create python configuration file for the analyze_1l_2tau executable (analysis code) Args: inputFiles: list of input files (Ntuples) outputFile: output file of the job -- a ROOT file containing histogram process: either `TT`, `TTW`, `TTZ`, `EWK`, `Rares`, `data_obs`, `ttH_hww`, `ttH_hzz` or `ttH_htt` is_mc: flag indicating whether job runs on MC (True) or data (False) lumi_scale: event weight (= xsection * luminosity / number of events) central_or_shift: either 'central' or one of the systematic uncertainties defined in $CMSSW_BASE/src/tthAnalysis/HiggsToTauTau/bin/analyze_1l_2tau.cc """ lines = [] ##lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % [ os.path.basename(inputFile) for inputFile in inputFiles ]) lines.append("process.fwliteInput.fileNames = cms.vstring(%s)" % inputFiles) lines.append("process.fwliteOutput.fileName = cms.string('%s')" % os.path.basename(outputFile)) lines.append("process.analyze_1l_2tau.process = cms.string('%s')" % sample_category) hadTau_frWeight = None if applyFakeRateWeights == "disabled": hadTau_frWeight = "disabled" else: hadTau_frWeight = "enabled" histogramDir = getHistogramDir(hadTau_selection, hadTau_frWeight, hadTau_charge_selection) lines.append("process.analyze_1l_2tau.histogramDir = cms.string('%s')" % histogramDir) lines.append("process.analyze_1l_2tau.era = cms.string('%s')" % era) lines.append("process.analyze_1l_2tau.triggers_1e = cms.vstring(%s)" % self.triggers_1e) lines.append("process.analyze_1l_2tau.use_triggers_1e = cms.bool(%s)" % ("1e" in triggers)) lines.append("process.analyze_1l_2tau.triggers_1mu = cms.vstring(%s)" % self.triggers_1mu) lines.append("process.analyze_1l_2tau.use_triggers_1mu = cms.bool(%s)" % ("1mu" in triggers)) lines.append("process.analyze_1l_2tau.leptonSelection = cms.string('%s')" % lepton_selection) lines.append("process.analyze_1l_2tau.apply_leptonGenMatching = cms.bool(%s)" % (apply_leptonGenMatching and is_mc)) lines.append("process.analyze_1l_2tau.hadTauSelection = cms.string('%s')" % hadTau_selection) lines.append("process.analyze_1l_2tau.hadTauChargeSelection = cms.string('%s')" % hadTau_charge_selection) lines.append("process.analyze_1l_2tau.apply_hadTauGenMatching = cms.bool(%s)" % (apply_hadTauGenMatching and is_mc)) lines.append("process.analyze_1l_2tau.applyFakeRateWeights = cms.string('%s')" % applyFakeRateWeights) if hadTau_selection.find("Fakeable") != -1 and applyFakeRateWeights in [ "3L", "2tau" ]: fitFunctionName = None if era == "2015": lines.append("process.analyze_1l_2tau.hadTauFakeRateWeight.inputFileName = cms.string('tthAnalysis/HiggsToTauTau/data/FR_tau_2015.root')") # CV: use data/MC corrections determined for dR03mvaLoose discriminator, # as the event statistics in 2015 data is too low to determine data/MC corrections for tighter working-points fitFunctionName = "jetToTauFakeRate/dR03mvaLoose/$etaBin/fitFunction_data_div_mc_hadTaus_pt" elif era == "2016": lines.append("process.analyze_1l_2tau.hadTauFakeRateWeight.inputFileName = cms.string('tthAnalysis/HiggsToTauTau/data/FR_tau_2016.root')") # CV: use data/MC corrections determined for dR03mvaMedium discriminator for 2016 data fitFunctionName = "jetToTauFakeRate/dR03mvaMedium/$etaBin/fitFunction_data_div_mc_hadTaus_pt" else: raise ValueError("Invalid parameter 'era' = %s !!" % era) lines.append("process.analyze_1l_2tau.hadTauFakeRateWeight.lead.fitFunctionName = cms.string('%s')" % fitFunctionName) lines.append("process.analyze_1l_2tau.hadTauFakeRateWeight.sublead.fitFunctionName = cms.string('%s')" % fitFunctionName) if hadTau_selection.find("mcClosure") != -1: lines.append("process.analyze_1l_2tau.hadTauFakeRateWeight.applyFitFunction_lead = cms.bool(False)") lines.append("process.analyze_1l_2tau.hadTauFakeRateWeight.applyFitFunction_sublead = cms.bool(False)") lines.append("process.analyze_1l_2tau.isMC = cms.bool(%s)" % is_mc) lines.append("process.analyze_1l_2tau.central_or_shift = cms.string('%s')" % central_or_shift) lines.append("process.analyze_1l_2tau.lumiScale = cms.double(%f)" % lumi_scale) lines.append("process.analyze_1l_2tau.apply_genWeight = cms.bool(%s)" % apply_genWeight) lines.append("process.analyze_1l_2tau.apply_trigger_bits = cms.bool(%s)" % apply_trigger_bits) lines.append("process.analyze_1l_2tau.selEventsFileName_output = cms.string('%s')" % rle_output_file) create_cfg(self.cfgFile_analyze_original, cfgFile_modified, lines)