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