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