Example #1
0
def configure ( datafiles        ,
                catalogs = []    ,
                castor   = False ,
                params   = {}    ) :
    """
    Configure the job
    """
    
    ##
    ## 1. Static configuration using "Configurables"
    ##

    the_year = '2012'
    from Configurables import DaVinci
    dv = DaVinci (
        DataType = the_year ,
        ) 
    
    alg_name = 'MyAlg'
    davinci.UserAlgorithms += [ alg_name ]
   
    from Configurables import CondDB
    CondDB ( LatestGlobalTagByDataType = the_year )
    
    from Configurables import LHCbApp
    LHCbApp().XMLSummary = 'summary.xml'
    
    from BenderTools.Utils import silence
    silence()
    
    ## define/set the input data 
    setData ( datafiles , catalogs )
    

    
    ##
    ## jump into the wonderful world of the actual Gaudi components!
    ## 
    
    ## get the actual application manager (create if needed)
    gaudi = appMgr() 
    
    ## create local algorithm:
    
    alg = Template(
        alg_name          ## algorithm instance name 
        )

    
    return SUCCESS
Example #2
0
def configure(
        inputdata,  ## the list of input files  
        catalogs=[],  ## xml-catalogs (filled by GRID)
        castor=False,  ## use the direct access to castor/EOS ? 
        params={}):

    ## import DaVinci
    from Configurables import DaVinci

    decay = '[(D0 =>  K-  mu+ nu_mu) && ~(D0 --> K- (pi0|eta) mu+ nu_mu ... )]CC'
    decay_K = '[(D0 => ^K-  mu+ nu_mu) && ~(D0 --> K- (pi0|eta) mu+ nu_mu ... )]CC'
    decay_mu = '[(D0 =>  K- ^mu+ nu_mu) && ~(D0 --> K- (pi0|eta) mu+ nu_mu ... )]CC'

    from PhysConf.Filters import LoKi_Filters
    fltrs = LoKi_Filters(MC_Code="has ( MCDECTREE('%s') )" % decay,
                         MC_Preambulo=["from LoKiCore.functions import has"])

    ## delegate the actual configuration to DaVinci
    dv = DaVinci(DataType='2012',
                 EventPreFilters=fltrs.filters('MC-filter'),
                 InputType='DST',
                 Simulation=True,
                 TupleFile='Xuhao.root',
                 DDDBtag='Sim08-20130503-1',
                 CondDBtag='Sim08-20130503-1-vc-md100')

    ##
    ## reconstruct D0 -> K mu candidates
    ##
    from StandardParticles import StdAllLooseKaons as kaons
    from StandardParticles import StdAllLooseMuons as muons

    from PhysSelPython.Wrappers import SimpleSelection
    from GaudiConfUtils.ConfigurableGenerators import FilterDesktop
    #
    true_kaons = SimpleSelection(
        'MCTrueKaon',  ## selection name 
        FilterDesktop,  ## algorithm type
        [kaons],  ## input/required selection
        ## algorithm propperties
        Preambulo=["from LoKiPhysMC.decorators import *"],
        Code="mcMatch ('%s', 2 )" % decay_K)
    #
    true_muons = SimpleSelection(
        'MCTrueMuon',  ## selection name 
        FilterDesktop,  ## algorithm type
        [muons],  ## input/required selection
        ## algorithm propperties
        Preambulo=["from LoKiPhysMC.decorators import *"],
        Code="mcMatch ('%s', 2 )" % decay_mu)

    from GaudiConfUtils.ConfigurableGenerators import CombineParticles
    sel_D0 = SimpleSelection(
        'SelD0',  ## name 
        CombineParticles,  ## algorithm type 
        [true_muons, true_kaons],  ## input/required selections 
        ## the decays to be reconstructed
        DecayDescriptor='[D0 -> K- mu+]cc',
        ## combination cut : mass window
        CombinationCut="""
        in_range ( 1 *  GeV ,  AM , 2 * GeV )
        """,
        ##      mother cut : require good vertex & some separation
        MotherCut="""
        ( VFASPF( VCHI2 ) <  10 ) &
        ( BPVVDCHI2       >   9 )  
        """,
    )

    from PhysSelPython.Wrappers import SelectionSequence
    SEQ_D0 = SelectionSequence('TRUED0', sel_D0)

    alg1_name = 'Lines'
    ## add the name of Bender algorithm into User sequence sequence
    from Configurables import GaudiSequencer
    seq_lines = GaudiSequencer('SEQ_lines',
                               Members=[SEQ_D0.sequence(), alg1_name])

    alg2_name = 'TisTosAlg'
    ## add the name of Bender algorithm into User sequence sequence
    from Configurables import GaudiSequencer
    seq_tistos = GaudiSequencer('SEQ_tistos',
                                Members=[SEQ_D0.sequence(), alg2_name])

    dv.UserAlgorithms = [seq_lines, seq_tistos]

    ## define the input data
    setData(inputdata, catalogs, castor)

    from BenderTools.Utils import silence, totalSilence
    silence()
    totalSilence()

    ## get/create application manager
    gaudi = appMgr()

    alg1 = Lines(alg1_name, Inputs=[SEQ_D0.outputLocation()])
    alg2 = Tistos(alg2_name, Inputs=[SEQ_D0.outputLocation()])

    return SUCCESS
Example #3
0
def configure(datafiles, catalogs=[], params={}, castor=False):

    from Configurables import DaVinci
    from Configurables import EventSelector

    from PhysConf.Filters import LoKi_Filters

    fltrs = LoKi_Filters(
        VOID_Code="""
        0 < CONTAINS ('/Event/PSIX/Phys/SelPsi3KForPsiX/Particles')
        """
    )
    filters = fltrs.filters('Filters')

    the_year = '2011'

    daVinci = DaVinci(
        #
        EventPreFilters = filters ,
        #
        DataType  = params['year'] ,
        InputType = 'MDST' ,
        RootInTES = 'PSIX' ,
        #
        PrintFreq =  1000  ,
        EvtMax    =    -1  ,
        #
        TupleFile='Bu2JpsiKKK.root',
        #
        Lumi=True
        #
        )

    daVinci.UserAlgorithms = [ 'JpsiKKK' ]

    from Configurables import CondDB
    CondDB ( LatestGlobalTagByDataType = the_year )

    #
    ## define input data
    #
    setData(datafiles, catalogs, castor)

    #
    ## suppress some extra printput
    #
    from BenderTools.Utils import silence
    silence()

    #
    ## get the actual application manager (create if needed)
    #
    gaudi = appMgr()

    #
    ## create local algorithm:
    #
    alg = Bu2JpsiKKK (
        'JpsiKKK',
        # input particles :
        RootInTES='/Event/PSIX',
        Inputs=['Phys/SelPsi3KForPsiX/Particles']
        )

    return SUCCESS
