Skip to content

Commit

Permalink
Merge pull request cms-sw#347 from arizzi/puandjson
Browse files Browse the repository at this point in the history
Pileup weight update and new json
  • Loading branch information
arizzi committed Feb 5, 2016
2 parents e6c3ec3 + 9696a3a commit 8b1cd1f
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 1 deletion.
15 changes: 15 additions & 0 deletions PhysicsTools/Heppy/python/analyzers/core/PileUpAnalyzer.py
Expand Up @@ -72,6 +72,19 @@ def __init__(self, cfg_ana, cfg_comp, looperName):
self.datafile = TFile( self.cfg_comp.puFileData )
self.datahist = self.datafile.Get('pileup')
self.datahist.Scale( 1 / self.datahist.Integral() )

#PU uncertainties variations
self.datahistPlus=None
self.datahistMinus=None
if hasattr(self.cfg_comp,"puFileDataPlus") :
self.datafilePlus = TFile( self.cfg_comp.puFileDataPlus )
self.datahistPlus = self.datafilePlus.Get('pileup')
self.datahistPlus.Scale( 1. / self.datahistPlus.Integral() )
if hasattr(self.cfg_comp,"puFileDataMinus") :
self.datafileMinus = TFile( self.cfg_comp.puFileDataMinus )
self.datahistMinus = self.datafileMinus.Get('pileup')
self.datahistMinus.Scale( 1. / self.datahistMinus.Integral() )

# import pdb; pdb.set_trace()
if self.mchist.GetNbinsX() != self.datahist.GetNbinsX():
raise ValueError('data and mc histograms must have the same number of bins')
Expand Down Expand Up @@ -147,6 +160,8 @@ def process(self, event):
#Protect 0 division!!!!
if mc !=0.0:
event.puWeight = data/mc
event.puWeightPlus = self.datahistPlus.GetBinContent(bin)/mc if self.datahistPlus is not None else 1.
event.puWeightMinux = self.datahistPlus.GetBinContent(bin)/mc if self.datahistMinus is not None else 1.
else:
event.puWeight = 1

