Reconstruction on KEKcc Batch System

Reconstruction on KEKcc Batch System#

Let us now look at the reconstruction, which produces the reconstructed nTuples required by the MergeFiles task.

Listing 3.4 reconstruction.py#
# @cond
import b2luigi as luigi
from b2luigi.basf2_helper import Basf2PathTask, Basf2nTupleMergeTask

import json
import basf2 as b2
import modularAnalysis as ma
import vertex as vx

from skim import BatchesToTextFile


class ReconstructBatch(Basf2PathTask):
    queue = "s"
    looper = luigi.IntParameter()
    projectName = luigi.Parameter()
    skim = luigi.Parameter(hashed=True)
    runningOnMC = luigi.BoolParameter()

    def requires(self):
        yield BatchesToTextFile(
                runningOnMC=self.runningOnMC, projectName=self.projectName, skim=self.skim
            )

    def output(self):
        yield self.add_to_output("reco.root")

    def create_path(self):

        mypath = b2.create_path()
        with open(self.get_input_file_names()[f"batch{self.looper}.json"][0]) as f:
            inputMdstList = json.load(f)

        ma.inputMdstList(filelist=inputMdstList, path=mypath)

        ma.fillParticleList(
            decayString='K+:my',
            cut="dr < 0.5 and abs(dz) < 3 and thetaInCDCAcceptance and kaonID > 0.01",
            path=mypath)
        ma.fillParticleList(decayString='pi+:my', cut="dr < 0.5 and abs(dz) < 3 and thetaInCDCAcceptance", path=mypath)

        ma.reconstructDecay(decayString="D-:K2Pi -> K+:my pi-:my pi-:my", cut="1.844 < M < 1.894", path=mypath)

        ma.reconstructDecay(decayString='B0:PiD-toK2Pi -> D-:K2Pi pi+:my', cut='5.0 < Mbc and abs(deltaE) < 1.0', path=mypath)
        vx.treeFit('B0:PiD-toK2Pi', 0, path=mypath, updateAllDaughters=False, ipConstraint=True, massConstraint=[411])

        if(self.runningOnMC):
            ma.matchMCTruth(list_name='B0:PiD-toK2Pi', path=mypath)

        some_variables = ['Mbc', 'deltaE']
        ma.variablesToNtuple(decayString='B0:PiD-toK2Pi', variables=some_variables,
                             filename=self.get_output_file_name("reco.root"),  path=mypath, treename='BtoPiDtoKPiPi')
        return mypath


class ReconstructionWrapper(Basf2nTupleMergeTask):
    batch_system = 'local'
    projectName = luigi.Parameter()
    skim = luigi.Parameter(hashed=True)

    def requires(self):
        for looper in range(BatchesToTextFile.NumBatches):
            yield self.clone(ReconstructBatch, runningOnMC=True,
                             looper=looper, projectName=self.projectName, skim=self.skim)
# @endcond

The reconstruction task ReconstructBatch employs b2luigi.basf2_helper.Basf2PathTask to run a minimal steering script on the input mdst list produced by the BatchesToTextFile task. The reconstruction tasks are the only tasks not marked as local and will therefore be scheduled to the KEKcc batch system. The ReconstructionWrapper task merges all reconstructed batches of a skim.