예제 #1
0
# Main function
Vars = {'inv_mass': 0}

parser = argparse.ArgumentParser(description='Arguments')
parser.add_argument('--mc', action='store_true', help='flag for MC outputs')
parser.add_argument('inputfile', metavar='text', help='input root file name')
parser.add_argument('inputdir', metavar='text', help='task directory name')
parser.add_argument('inputlist', metavar='text', help='task list name')
args = parser.parse_args()

if args.mc:
    print('MC validation not yet implemented. Exit')
    sys.exit()

SetGlobalStyle(padleftmargin=0.15,
               padtopmargin=0.05,
               titlesize=0.045,
               labelsize=0.04)

hMassTask, hMassTreeCreator, cComparison = ({} for iDic in range(3))

infile = TFile.Open(args.inputfile)
listTask = infile.Get('{0}/{1}'.format(args.inputdir, args.inputlist))
hEv = listTask.FindObject('hNEvents')
sparse = listTask.FindObject('fnSparse')
for iVar in Vars:
    hMassTask[iVar] = sparse.Projection(Vars[iVar])
    SetObjectStyle(hMassTask[iVar], color=kBlack, markerstyle=kFullCircle)

dfD = uproot.open(args.inputfile)['PWGHF_TreeCreator/tree_Ds'].arrays(
    library='pd')  #tree_event_char
dfEv = uproot.open(
예제 #2
0
from utils.AnalysisUtils import ComputeRatioDiffBins  #pylint: disable=wrong-import-position,import-error
from utils.StyleFormatter import SetGlobalStyle, SetObjectStyle  #pylint: disable=wrong-import-position,import-error

inDir = 'inputdir'
inFileNames = ['file1.root', 'file2.root']
histoNames = ['hAccEff', 'hAccEff']
colors = [kRed + 1, kAzure + 4]
markers = [kFullSquare, kFullCircle]
legNames = ['title1', 'title2']
outDir = 'outputdir'
outSuffix = 'suffix'
showUnc = True

SetGlobalStyle(padleftmargin=0.16,
               padtopmargin=0.05,
               padbottommargin=0.14,
               titleoffsety=1.5,
               titlesize=0.05,
               labelsize=0.045)

hEffPrompt, hEffFD, hEffPromptRatio, hEffFDRatio = ([] for _ in range(4))

leg = TLegend(0.2, 0.18, 0.9, 0.33)
leg.SetFillStyle(0)
leg.SetBorderSize(0)
leg.SetTextSize(0.04)

for iFile, inFileName in enumerate(inFileNames):
    inFileName = join(inDir, inFileName)
    inFile = TFile.Open(inFileName)
    hEffPrompt.append(inFile.Get(f'{histoNames[iFile]}Prompt'))
    hEffFD.append(inFile.Get(f'{histoNames[iFile]}FD'))
예제 #3
0
def main():  #pylint: disable=too-many-statements
    """
    main function of script
    """
    SetGlobalStyle(padleftmargin=0.18,
                   padbottommargin=0.14,
                   titleoffsety=1.6,
                   maxdigits=2,
                   optstat=0)

    BR_dsPhitoKKpi = 0.0224  # (PDG 2020)
    BR_BtoDs = np.array([0.09, 0.117, 0.93,
                         0.011])  # B+, B0, Bs, Lb (PDG 2020)
    FF_btoB = np.array([0.344, 0.344, 0.115, 0.198
                        ])  # B+, B0, Bs, Lb (PDG 2020 from ppbar collisions)
    Ds_from_B = np.inner(BR_BtoDs, FF_btoB)
    cooked_factor = Ds_from_B * BR_dsPhitoKKpi

    n_bins = 1001
    bin_width = 0.05  # GeV
    bin_lims = [i * bin_width for i in range(0, n_bins + 1)]
    hFONLLCentral = TH1D(
        'hDsPhipitoKkpifromBpred_central_corr',
        ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (pb GeV^{-1} #it{c})',
        n_bins, np.asarray(bin_lims, 'd'))
    hFONLLMin = TH1D(
        'hDsPhipitoKkpifromBpred_min_corr',
        ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (pb GeV^{-1} #it{c})',
        n_bins, np.asarray(bin_lims, 'd'))
    hFONLLMax = TH1D(
        'hDsPhipitoKkpifromBpred_max_corr',
        ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (pb GeV^{-1} #it{c})',
        n_bins, np.asarray(bin_lims, 'd'))

    fonll_df = pd.read_csv("fonll/FONLL_DfromB_pp5_y05_toCook.txt",
                           sep=" ",
                           header=14).astype('float64')

    for pt, cen, low, up in zip(fonll_df['pt'].to_numpy(),
                                fonll_df['central'].to_numpy(),
                                fonll_df['min'].to_numpy(),
                                fonll_df['max'].to_numpy()):
        hFONLLCentral.Fill(pt, cen * cooked_factor)
        hFONLLMin.Fill(pt, low * cooked_factor)
        hFONLLMax.Fill(pt, up * cooked_factor)

    for iBin in range(hFONLLCentral.GetNbinsX()):
        hFONLLCentral.SetBinError(iBin + 1, 1.e-3)
        hFONLLMin.SetBinError(iBin + 1, 1.e-3)
        hFONLLMax.SetBinError(iBin + 1, 1.e-3)

    stdFONLLfile = TFile.Open(
        "fonll/feeddown/D0DplusDstarPredictions_502TeV_y05_noYShift_all_191017_BDShapeCorrected.root"
    )
    hStdFONLLCentral = stdFONLLfile.Get('hDsPhipitoKkpifromBpred_central_corr')
    hStdFONLLMin = stdFONLLfile.Get('hDsPhipitoKkpifromBpred_min_corr')
    hStdFONLLMax = stdFONLLfile.Get('hDsPhipitoKkpifromBpred_max_corr')
    hFONLLPromptCentral = stdFONLLfile.Get('hDsPhipitoKkpipred_central')
    hFONLLPromptMin = stdFONLLfile.Get('hDsPhipitoKkpipred_min')
    hFONLLPromptMax = stdFONLLfile.Get('hDsPhipitoKkpipred_max')
    hStdFONLLCentral.SetDirectory(0)
    hStdFONLLMin.SetDirectory(0)
    hStdFONLLMax.SetDirectory(0)
    hFONLLPromptCentral.SetDirectory(0)
    hFONLLPromptMin.SetDirectory(0)
    hFONLLPromptMax.SetDirectory(0)
    hStdFONLLCentral.SetStats(0)
    hStdFONLLMin.SetStats(0)
    hStdFONLLMax.SetStats(0)
    hFONLLPromptCentral.SetStats(0)
    hFONLLPromptMin.SetStats(0)
    hFONLLPromptMax.SetStats(0)
    stdFONLLfile.Close()

    outFile = TFile(
        'fonll/feeddown/NonPromptDsPredictions_502TeV_y05_cooked.root',
        'recreate')
    hFONLLCentral.Write()
    hFONLLMin.Write()
    hFONLLMax.Write()
    hFONLLPromptCentral.Write()
    hFONLLPromptMin.Write()
    hFONLLPromptMax.Write()
    outFile.Close()

    hFONLL = [hFONLLCentral, hFONLLMin, hFONLLMax]
    hStdFONLL = [hStdFONLLCentral, hStdFONLLMin, hStdFONLLMax]
    labels = ['Central', 'Min', 'Max']
    canvas = []

    for label in labels:
        canvas.append(TCanvas(f'cComp{label}', '', 2000, 1000))

    for (histo, histo_std, label, canv) in zip(hFONLL, hStdFONLL, labels,
                                               canvas):
        pt_lims = np.array(histo.GetXaxis().GetXbins(), 'd')

        pt_min = list(pt_lims)[0]
        pt_max = list(pt_lims)[-1]
        histo_std = histo_std.Rebin(histo.GetNbinsX(), f'hStdFONLL{label}',
                                    pt_lims)
        histo.Rebin(5)
        histo_std.Rebin(5)
        histo.Scale(1.e-6)
        histo_std.Scale(1.e-6)
        histo_ratio = histo.Clone(f'hRatioCookedOverStd{label}')
        histo_ratio.Divide(histo, histo_std)
        histo_ratio.GetYaxis().SetTitle('Cooked FONLL / "Std" FONLL')

        print(
            f'\n"STD" FONLL {label} integral (ub): {histo_std.Integral("width"):.4e}'
        )
        print(
            f'Cooked FONLL {label} integral (ub): {histo.Integral("width"):.4e}\n'
        )

        canv.Divide(2, 1)
        canv.cd(1).DrawFrame(
            pt_min, 1e-7, pt_max, 2.,
            ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (#mub GeV^{-1} #it{c})'
        )
        leg = TLegend(0.4, 0.7, 0.8, 0.9)
        leg.SetTextSize(0.045)
        leg.SetBorderSize(0)
        leg.SetFillStyle(0)
        SetObjectStyle(histo, color=kAzure + 4, markerstyle=kFullSquare)
        SetObjectStyle(histo_std, color=kRed, markerstyle=kFullCircle)
        histo.Draw('same')
        histo_std.Draw('same')
        leg.AddEntry(histo, f'Cooked FONLL {label}', 'p')
        leg.AddEntry(histo_std, f'"Std" FONLL {label}', 'p')
        gPad.SetLogy()
        leg.Draw()

        hframe_ratio = canv.cd(2).DrawFrame(
            pt_min, 0., pt_max, 3.,
            ';#it{p}_{T} (GeV/#it{c}); Cooked FONLL / "Std" FONLL')
        hframe_ratio.GetYaxis().SetDecimals()
        SetObjectStyle(histo_ratio, color=kAzure + 4, markerstyle=kFullSquare)
        histo_ratio.Draw('same')
        canv.Update()
        canv.SaveAs(f'CompFONLL_CookedVsStd_{label}.pdf')

    input('Press enter to exit')
예제 #4
0
'''
Script for the computation of the data-driven fraction ratio
run: python ComputeDataDrivenFracRatio.py config.yml
'''

import os
import argparse
import numpy as np
import yaml
from ROOT import TCanvas, TFile, TLine, TLegend, TGraphAsymmErrors # pylint: disable=import-error,no-name-in-module
from utils.StyleFormatter import SetGlobalStyle, SetObjectStyle, GetROOTColor #pylint: disable=wrong-import-position,import-error,no-name-in-module

SetGlobalStyle(padbottommargin=0.14, padleftmargin=0.16,
               padtopmargin=0.035, titleoffsety=1.4, maxdigits=3)

parser = argparse.ArgumentParser(description='Arguments to pass')
parser.add_argument('config', metavar='text', default='config.yml',
                    help='yaml config file')
args = parser.parse_args()

with open(args.config, 'r') as ymlCfg: # pylint: disable=unspecified-encoding
    cfg = yaml.load(ymlCfg, yaml.FullLoader)

inFileNames, colors, correl, labels, titles = ([] for _ in range(5))
cfgDen = cfg['inputs']['denominator']
inFileNames.append(cfgDen['file'])
colors.append(cfgDen['color'])
labels.append(cfgDen['label'])
titles.append(cfgDen['title'])
correl.append(None)
cfgNum = cfg['inputs']['numerator']
args = parser.parse_args()

with open(args.cfgFileName, 'r') as ymlCfgFile:
    inputCfg = yaml.load(ymlCfgFile, yaml.FullLoader)
inKineFileName = inputCfg['inKineFileName']
Bhadrons = inputCfg['pdgCodeB']
FFbtoB = inputCfg['FFbtoB']
Dhadrons = inputCfg['pdgCodeD']
BRDhadrons = inputCfg['BRD']
partPlusAntiPart = inputCfg['partPlusAntiPart']
outFileName = inputCfg['outFileName']

kineDf = LoadDfFromRootOrParquet(inKineFileName, None, 'fTreeDecays')

SetGlobalStyle(padleftmargin=0.14,
               padbottommargin=0.12,
               titleoffsety=1.3,
               optstat=0)
Bcolors = [kRed + 1, kAzure + 4, kOrange + 7, kGreen + 2]
Bnames = {
    511: 'B^{+}',
    521: 'B^{0}',
    531: 'B_{s}^{0}',
    5122: '#Lambda_{b}^{0}'
}
Dnames = {
    411: 'D^{+}',
    421: 'D^{0}',
    431: 'D_{s}^{+}',
    4122: '#Lambda_{c}^{+}'
}
예제 #6
0
                (uncEffAcc / effAcc)**2)
        gCrossSectionSyst[systSource].SetPointError(iPt, 0.4,
                                                    relSyst * crossSec)

if args.system == 'pp':
    gCrossSectionSystLumi = TGraphErrors(1)
    gCrossSectionSystLumi.SetName('gCrossSectionSystLumi')
    gCrossSectionSystLumi.SetTitle('Luminosity syst. unc.;;')
    gCrossSectionSystLumi.SetPoint(0, 1., 1.)
    gCrossSectionSystLumi.SetPointError(0, 0.4, lumiUnc)
    SetObjectStyle(gCrossSectionSystLumi,
                   color=GetROOTColor('kBlue'),
                   fillstyle=0)

gROOT.SetBatch(args.batch)
SetGlobalStyle(padleftmargin=0.18, padbottommargin=0.14)

cCrossSec = TCanvas(f'c{histoName}', '', 700, 800)
cCrossSec.SetLogy()
hCrossSection.Draw()
gCrossSectionSyst['Tot'].Draw('2')

legFrac = TLegend(0.2, 0.84, 0.4, 0.94)
legFrac.SetBorderSize(0)
legFrac.SetFillStyle(0)
legFrac.SetTextSize(0.045)
legFrac.AddEntry(hPromptFrac, 'Prompt', 'p')
legFrac.AddEntry(hFDFrac, 'Non-prompt', 'p')

legEff = legFrac.Clone('legEff')
legEff.SetY1(0.2)
parser.add_argument('multDepFileName',
                    metavar='text',
                    default='multDepFile.root',
                    help='root file containing B/D multiplicity dependence')
parser.add_argument('outFileName',
                    metavar='text',
                    default='outFile.root',
                    help='output root file')
parser.add_argument('--multFactor',
                    type=float,
                    default=1.,
                    help='value of multiplicity wrt to MB')
args = parser.parse_args()

# set global style
SetGlobalStyle(padleftmargin=0.18, padbottommargin=0.14, titleoffsety=1.7)

inFileFrac = TFile.Open(args.fracFileName)
gFrac = inFileFrac.Get('gFcConservative')
if not gFrac:
    print('ERROR: graph with prompt fraction not present in input file! Exit')
    sys.exit()
inFileFrac.Close()

sFracRatioVsMult, multFactor = [], []
tunes = [0, 3, 7, 8, 9]
for tune in tunes:
    fRatioVsMult = uproot.open(
        args.multDepFileName)[f'hfnonprompt_ratioMB_meson_tune{tune}']
    bins = fRatioVsMult.axis(0).edges()
    multCent = [(bins[iBin] + bins[iBin + 1]) / 2
def comp_fit_pars(do_ratio=False, meson='Ds'): #pylint: disable-msg=too-many-statements,too-many-locals
    inputdir = '../../AnalysisNonPromptDpp2017/Dplus/outputs/rawyields'
    input_files = ['RawYieldsDplus_pp5TeV_prompt_central.root', 'RawYieldsDplus_pp5TeV_FD_central_freesigma.root']
    input_files_MC = ['RawYieldsDplusMC_pp5TeV_prompt_central.root', 'RawYieldsDplusMC_pp5TeV_FD_central.root']
    colors = [kOrange+7, kAzure+2, kRed+1, kAzure+4]
    markers = [kOpenCircle, kOpenSquare, kFullCircle, kFullSquare]
    legendnames = ['MC - prompt enhanced', 'MC - FD enhanced', 'data - prompt enhanced', 'data - FD enhanced']
    suffix = 'CompMCData'
    min_pt = 2.
    max_pt = 16.

    SetGlobalStyle(padleftmargin=0.18, padtopmargin=0.05, padbottommargin=0.14,
                   titleoffsety=1.6, titlesize=0.045, labelsize=0.04)
    hMean, hSigma = [], []
    input_files = input_files_MC + input_files

    if meson == 'Ds':
        massD = TDatabasePDG.Instance().GetParticle(431).Mass()
    elif meson == 'Dplus':
        massD = TDatabasePDG.Instance().GetParticle(411).Mass()

    lineMass = TLine(min_pt, massD, max_pt, massD)
    lineMass.SetLineWidth(2)
    lineMass.SetLineColor(kBlack)
    lineMass.SetLineStyle(9)

    legSigma = TLegend(0.2, 0.78, 0.8, 0.93)
    legSigma.SetFillStyle(0)
    legSigma.SetBorderSize(0)
    legSigma.SetTextSize(0.04)

    legMean = TLegend(0.4, 0.73, 0.7, 0.93)
    legMean.SetFillStyle(0)
    legMean.SetBorderSize(0)
    legMean.SetTextSize(0.04)
    legMean.AddEntry(lineMass, "PDG", 'l')

    for file_path, color, marker, legend_name in zip(input_files, colors, markers, legendnames):
        input_file = TFile(f'{inputdir}/{file_path}')
        histo_mean = input_file.Get('hRawYieldsMean')
        histo_sigma = input_file.Get('hRawYieldsSigma')
        histo_mean.SetDirectory(0)
        histo_sigma.SetDirectory(0)
        SetObjectStyle(histo_mean, linecolor=color, markercolor=color, markerstyle=marker)
        SetObjectStyle(histo_sigma, linecolor=color, markercolor=color, markerstyle=marker)
        legMean.AddEntry(histo_mean, legend_name, 'p')
        legSigma.AddEntry(histo_sigma, legend_name, 'p')
        hMean.append(histo_mean)
        hSigma.append(histo_sigma)

    if do_ratio:
        mean_num_list = list(hMean)
        mean_num_list.pop(0)
        mean_den_hist = hMean[0]
        mean_ratio_list = []
        for histo in mean_num_list:
            mean_ratio_list.append(ComputeRatioDiffBins(histo, mean_den_hist))
        cMeanRatio = TCanvas('cMeanRatio', '', 800, 800)
        cMeanRatio.DrawFrame(min_pt, 0.99, max_pt, 1.01, ';#it{p}_{T} (GeV/#it{c}); peak mean / peak mean MC')
        lineRatio = TLine(min_pt, 1., max_pt, 1.)
        lineRatio.SetLineWidth(2)
        lineRatio.SetLineColor(kBlack)
        lineRatio.SetLineStyle(9)
        legMeanRatio = TLegend(0.4, 0.73, 0.7, 0.93)
        legMeanRatio.SetFillStyle(0)
        legMeanRatio.SetBorderSize(0)
        legMeanRatio.SetTextSize(0.04)
        for hist, color, marker, legend_name in zip(mean_ratio_list, colors[1:],
                                                    markers[1:], legendnames[1:]):
            SetObjectStyle(hist, linecolor=color, markercolor=color, markerstyle=marker)
            hist.Draw('same')
            legMeanRatio.AddEntry(hist, legend_name, 'p')
        lineRatio.Draw()
        legMeanRatio.Draw()

        sigma_num_list = list(hSigma)
        sigma_num_list.pop(0)
        sigma_den_hist = hSigma[0]
        sigma_ratio_list = []
        for histo in sigma_num_list:
            sigma_ratio_list.append(ComputeRatioDiffBins(histo, sigma_den_hist))
        cSigmaRatio = TCanvas('cSigmaRatio', '', 800, 800)
        hFrameSigma = cSigmaRatio.DrawFrame(min_pt, 0.6, max_pt, 1.8,
                                            ';#it{p}_{T} (GeV/#it{c}); peak width / peak width MC')
        hFrameSigma.GetYaxis().SetDecimals()
        legSigmaRatio = TLegend(0.4, 0.73, 0.7, 0.93)
        legSigmaRatio.SetFillStyle(0)
        legSigmaRatio.SetBorderSize(0)
        legSigmaRatio.SetTextSize(0.04)
        for hist, color, marker, legend_name in zip(sigma_ratio_list, colors[1:],
                                                    markers[1:], legendnames[1:]):
            SetObjectStyle(hist, linecolor=color, markercolor=color, markerstyle=marker)
            hist.Draw('same')
            legSigmaRatio.AddEntry(hist, legend_name, 'p')
        lineRatio.Draw()
        legSigmaRatio.Draw()
        cMeanRatio.SaveAs(f'{inputdir}/MeanRatio_{suffix}.pdf')
        cSigmaRatio.SaveAs(f'{inputdir}/SigmaRatio_{suffix}.pdf')

    cMean = TCanvas('cMean', '', 800, 800)
    hFrameMean = cMean.DrawFrame(min_pt, massD*0.995, max_pt, massD*1.01,
                                 ';#it{p}_{T} (GeV/#it{c}); peak mean (GeV/#it{c}^{2})')
    hFrameMean.GetYaxis().SetDecimals()
    lineMass.Draw("same")
    for histo_mean in hMean:
        histo_mean.Draw('same')
    legMean.Draw()

    cSigma = TCanvas('cSigma', '', 800, 800)
    cSigma.DrawFrame(min_pt, 0., max_pt, 0.025, ';#it{p}_{T} (GeV/#it{c}); peak width (GeV/#it{c}^{2})')
    for histo_sigma in hSigma:
        histo_sigma.Draw('same')
    legSigma.Draw()

    cMean.SaveAs(f'{inputdir}/Mean_{suffix}.pdf')
    cSigma.SaveAs(f'{inputdir}/Sigma_{suffix}.pdf')
    input('Press enter to exit')
예제 #9
0
def main(): #pylint: disable=too-many-statements
    SetGlobalStyle(padleftmargin=0.18, padbottommargin=0.14, titleoffsety=1.6, maxdigits=2, optstat=0)

    inFileFONLL = TFile.Open('fonll/feeddown/DmesonLcPredictions_502TeV_y05_FFee_BRpythia8_SepContr_PDG2020.root')
    hFONLLPromptD0 = inFileFONLL.Get('hD0Kpipred_max')
    hFONLLPromptDplus = inFileFONLL.Get('hDpluskpipipred_max')
    hFONLLPromptDs = inFileFONLL.Get('hDsPhipitoKkpipred_max')
    hFONLLNonPromptD0 = inFileFONLL.Get('hD0KpifromBpred_central_corr')
    hFONLLNonPromptDplus = inFileFONLL.Get('hDpluskpipifromBpred_central_corr')
    hFONLLNonPromptDs = inFileFONLL.Get('hDsPhipitoKkpifromBpred_central_corr')

    binLims = np.array([0., 1., 2., 3., 4., 5., 6., 7., 8., 10., 12., 16., 24.], 'd')
    nBins = 12

    hFONLLPromptD0 = hFONLLPromptD0.Rebin(nBins, 'hFONLLPromptD0', binLims)
    hFONLLPromptDplus = hFONLLPromptDplus.Rebin(nBins, 'hFONLLPromptDplus', binLims)
    hFONLLPromptDs = hFONLLPromptDs.Rebin(nBins, 'hFONLLPromptDs', binLims)
    hFONLLNonPromptD0 = hFONLLNonPromptD0.Rebin(nBins, 'hFONLLNonPromptD0', binLims)
    hFONLLNonPromptDplus = hFONLLNonPromptDplus.Rebin(nBins, 'hFONLLNonPromptDplus', binLims)
    hFONLLNonPromptDs = hFONLLNonPromptDs.Rebin(nBins, 'hFONLLNonPromptDs', binLims)

    hFONLLNPfracD0 = hFONLLPromptD0.Clone('hFONLLNPfracD0')
    hFONLLNPfracD0.Divide(hFONLLNonPromptD0, hFONLLNPfracD0)
    hFONLLNPfracDplus = hFONLLPromptDplus.Clone('hFONLLNPfracDplus')
    hFONLLNPfracDplus.Divide(hFONLLNonPromptDplus, hFONLLNPfracDplus)
    hFONLLNPfracDs = hFONLLPromptDs.Clone('hFONLLNPfracDs')
    hFONLLNPfracDs.Divide(hFONLLNonPromptDs, hFONLLNPfracDs)

    SetObjectStyle(hFONLLNPfracD0, color=kRed, linewitdh=2, markerstyle=0, fillstyle=0)
    SetObjectStyle(hFONLLNPfracDplus, color=kGreen, linewitdh=2, markerstyle=0, fillstyle=0)
    SetObjectStyle(hFONLLNPfracDs, color=kOrange, linewitdh=2, markerstyle=0, fillstyle=0)

    mesonList = ['D0', 'D+', 'Ds']
    histoList = [hFONLLNPfracD0, hFONLLNPfracDplus, hFONLLNPfracDs]

    print(*binLims, sep=' ')
    for meson, histo in zip(mesonList, histoList):
        valueList = []
        for iBin in range(1, nBins + 1):
            valueList.append(f'{histo.GetBinContent(iBin):.3f}')
        print(meson)
        print(*valueList, sep=' ')

    legMeson = TLegend(0.65, 0.6, 0.85, 0.8)
    legMeson.SetTextSize(0.04)
    legMeson.SetFillStyle(0)
    legMeson.AddEntry(hFONLLNPfracD0, 'D^{0}', 'l')
    legMeson.AddEntry(hFONLLNPfracDplus, 'D^{+}', 'l')
    legMeson.AddEntry(hFONLLNPfracDs, 'D_{s}^{+}', 'l')

    cFrac = TCanvas('cFrac', '', 500, 500)
    hFrame = cFrac.DrawFrame(0., 0.01, 24., 1.05, ';#it{p}_{T} (GeV/#it{c}); #it{f}_{non-prompt}')
    hFrame.GetYaxis().SetDecimals()
    hFrame.Draw('axis same')
    hFONLLNPfracD0.Draw('same')
    hFONLLNPfracDplus.Draw('same')
    hFONLLNPfracDs.Draw('same')
    legMeson.Draw('same')
    cFrac.Update()

    TFile('./NaturalNonPromptFrac_FONLL_FFee_BRpythia8.root', 'recreate')
    hFONLLNPfracD0.Write()
    hFONLLNPfracDplus.Write()
    hFONLLNPfracDs.Write()
    cFrac.Write()

    input('Press enter to exit')
    hCrossSecFD.append(
        inFileCrossSec.Get(
            f"{crossSecCfg['histonames']['feeddown']}_central_corr"))
    hCrossSecFD.append(
        inFileCrossSec.Get(
            f"{crossSecCfg['histonames']['feeddown']}_min_corr"))
    hCrossSecFD.append(
        inFileCrossSec.Get(
            f"{crossSecCfg['histonames']['feeddown']}_max_corr"))
    if compareToNb:
        sigmaMB = cutSetCfg['theorydriven']['sigmaMB']

SetGlobalStyle(padleftmargin=0.15,
               padtopmargin=0.08,
               titleoffsetx=1.,
               titleoffsety=1.4,
               opttitle=1,
               palette=kRainBow,
               maxdigits=2)

legDistr = TLegend(0.45, 0.69, 0.75, 0.89)
legDistr.SetFillStyle(0)
legDistr.SetBorderSize(0)
legDistr.SetTextSize(0.045)

legEff = TLegend(0.2, 0.2, 0.4, 0.4)
legEff.SetFillStyle(0)
legEff.SetBorderSize(0)
legEff.SetTextSize(0.045)

legFrac = TLegend(0.2, 0.79, 0.4, 0.89)
'''
Script for plotting the RMS and shift of the raw-yield multi-trial distributions vs pT
run: python PlotMultiTrialRMSvsPt MultiTrial.root RawYieldsDefault.root Output.root
'''

import sys
import argparse
from ROOT import TCanvas, TFile, TGaxis, gPad, TMath, TLegend  # pylint: disable=import-error,no-name-in-module
from ROOT import kBlack, kRed, kBlue  # pylint: disable=import-error,no-name-in-module
sys.path.append('../..')
from utils.StyleFormatter import SetGlobalStyle, SetObjectStyle  #pylint: disable=wrong-import-position,import-error

# set global style
SetGlobalStyle(padleftmargin=0.14,
               padrightmargin=0.14,
               padbottommargin=0.14,
               titleoffsety=1.2,
               padticky=0)

# load inputs
parser = argparse.ArgumentParser(description='Arguments')
parser.add_argument('inFileNameMultiTrial',
                    metavar='text',
                    default='MultiTrial.root')
parser.add_argument('inFileNameRawYields',
                    metavar='text',
                    default='RawYieldsDefault.root')
parser.add_argument('outFileName', metavar='text', default='Output.root')
args = parser.parse_args()

inFileRaw = TFile.Open(args.inFileNameRawYields)
예제 #12
0
'''

import sys
import argparse
import yaml
import numpy as np
from ROOT import TFile, TCanvas, TH2F, TLegend  # pylint: disable=import-error,no-name-in-module
from ROOT import kRed, kAzure, kRainBow, kFullCircle, kFullSquare, kFullDiamond  # pylint: disable=import-error,no-name-in-module
sys.path.append('../..')
from utils.DfUtils import FilterBitDf, LoadDfFromRootOrParquet  #pylint: disable=wrong-import-position,import-error
from utils.AnalysisUtils import ApplyHistoEntriesToColumn  #pylint: disable=wrong-import-position,import-error
from utils.StyleFormatter import SetGlobalStyle, SetObjectStyle  #pylint: disable=wrong-import-position,import-error

SetGlobalStyle(palette=kRainBow,
               padleftmargin=0.14,
               padrightmargin=0.14,
               padbottommargin=0.14,
               titleoffsety=1.4)

parser = argparse.ArgumentParser(description='Arguments to pass')
parser.add_argument('cfgFileName',
                    metavar='text',
                    default='cfgFileName.yml',
                    help='config file name with root input files')
parser.add_argument('cutSetFileName',
                    metavar='text',
                    default='cutSetFileName.yml',
                    help='input file with cut set')
parser.add_argument('outFileName',
                    metavar='text',
                    default='outFileName.root',
예제 #13
0
    'EffAccFD': '(Acc#times#font[152]{e})_{FD}',
    'fPrompt': '#it{f}_{ prompt}^{ fc}',
    'fFD': '#it{f}_{ FD}^{ fc}'
}
varsName4Tuple = ':'.join(cutVars) + ':PtMin:PtMax:S:B:' + ':'.join(
    estNames.keys())
tSignif = TNtuple('tSignif', 'tSignif', varsName4Tuple)

totSets = 1
for cutRange in cutRanges:
    totSets *= len(cutRange)
print(f'Total number of sets per pT bin: {totSets}')

SetGlobalStyle(padleftmargin=0.2,
               padrightmargin=0.2,
               padbottommargin=0.15,
               titleoffset=1.4,
               titleoffsety=1.8,
               palette=kRainBow)

cSignifVsRest, hSignifVsRest, cEstimVsCut, hEstimVsCut = [], [], [], []
for iPt, (ptMin, ptMax) in enumerate(zip(ptMins, ptMaxs)):

    if not inputCfg['infiles']['background']['isMC']:
        outDirFitSB.cd()
        outDirFitSBPt.append(
            TDirectoryFile(f'pT{ptMin}-{ptMax}', f'pT{ptMin}-{ptMax}'))
        outDirFitSBPt[iPt].Write()
    outDirPlots.cd()
    outDirPlotsPt.append(
        TDirectoryFile(f'pT{ptMin}-{ptMax}', f'pT{ptMin}-{ptMax}'))
    outDirPlotsPt[iPt].Write()
run: python ComputeDataDrivenFracVsMultSyst.py config.yml
'''

import sys
import os
import argparse
import numpy as np
import yaml
from ROOT import TCanvas, TFile, TH1F, TGraphErrors, TLine, TBox, TLatex, TLegend, kRainBow, kRed, kBlack  # pylint: disable=import-error,no-name-in-module

sys.path.append('../..')
from utils.StyleFormatter import SetGlobalStyle, SetObjectStyle, DivideCanvas  #pylint: disable=wrong-import-position,import-error,no-name-in-module

SetGlobalStyle(padbottommargin=0.2,
               padleftmargin=0.2,
               padtopmargin=0.1,
               opttitle=1,
               titleoffset=1.6,
               maxdigits=3)

parser = argparse.ArgumentParser(description='Arguments to pass')
parser.add_argument('config',
                    metavar='text',
                    default='config.yml',
                    help='yaml config file')
args = parser.parse_args()

with open(args.config, 'r') as ymlCfg:  # pylint: disable=unspecified-encoding
    cfg = yaml.load(ymlCfg, yaml.FullLoader)

multClasses = cfg['inputs'].keys()
if 'MB' not in multClasses:
'''

import sys
import argparse
import yaml
from ROOT import TCanvas, TFile, TLine, TLegend  # pylint: disable=import-error,no-name-in-module
from ROOT import kBlack, kBlue, kOrange, kGreen, kRed, kAzure  # pylint: disable=import-error,no-name-in-module
from ROOT import kFullTriangleUp, kFullTriangleDown, kFullCross, kFullCircle, kFullSquare, kFullDiamond, kFullStar  # pylint: disable=import-error,no-name-in-module
sys.path.append('../..')
from utils.StyleFormatter import SetGlobalStyle, SetObjectStyle  #pylint: disable=wrong-import-position,import-error

parser = argparse.ArgumentParser(description='Arguments')
parser.add_argument('cfgFileName', metavar='text', default='config_ptshape_syst.yml')
args = parser.parse_args()

SetGlobalStyle(padleftmargin=0.15, padbottommargin=0.14, titlesize=0.045, labelsize=0.04, titleoffsety=1.4)

modelNames = ['pythia', 'fonll', 'tamu', 'phsd', 'mc@shq', 'catania', 'lido']
colors = {'pythia': kBlack, 'fonll': kBlue+1, 'tamu': kOrange+7, 'phsd': kGreen+2,
          'catania': kRed+2, 'mc@shq': kAzure+4, 'lido': kRed}
markers = {'pythia': kFullCircle, 'fonll': kFullSquare, 'tamu': kFullCross, 'phsd': kFullDiamond,
           'catania': kFullTriangleUp, 'mc@shq': kFullTriangleDown, 'lido': kFullStar}
legNames = {'pythia': 'Pythia', 'fonll': 'FONLL', 'tamu': 'FONLL #times TAMU', 'phsd': 'FONLL #times PHSD',
            'catania': 'FONLL #times Catania', 'mc@shq': 'FONLL #times MC@sHQ', 'lido': 'LIDO'}
histoNames = {'pythia': 'hPtGen', 'fonll': 'hPtFONLL', 'tamu': 'hPtFONLLtimesTAMU', 'phsd': 'hPtFONLLtimesPHSD',
              'catania': 'hPtFONLLtimesCatania', 'mc@shq': 'hPtFONLLtimesGossiaux', 'lido': 'hPtFONLLtimesLIDO'}
histoWeightNames = {'fonll': 'hPtWeightsFONLL', 'tamu': 'hPtWeightsFONLLtimesTAMU', 'phsd': 'hPtWeightsFONLLtimesPHSD',
                    'catania': 'hPtWeightsFONLLtimesCatania', 'mc@shq': 'hPtWeightsFONLLtimesGossiaux',
                    'lido': 'hPtWeightsFONLLtimesLIDO'}

leg = TLegend(0.2, 0.2, 0.5, 0.4)
예제 #16
0
def main():  #pylint: disable=too-many-statements
    """
    main function of script
    """
    SetGlobalStyle(padleftmargin=0.18,
                   padbottommargin=0.14,
                   titleoffsety=1.6,
                   maxdigits=2,
                   optstat=0)

    n_bins = 1001
    bin_width = 0.05  # GeV
    bin_lims = [i * bin_width for i in range(0, n_bins + 1)]
    hFONLLBtoDCentral = TH1D(
        'hDfromBpred_central',
        ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (pb GeV^{-1} #it{c})',
        n_bins, np.asarray(bin_lims, 'd'))
    hFONLLBtoDMin = TH1D(
        'hDfromBpred_min',
        ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (pb GeV^{-1} #it{c})',
        n_bins, np.asarray(bin_lims, 'd'))
    hFONLLBtoDMax = TH1D(
        'hDfromBpred_max',
        ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (pb GeV^{-1} #it{c})',
        n_bins, np.asarray(bin_lims, 'd'))
    hFONLLBCentral = TH1D(
        'hBpred_central',
        ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (pb GeV^{-1} #it{c})',
        n_bins, np.asarray(bin_lims, 'd'))
    hFONLLBMin = TH1D(
        'hBpred_min',
        ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (pb GeV^{-1} #it{c})',
        n_bins, np.asarray(bin_lims, 'd'))
    hFONLLBMax = TH1D(
        'hBpred_max',
        ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (pb GeV^{-1} #it{c})',
        n_bins, np.asarray(bin_lims, 'd'))

    fonllBtoD_df = pd.read_csv("fonll/FONLL_DfromB_pp5_y05_toCook.txt",
                               sep=" ",
                               header=14).astype('float64')
    fonllB_df = pd.read_csv("fonll/FONLL_B_pp5_y05.txt", sep=" ",
                            header=13).astype('float64')

    for pt, cen, low, up in zip(fonllBtoD_df['pt'].to_numpy(),
                                fonllBtoD_df['central'].to_numpy(),
                                fonllBtoD_df['min'].to_numpy(),
                                fonllBtoD_df['max'].to_numpy()):
        hFONLLBtoDCentral.Fill(pt, cen)
        hFONLLBtoDMin.Fill(pt, low)
        hFONLLBtoDMax.Fill(pt, up)
    for pt, cen, low, up in zip(fonllB_df['pt'].to_numpy(),
                                fonllB_df['central'].to_numpy(),
                                fonllB_df['min'].to_numpy(),
                                fonllB_df['max'].to_numpy()):
        hFONLLBCentral.Fill(pt, cen)
        hFONLLBMin.Fill(pt, low)
        hFONLLBMax.Fill(pt, up)

    for iBin in range(hFONLLBtoDCentral.GetNbinsX()):
        hFONLLBtoDCentral.SetBinError(iBin + 1, 1.e-3)
        hFONLLBtoDMin.SetBinError(iBin + 1, 1.e-3)
        hFONLLBtoDMax.SetBinError(iBin + 1, 1.e-3)
        hFONLLBCentral.SetBinError(iBin + 1, 1.e-3)
        hFONLLBMin.SetBinError(iBin + 1, 1.e-3)
        hFONLLBMax.SetBinError(iBin + 1, 1.e-3)

    hFONLL = [hFONLLBtoDCentral, hFONLLBtoDMin, hFONLLBtoDMax]
    hBFONLL = [hFONLLBCentral, hFONLLBMin, hFONLLBMax]
    labels = ['Central', 'Min', 'Max']
    canvas = []

    for label in labels:
        canvas.append(TCanvas(f'cComp{label}', '', 2000, 1000))

    for (histo, histo_std, label, canv) in zip(hFONLL, hBFONLL, labels,
                                               canvas):
        pt_lims = np.array(histo.GetXaxis().GetXbins(), 'd')

        pt_min = list(pt_lims)[0]
        pt_max = list(pt_lims)[-1]
        histo_std = histo_std.Rebin(histo.GetNbinsX(), f'hBFONLL{label}',
                                    pt_lims)
        histo.Rebin(5)
        histo_std.Rebin(5)
        histo.Scale(1.e-6)
        histo_std.Scale(1.e-6)
        histo_ratio = histo.Clone(f'hRatioDfromBOverB{label}')
        histo_ratio.Divide(histo, histo_std)
        histo_ratio.GetYaxis().SetTitle('FONLL D from B / FONLL B')

        print(
            f'\nFONLL B {label} integral (ub): {histo_std.Integral("width"):.4e}'
        )
        print(
            f'FONLL B from D {label} integral (ub): {histo.Integral("width"):.4e}\n'
        )

        canv.Divide(2, 1)
        canv.cd(1).DrawFrame(
            pt_min, 1e-4, pt_max, 100.,
            ';#it{p}_{T} (GeV/#it{c});#frac{d#sigma}{d#it{p}_{T}} (#mub GeV^{-1} #it{c})'
        )
        leg = TLegend(0.4, 0.7, 0.8, 0.9)
        leg.SetTextSize(0.045)
        leg.SetBorderSize(0)
        leg.SetFillStyle(0)
        SetObjectStyle(histo, color=kAzure + 4, markerstyle=kFullSquare)
        SetObjectStyle(histo_std, color=kRed, markerstyle=kFullCircle)
        histo.Draw('same')
        histo_std.Draw('same')
        leg.AddEntry(histo, f'FONLL D from B {label}', 'p')
        leg.AddEntry(histo_std, f'FONLL B {label}', 'p')
        gPad.SetLogy()
        leg.Draw()

        hframe_ratio = canv.cd(2).DrawFrame(
            pt_min, 0., pt_max, 3.5,
            ';#it{p}_{T} (GeV/#it{c}); FONLL D from B / FONLL B')
        hframe_ratio.GetYaxis().SetDecimals()
        SetObjectStyle(histo_ratio, color=kAzure + 4, markerstyle=kFullSquare)
        histo_ratio.Draw('same')
        canv.Update()
        canv.SaveAs(f'CompFONLL_DfromBvsB_{label}.pdf')

    input('Press enter to exit')
    SetObjectStyle(hNtrklCandInMass[inpt],
                   fillstyle=0,
                   color=colors[inpt],
                   markerstyle=markers[inpt])

hNtrklWeights = hNtrkl['data'].Clone('hNtrklWeights')
hNtrklWeights.Divide(hNtrkl['MC'])
hNtrklWeightsCand = hNtrklCand['data'].Clone('hNtrklWeightsCand')
hNtrklWeightsCand.Divide(hNtrklCand['MC'])
hNtrklWeightsCandInMass = hNtrklCandInMass['data'].Clone(
    'hNtrklWeightsCandInMass')
hNtrklWeightsCandInMass.Divide(hNtrklCandInMass['MC'])

SetGlobalStyle(padbottommargin=0.12,
               padleftmargin=0.14,
               padtopmargin=0.075,
               titleoffsety=1.4,
               opttitle=1)

lNtrkl = TLegend(0.2, 0.8, 0.7, 0.9)
lNtrkl.SetTextSize(0.045)
lNtrkl.SetBorderSize(0)
lNtrkl.SetFillStyle(0)
lNtrkl.AddEntry(
    hNtrkl['data'],
    f'data, mean = {hNtrkl["data"].GetMean():0.1f}, RMS = {hNtrkl["data"].GetRMS():0.1f}',
    'pl')
lNtrkl.AddEntry(
    hNtrkl['MC'],
    f'MC, mean = {hNtrkl["MC"].GetMean():0.1f}, RMS = {hNtrkl["MC"].GetRMS():0.1f}',
    'pl')
예제 #18
0
inputfilenames = ['file1.root', 'file2.root']
outputdir = 'outputdir'
outputsuffix = 'suffix'
signalhistonames = ['hRawYields', 'hRawYields']
bkghistonames = ['hRawYieldsBkg', 'hRawYieldsBkg']
SoverBhistonames = ['hRawYieldsSoverB', 'hRawYieldsSoverB']
signifhistonames = ['hRawYieldsSignificance', 'hRawYieldsSignificance']
evhistonames = ['hEvForNorm', 'hEvForNorm']
colors = [kRed + 1, kAzure + 4]
markers = [kFullSquare, kFullCircle]
legendnames = ['title1', 'title2']

SetGlobalStyle(padleftmargin=0.18,
               padtopmargin=0.05,
               padbottommargin=0.14,
               titleoffsety=1.8,
               titlesize=0.045,
               labelsize=0.04,
               maxdigits=2)

hSignal, hRatioSignal, hBackground, hRatioBkg, hSoverB, hSignif, hRatioSignif, hEv = [], [], [], [], [], [], [], []

leg = TLegend(0.5, 0.73, 0.8, 0.93)
leg.SetFillStyle(0)
leg.SetBorderSize(0)
leg.SetTextSize(0.04)

for iFile, filename in enumerate(inputfilenames):
    inputfile = TFile(f'{inputdir}/{filename}')
    hSignal.append(inputfile.Get(signalhistonames[iFile]))
    hBackground.append(inputfile.Get(bkghistonames[iFile]))
예제 #19
0
def main():  #pylint: disable=too-many-locals,too-many-statements
    """
    Main function of the script
    """
    parser = argparse.ArgumentParser(description='Arguments to pass')
    parser.add_argument('cfgFileName',
                        metavar='text',
                        default='cfgFileName.yml',
                        help='config file name')
    parser.add_argument('outFileDir',
                        metavar='text',
                        default='./',
                        help='output file directory')
    args = parser.parse_args()

    with open(args.cfgFileName, 'r') as ymlCfgFile:
        inputCfg = yaml.load(ymlCfgFile, yaml.FullLoader)

    #Load data
    dfPromptP6 = LoadDfFromRootOrParquet(inputCfg['input']['prompt_files'][0])
    dfPromptP8 = LoadDfFromRootOrParquet(inputCfg['input']['prompt_files'][1])
    dfFDP6 = LoadDfFromRootOrParquet(inputCfg['input']['fd_files'][0])
    dfFDP8 = LoadDfFromRootOrParquet(inputCfg['input']['fd_files'][1])

    #Select pt bin
    ptMin = inputCfg['pt_bin'][0]
    ptMax = inputCfg['pt_bin'][1]
    dfPromptP6 = dfPromptP6.query(f'{ptMin} < pt_cand < {ptMax}')
    dfPromptP8 = dfPromptP8.query(f'{ptMin} < pt_cand < {ptMax}')
    dfFDP6 = dfFDP6.query(f'{ptMin} < pt_cand < {ptMax}')
    dfFDP8 = dfFDP8.query(f'{ptMin} < pt_cand < {ptMax}')

    SetGlobalStyle(padbottommargin=0.14,
                   padleftmargin=0.18,
                   padrightmargin=0.06,
                   titleoffsety=1.6)
    varTitle = inputCfg['scan_variable']['title']
    nBins = inputCfg['scan_variable']['histo_bins']
    binLims = inputCfg['scan_variable']['histo_lims']
    varName = inputCfg['scan_variable']['name']
    hPromptP6 = TH1F('hPromptP6', f';{varTitle};Counts', nBins, binLims[0],
                     binLims[1])
    hPromptP8 = TH1F('hPromptP8', f';{varTitle};Counts', nBins, binLims[0],
                     binLims[1])
    hFDP6 = TH1F('hFDP6', f';{varTitle};Counts', nBins, binLims[0], binLims[1])
    hFDP8 = TH1F('hFDP8', f';{varTitle};Counts', nBins, binLims[0], binLims[1])
    scaleFactor = inputCfg['scan_variable']['rescale_factor']
    dfPromptP6[varName] = dfPromptP6[varName] * scaleFactor
    dfPromptP8[varName] = dfPromptP8[varName] * scaleFactor
    dfFDP6[varName] = dfFDP6[varName] * scaleFactor
    dfFDP8[varName] = dfFDP8[varName] * scaleFactor
    for value in dfPromptP6[varName].to_numpy():
        hPromptP6.Fill(value)
    for value in dfPromptP8[varName].to_numpy():
        hPromptP8.Fill(value)
    for value in dfFDP6[varName].to_numpy():
        hFDP6.Fill(value)
    for value in dfFDP8[varName].to_numpy():
        hFDP8.Fill(value)
    SetObjectStyle(hPromptP6, color=kAzure + 4, marker=kFullCircle)
    SetObjectStyle(hPromptP8, color=kRed + 1, marker=kFullCircle)
    SetObjectStyle(hFDP6, color=kAzure + 4, marker=kFullCircle)
    SetObjectStyle(hFDP8, color=kRed + 1, marker=kFullCircle)
    hPromptP6.GetXaxis().SetNdivisions(505)
    hFDP6.GetXaxis().SetNdivisions(505)
    hPromptP8.GetXaxis().SetNdivisions(505)
    hFDP8.GetXaxis().SetNdivisions(505)

    scanRange = inputCfg['scan_variable']['scan_range']
    scanStep = inputCfg['scan_variable']['scan_step']
    nEffBins = round((scanRange[1] - scanRange[0]) / scanStep)
    hEffPromptP6 = TH1F('hEffPromptP6', f';{varTitle} >;Efficiency', nEffBins,
                        scanRange[0], scanRange[1])
    hEffPromptP8 = TH1F('hEffPromptP8', f';{varTitle} >;Efficiency', nEffBins,
                        scanRange[0], scanRange[1])
    hEffFDP6 = TH1F('hEffFDP6', f';{varTitle} >;Efficiency', nEffBins,
                    scanRange[0], scanRange[1])
    hEffFDP8 = TH1F('hEffFDP8', f';{varTitle} >;Efficiency', nEffBins,
                    scanRange[0], scanRange[1])
    SetObjectStyle(hEffPromptP6, color=kAzure + 4, marker=kFullCircle)
    SetObjectStyle(hEffPromptP8, color=kRed + 1, marker=kFullCircle)
    SetObjectStyle(hEffFDP6, color=kAzure + 4, marker=kFullCircle)
    SetObjectStyle(hEffFDP8, color=kRed + 1, marker=kFullCircle)

    effPromptP6, effPromptP8, effFDP6, effFDP8 = ([] for _ in range(4))
    effPromptUncP6, effPromptUncP8, effFDUncP6, effFDUncP8 = (
        [] for _ in range(4))
    labelsConf = inputCfg['legend']['conf_labels']
    legPrompt = TLegend(0.25, 0.2, 0.6, 0.4)
    legPrompt.SetBorderSize(0)
    legPrompt.SetFillStyle(0)
    legPrompt.SetHeader('Prompt')
    legPrompt.AddEntry(hEffPromptP6, labelsConf[0], 'p')
    legPrompt.AddEntry(hEffPromptP8, labelsConf[1], 'p')
    legFD = TLegend(0.25, 0.2, 0.65, 0.4)
    legFD.SetBorderSize(0)
    legFD.SetFillStyle(0)
    legFD.SetHeader('Non-prompt')
    legFD.AddEntry(hEffPromptP6, labelsConf[0], 'p')
    legFD.AddEntry(hEffPromptP8, labelsConf[1], 'p')

    for iBin, cut in enumerate(np.arange(scanRange[0], scanRange[1],
                                         scanStep)):
        dfPromptP6Sel = dfPromptP6.query(f'{varName} > {cut}')
        dfPromptP8Sel = dfPromptP8.query(f'{varName} > {cut}')
        dfFDP6Sel = dfFDP6.query(f'{varName} > {cut}')
        dfFDP8Sel = dfFDP8.query(f'{varName} > {cut}')

        effPromptP6.append(float(len(dfPromptP6Sel) / len(dfPromptP6)))
        effPromptP8.append(float(len(dfPromptP8Sel) / len(dfPromptP8)))
        effFDP6.append(float(len(dfFDP6Sel) / len(dfFDP6)))
        effFDP8.append(float(len(dfFDP8Sel) / len(dfFDP8)))

        effPromptUncP6.append(
            np.sqrt(effPromptP6[-1] * (1 - effPromptP6[-1]) / len(dfPromptP6)))
        effPromptUncP8.append(
            np.sqrt(effPromptP8[-1] * (1 - effPromptP8[-1]) / len(dfPromptP8)))
        effFDUncP6.append(
            np.sqrt(effFDP6[-1] * (1 - effFDP6[-1]) / len(dfFDP6)))
        effFDUncP8.append(
            np.sqrt(effFDP8[-1] * (1 - effFDP8[-1]) / len(dfFDP8)))

        hEffPromptP6.SetBinContent(iBin + 1, effPromptP6[-1])
        hEffPromptP8.SetBinContent(iBin + 1, effPromptP8[-1])
        hEffFDP6.SetBinContent(iBin + 1, effFDP6[-1])
        hEffFDP8.SetBinContent(iBin + 1, effFDP8[-1])

        hEffPromptP6.SetBinError(iBin + 1, effPromptUncP6[-1])
        hEffPromptP8.SetBinError(iBin + 1, effPromptUncP8[-1])
        hEffFDP6.SetBinError(iBin + 1, effFDUncP6[-1])
        hEffFDP8.SetBinError(iBin + 1, effFDUncP8[-1])

    hEffPromptP6.GetXaxis().SetNdivisions(505)
    hEffFDP6.GetXaxis().SetNdivisions(505)
    hEffPromptP8.GetXaxis().SetNdivisions(505)
    hEffFDP8.GetXaxis().SetNdivisions(505)

    hEffPromptRatio = hEffPromptP8.Clone('hEffPromptRatio')
    hEffPromptRatio.Divide(hEffPromptP6)
    hEffPromptRatio.GetYaxis().SetTitle(
        f'Prompt eff ratio {labelsConf[1]} / {labelsConf[0]}')
    hEffFDRatio = hEffFDP8.Clone('hEffFDRatio')
    hEffFDRatio.Divide(hEffFDP6)
    hEffFDRatio.GetYaxis().SetTitle(
        f'Non-prompt eff ratio {labelsConf[1]} / {labelsConf[0]}')

    hEffPromptRatio.GetXaxis().SetNdivisions(505)
    hEffFDRatio.GetXaxis().SetNdivisions(505)

    cDistributions = TCanvas('cDistributions', '', 1920, 1080)
    cDistributions.Divide(2, 1)
    cDistributions.cd(1).SetLogy()
    hPromptP8.Draw('e')
    hPromptP6.Draw('esame')
    legPrompt.Draw()
    cDistributions.cd(2).SetLogy()
    hFDP8.Draw('e')
    hFDP6.Draw('esame')
    legFD.Draw()

    cEfficiency = TCanvas('cEfficiency', '', 1920, 1080)
    cEfficiency.Divide(2, 1)
    cEfficiency.cd(1).SetLogy()
    hEffPromptP6.Draw('e')
    hEffPromptP8.Draw('esame')
    legPrompt.Draw()
    cEfficiency.cd(2).SetLogy()
    hEffFDP6.Draw('e')
    hEffFDP8.Draw('esame')
    legFD.Draw()

    cEfficiencyRatio = TCanvas('cEfficiencyRatio', '', 1920, 1080)
    cEfficiencyRatio.Divide(2, 1)
    cEfficiencyRatio.cd(1)
    hEffPromptRatio.Draw('e')
    cEfficiencyRatio.cd(2)
    hEffFDRatio.Draw('e')

    tag = f'{labelsConf[0]}Vs{labelsConf[1]}_pT{ptMin}_{ptMax}'
    cDistributions.SaveAs(f'{args.outFileDir}/{varName}_Distr_{tag}.pdf')
    cEfficiency.SaveAs(f'{args.outFileDir}/{varName}_CutEff_{tag}.pdf')
    cEfficiencyRatio.SaveAs(
        f'{args.outFileDir}/{varName}_CutEffRatio_{tag}.pdf')

    print('Press any key to exit!')
    input()
예제 #20
0
elif args.centClass == 'kpp5TeVPrompt':
    cent = 'pp5TeVPrompt'
elif args.centClass == 'kpp13TeVFD':
    cent = 'pp13TeVFD'
elif args.centClass == 'kpp13TeVPrompt':
    cent = 'pp13TeVPrompt'
else:
    print(f"ERROR: cent class \'{args.centClass}\' is not supported! Exit")
    sys.exit()

with open(args.fitConfigFileName, 'r') as ymlfitConfigFile:
    fitConfig = yaml.load(ymlfitConfigFile, yaml.FullLoader)

gROOT.SetBatch(args.batch)
SetGlobalStyle(padleftmargin=0.14,
               padbottommargin=0.12,
               padtopmargin=0.12,
               opttitle=1)

ptMins = fitConfig[cent]['PtMin']
ptMaxs = fitConfig[cent]['PtMax']
fixSigma = fitConfig[cent]['FixSigma']
fixMean = fitConfig[cent]['FixMean']
if 'EnableRef' not in fitConfig[cent]:
    enableRef = False
else:
    enableRef = fitConfig[cent]['EnableRef']
if not isinstance(fixSigma, list):
    fixSigma = [fixSigma for _ in ptMins]
if not isinstance(fixMean, list):
    fixMean = [fixMean for _ in ptMins]
ptLims = list(ptMins)
    ':PtMin:PtMax:ParCutMin:ParCutMax:EffAccPromptError:EffAccFDError:SError:BError'
    ':SignifError:SoverBError:' + ':'.join(estNames.keys()))
tSignif = TNtuple('tSignif', 'tSignif', varsName4Tuple)

totSets = [1 for _ in enumerate(ptMaxs)]

for iPt, _ in enumerate(ptMaxs):
    for cutRange in cutRanges[iPt]:
        totSets[iPt] *= len(cutRange)
print(f'Total number of sets per pT bin: {totSets}')

SetGlobalStyle(padleftmargin=0.12,
               padrightmargin=0.2,
               padbottommargin=0.15,
               padtopmargin=0.075,
               titleoffset=1.,
               palette=kRainBow,
               titlesize=0.06,
               labelsize=0.055,
               maxdigits=4)

cSignifVsRest, hSignifVsRest, cEstimVsCut, hEstimVsCut = [], [], [], []
counter = 0
for iPt, (ptMin, ptMax) in enumerate(zip(ptMins, ptMaxs)):
    # reshuffle bkg and take only a fraction of it, seed fixed for reproducibility
    dfBkgPt = dfBkg_tot.query(
        f'{ptMin} < pt_cand  and pt_cand < {ptMax}').sample(
            frac=fractionstokeep[iPt], random_state=42).reset_index(drop=True)

    outDirFitSB.cd()
    outDirFitSBPt.append(
예제 #22
0
import ctypes
import numpy as np
import yaml
from ROOT import AliHFInvMassFitter, AliVertexingHFUtils  # pylint: disable=import-error,no-name-in-module
from ROOT import TFile, TCanvas, TH1F, TF1, TVirtualFitter, TDatabasePDG, TLegend  # pylint: disable=import-error,no-name-in-module
from ROOT import kGreen, kAzure, kRed, kRainBow, kFullCircle, kFullSquare, kFullDiamond  # pylint: disable=import-error,no-name-in-module
from ROOT import kFullCross, kOpenCircle, kOpenSquare, kOpenDiamond, kOpenCross  # pylint: disable=import-error,no-name-in-module
sys.path.append('../..')
from utils.StyleFormatter import SetObjectStyle, SetGlobalStyle, DivideCanvas  #pylint: disable=wrong-import-position,import-error
from utils.FitUtils import VoigtFunc, ExpoPowLaw  #pylint: disable=wrong-import-position,import-error

# set global style
SetGlobalStyle(padrightmargin=0.1,
               padleftmargin=0.18,
               padbottommargin=0.14,
               padtopmargin=0.075,
               titleoffsety=1.8,
               palette=kRainBow,
               maxdigits=2,
               opttitle=1)

parser = argparse.ArgumentParser(description='Arguments to pass')
parser.add_argument('cfgFileNameMC',
                    metavar='text',
                    default='cfgFileNameMC.yml',
                    help='config file name with MC root input files')
parser.add_argument('cfgFileNameData',
                    metavar='text',
                    default='cfgFileNameData.yml',
                    help='config file name with data root input files')
parser.add_argument('outputPath',
                    metavar='text',
예제 #23
0
'''

import sys
import argparse
import os
import numpy as np
import yaml
from PIL import Image
from ROOT import TFile, TCanvas, TDirectoryFile, TLegend  # pylint: disable=import-error,no-name-in-module
from ROOT import kBlue, kRed, kFullCircle, kOpenCircle  # pylint: disable=import-error,no-name-in-module
sys.path.append('../..')
from utils.TaskFileLoader import LoadSparseFromTask  #pylint: disable=wrong-import-position,import-error
from utils.StyleFormatter import SetObjectStyle, SetGlobalStyle  #pylint: disable=wrong-import-position,import-error

# main function
SetGlobalStyle()

PARSER = argparse.ArgumentParser(description='Arguments to pass')
PARSER.add_argument('cfgFileName',
                    metavar='text',
                    default='cfgFileName.yml',
                    help='config file name with root input files')
PARSER.add_argument('cutSetFileName',
                    metavar='text',
                    default='cutSetFileName.yml',
                    help='input file with cut set')
PARSER.add_argument('outFileName',
                    metavar='text',
                    default='outFileName.root',
                    help='output root file name')
ARGS = PARSER.parse_args()
예제 #24
0
    print('ERROR: you should enable the comparison for either D+ or Ds! Exit')
    sys.exit()
elif args.Dplus and args.Ds:
    print('ERROR: you cannot enable the comparison for both D+ and Ds! Exit')
    sys.exit()

if args.Dplus:
    BR = 0.0898
    mesonName = 'D^{+}'
elif args.Ds:
    BR = 0.0227
    mesonName = 'D_{s}^{+}'

SetGlobalStyle(padleftmargin=0.18,
               padbottommargin=0.14,
               titleoffsety=1.6,
               maxdigits=2,
               optstat=0)

if args.prompt:
    infilePrompt = TFile.Open(args.prompt)
    hCrossSectionPrompt = infilePrompt.Get('hCrossSection')
    if args.syst:
        gCrossSectionPrompt = infilePrompt.Get('gCrossSectionSystTot')
    if not hCrossSectionPrompt:
        hCrossSectionPrompt = infilePrompt.Get('histoSigmaCorr')
        hCrossSectionPrompt.Scale(1.e-6 / BR)
        hCrossSectionPrompt.SetStats(0)
        if args.syst:
            gCrossSectionPrompt = infilePrompt.Get('gSigmaCorr')
            gCrossSectionPrompt.RemovePoint(0)
    cent = 'Cent6080'
elif args.centClass == 'kpp5TeVPrompt':
    cent = 'pp5TeVPrompt'
elif args.centClass == 'kpp5TeVFD':
    cent = 'pp5TeVFD'
elif args.centClass == 'kpp13TeVPrompt':
    cent = 'pp13TeVPrompt'
elif args.centClass == 'kpp13TeVFD':
    cent = 'pp13TeVFD'
else:
    print(f'ERROR: centrality {args.centClass} is not supported! Exit')
    exit()

gROOT.SetBatch(args.batch)
SetGlobalStyle(padleftmargin=0.14,
               padbottommargin=0.12,
               titlesize=0.045,
               labelsize=0.04)

ptMins = fitConfig[cent]['PtMin']
ptMaxs = fitConfig[cent]['PtMax']
ptLims = list(ptMins)
nPtBins = len(ptMins)
ptLims.append(ptMaxs[-1])

hEffPrompt = TH1F('hEffPrompt', ';#it{p}_{T} (GeV/#it{c});Efficiency', nPtBins,
                  np.asarray(ptLims, 'd'))
hEffFD = TH1F('hEffFD', ';#it{p}_{T} (GeV/#it{c});Efficiency', nPtBins,
              np.asarray(ptLims, 'd'))
hYieldPromptGen = TH1F('hYieldPromptGen',
                       ';#it{p}_{T} (GeV/#it{c}); # Generated MC', nPtBins,
                       np.asarray(ptLims, 'd'))
'''
python script for the pT extrapolation of data-driven pp references
run: python ExtrapolateDataDrivenCrossSection.py configFile.yml
'''

import sys
import argparse
import numpy as np
import yaml
from ROOT import TFile, TF1, TCanvas, TH1F, TLegend, TGraphAsymmErrors  # pylint: disable=import-error,no-name-in-module
sys.path.append('..')
from utils.AnalysisUtils import ComputeRatioDiffBins
from utils.StyleFormatter import SetGlobalStyle, SetObjectStyle, GetROOTColor, GetROOTMarker

SetGlobalStyle(padbottommargin=0.13)

parser = argparse.ArgumentParser(description='Arguments to pass')
parser.add_argument('cfgFileName',
                    metavar='text',
                    default='cfgFileName.yml',
                    help='config file name with root input files')
args = parser.parse_args()

with open(args.cfgFileName, 'r') as ymlCutSetFile:
    inCfg = yaml.load(ymlCutSetFile, yaml.FullLoader)

inFile = TFile.Open(inCfg['infilename'])
hCrossSec = inFile.Get('hCrossSection')
hCrossSec.SetName('hCrossSecMeas')
hCrossSec.SetDirectory(0)
gCrossSec = inFile.Get('gCrossSectionSystTot')
예제 #27
0
# load published result
if inputCfg['PublishedResult']['plotPublished']:
    hDRaaStat, gDRaaSyst = ReadHepDataROOT(
        inputCfg['PublishedResult']['filenameHepData'],
        inputCfg['PublishedResult']['tableRaa'])
    hDCorrYieldStat, gDCorrYieldSyst = ReadHepDataROOT(
        inputCfg['PublishedResult']['filenameHepData'],
        inputCfg['PublishedResult']['tableCorrYield'])
    SetGraphStyle(gDRaaSyst, kBlack, kWhite, kFullSquare, 1)
    SetGraphStyle(gDCorrYieldSyst, kBlack, kWhite, kFullSquare, 1)
    SetGraphStyle(hDRaaStat, kBlack, kWhite, kFullSquare, 1)
    SetGraphStyle(hDCorrYieldStat, kBlack, kWhite, kFullSquare, 1)

# plots
SetGlobalStyle(padleftmargin=0.14, titlesize=0.045, labelsize=0.04)

legTAMU, legPHSD, legGossiaux, legCatania = ({
    'CorrYield':
    TLegend(0.45, 0.7, 0.65, 0.85),
    'Raa':
    TLegend(0.45, 0.7, 0.65, 0.85),
    'Signif':
    TLegend(0.45, 0.75, 0.65, 0.85)
} for iDic in range(4))

for iLeg in legTAMU:
    legTAMU[iLeg].SetFillStyle(0)
    legTAMU[iLeg].SetTextSize(0.045)
    legPHSD[iLeg].SetFillStyle(0)
    legPHSD[iLeg].SetTextSize(0.045)
예제 #28
0
import os
import sys
import argparse
import yaml
from ROOT import TCanvas, TLegend, TDatabasePDG, TH1F, TH2F, TF1, TLine, TGraph, TVirtualFitter, TLatex  # pylint: disable=import-error,no-name-in-module
from ROOT import kFullCircle, kFullSquare, kRainBow, kRed, kAzure, kGray, kBlack  # pylint: disable=import-error,no-name-in-module
from ROOT import RooStats  # pylint: disable=import-error,no-name-in-module
sys.path.append('../..')
from utils.TaskFileLoader import LoadSingleSparseFromTask  #pylint: disable=wrong-import-position,import-error
from utils.DfUtils import LoadDfFromRootOrParquet  #pylint: disable=wrong-import-position,import-error
from utils.StyleFormatter import SetObjectStyle, SetGlobalStyle, DivideCanvas  #pylint: disable=wrong-import-position,import-error

SetGlobalStyle(palette=kRainBow,
               padbottommargin=0.14,
               padrightmargin=0.14,
               padleftmargin=0.14,
               padtopmargin=0.075,
               titleoffsety=1.4,
               opttitle=1)

parser = argparse.ArgumentParser(description='Arguments to pass')
parser.add_argument('cfgFileName',
                    metavar='text',
                    default='cfgFileName.yml',
                    help='config file name with root input files')
parser.add_argument('cutSetFileName',
                    metavar='text',
                    default='cutset.yml',
                    help='config file name with root input files')
parser.add_argument('outputPath',
                    metavar='text',