18 path = basf2.create_path()
19 path.add_module(
'RootInput', inputFileName=inputFile)
20 path.add_module(
'ParticleLoader', decayStrings=[
'e+'])
21 path.add_module(
'ParticleLoader', decayStrings=[
'gamma'])
22 path.add_module(
'ParticleListManipulator', outputListName=
'gamma', inputListNames=[
'gamma:all'], cut=
'clusterE > 2.5')
25 path.add_module(
'VariablesToNtuple',
26 particleList=
'e+:all',
27 variables=[
'electronID',
'p',
'isSignal'],
28 sampling=(
'isSignal', {1: 0, 0: 20}),
29 fileName=
'particleListNtuple.root',
30 treeName=
'electronListTree')
33 path.add_module(
'VariablesToNtuple',
35 variables=[
'clusterE',
'p',
'isSignal'],
36 fileName=
'particleListNtuple.root',
37 treeName=
'photonListTree')
40 path.add_module(
'VariablesToNtuple',
42 variables=[
'nTracks',
'nKLMClusters'],
43 sampling=(
'nTracks', {12: 10}),
44 fileName=
'eventNtuple.root',
48 path.add_module(
'VariablesToNtuple',
50 variables=[
'expNum',
'runNum',
'evtNum'],
51 fileName=
'countersNtuple.root',
52 treeName=
'countersTree')
59 assert os.path.isfile(
'particleListNtuple.root'),
"particleListNtuple.root wasn't created"
60 f = ROOT.TFile(
'particleListNtuple.root')
61 t1 = f.Get(
'electronListTree')
62 t2 = f.Get(
'photonListTree')
63 assert bool(t1),
"electronListTree isn't contained in file"
64 assert bool(t2),
"photonListTree isn't contained in file"
65 assert t1.GetEntries() > 0,
"electronListTree contains zero entries"
66 assert t2.GetEntries() > 0,
"photonListTree contains zero entries"
67 assert t1.GetListOfBranches().Contains(
'electronID'),
"electronID branch is missing from electronListTree"
68 assert t1.GetListOfBranches().Contains(
'p'),
"p branch is missing from electronListTree"
69 assert t1.GetListOfBranches().Contains(
'__weight__'),
"weight branch is missing from electronListTree"
70 assert t1.GetListOfBranches().Contains(
'__event__'),
"event number branch is missing from electronList tree"
71 assert t1.GetListOfBranches().Contains(
'__run__'),
"run number branch is missing from electronList tree"
72 assert t1.GetListOfBranches().Contains(
'__experiment__'),
"experiment number branch is missing from electronList tree"
73 assert t1.GetListOfBranches().Contains(
'__production__'),
"production number branch is missing from electronList tree"
74 assert t1.GetListOfBranches().Contains(
'__candidate__'),
"candidate number branch is missing from electronList tree"
75 assert t1.GetListOfBranches().Contains(
'__ncandidates__'),
"candidate count branch is missing from electronList tree"
77 assert t2.GetListOfBranches().Contains(
'clusterE'),
"clusterEnergy branch is missing from photonListTree"
78 assert t2.GetListOfBranches().Contains(
'p'),
"p branch is missing from photonListTree"
79 assert t2.GetListOfBranches().Contains(
'__weight__'),
"weight branch is missing from photonListTree"
80 assert t2.GetListOfBranches().Contains(
'__event__'),
"event number branch is missing from photonList tree"
81 assert t2.GetListOfBranches().Contains(
'__run__'),
"run number branch is missing from photonList tree"
82 assert t2.GetListOfBranches().Contains(
'__experiment__'),
"experiment number branch is missing from photonList tree"
83 assert t2.GetListOfBranches().Contains(
'__production__'),
"production number branch is missing from photonList tree"
84 assert t2.GetListOfBranches().Contains(
'__candidate__'),
"candidate number branch is missing from photonList tree"
85 assert t2.GetListOfBranches().Contains(
'__ncandidates__'),
"candidate count branch is missing from photonList tree"
90 if event.isSignal == 1:
91 assert event.__weight__ == 1, f
"Expected weight 1 for a true electron candidate got {event.__weight__}"
94 assert event.__weight__ == 20, f
"Expected weight 20 for a wrong electron candidate got {event.__weight__}"
96 assert nBckgrd < nSignal,
"Expected less background than signal due to the large sampling rate"
99 assert event.__weight__ == 1, f
"Expected weight 1 for all photon candidates got {event.__weight__}"
101 assert os.path.isfile(
'eventNtuple.root'),
"eventNtuple.root wasn't created"
102 f = ROOT.TFile(
'eventNtuple.root')
103 t = f.Get(
'eventTree')
104 assert bool(t),
"eventTree isn't contained in file"
105 assert t.GetListOfBranches().Contains(
'nTracks'),
"nTracks branch is missing"
106 assert t.GetListOfBranches().Contains(
'nKLMClusters'),
"nKLMClusters branch is missing"
107 assert t.GetListOfBranches().Contains(
'__weight__'),
"weight branch is missing"
108 assert t.GetListOfBranches().Contains(
'__event__'),
"event number branch is missing"
109 assert t.GetListOfBranches().Contains(
'__run__'),
"run number branch is missing"
110 assert t.GetListOfBranches().Contains(
'__experiment__'),
"experiment number branch is missing"
111 assert t.GetListOfBranches().Contains(
'__production__'),
"production number branch is missing"
112 assert not t.GetListOfBranches().Contains(
'__candidate__'),
"candidate number branch is present in eventwise tree"
113 assert not t.GetListOfBranches().Contains(
'__ncandidates__'),
"candidate count branch is present in eventwise tree"
116 assert t.__run__ == 0,
"run number not as expected"
117 assert t.__experiment__ == 1003,
"experiment number not as expected"
118 assert t.__event__ == 1,
"event number not as expected"
119 assert t.__production__ == 0,
"production number not as expected"
124 if event.nTracks == 12:
125 assert event.__weight__ == 10, f
"Expected weight 10 in an event with 12 tracks got {event.__weight__}"
128 assert event.__weight__ == 1, f
"Expected weight 1 in an event with unequal 12 tracks got {event.__weight__}"
129 if event.nTracks == 11:
131 assert nTracks_12 * 5 < nTracks_11,
"Expected much less events with 12 tracks than with 11, due to the large sampling rate"
133 assert os.path.isfile(
'countersNtuple.root'),
"eventNtuple.root wasn't created"
134 f = ROOT.TFile(
'countersNtuple.root')
135 t = f.Get(
'countersTree')
136 assert bool(t),
"countersTree isn't contained in file"
137 assert t.GetListOfBranches().Contains(
'__event__'),
"event number branch is missing"
138 assert t.GetListOfBranches().Contains(
'__run__'),
"run number branch is missing"
139 assert t.GetListOfBranches().Contains(
'__experiment__'),
"experiment number branch is missing"
142 assert t.__run__ == 0,
"run number not as expected"
143 assert t.__experiment__ == 1003,
"experiment number not as expected"
144 assert t.__event__ == 1,
"event number not as expected"
145 assert t.__production__ == 0,
"production number not as expected"
148 assert t.__run__ == 0,
"run number not as expected"
149 assert t.__experiment__ == 1003,
"experiment number not as expected"
150 assert t.__event__ == 10,
"event number not as expected"
151 assert t.__production__ == 0,
"production number not as expected"
def require_file(filename, data_type="", py_case=None)
def clean_working_directory()