From 6c02fa8088263f738c918e5bbe4572ca2e46f461 Mon Sep 17 00:00:00 2001 From: Alex Pearce <alex.pearce@cern.ch> Date: Tue, 25 Jul 2017 14:37:24 +0200 Subject: [PATCH] Unify logic for un/filtered MC productions. --- Phys/Tesla/python/Tesla/Configuration.py | 79 ++++++++++-------------- 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/Phys/Tesla/python/Tesla/Configuration.py b/Phys/Tesla/python/Tesla/Configuration.py index d583f5c62..eaddbc6d1 100644 --- a/Phys/Tesla/python/Tesla/Configuration.py +++ b/Phys/Tesla/python/Tesla/Configuration.py @@ -145,11 +145,6 @@ class Tesla(LHCbConfigurableUser): # Add it to a sequence return assoctr - def _configureDigitsTruth(self) : - from Configurables import CaloDigit2MCLinks2Table - assocdigits = CaloDigit2MCLinks2Table("TurboDigitAssoc") - return - def _configureClustersAndProtosTruth(self,digits,clusters,protos) : retSeq = GaudiSequencer("NeutralTruth") clusterTabLoc = self.base + "Relations/CaloClusters" @@ -165,8 +160,6 @@ class Tesla(LHCbConfigurableUser): # When filtering MC, the relations table cloners will copy the tables # to /Event/Turbo for us. Otherwise we create them there directly protoTabLoc = "Relations/Turbo/NeutralPP2MC" - if not self.getProp("FilterMC"): - protoTabLoc = os.path.join(self.base, protoTabLoc) assocneutral = NeutralPP2MC("TurboNeutralPP2MC") assocneutral.InputData += protos assocneutral.OutputLevel = self.getProp('OutputLevel') @@ -182,7 +175,7 @@ class Tesla(LHCbConfigurableUser): DataOnDemandSvc().AlgMap["MC/Vertices"] = "UnpackMCVertex" - def _filterMCParticlesSequence(self, relations_locations): + def _copyMCRelationsAndParticlesSequence(self, relations_locations): """Copy signal and associated MC particles to microDST-like locations. In the Stripping, the microDST machinery only saves a subset of the @@ -197,35 +190,39 @@ class Tesla(LHCbConfigurableUser): microDST algorithms, using the relations tables Tesla makes to find the MC particles that have been associated to the reconstruction. """ - if not self.getProp('FilterMC'): - return - from Configurables import ( CopyProtoParticle2MCRelations, CopySignalMCParticles ) output_prefix = self.base.replace('/', '') + algorithms = [] - # Algorithm to clone the existing relations tables and the MC particles - # and vertices these tables point to from their original location to - # the same location prefixed by /Event/Turbo + # Clone existing relations tables from their original location to the + # same location prefixed by /Event/Turbo + # If FilterMC, also clone the MCParticle objects the tables point to copy_pp2mcp = CopyProtoParticle2MCRelations() copy_pp2mcp.InputLocations = relations_locations copy_pp2mcp.OutputPrefix = output_prefix # Don't use the assumed copy of the input ProtoParticle objects, as # Tesla doesn't need to copy them (they're already under /Event/Turbo) copy_pp2mcp.UseOriginalFrom = True + # Only clone the MCParticle objects when filtering + if not self.getProp('FilterMC'): + copy_pp2mcp.ClonerType = 'NONE' + algorithms.append(copy_pp2mcp) - # Algorithm to clone all MC particles and vertices that are associated - # to the simulated signal process (using LHCb::MCParticle::fromSignal) - copy_signal_mcp = CopySignalMCParticles() - copy_signal_mcp.OutputPrefix = output_prefix - # Don't copy the associated reconstruction, as Tesla already saves it - copy_signal_mcp.SaveAssociatedRecoInfo = False + # Clone all MC particles and vertices that are associated to the + # simulated signal process (using LHCb::MCParticle::fromSignal) + if self.getProp('FilterMC'): + copy_signal_mcp = CopySignalMCParticles() + copy_signal_mcp.OutputPrefix = output_prefix + # Don't copy the associated reconstruction, as Tesla already saves + # it + copy_signal_mcp.SaveAssociatedRecoInfo = False + algorithms.append(copy_signal_mcp) - algorithms = [copy_pp2mcp, copy_signal_mcp] - seq = GaudiSequencer('TurboMCFiltering', Members=algorithms) + seq = GaudiSequencer('TurboMCCloning', Members=algorithms) return seq @@ -365,13 +362,7 @@ class Tesla(LHCbConfigurableUser): assocpp=ChargedPP2MC("TurboProtoAssocPP") assocpp.OutputLevel = self.getProp('OutputLevel') assocpp.VetoEmpty=True - # When filtering MC, the relations table cloners will copy the - # tables to /Event/Turbo for us. Otherwise we create them there - # directly - tesROOT = "/Event/" - if not self.getProp("FilterMC"): - tesROOT = os.path.join(tesROOT, self.base) - assocpp.RootInTES=tesROOT + assocpp.RootInTES="/Event/" # Start with an empty input list, so we don't accidentally create # relations for non-Turbo/non-PersistReco objects assocpp.InputData = [] @@ -407,11 +398,10 @@ class Tesla(LHCbConfigurableUser): NeutralProtoSeq = GaudiSequencer("NeutralTruthSequencer") ## Add the digits associator - outputDigiLoc = tesROOT + "Digi2MCP" from Configurables import CaloDigit2MCLinks2Table + outputDigiLoc = os.path.join(self.base, "Relations/CaloDigits") assocdigits = CaloDigit2MCLinks2Table("TurboDigitAssoc") assocdigits.OutputLevel = self.getProp('OutputLevel') - outputiDigiLoc = tesROOT + "Relations/CaloDigits" assocdigits.Output = outputDigiLoc ## Add the cluster associator @@ -433,31 +423,24 @@ class Tesla(LHCbConfigurableUser): neutralProtosTot+=[protos] # Configure - self._configureDigitsTruth() protoneutral, retSeq = self._configureClustersAndProtosTruth(outputDigiLoc,neutralClustersTot,neutralProtosTot) NeutralProtoSeq.Members+=[retSeq] # Add standard Turbo locations if not packing - outputPPLoc = tesROOT+'Relations/Turbo/' if not self.getProp('Pack'): - writer.OptItemList+=[ - outputPPLoc + 'Protos' + '#99' - ] - if not self.getProp('Pack'): - writer.OptItemList+=[ - protoneutral + '#99' - ] + writer.OptItemList.append( + os.path.join(self.base, 'Relations') + '#99' + ) # Add final sequences TeslaReportAlgoSeq.Members+=[ChargedProtoSeq,NeutralProtoSeq] - # Sequence to copy the relations tables, and the subset of MC - # particles used by those tables, into /Event/Turbo - if self.getProp("FilterMC"): - relationsLocations = [os.path.join('Relations', path) - for path in assocpp.InputData] - relationsLocations.append(protoneutral) - filterMCSeq = self._filterMCParticlesSequence(relationsLocations) - TeslaReportAlgoSeq.Members += [filterMCSeq] + # Sequence to copy the relations tables, and optionally the subset + # of MC particles used by those tables, into /Event/Turbo + relationsLocations = [os.path.join('Relations', path.replace('/Event/', '')) + for path in assocpp.InputData] + relationsLocations.append(protoneutral) + filterMCSeq = self._copyMCRelationsAndParticlesSequence(relationsLocations) + TeslaReportAlgoSeq.Members += [filterMCSeq] if self.getProp('Pack'): packer = PackParticlesAndVertices( name = "TurboPacker", -- GitLab