Ejemplo n.º 1
0
    def __init__(self, chain, new_chain, is_reco_level=True, **kwargs):
        self.chain = chain
        self.new_chain = new_chain

        self.chain.strategy = kwargs.get('strategy')
        self.chain.region = kwargs.get('region')
        self.chain.selection = kwargs.get('selection')
        self.additional_options = kwargs.get('additional_options', None)

        self.chain.obj_sel = getObjectSelection(self.chain.selection)

        self.event_category = EventCategory(self.chain)
        self.event_selector = EventSelector(
            self.chain.region,
            self.chain,
            self.new_chain,
            is_reco_level=is_reco_level,
            event_categorization=self.event_category,
            additional_options=self.additional_options)
Ejemplo n.º 2
0
        max_events = 20000
        event_range = xrange(max_events) if max_events < len(
            sample.getEventRange(args.subJob)) else sample.getEventRange(
                args.subJob)
    else:
        event_range = sample.getEventRange(args.subJob)

    #
    # Get luminosity weight
    #
    from HNL.Weights.lumiweight import LumiWeight
    lw = LumiWeight(sample, sample_manager)

    from HNL.EventSelection.eventCategorization import EventCategory
    try:
        ec = EventCategory(chain)
    except:
        ec = None

    #
    # Define event selection
    #
    event = Event(chain,
                  chain,
                  is_reco_level=True,
                  selection=args.selection,
                  strategy='MVA',
                  region=region_to_select)

    #
    # Create fake rate objects
Ejemplo n.º 3
0
    eventRange = xrange(20000)
else:
    eventRange = sample.getEventRange(int(args.subJob))

from HNL.Tools.helpers import progress


def getSortKey(item):
    return item[0]


from HNL.EventSelection.eventSelector import EventSelector
from HNL.EventSelection.eventCategorization import EventCategory, filterSuperCategory
from HNL.EventSelection.signalLeptonMatcher import SignalLeptonMatcher
slm = SignalLeptonMatcher(chain)
ec = EventCategory(chain)
es = EventSelector('baseline',
                   chain,
                   chain,
                   is_reco_level=False,
                   event_categorization=ec)

#
# Create cutter to provide cut flow
#
from HNL.EventSelection.cutter import Cutter
cutter = Cutter(chain=chain)

#Loop over events
for entry in eventRange:
Ejemplo n.º 4
0
    if args.removeOverlap:
        if 'DYJets' in sample.name and chain._zgEventType>=3: continue
        if sample.name == 'ZG' and chain._hasInternalConversion: continue

    if args.genSkim:
        if not select3GenLeptons(chain, new_vars):      continue
    elif not args.oldAnalysisSkim:
        # if not select3Leptons(chain, new_vars, light_algo=args.lightLeptonSelection, tau_algo=args.tauSelection):       continue
        select3Leptons(chain, new_vars, light_algo=args.lightLeptonSelection, tau_algo=args.tauSelection, workingpoint = 'loose')
        if len(chain.leptons) < 3:       continue
    else:
        select3Leptons(chain, new_vars, light_algo='cutbased', workingpoint = 'tight', no_tau = True, cutter = cutter)
        if len(chain.leptons) < 3:       continue

    
    ec = EventCategory(new_vars)
    c = ec.returnCategory()
    new_vars.event_category = c

    print 'calcing'
    calculateGeneralVariables(chain, new_vars, is_reco_level=not args.genSkim)
    calculateThreeLepVariables(chain, new_vars, is_reco_level=not args.genSkim)
    new_vars.lumiweight = lw.getLumiWeight()
    output_tree.Fill()

# print output_name.split('.')[-1]+'_cutflow.root'
# cutter.saveCutFlow(output_name.split('.')[-1]+'_cutflow.root')


output_tree.AutoSave()
#if hcounter is not None:
Ejemplo n.º 5
0
        if args.separateTriggers is not None:
            output_name += '/'+args.separateTriggers
        if args.isChild:
            output_name += '/tmp_'+sample.output
        
        if args.useRef:        output_name += '/'+ sample.name +'_TrigEff_' +subjobAppendix+ '.root'
        else:   output_name += '/'+ sample.name +'_TrigEffnoMET_' +subjobAppendix+ '.root'

    return output_name 

#
# Define histograms
# Could these lists could have been done in a nicer way but since the wanted lepton is different for different var, I was too lazy for now. Redo later if needed
#                (channel, dim) 
from HNL.EventSelection.eventCategorization import EventCategory, returnCategoryTriggerNames, returnCategoryTriggers
ec = EventCategory(chain)
categories = ec.categories
category_triggers = lambda chain, category : returnCategoryTriggers(chain, category)

#First if keeps old code for reference
# if args.ignoreCategories:
#     category_map = {('eee', '1D') : ['integral'], 
#                     ('eee', '2D') : ['integral'], 
#                     ('eemu', '1D') : ('15to30', '30to55'),
#                     ('eemu', '2D') : ('15to20', '20to25', '25to30', '30to40', '40to50', '55to100'),
#                     ('emumu', '1D') : ('15to30', '30to55'),
#                     ('emumu', '2D') : ('15to20', '20to25', '25to30', '30to40', '40to50', '55to100'),
#                     ('mumumu', '1D') : ['integral'],
#                     ('mumumu', '2D') : ['integral']}

