def checkOptions(self, opts):
        if not (hasattr(opts, 'fitfile')):
            raise RuntimeError('Missing parameter')

        self.trgEff = TriggerEff(getattr(opts, 'fitfile'))
        self.trgEEeff = self.trgEff.getEEeff()
        self.trgMMeff = self.trgEff.getMMeff()
        self.trgEMeff = self.trgEff.getEMeff()

        self.branch = opts.branch
    def checkOptions(self,opts):
        if not (hasattr(opts,'fitfile')):
            raise RuntimeError('Missing parameter')

        self.trgEff = TriggerEff(getattr(opts,'fitfile'))
        self.trgEEeff = self.trgEff.getEEeff()
        self.trgMMeff = self.trgEff.getMMeff()
        self.trgEMeff = self.trgEff.getEMeff()
        
        self.branch = opts.branch
class EffTrgFiller(TreeCloner):
    def __init__(self):
        pass

    def help(self):
        return '''Add a new trigger efficiency weight. The source files must be passed as an option'''

    def addOptions(self, parser):
        description = self.help()
        group = optparse.OptionGroup(parser, self.label, description)

        group.add_option(
            '-f',
            '--fitfile',
            dest='fitfile',
            help='path to the file containing the fit results',
        )
        group.add_option('-b',
                         '--branch',
                         dest='branch',
                         help='Name of the trigger efficiency weight branch',
                         default='triggW')

        parser.add_option_group(group)
        return group

    def checkOptions(self, opts):
        if not (hasattr(opts, 'fitfile')):
            raise RuntimeError('Missing parameter')

        self.trgEff = TriggerEff(getattr(opts, 'fitfile'))
        self.trgEEeff = self.trgEff.getEEeff()
        self.trgMMeff = self.trgEff.getMMeff()
        self.trgEMeff = self.trgEff.getEMeff()

        self.branch = opts.branch

    def process(self, **kwargs):
        tree = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']

        self.connect(tree, input)
        self.clone(output, [self.branch])

        trgweight = numpy.ones(1, dtype=numpy.float32)
        self.otree.Branch(self.branch, trgweight, self.branch + '/F')

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ', nentries

        # avoid dots to go faster
        itree = self.itree
        otree = self.otree
        trgEff = self.trgEff
        trgEEeff = self.trgEEeff
        trgMMeff = self.trgMMeff
        trgEMeff = self.trgEMeff

        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)

            ## print event count
            if i > 0 and i % step == 0.:
                print i, 'events processed.'

            channel = itree.channel

            if channel == 0:
                e = trgEff.getTriggerEfficiency(trgMMeff, itree)
            elif channel == 1:
                e = trgEff.getTriggerEfficiency(trgEEeff, itree)
            elif channel == 2 or channel == 3:
                e = trgEff.getTriggerEfficiency(trgEMeff, itree)
            else:
                raise ValueError(
                    'channel=={0} What is that?!?!'.format(channel))

            if e > 1:
                print 'channel=={%d}, triggW: {%f} > 1 !!!' % (channel, e)

            trgweight[0] = e

            otree.Fill()
        self.disconnect()
        print '- Eventloop completed'
class EffTrgFiller(TreeCloner):

    def __init__(self):
        pass

    def help(self):
        return '''Add a new trigger efficiency weight. The source files must be passed as an option'''

    def addOptions(self,parser):
        description = self.help()
        group = optparse.OptionGroup(parser,self.label, description)

        group.add_option('-f', '--fitfile', dest='fitfile', help='path to the file containing the fit results',)
        group.add_option('-b', '--branch',   dest='branch', help='Name of the trigger efficiency weight branch', default='triggW')

        parser.add_option_group(group)
        return group 

    def checkOptions(self,opts):
        if not (hasattr(opts,'fitfile')):
            raise RuntimeError('Missing parameter')

        self.trgEff = TriggerEff(getattr(opts,'fitfile'))
        self.trgEEeff = self.trgEff.getEEeff()
        self.trgMMeff = self.trgEff.getMMeff()
        self.trgEMeff = self.trgEff.getEMeff()
        
        self.branch = opts.branch

    def process(self,**kwargs):
        tree  = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']

        self.connect(tree,input)
        self.clone(output,[self.branch]) 

        trgweight = numpy.ones(1, dtype=numpy.float32)
        self.otree.Branch(self.branch,trgweight,self.branch+'/F')

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ',nentries 
                
        # avoid dots to go faster
        itree     = self.itree
        otree     = self.otree
        trgEff    = self.trgEff
        trgEEeff  = self.trgEEeff
        trgMMeff  = self.trgMMeff
        trgEMeff  = self.trgEMeff
        
        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)

            ## print event count
            if i > 0 and i%step == 0.:
                print i,'events processed.'

            channel = itree.channel

            if channel == 0:
                e = trgEff.getTriggerEfficiency(trgMMeff, itree)
            elif channel == 1:
                e = trgEff.getTriggerEfficiency(trgEEeff, itree)
            elif channel == 2 or channel == 3:
                e = trgEff.getTriggerEfficiency(trgEMeff, itree)
            else:
                raise ValueError('channel=={0} What is that?!?!'.format(channel))

            if e > 1:
                print 'channel=={%d}, triggW: {%f} > 1 !!!' % (channel,e)
                
            trgweight[0] = e
            
            otree.Fill()
        self.disconnect()
        print '- Eventloop completed'