PublicAnalysisDatabase: getmaps.py

File getmaps.py, 1.8 KB (added by BenjF, 3 years ago)

Efficiency maps

Line 
1#! /usr/bin/env python
2import sys,os,subprocess
3
4def usage():
5    print ' - Usage: ./getmaps.py benchmark_point cross section'
6    print ' - Example: ./getmaps.py T2tt_650_50.txt -1'
7    print ' - Only the last run of a given analysis is taken'
8    print ' - If a negative cross section is given, a cross section of'
9    print '   0.001 fb is used and no information on the best region is'
10    print '   displayed in the output'
11
12def GetAnalysisNumber(name):
13  rpos = name.rfind('_')
14  nr= int(name[rpos+1:])
15  aname=name[:rpos]
16  if nr>Numbers[aname]:
17    Numbers[aname]=nr
18
19# at least one argument, check if asking for help
20if len(sys.argv) < 3 or (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
21    usage()
22    sys.exit()
23
24# xsection information
25if float(sys.argv[2]) < 0:
26   xsec = 0.001
27else:
28   xsec = float(sys.argv[2])
29
30# get the list of the relevant analysis
31analysispath = os.getcwd()+'/Output/'+sys.argv[1]
32dirlist=[dirnames[0] for dirnames in os.walk(analysispath)]
33dirlist = [ dir for dir in dirlist if not('Cutflows' in dir or 'Histograms' in dir or dir==analysispath)]
34dirlist = [ dir.replace(analysispath,'') for dir in dirlist]
35dirlist = [ dir.replace('/','',1) for dir in dirlist if dir[0]=='/']
36anames = [ dir[:dir.rfind('_')] for dir in dirlist]
37anames = list(set(anames))
38Numbers = dict([analysis,-1] for analysis in anames)
39for dir in dirlist:
40  GetAnalysisNumber(dir)
41for analysis in anames:
42  TheCommand = './exclusion_CLs.py '+analysis+' '+sys.argv[1]+' ' +str(Numbers[analysis])+' ' + str(xsec)
43  try:
44    result=subprocess.Popen([TheCommand],shell=True,stdout=subprocess.PIPE,cwd=os.getcwd())
45  except:
46    print 'ERROR: impossible to execute the command: ' + TheCommand+'\n'
47    sys.exit()
48  ok, err = result.communicate()
49  if not ok:
50    print "ERROR with the extraction of the efficiencies. Check the ", analysis, "analysis...\n"
51