#     var = {('pt', '1D') : (lambda c : c._lPt[c.l3],                                 np.arange(5., 40., 5.),                 ('p_{T}(trailing) [GeV]', 'Events')),
Ejemplo n.º 6
0
        output_name += '/tmp_'+args.flavor

    if args.baselineCut is None:
        output_name += '/'+ sample.name +'_signalSelection-noFilter_' +subjobAppendix+ '.root'
    else:
        output_name += '/'+ sample.name +'_signalSelection-'+args.baselineCut+'_' +subjobAppendix+ '.root'

    #
    # Calculate the range for the histograms. These are as a function of the mass of the signal samples.
    # This function looks at the names of all samples and returns an array with all values right the middle of those
    # It assumes the samples are ordered by mass in the input list
    #
    mass_range = getMassRange([sample_name for sample_name in sample_manager.sample_names if '-'+args.flavor+'-' in sample_name])

    from HNL.EventSelection.eventCategorization import EventCategory
    ec = EventCategory(chain)

    #
    # Define the variables and axis name of the variable to fill and create efficiency objects
    #
    var = {'HNLmass': (lambda c : c.HNLmass,        np.array(mass_range),   ('m_{N} [GeV]', 'Events'))}
    efficiency = createEfficiencies(output_name, ec.categories, var)

    #
    # Set event range
    #
    if args.isTest:
        max_events = 20000
        event_range = xrange(max_events) if max_events < len(sample.getEventRange(args.subJob)) else sample.getEventRange(args.subJob)
    else:
        event_range = sample.getEventRange(args.subJob)    
Ejemplo n.º 7
0
            sample.getEventRange(args.subJob)) else sample.getEventRange(
                args.subJob)
    else:
        event_range = sample.getEventRange(args.subJob)

    chain.HNLmass = sample.getMass()
    chain.year = int(args.year)

    #
    # Get luminosity weight
    #
    from HNL.Weights.lumiweight import LumiWeight
    lw = LumiWeight(sample, sample_manager, skimmed=not args.noskim)

    from HNL.EventSelection.eventCategorization import EventCategory
    ec = EventCategory(chain)

    #
    # Object ID param
    #
    if args.selection == 'AN2017014':
        object_selection_param = {
            'no_tau': True,
            'light_algo': 'cutbased',
            'workingpoint': 'tight'
        }
    else:
        object_selection_param = {
            'no_tau': False,
            'light_algo': 'leptonMVAtop',
            'workingpoint': 'medium'
Ejemplo n.º 8
0
            args.subJob)
else:
    event_range = xrange(chain.GetEntries())

chain.HNLmass = float(sample.name.rsplit('-', 1)[1]) if is_signal else None
chain.year = int(args.year)
#
# Loop over all events
#
from HNL.Tools.helpers import progress
from HNL.EventSelection.eventSelectionTools import select3Leptons
from HNL.EventSelection.eventCategorization import EventCategory
from HNL.ObjectSelection.tauSelector import isGoodTau
from HNL.ObjectSelection.leptonSelector import isGoodLepton

ec = EventCategory(chain)
for entry in event_range:

    chain.GetEntry(entry)
    progress(entry - event_range[0], len(event_range))

    #if not select3GenLeptons(chain, chain): continue

    #chain.event_supercategory = ec.returnSuperCategory()
    #if chain.event_supercategory > 2: continue

    #Add here any additional cuts
    list_of_numbers['total'] += 1

    chain.leptons = [
        l for l in xrange(chain._nLight) if isGoodLepton(chain, l, 'tight')
Ejemplo n.º 9
0
    else:
        event_range = sample.getEventRange(args.subJob)    

    chain.HNLmass = sample.getMass()
    chain.year = int(args.year)

    #
    # Get luminosity weight
    #
    from HNL.Weights.lumiweight import LumiWeight
    if args.noskim:
        lw = LumiWeight(sample, sample_manager)
        

    from HNL.EventSelection.eventCategorization import EventCategory
    ec = EventCategory(chain)

    list_of_numbers = {}
    for c in listOfCategories():
        list_of_numbers[c] = {}
        for sr in xrange(1, srm.getNumberOfSearchRegions()+1):
            list_of_numbers[c][sr] = Histogram('_'.join([str(c), str(sr)]), lambda c: 0.5, ('', 'Events'), np.arange(0., 2., 1.))

    subjobAppendix = 'subJob' + args.subJob if args.subJob else ''
    selection_str = 'OldSel' if args.oldAnalysisCuts else 'NewCuts'
    mass_str = 'allMass' if args.massRegion is None else args.massRegion

    if not args.isTest:
        output_name = os.path.join(os.getcwd(), 'data', __file__.split('.')[0], selection_str, mass_str, sample.output)
    else:
        output_name = os.path.join(os.getcwd(), 'data', 'testArea', __file__.split('.')[0], selection_str, mass_str, sample.output)