Created
April 7, 2011 09:42
-
-
Save mgmarino/907424 to your computer and use it in GitHub Desktop.
Make random charge depositions. Distribute across cores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE, STDOUT | |
import random | |
import math | |
import ROOT | |
# Following in mm | |
lx_radius = 185.7248 | |
z_height = 180.00 | |
voxel_size = 0.5 | |
def do_job(exoanalysis, num_cores, num_points_per_core): | |
job_list = [] | |
file_names = [] | |
for i in range(num_cores): | |
file_name = "outputtemp%i.root" % i | |
output_text = """echoexo false | |
load $EXOLIB/plugins/EXODigi* | |
use exodig rec toutput | |
/toutput/writeSignals false | |
/rec/ATeam_YMatch 1 | |
/rec/pattern_recognition 4 | |
/toutput/file %s | |
/exodig/setsamples 2048 | |
printmodulo 1000 | |
show | |
""" % file_name | |
file_names.append(file_name) | |
for i in range(num_points_per_core): | |
r = lx_radius*math.sqrt(random.random()) | |
theta = ROOT.TMath.TwoPi()*random.random() | |
z = int(random.uniform(-z_height, z_height)/voxel_size) | |
x = int(r*math.cos(theta)/voxel_size) | |
y = int(r*math.sin(theta)/voxel_size) | |
if i != 0: output_text += """ | |
/exodig/nextevent """ | |
output_text += """ | |
/exodig/addapdhit 20 100 1000 | |
/exodig/addchargepoint %i %i %i 1.0 1000 """ % (x,y,z) | |
output_text += """ | |
begin | |
exit | |
""" | |
p = Popen(exoanalysis, stdin=PIPE, stdout=PIPE, stderr=STDOUT) | |
p.stdin.write(output_text) | |
job_list.append(p) | |
for p in job_list: | |
comm = p.communicate() | |
#print comm[0] | |
if p.returncode != 0: | |
print "error", p.pid | |
return False | |
ROOT.gSystem.Load("libEXOUtilities") | |
chain = ROOT.TChain("tree") | |
for afile in file_names: chain.Add(afile) | |
chain.Merge("output.root") | |
return True | |
if __name__ == '__main__': | |
do_job("EXOAnalysis", 4, 10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment