Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run2 pileup calculation script #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"299368": [[37, 175]], "299369": [[1, 303]], "299370": [[1, 7], [47, 705]], "299380": [[34, 227]], "299381": [[1, 45]], "299394": [[5, 33]], "299395": [[1, 187]], "299396": [[1, 81]], "299420": [[2, 50]], "299443": [[145, 164]], "299450": [[39, 88]], "299477": [[39, 42], [82, 87]], "299478": [[1, 175]], "299479": [[1, 123]], "299480": [[1, 715]], "299481": [[1, 196], [199, 236], [260, 479], [487, 940], [943, 1037], [1061, 1257]], "299593": [[95, 177], [179, 896]], "299594": [[1, 317]], "299595": [[1, 134], [138, 138]], "299597": [[3, 91], [93, 540]], "299649": [[151, 332]], "300087": [[36, 59], [61, 126], [128, 216], [218, 239]], "300105": [[1, 21]], "300106": [[1, 74]], "300107": [[1, 28], [30, 47]], "300117": [[35, 67]], "300122": [[46, 730], [735, 924], [927, 1295]], "300123": [[1, 384], [387, 612]], "300155": [[35, 1229]], "300156": [[1, 72]], "300157": [[9, 1107]], "300226": [[43, 448]], "300233": [[43, 162]], "300234": [[1, 59]], "300235": [[1, 187]], "300236": [[11, 187]], "300237": [[1, 713], [716, 717]], "300238": [[30, 58], [62, 329]], "300239": [[1, 145], [148, 167], [171, 213]], "300240": [[1, 7], [11, 46], [51, 362]], "300280": [[52, 56], [61, 69], [73, 150], [155, 165], [178, 198], [207, 222], [226, 251], [255, 268], [275, 345], [349, 370], [381, 548], [553, 607], [617, 639], [663, 691]], "300281": [[3, 8]], "300282": [[1, 9], [13, 59], [73, 92], [97, 114], [142, 151], [156, 186]], "300283": [[1, 34]], "300284": [[1, 22], [38, 47], [50, 82], [90, 98], [108, 130], [133, 152], [156, 250], [260, 414], [420, 561], [568, 585], [590, 680], [691, 751]], "300364": [[27, 46]], "300365": [[1, 20]], "300366": [[1, 21]], "300367": [[1, 20]], "300368": [[1, 20]], "300369": [[1, 20]], "300370": [[1, 20]], "300371": [[1, 20]], "300372": [[1, 8]], "300373": [[1, 21]], "300374": [[1, 21]], "300375": [[1, 93]], "300389": [[1, 1], [4, 5], [8, 8], [11, 20], [23, 39], [60, 149]], "300390": [[2, 21]], "300391": [[1, 21]], "300392": [[1, 21]], "300393": [[1, 20]], "300394": [[1, 21]], "300395": [[1, 20]], "300396": [[1, 20]], "300397": [[1, 20]], "300398": [[1, 20]], "300399": [[1, 20]], "300400": [[1, 677]], "300401": [[19, 673]], "300459": [[40, 332]], "300461": [[1, 98]], "300462": [[1, 97]], "300463": [[1, 124]], "300464": [[1, 103], [126, 265]], "300466": [[1, 650]], "300467": [[1, 563]], "300497": [[26, 175]], "300514": [[38, 150]], "300515": [[1, 838], [957, 1013]], "300516": [[1, 111]], "300517": [[1, 8], [103, 623]], "300558": [[8, 548]], "300560": [[1, 640], [645, 844]], "300574": [[15, 111]], "300575": [[1, 82]], "300576": [[7, 123], [125, 1206]], "300631": [[41, 49], [63, 66], [75, 226]], "300632": [[1, 21]], "300633": [[1, 447]], "300635": [[1, 23], [26, 176]], "300636": [[1, 335], [338, 1572]], "300673": [[41, 47], [49, 49], [52, 56], [59, 66]], "300674": [[1, 33]], "300675": [[1, 33]], "300676": [[1, 26]], "300742": [[56, 343]], "300777": [[21, 509]], "300780": [[3, 341]], "300785": [[1, 549], [552, 750], [752, 1201], [1219, 1272]], "300806": [[36, 214]], "300811": [[6, 508]], "300812": [[1, 59]], "300816": [[6, 161]], "300817": [[1, 33], [36, 74], [80, 383], [410, 493]], "301046": [[162, 223]], "301141": [[25, 31]], "301142": [[1, 897]], "301161": [[36, 805]], "301165": [[1, 145]], "301179": [[35, 59]], "301180": [[1, 97]], "301183": [[3, 10], [13, 303]], "301281": [[38, 157]], "301283": [[3, 886]], "301298": [[45, 949]], "301323": [[35, 474], [477, 990]], "301330": [[22, 353]], "301359": [[33, 319]], "301384": [[1, 476]], "301391": [[38, 214]], "301392": [[1, 627]], "301393": [[2, 18]], "301396": [[1, 33]], "301397": [[1, 228], [231, 728]], "301398": [[1, 9]], "301399": [[1, 108]], "301417": [[50, 367]], "301447": [[86, 96], [99, 400], [404, 512]], "301448": [[1, 329]], "301449": [[1, 404]], "301450": [[1, 173]], "301461": [[28, 581]], "301472": [[35, 830]], "301475": [[1, 18]], "301476": [[1, 844]], "301519": [[42, 250]], "301524": [[1, 110], [117, 263]], "301529": [[1, 49]], "301530": [[1, 110]], "301531": [[1, 394]], "301532": [[1, 611]], "301567": [[14, 372]], "301627": [[57, 943]], "301664": [[28, 445]], "301665": [[1, 294], [319, 487]], "301694": [[36, 102]], "301912": [[43, 52], [101, 422]], "301913": [[1, 58]], "301914": [[1, 350]], "301941": [[31, 568]], "301959": [[30, 1938]], "301960": [[1, 147]], "301970": [[6, 123]], "301984": [[17, 317]], "301985": [[1, 367]], "301986": [[1, 381]], "301987": [[1, 1128]], "301997": [[37, 407]], "301998": [[1, 1704]], "302019": [[34, 86]], "302026": [[24, 53], [66, 72]], "302029": [[1, 98]], "302031": [[1, 401], [403, 446], [448, 675], [678, 818]], "302033": [[1, 40], [44, 46]], "302034": [[1, 20]], "302037": [[18, 20]], "302038": [[10, 10]], "302040": [[1, 174]], "302041": [[1, 72]], "302042": [[1, 523]], "302043": [[1, 228]], "302131": [[71, 943]], "302159": [[33, 140]], "302163": [[32, 671], [674, 1230]], "302165": [[1, 85]], "302166": [[1, 16]], "302225": [[54, 133], [136, 923]], "302228": [[58, 78], [81, 293]], "302229": [[1, 457]], "302240": [[1, 960]], "302262": [[37, 471]], "302263": [[1, 1250]], "302277": [[15, 17], [22, 192], [194, 391]], "302279": [[1, 71]], "302280": [[1, 152]], "302322": [[33, 870]], "302328": [[42, 722]], "302337": [[27, 162]], "302342": [[19, 72]], "302343": [[1, 98]], "302344": [[3, 482]], "302350": [[1, 136]], "302388": [[27, 157], [164, 717]], "302392": [[45, 407]], "302393": [[1, 887]], "302448": [[21, 312], [317, 442], [445, 483], [486, 1926]], "302472": [[28, 808]], "302473": [[1, 368], [398, 406]], "302474": [[1, 305]], "302475": [[1, 7]], "302476": [[1, 259]], "302479": [[30, 222], [225, 340]], "302484": [[8, 176]], "302485": [[1, 922]], "302492": [[10, 21], [23, 59]], "302493": [[1, 7]], "302494": [[1, 618]], "302509": [[73, 92]], "302513": [[37, 89]], "302522": [[29, 46]], "302523": [[1, 59]], "302525": [[1, 677], [747, 778]], "302526": [[1, 582]], "302548": [[40, 124]], "302551": [[1, 7]], "302553": [[1, 188]], "302554": [[1, 7]], "302555": [[1, 11]], "302563": [[40, 46]], "302565": [[1, 7]], "302572": [[6, 291]], "302573": [[1, 693], [730, 1285]], "302596": [[47, 534], [545, 705], [710, 986]], "302597": [[1, 1054]], "302634": [[37, 73], [75, 123], [125, 129], [133, 165], [168, 175], [177, 216], [218, 358], [361, 375], [378, 404], [407, 423], [425, 503], [505, 578], [581, 594], [596, 638]], "302635": [[1, 22], [24, 28], [30, 39], [41, 53], [55, 132], [134, 144], [146, 265], [267, 271], [274, 344], [347, 357], [359, 375], [378, 384], [386, 414], [416, 494], [497, 608], [611, 634], [637, 684], [687, 706], [708, 724], [726, 901], [904, 954], [957, 982], [984, 1072], [1075, 1124], [1126, 1129], [1132, 1206], [1209, 1234], [1236, 1291]], "302651": [[1, 149]], "302654": [[1, 317]], "302661": [[1, 72]], "302663": [[1, 706]], "303825": [[1, 180]], "303832": [[54, 1334], [1338, 1913]], "303838": [[54, 54], [83, 2044]], "303885": [[60, 2052]], "303948": [[55, 1678]], "303998": [[58, 319]], "303999": [[1, 751]], "304000": [[1, 56]], "304062": [[54, 2014]], "304119": [[71, 138], [143, 150]], "304120": [[1, 253]], "304125": [[1, 1769]], "304144": [[76, 2596], [2598, 2656]], "304158": [[165, 1750], [1752, 2087]], "304169": [[50, 1714], [1731, 1733]], "304170": [[1, 620]], "304199": [[10, 18]], "304200": [[1, 321]], "304204": [[55, 607]], "304209": [[52, 98], [100, 133], [135, 157], [176, 253], [255, 477]], "304291": [[56, 85]], "304292": [[1, 1125], [1183, 1779], [1781, 1811]], "304333": [[74, 1653]], "304354": [[82, 295]], "304366": [[44, 1387], [1390, 1396], [1399, 1402], [1404, 1407], [1409, 1412], [1414, 1416], [1419, 1421], [1424, 1873]], "304446": [[40, 92], [110, 111]], "304447": [[1, 534], [540, 1644]], "304451": [[1, 60]], "304505": [[60, 86]], "304506": [[1, 370]], "304507": [[1, 239]], "304508": [[1, 1324]], "304562": [[52, 56], [60, 848]], "304616": [[52, 223], [227, 740], [747, 1002]], "304625": [[73, 536]], "304626": [[1, 8]], "304654": [[53, 704]], "304655": [[1, 1194]], "304661": [[53, 67], [69, 143], [147, 173], [175, 198], [237, 240]], "304662": [[1, 150]], "304663": [[1, 689]], "304671": [[51, 1193]], "304672": [[1, 60]], "304737": [[69, 149]], "304738": [[1, 1681]], "304739": [[3, 16]], "304740": [[1, 278]], "304776": [[49, 98]], "304777": [[1, 431], [438, 510]], "304778": [[4, 1300]], "304797": [[28, 87], [91, 306], [308, 377], [385, 1202], [1205, 2950]], "305044": [[3, 203], [302, 306], [309, 310], [313, 313], [318, 330]], "305045": [[1, 873]], "305046": [[1, 667], [671, 686]], "305059": [[63, 518], [520, 575]], "305062": [[1, 8]], "305063": [[1, 35]], "305064": [[1, 2045]], "305081": [[52, 1107]], "305112": [[68, 1527]], "305113": [[9, 72]], "305114": [[1, 526]], "305178": [[69, 124]], "305179": [[1, 21]], "305180": [[1, 9]], "305181": [[1, 8]], "305182": [[1, 8]], "305183": [[1, 231], [262, 266]], "305184": [[1, 8]], "305186": [[1, 112], [120, 422]], "305188": [[1, 1002]], "305202": [[74, 132], [136, 729]], "305204": [[1, 1229]], "305207": [[52, 1077]], "305208": [[1, 372]], "305234": [[52, 99]], "305236": [[1, 23]], "305237": [[1, 16], [18, 1147]], "305247": [[57, 433]], "305248": [[1, 957]], "305252": [[1, 548]], "305282": [[75, 207]], "305310": [[60, 157], [163, 458]], "305311": [[1, 153]], "305312": [[1, 227]], "305313": [[1, 741]], "305314": [[1, 404]], "305336": [[36, 241]], "305338": [[1, 107]], "305341": [[1, 503]], "305349": [[1, 34]], "305350": [[1, 21]], "305351": [[1, 868]], "305358": [[91, 231], [233, 253]], "305364": [[50, 147]], "305365": [[1, 668], [676, 832]], "305366": [[1, 721], [724, 756], [769, 1254]], "305376": [[71, 168]], "305377": [[9, 1292], [1294, 1383], [1386, 1525]], "305405": [[44, 536], [573, 575]], "305406": [[1, 394], [401, 520], [528, 535], [540, 1475]], "305440": [[20, 291]], "305441": [[1, 121]], "305516": [[46, 518], [558, 639]], "305517": [[1, 163]], "305518": [[1, 1134]], "305586": [[53, 583]], "305589": [[1, 691]], "305590": [[1, 500], [517, 1020]], "305636": [[60, 339], [342, 667], [671, 2390]], "305766": [[55, 902]], "305809": [[56, 197]], "305814": [[85, 689], [692, 978], [980, 1074], [1077, 1912]], "305821": [[59, 830]], "305832": [[87, 266]], "305840": [[1, 1144]], "305842": [[1, 862]], "305862": [[81, 705]], "305898": [[70, 780]], "305902": [[53, 521]], "305967": [[1, 32]], "306029": [[63, 96]], "306030": [[1, 110]], "306036": [[60, 63]], "306037": [[1, 49]], "306038": [[1, 139]], "306041": [[1, 320]], "306042": [[1, 371]], "306048": [[1, 140]], "306049": [[1, 358]], "306051": [[1, 415]], "306091": [[422, 629]], "306092": [[1, 588], [593, 976]], "306095": [[1, 300]], "306121": [[57, 152]], "306122": [[1, 127]], "306125": [[1, 756], [770, 2642], [2667, 3007]], "306126": [[1, 497]], "306134": [[53, 84]], "306135": [[1, 1095]], "306138": [[1, 1298]], "306139": [[1, 1112]], "306153": [[78, 165]], "306154": [[1, 251], [253, 691], [709, 1233]], "306155": [[1, 1440]], "306169": [[1, 745]], "306170": [[1, 22]], "306171": [[1, 503]], "306418": [[1, 33], [35, 75]], "306419": [[1, 62]], "306420": [[1, 108]], "306422": [[9, 126]], "306423": [[1, 333]], "306432": [[1, 339]], "306454": [[13, 101]], "306455": [[1, 11]], "306456": [[1, 237], [239, 787]], "306457": [[1, 31]], "306458": [[1, 17], [20, 35], [37, 41], [43, 47], [49, 53], [56, 60], [62, 66], [68, 72], [74, 77], [79, 83], [85, 89], [93, 102], [104, 108], [110, 114], [116, 120], [122, 126], [129, 139], [141, 145], [147, 151], [153, 166], [169, 173], [175, 179], [181, 185], [187, 191], [193, 197], [200, 210], [212, 216], [218, 222], [225, 229], [231, 235], [237, 241], [243, 247], [249, 249], [252, 256], [258, 268]], "306459": [[1, 512], [514, 2275]], "306460": [[1, 73]]}
81 changes: 81 additions & 0 deletions Run2PU/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Pileup re-weigt calculation
## How to run
```
cmsrel CMSSW_10_6_2
cd CMSSW_10_6_2/src
cmsenv
git clone [email protected]:cms-tamu/MuJetAnalysis_PileupStudy.git
cd MuJetAnalysis_PileupStudy/Run2PU
./puCal.py
```
Calculation reference:

https://github.com/cms-sw/cmssw/blob/master/PhysicsTools/Utilities/src/LumiReWeighting.cc

## Edit input variable
All input variables are in puCalInPut.py
### Cross-section setting
nomXsec = 69200.0 # minBiasXsec, recommended cross-section 69.2 mb

uncertainty = 0.05 # pileup uncertainty, recommended ± 4.6 %

https://twiki.cern.ch/twiki/bin/view/CMS/PileupJSONFileforData#Recommended_cross_section

### Bin setting
nBins = 100

maxBin = 100

### Pileup calculation on/off for run
cal16=True # or False

cal17=True # or False

cal18=True # or False

### MC distribution
2016: mix_2016_25ns_Moriond17MC_PoissonOOTPU_cfi

2017: mix_2017_25ns_WinterMC_PUScenarioV1_PoissonOOTPU_cfi

2018: mix_2018_25ns_UltraLegacy_PoissonOOTPU_cfi

https://github.com/cms-sw/cmssw/tree/master/SimGeneral/MixingModule/python

### LimiBlock JSON
2017 JSON includes 2017C, D, E, and F (excludes 2017A and B)

### Default setting
```
nomXsec = 69200.0
uncertainty = 0.05
#uncertainty = 0.046
nBins = 100
maxBin = 100

cal16=True
cal17=True
cal18=True

#from SimGeneral.MixingModule.mix_2016_PoissonOOTPU_HighPUTrains_Fill5412_cfi import mix as mc16
#from SimGeneral.MixingModule.mix_2016_25ns_SpringMC_PUScenarioV1_PoissonOOTPU_cfi import mix as mc16
from SimGeneral.MixingModule.mix_2016_25ns_Moriond17MC_PoissonOOTPU_cfi import mix as mc16
nMC16 = mc16.input.nbPileupEvents.probValue

from SimGeneral.MixingModule.mix_2017_25ns_WinterMC_PUScenarioV1_PoissonOOTPU_cfi import mix as mc17
#from SimGeneral.MixingModule.mix_2017_25ns_UltraLegacy_PoissonOOTPU_cfi import mix as mc17
nMC17 = mc17.input.nbPileupEvents.probValue

#from SimGeneral.MixingModule.mix_2018_25ns_JuneProjectionFull18_PoissonOOTPU_cfi import mix as mc18
#from SimGeneral.MixingModule.mix_2018_25ns_ProjectedPileup_PoissonOOTPU_cfi import mix as mc18
from SimGeneral.MixingModule.mix_2018_25ns_UltraLegacy_PoissonOOTPU_cfi import mix as mc18
nMC18 = mc18.input.nbPileupEvents.probValue

PUJSON16 = "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/PileUp/pileup_latest.txt"
PUJSON17 = "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions17/13TeV/PileUp/pileup_latest.txt"
PUJSON18 = "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions18/13TeV/PileUp/pileup_latest.txt"
JSON16 = "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/Final/Cert_271036-284044_13TeV_PromptReco_Collisions16_JSON.txt"
#JSON17 = "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions17/13TeV/Final/Cert_294927-306462_13TeV_PromptReco_Collisions17_JSON.txt"
JSON17 = "./Cert_294927-306462_13TeV_PromptReco_Collisions17_JSON.txt" #trim run2017A and run2017B
JSON18 = "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions18/13TeV/ReReco/Cert_314472-325175_13TeV_17SeptEarlyReReco2018ABC_PromptEraD_Collisions18_JSON.txt"
```
135 changes: 135 additions & 0 deletions Run2PU/puCal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env python
import os
if os.getenv("CMSSW_BASE") == None:
print "no CMSSW env"
exit()
if not os.getenv("HOSTNAME").startswith("lxplus"):
print "run on lxplus"
exit()

