Commit 8ae635a8 authored by Vanya Belyaev's avatar Vanya Belyaev Committed by Alex Pearce
Browse files

- Selections.py - add RebuildSelection - useful tool to rerun/rebuild...

- Selections.py - add RebuildSelection - useful tool to rerun/rebuild common/standard selection ignoring the input from the tape

Cherry-picked from Phys, commit 2499b5f0.
parent 9e38941b
......@@ -5,6 +5,12 @@
! Purpose : Helper python classes for writing offline selections
!-----------------------------------------------------------------------------
! 2016-11-21 - Vanya Belyaev
Selections.py, Wrappers.py
- add RebuildSelection - useful tool to rerun/rebuild common/standard
selection ignoring the input from the tape
! 2016-05-09 - Vanya Belyaev
- Wrappers.py:
(re)add FilterSelections
......
......@@ -23,6 +23,7 @@
# - LimitSelection : limit selection
# - CheckPVSelection : embed CheckPV algorithm into selectiton sequence
# - MomentumScaling : insert momentum scaling into selectiton sequence
# - RebuildSelection : re-run/re-build some existing common/standard selections
#
# @author Juan PALACIOS
# @author Vanya BELYAEV Ivan.Belyaev@itep.ru
......@@ -34,7 +35,7 @@
""" Collection of high-level blocks for ``Selections''-framework:
Basic blocks:
- AutomaticData : selection that gets data from TES (or Datra-On-Demand)
- AutomaticData : selection that gets data from TES (or Data-On-Demand)
- MergedSelection : merge several selections into one ('OR'-mode)
- SelectionSequence : create the selection sequence
- MultiSelectionSequence : create the sequence for several selections
......@@ -50,6 +51,7 @@ Derived blocks:
- LimitSelection : limit selection
- CheckPVSelection : embed CheckPV algorithm into selectiton sequence
- MomentumScaling : insert momentum scaling into selectiton sequence
- RebuildSelection : re-run/re-build some existing common/standard selections
"""
# =============================================================================
__author__ = 'Juan PALACIOS, Vanya BELYAEV'
......@@ -72,6 +74,7 @@ __all__ = ( 'AutomaticData' ,
##
'CheckPVSelection' ,
##
'RebuildSelection' ,
'MomentumScaling'
)
# =============================================================================
......
......@@ -17,6 +17,7 @@ are available:
- CheckPVSelection Specialization of PassThroughSelection to limit the selection to use CheckPV
- LimitSelection Specialization of PassThroughSelection to limit the selection
- MomentumScaling ``pseudo-selection'' that applyes (globally) Momentum calibration
- RebuildSelection re-run/re-build some existing common/standard selections
- SimpleSelection simple compact 1-step way to create the selection
- FilterSelection Specialization of SimpleSelection for filtering using FilterDesktop
- CombineSelection Specialization of SimpleSelection for CombineParticles algorithm
......@@ -51,6 +52,7 @@ __all__ = ( 'DataOnDemand' ,
##
'CheckPVSelection' ,
##
'RebuildSelection' ,
'MomentumScaling' ## ``pseudo-selection'' to aplly (globaly) momentum sclaing
)
......@@ -1096,7 +1098,91 @@ class MomentumScaling(UniquelyNamedObject ,
algorithm = _alg ,
outputLocation = RequiredSelection.outputLocation(),
requiredSelections = [RequiredSelection] )
# =============================================================================
## "Rebuild"-selection:
# A way to rerun/rebuild the existing "standard/common" selection, ignoring
# the objects on tape. It is *very* useful for e.g. MC-uDST.
# Essentially it is *vital* for "inclusive" lines in MC-uDST
# @code
# muons = RebuildSelection ( 'StdAllNoPIDsMuons' ) ## by name
#
# from CommonParticles.StdLooseProtons import StdLooseProtons
# protons = RebuildSelection ( StdLooseProtons ) ## by algorithm
#
# from StrandardParticles StdLoosePions
# pions = RebuildSelection ( StdLoosePions ) ## by selection
# @endcode
# @see Selection
# @see AutomaticData
# @see CommonParticles
# @see StandardParticles
# @author Vanya BELYAEV Ivan.Belyaev@itep.ru
# @date 2016-11-09
def RebuildSelection ( selection , replace = True , prefix = 'REBUILD:%s' ) :
""" ``Rebuild''-selection:
A way to rerun/rebuild the existing ``standard/common'' selection, ignoring
the objects on tape. It is *very* useful for e.g. MC-uDST.
Essentially it is *vital* for ``inclusive'' lines in MC-uDST
>>> muons = RebuildSelection ( 'StdAllNoPIDsMuons' ) ## by name
>>> from CommonParticles.StdLooseProtons import StdLooseProtons
>>> protons = RebuildSelection ( StdLooseProtons ) ## by algorithm
>>> from StandardParticles StdLoosePions
>>> pions = RebuildSelection ( StdLoosePions ) ## by selection
"""
if isinstance ( selection , AutomaticData ) :
n = selection .name()
n = n[:n.find('_Particles')]
d,r,n = n.rpartition('_')
if r and n : selection = n
if isinstance ( selection , str ) :
import importlib
COMMON = importlib.import_module ( 'CommonParticles.%s' % selection )
algorithm = COMMON.algorithm
if not algorithm :
raise AttributeError('No proper algorithm is found!')
elif isinstance ( selection , Configurable ) : algorithm = selection
else :
raise AttributeError("Unknown selection type")
inputs = []
if hasattr ( algorithm , 'Inputs' ) :
for i in algorithm.Inputs :
ii = i[:i.rfind('/Particles')]
d,s,n = ii.rpartition('/')
if s and n :
## recursion starts here
ss = RebuildSelection ( n , replace , prefix )
inputs.append ( ss )
aname = algorithm.name()
try :
NAME = prefix % aname
except:
NAME = prefix + aname
import StandardParticles as SP
if not hasattr ( SP , 'rebuild' ) : SP.rebuild = {}
sel = SP.rebuild.get( NAME , None )
if not sel :
algorithm.Inputs = []
sel = Selection ( NAME , Algorithm = algorithm , RequiredSelections = inputs )
SP.rebuild [ NAME ] = sel
if replace : setattr ( SP , aname , sel )
return sel
# =============================================================================
# The END
# =============================================================================
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