ATLAS Offline Software
Loading...
Searching...
No Matches
ICHEP2016/MakeFileForMJB.py
Go to the documentation of this file.
1# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2
3from ROOT import *
4from array import array
5import sys
6import os
7import glob
8import re
9import math
10
11from ParseEtaIntercalInput import ReadEtaIntercalibrationHistograms
12from ParseInsituInput_MJB import ReadInSituHistograms
13from ParsePileupInput import ReadPileupHistograms
14from ParseFlavourInput import ReadFlavourHistograms
15from ParsePunchthroughInput import ReadPunchthroughHistograms
16from Parse2012Input import Read2012Histograms
17
18#http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
19from itertools import groupby
21 return [int(''.join(g)) if k else ''.join(g) for k, g in groupby(s[0], str.isdigit)]
22
23# Option 2
24#
25# Design: This is to make a file entirely from scratch.
26# All components are assumed available new.
27# If that is not the case borrow parallel script from
28# the Moriond 2016 directory (where punchthrough was kept from 2012)
29
30# Full list of required inputs, distinguished by needing them
31# from a different person
32# - In situ terms
33# - Eta intercalibration
34# - Pileup
35# - Flavour
36# - Punchthrough
37
38
39# NOTES
40# Need to carefully check all flavour histograms in comparison to 2012 to make sure they look sensible!!
41# Things below were done in pre-recs and are currently being done here:
42# - 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.
43# - FlavorResponse histogram inverted from input file to match Run I convention
44freezeFlavourInPt = True
45
46
47
48# Check useage and store arguments
49if len(sys.argv) < 3:
50 print "USAGE: Expected the following arguments"
51 print " 1. Directory path to V+jet calibrations"
52 print " 2. Eta intercalibration directory path"
53 print " 3. Pileup directory path"
54 print " 5. Flavour directory path"
55 print " 6. Punchthrough directory path"
56 exit(1)
57
58outBaselineFile = "JESUncertainty_forMJB.root"
59theVPlusJetsDir = sys.argv[1]
60etaIntercalDir = sys.argv[2]
61pileupDir = sys.argv[3]
62flavourDir = sys.argv[4]
63punchthroughDir = sys.argv[5]
64
65# Ensure that all of the directories exist
66if not outBaselineFile.endswith(".root"):
67 print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
68 exit(2)
69if not os.path.exists(theVPlusJetsDir):
70 print "V+jets directory does not exist:",theVPlusJetsDir
71 exit(3)
72if not os.path.exists(etaIntercalDir):
73 print "Eta intercalibration directory does not exist:",etaIntercalDir
74 exit(4)
75if not os.path.exists(pileupDir):
76 print "Pileup directory does not exist:",pileupDir
77 exit(5)
78if not os.path.exists(flavourDir):
79 print "Flavour directory does not exist:",flavourDir
80 exit(6)
81if not os.path.exists(punchthroughDir):
82 print "Punchthrough directory does not exist:",punchthroughDir
83 exit(7)
84
85
86# Store everything in memory!
87currentDir = gDirectory
88gROOT.cd()
89
90# Now read the histograms
91print "Reading inputs..."
92# For now, everything except flavour and cross calibration inputs
93# are read in from the final 2012 calibration files.
94theVPlusJetsHistos = ReadInSituHistograms(theVPlusJetsDir) # Check!
95etaIntercalHistos = ReadEtaIntercalibrationHistograms(etaIntercalDir)
96pileupHistos = ReadPileupHistograms(pileupDir)
97print "For pileup, got:"
98for jetdef in pileupHistos.keys() :
99 print "Jet def",jetdef
100 print pileupHistos[jetdef]
101
102flavourHistos = ReadFlavourHistograms(flavourDir,freezeFlavourInPt) # True flag freezes uncertainty above pT = 2TeV (lower at higher eta)
103print "For flavour, got:"
104for jetdef in flavourHistos.keys() :
105 print "Jet def",jetdef
106 print flavourHistos[jetdef]
107
108punchthroughHistos = ReadPunchthroughHistograms(punchthroughDir)
109print "For punchthrough, got:"
110for jetdef in punchthroughHistos.keys() :
111 print "Jet def",jetdef
112 print punchthroughHistos[jetdef]
113
114# Make one mega-dictionary
115print "Merging inputs..."
116jetDefs = {"AntiKt4Topo_EMJES" : "AntiKt4EMTopo", "AntiKt4Topo_LCJES" : "AntiKt4LCTopo"}#"AntiKt6Topo_EMJES","AntiKt6Topo_LCJES"]
117systematics = {}
118for aJetDef in jetDefs.keys():
119
120 systematics[aJetDef] = {}
121 dictsToUse = [punchthroughHistos,
122 etaIntercalHistos,
123 theVPlusJetsHistos,
124 pileupHistos,
125 flavourHistos]
126
127 for dictionary in dictsToUse :
128
129 # We don't have LC inputs for some of these
130 #if "LC" in aJetDef :
131 # if aJetDef not in dictionary.keys() :
132 # useInstead = dictionary["AntiKt4Topo_EMJES"]
133 # Need to change name & copy hists so I don't have
134 # memory problems down the road
135 # myNewDict = {}
136 # for item in useInstead.keys() :
137 # thisHist = useInstead[item].Clone()
138 # thisHistName = useInstead[item].GetName().replace("EM","LC")
139 # thisHist.SetName(thisHistName)
140 # myNewDict[item] = thisHist
141
142 # dictionary[aJetDef] = myNewDict
143
144 systematics[aJetDef].update(dictionary[aJetDef].items())
145
146 print "\nFor jet def",aJetDef,"added:"
147 print systematics[aJetDef]
148
149
150# Loop over the mega-dictionary and write results
151print "Writing to output file",outBaselineFile,"..."
152baselineFile = TFile(outBaselineFile,"RECREATE")
153for aJetDef,aSyst in sorted(systematics.iteritems(),key=natural_sort):
154 for aSystName,aSystHisto in sorted(aSyst.iteritems(),key=natural_sort):
155 baselineFile.cd()
156 aSystHisto.SetTitle(aSystName+"_"+jetDefs[aJetDef])
157 aSystHisto.Write(aSystHisto.GetTitle())
158
159# Done, close the files, revert directory
160baselineFile.Close()
161gDirectory = currentDir
162print "Done!"
163