configMgr.writeXML = True

##########################

# Give the analysis a name
configMgr.analysisName = "MyUserAnalysis"
configMgr.outputFileName = "results/%s_Output.root"%configMgr.analysisName

# Define cuts
configMgr.cutsDict["UserRegion"] = "1."

# Define weights
configMgr.weights = "1."

# Define samples
bkgSample = Sample("Bkg",kGreen-9)
bkgSample.setStatConfig(True)
bkgSample.buildHisto([nbkg],"UserRegion","cuts",0.5)
bkgSample.buildStatErrors([nbkgErr],"UserRegion","cuts")
bkgSample.addSystematic(corb)
bkgSample.addSystematic(ucb)

sigSample = Sample("Sig",kPink)
sigSample.setNormFactor("mu_Sig",1.,0.,100.)
sigSample.setStatConfig(True)
sigSample.setNormByTheory()
sigSample.buildHisto([nsig],"UserRegion","cuts",0.5)
sigSample.buildStatErrors([nsigErr],"UserRegion","cuts")
sigSample.addSystematic(cors)
sigSample.addSystematic(ucs)
Example #2
0
# KtScale uncertainty as histoSys - two-sided, no additional normalization
topKtScale = Systematic("KtScaleTop",configMgr.weights,ktScaleTopHighWeights,ktScaleTopLowWeights,"weight","overallNormHistoSys")
wzKtScale = Systematic("KtScaleWZ",configMgr.weights,ktScaleWHighWeights,ktScaleWLowWeights,"weight","overallNormHistoSys")


# JES uncertainty as shapeSys - one systematic per region (combine WR and TR), merge samples
jes = Systematic("JES","_NoSys","_JESup","_JESdown","tree","overallNormHistoSys")

statWRwz  = Systematic("SLWR_wz", "_NoSys","","","tree","shapeStat")
statWRtop = Systematic("SLWR_top","_NoSys","","","tree","shapeStat")

# name of nominal histogram for systematics
configMgr.nomName = "_NoSys"

# List of samples and their plotting colours
topSample = Sample("Top",kGreen-9)
topSample.setNormFactor("mu_Top",1.,0.,5.)
topSample.setStatConfig(useStat)
topSample.setNormRegions([("SLWR","nJet"),("SLTR","nJet")])
wzSample = Sample("WZ",kAzure+1)
wzSample.setNormFactor("mu_WZ",1.,0.,5.)
wzSample.setStatConfig(useStat)
wzSample.setNormRegions([("SLWR","nJet"),("SLTR","nJet")])
bgSample = Sample("BG",kYellow-3)
bgSample.setNormFactor("mu_BG",1.,0.,5.)
bgSample.setStatConfig(useStat)
bgSample.setNormRegions([("SLWR","nJet"),("SLTR","nJet")])
qcdSample = Sample("QCD",kGray+1)
qcdSample.setQCD(True,"histoSys")
qcdSample.setStatConfig(useStat)
dataSample = Sample("Data",kBlack)
Example #3
0
]

qFlipSys = formTreeSys("CFLIP_SYS", "__1up", "__1down", "overallSys")
fLepSys = formTreeSys("FAKE_LEP_E_SYS", "__1up", "__1down", "overallSys")
fLepSys = formTreeSys("FAKE_LEP_U_SYS", "__1up", "__1down", "overallSys")

#the input Lumi for mc is 0.001 but data driven bkg is obtained from 3.248fb-1 data
#so need a scale factor to convert data driven bkg back to 0.001 inputLumi...
dataDrivenBkgScale = "%e" % (configMgr.inputLumi / options.bkgLumi)

configMgr.nomName = ""

#-------------------------------------------
# List of samples and their plotting colours
#-------------------------------------------
wgammaSample = Sample("wgamma", kGreen - 9)
dibosonSample = Sample("diboson", kAzure + 1)
tribosonSample = Sample("triboson", kAzure + 2)
topXSample = Sample("topX", kRed + 1)
higgsSample = Sample("higgs", kRed + 2)

qFlipSample = Sample("qFlip", kBlue)
fLepSample = Sample("fLep", kYellow)

#cflipSample.setNormFactor("mu_CFlip",1.,0.7,1.3,True) #no sys for CFlip yet, use 30% uncertain non-constant normFac
#fakelepSample.setNormFactor("mu_FakeLep",1.,0.7,1.3,True) #no sys for CFlip yet, use 30% uncertain non-constant normFac

dataSample = Sample("data", kBlack)
dataSample.setData()
#dataSample.buildHisto([1.0],"SR","cuts",0.5)
#dataSample.setStatConfig(False)
##########################

# Give the analysis a name
configMgr.analysisName = "MyUserAnalysis_ShapeFactor"
configMgr.outputFileName = "results/%s_Output.root"%configMgr.analysisName

# Define cuts
configMgr.cutsDict["CR"] = "1."
configMgr.cutsDict["SR"] = "1."

# Define weights
configMgr.weights = "1."

# Define samples
bkgSample = Sample("Bkg",kGreen-9)
bkgSample.setNormByTheory(True)
bkgSample.buildHisto(nBkgCR,"CR","cuts",0.5)
bkgSample.buildHisto(nBkgSR,"SR","cuts",0.5)
bkgSample.addSystematic(bg1xsec)

ddSample = Sample("DataDriven",kGreen+2)
ddSample.addShapeFactor("DDShape")

sigSample = Sample("Sig",kPink)
sigSample.setNormFactor("mu_Sig",1.,0.2,1.5)
sigSample.buildHisto(nSigSR,"SR","cuts",0.5)
sigSample.setNormByTheory(True)
sigSample.addSystematic(sigxsec)

dataSample = Sample("Data",kBlack)
Example #5
0
                          _signalRegion,            # Specify the signal region
                          _ch,                      # Lepton Channel
                          _sleptonHand,             # Slepton Handedness to consider
                          bkgFile,                  # input bkg file
                          dataFile,                 # input data file   // dantrim
                          signalFile,               # input signal file
                          analysisName,             # Analysis Name for saving
                          20.3,                     # Input Lumi units
                          20.3,                     # Ouput Lumi units
                          "fb-1"                    # Input Lumi units
                          )


# Specify the samples to consider and use the correct names
# corresponding to your input trees
zxSample    = Sample("Zjets"       , kGreen+2)
fakeSample  = Sample("Fake"       , kGray)
higgsSample = Sample("Higgs"       , kYellow)
zvSample    = Sample("ZV"          , kGreen)
topSample   = Sample("Top"        , kViolet)
wwSample    = Sample("WW"          , kAzure-4)
dataSample  = Sample("Data_CENTRAL", kBlack)

#mcSamples  = [zxSample, higgsSample, zvSample, topSample, wwSample, dataSample]
##mcSamples  = [higgsSample, zvSample, wwSample, dataSample]

#bkgFiles  = []
#if userOpts.do2L:
#    bkgFiles.append( userOpts.bkgFile )
#for sample in mcSamples :
#    sample.setFileList(bkgFiles)
Example #6
0
                         "bTagWeight2Jet")
ktScaleTopLowWeights = ("genWeight", "eventWeight", "ktfacDownWeightTop",
                        "bTagWeight2Jet")
#topKtScale = Systematic("KtScaleTop",configMgr.weights,ktScaleTopHighWeights,ktScaleTopLowWeights,"weight","overallSys")
topKtScale = Systematic("KtScaleTop", configMgr.weights, ktScaleTopHighWeights,
                        ktScaleTopLowWeights, "weight", "histoSys")
#topKtScale = Systematic("KtScaleTop",configMgr.weights,ktScaleTopHighWeights,ktScaleTopLowWeights,"weight","normHistoSys")

#JES (tree-based)
jes = Systematic("JES", "_NoSys", "_JESup", "_JESdown", "tree", "overallSys")
configMgr.nomName = "_NoSys"

#-------------------------------------------
# List of samples and their plotting colours
#-------------------------------------------
topSample = Sample("Top", kGreen - 9)
#topSample.setNormFactor("mu_Top",1.,0.,5.)
wzSample = Sample("WZ", kAzure + 1)
#wzSample.setNormFactor("mu_WZ",1.,0.,5.)
dataSample = Sample("Data", kBlack)
dataSample.setData()
dataSample.buildHisto([0., 1., 5., 15., 4., 0.], "SR", "metmeff2Jet", 0.1, 0.1)
#dataSample.buildStatErrors([1.,1.,2.4,3.9,2.,0.],"SR","metmeff2Jet")

#**************
# Exclusion fit
#**************
if myFitType == FitType.Exclusion:

    # loop over all signal points
    for sig in sigSamples:
configMgr.writeXML = True

##########################

# Give the analysis a name
configMgr.analysisName = "PhotonMetAnalysis_Simple"
configMgr.outputFileName = "results/%s_Output.root" % configMgr.analysisName

# Define cuts
configMgr.cutsDict["SR"] = "1."

# Define weights
configMgr.weights = "1."

# Define samples
bkgSample = Sample("Bkg", ROOT.kGreen - 9)
bkgSample.setStatConfig(True)
bkgSample.buildHisto([nbkg], "SR", "cuts", 0.5)
bkgSample.addSystematic(ucb)

