def makeOptGraphs(category, higgswindow, compileOrLoad): #cosThetaCutValue = 0.7 print "making optgraphs for category %s, window (%i-%i)" % ( category, higgswindow[0], higgswindow[1]) graphs = [] massWindows = getMassWindows() massWindows.pop(2000) massWindows.pop(3000) cutValues = getCutValues() pToverMcutValue = cutValues["ptOverM"] deltaRcutValue = cutValues["deltaR"] jetEtaCutValue = cutValues["jetEta"] phoEtaCutValue = cutValues["phEta"] for mass in getSortedDictKeys(massWindows): print "making S/rootB optGraph for mass %s" % mass masswindow = massWindows[mass] graphs.append(TGraph()) graphs[-1].SetNameTitle( "HbbOpt", "S/#sqrt{B}, M=%s, higgs window %s-%s" % (str(mass), str(higgswindow[0]), str(higgswindow[1]))) #print "Signal mass %f" % mass # just keep the name from TTree::MakeClass(), don't give it a special name samplesDirs = getSamplesDirs() fillGraph(graphs[-1], dataOrMCbg, str(mass), higgswindow, masswindow, category, pToverMcutValue, deltaRcutValue, jetEtaCutValue, phoEtaCutValue, compileOrLoad) compileOrLoad = "load" canvas = TCanvas() canvas.cd() option = "" iGraph = 0 for graph in graphs: graph.Draw(option) x = TColor() graph.SetLineColor(x.GetColor(0, 0.9 - iGraph * 0.15, iGraph * 0.15)) graph.SetFillColor(kWhite) iGraph += 1 option = "SAME" outfile = TFile( "HbbOpt_SoverRootB_higgsWindow_%i-%i.root" % (higgswindow[0], higgswindow[1]), "RECREATE") outfile.cd() canvas.BuildLegend() canvas.Draw() legend = canvas.GetPrimitive("TPave") legend.SetHeader("%s category" % category) for prim in canvas.GetListOfPrimitives(): if "HbbOpt" in prim: prim.SetTitle("H(b#bar{b})#gamma optimization: S/#sqrt{B}") prim.GetXaxis().SetRangeUser(0, 2500) canvas.Write() outfile.Close()
def processHg(inputFileName, outputFileName, load, loopMode = False, btagVariation=0): if inputFileName is None: print "\nPlease specify the input file with the -i option." exit(1) elif outputFileName is None: print "\nPlease specify the output filename with the -o option." exit(1) elif not os.path.isfile(inputFileName): print "\nThe input file specified was not found: %s" % inputfileName exit(1) print "\nInput file is %s\n" % inputFileName presentTense = "load" if load else "compile" pastTense = "loaded" if load else "compiled" print "\nAttempting to %s HgammaSelector.\n" % presentTense # call the compiling function to compile the HgammaSelector, then run its Loop() method if presentTense=="compile" and not loopMode: deleteLibs("HgammaSelector") # compile the macro using g++ and check compilation status exitCode = gSystem.CompileMacro("HgammaSelector.C", "gOck") success=(exitCode==1) elif presentTense=="load" and not loopMode: exitCode = gSystem.Load('HgammaSelector_C') success=(exitCode>=-1) if not loopMode: if not success: print "\nError... HgammaSelector failed to %s. :-("%presentTense print "Make sure you're using an up-to-date version of ROOT by running cmsenv in a 7_4_X>=16 CMSSW area." exit(1) print "\nHgammaSelector %s successfully."%pastTense if presentTense=="compile" and not loopMode: gSystem.Load('HgammaSelector_C') inputFile = TFile(inputFileName) print "testing" from pprint import pprint from os.path import basename sampleDirs = getSamplesDirs() weights = getMCbgWeightsDict(sampleDirs["bkgSmall3sDir"]) pprint(weights) shortName = basename(inputFile.GetName()).replace("smallified_", "") print shortName weight = 1. if shortName in weights.keys(): weight = weights[shortName][0] print "weight for this sample:", weight # get the ntuplizer/tree tree from the file specified by argument 1 tree = inputFile.Get("ntuplizer/tree") instance = HgammaSelector(tree) # run the HgammaSelector::Loop method instance.Loop(outputFileName, btagVariation, weight)
print "Number of events for signal with mass %i is %i" % (mass, nGenEvents) eff = sigAndBGinfo["S"]/nGenEvents seff = eff*quadratureUncertainties bck = sigAndBGinfo["B"] sbck = sigAndBGinfo["B"]*quadratureUncertainties expectedLimit = CLA(ilum, slum, eff, seff, bck, sbck) print "expected limit is: %f" % expectedLimit compileOrLoad = "load" response = {} response["compileOrLoad"]="load" response["expectedLimit"]=expectedLimit return response samplesDirs = getSamplesDirs() small3sDir = samplesDirs["small3sDir"] ddDir = samplesDirs["ddDir"] massWindows = getMassWindows() def useHbbTag(cosThetaCutValue): if testTwoMasses: del massWindows[1000] del massWindows[2000] graphs = [] compileOrLoad = "compile" for mass in massWindows.keys(): graphs.append(TGraph()) graphs[-1].SetNameTitle(str(mass), str(mass)) #for i in range(-10, 20): # TODO make some reasonable way of chosing the step size and bounds for the optimization scan # HbbCutValue = i/float(20)