def __init__(self, options): self.projPath = options.projPath + '/' self.regions = options.regions self.name = options.name self.toyDir = 'toy' + options.toynum + '_' + self.name + '_plots/' self.toynum = options.toynum if not os.path.isdir(self.projPath + '/' + self.toyDir): os.mkdir(self.projPath + '/' + self.toyDir) if os.path.isfile(self.projPath + '/fitDiagnostics' + self.name + '.root'): self.fd_file = TFile.Open(self.projPath + '/fitDiagnostics' + self.name + '.root') else: self.fd_file = False if options.workspacefile == '': self.ws_file = TFile.Open(self.projPath + '/higgsCombine' + self.name + '.GoodnessOfFit.mH120.' + options.seed + '.root') else: self.ws_file = TFile.Open(self.projPath + '/' + options.workspacefile) if options.toyfile == '': self.toy_file = self.ws_file else: self.toy_file = TFile.Open(self.projPath + '/' + options.toyfile) # self.ws_file.ls() self.ws = self.ws_file.Get('w') # self.ws.Print() # self.toy_w = self.ws.Clone('toy_w') self.toy = self.toy_file.Get('toys/toy_' + options.toynum) getattr(self.ws, 'import')(self.toy) self.ws.writeToFile( self.projPath + '/' + self.toyDir + '/toy_workspace.root', True) if not options.skipSamples: with header.cd(self.projPath): header.executeCmd( 'PostFit2DShapesFromWorkspace -w ' + self.toyDir + '/toy_workspace.root --dataset model_sData -o ' + self.toyDir + 'postfitshapes_s.root -f fitDiagnostics' + self.name + '.root:fit_s --samples 50 --postfit --sampling --print') with header.cd(self.projPath): # diffnuis_cmd = 'python $CMSSW_BASE/src/HiggsAnalysis/CombinedLimit/test/diffNuisances.py fitDiagnostics'+self.name+'.root --abs -g toy'+options.toynum+'_'+self.name+'_plots/nuisance_pulls.root' # header.executeCmd(diffnuis_cmd) self.plotNuisances() self.post_file = TFile.Open(self.projPath + self.toyDir + 'postfitshapes_s.root') for r in self.regions.split(','): if not os.path.isdir(self.projPath + '/' + self.toyDir + r): os.mkdir(self.projPath + '/' + self.toyDir + r) if os.path.isfile(self.projPath + '/saveOut.p'): pickleFile = pickle.load( open(self.projPath + '/saveOut.p', 'rb')) else: pickleFile = pickle.load( open(self.projPath + r + '/saveOut.p', 'rb')) self.plotFitResults(r, pickleFile)
# Instantiate all class instances for i in inputConfigs: instance = TwoDAlphabet(i, options.quicktag, stringSwaps) twoDinstances.append(instance) # For each instance, check tags match and if they don't, ask the user for one for t in twoDinstances: if t.tag != twoDinstances[0].tag: print 'ERROR: tags in configuration files do not match. ' + t.tag + ' does not match ' + twoDinstances[ 0].tag + '. Please make sure they match and try again. Quitting...' quit() thistag = twoDinstances[0].tag # Combine the cards print 'cd ' + thistag with header.cd(thistag): card_combination_command = 'combineCards.py' for i in twoDinstances: card_combination_command += ' ' + i.name + '/card_' + i.name + '.txt' card_combination_command += ' > card_' + thistag + '.txt' print 'Executing ' + card_combination_command subprocess.call([card_combination_command], shell=True) for num in range(1, len(twoDinstances) + 1): subprocess.call( ["sed -i 's/ch" + str(num) + "_//g' card_" + thistag + ".txt"], shell=True) runLimit(twoDinstances, postfitWorkspaceDir, blindData=(not bool(options.unblindData)),
if (options.biasStudy != '' or options.ftest == 'fitAlt' or options.ftest == 'post' or options.ftest == 'pvalue'): altDir = options.altDir # home of the alternate workspace - has the cards, fit results, etc alttag = altDir.split('/')[0] if altDir.split('/')[-1] != '': altcard_tag = altDir.split('/')[-1] else: altcard_tag = altDir.split('/')[-2] if altDir[-1] != '/': altDir_depth = '../' * (altDir.count('/') + 1) else: altDir_depth = '../' * (altDir.count('/')) if not os.path.isdir(altDir): print altDir + ' is not a directory. Quitting...' quit() # Start with tests that only require the projDir and don't do a comparison with header.cd(projDir): # Determine if there are channel masks from the fit in the projDir masked_regions = getMasks('higgsCombineTest.FitDiagnostics.mH120.root') mask_string = '' if len(masked_regions) == 0 else ' --setParameters ' for mask in masked_regions: mask_string += mask + '=1,' mask_string = mask_string[:-1] # Set the string to specify the blinding blind_string = "--setParametersForFit " for m in masked_regions: blind_string += m + '=1,' blind_string = blind_string[:-1] + ' ' blind_string = blind_string + blind_string.replace( 'setParametersForFit', 'setParametersForEval') #.replace('=1','=0')
tag = projDir.split('/')[0] runname = 'Scan%s' % options.name rrange = [int(options.rMin), int(options.rMax)] if options.toys == '': raise ValueError( 'Toy option empty. Scanning data fit not currently supported.') if os.path.exists(options.toysFile): toysFile = options.toysFile elif os.path.exists(projDir + '/' + options.toysFile): toysFile = projDir + '/' + options.toysFile else: raise Exception('Cannot find file %s' % options.toysFile) with header.cd(projDir): if not options.skipScan: header.executeCmd( 'combine -M MultiDimFit -d card_%s.txt --algo grid -P %s --floatOtherPOIs=0 --setParameterRanges %s=%s,%s --cminDefaultMinimizerStrategy 0 --saveNLL -n %s -t %s --toysFile %s' % (tag, options.parameter, options.parameter, rrange[0], rrange[1], runname, options.toys, options.toysFile)) header.executeCmd('mkdir %s_plots/' % runname) f_out = ROOT.TFile.Open('%s_plots/all.root' % runname, 'RECREATE') f = ROOT.TFile.Open('higgsCombine%s.MultiDimFit.mH120.123456.root' % runname) for i in range(1, int(options.toys) + 1): TLimit = f.Get('limit') r = [] nll = []
projDir = options.projDir # home of the workspace - has the cards, fit results, etc tag = projDir.split('/')[0] if projDir.split('/')[-1] != '': card_tag = projDir.split('/')[-1] else: card_tag = projDir.split('/')[-2] if tag == '': print 'ERROR in project directory name (where your workspace and data card lives). Did you accidentally provide a leading slash? (ie /projDir/) Quitting...' quit() if not os.path.isdir(projDir): print projDir + ' is not a directory. Quitting...' quit() # Start with tests that only require the projDir and don't do a comparison with header.cd(projDir): ####### # GOF # ####### if options.gof: if not options.plotOnly: commands = [] # Determine if there are channel masks from the fit in the projDir masked_regions = [] f = TFile.Open('higgsCombineTest.FitDiagnostics.mH120.root') w = f.Get('w') allVars = RooArgList(w.allVars()) # Loop over all vars in original workspace and add any masked region names to list for i in range(allVars.getSize()):