Expand Down
@@ -0,0 +1 @@
{"254231": [[1, 24]], "254232": [[1, 81]], "254790": [[90, 90], [93, 630], [633, 697], [701, 715], [719, 784]], "254852": [[47, 94]], "254879": [[52, 52], [54, 140]], "254906": [[1, 75]], "254907": [[1, 52]], "254914": [[32, 32], [34, 78]], "256630": [[5, 26]], "256673": [[55, 56]], "256674": [[1, 2]], "256675": [[1, 106], [111, 164]], "256676": [[1, 160], [162, 208]], "256677": [[1, 291], [293, 390], [392, 397], [400, 455], [457, 482]], "256801": [[73, 263]], "256842": [[131, 132]], "256843": [[1, 204], [207, 284], [286, 378], [380, 461], [463, 587], [598, 627], [630, 661], [1001, 1034], [1036, 1081], [1083, 1191], [1193, 1193], [1195, 1329], [1331, 1332]], "256866": [[34, 47]], "256867": [[1, 16], [19, 94]], "256868": [[5, 33], [35, 200], [202, 492]], "256869": [[1, 34]], "256926": [[35, 50], [53, 62], [64, 65]], "256941": [[1, 17], [19, 29], [103, 105], [107, 126], [129, 129], [131, 168], [170, 170], [175, 290], [293, 294]], "257461": [[44, 95]], "257531": [[5, 45], [50, 143]], "257599": [[42, 118]], "257613": [[14, 1307]], "257614": [[1, 16]], "257645": [[37, 73], [75, 1096]], "257682": [[66, 366]], "257722": [[1, 19]], "257723": [[1, 1], [3, 108], [114, 148]], "257735": [[1, 15]], "257751": [[1, 463]], "257804": [[1, 17]], "257805": [[1, 249]], "257816": [[1, 385]], "257819": [[1, 248]], "257968": [[69, 326]], "257969": [[1, 634]], "258129": [[30, 124]], "258136": [[1, 60]], "258157": [[1, 56]], "258158": [[1, 1088], [1091, 1786]], "258159": [[1, 501]], "258177": [[1, 342], [347, 724], [755, 1939]], "258211": [[43, 129]], "258213": [[1, 165]], "258214": [[1, 217]], "258215": [[1, 6]], "258287": [[45, 144], [148, 227]], "258403": [[1, 251]], "258425": [[3, 136]], "258426": [[1, 10]], "258427": [[1, 107]], "258428": [[1, 159]], "258432": [[1, 4]], "258434": [[1, 453]], "258440": [[1, 442], [444, 732]], "258444": [[1, 37]], "258445": [[1, 302]], "258446": [[1, 142]], "258448": [[2, 100], [102, 731]], "258655": [[60, 68]], "258656": [[1, 334]], "258694": [[23, 199]], "258702": [[52, 402]], "258703": [[1, 389]], "258705": [[1, 100]], "258706": [[1, 733]], "258712": [[1, 524]], "258713": [[1, 161]], "258714": [[1, 67]], "258741": [[22, 72]], "258742": [[2, 693]], "258745": [[1, 260]], "258749": [[1, 204], [220, 604]], "258750": [[1, 197]], "259626": [[83, 111], [113, 167], [169, 437]], "259637": [[1, 72], [75, 221]], "259681": [[64, 98]], "259683": [[5, 19], [21, 23], [25, 94]], "259685": [[1, 209], [212, 240], [242, 290], [292, 445], [447, 538], [540, 544], [546, 630]], "259686": [[1, 43], [45, 47], [49, 100], [102, 245], [248, 341]], "259721": [[73, 99], [102, 408]], "259809": [[53, 222]], "259810": [[1, 113], [116, 116]], "259811": [[1, 47], [50, 91]], "259813": [[1, 10]], "259817": [[1, 5]], "259818": [[1, 160]], "259820": [[1, 32], [36, 161]], "259821": [[1, 75], [78, 212]], "259822": [[1, 14], [17, 464]], "259861": [[1, 34], [36, 38], [40, 66], [69, 156]], "259862": [[1, 13], [16, 532]], "259884": [[73, 143], [147, 155]], "259890": [[1, 34], [37, 109]], "259891": [[1, 108]], "260373": [[47, 370], [373, 408]], "260424": [[3, 12], [15, 266], [269, 672]], "260425": [[1, 18], [21, 55], [58, 256]], "260426": [[1, 52], [55, 296], [298, 307], [310, 504]], "260427": [[1, 285]], "260431": [[1, 447]], "260532": [[3, 8], [10, 456], [458, 746]], "260533": [[1, 14]], "260534": [[1, 375]], "260536": [[9, 37], [45, 60], [62, 193]], "260538": [[1, 284]], "260541": [[1, 24]], "260575": [[2, 21]], "260576": [[2, 88], [90, 465]], "260577": [[1, 76]], "260593": [[65, 401]], "260627": [[97, 611], [613, 757], [760, 788], [791, 1051], [1054, 1530], [1533, 1845]]}
21 changes: 21 additions & 0 deletions VHbbAnalysis/Heppy/test/Lumi/V20/makeDataPUfile.sh
@@ -0,0 +1,21 @@
#!/bin/sh
#JSON=newJSON_max196509.txt
JSON=Cert_246908-260627_13TeV_PromptReco_Collisions15_25ns_JSON_v2.txt
#/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions15/13TeV/Cert_246908-260627_13TeV_PromptReco_Collisions15_25ns_JSON_v2.txt
#PUJSON=/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions12/8TeV/PileUp/pileup_JSON_DCSONLY_190389-202478_corr.txt
PUJSON=pileup_latest.txt

#INBIAS=75000

#MINBIASP=66475
#MINBIASM=72450
#MINBIAS=71000

pileupCalc.py -i ${JSON} --inputLumiJSON $PUJSON --calcMode true --minBiasXsec 69000 --maxPileupBin 50 --numPileupBins 50 outputData.root
pileupCalc.py -i ${JSON} --inputLumiJSON $PUJSON --calcMode true --minBiasXsec 72450 --maxPileupBin 50 --numPileupBins 50 outputDataP.root
pileupCalc.py -i ${JSON} --inputLumiJSON $PUJSON --calcMode true --minBiasXsec 65715 --maxPileupBin 50 --numPileupBins 50 outputDataM.root

