10 from pdg
import add_particle
11 from basf2
import create_path, register_module, process, print_params, find_file
12 from modularAnalysis
import fillParticleListsFromMC, printVariableValues, variablesToNtuple
13 from variables
import variables
as vm
14 from tempfile
import TemporaryDirectory
17 inputfile = find_file(
'generators/tests/event_nominal.lhe')
18 if len(inputfile) == 0:
20 'TEST SKIPPED: input file ' +
27 add_particle(
'A', 9000008, 5.5, 0.1329, 0, 0)
30 lhereader = register_module(
'LHEInput')
31 lhereader.param(
'makeMaster',
True)
32 lhereader.param(
'runNum', 1337)
33 lhereader.param(
'expNum', 0)
34 lhereader.param(
'inputFileList', [inputfile])
35 lhereader.param(
'useWeights',
False)
36 lhereader.param(
'nInitialParticles', 2)
37 lhereader.param(
'nVirtualParticles', 0)
38 lhereader.param(
'wrongSignPz',
False)
39 print_params(lhereader)
42 testpath = create_path()
43 testpath.add_module(
'Progress')
44 testpath.add_module(lhereader)
45 testpath.add_module(
'BoostMCParticles')
46 fillParticleListsFromMC([(
'gamma:gen',
''), (
'A:gen',
'')], path=testpath)
49 vm.addAlias(
'pxcms',
'useCMSFrame(px)')
50 vm.addAlias(
'pycms',
'useCMSFrame(py)')
51 vm.addAlias(
'pzcms',
'useCMSFrame(pz)')
52 vm.addAlias(
'pecms',
'useCMSFrame(E)')
53 variables = [
'M',
'px',
'py',
'pz',
'E',
54 'pxcms',
'pycms',
'pzcms',
'pecms']
56 printVariableValues(
'A:gen', variables, path=testpath)
57 printVariableValues(
'gamma:gen', variables, path=testpath)
63 with TemporaryDirectory()
as tmp:
70 fi = TFile(
'test.root')
71 t1 = fi.Get(
'darkphoton')
74 assert t1.GetEntries() == 1,
'Output contains %i entries' % t1.GetEntries()
75 assert t2.GetEntries() == 1,
'Output contains %i entries' % t1.GetEntries()
80 assert t1.__run__ == 1337,
'Run number not set correctly'
81 assert t1.__experiment__ == 0,
'Experiment number not set correctly'
82 assert t2.M == 0,
'Photon is not as expected'
89 assert math.isclose(t1.pxcms, -t2.pxcms, rel_tol=eps),
'Momenta don\'t balance'
90 assert math.isclose(t1.pycms, -t2.pycms, rel_tol=eps),
'Momenta don\'t balance'
91 assert math.isclose(t1.pzcms, -t2.pzcms, rel_tol=eps),
'Momenta don\'t balance'
94 assert math.isclose(t1.pxcms, +1.4572035746e-03, rel_tol=eps),
'CMS momenta are not as expected'
95 assert math.isclose(t1.pycms, +2.5198484375e-03, rel_tol=eps),
'CMS momenta are not as expected'
96 assert math.isclose(t1.pzcms, -3.8826254795e+00, rel_tol=eps),
'CMS momenta are not as expected'
97 assert math.isclose(t1.pecms, 6.6973734293e+00, rel_tol=eps),
'CMS momenta are not as expected'
100 assert math.isclose(t1.M, 5.4571074540e+00, rel_tol=eps),
'Mass is not as expected'
103 assert math.isclose(t1.px, 0.24481175912036506892, rel_tol=eps),
'Boosted momenta are not as expected'
104 assert math.isclose(t1.py, 0.002519848437500000083, rel_tol=eps),
'Boosted momenta are not as expected'
105 assert math.isclose(t1.pz, -2.1368737390471825854, rel_tol=eps),
'Boosted momenta are not as expected'
108 assert math.isclose(t2.px, 0.21182522798639694117, rel_tol=eps),
'Boosted momenta are not as expected'
109 assert math.isclose(t2.py, -0.002519848437500000083, rel_tol=eps),
'Boosted momenta are not as expected'
110 assert math.isclose(t2.pz, 5.1364143846516343572, rel_tol=eps),
'Boosted momenta are not as expected'