13 <contact>wsut@uni-bonn.de</contact>
26 import modularAnalysis
as ma
29 tempdir = tempfile.mkdtemp()
32 b2.conditions.append_testing_payloads(
'localdb/database.txt')
34 fei.core.Teacher.MaximumNumberOfMVASamples = int(1e7)
35 fei.core.Teacher.MinimumNumberOfMVASamples = int(10)
37 particles = fei.get_unittest_channels()
40 path = b2.create_path()
42 ma.inputMdst(filename=b2.find_file(
'mdst14.root',
'validation',
False),
46 empty_path = b2.create_path()
47 skimfilter = b2.register_module(
'VariableToReturnValue')
48 skimfilter.param(
'variable',
'nCleanedTracks(dr < 2 and abs(dz) < 4)')
49 skimfilter.if_value(
'>{}'.format(maxTracks), empty_path, b2.AfterConditionPath.END)
50 path.add_module(skimfilter)
52 configuration = fei.config.FeiConfiguration(prefix=
'FEI_VALIDATION', cache=-1, training=
True, monitor=
False)
53 feistate = fei.get_path(particles, configuration)
54 path.add_path(feistate.path)
55 path.add_module(
'RootOutput')
57 assert feistate.stage == 0
58 path.add_module(
'Progress')
60 b2.process(path, max_event=10000)
61 assert len(glob.glob(
'RootOutput.root')) == 1
62 assert len(glob.glob(
'mcParticlesCount.root')) == 1
65 path = b2.create_path()
66 ma.inputMdstList([
'./RootOutput.root'], path)
69 empty_path = b2.create_path()
70 skimfilter = b2.register_module(
'VariableToReturnValue')
71 skimfilter.param(
'variable',
'nCleanedTracks(dr < 2 and abs(dz) < 4)')
72 skimfilter.if_value(
'>{}'.format(maxTracks), empty_path, b2.AfterConditionPath.END)
73 path.add_module(skimfilter)
75 configuration = fei.config.FeiConfiguration(prefix=
'FEI_VALIDATION', cache=feistate.stage, training=
True, monitor=
False)
76 feistate = fei.get_path(particles, configuration)
77 path.add_path(feistate.path)
78 path.add_module(
'RootOutput')
80 assert feistate.stage == 1
81 path.add_module(
'Progress')
83 b2.process(path, max_event=10000)
86 assert len(glob.glob(
'RootOutput.root')) == 1
87 assert len(glob.glob(
'training_input.root')) == 1
88 f = ROOT.TFile.Open(
"training_input.root",
"read")
89 assert sum([
'gamma' in key.GetName()[:5]
for key
in f.GetListOfKeys()]) == 2
90 assert sum([
'mu+' in key.GetName()[:4]
for key
in f.GetListOfKeys()]) == 1
91 assert sum([
'pi+' in key.GetName()[:4]
for key
in f.GetListOfKeys()]) == 1
92 assert sum([
'K+' in key.GetName()[:3]
for key
in f.GetListOfKeys()]) == 1
96 fei.do_trainings(particles, configuration)
99 shutil.move(
"training_input.root", f
"training_input_stage{feistate.stage-1}.root")
102 assert len(glob.glob(
'gamma*.xml')) == 2
103 assert len(glob.glob(
'mu+*.xml')) == 1
104 assert len(glob.glob(
'pi+*.xml')) == 1
105 assert len(glob.glob(
'K+*.xml')) == 1
108 path = b2.create_path()
109 ma.inputMdstList([
'./RootOutput.root'], path)
112 empty_path = b2.create_path()
113 skimfilter = b2.register_module(
'VariableToReturnValue')
114 skimfilter.param(
'variable',
'nCleanedTracks(dr < 2 and abs(dz) < 4)')
115 skimfilter.if_value(
'>{}'.format(maxTracks), empty_path, b2.AfterConditionPath.END)
116 path.add_module(skimfilter)
118 configuration = fei.config.FeiConfiguration(prefix=
'FEI_VALIDATION', cache=feistate.stage, training=
True, monitor=
False)
119 feistate = fei.get_path(particles, configuration)
120 path.add_path(feistate.path)
121 path.add_module(
'RootOutput')
123 assert feistate.stage == 2
124 path.add_module(
'Progress')
126 b2.process(path, max_event=10000)
129 assert len(glob.glob(
'RootOutput.root')) == 1
130 assert len(glob.glob(
'training_input.root')) == 1
131 f = ROOT.TFile.Open(
"training_input.root",
"read")
132 assert sum([
'pi0' in key.GetName()[:4]
for key
in f.GetListOfKeys()]) == 1
136 fei.do_trainings(particles, configuration)
139 shutil.move(
"training_input.root", f
"training_input_stage{feistate.stage-1}.root")
142 assert len(glob.glob(
'pi0*.xml')) == 1
145 path = b2.create_path()
146 ma.inputMdstList([
'./RootOutput.root'], path)
149 empty_path = b2.create_path()
150 skimfilter = b2.register_module(
'VariableToReturnValue')
151 skimfilter.param(
'variable',
'nCleanedTracks(dr < 2 and abs(dz) < 4)')
152 skimfilter.if_value(
'>{}'.format(maxTracks), empty_path, b2.AfterConditionPath.END)
153 path.add_module(skimfilter)
155 configuration = fei.config.FeiConfiguration(prefix=
'FEI_VALIDATION', cache=feistate.stage, training=
True, monitor=
False)
156 feistate = fei.get_path(particles, configuration)
157 path.add_path(feistate.path)
158 path.add_module(
'RootOutput')
160 assert feistate.stage == 4
161 path.add_module(
'Progress')
163 b2.process(path, max_event=10000)
166 assert len(glob.glob(
'RootOutput.root')) == 1
167 assert len(glob.glob(
'training_input.root')) == 1
168 f = ROOT.TFile.Open(
"training_input.root",
"read")
169 assert sum([
'D' in key.GetName()[:2]
for key
in f.GetListOfKeys()]) == 5
173 fei.do_trainings(particles, configuration)
176 shutil.move(
"training_input.root", f
"training_input_stage{feistate.stage-1}.root")
179 assert len(glob.glob(
'D*.xml')) == 5
182 subprocess.call([
"analysis-fei-mergefiles",
"training_input.root"] + glob.glob(
"training_input_stage*.root"))
185 assert len(glob.glob(
'training_input*.root')) == 4
188 path = b2.create_path()
189 ma.inputMdst(filename=b2.find_file(
'mdst14.root',
'validation',
False),
193 empty_path = b2.create_path()
194 skimfilter = b2.register_module(
'VariableToReturnValue')
195 skimfilter.param(
'variable',
'nCleanedTracks(dr < 2 and abs(dz) < 4)')
196 skimfilter.if_value(
'>{}'.format(maxTracks), empty_path, b2.AfterConditionPath.END)
197 path.add_module(skimfilter)
199 configuration = fei.config.FeiConfiguration(prefix=
'FEI_VALIDATION', cache=0, monitor=
True)
200 feistate = fei.get_path(particles, configuration)
201 path.add_path(feistate.path)
203 assert feistate.stage == 7
204 path.add_module(
'Progress')
206 b2.process(path, max_event=10000)
209 assert len(glob.glob(
'Monitor_FSPLoader.root')) == 1
211 assert len(glob.glob(
'Monitor_ModuleStatistics.root')) == 1
213 assert len(glob.glob(
'Monitor_Final.root')) == 1
214 f = ROOT.TFile.Open(
"Monitor_Final.root",
"read")
215 assert f.GetListOfKeys().GetEntries() == 7
218 prereconstruction_files = [
219 'Monitor_PreReconstruction_BeforeRanking.root',
220 'Monitor_PreReconstruction_AfterRanking.root',
221 'Monitor_PreReconstruction_AfterVertex.root',
222 'Monitor_PostReconstruction_AfterMVA.root'
225 for fname
in prereconstruction_files:
226 assert len(glob.glob(fname)) == 1
227 f = ROOT.TFile.Open(fname,
"read")
228 assert f.GetListOfKeys().GetEntries() == 11
231 postreconstruction_files = [
232 'Monitor_PostReconstruction_BeforePostCut.root',
233 'Monitor_PostReconstruction_BeforeRanking.root',
234 'Monitor_PostReconstruction_AfterRanking.root'
237 for fname
in postreconstruction_files:
238 assert len(glob.glob(fname)) == 1
239 f = ROOT.TFile.Open(fname,
"read")
240 assert f.GetListOfKeys().GetEntries() == 7
243 shutil.rmtree(tempdir)