Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-10 22:50:05

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