Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:27

0001 from builtins import range
0002 import operator 
0003 import itertools
0004 import copy
0005 from math import *
0006 
0007 from ROOT import std 
0008 from ROOT import TLorentzVector, TVectorD
0009 
0010 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
0011 from PhysicsTools.HeppyCore.framework.event import Event
0012 from PhysicsTools.HeppyCore.statistics.counter import Counter, Counters
0013 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
0014 
0015 import PhysicsTools.HeppyCore.framework.config as cfg
0016 
0017 from PhysicsTools.HeppyCore.utils.deltar import deltaR
0018 
0019 from ROOT.heppy import Hemisphere
0020 from ROOT.heppy import ReclusterJets
0021 
0022 from ROOT.heppy import Davismt2
0023 davismt2 = Davismt2()
0024 
0025 from ROOT.heppy import mt2w_bisect 
0026 mt2wSNT = mt2w_bisect.mt2w()
0027 
0028 import ROOT
0029 
0030 import os
0031 
0032 
0033 class MT2Analyzer( Analyzer ):
0034     def __init__(self, cfg_ana, cfg_comp, looperName ):
0035         super(MT2Analyzer,self).__init__(cfg_ana,cfg_comp,looperName) 
0036         self.jetPt = cfg_ana.jetPt
0037 
0038     def declareHandles(self):
0039         super(MT2Analyzer, self).declareHandles()
0040        #genJets                                                                                                                                                                     
0041         self.handles['genJets'] = AutoHandle( 'slimmedGenJets','std::vector<reco::GenJet>')
0042         self.handles['met'] = AutoHandle( self.cfg_ana.metCollection, 'std::vector<pat::MET>' )
0043 
0044     def beginLoop(self, setup):
0045         super(MT2Analyzer,self).beginLoop(setup)
0046         self.counters.addCounter('pairs')
0047         count = self.counters.counter('pairs')
0048         count.register('all events')
0049 
0050     def computeMT2(self, visaVec, visbVec, metVec):
0051         
0052         import array
0053         import numpy
0054 
0055         metVector = array.array('d',[0.,metVec.px(), metVec.py()])
0056         visaVector = array.array('d',[0.,visaVec.px(), visaVec.py()])
0057         visbVector = array.array('d',[0.,visbVec.px(), visbVec.py()])
0058 
0059         davismt2.set_momenta(visaVector,visbVector,metVector);
0060         davismt2.set_mn(0);
0061 
0062         return davismt2.get_mt2()
0063 
0064     def getMT2AKT(self, event, TMPobjects40jc, met , collectionPostFix, postFix):
0065 
0066 #### get hemispheres via AntiKT -1 antikt, 1 kt, 0 CA
0067         if len(TMPobjects40jc)>=2:
0068 
0069             objects  = ROOT.std.vector(ROOT.reco.Particle.LorentzVector)()
0070             for jet in TMPobjects40jc:
0071                 objects.push_back(jet.p4())
0072 
0073             hemisphereViaKt = ReclusterJets(objects, 1.,50.0)
0074             groupingViaKt=hemisphereViaKt.getGroupingExclusive(2)
0075 
0076             if len(groupingViaKt)>=2:
0077                 setattr(event, "pseudoViaKtJet1"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector(groupingViaKt[0]) )
0078                 setattr(event, "pseudoViaKtJet2"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector(groupingViaKt[1]) )
0079                 setattr(event, "mt2ViaAKt"+collectionPostFix+postFix, self.computeMT2(getattr(event,'pseudoViaKtJet1'+collectionPostFix+postFix), getattr(event,'pseudoViaKtJet2'+collectionPostFix+postFix), met) )
0080                 return self.computeMT2(getattr(event,'pseudoViaKtJet1'+collectionPostFix+postFix), getattr(event,'pseudoViaKtJet2'+collectionPostFix+postFix), met)
0081 
0082             if not self.cfg_ana.doOnlyDefault:
0083                 hemisphereViaAKt = ReclusterJets(objects, -1.,50.0)
0084                 groupingViaAKt=hemisphereViaAKt.getGroupingExclusive(2)
0085 
0086                 if len(groupingViaAKt)>=2:
0087                     setattr(event, "pseudoViaAKtJet1"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector(groupingViaAKt[0]) )
0088                     setattr(event, "pseudoViaAKtJet2"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector(groupingViaAKt[1]) )
0089                     setattr(event, "mt2ViaAKt"+collectionPostFix+postFix, self.computeMT2(getattr(event,'pseudoViaAKtJet1'+collectionPostFix+postFix), getattr(event,'pseudoViaAKtJet2'+collectionPostFix+postFix), met) )
0090                     return self.computeMT2(getattr(event,'pseudoViaAKtJet1'+collectionPostFix+postFix), getattr(event,'pseudoViaAKtJet2'+collectionPostFix+postFix), met)
0091 
0092     def getMT2Hemi(self, event, TMPobjects40jc, met, collectionPostFix, postFix):
0093 
0094         if len(TMPobjects40jc)>=2:
0095 
0096             pxvec  = ROOT.std.vector(float)()
0097             pyvec  = ROOT.std.vector(float)()
0098             pzvec  = ROOT.std.vector(float)()
0099             Evec  = ROOT.std.vector(float)()
0100             grouping  = ROOT.std.vector(int)()
0101             
0102             for jet in TMPobjects40jc:
0103                 pxvec.push_back(jet.px())
0104                 pyvec.push_back(jet.py())
0105                 pzvec.push_back(jet.pz())
0106                 Evec.push_back(jet.energy())
0107 
0108             hemisphere = Hemisphere(pxvec, pyvec, pzvec, Evec, 2, 3)
0109             grouping=hemisphere.getGrouping()
0110 
0111             pseudoJet1px = 0 
0112             pseudoJet1py = 0 
0113             pseudoJet1pz = 0
0114             pseudoJet1energy = 0 
0115             multPSJ1 = 0
0116 
0117             pseudoJet2px = 0 
0118             pseudoJet2py = 0 
0119             pseudoJet2pz = 0
0120             pseudoJet2energy = 0 
0121             multPSJ2 = 0
0122                 
0123             for index in range(0, len(pxvec)):
0124                 if(grouping[index]==1):
0125                     pseudoJet1px += pxvec[index]
0126                     pseudoJet1py += pyvec[index]
0127                     pseudoJet1pz += pzvec[index]
0128                     pseudoJet1energy += Evec[index]
0129                     multPSJ1 += 1
0130                 if(grouping[index]==2):
0131                     pseudoJet2px += pxvec[index]
0132                     pseudoJet2py += pyvec[index]
0133                     pseudoJet2pz += pzvec[index]
0134                     pseudoJet2energy += Evec[index]                    
0135                     multPSJ2 += 1
0136 
0137             pseudoJet1pt2 = pseudoJet1px*pseudoJet1px + pseudoJet1py*pseudoJet1py
0138             pseudoJet2pt2 = pseudoJet2px*pseudoJet2px + pseudoJet2py*pseudoJet2py
0139 
0140             if pseudoJet1pt2 >= pseudoJet2pt2:
0141                 setattr(event, "pseudoJet1"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector( pseudoJet1px, pseudoJet1py, pseudoJet1pz, pseudoJet1energy ))
0142                 setattr(event, "pseudoJet2"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector( pseudoJet2px, pseudoJet2py, pseudoJet2pz, pseudoJet2energy ))
0143                 setattr(event, "multPseudoJet1"+collectionPostFix+postFix, multPSJ1 )
0144                 setattr(event, "multPseudoJet2"+collectionPostFix+postFix, multPSJ2 )
0145             else:
0146                 setattr(event, "pseudoJet2"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector( pseudoJet1px, pseudoJet1py, pseudoJet1pz, pseudoJet1energy ))
0147                 setattr(event, "pseudoJet1"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector( pseudoJet2px, pseudoJet2py, pseudoJet2pz, pseudoJet2energy ))
0148                 setattr(event, "multPseudoJet1"+collectionPostFix+postFix, multPSJ2 )
0149                 setattr(event, "multPseudoJet2"+collectionPostFix+postFix, multPSJ1 )
0150 
0151             setattr(event, "mt2"+collectionPostFix+postFix, self.computeMT2(getattr(event,'pseudoJet1'+collectionPostFix+postFix), getattr(event,'pseudoJet2'+collectionPostFix+postFix), met) )
0152             return self.computeMT2(getattr(event,'pseudoJet1'+collectionPostFix+postFix), getattr(event,'pseudoJet2'+collectionPostFix+postFix), met)
0153 
0154 
0155     def makeMT2(self, event):
0156 #        print '==> INSIDE THE PRINT MT2'
0157 #        print 'MET=',event.met.pt()
0158 
0159         self.met = ROOT.pat.MET(self.handles['met'].product()[0])
0160 
0161         import array
0162         import numpy
0163 
0164         objects40jc = [ j for j in event.cleanJets if j.pt() > 40 and abs(j.eta())<2.5 ]
0165         objectsXjc = [ j for j in event.cleanJets if j.pt() > self.jetPt and abs(j.eta())<2.5 ]
0166 
0167         setattr(event, "mt2ViaKt"+self.cfg_ana.collectionPostFix+"had", -999)
0168         setattr(event, "mt2ViaKt"+self.cfg_ana.collectionPostFix+"_Xj_had", -999)
0169         setattr(event, "pseudoViaKtJet1"+self.cfg_ana.collectionPostFix+"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0170         setattr(event, "pseudoViaKtJet2"+self.cfg_ana.collectionPostFix+"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0171         setattr(event, "pseudoViaKtJet1"+self.cfg_ana.collectionPostFix+"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0172         setattr(event, "pseudoViaKtJet2"+self.cfg_ana.collectionPostFix+"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0173 
0174         setattr(event, "mt2ViaAKt"+self.cfg_ana.collectionPostFix+"had", -999)
0175         setattr(event, "mt2ViaAKt"+self.cfg_ana.collectionPostFix+"_Xj_had", -999)
0176         setattr(event, "pseudoViaAKtJet1"+self.cfg_ana.collectionPostFix+"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0177         setattr(event, "pseudoViaAKtJet2"+self.cfg_ana.collectionPostFix+"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0178         setattr(event, "pseudoViaAKtJet1"+self.cfg_ana.collectionPostFix+"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0179         setattr(event, "pseudoViaAKtJet2"+self.cfg_ana.collectionPostFix+"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0180 
0181 #### get hemispheres via AntiKT -1 antikt, 1 kt, 0 CA
0182         if len(objects40jc)>=2:
0183 
0184             self.mt2ViaKt_had=self.getMT2AKT(event, objects40jc, self.met, self.cfg_ana.collectionPostFix, "_had")
0185 
0186         if len(objectsXjc)>=2:
0187 
0188             self.mt2ViaKt_Xj_had=self.getMT2AKT(event, objectsXjc, self.met, self.cfg_ana.collectionPostFix, "_Xj_had")
0189 
0190 ## ===> hadronic MT2 (as used in the SUS-13-019)
0191 #### get hemispheres (seed 2: max inv mass, association method: default 3 = minimal lund distance)
0192 
0193         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_had", -999)
0194         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_Xj_had", -999)
0195 
0196         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0197         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0198         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0199         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0200 
0201         if len(objects40jc)>=2:
0202 
0203             self.mt2_had = self.getMT2Hemi(event,objects40jc, self.met, self.cfg_ana.collectionPostFix, "_had")
0204 
0205         if len(objectsXjc)>=2:
0206 
0207             self.mt2_Xj_had = self.getMT2Hemi(event,objectsXjc, self.met, self.cfg_ana.collectionPostFix, "_Xj_had")
0208 
0209 #### do same things for GEN
0210 
0211         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_gen", -999)
0212         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_Xj_gen", -999)
0213 
0214         if self.cfg_comp.isMC and self.met.genMET():
0215             allGenJets = [ x for x in self.handles['genJets'].product() ] 
0216             objects40jc_Gen = [ j for j in allGenJets if j.pt() > 40 and abs(j.eta())<2.5 ]
0217             objectsXjc_Gen = [ j for j in allGenJets if j.pt() > self.jetPt and abs(j.eta())<2.5 ]
0218 
0219             if len(objects40jc_Gen)>=2:
0220                 self.mt2_gen = self.getMT2Hemi(event,objects40jc_Gen, self.met.genMET(), self.cfg_ana.collectionPostFix, "_gen")
0221 
0222             if len(objectsXjc_Gen)>=2:
0223                 self.mt2_Xj_gen = self.getMT2Hemi(event,objectsXjc_Gen, self.met.genMET(), self.cfg_ana.collectionPostFix, "_Xj_gen")
0224 
0225         else:
0226             self.mt2_gen = -999.
0227 
0228             
0229 ## ===> full MT2 (jets + leptons)
0230                                                                                                                                                                                              
0231         objects10lc = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta())<2.5 ]
0232         if hasattr(event, 'selectedIsoCleanTrack'):
0233             objects10lc = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta())<2.5 ] + [ t for t in event.selectedIsoCleanTrack ]
0234 
0235         objects40j10lc = objects40jc + objects10lc
0236         objects40j10lc.sort(key = lambda obj : obj.pt(), reverse = True)
0237 
0238         objectsXj10lc = objectsXjc + objects10lc
0239         objectsXj10lc.sort(key = lambda obj : obj.pt(), reverse = True)
0240 
0241         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"", -999)
0242         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_Xj", -999)
0243 
0244         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0245         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0246         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_Xj", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0247         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_Xj", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0248 
0249         if len(objects40j10lc)>=2:
0250 
0251             self.mt2 = self.getMT2Hemi(event,objects40j10lc,self.met,self.cfg_ana.collectionPostFix,"") # no postfit since this is the nominal MT2
0252 
0253         if len(objectsXj10lc)>=2:
0254 
0255             self.mt2_Xj = self.getMT2Hemi(event,objectsXj10lc,self.met,self.cfg_ana.collectionPostFix,"_Xj") # no postfit since this is the nominal MT2
0256 
0257 ## ===> full gamma_MT2
0258 
0259         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_gamma", -999)
0260 
0261         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_gamma", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0262         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_gamma", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0263             
0264         if hasattr(event, 'gamma_met'):
0265 
0266             gamma_objects40jc = [ j for j in event.gamma_cleanJets if j.pt() > 40 and abs(j.eta())<2.5 ]
0267             
0268             gamma_objects40j10lc = gamma_objects40jc + objects10lc
0269             
0270             gamma_objects40j10lc.sort(key = lambda obj : obj.pt(), reverse = True)
0271             
0272 ##        if len(gamma_objects40j10lc)>=2:
0273             if len(gamma_objects40jc)>=2:
0274                 
0275                 self.gamma_mt2 = self.getMT2Hemi(event,gamma_objects40jc,event.gamma_met,self.cfg_ana.collectionPostFix,"_gamma")
0276 
0277         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_Xj_gamma", -999)
0278         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_Xj_gamma", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0279         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_Xj_gamma", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0280             
0281         if hasattr(event, 'gamma_met'):
0282 
0283             gamma_objectsXjc = [ j for j in event.gamma_cleanJets if j.pt() > self.jetPt and abs(j.eta())<2.5 ]
0284             
0285             gamma_objectsXj10lc = gamma_objectsXjc + objects10lc
0286             
0287             gamma_objectsXj10lc.sort(key = lambda obj : obj.pt(), reverse = True)
0288             
0289             if len(gamma_objectsXjc)>=2:
0290                 
0291                 self.gamma_mt2_Xj = self.getMT2Hemi(event,gamma_objectsXjc,event.gamma_met,self.cfg_ana.collectionPostFix,"_Xj_gamma")
0292 
0293 
0294 
0295 ## ===> zll_MT2
0296         
0297         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_zll", -999)
0298         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_zll", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0299         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_zll", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0300                 
0301         if hasattr(event, 'zll_met'):
0302 
0303             csLeptons = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta()) < 2.5 ]
0304             
0305             if len(csLeptons)==2 and len(objects40jc)>=2:
0306             
0307                 self.zll_mt2 = self.getMT2Hemi(event,objects40jc,event.zll_met,self.cfg_ana.collectionPostFix,"_zll")
0308 
0309         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_Xj_zll", -999)
0310         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_Xj_zll", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0311         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_Xj_zll", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0312 
0313         if hasattr(event, 'zll_met'):
0314 
0315             csLeptons = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta()) < 2.5 ]
0316             
0317             if len(csLeptons)==2 and len(objectsXjc)>=2:
0318             
0319                 self.zll_mt2_Xj = self.getMT2Hemi(event,objectsXjc,event.zll_met,self.cfg_ana.collectionPostFix,"_Xj_zll")
0320 
0321 ### ===> zllmt_MT2
0322 #        
0323 #        setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_zllmt", -999)
0324 #        setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0325 #        setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0326 #                
0327 #        if hasattr(event, 'zllmt_met'):
0328 #
0329 #            csLeptons = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta()) < 2.5 ]
0330 #            
0331 #            if len(csLeptons)==2 and len(objects40jc)>=2:
0332 #            
0333 #                self.zllmt_mt2 = self.getMT2Hemi(event,objects40jc,event.zllmt_met,self.cfg_ana.collectionPostFix,"_zllmt")
0334 #
0335 #        setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_Xj_zllmt", -999)
0336 #        setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_Xj_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0337 #        setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_Xj_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0338 #
0339 #        if hasattr(event, 'zllmt_met'):
0340 #
0341 #            csLeptons = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta()) < 2.5 ]
0342 #            
0343 #            if len(csLeptons)==2 and len(objectsXjc)>=2:
0344 #            
0345 #                self.zllmt_mt2_Xj = self.getMT2Hemi(event,objectsXjc,event.zllmt_met,self.cfg_ana.collectionPostFix,"_Xj_zllmt")
0346 
0347 
0348 ## ===> rl_MT2
0349         
0350         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_rl", -999)
0351         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_rl", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0352         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_rl", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0353                 
0354         if hasattr(event, 'rl_met'):
0355 
0356             csLeptons = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta()) < 2.5 ]
0357             
0358             if len(csLeptons)==1 and len(objects40jc)>=2:
0359             
0360                 self.rl_mt2 = self.getMT2Hemi(event,objects40jc,event.rl_met,self.cfg_ana.collectionPostFix,"_rl")
0361 
0362         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_Xj_rl", -999)
0363         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_Xj_rl", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0364         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_Xj_rl", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0365 
0366         if hasattr(event, 'rl_met'):
0367 
0368             csLeptons = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta()) < 2.5 ]
0369             
0370             if len(csLeptons)==1 and len(objectsXjc)>=2:
0371             
0372                 self.rl_mt2_Xj = self.getMT2Hemi(event,objectsXjc,event.rl_met,self.cfg_ana.collectionPostFix,"_Xj_rl")
0373 
0374 
0375 ## ===> zllmt_MT2
0376         
0377         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_zllmt", -999)
0378         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0379         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0380                 
0381         if hasattr(event, 'zllmt_met'):
0382 
0383             csLeptons = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta()) < 2.5 ]
0384             
0385             if len(csLeptons)==2 and len(objects40jc)>=2:
0386             
0387                 self.zllmt_mt2 = self.getMT2Hemi(event,objects40jc,event.zllmt_met,self.cfg_ana.collectionPostFix,"_zllmt")
0388 
0389         setattr(event, "mt2"+self.cfg_ana.collectionPostFix+"_Xj_zllmt", -999)
0390         setattr(event, "pseudoJet1"+self.cfg_ana.collectionPostFix+"_Xj_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0391         setattr(event, "pseudoJet2"+self.cfg_ana.collectionPostFix+"_Xj_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
0392 
0393         if hasattr(event, 'zllmt_met'):
0394 
0395             csLeptons = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta()) < 2.5 ]
0396             
0397             if len(csLeptons)==2 and len(objectsXjc)>=1:
0398                 
0399                 csLeptons_mt = []
0400                 if (event.eventId%2):
0401                     csLeptons_mt.append(csLeptons[1])
0402                 else:
0403                     csLeptons_mt.append(csLeptons[0])
0404             
0405                 self.zllmt_mt2_Xj = self.getMT2Hemi(event,objectsXjc+[l for l in csLeptons if l not in csLeptons_mt],event.zllmt_met,self.cfg_ana.collectionPostFix,"_Xj_zllmt")
0406 
0407 
0408 #### do the mt2 with one or two b jets (medium CSV)                                                                                                                                                                                                         
0409         if len(event.bjetsMedium)>=2:
0410 
0411            event.mt2bb = self.computeMT2(event.bjetsMedium[0], event.bjetsMedium[1], self.met)
0412            event.mt2bb_Xj = self.computeMT2(event.bjetsMedium[0], event.bjetsMedium[1], self.met)
0413 #            print 'MT2bb(2b)',event.mt2bb                                                                                                                                                                                                                 
0414         if len(event.bjetsMedium)==1:
0415 
0416             objects40jcCSV = [ j for j in event.cleanJets if j.pt() > 40 and abs(j.eta())<2.5 and j.p4()!=event.bjetsMedium[0].p4() ]
0417             objects40jcCSV.sort(key = lambda l : l.btag('pfCombinedInclusiveSecondaryVertexV2BJetTags'), reverse = True)
0418 
0419             objectsXjcCSV = [ j for j in event.cleanJets if j.pt() > self.jetPt and abs(j.eta())<2.5 and j.p4()!=event.bjetsMedium[0].p4() ]
0420             objectsXjcCSV.sort(key = lambda l : l.btag('pfCombinedInclusiveSecondaryVertexV2BJetTags'), reverse = True)
0421 
0422             if len(objects40jcCSV)>0:
0423                 self.mt2bb = self.computeMT2(event.bjetsMedium[0], objects40jcCSV[0], self.met)
0424                 setattr(event, "mt2bb"+self.cfg_ana.collectionPostFix, self.mt2bb)
0425 
0426             if len(objectsXjcCSV)>0:
0427                 self.mt2bb_Xj = self.computeMT2(event.bjetsMedium[0], objectsXjcCSV[0], self.met)
0428                 setattr(event, "mt2bb_Xj"+self.cfg_ana.collectionPostFix, self.mt2bb_Xj)
0429 
0430 ##                print 'MT2bb(1b)',event.mt2bb
0431 
0432 ## ===> leptonic MT2 (as used in the SUS-13-025 )                                                                                                                                                                                                           
0433         if not self.cfg_ana.doOnlyDefault:
0434             if len(event.selectedLeptons)>=2:
0435                 self.mt2lep = self.computeMT2(event.selectedLeptons[0], event.selectedLeptons[1], self.met)
0436                 setattr(event, "mt2lep"+self.cfg_ana.collectionPostFix, self.mt2lep)
0437 
0438 ###
0439 
0440     def process(self, event):
0441         self.readCollections( event.input )
0442 
0443         event.mt2bb=-999
0444         event.mt2bb_Xj=-999
0445         event.mt2lept=-999        
0446 
0447         event.multPseudoJet1_had=0
0448         event.multPseudoJet2_had=0
0449         
0450         event.multPseudoJet1_Xj_had=0
0451         event.multPseudoJet2_Xj_had=0
0452  
0453         ###
0454 
0455         self.makeMT2(event)
0456 
0457 #        print 'variables computed: MT=',event.mtw,'MT2=',event.mt2,'MT2W=',event.mt2w
0458 #        print 'pseudoJet1 px=',event.pseudoJet1.px(),' py=',event.pseudoJet1.py(),' pz=',event.pseudoJet1.pz()
0459 #        print 'pseudoJet2 px=',event.pseudoJet2.px(),' py=',event.pseudoJet2.py(),' pz=',event.pseudoJet2.pz()   
0460 
0461         return True
0462 
0463 
0464 
0465 setattr(MT2Analyzer,"defaultConfig", cfg.Analyzer(
0466     class_object = MT2Analyzer,
0467     metCollection     = "slimmedMETs",
0468     collectionPostFix = "",
0469     doOnlyDefault = True,
0470     )
0471 )