<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def lhood(self, trsig, recalc=False, cachefile=None):
 """Returns likelihood of transit signal Returns sum of ``trsig`` MCMC samples evaluated at ``self.kde``. :param trsig: :class:`vespa.TransitSignal` object. :param recalc: (optional) Whether to recalculate likelihood (if calculation is cached). :param cachefile: (optional) File that holds likelihood calculation cache. """

        if not hasattr(self,'kde'):
            self._make_kde()

        if cachefile is None:
            cachefile = self.lhoodcachefile
            if cachefile is None:
                cachefile = 'lhoodcache.dat'

        lhoodcache = _loadcache(cachefile)
        key = hashcombine(self, trsig)
        if key in lhoodcache and not recalc:
            return lhoodcache[key]

        if self.is_ruled_out:
            return 0

        N = trsig.kde.dataset.shape[1]
        lh = self.kde(trsig.kde.dataset).sum() / N

        with open(cachefile, 'a') as fout:
            fout.write('%i %g\n' % (key, lh))

        return lh