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(specific=
True)
40 sig_path = b2.create_path()
41 ma.inputMdst(filename=b2.find_file(
'mdst14.root',
'validation',
False),
43 ma.fillParticleList(
'mu+:sig',
'muonID > 0.5 and dr < 1 and abs(dz) < 2', writeOut=
True, path=sig_path)
44 ma.reconstructDecay(
'tau+:sig -> mu+:sig',
'', 1, writeOut=
True, path=sig_path)
45 ma.matchMCTruth(
'tau+:sig', path=sig_path)
46 ma.reconstructDecay(
'B+:sig -> tau+:sig',
'', writeOut=
True, path=sig_path)
47 ma.matchMCTruth(
'B+:sig', path=sig_path)
48 ma.buildRestOfEvent(
'B+:sig', path=sig_path)
50 configuration = fei.config.FeiConfiguration(prefix=
'FEI_VALIDATION', cache=-1, training=
True, monitor=
False)
51 feistate = fei.get_path(particles, configuration)
54 path = b2.create_path()
55 roe_path = b2.create_path()
56 cond_module = b2.register_module(
'SignalSideParticleFilter')
57 cond_module.param(
'particleLists', [
'B+:sig'])
58 cond_module.if_true(feistate.path, b2.AfterConditionPath.END)
59 roe_path.add_module(cond_module)
60 path.add_path(sig_path)
61 path.for_each(
'RestOfEvent',
'RestOfEvents', roe_path)
63 assert feistate.stage == 0
64 path.add_module(
'Progress')
66 b2.process(path, max_event=10000)
67 assert len(glob.glob(
'mcParticlesCount.root')) == 1
70 path = b2.create_path()
71 configuration = fei.config.FeiConfiguration(prefix=
'FEI_VALIDATION', cache=0, training=
True, monitor=
False)
72 feistate = fei.get_path(particles, configuration)
73 roe_path = b2.create_path()
74 cond_module = b2.register_module(
'SignalSideParticleFilter')
75 cond_module.param(
'particleLists', [
'B+:sig'])
76 cond_module.if_true(feistate.path, b2.AfterConditionPath.END)
77 roe_path.add_module(cond_module)
78 path.add_path(sig_path)
79 path.for_each(
'RestOfEvent',
'RestOfEvents', roe_path)
81 assert feistate.stage == 1
82 path.add_module(
'Progress')
84 b2.process(path, max_event=10000)
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 feistate = fei.get_path(particles, configuration)
110 roe_path = b2.create_path()
111 cond_module = b2.register_module(
'SignalSideParticleFilter')
112 cond_module.param(
'particleLists', [
'B+:sig'])
113 cond_module.if_true(feistate.path, b2.AfterConditionPath.END)
114 roe_path.add_module(cond_module)
115 path.add_path(sig_path)
116 path.for_each(
'RestOfEvent',
'RestOfEvents', roe_path)
118 assert feistate.stage == 2
119 path.add_module(
'Progress')
121 b2.process(path, max_event=10000)
124 assert len(glob.glob(
'training_input.root')) == 1
125 f = ROOT.TFile.Open(
"training_input.root",
"read")
126 assert sum([
'pi0' in key.GetName()[:4]
for key
in f.GetListOfKeys()]) == 1
130 fei.do_trainings(particles, configuration)
133 shutil.move(
"training_input.root", f
"training_input_stage{feistate.stage-1}.root")
136 assert len(glob.glob(
'pi0*.xml')) == 1
139 path = b2.create_path()
140 feistate = fei.get_path(particles, configuration)
141 roe_path = b2.create_path()
142 cond_module = b2.register_module(
'SignalSideParticleFilter')
143 cond_module.param(
'particleLists', [
'B+:sig'])
144 cond_module.if_true(feistate.path, b2.AfterConditionPath.END)
145 roe_path.add_module(cond_module)
146 path.add_path(sig_path)
147 path.for_each(
'RestOfEvent',
'RestOfEvents', roe_path)
149 assert feistate.stage == 4
150 path.add_module(
'Progress')
152 b2.process(path, max_event=10000)
155 assert len(glob.glob(
'training_input.root')) == 1
156 f = ROOT.TFile.Open(
"training_input.root",
"read")
157 assert sum([
'D' in key.GetName()[:2]
for key
in f.GetListOfKeys()]) == 5
161 fei.do_trainings(particles, configuration)
164 shutil.move(
"training_input.root", f
"training_input_stage{feistate.stage-1}.root")
167 assert len(glob.glob(
'D*.xml')) == 5
170 subprocess.call([
"analysis-fei-mergefiles",
"training_input.root"] + glob.glob(
"training_input_stage*.root"))
173 assert len(glob.glob(
'training_input*.root')) == 4
176 configuration = fei.config.FeiConfiguration(prefix=
'FEI_VALIDATION', cache=0, monitor=
True)
177 path = b2.create_path()
178 feistate = fei.get_path(particles, configuration)
179 roe_path = b2.create_path()
180 cond_module = b2.register_module(
'SignalSideParticleFilter')
181 cond_module.param(
'particleLists', [
'B+:sig'])
182 cond_module.if_true(feistate.path, b2.AfterConditionPath.END)
183 roe_path.add_module(cond_module)
184 path.add_path(sig_path)
185 path.for_each(
'RestOfEvent',
'RestOfEvents', roe_path)
187 assert feistate.stage == 7
188 path.add_module(
'Progress')
190 b2.process(path, max_event=10000)
193 assert len(glob.glob(
'Monitor_FSPLoader.root')) == 1
195 assert len(glob.glob(
'Monitor_ModuleStatistics.root')) == 1
197 assert len(glob.glob(
'Monitor_Final.root')) == 1
198 f = ROOT.TFile.Open(
"Monitor_Final.root",
"read")
199 assert f.GetListOfKeys().GetEntries() == 7
202 prereconstruction_files = [
203 'Monitor_PreReconstruction_BeforeRanking.root',
204 'Monitor_PreReconstruction_AfterRanking.root',
205 'Monitor_PreReconstruction_AfterVertex.root',
206 'Monitor_PostReconstruction_AfterMVA.root'
209 for fname
in prereconstruction_files:
210 assert len(glob.glob(fname)) == 1
211 f = ROOT.TFile.Open(fname,
"read")
212 assert f.GetListOfKeys().GetEntries() == 11
215 postreconstruction_files = [
216 'Monitor_PostReconstruction_BeforePostCut.root',
217 'Monitor_PostReconstruction_BeforeRanking.root',
218 'Monitor_PostReconstruction_AfterRanking.root'
221 for fname
in postreconstruction_files:
222 assert len(glob.glob(fname)) == 1
223 f = ROOT.TFile.Open(fname,
"read")
224 assert f.GetListOfKeys().GetEntries() == 7
227 shutil.rmtree(tempdir)