df2rdh.n_max_total_bins = 1e6
# a histogram-based pdf is created out of the roodatahist object
# we use this pdf below to simulate a new dataset with the same properties as the original
df2rdh.create_hist_pdf = 'hpdf_Ndim'
# all output is stored in the workspace, not datastore
df2rdh.into_ws = True
ch.add(df2rdh)

# --- Print overview
pws = root_analysis.PrintWs()
ch.add(pws)

pds = core_ops.PrintDs()
ch.add(pds)

# --- 3. resimulate the data with the created hist-pdf, and plot these data and the pdf
ch = Chain('WsOps')
wsu = root_analysis.WsUtils()
wsu.add_simulate(pdf='hpdf_Ndim', obs='rdh_vars', num=10000, key='simdata')
wsu.add_plot(obs='age',
             data='simdata',
             pdf='hpdf_Ndim',
             output_file='test.pdf',
             pdf_kwargs={'ProjWData': ('rdh_cats', 'simdata')})
ch.add(wsu)

#########################################################################################

logger.debug(
    'Done parsing configuration file esk405_simulation_based_on_binned_data')
#########################################################################################
# --- now set up the chains and links based on configuration flags

if settings['generate_fit_plot']:
    # --- generate pdf, simulate, fit, and plot
    ch = proc_mgr.add_chain('WsOps')

    # --- 1. define a model by passing strings to the rooworkspace factory
    #     For the workspace factory syntax, see:
    #     https://root.cern.ch/doc/master/RooFactoryWSTool_8cxx_source.html#l00722
    #     For rooworkspace factory examples see:
    #     https://root.cern.ch/root/html/tutorials/roofit/rf511_wsfactory_basic.C.html
    #     https://root.cern.ch/root/html/tutorials/roofit/rf512_wsfactory_oper.C.html
    #     https://root.cern.ch/root/html/tutorials/roofit/rf513_wsfactory_tools.C.html
    wsu = root_analysis.WsUtils(name='modeller')
    wsu.factory = [
        "Gaussian::sig1(x[-10,10],mean[5,0,10],0.5)",
        "Gaussian::sig2(x,mean,1)",
        "Chebychev::bkg(x,{a0[0.5,0.,1],a1[-0.2,-1,1]})",
        "SUM::sig(sig1frac[0.8,0.,1.]*sig1,sig2)",
        "SUM::model(bkgfrac[0.5,0.,1.]*bkg,sig)"
    ]
    ch.add_link(wsu)

    # --- 2. simulation: 1000 records of observable 'x' with pdf 'model'.
    #        in case pdf covers several observables use comma-separated string obs='x,y,z'
    #        the simulated data is stored in the datastore under key 'simdata'
    wsu = root_analysis.WsUtils(name='simulater')
    wsu.add_simulate(pdf='model', obs='x', num=1000, key='simdata')
    ch.add_link(wsu)
示例#3
0
settings['process'] = True
settings['fit_plot'] = True
settings['summary'] = True

fitpdf = 'sum3pdf'
n_percentile_bins = 300

#########################################################################################
# --- now set up the chains and links based on configuration flags

if settings['model']:
    # --- generate pdf
    ch = Chain('Model')

    # --- 1. define a model
    wsu = root_analysis.WsUtils(name='modeller')
    factory = [
        "RooWeibull::wb1(t[0,110000000],a1[0.93,0,2],b1[2.2e-4,0,1e-3])",
        "RooWeibull::wb2(t,a2[0.61,0,2],b2[1.1e-5,0,1e-3])",
        "RooWeibull::wb3(t,a3[0.43,0,2],b3[4.7e-7,0,1e-3])",
        "RooWeibull::wb4(t,a4[0.43,0,2],b4[2.2e-7,0,1e-3])",
        "SUM::sum2pdf(N1[580000,0,2e6]*wb1,N2[895000,0,2e6]*wb2)",
        "SUM::sum3pdf(N1[580000,0,2e6]*wb1,N2[895000,0,2e6]*wb2,N3[150500,0,2e6]*wb3)",
        "SUM::sum4pdf(N1[580000,0,2e6]*wb1,N2[895000,0,2e6]*wb2,N3[150500,0,2e6]*wb3,N4[1e5,0,2e6]*wb4)"
    ]
    wsu.factory += factory
    ch.add(wsu)

if settings['generate']:
    # --- generate pdf
    ch = Chain('Generate')
# --- minimal analysis information

proc_mgr = ProcessManager()

settings = proc_mgr.service(ConfigObject)
settings['analysisName'] = 'esk407_classification_unbiased_fit_estimate'
settings['version'] = 0

#########################################################################################
# --- now set up the chains and links based on configuration flags

# --- generate pdf, simulate, fit, and plot
ch = proc_mgr.add_chain('WsOps')

# 1. simulate output score of machine learning classifier
wsu = root_analysis.WsUtils(name='DataSimulator')
wsu.factory = [
    "expr::trans('@0-@1',{score[0,1],1})",
    "RooExponential::high_risk(trans,10)",
    "RooPolynomial::low_risk(score,{-0.4,-0.4})",
    "SUM::model(low_risk_frac[0.95,0.,1.]*low_risk,high_risk)"
]
wsu.add_simulate(pdf='high_risk',
                 obs='score',
                 num=1000,
                 key='unbiased_high_risk_testdata',
                 into_ws=True)
wsu.add_simulate(pdf='low_risk',
                 obs='score',
                 num=1000,
                 key='unbiased_low_risk_testdata',
示例#5
0
settings = process_manager.service(ConfigObject)
settings['analysisName'] = 'esk408_classification_error_propagation_after_fit'
settings['version'] = 0

#########################################################################################
# --- Analysis values, settings, helper functions, configuration flags.

#########################################################################################
# --- now set up the chains and links based on configuration flags

# --- generate pdf, simulate, fit, and plot
ch = Chain('WsOps')

# 1. simulate output score of machine learning classifier
wsu = root_analysis.WsUtils(name='DataSimulator')
wsu.factory = ["RooGaussian::high_risk(score[0,1],1,0.15)",
               "RooPolynomial::low_risk(score,{-0.3,-0.3})",
               "SUM::model(frac[0.1,0.,1.]*high_risk,low_risk)"]
wsu.add_simulate(pdf='model', obs='score', num=500, key='data', into_ws=True)
wsu.add_fit(pdf='model', data='data', key='fit_result', into_ws=True)
wsu.add_plot(obs='score', data='data', pdf='model', key='simplot')
wsu.add_plot(obs='score', pdf='model',
             pdf_args=(RooFit.Components('low_risk'), RooFit.LineColor(ROOT.kRed),
                       RooFit.LineStyle(ROOT.kDashed)),
             output_file='data_with_generator_model.pdf', key='simplot')
ch.add(wsu)

ch = Chain('SignalPValue')

# 2. plot signal probability