ATLAS Offline Software
Loading...
Searching...
No Matches
January2018_specialStatTerms/MakeFileForMJB.py
Go to the documentation of this file.
1from ROOT import *
2from array import array
3import sys
4import os
5import glob
6import re
7import math
8
9from ParseEtaIntercalInput import ReadEtaIntercalibrationHistograms
10from ParseInsituInput_MJB import ReadInSituHistograms
11from ParsePileupInput import ReadPileupHistograms
12from ParseFlavourInput import ReadFlavourHistograms
13from ParsePunchthroughInput import ReadPunchthroughHistograms
14from Parse2012Input import Read2012Histograms
15
16#http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
17from itertools import groupby
18def natural_sort(s):
19 return [int(''.join(g)) if k else ''.join(g) for k, g in groupby(s[0], str.isdigit)]
20
21# Design: This is to make a file entirely from scratch.
22# All components are assumed available in new versions.
23# If that is not the case borrow parallel script from
24# the Moriond 2016 directory (where punchthrough was kept from 2012)
25
26# Full list of required inputs, distinguished by needing them
27# from a different person
28# - In situ terms
29# - Eta intercalibration
30# - Pileup
31# - Flavour
32# - Punchthrough
33
34
35# NOTES
36# For this Moriond release, all MC histograms being kept from 20.1 as no changes observed to MC.
37# Thus flavour histograms already validated at an earlier stage.
38# Things below were done in pre-recs and are currently being done here:
39# - Freeze flavour histograms by hand wherever input histogram falls below 0: extrapolate forward in pT from around 2 TeV centrally and from lower pT as eta increases.
40# - FlavorResponse histogram inverted from input file to match Run I convention
41freezeFlavourInPt = False
42# Punchthrough needs to be checked to ensure axes are where we think they are
43# Eta intercalibration currently includes TWO non-closure terms:
44# - one with all bins used
45# - one with only bins in 2.0 to 2.6 used (consider this an OFC uncertainty)
46# Pileup fixed <mu> and <NPV> values are being kept from 2015 at this stage.
47# In situ terms:
48# - Using OOC from DB for MPF Z+jet results
49# - Using small value MC generator uncertainty in Z+jets
50# essentially due to how close nominal and alternate
51# samples are. Not prioritising rebinned version, since fluctuations
52# appear statistical.
53
54
55
56# Check useage and store arguments
57if len(sys.argv) < 3:
58 print "USAGE: Expected the following arguments"
59 print " 1. Directory path to V+jet calibrations"
60 print " 2. Eta intercalibration directory path"
61 print " 3. Pileup directory path"
62 print " 5. Flavour directory path"
63 print " 6. Punchthrough directory path"
64 exit(1)
65
66outBaselineFile = "JESUncertainty_forMJB.root"
67theVPlusJetsDir = sys.argv[1]
68etaIntercalDir = sys.argv[2]
69pileupDir = sys.argv[3]
70flavourDir = sys.argv[4]
71punchthroughDir = sys.argv[5]
72
73# Ensure that all of the directories exist
74if not outBaselineFile.endswith(".root"):
75 print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
76 exit(2)
77if not os.path.exists(theVPlusJetsDir):
78 print "V+jets directory does not exist:",theVPlusJetsDir
79 exit(3)
80if not os.path.exists(etaIntercalDir):
81 print "Eta intercalibration directory does not exist:",etaIntercalDir
82 exit(4)
83if not os.path.exists(pileupDir):
84 print "Pileup directory does not exist:",pileupDir
85 exit(5)
86if not os.path.exists(flavourDir):
87 print "Flavour directory does not exist:",flavourDir
88 exit(6)
89if not os.path.exists(punchthroughDir):
90 print "Punchthrough directory does not exist:",punchthroughDir
91 exit(7)
92
93
94# Store everything in memory!
95currentDir = gDirectory
96gROOT.cd()
97
98# Now read the histograms
99print "Reading inputs..."
100# For now, everything except flavour and cross calibration inputs
101# are read in from the final 2012 calibration files.
102theVPlusJetsHistos = ReadInSituHistograms(theVPlusJetsDir) # Check!
103etaIntercalHistos = ReadEtaIntercalibrationHistograms(etaIntercalDir)
104pileupHistos = ReadPileupHistograms(pileupDir)
105
106flavourHistos = ReadFlavourHistograms(flavourDir,freezeFlavourInPt) # True flag freezes uncertainty above pT = 2TeV (lower at higher eta)
107
108punchthroughHistos = ReadPunchthroughHistograms(punchthroughDir)
109
110# Make one mega-dictionary
111print "Merging inputs..."
112jetDefs = {"AntiKt4Topo_EMJES" : "AntiKt4EMTopo", "AntiKt4PFlow_EMJES" : "AntiKt4EMPFlow"}
113systematics = {}
114for aJetDef in jetDefs.keys():
115
116 systematics[aJetDef] = {}
117 dictsToUse = [punchthroughHistos,
118 etaIntercalHistos,
119 theVPlusJetsHistos,
120 pileupHistos,
121 flavourHistos]
122
123 for dictionary in dictsToUse :
124 print dictionary
125 print aJetDef
126 systematics[aJetDef].update(dictionary[aJetDef].items())
127
128 print systematics[aJetDef]
129
130
131# Loop over the mega-dictionary and write results
132print "Writing to output file",outBaselineFile,"..."
133baselineFile = TFile(outBaselineFile,"RECREATE")
134for aJetDef,aSyst in sorted(systematics.iteritems(),key=natural_sort):
135 for aSystName,aSystHisto in sorted(aSyst.iteritems(),key=natural_sort):
136 baselineFile.cd()
137 aSystHisto.SetTitle(aSystName+"_"+jetDefs[aJetDef])
138 aSystHisto.Write(aSystHisto.GetTitle())
139
140# Done, close the files, revert directory
141baselineFile.Close()
142gDirectory = currentDir
143print "Done!"
144