ATLAS Offline Software
January2018_specialStatTerms/ParseInsituInput.py
Go to the documentation of this file.
1 from ROOT import *
2 from array import array
3 import glob
4 import re
5 import math
6 import ProviderHistoHelpers
7 
8 # Dictinary below last updated to match inputs from Bogdan and Meghan
9 # sent December 14 2016
10 
11 # Dictionary to translate from Bogan's names to provider names
12 SystematicNameDictionary = {
13  'gammajetdphi' : 'Gjet_dPhi',
14  'gammajetgenerator' : 'Gjet_Generator',
15  'gammajetjvt' : 'Gjet_Jvt',
16  'gammajetshower' : 'Gjet_ShowerTopology',
17  'gammajetphscalez' : 'Gjet_GamESZee',
18  'gammajetphsmear' : 'Gjet_GamEsmear',
19  'gammajetpurity' : 'Gjet_Purity',
20  'gammajetstat1' : 'Gjet_Stat1',
21  'gammajetstat2' : 'Gjet_Stat2',
22  'gammajetstat3' : 'Gjet_Stat3',
23  'gammajetstat4' : 'Gjet_Stat4',
24  'gammajetstat5' : 'Gjet_Stat5',
25  'gammajetstat6' : 'Gjet_Stat6',
26  'gammajetstat7' : 'Gjet_Stat7',
27  'gammajetstat8' : 'Gjet_Stat8',
28  'gammajetstat9' : 'Gjet_Stat9',
29  'gammajetstat10' : 'Gjet_Stat10',
30  'gammajetstat11' : 'Gjet_Stat11',
31  'gammajetstat12' : 'Gjet_Stat12',
32  'gammajetstat13' : 'Gjet_Stat13',
33  'gammajetstat14' : 'Gjet_Stat14',
34  'gammajetstat15' : 'Gjet_Stat15',
35  'gammajetstat16' : 'Gjet_Stat16',
36  'gammajetsubleadingjet' : 'Gjet_Veto',
37  'mjbalpha' : 'MJB_Alpha',
38  'mjbbeta' : 'MJB_Beta',
39  'mjbfrag' : 'MJB_Fragmentation', # WAS: mjbmodelling
40  'mjbjvt' : 'MJB_JVT',
41  'mjbptasymm' : 'MJB_Asym',
42  'mjbptthreshold' : 'MJB_Threshold',
43  'mjbstat1' : 'MJB_Stat1',
44  'mjbstat2' : 'MJB_Stat2',
45  'mjbstat3' : 'MJB_Stat3',
46  'mjbstat4' : 'MJB_Stat4',
47  'mjbstat5' : 'MJB_Stat5',
48  'mjbstat6' : 'MJB_Stat6',
49  'mjbstat7' : 'MJB_Stat7',
50  'mjbstat8' : 'MJB_Stat8',
51  'mjbstat9' : 'MJB_Stat9',
52  'mjbstat10' : 'MJB_Stat10',
53  'mjbstat11' : 'MJB_Stat11',
54  'mjbstat12' : 'MJB_Stat12',
55  'mjbstat13' : 'MJB_Stat13',
56  'mjbstat14' : 'MJB_Stat14',
57  'mjbstat15' : 'MJB_Stat15',
58  'mjbstat16' : 'MJB_Stat16',
59  'mjbstat17' : 'MJB_Stat17',
60  'mjbstat18' : 'MJB_Stat18',
61  'mjbstat19' : 'MJB_Stat19',
62  'mjbstat20' : 'MJB_Stat20',
63  'mjbstat21' : 'MJB_Stat21',
64  'mjbstat22' : 'MJB_Stat22',
65  'mjbstat23' : 'MJB_Stat23',
66  'mjbstat24' : 'MJB_Stat24',
67  'mjbstat25' : 'MJB_Stat25',
68  'mjbstat26' : 'MJB_Stat26',
69  'mjbstat27' : 'MJB_Stat27',
70  'mjbstat28' : 'MJB_Stat28',
71  'zjetdphi' : 'Zjet_dPhi',
72  'zjetescale' : 'Zjet_ElecESZee',
73  'zjetesmear' : 'Zjet_ElecEsmear',
74  'zjetgenerator' : 'Zjet_MC',
75  'zjetjvt' : 'Zjet_Jvt',
76  'zjetmuscale' : 'Zjet_MuScale',
77  'zjetmusmearid' : 'Zjet_MuSmearID',
78  'zjetmusmearms' : 'Zjet_MuSmearMS',
79  'zjetmusagittares' : 'Zjet_MuSagittaRes',
80  'zjetmusagittarho' : 'Zjet_MuSagittaRho',
81  'zjetelstat1' : 'Zjet_ElecStat1',
82  'zjetelstat2' : 'Zjet_ElecStat2',
83  'zjetelstat3' : 'Zjet_ElecStat3',
84  'zjetelstat4' : 'Zjet_ElecStat4',
85  'zjetelstat5' : 'Zjet_ElecStat5',
86  'zjetelstat6' : 'Zjet_ElecStat6',
87  'zjetelstat7' : 'Zjet_ElecStat7',
88  'zjetelstat8' : 'Zjet_ElecStat8',
89  'zjetelstat9' : 'Zjet_ElecStat9',
90  'zjetelstat10' : 'Zjet_ElecStat10',
91  'zjetelstat11' : 'Zjet_ElecStat11',
92  'zjetelstat12' : 'Zjet_ElecStat12',
93  'zjetelstat13' : 'Zjet_ElecStat13',
94  'zjetelstat14' : 'Zjet_ElecStat14',
95  'zjetmustat1' : 'Zjet_MuStat1',
96  'zjetmustat2' : 'Zjet_MuStat2',
97  'zjetmustat3' : 'Zjet_MuStat3',
98  'zjetmustat4' : 'Zjet_MuStat4',
99  'zjetmustat5' : 'Zjet_MuStat5',
100  'zjetmustat6' : 'Zjet_MuStat6',
101  'zjetmustat7' : 'Zjet_MuStat7',
102  'zjetmustat8' : 'Zjet_MuStat8',
103  'zjetmustat9' : 'Zjet_MuStat9',
104  'zjetmustat10' : 'Zjet_MuStat10',
105  'zjetmustat11' : 'Zjet_MuStat11',
106  'zjetmustat12' : 'Zjet_MuStat12',
107  'zjetmustat13' : 'Zjet_MuStat13',
108  'zjetmustat14' : 'Zjet_MuStat14',
109  'zjetsubleadingjet' : 'Zjet_Veto',
110  'zjetshower' : 'Zjet_ShowerTopology',
111  # The following are from the terms which
112  # were propagated through the MJB calculation
113  'etaintercalibrationmodelling' : 'InSituProp_EtaIntercalModelling',
114  'etaintercalibrationnonclosurehighe' : 'InSituProp_EtaIntercalNonClosureHighE',
115  'etaintercalibrationnonclosureposeta' : 'InSituProp_EtaIntercalNonClosurePosEta',
116  'etaintercalibrationnonclosurenegeta' : 'InSituProp_EtaIntercalNonClosureNegEta',
117  'etaintercalibrationofcs' : 'InSituProp_EtaIntercalOFCs',
118  'etaintercalibrationtotalstat' : 'InSituProp_EtaIntercalStat',
119  'flavorcomposition' : 'InSituProp_FlavorComposition',
120  'flavorresponse' : 'InSituProp_FlavorResponse',
121  'pileupoffsetmu' : 'InSituProp_PileupOffsetMu',
122  'pileupoffsetnpv' : 'InSituProp_PileupOffsetNPV',
123  'pileupptterm' : 'InSituProp_PileupPtTerm',
124  'pileuprhotopology' : 'InSituProp_PileupRhoTopology',
125  'punchthroughmc16' : 'InSituProp_PunchThroughMC',
126  }
127 
128 jetDefDict = {
129  'EMJES_R4' : 'AntiKt4Topo_EMJES',
130  'PFJES_R4' : 'AntiKt4PFlow_EMJES'
131  }
132 
133 def ReadInSituHistograms(dirName):
134  if not dirName.endswith("/"):
135  dirName = dirName + "/"
136 
137  print dirName
138  import os
139  print os.listdir(dirName)
140 
141  # Run over each subdirectory (one per jet definition)
142  histos = {}
143  subDirs = sorted(glob.glob(dirName+"*/"))
144  print "Checking subdirs",subDirs
145  for aSubDirName in subDirs:
146  # Determine the jet definition
147  jetDef = ""
148  for aDirDef,aJetDef in jetDefDict.iteritems():
149  if aDirDef in aSubDirName:
150  jetDef = aJetDef
151  break
152  if jetDef == "":
153  print "Failed to determine jet definition for directory:",aSubDirName
154  return None
155  histos[jetDef] = {}
156 
157  # Loop over the systematic files in the subdirectory
158  systFiles = sorted(glob.glob(aSubDirName+"/SystError_*.txt"))
159  for aSystFile in systFiles:
160  # Figure out which component this is
161  aSubDirName = aSubDirName.rstrip("/")
162  systematicNameHandle = aSystFile.replace(aSubDirName+"/SystError_","")
163  systematicNameHandle = systematicNameHandle.replace(".txt","")
164  systematicName = SystematicNameDictionary[systematicNameHandle]
165  print "Making histogram %s --> %s"%(systematicNameHandle,systematicName)
166 
167  # Open the file
168  systematicFile = open(aSystFile,"r")
169 
170  # Read the lines of the file into arrays
171  lowBinEdges = []
172  systValues = []
173  for line in systematicFile.readlines():
174  line = line.strip("\r\n")
175  lowEdge = float(line.split()[0])
176  systVal = float(line.split()[2].strip())
177 
178  lowBinEdges.append(lowEdge)
179  systValues.append(systVal)
180 
181  # Done reading, close the file
182  systematicFile.close()
183 
184  # Make the last bin go up to 2500
185  lowBinEdges.append(2500.)
186  systValues.append(systValues[-1])
187 
188  # Turn the lists into arrays and build the 1D histogram
189  lowBinEdgesArray = array('d',lowBinEdges)
190  systValuesArray = array('d',systValues)
191  histoName = systematicName+"_"+jetDef
192  histo1D = TH1D(histoName+"_1D",histoName+"_1D",len(lowBinEdges)-1,lowBinEdgesArray)
193 
194  # Fill it from the file values
195  for iBin in xrange(1,histo1D.GetNbinsX()+1):
196  histo1D.SetBinContent(iBin,systValues[iBin-1])
197 
198  histos[jetDef][systematicName] = histo1D
199 
200  # EM has 10 stat parameters, LC has 11
201  # So for EM algorithms, make an empty histo for stat 11
202 # if "EM" in jetDef:
203 # systematicName = SystematicNameDictionary['mjbstat11']
204 # histos[jetDef][systematicName] = ProviderHistoHelpers.MakeProviderHisto(systematicName+"_"+jetDef)
205 # histos[jetDef][systematicName].SetDirectory(0)
206 
207 
208  # Done, return dictionary of histos
209  return histos
210 
211 
212 
213 
xrange
void xrange(TH1 *h, bool symmetric)
Definition: computils.cxx:516
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.
array
ParseInsituInput.ReadInSituHistograms
def ReadInSituHistograms(dirName)
Definition: Final2012/ParseInsituInput.py:82
Trk::open
@ open
Definition: BinningType.h:40
readCCLHist.float
float
Definition: readCCLHist.py:83