SND@LHC Software
Loading...
Searching...
No Matches
runCharmHadProd.py
Go to the documentation of this file.
1
from
__future__
import
print_function
2
import
sys,os,ROOT
3
ncpus = 20
4
msel =
"4"
5
# msel = "5"
6
7
if
msel ==
"4"
:
8
nev = 2000000
# 0.1s / event
9
path =
"/afs/cern.ch/project/lbcern/vol1/truf/charm/"
10
else
:
11
nev = 1000000
12
path =
"/afs/cern.ch/project/lbcern/vol1/truf/beauty/"
13
14
# path = "/home/truf/charm/"
15
16
# store only charm
17
18
# story about weights, run_fixedTarget puts into file header: pot = nrpotspill / wspill
19
# with wspill = nrpotspill*chicc/nrcpot*nEvents/nev -> pot = nev * nrcpot / (chicc * nEvents)
20
# nEvents nr of events in input file, number of events requested for job, ratio should be 1
21
# pot = nrcpot / chicc
22
# nrcpot=((TH1F*)fin->Get("2"))->GetBinContent(1)/2.; // pot are counted double, i.e. for each signal, i.e. pot/2.
23
24
def
makeHadrons
(run):
25
for
n
in
range(ncpus):
26
s = x.Rndm()*1000000000.
27
os.system(
'mkdir run'
+str(run))
28
os.chdir(
'run'
+str(run))
29
cmd =
"python $FAIRSHIP/macro/makeCascade.py -m "
+msel+
" -n "
+ str(nev) +
" -t Cascade-run"
+str(run)+
"-parp16-MSTP82-1-MSEL"
+msel+
".root"
30
# if not run in runList:
31
os.system(cmd+
" >log"
+str(run)+
" &"
)
32
os.chdir(
'../'
)
33
run+=1
34
35
def
makeBackground
(run,cycle=0):
36
for
n
in
range(ncpus):
37
orun = run+cycle*1000
38
os.chdir(
'run'
+str(run))
39
inputFile = path+
"run"
+str(run)+
"/Cascade-run"
+str(run)+
"-parp16-MSTP82-1-MSEL"
+msel+
".root"
40
f=ROOT.TFile(inputFile)
41
nt = f.pythia6
42
N = nt.GetEntries()
43
f.Close()
44
if
msel ==
"4"
:
45
cmd =
"python $FAIRSHIP/muonShieldOptimization/run_fixedTarget.py --force --charm -V -e 10 -P -n "
+str(N)+
" -r "
+str(orun)+
" -b 100 -X 100 -I "
+inputFile
46
else
:
47
cmd =
"python $FAIRSHIP/muonShieldOptimization/run_fixedTarget.py --force --beauty -V -e 10 -P -n "
+str(N)+
" -r "
+str(orun)+
" -b 100 -X 100 -I "
+inputFile
48
os.system(cmd+
" >logFT"
+str(orun)+
" &"
)
49
os.chdir(
'../'
)
50
run+=1
51
52
cycle = 2
53
runList = [20,28,30,33]
54
def
makeBackgroundX
(runList,cycle=0):
55
for
run
in
runList:
56
orun = run+cycle*1000
57
os.chdir(
'run'
+str(run))
58
inputFile = path+
"run"
+str(run)+
"/Cascade-run"
+str(run)+
"-parp16-MSTP82-1-MSEL"
+msel+
".root"
59
f=ROOT.TFile(inputFile)
60
nt = f.pythia6
61
N = nt.GetEntries()
62
f.Close()
63
cmd =
"python $FAIRSHIP/muonShieldOptimization/run_fixedTarget.py --force --charm -V -e 10 -P -n "
+str(N)+
" -r "
+str(orun)+
" -b 100 -X 100 -I "
+inputFile
64
if
run
in
runList: os.system(cmd+
" >logFT"
+str(orun)+
" &"
)
65
os.chdir(
'../'
)
66
67
def
merge
(run,cycle=0):
68
fname =
"pythia8_Geant4_XX_10.0.root"
69
cmd =
" "
70
for
n
in
range(ncpus):
71
for
x
in
os.listdir(path+
'/run'
+str(run+n)):
72
orun = run+cycle*1000
73
if
not
x.find(
'run_fixedTarget_'
+str(orun+n)) < 0:
74
if
cycle == 0
and
run == 0
and
not
x.find(
'1001'
) < 0:
continue
75
if
cycle == 0
and
run == 0
and
not
x.find(
'1010'
) < 0:
continue
76
cmd += path+
'/run'
+str(run+n)+
'/'
+x+
'/'
+fname.replace(
'XX'
,str(orun+n))+
' '
77
if
msel ==
"4"
: outFile = fname.replace(
'XX'
,
'charm_'
+str(orun)+
'-'
+str(orun+ncpus-1) )
78
else
: outFile = fname.replace(
'XX'
,
'beauty_'
+str(orun)+
'-'
+str(orun+ncpus-1) )
79
rc = os.system(
"hadd -O "
+outFile +
" "
+cmd)
80
if
rc != 0:
81
print(
"hadd failed, stop"
,outFile)
82
else
:
83
rc = os.system(
"xrdcp "
+outFile+
" $EOSSHIP/eos/experiment/ship/data/Mbias/background-prod-2018/"
+outFile)
84
if
rc != 0:
85
print(
"copy to EOS failed, stop"
,outFile)
86
else
:
87
rc = os.system(
"rm "
+outFile)
88
89
def
mergeAll
():
90
cmd =
"hadd pythia8_Geant4_charm_153.3B_10.0_mu.root "
91
tmp =
"/eos/experiment/ship/data/Mbias/background-prod-2018/pythia8_Geant4_charm_XX_10.0_mu.root"
92
for
x
in
[
"0-19"
,
"20-39"
,
"40-59"
,
"60-79"
,
"80-99"
,\
93
"1000-1019"
,
"1020-1039"
,
"1040-1059"
,
"1060-1079"
,
"1080-1099"
,\
94
"2000-2019"
,
"2020-2039"
,
"2040-2059"
,
"2060-2079"
,
"2080-2099"
]:
95
cmd+=tmp.replace(
'XX'
,x)+
" "
96
os.system(cmd)
97
98
def
compactifyCascade
(run):
99
ncpus = 20
100
cmd =
''
101
Ntot = 0
102
NperJob = nev
103
for
i
in
range(run,+ncpus):
104
fName = path+
"run"
+str(i)+
"/Cascade-run"
+str(i)+
"-parp16-MSTP82-1-MSEL"
+msel+
".root"
105
f=open(path+
"run"
+str(i)+
"/log"
+str(i))
106
success =
False
107
for
l
in
f.readlines():
108
if
not
l.find(
'Macro finished succesfully'
)<0: success =
True
109
if
not
success:
110
print(
"job not finished properly"
,fName)
111
continue
112
cmd += fName +
" "
113
f.close()
114
Ntot+= NperJob
115
if
cmd.find(
'root'
)<0:
116
print(
'no file found, exit'
)
117
else
:
118
stat = str( int(Ntot/1E6))+
'Mpot'
119
outFile =
"Cascade-run"
+str(run)+
"-"
+str(run+ncpus-1)+
"-parp16-MSTP82-1-MSEL"
+msel+
"-"
+stat+
".root"
120
rc = os.system(
"hadd -O "
+outFile +
" "
+cmd)
121
f = ROOT.TFile(outFile)
122
Npot = f.Get(
"2"
).GetBinContent(1)/2./chicc
123
f.Close()
124
stat = str( int(Npot/1E9))+
'Bpot'
125
oldOutFile = outFile
126
outFile =
"Cascade-run"
+str(run)+
"-"
+str(run+ncpus-1)+
"-parp16-MSTP82-1-MSEL"
+msel+
"-"
+stat+
".root"
127
os.system(
"mv "
+oldOutFile+
" "
+outFile)
128
rc = os.system(
"xrdcp "
+outFile+
" $EOSSHIP/eos/experiment/ship/data/Mbias/background-prod-2018/"
+outFile)
129
if
rc != 0:
130
print(
"copy to EOS failed, stop"
,outFile)
131
else
:
132
rc = os.system(
"rm "
+outFile)
133
134
def
statistics
():
135
chicc=1.7e-3
136
if
msel==
'5'
: chicc = 1.6e-7
137
path = os.environ[
'EOSSHIP'
]+
"/eos/experiment/ship/data/Mbias/background-prod-2018/"
138
fname =
"Cascade-runAA-BB-parp16-MSTP82-1-MSEL4-40Mpot.root"
139
nPot = 0
140
nhadrons = 0
141
for
x
in
[0,20,40,60,80]:
142
fn = fname.replace(
'AA'
,str(x)).replace(
'BB'
,str(x+19))
143
f=ROOT.TFile.Open(path+fn)
144
nPot += f.Get(
"2"
).GetBinContent(1)/2.
145
nhadrons += f.Get(
'pythia6'
).GetEntries()
146
print(
"total nr of hadrons:"
,nhadrons,nPot/chicc/1.E9,
'Billion'
)
147
148
def
potFromFileHeader
():
149
pot = 0
150
for
x
in
f.GetListOfKeys():
151
if
x.GetName()==
'FileHeader'
:
152
pot += float(x.GetTitle().split(
' '
)[3])
153
print(
"PoT = "
,pot)
154
155
x=ROOT.TRandom3()
156
x.SetSeed(0)
157
158
run = int(sys.argv[1])
159
160
print(
"following functions exist"
)
161
print(
" - makeHadrons(run): will run makeCascade"
)
162
print(
" - makeBackground(run): will run fixedTarget generator"
)
163
164
runCharmHadProd.mergeAll
mergeAll()
Definition
runCharmHadProd.py:89
runCharmHadProd.compactifyCascade
compactifyCascade(run)
Definition
runCharmHadProd.py:98
runCharmHadProd.statistics
statistics()
Definition
runCharmHadProd.py:134
runCharmHadProd.makeBackground
makeBackground(run, cycle=0)
Definition
runCharmHadProd.py:35
runCharmHadProd.potFromFileHeader
potFromFileHeader()
Definition
runCharmHadProd.py:148
runCharmHadProd.makeHadrons
makeHadrons(run)
Definition
runCharmHadProd.py:24
runCharmHadProd.makeBackgroundX
makeBackgroundX(runList, cycle=0)
Definition
runCharmHadProd.py:54
runCharmHadProd.merge
merge(run, cycle=0)
Definition
runCharmHadProd.py:67
muonShieldOptimization
runCharmHadProd.py
Generated by
1.9.8