Example #1
0
def buildStream(stripping, streamName=''):
    """
    Create a StrippingStream from the lineBuilder database
    Usage:
    >>> streamDimuon = strippingStream('Stripping13','Dimuon')
    or:
    >>> conf = strippingConfiguration('Stripping13')
    >>> streamDimuon = strippingStream(conf,'Dimuon')
    
    """

    from StrippingConf.StrippingStream import StrippingStream
    from StrippingSettings.Utils import strippingConfiguration
    from StrippingSelections import lineBuilders

    stream = StrippingStream(streamName)

    if isinstance(stripping, basestring):
        _db = strippingConfiguration(stripping)
    else:
        _db = stripping

    for key in _db.keys():
        _conf = _db[key]
        if stream.name() in _conf['STREAMS']:
            _lb = lineBuilders()[_conf['BUILDERTYPE']](key, _conf['CONFIG'])
            stream.appendLines(_lb.lines())
    return stream
Example #2
0
def cloneStream(stream, newStreamName='Full', linePrefix='Full', prescale=1.0):
    """
	Clone the stream
	"""
    from StrippingConf.StrippingStream import StrippingStream
    lines = cloneLinesFromStream(stream, linePrefix, prescale)
    stream = StrippingStream(newStreamName)
    stream.appendLines(lines)
    return stream
Example #3
0
def cloneStream( stream, newStreamName = 'Full', linePrefix = 'Full', prescale = 1.0 ):
	"""
	Clone an entire stream, with a new prefix and a different prescale
	"""
	from StrippingConf.StrippingStream import StrippingStream
	lines = cloneLinesFromStream( stream, linePrefix, prescale )
	stream = StrippingStream( newStreamName )
	stream.appendLines( lines )
	return stream
Example #4
0
def buildStreams(stripping, WGs=None):
    """
    Build and return a set of StrippingStreams for a given
    stripping configuration.
    Usage:

    >>> streams = buildStreams('Stripping13')
    >>> for s in streams :
    ...   print s.name(), s.lines


    It is also possible to use a configuration dictionary
    directly:

    >>> conf = strippingConfiguration('Stripping13')
    >>> streams = buildStreams(conf)

    To select only streams belonging to the RD or the
    Gamma from trees WGs:

    >>> streams = buildStreams('stripping13', WGs = ['RD','GammaFromTrees'] )
    >>>

    """
    from StrippingConf.StrippingStream import StrippingStream
    from StrippingSettings.Utils import strippingConfiguration
    from StrippingSelections import lineBuilders

    streams = {}

    if isinstance(stripping, basestring):
        scdb = strippingConfiguration(stripping)
    else:
        scdb = stripping

    for k, v in scdb.iteritems():
        if 'STREAMS' in v.keys() and not WGs or 'WGs' in v.keys():
            if not WGs or any(WG for WG in v['WGs'] if WG in WGs):
                lb = lineBuilders()[v['BUILDERTYPE']](k, v['CONFIG'])
                addBuilderToStreamGrouping(streams, v, lb)
        else:
            raise Exception('Config', k,
                            'missing either STREAM or WG data data.')

    strippingStreams = []
    for stream in streams:
        lines = [line for line in streams[stream]]
        print('Creating ' + stream + ' stream with ' + str(len(lines)) +
              ' lines')
        strippingStreams.append(StrippingStream(stream, Lines=lines))
    return strippingStreams
