def process(self, cut): configMgr.analysisName = "MonoJet_"+str(cut)+"GeV" in_file_path = "data/"+configMgr.analysisName+".root" configMgr.histBackupCacheFile = "data/"+configMgr.analysisName+"_template.root" configMgr.outputFileName = "results/%s_Output.root"%configMgr.analysisName # define unnecessary cuts configMgr.cutsDict["SR"] = "1." configMgr.cutsDict["WMUNU"] = "1." configMgr.cutsDict["WENU"] = "1." configMgr.cutsDict["ZMM"] = "1." configMgr.weights = "1." yield_mgr = SampleHist(cut) # get systematics yield_mgr.create_common_sys() # create MC samples yield_mgr.create_samples() # define background-only bkg = configMgr.addFitConfig("BkgOnly") if self.use_stat: bkg.statErrThreshold = 0.05 else: bkg.statErrThreshold = None all_samples = yield_mgr.bkg_samples[:] all_samples.append(yield_mgr.data_sample) bkg.addSamples(all_samples) meas = bkg.addMeasurement(name="Normal", lumi=1.0, lumiErr=0.039) meas.addPOI("mu") meas.addParamSetting("Lumi", True, 1) constraint_chan = [] for region in regions: if "SR" in region: continue cstr_ch = bkg.addChannel("cuts", [region], 1, 0.5,1.5) cstr_ch.minY = 1e-4 cstr_ch.maxY = 400 constraint_chan.append(cstr_ch) bkg.setBkgConstrainChannels(constraint_chan) #Discovery if myFitType == FitType.Discovery: discovery = configMgr.addFitConfigClone(bkg, "Discovery") discovery.addSamples(yield_mgr.signal_sample) discovery.setSignalSample(yield_mgr.signal_sample) sig_channel = discovery.addChannel("cuts",["SR"], 1, 0.5, 1.5) sig_channel.minY = 1e-4 sig_channel.maxY = 2500 discovery.setSignalChannels([sig_channel]) if myFitType == FitType.Exclusion: print "In exclusion mode" exclusion = configMgr.addFitConfigClone(bkg, "Exclusion") exclusion.addSamples(yield_mgr.signal_sample) exclusion.setSignalSample(yield_mgr.signal_sample) sig_channel = exclusion.addChannel("cuts",["SR"], 1, 0.5, 1.5) sig_channel.minY = 1e-4 sig_channel.maxY = 2500 exclusion.setSignalChannels([sig_channel]) if configMgr.executeHistFactory: pass
# ------------------------------------------------------------------------------ # Configure exclusion fits if myFitType == FitType.Exclusion: print 'Setting up exclusion fit!' # sig_sample_list=['sig_100', 'sig_200', 'sig_300', 'sig_400', 'sig_500', # 'sig_600', 'sig_700', 'sig_800', 'sig_900', 'sig_1000'] sig_sample_list=['sig_400', 'sig_500', 'sig_600', 'sig_700', 'sig_800', 'sig_900', 'sig_1000', 'sig_1100'] # sig_sample_list=['sig_900'] sig_samples = [] for sig in sig_sample_list: print 'setting up signal sample: ', sig exclusion_sr_config = configMgr.addFitConfigClone(background_config, "Sig_excl_%s" % sig) sig_sample = Sample(sig, kViolet+5) sig_sample.setStatConfig(use_stat) sig_sample.setFileList(sig_files) sig_sample.setNormByTheory() sig_sample.setNormFactor("mu_SIG", 1., 0., 5.) sig_sample.weights = [nominal_weight_sig] # add baseline systematics to signal samples addSystematic([sig_sample], (btag_sf_uncert_sig_list + jes_uncert_list + [jer_uncert]))
if myFitType == FitType.Exclusion: points = [] try: sigSamples except NameError: sigSamples = None for sid in sigSamples: m3, mu = sid.split('_') points.append((int(m3), int(mu))) for (m3, mu) in points: print "Adding fit config for sample (%d, %d)" % (m3, mu) exclfit = configMgr.addFitConfigClone(fitconfig, "GGM_M3_mu_%d_%d" % (m3, mu)) sigSample = Sample("GGM_M3_mu_%d_%d" % (m3, mu), ROOT.kOrange+3) sigSample.setNormByTheory() sigSample.setStatConfig(useStat) sigSample.setNormFactor("mu_SIG", 1., 0., 5.) if do_signal_theory_unc: configMgr.fixSigXSec = True sigSample.addSystematic(sigXsec) #--- Special uncertainty. Theory variations (creates extra files) exclfit.addSamples(sigSample) exclfit.setSignalSample(sigSample) exclfit.setSignalChannels(signal_channels)
#read the line fName = aLine.split()[0] sigName = ssUtil.guessSampleType(fName) if (not sigName): print "Cannot infer signal type from file name, skipping " + sigfName continue print "Add fitConfig for " + sigName for cutVal in tarCutVals: cutValStr = str(cutVal).replace('.', 'd') for dm in tarDms: for ch in tarChs: cutName = "SR_%s_dm%s_Cut%s" % (ch, dm, cutValStr) aSigExclusionFitConfig = configMgr.addFitConfigClone( exclusionFitConfig, "Exclusion_%s_%s_dm%s_%s" % (sigName, ch, dm, cutValStr)) srBin = aSigExclusionFitConfig.addChannel( "cuts", [cutName], 1, 0.5, 1.5) aSigExclusionFitConfig.addSignalChannels([srBin]) #aSigExclusionFitConfig.setSignalChannels([srnonISRBin, srISRBin]) sigSample = Sample(sigName, kCyan) sigSample.setFileList([fName]) sigSample.setNormByTheory() sigSample.setNormFactor("mu_SIG", 1., 0., 5.) #set PRW off and overrides configMgr.weights #sigWeights = ("ElSF","MuSF", "BtagSF","weight","1.0", "mcEvtW")
mm2Jl.addSystematic(jes) # bkt.setValidationChannels([nJetSLVR2,metSLVR2,meffSLVR2,nBJetSLVR2,metmeffSLVR2,mm2J,srs1l2jTChannel]) bkt.setValidationChannels([nJetSLVR2,srs1l2jTChannel,mm2J,mm2Jl]) dataSample.buildHisto([0.,1.,6.,16.,3.,0.],"SS","metmeff2Jet",0.1,0.1) dataSample.buildHisto([25.],"SR1sl2j","cuts",0.5) dataSample.buildHisto([1.,6.,24.,37.,7.,0.],"SSloose","metmeff2Jet",0.1,0.1) dataSample.buildHisto([403.,202.,93.,39.,11.,10.,4.,1.],"SLVR2","nJet",2) #************** # Discovery fit #************** if myFitType==FitType.Discovery: discovery = configMgr.addFitConfigClone(bkt,"Discovery") # s1l2jT = signal region/channel ssChannel = discovery.addChannel("cuts",["SS"],srNBins,srBinLow,srBinHigh) ssChannel.addSystematic(jes) ssChannel.addDiscoverySamples(["SS"],[1.],[0.],[100.],[kMagenta]) discovery.setSignalChannels([ssChannel]) dataSample.buildHisto([26.],"SS","cuts",0.5) #----------------------------- # Exclusion fits (1-step simplified model in this case) #----------------------------- if myFitType==FitType.Exclusion: sigSamples=["SM_GG_onestepCC_425_385_345"] dataSample.buildHisto([1.,6.,16.,3.,0.],"SS","metmeff2Jet",0.2,0.1)
return counter # ---------------------------------------------------------------- # # Now add the channels srCounter = addSR("cuts", channels, srCounter, srs, crList, 1, 0.5, 1.5) tlx.setSignalChannels(srList) userPrint("Setting up signal [END]") # ---------------------------------------------------------------- # doToys = userOpts.doToys hasHippo = doToys and 'hippo' in userOpts.gridForToys hasSig = doToys and signame in userOpts.gridForToys if not doToys or hasHippo or hasSig: exclusion = configMgr.addFitConfigClone(tlx,'TopLvlXML_Exclusion_%s'%s) print '!!!--- in LOOP ', s sigSample = Sample(s, kRed) sigSample.setStatConfig(useStat) if userOpts.splitMCSys: sigSample.addSystematic(sysObj.AR_mcstat_SIG) sigUncert = userOpts.sigUncert sigSample.setFileList([userOpts.sigFile]) if sigUncert == "up": sigSample.setWeights(("eventweight","syst_XSUP","1.0")) elif sigUncert == "down": sigSample.setWeights(("eventweight","syst_XSDOWN","1.0")) # TODO sigSample.addSystematic(sysObj.AR_all_JES_MC)
## Discovery fit #discovery = configMgr.adFitConfigClone(bkgOnly,"SimpleChannel_Discovery") #discovery.clearSystematics() #sigSample = Sample("discoveryMode",kBlue) #sigSample.setNormFactor("mu_SIG",1.0, 0.0, 5.0) #sigSample.setNormByTheory() #discovery.addSamples(sigSample) #discovery.setSignalSample(sigSample) ## Exclusion fits (MSUGRA grid) #sigSamples=["SU_180_360_0_10","SU_580_240_0_10","SU_740_330_0_10","SU_900_420_0_10","SU_1300_210_0_10"] sigSamples = ["SU_680_310_0_10","SU_440_145_0_10","SU_200_160_0_10","SU_440_340_0_10","SU_440_100_0_10","SU_120_130_0_10","SU_600_280_0_10","SU_320_115_0_10","SU_360_175_0_10","SU_920_310_0_10","SU_280_205_0_10","SU_1080_340_0_10","SU_40_280_0_10","SU_760_160_0_10","SU_200_115_0_10","SU_280_280_0_10","SU_40_160_0_10","SU_520_280_0_10","SU_120_220_0_10","SU_680_220_0_10","SU_40_115_0_10","SU_920_190_0_10","SU_320_130_0_10","SU_440_280_0_10","SU_360_100_0_10","SU_120_160_0_10","SU_1080_190_0_10","SU_840_250_0_10","SU_120_100_0_10","SU_120_340_0_10","SU_840_280_0_10","SU_80_115_0_10","SU_840_130_0_10","SU_320_175_0_10","SU_120_205_0_10","SU_520_100_0_10","SU_400_130_0_10","SU_360_310_0_10","SU_160_115_0_10","SU_1000_310_0_10","SU_40_220_0_10","SU_440_130_0_10","SU_1000_190_0_10","SU_80_220_0_10","SU_840_160_0_10","SU_120_145_0_10","SU_440_175_0_10","SU_360_280_0_10","SU_320_145_0_10","SU_400_160_0_10","SU_1000_340_0_10","SU_600_310_0_10","SU_320_190_0_10","SU_840_310_0_10","SU_200_220_0_10","SU_440_205_0_10","SU_360_205_0_10","SU_120_280_0_10","SU_1080_130_0_10","SU_160_145_0_10","SU_520_250_0_10","SU_840_100_0_10","SU_160_220_0_10","SU_120_190_0_10","SU_40_205_0_10","SU_280_250_0_10","SU_80_145_0_10","SU_200_175_0_10","SU_840_190_0_10","SU_240_145_0_10","SU_160_205_0_10","SU_400_115_0_10","SU_440_250_0_10","SU_600_340_0_10","SU_80_100_0_10","SU_520_190_0_10","SU_1160_190_0_10","SU_80_130_0_10","SU_400_190_0_10","SU_400_175_0_10","SU_600_130_0_10","SU_1080_100_0_10","SU_200_340_0_10","SU_1160_310_0_10","SU_440_160_0_10","SU_240_220_0_10","SU_200_100_0_10","SU_240_130_0_10","SU_360_130_0_10","SU_1000_250_0_10","SU_920_130_0_10","SU_240_190_0_10","SU_520_340_0_10","SU_40_175_0_10","SU_240_100_0_10","SU_400_145_0_10","SU_40_145_0_10","SU_240_205_0_10","SU_1080_280_0_10","SU_600_250_0_10","SU_360_145_0_10","SU_520_130_0_10","SU_1000_130_0_10","SU_440_310_0_10","SU_600_160_0_10","SU_920_280_0_10","SU_760_280_0_10","SU_280_190_0_10","SU_280_175_0_10","SU_120_310_0_10","SU_440_220_0_10","SU_1000_220_0_10","SU_1160_250_0_10","SU_400_205_0_10","SU_160_160_0_10","SU_1000_280_0_10","SU_1000_160_0_10","SU_400_100_0_10","SU_760_190_0_10","SU_680_160_0_10","SU_840_220_0_10","SU_360_340_0_10","SU_1080_220_0_10","SU_360_250_0_10","SU_760_130_0_10","SU_440_115_0_10","SU_240_160_0_10","SU_200_310_0_10","SU_200_145_0_10","SU_600_220_0_10","SU_280_130_0_10","SU_520_220_0_10","SU_1080_160_0_10","SU_40_190_0_10","SU_1160_160_0_10","SU_280_310_0_10","SU_920_160_0_10","SU_80_190_0_10","SU_40_310_0_10","SU_1160_130_0_10","SU_40_250_0_10","SU_40_100_0_10","SU_400_220_0_10","SU_40_340_0_10","SU_1000_100_0_10","SU_120_175_0_10","SU_280_220_0_10","SU_760_340_0_10","SU_240_115_0_10","SU_440_190_0_10","SU_1160_340_0_10","SU_600_100_0_10","SU_200_250_0_10","SU_280_145_0_10","SU_200_190_0_10","SU_200_205_0_10","SU_760_250_0_10","SU_120_250_0_10","SU_80_175_0_10","SU_40_130_0_10","SU_920_250_0_10","SU_80_160_0_10","SU_240_175_0_10","SU_280_100_0_10","SU_1080_310_0_10","SU_920_340_0_10","SU_120_115_0_10","SU_1160_100_0_10","SU_280_340_0_10","SU_1160_220_0_10","SU_200_130_0_10","SU_160_175_0_10","SU_360_220_0_10"] #if not 'sigSamples' in dir(): # sigSamples=["SU_680_310_0_10"] for sig in sigSamples: myTopLvl = configMgr.addFitConfigClone(bkgOnly,"SimpleChannel_%s"%sig) #myTopLvl.removeSystematic(jes) sigSample = Sample(sig,kBlue) sigSample.setNormFactor("mu_SIG", 1.0, 0., 5.0) sigXSSyst = Systematic("SigXSec",configMgr.weights,1.1,0.9,"user","overallSys") sigSample.addSystematic(sigXSSyst) #sigSample.addSystematic(jesSig) sigSample.setNormByTheory() myTopLvl.addSamples(sigSample) myTopLvl.setSignalSample(sigSample) ch = myTopLvl.getChannel("cuts",cutsRegions) myTopLvl.addSignalChannels(ch)
fitconfig.addSamples(discovery_sample) fitconfig.setSignalSample(discovery_sample) if myFitType == FitType.Exclusion: points = [] try: sigSamples except NameError: sigSamples = None for sig in sigSamples: print "Adding fit config for sample %s" % sig exclfit = configMgr.addFitConfigClone(fitconfig, sig) sig_sample = Sample(sig, ROOT.kOrange + 3) sig_sample.setNormByTheory() sig_sample.setStatConfig(useStat) sig_sample.setNormFactor("mu_SIG", 1., 0., 5.) if do_signal_theory_unc: configMgr.fixSigXSec = True sig_sample.addSystematic( sigXsec ) #--- Special uncertainty. Theory variations (creates extra files) exclfit.addSamples(sig_sample) exclfit.setSignalSample(sig_sample) exclfit.setSignalChannels(signal_channels)
mm2Jl.addSystematic(jes) # bkt.addValidationChannels([nJetSLVR2,metSLVR2,meffSLVR2,nBJetSLVR2,metmeffSLVR2,mm2J,srs1l2jTChannel]) bkt.addValidationChannels([nJetSLVR2,srs1l2jTChannel,mm2J,mm2Jl]) dataSample.buildHisto([0.,1.,6.,16.,3.,0.],"SS","metmeff2Jet",0.1,0.1) dataSample.buildHisto([25.],"SR1sl2j","cuts",0.5) dataSample.buildHisto([1.,6.,24.,37.,7.,0.],"SSloose","metmeff2Jet",0.1,0.1) dataSample.buildHisto([403.,202.,93.,39.,11.,10.,4.,1.],"SLVR2","nJet",2) #************** # Discovery fit #************** if myFitType==FitType.Discovery: discovery = configMgr.addFitConfigClone(bkt,"Discovery") # s1l2jT = signal region/channel ssChannel = discovery.addChannel("cuts",["SS"],srNBins,srBinLow,srBinHigh) ssChannel.addSystematic(jes) ssChannel.addDiscoverySamples(["SS"],[1.],[0.],[100.],[kMagenta]) discovery.addSignalChannels([ssChannel]) dataSample.buildHisto([26.],"SS","cuts",0.5) #----------------------------- # Exclusion fits (1-step simplified model in this case) #----------------------------- if myFitType==FitType.Exclusion: sigSamples=["SM_GG_onestepCC_425_385_345"] dataSample.buildHisto([1.,6.,16.,3.,0.],"SS","metmeff2Jet",0.2,0.1)
## Discovery fit #discovery = configMgr.adFitConfigClone(bkgOnly,"SimpleChannel_Discovery") #discovery.clearSystematics() #sigSample = Sample("discoveryMode",kBlue) #sigSample.setNormFactor("mu_SIG",0.5,0.,1.) #sigSample.setNormByTheory() #discovery.addSamples(sigSample) #discovery.setSignalSample(sigSample) ## Exclusion fits (MSUGRA grid) #sigSamples=["SU_180_360_0_10","SU_580_240_0_10","SU_740_330_0_10","SU_900_420_0_10","SU_1300_210_0_10"] sigSamples = ["SU_680_310_0_10","SU_440_145_0_10","SU_200_160_0_10","SU_440_340_0_10","SU_440_100_0_10","SU_120_130_0_10","SU_600_280_0_10","SU_320_115_0_10","SU_360_175_0_10","SU_920_310_0_10","SU_280_205_0_10","SU_1080_340_0_10","SU_40_280_0_10","SU_760_160_0_10","SU_200_115_0_10","SU_280_280_0_10","SU_40_160_0_10","SU_520_280_0_10","SU_120_220_0_10","SU_680_220_0_10","SU_40_115_0_10","SU_920_190_0_10","SU_320_130_0_10","SU_440_280_0_10","SU_360_100_0_10","SU_120_160_0_10","SU_1080_190_0_10","SU_840_250_0_10","SU_120_100_0_10","SU_120_340_0_10","SU_840_280_0_10","SU_80_115_0_10","SU_840_130_0_10","SU_320_175_0_10","SU_120_205_0_10","SU_520_100_0_10","SU_400_130_0_10","SU_360_310_0_10","SU_160_115_0_10","SU_1000_310_0_10","SU_40_220_0_10","SU_440_130_0_10","SU_1000_190_0_10","SU_80_220_0_10","SU_840_160_0_10","SU_120_145_0_10","SU_440_175_0_10","SU_360_280_0_10","SU_320_145_0_10","SU_400_160_0_10","SU_1000_340_0_10","SU_600_310_0_10","SU_320_190_0_10","SU_840_310_0_10","SU_200_220_0_10","SU_440_205_0_10","SU_360_205_0_10","SU_120_280_0_10","SU_1080_130_0_10","SU_160_145_0_10","SU_520_250_0_10","SU_840_100_0_10","SU_160_220_0_10","SU_120_190_0_10","SU_40_205_0_10","SU_280_250_0_10","SU_80_145_0_10","SU_200_175_0_10","SU_840_190_0_10","SU_240_145_0_10","SU_160_205_0_10","SU_400_115_0_10","SU_440_250_0_10","SU_600_340_0_10","SU_80_100_0_10","SU_520_190_0_10","SU_1160_190_0_10","SU_80_130_0_10","SU_400_190_0_10","SU_400_175_0_10","SU_600_130_0_10","SU_1080_100_0_10","SU_200_340_0_10","SU_1160_310_0_10","SU_440_160_0_10","SU_240_220_0_10","SU_200_100_0_10","SU_240_130_0_10","SU_360_130_0_10","SU_1000_250_0_10","SU_920_130_0_10","SU_240_190_0_10","SU_520_340_0_10","SU_40_175_0_10","SU_240_100_0_10","SU_400_145_0_10","SU_40_145_0_10","SU_240_205_0_10","SU_1080_280_0_10","SU_600_250_0_10","SU_360_145_0_10","SU_520_130_0_10","SU_1000_130_0_10","SU_440_310_0_10","SU_600_160_0_10","SU_920_280_0_10","SU_760_280_0_10","SU_280_190_0_10","SU_280_175_0_10","SU_120_310_0_10","SU_440_220_0_10","SU_1000_220_0_10","SU_1160_250_0_10","SU_400_205_0_10","SU_160_160_0_10","SU_1000_280_0_10","SU_1000_160_0_10","SU_400_100_0_10","SU_760_190_0_10","SU_680_160_0_10","SU_840_220_0_10","SU_360_340_0_10","SU_1080_220_0_10","SU_360_250_0_10","SU_760_130_0_10","SU_440_115_0_10","SU_240_160_0_10","SU_200_310_0_10","SU_200_145_0_10","SU_600_220_0_10","SU_280_130_0_10","SU_520_220_0_10","SU_1080_160_0_10","SU_40_190_0_10","SU_1160_160_0_10","SU_280_310_0_10","SU_920_160_0_10","SU_80_190_0_10","SU_40_310_0_10","SU_1160_130_0_10","SU_40_250_0_10","SU_40_100_0_10","SU_400_220_0_10","SU_40_340_0_10","SU_1000_100_0_10","SU_120_175_0_10","SU_280_220_0_10","SU_760_340_0_10","SU_240_115_0_10","SU_440_190_0_10","SU_1160_340_0_10","SU_600_100_0_10","SU_200_250_0_10","SU_280_145_0_10","SU_200_190_0_10","SU_200_205_0_10","SU_760_250_0_10","SU_120_250_0_10","SU_80_175_0_10","SU_40_130_0_10","SU_920_250_0_10","SU_80_160_0_10","SU_240_175_0_10","SU_280_100_0_10","SU_1080_310_0_10","SU_920_340_0_10","SU_120_115_0_10","SU_1160_100_0_10","SU_280_340_0_10","SU_1160_220_0_10","SU_200_130_0_10","SU_160_175_0_10","SU_360_220_0_10"] #if not 'sigSamples' in dir(): # sigSamples=["SU_680_310_0_10"] for sig in sigSamples: myTopLvl = configMgr.addFitConfigClone(bkgOnly,"SimpleChannel_%s"%sig) #myTopLvl.removeSystematic(jes) sigSample = Sample(sig,kBlue) sigSample.setNormFactor("mu_SIG",0.5,0.,1.) sigXSSyst = Systematic("SigXSec",configMgr.weights,1.1,0.9,"user","overallSys") sigSample.addSystematic(sigXSSyst) #sigSample.addSystematic(jesSig) sigSample.setNormByTheory() myTopLvl.addSamples(sigSample) myTopLvl.setSignalSample(sigSample) ch = myTopLvl.getChannel("cuts",cutsRegions) myTopLvl.setSignalChannels(ch)
configMgr.runOnlyNominalXSec = not runOptions.doTheoryBand() signals = signalGrid.getSampleList() # returns list of <Grid>_mX_mY # userPrint(" !! Only running over first signal point !! ") ok_samples = ["250.0_160.0", "225.0_135.0", "300.0_180.0", "300.0_150.0"] for s in signals: # use_this = False # for oksampk in ok_samples : # if oksampk in s : use_this = True # if not use_this : continue # if "225" not in s : continue # if "135" not in s : continue # s_ = s.replace(".0", "") s_ = s extlx = configMgr.addFitConfigClone(tlx, "Sig_%s" % s_) userPrint(" > Adding signal sample to exclusion fit config : %s" % s) sigSample_ = Sample(s, kPink) sigSample_.setFileList(signal_files) sigSample_.setNormByTheory() sigSample_.setStatConfig(not runOptions.doSplitMCsys()) if runOptions.doSplitMCsys(): sigSample_.addSystematic(sysObj.mcstat_SIG) ## set the signal weight to be the weight with no PUPW sigSample_.weights = ["eventweightNOPUPW"] if runOptions.doTheoryBand(): ### TODO check if we need the configMgr setRunOnlyNominalXSec sigXSSyst = Systematic( "SigXSec", ["eventweightNOPUPW"], 1.07, 0.93, "user", "overallSys"