Пример #1
0
def addTMVAResponse ( dataset        ,
                      inputs         ,
                      weights_files  ,
                      prefix   = ''  , 
                      suffix   = ''  ,
                      aux      = 0.9 ) :
    """
    Helper function to add TMVA  responce into dataset
    >>> tar_file = trainer.tar_file
    >>> dataset  = ...
    >>> inputs = [ 'var1' , 'var2' , 'var2' ]
    >>> dataset.addTMVAResponce (  inputs , tar_file , prefix = 'tmva_' )
    """
    from ostap.core.core import cpp, std, Ostap
    PP = std.pair   ( 'std::string', 'std::string' )
    VP = std.vector ( PP )
    
    _inputs  = _inputs2map_  ( inputs        )
    _weights = _weights2map_ ( weights_files )
    
    sc = Ostap.TMVA.addResponse ( dataset  ,
                                  _inputs  ,
                                  _weights ,
                                  prefix   ,
                                  suffix   ,
                                  aux      )
    if sc.isFailure() :
        logger.error ( 'Error from Ostap::TMVA::addResponse %s' % sc )
    return sc 
Пример #2
0
logger.info('Dataset:%s ' % dataset)

models = set()
# =============================================================================

signal1 = Models.Gauss_pdf('Gx', xvar=m_x)
signal2 = Models.Gauss_pdf('Gy', xvar=m_y)
signal2s = signal1.clone(name='GyS', xvar=m_y)

signal1.mean = m.value()
signal1.sigma = m.error()
signal2.mean = m.value()
signal2.sigma = m.error()

knots = std.vector('double')()
knots.push_back(m_x.xmin())
knots.push_back(0.5 * (m_x.xmin() + m_x.xmax()))
knots.push_back(m_x.xmax())
spline1 = Ostap.Math.BSpline(knots, 2)


# =============================================================================
## gauss as signal, expo times 1st order polynomial as background
# =============================================================================
def test_model_14():

    logger = getLogger('test_model_14')
    logger.info(
        'Non-factorazeable background component (spline):  ( Gauss + P1 ) (x) ( Gauss + P1 ) + Spline2D'
    )
Пример #3
0
def addChoppingResponse(dataset,
                        chopper,
                        N,
                        inputs,
                        weights_files,
                        category_name='chopping',
                        prefix='tmva_',
                        suffix='_response',
                        aux=0.9):
    """
    Helper function to add TMVA  response into dataset
    >>> tar_file = trainer.tar_file
    >>> dataset  = ...
    >>> inputs = [ 'var1' , 'var2' , 'var2' ]
    >>> dataset.addTMVAResponce (  inputs , tar_file , prefix = 'tmva_' )
    """
    assert isinstance(N, int) and 1 < N < 10000, 'Invalid "N" %s' % N

    if isinstance(chopper, str):

        if chopper in dataset:
            chopper = getattr(varset, chopper)
        else:
            varset = dataset.get()
            varlist = ROOT.RooArgList()
            for v in varset:
                varlist.add(v)
            chopper = ROOT.RooFormulaVar('chopping', chopper, varlist)
            logger.debug('Create chopping function %s' % chopper)

    assert isinstance(chopper,
                      ROOT.RooAbsReal), 'Invalid choper type %s' % chopper

    category = ROOT.RooCategory(
        category_name, 'Chopping category: (%s)%%%d' % (chopper.GetTitle(), N))
    for i in range(N):

        if N < 10: cn = category_name + '_%d' % i
        if N < 100: cn = category_name + '_%02d' % i
        elif N < 1000: cn = category_name + '_%03d' % i
        elif N < 10000: cn = category_name + '_%04d' % i
        else: cn = category_name + '_%d' % i
        category.defineType(cn, i)

    ## decode inputs&weights

    from ostap.tools.tmva import _inputs2map_, _weights2map_

    _inputs = _inputs2map_(inputs)

    files = WeightsFiles(weights_files).files
    files_ = [_weights2map_(f) for f in files]

    from ostap.core.core import cpp, std, Ostap
    MAP = std.map('std::string', 'std::string')
    MAPS = std.vector(MAP)
    _maps = MAPS()
    for m in files_:
        _maps.push_back(m)

    sc = Ostap.TMVA.addChoppingResponse(dataset, chopper, category, N, _inputs,
                                        _maps, prefix, suffix, aux)
    if sc.isFailure():
        logger.error('Error from Ostap::TMVA::addChoppingResponse %s' % sc)
    return sc