diff --git a/Phys/DaVinci/python/DaVinci/Configuration.py b/Phys/DaVinci/python/DaVinci/Configuration.py index c0d494944306ab040a80c420de47e24edfb9fa1d..545828040fe7c6123308777f080ca67d88ada8d7 100644 --- a/Phys/DaVinci/python/DaVinci/Configuration.py +++ b/Phys/DaVinci/python/DaVinci/Configuration.py @@ -15,7 +15,7 @@ High level configuration tools for DaVinci. from LHCbKernel.Configuration import * from Configurables import GaudiSequencer from Configurables import ( LHCbConfigurableUser, LHCbApp, - PhysConf, AnalysisConf, + PhysConf, DstConf, LumiAlgsConf, TurboConf, FlavourTaggingConf ) from Configurables import ToolSvc, DataOnDemandSvc from LumiAlgs.LumiIntegratorConf import LumiIntegratorConf @@ -40,7 +40,7 @@ class DaVinci(LHCbConfigurableUser) : "EvtMax" : -1 # Number of events to analyse , "SkipEvents" : 0 # Number of events to skip at beginning for file , "PrintFreq" : 1000 # The frequency at which to print event numbers - , "DataType" : '' # Data type, can be ['2008','2009','MC09','2010','2011','2012','2015','2016','2017','2018','Upgrade'] Forwarded to PhysConf, AnalysisConf, DstConf and LHCbApp. MUST be set. + , "DataType" : '' # Data type, can be ['2008','2009','MC09','2010','2011','2012','2015','2016','2017','2018','Upgrade'] Forwarded to PhysConf, DstConf and LHCbApp. MUST be set. , "Simulation" : False # set to True to use SimCond. Forwarded to PhysConf , "DDDBtag" : "" # Tag for DDDB. Default as set in DDDBConf for DataType , "CondDBtag" : "" # Tag for CondDB. Default as set in DDDBConf for DataType @@ -79,7 +79,7 @@ class DaVinci(LHCbConfigurableUser) : "EvtMax" : """ Number of events to analyse """ , "SkipEvents" : """ Number of events to skip at beginning for file """ , "PrintFreq" : """ The frequency at which to print event numbers """ - , "DataType" : """ Data type, can be ['2008','2009','MC09','2010','2011','2012','2015','2016','2017','2018','Upgrade'] Forwarded to PhysConf, AnalysisConf, DstConf and LHCbApp """ + , "DataType" : """ Data type, can be ['2008','2009','MC09','2010','2011','2012','2015','2016','2017','2018','Upgrade'] Forwarded to PhysConf, DstConf and LHCbApp """ , "Simulation" : """ set to True to use SimCond. Forwarded to PhysConf """ , "DDDBtag" : """ Tag for DDDB. Default as set in DDDBConf for DataType """ , "CondDBtag" : """ Tag for CondDB. Default as set in DDDBConf for DataType """ @@ -110,7 +110,6 @@ class DaVinci(LHCbConfigurableUser) : __used_configurables__ = [ PhysConf , - AnalysisConf , DstConf , LumiAlgsConf , LumiIntegratorConf, @@ -295,7 +294,6 @@ class DaVinci(LHCbConfigurableUser) : self.setOtherProps(LHCbApp(),["DataType","CondDBtag","DDDBtag", "DQFLAGStag","Simulation","IgnoreDQFlags"]) self.setOtherProps(PhysConf(),["DataType","Simulation","InputType","Detectors"]) - self.setOtherProps(AnalysisConf(),["DataType","Simulation","InputType","RootInTES"]) self.setOtherProps(DstConf(),["DataType","Turbo"]) if self.getProp("Turbo"): @@ -348,7 +346,7 @@ class DaVinci(LHCbConfigurableUser) : return di def _init(self): - from Configurables import (PhysConf,AnalysisConf) + from Configurables import PhysConf inputType = self.getProp( "InputType" ).upper() @@ -380,6 +378,115 @@ class DaVinci(LHCbConfigurableUser) : # # Set MC # + def configureMC(self): + """ + Define DaVinciAssociators. Do MC unpacking. + """ + from CaloKernel.ConfUtils import getAlgo + from Configurables import NeutralPP2MC, ChargedPP2MC + + root_ = '/Event' + if self.getProp("InputType") == 'MDST' and self.getProp('RootInTES'): + root_ = self.getProp('RootInTES') + + self.unpackMC(root_) + + ## offline neutral protoparticles + alg1 = getAlgo( + NeutralPP2MC, ## type + 'NeutralPP2MC', ## base-name + 'Offline', ## context + root_ + '/Relations/Rec/ProtoP/Neutrals', ## base-location + True) ## on-demand + + ## hlt neutral protoparticles + alg2 = getAlgo( + NeutralPP2MC, ## type + 'NeutralPP2MC', ## base-name + 'Hlt', ## context + root_ + '/Relations/Rec/ProtoP/Neutrals', ## base-location + True) ## on-demand + + from Configurables import DataOnDemandSvc, ChargedPP2MC + + if root_ != '/Event': + alg1.RootInTES = root_ + ChargedPP2MC(RootInTES=root_) + + dod = DataOnDemandSvc() + dod.AlgMap[root_ + '/Relations/Rec/ProtoP/Charged'] = ChargedPP2MC() + dod.AlgMap[root_ + '/Relations/Rec/ProtoP/Upstream'] = ChargedPP2MC() + + # + # Unpack MC + # + def unpackMC(self, rootInTES): + """ + Do MC unpacking for objects under rootInTES + """ + import os + from Configurables import UnpackMCParticle, UnpackMCVertex + + mcRoot = os.path.join(rootInTES, "MC") + + log.info("Will unpack MC objects to {0}".format(mcRoot)) + + particlesOutput = os.path.join(mcRoot, "Particles") + verticesOutput = os.path.join(mcRoot, "Vertices") + + dod = DataOnDemandSvc() + + dod.NodeMap[mcRoot] = "DataObject" + + dod.AlgMap[particlesOutput] = UnpackMCParticle(RootInTES=rootInTES) + dod.AlgMap[verticesOutput] = UnpackMCVertex(RootInTES=rootInTES) + + ## for uDST + if mcRoot != '/Event/MC': + ## create the directory (if missing) + dod.NodeMap[rootInTES + '/pSim'] = 'DataObject' + from Configurables import Gaudi__DataLink as Link + for name, target, what in [ + ## process ``pMC'' and ``pSim'' variants of uDST coherently + ('LINK:MC2Sim4Particles', rootInTES + '/pSim/MCParticles', + rootInTES + '/pMC/Particles'), + ('LINK:MC2Sim4Vertices', rootInTES + '/pSim/MCVertices', + rootInTES + '/pMC/Vertices'), + # In case any algorithm has a hard-coded dependency on /Event/MC/..., + # creates links from the location under RootInTES to /Event/MC + ('LINK:MCParticles', '/Event/MC/Particles', + rootInTES + '/MC/Particles'), + ('LINK:MCVertices', '/Event/MC/Vertices', + rootInTES + '/MC/Vertices'), + ]: + dod.AlgMap[target] = Link( + name, Target=target, What=what, OutputLevel=5) + log.debug( + 'Set additional MC->SIM links %s -> %s ' % (what, target)) + + ## some non-trivial action for non-trivial settings + from Configurables import GaudiSequencer + dod.AlgMap[particlesOutput] = GaudiSequencer( + "SEQ:MCParticles", + Members=[ + dod.AlgMap[particlesOutput], + Link( + 'LINK:MCParticles2MC', + Target=particlesOutput, + What='/Event/MC/Particles', + OutputLevel=5) + ]) + dod.AlgMap[verticesOutput] = GaudiSequencer( + "SEQ:MCVertices", + Members=[ + dod.AlgMap[verticesOutput], + Link( + 'LINK:MCVertices2MC', + Target=verticesOutput, + What='/Event/MC/Vertices', + OutputLevel=5) + ]) + def redoMCLinks(self, init): """ Redo MC links. @@ -821,6 +928,10 @@ class DaVinci(LHCbConfigurableUser) : self._defineEvents() self._defineInput() self._rootFiles() + log.info("Applying Analysis configuration") + log.info(self) + if (self.getProp("Simulation")): + self.configureMC() self._upgradeAction() self.tagging() self.standardParticles()