Example #5
0
def buildStream(stripping, streamName='', WGs=None):
    """
    Create a StrippingStream from the lineBuilder database
    Usage:
    >>> streamDimuon = strippingStream('Stripping13','Dimuon')
    or:
    >>> conf = strippingConfiguration('Stripping13')
    >>> streamDimuon = strippingStream(conf,'Dimuon')

    """

    from StrippingConf.StrippingStream import StrippingStream
    from StrippingSettings.Utils import strippingConfiguration
    from StrippingSelections import lineBuilders
    from StrippingUtils.Utils import lineFromName

    stream = StrippingStream(streamName)

    if isinstance(stripping, basestring):
        _db = strippingConfiguration(stripping)
    else:
        _db = stripping

    for key in _db.keys():
        _conf = _db[key]
        if stream.name() in _conf['STREAMS']:
            if WGs and not any(WG for WG in _conf['WGs'] if WG in WGs):
                continue
            _lb = lineBuilders()[_conf['BUILDERTYPE']](key, _conf['CONFIG'])

            if isinstance(_conf['STREAMS'], dict):
                for linename in _conf['STREAMS'][stream.name()]:
                    line = lineFromName(_lb, linename)
                    if line:
                        stream.appendLines([line])
                    else:
                        raise Exception(
                            'The line you have requested does not exist ' +
                            linename)
            elif isinstance(_conf['STREAMS'], list):
                stream.appendLines(_lb.lines())
            else:
                raise Exception('Unsupported type, expected list ' +
                                'or dict for line-to-STREAM mapping')
    return stream
Example #6
0
def buildStreams(stripping):
    """
    Build and return a set of StrippingStreams for a given stripping
    configuration.
    Usage:

    >>> streams = buildStreams('Stripping13')
    >>> for s in streams :
    ...   print s.name(), s.lines


    It is also possible to use a configuration dictionary directly:

    >>> conf = strippingConfiguration('Stripping13')
    >>> streams = buildStreams(conf)
    
    """
    from StrippingConf.StrippingStream import StrippingStream
    streams = {}
    if isinstance(stripping, basestring):
        scdb = strippingConfiguration(stripping)
    else:
        scdb = stripping

    for k, v in scdb.iteritems():
        if 'STREAMS' in v.keys():
            for stream in v['STREAMS']:
                if stream in streams.keys():
                    streams[stream] += [k]
                else:
                    streams[stream] = [k]
        else:
            print 'ERROR: config', k, 'had no STREAMS data. Ignore!!!'
    builderMap = {}
    for builder in scdb.keys():
        builderMap[builder] = lineBuilder(scdb, builder)

    strippingStreams = []
    for stream, builderNames in streams.iteritems():
        lines = []
        for b in builderNames:
            lines += [line for line in builderMap[b].lines()]
        print 'Creating steam', stream, 'with lines', lines
        strippingStreams.append(StrippingStream(stream, Lines=lines))
    return strippingStreams
Example #7
0
def buildStreams(stripping,archive=None, WGs = None) :
    """
    Build and return a set of StrippingStreams for a given stripping
    configuration.
    Usage:

    >>> streams = buildStreams('Stripping13')
    >>> for s in streams :
    ...   print s.name(), s.lines


    It is also possible to use a configuration dictionary directly:

    >>> conf = strippingConfiguration('Stripping13')
    >>> archive = strippingArchive('Stripping13')
    >>> streams = buildStreams(conf,archive)

    """
    from StrippingConf.StrippingStream import StrippingStream

    streams = {}

    if isinstance(stripping, basestring) :
        scdb = _sConf(stripping)
        from StrippingArchive import strippingArchive
        archive=strippingArchive(stripping)
    else :
        scdb = stripping

    for k, v in scdb.iteritems() :
        if 'STREAMS' in v.keys() and not WGs or 'WGs' in v.keys():
            if not WGs or any( WG for WG in v['WGs'] if WG in WGs ):
                lb = archive.lineBuilders()[v['BUILDERTYPE']](k,v['CONFIG'])
                addBuilderToStreamGrouping( streams, v, lb )
        else:
            raise Exception('Config',k,'missing either STREAM or WG data data.')

    strippingStreams=[]
    for stream in streams:
        lines = [ line for line in streams[stream] ]
        print ( 'Creating ' + stream + ' stream with '
                + str( len(lines) ) + ' lines' )
        strippingStreams.append( StrippingStream( stream, Lines = lines ) )

    return strippingStreams
