3 from hpsmc.tools import StdHepTool, BeamCoords, RandomSample, DisplaceTime, DisplaceUni, AddMother, AddMotherFullTruth, MergePoisson, MergeFiles
10 self.assertEqual(stdheptool.name,
'tool')
11 self.assertEqual(stdheptool.command,
'stdhep_tool')
14 stdheptool =
StdHepTool(name=
'beam_coords', seed=1, inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'])
15 self.assertEqual(stdheptool.cmd_args(), [
'input1.stdhep',
'input2.stdhep',
'output.stdhep',
'-s',
'1'])
18 stdheptool =
StdHepTool(name=
'tool', inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'])
19 self.assertEqual(stdheptool.cmd_args(), [
'input1.stdhep',
'input2.stdhep',
'output.stdhep'])
22 stdheptool =
StdHepTool(name=
'tool', outputs=[
'output.stdhep'])
23 self.assertRaises(Exception,
lambda: stdheptool.cmd_args())
26 stdheptool =
StdHepTool(name=
'tool', inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output1.stdhep',
'output2.stdhep'])
27 self.assertEqual(len(stdheptool.output_files()), 2)
28 self.assertRaises(Exception,
lambda: stdheptools.cmd_args())
35 self.assertEqual(beam_coords.name,
'beam_coords')
36 self.assertEqual(beam_coords.append_tok,
'rot')
40 self.assertEqual(beam_coords.optional_parameters(), [
'beam_sigma_x',
'beam_sigma_y',
'beam_rot_x',
'beam_rot_y',
'beam_rot_z',
'target_x',
'target_y',
'target_z'])
43 beam_coords =
BeamCoords(inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'])
44 beam_coords.set_parameters({
'beam_sigma_x': 11,
'beam_sigma_y': 12,
'beam_rot_x': 21,
'beam_rot_y': 22,
'beam_rot_z': 23,
'target_x': 31,
'target_y': 32,
'target_z': 33})
45 self.assertEqual(beam_coords.cmd_args(), [
'input1.stdhep',
'input2.stdhep',
'output.stdhep',
'-s',
'1',
'-x',
'11',
'-y',
'12',
'-u',
'21',
'-v',
'22',
'-w',
'23',
'-X',
'31',
'-Y',
'32',
'-Z',
'33'])
52 self.assertEqual(random_sample.name,
'random_sample')
53 self.assertEqual(random_sample.append_tok,
'sampled')
57 self.assertEqual(random_sample.optional_parameters(), [
'nevents',
'mu'])
60 random_sample =
RandomSample(inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'], seed=2)
61 random_sample.set_parameters({
'nevents': 100,
'mu': 1,
'seed': 2})
62 self.assertEqual(random_sample.cmd_args(), [
'input1.stdhep',
'input2.stdhep',
'output',
'-s',
'2',
'-N',
'1',
'-n',
'100',
'-m',
'1'])
69 self.assertEqual(displace_time.name,
'lhe_tridents_displacetime')
70 self.assertEqual(displace_time.output_ext,
'.stdhep')
74 self.assertEqual(displace_time.optional_parameters(), [
'ctau'])
77 displace_time =
DisplaceTime(inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'])
78 displace_time.set_parameters({
'ctau': 1})
79 self.assertEqual(displace_time.cmd_args(), [
'input1.stdhep',
'input2.stdhep',
'output.stdhep',
'-s',
'1',
'-l',
'1'])
86 self.assertEqual(displace_uni.name,
'lhe_tridents_displaceuni')
87 self.assertEqual(displace_uni.output_ext,
'.stdhep')
91 self.assertEqual(displace_uni.optional_parameters(), [
'ctau'])
94 displace_uni =
DisplaceUni(inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'])
95 displace_uni.set_parameters({
'ctau': 1})
96 self.assertEqual(displace_uni.cmd_args(), [
'input1.stdhep',
'input2.stdhep',
'output.stdhep',
'-s',
'1',
'-l',
'1'])
103 self.assertEqual(add_mother.name,
'add_mother')
104 self.assertEqual(add_mother.append_tok,
'mom')
110 add_mother_full_truth =
AddMotherFullTruth(inputs=[
'input1.stdhep',
'input2.lhe'], outputs=[
'output.stdhep'])
111 self.assertEqual(add_mother_full_truth.name,
'add_mother_full_truth')
112 self.assertEqual(add_mother_full_truth.append_tok,
'mom_full_truth')
115 self.assertRaises(Exception,
lambda:
AddMotherFullTruth(outputs=[
'output.stdhep']), msg=
"Must have 2 input files: a stdhep file and a lhe file in order")
116 self.assertRaises(Exception,
lambda:
AddMotherFullTruth(inputs=[
'input1.stdhep',
'input2.lhe',
'input3.stdhep'], outputs=[
'output.stdhep']), msg=
"Must have 2 input files: a stdhep file and a lhe file in order")
117 self.assertRaises(Exception,
lambda:
AddMotherFullTruth(inputs=[
'input1.stdhep'], outputs=[
'output.stdhep']), msg=
"Must have 2 input files: a stdhep file and a lhe file in order")
118 self.assertRaises(Exception,
lambda:
AddMotherFullTruth(inputs=[
'input1.root',
'input2.lhe'], outputs=[
'output.stdhep']), msg=
"The first input file must be a stdhep file")
119 self.assertRaises(Exception,
lambda:
AddMotherFullTruth(inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep']), msg=
"The second input file must be a lhe file")
122 add_mother_full_truth =
AddMotherFullTruth(inputs=[
'input1.stdhep',
'input2.lhe'], outputs=[
'output.stdhep'])
123 self.assertEqual(add_mother_full_truth.cmd_args(), [
'input1.stdhep',
'input2.lhe',
'output.stdhep'])
130 self.assertEqual(merge_poisson.name,
'merge_poisson')
131 self.assertEqual(merge_poisson.append_tok,
'sampled')
132 self.assertEqual(merge_poisson.xsec, 0)
136 self.assertEqual(merge_poisson.required_parameters(), [
'target_thickness',
'num_electrons'])
139 merge_poisson =
MergePoisson(inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'], xsec=1)
140 merge_poisson.set_parameters({
'target_thickness': 0.0004062,
'num_electrons': 625})
141 merge_poisson.setup()
142 res = 6.306e-14 * 0.0004062 * 625
143 self.assertEqual(merge_poisson.mu, res)
146 merge_poisson =
MergePoisson(inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'], xsec=20)
147 merge_poisson.set_parameters({
'target_thickness': 0.0004062,
'num_electrons': 625})
148 merge_poisson.setup()
149 res = 6.306e-14 * 0.0004062 * 625 * 20
150 self.assertEqual(merge_poisson.mu, res)
153 merge_poisson =
MergePoisson(inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'], xsec=1)
154 merge_poisson.set_parameters({
'target_thickness': 0.000875,
'num_electrons': 625})
155 merge_poisson.setup()
156 res = 6.306e-14 * 0.000875 * 625
157 self.assertEqual(merge_poisson.mu, res)
160 merge_poisson =
MergePoisson(inputs=[
'input1.stdhep',
'input2.stdhep'], outputs=[
'output.stdhep'], xsec=1)
161 merge_poisson.set_parameters({
'target_thickness': 0.0004062,
'num_electrons': 625,
'mu': 1,
'seed': 2,
'nevents': 100})
162 merge_poisson.setup()
163 self.assertEqual(merge_poisson.cmd_args(), [
'input1.stdhep',
'input2.stdhep',
'output',
'-s',
'2',
'-m', str(6.306e-14 * 0.0004062 * 625),
'-N',
'1',
'-n',
'100'])
170 self.assertEqual(merge_files.name,
'merge_files')
174 self.assertEqual(merge_files.optional_parameters(), [])
178 self.assertEqual(merge_files.required_parameters(), [])
181 if __name__ ==
'__main__':