def checkReferencePoint(sample): ''' check if sample is simulated with a reference point ''' return pickle.load(file(sample.reweight_pkl))['ref_point'] != {} # somehow this has to be done first, not in the next loop if args.small: for s in [ttXSample] + bg: s.reduceFiles(to=10) # configure samples for s in [ttXSample] + bg: # Scale the plots with number of events used (implemented in ref_lumiweight1fb) s.event_factor = s.nEvents / float(s.chain.GetEntries()) s.setSelectionString(cutInterpreter.cutString(args.selection)) if checkReferencePoint(s): s.read_variables = [ "ref_lumiweight1fb/F", VectorTreeVariable.fromString('p[C/F]', nMax=2000) ] catPhoton_variables = [ "signalPhoton/I", "isrPhoton/I", "lepPhoton/I", "nonIsoPhoton/I", "fakePhoton/I" ] catZ_variables = ["signalZ/I"] if args.processFile.split('_')[0] == 'ttgamma': # overlap removal + signal categorization for ttgamma
def checkReferencePoint( sample ): ''' check if sample is simulated with a reference point ''' return pickle.load(file(sample.reweight_pkl))['ref_point'] != {} # somehow this has to be done first, not in the next loop if args.small: for s in [ttXSample] + bg: s.reduceFiles( to = 1 ) # configure samples for s in [ttXSample] + bg: # Scale the plots with number of events used (implemented in ref_lumiweight1fb) s.event_factor = s.nEvents / float( s.chain.GetEntries() ) s.setSelectionString( cutInterpreter.cutString(args.selection) ) if checkReferencePoint( s ): s.read_variables = ["ref_lumiweight1fb/F", VectorTreeVariable.fromString('p[C/F]', nMax=2000)] catPhoton_variables = [ "signalPhoton/I", "isrPhoton/I", "lepPhoton/I", "nonIsoPhoton/I", "fakePhoton/I"] catZ_variables = [ "signalZ/I" ] if args.processFile.split('_')[0] == 'ttgamma': # overlap removal + signal categorization for ttgamma ttXSample.read_variables += catPhoton_variables ttgammaIsrSample.read_variables += catPhoton_variables ttgammaLepSample.read_variables = catPhoton_variables ttSample.read_variables = catPhoton_variables ttgammabSample.read_variables = catPhoton_variables ttgammaFakeSample.read_variables = catPhoton_variables
if args.nonInfoSignal: ttZISRSample = copy.deepcopy( ttXSample ) #select ttgamma events with isolated gamma from ISR (cat a2) ttZISRSample.name = 'fwlite_nonInfo_LO_order2_15weights_ref' nonInfo.append(ttZISRSample) def checkReferencePoint(sample): ''' check if sample is simulated with a reference point ''' return pickle.load(file(sample.reweight_pkl))['ref_point'] != {} # set selection string selectionString = cutInterpreter.cutString(args.selection) selectionString_up = selectionString.replace('nBTag', 'nBTag_JEC_up').replace( 'nrecoJet', 'nrecoJets_JEC_up') selectionString_down = selectionString.replace( 'nBTag', 'nBTag_JEC_down').replace('nrecoJet', 'nrecoJets_JEC_down') # somehow has to be separate from the next loop if args.small: for s in [ttXSample] + bg + nonInfo: s.reduceFiles(to=5) # configure samples for i, s in enumerate([ttXSample] + bg + nonInfo): s.shortname = s.name.split('_')[1] s.event_factor = s.nEvents / float(s.chain.GetEntries())
# ATTENTION IF U USE MORE THAN ONE SIGNAL SAMPLE!!! w = WeightInfo(ttXSample.reweight_pkl) w.set_order(int(args.order)) if len(args.variables) == 0: args.variables = w.variables def checkReferencePoint(sample): ''' check if sample is simulated with a reference point ''' print pickle.load(file(sample.reweight_pkl))['ref_point'] return pickle.load(file(sample.reweight_pkl))['ref_point'] != {} ttXSample.event_factor = ttXSample.nEvents / float( ttXSample.chain.GetEntries()) ttXSample.setSelectionString(cutInterpreter.cutString(args.selection)) ttXSample.read_variables = ["ref_lumiweight1fb/F"] ttXSample.read_variables.append( VectorTreeVariable.fromString('p[C/F]', nMax=2000)) ttXSampleNoRef.event_factor = ttXSampleNoRef.nEvents / float( ttXSampleNoRef.chain.GetEntries()) ttXSampleNoRef.setSelectionString(cutInterpreter.cutString(args.selection)) print ttXSample.event_factor print ttXSampleNoRef.event_factor signal = ttXSample #stackList = [ [signal], [ttXSampleNoRef] ] stackList = [[signal], [ttXSampleNoRef]] stack = Stack(*stackList)
WC = {coeff: vals[i] for i, coeff in enumerate(coeffs)} WC_string = '_'.join(args.parameters) def get_reweight_function(): ''' return a weight function ''' def reweight(event, sample): return event.ref_lumiweight1fb * float(args.luminosity) * event_factor # return sample.xsec * 1000 / sample.nEvents / event.p_C[0] * float(args.luminosity) * event_factor return reweight selection_string = cutInterpreter.cutString(args.selection) selection_addon = "(1)" # overlap removal + signal categorization if args.process == 'ttgamma': selection_addon = "(signalPhoton==1)" selection_string += '&&' + selection_addon #elif args.process == 'ttZ': # selection_addon = "(signalZ==1)" # selection_string += '&&' + selection_addon # Make sure that weightString contains the same as weightFunction!!! weightString = 'ref_lumiweight1fb*%s*%s' % (str( args.luminosity), str(event_factor)) #weightString = '%s*1000/%s*%s*%s/p_C[0]' %( str(sample.xsec), str(sample.nEvents), str(args.luminosity), str(event_factor) ) weightFunction = get_reweight_function()
w.set_order(int(args.order)) def checkReferencePoint( sample ): ''' check if sample is simulated with a reference point ''' return pickle.load(file(sample.reweight_pkl))['ref_point'] != {} if args.small: for s in [sample] + bg: s.reduceFiles( to = 10 ) # configure samples for s in [sample] + bg: # Scale the plots with number of events used (implemented in ref_lumiweight1fb) s.event_factor = s.nEvents / float( s.chain.GetEntries() ) print cutInterpreter.cutString(args.selection) s.setSelectionString( cutInterpreter.cutString(args.selection) ) if checkReferencePoint( s ): s.read_variables = ["ref_lumiweight1fb/F", VectorTreeVariable.fromString('p[C/F]', nMax=2000)] # draw all WC + SM as line stackList = [ [sample] for param in params ] # draw all bg filled bgParams = [] stackList += [ bg ] bgParams = [[ {'legendText':s.name.split('_')[1], 'WC':{}, 'color':colorsBg[i]} for i, s in enumerate(bg) ]] stack = Stack( *stackList ) allParams = params + bgParams
WC = {coeff: vals[i] for i, coeff in enumerate(coeffs)} WC_string = '_'.join(args.parameters) def get_reweight_function(): ''' return a weight function ''' def reweight(event, sample): return event.ref_lumiweight1fb * args.luminosity * event_factor # return sample.xsec * 1000 / sample.nEvents / event.p_C[0] * args.luminosity * event_factor return reweight selection_string = cutInterpreter.cutString(args.selection) selection_addon = "(1)" # overlap removal + signal categorization if args.process == 'ttgamma': selection_addon = "(signalPhoton==1)" selection_string += '&&' + selection_addon #elif args.process == 'ttZ': # selection_addon = "(signalZ==1)" # selection_string += '&&'+selection_addon # Make sure that weightString contains the same as weightFunction!!! weightString = 'ref_lumiweight1fb*%s*%s' % (str( args.luminosity), str(event_factor)) #weightString = '%s*1000/%s*%s*%s/p_C[0]' %( str(sample.xsec), str(sample.nEvents), str(args.luminosity), str(event_factor) ) weightFunction = get_reweight_function()