from puCalInPut import *
upXsec = nomXsec*(1.0+uncertainty)
dnXsec = nomXsec*(1.0-uncertainty)

nomH1 = "puNom"
upH1 = "puUp"
dnH1 = "puDn"

tmpSh = """#!/bin/bash
JSON={json}
echo $JSON >> {log}
PUJSON={pujson}
echo $PUJSON >> {log}
echo "nominal {nomXsec}" >> {log}
echo "dn {dnXsec}" >> {log}
echo "up {upXsec}" >> {log}
echo "nominal log" >> {log}
pileupCalc.py -i $JSON --inputLumiJSON $PUJSON --calcMode true --minBiasXsec {nomXsec} --maxPileupBin {maxBin} --numPileupBins {nBins} --pileupHistName={nomH1} {nomROOT}| tee >> {log}
echo "dn log" >> {log}
pileupCalc.py -i $JSON --inputLumiJSON $PUJSON --calcMode true --minBiasXsec {dnXsec} --maxPileupBin {maxBin} --numPileupBins {nBins} --pileupHistName={dnH1} {dnROOT}| tee >> {log}
echo "up log" >> {log}
pileupCalc.py -i $JSON --inputLumiJSON $PUJSON --calcMode true --minBiasXsec {upXsec} --maxPileupBin {maxBin} --numPileupBins {nBins} --pileupHistName={upH1} {upROOT}| tee >> {log}
echo "output ROOT file: {totROOT}">> {log}
hadd {totROOT} {nomROOT} {upROOT} {dnROOT}
sha1sum {totROOT} | tee >> {log}
rm {nomROOT} {upROOT} {dnROOT}"""