sigSample = Sample("GGM_GG_bhmix_%d_%d" % (args.m3, args.mu), ROOT.kOrange + 3)
sigSample.setNormFactor("mu_SIG", 1., 0., 10.)
#sigSample.setStatConfig(True)
sigSample.setNormByTheory()
sigSample.buildHisto([nsig], "SR", "cuts", 0.5)

dataSample = Sample("Data", ROOT.kBlack)
dataSample.setData()
dataSample.buildHisto([ndata], "SR", "cuts", 0.5)

# Define top-level
configMgr.nPoints=20       # number of values scanned of signal-strength for upper-limit determination of signal strength.

##########################

# Give the analysis a name
configMgr.analysisName = "MyUserAnalysis"
configMgr.outputFileName = "results/%s_Output.root"%configMgr.analysisName

# Define cuts
configMgr.cutsDict["UserRegion"] = "1."

# Define weights
configMgr.weights = "1."

# Define samples
bkgSample = Sample("Bkg",kGreen-9)
bkgSample.setStatConfig(True)
bkgSample.buildHisto([nbkg],"UserRegion","cuts")
bkgSample.buildStatErrors([nbkgErr],"UserRegion","cuts") ###
if(runMode=="exclusion"):
	bkgSample.addSystematic(corb)
bkgSample.addSystematic(ucb)

sigSample = Sample("Sig",kPink)
sigSample.setNormFactor("mu_Sig",1.,normFactorMin,normFactorMax)
sigSample.setStatConfig(False)
sigSample.setNormByTheory(False)
sigSample.buildHisto([nsig],"UserRegion","cuts")
sigSample.buildStatErrors([nsigErr],"UserRegion","cuts") ###
sigSample.addSystematic(cors) ###
sigSample.addSystematic(ucs) ###
Example #9
0
    True,  # Blind CR
    True,  # Blind VR
    _sigUncert,  # Specify uncertainty
    _grid,  # Specify grid
    _signalRegion,  # Specify the signal region
    _ch,  # Lepton Channel
    bkgFile,  # input bkg file
    signalFile,  # input signal file
    analysisName,  # Analysis Name for saving
    20.3,  # Input Lumi units
    20.3,  # Ouput Lumi units
    "fb-1",  # Input Lumi units
)

# Define Data and BG samples
dataSample = Sample("Data_CENTRAL", ROOT.kBlack)
zjetsSample = Sample("Zjets", ROOT.kGreen + 2)
fakeSample = Sample("fake", ROOT.kOrange - 4)
higgsSample = Sample("Higgs", ROOT.kYellow)
wwSample = Sample("WW", ROOT.kAzure - 4)
wzSample = Sample("WZ", ROOT.kGreen)
zzSample = Sample("ZZ", ROOT.kGreen - 4)
tribosonSample = Sample("triboson", ROOT.kAzure)
ttbarVSample = Sample("ttbarV", ROOT.kViolet)

#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
#                                 USER SHOULD NOT HAVE TO EDIT BELOW HERE                                    #
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#

# --------------------------------------------------------#
# Useful methods used below
Example #10
0
    configMgr.nPoints = 20  # number of values scanned of signal-strength for upper-limit determination of signal strength.

    ##########################

    # Give the analysis a name
    configMgr.analysisName = "SimpleUL_%s" % SR
    configMgr.outputFileName = "results/%s_Output.root" % configMgr.analysisName

    # Define cuts
    configMgr.cutsDict["UserRegion"] = "1."

    # Define weights
    configMgr.weights = "1."

    # Define samples
    bkgSample = Sample("Bkg", kGreen - 9)
    bkgSample.setStatConfig(False)
    bkgSample.buildHisto([nbkg], "UserRegion", "cuts")
    #bkgSample.buildStatErrors([nbkgErr],"UserRegion","cuts")
    #bkgSample.addSystematic(corb)
    bkgSample.addSystematic(ucb)

    dataSample = Sample("Data", kBlack)
    dataSample.setData()
    dataSample.buildHisto([ndata], "UserRegion", "cuts")

    # Define top-level
    ana = configMgr.addFitConfig("SPlusB")
    ana.addSamples([bkgSample, dataSample])
    #ana.setSignalSample(sigSample)
configMgr.setLumiUnits("fb-1")

configMgr.weights = ["1"]

configMgr.calculatorType = 2 # calculator type: 0= Frequentist, 1=Hybrid, 2=Aymptotic
configMgr.testStatType = 3 # # test stat type: 0=LEP, 1=Tevatron, 2=Profile Likelihood, 3=One-sided PLL
configMgr.nPoints = 20
configMgr.writeXML = True

configMgr.histCacheFile = "data/" + configMgr.analysisName + ".root"
configMgr.outputFileName = "results/" + configMgr.analysisName + "_Output.root"


print "is discovery ? %s" % (myFitType == FitType.Discovery)

sample_bkg0 = Sample("bkg0", ROOT.kBlue)
sample_bkg0.setStatConfig(True)

sample_bkg1 = Sample("bkg1", ROOT.kGreen)
sample_bkg1.setStatConfig(True)

sample_data = Sample("data", ROOT.kBlack)
sample_data.setData()

sample_sig = Sample("sig", ROOT.kRed)
sample_sig.setStatConfig(True)

all_samples = [sample_bkg0, sample_bkg1, sample_data]

# systematics
norm_syst_bkg0 = Systematic("Norm_Bkg0", configMgr.weights, 1.0 + 0.5, 1.0 - 0.5, "user", "userHistoSys")
Example #12
0
vv_df_file = hft_dir + "HFT_VVDF_13TeV_Nov22.root"
vv_sf_file = hft_dir + "HFT_VVSF_13TeV_Nov22.root"
drellyan_file = hft_dir + "HFT_BG_13TeV_DrellYan.root"
fake_file = hft_dir + "HFT_Fakes_13TeV_Jul27.root"  # scaling up the fakes from ICHEP
signal_file = ""
if gridname == "bWN":
    signal_file = hft_dir + "HFT_bWN_13TeV_Nov22.root"
else:
    userPrint('HFT not available for requested grid "%s"' % gridname)
    userPrint(" --> Exitting.")
    sys.exit()

## set the samples
# ttbar skip
ttbarSample = Sample("TTbar", ROOT.TColor.GetColor("#FC0D1B"))
vvDFSample = Sample("VVDF", ROOT.TColor.GetColor("#41C1FC"))
vvSFSample = Sample("VVSF", ROOT.TColor.GetColor("#41C1FC"))
# wwSample    = Sample("WW",      ROOT.TColor.GetColor("#41C1FC"))
stSample = Sample("ST", ROOT.TColor.GetColor("#DE080C"))
dysample = Sample("DrellYan", ROOT.kYellow)
ttvSample = Sample("TTV", ROOT.kCyan - 7)  # ROOT.kRed)
fakeSample = Sample("Fakes", ROOT.kOrange + 7)
higgsSample = Sample("Higgs", ROOT.TColor.GetColor("#ddc29a"))
print 45 * "-"
print "REMOVING W+JETS SAMPLE"
print "REMOVING W+JETS SAMPLE"
print "REMOVING W+JETS SAMPLE"
print "REMOVING W+JETS SAMPLE"
print "REMOVING W+JETS SAMPLE"
print 45 * "-"
wjetsSample = Sample("Wjets", ROOT.TColor.GetColor("#5E9AD6"))
configMgr.writeXML = True

##########################

# Give the analysis a name
configMgr.analysisName = "MyUpperLimitAnalysis_SS"
configMgr.outputFileName = "results/%s_Output.root"%configMgr.analysisName

# Define cuts
configMgr.cutsDict["UserRegion"] = "1."

# Define weights
configMgr.weights = "1."

# Define samples
bkgSample = Sample("Bkg",kGreen-9)
bkgSample.setStatConfig(True)
bkgSample.buildHisto([nbkg],"UserRegion","cuts",0.5)


bkgSample.addSystematic(ucb)

sigSample = Sample("Sig",kPink)
sigSample.setNormFactor("mu_SS",1.,0.,10.)
#sigSample.setStatConfig(True)
sigSample.setNormByTheory()
sigSample.buildHisto([nsig],"UserRegion","cuts",0.5)



ktScaleTopHighWeights = ("genWeight","eventWeight","ktfacUpWeightTop","bTagWeight2Jet")
ktScaleTopLowWeights = ("genWeight","eventWeight","ktfacDownWeightTop","bTagWeight2Jet")
topKtScale = Systematic("KtScaleTop",configMgr.weights,ktScaleTopHighWeights,ktScaleTopLowWeights,"weight","overallSys")

#JES (tree-based)
jes = Systematic("JES","_NoSys","_JESup","_JESdown","tree","overallSys")
configMgr.nomName = "_NoSys"

#-------------------------------------------
# List of samples and their plotting colours
#-------------------------------------------
topSample = Sample("Top",kGreen-9)
#topSample.setNormFactor("mu_Top",1.,0.,5.)
wzSample = Sample("WZ",kAzure+1)
#wzSample.setNormFactor("mu_WZ",1.,0.,5.)
dataSample = Sample("Data",kBlack)
dataSample.setData()
dataSample.buildHisto([3.],"SR","cuts",0.5)

