ATLAS Offline Software
Loading...
Searching...
No Matches
ICHEP2016/ParseInputs.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 import ReadInSituHistograms
13from ParsePileupInput import ReadPileupHistograms
14from ParseNonClosureInput import ReadNonClosureHistograms
15from ParseHighPtInput import ReadHighPtHistograms,ReadHighPtHistogramsFromOldFile
16from ParseFlavourInput import ReadFlavourHistograms
17from ParsebJESInput import ReadBJESHistograms
18from ParsePunchthroughInput import ReadPunchthroughHistograms
19
20#http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
21from itertools import groupby
22def natural_sort(s):
23 return [int(''.join(g)) if k else ''.join(g) for k, g in groupby(s[0], str.isdigit)]
24
25# Design: This is to make a file entirely from scratch.
26# At present the high pT term has not been updated since 2012, so
27# that one will be retrieved from the final 2012 recommendations.
28# All else is needed new.
29
30# Full list of required inputs, distinguished by needing them
31# from a different person
32# - In situ terms
33# - Eta intercalibration
34# - Single particle
35# - MC non-closure
36# - Pileup
37# - Flavour
38# - B-JES
39# - Punchthrough
40
41
42# NOTES
43# Need to carefully check all flavour histograms in comparison to 2012 to make sure they look sensible!!
44# Things below were done in pre-recs and are currently being done here:
45# - 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.
46# - FlavorResponse histogram inverted from input file to match Run I convention
47freezeFlavourInPt = True
48
49
50
51# Check useage and store arguments
52if len(sys.argv) < 3:
53 print "USAGE: Expected the following arguments"
54 print " 1. InSitu directory path"
55 print " 2. Eta intercalibration directory path"
56 print " 3. Path or directory for single-particle: currently 2012 recommendation"
57 print " 4. MC nonclosure directory path"
58 print " 5. Pileup directory path"
59 print " 6. Flavour directory path"
60 print " 7. bJES directory path"
61 print " 8. Punchthrough directory path"
62 exit(1)
63
64outBaselineFile = "JESUncertainty_AllComponents_ICHEP2016.root"
65inSituDir = sys.argv[1]
66etaIntercalDir = sys.argv[2]
67highPtDir = sys.argv[3]
68nonclosureDir = sys.argv[4]
69pileupDir = sys.argv[5]
70flavourDir = sys.argv[6]
71bJESDir = sys.argv[7]
72punchthroughDir = sys.argv[8]
73
74# Ensure that all of the directories exist
75if not outBaselineFile.endswith(".root"):
76 print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
77 exit(2)
78if not os.path.exists(inSituDir):
79 print "InSitu directory does not exist:",inSituDir
80 exit(3)
81if not os.path.exists(etaIntercalDir):
82 print "Eta intercalibration directory does not exist:",etaIntercalDir
83 exit(4)
84if not os.path.exists(highPtDir):
85 print "HighPt directory does not exist:",highPtDir
86 exit(5)
87if not os.path.exists(nonclosureDir):
88 print "MC nonclosure directory does not exist:",nonclosureDir
89 exit(6)
90if not os.path.exists(pileupDir):
91 print "Pileup directory does not exist:",pileupDir
92 exit(7)
93if not os.path.exists(flavourDir):
94 print "Flavour directory does not exist:",flavourDir
95 exit(8)
96if not os.path.exists(bJESDir):
97 print "bJES directory does not exist:",bJESDir
98 exit(9)
99if not os.path.exists(punchthroughDir):
100 print "Punchthrough directory does not exist:",punchthroughDir
101 exit(10)
102
103# Store everything in memory!
104currentDir = gDirectory
105gROOT.cd()
106
107# Now read the histograms
108print "Reading inputs..."
109# For now, the high pT component
110# is read in from the final 2012 calibration files.
111inSituHistos = ReadInSituHistograms(inSituDir)
112etaIntercalHistos = ReadEtaIntercalibrationHistograms(etaIntercalDir)
113highPtHistos = ReadHighPtHistogramsFromOldFile(highPtDir)#ReadHighPtHistograms(highPtDir)
114nonclosureHistos = ReadNonClosureHistograms(nonclosureDir,True)
115pileupHistos = ReadPileupHistograms(pileupDir)
116flavourHistos = ReadFlavourHistograms(flavourDir,freezeFlavourInPt) # True flag freezes uncertainty above pT = 2TeV (lower at higher eta)
117bJESHistos = ReadBJESHistograms(bJESDir)
118punchthroughHistos = ReadPunchthroughHistograms(punchthroughDir)
119
120print nonclosureHistos
121
122# Make one mega-dictionary
123print "Merging inputs..."
124jetDefs = {"AntiKt4Topo_EMJES" : "AntiKt4EMTopo", "AntiKt4Topo_LCJES" : "AntiKt4LCTopo"}#,"AntiKt6Topo_EMJES","AntiKt6Topo_LCJES"]
125systematics = {}
126for aJetDef in jetDefs.keys():
127
128 systematics[aJetDef] = dict(
129 inSituHistos[aJetDef].items() +
130 etaIntercalHistos[aJetDef].items() +
131 highPtHistos[aJetDef].items() +
132 nonclosureHistos[aJetDef].items() +
133 pileupHistos[aJetDef].items() +
134 flavourHistos[aJetDef].items() +
135 bJESHistos[aJetDef].items() +
136 punchthroughHistos[aJetDef].items()
137 )
138
139# Loop over the mega-dictionary and write results
140print "Writing to output file",outBaselineFile,"..."
141baselineFile = TFile(outBaselineFile,"RECREATE")
142for aJetDef,aSyst in sorted(systematics.iteritems(),key=natural_sort):
143 for aSystName,aSystHisto in sorted(aSyst.iteritems(),key=natural_sort):
144 baselineFile.cd()
145 aSystHisto.SetTitle(aSystName+"_"+jetDefs[aJetDef])
146 aSystHisto.Write(aSystHisto.GetTitle())
147
148# Done, close the files, revert directory
149baselineFile.Close()
150gDirectory = currentDir
151print "Done!"
152