def ConfigureDaVinci():
    config = Swimming()
    from Configurables import DaVinci
    from StrippingConf.Configuration import StrippingConf
    from Configurables import ProcStatusCheck
    from Configurables import EventNodeKiller, GaudiSequencer
    from PhysSelPython.Wrappers import (AutomaticData, SelectionSequence,
                                        MultiSelectionSequence)

    # Get the stripping line
    from StrippingSettings.Utils import lineBuilderConfiguration
    strippingFile = None
    if config.getProp('StrippingFile') != 'none':
        strippingFile = config.getProp('StrippingFile')
    else:
        strippingFile = config.getProp('StrippingLineGroup')
    myconfig = lineBuilderConfiguration(config.getProp('StrippingVersion'),
                                        config.getProp('StrippingLineGroup'))
    import StrippingArchive
    mylineconf = getattr(
        __import__(
            'StrippingArchive.' +
            config.getProp('StrippingVersion') + '.Stripping' + strippingFile,
            globals(), locals(), [myconfig["BUILDERTYPE"]], -1),
        myconfig["BUILDERTYPE"])
    mylinedict = myconfig["CONFIG"]
    substitutions = config.getProp('StrippingConfigSubstitutions')
    print "mylinedict before substitutions:", mylinedict
    print "stripping config substitutions:", substitutions
    mylinedict.update(substitutions)
    print "mylineconf:", mylineconf
    print "mylinedict after substitutions:", mylinedict

    from StrippingConf.StrippingStream import StrippingStream
    stream = StrippingStream(config.getProp('StrippingStream') + "Swimming")
    allLines = mylineconf(config.getProp('StrippingLineGroup'),
                          mylinedict).lines()
    lines = []
    #lineNames = [l.split('/')[-1] for l in config.getProp('StripCands').keys()]
    lineNames = config.getProp('StrippingLines')
    print "lineNames:", lineNames
    for l in allLines:
        for lineName in lineNames:
            if l.outputLocation().find(lineName) != -1:
                lines.append(l)
                print l.outputLocation()
    stream.appendLines(lines)

    # Define the stream
    filterBadEvents = ProcStatusCheck()
    sc = StrippingConf(Streams=[stream],
                       MaxCandidates=2000,
                       AcceptBadEvents=False,
                       BadEventSelection=filterBadEvents)

    # Define the node killer, and make sure to kill everything corresponding to
    # the stream which we want to swim
    outputs = []
    from Configurables import Swimming__PVReFitter as ReFitter
    for l in lines:
        for f in l.filterMembers():
            if hasattr(f, 'ReFitPVs') and f.ReFitPVs:
                if not config.getProp('RefitPVs'):
                    log.warning('RefitPVs is not set, but stripping line applies refitting. Refitted ' + \
                                'PVs will be used for turning-point lifetime calculations.')
                    config.setProp('RefitPVs', True)
                t = f.PVReFitters['']
                f.PVReFitters = {'': 'Swimming::PVReFitter/PVReFitter'}
                f.addTool(ReFitter, 'PVReFitter')
                f.PVReFitter.PVReFitter = t
            elif not hasattr(f, 'Output'):
                continue
            # Remove the last item so we get everything (Particle, relations,
            # decayVertices, etc...
            o = '/'.join(f.Output.split('/')[:-1])
            outputs.append(o)
    print "Outputs are", outputs
    mykiller = EventNodeKiller("killStripping")
    # Some default nodes which we will want to kill in all cases
    nodestokill = outputs + ['Strip', '/Event/Rec/Vertex/Primary']
    mykiller.Nodes = nodestokill
    deathstar = GaudiSequencer("killStrippingSeq")
    deathstar.Members = [mykiller]

    # Configure DaVinci
    DaVinci().InputType = config.getProp('InputType')
    DaVinci().DataType = config.getProp('DataType')
    DaVinci().Simulation = config.getProp('Simulation')
    DaVinci().DDDBtag = config.getProp('DDDBtag')
    DaVinci().CondDBtag = config.getProp('CondDBtag')
    try:
        DaVinci().Persistency = config.getProp('Persistency')
    except AttributeError:
        print "DaVinci doesn't have a Persistency attribute to set"

    # The sequence for the swimming has to be configured
    # by hand inserting the node killer before it
    DaVinci().appendToMainSequence([deathstar])
    DaVinci().appendToMainSequence([sc.sequence()])

    # Since the name of the output file is configured in two places in DaVinci,
    # do some splitting.
    splitName = config.getProp('OutputFile').split(os.path.extsep)
    seqName = ''
    prefix = ''
    if len(splitName) <= 2:
        seqName = splitName[0]
        print "Warning, an output filename in three parts was specified. This does not work well, " + \
              " so 'Swimming.' will be prefixed."
        prefix = 'Swimming'
    else:
        prefix = splitName[0]
        seqName = os.path.extsep.join(splitName[1:-1])

    dstWriter = None
    print config.getProp('OutputType')

    # Offline candidate selection sequences
    sequences = []
    offCands = config.getProp('OffCands').keys()
    for i, cands in enumerate(offCands):
        data = AutomaticData(Location=cands + "/Particles")
        offSeq = SelectionSequence("OfflineCandidates_%d" % i,
                                   TopSelection=data)
        sequences.append(offSeq)

    # selection sequence for offline candidates
    muCands = config.getProp('MuDSTCands')
    for i, cands in enumerate(muCands):
        # Add extra selections for additional MuDSTCands
        data = AutomaticData(Location=cands + "/Particles")
        seq = SelectionSequence("MuDSTCands_%d" % i, TopSelection=data)
        sequences.append(seq)

    selectionSeq = MultiSelectionSequence(seqName, Sequences=sequences)

    if config.getProp('OutputType') == 'MDST':
        pack = False
        isMC = config.getProp("Simulation")
        SwimmingConf = config.getProp('MicroDSTStreamConf')
        SwimmingElements = config.getProp('MicroDSTElements')
        if SwimmingConf == False:
            from DSTWriters.Configuration import stripMicroDSTStreamConf
            SwimmingConf = stripMicroDSTStreamConf(pack=pack, isMC=isMC)
        if len(SwimmingElements) == 0:
            from DSTWriters.Configuration import stripMicroDSTElements
            from DSTWriters.microdstelements import CloneSwimmingReports, CloneParticleTrees, CloneTPRelations
            mdstElements = stripMicroDSTElements(pack=pack, isMC=isMC)
            SwimmingElements = [CloneSwimmingReports()]
            for element in mdstElements:
                SwimmingElements += [element]
                if type(element) == CloneParticleTrees:
                    SwimmingElements += [CloneTPRelations("P2TPRelations")]

        streamConf = {'default': SwimmingConf}
        elementsConf = {'default': SwimmingElements}
        try:
            from DSTWriters.__dev__.Configuration import MicroDSTWriter
        except:
            from DSTWriters.Configuration import MicroDSTWriter
        dstWriter = MicroDSTWriter('MicroDST',
                                   StreamConf=streamConf,
                                   MicroDSTElements=elementsConf,
                                   WriteFSR=config.getProp('WriteFSR'),
                                   OutputFileSuffix=prefix,
                                   SelectionSequences=[selectionSeq])
    elif config.getProp('OutputType') == 'DST':
        try:
            from DSTWriters.__dev__.streamconf import OutputStreamConf
            from DSTWriters.__dev__.Configuration import SelDSTWriter
        except ImportError:
            from DSTWriters.streamconf import OutputStreamConf
            from DSTWriters.Configuration import SelDSTWriter

        streamConf = OutputStreamConf(streamType = InputCopyStream,
                                      fileExtension = '.dst',
                                      extraItems = [config.getProp('SwimmingPrefix') + '/Reports#1'] +\
                                      list(set([l + '/P2TPRelations#1' for l in config.getProp('OffCands').values()])))
        SelDSTWriterElements = {'default': []}
        SelDSTWriterConf = {'default': streamConf}
        dstWriter = SelDSTWriter('FullDST',
                                 StreamConf=SelDSTWriterConf,
                                 MicroDSTElements=SelDSTWriterElements,
                                 WriteFSR=config.getProp('WriteFSR'),
                                 OutputFileSuffix=prefix,
                                 SelectionSequences=[selectionSeq])

    DaVinci().appendToMainSequence([dstWriter.sequence()])