#**************
# Discovery fit
#**************

if myFitType==FitType.Discovery:
 
   #Fit config instance
   discoveryFitConfig = configMgr.addTopLevelXML("Discovery")
   meas=discoveryFitConfig.addMeasurement(name="NormalMeasurement",lumi=1.0,lumiErr=0.039)
   meas.addPOI("mu_Discovery")
 
   #Samples
Example #15
0
##########################

# Give the analysis a name
configMgr.analysisName = "MyUserAnalysis_ShapeFactor"
configMgr.outputFileName = "results/%s_Output.root"%configMgr.analysisName

# Define cuts
configMgr.cutsDict["CR"] = "1."
configMgr.cutsDict["SR"] = "1."

# Define weights
configMgr.weights = "1."

# Define samples
bkgSample = Sample("Bkg",kGreen-9)
bkgSample.setNormByTheory(True)
bkgSample.buildHisto(nBkgCR,"CR","cuts",0.5)
bkgSample.buildHisto(nBkgSR,"SR","cuts",0.5)
bkgSample.addSystematic(bg1xsec)

ddSample = Sample("DataDriven",kGreen+2)
ddSample.addShapeFactor("DDShape")

sigSample = Sample("Sig",kPink)
sigSample.setNormFactor("mu_Sig",1.,0.2,1.5)
sigSample.buildHisto(nSigSR,"SR","cuts",0.5)
sigSample.setNormByTheory(True)
sigSample.addSystematic(sigxsec)

dataSample = Sample("Data",kBlack)
configMgr.nPoints=50       # number of values scanned of signal-strength for upper-limit determination of signal strength.

##########################

# Give the analysis a name
configMgr.analysisName = "MI_SR2_95CL_incl"
configMgr.outputFileName = "results/%s_Output.root"%configMgr.analysisName

# Define cuts
configMgr.cutsDict["UserRegion"] = "1."

#Define weights
configMgr.weights = "1."

#Define samples
bkgSample = Sample("Bkg",kGreen-9)
bkgSample.setStatConfig(True)
bkgSample.setNormByTheory(False)     #this has to be true for samples with normalisation taken from MC, it means include lumi error (set false if data driven)
bkgSample.buildHisto([nbkg],"UserRegion","cuts")
bkgSample.buildStatErrors([nbkgErr],"UserRegion","cuts")
bkgSample.addSystematic(ucb)

sigSample = Sample("Sig",kPink)
sigSample.setNormFactor("mu_Sig",1.0,0.,24645.6)
sigSample.setStatConfig(True)
sigSample.setNormByTheory(False)    #this has to be false since xsec is scaled by mu
sigSample.buildHisto([nsig],"UserRegion","cuts")
sigSample.buildStatErrors([nsigErr],"UserRegion","cuts")

dataSample = Sample("Data",kBlack)
dataSample.setData()
configMgr.outputLumi = 139  # fb-1
configMgr.setLumiUnits("fb-1")

configMgr.weights = ["1"]

configMgr.calculatorType = 2  # calculator type: 0= Frequentist, 1=Hybrid, 2=Aymptotic
configMgr.testStatType = 3  # # test stat type: 0=LEP, 1=Tevatron, 2=Profile Likelihood, 3=One-sided PLL
configMgr.nPoints = 20
configMgr.writeXML = True

configMgr.histCacheFile = "data/" + configMgr.analysisName + ".root"
configMgr.outputFileName = "results/" + configMgr.analysisName + "_Output.root"

print "is discovery ? %s" % (myFitType == FitType.Discovery)

sample_bkg0 = Sample("bkg0", ROOT.kBlue)
sample_bkg0.setStatConfig(True)

#sample_bkg1 = Sample("bkg1", ROOT.kGreen)
#sample_bkg1.setStatConfig(True)
#
#sample_bkg2 = Sample("bkg2", ROOT.kMagenta)
#sample_bkg2.setStatConfig(True)

sample_data = Sample("data", ROOT.kBlack)
sample_data.setData()

#sample_sig = Sample("sig", ROOT.kRed)
#sample_sig.setStatConfig(True)

all_samples = [sample_bkg0,
configMgr.nPoints=20       # number of values scanned of signal-strength for upper-limit determination of signal strength.
#configMgr.blindSR = True
##########################

# Give the analysis a name
configMgr.analysisName = "UpperLimitScharm%s" % os.environ['REGION']
configMgr.outputFileName = "results/%s_Output.root"%configMgr.analysisName

# Define cuts
configMgr.cutsDict["UserRegion"] = "1."

# Define weights
configMgr.weights = "1."

# Define samples
bkgSample = Sample("Bkg",0)
bkgSample.setStatConfig(True)
bkgSample.buildHisto([nbkg],"UserRegion","BDTG")


bkgSample.addSystematic(ucb)
sigSample = Sample("Sig",0)
sigSample.setNormFactor("mu_Sig",1.,0.,30.)

#sigSample.setStatConfig(True)
sigSample.setNormByTheory()
sigSample.buildHisto([nsig],"UserRegion","BDTG")


dataSample = Sample("Data",0)
dataSample.setData()
Example #19
0
                        1. - theoSysTopNumber, "user", "userOverallSys")
theoSysW = Systematic("theoSysW", configMgr.weights, 1.0 + theoSysWNumber,
                      1.0 - theoSysWNumber, "user", "userOverallSys")

#diboson
theoSysDiboson = Systematic("theoSysDiboson", configMgr.weights, 1.5, 0.5,
                            "user", "userOverallSys")

#photon systematics in SR for Z
gammaToZSyst = Systematic("gammaToZSyst", configMgr.weights, 1.25, 0.75,
                          "user", "userOverallSys")

#-------------------------------------------
# List of samples and their plotting colours
#-------------------------------------------
dibosonSample = Sample("Diboson", kRed + 3)
dibosonSample.setTreeName("Diboson_SRAll")
dibosonSample.setFileList(dibosonFiles)
dibosonSample.setStatConfig(useStat)
dibosonSample.addSystematic(theoSysDiboson)

topSample = Sample("Top", kGreen - 9)
topSample.setTreeName("Top_SRAll")
topSample.setNormFactor("mu_Top", 1., 0., 500.)
topSample.setFileList(topFiles)
topSample.setStatConfig(useStat)

qcdSample = Sample("MCMultijet", kOrange + 2)
qcdSample.setTreeName("QCD_SRAll")
qcdSample.setNormFactor("mu_MCMultijet", 1., 0., 500.)
qcdSample.setFileList(qcdFiles)
    )  # number of values scanned of signal-strength for upper-limit determination of signal strength.

    ##########################

    # Give the analysis a name
    configMgr.analysisName = "SimpleUL_%s" % SR
    configMgr.outputFileName = "results/%s_Output.root" % configMgr.analysisName

    # Define cuts
    configMgr.cutsDict["UserRegion"] = "1."

    # Define weights
    configMgr.weights = "1."

    # Define samples
    bkgSample = Sample("Bkg", kGreen - 9)
    bkgSample.setStatConfig(False)
    bkgSample.buildHisto([nbkg], "UserRegion", "cuts")
    # bkgSample.buildStatErrors([nbkgErr],"UserRegion","cuts")
    # bkgSample.addSystematic(corb)
    bkgSample.addSystematic(ucb)

    dataSample = Sample("Data", kBlack)
    dataSample.setData()
    dataSample.buildHisto([ndata], "UserRegion", "cuts")

    # Define top-level
    ana = configMgr.addFitConfig("SPlusB")
    ana.addSamples([bkgSample, dataSample])
    # ana.setSignalSample(sigSample)
                                     nominal = nominal_weight_bkg,
                                     high = [nominal_weight_bkg, '(1+0.5*(ht_signal>500))'],
                                     low  = [nominal_weight_bkg, '(1-0.5*(ht_signal>500))'],
                                     type = 'weight',
                                     method = 'overallSys')

# --------------------------------------------
# - List of samples and their plotting colours
# --------------------------------------------
sample_list_bkg  = []
sample_list_data = []
sample_list_sig  = []

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Other
other_sample = Sample("Other", kAzure+8)
other_sample.setStatConfig(use_stat)
other_sample.setNormByTheory()
sample_list_bkg.append(other_sample)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# single top
single_top_sample = Sample("SingleTop", kGreen-1)

single_top_sample.setStatConfig(use_stat)
single_top_sample.setNormByTheory()
sample_list_bkg.append(single_top_sample)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Z/gamma*
z_sample = Sample("ZGamma", kRed+1 )
Example #22
0
phoScaleElttgamma = Systematic("phoScale",configMgr.weights, 1.013,1-.013, "user","userOverallSys")
phoScaleElttbarDilep = Systematic("phoScale",configMgr.weights, 1.027, 1-.027, "user","userOverallSys")
phoScaleElst = Systematic("phoScale",configMgr.weights, 1.036, 1-.036, "user","userOverallSys")
phoScaleEldiboson = Systematic("phoScale",configMgr.weights, 1.029, 1-.029, "user","userOverallSys")
phoScaleElZgamma = Systematic("phoScale",configMgr.weights, 1.025, 1-.025, "user","userOverallSys")

