17path = basf2.create_path()
18path.add_module(
'RootInput', inputFileName=inputFile)
19path.add_module(
'ParticleLoader', decayStrings=[
'e+'])
22path.add_module(
'VariablesToHistogram',
23 particleList=
'e+:all',
24 variables=[(
'electronID', 100, 0, 1), (
'isSignal', 2, -0.5, 1.5)],
25 variables_2d=[(
'mcErrors', 513, -0.5, 512.5,
'isSignal', 2, -0.5, 1.5)],
26 fileName=
'particleListNtuple.root')
29path.add_module(
'VariablesToHistogram',
31 variables=[(
'nTracks', 31, -0.5, 30.5), (
'nKLMClusters', 51, -0.5, 50.5)],
32 variables_2d=[(
'nTracks', 31, -0.5, 30.5,
'nKLMClusters', 51, -0.5, 50.5)],
33 fileName=
'eventNtuple.root')
40 assert os.path.isfile(
'particleListNtuple.root'),
"particleListNtuple.root wasn't created"
41 f = ROOT.TFile(
'particleListNtuple.root')
42 t = f.Get(
'electronID')
43 assert bool(t),
"electronID histogram isn't contained in file"
44 assert t.GetBinContent(1) > t.GetBinContent(
45 100),
'Expected fewer candidates with a highest electronID compared to lowest electronID'
47 assert bool(t),
"isSignal histogram isn't contained in file"
48 assert t.GetBinContent(1) > t.GetBinContent(2),
'Expected more background than signal'
49 signal_1d = t.GetBinContent(2)
50 t = f.Get(
'mcErrorsisSignal')
51 assert bool(t),
"mcErrorsisSignal histogram isn't contained in file"
56 assert t.GetBinContent(i, 2) == 0,
'Expected no entries for mcError >= 4 and true electron candidates'
58 assert t.GetBinContent(i, 1) == 0,
'Expected no entries for mcError < 4 and false electron candidates'
59 signal_2d.append(t.GetBinContent(i, 2))
60 assert signal_1d == sum(signal_2d), f
'Expected same amount of signal in 1D and 2D histograms got {signal_1d} {sum(signal_2d)}'
62 assert os.path.isfile(
'eventNtuple.root'),
"eventNtuple.root wasn't created"
63 f = ROOT.TFile(
'eventNtuple.root')
65 assert bool(t),
"nTracks histogram isn't contained in file"
66 assert t.GetBinContent(13) > t.GetBinContent(1),
'Expected more 12 track events than 1 track events'
67 assert t.GetBinContent(13) > t.GetBinContent(2),
'Expected more 12 track events than 2 track events'
68 assert t.GetBinContent(13) > t.GetBinContent(3),
'Expected more 12 track events than 3 track events'
69 assert t.GetBinContent(13) > t.GetBinContent(4),
'Expected more 12 track events than 4 track events'
70 assert t.GetBinContent(13) > t.GetBinContent(26),
'Expected more 12 track events than 26 track events'
71 assert t.GetBinContent(13) > t.GetBinContent(27),
'Expected more 12 track events than 27 track events'
72 assert t.GetBinContent(13) > t.GetBinContent(28),
'Expected more 12 track events than 28 track events'
73 assert t.GetBinContent(13) > t.GetBinContent(29),
'Expected more 12 track events than 29 track events'
74 ntracks_12_1d = t.GetBinContent(13)
76 t = f.Get(
'nKLMClusters')
77 assert bool(t),
"nKLMClusters histogram isn't contained in file"
79 t = f.Get(
'nTracksnKLMClusters')
80 assert bool(t),
"nTracksnKLMClusters 2d histogram isn't contained in file"
83 ntracks_12_2d.append(t.GetBinContent(13, i))
84 assert ntracks_12_1d == sum(ntracks_12_2d), \
85 f
'Expected same amount of events with 12 tracks in 1D and 2D histograms got {ntracks_12_1d} {sum(ntracks_12_2d)}'
def require_file(filename, data_type="", py_case=None)
def clean_working_directory()