def __init__(self, sample, sample_manager): self.sample = sample self.sample_manager = sample_manager #lumi weights self.lumiweighter = LumiWeight(sample, sample_manager) #pu weights if not sample.is_data: self.puReweighting = getReweightingFunction( sample.chain.year, 'central') self.puReweightingUp = getReweightingFunction( sample.chain.year, 'up') self.puReweightingDown = getReweightingFunction( sample.chain.year, 'down') self.fakerate_collection = None
class Reweighter: def __init__(self, sample, sample_manager): self.sample = sample self.sample_manager = sample_manager #lumi weights self.lumiweighter = LumiWeight(sample, sample_manager) #pu weights if not sample.is_data: self.puReweighting = getReweightingFunction( sample.chain.year, 'central') self.puReweightingUp = getReweightingFunction( sample.chain.year, 'up') self.puReweightingDown = getReweightingFunction( sample.chain.year, 'down') self.fakerate_collection = None def getLumiWeight(self): return self.lumiweighter.getLumiWeight() def getPUWeight(self): if not self.sample.is_data: return self.puReweighting(self.sample.chain._nTrueInt) else: return 1. def getFakeRateWeight(self): try: return self.fakerate_collection.getFakeWeight() except: self.fakerate_collection = returnFakeRateCollection( self.sample.chain) return self.fakerate_collection.getFakeWeight() def getTotalWeight(self, sideband=False): tot_weight = 1. tot_weight *= self.getLumiWeight() tot_weight *= self.getPUWeight() if sideband: tot_weight *= self.getFakeRateWeight() return tot_weight
# # Set range of events to process # 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) # # 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',
# if args.isTest: if len(sample.getEventRange(0)) < 1000: event_range = sample.getEventRange(0) else: event_range = xrange(1000) elif args.runOnCream: event_range = sample.getEventRange(args.subJob) else: event_range = xrange(chain.GetEntries()) chain.HNLmass = sample.getMass() chain.year = int(args.year) from HNL.Weights.lumiweight import LumiWeight lw = LumiWeight(sample, sample_manager) print sample.name # # Loop over all events # from HNL.Tools.helpers import progress, makeDirIfNeeded from HNL.ObjectSelection.tauSelector import isGoodGenTau from HNL.EventSelection.eventSelectionTools import select3GenLeptons 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
sample = sample_manager.getSample(args.sample) chain = sample.initTree() chain.year = int(args.year) chain.is_signal = 'HNL' in sample.name # # Import and create cutter to provide cut flow # from HNL.EventSelection.cutter import Cutter cutter = Cutter(chain = chain) # # Get lumiweight # from HNL.Weights.lumiweight import LumiWeight lw = LumiWeight(sample, sample_manager) # # Create new reduced tree (except if it already exists and overwrite option is not used) # from HNL.Tools.helpers import isValidRootFile, makeDirIfNeeded gen_name = 'Reco' if not args.genSkim else 'Gen' if sample.is_data: output_file_name = 'Data' elif chain.is_signal: output_file_name = sample.path.split('/')[-1].rsplit('.', 1)[0] else: output_file_name = sample.path.split('/')[-2] output_base = os.path.expandvars(os.path.join('/user/$USER/public/ntuples/HNL')) if not args.isTest else os.path.expandvars(os.path.join('$CMSSW_BASE', 'src', 'HNL', 'SkimTuples', 'data', 'testArea'))
for channel in ['Ditau', 'SingleTau']: list_of_hist[algo][iso_wp][ele_wp][mu_wp][ channel] = ROOT.TH1D( '_'.join( [channel, algo, iso_wp, ele_wp, mu_wp]), '_'.join( [channel, algo, iso_wp, ele_wp, mu_wp]), 1, 0, 1) list_of_hist[algo][iso_wp][ele_wp][mu_wp][ channel].Sumw2() # # Get luminosity weight # from HNL.Weights.lumiweight import LumiWeight lw = LumiWeight(sample, sample_manager) from HNL.EventSelection.eventSelectionTools import bVeto def passCuts(chain, indices): if len(indices) != 3: return False if chain._lCharge[indices[0]] == chain._lCharge[ indices[1]] and chain._lCharge[indices[2]] == chain._lCharge[ indices[1]]: return False if bVeto(chain): return False vectors = [] for lepton_index in indices: vectors.append( getFourVec(chain._lPt[lepton_index], chain._lEta[lepton_index], chain._lPhi[lepton_index], chain._lE[lepton_index]))
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) chain.HNLmass = sample.getMass() chain.year = int(args.year) chain.selection = args.selection chain.strategy = args.strategy # # Get luminosity weight # from HNL.Weights.lumiweight import LumiWeight lw = LumiWeight(sample, sample_manager) # # Import and create cutter to provide cut flow # from HNL.EventSelection.cutter import Cutter cutter = Cutter(chain = chain) # # Loop over all events # from HNL.Tools.helpers import progress from HNL.EventSelection.eventSelectionTools import selectGenLeptonsGeneral, passedCustomPtCuts from HNL.EventSelection.signalLeptonMatcher import SignalLeptonMatcher from HNL.ObjectSelection.leptonSelector import isGoodLepton
if args.isTest: max_events = 2000 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) 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 = {
cutter = Cutter(chain = chain) if args.isTest: event_range = xrange(1000) 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