Example #9
0
from StrippingSelections.StrippingSL import StrippingB2DMuForTauMu
#import actual selections
from StrippingSettings.Stripping28.LineConfigDictionaries_Semileptonic import B2DMuForTauMu

#**************************************************************************
# MODIFY STRIPPING CUTS for PIDs.
#---> PID is not applied to MC because badly modeled.
#---> Corrections with data are applied to MC PID variables
#---> Substitute the tauonic line PID cuts.
B2DMuForTauMu['CONFIG']['PIDmu'] = -99999
B2DMuForTauMu['CONFIG']['KaonPIDK'] = -99999
B2DMuForTauMu['CONFIG']['ProtonPIDp'] = -99999
B2DMuForTauMu['CONFIG']['PionPIDKTight'] = 99999
B2DMuForTauMu['CONFIG']['Hlt2Line'] = ""

MyStream = StrippingStream("B2DMuNuXANDTAU")
#create a line builder instance of type 'B2DMuForTauMu' and configure it with the 'CONFIG' dictionary.
confB2DMuForTauMu = StrippingB2DMuForTauMu.B2DMuForTauMuconf(
    "B2DMuForTauMu", B2DMuForTauMu['CONFIG'])

#Replace Mu/Pi/K/p Selections with NoPID particles
replaceDictFilterDesktop = {
    'MuforB2DMuForTauMu': 'Phys/StdAllNoPIDsMuons/Particles',
    'PiforB2DMuForTauMu': 'Phys/StdAllNoPIDsPions/Particles',
    'KforB2DMuForTauMu': 'Phys/StdAllNoPIDsKaons/Particles',
    'PforB2DMuForTauMu': 'Phys/StdAllNoPIDsProtons/Particles'
}
replaceDictVoidFilter = {
    'SelFilterPhys_StdAllLooseMuons_Particles':
    "\n 0<CONTAINS('Phys/StdAllNoPIDsMuons/Particles',True)\n ",
    'SelFilterPhys_StdLooseKaons_Particles':
from StrippingArchive.Stripping21.StrippingB2XMuMu import B2XMuMuConf

from StrippingSettings.Stripping21.LineConfigDictionaries_RD import B2XMuMu
from PhysSelPython.Wrappers import AutomaticData, Selection, SelectionSequence


B2XMuMu['CONFIG']['HLT_FILTER'] = ""
B2XMuMuConf = B2XMuMuConf("B2XMuMu", B2XMuMu['CONFIG'])
B2XMuMuLines = B2XMuMuConf.lines()
for line in B2XMuMuLines:
    print "CL DEBUG", line
    print "CL DEBUG", line.name()
stripline = B2XMuMuLines[0]
    
sc = StrippingConf( HDRLocation = "DecReports"  )
sstream = StrippingStream("TestStream")
sstream.appendLines([  stripline  ] )
sstream.OutputLevel = 2
sc.appendStream( sstream )
            
Strip_Location1 = stripline.outputLocation()
print Strip_Location1
StripSel1 = AutomaticData(Location = Strip_Location1)
print StripSel1
print "ALL OK"


rootintes = "/Event/AllStreams"
#---------------------------
# Run fixing XmumuLine
#---------------------------
Example #11
0
 if options.strippingFile != 'none':
     strippingFile = options.strippingFile
 else:
     strippingFile = options.strippingLine
 myconfig = lineBuilderConfiguration(options.strippingVersion,
                                     options.strippingLine)
 import StrippingSelections
 mylineconf = getattr(
     __import__('StrippingSelections.Stripping' + strippingFile, globals(),
                locals(), [myconfig["BUILDERTYPE"]], -1),
     myconfig["BUILDERTYPE"])
 mylinedict = myconfig["CONFIG"]
 print mylineconf
 print mylinedict
 from StrippingConf.StrippingStream import StrippingStream
 stream = StrippingStream(options.strippingStream + "Swimming")
 allLines = mylineconf(options.strippingLine, mylinedict).lines()
 lines = []
 for l in allLines:
     lineName = options.stripcands.split('/')[-1]
     if l.outputLocation().find(lineName) != -1:
         lines.append(l)
 stream.appendLines(lines)
 #Define the stream
 filterBadEvents = ProcStatusCheck()
 sc = StrippingConf(Streams=[stream],
                    MaxCandidates=2000,
                    AcceptBadEvents=False,
                    BadEventSelection=filterBadEvents)
 #Define the node killer, and make sure to kill everything corresponding to
 #the stream which we want to swim
Example #12
0
            if not WGs or any( WG for WG in v['WGs'] if WG in WGs ):
                try:
                    lb = lineBuilders()[v['BUILDERTYPE']](k,v['CONFIG'])
                except Exception, x:
                    log.error("Unable to configure %s because of %s" %(v['BUILDERTYPE'],str(x)))
                else:
                    addBuilderToStreamGrouping( streams, v, lb )
        else:
            raise Exception('Config',k,'missing either STREAM or WG data data.')

    strippingStreams=[]
    for stream in streams:
        lines = [ line for line in streams[stream] ]
        print ( 'Creating ' + stream + ' stream with '
                + str( len(lines) ) + ' lines' )
        strippingStreams.append( StrippingStream( stream, Lines = lines ) )
    return strippingStreams

def buildStreamsFromBuilder(conf, names ):
    """
    Build and return a set of StrippingStreams for a given line builder configuration
    Usage:

    >>> streams = buildStreamsFromBuilder(somelinebuilder, 'B2ppipiSigmacmm_Lcpi')
    """
    
    from StrippingConf.StrippingStream import StrippingStream
    from StrippingSettings.Utils import strippingConfiguration
    from StrippingSelections import lineBuilders

    streams = {}
                               "StdNoPIDsKaons",
                               "StdNoPIDsPions",
                               "Sel_Bd2KstarMuMu_DiMuon",
                               "Sel_Bd2KstarMuMu_Kstar",
                               "StrippingBd2KstarMuMu_BdToKstarMuMuLine" ]