# phoScaleMuWgamma = Systematic("phoScale",configMgr.weights, 1.018, 1-.018, "user","userOverallSys")
# phoScaleMuttgamma = Systematic("phoScale",configMgr.weights, 1.015,1-.015, "user","userOverallSys")
# phoScaleMuttbarDilep = Systematic("phoScale",configMgr.weights, 1.028, 1-.028, "user","userOverallSys")
# phoScaleMust = Systematic("phoScale",configMgr.weights, 1.023, 1-.023, "user","userOverallSys")
# phoScaleMudiboson = Systematic("phoScale",configMgr.weights, 1.040, 1-.040, "user","userOverallSys")
# phoScaleMuZgamma = Systematic("phoScale",configMgr.weights, 1.025, 1-.025, "user","userOverallSys")

## List of samples and their plotting colours. Associate dedicated systematics if applicable.

ttbargamma = Sample("ttbargamma",46) # brick
ttbargamma.setNormByTheory()
ttbargamma.setStatConfig(True)
ttbargamma.addSystematic(ttbargammaNorm)

Wgamma = Sample("Wgamma",7) # cyan
Wgamma.setNormFactor("mu_Wgamma",1.,0.,5.)
Wgamma.setNormRegions([("WCRhHTEl", "cuts")])
Wgamma.setStatConfig(True)
#Wgamma.addSystematic(WgammaNorm)

Zgamma = Sample("Zgamma",kViolet) # cyan
Zgamma.setNormByTheory()
Zgamma.setStatConfig(True)
Zgamma.addSystematic(ZgammaNorm)
                                     nominal = nominal_weight_bkg,
                                     high = [nominal_weight_bkg, '(1+0.5*(ht_signal>500))'],
                                     low  = [nominal_weight_bkg, '(1-0.5*(ht_signal>500))'],
                                     type = 'weight',
                                     method = 'overallSys')

# --------------------------------------------
# - List of samples and their plotting colours
# --------------------------------------------
sample_list_bkg  = []
sample_list_data = []
sample_list_sig  = []

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Other
other_sample = Sample("Other", kAzure+8)
other_sample.setStatConfig(use_stat)
other_sample.setNormByTheory()
sample_list_bkg.append(other_sample)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# single top
single_top_sample = Sample("SingleTop", kGreen-1)

single_top_sample.setStatConfig(use_stat)
single_top_sample.setNormByTheory()
sample_list_bkg.append(single_top_sample)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Z/gamma*
z_sample = Sample("ZGamma", kRed+1 )
log.debug(pprint.pformat(configMgr.cutsDict, width=60))

log.info("Wait 3 seconds for you to panic if these settings are wrong")
wait(3)
log.info("No panicking detected, continuing...")

#######################################################################
# List of samples and their plotting colours
#######################################################################

#--------------------------
# Diboson
#--------------------------
# NB: note that theoSys on diboson are applied on the level of the region definitions,
# since we have one for the SR and one for the CR
dibosonSample = Sample(zlFitterConfig.dibosonSampleName, kRed+3)
dibosonSample.setTreeName("Diboson_SRAll")
dibosonSample.setFileList(dibosonFiles)
dibosonSample.setStatConfig(zlFitterConfig.useStat)

#--------------------------
# QCD
#--------------------------
qcdSample = Sample(zlFitterConfig.qcdSampleName, kOrange+2)
qcdSample.setTreeName("QCD_SRAll")
qcdSample.setNormFactor("mu_"+zlFitterConfig.qcdSampleName, 1., 0., 500.)
qcdSample.setFileList(qcdFiles)
qcdSample.setStatConfig(zlFitterConfig.useStat)

qcdWeight = 1
nJets = channel.nJets
    mu1ScaleTFSysW  = Systematic("mu1ScaleTFSys", configMgr.weights, 1.0+WMap['mu1ScaleWeightUp'][level][chn],1.0-WMap['mu1ScaleWeightDown'][level][chn], "user","userOverallSys")
    mu2ScaleTFSysW  = Systematic("mu2ScaleTFSys", configMgr.weights, 1.0+WMap['mu2ScaleWeightUp'][level][chn],1.0-WMap['mu2ScaleWeightDown'][level][chn], "user","userOverallSys")
    matchScaleTFSysW  = Systematic("matchScaleTFSys", configMgr.weights, 1.0+WMap['matchScaleWeightUp'][level][chn],1.0, "user","userOverallSys")
    
    
    mu1ScaleTFSysZ  = Systematic("mu1ScaleTFSys", configMgr.weights, 1.0+ZMap['mu1ScaleWeightUp'][level][chn],1.0-ZMap['mu1ScaleWeightDown'][level][chn], "user","userOverallSys")
    mu2ScaleTFSysZ  = Systematic("mu2ScaleTFSys", configMgr.weights, 1.0+ZMap['mu2ScaleWeightUp'][level][chn],1.0-ZMap['mu2ScaleWeightDown'][level][chn], "user","userOverallSys")

    sherpaTFSysTop  = Systematic("sherpaTFSys", configMgr.weights, 1.0+TopMap['topSherpa'][level][chn],1.0-TopMap['topSherpa'][level][chn], "user","userOverallSys")
    


#-------------------------------------------
# List of samples and their plotting colours
#-------------------------------------------
dibosonSample = Sample("Diboson",kRed+3)
dibosonSample.setTreeName("Diboson_SRAll")
dibosonSample.setFileList(dibosonFiles)
dibosonSample.setStatConfig(useStat)
if useSyst: dibosonSample.addSystematic(theoSysDiboson)


topSample = Sample("ttbar",kGreen-9)
topSample.setTreeName("Top_SRAll")
topSample.setNormFactor("mu_Top",1.,0.,500.)
topSample.setFileList(topFiles)
topSample.setStatConfig(useStat) 
if useTheoSys:
    if useSyst: topSample.addSystematic(theoSysTop)
    ####topSample.addSystematic(mu1ScaleSysTop)
    ####topSample.addSystematic(mu2ScaleSysTop)
                              configMgr.weights + ["matchScaleWeightDown"], 
                              "weight", "overallNormHistoSys") 

# QCD
theoSysQCD = Systematic("theoSysQCD", configMgr.weights, 1.0 + theoSysQCDNumber,1.0-theoSysQCDNumber, "user", "userOverallSys")
QCDGausSys = Systematic("QCDGausSys", "", "_ghi", "_glo", "tree", "overallNormHistoSys")
QCDTailSys = Systematic("QCDTailSys", "", "_thi", "_tlo", "tree", "overallNormHistoSys")

# Diboson
theoSysDiboson = Systematic("theoSysDiboson",  configMgr.weights,  1.5, 0.5,  "user", "userOverallSys")

#-------------------------------------------
# List of samples and their plotting colours
#-------------------------------------------
# Diboson
dibosonSample = Sample("Diboson", kRed+3)
dibosonSample.setTreeName("Diboson_SRAll")
dibosonSample.setFileList(dibosonFiles)
dibosonSample.setStatConfig(useStat)

# Top
topSample = Sample("ttbar", kGreen-9)
topSample.setTreeName("Top_SRAll")
topSample.setNormFactor("mu_Top", 1., 0., 500.)
topSample.setFileList(topFiles)
topSample.setStatConfig(useStat) 

if useTheoSys:
    topSample.addSystematic(theoSysTop)

if useSyst :
#MC theo systematics
theoSysTop = Systematic("theoSysTop", configMgr.weights, 1.+theoSysTopNumber,1.-theoSysTopNumber, "user","userOverallSys")
theoSysW = Systematic("theoSysW", configMgr.weights, 1.0+theoSysWNumber,1.0-theoSysWNumber, "user","userOverallSys")

#diboson
theoSysDiboson = Systematic("theoSysDiboson", configMgr.weights, 1.5,0.5, "user","userOverallSys")

#photon systematics in SR for Z
gammaToZSyst = Systematic("gammaToZSyst", configMgr.weights, 1.25,0.75, "user","userOverallSys")



#-------------------------------------------
# List of samples and their plotting colours
#-------------------------------------------
dibosonSample = Sample("Diboson",kRed+3)
dibosonSample.setTreeName("Diboson_SRAll")
dibosonSample.setFileList(dibosonFiles)
dibosonSample.setStatConfig(useStat)
dibosonSample.addSystematic(theoSysDiboson)

topSample = Sample("Top",kGreen-9)
topSample.setTreeName("Top_SRAll")
topSample.setNormFactor("mu_Top",1.,0.,50000.)
topSample.setFileList(topFiles)
topSample.setStatConfig(useStat)

