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