ATLAS Offline Software
Loading...
Searching...
No Matches
January2018_specialStatTerms/ParseInsituInput_MJB.py
Go to the documentation of this file.
1from ROOT import *
2from array import array
3import glob
4import re
5import math
6import ProviderHistoHelpers
7import os
8
9# Dictionary to translate from Bogan's names to provider names
10SystematicNameDictionary = {
11 'gammajetdphi' : 'Gjet_dPhi',
12 'gammajetgenerator' : 'Gjet_Generator',
13 'gammajetjvt' : 'Gjet_Jvt',
14 'gammajetshower' : 'Gjet_ShowerTopology',
15 'gammajetphscalez' : 'Gjet_GamESZee',
16 'gammajetphsmear' : 'Gjet_GamEsmear',
17 'gammajetpurity' : 'Gjet_Purity',
18 'gammajetstat1' : 'Gjet_Stat1',
19 'gammajetstat2' : 'Gjet_Stat2',
20 'gammajetstat3' : 'Gjet_Stat3',
21 'gammajetstat4' : 'Gjet_Stat4',
22 'gammajetstat5' : 'Gjet_Stat5',
23 'gammajetstat6' : 'Gjet_Stat6',
24 'gammajetstat7' : 'Gjet_Stat7',
25 'gammajetstat8' : 'Gjet_Stat8',
26 'gammajetstat9' : 'Gjet_Stat9',
27 'gammajetstat10' : 'Gjet_Stat10',
28 'gammajetstat11' : 'Gjet_Stat11',
29 'gammajetstat12' : 'Gjet_Stat12',
30 'gammajetstat13' : 'Gjet_Stat13',
31 'gammajetstat14' : 'Gjet_Stat14',
32 'gammajetstat15' : 'Gjet_Stat15',
33 'gammajetstat16' : 'Gjet_Stat16',
34 'gammajetsubleadingjet' : 'Gjet_Veto',
35 'zjetdphi' : 'Zjet_dPhi',
36 'zjetescale' : 'Zjet_ElecESZee',
37 'zjetesmear' : 'Zjet_ElecEsmear',
38 'zjetgenerator' : 'Zjet_MC',
39 'zjetjvt' : 'Zjet_Jvt',
40 'zjetmuscale' : 'Zjet_MuScale',
41 'zjetmusmearid' : 'Zjet_MuSmearID',
42 'zjetmusmearms' : 'Zjet_MuSmearMS',
43 'zjetmusagittares' : 'Zjet_MuSagittaRes',
44 'zjetmusagittarho' : 'Zjet_MuSagittaRho',
45 'zjetelstat1' : 'Zjet_ElecStat1',
46 'zjetelstat2' : 'Zjet_ElecStat2',
47 'zjetelstat3' : 'Zjet_ElecStat3',
48 'zjetelstat4' : 'Zjet_ElecStat4',
49 'zjetelstat5' : 'Zjet_ElecStat5',
50 'zjetelstat6' : 'Zjet_ElecStat6',
51 'zjetelstat7' : 'Zjet_ElecStat7',
52 'zjetelstat8' : 'Zjet_ElecStat8',
53 'zjetelstat9' : 'Zjet_ElecStat9',
54 'zjetelstat10' : 'Zjet_ElecStat10',
55 'zjetelstat11' : 'Zjet_ElecStat11',
56 'zjetelstat12' : 'Zjet_ElecStat12',
57 'zjetelstat13' : 'Zjet_ElecStat13',
58 'zjetelstat14' : 'Zjet_ElecStat14',
59 'zjetmustat1' : 'Zjet_MuStat1',
60 'zjetmustat2' : 'Zjet_MuStat2',
61 'zjetmustat3' : 'Zjet_MuStat3',
62 'zjetmustat4' : 'Zjet_MuStat4',
63 'zjetmustat5' : 'Zjet_MuStat5',
64 'zjetmustat6' : 'Zjet_MuStat6',
65 'zjetmustat7' : 'Zjet_MuStat7',
66 'zjetmustat8' : 'Zjet_MuStat8',
67 'zjetmustat9' : 'Zjet_MuStat9',
68 'zjetmustat10' : 'Zjet_MuStat10',
69 'zjetmustat11' : 'Zjet_MuStat11',
70 'zjetmustat12' : 'Zjet_MuStat12',
71 'zjetmustat13' : 'Zjet_MuStat13',
72 'zjetmustat14' : 'Zjet_MuStat14',
73 'zjetsubleadingjet' : 'Zjet_Veto',
74 'zjetshower' : 'Zjet_ShowerTopology',
75 }
76
77jetDefDict = {
78 'EMJES_R4' : 'AntiKt4Topo_EMJES',
79 'LCJES_R4' : 'AntiKt4Topo_LCJES',
80 'PFJES_R4' : 'AntiKt4PFlow_EMJES'
81 }
82
83def ReadInSituHistograms(dirName):
84 if not dirName.endswith("/"):
85 dirName = dirName + "/"
86
87 # Run over each subdirectory (one per jet definition)
88 histos = {}
89 subDirs = sorted(glob.glob(dirName+"*"))
90 subDirs = [i for i in subDirs if os.path.isdir(os.path.join(os.getcwd(), i))]
91 for aSubDirName in subDirs:
92 # Determine the jet definition
93 jetDef = ""
94 for aDirDef,aJetDef in jetDefDict.iteritems():
95 if aDirDef in aSubDirName:
96 jetDef = aJetDef
97 break
98 if jetDef == "":
99 print "Failed to determine jet definition for directory:",aSubDirName
100 continue
101 else :
102 print "Jet definition is",jetDef
103 histos[jetDef] = {}
104
105 # Loop over the systematic files in the subdirectory
106 systFiles = sorted(glob.glob(aSubDirName+"/SystError_*.txt"))
107 for aSystFile in systFiles:
108 # If anything else is present, skip it
109 if not "SystError_" in aSystFile :
110 continue
111
112 # Figure out which component this is
113 systematicNameHandle = re.sub(aSubDirName+"/SystError_","",aSystFile)
114 systematicNameHandle = re.sub(".txt","",systematicNameHandle)
115 systematicName = SystematicNameDictionary[systematicNameHandle]
116 print "Making histogram %s --> %s"%(systematicNameHandle,systematicName)
117
118 # Open the file
119 systematicFile = open(aSystFile,"r")
120
121 # Read the lines of the file into arrays
122 lowBinEdges = []
123 systValues = []
124 for line in systematicFile.readlines():
125 line = line.strip("\r\n")
126 lowEdge = float(line.split()[0])
127 systVal = float(line.split()[2].strip())
128
129 lowBinEdges.append(lowEdge)
130 systValues.append(systVal)
131
132 # Done reading, close the file
133 systematicFile.close()
134
135 # Make the last bin go up to 2500
136 lowBinEdges.append(2500.)
137 systValues.append(systValues[-1])
138
139 # Turn the lists into arrays and build the 1D histogram
140 lowBinEdgesArray = array('d',lowBinEdges)
141 systValuesArray = array('d',systValues)
142 histoName = systematicName+"_"+jetDef
143 histo1D = TH1D(histoName+"_1D",histoName+"_1D",len(lowBinEdges)-1,lowBinEdgesArray)
144
145 # Fill it from the file values
146 for iBin in xrange(1,histo1D.GetNbinsX()+1):
147 histo1D.SetBinContent(iBin,systValues[iBin-1])
148
149 # Convert to a 2D provider-stlye histo -- WHY WOULD WE DO THAT
150 # STOP DOING THAT IT BREAKS THINGS
151# histo = ProviderHistoHelpers.ConvertPtHistoToProviderHisto(histo1D,histoName)
152# histo.SetDirectory(0)
153# print "Histo is type",type(histo),"whereas input was",histo1D
154# histos[jetDef][systematicName] = histo
155 histos[jetDef][systematicName] = histo1D
156
157 # EM has 10 stat parameters, LC has 11
158 # So for EM algorithms, make an empty histo for stat 11
159# if "EM" in jetDef:
160# systematicName = SystematicNameDictionary['mjbstat11']
161# histos[jetDef][systematicName] = ProviderHistoHelpers.MakeProviderHisto(systematicName+"_"+jetDef)
162# histos[jetDef][systematicName].SetDirectory(0)
163
164
165 # Done, return dictionary of histos
166 return histos
167
168
169
170
STL class.
void xrange(TH1 *h, bool symmetric)