qcdSample = Sample("MCMultijet",kOrange+2)
qcdSample.setTreeName("QCD_SRAll")
qcdSample.setNormFactor("mu_MCMultijet",1.,0.,500.)
qcdSample.setFileList(qcdFiles)
Example #28
0
def common_setting(mass):
    from configManager import configMgr
    from ROOT import kBlack, kGray, kRed, kPink, kViolet, kBlue, kAzure, kGreen, \
        kOrange
    from configWriter import Sample
    from systematic import Systematic
    import os

    color_dict = {
        "Zbb": kAzure,
        "Zbc": kAzure,
        "Zbl": kAzure,
        "Zcc": kAzure,
        "Zcl": kBlue,
        "Zl": kBlue,
        "Wbb": kGreen,
        "Wbc": kGreen,
        "Wbl": kGreen,
        "Wcc": kGreen,
        "Wcl": kGreen,
        "Wl": kGreen,
        "ttbar": kOrange,
        "stop": kOrange,
        "stopWt": kOrange,
        "ZZPw": kGray,
        "WZPw": kGray,
        "WWPw": kGray,
        "fakes": kPink,
        "Zjets": kAzure,
        "Wjets": kGreen,
        "top": kOrange,
        "diboson": kGray,
        "$Z\\tau\\tau$+HF": kAzure,
        "$Z\\tau\\tau$+LF": kBlue,
        "$W$+jets": kGreen,
        "$Zee$": kViolet,
        "Zhf": kAzure,
        "Zlf": kBlue,
        "Zee": kViolet,
        "others": kViolet,
        signal_prefix + "1000": kRed,
        signal_prefix + "1100": kRed,
        signal_prefix + "1200": kRed,
        signal_prefix + "1400": kRed,
        signal_prefix + "1600": kRed,
        signal_prefix + "1800": kRed,
        signal_prefix + "2000": kRed,
        signal_prefix + "2500": kRed,
        signal_prefix + "3000": kRed,
        # Add your new processes here
        "VH": kGray + 2,
        "VHtautau": kGray + 2,
        "ttH": kGray + 2,
    }

    ##########################

    # Setting the parameters of the hypothesis test
    configMgr.doExclusion = True  # True=exclusion, False=discovery
    configMgr.nTOYs = 10000  # default=5000
    configMgr.calculatorType = 0  # 2=asymptotic calculator, 0=frequentist calculator
    configMgr.testStatType = 3  # 3=one-sided profile likelihood test statistic (LHC default)
    configMgr.nPoints = 30  # number of values scanned of signal-strength for upper-limit determination of signal strength.
    configMgr.writeXML = False
    configMgr.seed = 40
    configMgr.toySeedSet = True
    configMgr.toySeed = 400

    # Pruning
    # - any overallSys systematic uncertainty if the difference of between the up variation and the nominal and between
    #   the down variation and the nominal is below a certain (user) given threshold
    # - for histoSys types, the situation is more complex:
    #   - a first check is done if the integral of the up histogram - the integral of the nominal histogram is smaller
    #     than the integral of the nominal histogram and the same for the down histogram
    #   - then a second check is done if the shape of the up, down and nominal histograms is very similar Only when both
    #     conditions are fulfilled the systematics will be removed.
    # default is False, so the pruning is normally not enabled
    configMgr.prun = True
    # The threshold to decide if an uncertainty is small or not is set by configMgr.prunThreshold = 0.005
    # where the number gives the fraction of deviation with respect to the nominal histogram below which an uncertainty
    # is considered to be small. The default is currently set to 0.01, corresponding to 1 % (This might be very aggressive
    # for the one or the other analyses!)
    configMgr.prunThreshold = 0.005
    # method 1: a chi2 test (this is still a bit experimental, so watch out if this is working or not)
    # method 2: checking for every bin of the histograms that the difference between up variation and nominal and down (default)
    configMgr.prunMethod = 2
    # variation and nominal is below a certain threshold.
    # Smoothing: HistFitter does not provide any smoothing tools.
    # More Details: https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/HistFitterAdvancedTutorial#Pruning_in_HistFitter

    ##########################

    # Keep SRs also in background fit confuguration
    configMgr.keepSignalRegionType = True
    configMgr.blindSR = BLIND

    # Give the analysis a name
    configMgr.analysisName = "bbtautau" + "X" + mass
    configMgr.histCacheFile = "data/" + configMgr.analysisName + ".root"
    configMgr.outputFileName = "results/" + configMgr.analysisName + "_Output.root"

    # Define cuts
    configMgr.cutsDict["SR"] = "1."

    # Define weights
    configMgr.weights = "1."

    # Define samples
    list_samples = []

    yields_mass = yields[mass]
    for process, yields_process in yields_mass.items():
        if process == 'data' or signal_prefix in process: continue
        # print("-> {} / Colour: {}".format(process, color_dict[process]))
        bkg = Sample(str(process), color_dict[process])
        bkg.setStatConfig(stat_config)
        # OLD: add lumi uncertainty (bkg/sig correlated, not for data-driven fakes)
        # NOW: add lumi by hand
        bkg.setNormByTheory(False)
        noms = yields_process["nEvents"]
        errors = yields_process["nEventsErr"] if use_mcstat else [0.0]
        # print("  nEvents (StatError): {} ({})".format(noms, errors))
        bkg.buildHisto(noms, "SR", my_disc, 0.5)
        bkg.buildStatErrors(errors, "SR", my_disc)
        if not stat_only and not no_syst:
            if process == 'fakes':
                key_here = "ATLAS_FF_1BTAG_SIDEBAND_Syst_hadhad"
                if not impact_check_continue(dict_syst_check, key_here):
                    bkg.addSystematic(
                        Systematic(key_here, configMgr.weights, 1.50, 0.50,
                                   "user", syst_type))
            else:
                key_here = "ATLAS_Lumi_Run2_hadhad"
                if not impact_check_continue(dict_syst_check, key_here):
                    bkg.addSystematic(
                        Systematic(key_here, configMgr.weights, 1.017, 0.983,
                                   "user", syst_type))
            for key, values in yields_process.items():
                if 'ATLAS' not in key: continue
                if impact_check_continue(dict_syst_check, key): continue
                # this should not be applied on the Sherpa
                if process == 'Zhf' and key == 'ATLAS_DiTauSF_ZMODEL_hadhad':
                    continue
                if process == 'Zlf' and key == 'ATLAS_DiTauSF_ZMODEL_hadhad':
                    continue
                ups = values[0]
                downs = values[1]
                systUpRatio = [
                    u / n if n != 0. else float(1.) for u, n in zip(ups, noms)
                ]
                systDoRatio = [
                    d / n if n != 0. else float(1.)
                    for d, n in zip(downs, noms)
                ]
                bkg.addSystematic(
                    Systematic(str(key), configMgr.weights, systUpRatio,
                               systDoRatio, "user", syst_type))
        list_samples.append(bkg)

    # FIXME: This is unusual!
    top = Sample('top', kOrange)
    top.setStatConfig(False)  # No stat error
    top.setNormByTheory(False)  # consider lumi for it
    top.buildHisto([0.00001], "SR", my_disc, 0.5)  # small enough
    # HistFitter can accept such large up ratio
    # Systematic(name, weight, ratio_up, ratio_down, syst_type, syst_fistfactory_type)
    if not stat_only and not no_syst:
        key_here = 'ATLAS_TTBAR_YIELD_UPPER_hadhad'
        if not impact_check_continue(dict_syst_check, key_here):
            top.addSystematic(
                Systematic(key_here, configMgr.weights, unc_ttbar[mass], 0.9,
                           "user", syst_type))
    list_samples.append(top)

    sigSample = Sample("Sig", kRed)
    sigSample.setNormFactor("mu_Sig", 1., 0., 100.)
    #sigSample.setStatConfig(stat_config)
    sigSample.setStatConfig(False)
    sigSample.setNormByTheory(False)
    noms = yields_mass[signal_prefix + mass]["nEvents"]
    errors = yields_mass[signal_prefix +
                         mass]["nEventsErr"] if use_mcstat else [0.0]
    sigSample.buildHisto([n * MY_SIGNAL_NORM * 1e-3 for n in noms], "SR",
                         my_disc, 0.5)
    #sigSample.buildStatErrors(errors, "SR", my_disc)
    for key, values in yields_mass[signal_prefix + mass].items():
        if 'ATLAS' not in key: continue
        if impact_check_continue(dict_syst_check, key):
            continue
        ups = values[0]
        downs = values[1]
        systUpRatio = [
            u / n if n != 0. else float(1.) for u, n in zip(ups, noms)
        ]
        systDoRatio = [
            d / n if n != 0. else float(1.) for d, n in zip(downs, noms)
        ]
        if not stat_only and not no_syst:
            sigSample.addSystematic(
                Systematic(str(key), configMgr.weights, systUpRatio,
                           systDoRatio, "user", syst_type))
    if not stat_only and not no_syst:
        key_here = "ATLAS_SigAccUnc_hadhad"
        if not impact_check_continue(dict_syst_check, key_here):
            sigSample.addSystematic(
                Systematic(key_here, configMgr.weights,
                           [1 + unc_sig_acc[mass] for i in range(my_nbins)],
                           [1 - unc_sig_acc[mass]
                            for i in range(my_nbins)], "user", syst_type))
        key_here = "ATLAS_Lumi_Run2_hadhad"
        if not impact_check_continue(dict_syst_check, key_here):
            sigSample.addSystematic(
                Systematic(key_here, configMgr.weights, 1.017, 0.983, "user",
                           syst_type))

    list_samples.append(sigSample)

    # Set observed and expected number of events in counting experiment
    n_SPlusB = yields_mass[signal_prefix +
                           mass]["nEvents"][0] + sum_of_bkg(yields_mass)[0]
    n_BOnly = sum_of_bkg(yields_mass)[0]
    if BLIND:
        # configMgr.useAsimovSet = True # Use the Asimov dataset
        # configMgr.generateAsimovDataForObserved = True # Generate Asimov data as obsData for UL
        # configMgr.useSignalInBlindedData = False
        ndata = sum_of_bkg(yields_mass)
    else:
        try:
            ndata = yields_mass["data"]["nEvents"]
        except:
            ndata = [0. for _ in range(my_nbins)]

    lumiError = 0.017  # Relative luminosity uncertainty

    dataSample = Sample("Data", kBlack)
    dataSample.setData()
    dataSample.buildHisto(ndata, "SR", my_disc, 0.5)
    list_samples.append(dataSample)

    # Define top-level
    ana = configMgr.addFitConfig("SPlusB")
    ana.addSamples(list_samples)
    ana.setSignalSample(sigSample)

    # Define measurement
    meas = ana.addMeasurement(name="NormalMeasurement",
                              lumi=1.0,
                              lumiErr=lumiError / 100000.)
    # make it very small so that pruned
    # we use the one added by hand
    meas.addPOI("mu_Sig")
    #meas.statErrorType = "Poisson"
    # Fix the luminosity in HistFactory to constant
    meas.addParamSetting("Lumi", True, 1)

    # Add the channel
    chan = ana.addChannel(my_disc, ["SR"], my_nbins, my_xmin, my_xmax)
    chan.blind = BLIND
    #chan.statErrorType = "Poisson"
    ana.addSignalChannels([chan])

    # These lines are needed for the user analysis to run
    # Make sure file is re-made when executing HistFactory
    if configMgr.executeHistFactory:
        if os.path.isfile("data/%s.root" % configMgr.analysisName):
            os.remove("data/%s.root" % configMgr.analysisName)
