14ncores = min(multiprocessing.cpu_count(), 4)
15user = getpass.getuser()
21def fitSingleGauss(x: str, ba: float |
None =
None, be: float |
None =
None) ->
None:
23 myGauss = h[x].GetListOfFunctions().FindObject(name)
26 ba = h[x].GetBinCenter(1)
28 be = h[x].GetBinCenter(h[x].GetNbinsX())
29 bw = h[x].GetBinWidth(1)
32 norm = h[x].GetEntries() * 0.3
33 myGauss = ROOT.TF1(name,
"[0]*" + str(bw) +
"/([2]*sqrt(2*pi))*exp(-0.5*((x-[1])/[2])**2)+[3]", 4)
34 myGauss.SetParameter(0, norm)
35 myGauss.SetParameter(1, mean)
36 myGauss.SetParameter(2, sigma)
37 myGauss.SetParameter(3, 1.0)
38 myGauss.SetParName(0,
"Signal")
39 myGauss.SetParName(1,
"Mean")
40 myGauss.SetParName(2,
"Sigma")
41 myGauss.SetParName(3,
"bckgr")
42 h[x].Fit(myGauss,
"",
"", ba, be)
45cmd = os.environ[
"FAIRSHIP"] +
"/macro/ShipReco.py"
46cmdAna = os.environ[
"FAIRSHIP"] +
"/macro/ShipAna.py"
55 for x
in os.listdir(
"."):
56 if not x.find(prefix) < 0:
64 if cpus[k]
is not None:
67 print(
"change to directory ", k, x)
69 for f
in os.listdir(
"."):
70 if not f.find(
"geofile_full") < 0:
71 inputfile = f.replace(
"geofile_full",
"ship")
72 log[k] =
open(
"logRec",
"w")
73 cpus[k] = subprocess.Popen(
74 [
"python", cmd,
"-n 9999999 -f " + inputfile],
85 for x
in os.listdir(
"."):
86 if not x.find(prefix) < 0:
93 processoutput = os.popen(
"ps -u " + user).
read()
95 for x
in processoutput.split(
"\n"):
96 if not x.find(
"python") < 0
and x.find(
"defunct") < 0:
102 processoutput = os.popen(
"ps -u " + user).
read()
103 for x
in processoutput.split(
"\n"):
104 if not x.find(
"python") < 0:
106 print(
"kill " + str(pid))
107 os.system(
"kill " + str(pid))
112 for prefix
in prefixes:
115 print(
"change to directory ", x)
118 for f
in os.listdir(
"."):
119 if not f.find(
"geofile_full") < 0:
123 print(
"ERROR: no geofile found", x)
127 inputfile = geofile.replace(
"geofile_full",
"ship")
129 while nproc > ncores:
132 print(
"wait a minute")
134 print(
"launch reco", x)
136 with contextlib.suppress(Exception):
137 os.system(
"rm logRec")
139 os.system(
"python " + cmd +
" -n 9999999 -f " + inputfile +
" --saveDisk >> logRec &")
141 os.system(
"python " + cmd +
" -n 9999999 -f " + inputfile +
" >> logRec &")
147 print(
"debug ", nJobs)
148 for p
in sorted(proc.keys()):
151 while nproc > ncores:
154 print(
"wait a minute")
156 with open(
"logRec")
as log:
159 if "finishing" in rl[len(rl) - 1]:
162 print(
"analyze ", p, nproc)
163 with contextlib.suppress(Exception):
164 os.system(
"rm logAna")
166 "python " + cmdAna +
" -n 9999999 -f " + inputfile.replace(
".root",
"_rec.root") +
" >> logAna &"
171 print(
"Rec job not finished yet", p)
174 print(
"rec job probably failed, only when python process running")
181 for prefix
in prefixes:
184 print(
"change to directory ", x)
186 for f
in os.listdir(
"."):
187 if not f.find(
"geofile_full") < 0:
188 inputfile = f.replace(
"geofile_full",
"ship")
189 log[x] =
open(
"logAna",
"w")
190 process = subprocess.Popen(
191 [
"python", cmdAna,
"-n 9999999",
"-f " + inputfile.replace(
".root",
"_rec.root")], stdout=log[x]
194 print(
"finished ", process.returncode)
204 if not isinstance(p, list):
211 for x
in os.listdir(
"."):
212 if not x.find(prefix) < 0:
214 hlist += x +
"/ShipAna.root "
216 os.system(
"hadd -f ShipAna.root " + hlist)
217 ut.readHists(h,
"ShipAna.root")
218 print(h[
"meanhits"].GetEntries())
220 ut.bookCanvas(h, key=
"strawanalysis", title=
"Distance to wire and mean nr of hits", nx=1200, ny=600, cx=2, cy=1)
222 cv = h[
"strawanalysis"].cd(1)
223 h[
"disty"].DrawCopy()
224 h[
"distu"].DrawCopy(
"same")
225 h[
"distv"].DrawCopy(
"same")
226 cv = h[
"strawanalysis"].cd(2)
227 h[
"meanhits"].DrawCopy()
228 print(h[
"meanhits"].GetEntries())
230 ut.bookCanvas(h, key=
"fitresults", title=
"Fit Results", nx=1600, ny=1200, cx=2, cy=2)
231 cv = h[
"fitresults"].cd(1)
232 h[
"delPOverP"].Draw(
"box")
233 cv = h[
"fitresults"].cd(2)
236 cv = h[
"fitresults"].cd(3)
237 h[
"delPOverP_proj"] = h[
"delPOverP"].ProjectionY()
238 ROOT.gStyle.SetOptFit(11111)
239 h[
"delPOverP_proj"].Draw()
240 h[
"delPOverP_proj"].Fit(
"gaus")
241 cv = h[
"fitresults"].cd(4)
242 h[
"delPOverP2_proj"] = h[
"delPOverP2"].ProjectionY()
243 h[
"delPOverP2_proj"].Draw()
245 h[
"fitresults"].Print(
"fitresults.gif")
246 ut.bookCanvas(h, key=
"fitresults2", title=
"Fit Results", nx=1600, ny=1200, cx=2, cy=2)
247 print(
"finished with first canvas")
248 cv = h[
"fitresults2"].cd(1)
250 cv = h[
"fitresults2"].cd(2)
252 cv = h[
"fitresults2"].cd(3)
255 cv = h[
"fitresults2"].cd(4)
256 h[
"IP0/mass"].Draw(
"box")
257 h[
"fitresults2"].Print(
"fitresults2.gif")
258 h[
"strawanalysis"].Print(
"strawanalysis.gif")
259 print(
"finished making plots")
263 for prefix
in prefixes:
267 for f
in os.listdir(x):
268 if not f.find(
"geofile_full") < 0:
269 inputfile = (f.replace(
"geofile_full",
"ship")).replace(
".root",
"_rec.root")
270 haddCommand +=
" " + x +
"/" + inputfile
272 cmd =
"hadd -f " + inputfile.replace(
".root",
"_" + prefix +
".root") + haddCommand
277 summary = {
"Sim": {},
"Rec": {},
"Ana": {}}
278 for prefix
in prefixes:
282 log =
open(x +
"/log")
285 print(
"no log file for ", x)
286 summary[
"Sim"][x] = -1
292 print(
"simulation failed log file 0", x)
293 summary[
"Sim"][x] = 0
295 elif "Real time" in rl[len(rl) - 1]:
297 print(
"simulation step OK ", x)
298 summary[
"Sim"][x] = 1
301 print(
"simulation failed ", x)
302 summary[
"Sim"][x] = 0
305 log =
open(x +
"/logRec")
308 print(
"no logRec file for ", x)
309 summary[
"Rec"][x] = -1
313 if "finishing" in rl[len(rl) - 1]:
315 print(
"reconstruction step OK ", x)
316 summary[
"Rec"][x] = 1
319 print(
"reconstruction failed ", x)
320 summary[
"Rec"][x] = 0
323 log =
open(x +
"/logAna")
326 print(
"no logAna file for ", x)
327 summary[
"Ana"][x] = -1
331 if "finished" in rl[len(rl) - 1]:
333 print(
"analysis step OK ", x)
334 summary[
"Ana"][x] = 1
337 print(
"analysis failed ", x)
338 summary[
"Ana"][x] = 0
348 print(p, x, result[p][x])
358 for prefix
in prefixes:
361 for f
in os.listdir(x):
362 if not f.find(
"geofile_full") < 0:
363 inputfile = (f.replace(
"geofile_full",
"ship")).replace(
".root",
"_rec.root")
364 os.system(
"rm " + x +
"/" + inputfile)
369 eos =
"/afs/cern.ch/project/eos/installation/0.3.15/bin/eos.select"
370 for x
in result[
"Rec"]:
371 if result[
"Rec"][x] < 1:
372 print(
"Reco failed !", x, result[
"Rec"][x])
377 + os.path.abspath(
".")
380 +
"/ /eos/experiment/ship/data/DAFreco/muonBackground/"
385 print(
"copied to eos", x)
389for p
in os.sys.argv[1].split(
","):
391 xx = os.path.abspath(
".").lower()
392 if not xx.find(
"neutrino") < 0:
394 if not xx.find(
"vdis") < 0
or not xx.find(
"vetodis") < 0:
396 elif not xx.find(
"clby") < 0:
398 elif not xx.find(
"dis") < 0:
401print(
" execute() input comma separated production nr, performs Simple/mergeHistos/mergeNtuples ")
402print(
" executeSimple(pl,reset=True) ")
403print(
" checkProd(pl)")
404print(
" executeAna(pl) ")
405print(
" mergeNtuples(pl) ")
406print(
" removeIntermediateFiles(pl) only _rec ")
407print(
" checkRunningProcesses() ")
def checkProd(prefixes, quiet=False)
def execute_parallel(prefix, int ncpu=4)
None removeIntermediateFiles(prefixes)
None mergeNtuples(list[str] prefixes)
list[str] getJobs(prefix)
None mergeHistosMakePlots(list[str] p)
None executeAna(prefixes)
int checkRunningProcesses()
None executeSimple(list[str] prefixes, reset=False)
None fitSingleGauss(str x, float|None ba=None, float|None be=None)
int open(const char *, int)
Opens a file descriptor.
int read(int, char *, size_t)
Read bytes from a file descriptor.
int close(int)
Closes the file descriptor fd.