def backgroundsWithRooMultiPdf(): modelGroupToUse = modelGroupForMultiPdf pathToDir = os.path.join(backgroundfitswithroomultipdfDir, args.outDirName) aux.mkdir(pathToDir) for category in categoriesToUse: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) counter = 0; for model in modelGroupToUse.models: model.color = colors[counter] counter += 1 funcs.backgroundsWithRooMultiPdf((category, diMuonMass125), ws, data, modelGroupToUse.models, settings, pathToDir=pathToDir, groupName=modelGroupToUse.name)
def signalFitInterpolations(): pathToDir = os.path.join(singalfitinterpolationsDir, args.outDirName) aux.mkdir(pathToDir) for category in categoriesToUse: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) funcs.signalFitInterpolation( category, ws, [ (vbf120, tripleGaus120, diMuonMass120), (vbf125, tripleGaus125, diMuonMass125), (vbf130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir)
def signalFitInterpolations(): pathToDir = os.path.join(singalfitinterpolationsDir, args.outDirName) aux.mkdir(pathToDir) for category in categoriesToUse: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) funcs.signalFitInterpolation(category, ws, [ (vbf120, tripleGaus120, diMuonMass120), (vbf125, tripleGaus125, diMuonMass125), (vbf130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir )
def backgroundFits(): pathToDir = os.path.join(backgroundfitsDir, args.outDirName) aux.mkdir(pathToDir) for category in categoriesToUse: for modelGroup in backgroundModelGroups: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) modelsToUse = modelGroup.models counter = 0; for m in modelsToUse: m.color = colors[counter] counter+=1 funcs.backgroundFits( (category, diMuonMass125), ws, data, modelsToUse, settings, pathToDir=pathToDir,groupName=modelGroup.name)
def backgroundsWithRooMultiPdf(): modelGroupToUse = modelGroupForMultiPdf pathToDir = os.path.join(backgroundfitswithroomultipdfDir, args.outDirName) aux.mkdir(pathToDir) for category in categoriesToUse: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) counter = 0 for model in modelGroupToUse.models: model.color = colors[counter] counter += 1 funcs.backgroundsWithRooMultiPdf((category, diMuonMass125), ws, data, modelGroupToUse.models, settings, pathToDir=pathToDir, groupName=modelGroupToUse.name)
def ftest(): pathToDir = os.path.join(ftestDir, args.outDirName) aux.mkdir(pathToDir) fTestResults = {} for category in categoriesToUse: fTestResults[category] = {} for modelGroup in orderedModelGroups: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) counter = 0; for m in modelGroup.models: m.color = colors[counter] counter+=1 modelToBeUsed, values = funcs.ftestPerFamily( (category, diMuonMass125), ws, data, modelGroup, settings, pathToDir=pathToDir) fTestResults[category][modelGroup.name] = values funcs.plotFTestResults(fTestResults, pathToDir=pathToDir)
def backgroundFits(): pathToDir = os.path.join(backgroundfitsDir, args.outDirName) aux.mkdir(pathToDir) for category in categoriesToUse: for modelGroup in backgroundModelGroups: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) modelsToUse = modelGroup.models counter = 0 for m in modelsToUse: m.color = colors[counter] counter += 1 funcs.backgroundFits((category, diMuonMass125), ws, data, modelsToUse, settings, pathToDir=pathToDir, groupName=modelGroup.name)
def signalFits(): pathToDir = os.path.join(signalfitsDir, args.outDirName) aux.mkdir(pathToDir) initialValuesFromTH1 = True for category in categoriesToUse: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) for modelToUse in [singleGaus125, doubleGaus125, tripleGaus125]: modelToUse.color = R.kRed funcs.signalFit((category, diMuonMass125), ws, vbf125, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass125), ws, glu125, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass125), ws, wm125, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass125), ws, wp125, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass125), ws, zh125, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) aux.buildMassVariable(ws, **diMuonMass120) for modelToUse in [singleGaus120, doubleGaus120, tripleGaus120]: modelToUse.color = R.kRed funcs.signalFit((category, diMuonMass120), ws, vbf120, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass120), ws, glu120, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass120), ws, wm120, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass120), ws, wp120, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass120), ws, zh120, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) aux.buildMassVariable(ws, **diMuonMass130) for modelToUse in [singleGaus130, doubleGaus130, tripleGaus130]: modelToUse.color = R.kRed funcs.signalFit((category, diMuonMass130), ws, vbf130, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass130), ws, glu130, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass130), ws, wm130, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass130), ws, wp130, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1) funcs.signalFit((category, diMuonMass130), ws, zh130, modelToUse, settings, pathToDir=pathToDir, initialValuesFromTH1=initialValuesFromTH1)
def ftest(): pathToDir = os.path.join(ftestDir, args.outDirName) aux.mkdir(pathToDir) fTestResults = {} for category in categoriesToUse: fTestResults[category] = {} for modelGroup in orderedModelGroups: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) counter = 0 for m in modelGroup.models: m.color = colors[counter] counter += 1 modelToBeUsed, values = funcs.ftestPerFamily( (category, diMuonMass125), ws, data, modelGroup, settings, pathToDir=pathToDir) fTestResults[category][modelGroup.name] = values funcs.plotFTestResults(fTestResults, pathToDir=pathToDir)
def signalFitInterpolationsWithSpline(): pathToDir = os.path.join(signalfitinterpolationswithsplineDir, args.outDirName) aux.mkdir(pathToDir) for category in categoriesToUse: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) aux.buildMH(ws, mhmin=120, mhmax=130) print "*" * 80 print "Generating Single Gaus Splines" print "*" * 80 funcs.signalFitInterpolationWithSpline( category, ws, [ (vbf120, singleGaus120, diMuonMass120), (vbf125, singleGaus125, diMuonMass125), (vbf130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (glu120, singleGaus120, diMuonMass120), (glu125, singleGaus125, diMuonMass125), (glu130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (wp120, singleGaus120, diMuonMass120), (wp125, singleGaus125, diMuonMass125), (wp130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (wm120, singleGaus120, diMuonMass120), (wm125, singleGaus125, diMuonMass125), (wm130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (zh120, singleGaus120, diMuonMass120), (zh125, singleGaus125, diMuonMass125), (zh130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) print "*" * 80 print "Generating Double Gaus Splines" print "*" * 80 funcs.signalFitInterpolationWithSpline( category, ws, [ (vbf120, doubleGaus120, diMuonMass120), (vbf125, doubleGaus125, diMuonMass125), (vbf130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (glu120, doubleGaus120, diMuonMass120), (glu125, doubleGaus125, diMuonMass125), (glu130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (wp120, doubleGaus120, diMuonMass120), (wp125, doubleGaus125, diMuonMass125), (wp130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (wm120, doubleGaus120, diMuonMass120), (wm125, doubleGaus125, diMuonMass125), (wm130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (zh120, doubleGaus120, diMuonMass120), (zh125, doubleGaus125, diMuonMass125), (zh130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) print "*" * 80 print "Generating Triple Gaus Splines" print "*" * 80 funcs.signalFitInterpolationWithSpline( category, ws, [ (vbf120, tripleGaus120, diMuonMass120), (vbf125, tripleGaus125, diMuonMass125), (vbf130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (glu120, tripleGaus120, diMuonMass120), (glu125, tripleGaus125, diMuonMass125), (glu130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (wp120, tripleGaus120, diMuonMass120), (wp125, tripleGaus125, diMuonMass125), (wp130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (wm120, tripleGaus120, diMuonMass120), (wm125, tripleGaus125, diMuonMass125), (wm130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir) funcs.signalFitInterpolationWithSpline( category, ws, [ (zh120, tripleGaus120, diMuonMass120), (zh125, tripleGaus125, diMuonMass125), (zh130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir)
def datacardsSingleGaus(): physGroupToUse = physGroupTest orderedGroupsToUse = orderedGroupsTest workspaceName = "higgs" signalSplinesDir = os.path.join(signalfitinterpolationswithsplineDir, args.outDirName) backgroundsDir = os.path.join(backgroundfitswithroomultipdfDir, args.outDirName) datacardsDir = os.path.join(datacardsworkspacesDir, args.outDirName) fffTestDir = os.path.join(ftestDir, args.outDirName) aux.mkdir(signalSplinesDir) aux.mkdir(backgroundsDir) aux.mkdir(datacardsDir) aux.mkdir(fffTestDir) fTestResults = {} for category in categoriesToUse: fTestResults[category] = {} workspaceFileName = "workspace__{category}__{signalModelId}.root".format( category=names2RepsToUse[category], signalModelId=singleGaus120.modelId) ws = R.RooWorkspace(workspaceName) aux.buildMassVariable(ws, **diMuonMass125) aux.buildMH(ws, mhmin=120, mhmax=130) # # create the RooDataHist and import it into the Workspace here explicitly # fdata = R.TFile(data.pathToFile) hdata_name = category + "/DiMuonMass" if settings.useInputFileUF: hdata_name = "net_histos/" + category + "_Net_Data" hdata = fdata.Get(hdata_name) rdata = aux.buildRooHist( ws, hdata, "data_obs_{category}".format(category=names2RepsToUse[category])) getattr(ws, "import")(rdata, R.RooFit.RecycleConflictNodes()) fdata.Close() # # Create the Signal Models # print "*" * 80 print "Generating Single Gaus Splines" print "*" * 80 vbfmodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (vbf120, singleGaus120, diMuonMass120), (vbf125, singleGaus125, diMuonMass125), (vbf130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) glumodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (glu120, singleGaus120, diMuonMass120), (glu125, singleGaus125, diMuonMass125), (glu130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) wpmodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (wp120, singleGaus120, diMuonMass120), (wp125, singleGaus125, diMuonMass125), (wp130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) wmmodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (wm120, singleGaus120, diMuonMass120), (wm125, singleGaus125, diMuonMass125), (wm130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) zhmodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (zh120, singleGaus120, diMuonMass120), (zh125, singleGaus125, diMuonMass125), (zh130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) # # Perform the F-Test and select the proper order of the # selectedOrderedModels = [] for modelGroup in orderedGroupsToUse: counter = 0 for m in modelGroup.models: m.color = colors[counter] counter += 1 selectedModel, values = funcs.ftestPerFamily( (category, diMuonMass125), ws, data, modelGroup, settings, pathToDir=fffTestDir) if selectedModel is not None: selectedOrderedModels.append(selectedModel) fTestResults[category][modelGroup.name] = values # # Create the Background Model # totalModelGroup = ModelGroup( "bkgModels", physGroupTest.models + selectedOrderedModels) counter = 0 for model in totalModelGroup.models: model.color = colors[counter] counter += 1 funcs.backgroundsWithRooMultiPdf((category, diMuonMass125), ws, data, totalModelGroup.models, settings, pathToDir=backgroundsDir, groupName=totalModelGroup.name) # # Signal and Background Models are ready and are in the Workspace # create the datacard for this category # funcs.datacardAnalytic(category, ws, data, [vbfmodel, glumodel, wpmodel, wmmodel, zhmodel], ws.pdf("multipdf_{category}".format( category=names2RepsToUse[category])), settings, pathToDir=datacardsDir, workspaceFileName=workspaceFileName, workspaceName=workspaceName, withSystematics=args.withSystematics) # # save the Workspacee # print "*" * 80 print "*** Final RooWorkspace contents ***" print "*" * 80 ws.Print("v") ws.SaveAs(os.path.join(datacardsDir, workspaceFileName)) # # plot all the F-Test Results # funcs.plotFTestResults(fTestResults, pathToDir=fffTestDir)
def datacardsTripleGaus(): physGroupToUse = physGroupTest # The physics derived background fit functions (non ordered) orderedGroupsToUse = orderedGroupsTest # The ordered background fits (berenstein, sumexp, etc) # book keeping, set up output dirs for signal, bkg, datacards, and workspaces workspaceName = "higgs" signalSplinesDir = os.path.join(signalfitinterpolationswithsplineDir, args.outDirName) backgroundsDir = os.path.join(backgroundfitswithroomultipdfDir, args.outDirName) datacardsDir = os.path.join(datacardsworkspacesDir, args.outDirName) fffTestDir = os.path.join(ftestDir, args.outDirName) aux.mkdir(signalSplinesDir) aux.mkdir(backgroundsDir) aux.mkdir(datacardsDir) aux.mkdir(fffTestDir) fTestResults = {} # run over every category and fit the signal and background and make the workspaces for category in categoriesToUse: fTestResults[category] = {} # Create workspace for category # use the representation of the name rather than the complicated name, should set up reps in config file workspaceFileName = "workspace__{category}__{signalModelId}.root".format( category=names2RepsToUse[category], signalModelId=tripleGaus120.modelId) ws = R.RooWorkspace(workspaceName) aux.buildMassVariable(ws, **diMuonMass125) aux.buildMH(ws, mhmin=120, mhmax=130) # # Create the RooDataHist and import it into the Workspace # fdata = R.TFile(data.pathToFile) hdata_name = category + "/DiMuonMass" if settings.useInputFileUF: hdata_name = "net_histos/" + category + "_Net_Data" # Get data histogram from the input file for the category # Turn it into a roo data histogram to use with roofit hdata = fdata.Get(hdata_name) rdata = aux.buildRooHist( ws, hdata, "data_obs_{category}".format(category=names2RepsToUse[category])) getattr(ws, "import")(rdata, R.RooFit.RecycleConflictNodes()) fdata.Close() # # Create the Signal Models # print "*" * 80 print "Generating Triple Gaus Splines" print "*" * 80 # vbf120, tripleGaus120, diMuonMass120 imported from config file # vbf120 is of defs.MC('NoCats', inputFileUF, vbf120MC, color=R.kRed) # vbf120MC = samp.mcMoriond2017datasets_1['VBF_120'] # tripleGaus120 = models.TripleGaus(tripleGaus120_initialValues) # diMuonMass120 = {name: DiMuonMass, central: 120, min:110, max:160, fitmin:110, fitmax:130} vbfmodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (vbf120, tripleGaus120, diMuonMass120), # (mc sample, fit, fit window) (vbf125, tripleGaus125, diMuonMass125), (vbf130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) glumodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (glu120, tripleGaus120, diMuonMass120), (glu125, tripleGaus125, diMuonMass125), (glu130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) wpmodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (wp120, tripleGaus120, diMuonMass120), (wp125, tripleGaus125, diMuonMass125), (wp130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) wmmodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (wm120, tripleGaus120, diMuonMass120), (wm125, tripleGaus125, diMuonMass125), (wm130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) zhmodel = funcs.signalFitInterpolationWithSpline( category, ws, [ (zh120, tripleGaus120, diMuonMass120), (zh125, tripleGaus125, diMuonMass125), (zh130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir) # # Perform the F-Test and select the proper order of the # selectedOrderedModels = [ ] # ordered models for this category that passed the f-test for modelGroup in orderedGroupsToUse: # ModelGroup has a name for the group and a list of models counter = 0 for m in modelGroup.models: m.color = colors[counter] counter += 1 # return the model with the order that passes the ftest # e.g. berenstein6 for berensten model group or sumExp3 for sum exp model group # ftestPerFamily imported from Modeling/higgs2/generatingFunctions.py selectedModel, values = funcs.ftestPerFamily( (category, diMuonMass125), ws, data, modelGroup, settings, pathToDir=fffTestDir, unblind=args.unblind) if selectedModel is not None: selectedOrderedModels.append(selectedModel) # Save ftest results for each category,modelgroup fTestResults[category][modelGroup.name] = values # # Create the Background Model # totalModelGroup = ModelGroup( "bkgModels", physGroupTest.models + selectedOrderedModels) counter = 0 for model in totalModelGroup.models: model.color = colors[counter] counter += 1 # Multipdf for background with physics based models and the ftest passed ordered models # !!! DOES NOT use modelGroupForMultiPdf from config file !!! funcs.backgroundsWithRooMultiPdf((category, diMuonMass125), ws, data, totalModelGroup.models, settings, pathToDir=backgroundsDir, groupName=totalModelGroup.name, unblind=args.unblind) # # Signal and Background Models are ready and are in the Workspace # create the datacard for this category # funcs.datacardAnalytic(category, ws, data, [vbfmodel, glumodel, wpmodel, wmmodel, zhmodel], ws.pdf("multipdf_{category}".format( category=names2RepsToUse[category])), settings, pathToDir=datacardsDir, workspaceFileName=workspaceFileName, workspaceName=workspaceName, withSystematics=args.withSystematics) # # save the Workspacee # ws.SaveAs(os.path.join(datacardsDir, workspaceFileName)) # # plot all the F-test results # funcs.plotFTestResults(fTestResults, pathToDir=fffTestDir)
def datacardsSingleGaus(): physGroupToUse = physGroupTest orderedGroupsToUse = orderedGroupsTest workspaceName = "higgs" signalSplinesDir = os.path.join(signalfitinterpolationswithsplineDir, args.outDirName) backgroundsDir = os.path.join(backgroundfitswithroomultipdfDir, args.outDirName) datacardsDir = os.path.join(datacardsworkspacesDir, args.outDirName) fffTestDir = os.path.join(ftestDir, args.outDirName) aux.mkdir(signalSplinesDir); aux.mkdir(backgroundsDir); aux.mkdir(datacardsDir) aux.mkdir(fffTestDir) fTestResults = {} for category in categoriesToUse: fTestResults[category] = {} workspaceFileName = "workspace__{category}__{signalModelId}.root".format( category=names2RepsToUse[category], signalModelId = singleGaus120.modelId) ws = R.RooWorkspace(workspaceName) aux.buildMassVariable(ws, **diMuonMass125) aux.buildMH(ws, mhmin=120, mhmax=130) # # create the RooDataHist and import it into the Workspace here explicitly # fdata = R.TFile(data.pathToFile) hdata_name = category + "/DiMuonMass" if settings.useInputFileUF: hdata_name = "net_histos/"+category+"_Net_Data" hdata = fdata.Get(hdata_name) rdata = aux.buildRooHist(ws, hdata, "data_obs_{category}".format(category=names2RepsToUse[category])) getattr(ws, "import")(rdata, R.RooFit.RecycleConflictNodes()) fdata.Close() # # Create the Signal Models # print "*"*80 print "Generating Single Gaus Splines" print "*"*80 vbfmodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (vbf120, singleGaus120, diMuonMass120), (vbf125, singleGaus125, diMuonMass125), (vbf130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) glumodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (glu120, singleGaus120, diMuonMass120), (glu125, singleGaus125, diMuonMass125), (glu130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) wpmodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (wp120, singleGaus120, diMuonMass120), (wp125, singleGaus125, diMuonMass125), (wp130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) wmmodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (wm120, singleGaus120, diMuonMass120), (wm125, singleGaus125, diMuonMass125), (wm130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) zhmodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (zh120, singleGaus120, diMuonMass120), (zh125, singleGaus125, diMuonMass125), (zh130, singleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) # # Perform the F-Test and select the proper order of the # selectedOrderedModels = [] for modelGroup in orderedGroupsToUse: counter = 0; for m in modelGroup.models: m.color = colors[counter] counter+=1 selectedModel, values = funcs.ftestPerFamily( (category, diMuonMass125), ws, data, modelGroup, settings, pathToDir=fffTestDir) if selectedModel is not None: selectedOrderedModels.append(selectedModel) fTestResults[category][modelGroup.name] = values # # Create the Background Model # totalModelGroup = ModelGroup("bkgModels", physGroupTest.models + selectedOrderedModels) counter = 0 for model in totalModelGroup.models: model.color = colors[counter] counter += 1 funcs.backgroundsWithRooMultiPdf((category, diMuonMass125), ws, data, totalModelGroup.models, settings, pathToDir=backgroundsDir, groupName=totalModelGroup.name) # # Signal and Background Models are ready and are in the Workspace # create the datacard for this category # funcs.datacardAnalytic(category, ws, data, [vbfmodel, glumodel, wpmodel, wmmodel, zhmodel], ws.pdf("multipdf_{category}".format(category=names2RepsToUse[category])), settings, pathToDir=datacardsDir, workspaceFileName=workspaceFileName, workspaceName=workspaceName, withSystematics=args.withSystematics ) # # save the Workspacee # print "*"*80 print "*** Final RooWorkspace contents ***" print "*"*80 ws.Print("v") ws.SaveAs(os.path.join(datacardsDir, workspaceFileName)) # # plot all the F-Test Results # funcs.plotFTestResults(fTestResults, pathToDir=fffTestDir)
def datacardsTripleGaus(): physGroupToUse = physGroupTest # The physics derived background fit functions (non ordered) orderedGroupsToUse = orderedGroupsTest # The ordered background fits (berenstein, sumexp, etc) # book keeping, set up output dirs for signal, bkg, datacards, and workspaces workspaceName = "higgs" signalSplinesDir = os.path.join(signalfitinterpolationswithsplineDir, args.outDirName) backgroundsDir = os.path.join(backgroundfitswithroomultipdfDir, args.outDirName) datacardsDir = os.path.join(datacardsworkspacesDir, args.outDirName) fffTestDir = os.path.join(ftestDir, args.outDirName) aux.mkdir(signalSplinesDir); aux.mkdir(backgroundsDir); aux.mkdir(datacardsDir) aux.mkdir(fffTestDir) fTestResults = {} # run over every category and fit the signal and background and make the workspaces for category in categoriesToUse: fTestResults[category] = {} # Create workspace for category # use the representation of the name rather than the complicated name, should set up reps in config file workspaceFileName = "workspace__{category}__{signalModelId}.root".format( category=names2RepsToUse[category], signalModelId = tripleGaus120.modelId) ws = R.RooWorkspace(workspaceName) aux.buildMassVariable(ws, **diMuonMass125) aux.buildMH(ws, mhmin=120, mhmax=130) # # Create the RooDataHist and import it into the Workspace # fdata = R.TFile(data.pathToFile) hdata_name = category + "/DiMuonMass" if settings.useInputFileUF: hdata_name = "net_histos/"+category+"_Net_Data" # Get data histogram from the input file for the category # Turn it into a roo data histogram to use with roofit hdata = fdata.Get(hdata_name) rdata = aux.buildRooHist(ws, hdata, "data_obs_{category}".format(category=names2RepsToUse[category])) getattr(ws, "import")(rdata, R.RooFit.RecycleConflictNodes()) fdata.Close() # # Create the Signal Models # print "*"*80 print "Generating Triple Gaus Splines" print "*"*80 # vbf120, tripleGaus120, diMuonMass120 imported from config file # vbf120 is of defs.MC('NoCats', inputFileUF, vbf120MC, color=R.kRed) # vbf120MC = samp.mcMoriond2017datasets_1['VBF_120'] # tripleGaus120 = models.TripleGaus(tripleGaus120_initialValues) # diMuonMass120 = {name: DiMuonMass, central: 120, min:110, max:160, fitmin:110, fitmax:130} vbfmodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (vbf120, tripleGaus120, diMuonMass120), # (mc sample, fit, fit window) (vbf125, tripleGaus125, diMuonMass125), (vbf130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) glumodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (glu120, tripleGaus120, diMuonMass120), (glu125, tripleGaus125, diMuonMass125), (glu130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) wpmodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (wp120, tripleGaus120, diMuonMass120), (wp125, tripleGaus125, diMuonMass125), (wp130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) wmmodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (wm120, tripleGaus120, diMuonMass120), (wm125, tripleGaus125, diMuonMass125), (wm130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) zhmodel = funcs.signalFitInterpolationWithSpline(category, ws, [ (zh120, tripleGaus120, diMuonMass120), (zh125, tripleGaus125, diMuonMass125), (zh130, tripleGaus130, diMuonMass130), ], settings, pathToDir=signalSplinesDir ) # # Perform the F-Test and select the proper order of the # selectedOrderedModels = [] # ordered models for this category that passed the f-test for modelGroup in orderedGroupsToUse: # ModelGroup has a name for the group and a list of models counter = 0; for m in modelGroup.models: m.color = colors[counter] counter+=1 # return the model with the order that passes the ftest # e.g. berenstein6 for berensten model group or sumExp3 for sum exp model group # ftestPerFamily imported from Modeling/higgs2/generatingFunctions.py selectedModel, values = funcs.ftestPerFamily( (category, diMuonMass125), ws, data, modelGroup, settings, pathToDir=fffTestDir, unblind=args.unblind) if selectedModel is not None: selectedOrderedModels.append(selectedModel) # Save ftest results for each category,modelgroup fTestResults[category][modelGroup.name] = values # # Create the Background Model # totalModelGroup = ModelGroup("bkgModels", physGroupTest.models + selectedOrderedModels) counter = 0 for model in totalModelGroup.models: model.color = colors[counter] counter += 1 # Multipdf for background with physics based models and the ftest passed ordered models # !!! DOES NOT use modelGroupForMultiPdf from config file !!! funcs.backgroundsWithRooMultiPdf((category, diMuonMass125), ws, data, totalModelGroup.models, settings, pathToDir=backgroundsDir, groupName=totalModelGroup.name, unblind=args.unblind) # # Signal and Background Models are ready and are in the Workspace # create the datacard for this category # funcs.datacardAnalytic(category, ws, data, [vbfmodel, glumodel, wpmodel, wmmodel, zhmodel], ws.pdf("multipdf_{category}".format(category=names2RepsToUse[category])), settings, pathToDir=datacardsDir, workspaceFileName=workspaceFileName, workspaceName=workspaceName, withSystematics=args.withSystematics ) # # save the Workspacee # ws.SaveAs(os.path.join(datacardsDir, workspaceFileName)) # # plot all the F-test results # funcs.plotFTestResults(fTestResults, pathToDir=fffTestDir)
def signalFitInterpolationsWithSpline(): pathToDir = os.path.join(signalfitinterpolationswithsplineDir, args.outDirName) aux.mkdir(pathToDir) for category in categoriesToUse: ws = R.RooWorkspace("higgs") aux.buildMassVariable(ws, **diMuonMass125) aux.buildMH(ws, mhmin=120, mhmax=130) print "*"*80 print "Generating Single Gaus Splines" print "*"*80 funcs.signalFitInterpolationWithSpline(category, ws, [ (vbf120, singleGaus120, diMuonMass120), (vbf125, singleGaus125, diMuonMass125), (vbf130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (glu120, singleGaus120, diMuonMass120), (glu125, singleGaus125, diMuonMass125), (glu130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (wp120, singleGaus120, diMuonMass120), (wp125, singleGaus125, diMuonMass125), (wp130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (wm120, singleGaus120, diMuonMass120), (wm125, singleGaus125, diMuonMass125), (wm130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (zh120, singleGaus120, diMuonMass120), (zh125, singleGaus125, diMuonMass125), (zh130, singleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) print "*"*80 print "Generating Double Gaus Splines" print "*"*80 funcs.signalFitInterpolationWithSpline(category, ws, [ (vbf120, doubleGaus120, diMuonMass120), (vbf125, doubleGaus125, diMuonMass125), (vbf130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (glu120, doubleGaus120, diMuonMass120), (glu125, doubleGaus125, diMuonMass125), (glu130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (wp120, doubleGaus120, diMuonMass120), (wp125, doubleGaus125, diMuonMass125), (wp130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (wm120, doubleGaus120, diMuonMass120), (wm125, doubleGaus125, diMuonMass125), (wm130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (zh120, doubleGaus120, diMuonMass120), (zh125, doubleGaus125, diMuonMass125), (zh130, doubleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) print "*"*80 print "Generating Triple Gaus Splines" print "*"*80 funcs.signalFitInterpolationWithSpline(category, ws, [ (vbf120, tripleGaus120, diMuonMass120), (vbf125, tripleGaus125, diMuonMass125), (vbf130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (glu120, tripleGaus120, diMuonMass120), (glu125, tripleGaus125, diMuonMass125), (glu130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (wp120, tripleGaus120, diMuonMass120), (wp125, tripleGaus125, diMuonMass125), (wp130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (wm120, tripleGaus120, diMuonMass120), (wm125, tripleGaus125, diMuonMass125), (wm130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir ) funcs.signalFitInterpolationWithSpline(category, ws, [ (zh120, tripleGaus120, diMuonMass120), (zh125, tripleGaus125, diMuonMass125), (zh130, tripleGaus130, diMuonMass130), ], settings, pathToDir=pathToDir )
# # close... # fdata.Close() if __name__ == "__main__": singleGaus = models.SingleGaus(singleGaus_initialValues) #distributions(("NoCats", "DiMuonMass"), data, [glu, vbf, wm, wp, zh], [wJetsToLNu, wwTo2L2Nu, wzTo3LNu, tt, dy]) #distributions(("NoCats", "DiMuonpt"), data, [glu, vbf, wm, wp, zh], [wJetsToLNu, wwTo2L2Nu, wzTo3LNu, tt, dy]) #distributions(("NoCats", "Muonpt"), data, [glu, vbf, wm, wp, zh], [wJetsToLNu, wwTo2L2Nu, wzTo3LNu, tt, dy]) ws = R.RooWorkspace("higgs") ws.Print("v") aux.buildMassVariable(ws, **diMuonMass125) signalFit(("VBFTight", diMuonMass125), ws, vbf, singleGaus, pathToDir=signalfitsDir) signalFit(("ggFTight", diMuonMass125), ws, vbf, singleGaus, pathToDir=signalfitsDir) expGaus = models.ExpGaus(expGaus_defaultValues) expGaus.color = R.kRed bwzRedux = models.BWZRedux(bwzredux_defaultValues) bwzRedux.color = R.kBlue
# # close... # fdata.Close() if __name__=="__main__": singleGaus = models.SingleGaus(singleGaus_initialValues) #distributions(("NoCats", "DiMuonMass"), data, [glu, vbf, wm, wp, zh], [wJetsToLNu, wwTo2L2Nu, wzTo3LNu, tt, dy]) #distributions(("NoCats", "DiMuonpt"), data, [glu, vbf, wm, wp, zh], [wJetsToLNu, wwTo2L2Nu, wzTo3LNu, tt, dy]) #distributions(("NoCats", "Muonpt"), data, [glu, vbf, wm, wp, zh], [wJetsToLNu, wwTo2L2Nu, wzTo3LNu, tt, dy]) ws = R.RooWorkspace("higgs") ws.Print("v") aux.buildMassVariable(ws, **diMuonMass125) signalFit(("VBFTight", diMuonMass125), ws, vbf, singleGaus, pathToDir=signalfitsDir) signalFit(("ggFTight", diMuonMass125), ws, vbf, singleGaus, pathToDir=signalfitsDir) expGaus = models.ExpGaus(expGaus_defaultValues) expGaus.color = R.kRed bwzRedux = models.BWZRedux(bwzredux_defaultValues) bwzRedux.color = R.kBlue bwzGamma = models.BWZGamma(bwzgamma_defaultValues) bwzGamma.color = R.kGreen b5 = models.Bernstein(bernstein_defaultValues, degree=6) b5.color = R.kYellow sumExp5 = models.SumExponentials(sumExp_defaultValues, degree=5) sumExp5.color = R.kViolet backgroundFits(("VBFTight", diMuonMass125), ws, data, [expGaus, bwzRedux, bwzGamma, b5, sumExp5], pathToDir=backgroundfitsDir, groupName="testGroup")