def fill_histos(dirname, row, weight): mass = frfits.default_scaler(row.e1_e2_Mass) if "charge_weight" in dirname else row.e1_e2_Mass mass_up = frfits.default_scaler_up(row.e1_e2_Mass) if "charge_weight" in dirname else row.e1_e2_Mass mass_dw = frfits.default_scaler_down(row.e1_e2_Mass) if "charge_weight" in dirname else row.e1_e2_Mass histos[dirname]['ePt' ].Fill(row.e1Pt,weight) histos[dirname]['eAbsEta' ].Fill(row.e1AbsEta,weight) histos[dirname]['SCEnergy'].Fill(row.e1SCEnergy,weight) histos[dirname]['ePt' ].Fill(row.e2Pt,weight) histos[dirname]['eAbsEta' ].Fill(row.e2AbsEta,weight) histos[dirname]['SCEnergy'].Fill(row.e2SCEnergy,weight) histos[dirname]['TrkMass' ].Fill(mass, weight) histos[dirname]['TrkMass_low' ].Fill(mass_dw, weight) histos[dirname]['TrkMass_high' ].Fill(mass_up, weight) #histos[dirname]['SCMass' ].Fill(sc_inv_mass(row),weight) histos[dirname]["e1Pt" ].Fill(row.e1Pt,weight) histos[dirname]["e2Pt" ].Fill(row.e2Pt,weight) histos[dirname]["e1AbsEta"].Fill(row.e1AbsEta,weight) histos[dirname]["e2AbsEta"].Fill(row.e2AbsEta,weight) histos[dirname]['TrkMass_NOSCALE'].Fill(row.e1_e2_Mass, weight) histos[dirname]['TrkMass_NoWeight'].Fill(row.e1_e2_Mass) histos[dirname]['type1_pfMetEt'].Fill(row.type1_pfMetEt, weight) histos[dirname]['mva_metEt'].Fill(row.mva_metEt, weight) if row.run < 2: histos[dirname]["trig_weight" ].Fill( self.pucorrector(row.nTruePU) ) histos[dirname]["PU_weight" ].Fill( mcCorrectors.get_electron_corrections(row,'e1','e2') ) histos[dirname]["idIso_weight"].Fill( mcCorrectors.double_electron_trigger(row) )
def anti_charge_flip_100(row): z_Mass_distance = row.e1_e2_Mass - frfits.default_scaler(91.2) \ if row.e1_e2_SS else \ row.e1_e2_Mass - 91.2 z_Mass_distance = abs(z_Mass_distance) if z_Mass_distance <= 10: return False return True
def anti_charge_flip_90(row): z_Mass_distance = row.e1_e2_Mass - frfits.default_scaler(91.2) \ if row.e1_e2_SS else \ row.e1_e2_Mass - 91.2 z_Mass_distance = abs(z_Mass_distance) if row.e1AbsEta < 1.48 and row.e2AbsEta < 1.48: #both barrel return ( ( row.mva_metEt ) > 45 or z_Mass_distance > 10 ) elif row.e1AbsEta < 1.48 or row.e2AbsEta < 1.48: #at least one in barrel return ( ( row.mva_metEt ) > 55 or z_Mass_distance < 25 ) else: #both in endcap return ( ( row.mva_metEt ) > 60 or z_Mass_distance > 30 ) return True
def fill_histos(dirname, row, weight): mass = frfits.default_scaler( row.e1_e2_Mass ) if "charge_weight" in dirname else row.e1_e2_Mass mass_up = frfits.default_scaler_up( row.e1_e2_Mass ) if "charge_weight" in dirname else row.e1_e2_Mass mass_dw = frfits.default_scaler_down( row.e1_e2_Mass ) if "charge_weight" in dirname else row.e1_e2_Mass histos[dirname]['ePt'].Fill(row.e1Pt, weight) histos[dirname]['eAbsEta'].Fill(row.e1AbsEta, weight) histos[dirname]['SCEnergy'].Fill(row.e1SCEnergy, weight) histos[dirname]['ePt'].Fill(row.e2Pt, weight) histos[dirname]['eAbsEta'].Fill(row.e2AbsEta, weight) histos[dirname]['SCEnergy'].Fill(row.e2SCEnergy, weight) histos[dirname]['TrkMass'].Fill(mass, weight) histos[dirname]['TrkMass_low'].Fill(mass_dw, weight) histos[dirname]['TrkMass_high'].Fill(mass_up, weight) #histos[dirname]['SCMass' ].Fill(sc_inv_mass(row),weight) histos[dirname]["e1Pt"].Fill(row.e1Pt, weight) histos[dirname]["e2Pt"].Fill(row.e2Pt, weight) histos[dirname]["e1AbsEta"].Fill(row.e1AbsEta, weight) histos[dirname]["e2AbsEta"].Fill(row.e2AbsEta, weight) histos[dirname]['TrkMass_NOSCALE'].Fill(row.e1_e2_Mass, weight) histos[dirname]['TrkMass_NoWeight'].Fill(row.e1_e2_Mass) histos[dirname]['type1_pfMetEt'].Fill(row.type1_pfMetEt, weight) histos[dirname]['mva_metEt'].Fill(row.mva_metEt, weight) if row.run < 2: histos[dirname]["trig_weight"].Fill( self.pucorrector(row.nTruePU)) histos[dirname]["PU_weight"].Fill( mcCorrectors.get_electron_corrections(row, 'e1', 'e2')) histos[dirname]["idIso_weight"].Fill( mcCorrectors.double_electron_trigger(row))
def f(row, weight): val, w = fcn(row, weight) return frfits.default_scaler(val), w
def f(row, weight): val, w = fcn(row, weight) res = val if row.ePt < row.mPt: res = frfits.default_scaler(val) return res, w
def __init__(self, tree, outfile, **kwargs): self.channel = 'EMT' super(WHAnalyzeEMT, self).__init__(tree, outfile, EMuTauTree, **kwargs) def attr_getter(attribute): def f(row, weight): return (getattr(row,attribute), weight) return f def mass_scaler(fcn): def f(row, weight): val, w = fcn(row, weight) res = val if row.ePt < row.mPt: res = frfits.default_scaler(val) return res, w return f def merge_functions(fcn_1, fcn_2): def f(row, weight): r1, w1 = fcn_1(row, weight) r2, w2 = fcn_2(row, weight) w = w1 if w1 == w2 else None return ((r1, r2), w) return f def sub_mass(row, weight): return (row.e_t_Mass, weight) if row.ePt < row.mPt else (row.m_t_Mass, weight) lead_iso = self.grid_search['']['leading_iso'] sublead_iso = self.grid_search['']['subleading_iso'] #def f_prob(row, weight): # p_m = ( self.obj1_weight(row, lead_iso, sublead_iso) + \ # self.obj1_qcd_weight(row, lead_iso, sublead_iso))/2 # p_e = ( self.obj2_weight(row, lead_iso, sublead_iso) + \ # self.obj2_qcd_weight(row, lead_iso, sublead_iso))/2 # p_t = frfits.tau_fr(row.tPt) # return ((p_m + p_e*(1 - p_m) + p_t*(1 - p_m)*(1 - p_e)), weight) # #def log_prob(row, weight): # prob, weight = f_prob(row, weight) # return math.log(prob), weight #self.hfunc['faking_prob'] = f_prob #self.hfunc['log_prob'] = log_prob #self.hfunc["subMass#faking_prob"] = merge_functions( sub_mass, f_prob ) #self.hfunc["subMass#log_prob" ] = merge_functions( sub_mass, log_prob) self.hfunc["subMass#LT" ] = merge_functions( sub_mass, attr_getter('LT')) self.hfunc["subMass#tPt"] = merge_functions( sub_mass, attr_getter('tPt')) #self.hfunc["subMass*#faking_prob"] = merge_functions( mass_scaler( sub_mass ), f_prob ) #self.hfunc["subMass*#log_prob" ] = merge_functions( mass_scaler( sub_mass ), log_prob) self.hfunc["subMass*#LT" ] = merge_functions( mass_scaler( sub_mass ), attr_getter('LT')) self.hfunc["subMass*#tPt"] = merge_functions( mass_scaler( sub_mass ), attr_getter('tPt')) #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in WHAnalyzerBase.fill_histos later self.hfunc['subMass'] = sub_mass self.hfunc['tLeadDR'] = lambda row, weight: (row.m_t_DR, weight) if row.ePt < row.mPt else (row.e_t_DR, weight) self.hfunc['tSubDR'] = lambda row, weight: (row.e_t_DR, weight) if row.ePt < row.mPt else (row.m_t_DR, weight) self.hfunc["subPt"] = lambda row, weight: (row.ePt, weight) if row.ePt < row.mPt else (row.mPt, weight) self.hfunc["leadPt"] = lambda row, weight: (row.mPt, weight) if row.ePt < row.mPt else (row.ePt, weight) self.hfunc["subJetPt"] = lambda row, weight: (row.eJetPt, weight) if row.ePt < row.mPt else (row.mJetPt, weight) self.hfunc["leadJetPt"] = lambda row, weight: (row.mJetPt, weight) if row.ePt < row.mPt else (row.eJetPt, weight) self.hfunc['pt_ratio' ] = lambda row, weight: (row.ePt/row.mPt, weight) if row.ePt < row.mPt else (row.mPt/row.ePt, weight) self.hfunc["e*_t_Mass"] = lambda row, weight: ( frfits.default_scaler( row.e_t_Mass), weight) self.hfunc["e*_m_Mass"] = lambda row, weight: ( frfits.default_scaler( row.e_m_Mass), weight) self.hfunc["subMass*" ] = mass_scaler( sub_mass ) self.hfunc["_recoilDaught" ] = lambda row, weight: (math.sqrt(row.recoilDaught) , weight) self.hfunc["_recoilWithMet"] = lambda row, weight: (math.sqrt(row.recoilWithMet), weight) self.hfunc['SYNC'] = lambda row, weight: (row, None) #((row.run, row.lumi, row.evt, row.mPt, row.mEta, row.mPhi, row.ePt, row.eEta, row.ePhi, row.tPt, row.tEta, row.tPhi, weight), None ) self.pucorrector = mcCorrectors.make_puCorrector('mueg')
def __init__(self, tree, outfile, **kwargs): self.channel = 'EMT' super(WHAnalyzeEMT, self).__init__(tree, outfile, EMuTauTree, **kwargs) def attr_getter(attribute): def f(row, weight): return (getattr(row, attribute), weight) return f def mass_scaler(fcn): def f(row, weight): val, w = fcn(row, weight) res = val if row.ePt < row.mPt: res = frfits.default_scaler(val) return res, w return f def merge_functions(fcn_1, fcn_2): def f(row, weight): r1, w1 = fcn_1(row, weight) r2, w2 = fcn_2(row, weight) w = w1 if w1 == w2 else None return ((r1, r2), w) return f def sub_mass(row, weight): return (row.e_t_Mass, weight) if row.ePt < row.mPt else (row.m_t_Mass, weight) lead_iso = self.grid_search['']['leading_iso'] sublead_iso = self.grid_search['']['subleading_iso'] #def f_prob(row, weight): # p_m = ( self.obj1_weight(row, lead_iso, sublead_iso) + \ # self.obj1_qcd_weight(row, lead_iso, sublead_iso))/2 # p_e = ( self.obj2_weight(row, lead_iso, sublead_iso) + \ # self.obj2_qcd_weight(row, lead_iso, sublead_iso))/2 # p_t = frfits.tau_fr(row.tPt) # return ((p_m + p_e*(1 - p_m) + p_t*(1 - p_m)*(1 - p_e)), weight) # #def log_prob(row, weight): # prob, weight = f_prob(row, weight) # return math.log(prob), weight #self.hfunc['faking_prob'] = f_prob #self.hfunc['log_prob'] = log_prob #self.hfunc["subMass#faking_prob"] = merge_functions( sub_mass, f_prob ) #self.hfunc["subMass#log_prob" ] = merge_functions( sub_mass, log_prob) self.hfunc["subMass#LT"] = merge_functions(sub_mass, attr_getter('LT')) self.hfunc["subMass#tPt"] = merge_functions(sub_mass, attr_getter('tPt')) #self.hfunc["subMass*#faking_prob"] = merge_functions( mass_scaler( sub_mass ), f_prob ) #self.hfunc["subMass*#log_prob" ] = merge_functions( mass_scaler( sub_mass ), log_prob) self.hfunc["subMass*#LT"] = merge_functions(mass_scaler(sub_mass), attr_getter('LT')) self.hfunc["subMass*#tPt"] = merge_functions(mass_scaler(sub_mass), attr_getter('tPt')) #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in WHAnalyzerBase.fill_histos later self.hfunc['subMass'] = sub_mass self.hfunc['tLeadDR'] = lambda row, weight: ( row.m_t_DR, weight) if row.ePt < row.mPt else (row.e_t_DR, weight) self.hfunc['tSubDR'] = lambda row, weight: ( row.e_t_DR, weight) if row.ePt < row.mPt else (row.m_t_DR, weight) self.hfunc["subPt"] = lambda row, weight: ( row.ePt, weight) if row.ePt < row.mPt else (row.mPt, weight) self.hfunc["leadPt"] = lambda row, weight: ( row.mPt, weight) if row.ePt < row.mPt else (row.ePt, weight) self.hfunc["subJetPt"] = lambda row, weight: ( row.eJetPt, weight) if row.ePt < row.mPt else (row.mJetPt, weight) self.hfunc["leadJetPt"] = lambda row, weight: ( row.mJetPt, weight) if row.ePt < row.mPt else (row.eJetPt, weight) self.hfunc['pt_ratio'] = lambda row, weight: ( row.ePt / row.mPt, weight) if row.ePt < row.mPt else (row.mPt / row .ePt, weight) self.hfunc["e*_t_Mass"] = lambda row, weight: (frfits.default_scaler( row.e_t_Mass), weight) self.hfunc["e*_m_Mass"] = lambda row, weight: (frfits.default_scaler( row.e_m_Mass), weight) self.hfunc["subMass*"] = mass_scaler(sub_mass) self.hfunc["_recoilDaught"] = lambda row, weight: (math.sqrt( row.recoilDaught), weight) self.hfunc["_recoilWithMet"] = lambda row, weight: (math.sqrt( row.recoilWithMet), weight) self.hfunc['SYNC'] = lambda row, weight: ( row, None ) #((row.run, row.lumi, row.evt, row.mPt, row.mEta, row.mPhi, row.ePt, row.eEta, row.ePhi, row.tPt, row.tEta, row.tPhi, weight), None ) self.pucorrector = mcCorrectors.make_puCorrector('mueg')