Example #4
0
def configure(datafiles,
              catalogs=[],
              castor=False,
              params={}):
    """
    Job configuration 
    """

    ## needed for job configuration
    from Configurables import DaVinci

    the_year = "2011"

    from BenderTools.Parser import hasInFile

    if params:
        the_year = params['Year']
        logger.info('Year is set from params to be %s ' % the_year)
    else:
        if hasInFile(datafiles, 'Collision11'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Collision12'):
            the_year = '2012'
        elif hasInFile(datafiles, 'Collision13'):
            the_year = '2013'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping13'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping15'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping19'):
            the_year = '2012'
        logger.info('Year is set from files  to be %s ' % the_year)

    #
    # check
    #
    if '2011' == the_year and hasInFile(datafiles, 'Collision12'):
        raise AttributeError, 'Invalid Year %s ' % the_year
    if '2012' == the_year and hasInFile(datafiles, 'Collision11'):
        raise AttributeError, 'Invalid Year %s ' % the_year

    logger.info('Use the Year = %s ' % the_year)

    rootInTES = '/Event/PSIX'

    # Read only fired events to speed up
    from PhysConf.Filters import LoKi_Filters
    fltrs = LoKi_Filters(
        VOID_Code="""
        0.5 < CONTAINS('/Event/PSIX/Phys/SelB&B/Particles' )
        """
    )

    dv = DaVinci(
        DataType=the_year,
        InputType='MDST',
        RootInTES=rootInTES,
        Simulation=False,
        PrintFreq=1000,
        EvtMax=-1,
        #
        HistogramFile='BB_Histos.root',
        TupleFile='BB.root',
        #
        Lumi=True,
        #
    )

    dv.UserAlgorithms = ['BB']

    from Configurables import CondDB
    CondDB(LatestGlobalTagByDataType=the_year)

    from BenderTools.Utils import silence
    silence()

    #
    # come back to Bender
    #
    setData(datafiles, catalogs, castor)

    #
    # start Gaudi
    #
    gaudi = appMgr()
    alg = BB(
        'BB',
        RootInTES=rootInTES,
        Inputs=['Phys/SelB&B/Particles']
    )

    return SUCCESS
Example #5
0
def configure(datafiles,
              catalogs=[],
              castor=False,
              params={}):
    """
    Job configuration 
    """

    logger.info("start: params: %s " % params)
    from BenderTools.Parser import hasInFile

    the_year = "2011"

    if params:
        the_year = params['Year']
        logger.info('Year is set from params to be %s ' % the_year)
    else:
        if hasInFile(datafiles, 'Collision11'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Collision12'):
            the_year = '2012'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping13'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping15'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping19'):
            the_year = '2012'
        logger.info('Year is set from files  to be %s ' % the_year)

    #
    # check
    #
    if '2011' == the_year and hasInFile(datafiles, 'Collision12'):
        raise AttributeError, 'Invalid Year %s ' % the_year
    if '2012' == the_year and hasInFile(datafiles, 'Collision11'):
        raise AttributeError, 'Invalid Year %s ' % the_year

    logger.info('Use the Year = %s ' % the_year)

    #
    # dimuon locations in DIMUON.DST
    #
    Jpsi_det_location = '/Event/AllStreams/Phys/FullDSTDiMuonJpsi2MuMuDetachedLine/Particles'
    Jpsi_unb_location = '/Event/AllStreams/Phys/FullDSTDiMuonJpsi2MuMuTOSLine/Particles'

    if hasInFile(datafiles, '/MC/MC11a/'):
        Jpsi_unb_location = '/Event/AllStreams/Phys/FullDSTDiMuonJpsi2MuMuLine/Particles'
        logger.warning('Rename ``unbised line'' to be %s ' %
                       Jpsi_unb_location)

    from PhysSelPython.Wrappers import AutomaticData
    jpsi_det = AutomaticData(Location=Jpsi_det_location)
    jpsi_unb = AutomaticData(Location=Jpsi_unb_location)

    # pions :
    from GaudiConfUtils.ConfigurableGenerators import FilterDesktop
    alg_pions = FilterDesktop(
        #
        Preambulo=["from LoKiPhysMC.decorators import mcMatch"],
        Code="""
        ( PT > 500  * MeV      ) & 
        ( CLONEDIST   > 5000   ) & 
        ( TRGHOSTPROB < 0.5    ) &
        ( TRCHI2DOF   < 4      ) & 
        in_range ( 2 , ETA , 5 ) &
        HASRICH                  
        & mcMatch( '[B_c+  =>  ( J/psi(1S) => mu+ mu- ) ^pi+ ]CC' , 1 )
        """ ,
    )

    ## ( PROBNNpi > 0.10      )

    from PhysSelPython.Wrappers import Selection
    from StandardParticles import StdAllLoosePions
    pions = Selection(
        "ThePions",
        Algorithm=alg_pions,
        RequiredSelections=[StdAllLoosePions]
    )

    alg_kaons = FilterDesktop(
        #
        Preambulo=["from LoKiPhysMC.decorators import mcMatch"],
        Code="""
        ( PT > 500  * MeV      ) & 
        ( CLONEDIST   > 5000   ) & 
        ( TRCHI2DOF   < 4      ) & 
        ( TRGHOSTPROB < 0.5    ) & 
        in_range ( 2 , ETA , 5 ) &
        HASRICH                  
        & mcMatch( '[B+  =>  ( J/psi(1S) => mu+ mu- ) ^K+ ]CC' , 1 )
        """
    )

    ## ( PROBNNk > 0.10       )

    from StandardParticles import StdAllLooseKaons
    kaons = Selection(
        "TheKaons",
        Algorithm=alg_kaons,
        RequiredSelections=[StdAllLooseKaons]
    )

    #
    Preambulo = [
        # shortcut for chi2 of vertex fit
        "chi2vx   = VFASPF(VCHI2)",
        # shortcut for the c*tau
        "from GaudiKernel.PhysicalConstants import c_light",
        # use the embedded cut for chi2(LifetimeFit)<16
        "ctau_25   = BPVLTIME ( 25 ) * c_light ",
        "mbc_acut  = in_range ( 6.050 * GeV , AM , 6.550 * GeV ) ",
        "mbp_acut  = in_range ( 5.100 * GeV , AM , 5.550 * GeV ) ",
        # mass-cut for beauty particles
        "mbc_cut   = in_range ( 6.100 * GeV ,  M , 6.500 * GeV ) ",
        "mbp_cut   = in_range ( 5.150 * GeV ,  M , 5.500 * GeV ) ",
        #
        "from LoKiPhysMC.decorators import mcMatch"
    ]

    # Bc :
    from GaudiConfUtils.ConfigurableGenerators import CombineParticles
    alg_bc = CombineParticles(
        DecayDescriptor="[B_c+ -> J/psi(1S) pi+ ]cc",
        DaughtersCuts={
            "J/psi(1S)": "mcMatch( '[ B_c+  =>  ^( J/psi(1S) => mu+ mu- ) pi+ ]CC' , 1 )"
        },
        Preambulo=Preambulo,
        CombinationCut=" mbc_acut ",
        MotherCut="""
        ( chi2vx < 25  ) & mbc_cut &  ( ctau_25 > %s )
        & mcMatch( '[ B_c+  => ( J/psi(1S) => mu+ mu- ) pi+ ]CC' , 1 )
        """ %  ( 40 * micrometer )
    )

    # B+ :
    alg_bu = CombineParticles(
        DecayDescriptor="[B+ -> J/psi(1S) K+ ]cc",
        DaughtersCuts={
            "J/psi(1S)": "mcMatch( '[ B+  => ^( J/psi(1S) => mu+ mu- ) K+ ]CC' , 1 )"
        },
        Preambulo=Preambulo,
        CombinationCut=" mbp_acut ",
        MotherCut="""
        ( chi2vx < 25  ) & mbp_cut &  ( ctau_25 > %s )
        & mcMatch( '[ B+  =>  ( J/psi(1S) => mu+ mu- ) K+ ]CC' , 1 )
        """ %  ( 40 * micrometer )
    )

    sel_bc_det = Selection(
        "TheBc_det",
        Algorithm=alg_bc,
        RequiredSelections=[jpsi_det, pions]
    )

    sel_bc_unb = Selection(
        "TheBc_unb",
        Algorithm=alg_bc,
        RequiredSelections=[jpsi_unb, pions]
    )

    sel_bu_det = Selection(
        "TheB_det",
        Algorithm=alg_bu,
        RequiredSelections=[jpsi_det, kaons]
    )

    sel_bu_unb = Selection(
        "TheB_unb",
        Algorithm=alg_bu,
        RequiredSelections=[jpsi_unb, kaons]
    )

    from PhysSelPython.Wrappers import SelectionSequence
    Bc_det_seq = SelectionSequence("Bc_det", TopSelection=sel_bc_det)
    Bu_det_seq = SelectionSequence("Bu_det", TopSelection=sel_bu_det)
    Bc_unb_seq = SelectionSequence("Bc_unb", TopSelection=sel_bc_unb)
    Bu_unb_seq = SelectionSequence("Bu_unb", TopSelection=sel_bu_unb)

    #
    # selection sequence
    #

    mode = params['Mode']
    mode = mode.upper()
    if 0 <= mode.find('BC') or 0 <= mode.find('PI'):
        seqs = [Bc_det_seq, Bc_unb_seq]
        # seqs = [ Bc_det_seq ]
    elif 0 <= mode.find('B+') or 0 <= mode.find('K+'):
        seqs = [Bu_det_seq, Bu_unb_seq]
        # seqs = [ Bu_det_seq ]
    else:
        raise

    from PhysSelPython.Wrappers import MultiSelectionSequence
    B_SEQ = MultiSelectionSequence(
        "B2PSI",
        Sequences=seqs,
    )

    from DSTWriters.Configuration import (SelDSTWriter,
                                          stripMicroDSTStreamConf,
                                          stripMicroDSTElements)

    # Configuration of SelDSTWriter
    SelDSTWriterConf = {
        'default': stripMicroDSTStreamConf(pack=False)}
    SelDSTWriterElements = {
        'default': stripMicroDSTElements(pack=False)}

    udstWriter = SelDSTWriter(
        "MyMicroDSTWriter",
        StreamConf=SelDSTWriterConf,
        MicroDSTElements=SelDSTWriterElements,
        OutputFileSuffix='MCBSEQ',
        SelectionSequences=[B_SEQ]
    )

    # Read only fired events to speed up
    from PhysConf.Filters import LoKi_Filters
    fltrs = LoKi_Filters(
        STRIP_Code="HLT_PASS_RE('Stripping.*DiMuonJpsi2MuMu.*')",
        VOID_Code="""
        ( 0.5 < CONTAINS('%s') ) | 
        ( 0.5 < CONTAINS('%s') ) 
        """ %  ( Jpsi_det_location , Jpsi_unb_location )
    )
    #
    fltrs_0 = LoKi_Filters(
        VOID_Code="""
        ( EXISTS ( '/Event/DAQ/RawEvent') | EXISTS('/Event/Trigger/RawEvent' ) ) 
        & EXISTS ( '/Event/Strip/Phys/DecReports')
        & ( RECSUMMARY (  0 , -1 ) >  0.5 )
        """
    )

    #
    # finally: DaVinci
    #
    ## needed for job configuration
    from Configurables import DaVinci
    davinci = DaVinci(
        EventPreFilters=fltrs_0.filters(
            'Filters0') + fltrs.filters('Filters1'),
        DataType=the_year,
        InputType='MDST',
        Simulation=True,
        PrintFreq=1000,
        EvtMax=-1,
        #
        HistogramFile='MCBc_Histos.root',
        TupleFile='MCBc.root',
        #
        DDDBtag=params['DDDB'],
        CondDBtag=params['SIMCOND'],
        #
        Lumi=False  # True ,
        #
    )

    davinci.appendToMainSequence([udstWriter.sequence()])

    #
    # come back to Bender
    #
    setData(datafiles, catalogs, castor)

    from BenderTools.Utils import silence
    silence()

    #
    gaudi = appMgr()
    #

    logger.info("end: params: %s " % params)

    return SUCCESS
Example #6
0
def configChkTrg ( config , colors = False ) :
    """
    """
    config.teslocation = config.teslocation.strip()
    # the basic configuration 
    from BenderTools.DstExplorer import configure
    configure ( config , colors )
    
    root  = config.RootInTES   
    line  = config.teslocation
    
    if root :
        if   0 == line.find ( root + '/') :
            line = line.replace( root + '/' , '' )
            logger.info('Line name is adjusted to be %s' % line )
        elif 0 != config.teslocation.find ( '/Event/' ) :
            tmpl = '/Event/' + line 
            if   0 == tmpl.find ( root ) :
                line = tmpl.replace( root , '' )
                logger.info('Line name is adjusted to be %s' % line  )
                
    if 0 == line.find('/Event/') :
        line = line.replace( '/Event/' , '' )
        logger.info('Line name is adjusted to be %s' % line )

    if       config.Simulation and 0 != line.find ( 'AllStreams/Phys/' ) :
        logger.warning('Suspicious line name %s' % line )
    elif not config.Simulation and 0 != line.find ( 'Phys/' ) :
        logger.warning('Suspicious line name %s' % line )
        
    if not 0 < line.rfind ('/Particles') :
        line = line + '/Particles'
        logger.info('Line name is adjusted to be %s' % line )

    config.teslocation = line
    
    ##
    ## add filters:
    #
    
    from PhysConf.Filters import LoKi_Filters
    if root : location = root + '/' + line 
    else    : location = '/Event/'  + line 
    logger.info("Use filter for non-empty location:'%s'"               % location )
    fltrs = LoKi_Filters ( VOID_Code  = " 0.5 < CONTAINS ('%s',True) " % location )
    from Configurables       import DaVinci

    dv = DaVinci (
        EventPreFilters = fltrs.filters('Filters')  ,
        UserAlgorithms  = [ 'CheckTrg' ]    
        )

    
    from BenderTools.Utils import silence, totalSilence
    
    silence()    
    if config.Quiet or 5 <=config.OutputLevel :
        totalSilence()

    from   Bender.Main  import appMgr
    gaudi = appMgr()

    ## create algorithm 
    ALGTYPE    = chkTrg()
    ## .. and configure it 
    kwargs = { 'Inputs'          : [ config.teslocation ] }
    if config.OutputLevel <3 and not config.Quiet :
        kwargs.update (  { 'PropertiesPrint' : True             } ) 
    if config.RootInTES :
        kwargs.update (  { 'RootInTES'       : config.RootInTES } )

    alg = ALGTYPE ( 'CheckTrg', **kwargs )

    return alg 
Example #7
0
def configure(datafiles,
              catalogs=[],
              castor=False,
              params={}):
    """
    Job configuration 
    """

    ## needed for job configuration
    from Configurables import DaVinci

    from BenderTools.Parser import hasInFile

    the_year = "2011"

    if params:
        the_year = params['Year']
        logger.info('Year is set from params to be %s ' % the_year)
    else:
        if hasInFile(datafiles, 'Collision11'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Collision12'):
            the_year = '2012'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping13'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping15'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping19'):
            the_year = '2012'
        logger.info('Year is set from files  to be %s ' % the_year)

    #
    # check
    #
    if '2011' == the_year and hasInFile(datafiles, 'Collision12'):
        raise AttributeError, 'Invalid Year %s ' % the_year
    if '2012' == the_year and hasInFile(datafiles, 'Collision11'):
        raise AttributeError, 'Invalid Year %s ' % the_year

    logger.info('Use the Year = %s ' % the_year)

    rootInTES = '/Event/B'

    davinci = DaVinci(
        DataType=the_year,
        InputType='MDST',
        Simulation=False,
        PrintFreq=1000,
        EvtMax=-1,
        #
        HistogramFile='B2X_Histos.root',
        TupleFile='B2X.root',
        #
        Lumi=True,
        #
    )

    from Configurables import CondDB
    CondDB(LatestGlobalTagByDataType=the_year)

    # ------- decoding set-up start ----------
    from BenderTools.MicroDST import uDstConf
    uDstConf(rootInTES)
    # ------- decoding set-up end  -----------

    # suppress some unnesessary prints
    from BenderTools.Utils import silence
    silence()

    #
    # come back to Bender
    #
    setData(datafiles, catalogs, castor)

    #
    # start Gaudi
    #
    gaudi = appMgr()

    alg = B2X(
        'B2X',  # Algorithm name ,
        RootInTES=rootInTES,
        Inputs=['Phys/Bplus/Particles']
    )

    mainSeq = gaudi.algorithm('GaudiSequencer/DaVinciUserSequence', True)
    mainSeq.Members += [alg . name()]

    return SUCCESS
Example #8
0
def configure(datafiles,
              catalogs=[],
              castor=False,
              params={}):
    """
    Job configuration 
    """

    ## needed for job configuration
    from Configurables import DaVinci

    the_year = "2012"

    from BenderTools.Parser import hasInFile

    if params:
        the_year = params['Year']
        logger.info('Year is set from params to be %s ' % the_year)
    else:
        if hasInFile(datafiles, 'Collision11'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Collision12'):
            the_year = '2012'
        elif hasInFile(datafiles, 'Collision13'):
            the_year = '2013'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping13'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping15'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping19'):
            the_year = '2012'
        logger.info('Year is set from files  to be %s ' % the_year)

    #
    # check
    #
    if '2011' == the_year and hasInFile(datafiles, 'Collision12'):
        raise AttributeError, 'Invalid Year %s ' % the_year
    if '2012' == the_year and hasInFile(datafiles, 'Collision11'):
        raise AttributeError, 'Invalid Year %s ' % the_year

    logger.info('Use the Year = %s ' % the_year)

    rootInTES = '/Event/YC'

    davinci = DaVinci(
        DataType=the_year,
        InputType='DST',
        Simulation=False,
        PrintFreq=1000,
        EvtMax=-1,
        #
        HistogramFile='CY_Histos.root',
        TupleFile='CY.root',
        #
        Lumi=True,
        #
    )

    from Configurables import CondDB
    CondDB(LatestGlobalTagByDataType=the_year)

    # ------- decoding set-up start ----------
    from BenderTools.MicroDST import uDstConf
    uDstConf(rootInTES)
    # ------- decoding set-up end  -----------

    from BenderTools.Utils import silence
    silence()

    #
    # come back to Bender
    #
    setData(datafiles, catalogs, castor)

    #
    # start Gaudi
    #
    gaudi = appMgr()

    alg1 = CY(
        'YD0', RootInTES=rootInTES, Inputs=['Phys/Y&D0/Particles'])
    alg2 = CY(
        'YD+', RootInTES=rootInTES, Inputs=['Phys/Y&D+/Particles'])
    alg3 = CY(
        'YDs', RootInTES=rootInTES, Inputs=['Phys/Y&Ds+/Particles'])
    alg4 = CY(
        'YLc', RootInTES=rootInTES, Inputs=['Phys/Y&Lc+/Particles'])
    alg5 = CY(
        'YDst', RootInTES=rootInTES, Inputs=['Phys/Y&Dstar+/Particles'])
    alg6 = CY(
        'YSc', RootInTES=rootInTES, Inputs=['Phys/Y&Sigmac/Particles'])
    alg7 = CY(
        'YLcst', RootInTES=rootInTES, Inputs=['Phys/Y&Lcstar+/Particles'])

    # single charm
    alg8 = C1(
        'D01', RootInTES=rootInTES, Inputs=['Phys/SelD02HHForPromptCharm/Particles '])
    alg9 = C1(
        'Dp1', RootInTES=rootInTES, Inputs=['Phys/SelDForPromptCharm/Particles'])
    alg10 = C1(
        'Ds1', RootInTES=rootInTES, Inputs=['Phys/SelDsForPromptCharm/Particles'])
    alg11 = C1(
        'Lc1', RootInTES=rootInTES, Inputs=['Phys/SelLambdaCForPromptCharm/Particles'])

    alg8 ._mode = "[ D0         -> K- pi+    ]CC"
    alg9 ._mode = "[ D+        --> K- pi+ pi+]CC"
    alg10._mode = "[ D_s+      --> K- K+  pi+]CC"
    alg11._mode = "[ Lambda_c+ --> p+ K-  pi+]CC"

    mainSeq = gaudi.algorithm('GaudiSequencer/DaVinciUserSequence', True)
    mainSeq.Members += [alg1  . name(),
                        alg2  . name(),
                        alg3  . name(),
                        alg4  . name(),
                        alg5  . name(),
                        # alg6  . name () ,
                        # alg7  . name () ,
                        #
                        alg8  . name(),
                        alg9  . name(),
                        alg10 . name(),
                        alg11 . name()
                        ]

    return SUCCESS
Example #9
0
def configure(config, colors=False):
    """Configure the application from parser data 
    """

    #
    if config.OutputLevel <= 3 and not config.Quiet:
        _vars = vars(config)
        _keys = _vars.keys()
        _keys.sort()
        logger.info('Configuration:')
        for _k in _keys:
            logger.info('  %15s : %-s ' % (_k, _vars[_k]))

    ## redefine output level for 'quiet'-mode
    if config.OutputLevel > 5:
        config.OutputLevel = 5
        logger.info('set OutputLevel to be %s ' % config.OutputLevel)

    if config.OutputLevel < 0:
        config.OutputLevel = 0
        logger.info('set OutputLevel to be %s ' % config.OutputLevel)

    if config.Quiet and 4 > config.OutputLevel:
        config.OutputLevel = 4
        logger.info('set OutputLevel to be %s ' % config.OutputLevel)
        from BenderTools.Utils import silence
        silence()
    #
    ## use coherent C++/Python logging levels
    setLogging(config.OutputLevel)
    #
    # some sanity actions:
    #
    config.RootInTES = config.RootInTES.strip()
    config.files = [i.strip() for i in config.files if i.strip()]
    #
    ## start the actual action:
    #
    from Configurables import DaVinci
    #
    ## get the file type for the file extension
    #
    from BenderTools.Parser import dataType
    pyfiles = [i for i in config.files if len(i) == 3 + i.rfind('.py')]
    files = [i for i in config.files if i not in pyfiles]

    from BenderTools.Parser import fileList
    for f in config.FileList:
        files += fileList(f)

    if not files and not config.ImportOptions:
        raise AttributeError('No data files are specified!')

    ## get some info from file names/extensision
    dtype, simu, ext = None, None, None
    if files:
        dtype, simu, ext = dataType(files)
        logger.debug('DataType,Simu&extension:"%s",%s,"%s" (from files)' %
                     (dtype, simu, ext))
    elif config.ImportOptions:
        from Bender.DataUtils import evtSelInput
        ifiles = evtSelInput(config.ImportOptions)
        dtype, simu, ext = dataType(ifiles)
        logger.debug(
            'DataType,Simu&extension:"%s",%s&"%s" (from EventSelector)' %
            (dtype, simu, ext))

    if '2013' == dtype:
        logger.info('Data type 2013 is redefined to be 2012')
        dtype = '2012'

        #
    if ext in ('gen', 'xgen', 'GEN', 'XGEN', 'ldst', 'LDST') and not simu:
        simu = True

    if dtype and dtype != config.DataType:
        logger.info('Redefine DataType from  %s to %s ' %
                    (config.DataType, dtype))
        config.DataType = dtype

    if simu and not config.Simulation:
        logger.info('Redefine Simulation from  %s to %s ' %
                    (config.Simulation, simu))
        config.Simulation = simu

    if config.Simulation and config.Lumi:
        logger.info('suppress Lumi for Simulated data')
        config.Lumi = False

    ## summary information (when available)
    from Configurables import LHCbApp
    LHCbApp().XMLSummary = 'summary.xml'

    daVinci = DaVinci(
        DataType=config.DataType,
        Simulation=config.Simulation,
        Lumi=config.Lumi,
    )

    if hasattr(config, 'TupleFile') and config.TupleFile:
        logger.info('Define TupleFile to be %s' % config.TupleFile)
        daVinci.TupleFile = config.TupleFile

    if hasattr(config, 'HistoFile') and config.HistoFile:
        logger.info('Define HistogramFile to be %s' % config.HistoFile)
        daVinci.HistogramFile = config.HistoFile

    if config.MicroDST or 'mdst' == ext or 'MDST' == ext or 'uDST' == ext:
        logger.info('Define input type as micro-DST')
        daVinci.InputType = 'MDST'

    #
    ## try to guess RootInTES
    #
    from BenderTools.Parser import hasInFile
    if hasInFile(files, 'CHARM.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/Charm'
        logger.info('RootInTES is set according to CHARM.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'LEPTONIC.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/Leptonic'
        logger.info('RootInTES is set according to LEPTONIC.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'BHADRON.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/Bhadron'
        logger.info('RootInTES is set according to BHADRON.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'PID.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/PID'
        logger.info('RootInTES is set according to PID.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'PSIX.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/PSIX'
        logger.info('RootInTES is set according to PSIX.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'PSIX0.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/PSIX0'
        logger.info('RootInTES is set according to PSIX0.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'BOTTOM.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/BOTTOM'
        logger.info('RootInTES is set according to BOTTOM.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'TURBO.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/Turbo'
        logger.info('RootInTES is set according to TURBO.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'ALLSTREAMS.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/AllStreams'
        logger.info('RootInTES is set according to ALLSTREAMS.MDST')
        daVinci.InputType = 'MDST'

    if config.RootInTES and 0 != config.RootInTES.find('/Event'):
        config.RootInTES = '/Event/' + config.RootInTES
    if config.RootInTES and '/' == config.RootInTES[-1]:
        config.RootInTES = config.RootInTES[:-1]
    if config.RootInTES and '/Event' != config.RootInTES:
        daVinci.RootInTES = config.RootInTES
    #
    ## check for Grid-access
    #
    if config.Grid:
        from Bender.DataUtils import hasGridProxy
        if not hasGridProxy():
            logger.warning(
                'GRID proxy is not available, switch off GRID-lookup')
            config.Grid = ''  ## SWITCH OFF Grid-lookup

    if not config.Simulation and config.DataType in ('2010', '2011', '2012',
                                                     '2013', '2015'):
        #
        ## try to use the latest available tags:
        #
        from Configurables import CondDB
        ## CondDB ( UseLatestTags = [ options.DataType ] )
        ## logger.info('Use latest tags for %s' % options.DataType )
        CondDB(LatestGlobalTagByDataType=config.DataType)
        logger.info('Use latest global tag for data type %s' % config.DataType)

    if config.Simulation:
        #
        ## try to get the tags from Rec/Header
        from BenderTools.GetDBtags import useDBTagsFromData
        tags = useDBTagsFromData(files,
                                 castor=config.Castor,
                                 grid=config.Grid,
                                 daVinci=daVinci,
                                 importOpts=config.ImportOptions,
                                 catalogs=config.XmlCatalogs)

    if config.IgnoreDQFlags:
        logger.info('DataQuality flags will be ignored')
        daVinci.IgnoreDQFlags = config.IgnoreDQFlags

    ## specific action for (x)gen files
    if ext in ('gen', 'xgen', 'GEN', 'XGEN'):
        from BenderTools.GenFiles import genAction
        genAction(ext)

    ## prepare to copy good/marked/tagged evenst
    if hasattr(config, 'OutputFile') and config.OutputFile:
        from BenderTools.GoodEvents import copyGoodEvents
        if 0 <= config.OutputFile.find('.'):
            copyGoodEvents(config.OutputFile)
        else:
            copyGoodEvents("%s.%s" % (config.OutputFile, ext))

    ##  OutptuLevel
    from Configurables import MessageSvc
    msgSvc = MessageSvc(OutputLevel=config.OutputLevel)

    ## import options (if specified)
    for i in config.ImportOptions:
        logger.info("Import options from file %s'" % i)
        from Gaudi.Configuration import importOptions
        importOptions(i)

    if colors:

        logger.debug('Add colorization to MessageSvc')

        from Configurables import MessageSvc
        msgsvc = MessageSvc(
            useColors=True,
            errorColorCode=['yellow', 'red'],
            warningColorCode=['red'],
            fatalColorCode=['blue', 'red'],
        )

        def _color_pre_start_action_():

            logger.debug('Add colorization to MessageSvc')
            from GaudiPython.Bindings import AppMgr
            _g = AppMgr()
            if not _g: return
            _s = _g.service('MessageSvc')
            if not _s: return
            _s.useColors = True
            _s.errorColorCode = ['yellow', 'red']
            _s.warningColorCode = ['red']
            _s.fatalColorCode = ['blue', 'red']
            ##_s.alwaysColorCode  = [ 'blue'            ]
            ##_s.infoColorCode    = [ 'green'           ]
            del _g, _s

        from Bender.Utils import addPreInitAction
        addPreInitAction(_color_pre_start_action_)

    ## set input data
    from Bender.Utils import setData
    setData(
        files,
        config.XmlCatalogs,  ## XML-catalogues 
        config.Castor,  ## use Castor/EOS lookup 
        config.Grid)  ## Use GRID to locate files

    return pyfiles
Example #10
0
def configure(datafiles,
              catalogs=[],
              castor=False,
              params={}):
    """
    Job configuration 
    """

    ## needed for job configuration
    from Configurables import DaVinci

    from BenderTools.Parser import hasInFile

    the_year = "2011"

    if params:
        the_year = params['Year']
        logger.info('Year is set from params to be %s ' % the_year)
    else:
        if hasInFile(datafiles, 'Collision11'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Collision12'):
            the_year = '2012'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping13'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping15'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping19'):
            the_year = '2012'
        logger.info('Year is set from files  to be %s ' % the_year)

    #
    # check
    #
    if '2011' == the_year and hasInFile(datafiles, 'Collision12'):
        raise AttributeError, 'Invalid Year %s ' % the_year
    if '2012' == the_year and hasInFile(datafiles, 'Collision11'):
        raise AttributeError, 'Invalid Year %s ' % the_year

    logger.info('Use the Year = %s ' % the_year)

    rootInTES = '/Event/PSIX'

    # Read only fired events to speed up
    from PhysConf.Filters import LoKi_Filters
    fltrs = LoKi_Filters(
        VOID_Code="""
        ( CONTAINS('/Event/PSIX/Phys/SelPsiKForPsiX/Particles'  ) > 0.5 ) |
        ( CONTAINS('/Event/PSIX/Phys/SelPsiPiForPsiX/Particles' ) > 0.5 ) 
        """
    )

    davinci = DaVinci(
        EventPreFilters=fltrs.filters('Filters'),
        DataType=the_year,
        InputType='MDST',
        RootInTES=rootInTES,
        Simulation=False,
        PrintFreq=1000,
        EvtMax=-1,
        #
        HistogramFile='Bc_Histos.root',
        TupleFile='Bc.root',
        #
        Lumi=True,
        #
    )

    from BenderTools.Utils import silence
    silence()

    from Configurables import TrackScaleState
    state_scale = TrackScaleState('StateScale')
    davinci.UserAlgorithms = [
        state_scale,
        'B2K',
        'B2P'
    ]

    from Configurables import CondDB
    CondDB(LatestGlobalTagByDataType=the_year)

    #
    # come back to Bender
    #
    setData(datafiles, catalogs, castor)

    #
    # start Gaudi
    #
    gaudi = appMgr()

    #
    alg1 = B2PsiH(
        'B2K',  # Algorithm name ,
        RootInTES=rootInTES,
        Inputs=['Phys/SelPsiKForPsiX/Particles']
    )  # Phys/SelPsiKForPsiX/Particles

    alg2 = B2PsiH(
        'B2P',  # Algorithm name ,
        RootInTES=rootInTES,
        Inputs=['Phys/SelPsiPiForPsiX/Particles']
    )

    return SUCCESS
Example #11
0
def configure(datafiles,
              catalogs=[],
              castor=False,
              params={}):
    """
    Job configuration 
    """

    ## needed for job configuration
    from Configurables import DaVinci

    from BenderTools.Parser import hasInFile

    the_year = "2011"

    if params:
        the_year = params['Year']
        logger.info('Year is set from params to be %s ' % the_year)
    else:
        if hasInFile(datafiles, 'Collision11'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Collision12'):
            the_year = '2012'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping13'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping15'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping19'):
            the_year = '2012'
        logger.info('Year is set from files  to be %s ' % the_year)

    #
    # check
    #
    if '2011' == the_year and hasInFile(datafiles, 'Collision12'):
        raise AttributeError, 'Invalid Year %s ' % the_year
    if '2012' == the_year and hasInFile(datafiles, 'Collision11'):
        raise AttributeError, 'Invalid Year %s ' % the_year

    logger.info('Use the Year = %s ' % the_year)

    rootInTES = '/Event/Charm'

    from PhysConf.Filters import LoKi_Filters
    fltrs = LoKi_Filters(
        STRIP_Code="""
        HLT_PASS_RE ( 'Stripping.*Xicc.*ForPromptCharm.*' ) 
        """
    )

    davinci = DaVinci(
        DataType=the_year,
        EventPreFilters=fltrs.filters('Filters'),
        InputType='MDST',
        RootInTES=rootInTES,
        Simulation=False,
        PrintFreq=1000,
        EvtMax=-1,
        #
        HistogramFile='Xic_Histos.root',
        TupleFile='Xic.root',
        #
        Lumi=True,
        #
    )

    from BenderTools.Utils import silence
    silence()

    from Configurables import TrackScaleState
    state_scale = TrackScaleState(
        'StateScale',
    )

    davinci.UserAlgorithms = [state_scale, 'Xi1', 'Xi2']

    from Configurables import CondDB
    CondDB(LatestGlobalTagByDataType=the_year)

    #
    # come back to Bender
    #
    setData(datafiles, catalogs, castor)

    #
    # start Gaudi
    #
    gaudi = appMgr()

    #
    alg1 = Xicc(
        'Xi1',  # Algorithm name ,
        RootInTES=rootInTES,
        Inputs=['Phys/Xicc+ForPromptCharm/Particles']
    )

    alg2 = Xicc(
        'Xi2',  # Algorithm name ,
        RootInTES=rootInTES,
        Inputs=['Phys/Xicc++ForPromptCharm/Particles']
    )

    alg2.mode = " [ Xi_cc++ -> Lambda_c+ (K-|K+) (pi+|pi-) (pi+|pi-)]CC"

    return SUCCESS
Example #12
0
def configure_COMMON(datafiles,
                     catalogs,
                     castor,
                     params):
    """
    The actual job configuration 
    """
    # =====================================================================
    from Configurables import DaVinci  # needed for job configuration

    the_year = params['Year']

    rootInTES = '/Event/B2PSI'

    davinci = DaVinci(
        #
        DataType=params['Year'],
        RootInTES=rootInTES,
        InputType='MDST',
        #
        PrintFreq=1000,
        EvtMax=-1,
        #
    )

    #
    # define input files
    #
    setData(datafiles, catalogs, castor)

    #
    # suppress some extra printput
    #
    from BenderTools.Utils import silence
    silence()

    mode = params.get('Mode', '')
    logger.info("Mode is '%s' " % mode)

    mode = mode.upper()

    if not mode:

        davinci.UserAlgorithms += ['Bc_det', 'Bc_unb']
        davinci.UserAlgorithms += ['Bu_det', 'Bu_unb']

    elif 0 <= mode.find('BC') or 0 <= mode.find('PI'):

        davinci.UserAlgorithms += ['Bc_det', 'Bc_unb']

    elif 0 <= mode.find('B+') or 0 <= mode.find('BU') or 0 <= mode.find('K+'):

        davinci.UserAlgorithms += ['Bu_det', 'Bu_unb']

    else:

        raise AttibuteError, 'Mode is not specified!'

    gaudi = appMgr()

    bc_det = AlgBc('Bc_det',
                   RootInTES='/Event/B2PSI',
                   Inputs=['Phys/TheBc_det/Particles'],
                   ReFitPVs=True)

    bc_unb = AlgBc('Bc_unb',
                   RootInTES='/Event/B2PSI',
                   Inputs=['Phys/TheBc_unb/Particles'],
                   ReFitPVs=True)

    bu_det = AlgBu('Bu_det',
                   RootInTES='/Event/B2PSI',
                   Inputs=['Phys/TheB_det/Particles'],
                   ReFitPVs=True)

    bu_unb = AlgBu('Bu_unb',
                   RootInTES='/Event/B2PSI',
                   Inputs=['Phys/TheB_unb/Particles'],
                   ReFitPVs=True)

    return SUCCESS
Example #13
0
def configure(datafiles,
              catalogs=[],
              castor=False,
              params={}):
    """
    Job configuration 
    """

    ## needed for job configuration
    from Configurables import DaVinci

    the_year = "2012"

    from BenderTools.Parser import hasInFile

    if params:
        the_year = params['Year']
        logger.info('Year is set from params to be %s ' % the_year)
    else:
        if hasInFile(datafiles, 'Collision11'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Collision12'):
            the_year = '2012'
        elif hasInFile(datafiles, 'Collision13'):
            the_year = '2013'
        logger.info('Year is set from files  to be %s ' % the_year)

    #
    # check
    #
    if '2011' == the_year and hasInFile(datafiles, 'Collision12'):
        raise AttributeError, 'Invalid Year %s ' % the_year
    if '2012' == the_year and hasInFile(datafiles, 'Collision11'):
        raise AttributeError, 'Invalid Year %s ' % the_year

    logger.info('Use the Year = %s ' % the_year)

    rootInTES = '/Event/BOTTOM'

    dv = DaVinci(
        DataType=the_year,
        InputType='DST',
        RootInTES=rootInTES,
        Simulation=False,
        PrintFreq=1000,
        EvtMax=-1,
        #
        HistogramFile='Y_Histos.root',
        TupleFile='Y.root',
        #
        Lumi=True,
        #
    )

    from Configurables import CondDB
    CondDB(LatestGlobalTagByDataType=the_year)

    dv.UserAlgorithms = ['Y']

    from BenderTools.Utils import silence
    silence()

    #
    # come back to Bender
    #
    setData(datafiles, catalogs, castor)

    #
    # start Gaudi
    #
    gaudi = appMgr()

    alg = TrgY(
        'Y',
        RootInTES=rootInTES,
        Inputs=['Phys/Upsilon/Particles']
    )

    return SUCCESS
Example #14
0
def configure(datafiles,
              catalogs=[],
              castor=False,
              params={}):
    """
    Job configuration 
    """

    from BenderTools.Parser import hasInFile

    the_year = "2011"

    if params:
        the_year = params['Year']
        logger.info('Year is set from params to be %s ' % the_year)
    else:
        if hasInFile(datafiles, 'Collision11'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Collision12'):
            the_year = '2012'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping13'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping15'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping17'):
            the_year = '2011'
        elif hasInFile(datafiles, 'Stripping19'):
            the_year = '2012'
        logger.info('Year is set from files  to be %s ' % the_year)

    #
    # check
    #
    if '2011' == the_year and hasInFile(datafiles, 'Collision12'):
        raise AttributeError, 'Invalid Year %s ' % the_year
    if '2012' == the_year and hasInFile(datafiles, 'Collision11'):
        raise AttributeError, 'Invalid Year %s ' % the_year

    logger.info('Use the Year = %s ' % the_year)

    #
    # pseudo stripping & WG-production
    #
    # from PhysSelPython.Wrappers import AutomaticData
    # jpsi_location = '/Event/AllStreams/Phys/FullDSTDiMuonJpsi2MuMuDetachedLine/Particles'
    # jpsi = AutomaticData ( Location = jpsi_location )

# if   '2012' == the_year :
##         import StrippingArchive.Stripping20.StrippingDiMuonNew              as DiMuon
##         import StrippingSettings.Stripping20.LineConfigDictionaries_BandQ   as LineSettings
# elif '2011' == the_year :
##         import StrippingArchive.Stripping20r1.StrippingDiMuonNew            as DiMuon
##         import StrippingSettings.Stripping20r1.LineConfigDictionaries_BandQ as LineSettings
##     config  = LineSettings.FullDSTDiMuon['CONFIG']
##     name    = 'FullDST'
##     builder = DiMuon.DiMuonConf ( name , config )
# selection
##     jpsi  = builder.SelJpsi2MuMuDetached
    import CommonParticles.StdLooseJpsi2MuMu

    # from StandardParticles import StdLooseJpsi2MuMu
    # jpsi  = StdLooseJpsi2MuMu

    from PhysSelPython.Wrappers import AutomaticData
    jpsi = AutomaticData('/Event/Phys/StdLooseJpsi2MuMu/Particles')

    from GaudiConfUtils.ConfigurableGenerators import FilterDesktop
    # pions :
    alg_pions = FilterDesktop(
        #
        Code="""
        ( PT > 500  * MeV      ) & 
        ( CLONEDIST   > 5000   ) & 
        ( TRGHOSTPROB < 0.5    ) &
        ( TRCHI2DOF   < 4      ) & 
        in_range ( 2 , ETA , 5 ) &
        HASRICH                  &
        ( PIDpi - PIDK > -2    ) 
        """ ,
    )

    from PhysSelPython.Wrappers import Selection
    from StandardParticles import StdAllLoosePions
    pions = Selection(
        "ThePions",
        Algorithm=alg_pions,
        RequiredSelections=[StdAllLoosePions]
    )

    alg_kaons = FilterDesktop(
        #
        Code="""
        ( PT > 500  * MeV      ) & 
        ( CLONEDIST   > 5000   ) & 
        ( TRCHI2DOF   < 4      ) & 
        ( TRGHOSTPROB < 0.5    ) & 
        in_range ( 2 , ETA , 5 ) &
        HASRICH                  &
        ( PIDK - PIDpi > -2    ) 
        """
    )

    from StandardParticles import StdAllLooseKaons
    kaons = Selection(
        "TheKaons",
        Algorithm=alg_kaons,
        RequiredSelections=[StdAllLooseKaons]
    )

    #
    Preambulo = [
        # shortcut for chi2 of vertex fit
        "chi2vx   = VFASPF(VCHI2)",
        # shortcut for the c*tau
        "from GaudiKernel.PhysicalConstants import c_light",
        # use the embedded cut for chi2(LifetimeFit)<16
        "ctau_25   = BPVLTIME ( 25 ) * c_light ",
        "mbc_acut  = in_range ( 6.050 * GeV , AM , 6.550 * GeV ) ",
        "mbp_acut  = in_range ( 5.100 * GeV , AM , 5.550 * GeV ) ",
        # mass-cut for beauty particles
        "mbc_cut   = in_range ( 6.100 * GeV ,  M , 6.500 * GeV ) ",
        "mbp_cut   = in_range ( 5.150 * GeV ,  M , 5.500 * GeV ) ",
    ]

    # Bc :
    from GaudiConfUtils.ConfigurableGenerators import CombineParticles
    alg_bc = CombineParticles(
        DecayDescriptor="[B_c+ -> J/psi(1S) pi+ ]cc",
        Preambulo=Preambulo,
        CombinationCut=" mbc_acut ",
        MotherCut="""
        ( chi2vx < 20  ) & mbc_cut &  ( ctau_25 > %s )
        """ %  ( 40 * micrometer )
    )

    sel_bc = Selection(
        "TheBc",
        Algorithm=alg_bc,
        RequiredSelections=[jpsi, pions]
    )

    # B+ :
    alg_bu = CombineParticles(
        DecayDescriptor="[B+ -> J/psi(1S) K+ ]cc",
        Preambulo=Preambulo,
        CombinationCut=" mbp_acut ",
        MotherCut="""
        ( chi2vx < 20  ) & mbp_cut &  ( ctau_25 > %s )
        """ %  ( 40 * micrometer )
    )

    sel_bu = Selection(
        "TheB",
        Algorithm=alg_bu,
        RequiredSelections=[jpsi, kaons]
    )

    # B0 :
    alg_bd = CombineParticles(
        DecayDescriptor="[B0 -> J/psi(1S) K+ pi-]cc",
        Preambulo=Preambulo,
        CombinationCut="""
        mbp_acut & in_range ( 600 * MeV , AM23  , 1.2 * GeV ) 
        """ ,
        MotherCut="""
        ( chi2vx < 50  ) & mbp_cut &  ( ctau_25 > %s )
        """ %  ( 40 * micrometer )
    )

    sel_bd = Selection(
        "TheB0",
        Algorithm=alg_bd,
        RequiredSelections=[jpsi, kaons, pions]
    )

    from PhysSelPython.Wrappers import SelectionSequence
    selseq_pi = SelectionSequence("Bc", TopSelection=sel_bc)
    selseq_k = SelectionSequence("Bu", TopSelection=sel_bu)
    selseq_kst = SelectionSequence("Bd", TopSelection=sel_bd)

    # Read only fired events to speed up
    from PhysConf.Filters import LoKi_Filters
    fltrs = LoKi_Filters(
        #
        # Require at least one primary vertex
        #
        VOID_Code="""
        ( RECSUMMARY (  0 , -1 ) >  0.5 ) 
        """
    )

    #
    # make the final sequencers:
    #

    from Configurables import GaudiSequencer
    seq_pi = GaudiSequencer(
        'PION',
        Members=[selseq_pi  . sequence(), "MCB2PI"]
    )
    seq_k = GaudiSequencer(
        'KAON',
        Members=[selseq_k   . sequence(), "MCB2K"]
    )
    seq_kst = GaudiSequencer(
        'KSTAR',
        Members=[selseq_kst . sequence(), "MCB2KST"]
    )

    #
    # make the final choice
    #

    mode = params['Mode']
    mode = mode.upper()
    if 0 <= mode.find('BC') or 0 <= mode.find('PI'):
        seq = seq_pi
    elif  0 <= mode.find( 'B+' ) or 0 <= mode.find('BP') or \
            0 <= mode.find('BU') or 0 <= mode.find('K+'):
        seq = seq_k
    elif 0 <= mode.find('B0') or 0 <= mode.find('BZ') or 0 <= mode.find('K*'):
        seq = seq_kst

    #
    # finally: DaVinci
    #
    ## needed for job configuration
    from Configurables import DaVinci
    davinci = DaVinci(
        EventPreFilters=fltrs.filters('Filters'),
        DataType=the_year,
        InputType='MDST',
        Simulation=True,
        PrintFreq=1000,
        EvtMax=-1,
        #
        HistogramFile='MCBc_Histos.root',
        TupleFile='MCBc.root',
        #
        DDDBtag=params['DDDB'],
        CondDBtag=params['SIMCOND'],
        #
        Lumi=False  # True ,
        #
    )

    from BenderTools.Utils import silence
    silence()

    #
    # finally inform Davinci about algorithsm
    #
    davinci.UserAlgorithms = [
        seq
    ]

    #
    # come back to Bender
    #
    setData(datafiles, catalogs, castor)

    #
    # start Gaudi
    #
    gaudi = appMgr()
    #

    #
    alg1 = MCB2PsiH(
        'MCB2PI',  # Algorithm name ,
        Inputs=[selseq_pi.outputLocation()],
        PP2MCs=['Relations/Rec/ProtoP/Charged'],
        ReFitPVs=True
    )

    alg2 = MCB2PsiH(
        'MCB2K',  # Algorithm name ,
        Inputs=[selseq_k.outputLocation()],
        PP2MCs=['Relations/Rec/ProtoP/Charged'],
        ReFitPVs=True
    )

    alg3 = MCB2PsiH(
        'MCB2KST',  # Algorithm name ,
        Inputs=[selseq_kst.outputLocation()],
        PP2MCs=['Relations/Rec/ProtoP/Charged'],
        ReFitPVs=True
    )

    alg3._decay = '[ Beauty -> ( J/psi(1S) -> mu+ mu- ) K+ pi- ]CC'

    return SUCCESS