ATLAS Offline Software
ICHEP2016/ParseInputs.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2 
3 from ROOT import *
4 from array import array
5 import sys
6 import os
7 import glob
8 import re
9 import math
10 
11 from ParseEtaIntercalInput import ReadEtaIntercalibrationHistograms
12 from ParseInsituInput import ReadInSituHistograms
13 from ParsePileupInput import ReadPileupHistograms
14 from ParseNonClosureInput import ReadNonClosureHistograms
15 from ParseHighPtInput import ReadHighPtHistograms,ReadHighPtHistogramsFromOldFile
16 from ParseFlavourInput import ReadFlavourHistograms
17 from ParsebJESInput import ReadBJESHistograms
18 from ParsePunchthroughInput import ReadPunchthroughHistograms
19 
20 #http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
21 from itertools import groupby
22 def 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
47 freezeFlavourInPt = True
48 
49 
50 
51 # Check useage and store arguments
52 if 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 
64 outBaselineFile = "JESUncertainty_AllComponents_ICHEP2016.root"
65 inSituDir = sys.argv[1]
66 etaIntercalDir = sys.argv[2]
67 highPtDir = sys.argv[3]
68 nonclosureDir = sys.argv[4]
69 pileupDir = sys.argv[5]
70 flavourDir = sys.argv[6]
71 bJESDir = sys.argv[7]
72 punchthroughDir = sys.argv[8]
73 
74 # Ensure that all of the directories exist
75 if not outBaselineFile.endswith(".root"):
76  print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
77  exit(2)
78 if not os.path.exists(inSituDir):
79  print "InSitu directory does not exist:",inSituDir
80  exit(3)
81 if not os.path.exists(etaIntercalDir):
82  print "Eta intercalibration directory does not exist:",etaIntercalDir
83  exit(4)
84 if not os.path.exists(highPtDir):
85  print "HighPt directory does not exist:",highPtDir
86  exit(5)
87 if not os.path.exists(nonclosureDir):
88  print "MC nonclosure directory does not exist:",nonclosureDir
89  exit(6)
90 if not os.path.exists(pileupDir):
91  print "Pileup directory does not exist:",pileupDir
92  exit(7)
93 if not os.path.exists(flavourDir):
94  print "Flavour directory does not exist:",flavourDir
95  exit(8)
96 if not os.path.exists(bJESDir):
97  print "bJES directory does not exist:",bJESDir
98  exit(9)
99 if not os.path.exists(punchthroughDir):
100  print "Punchthrough directory does not exist:",punchthroughDir
101  exit(10)
102 
103 # Store everything in memory!
104 currentDir = gDirectory
105 gROOT.cd()
106 
107 # Now read the histograms
108 print "Reading inputs..."
109 # For now, the high pT component
110 # is read in from the final 2012 calibration files.
111 inSituHistos = ReadInSituHistograms(inSituDir)
112 etaIntercalHistos = ReadEtaIntercalibrationHistograms(etaIntercalDir)
113 highPtHistos = ReadHighPtHistogramsFromOldFile(highPtDir)#ReadHighPtHistograms(highPtDir)
114 nonclosureHistos = ReadNonClosureHistograms(nonclosureDir,True)
115 pileupHistos = ReadPileupHistograms(pileupDir)
116 flavourHistos = ReadFlavourHistograms(flavourDir,freezeFlavourInPt) # True flag freezes uncertainty above pT = 2TeV (lower at higher eta)
117 bJESHistos = ReadBJESHistograms(bJESDir)
118 punchthroughHistos = ReadPunchthroughHistograms(punchthroughDir)
119 
120 print nonclosureHistos
121 
122 # Make one mega-dictionary
123 print "Merging inputs..."
124 jetDefs = {"AntiKt4Topo_EMJES" : "AntiKt4EMTopo", "AntiKt4Topo_LCJES" : "AntiKt4LCTopo"}#,"AntiKt6Topo_EMJES","AntiKt6Topo_LCJES"]
125 systematics = {}
126 for 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
140 print "Writing to output file",outBaselineFile,"..."
141 baselineFile = TFile(outBaselineFile,"RECREATE")
142 for 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
149 baselineFile.Close()
150 gDirectory = currentDir
151 print "Done!"
152 
ParseNonClosureInput.ReadNonClosureHistograms
def ReadNonClosureHistograms(dirName)
Definition: Final2012/ParseNonClosureInput.py:22
ParsePunchthroughInput.ReadPunchthroughHistograms
def ReadPunchthroughHistograms(dirName)
Definition: Final2012/ParsePunchthroughInput.py:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParseHighPtInput.ReadHighPtHistogramsFromOldFile
def ReadHighPtHistogramsFromOldFile(fileName)
Definition: ICHEP2016/ParseHighPtInput.py:18
ParseEtaIntercalInput.ReadEtaIntercalibrationHistograms
def ReadEtaIntercalibrationHistograms(dirName)
Definition: Final2012/ParseEtaIntercalInput.py:19
ParseFlavourInput.ReadFlavourHistograms
def ReadFlavourHistograms(dirName)
Definition: Final2012/ParseFlavourInput.py:30
ParsebJESInput.ReadBJESHistograms
def ReadBJESHistograms(dirName)
Definition: Final2012/ParsebJESInput.py:24
ParseInputs.natural_sort
def natural_sort(s)
Definition: Final2012/ParseInputs.py:23
calibdata.exit
exit
Definition: calibdata.py:236
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
ParseInsituInput.ReadInSituHistograms
def ReadInSituHistograms(dirName)
Definition: Final2012/ParseInsituInput.py:82
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
ParsePileupInput.ReadPileupHistograms
def ReadPileupHistograms(dirName)
Definition: Final2012/ParsePileupInput.py:15