Example #29
0
# KtScale uncertainty as histoSys - two-sided, no additional normalization
topKtScale = Systematic("KtScaleTop", configMgr.weights, ktScaleTopHighWeights,
                        ktScaleTopLowWeights, "weight", "normHistoSys")
wzKtScale = Systematic("KtScaleWZ", configMgr.weights, ktScaleWHighWeights,
                       ktScaleWLowWeights, "weight", "normHistoSys")

# JES uncertainty as shapeSys - one systematic per region (combine WR and TR), merge samples
jes = Systematic("JES", "_NoSys", "_JESup", "_JESdown", "tree", "normHistoSys")
mcstat = Systematic("mcstat", "_NoSys", "_NoSys", "_NoSys", "tree",
                    "shapeStat")

# name of nominal histogram for systematics
configMgr.nomName = "_NoSys"

# List of samples and their plotting colours
topSample = Sample("Top", kGreen - 9)
topSample.setNormFactor("mu_Top", 1., 0., 5.)
topSample.setStatConfig(useStat)
topSample.setNormRegions([("SLWR", "nJet"), ("SLTR", "nJet")])
wzSample = Sample("WZ", kAzure + 1)
wzSample.setNormFactor("mu_WZ", 1., 0., 5.)
wzSample.setStatConfig(useStat)
wzSample.setNormRegions([("SLWR", "nJet"), ("SLTR", "nJet")])
bgSample = Sample("BG", kYellow - 3)
bgSample.setNormFactor("mu_BG", 1., 0., 5.)
bgSample.setStatConfig(useStat)
bgSample.setNormRegions([("SLWR", "nJet"), ("SLTR", "nJet")])
qcdSample = Sample("QCD", kGray + 1)
qcdSample.setQCD(True, "histoSys")
qcdSample.setStatConfig(useStat)
dataSample = Sample("Data", kBlack)
Example #30
0
    'VRL3',
    'VRL4',
    'VRE',
]

regions += srs

for r in regions:
    configMgr.cutsDict[r] = ''  # need by HF but not used anyway o.O

#-----------------
# Samples
#-----------------

# W/Z + jets
wjets_sample = Sample('wjets', color("wjets"))
zjets_sample = Sample('zjets', color("zjets"))

wjets_sample.setNormByTheory()
zjets_sample.setNormByTheory()

# ttbar
ttbar_sample = Sample('ttbar', color("ttbar"))
ttbarg_sample = Sample('ttgamma', color("ttbarg"))

ttbar_sample.setNormByTheory()
ttbarg_sample.setNormFactor("mu_t", 1., 0., 2.)

# W/Z gamma
wgamma_sample = Sample('wgamma', color("wgamma"))
zllgamma_sample = Sample('zllgamma', color("zllgamma"))
configMgr.outputLumi = 139  # fb-1
configMgr.setLumiUnits("fb-1")

configMgr.weights = ["1"]

configMgr.calculatorType = 2  # calculator type: 0= Frequentist, 1=Hybrid, 2=Aymptotic
configMgr.testStatType = 3  # # test stat type: 0=LEP, 1=Tevatron, 2=Profile Likelihood, 3=One-sided PLL
configMgr.nPoints = 20
configMgr.writeXML = True

configMgr.histCacheFile = "data/" + configMgr.analysisName + ".root"
configMgr.outputFileName = "results/" + configMgr.analysisName + "_Output.root"

print "is discovery ? %s" % (myFitType == FitType.Discovery)

sample_bkg0 = Sample("bkg0", ROOT.kBlue)
sample_bkg0.setStatConfig(True)

sample_bkg1 = Sample("bkg1", ROOT.kGreen)
sample_bkg1.setStatConfig(True)

sample_bkg2 = Sample("bkg2", ROOT.kMagenta)
sample_bkg2.setStatConfig(True)

sample_data = Sample("data", ROOT.kBlack)
sample_data.setData()

sample_sig = Sample("sig", ROOT.kRed)
sample_sig.setStatConfig(True)

all_samples = [sample_bkg0, sample_bkg1, sample_bkg2, sample_data]
configMgr.writeXML = True

##########################

# Give the analysis a name
configMgr.analysisName = "MyUpperLimitAnalysis_SS"
configMgr.outputFileName = "results/%s_Output.root" % configMgr.analysisName

# Define cuts
configMgr.cutsDict["UserRegion"] = "1."

# Define weights
configMgr.weights = "1."

# Define samples
bkgSample = Sample("Bkg", kGreen - 9)
bkgSample.setStatConfig(True)
bkgSample.buildHisto([nbkg], "UserRegion", "cuts", 0.5)

bkgSample.addSystematic(ucb)

sigSample = Sample("Sig", kPink)
sigSample.setNormFactor("mu_SS", 1., 0., 10.)
#sigSample.setStatConfig(True)
sigSample.setNormByTheory()
sigSample.buildHisto([nsig], "UserRegion", "cuts", 0.5)

dataSample = Sample("Data", kBlack)
dataSample.setData()
dataSample.buildHisto([ndata], "UserRegion", "cuts", 0.5)
Example #33
0
                          _signalRegion,            # Specify the signal region
                          _ch,                      # Lepton Channel
                          _sleptonHand,             # slepton handedness
                          bkgFile,                  # input bkg file
                          dataFile,                 # input data file
                          signalFile,               # input signal file
                          analysisName,             # Analysis Name for saving
                          20.3,                     # Input Lumi units
                          20.3,                     # Ouput Lumi units
                          "fb-1"                    # Input Lumi units
                          )

##############################################################
## Define Data and BG samples                               ##
##############################################################
dataSample       = Sample("Data_CENTRAL", ROOT.kBlack    )
zjetsSample      = Sample("Zjets"       , ROOT.kGreen+2  )
higgsSample      = Sample("Higgs"       , ROOT.kYellow   )
zvSample         = Sample("ZV"          , ROOT.kGreen    )
wwSample         = Sample("WW"          , ROOT.kAzure-4  )
topSample        = Sample("Top"         , ROOT.kViolet   )
fakeSample       = Sample("Fake"        , ROOT.kOrange-4 )


# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #
#                                 USER SHOULD NOT HAVE TO EDIT BELOW HERE                                      #
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #
Example #34
0
## set scan range for the upper limit
#configMgr.scanRange = (0., 1.)

## Suffix of nominal tree
configMgr.nomName = "_NoSys"

## Map regions to cut strings
configMgr.cutsDict = {"SR":"1.0"}

## Systematics to be applied
jes = Systematic("JES","_NoSys","_JESup","_JESdown","tree","overallSys")
#jes = Systematic("JES",None,1.2,0.8,"user","overallSys")

## List of samples and their plotting colours
allbkgSample = Sample("Bkg",kGreen)
#allbkgSample.setNormFactor("mu_AllBkg",1.,0.,5.)
#allbkgSample.addSystematic(jesWT)
dataSample = Sample("Data",kBlack)
dataSample.setData()

commonSamples = [allbkgSample,dataSample]
configMgr.plotColours = [kGreen,kBlack]

## Parameters of the Measurement
measName = "BasicMeasurement"
measLumi = 1.
measLumiError = 0.039