def calPU(year):
yList = [16,17,18]
mcMap = {16:nMC16, 17:nMC17, 18:nMC18}
jsonMap = {16:JSON16, 17:JSON17, 18:JSON18}
pujsonMap = {16:PUJSON16, 17:PUJSON17, 18:PUJSON18}
if year not in yList:
print "wrong year input"
return
print "start pu{} cal.".format(year)
rfName = "pu{year}_{nBins}.root".format(**{'year':year,'nBins':nBins})
logName = rfName.replace(".root",".log")
if rfName not in os.listdir("."):
print "{} to be generated.".format(rfName)
os.system(tmpSh.format(**{'json':jsonMap[year], 'pujson':pujsonMap[year], 'nomXsec':nomXsec, 'upXsec':upXsec, 'dnXsec':dnXsec, 'nBins':nBins, 'maxBin':maxBin, 'nomH1':nomH1, 'upH1':upH1, 'dnH1':dnH1, 'nomROOT':"pu{}nom.root".format(year), 'upROOT':"pu{}up.root".format(year), 'dnROOT':"pu{}dn.root".format(year), 'totROOT':rfName, 'log':logName}))
else:
try:
logF = open(logName)
if not logF.readline().startswith(jsonMap[year]): print "WARNING! JSON is not matched with log"
if not logF.readline().startswith(pujsonMap[year]): print "WARNING! PU JSON is not matched with log"
if float(logF.readline().split()[1]) != nomXsec: print "WARNING! nomXsec is not matched with log"
if float(logF.readline().split()[1]) != dnXsec: print "WARNING! dnXsec is not matched with log"
if float(logF.readline().split()[1]) != upXsec: print "WARNING! upXsec is not matched with log"
if logF.readlines()[-1] != os.popen("sha1sum "+rfName).read(): print "WARNING! root file hash is not matched with log"
except: print "WARNING! no log file, can't check log"
c = TCanvas("","",800,500)
color = {'puNom':kBlack, 'puUp':kRed-4, 'puDn':kBlue-4, 'mc':kViolet-4}
rf = TFile(rfName)
mc = TH1D("mc","mc",nBins,0,maxBin)
if len(mcMap[year]) < nBins: mcMap[year].extend([0.0]*(nBins-len(mcMap[year])))
for x in range(nBins):
mc.SetBinContent(x+1,mcMap[year][x])
hList = [mc, rf.Get(nomH1), rf.Get(upH1), rf.Get(dnH1)]
for x in hList:
x.SetLineWidth(2)
x.SetLineColor(color[x.GetName()])
x.SetXTitle("N_{TrueInteractions}")
if x.Integral() > 1.1: x.Scale(1./x.Integral())
x.Draw("HIST")
c.SaveAs("nom{}_".format(year)+x.GetName()+".png")

