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:
65 if running
is not None:
68 print(
"change to directory ", k, x)
70 for f
in os.listdir(
"."):
71 if not f.find(
"geofile_full") < 0:
72 inputfile = f.replace(
"geofile_full",
"ship")
73 log[k] = open(
"logRec",
"w")
74 cpus[k] = subprocess.Popen(
75 [
"python", cmd,
"-n",
"9999999",
"-f", inputfile,
"-g", f],
86 for x
in os.listdir(
"."):
87 if not x.find(prefix) < 0:
94 processoutput = os.popen(
"ps -u " + user).read()
96 for x
in processoutput.split(
"\n"):
97 if not x.find(
"python") < 0
and x.find(
"defunct") < 0:
103 processoutput = os.popen(
"ps -u " + user).read()
104 for x
in processoutput.split(
"\n"):
105 if not x.find(
"python") < 0:
107 print(
"kill " + str(pid))
108 os.system(
"kill " + str(pid))
113 for prefix
in prefixes:
116 print(
"change to directory ", x)
119 for f
in os.listdir(
"."):
120 if not f.find(
"geofile_full") < 0:
124 print(
"ERROR: no geofile found", x)
128 inputfile = geofile.replace(
"geofile_full",
"ship")
130 while nproc > ncores:
133 print(
"wait a minute")
135 print(
"launch reco", x)
136 proc[x] = (inputfile, geofile)
137 with contextlib.suppress(Exception):
138 os.system(
"rm logRec")
141 "python " + cmd +
" -n 9999999 -f " + inputfile +
" -g " + geofile +
" --saveDisk >> logRec &"
144 os.system(
"python " + cmd +
" -n 9999999 -f " + inputfile +
" -g " + geofile +
" >> logRec &")
150 print(
"debug ", nJobs)
151 for p
in sorted(proc.keys()):
154 while nproc > ncores:
157 print(
"wait a minute")
159 with open(
"logRec")
as log:
162 if "finishing" in rl[len(rl) - 1]:
165 print(
"analyze ", p, nproc)
166 inputfile, geofile = proc[p]
167 with contextlib.suppress(Exception):
168 os.system(
"rm logAna")
173 + inputfile.replace(
".root",
"_rec.root")
181 print(
"Rec job not finished yet", p)
184 print(
"rec job probably failed, only when python process running")
191 for prefix
in prefixes:
194 print(
"change to directory ", x)
196 for f
in os.listdir(
"."):
197 if not f.find(
"geofile_full") < 0:
198 inputfile = f.replace(
"geofile_full",
"ship")
199 log[x] = open(
"logAna",
"w")
200 process = subprocess.Popen(
207 inputfile.replace(
".root",
"_rec.root"),
214 print(
"finished ", process.returncode)
224 if not isinstance(p, list):
231 for x
in os.listdir(
"."):
232 if not x.find(prefix) < 0:
234 hlist += x +
"/ShipAna.root "
236 os.system(
"hadd -f ShipAna.root " + hlist)
237 ut.readHists(h,
"ShipAna.root")
238 print(h[
"meanhits"].GetEntries())
240 ut.bookCanvas(h, key=
"strawanalysis", title=
"Distance to wire and mean nr of hits", nx=1200, ny=600, cx=2, cy=1)
242 cv = h[
"strawanalysis"].cd(1)
243 h[
"disty"].DrawCopy()
244 h[
"distu"].DrawCopy(
"same")
245 h[
"distv"].DrawCopy(
"same")
246 cv = h[
"strawanalysis"].cd(2)
247 h[
"meanhits"].DrawCopy()
248 print(h[
"meanhits"].GetEntries())
250 ut.bookCanvas(h, key=
"fitresults", title=
"Fit Results", nx=1600, ny=1200, cx=2, cy=2)
251 cv = h[
"fitresults"].cd(1)
252 h[
"delPOverP"].Draw(
"box")
253 cv = h[
"fitresults"].cd(2)
256 cv = h[
"fitresults"].cd(3)
257 h[
"delPOverP_proj"] = h[
"delPOverP"].ProjectionY()
258 ROOT.gStyle.SetOptFit(11111)
259 h[
"delPOverP_proj"].Draw()
260 h[
"delPOverP_proj"].Fit(
"gaus")
261 cv = h[
"fitresults"].cd(4)
262 h[
"delPOverP2_proj"] = h[
"delPOverP2"].ProjectionY()
263 h[
"delPOverP2_proj"].Draw()
265 h[
"fitresults"].Print(
"fitresults.gif")
266 ut.bookCanvas(h, key=
"fitresults2", title=
"Fit Results", nx=1600, ny=1200, cx=2, cy=2)
267 print(
"finished with first canvas")
268 cv = h[
"fitresults2"].cd(1)
270 cv = h[
"fitresults2"].cd(2)
272 cv = h[
"fitresults2"].cd(3)
275 cv = h[
"fitresults2"].cd(4)
276 h[
"IP0/mass"].Draw(
"box")
277 h[
"fitresults2"].Print(
"fitresults2.gif")
278 h[
"strawanalysis"].Print(
"strawanalysis.gif")
279 print(
"finished making plots")
283 for prefix
in prefixes:
288 for f
in os.listdir(x):
289 if not f.find(
"geofile_full") < 0:
290 inputfile = (f.replace(
"geofile_full",
"ship")).replace(
".root",
"_rec.root")
291 haddCommand +=
" " + x +
"/" + inputfile
293 if inputfile
is None:
294 print(
"ERROR: no geofile found for prefix", prefix)
296 cmd =
"hadd -f " + inputfile.replace(
".root",
"_" + prefix +
".root") + haddCommand
301 summary = {
"Sim": {},
"Rec": {},
"Ana": {}}
302 for prefix
in prefixes:
306 log = open(x +
"/log")
309 print(
"no log file for ", x)
310 summary[
"Sim"][x] = -1
316 print(
"simulation failed log file 0", x)
317 summary[
"Sim"][x] = 0
319 elif "Real time" in rl[len(rl) - 1]:
321 print(
"simulation step OK ", x)
322 summary[
"Sim"][x] = 1
325 print(
"simulation failed ", x)
326 summary[
"Sim"][x] = 0
329 log = open(x +
"/logRec")
332 print(
"no logRec file for ", x)
333 summary[
"Rec"][x] = -1
337 if "finishing" in rl[len(rl) - 1]:
339 print(
"reconstruction step OK ", x)
340 summary[
"Rec"][x] = 1
343 print(
"reconstruction failed ", x)
344 summary[
"Rec"][x] = 0
347 log = open(x +
"/logAna")
350 print(
"no logAna file for ", x)
351 summary[
"Ana"][x] = -1
355 if "finished" in rl[len(rl) - 1]:
357 print(
"analysis step OK ", x)
358 summary[
"Ana"][x] = 1
361 print(
"analysis failed ", x)
362 summary[
"Ana"][x] = 0
372 print(p, x, result[p][x])
382 for prefix
in prefixes:
385 for f
in os.listdir(x):
386 if not f.find(
"geofile_full") < 0:
387 inputfile = (f.replace(
"geofile_full",
"ship")).replace(
".root",
"_rec.root")
388 os.system(
"rm " + x +
"/" + inputfile)
393 eos =
"/afs/cern.ch/project/eos/installation/0.3.15/bin/eos.select"
394 for x
in result[
"Rec"]:
395 if result[
"Rec"][x] < 1:
396 print(
"Reco failed !", x, result[
"Rec"][x])
401 + os.path.abspath(
".")
404 +
"/ /eos/experiment/ship/data/DAFreco/muonBackground/"
409 print(
"copied to eos", x)
413for p
in os.sys.argv[1].split(
","):
415 xx = os.path.abspath(
".").lower()
416 if not xx.find(
"neutrino") < 0:
418 if not xx.find(
"vdis") < 0
or not xx.find(
"vetodis") < 0:
420 elif not xx.find(
"clby") < 0:
422 elif not xx.find(
"dis") < 0:
425print(
" execute() input comma separated production nr, performs Simple/mergeHistos/mergeNtuples ")
426print(
" executeSimple(pl,reset=True) ")
427print(
" checkProd(pl)")
428print(
" executeAna(pl) ")
429print(
" mergeNtuples(pl) ")
430print(
" removeIntermediateFiles(pl) only _rec ")
431print(
" checkRunningProcesses() ")
execute_parallel(prefix, int ncpu=4)
checkProd(prefixes, quiet=False)
None removeIntermediateFiles(prefixes)
None mergeNtuples(list[str] prefixes)
list[str] getJobs(prefix)
None mergeHistosMakePlots(str|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)