## Parameters of Channels
cutsRegions = ["SR"]
phoScaleElttgamma = Systematic("phoScale",configMgr.weights, 1.013,1-.013, "user","userOverallSys")
phoScaleElttbarDilep = Systematic("phoScale",configMgr.weights, 1.027, 1-.027, "user","userOverallSys")
phoScaleElst = Systematic("phoScale",configMgr.weights, 1.036, 1-.036, "user","userOverallSys")
phoScaleEldiboson = Systematic("phoScale",configMgr.weights, 1.029, 1-.029, "user","userOverallSys")
phoScaleElZgamma = Systematic("phoScale",configMgr.weights, 1.025, 1-.025, "user","userOverallSys")

phoScaleMuWgamma = Systematic("phoScale",configMgr.weights, 1.018, 1-.018, "user","userOverallSys")
phoScaleMuttgamma = Systematic("phoScale",configMgr.weights, 1.015,1-.015, "user","userOverallSys")
phoScaleMuttbarDilep = Systematic("phoScale",configMgr.weights, 1.028, 1-.028, "user","userOverallSys")
phoScaleMust = Systematic("phoScale",configMgr.weights, 1.023, 1-.023, "user","userOverallSys")
phoScaleMudiboson = Systematic("phoScale",configMgr.weights, 1.040, 1-.040, "user","userOverallSys")
phoScaleMuZgamma = Systematic("phoScale",configMgr.weights, 1.025, 1-.025, "user","userOverallSys")

## List of samples and their plotting colours. Associate dedicated systematics if applicable.

ttbargamma = Sample("ttbargamma",46) # brick
ttbargamma.setNormByTheory()
ttbargamma.setStatConfig(True)
ttbargamma.addSystematic(ttbargammaNorm)

Wgamma = Sample("Wgamma",7) # cyan
Wgamma.setNormByTheory()
Wgamma.setStatConfig(True)
Wgamma.addSystematic(WgammaNorm)

Zgamma = Sample("Zgamma",7) # cyan
Zgamma.setNormByTheory()
Zgamma.setStatConfig(True)
Zgamma.addSystematic(ZgammaNorm)

Zleplep = Sample("Zleplep",7) # cyan
## Suffix of nominal tree
configMgr.nomName = "_NoSys"

## Map regions to cut strings
configMgr.cutsDict = {"SR":"1.0"}

## Systematics to be applied
jes = Systematic("JES","_NoSys","_JESup","_JESdown","tree","overallSys")
#jes = Systematic("JES",None,1.2,0.8,"user","overallSys")

## List of samples and their plotting colours
allbkgSample = Sample("Bkg",kGreen)
#allbkgSample.setNormFactor("mu_AllBkg",1.,0.,5.)
#allbkgSample.addSystematic(jesWT)
dataSample = Sample("Data",kBlack)
dataSample.setData()

commonSamples = [allbkgSample,dataSample]
configMgr.plotColours = [kGreen,kBlack]

## Parameters of the Measurement
measName = "BasicMeasurement"
measLumi = 1.
measLumiError = 0.039

## Parameters of Channels
cutsRegions = ["SR"]
cutsNBins = 1
cutsBinLow = 0.0
cutsBinHigh = 1.0
log.debug(pprint.pformat(configMgr.cutsDict, width=60))

log.info("Wait 3 seconds for you to panic if these settings are wrong")
wait(3)
log.info("No panicking detected, continuing...")

#######################################################################
# List of samples and their plotting colours
#######################################################################

#--------------------------
# Diboson
#--------------------------
# NB: note that theoSys on diboson are applied on the level of the region definitions,
# since we have one for the SR and one for the CR
dibosonSample = Sample(zlFitterConfig.dibosonSampleName, kRed+3)
dibosonSample.setTreeName("Diboson_SRAll")
dibosonSample.setFileList(dibosonFiles)
dibosonSample.setStatConfig(zlFitterConfig.useStat)

#--------------------------
# QCD
#--------------------------
qcdSample = Sample(zlFitterConfig.qcdSampleName, kOrange+2)
if zlFitterConfig.useDDQCDsample:#normWeight is 0 => remove it
    qcdSample.setTreeName("Data_SRAll")
else :
    qcdSample.setTreeName("QCD_SRAll")
qcdSample.setNormFactor("mu_"+zlFitterConfig.qcdSampleName, 1., 0., 50000000.)
qcdSample.setFileList(qcdFiles)
qcdSample.setStatConfig(zlFitterConfig.useStat)
#--------------------

# KtScale uncertainty as histoSys - two-sided, no additional normalization
topKtScale = Systematic("KtScaleTop",configMgr.weights,ktScaleTopHighWeights,ktScaleTopLowWeights,"weight","normHistoSys")
wzKtScale = Systematic("KtScaleWZ",configMgr.weights,ktScaleWHighWeights,ktScaleWLowWeights,"weight","normHistoSys")


# JES uncertainty as shapeSys - one systematic per region (combine WR and TR), merge samples
jes = Systematic("JES","_NoSys","_JESup","_JESdown","tree","normHistoSys")
mcstat = Systematic("mcstat", "_NoSys", "_NoSys", "_NoSys", "tree", "shapeStat")

# name of nominal histogram for systematics
configMgr.nomName = "_NoSys"

# List of samples and their plotting colours
topSample = Sample("Top",kGreen-9)
topSample.setNormFactor("mu_Top",1.,0.,5.)
topSample.setStatConfig(useStat)
topSample.setNormRegions([("SLWR","nJet"),("SLTR","nJet")])
wzSample = Sample("WZ",kAzure+1)
wzSample.setNormFactor("mu_WZ",1.,0.,5.)
wzSample.setStatConfig(useStat)
wzSample.setNormRegions([("SLWR","nJet"),("SLTR","nJet")])
bgSample = Sample("BG",kYellow-3)
bgSample.setNormFactor("mu_BG",1.,0.,5.)
bgSample.setStatConfig(useStat)
bgSample.setNormRegions([("SLWR","nJet"),("SLTR","nJet")])
qcdSample = Sample("QCD",kGray+1)
qcdSample.setQCD(True,"histoSys")
qcdSample.setStatConfig(useStat)
dataSample = Sample("Data",kBlack)
Example #39
0
configMgr.nPoints = 20  # number of values scanned of signal-strength for upper-limit determination of signal strength.

##########################

# Give the analysis a name
configMgr.analysisName = "MyUserAnalysis"
configMgr.outputFileName = "results/%s_Output.root" % configMgr.analysisName

# Define cuts
configMgr.cutsDict["UserRegion"] = "1."

# Define weights
configMgr.weights = "1."

# Define samples
bkgSample = Sample("Bkg", kGreen - 9)
bkgSample.setStatConfig(False)
bkgSample.buildHisto([nbkg], "UserRegion", "cuts")
# bkgSample.buildStatErrors([nbkgErr],"UserRegion","cuts")
# bkgSample.addSystematic(corb)
bkgSample.addSystematic(ucb)

sigSample = Sample("Sig", kPink)
sigSample.setNormFactor("mu_Sig", 1.0, 0.0, 100.0)
sigSample.setStatConfig(False)
sigSample.setNormByTheory(False)
sigSample.buildHisto([nsig], "UserRegion", "cuts")
# sigSample.buildStatErrors([nsigErr],"UserRegion","cuts")
# sigSample.addSystematic(cors)
# sigSample.addSystematic(ucs)
Example #40
0
# ---------------------
# - List of systematics
# ---------------------
# generic systematic -- placeholder for now
gen_syst = Systematic( "gen_syst" , configMgr.weights , 1.0 + 0.30 , 1.0 - 0.30 , "user" , "userOverallSys" )

# JES uncertainty as shapeSys - one systematic per region (combine WR and TR), merge samples
# jes = Systematic("JES","_NoSys","_JESup","_JESdown","tree","overallNormHistoSys")

# --------------------------------------------
# - List of samples and their plotting colours
# --------------------------------------------
sample_list = []

# ttbar
ttbar_sample = Sample( "ttbar" , kGreen-2 )
ttbar_sample.setNormFactor("mu_ttbar",1.,0.,5.)
ttbar_sample.setStatConfig(use_stat)
ttbar_sample.setNormByTheory()
sample_list.append(ttbar_sample)

# single top
single_top_sample = Sample( "SingleTop" , kGreen-1 )
single_top_sample.setNormFactor("mu_st",1.,0.,5.)
single_top_sample.setStatConfig(use_stat)
single_top_sample.setNormByTheory()
sample_list.append(single_top_sample)

# Z/gamma*
z_sample = Sample( "Z" , kRed+1 )
z_sample.setNormFactor("mu_z",1.,0.,5.)
Example #41
0
    def create_samples(self):
        print "total samples:",len(sample_names)
        for index in range(len(sample_names)):
            sample_name = sample_names[index]
            sample = Sample(sample_name, sample_colors[index])
            
            file_name = input_dir+sample_name+"_combined.root"
            yields_dic = self.read_hist(file_name)
            print "Sample:", sample_name+";",
            if "data" in sample_name:
                sample.setData()
                self.data_sample = sample
                for region in regions:
                    nevts, nerror = yields_dic[region]
                    sample.buildHisto([nevts], region, "cuts", 0.5)
                    print region,str(round(nevts,3))+";",
                print
                continue

            sample.setNormByTheory()
            for region in regions:
                nevts, nerror = yields_dic[region]
                nevts *= weight
                nerror *= weight
                if "Dijets" in sample_name and "SR" in region:
                    if self.cut == 10:
                        nevts = 4.07
                        nerror = math.sqrt(nevts)
                    if self.cut == 14:
                        nevts = 2.42
                        nerror = math.sqrt(nevts)
                sample.buildHisto([nevts], region, "cuts", 0.5)
                sample.buildStatErrors([nerror], region, "cuts")
                print region,str(round(nevts,3))+";",
            print
            #sample.setStatConfig(True)
            sample.setFileList([in_file_path])
            ## add systematic??
            sample.addSystematic(Systematic(sample_name+"_stats",\
                        configMgr.weights, 1.2, 0.8, "user", "userOverallSys"))
            #for systematic in self.sys_common:
                #sample.addSystematic(systematic)
            self.set_norm_factor(sample)