#ileupCalc.py -i ${JSON} --inputLumiJSON $PUJSON --calcMode true --minBiasXsec $MINBIAS --maxPileupBin 52 --numPileupBins 52 outputfile.root
#pileupCalc.py -i ${JSON} --inputLumiJSON $PUJSON --calcMode true --minBiasXsec $MINBIASP --maxPileupBin 60 --numPileupBins 60 outputfileP.root
#pileupCalc.py -i ${JSON} --inputLumiJSON $PUJSON --calcMode true --minBiasXsec $MINBIASM --maxPileupBin 60 --numPileupBins 60 outputfileM.root

19 changes: 19 additions & 0 deletions VHbbAnalysis/Heppy/test/Lumi/V20/makeMChisto.py
@@ -0,0 +1,19 @@
#!/usr/bin/env python

#CHANGE THIS LINE TO CHANGE PU SCENARIO
from SimGeneral.MixingModule import mix_2015_25ns_FallMC_matchData_PoissonOOTPU_cfi as pu

import ROOT
n=len(pu.mix.input.nbPileupEvents.probValue )
x=pu.mix.input.nbPileupEvents.probValue

f= ROOT.TFile("mcpu.root","recreate")
pu = ROOT.TH1F("pileup","pileip",n,0,n)

for i in xrange(0,n) :
print i
pu.SetBinContent(i+1,x[i])


pu.Write()
f.Write()
Binary file added VHbbAnalysis/Heppy/test/Lumi/V20/mcpu.root
Binary file not shown.
Binary file added VHbbAnalysis/Heppy/test/Lumi/V20/outputData.root
Binary file not shown.
Binary file added VHbbAnalysis/Heppy/test/Lumi/V20/outputDataM.root
Binary file not shown.
Binary file added VHbbAnalysis/Heppy/test/Lumi/V20/outputDataP.root
Binary file not shown.
1 change: 1 addition & 0 deletions VHbbAnalysis/Heppy/test/Lumi/V20/pileup_latest.txt

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions VHbbAnalysis/Heppy/test/Lumi/makeMChisto.py
@@ -0,0 +1,19 @@
#!/usr/bin/env python

#CHANGE THIS LINE TO CHANGE PU SCENARIO
from SimGeneral.MixingModule import mix_2015_25ns_FallMC_matchData_PoissonOOTPU_cfi as pu

import ROOT
n=len(pu.mix.input.nbPileupEvents.probValue )
x=pu.mix.input.nbPileupEvents.probValue

f= ROOT.TFile("mcpu.root","recreate")
pu = ROOT.TH1F("pileup","pileip",n,0,n)

for i in xrange(0,n) :
print i
pu.SetBinContent(i+1,x[i])


pu.Write()
f.Write()
2 changes: 1 addition & 1 deletion VHbbAnalysis/Heppy/test/json.txt
Binary file modified VHbbAnalysis/Heppy/test/puData.root
Binary file not shown.
Binary file added VHbbAnalysis/Heppy/test/puDataMinus.root
Binary file not shown.
Binary file added VHbbAnalysis/Heppy/test/puDataPlus.root
Binary file not shown.
Binary file modified VHbbAnalysis/Heppy/test/puStartup2015.root
Binary file not shown.
4 changes: 4 additions & 0 deletions VHbbAnalysis/Heppy/test/vhbb.py
Expand Up @@ -25,6 +25,8 @@
verbose=False,
vectorTree = True,
globalVariables = [
NTupleVariable("puWeightUp", lambda ev : getattr(ev,"puWeightPlus",1.), help="Pileup up variation",mcOnly=True),
NTupleVariable("puWeightDown", lambda ev : getattr(ev,"puWeightMinus",1.), help="Pileup down variation",mcOnly=True),
NTupleVariable("json", lambda ev : getattr(ev,"json",True), help="Passing json selection"),
NTupleVariable("nPU0", lambda ev : [bx.nPU() for bx in ev.pileUpInfo if bx.getBunchCrossing()==0][0], help="nPU in BX=0",mcOnly=True),
NTupleVariable("nPVs", lambda ev : len(ev.goodVertices), help="total number of good PVs"),
Expand Down Expand Up @@ -399,6 +401,8 @@ def ele_mvaEleID_Trig_preselection(ele) :
name="ZHLL125", isEmbed=False,
puFileMC="puMC.root",
puFileData="puData.root",
puFileDataPlus="puDataPlus.root",
puFileDataMinus="puDataMinus.root",
splitFactor = 5
)
sample.isMC=True
Expand Down

0 comments on commit 8b1cd1f

Please sign in to comment.