def nevents_plot(): in_f = ROOT.TFile(gp.fn) out_f = ROOT.TFile('nevents.root', 'recreate') kinds, masses, taus, nmasses, ntaus = axes(in_f) for kind in kinds: h = ROOT.TH2D('nevents_%s' % kind, ';mass (GeV);#tau (mm)', nmasses, masses, ntaus, taus) for ibin in xrange(1, nmasses+1): mass = h.GetXaxis().GetBinLowEdge(ibin) for jbin in xrange(1, ntaus+1): tau = h.GetYaxis().GetBinLowEdge(jbin) try: isample = name2isample(in_f, details2name(kind, tau, mass)) except ValueError: continue nev = nevents(in_f, isample) h.SetBinContent(ibin, jbin, nev) h.SetBinError (ibin, jbin, nev**0.5) out_f.cd() h.Write() out_f.Write() out_f.Close()
def event_scale_factors(): from signal_efficiency import SignalEfficiencyCombiner for which, years in ('2017p8', [2017,2018]), : combiner = SignalEfficiencyCombiner(years) in_f = combiner.inputs[0].f out_f = ROOT.TFile('event_TrackMover_scale_factors_%s.root' % which, 'recreate') kinds, masses, taus, nmasses, ntaus = axes(in_f) taus.remove(30.) ntaus -= 1 for kind in kinds: h = ROOT.TH2D('event_TrackMover_scale_factors_%s' % kind, ';mass (GeV);#tau (mm)', nmasses, masses, ntaus, taus) for ibin in xrange(1, nmasses+1): mass = h.GetXaxis().GetBinLowEdge(ibin) for jbin in xrange(1, ntaus+1): tau = h.GetYaxis().GetBinLowEdge(jbin) pt = kind, tau, mass try: name = details2name(*pt) isample = name2isample(in_f, name) except ValueError as exc: if tau < 100: print colors.warning('problem getting %r : isample %r exc %s' % (pt, isample, exc)) continue # leave holes in the plot to know which samples are missing event_SF = None if which == '2017p8' : vtx_SF_2017 = sig_datamcSF_2017p8(name+"_2017") vtx_SF_2018 = sig_datamcSF_2017p8(name+"_2018") event_SF_2017 = vtx_SF_2017**2 event_SF_2018 = vtx_SF_2018**2 lumi2017 = gp.int_lumis[gp.years.index("2017")] lumi2018 = gp.int_lumis[gp.years.index("2018")] event_SF = (event_SF_2017*lumi2017 + event_SF_2018*lumi2018) / (lumi2017+lumi2018) # for table of SFs, with bins 0.1--0.3\mm & 0.3--1\mm & 1--10\mm & 10--100\mm, # take the ~midpoint of each bin and put its SF in the table (averaged where necessary) if mass == 1600 : if tau == 0.2 or tau == 0.6 or tau == 0.7 or tau == 4 or tau == 7 or tau == 55 : print("for SF table:",name, round(event_SF, 4)) else : sys.exit('event_scale_factors not set up to handle %s! Exiting.' % which) h.SetBinContent(ibin, jbin, event_SF) h.SetBinError (ibin, jbin, 0) # JMTBAD out_f.cd() h.Write() out_f.Write() out_f.Close()
def signal_efficiency(): from signal_efficiency import SignalEfficiencyCombiner for which, years in ('run2', [2016, 2017, 2018]), ('2017p8', [2017, 2018]): combiner = SignalEfficiencyCombiner(years) in_f = combiner.inputs[0].f out_f = ROOT.TFile('signal_efficiency_%s.root' % which, 'recreate') kinds, masses, taus, nmasses, ntaus = axes(in_f) taus.remove(30.) ntaus -= 1 for kind in kinds: h = ROOT.TH2D('signal_efficiency_%s' % kind, ';mass (GeV);#tau (mm)', nmasses, masses, ntaus, taus) for ibin in xrange(1, nmasses + 1): mass = h.GetXaxis().GetBinLowEdge(ibin) for jbin in xrange(1, ntaus + 1): tau = h.GetYaxis().GetBinLowEdge(jbin) pt = kind, tau, mass isample, r = None, None try: isample = name2isample(in_f, details2name(*pt)) r = combiner.combine(isample) except ValueError as exc: if tau < 100: print colors.warning( 'problem getting %r : isample %r exc %s' % (pt, isample, exc)) continue # leave holes in the plot to know which samples are missing h.SetBinContent(ibin, jbin, r.total_sig_eff) h.SetBinError(ibin, jbin, 0) # JMTBAD out_f.cd() h.Write() out_f.Write() out_f.Close()