ATLAS Offline Software
ParseInputs_Preliminary.py
Go to the documentation of this file.
1 from ROOT import *
2 from array import array
3 import sys
4 import os
5 import glob
6 import re
7 import math
8 
9 from ParseEtaIntercalInput import ReadEtaIntercalibrationHistograms
10 from ParseInsituInput_MJB import ReadInSituHistograms
11 from ParsePileupInput import ReadPileupHistograms
12 from ParseHighPtInput import ReadHighPtHistograms,ReadHighPtHistogramsFromOldFile
13 from ParseFlavourInput import ReadFlavourHistograms
14 from ParsebJESInput import ReadBJESHistograms
15 from ParsePunchthroughInput import ReadPunchthroughHistograms
16 from CreateNonClosureInput import CreateNonClosureHistograms
17 
18 #http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
19 from itertools import groupby
20 def natural_sort(s):
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
45 freezeFlavourInPt = False
46 
47 
48 
49 # Check useage and store arguments
50 if 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 
61 outBaselineFile = "JESUncertainty_AllComponents.root"
62 inSituDir = sys.argv[1]
63 etaIntercalDir = sys.argv[2]
64 highPtDir = sys.argv[3]
65 pileupDir = sys.argv[4]
66 flavourDir = sys.argv[5]
67 bJESDir = sys.argv[6]
68 punchthroughDir = sys.argv[7]
69 
70 # Ensure that all of the directories exist
71 if not outBaselineFile.endswith(".root"):
72  print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
73  exit(2)
74 if not os.path.exists(inSituDir):
75  print "InSitu directory does not exist:",inSituDir
76  exit(3)
77 if not os.path.exists(etaIntercalDir):
78  print "Eta intercalibration directory does not exist:",etaIntercalDir
79  exit(4)
80 if not os.path.exists(highPtDir):
81  print "HighPt directory does not exist:",highPtDir
82  exit(5)
83 if not os.path.exists(pileupDir):
84  print "Pileup directory does not exist:",pileupDir
85  exit(7)
86 if not os.path.exists(flavourDir):
87  print "Flavour directory does not exist:",flavourDir
88  exit(8)
89 if not os.path.exists(bJESDir):
90  print "bJES directory does not exist:",bJESDir
91  exit(9)
92 if not os.path.exists(punchthroughDir):
93  print "Punchthrough directory does not exist:",punchthroughDir
94  exit(10)
95 
96 # Store everything in memory!
97 currentDir = gDirectory
98 gROOT.cd()
99 
100 # Now read the histograms
101 print "Reading inputs..."
102 # For now, the high pT component
103 # is read in from the final 2012 calibration files.
104 inSituHistos = ReadInSituHistograms(inSituDir)
105 etaIntercalHistos = ReadEtaIntercalibrationHistograms(etaIntercalDir)
106 highPtHistos = ReadHighPtHistogramsFromOldFile(highPtDir)#ReadHighPtHistograms(highPtDir)
107 pileupHistos = ReadPileupHistograms(pileupDir)
108 flavourHistos = ReadFlavourHistograms(flavourDir,freezeFlavourInPt) # True flag freezes uncertainty above pT = 2TeV (lower at higher eta)
109 bJESHistos = ReadBJESHistograms(bJESDir)
110 punchthroughHistos = ReadPunchthroughHistograms(punchthroughDir)
111 nonClosureHists = CreateNonClosureHistograms()
112 
113 # Make one mega-dictionary
114 print "Merging inputs..."
115 jetDefs = {"AntiKt4Topo_EMJES" : "AntiKt4EMTopo", "AntiKt4PFlow_EMJES" : "AntiKt4EMPFlow"}
116 systematics = {}
117 for 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
131 print "Writing to output file",outBaselineFile,"..."
132 baselineFile = TFile(outBaselineFile,"RECREATE")
133 for 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
140 baselineFile.Close()
141 gDirectory = currentDir
142 print "Done!"
143 
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
ParseInputs_Preliminary.natural_sort
def natural_sort(s)
Definition: ParseInputs_Preliminary.py:20
ParseFlavourInput.ReadFlavourHistograms
def ReadFlavourHistograms(dirName)
Definition: Final2012/ParseFlavourInput.py:30
ParsebJESInput.ReadBJESHistograms
def ReadBJESHistograms(dirName)
Definition: Final2012/ParsebJESInput.py:24
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
CreateNonClosureInput.CreateNonClosureHistograms
def CreateNonClosureHistograms()
Definition: CreateNonClosureInput.py:18
ParsePileupInput.ReadPileupHistograms
def ReadPileupHistograms(dirName)
Definition: Final2012/ParsePileupInput.py:15