HPS-MC
 
Loading...
Searching...
No Matches
pede_job.py
Go to the documentation of this file.
1"""!
2@file pede_job.py
3
4Run pede alignment over input bin files generated by tracking accumulation
5
6Besides the main purpose of running the pede minimizer, we also do other helpful
7tasks that are commonly done with alignment.
81. Apply the results from the pede minimizer to a new iteration of the detector
92. Construct the new iteration of the detector so that another round of tracking
10 can be done
113. Merge the histogram files generated from the previous round of tracking for
12 later analysis/drawing - this merging is only done if those histogram files
13 exist and an output histogrma file is defined in the job JSON.
14 - The histogram files are looked for by replacing the input _mille.bin suffix
15 on the input files with _gblplots.bin which is the format of the outputs
16 done by the tracking example.
17"""
18import os
19from hpsmc.alignment import PEDE, ApplyPedeRes, ConstructDetector
20
21job.description = 'alignment parameter minimizatin via pede'
22
23if not isinstance(job.input_files, (str, dict)):
24 raise ValueError('"input_files" must be a dict list of input files or a path to a text file listing the input files')
25
26if isinstance(job.input_files, str):
27 listing = job.input_files
28 job.input_files = dict()
29 with open(listing) as lf:
30 for line in lf:
31 line = line.strip()
32 # skip empty lines or ones starting with #
33 if line == '' or line.startswith('#'):
34 continue
35 # non-empty line, have destination be just the name of the file
36 job.input_files[line] = os.path.basename(line)
37
38pede = PEDE(inputs=job.input_files.keys() if 'no_copy' in job.params else job.input_files.values())
39apply_res = ApplyPedeRes()
40construct_det = ConstructDetector()
41
42job.add([pede, apply_res, construct_det])
43
44gbl_plots = [
45 pede_bin_fp.replace('_mille.bin', '_gblplots.root')
46 for pede_bin_fp in job.input_files.keys()
47 if os.path.isfile(pede_bin_fp.replace('_mille.bin', '_gblplots.root'))
48 ]
49
50merged_gbl_plots = [
51 f for f in job.output_files.keys() if f.endswith('root')
52 ]
53
54if len(gbl_plots) > 0 and len(merged_gbl_plots) > 0:
55 # if we found GBL plots and an output ROOT was provided, we attempt to merge
56 from hpsmc import hadd
57 hist_merge = hadd(
58 inputs=gbl_plots,
59 outputs=merged_gbl_plots
60 )
61 job.add(hist_merge)
Run ROOT's histogram/TTree merger.
Definition _hadd.py:11
Apply a millepede.res file to a detector description.
Definition _apply.py:200
construct an LCDD from a compact.xml and recompile necessary parts of hps-java
Definition _apply.py:369
Run pede minimizer over input bin files for alignment.
Definition _pede.py:13
alignment module within hps-mc
Definition __init__.py:1