Skip to content

Commit

Permalink
Merge pull request cms-sw#29 from amarini/topic_optimization
Browse files Browse the repository at this point in the history
Topic optimization
  • Loading branch information
amarini committed Jul 19, 2015
2 parents ccb0f13 + 4d465cb commit 9ca26de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
7 changes: 4 additions & 3 deletions script/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,10 @@ def Combine(h1,h2,postfix="",dir="/tmp/%(USER)s"):
h1.Clone("sig").Write()
h2.Clone("bkg").Write()
data= h1.Clone("data") ## no data, but needed to convert datacard into ws, I put an asimov instead
data.Add(bkg)
data.Add(h2)
data.Write()
f.Close()
print "writing datacard in ",wdir+"datacard%s.txt"%postfix
dat = open(wdir+"datacard%s.txt"%postfix ,"w")

dat.write("-------------------------------------\n")
Expand Down Expand Up @@ -343,8 +344,8 @@ def CleanForCombine(px_s,px_b):
RemoveSpikes(px_s,False,3)
RemoveSpikes(px_b,False,3)

px_s.Smooth(20)
px_b.Smooth(20)
#px_s.Smooth(20)
#px_b.Smooth(20)
return


Expand Down
37 changes: 37 additions & 0 deletions script/parallel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!env python

#import os,sys
from subprocess import call, check_output
#import re
import threading
import time

from optparse import OptionParser, OptionGroup

usage = "usage: %prog [options] exe1 exe2 ..."
parser=OptionParser(usage=usage)
parser.add_option("-n","--ncore" ,dest='ncore',type='int',help="Input Datacard [Default=%default]",default=10)

def call_exe(exe):
print " -> Calling "+ exe
call(exe,shell=True)
print " -> Done "+exe

(opts,args)=parser.parse_args()

threads=[]

for exe in args:
while threading.activeCount() >= opts.ncore:
print "sleep ...",
time.sleep(3)
print "wake up"
t = threading.Thread(target=call_exe, args= (exe,) )
t.start()
threads.append( t )

for t in threads:
t.join()

print "Done"

0 comments on commit 9ca26de

Please sign in to comment.