ATLAS Offline Software
Moriond2016/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 Parse2012Input import Read2012Histograms
12 from ParseEtaIntercalInput import ReadEtaIntercalibrationHistograms
13 from ParseInsituInput import ReadInSituHistograms
14 from ParsePileupInput import ReadPileupHistograms
15 from ParseNonClosureInput import ReadNonClosureHistograms
16 from ParseHighPtInput import ReadHighPtHistograms,ReadHighPtHistogramsFromOldFile
17 from ParseFlavourInput import ReadFlavourHistograms
18 from ParsebJESInput import ReadBJESHistograms
19 from ParsePunchthroughInput import ReadPunchthroughHistograms
20 
21 #http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
22 from itertools import groupby
23 def 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
48 freezeFlavourInPt = True
49 
50 
51 
52 # Check useage and store arguments
53 if 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 
65 outBaselineFile = "JESUncertainty_AllComponents_Moriond2016.root"
66 inSituDir = sys.argv[1]
67 etaIntercalDir = sys.argv[2]
68 highPtDir = sys.argv[3]
69 nonclosureDir = sys.argv[4]
70 pileupDir = sys.argv[5]
71 flavourDir = sys.argv[6]
72 bJESDir = sys.argv[7]
73 punchthroughDir = sys.argv[8]
74 
75 # Ensure that all of the directories exist
76 if not outBaselineFile.endswith(".root"):
77  print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
78  exit(2)
79 if not os.path.exists(inSituDir):
80  print "InSitu directory does not exist:",inSituDir
81  exit(3)
82 if not os.path.exists(etaIntercalDir):
83  print "Eta intercalibration directory does not exist:",etaIntercalDir
84  exit(4)
85 if not os.path.exists(highPtDir):
86  print "HighPt directory does not exist:",highPtDir
87  exit(5)
88 if not os.path.exists(nonclosureDir):
89  print "MC nonclosure directory does not exist:",nonclosureDir
90  exit(6)
91 if not os.path.exists(pileupDir):
92  print "Pileup directory does not exist:",pileupDir
93  exit(7)
94 if not os.path.exists(flavourDir):
95  print "Flavour directory does not exist:",flavourDir
96  exit(8)
97 if not os.path.exists(bJESDir):
98  print "bJES directory does not exist:",bJESDir
99  exit(9)
100 if not os.path.exists(punchthroughDir):
101  print "Punchthrough directory does not exist:",punchthroughDir
102  exit(10)
103 
104 # Store everything in memory!
105 currentDir = gDirectory
106 gROOT.cd()
107 
108 # Now read the histograms
109 print "Reading inputs..."
110 # For now, the high pT component
111 # is read in from the final 2012 calibration files.
112 inSituHistos = ReadInSituHistograms(inSituDir)
113 etaIntercalHistos = ReadEtaIntercalibrationHistograms(etaIntercalDir)
114 highPtHistos = ReadHighPtHistogramsFromOldFile(highPtDir)#ReadHighPtHistograms(highPtDir)
115 nonclosureHistos = ReadNonClosureHistograms(nonclosureDir,True)
116 pileupHistos = ReadPileupHistograms(pileupDir)
117 flavourHistos = ReadFlavourHistograms(flavourDir,freezeFlavourInPt) # True flag freezes uncertainty above pT = 2TeV (lower at higher eta)
118 bJESHistos = ReadBJESHistograms(bJESDir)
119 punchthroughHistos = ReadPunchthroughHistograms(punchthroughDir)
120 
121 # Make one mega-dictionary
122 print "Merging inputs..."
123 jetDefs = {"AntiKt4Topo_EMJES" : "AntiKt4EMTopo"}#,"AntiKt4Topo_LCJES","AntiKt6Topo_EMJES","AntiKt6Topo_LCJES"]
124 systematics = {}
125 for 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
141 print "Writing to output file",outBaselineFile,"..."
142 baselineFile = TFile(outBaselineFile,"RECREATE")
143 for 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
150 baselineFile.Close()
151 gDirectory = currentDir
152 print "Done!"
153 
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