Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:38

0001 from builtins import range
0002 import ROOT, os, math, sys
0003 import numpy as num
0004 from DataFormats.FWLite import Events, Handle
0005 from .DeltaR import *
0006 
0007 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
0008 from PhysicsTools.Heppy.physicsobjects.Muon import Muon
0009 from PhysicsTools.Heppy.physicsobjects.Electron import Electron
0010 from PhysicsTools.Heppy.physicsobjects.Tau import Tau
0011 from PhysicsTools.Heppy.physicsutils.TauDecayModes import tauDecayModes
0012 
0013 
0014 ROOT.gROOT.SetBatch(True)
0015 
0016 #RelVal = '7_6_0_pre7'
0017 #RelVal = '7_6_0'
0018 #RelVal = '7_6_1'
0019 #RelVal = '7_6_1_v2'
0020 RelVal = '7_6_1_v3'
0021 
0022 tag = 'v11'
0023 if RelVal=='7_6_0_pre7':
0024     tag = 'v5'
0025 
0026 tauH = Handle('vector<pat::Tau>')
0027 vertexH = Handle('std::vector<reco::Vertex>')
0028 genParticlesH  = Handle ('std::vector<reco::GenParticle>')
0029 jetH = Handle('vector<pat::Jet>')
0030 
0031 filelist = []
0032 argvs = sys.argv
0033 argc = len(argvs)
0034 
0035 if argc != 2:
0036     print('Please specify the runtype : python3 runTauDisplay.py <ZTT, ZEE, ZMM, QCD>')
0037     sys.exit(0)
0038 
0039 runtype = argvs[1]
0040 
0041 print('You selected', runtype)
0042 
0043 
0044 
0045 #def isFinal(p):
0046 #    return not (p.numberOfDaughters() == 1 and p.daughter(0).pdgId() == p.pdgId())
0047 
0048 
0049 def returnRough(dm):
0050     if dm in [0]:
0051         return 0
0052     elif dm in [1,2]:
0053         return 1
0054     elif dm in [5,6]:
0055         return 2
0056     elif dm in [10]:
0057         return 3
0058     elif dm in [11]:
0059         return 4
0060     else:
0061         return -1
0062 
0063 
0064 def finalDaughters(gen, daughters=None):
0065     if daughters is None:
0066         daughters = []
0067     for i in range(gen.numberOfDaughters()):
0068         daughter = gen.daughter(i)
0069         if daughter.numberOfDaughters() == 0:
0070             daughters.append(daughter)
0071         else:
0072             finalDaughters(daughter, daughters)
0073 
0074     return daughters
0075 
0076 
0077 def visibleP4(gen):
0078     final_ds = finalDaughters(gen)
0079 
0080     p4 = sum((d.p4() for d in final_ds if abs(d.pdgId()) not in [12, 14, 16]), ROOT.math.XYZTLorentzVectorD())
0081 
0082     return p4
0083 
0084 
0085 
0086 
0087 
0088 for ii in range(1, 4):
0089 
0090     if runtype == 'ZEE' and RelVal.find('7_6_1')!=-1: pass
0091     else:
0092         if ii==3 : continue
0093 
0094     filename = ''
0095     
0096     if runtype == 'ZTT':
0097         filename = 'root://eoscms//eos/cms/store/cmst3/user/ytakahas/TauPOG/ZTT_CMSSW_' + RelVal + '_RelValZTT_13_MINIAODSIM_76X_mcRun2_asymptotic_' + tag + '-v1_' + str(ii) + '.root'
0098     elif runtype == 'ZEE':
0099         filename = 'root://eoscms//eos/cms/store/cmst3/user/ytakahas/TauPOG/ZEE_CMSSW_' + RelVal + '_RelValZEE_13_MINIAODSIM_76X_mcRun2_asymptotic_' + tag + '-v1_' + str(ii) + '.root'
0100     elif runtype == 'ZMM':
0101         filename = 'root://eoscms//eos/cms/store/cmst3/user/ytakahas/TauPOG/ZMM_CMSSW_' + RelVal + '_RelValZMM_13_MINIAODSIM_76X_mcRun2_asymptotic_' + tag + '-v1_' + str(ii) + '.root'
0102     elif runtype == 'QCD':
0103         filename = 'root://eoscms//eos/cms/store/cmst3/user/ytakahas/TauPOG/QCD_CMSSW_' + RelVal + '_QCD_FlatPt_15_3000HS_13_MINIAODSIM_76X_mcRun2_asymptotic_v11-v1_' + str(ii) + '.root'
0104 
0105     print(filename)
0106     filelist.append(filename)
0107 
0108 events = Events(filelist)
0109 print(len(filelist), 'files will be analyzed')
0110 
0111 
0112 outputname = 'Myroot_' + RelVal + '_' + runtype + '.root'
0113 file = ROOT.TFile(outputname, 'recreate')
0114 
0115 h_ngen = ROOT.TH1F("h_ngen", "h_ngen",10,0,10)
0116 
0117 tau_tree = ROOT.TTree('per_tau','per_tau')
0118 
0119 tau_eventid = num.zeros(1, dtype=int)
0120 tau_id = num.zeros(1, dtype=int)
0121 tau_dm = num.zeros(1, dtype=int)
0122 tau_dm_rough = num.zeros(1, dtype=int)
0123 tau_pt = num.zeros(1, dtype=float)
0124 tau_eta = num.zeros(1, dtype=float)
0125 tau_phi = num.zeros(1, dtype=float)
0126 tau_mass = num.zeros(1, dtype=float)
0127 tau_gendm = num.zeros(1, dtype=int)
0128 tau_gendm_rough = num.zeros(1, dtype=int)
0129 tau_genpt = num.zeros(1, dtype=float)
0130 tau_geneta = num.zeros(1, dtype=float)
0131 tau_genphi = num.zeros(1, dtype=float)
0132 tau_vertex = num.zeros(1, dtype=int)
0133 
0134 tau_againstMuonLoose3 = num.zeros(1, dtype=int)
0135 tau_againstMuonTight3 = num.zeros(1, dtype=int)
0136 
0137 tau_againstElectronVLooseMVA5  = num.zeros(1, dtype=int)
0138 tau_againstElectronLooseMVA5 = num.zeros(1, dtype=int)
0139 tau_againstElectronMediumMVA5 = num.zeros(1, dtype=int)
0140 tau_againstElectronTightMVA5 = num.zeros(1, dtype=int)
0141 tau_againstElectronVTightMVA5 = num.zeros(1, dtype=int)
0142 tau_againstElectronMVA5raw = num.zeros(1, dtype=float)
0143 tau_byIsolationMVA3oldDMwLTraw = num.zeros(1, dtype=float)
0144 tau_byLooseIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
0145 tau_byMediumIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
0146 tau_byTightIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
0147 tau_byVLooseIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
0148 tau_byVTightIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
0149 tau_byVVTightIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
0150 
0151 
0152 tau_byCombinedIsolationDeltaBetaCorrRaw3Hits = num.zeros(1, dtype=float)
0153 tau_byLooseCombinedIsolationDeltaBetaCorr3Hits = num.zeros(1, dtype=int)
0154 tau_byMediumCombinedIsolationDeltaBetaCorr3Hits = num.zeros(1, dtype=int)
0155 tau_byTightCombinedIsolationDeltaBetaCorr3Hits = num.zeros(1, dtype=int)
0156 tau_chargedIsoPtSum = num.zeros(1, dtype=float)
0157 tau_neutralIsoPtSum = num.zeros(1, dtype=float)
0158 tau_puCorrPtSum = num.zeros(1, dtype=float)
0159 tau_byLoosePileupWeightedIsolation3Hits = num.zeros(1, dtype=int)
0160 tau_byMediumPileupWeightedIsolation3Hits = num.zeros(1, dtype=int)
0161 tau_byTightPileupWeightedIsolation3Hits = num.zeros(1, dtype=int)
0162 tau_byPileupWeightedIsolationRaw3Hits = num.zeros(1, dtype=float)
0163 tau_neutralIsoPtSumWeight = num.zeros(1, dtype=float)
0164 tau_footprintCorrection = num.zeros(1, dtype=float)
0165 tau_photonPtSumOutsideSignalCone = num.zeros(1, dtype=float)
0166 tau_decayModeFindingOldDMs = num.zeros(1, dtype=int)
0167 tau_decayModeFindingNewDMs = num.zeros(1, dtype=int)
0168 
0169 
0170 tau_againstElectronVLooseMVA6  = num.zeros(1, dtype=int)
0171 tau_againstElectronLooseMVA6 = num.zeros(1, dtype=int)
0172 tau_againstElectronMediumMVA6 = num.zeros(1, dtype=int)
0173 tau_againstElectronTightMVA6 = num.zeros(1, dtype=int)
0174 tau_againstElectronVTightMVA6 = num.zeros(1, dtype=int)
0175 tau_againstElectronMVA6raw = num.zeros(1, dtype=float)
0176 
0177 #'byIsolationMVArun2v1DBdR03oldDMwLTraw' 
0178 tau_byIsolationMVArun2v1DBoldDMwLTraw = num.zeros(1, dtype=float)
0179 tau_byVLooseIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
0180 tau_byLooseIsolationMVArun2v1DBoldDMwLT  = num.zeros(1, dtype=int)
0181 tau_byMediumIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
0182 tau_byTightIsolationMVArun2v1DBoldDMwLT  = num.zeros(1, dtype=int)
0183 tau_byVTightIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
0184 tau_byVVTightIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
0185 
0186 #byIsolationMVArun2v1PWdR03oldDMwLTraw'
0187 #'byLooseCombinedIsolationDeltaBetaCorr3HitsdR03'  
0188 #'byLooseIsolationMVArun2v1DBdR03oldDMwLT' 
0189 #'byLooseIsolationMVArun2v1PWdR03oldDMwLT' 
0190 #'byMediumCombinedIsolationDeltaBetaCorr3HitsdR03' 
0191 #'byMediumIsolationMVArun2v1DBdR03oldDMwLT' 
0192 #'byMediumIsolationMVArun2v1PWdR03oldDMwLT' 
0193 #'byTightCombinedIsolationDeltaBetaCorr3HitsdR03' 
0194 #'byTightIsolationMVArun2v1DBdR03oldDMwLT' 
0195 #'byTightIsolationMVArun2v1PWdR03oldDMwLT' 
0196 tau_byIsolationMVArun2v1PWoldDMwLTraw = num.zeros(1, dtype=float)
0197 tau_byLooseIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
0198 tau_byMediumIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
0199 tau_byTightIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
0200 tau_byVLooseIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
0201 tau_byVTightIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
0202 tau_byVVTightIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
0203 
0204 #'byVLooseIsolationMVArun2v1DBdR03oldDMwLT' 
0205 #'byVLooseIsolationMVArun2v1PWdR03oldDMwLT' 
0206 #'byVTightIsolationMVArun2v1DBdR03oldDMwLT' 
0207 #'byVTightIsolationMVArun2v1PWdR03oldDMwLT' 
0208 #'byVVTightIsolationMVArun2v1DBdR03oldDMwLT' 
0209 #'byVVTightIsolationMVArun2v1PWdR03oldDMwLT' 
0210 
0211 
0212 
0213 tau_tree.Branch('tau_id', tau_id, 'tau_id/I')
0214 tau_tree.Branch('tau_vertex', tau_vertex, 'tau_vertex/I')
0215 tau_tree.Branch('tau_eventid', tau_eventid, 'tau_eventid/I')
0216 tau_tree.Branch('tau_dm', tau_dm, 'tau_dm/I')
0217 tau_tree.Branch('tau_dm_rough', tau_dm_rough, 'tau_dm_rough/I')
0218 tau_tree.Branch('tau_pt', tau_pt, 'tau_pt/D')
0219 tau_tree.Branch('tau_eta', tau_eta, 'tau_eta/D')
0220 tau_tree.Branch('tau_phi', tau_phi, 'tau_phi/D')
0221 tau_tree.Branch('tau_mass', tau_mass, 'tau_mass/D')
0222 tau_tree.Branch('tau_gendm', tau_gendm, 'tau_gendm/I')
0223 tau_tree.Branch('tau_gendm_rough', tau_gendm_rough, 'tau_gendm_rough/I')
0224 tau_tree.Branch('tau_genpt', tau_genpt, 'tau_genpt/D')
0225 tau_tree.Branch('tau_geneta', tau_geneta, 'tau_geneta/D')
0226 tau_tree.Branch('tau_genphi', tau_genphi, 'tau_genphi/D')
0227 
0228 tau_tree.Branch('tau_againstMuonLoose3', tau_againstMuonLoose3, 'tau_againstMuonLoose3/I')
0229 tau_tree.Branch('tau_againstMuonTight3', tau_againstMuonTight3, 'tau_againstMuonTight3/I')
0230 
0231 tau_tree.Branch('tau_againstElectronVLooseMVA5', tau_againstElectronVLooseMVA5, 'tau_againstElectronVLooseMVA5/I')
0232 tau_tree.Branch('tau_againstElectronLooseMVA5', tau_againstElectronLooseMVA5, 'tau_againstElectronLooseMVA5/I')
0233 tau_tree.Branch('tau_againstElectronMediumMVA5', tau_againstElectronMediumMVA5, 'tau_againstElectronMediumMVA5/I')
0234 tau_tree.Branch('tau_againstElectronTightMVA5', tau_againstElectronTightMVA5, 'tau_againstElectronTightMVA5/I')
0235 tau_tree.Branch('tau_againstElectronVTightMVA5', tau_againstElectronVTightMVA5, 'tau_againstElectronVTightMVA5/I')
0236 tau_tree.Branch('tau_againstElectronMVA5raw', tau_againstElectronMVA5raw, 'tau_againstElectronMVA5raw/D')
0237 
0238 tau_tree.Branch('tau_againstElectronVLooseMVA6', tau_againstElectronVLooseMVA6, 'tau_againstElectronVLooseMVA6/I')
0239 tau_tree.Branch('tau_againstElectronLooseMVA6', tau_againstElectronLooseMVA6, 'tau_againstElectronLooseMVA6/I')
0240 tau_tree.Branch('tau_againstElectronMediumMVA6', tau_againstElectronMediumMVA6, 'tau_againstElectronMediumMVA6/I')
0241 tau_tree.Branch('tau_againstElectronTightMVA6', tau_againstElectronTightMVA6, 'tau_againstElectronTightMVA6/I')
0242 tau_tree.Branch('tau_againstElectronVTightMVA6', tau_againstElectronVTightMVA6, 'tau_againstElectronVTightMVA6/I')
0243 tau_tree.Branch('tau_againstElectronMVA6raw', tau_againstElectronMVA6raw, 'tau_againstElectronMVA6raw/D')
0244 
0245 
0246 tau_tree.Branch('tau_byCombinedIsolationDeltaBetaCorrRaw3Hits', tau_byCombinedIsolationDeltaBetaCorrRaw3Hits, 'tau_byCombinedIsolationDeltaBetaCorrRaw3Hits/D')
0247 tau_tree.Branch('tau_byLooseCombinedIsolationDeltaBetaCorr3Hits', tau_byLooseCombinedIsolationDeltaBetaCorr3Hits, 'tau_byLooseCombinedIsolationDeltaBetaCorr3Hits/I')
0248 tau_tree.Branch('tau_byMediumCombinedIsolationDeltaBetaCorr3Hits', tau_byMediumCombinedIsolationDeltaBetaCorr3Hits, 'tau_byMediumCombinedIsolationDeltaBetaCorr3Hits/I')
0249 tau_tree.Branch('tau_byTightCombinedIsolationDeltaBetaCorr3Hits', tau_byTightCombinedIsolationDeltaBetaCorr3Hits, 'tau_byTightCombinedIsolationDeltaBetaCorr3Hits/I')
0250 tau_tree.Branch('tau_chargedIsoPtSum', tau_chargedIsoPtSum, 'tau_chargedIsoPtSum/D')
0251 tau_tree.Branch('tau_neutralIsoPtSum', tau_neutralIsoPtSum, 'tau_neutralIsoPtSum/D')
0252 tau_tree.Branch('tau_puCorrPtSum', tau_puCorrPtSum, 'tau_puCorrPtSum/D')
0253 tau_tree.Branch('tau_byLoosePileupWeightedIsolation3Hits', tau_byLoosePileupWeightedIsolation3Hits, 'tau_byLoosePileupWeightedIsolation3Hits/I')
0254 tau_tree.Branch('tau_byMediumPileupWeightedIsolation3Hits', tau_byMediumPileupWeightedIsolation3Hits, 'tau_byMediumPileupWeightedIsolation3Hits/I')
0255 tau_tree.Branch('tau_byTightPileupWeightedIsolation3Hits', tau_byTightPileupWeightedIsolation3Hits, 'tau_byTightPileupWeightedIsolation3Hits/I')
0256 tau_tree.Branch('tau_byPileupWeightedIsolationRaw3Hits', tau_byPileupWeightedIsolationRaw3Hits, 'tau_byPileupWeightedIsolationRaw3Hits/D')
0257 tau_tree.Branch('tau_neutralIsoPtSumWeight', tau_neutralIsoPtSumWeight, 'tau_neutralIsoPtSumWeight/D')
0258 tau_tree.Branch('tau_footprintCorrection', tau_footprintCorrection, 'tau_footprintCorrection/D')
0259 tau_tree.Branch('tau_photonPtSumOutsideSignalCone', tau_photonPtSumOutsideSignalCone, 'tau_photonPtSumOutsideSignalCone/D')
0260 tau_tree.Branch('tau_decayModeFindingOldDMs', tau_decayModeFindingOldDMs, 'tau_decayModeFindingOldDMs/I')
0261 tau_tree.Branch('tau_decayModeFindingNewDMs', tau_decayModeFindingNewDMs, 'tau_decayModeFindingNewDMs/I')
0262 
0263 tau_tree.Branch('tau_byIsolationMVA3oldDMwLTraw', tau_byIsolationMVA3oldDMwLTraw, 'tau_byIsolationMVA3oldDMwLTraw/D')
0264 tau_tree.Branch('tau_byLooseIsolationMVA3oldDMwLT', tau_byLooseIsolationMVA3oldDMwLT, 'tau_byLooseIsolationMVA3oldDMwLT/I')
0265 tau_tree.Branch('tau_byMediumIsolationMVA3oldDMwLT', tau_byMediumIsolationMVA3oldDMwLT, 'tau_byMediumIsolationMVA3oldDMwLT/I')
0266 tau_tree.Branch('tau_byTightIsolationMVA3oldDMwLT', tau_byTightIsolationMVA3oldDMwLT, 'tau_byTightIsolationMVA3oldDMwLT/I')
0267 tau_tree.Branch('tau_byVLooseIsolationMVA3oldDMwLT', tau_byVLooseIsolationMVA3oldDMwLT, 'tau_byVLooseIsolationMVA3oldDMwLT/I')
0268 tau_tree.Branch('tau_byVTightIsolationMVA3oldDMwLT', tau_byVTightIsolationMVA3oldDMwLT, 'tau_byVTightIsolationMVA3oldDMwLT/I')
0269 tau_tree.Branch('tau_byVVTightIsolationMVA3oldDMwLT', tau_byVVTightIsolationMVA3oldDMwLT, 'tau_byVVTightIsolationMVA3oldDMwLT/I')
0270 
0271 
0272 tau_tree.Branch('tau_byIsolationMVArun2v1DBoldDMwLTraw', tau_byIsolationMVArun2v1DBoldDMwLTraw, 'tau_byIsolationMVArun2v1DBoldDMwLTraw/D')
0273 tau_tree.Branch('tau_byLooseIsolationMVArun2v1DBoldDMwLT', tau_byLooseIsolationMVArun2v1DBoldDMwLT, 'tau_byLooseIsolationMVArun2v1DBoldDMwLT/I')
0274 tau_tree.Branch('tau_byMediumIsolationMVArun2v1DBoldDMwLT', tau_byMediumIsolationMVArun2v1DBoldDMwLT, 'tau_byMediumIsolationMVArun2v1DBoldDMwLT/I')
0275 tau_tree.Branch('tau_byTightIsolationMVArun2v1DBoldDMwLT', tau_byTightIsolationMVArun2v1DBoldDMwLT, 'tau_byTightIsolationMVArun2v1DBoldDMwLT/I')
0276 tau_tree.Branch('tau_byVLooseIsolationMVArun2v1DBoldDMwLT', tau_byVLooseIsolationMVArun2v1DBoldDMwLT, 'tau_byVLooseIsolationMVArun2v1DBoldDMwLT/I')
0277 tau_tree.Branch('tau_byVTightIsolationMVArun2v1DBoldDMwLT', tau_byVTightIsolationMVArun2v1DBoldDMwLT, 'tau_byVTightIsolationMVArun2v1DBoldDMwLT/I')
0278 tau_tree.Branch('tau_byVVTightIsolationMVArun2v1DBoldDMwLT', tau_byVVTightIsolationMVArun2v1DBoldDMwLT, 'tau_byVVTightIsolationMVArun2v1DBoldDMwLT/I')
0279 
0280 tau_tree.Branch('tau_byIsolationMVArun2v1PWoldDMwLTraw', tau_byIsolationMVArun2v1PWoldDMwLTraw, 'tau_byIsolationMVArun2v1PWoldDMwLTraw/D')
0281 tau_tree.Branch('tau_byLooseIsolationMVArun2v1PWoldDMwLT', tau_byLooseIsolationMVArun2v1PWoldDMwLT, 'tau_byLooseIsolationMVArun2v1PWoldDMwLT/I')
0282 tau_tree.Branch('tau_byMediumIsolationMVArun2v1PWoldDMwLT', tau_byMediumIsolationMVArun2v1PWoldDMwLT, 'tau_byMediumIsolationMVArun2v1PWoldDMwLT/I')
0283 tau_tree.Branch('tau_byTightIsolationMVArun2v1PWoldDMwLT', tau_byTightIsolationMVArun2v1PWoldDMwLT, 'tau_byTightIsolationMVArun2v1PWoldDMwLT/I')
0284 tau_tree.Branch('tau_byVLooseIsolationMVArun2v1PWoldDMwLT', tau_byVLooseIsolationMVArun2v1PWoldDMwLT, 'tau_byVLooseIsolationMVArun2v1PWoldDMwLT/I')
0285 tau_tree.Branch('tau_byVTightIsolationMVArun2v1PWoldDMwLT', tau_byVTightIsolationMVArun2v1PWoldDMwLT, 'tau_byVTightIsolationMVArun2v1PWoldDMwLT/I')
0286 tau_tree.Branch('tau_byVVTightIsolationMVArun2v1PWoldDMwLT', tau_byVVTightIsolationMVArun2v1PWoldDMwLT, 'tau_byVVTightIsolationMVArun2v1PWoldDMwLT/I')
0287 
0288 
0289 
0290 
0291 evtid = 0
0292 
0293 for event in events:
0294     
0295     evtid += 1  
0296     eid = event.eventAuxiliary().id().event()
0297     
0298     if evtid%1000 == 0:
0299         print('Event ', evtid, 'processed')
0300 
0301     event.getByLabel("slimmedTaus", tauH)
0302     event.getByLabel("offlineSlimmedPrimaryVertices", vertexH)
0303     event.getByLabel('prunedGenParticles',genParticlesH)
0304     event.getByLabel("slimmedJets", jetH)
0305 
0306     taus = tauH.product()
0307     vertices = vertexH.product()
0308     genParticles = genParticlesH.product()
0309     jets = [jet for jet in jetH.product() if jet.pt() > 20 and abs(jet.eta()) < 2.3]
0310 
0311     genTaus = [p for p in genParticles if abs(p.pdgId()) == 15 and p.status()==2]
0312     genElectrons = [p for p in genParticles if abs(p.pdgId()) == 11 and p.status()==1 and p.pt() > 20 and abs(p.eta())<2.3]
0313     genMuons = [p for p in genParticles if abs(p.pdgId()) == 13 and p.status()==1 and p.pt() > 20 and abs(p.eta())<2.3]
0314 
0315     for tau in taus:
0316 
0317         _genparticle_ = []
0318 
0319         for igen in genTaus:
0320                         
0321             visP4 = visibleP4(igen)
0322 
0323             gen_dm = tauDecayModes.genDecayModeInt([d for d in finalDaughters(igen) if abs(d.pdgId()) not in [12, 14, 16]])
0324 
0325             igen.decaymode = gen_dm
0326             igen.vis = visP4
0327             
0328             if abs(visP4.eta()) > 2.3: continue
0329             if visP4.pt() < 20: continue
0330 
0331             dr = deltaR(tau.eta(), tau.phi(), visP4.eta(), visP4.phi())
0332 
0333             if dr < 0.5:
0334                 _genparticle_.append(igen)
0335 
0336 
0337 
0338         if runtype=='ZTT':
0339             h_ngen.Fill(len(genTaus))
0340             if len(_genparticle_) != 1: continue
0341 
0342         bmjet, _dr_ = bestMatch(tau, jets)
0343         if runtype=='QCD':
0344             h_ngen.Fill(len(jets))
0345             if bmjet == None: continue
0346 
0347         bme, _dr_ = bestMatch(tau, genElectrons)
0348         if runtype=='ZEE':
0349             h_ngen.Fill(len(genElectrons))
0350             if bme == None: continue
0351 
0352         bmm, _dr_ = bestMatch(tau, genMuons)
0353         if runtype=='ZMM':
0354             h_ngen.Fill(len(genMuons))
0355             if bmm == None: continue
0356 
0357 
0358         tau_id[0] = evtid
0359         tau_eventid[0] = eid
0360         tau_dm[0] = tau.decayMode()
0361         tau_dm_rough[0] = returnRough(tau.decayMode())
0362         tau_pt[0] = tau.pt()
0363         tau_eta[0] = tau.eta()
0364         tau_phi[0] = tau.phi()
0365         tau_mass[0] = tau.mass()
0366         tau_vertex[0] = len(vertices)
0367 
0368         tau_againstMuonLoose3[0] = tau.tauID('againstMuonLoose3')
0369         tau_againstMuonTight3[0] = tau.tauID('againstMuonTight3')
0370 
0371         tau_againstElectronVLooseMVA5[0] = tau.tauID('againstElectronVLooseMVA5')
0372         tau_againstElectronLooseMVA5[0] = tau.tauID('againstElectronLooseMVA5')
0373         tau_againstElectronMediumMVA5[0] = tau.tauID('againstElectronMediumMVA5')
0374         tau_againstElectronTightMVA5[0] = tau.tauID('againstElectronTightMVA5')
0375         tau_againstElectronVTightMVA5[0] = tau.tauID('againstElectronVTightMVA5')
0376         tau_againstElectronMVA5raw[0] = tau.tauID('againstElectronMVA5raw')
0377 
0378         tau_byCombinedIsolationDeltaBetaCorrRaw3Hits[0] = tau.tauID('byCombinedIsolationDeltaBetaCorrRaw3Hits')
0379         tau_byLooseCombinedIsolationDeltaBetaCorr3Hits[0] = tau.tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits')
0380         tau_byMediumCombinedIsolationDeltaBetaCorr3Hits[0] = tau.tauID('byMediumCombinedIsolationDeltaBetaCorr3Hits')
0381         tau_byTightCombinedIsolationDeltaBetaCorr3Hits[0] = tau.tauID('byTightCombinedIsolationDeltaBetaCorr3Hits')
0382         tau_chargedIsoPtSum[0] = tau.tauID('chargedIsoPtSum')
0383         tau_neutralIsoPtSum[0] = tau.tauID('neutralIsoPtSum')
0384         tau_puCorrPtSum[0] = tau.tauID('puCorrPtSum')
0385         tau_byLoosePileupWeightedIsolation3Hits[0] = tau.tauID('byLoosePileupWeightedIsolation3Hits')
0386         tau_byMediumPileupWeightedIsolation3Hits[0] = tau.tauID('byMediumPileupWeightedIsolation3Hits')
0387         tau_byTightPileupWeightedIsolation3Hits[0] = tau.tauID('byTightPileupWeightedIsolation3Hits')
0388         tau_byPileupWeightedIsolationRaw3Hits[0] = tau.tauID('byPileupWeightedIsolationRaw3Hits')
0389         tau_neutralIsoPtSumWeight[0] = tau.tauID('neutralIsoPtSumWeight')
0390         tau_footprintCorrection[0] = tau.tauID('footprintCorrection')
0391         tau_photonPtSumOutsideSignalCone[0] = tau.tauID('photonPtSumOutsideSignalCone')
0392         tau_decayModeFindingOldDMs[0] = tau.tauID('decayModeFinding')
0393         tau_decayModeFindingNewDMs[0] = tau.tauID('decayModeFindingNewDMs')
0394 
0395         tau_byIsolationMVA3oldDMwLTraw[0] = tau.tauID('byIsolationMVA3oldDMwLTraw')
0396         tau_byLooseIsolationMVA3oldDMwLT[0] = tau.tauID('byLooseIsolationMVA3oldDMwLT')
0397         tau_byMediumIsolationMVA3oldDMwLT[0] = tau.tauID('byMediumIsolationMVA3oldDMwLT')
0398         tau_byTightIsolationMVA3oldDMwLT[0] = tau.tauID('byTightIsolationMVA3oldDMwLT')
0399         tau_byVLooseIsolationMVA3oldDMwLT[0] = tau.tauID('byVLooseIsolationMVA3oldDMwLT')
0400         tau_byVTightIsolationMVA3oldDMwLT[0] = tau.tauID('byVTightIsolationMVA3oldDMwLT')
0401         tau_byVVTightIsolationMVA3oldDMwLT[0] = tau.tauID('byVVTightIsolationMVA3oldDMwLT')
0402 
0403         if RelVal.find('7_6_1')!=-1:
0404             tau_againstElectronVLooseMVA6[0] = tau.tauID('againstElectronVLooseMVA6')
0405             tau_againstElectronLooseMVA6[0] = tau.tauID('againstElectronLooseMVA6')
0406             tau_againstElectronMediumMVA6[0] = tau.tauID('againstElectronMediumMVA6')
0407             tau_againstElectronTightMVA6[0] = tau.tauID('againstElectronTightMVA6')
0408             tau_againstElectronVTightMVA6[0] = tau.tauID('againstElectronVTightMVA6')
0409             tau_againstElectronMVA6raw[0] = tau.tauID('againstElectronMVA6raw')
0410 
0411             tau_byIsolationMVArun2v1DBoldDMwLTraw[0] = tau.tauID('byIsolationMVArun2v1DBoldDMwLTraw')
0412             tau_byLooseIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byLooseIsolationMVArun2v1DBoldDMwLT')
0413             tau_byMediumIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byMediumIsolationMVArun2v1DBoldDMwLT')
0414             tau_byTightIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byTightIsolationMVArun2v1DBoldDMwLT')
0415             tau_byVLooseIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byVLooseIsolationMVArun2v1DBoldDMwLT')
0416             tau_byVTightIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byVTightIsolationMVArun2v1DBoldDMwLT')
0417             tau_byVVTightIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byVVTightIsolationMVArun2v1DBoldDMwLT')
0418 
0419             tau_byIsolationMVArun2v1PWoldDMwLTraw[0] = tau.tauID('byIsolationMVArun2v1PWoldDMwLTraw')
0420             tau_byLooseIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byLooseIsolationMVArun2v1PWoldDMwLT')
0421             tau_byMediumIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byMediumIsolationMVArun2v1PWoldDMwLT')
0422             tau_byTightIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byTightIsolationMVArun2v1PWoldDMwLT')
0423             tau_byVLooseIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byVLooseIsolationMVArun2v1PWoldDMwLT')
0424             tau_byVTightIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byVTightIsolationMVArun2v1PWoldDMwLT')
0425             tau_byVVTightIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byVVTightIsolationMVArun2v1PWoldDMwLT')
0426 
0427 
0428         if runtype == 'ZTT':
0429             gp = _genparticle_[0]
0430             tau_gendm[0] = gp.decaymode
0431             tau_gendm_rough[0] = returnRough(gp.decaymode)
0432             tau_genpt[0] = gp.vis.pt()
0433             tau_geneta[0] = gp.vis.eta()
0434             tau_genphi[0] = gp.vis.phi()
0435         elif runtype == 'QCD':
0436             tau_gendm[0] = -1
0437             tau_genpt[0] = bmjet.pt()
0438             tau_geneta[0] = bmjet.eta()
0439             tau_genphi[0] = bmjet.phi()
0440         elif runtype == 'ZEE':
0441             tau_gendm[0] = -1
0442             tau_genpt[0] = bme.pt()
0443             tau_geneta[0] = bme.eta()
0444             tau_genphi[0] = bme.phi()
0445         elif runtype == 'ZMM':
0446             tau_gendm[0] = -1
0447             tau_genpt[0] = bmm.pt()
0448             tau_geneta[0] = bmm.eta()
0449             tau_genphi[0] = bmm.phi()
0450 
0451         tau_tree.Fill()
0452 
0453 
0454 
0455 print(evtid, 'events are processed !')
0456 
0457 file.Write()
0458 file.Close()
0459