###
# DaVinci
###
## Preselection

from StrippingConf.Configuration import StrippingConf
from StrippingConf.StrippingStream import StrippingStream

from StrippingArchive.Utils import lineBuilder
lineBuilder = lineBuilder('Stripping17', 'Bd2KstarMuMu')
stream = StrippingStream("BKstarMuMuTest", Lines = lineBuilder.lines())
sc = StrippingConf()
sc.appendStream( stream )

from Configurables import DaVinci
DaVinci().UserAlgorithms = [ trueSeq ]
DaVinci().MoniSequence = [ TestCorrelations ]
DaVinci().appendToMainSequence( [ sc.sequence() ] )
########################################################################
#-- GAUDI jobOptions generated on Tue Jan 18 17:40:43 2011
#-- Contains event types : 
#--   11114004 - 1 files - 10000 events - 2.78 GBytes
# MC_2010_428935_2010-Sim08Reco06-withTruth_11114004
#
from Gaudi.Configuration import * 
Example #14
0
from Gaudi.Configuration import *
from GaudiKernel.SystemOfUnits import *

MessageSvc().Format = "% F%30W%S%7W%R%T %0W%M"
#######################################################################
#
# Selection
#

from StrippingConf.Configuration import StrippingConf
from StrippingConf.StrippingStream import StrippingStream
from StrippingArchive.Utils import lineBuilder

lineBuilder = lineBuilder('Stripping17', 'BetaS')
line = lineBuilder.lineFromName('StrippingBetaSBd2JpsiKsDetachedLine')
stream = StrippingStream("B2JpsiXTest", Lines=[line])
sc = StrippingConf()
sc.appendStream(stream)

########################################################################
#
# The Decay Tuple
#
from Configurables import DecayTreeTuple

tuple = DecayTreeTuple("Tuple")
tuple.ToolList += [
    "TupleToolMCTruth", "TupleToolMCBackgroundInfo", "TupleToolGeometry",
    "TupleToolKinematic", "TupleToolPropertime", "TupleToolPrimaries",
    "TupleToolEventInfo", "TupleToolTrackInfo"
    #    , "TupleToolTISTOS"