From f8c3d01fab3386a7c9eae145b401f66c95d09ea3 Mon Sep 17 00:00:00 2001 From: maria Date: Fri, 13 Feb 2015 17:32:02 +0100 Subject: [PATCH 1/3] add Z skimmer --- CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py | 24 ++++++++- .../python/analyzers/ttHmllSkimmer.py | 50 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 CMGTools/TTHAnalysis/python/analyzers/ttHmllSkimmer.py diff --git a/CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py b/CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py index db639c263d4..aaf895bd221 100644 --- a/CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py +++ b/CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py @@ -84,6 +84,23 @@ doOnlyDefault = True ) +##------------------------------------------ +## Z skim +##------------------------------------------ + +from CMGTools.TTHAnalysis.analyzers.ttHmllSkimmer import ttHmllSkimmer +# Tree Producer +ttHZskim = cfg.Analyzer( + ttHmllSkimmer, name='ttHmllSkimmer', + lepId=13, + maxLeps=3, + intPDG=13, + massMin=60, + massMax=120, + doZGen = False, + doZReco = True + ) + ##------------------------------------------ ## PRODUCER @@ -119,9 +136,12 @@ defaultFloatType = 'F', ) - susyCoreSequence.insert(susyCoreSequence.index(skimAnalyzer), susyCounter) + +#susyCoreSequence.insert(susyCoreSequence.index(ttHLepSkim), +# ttHZskim) + sequence = cfg.Sequence( susyCoreSequence+[ ttHMT2Control, @@ -185,6 +205,8 @@ comp=GJets_HT200to400 # comp.files = ['/afs/cern.ch/work/d/dalfonso/public/gjets_ht200to400_miniaodsim_060B8ED3-8571-E411-A2CD-002590D0AFEA.root'] comp.files = ['/afs/cern.ch/user/d/dalfonso/public/TESTfilesPHY14/gjets_ht200to400_miniaodsim_fix.root'] +# comp=DYJetsToLL_M50_PU4bx50 +# comp.files = comp.files[:1] selectedComponents = [comp] comp.splitFactor = 10 diff --git a/CMGTools/TTHAnalysis/python/analyzers/ttHmllSkimmer.py b/CMGTools/TTHAnalysis/python/analyzers/ttHmllSkimmer.py new file mode 100644 index 00000000000..99dc40e3c6e --- /dev/null +++ b/CMGTools/TTHAnalysis/python/analyzers/ttHmllSkimmer.py @@ -0,0 +1,50 @@ +from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer +from PhysicsTools.HeppyCore.framework.event import Event +from PhysicsTools.HeppyCore.statistics.counter import Counter, Counters +from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle + +class ttHmllSkimmer( Analyzer ): + def __init__(self, cfg_ana, cfg_comp, looperName ): + super(ttHmllSkimmer,self).__init__(cfg_ana,cfg_comp,looperName) + + def declareHandles(self): + super(ttHmllSkimmer, self).declareHandles() + + def beginLoop(self,setup): + super(ttHmllSkimmer,self).beginLoop(setup) + self.counters.addCounter('events') + count = self.counters.counter('events') + count.register('all events') + count.register('pass gen Zll skim') + count.register('pass reco Zll skim') + + def makeZs(self, event, maxLeps, intPDG): + event.bestZ = [ 0., -1,-1 ] + nlep = len(event.selectedLeptons) + for i,l1 in enumerate(event.selectedLeptons): + for j in range(i+1,nlep): + if j >= maxLeps: break + l2 = event.selectedLeptons[j] + if l1.pdgId() == -l2.pdgId() and abs(l1.pdgId())==intPDG: + zmass = (l1.p4() + l2.p4()).M() + if event.bestZ[0] == 0 or abs(zmass - 91.188) < abs(event.bestZ[0] - 91.188): + event.bestZ = [ zmass, i, j ] + + def process(self, event): + self.readCollections( event.input ) + self.counters.counter('events').inc('all events') + + if self.cfg_ana.doZGen and len(event.genleps)==2: + if(event.genleps[0].pdgId() == - event.genleps[1].pdgId()) and abs(event.genleps[0].pdgId())==self.cfg_ana.lepId : + if (event.genleps[0].sourceId==23 and event.genleps[1].sourceId==23) : + self.counters.counter('events').inc('pass gen Zll skim') + return True + + if self.cfg_ana.doZReco: + self.makeZs( event, self.cfg_ana.maxLeps, self.cfg_ana.intPDG) + if event.bestZ[0] > self.cfg_ana.massMin and event.bestZ[0] < self.cfg_ana.massMax: + self.counters.counter('events').inc('pass reco Zll skim') + return True + + #If none of the Z selection return veto + return False From 0a86b4ff25acd64c5df62a1625b37b02ee594050 Mon Sep 17 00:00:00 2001 From: maria Date: Fri, 13 Feb 2015 17:33:57 +0100 Subject: [PATCH 2/3] add plot to the validation script --- CMGTools/TTHAnalysis/cfg/validate_MT2.sh | 2 +- .../plotter/bins/validation_plots_MT2.txt | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMGTools/TTHAnalysis/cfg/validate_MT2.sh b/CMGTools/TTHAnalysis/cfg/validate_MT2.sh index 9f6aa2ee243..68bfafa0115 100644 --- a/CMGTools/TTHAnalysis/cfg/validate_MT2.sh +++ b/CMGTools/TTHAnalysis/cfg/validate_MT2.sh @@ -10,7 +10,7 @@ X=$PWD/$1; if test \! -d $X/ETHCERN; then echo "Did not find ETHCERN in $X"; exit 1; fi test -L $PWD/SNT || ln -sd $PWD/SNT $X/ -v; ( cd ../python/plotter; - python mcPlots.py -f --s2v --tree mt2 -P $X bins/validation_mca_mt2.txt bins/validation_MT2.txt bins/validation_plots_MT2.txt --pdir plots/70X/validation -p ref_ttHWWdata,ttHWWdata -u -e --plotmode=norm --showRatio --maxRatioRange 0.65 1.35 --flagDifferences + python mcPlots.py -f --tree mt2 -P $X bins/validation_mca_mt2.txt bins/validation_MT2.txt bins/validation_plots_MT2.txt --pdir plots/70X/validation -p ref_ttHWWdata,ttHWWdata -u -e --plotmode=norm --showRatio --maxRatioRange 0.65 1.35 --flagDifferences ) ## bins/validation_mca.txt --> this contains stile diff --git a/CMGTools/TTHAnalysis/python/plotter/bins/validation_plots_MT2.txt b/CMGTools/TTHAnalysis/python/plotter/bins/validation_plots_MT2.txt index e3a60387058..359cd5c1fb7 100644 --- a/CMGTools/TTHAnalysis/python/plotter/bins/validation_plots_MT2.txt +++ b/CMGTools/TTHAnalysis/python/plotter/bins/validation_plots_MT2.txt @@ -62,15 +62,15 @@ mt2: mt2: 16,0,800 ; XTitle="MT2 [GeV]" mt2_gen: mt2_gen: 16,0,800 ; XTitle="MT2 gen [GeV]" -#pseudoJet1_pt: pseudoJet1_pt: 16,0,800 ; XTitle="PseJet1 p_{T} [GeV]", Legend='TR' -#pseudoJet1_phi: pseudoJet1_phi: 8,-3.15,3.15 ; XTitle="PseJet1 phi" -#pseudoJet1_eta: pseudoJet1_eta: 10,-5.,5. ; XTitle="PseJet1 eta" -#pseudoJet1_mass: pseudoJet1_mass: 20,0,400. ; XTitle="PseJet1 mass [GeV]" - -#pseudoJet2_pt: pseudoJet2_pt: 16,0,800 ; XTitle="PseJet12 p_{T} [GeV]" -#pseudoJet2_phi: pseudoJet2_phi: 8,-3.15,3.15 ; XTitle="PseJet2 phi" -#pseudoJet2_eta: pseudoJet2_eta: 10,-5.,5. ; XTitle="PseJet2 eta" -#pseudoJet2_mass: pseudoJet2_mass: 20,0,400. ; XTitle="PseJet2 mass [GeV]" +pseudoJet1_pt: pseudoJet1_pt: 16,0,800 ; XTitle="PseJet1 p_{T} [GeV]", Legend='TR' +pseudoJet1_phi: pseudoJet1_phi: 8,-3.15,3.15 ; XTitle="PseJet1 phi" +pseudoJet1_eta: pseudoJet1_eta: 10,-5.,5. ; XTitle="PseJet1 eta" +pseudoJet1_mass: pseudoJet1_mass: 20,0,400. ; XTitle="PseJet1 mass [GeV]" + +pseudoJet2_pt: pseudoJet2_pt: 16,0,800 ; XTitle="PseJet12 p_{T} [GeV]" +pseudoJet2_phi: pseudoJet2_phi: 8,-3.15,3.15 ; XTitle="PseJet2 phi" +pseudoJet2_eta: pseudoJet2_eta: 10,-5.,5. ; XTitle="PseJet2 eta" +pseudoJet2_mass: pseudoJet2_mass: 20,0,400. ; XTitle="PseJet2 mass [GeV]" nPFLep5LowMT: nPFLep5LowMT: [-0.5,0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5] ; XTitle='N(PFLep\, p_{T} > 5\, M_{T} < 100)' From f09dd7cdd6035f6a2c260308ad8174c4c488ccb5 Mon Sep 17 00:00:00 2001 From: maria Date: Fri, 13 Feb 2015 18:26:24 +0100 Subject: [PATCH 3/3] clean up ID in Z skimmer --- CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py | 4 +--- CMGTools/TTHAnalysis/python/analyzers/ttHmllSkimmer.py | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py b/CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py index aaf895bd221..73e448f1c99 100644 --- a/CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py +++ b/CMGTools/TTHAnalysis/cfg/run_susyMT2_cfg.py @@ -92,9 +92,8 @@ # Tree Producer ttHZskim = cfg.Analyzer( ttHmllSkimmer, name='ttHmllSkimmer', - lepId=13, + lepId=[13], maxLeps=3, - intPDG=13, massMin=60, massMax=120, doZGen = False, @@ -199,7 +198,6 @@ ## 25 ns ttbar PHYS14 # comp = TTJets # comp.files = comp.files[:1] - # comp=TTJets # comp.files = ['/afs/cern.ch/work/d/dalfonso/public/ttjets_miniaodsim_00C90EFC-3074-E411-A845-002590DB9262.root'] comp=GJets_HT200to400 diff --git a/CMGTools/TTHAnalysis/python/analyzers/ttHmllSkimmer.py b/CMGTools/TTHAnalysis/python/analyzers/ttHmllSkimmer.py index 99dc40e3c6e..31c4a9b23d9 100644 --- a/CMGTools/TTHAnalysis/python/analyzers/ttHmllSkimmer.py +++ b/CMGTools/TTHAnalysis/python/analyzers/ttHmllSkimmer.py @@ -18,14 +18,14 @@ def beginLoop(self,setup): count.register('pass gen Zll skim') count.register('pass reco Zll skim') - def makeZs(self, event, maxLeps, intPDG): + def makeZs(self, event, maxLeps, lepId): event.bestZ = [ 0., -1,-1 ] nlep = len(event.selectedLeptons) for i,l1 in enumerate(event.selectedLeptons): for j in range(i+1,nlep): if j >= maxLeps: break l2 = event.selectedLeptons[j] - if l1.pdgId() == -l2.pdgId() and abs(l1.pdgId())==intPDG: + if l1.pdgId() == -l2.pdgId() and abs(l1.pdgId()) in lepId: zmass = (l1.p4() + l2.p4()).M() if event.bestZ[0] == 0 or abs(zmass - 91.188) < abs(event.bestZ[0] - 91.188): event.bestZ = [ zmass, i, j ] @@ -35,13 +35,13 @@ def process(self, event): self.counters.counter('events').inc('all events') if self.cfg_ana.doZGen and len(event.genleps)==2: - if(event.genleps[0].pdgId() == - event.genleps[1].pdgId()) and abs(event.genleps[0].pdgId())==self.cfg_ana.lepId : + if event.genleps[0].pdgId() == - event.genleps[1].pdgId() and abs(event.genleps[0].pdgId()) in self.cfg_ana.lepId : if (event.genleps[0].sourceId==23 and event.genleps[1].sourceId==23) : self.counters.counter('events').inc('pass gen Zll skim') return True if self.cfg_ana.doZReco: - self.makeZs( event, self.cfg_ana.maxLeps, self.cfg_ana.intPDG) + self.makeZs( event, self.cfg_ana.maxLeps, self.cfg_ana.lepId) if event.bestZ[0] > self.cfg_ana.massMin and event.bestZ[0] < self.cfg_ana.massMax: self.counters.counter('events').inc('pass reco Zll skim') return True