ATLAS Offline Software
Loading...
Searching...
No Matches
Final2012/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 ParseEtaIntercalInput import ReadEtaIntercalibrationHistograms
12from ParseInsituInput import ReadInSituHistograms
13from ParsePileupInput import ReadPileupHistograms
14from ParseNonClosureInput import ReadNonClosureHistograms
15from ParseHighPtInput import ReadHighPtHistograms
16from ParseFlavourInput import ReadFlavourHistograms
17from ParsebJESInput import ReadBJESHistograms
18from ParsePunchthroughInput import ReadPunchthroughHistograms
19
20
21#http://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python
22from itertools import groupby
24 return [int(''.join(g)) if k else ''.join(g) for k, g in groupby(s[0], str.isdigit)]
25
26# Check useage and store arguments
27if len(sys.argv) < 9:
28 print "USAGE: Expected the following arguments"
29 print " 1. Eta intercalibration directory path"
30 print " 2. InSitu directory path"
31 print " 3. Pileup directory path"
32 print " 4. MC nonclosure directory path"
33 print " 5. HighPt directory path"
34 print " 6. Flavour directory path"
35 print " 7. bJES directory path"
36 print " 8. Punchthrough directory path"
37 exit(1)
38
39outBaselineFile = "JESUncertainty_BaseComponents_2012.root"
40outMultijetFile = "MJESUncertainty_2012.root"
41etaIntercalDir = sys.argv[1]
42inSituDir = sys.argv[2]
43pileupDir = sys.argv[3]
44nonclosureDir = sys.argv[4]
45highPtDir = sys.argv[5]
46flavourDir = sys.argv[6]
47bJESDir = sys.argv[7]
48punchthroughDir = sys.argv[8]
49
50# Ensure that all of the directories exist
51if not outBaselineFile.endswith(".root"):
52 print "Output baseline ROOT file doesn't appear to be a root file:",outBaselineFile
53 exit(2)
54if not outMultijetFile.endswith(".root"):
55 print "Output multijet ROOT file doesn't appear to be a root file:",outMultijetFile
56 exit(3)
57if not os.path.exists(etaIntercalDir):
58 print "Eta intercalibration directory does not exist:",etaIntercalDir
59 exit(4)
60if not os.path.exists(inSituDir):
61 print "InSitu directory does not exist:",inSituDir
62 exit(5)
63if not os.path.exists(pileupDir):
64 print "Pileup directory does not exist:",pileupDir
65 exit(6)
66if not os.path.exists(nonclosureDir):
67 print "MC nonclosure directory does not exist:",nonclosureDir
68 exit(7)
69if not os.path.exists(highPtDir):
70 print "HighPt directory does not exist:",highPtDir
71 exit(8)
72if not os.path.exists(flavourDir):
73 print "Flavour directory does not exist:",flavourDir
74 exit(9)
75if not os.path.exists(bJESDir):
76 print "bJES directory does not exist:",bJESDir
77 exit(10)
78if not os.path.exists(punchthroughDir):
79 print "Punchthrough directory does not exist:",punchthroughDir
80 exit(11)
81
82# Store everything in memory!
83currentDir = gDirectory
84gROOT.cd()
85
86
87# Now read the histograms
88print "Reading inputs..."
89etaIntercalHistos = ReadEtaIntercalibrationHistograms(etaIntercalDir)
90inSituHistos = ReadInSituHistograms(inSituDir)
91pileupHistos = ReadPileupHistograms(pileupDir)
92nonclosureHistos = ReadNonClosureHistograms(nonclosureDir)
93highPtHistos = ReadHighPtHistograms(highPtDir)
94flavourHistos = ReadFlavourHistograms(flavourDir)
95bJESHistos = ReadBJESHistograms(bJESDir)
96punchthroughHistos = ReadPunchthroughHistograms(punchthroughDir)
97
98#print etaIntercalHistos
99
100# Make one mega-dictionary
101print "Merging inputs..."
102jetDefs = ["AntiKt4Topo_EMJES","AntiKt4Topo_LCJES","AntiKt6Topo_EMJES","AntiKt6Topo_LCJES"]
103systematics = {}
104for aJetDef in jetDefs:
105 systematics[aJetDef] = dict(
106 etaIntercalHistos[aJetDef].items() +
107 inSituHistos[aJetDef].items() +
108 pileupHistos[aJetDef].items() +
109 nonclosureHistos[aJetDef].items() +
110 highPtHistos[aJetDef].items() +
111 flavourHistos[aJetDef].items() +
112 bJESHistos[aJetDef].items() +
113 punchthroughHistos[aJetDef].items()
114 )
115
116# Loop over the mega-dictionary and write results
117print "Writing to output file..."
118baselineFile = TFile(outBaselineFile,"RECREATE")
119multijetFile = TFile(outMultijetFile,"RECREATE")
120for aJetDef,aSyst in sorted(systematics.iteritems(),key=natural_sort):
121 for aSystName,aSystHisto in sorted(aSyst.iteritems(),key=natural_sort):
122 if "bJES" in aSystName or "flavor" in aSystName or "Flavor" in aSystName or "PunchThrough" in aSystName or "Close" in aSystName:
123 multijetFile.cd()
124 else:
125 baselineFile.cd()
126
127 aSystHisto.SetTitle(aSystName+"_"+aJetDef)
128 aSystHisto.Write(aSystHisto.GetTitle())
129
130# Done, close the files, revert directory
131baselineFile.Close()
132multijetFile.Close()
133gDirectory = currentDir
134print "Done!"
135