From f9df34f86411ca775982ef6e3456c3f52eb8d97a Mon Sep 17 00:00:00 2001
From: Eduardo Rodrigues <eduardo.rodrigues@cern.ch>
Date: Thu, 20 Sep 2018 09:58:01 +0000
Subject: [PATCH] Merge branch 'apearce-LHCBPS-1807' into '2017-patches'

Truth-match objects beyond the standard HLT2 reconstruction in Tesla

See merge request lhcb/DaVinci!246

(cherry picked from commit 89ed5446eac483219158f5e68b754466b63a22ea)

86cfcf02 Truth match additional Track and ProtoParticle containers.
5d0b2b2c Hard-code the list of extra locations.
1b95995a Clarify NeverFail logic.
---
 Phys/Tesla/python/Tesla/Configuration.py | 44 +++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/Phys/Tesla/python/Tesla/Configuration.py b/Phys/Tesla/python/Tesla/Configuration.py
index a98509b6c..8b5bef0ee 100644
--- a/Phys/Tesla/python/Tesla/Configuration.py
+++ b/Phys/Tesla/python/Tesla/Configuration.py
@@ -71,6 +71,40 @@ from LHCbKernel.Configuration import *
 from RawEventCompat.Configuration import ReverseDict as RawEventLocationsToBanks
 
 
+# Locations of Track and ProtoParticle objects created in HLT2 that are not
+# defined as part of the 'standard reconstruction' that is saved in PersistReco
+# We need to know these locations in Tesla so that we can truth match the objects
+# See LHCBPS-1807 for more details, and how this list was obtained
+_extra_track_locations = [
+    # These two locations are defined as part of the standard HLT2 reconstruction
+    # 'Hlt2/Track/Best/Downstream',
+    # 'Hlt2/Track/Best/Long',
+    'Hlt2/Track/Best/LongDownstreamClones',
+    'Hlt2/Track/Best/LongV0Vertices',
+    'Hlt2/Track/Best/Muon',
+    'Hlt2/Track/Best/Ttrack',
+    'Hlt2/Track/ComplementForward',
+    'Hlt2/Track/Downstream',
+    'Hlt2/Track/Forward',
+    'Hlt2/Track/Match',
+    'Hlt2/Track/Seeding',
+    'Hlt2/TrackBest/PID/MuonSegments',
+    'Hlt2/TrackEff/Track/FullDownstream',
+    'Hlt2/TrackEff/Track/MuonTT',
+    'Hlt2/TrackEff/Track/StandaloneMuon',
+    'Hlt2/TrackEff/Track/VeloMuon'
+]
+_extra_protoparticle_locations = [
+    # These two locations are defined as part of the standard HLT2 reconstruction
+    # 'Hlt2/ProtoP/Downstream/Charged/WithAllPIDs',
+    # 'Hlt2/ProtoP/Long/Charged/WithAllPIDs',
+    'Hlt2/ProtoP/Best/FullDownstream',
+    'Hlt2/ProtoP/Best/MuonTT',
+    'Hlt2/ProtoP/Best/VeloMuon',
+    'Hlt2/ProtoP/Hlt2/TrackEff/Velo'
+]
+
+
 def _strip_root(root, locs):
     """Return list of paths `loc` stripped of the `root` prefix.
 
@@ -625,12 +659,16 @@ class Tesla(LHCbConfigurableUser):
 
     def _configureTruthMatching(self, name, packing):
         output_level = self.getProp('OutputLevel')
+        extra_track_locs = [os.path.join('/Event', self.base, l) for l in _extra_track_locations]
+        extra_proto_locs = [os.path.join('/Event', self.base, l) for l in _extra_protoparticle_locations]
 
         # Locations of the objects we want to truth-match
         track_locs = [packing.outputs['Hlt2LongTracks'],
                       packing.outputs['Hlt2DownstreamTracks']]
+        track_locs += extra_track_locs
         proto_locs = [packing.outputs['Hlt2LongProtos'],
                       packing.outputs['Hlt2DownstreamProtos']]
+        proto_locs += extra_proto_locs
         cluster_locs = [packing.outputs['Hlt2CaloClusters']]
         neutral_locs = [packing.outputs['Hlt2NeutralProtos']]
 
@@ -720,7 +758,11 @@ class Tesla(LHCbConfigurableUser):
                     DataCopy('Copy{0}'.format(loc.replace('/', '')),
                              What=loc,
                              Target=os.path.join(base, loc),
-                             NeverFail=False,
+                             # It's very possible that the extra locations
+                             # might not exist, so no relations table will be
+                             # created; we don't mind the copying failing in
+                             # those cases
+                             NeverFail=True if loc.replace('Relations/', '/Event/') in (extra_track_locs + extra_proto_locs) else False,
                              OutputLevel=output_level)
                     for loc in relationsLocations
                     if self.base in loc
-- 
GitLab