#topKtScale = Systematic("KtScaleTop",configMgr.weights,ktScaleTopHighWeights,ktScaleTopLowWeights,"weight","overallSys")
topKtScale = Systematic("KtScaleTop",configMgr.weights,ktScaleTopHighWeights,ktScaleTopLowWeights,"weight","histoSys")
#topKtScale = Systematic("KtScaleTop",configMgr.weights,ktScaleTopHighWeights,ktScaleTopLowWeights,"weight","normHistoSys")

#JES (tree-based)
jes = Systematic("JES","_NoSys","_JESup","_JESdown","tree","overallSys")
configMgr.nomName = "_NoSys"

#-------------------------------------------
# List of samples and their plotting colours
#-------------------------------------------
topSample = Sample("Top",kGreen-9)
#topSample.setNormFactor("mu_Top",1.,0.,5.)
wzSample = Sample("WZ",kAzure+1)
#wzSample.setNormFactor("mu_WZ",1.,0.,5.)
dataSample = Sample("Data",kBlack)
dataSample.setData()
dataSample.buildHisto([0.,1.,5.,15.,4.,0.],"SR","metmeff2Jet",0.1,0.1)
#dataSample.buildStatErrors([1.,1.,2.4,3.9,2.,0.],"SR","metmeff2Jet")

#**************
# Exclusion fit
#**************
if myFitType==FitType.Exclusion:
    
    # loop over all signal points
    for sig in sigSamples:
    # Fit config instance
       exclusionFitConfig = configMgr.addFitConfig("Exclusion_"+sig)
       meas=exclusionFitConfig.addMeasurement(name="NormalMeasurement",lumi=1.0,lumiErr=0.039)
       meas.addPOI("mu_SIG")
samples = []
channels = []
POIs = []
signal_sample = None

# prepare the fit configuration
ana = configMgr.addFitConfig("shape_fit")
meas = ana.addMeasurement(name="shape_fit", lumi=1.0, lumiErr=0.01)

# load all MC templates ...
for sample_name, template_name, template_color, is_floating, is_signal in zip(
        sample_names, template_names, template_colors, normalization_floating,
        signal_samples):

    cur_sample = Sample(sample_name, template_color)

    if is_floating:
        normalization_name = "mu_" + sample_name
        cur_sample.setNormFactor(normalization_name, 1, 0, 100)

        if is_signal:
            POIs.append(normalization_name)
            signal_sample = cur_sample

    # ... for all regions
    for region_name, region_infile in zip(region_names, region_infiles):
        binvals, edges = HistogramImporter.import_histogram(
            os.path.join(indir, region_infile), template_name)
        bin_width = edges[1] - edges[0]
    'VRL1', 'VRL2', 'VRL3', 'VRL4', 'VRZ',
    'VRLW1', 'VRLT1', 'VRLW3', 'VRLT3',
    ]

regions += srs

for r in regions:
    configMgr.cutsDict[r] = '' # need by HF but not used anyway o.O


#-----------------
# Samples 
#-----------------

# W/Z + jets
wjets_sample = Sample('wjets', color("wjets"))
zjets_sample = Sample('zjets', color("zjets"))

wjets_sample.setNormByTheory()
zjets_sample.setNormByTheory()

# ttbar
ttbar_sample  = Sample('ttbar', color("ttbar"))
ttbarg_sample = Sample('ttbarg', color("ttbarg"))

ttbar_sample.setNormByTheory()
ttbarg_sample.setNormFactor("mu_t", 1., 0., 2.)   

# W/Z gamma
wgamma_sample     = Sample('wgamma', color("wgamma"))
zllgamma_sample   = Sample('zllgamma', color("zllgamma"))
    "KtScaleTop", configMgr.weights, ktScaleTopHighWeights, ktScaleTopLowWeights, "weight", "histoSys"
)
# topKtScale = Systematic("KtScaleTop",configMgr.weights,ktScaleTopHighWeights,ktScaleTopLowWeights,"weight","normHistoSys")

# JES (tree-based)
jes = Systematic("JES", "_NoSys", "_JESup", "_JESdown", "tree", "overallSys")
configMgr.nomName = "_NoSys"

# -------------------------------------------
# List of samples and their plotting colours
# -------------------------------------------
topSample = Sample("Top", kGreen - 9)
# topSample.setNormFactor("mu_Top",1.,0.,5.)
wzSample = Sample("WZ", kAzure + 1)
# wzSample.setNormFactor("mu_WZ",1.,0.,5.)
dataSample = Sample("Data", kBlack)
dataSample.setData()


# **************
# Exclusion fit
# **************

# Fit config instance
exclusionFitConfig = configMgr.addTopLevelXML("Exclusion")
meas = exclusionFitConfig.addMeasurement(name="NormalMeasurement", lumi=1.0, lumiErr=0.039)
meas.addPOI("mu_SIG")

# Samples
exclusionFitConfig.addSamples([topSample, wzSample, dataSample])
Example #46
0
ktScaleTopHighWeights = ("genWeight", "eventWeight", "ktfacUpWeightTop",
                         "bTagWeight2Jet")
ktScaleTopLowWeights = ("genWeight", "eventWeight", "ktfacDownWeightTop",
                        "bTagWeight2Jet")
topKtScale = Systematic("KtScaleTop", configMgr.weights, ktScaleTopHighWeights,
                        ktScaleTopLowWeights, "weight", "overallSys")

#JES (tree-based)
jes = Systematic("JES", "_NoSys", "_JESup", "_JESdown", "tree", "overallSys")
configMgr.nomName = "_NoSys"

#-------------------------------------------
# List of samples and their plotting colours
#-------------------------------------------
topSample = Sample("Top", kGreen - 9)
#topSample.setNormFactor("mu_Top",1.,0.,5.)
wzSample = Sample("WZ", kAzure + 1)
#wzSample.setNormFactor("mu_WZ",1.,0.,5.)
dataSample = Sample("Data", kBlack)
dataSample.setData()
dataSample.buildHisto([3.], "SR", "cuts", 0.5)

#**************
# Discovery fit
#**************

if myFitType == FitType.Discovery:

    #Fit config instance
    discoveryFitConfig = configMgr.addTopLevelXML("Discovery")
Example #47
0
                                     nominal = nominal_weight_bkg,
                                     high = [nominal_weight_bkg, '(1+0.5*(ht_signal>500))'],
                                     low  = [nominal_weight_bkg, '(1-0.5*(ht_signal>500))'],
                                     type = 'weight',
                                     method = 'overallSys')

# --------------------------------------------
# - List of samples and their plotting colours
# --------------------------------------------
sample_list_bkg  = []
sample_list_data = []
sample_list_sig  = []

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Other
other_sample = Sample("Other", kAzure+8)
other_sample.setStatConfig(use_stat)
other_sample.setNormByTheory()
sample_list_bkg.append(other_sample)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# single top
single_top_sample = Sample("SingleTop", kGreen-1)

single_top_sample.setStatConfig(use_stat)
single_top_sample.setNormByTheory()
sample_list_bkg.append(single_top_sample)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Z/gamma*
z_sample = Sample("ZGamma", kRed+1 )
Example #48
0
# Define top-level
ana = configMgr.addFitConfig("ABCD")
# Define measurement
meas = ana.addMeasurement(name="NormalMeasurement",
                          lumi=1.0,
                          lumiErr=lumiError)
meas.addPOI("mu_A")
"""
meas.addParamSetting("mu_dummy_D",True,1)
meas.addParamSetting("mu_dummy_B",True,1)
meas.addParamSetting("mu_dummy_C",True,1)
"""
#meas.addParamSetting("Lumi",True,1)

#create test data
dataSample = Sample("Data", kBlack)
dataSample.setData()
dataSample.buildHisto([ndataA], "A", "cuts", 0.5)
dataSample.buildHisto([ndataB], "B", "cuts", 0.5)
dataSample.buildHisto([ndataC], "C", "cuts", 0.5)
dataSample.buildHisto([ndataD], "D", "cuts", 0.5)

backgroundSample = Sample("NonQCDBackground", kBlack)
backgroundSample.buildHisto([nbkgA], "A", "cuts", 0.5)
backgroundSample.buildHisto([nbkgB], "B", "cuts", 0.5)
backgroundSample.buildHisto([nbkgC], "C", "cuts", 0.5)
backgroundSample.buildHisto([nbkgD], "D", "cuts", 0.5)

ana.addSamples([dataSample, backgroundSample])

#make dummy samples