HPS-MC
pede_job.py
Go to the documentation of this file.
1 """!
2 @file pede_job.py
3 
4 Run pede alignment over input bin files generated by tracking accumulation
5 
6 Besides the main purpose of running the pede minimizer, we also do other helpful
7 tasks that are commonly done with alignment.
8 1. Apply the results from the pede minimizer to a new iteration of the detector
9 2. Construct the new iteration of the detector so that another round of tracking
10  can be done
11 3. 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 """
18 import os
19 from hpsmc.alignment import PEDE, ApplyPedeRes, ConstructDetector
20 
21 job.description = 'alignment parameter minimizatin via pede'
22 
23 if 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 
26 if 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 
38 pede = PEDE(inputs=job.input_files.keys() if 'no_copy' in job.params else job.input_files.values())
39 apply_res = ApplyPedeRes()
40 construct_det = ConstructDetector()
41 
42 job.add([pede, apply_res, construct_det])
43 
44 gbl_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 
50 merged_gbl_plots = [
51  f for f in job.output_files.keys() if f.endswith('root')
52  ]
53 
54 if 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