Commit d411b6b3 authored by Rosen Matev's avatar Rosen Matev
Browse files

Move mva lines from options to modules

parent d51b912f
......@@ -8,92 +8,27 @@
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import absolute_import, division, print_function
import math
from GaudiKernel.SystemOfUnits import GeV
from PyConf import configurable
from Hlt1Conf.lines import (CombineTracks, PrFilterV2Tracks)
from RecoConf.hlt1_tracking import (require_gec, require_pvs, make_pvs,
make_hlt1_tracks,
make_velokalman_fitted_tracks)
from PyConf.Algorithms import FTRawBankDecoder
from PyConf.environment import EverythingHandler
def make_tracks_for_mva_lines():
return make_velokalman_fitted_tracks(make_hlt1_tracks())
@configurable
def one_track_MVA(
make_input_tracks=make_tracks_for_mva_lines,
make_pvs=make_pvs,
# TrackMVALoose cuts from ZombieMoore
max_chi2dof=2.5,
min_pt=2.0 * GeV,
max_pt=26 * GeV,
min_ipchi2=7.4,
param1=1.0,
param2=2.0,
param3=1.248):
pvs = make_pvs().location
from Functors import PT, CHI2DOF, MINIPCHI2, MINIPCHI2CUT
from Functors.math import in_range, log
pre_sel = (CHI2DOF < max_chi2dof)
hard_sel = (PT > max_pt) & MINIPCHI2CUT(IPChi2Cut=min_ipchi2, Vertices=pvs)
bulk_sel = in_range(min_pt, PT, max_pt) & (
log(MINIPCHI2(pvs)) >
(param1 / ((PT / GeV - param2)**2) +
(param3 / max_pt) * (max_pt - PT) + math.log(min_ipchi2)))
full_sel = pre_sel & (hard_sel | bulk_sel)
return PrFilterV2Tracks(
full_sel, Input=make_input_tracks()['v2Sel']).Output
def two_track_MVA(make_input_tracks=make_tracks_for_mva_lines,
make_pvs=make_pvs,
VertexCut=None,
ChildCut=None,
CombinationCut=None):
# Compared to TwoTrackMVALoose in ZombieMoore this is missing:
# in_range( 2, BPVETA, 5 )
# BPVCORRM > 1. * GeV
# (ignoring a very loose upper cut on BPVCORRM)
# and, of course, the actual MVA....
from Functors import P, PT, CHI2DOF, DOCACHI2, BPVDIRA, MINIPCHI2CUT
from GaudiKernel.SystemOfUnits import MeV
pvs = make_pvs().location
if ChildCut is None:
ChildCut = (PT > 800. * MeV) & (P > 5. * GeV) & (
CHI2DOF < 2.5) & MINIPCHI2CUT(
IPChi2Cut=4., Vertices=pvs)
if CombinationCut is None:
CombinationCut = (PT > 2. * GeV) & (DOCACHI2 < 10.)
if VertexCut is None:
VertexCut = (CHI2DOF < 10.) & (BPVDIRA(pvs) > 0)
children = PrFilterV2Tracks(
ChildCut, Input=make_input_tracks()['v2Sel']).Output
return CombineTracks(
NBodies=2,
VertexCut=VertexCut,
InputTracks=children,
CombinationCut=CombinationCut).OutputVerticesStorage
from PyConf.Algorithms import FTRawBankDecoder
from RecoConf.hlt1_tracking import require_gec
from Hlt1Conf.lines.track_mva import (one_track_mva_line, two_track_mva_line,
debug_two_track_mva_line)
ftdec_v = 4
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v):
gec = require_gec(FTDecodingVersion=ftdec_v)
NoPVFilter = require_pvs(make_pvs())
one_track = one_track_MVA()
two_track = two_track_MVA()
env = EverythingHandler(
threadPoolSize=1, nEventSlots=1, evtMax=1000, debug=True)
env.registerLine('one_track_mva', algs=[gec, NoPVFilter, one_track])
env.registerLine('two_track_mva', algs=[gec, NoPVFilter, two_track])
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v), \
require_gec.bind(FTDecodingVersion=ftdec_v):
builders = {
'Hlt1TrackMVALine': one_track_mva_line,
'Hlt1TwoTrackMVALine': two_track_mva_line,
'Hlt1DebugTwoTrackMVALine': debug_two_track_mva_line,
}
for name, builder in builders.items():
env.registerLine(name, builder())
env.setupInputFromTestFileDB('MiniBrunel_2018_MinBias_FTv4_DIGI')
env.configure()
# env.plotDataFlow()
......@@ -9,30 +9,92 @@
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import absolute_import, division, print_function
import math
from GaudiKernel.SystemOfUnits import GeV
from PyConf import configurable
from Hlt1Conf.lines import (
CombineTracks,
PrFilterV2Tracks,
)
from Hlt1Conf.reconstruction import (
gec, make_odin, FilterEmptyPVs, make_pvs, EmptyFilter,
make_param_forward_fitted_tracks_v2_selection)
from RecoConf.hlt1_tracking import (require_gec, require_pvs, make_pvs,
make_odin, make_hlt1_tracks,
make_velokalman_fitted_tracks)
from ..algorithms import CombineTracks, PrFilterV2Tracks
from PyConf.Algorithms import FTRawBankDecoder
from PyConf.environment import EverythingHandler
def new_two_track_MVA(
make_odin=make_odin,
make_input_tracks=make_param_forward_fitted_tracks_v2_selection,
def make_tracks_mva_tracks():
return make_velokalman_fitted_tracks(make_hlt1_tracks())
@configurable
def track_mva_prefilters(make_pvs=make_pvs):
return [require_gec(), require_pvs(make_pvs())]
@configurable
def one_track_mva_line(
make_input_tracks=make_tracks_mva_tracks,
make_pvs=make_pvs,
VertexCut=None,
ChildCut=None,
CombinationCut=None,
VoidDump=None,
ChildDump=None,
CombinationDump=None,
VertexDump=None):
from Functors import ALL, ETA, P, PT, CHI2DOF, SUM, DOCA, DOCACHI2, BPVDIRA, BPVIPCHI2, MINIP, PHI, RUNNUMBER, EVENTNUMBER, EVENTTYPE, BPVIPCHI2STATE
# TrackMVALoose cuts from ZombieMoore
max_chi2dof=2.5,
min_pt=2.0 * GeV,
max_pt=26 * GeV,
min_ipchi2=7.4,
param1=1.0,
param2=2.0,
param3=1.248):
pvs = make_pvs().location
from Functors import PT, CHI2DOF, MINIPCHI2, MINIPCHI2CUT
from Functors.math import in_range, log
pre_sel = (CHI2DOF < max_chi2dof)
hard_sel = (PT > max_pt) & MINIPCHI2CUT(IPChi2Cut=min_ipchi2, Vertices=pvs)
bulk_sel = in_range(min_pt, PT, max_pt) & (
log(MINIPCHI2(pvs)) >
(param1 / ((PT / GeV - param2)**2) +
(param3 / max_pt) * (max_pt - PT) + math.log(min_ipchi2)))
full_sel = pre_sel & (hard_sel | bulk_sel)
track_filter = PrFilterV2Tracks(
full_sel, Input=make_input_tracks()['v2Sel'])
return track_mva_prefilters() + [track_filter]
@configurable
def two_track_mva_line(make_input_tracks=make_tracks_mva_tracks,
make_pvs=make_pvs):
# Compared to TwoTrackMVALoose in ZombieMoore this is missing:
# in_range( 2, BPVETA, 5 )
# BPVCORRM > 1. * GeV
# (ignoring a very loose upper cut on BPVCORRM)
# and, of course, the actual MVA....
from Functors import P, PT, CHI2DOF, DOCACHI2, BPVDIRA, MINIPCHI2CUT
from GaudiKernel.SystemOfUnits import MeV
pvs = make_pvs().location
ChildCut = ((PT > 800. * MeV) & (P > 5. * GeV) &
(CHI2DOF < 2.5) & MINIPCHI2CUT(IPChi2Cut=4., Vertices=pvs))
CombinationCut = (PT > 2. * GeV) & (DOCACHI2 < 10.)
VertexCut = (CHI2DOF < 10.) & (BPVDIRA(pvs) > 0)
children = PrFilterV2Tracks(
ChildCut, Input=make_input_tracks()['v2Sel']).Output
combination_filter = CombineTracks(
NBodies=2,
VertexCut=VertexCut,
InputTracks=children,
CombinationCut=CombinationCut)
return track_mva_prefilters() + [combination_filter]
@configurable
def debug_two_track_mva_line(make_input_tracks=make_tracks_mva_tracks,
make_pvs=make_pvs,
VertexCut=None,
ChildCut=None,
CombinationCut=None,
VoidDump=None,
ChildDump=None,
CombinationDump=None,
VertexDump=None,
dump_filename='PrCombineTracks.root'):
from Functors import (ALL, ETA, P, PT, CHI2DOF, SUM, DOCA, DOCACHI2,
BPVDIRA, BPVIPCHI2, MINIP, PHI, RUNNUMBER,
EVENTNUMBER, EVENTTYPE, BPVIPCHI2STATE)
from GaudiKernel.SystemOfUnits import MeV, GeV, mm, mrad
pv_loc, odin_loc = make_pvs().location, make_odin().location
if VoidDump is None:
......@@ -75,8 +137,8 @@ def new_two_track_MVA(
'DOCACHI2': DOCACHI2,
}
children = PrFilterV2Tracks(
Functor=ChildCut, Input=make_input_tracks()).Output
return CombineTracks(
ChildCut, Input=make_input_tracks()['v2Sel']).Output
combiner = CombineTracks(
NBodies=2,
VertexCut=VertexCut,
InputTracks=children,
......@@ -85,18 +147,8 @@ def new_two_track_MVA(
ChildDump=ChildDump,
CombinationDump=CombinationDump,
VertexDump=VertexDump,
DumpFileName='PrCombineTracks.root').OutputVerticesStorage
ftdec_v = 4
with FTRawBankDecoder.bind(DecodingVersion=ftdec_v):
gec = gec(FTDecodingVersion=ftdec_v)
NoPVFilter = FilterEmptyPVs()
new_two_track = new_two_track_MVA()
env = EverythingHandler(threadPoolSize=1, nEventSlots=1, evtMax=5000)
env.registerLine(
'two_track', algs=[gec, NoPVFilter,
make_odin(), new_two_track])
env.setupInputFromTestFileDB('MiniBrunel_2018_MinBias_FTv4_DIGI')
env.configure()
DumpFileName=dump_filename)
# TODO remove make_odin() from the control flow when configuration
# starts handling data flow in functors, see
# https://gitlab.cern.ch/lhcb/Moore/issues/51
return track_mva_prefilters() + [make_odin(), combiner]
......@@ -80,7 +80,7 @@ def make_raw_data():
@configurable
def make_odin(make_raw_data=make_raw_data):
return createODIN(RawEvent=make_raw_data).ODIN
return createODIN(RawEvent=make_raw_data()).ODIN
@configurable
......
......@@ -106,12 +106,12 @@ def _check_input_integrity(t, inputs, other_args, input_transform=None):
dh_inputs = configurable_inputs(t)
if set(dh_inputs).intersection(other_args):
raise TypeError(
'Inputs must be provided as DataHandles or Algorithms, \
please check these arguments: {}'.format(dh_inputs))
'Inputs must be provided as DataHandles or Algorithms, '
'please check these arguments: {}'.format(dh_inputs))
if not set(dh_inputs).issubset(inputs):
raise ConfigurationError(" ".join(
('please provide all inputs.',
'The ones detected here are: {}'.format(dh_inputs))))
raise ConfigurationError(
'Please provide all inputs. The ones need here are: {}'.format(
dh_inputs))
if input_transform:
input_transform_args = _get_args(input_transform)
assert set(inputs).issubset(
......
......@@ -53,7 +53,7 @@ def test_init():
# Must always provide all inputs
with pytest.raises(ConfigurationError) as e:
consumer = Algorithm(IntDataConsumer)
assert re.search(r'please provide all inputs.*InputLocation.*', str(e))
assert re.match(r'.*provide all inputs.*InputLocation.*', str(e))
# Type of inputs
with pytest.raises(TypeError) as e:
......
......@@ -25,7 +25,7 @@ def test_init():
with pytest.raises(ConfigurationError) as e:
Tool(FloatTool)
assert re.search(r'please provide all inputs.*Input.*', str(e))
assert re.match(r'.*provide all inputs.*Input.*', str(e))
t = Tool(FloatTool, Input=Algorithm(Producer))
assert len(t.inputs) == 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment