Example #1
0
def FiltFunc(args):
    with open(args.cfgFileName, 'r') as ymlCfgFile:
        inputCfg = yaml.load(ymlCfgFile, yaml.FullLoader)

    with open(args.cutSetFileNames[0], 'r') as ymlCutSetFile:
        cutSetCfg = yaml.load(ymlCutSetFile, yaml.FullLoader)
    cutVars = cutSetCfg['cutvars']
    axesToKeep = cutSetCfg['axestokeep']

    infilenames = inputCfg['filename']
    if not isinstance(infilenames, list):
        infilenames = [infilenames]

    for iFile, infilename in enumerate(infilenames):
        sparseReco, sparseGen = LoadSparseFromTask(infilename, inputCfg)

        # filter sparses
        sparseFiltReco = FilterSparses(sparseReco, cutVars, axesToKeep)
        if inputCfg['isMC']:
            sparseFiltGen = FilterSparses(sparseGen, cutVars, axesToKeep)

        # plot filtered sparses (each variable vs pt)
        if args.plot:
            PlotFiltVarsVsPt(sparseFiltReco, 'cReco{0}'.format(iFile))
            if inputCfg['isMC']:
                PlotFiltVarsVsPt(sparseFiltGen, 'cGen{0}'.format(iFile))

        # get other objects from original file
        inlist = LoadListFromTask(infilename, inputCfg)
        _, normCounter = LoadNormObjFromTask(infilename, inputCfg)
        cutObj, cutObjName = LoadCutObjFromTask(infilename, inputCfg)
        for sparse in sparseFiltReco.values():
            sparsetodel = inlist.FindObject(sparse.GetName())
            inlist.Remove(sparsetodel)
            inlist.Add(sparse)
        if inputCfg['isMC']:
            for sparse in sparseFiltGen.values():
                sparsetodel = inlist.FindObject(sparse.GetName())
                inlist.Remove(sparsetodel)
                inlist.Add(sparse)

        # save new file with filtered sparses
        outfilename = infilename
        if args.suffix:
            outfilename = outfilename.replace(
                '.root', '{0}.root'.format(args.suffix))
        print('Saving filtered ThnSparses in file', outfilename)
        outfile = TFile(outfilename, 'recreate')
        outdir = TDirectoryFile(inputCfg['dirname'], inputCfg['dirname'])
        outdir.Write(inputCfg['dirname'])
        outdir.cd()
        inlist.Write(inputCfg['listname'], 1)
        cutObj.Write(cutObjName)
        normCounter.Write()
        outfile.Close()
Example #2
0
def FiltFuncV2(args):
    with open(args.cfgFileName, 'r') as ymlCfgFile:
        inputCfg = yaml.load(ymlCfgFile, yaml.FullLoader)

    cutSetsCfg = []
    for cutFile in args.cutSetFileNames:
        with open(cutFile, 'r') as file:
            cutCfg = yaml.load(file, yaml.FullLoader)
            cutSetsCfg.append(cutCfg)

    if not len(cutSetsCfg) == len(inputCfg['dirname']) == len(
            inputCfg['listname']):
        print('Wrong number of cut sets, dir names or list names')
        return

    sparseList = LoadSparseFromTaskV2(inputCfg)
    sparseListFilt = []

    for sparse, cutSet in zip(sparseList, cutSetsCfg):
        sparseFilt = FilterSparsesV2(sparse, cutSet['cutvars'],
                                     cutSet['axestokeep'])
        sparseListFilt.append(sparseFilt)

    for sparse in sparseListFilt[1:]:
        sparseListFilt[0].Add(sparse)

    # get other objects from original file
    inlist = LoadListFromTaskV2(inputCfg['filename'], inputCfg['dirname'][0],
                                inputCfg['listname'][0])
    sparsetodel = inlist.FindObject(sparseList[0].GetName())
    inlist.Remove(sparsetodel)
    inlist.Add(sparseListFilt[0])

    # save new file with filtered sparses
    outfilename = inputCfg['outfilename']
    print('Saving filtered ThnSparses in file', outfilename)
    outfile = TFile(outfilename, 'recreate')
    outdir = TDirectoryFile(inputCfg['outdirname'], inputCfg['outdirname'])
    outdir.Write(inputCfg['outdirname'])
    outdir.cd()
    inlist.Write(inputCfg['outlistname'], 1)
    outfile.Close()
Example #3
0
    1: '#it{p}_{T} (GeV/#it{c})',
    2: '#Delta#it{M}_{KK} (MeV/#it{c})',
    3: 'decay length (#mum #times 0.1)',
    4: 'decay length xy (#mum #times 0.1)',
    5: 'normalised decay length xy',
    6: 'cos(#theta_{p}) #times 100',
    7: 'cos(#theta_{p}^{xy}) #times 100',
    8: 'sigma vertex (#mum #times 0.1)',
    10: '|cos^{3}(#piK#phi)|',
    11: 'max norm #it{d}_{0}-#it{d}_{0}^{exp}',
    12: 'impact parameter xy'
}

outfile = TFile(ARGS.outFileName, 'recreate')
dir1D = TDirectoryFile('Distr1D', 'Distr1D')
dir1D.Write()
outfile.cd()
dirVsPt = TDirectoryFile('DistrVsPt', 'DistrVsPt')
dirVsPt.Write()
outfile.cd()
dirVsML = TDirectoryFile('DistrVsML', 'DistrVsML')
dirVsML.Write()

cVars, cVarsNorm, cVarsVsPt, cVarsVsML = {}, {}, {}, {}
hVars, hVarsSel, hVarsNorm, hVarsSelNorm, hVarsVsPt, hVarsSelVsPt, hVarsVsML, hVarsSelVsML = (
    {} for iDic in range(8))

listoffigures = []
for iPt, (ptmin,
          ptmax) in enumerate(zip(cutVars['Pt']['min'], cutVars['Pt']['max'])):
    cVars[f'Pt{ptmin:.0f}_{ptmax:.0f}'] = TCanvas(
    RaaFD = RaaFD_config

# load constant terms
nExpEv = inputCfg['nExpectedEvents']
Taa = inputCfg['Taa']
sigmaMB = inputCfg['sigmaMB']

# set batch mode if enabled
if args.batch:
    gROOT.SetBatch(True)
    gROOT.ProcessLine("gErrorIgnoreLevel = kFatal;")

# output file with TNtuple
outFile = TFile(args.outFileName, 'recreate')
outDirFitSB = TDirectoryFile('SBfits', 'SBfits')
outDirFitSB.Write()
outDirFitSBPt = []

outFile.cd()
outDirPlots = TDirectoryFile('plots', 'plots')
outDirPlots.Write()
outDirPlotsPt = []

estNames = {
    'Signif': 'expected significance',
    'SoverB': 'S/B',
    'S': 'expected signal',
    'B': 'expected background',
    'EffAccPrompt': '(Acc#times#font[152]{e})_{prompt}',
    'EffAccFD': '(Acc#times#font[152]{e})_{FD}',
    'fPrompt': '#it{f}_{ prompt}^{ fc}',
Example #5
0
hRawYieldsSecPeak.Write()
hRawYieldsMeanSecPeak.Write()
hRawYieldsSigmaSecPeak.Write()
hRawYieldsSignificanceSecPeak.Write()
hRawYieldsSigmaRatioSecondFirstPeak.Write()
hRawYieldsSoverBSecPeak.Write()
hRawYieldsSignalSecPeak.Write()
hRawYieldsBkgSecPeak.Write()
hRawYieldsTrue.Write()
hRawYieldsSecPeakTrue.Write()
hRelDiffRawYieldsFitTrue.Write()
hRelDiffRawYieldsSecPeakFitTrue.Write()
hEv.Write()
if not args.isMC:
    dirSB = TDirectoryFile('SandBDiffNsigma', 'SandBDiffNsigma')
    dirSB.Write()
    dirSB.cd()
    for iS, _ in enumerate(nSigma4SandB):
        hRawYieldsSignalDiffSigma[iS].Write()
        hRawYieldsBkgDiffSigma[iS].Write()
        hRawYieldsSoverBDiffSigma[iS].Write()
        hRawYieldsSignifDiffSigma[iS].Write()
    dirSB.Close()
outFile.Close()

outFileNamePDF = args.outFileName.replace('.root', '.pdf')
outFileNameResPDF = outFileNamePDF.replace('.pdf', '_Residuals.pdf')
for iCanv, (cM, cR) in enumerate(zip(cMass, cResiduals)):
    if iCanv == 0 and nCanvases > 1:
        cM.SaveAs(f'{outFileNamePDF}[')
    cM.SaveAs(outFileNamePDF)
    hBkg[-1].SetDirectory(0)
    hSgnMin[-1].SetDirectory(0)
    hSgnMax[-1].SetDirectory(0)
    hSignif[-1].SetDirectory(0)
    hSignifMin[-1].SetDirectory(0)
    hSignifMax[-1].SetDirectory(0)
    hSoverB[-1].SetDirectory(0)
    hSoverBMin[-1].SetDirectory(0)
    hSoverBMax[-1].SetDirectory(0)
    hEff[-1].SetDirectory(0)
    hAcc[-1].SetDirectory(0)
    hEffAcc[-1].SetDirectory(0)

    outFile.cd()
    outDir = TDirectoryFile(meson, meson)
    outDir.Write()
    outDir.cd()
    hSgn[-1].Write()
    hSgnMin[-1].Write()
    hSgnMax[-1].Write()
    for iPt, _ in enumerate(hMassSignal):
        hMassSignal[iPt].Write()
        hMassSignalMin[iPt].Write()
        hMassSignalMax[iPt].Write()
    hBkg[-1].Write()
    for iPt, _ in enumerate(hMassSignal):
        hMassBkg[iPt].Write()
        hMassBkgMin[iPt].Write()
        hMassBkgMax[iPt].Write()
    hSignif[-1].Write()
    hSignifMin[-1].Write()