diff --git a/Hlt/RecoConf/python/RecoConf/track_refitting.py b/Hlt/RecoConf/python/RecoConf/track_refitting.py index aca98c6eac3da07796b18bc3b8cef6e5ee903239..fb9c6ac5fb7f60c8d465db97209a5ba12ff0db18 100644 --- a/Hlt/RecoConf/python/RecoConf/track_refitting.py +++ b/Hlt/RecoConf/python/RecoConf/track_refitting.py @@ -15,22 +15,35 @@ from PyConf.Algorithms import SelectFTClustersFromTracks, VPMicroClustersToVPLig from PyConf.Algorithms import SelectUTClustersFromTracks, UTHitClustersToUTHitHandlerConverter from RecoConf.legacy_rec_hlt1_tracking import make_ut_hit_clusters, make_PrStoreUTHit_hits - from RecoConf.legacy_rec_hlt1_tracking import make_velo_micro_clusters, make_VPClus_hits from RecoConf.legacy_rec_hlt1_tracking import make_FTRawBankDecoder_clusters from RecoConf.legacy_rec_hlt1_tracking import make_PrStoreSciFiHits_hits +# Algorithms to get the Pr hits +from PyConf.Algorithms import VPLightClustersToVPHitsConverter +from PyConf.Algorithms import UTHitClustersToPrUTHitsConverter + +# Algotihms to perform the fit from RecoConf.hlt2_tracking import get_track_master_fitter from RecoConf.hlt2_tracking import get_global_measurement_provider from PyConf.Algorithms import V1V1PrKalmanFilter -# algorithms to get the Pr hits -from PyConf.Algorithms import VPLightClustersToVPHitsConverter -from PyConf.Algorithms import UTHitClustersToPrUTHitsConverter +# Algorithms to take care of decay-tree refitting +from PyConf.Algorithms import LHCbIDOverlapRelationTableParticleToTrack +from PyConf.Algorithms import RecombineDecayTrees +from PyConf.Algorithms import FlattenDecayTree +from PyConf.Algorithms import SelectTracksForParticles +from Hlt2Conf.algorithms_thor import ParticleFilter -def refit_tracks(tracks, get_clusters_from_track=True, use_PrKF=False): +import Functors as F + +# Optional workflow on PV association +from PyConf.Algorithms import PVsEmptyProducer + + +def refit_tracks(tracks, get_clusters_from_track, use_PrKF): if get_clusters_from_track: velo_micro_clusters_on_tracks = SelectVPMicroClustersFromTracks( Inputs=[tracks]) @@ -94,11 +107,65 @@ def refit_tracks(tracks, get_clusters_from_track=True, use_PrKF=False): ReferenceExtrapolator=TrackMasterExtrapolator( MaterialLocator=get_global_materiallocator()), TrackAddClusterTool=clusters_on_track_tool, - MaxChi2PreOutlierRemoval=20, - MaxChi2=2.8, + MaxChi2PreOutlierRemoval= + 9999999, # disable - try to keep as many tracks as possible + MaxChi2= + 9999999, # disable - try to keep as many tracks as possible UniqueIDGenerator=make_unique_id_generator()), Input=tracks).OutputTracks refitted_tracks = track_refitter return refitted_tracks + + +def refit_decay_tree(input_particles, + input_pvs, + get_clusters_from_track=True, + use_PrKF=True): + """ Takes an input DataHandle that contains LHCb::Particles (such as the + output of a trigger line), and: + (1) finds out which particles are basic particles, and calls the + track refitter on those + (2) takes the refitted tracks, along with the relation table, + to then call the DecayTree recombiner which re-combines the + particles together, and fits again the decay vertices. + + The output contains particles, the new vertices, the new protoparticles, + and again a relation table between the old particles and the new ones. + + When use_PrKF is false, the TrackEventFitter is used to refit the tracks. + + When get_clusters_from_track is false, the clusters are instead searched + for in the standard raw event - this only works when this is persisted. + """ + flat_particles = FlattenDecayTree(InputParticles=input_particles) + basic_particles = ParticleFilter( + flat_particles.OutputParticles, + F.FILTER(F.ISBASICPARTICLE), # ideally swap to some F.HASTRACK functor + name="SelectBasicParticlesForRefit_{hash}") + + tracks_from_particles = SelectTracksForParticles( + Inputs=[basic_particles]).OutputTracks + + tracks_from_dst = refit_tracks( + tracks_from_particles, get_clusters_from_track, use_PrKF=use_PrKF) + + relation_table_match_by_veloid_to_track = LHCbIDOverlapRelationTableParticleToTrack( + MatchFrom=basic_particles, + MatchTo=tracks_from_dst, + IncludeVP=True, + IncludeFT=True, + IncludeUT=True).OutputRelations + + if input_pvs is None: + input_pvs = PVsEmptyProducer() + + recombined_trees = RecombineDecayTrees( + InputParticles=input_particles, + InputPVs=input_pvs, + InputTracks=tracks_from_dst, # the refitted tracks + InputTrackRelations=relation_table_match_by_veloid_to_track + ) # the relation table + + return recombined_trees