# ____________________________________________________________________________________________________________________________________________ || reader = FileReader() if not os.path.exists(os.path.abspath(outputDir)): os.makedirs(os.path.abspath(outputDir)) for signal_model in signal_models: signal_model_name = signal_model.name if option.verbose: print "*"*100 if option.verbose: print "Making data card for ",signal_model_name #central_value = float(signal_model_name.replace("HZZd_M","")) central_value = signal_model.central_value binListCopy = [b for b in copy.deepcopy(binList) if option.sideband or (not option.sideband and "SR" in b.name)] cardDir = os.path.join(outputDir,signal_model_name) mkdir_p(cardDir) for ibin,bin in enumerate(binListCopy): if option.verbose: print "-"*20 if option.verbose: print bin.name histName = bin.inputBinName # bkg spb_data_count = 0. for bkg in bkgs: bkgName = bkg.name reader.openFile(inputDir if not hasattr(bkg,"inputDir") else bkg.inputDir,bkgName,TFileName if not hasattr(bkg,"TFileName") else bkg.TFileName) hist = reader.getObj(bkgName,histName) if bin.parameterDict: count,error = getIntegral(hist) else: count,error = getCountAndError(hist,central_value if not bin.central_value else bin.central_value,bin.width,isSR=isSRFunc(bin))
40, 45, 50, 55, 60, ] dirTemplate = "Zd_MZD%s" textFileName = "AsymptoticLimits_Out.txt" lineStr = "Expected 50.0%" outPlotPath = "/home/lucien/public_html/Higgs/HToZdZd/Misc/LimitComparison/2019-12-06_RunII_SRvsSR2D/AsymptoticLimitRatio.pdf" histName = "LimitRatio" title = "; m_{Z_{d}} (GeV); Limit ratio" # ________________________________________________________________________________ || outPoints = [] if outPlotPath: mkdir_p(os.path.dirname(outPlotPath)) for m in mass_points: textFilePath1 = os.path.join(inputDir1, dirTemplate % m, textFileName) textFile1 = open(textFilePath1, "r") lines1 = textFile1.readlines() foundLine1 = False for line1 in lines1: if line1.startswith(lineStr): foundLine1 = True break textFilePath2 = os.path.join(inputDir2, dirTemplate % m, textFileName) textFile2 = open(textFilePath2, "r") lines2 = textFile2.readlines() foundLine2 = False for line2 in lines2: if line2.startswith(lineStr):
for windowDir in glob.glob(inputDir+"*/"+mass_point.name+"/"): print "Reading directory "+windowDir window = windowDir.split("/")[-3] inputFile = ROOT.TFile(windowDir+"higgsCombineTest."+method+".mH120.root","READ") tree = inputFile.Get(varName) mass_value = mass_value_func(mass_point.name) x_value = x_value_func(window) outDict[mass_point][x_value] = [] if expOnly: for i,entry in enumerate(tree): outDict[mass_point][x_value].append(getattr(entry,varName)) else: raise RuntimeError ##__________________________________________________________________|| mkdir_p(os.path.dirname(option.outputPath)) c = ROOT.TCanvas() mg = ROOT.TMultiGraph() for i,mass_point in enumerate(mass_points): x_points = [] y_points = [] n = len(outDict[mass_point]) x_values_list = outDict[mass_point].keys() x_values_list.sort() for x_value in x_values_list: y_value = outDict[mass_point][x_value][select_entry] x_points.append(x_value) y_points.append(y_value) gr = ROOT.TGraph(n,array.array(array_type,x_points),array.array(array_type,y_points)) gr.SetName(mass_point.name) gr.SetTitle(mass_point.latexName)
parser.add_argument("--dry_run",action="store_true") parser.add_argument("--verbose",action="store_true") option = parser.parse_args() nExistDir = 0 nSkipFile = 0 for fpath in glob.glob(option.pattern): outputDir = os.path.join(option.outputDir,fpath.split("/")[8]+"/") if option.verbose: print "*"*40 print "Untarring "+fpath print "Output directory: "+outputDir if not os.path.exists(fpath): print "File "+fpath+" does not exist, skipping" nSkipFile += 1 continue mkdir_p(outputDir) if not option.dry_run: my_tar = tarfile.open(fpath) my_tar.extractall(outputDir) # specify which folder to extract to my_tar.close() if option.verbose: print "\n"*1 print "*"*40 print "Summary" print "*"*40 print "Available tar files: ",len(glob.glob(option.pattern)) print "Possible tarred files: ",nExistDir print "Skipped files: ",nSkipFile
ls -lrt %s ls -lrt tar -cf combine_output.tar *.root tar -cf combine_pdf.tar *.pdf rm higgsCombine*.root """ api = CombineAPI() for m in mass_points: print "*" * 100 print "Running on mass point " + str(m) modelName = "Zd_MZD" + str(m) crabDir = os.path.join(crabTaskDir, taskName, modelName) mkdir_p(crabDir) pwdPath = os.environ['PWD'] wsFilePath = os.path.join(inputDir, modelName, modelName + ".root") combine_cmd_list = [] wsFilePathRoot = wsFilePath.replace("/cms/data", "root://cms-xrd-global.cern.ch/") combine_cmd_list.append('./copyRemoteWorkspace.sh %s ./%s ' % (wsFilePathRoot, os.path.basename(wsFilePathRoot))) if asymLimitDict: median = asymLimitDict["central"][modelName] up2 = asymLimitDict["up2"][modelName] down2 = asymLimitDict["down2"][modelName] interval = abs(up2 - down2) / n_asym_scan print "Asymptotic median limit: ", median print "Asymptotic up2 limit: ", up2 print "Asymptotic down2 limit: ", down2