maxY = max([x.GetMaximum() for x in hList])*1.1
hList[0].SetMaximum(maxY)
hList[0].Draw("HIST")
le = TLegend(0.5,0.7,0.8,0.9)
le.SetTextSize(0.035)
le.SetFillStyle(0)
le.SetBorderSize(0)
for x in hList:
x.Draw("HIST same")
le.AddEntry(x, x.GetName())

le.Draw()
rwH = []
c.SaveAs("tot{}.png".format(year))
for x in hList[1:]:
tmp = x.Clone("reWeight_"+x.GetName())
tmp.Divide(hList[0])
rwH.append(tmp)
tmp.SetYTitle("puileup re-weight")
tmp.Draw("HIST")
c.SaveAs("rw{}_".format(year)+x.GetName()+".png")
tmp.GetXaxis().SetRange(1,51)
tmp.Draw("HIST")
c.SaveAs("rw{}_".format(year)+x.GetName()+"_range.png")
rfo = TFile("pu{}reWeight.root".format(year),"RECREATE")
for h in hList:
h.Write()
for h in rwH:
h.Write()
rfo.Write()
rfo.Close()
nom = [rwH[0].GetBinContent(x+1) for x in range(nBins)]
up = [rwH[1].GetBinContent(x+1) for x in range(nBins)]
dn = [rwH[2].GetBinContent(x+1) for x in range(nBins)]
outF = file("pu{}reWeight.py".format(year),"w")

outF.write("nom = [")
for x in nom:
outF.write("{:.8e}".format(x))
outF.write("]\n")
outF.write("dn = [")
for x in dn:
outF.write("{:.8e}".format(x))
outF.write("]\n")
outF.write("up = [")
for x in up:
outF.write("{:.8e}".format(x))
outF.write("]\n")
outF.close()

if __name__ == '__main__':
from ROOT import *
gROOT.SetBatch(1)
gStyle.SetOptStat(0)

if cal16: calPU(16)
if cal17: calPU(17)
if cal18: calPU(18)

Loading